Commit 6974d7c9 authored by Samir Noir's avatar Samir Noir 🧀
Browse files

Add resources param on job controller index

This GET param allow to query the job list with the two additional
fields `resources_by_type` and `assigned_nodes`.
parent 48020484
......@@ -22,20 +22,35 @@ class JobsController < ApplicationController
offset = [(params[:offset] || 0).to_i, 0].max
limit = [(params[:limit] || LIMIT).to_i, LIMIT_MAX].min
jobs = OAR::Job.list(params)
total = jobs.count(:all)
params[:resources] = 'no' if params[:resources].nil?
jobs = jobs.offset(offset).limit(limit).includes(:job_types, :job_events, :gantt)
jobs_extra_hash = {}
jobs.each do |job|
job.links = links_for_item(job)
if params[:resources] != 'no'
jobs_extra_hash[job[:job_id]] = {}
jobs_extra_hash[job[:job_id]][:resources_by_type] = job.resources_by_type
jobs_extra_hash[job[:job_id]][:assigned_nodes] = job.assigned_nodes
end
end
jobs_hash = jobs.as_json
if params[:resources] != 'no'
jobs_hash.each do |job|
job.merge!(jobs_extra_hash[job[:uid]])
end
end
result = {
'total' => total,
'offset' => offset,
'items' => jobs,
'items' => jobs_hash,
'links' => links_for_collection
}
......@@ -87,8 +102,8 @@ class JobsController < ApplicationController
else
response.header['X-Oar-Info'] = begin
(
JSON.parse(http.body)['oardel_output'] || ''
).split("\n").join(' ')
JSON.parse(http.body)['oardel_output'] || ''
).split("\n").join(' ')
rescue StandardError
'-'
end
......
......@@ -54,6 +54,20 @@ describe JobsController do
}
]
end
it 'should fetch the list of jobs, with their resources' do
get :index, params: { site_id: 'rennes', resources: 'yes', format: :json }
expect(response.status).to eq 200
expect(json['total']).to eq @job_uids.length
expect(json['offset']).to eq 0
expect(json['items'].length).to eq @job_uids.length
expect(json['items'].map { |i| i['uid'] }.sort).to eq @job_uids.sort
expect(json['items'].first.has_key?('assigned_nodes')).to be true
expect(json['items'].first.has_key?('resources_by_type')).to be true
expect(json['items'].first['assigned_nodes']).to eq ['parasilo-3.rennes.grid5000.fr']
expect(json['items'].first['resources_by_type']['cores']).to eq ['parasilo-3.rennes.grid5000.fr', 'parasilo-3.rennes.grid5000.fr', 'parasilo-3.rennes.grid5000.fr', 'parasilo-3.rennes.grid5000.fr', 'parasilo-3.rennes.grid5000.fr', 'parasilo-3.rennes.grid5000.fr', 'parasilo-3.rennes.grid5000.fr', 'parasilo-3.rennes.grid5000.fr']
end
it 'should correctly deal with pagination filters' do
get :index, params: { site_id: 'rennes', offset: 11, limit: 5, format: :json }
expect(response.status).to eq 200
......@@ -62,6 +76,7 @@ describe JobsController do
expect(json['items'].length).to eq 5
expect(json['items'].map { |i| i['uid'] }).to eq [374_190, 374_189, 374_188, 374_187, 374_186]
end
it 'should correctly deal with other filters' do
params = { user: 'crohr', name: 'whatever' }
expect(OAR::Job).to receive(:list).with(hash_including(params))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment