add crunch_worker_state to Node api response. refs #1586
authorTom Clegg <tom@clinicalfuture.com>
Fri, 8 Nov 2013 21:16:18 +0000 (13:16 -0800)
committerTom Clegg <tom@clinicalfuture.com>
Fri, 8 Nov 2013 21:59:44 +0000 (13:59 -0800)
services/api/app/models/node.rb
services/api/test/fixtures/nodes.yml
services/api/test/functional/arvados/v1/nodes_controller_test.rb

index 8e17a8765d4aff9d55aea61602559229e15728ed..358e12b9344d10d34a906ce66ab227ffbcf4c27c 100644 (file)
@@ -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
index 780c3db362b69029483d77ef60f05ffc578d5e89..398bdf5cb06b9c6344acdab4bb107bfd3a7ecaf5 100644 (file)
@@ -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"
index ed678e9ec2e2b281b99edd43896f22e9602693a8..0c18d5f68d02ce122e7714420b488fca85eb2720 100644 (file)
@@ -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