Commit bdb47a7c authored by Florent Didier's avatar Florent Didier
Browse files

status api: add network_address query string

parent a34b0691
......@@ -25,8 +25,8 @@ class ClustersController < ResourcesController
def status
result = {
"uid" => Time.now.to_i,
"nodes" => OAR::Resource.status(:clusters => params[:id]),
"disks" => OAR::Resource.disk_status(:clusters => params[:id]),
"nodes" => OAR::Resource.status(:clusters => params[:id], :network_address => params[:network_address]),
"disks" => OAR::Resource.disk_status(:clusters => params[:id], :network_address => params[:network_address]),
"links" => [
{
"rel" => "self",
......
......@@ -26,8 +26,8 @@ class SitesController < ResourcesController
result = {
"uid" => Time.now.to_i,
"nodes" => OAR::Resource.status(:clusters => valid_clusters),
"disks" => OAR::Resource.disk_status(:clusters => valid_clusters),
"nodes" => OAR::Resource.status(:clusters => valid_clusters, :network_address => params[:network_address]),
"disks" => OAR::Resource.disk_status(:clusters => valid_clusters, :network_address => params[:network_address]),
"links" => [
{
"rel" => "self",
......
......@@ -60,14 +60,19 @@ module OAR
"resource_id, cluster, network_address, core, state, available_upto#{include_comment ? ", comment" : ""}"
)
# Remove blank network addresses
resources = resources.where("network_address <> ''")
resources = resources.where(
:network_address => options[:network_address]
) unless options[:network_address].blank?
resources = resources.where(
:cluster => options[:clusters]
) unless options[:clusters].blank?
resources = resources.index_by(&:resource_id)
# Remove blank network addresses
resources = resources.where("network_address <> ''")
resources = resources.index_by(&:resource_id)
# abasu : Introduce a hash table to store counts of free / busy cores per node - 05.02.2015
# abasu : This hash table can be used to store other counters in future (add another element)
nodes_counter = {}
......@@ -77,7 +82,7 @@ module OAR
nodes_counter[resource.network_address]= {
:totalcores => 0,
:busycounter => 0,
:besteffortcounter => 0
:besteffortcounter => 0
} if !nodes_counter.has_key?(resource.network_address)
if !resource.core.zero?
# core=0 for non default type of resources
......@@ -225,14 +230,21 @@ module OAR
"resource_id, cluster, host, disk, diskpath"
)
# Keep only disks
# Column host of a disk resource is equal to column
# network_address of the node it belongs to
resources = resources.where(
:type => 'disk'
)
:host => options[:network_address]
) unless options[:network_address].blank?
resources = resources.where(
:cluster => options[:clusters]
) unless options[:clusters].blank?
# Keep only disks
resources = resources.where(
:type => 'disk'
)
resources = resources.index_by(&:resource_id)
get_active_jobs_by_moldable_id().each do |moldable_id, h|
......
......@@ -18,38 +18,53 @@ describe ClustersController do
render_views
describe "GET /sites/{{site_id}}/clusters/{{id}}/status" do
it "should return the status ONLY for the specified cluster" do
get :status, :site_id => "rennes", :id => "parapluie", :format => :json
response.status.should == 200
get :status, :site_id => "rennes", :id => "parasilo", :format => :json
expect(response.status).to eq 200
assert_media_type(:json)
json['nodes'].keys.map{|k| k.split('-')[0]}.uniq.sort.should == ['parapluie']
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']).not_to be_empty
expect(json['disks']['sdb.parasilo-5.rennes.grid5000.fr']['reservations']).not_to be_empty
end # "should return the status ONLY for the specified cluster"
# GET /sites/{{site_id}}/clusters/{{id}}/status?network_address={{network_address}}
it "should return the status ONLY for the specified node" do
get :status, :site_id => "rennes", :id => "parasilo", :network_address => "parasilo-5.rennes.grid5000.fr", :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-5']
expect(json['disks'].keys.map{|k| k.split('.')[1]}.uniq.sort).to eq ['parasilo-5']
expect(json['nodes']['parasilo-5.rennes.grid5000.fr']['reservations']).not_to be_empty
expect(json['disks']['sdb.parasilo-5.rennes.grid5000.fr']['reservations']).not_to be_empty
end # "should return the status ONLY for the specified node"
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
response.status.should == 200
expect(response.status).to eq 200
assert_media_type(:json)
json['nodes'].length.should == 46
json['nodes'].keys.uniq.sort.should == ["parapluie-1.rennes.grid5000.fr", "parapluie-10.rennes.grid5000.fr", "parapluie-11.rennes.grid5000.fr", "parapluie-12.rennes.grid5000.fr", "parapluie-13.rennes.grid5000.fr", "parapluie-14.rennes.grid5000.fr", "parapluie-15.rennes.grid5000.fr", "parapluie-16.rennes.grid5000.fr", "parapluie-17.rennes.grid5000.fr", "parapluie-18.rennes.grid5000.fr", "parapluie-19.rennes.grid5000.fr", "parapluie-2.rennes.grid5000.fr", "parapluie-20.rennes.grid5000.fr", "parapluie-21.rennes.grid5000.fr", "parapluie-22.rennes.grid5000.fr", "parapluie-23.rennes.grid5000.fr", "parapluie-24.rennes.grid5000.fr", "parapluie-25.rennes.grid5000.fr", "parapluie-26.rennes.grid5000.fr", "parapluie-27.rennes.grid5000.fr", "parapluie-28.rennes.grid5000.fr", "parapluie-29.rennes.grid5000.fr", "parapluie-3.rennes.grid5000.fr", "parapluie-30.rennes.grid5000.fr", "parapluie-31.rennes.grid5000.fr", "parapluie-32.rennes.grid5000.fr", "parapluie-33.rennes.grid5000.fr", "parapluie-34.rennes.grid5000.fr", "parapluie-35.rennes.grid5000.fr", "parapluie-36.rennes.grid5000.fr", "parapluie-37.rennes.grid5000.fr", "parapluie-38.rennes.grid5000.fr", "parapluie-39.rennes.grid5000.fr", "parapluie-4.rennes.grid5000.fr", "parapluie-40.rennes.grid5000.fr", "parapluie-5.rennes.grid5000.fr", "parapluie-51.rennes.grid5000.fr", "parapluie-52.rennes.grid5000.fr", "parapluie-53.rennes.grid5000.fr", "parapluie-54.rennes.grid5000.fr", "parapluie-55.rennes.grid5000.fr", "parapluie-56.rennes.grid5000.fr", "parapluie-6.rennes.grid5000.fr", "parapluie-7.rennes.grid5000.fr", "parapluie-8.rennes.grid5000.fr", "parapluie-9.rennes.grid5000.fr"]
expect(json['nodes'].length).to eq 46
expect(json['nodes'].keys.uniq.sort).to eq ["parapluie-1.rennes.grid5000.fr", "parapluie-10.rennes.grid5000.fr", "parapluie-11.rennes.grid5000.fr", "parapluie-12.rennes.grid5000.fr", "parapluie-13.rennes.grid5000.fr", "parapluie-14.rennes.grid5000.fr", "parapluie-15.rennes.grid5000.fr", "parapluie-16.rennes.grid5000.fr", "parapluie-17.rennes.grid5000.fr", "parapluie-18.rennes.grid5000.fr", "parapluie-19.rennes.grid5000.fr", "parapluie-2.rennes.grid5000.fr", "parapluie-20.rennes.grid5000.fr", "parapluie-21.rennes.grid5000.fr", "parapluie-22.rennes.grid5000.fr", "parapluie-23.rennes.grid5000.fr", "parapluie-24.rennes.grid5000.fr", "parapluie-25.rennes.grid5000.fr", "parapluie-26.rennes.grid5000.fr", "parapluie-27.rennes.grid5000.fr", "parapluie-28.rennes.grid5000.fr", "parapluie-29.rennes.grid5000.fr", "parapluie-3.rennes.grid5000.fr", "parapluie-30.rennes.grid5000.fr", "parapluie-31.rennes.grid5000.fr", "parapluie-32.rennes.grid5000.fr", "parapluie-33.rennes.grid5000.fr", "parapluie-34.rennes.grid5000.fr", "parapluie-35.rennes.grid5000.fr", "parapluie-36.rennes.grid5000.fr", "parapluie-37.rennes.grid5000.fr", "parapluie-38.rennes.grid5000.fr", "parapluie-39.rennes.grid5000.fr", "parapluie-4.rennes.grid5000.fr", "parapluie-40.rennes.grid5000.fr", "parapluie-5.rennes.grid5000.fr", "parapluie-51.rennes.grid5000.fr", "parapluie-52.rennes.grid5000.fr", "parapluie-53.rennes.grid5000.fr", "parapluie-54.rennes.grid5000.fr", "parapluie-55.rennes.grid5000.fr", "parapluie-56.rennes.grid5000.fr", "parapluie-6.rennes.grid5000.fr", "parapluie-7.rennes.grid5000.fr", "parapluie-8.rennes.grid5000.fr", "parapluie-9.rennes.grid5000.fr"]
end # "should return all nodes in the specified cluster for which the status is requested"
it "should return the status with the correct links" do
get :status, :site_id => "rennes", :id => "parapluie", :format => :json
response.status.should == 200
expect(response.status).to eq 200
assert_media_type(:json)
# the "links" section should be an array with only 2 elements "self" and "parent"
json["links"].should be_a(Array)
json["links"].length.should == 2
expect(json["links"]).to be_a(Array)
expect(json["links"].length).to eq 2
# first element is "self"
json["links"][0].should == {"rel"=>"self",
expect(json["links"][0]).to eq ({"rel"=>"self",
"href"=>"/sites/rennes/clusters/parapluie/status",
"type"=>"application/vnd.grid5000.item+json"}
"type"=>"application/vnd.grid5000.item+json"})
# second element is "parent"
json["links"][1].should == {"rel"=>"parent",
expect(json["links"][1]).to eq ({"rel"=>"parent",
"href"=>"/sites/rennes/clusters/parapluie",
"type"=>"application/vnd.grid5000.item+json"}
"type"=>"application/vnd.grid5000.item+json"})
end # "should return the status with the correct links"
end # "GET /sites/{{site_id}}/clusters/{{id}}/status"
......@@ -74,8 +89,8 @@ describe ClustersController do
get :show, :branch => 'master', :site_id => "nancy", :id => "mbi", :format => :json
assert_media_type(:json)
response.status.should == 200
json["queues"].should == ["admin", "production"]
expect(response.status).to eq 200
expect(json["queues"]).to eq ["admin", "production"]
end # it "should return ONLY cluster mbi in nancy without any queues filter"
it "should return ONLY cluster talc in nancy without any queues filter" do
......@@ -88,8 +103,8 @@ describe ClustersController do
get :show, :branch => 'master', :site_id => "nancy", :id => "talc", :format => :json
assert_media_type(:json)
response.status.should == 200
json["queues"].should == ["admin", "default"]
expect(response.status).to eq 200
expect(json["queues"]).to eq ["admin", "default"]
end # it "should return ONLY cluster talc in nancy without any queues filter"
it "should return ONLY cluster graphique in nancy without any queues filter" do
......@@ -102,8 +117,8 @@ describe ClustersController do
get :show, :branch => 'master', :site_id => "nancy", :id => "graphique", :format => :json
assert_media_type(:json)
response.status.should == 200
(json["queues"] | []).should == ["admin", "default"]
expect(response.status).to eq 200
expect(json["queues"] | []).to eq ["admin", "default"]
end # it "should return ONLY cluster graphique in nancy without any queues filter"
it "should return ONLY cluster mbi in nancy" do
......@@ -116,8 +131,8 @@ describe ClustersController do
get :show, :branch => 'master', :site_id => "nancy", :id => "mbi", :queues => "production", :format => :json
assert_media_type(:json)
response.status.should == 200
json["queues"].should == ["admin", "production"]
expect(response.status).to eq 200
expect(json["queues"]).to eq ["admin", "production"]
end # it "should return ONLY cluster mbi in nancy"
# abasu : unit test for bug ref 6363 to handle filter queues - 08.01.2016
......@@ -131,8 +146,8 @@ describe ClustersController do
get :show, :branch => 'master', :site_id => "nancy", :id => "talc", :queues => "default", :format => :json
assert_media_type(:json)
response.status.should == 200
json["queues"].should == ["admin", "default"]
expect(response.status).to eq 200
expect(json["queues"]).to eq ["admin", "default"]
end # it "should return ONLY cluster talc in nancy"
it "should return NO cluster because talc is NOT production cluster" do
......@@ -144,8 +159,8 @@ describe ClustersController do
to_return(:body => fixture("reference-repository/data/grid5000/sites/nancy/clusters/talc/talc.json"))
get :show, :branch => 'master', :site_id => "nancy", :id => "talc", :queues => "production", :format => :json
response.status.should == 404
response.body.should == "Cannot find resource /sites/nancy/clusters/talc"
expect(response.status).to eq 404
expect(response.body).to eq "Cannot find resource /sites/nancy/clusters/talc"
end # it "should return NO cluster because talc is NOT production cluster"
end # "GET /sites/{{site_id}}/clusters/{{id}}/"
......@@ -164,14 +179,14 @@ describe ClustersController do
get :index, :branch => 'master', :site_id => "nancy", :format => :json
assert_media_type(:json)
response.status.should == 200
json["total"].should == 3
expect(response.status).to eq 200
expect(json["total"]).to eq 3
clusterList = []
json["items"].each do |cluster|
clusterList = [cluster["uid"]] | clusterList
end
(clusterList - ["graphique","mbi","talc"]).should be_empty
expect(clusterList - ["graphique","mbi","talc"]).to be_empty
end # it "should return ALL clusters in site nancy without any queues param"
......@@ -185,10 +200,10 @@ describe ClustersController do
get :index, :branch => 'master', :site_id => "nancy", :queues => "production", :format => :json
assert_media_type(:json)
response.status.should == 200
json["total"].should == 1
json["items"][0]["uid"].should == "mbi"
json["items"][0]["queues"].should include("production")
expect(response.status).to eq 200
expect(json["total"]).to eq 1
expect(json["items"][0]["uid"]).to eq "mbi"
expect(json["items"][0]["queues"]).to include("production")
end # it "should return ONLY cluster mbi in nancy"
# abasu : unit test for bug ref 6363 to handle filter queues - 08.01.2016
......@@ -202,14 +217,14 @@ describe ClustersController do
get :index, :branch => 'master', :site_id => "nancy", :queues => "default", :format => :json
assert_media_type(:json)
response.status.should == 200
json["total"].should == 2
expect(response.status).to eq 200
expect(json["total"]).to eq 2
clusterList = []
json["items"].each do |cluster|
clusterList = [cluster["uid"]] | clusterList
cluster["queues"].should include("default")
expect(cluster["queues"]).to include("default")
end
(clusterList - ["graphique","talc"]).should be_empty
expect(clusterList - ["graphique","talc"]).to be_empty
end # it "should return ONLY clusters talc & graphique in site nancy"
......@@ -218,8 +233,8 @@ describe ClustersController do
get :index, :branch => 'master', :site_id => "nancy", :queues => "all", :format => :json
assert_media_type(:json)
response.status.should == 200
json["total"].should == 3
expect(response.status).to eq 200
expect(json["total"]).to eq 3
clusterList = []
combined_queues = []
......@@ -227,9 +242,9 @@ describe ClustersController do
clusterList = [cluster["uid"]] | clusterList
combined_queues = cluster["queues"] | combined_queues
end
combined_queues.should == ["admin","default","production"]
expect(combined_queues).to eq ["admin","default","production"]
(clusterList - ["graphique","mbi","talc"]).should be_empty
expect(clusterList - ["graphique","mbi","talc"]).to be_empty
end # it "should return ALL clusters in site nancy"
......
......@@ -20,33 +20,33 @@ describe SitesController do
describe "GET /sites" do
it "should get the correct collection of sites" do
get :index, :format => :json
response.status.should == 200
json['total'].should == 4
json['items'].length.should == 4
json['items'][0]['uid'].should == 'bordeaux'
json['items'][0]['links'].should be_a(Array)
expect(response.status).to eq 200
expect(json['total']).to eq 4
expect(json['items'].length).to eq 4
expect(json['items'][0]['uid']).to eq 'bordeaux'
expect(json['items'][0]['links']).to be_a(Array)
end
it "should correctly set the URIs when X-Api-Path-Prefix is present" do
@request.env['HTTP_X_API_PATH_PREFIX'] = 'sid'
get :index, :format => :json
response.status.should == 200
json['links'].find{|l| l['rel'] == 'self'}['href'].should == "/sid/sites"
expect(response.status).to eq 200
expect(json['links'].find{|l| l['rel'] == 'self'}['href']).to eq "/sid/sites"
end
it "should correctly set the URIs when X-Api-Mount-Path is present" do
@request.env['HTTP_X_API_MOUNT_PATH'] = '/sites'
get :index, :format => :json
response.status.should == 200
json['links'].find{|l| l['rel'] == 'self'}['href'].should == "/"
expect(response.status).to eq 200
expect(json['links'].find{|l| l['rel'] == 'self'}['href']).to eq "/"
end
it "should correctly set the URIs when X-Api-Mount-Path and X-Api-Path-Prefix are present" do
@request.env['HTTP_X_API_PATH_PREFIX'] = 'sid'
@request.env['HTTP_X_API_MOUNT_PATH'] = '/sites'
get :index, :format => :json
response.status.should == 200
json['links'].find{|l| l['rel'] == 'self'}['href'].should == "/sid"
expect(response.status).to eq 200
expect(json['links'].find{|l| l['rel'] == 'self'}['href']).to eq "/sid"
end
end # describe "GET /sites"
......@@ -54,15 +54,15 @@ describe SitesController do
describe "GET /sites/{{site_id}}" do
it "should fail if the site does not exist" do
get :show, :id => "doesnotexist", :format => :json
response.status.should == 404
expect(response.status).to eq 404
end
it "should return the site" do
get :show, :id => "rennes", :format => :json
response.status.should == 200
expect(response.status).to eq 200
assert_expires_in(60, :public => true)
json['uid'].should == 'rennes'
json['links'].map{|l| l['rel']}.sort.should == [
expect(json['uid']).to eq 'rennes'
expect(json['links'].map{|l| l['rel']}.sort).to eq [
"clusters",
"deployments",
"environments",
......@@ -75,21 +75,21 @@ describe SitesController do
"versions",
"vlans"
]
json['links'].find{|l|
expect(json['links'].find{|l|
l['rel'] == 'self'
}['href'].should == "/sites/rennes"
json['links'].find{|l|
}['href']).to eq "/sites/rennes"
expect(json['links'].find{|l|
l['rel'] == 'clusters'
}['href'].should == "/sites/rennes/clusters"
json['links'].find{|l|
}['href']).to eq "/sites/rennes/clusters"
expect(json['links'].find{|l|
l['rel'] == 'version'
}['href'].should == "/sites/rennes/versions/8a562420c9a659256eeaafcfd89dfa917b5fb4d0"
}['href']).to eq "/sites/rennes/versions/8a562420c9a659256eeaafcfd89dfa917b5fb4d0"
end
it "should return subresource links that are only in testing branch" do
get :show, :id => "lille", :format => :json, :branch => "testing"
response.status.should == 200
json['links'].map{|l| l['rel']}.sort.should == [
expect(response.status).to eq 200
expect(json['links'].map{|l| l['rel']}.sort).to eq [
"clusters",
"deployments",
"environments",
......@@ -108,32 +108,32 @@ describe SitesController do
# abasu 19.10.2016 - bug #7364 changed "deployments" to "deployment"
it "should return link for deployment" do
get :show, :id => "rennes", :format => :json
response.status.should == 200
json['uid'].should == 'rennes'
json['links'].find{|l|
expect(response.status).to eq 200
expect(json['uid']).to eq 'rennes'
expect(json['links'].find{|l|
l['rel'] == 'deployments'
}['href'].should == "/sites/rennes/deployments"
}['href']).to eq "/sites/rennes/deployments"
end # it "should return link for deployment" do
# abasu 26.10.2016 - bug #7301 should return link /servers if present in site
it "should return link /servers if present in site" do
get :show, :id => "nancy", :format => :json
response.status.should == 200
json['uid'].should == 'nancy'
json['links'].find{|l|
expect(response.status).to eq 200
expect(json['uid']).to eq 'nancy'
expect(json['links'].find{|l|
l['rel'] == 'servers'
}['href'].should == "/sites/nancy/servers"
}['href']).to eq "/sites/nancy/servers"
end # it "should return link /servers if present in site" do
it "should return the specified version, and the max-age value in the Cache-Control header should be big" do
get :show, :id => "rennes", :format => :json, :version => "b00bd30bf69c322ffe9aca7a9f6e3be0f29e20f4"
response.status.should == 200
expect(response.status).to eq 200
assert_expires_in(24*3600*30, :public => true)
json['uid'].should == 'rennes'
json['version'].should == 'b00bd30bf69c322ffe9aca7a9f6e3be0f29e20f4'
json['links'].find{|l|
expect(json['uid']).to eq 'rennes'
expect(json['version']).to eq 'b00bd30bf69c322ffe9aca7a9f6e3be0f29e20f4'
expect(json['links'].find{|l|
l['rel'] == 'version'
}['href'].should == "/sites/rennes/versions/b00bd30bf69c322ffe9aca7a9f6e3be0f29e20f4"
}['href']).to eq "/sites/rennes/versions/b00bd30bf69c322ffe9aca7a9f6e3be0f29e20f4"
end
end # describe "GET /sites/{{site_id}}"
......@@ -141,15 +141,26 @@ describe SitesController do
describe "GET /sites/{{site_id}}/status" do
it "should return 200 and the site status" do
get :status, :id => "rennes", :format => :json
response.status.should == 200
json['nodes'].length.should == 196
json['nodes'].keys.map{|k| k.split('-')[0]}.uniq.sort.should == [
expect(response.status).to eq 200
expect(json['nodes'].length).to eq 196
expect(json['nodes'].keys.map{|k| k.split('-')[0]}.uniq.sort).to eq [
'paraquad',
'paramount',
'paravent'
].sort
expect(json['disks']).to be_empty # no reservable disks on paramount-4
expect(json['nodes']['paramount-4.rennes.grid5000.fr']['reservations']).not_to be_nil
end
# GET /sites/{{site_id}}/status?network_address={{network_address}}
it "should return the status ONLY for the specified node" do
get :status, :id => "rennes", :network_address => "paramount-4.rennes.grid5000.fr", :format => :json
expect(response.status).to eq 200
expect(json['nodes'].keys.map{|k| k.split('.')[0]}.uniq.sort).to eq ['paramount-4']
expect(json['disks']).to be_empty
expect(json['nodes']['paramount-4.rennes.grid5000.fr']['reservations']).not_to be_nil
end
# it "should fail if the site does not exist" do
# pending "this will be taken care of at the api-proxy layer"
# end
......
......@@ -61,7 +61,12 @@ describe OAR::Resource do
expect(OAR::Resource.status(:clusters => ['paradent', 'paramount']).keys.
map{|n| n.split("-")[0]}.uniq.sort).to eq ['paradent', 'paramount']
end
it "should return the status only for the resources belonging to the given node" do
expect(OAR::Resource.status(:network_address => 'parasilo-1.rennes.grid5000.fr').keys.
map{|n| n.split(".")[0]}.uniq.sort).to eq ['parasilo-1']
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