[ARVADOS] updated: 35c20b4ad8220131f7f6bad6b3806a7d28df3ef3

git at public.curoverse.com git at public.curoverse.com
Fri Jun 6 09:47:18 EDT 2014


Summary of changes:
 .../app/controllers/arvados/v1/nodes_controller.rb | 12 +++++++++---
 services/api/app/models/node.rb                    |  9 +++++++++
 services/api/test/fixtures/nodes.yml               |  1 +
 .../functional/arvados/v1/nodes_controller_test.rb | 16 ++++++++++++++++
 services/api/test/unit/node_test.rb                | 22 +++++++++++++++++++---
 5 files changed, 54 insertions(+), 6 deletions(-)

       via  35c20b4ad8220131f7f6bad6b3806a7d28df3ef3 (commit)
       via  f48482bd37d3ae5a5f1aa488fa330f77c5fd640d (commit)
      from  0e7e57bbd8030c8144a18e43e68945ab11ad094c (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 35c20b4ad8220131f7f6bad6b3806a7d28df3ef3
Merge: 0e7e57b f48482b
Author: Brett Smith <brett at curoverse.com>
Date:   Fri Jun 6 09:47:11 2014 -0400

    Merge branch '2880-compute-ping-stats'
    
    Closes #2967, #2975.


commit f48482bd37d3ae5a5f1aa488fa330f77c5fd640d
Author: Brett Smith <brett at curoverse.com>
Date:   Thu Jun 5 11:38:46 2014 -0400

    2880: API server saves node statistics from pings.
    
    Crunch will use this information when scheduling Jobs, to satisfy
    specified runtime constraints.  Getting this data into the pings is
    the responsibility of the node's ping script.

diff --git a/services/api/app/controllers/arvados/v1/nodes_controller.rb b/services/api/app/controllers/arvados/v1/nodes_controller.rb
index 3fbf5fc..5bfeff0 100644
--- a/services/api/app/controllers/arvados/v1/nodes_controller.rb
+++ b/services/api/app/controllers/arvados/v1/nodes_controller.rb
@@ -20,9 +20,15 @@ class Arvados::V1::NodesController < ApplicationController
       if !@object
         return render_not_found
       end
-      @object.ping({ ip: params[:local_ipv4] || request.env['REMOTE_ADDR'],
-                     ping_secret: params[:ping_secret],
-                     ec2_instance_id: params[:instance_id] })
+      ping_data = {
+        ip: params[:local_ipv4] || request.env['REMOTE_ADDR'],
+        ec2_instance_id: params[:instance_id]
+      }
+      [:ping_secret, :total_cpu_cores, :total_ram_mb, :total_scratch_mb]
+        .each do |key|
+        ping_data[key] = params[key] if params[key]
+      end
+      @object.ping(ping_data)
       if @object.info['ping_secret'] == params[:ping_secret]
         render json: @object.as_api_response(:superuser)
       else
diff --git a/services/api/app/models/node.rb b/services/api/app/models/node.rb
index 2ca05f6..71d4dea 100644
--- a/services/api/app/models/node.rb
+++ b/services/api/app/models/node.rb
@@ -115,6 +115,15 @@ class Node < ArvadosModel
       end
     end
 
+    # Record other basic stats
+    ['total_cpu_cores', 'total_ram_mb', 'total_scratch_mb'].each do |key|
+      if value = (o[key] or o[key.to_sym])
+        self.info[key] = value
+      else
+        self.info.delete(key)
+      end
+    end
+
     save!
   end
 
diff --git a/services/api/test/fixtures/nodes.yml b/services/api/test/fixtures/nodes.yml
index 398bdf5..92e78da 100644
--- a/services/api/test/fixtures/nodes.yml
+++ b/services/api/test/fixtures/nodes.yml
@@ -32,3 +32,4 @@ idle:
   info:
     :ping_secret: "69udawxvn3zzj45hs8bumvndricrha4lcpi23pd69e44soanc0"
     :slurm_state: "idle"
+    total_cpu_cores: 16
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 e096a04..06695aa 100644
--- a/services/api/test/functional/arvados/v1/nodes_controller_test.rb
+++ b/services/api/test/functional/arvados/v1/nodes_controller_test.rb
@@ -75,4 +75,20 @@ class Arvados::V1::NodesControllerTest < ActionController::TestCase
     assert_not_nil json_response['info']['ping_secret']
   end
 
+  test "ping adds node stats to info" do
+    node = nodes(:idle)
+    post :ping, {
+      id: node.uuid,
+      ping_secret: node.info['ping_secret'],
+      total_cpu_cores: 32,
+      total_ram_mb: 1024,
+      total_scratch_mb: 2048
+    }
+    assert_response :success
+    info = JSON.parse(@response.body)['info']
+    assert_equal(node.info['ping_secret'], info['ping_secret'])
+    assert_equal(32, info['total_cpu_cores'].to_i)
+    assert_equal(1024, info['total_ram_mb'].to_i)
+    assert_equal(2048, info['total_scratch_mb'].to_i)
+  end
 end
diff --git a/services/api/test/unit/node_test.rb b/services/api/test/unit/node_test.rb
index ccc3765..5a9a057 100644
--- a/services/api/test/unit/node_test.rb
+++ b/services/api/test/unit/node_test.rb
@@ -1,7 +1,23 @@
 require 'test_helper'
 
 class NodeTest < ActiveSupport::TestCase
-  # test "the truth" do
-  #   assert true
-  # end
+  def ping_node(node_name, ping_data)
+    set_user_from_auth :admin
+    node = nodes(node_name)
+    node.ping({ping_secret: node.info['ping_secret'],
+                ip: node.ip_address}.merge(ping_data))
+    node
+  end
+
+  test "pinging a node can add and update stats" do
+    node = ping_node(:idle, {total_cpu_cores: '12', total_ram_mb: '512'})
+    assert_equal(12, node.info['total_cpu_cores'].to_i)
+    assert_equal(512, node.info['total_ram_mb'].to_i)
+  end
+
+  test "stats disappear if not in a ping" do
+    node = ping_node(:idle, {total_ram_mb: '256'})
+    refute_includes(node.info, 'total_cpu_cores')
+    assert_equal(256, node.info['total_ram_mb'].to_i)
+  end
 end

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list