1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 class Arvados::V1::NodesController < ApplicationController
6 skip_before_action :require_auth_scope, :only => :ping
7 skip_before_action :find_object_by_uuid, :only => :ping
8 skip_before_action :render_404_if_no_object, :only => :ping
12 def self._ping_requires_parameters
13 { ping_secret: {required: true} }
16 def self._create_requires_parameters
18 { assign_slot: {required: false, type: 'boolean', description: 'assign slot and hostname'} })
21 def self._update_requires_parameters
23 { assign_slot: {required: false, type: 'boolean', description: 'assign slot and hostname'} })
27 @object = model_class.new(resource_attrs)
28 @object.assign_slot if params[:assign_slot]
34 if resource_attrs[:job_uuid].is_a? String
35 @object.job_readable = readable_job_uuids([resource_attrs[:job_uuid]]).any?
37 attrs_to_update = resource_attrs.reject { |k,v|
38 [:kind, :etag, :href].index k
40 @object.update_attributes!(attrs_to_update)
41 @object.assign_slot if params[:assign_slot]
48 @object = Node.where(uuid: (params[:id] || params[:uuid])).first
50 return render_not_found
53 ip: params[:local_ipv4] || request.remote_ip,
54 ec2_instance_id: params[:instance_id]
56 [:ping_secret, :total_cpu_cores, :total_ram_mb, :total_scratch_mb]
58 ping_data[key] = params[key] if params[key]
60 @object.ping(ping_data)
61 if @object.info['ping_secret'] == params[:ping_secret]
62 send_json @object.as_api_response(:superuser)
64 raise "Invalid ping_secret after ping"
69 def find_objects_for_index
70 if !current_user.andand.is_admin && current_user.andand.is_active
71 # active non-admin users can list nodes that are (or were
73 @objects = model_class.where('last_ping_at >= ?', db_current_time - 1.hours)
76 if @select.nil? or @select.include? 'job_uuid'
77 job_uuids = @objects.map { |n| n[:job_uuid] }.compact
78 assoc_jobs = readable_job_uuids(job_uuids)
79 @objects.each do |node|
80 node.job_readable = assoc_jobs.include?(node[:job_uuid])
87 def readable_job_uuids(uuids)
88 Job.readable_by(*@read_users).select(:uuid).where(uuid: uuids).map(&:uuid)