Class: InsightsCloud::Async::CloudConnectorAnnounceTask
Constant Summary
ForemanInventoryUpload::Async::DelayedStart::START_WINDOW
Instance Method Summary
collapse
#after_delay, #humanized_name
#cert_auth_available?, #execute_cloud_request, #foreman_certificate
#candlepin_id_cert, #cp_owner_id, #upstream_owner
#execute_cloud_request
Instance Method Details
#logger ⇒ Object
96
97
98
|
# File 'lib/insights_cloud/async/cloud_connector_announce_task.rb', line 96
def logger
action_logger
end
|
#plan(immediate = false) ⇒ Object
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
|
# File 'lib/insights_cloud/async/cloud_connector_announce_task.rb', line 8
def plan(immediate = false)
if ForemanRhCloud.with_iop_smart_proxy?
logger.debug('Sources announcement skipped: running in IoP mode')
return
end
if Setting[:rhc_instance_id].blank?
logger.debug('Sources announcement skipped: rhc_instance_id is not set')
return
end
unless Setting[:allow_auto_inventory_upload]
logger.debug(
'Cloud connector is configured (rhc_instance_id is set) but automatic inventory upload is disabled. ' \
'Enable the "Automatic inventory upload" setting for full cloud connector functionality.'
)
end
if immediate
plan_self
else
after_delay do
plan_self
end
end
end
|
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/insights_cloud/async/cloud_connector_announce_task.rb', line 80
def recent_cloud_remediation?(org)
feature = RemoteExecutionFeature.find_by(label: 'rh_cloud_connector_run_playbook')
return false unless feature
JobInvocation.where(remote_execution_feature_id: feature.id)
.joins(:task)
.joins(targeting: :hosts)
.where(hosts: { organization_id: org.id })
.where('foreman_tasks_tasks.started_at > ?', 24.hours.ago)
.exists?
end
|
#rescue_strategy_for_self ⇒ Object
92
93
94
|
# File 'lib/insights_cloud/async/cloud_connector_announce_task.rb', line 92
def rescue_strategy_for_self
Dynflow::Action::Rescue::Skip
end
|
#run ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/insights_cloud/async/cloud_connector_announce_task.rb', line 35
def run
registered = []
confirmed_by_remediation = []
already_registered = []
skipped = []
failed = {}
Organization.unscoped.each do |org|
unless cert_auth_available?(org)
skipped << org.name
next
end
if recent_cloud_remediation?(org)
confirmed_by_remediation << org.name
next
end
presence = ForemanRhCloud::CloudPresence.new(org, logger)
result = presence.announce_to_sources
if result == :already_registered
already_registered << org.name
else
registered << org.name
end
rescue StandardError => ex
logger.warn("Failed to announce to Sources for organization #{org.name}: #{ex}")
logger.debug { ex.backtrace.join("\n") }
failed[org.name] = ex.message
end
parts = []
parts << "Registered: #{registered.join(', ')}" if registered.any?
parts << "Already registered: #{already_registered.join(', ')}" if already_registered.any?
parts << "Already registered (recent cloud remediation): #{confirmed_by_remediation.join(', ')}" if confirmed_by_remediation.any?
parts << "Skipped (no manifest): #{skipped.join(', ')}" if skipped.any?
if failed.any?
failed_details = failed.map { |name, msg| "#{name}: #{msg}" }.join('; ')
parts << "Failed: #{failed_details}"
end
output[:status] = parts.join('. ')
error!("Sources announcement failed for: #{failed.keys.join(', ')}") if failed.any?
end
|