21700: Install Bundler system-wide in Rails postinst
[arvados.git] / services / api / app / controllers / arvados / v1 / container_requests_controller.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'update_priorities'
6
7 class Arvados::V1::ContainerRequestsController < 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 :command, Array
12   accept_attribute_as_json :filters, Array
13   accept_attribute_as_json :scheduling_parameters, Hash
14   accept_attribute_as_json :secret_mounts, Hash
15
16   def self._index_requires_parameters
17     (super rescue {}).
18       merge({
19         include_trash: {
20           type: 'boolean', required: false, default: false, description: "Include container requests whose owner project is trashed.",
21         },
22       })
23   end
24
25   def self._show_requires_parameters
26     (super rescue {}).
27       merge({
28         include_trash: {
29           type: 'boolean', required: false, default: false, description: "Show container request even if its owner project is trashed.",
30         },
31       })
32   end
33
34   def self._container_status_requires_parameters
35     (super rescue {}).
36       merge({
37         uuid: {
38           type: 'string', required: true, description: "The UUID of the ContainerRequest in question.",
39         },
40       })
41   end
42
43   # This API is handled entirely by controller, so this method is
44   # never called -- it's only here for the sake of adding the API to
45   # the generated discovery document.
46   def container_status
47     send_json({"errors" => "controller-only API, not handled by rails"}, status: 400)
48   end
49
50   def update
51     if (resource_attrs.keys.map(&:to_sym) - [:owner_uuid, :name, :description, :properties]).empty? or @object.container_uuid.nil?
52       # If no attributes are being updated besides these, there are no
53       # cascading changes to other rows/tables, the only lock will be
54       # the single row lock on SQL UPDATE.
55       super
56     else
57       # Get locks ahead of time to avoid deadlock in cascading priority
58       # update
59       Container.transaction do
60         row_lock_for_priority_update @object.container_uuid
61         super
62       end
63     end
64   end
65 end