From d41a91a852046bf2a3cad1e6cbe0ea990e67c5a6 Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Fri, 8 Nov 2013 13:16:18 -0800 Subject: [PATCH] add crunch_worker_state to Node api response. refs #1586 --- services/api/app/models/node.rb | 12 +++++++++++ services/api/test/fixtures/nodes.yml | 21 ++++++++++++++++--- .../arvados/v1/nodes_controller_test.rb | 7 +++++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/services/api/app/models/node.rb b/services/api/app/models/node.rb index 8e17a8765d..358e12b934 100644 --- a/services/api/app/models/node.rb +++ b/services/api/app/models/node.rb @@ -25,6 +25,7 @@ class Node < ArvadosModel t.add :last_ping_at t.add :slot_number t.add :status + t.add :crunch_worker_state end api_accessible :superuser, :extend => :user do |t| t.add :first_ping_at @@ -41,6 +42,17 @@ class Node < ArvadosModel super || @@domain end + def crunch_worker_state + case self.info.andand[:slurm_state] + when 'alloc', 'comp' + 'busy' + when 'idle' + 'idle' + else + 'down' + end + end + def status if !self.last_ping_at if Time.now - self.created_at > 5.minutes diff --git a/services/api/test/fixtures/nodes.yml b/services/api/test/fixtures/nodes.yml index 780c3db362..398bdf5cb0 100644 --- a/services/api/test/fixtures/nodes.yml +++ b/services/api/test/fixtures/nodes.yml @@ -1,4 +1,4 @@ -running: +busy: uuid: zzzzz-7ekkf-53y36l1lu5ijveb owner_uuid: zzzzz-tpzed-d9tiejq69daie8f hostname: compute0 @@ -6,7 +6,9 @@ running: ip_address: 172.17.2.172 last_ping_at: <%= 1.minute.ago.to_s(:db) %> first_ping_at: <%= 23.hour.ago.to_s(:db) %> - info: {ping_secret: "48dpm3b8ijyj3jkr2yczxw0844dqd2752bhll7klodvgz9bg80"} + info: + :ping_secret: "48dpm3b8ijyj3jkr2yczxw0844dqd2752bhll7klodvgz9bg80" + :slurm_state: "alloc" down: uuid: zzzzz-7ekkf-2vbompg3ecc6e2s @@ -16,4 +18,17 @@ down: ip_address: 172.17.2.173 last_ping_at: <%= 1.hour.ago.to_s(:db) %> first_ping_at: <%= 23.hour.ago.to_s(:db) %> - info: {ping_secret: "2k3i71depad36ugwmlgzilbi4e8n0illb2r8l4efg9mzkb3a1k"} + info: + :ping_secret: "2k3i71depad36ugwmlgzilbi4e8n0illb2r8l4efg9mzkb3a1k" + +idle: + uuid: zzzzz-7ekkf-2z3mc76g2q73aio + owner_uuid: zzzzz-tpzed-d9tiejq69daie8f + hostname: compute2 + domain: "" + ip_address: 172.17.2.174 + last_ping_at: <%= 2.minute.ago.to_s(:db) %> + first_ping_at: <%= 23.hour.ago.to_s(:db) %> + info: + :ping_secret: "69udawxvn3zzj45hs8bumvndricrha4lcpi23pd69e44soanc0" + :slurm_state: "idle" diff --git a/services/api/test/functional/arvados/v1/nodes_controller_test.rb b/services/api/test/functional/arvados/v1/nodes_controller_test.rb index ed678e9ec2..0c18d5f68d 100644 --- a/services/api/test/functional/arvados/v1/nodes_controller_test.rb +++ b/services/api/test/functional/arvados/v1/nodes_controller_test.rb @@ -28,9 +28,16 @@ class Arvados::V1::NodesControllerTest < ActionController::TestCase assert_response :success node_items = JSON.parse(@response.body)['items'] assert_not_equal 0, node_items.size + found_busy_node = false node_items.each do |node| assert_nil node['info'].andand['ping_secret'] + assert_not_nil node['crunch_worker_state'] + if node['uuid'] == nodes(:busy).uuid + found_busy_node = true + assert_equal 'busy', node['crunch_worker_state'] + end end + assert_equal true, found_busy_node end end -- 2.30.2