Commit 2469dc04 authored by Florent Didier's avatar Florent Didier
Browse files

status api: add waiting query string

parent 093f3e50
......@@ -25,7 +25,7 @@ class ClustersController < ResourcesController
def status
result = {
"uid" => Time.now.to_i,
"nodes" => OAR::Resource.status(:clusters => params[:id], :network_address => params[:network_address], :job_details => params[:job_details]),
"nodes" => OAR::Resource.status(:clusters => params[:id], :network_address => params[:network_address], :job_details => params[:job_details], :waiting => params[:waiting]),
"links" => [
{
"rel" => "self",
......@@ -39,7 +39,7 @@ class ClustersController < ResourcesController
}
]
}
result["disks"] = OAR::Resource.disk_status(:clusters => params[:id], :network_address => params[:network_address], :job_details => params[:job_details]) if params[:disks] != "no"
result["disks"] = OAR::Resource.disk_status(:clusters => params[:id], :network_address => params[:network_address], :job_details => params[:job_details], :waiting => params[:waiting]) if params[:disks] != "no"
respond_to do |format|
format.g5kitemjson { render :json => result }
......
......@@ -26,7 +26,7 @@ class SitesController < ResourcesController
result = {
"uid" => Time.now.to_i,
"nodes" => OAR::Resource.status(:clusters => valid_clusters, :network_address => params[:network_address], :job_details => params[:job_details]),
"nodes" => OAR::Resource.status(:clusters => valid_clusters, :network_address => params[:network_address], :job_details => params[:job_details], :waiting => params[:waiting]),
"links" => [
{
"rel" => "self",
......@@ -40,7 +40,7 @@ class SitesController < ResourcesController
}
]
}
result["disks"] = OAR::Resource.disk_status(:clusters => valid_clusters, :network_address => params[:network_address], :job_details => params[:job_details]) if params[:disks] != "no"
result["disks"] = OAR::Resource.disk_status(:clusters => valid_clusters, :network_address => params[:network_address], :job_details => params[:job_details], :waiting => params[:waiting]) if params[:disks] != "no"
respond_to do |format|
format.g5kitemjson { render :json => result }
......
......@@ -204,6 +204,10 @@ module OAR
where("state IN ('Waiting','Hold','toLaunch','toError','toAckReservation','Launching','Running','Suspended','Resuming','Finishing')")
end # def active
def active_not_waiting
where("state IN ('Hold','toLaunch','toError','toAckReservation','Launching','Running','Suspended','Resuming','Finishing')")
end # def active_not_waiting
def expanded
Job.select("jobs.*, moldable_job_descriptions.moldable_walltime AS walltime, gantt_jobs_predictions.start_time AS predicted_start_time, moldable_job_descriptions.moldable_id").
joins("LEFT OUTER JOIN moldable_job_descriptions ON jobs.job_id = moldable_job_descriptions.moldable_job_id").
......
......@@ -90,7 +90,7 @@ module OAR
end
end # .each do |resource_id, resource|
get_active_jobs_by_moldable_id().each do |moldable_id, h|
get_active_jobs_by_moldable_id(options).each do |moldable_id, h|
current = h[:job].running?
# prepare job description now, since it will be added to each resource
......@@ -151,9 +151,10 @@ module OAR
result
end # def status
def get_active_jobs_by_moldable_id()
def get_active_jobs_by_moldable_id(options = {})
active_jobs_by_moldable_id = {}
Job.expanded.active.
jobs = options[:waiting] == 'no' ? Job.expanded.active_not_waiting : Job.expanded.active
jobs.
find(:all, :include => [:job_types]).
each{|job|
active_jobs_by_moldable_id[job.moldable_id] = {
......@@ -248,7 +249,7 @@ module OAR
resources = resources.index_by(&:resource_id)
get_active_jobs_by_moldable_id().each do |moldable_id, h|
get_active_jobs_by_moldable_id(options).each do |moldable_id, h|
current = h[:job].running?
# prepare job description now, since it will be added to each resource
......
......@@ -61,6 +61,17 @@ describe ClustersController do
expect(json['disks']['sdb.parasilo-5.rennes.grid5000.fr']['reservations']).to be_nil
end # "should return the status of nodes without the reservations"
# GET /sites/{{site_id}}/clusters/{{id}}/status?waiting=no
it "should not return the reservations in Waiting state" do
get :status, :site_id => "rennes", :id => "parasilo", :waiting => "no", :format => :json
expect(response.status).to eq 200
assert_media_type(:json)
expect(json['nodes'].keys.map{|k| k.split('-')[0]}.uniq.sort).to eq ['parasilo']
expect(json['disks']).not_to be_nil
expect(json['nodes']['parasilo-5.rennes.grid5000.fr']['reservations']).to be_empty
expect(json['disks']['sdb.parasilo-5.rennes.grid5000.fr']['reservations']).to be_empty
end # "should not return the reservations of nodes in Waiting state"
it "should return all nodes in the specified cluster for which the status is requested" do
get :status, :site_id => "rennes", :id => "parapluie", :format => :json
expect(response.status).to eq 200
......
......@@ -43,6 +43,10 @@ describe OAR::Job do
# abasu -- updated jobs list as new jobs added to test different bugs -- 2015.04.07
end
it "should fetch the list of active jobs being not in Waiting state" do
expect(OAR::Job.active_not_waiting.map(&:uid)).to eq([374173, 374179, 374180, 374185, 374186, 374190, 374191, 374192, 374193, 374194, 374195, 374196, 374198, 374210])
end
# abasu : test introduced below for correction to bug ref 5347 -- 2015.03.09
it "should fetch the job with the jobid AND match all job parameters" do
params = {
......
......@@ -71,6 +71,10 @@ describe OAR::Resource do
expect(OAR::Resource.status(:job_details => 'no').map{ |e| e[1]['reservations'] }.compact).to be_empty
end
it "should not return the reservations in Waiting state" do
expect(OAR::Resource.status(:waiting => 'no', :network_address => 'parasilo-5.rennes.grid5000.fr').first[1]['reservations']).to be_nil
end
# abasu : test added to check new status values -- bug ref 5106
it "should return a node with status free_busy" do
expect(OAR::Resource.status.select do |node, status|
......
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