Class: Actions::Katello::Repository::CreateContainerPushRoot

Inherits:
EntryAction
  • Object
show all
Defined in:
app/lib/actions/katello/repository/create_container_push_root.rb

Instance Method Summary collapse

Instance Method Details

#humanized_nameObject



38
39
40
# File 'app/lib/actions/katello/repository/create_container_push_root.rb', line 38

def humanized_name
  _("Create Container Push Repository Root")
end

#plan(root, relative_path = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/lib/actions/katello/repository/create_container_push_root.rb', line 5

def plan(root, relative_path = nil)
  repository = ::Katello::Repository.new(:environment => root.organization.library, :content_view_version => root.organization.library.default_content_view_version, :root => root)
  #Container push may concurrently call root add several times before the db can update.
  # If the root already exists, we can skip the creation of the root and repository.
  # We acquire a lock on the product to ensure that the root is not created multiple times by different workers.

  root.product.with_lock do
    begin
      root.save!
    rescue ActiveRecord::RecordInvalid => e
      if root.is_container_push && e.message.include?("Name has already been taken for this product")
        Rails.logger.debug("Skipping root repository creation as container push root repository already exists: #{root.container_push_name}")
        return
      end
      raise e
    end
    repository.container_repository_name = relative_path if root.docker? && root.is_container_push
    repository.relative_path = relative_path || repository.custom_repo_path
    begin
      repository.save!
    rescue ActiveRecord::RecordInvalid => e
      if root.is_container_push && e.message.include?("Container Repository Name") && e.message.include?("conflicts with an existing repository")
        Rails.logger.debug("Skipping repository creation as container push repository already exists: #{root.container_push_name}")
        return
      end
      raise e
    end
  end

  action_subject(repository)
  plan_action(::Actions::Katello::Repository::Create, repository)
end