Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions app/controllers/api/v2/job_invocations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ def output
param :id, :identifier, :required => true
def hosts
set_hosts_and_template_invocations
set_statuses_and_smart_proxies
@total = @hosts.size
@hosts = @hosts.search_for(params[:search], :order => params[:order]).paginate(:page => params[:page], :per_page => params[:per_page])
@subtotal = @hosts.total_entries
set_statuses_and_smart_proxies
if params[:awaiting]
@hosts = @hosts.select { |host| @host_statuses[host.id] == 'N/A' }
end
Expand Down Expand Up @@ -313,13 +313,14 @@ def set_hosts_and_template_invocations
def set_statuses_and_smart_proxies
template_invocations = @template_invocations.includes(:run_host_job_task).to_a
hosts = @hosts.to_a
@host_statuses = Hash[hosts.map do |host|
template_invocation = template_invocations.find { |ti| ti.host_id == host.id }
template_invocations_by_host_id = template_invocations.index_by(&:host_id)
@host_statuses = hosts.to_h do |host|
template_invocation = template_invocations_by_host_id[host.id]
task = template_invocation.try(:run_host_job_task)
[host.id, template_invocation_status(task, @job_invocation.task)]
end]
@smart_proxy_id = Hash[template_invocations.map { |ti| [ti.host_id, ti.smart_proxy_id] }]
@smart_proxy_name = Hash[template_invocations.map { |ti| [ti.host_id, ti.smart_proxy_name] }]
end
@smart_proxy_id = template_invocations.to_h { |ti| [ti.host_id, ti.smart_proxy_id] }
@smart_proxy_name = template_invocations.to_h { |ti| [ti.host_id, ti.smart_proxy_name] }
end
end
end
Expand Down
17 changes: 17 additions & 0 deletions test/functional/api/v2/job_invocations_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,23 @@ class JobInvocationsControllerTest < ActionController::TestCase
end
end

describe '#hosts' do
test 'should compute job_status for the paginated subset' do
invocation = FactoryBot.create(:job_invocation, :with_template, :with_task)
2.times { invocation.template_invocations << FactoryBot.create(:template_invocation, :with_task, :with_host, :job_invocation => invocation) }
invocation.job_category = invocation.pattern_template_invocations.first.template.job_category
invocation.targeting.hosts = invocation.template_invocations.map(&:host)
invocation.save!

get :hosts, params: { :id => invocation.id, :page => 2, :per_page => 1 }
assert_response :success
result = ActiveSupport::JSON.decode(@response.body)
assert_equal 3, result['total']
assert_equal 1, result['results'].size
assert_equal(['success'], result['results'].map { |r| r['job_status'] })
end
end

describe 'raw output' do
let(:fake_output) do
(1..5).map do |i|
Expand Down
9 changes: 6 additions & 3 deletions webpack/JobInvocationDetail/__tests__/MainInformation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ jest.spyOn(api, 'get');
const originalToLocaleString = Date.prototype.toLocaleString;
beforeAll(() => {
// eslint-disable-next-line no-extend-native
Date.prototype.toLocaleString = function (locale, options) {
return originalToLocaleString.call(this, locale, { ...options, timeZone: 'UTC' });
Date.prototype.toLocaleString = function(locale, options) {
return originalToLocaleString.call(this, locale, {
...options,
timeZone: 'UTC',
});
};
});
afterAll(() => {
Expand Down Expand Up @@ -232,7 +235,7 @@ describe('JobInvocationDetailPage', () => {
{ key: GET_REPORT_TEMPLATES, url: '/api/report_templates' },
{
key: JOB_INVOCATION_KEY,
url: `/api/job_invocations/${jobId}?host_status=true`,
url: `/api/job_invocations/${jobId}`,
},
{
key: GET_REPORT_TEMPLATE_INPUTS,
Expand Down
2 changes: 1 addition & 1 deletion webpack/JobInvocationDetail/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const JobInvocationDetailPage = ({
}

useEffect(() => {
dispatch(getJobInvocation(`/api/job_invocations/${id}?host_status=true`));
dispatch(getJobInvocation(`/api/job_invocations/${id}`));
if (finished && !autoRefresh) {
dispatch(stopInterval(JOB_INVOCATION_KEY));
}
Expand Down
Loading