X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/e350e7a5a074d6666f60b0a1789dce8da3037d8f..607fe087f6167061714a524dd53cbbc21b974973:/services/api/app/controllers/arvados/v1/nodes_controller.rb diff --git a/services/api/app/controllers/arvados/v1/nodes_controller.rb b/services/api/app/controllers/arvados/v1/nodes_controller.rb index c9ac096fb5..2f6c6504b7 100644 --- a/services/api/app/controllers/arvados/v1/nodes_controller.rb +++ b/services/api/app/controllers/arvados/v1/nodes_controller.rb @@ -3,22 +3,17 @@ class Arvados::V1::NodesController < ApplicationController skip_before_filter :find_object_by_uuid, :only => :ping skip_before_filter :render_404_if_no_object, :only => :ping - def create - @object = Node.new - @object.save! - @object.start!(lambda { |h| ping_arvados_v1_node_url(h) }) - show - end + include DbCurrentTime def update - if resource_attrs[:job_uuid] - @object.job_readable = readable_job_uuids(resource_attrs[:job_uuid]).any? + if resource_attrs[:job_uuid].is_a? String + @object.job_readable = readable_job_uuids([resource_attrs[:job_uuid]]).any? end super end def self._ping_requires_parameters - { ping_secret: true } + { ping_secret: {required: true} } end def ping @@ -28,7 +23,7 @@ class Arvados::V1::NodesController < ApplicationController return render_not_found end ping_data = { - ip: params[:local_ipv4] || request.env['REMOTE_ADDR'], + ip: params[:local_ipv4] || request.remote_ip, ec2_instance_id: params[:instance_id] } [:ping_secret, :total_cpu_cores, :total_ram_mb, :total_scratch_mb] @@ -37,7 +32,7 @@ class Arvados::V1::NodesController < ApplicationController end @object.ping(ping_data) if @object.info['ping_secret'] == params[:ping_secret] - render json: @object.as_api_response(:superuser) + send_json @object.as_api_response(:superuser) else raise "Invalid ping_secret after ping" end @@ -45,23 +40,24 @@ class Arvados::V1::NodesController < ApplicationController end def find_objects_for_index - if current_user.andand.is_admin || !current_user.andand.is_active - super - else + if !current_user.andand.is_admin && current_user.andand.is_active # active non-admin users can list nodes that are (or were # recently) working - @objects = model_class.where('last_ping_at >= ?', Time.now - 1.hours) + @objects = model_class.where('last_ping_at >= ?', db_current_time - 1.hours) end - assigned_nodes = @objects.select(&:job_uuid) - assoc_jobs = readable_job_uuids(*assigned_nodes.map(&:job_uuid)) - assigned_nodes.each do |node| - node.job_readable = assoc_jobs.include?(node.job_uuid) + super + if @select.nil? or @select.include? 'job_uuid' + job_uuids = @objects.map { |n| n[:job_uuid] }.compact + assoc_jobs = readable_job_uuids(job_uuids) + @objects.each do |node| + node.job_readable = assoc_jobs.include?(node[:job_uuid]) + end end end protected - def readable_job_uuids(*uuids) + def readable_job_uuids(uuids) Job.readable_by(*@read_users).select(:uuid).where(uuid: uuids).map(&:uuid) end end