Class: InsightsCloud::Async::VmaasReposcanSync

Inherits:
Actions::EntryAction
  • Object
show all
Includes:
ForemanRhCloud::CertAuth
Defined in:
lib/insights_cloud/async/vmaas_reposcan_sync.rb

Overview

Triggers VMaaS reposcan sync via IoP gateway when repositories are synced

Constant Summary collapse

HTTP_TOO_MANY_REQUESTS =
429

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ForemanRhCloud::CertAuth

#cert_auth_available?, #execute_cloud_request, #foreman_certificate

Methods included from CandlepinCache

#candlepin_id_cert, #cp_owner_id, #upstream_owner

Methods included from ForemanRhCloud::CloudRequest

#execute_cloud_request

Class Method Details

.subscribeObject

Subscribe to Katello repository sync hook action, if available



12
13
14
15
16
17
# File 'lib/insights_cloud/async/vmaas_reposcan_sync.rb', line 12

def self.subscribe
  'Actions::Katello::Repository::SyncHook'.constantize
rescue NameError
  Rails.logger.debug('VMaaS reposcan sync: Repository::SyncHook action not found')
  nil
end

Instance Method Details

#organizationObject



63
64
65
# File 'lib/insights_cloud/async/vmaas_reposcan_sync.rb', line 63

def organization
  @organization ||= Organization.find(input[:organization_id])
end

#plan(repo, *_args) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/insights_cloud/async/vmaas_reposcan_sync.rb', line 19

def plan(repo, *_args)
  return unless ::ForemanRhCloud.with_iop_smart_proxy?

  repo_id = repo.is_a?(Hash) ? (repo[:id] || repo['id']) : nil
  unless repo_id
    logger.error("VMaaS reposcan sync: missing repository id in SyncHook plan parameters: #{repo.inspect}")
    return
  end

  organization_id = Katello::Repository.find(repo_id).organization_id

  plan_self(organization_id: organization_id)
end

#rescue_strategy_for_selfObject



59
60
61
# File 'lib/insights_cloud/async/vmaas_reposcan_sync.rb', line 59

def rescue_strategy_for_self
  Dynflow::Action::Rescue::Skip
end

#runObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/insights_cloud/async/vmaas_reposcan_sync.rb', line 33

def run
  url = ::InsightsCloud.vmaas_reposcan_sync_url

  response = execute_cloud_request(
    organization: organization,
    method: :put,
    url: url,
    headers: { 'Content-Type' => 'application/json' }
  )

  if response.code >= 200 && response.code < 300
    message = "VMaaS reposcan sync triggered successfully: #{response.code}"
    logger.info(message)
  else
    message = "VMaaS reposcan sync failed with status: #{response.code}, body: #{response.body}"
    logger.error(message)
  end
  output[:message] = message

  response
rescue RestClient::ExceptionWithResponse => e
  handle_rest_client_error(e)
rescue StandardError => e
  handle_standard_error(e)
end