module Actions class EntryAction < Actions::Base include Helpers::ArgsSerialization include Helpers::Lock execution_plan_hooks.use :drop_all_locks!, :on => :stopped # what locks to use on the resource? All by default, can be overriden. # It might one or more locks available for the resource. This following # special values are supported as well: # # * `:all`: lock all possible operations (all locks defined in resource's # `available_locks` method. Only tasks that link to the resource are # allowed while running this task # * `:exclusive`: same as `:all` + doesn't allow even linking to the resoruce. # typical example is deleting a container, preventing all actions # heppening on it's sub-resources (such a system). # * `:link`: only link the task to the resource, not locking # anything except exclusive locks def resource_locks :all end # Performs all that's needed to connect the action to the resource. # It converts the resource (and it's relatives defined in +related_resources+ # to serialized form (using +to_action_input+). # # It also locks the resource on the actions defined in +resource_locks+ method. # # The additional args can include more resources and/or a hash # with more data describing the action that should appear in the # action's input. # TODO redo as a middleware def action_subject(resource, *additional_args) Type! resource, ForemanTasks::Concerns::ActionSubject input.update serialize_args(resource, *resource.all_related_resources, *additional_args) if resource.is_a? ActiveRecord::Base if resource_locks == :link link!(resource) else exclusive_lock!(resource) end end end def humanized_input Helpers::Humanizer.new(self).input end def humanized_name _(super) end def self.all_action_names subclasses.map { |k| k.allocate.humanized_name } end def delay(_schedule_options, *args) serializer_class.new args end def self.serializer_class Serializers::ActiveRecordSerializer end def drop_all_locks!(_execution_plan) ForemanTasks::Lock.where(:task_id => task.id).destroy_all end end end