2880: API server saves node statistics from pings.
authorBrett Smith <brett@curoverse.com>
Thu, 5 Jun 2014 15:38:46 +0000 (11:38 -0400)
committerBrett Smith <brett@curoverse.com>
Fri, 6 Jun 2014 13:39:55 +0000 (09:39 -0400)
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.

services/api/app/controllers/arvados/v1/nodes_controller.rb
services/api/app/models/node.rb
services/api/test/fixtures/nodes.yml
services/api/test/functional/arvados/v1/nodes_controller_test.rb
services/api/test/unit/node_test.rb

index 3fbf5fcc6bda25a9a2aedf4b3a72cb149619e31c..5bfeff06f5c11200c08258eba53489b594aa1e3f 100644 (file)
@@ -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
index 2ca05f62d59cc620d4e1b4fc8f48799c69c10266..71d4dea2c0cc815c7b29c30c8d0d7dac40c31cf1 100644 (file)
@@ -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
 
index 398bdf5cb06b9c6344acdab4bb107bfd3a7ecaf5..92e78da6c18e0f412a848b243b50b18b92e0555a 100644 (file)
@@ -32,3 +32,4 @@ idle:
   info:
     :ping_secret: "69udawxvn3zzj45hs8bumvndricrha4lcpi23pd69e44soanc0"
     :slurm_state: "idle"
+    total_cpu_cores: 16
index e096a045c60c81b9aef6bf1fcc08d714a48077e9..06695aa6a762a9871deef9f820dec14c33eefedb 100644 (file)
@@ -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
index ccc3765dd94060d98bed4b59f5f55b111292e8e4..5a9a057696041ab76a505977bdd3659b6e2daa94 100644 (file)
@@ -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