Added ArvadosModel.search_for_user to perform full-text search on a model.
[arvados.git] / services / api / app / models / node.rb
index 8e17a8765d4aff9d55aea61602559229e15728ed..0934f2e982914f1396a2650cea9762d18c1683b2 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
@@ -60,7 +72,7 @@ class Node < ArvadosModel
 
     if o[:ping_secret] != self.info[:ping_secret]
       logger.info "Ping: secret mismatch: received \"#{o[:ping_secret]}\" != \"#{self.info[:ping_secret]}\""
-      return nil
+      raise ArvadosModel::UnauthorizedError.new("Incorrect ping_secret")
     end
     self.last_ping_at = Time.now
 
@@ -77,7 +89,11 @@ class Node < ArvadosModel
     if o[:ec2_instance_id]
       if !self.info[:ec2_instance_id] 
         self.info[:ec2_instance_id] = o[:ec2_instance_id]
-        `ec2-create-tags #{o[:ec2_instance_id]} --tag 'Name=#{self.uuid}'`
+        if (Rails.configuration.compute_node_ec2_tag_enable rescue true)
+          tag_cmd = ("ec2-create-tags #{o[:ec2_instance_id]} " +
+                     "--tag 'Name=#{self.uuid}'")
+          `#{tag_cmd}`
+        end
       elsif self.info[:ec2_instance_id] != o[:ec2_instance_id]
         logger.debug "Multiple nodes have credentials for #{self.uuid}"
         raise "#{self.uuid} is already running at #{self.info[:ec2_instance_id]} so rejecting ping from #{o[:ec2_instance_id]}"
@@ -99,7 +115,9 @@ class Node < ArvadosModel
       end while true
       self.hostname = self.class.hostname_for_slot(self.slot_number)
       if info[:ec2_instance_id]
-        `ec2-create-tags #{self.info[:ec2_instance_id]} --tag 'hostname=#{self.hostname}'`
+        if (Rails.configuration.compute_node_ec2_tag_enable rescue true)
+          `ec2-create-tags #{self.info[:ec2_instance_id]} --tag 'hostname=#{self.hostname}'`
+        end
       end
     end
 
@@ -130,12 +148,16 @@ class Node < ArvadosModel
     result.match(/INSTANCE\s*(i-[0-9a-f]+)/) do |m|
       instance_id = m[1]
       self.info[:ec2_instance_id] = instance_id
-      `ec2-create-tags #{instance_id} --tag 'Name=#{self.uuid}'`
+      if (Rails.configuration.compute_node_ec2_tag_enable rescue true)
+        `ec2-create-tags #{instance_id} --tag 'Name=#{self.uuid}'`
+      end
     end
     result.match(/SPOTINSTANCEREQUEST\s*(sir-[0-9a-f]+)/) do |m|
       sir_id = m[1]
       self.info[:ec2_sir_id] = sir_id
-      `ec2-create-tags #{sir_id} --tag 'Name=#{self.uuid}'`
+      if (Rails.configuration.compute_node_ec2_tag_enable rescue true)
+        `ec2-create-tags #{sir_id} --tag 'Name=#{self.uuid}'`
+      end
     end
     self.save!
   end