1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 require 'update_priorities'
7 class Arvados::V1::ContainersController < ApplicationController
8 accept_attribute_as_json :environment, Hash
9 accept_attribute_as_json :mounts, Hash
10 accept_attribute_as_json :runtime_constraints, Hash
11 accept_attribute_as_json :runtime_status, Hash
12 accept_attribute_as_json :command, Array
13 accept_attribute_as_json :scheduling_parameters, Hash
15 skip_before_action :find_object_by_uuid, only: [:current]
16 skip_before_action :render_404_if_no_object, only: [:current]
19 if @object.locked_by_uuid != Thread.current[:api_client_authorization].uuid
20 raise ArvadosModel::PermissionDeniedError.new("Not locked by your token")
22 if @object.runtime_token.nil?
23 @object = @object.auth
25 @object = ApiClientAuthorization.validate(token: @object.runtime_token)
27 raise ArvadosModel::PermissionDeniedError.new("Invalid runtime_token")
34 if (resource_attrs.keys.map(&:to_sym) - [:cost, :gateway_address, :output_properties, :progress, :runtime_status]).empty?
35 # If no attributes are being updated besides these, there are no
36 # cascading changes to other rows/tables, the only lock will the
37 # single row lock on SQL UPDATE.
40 Container.transaction do
41 # Get locks ahead of time to avoid deadlock in cascading priority
43 row_lock_for_priority_update @object.uuid
49 def find_objects_for_index
51 if action_name == 'lock' || action_name == 'unlock'
52 # Avoid loading more fields than we need
53 @objects = @objects.select(:id, :uuid, :state, :priority, :auth_uuid, :locked_by_uuid, :lock_count)
54 # This gets called from within find_object_by_uuid.
55 # find_object_by_uuid stores the original value of @select in
56 # @preserve_select, edits the value of @select, calls
57 # find_objects_for_index, then restores @select from the value
58 # of @preserve_select. So if we want our updated value of
59 # @select here to stick, we have to set @preserve_select.
60 @select = @preserve_select = %w(uuid state priority auth_uuid locked_by_uuid)
61 elsif action_name == 'update_priority'
62 # We're going to reload in update_priority!, which will select
63 # all attributes, but will fail if we don't select :id now.
64 @objects = @objects.select(:id, :uuid)
79 @object.update_priority!
84 if Thread.current[:api_client_authorization].nil?
85 send_error("Not logged in", status: 401)
87 @object = Container.for_current_token
89 send_error("Token is not associated with a container.", status: 404)
97 c = Container.for_current_token
98 if @object && c && @object.uuid == c.uuid
99 send_json({"secret_mounts" => @object.secret_mounts})
101 send_error("Token is not associated with this container.", status: 403)