topological_inventory-providers-common 1.0.8 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -2
- data/lib/topological_inventory/providers/common.rb +1 -2
- data/lib/topological_inventory/providers/common/collector.rb +12 -4
- data/lib/topological_inventory/providers/common/collectors_pool.rb +2 -1
- data/lib/topological_inventory/providers/common/logging.rb +10 -4
- data/lib/topological_inventory/providers/common/mixins/sources_api.rb +58 -0
- data/lib/topological_inventory/providers/common/mixins/topology_api.rb +26 -0
- data/lib/topological_inventory/providers/common/mixins/x_rh_headers.rb +24 -0
- data/lib/topological_inventory/providers/common/operations/async_worker.rb +56 -0
- data/lib/topological_inventory/providers/common/operations/health_check.rb +15 -0
- data/lib/topological_inventory/providers/common/operations/source.rb +119 -144
- data/lib/topological_inventory/providers/common/sources_api_client.rb +92 -0
- data/lib/topological_inventory/providers/common/topology_api_client.rb +43 -0
- data/lib/topological_inventory/providers/common/version.rb +1 -1
- data/spec/support/shared/availability_check.rb +1 -1
- data/spec/topological_inventory/providers/common/operations/async_worker_spec.rb +36 -0
- data/topological_inventory-providers-common.gemspec +1 -1
- metadata +16 -7
- data/lib/topological_inventory/providers/common/operations/endpoint_client.rb +0 -65
- data/lib/topological_inventory/providers/common/operations/processor.rb +0 -135
- data/lib/topological_inventory/providers/common/operations/sources_api_client.rb +0 -94
- data/lib/topological_inventory/providers/common/operations/topology_api_client.rb +0 -28
- data/spec/topological_inventory/providers/common/operations/processor_spec.rb +0 -102
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 134e945b201072b8bdd7fc6af73b04a6f60698da831ef3989ab973453a1a5159
|
4
|
+
data.tar.gz: 20e4f260c411551572b557f4e4454fdc03c9e3b2ac9c8f5997e6600780298c1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a847566f6fb20e9518faef660c626788e6afd20d26cec28a5899e645c68cedd7c017974d0cb1c3c2524253007386b9728a1bb67a0f0a9101fe62bd388f03ccb
|
7
|
+
data.tar.gz: 6e786659b1bf913fe1e22d9c0618986d03dc4bc169d782e446ecd089b97a136b639f83be85c562006dccde83a8d025b102863b565aa571746767fa292e4dae89
|
data/CHANGELOG.md
CHANGED
@@ -4,8 +4,23 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
-
## [
|
7
|
+
## [2.0.0]
|
8
|
+
Operations/API clients refactoring
|
9
|
+
|
10
|
+
## [1.0.12] - 2020-10-01
|
11
|
+
Add Operations Async Worker class #55
|
12
|
+
|
13
|
+
## [1.0.11] - 2020-09-04
|
14
|
+
Make Collector Poll Time a parameter so we can tweak the collection interval #51
|
15
|
+
|
16
|
+
## [1.0.10] - 2020-08-26
|
17
|
+
Add HealthCheck class for operations workers #48
|
18
|
+
Set the LOG_LEVEL if present #50
|
19
|
+
|
20
|
+
## [1.0.9] - 2020-08-17
|
8
21
|
Added refresh-type to save and sweep inventory #45
|
22
|
+
|
23
|
+
## [1.0.8] - 2020-08-12
|
9
24
|
Add => to error messages that rubocop missed #44
|
10
25
|
|
11
26
|
## [1.0.7] - 2020-07-27
|
@@ -47,7 +62,12 @@ manageiq-loggers to >= 0.4.2 #20
|
|
47
62
|
## [1.0.0] - 2020-03-19
|
48
63
|
### Initial release to rubygems.org
|
49
64
|
|
50
|
-
[Unreleased]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/
|
65
|
+
[Unreleased]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.0.0...HEAD
|
66
|
+
[2.0.0]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v1.0.12...v2.0.0
|
67
|
+
[1.0.12]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v1.0.11...v1.0.12
|
68
|
+
[1.0.11]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v1.0.10...v1.0.11
|
69
|
+
[1.0.10]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v1.0.9...v1.0.10
|
70
|
+
[1.0.9]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v1.0.8...v1.0.9
|
51
71
|
[1.0.8]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v1.0.7...v1.0.8
|
52
72
|
[1.0.7]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v1.0.6...v1.0.7
|
53
73
|
[1.0.6]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v1.0.5...v1.0.6
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require "topological_inventory/providers/common/version"
|
2
2
|
require "topological_inventory/providers/common/logging"
|
3
|
-
require "topological_inventory/providers/common/operations/
|
4
|
-
require "topological_inventory/providers/common/operations/endpoint_client"
|
3
|
+
require "topological_inventory/providers/common/operations/health_check"
|
5
4
|
require "topological_inventory/providers/common/collectors_pool"
|
6
5
|
require "topological_inventory/providers/common/collector"
|
7
6
|
|
@@ -104,7 +104,8 @@ module TopologicalInventory
|
|
104
104
|
refresh_state_uuid = nil,
|
105
105
|
refresh_state_part_uuid = nil,
|
106
106
|
refresh_state_part_collected_at = nil,
|
107
|
-
refresh_state_part_sent_at = Time.now.utc
|
107
|
+
refresh_state_part_sent_at = Time.now.utc,
|
108
|
+
refresh_type = default_refresh_type)
|
108
109
|
return 0 if collections.empty?
|
109
110
|
|
110
111
|
SaveInventory::Saver.new(:client => ingress_api_client, :logger => logger).save(
|
@@ -116,7 +117,8 @@ module TopologicalInventory
|
|
116
117
|
:refresh_state_uuid => refresh_state_uuid,
|
117
118
|
:refresh_state_part_uuid => refresh_state_part_uuid,
|
118
119
|
:refresh_state_part_collected_at => refresh_state_part_collected_at,
|
119
|
-
:refresh_state_part_sent_at => refresh_state_part_sent_at
|
120
|
+
:refresh_state_part_sent_at => refresh_state_part_sent_at,
|
121
|
+
:refresh_type => refresh_type
|
120
122
|
)
|
121
123
|
)
|
122
124
|
rescue => e
|
@@ -134,7 +136,8 @@ module TopologicalInventory
|
|
134
136
|
total_parts,
|
135
137
|
sweep_scope,
|
136
138
|
refresh_state_started_at = nil,
|
137
|
-
refresh_state_sent_at = Time.now.utc
|
139
|
+
refresh_state_sent_at = Time.now.utc,
|
140
|
+
refresh_type = default_refresh_type)
|
138
141
|
return if !total_parts || sweep_scope.empty?
|
139
142
|
|
140
143
|
SaveInventory::Saver.new(:client => ingress_api_client, :logger => logger).save(
|
@@ -147,7 +150,8 @@ module TopologicalInventory
|
|
147
150
|
:total_parts => total_parts,
|
148
151
|
:sweep_scope => sweep_scope,
|
149
152
|
:refresh_state_started_at => refresh_state_started_at,
|
150
|
-
:refresh_state_sent_at => refresh_state_sent_at
|
153
|
+
:refresh_state_sent_at => refresh_state_sent_at,
|
154
|
+
:refresh_type => refresh_type
|
151
155
|
)
|
152
156
|
)
|
153
157
|
rescue => e
|
@@ -165,6 +169,10 @@ module TopologicalInventory
|
|
165
169
|
"Default"
|
166
170
|
end
|
167
171
|
|
172
|
+
def default_refresh_type
|
173
|
+
'full-refresh'
|
174
|
+
end
|
175
|
+
|
168
176
|
def ingress_api_client
|
169
177
|
TopologicalInventoryIngressApiClient::DefaultApi.new
|
170
178
|
end
|
@@ -5,8 +5,9 @@ module TopologicalInventory
|
|
5
5
|
module Common
|
6
6
|
class CollectorsPool
|
7
7
|
SECRET_FILENAME = "credentials".freeze
|
8
|
+
COLLECTOR_POLL_TIME = ENV['COLLECTOR_POLL_TIME']&.to_i || 300
|
8
9
|
|
9
|
-
def initialize(config_name, metrics, collector_poll_time:
|
10
|
+
def initialize(config_name, metrics, collector_poll_time: COLLECTOR_POLL_TIME, thread_pool_size: 2)
|
10
11
|
self.config_name = config_name
|
11
12
|
self.collector_status = Concurrent::Map.new
|
12
13
|
self.metrics = metrics
|
@@ -23,17 +23,23 @@ module TopologicalInventory
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def availability_check(message, severity = :info)
|
26
|
-
|
26
|
+
send("#{severity}_ext", "Source#availability_check", message)
|
27
27
|
end
|
28
28
|
|
29
|
-
|
30
|
-
|
29
|
+
%w[debug info warn error fatal].each do |severity|
|
30
|
+
define_method("#{severity}_ext".to_sym) do |prefix, message|
|
31
|
+
ext_message = [prefix, message].compact.join(' - ')
|
32
|
+
send(severity, ext_message)
|
33
|
+
end
|
31
34
|
end
|
32
35
|
end
|
33
36
|
|
34
37
|
class Logger < ManageIQ::Loggers::CloudWatch
|
35
38
|
def self.new(*args)
|
36
|
-
super.tap
|
39
|
+
super.tap do |logger|
|
40
|
+
logger.extend(TopologicalInventory::Providers::Common::LoggingFunctions)
|
41
|
+
logger.level = ENV['LOG_LEVEL'] if ENV['LOG_LEVEL']
|
42
|
+
end
|
37
43
|
end
|
38
44
|
end
|
39
45
|
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require "topological_inventory/providers/common/sources_api_client"
|
2
|
+
|
3
|
+
module TopologicalInventory
|
4
|
+
module Providers
|
5
|
+
module Common
|
6
|
+
module Mixins
|
7
|
+
module SourcesApi
|
8
|
+
AUTH_NOT_NECESSARY = "n/a".freeze
|
9
|
+
|
10
|
+
def sources_api
|
11
|
+
@sources_api ||= TopologicalInventory::Providers::Common::SourcesApiClient.new(identity)
|
12
|
+
end
|
13
|
+
|
14
|
+
def endpoint
|
15
|
+
@endpoint ||= sources_api.fetch_default_endpoint(source_id)
|
16
|
+
rescue => e
|
17
|
+
logger.error_ext(operation, "Failed to fetch Endpoint for Source #{source_id}: #{e.message}")
|
18
|
+
nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def authentication
|
22
|
+
@authentication ||= if endpoint.receptor_node.present?
|
23
|
+
AUTH_NOT_NECESSARY
|
24
|
+
else
|
25
|
+
sources_api.fetch_authentication(source_id, endpoint)
|
26
|
+
end
|
27
|
+
rescue => e
|
28
|
+
logger.error_ext(operation, "Failed to fetch Authentication for Source #{source_id}: #{e.message}")
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
|
32
|
+
def application
|
33
|
+
@application ||= sources_api.fetch_application(source_id)
|
34
|
+
rescue => e
|
35
|
+
logger.error_ext(operation, "Failed to fetch Application for Source #{source_id}: #{e.message}")
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
|
39
|
+
def on_premise?
|
40
|
+
@on_premise ||= endpoint&.receptor_node.to_s.strip.present?
|
41
|
+
end
|
42
|
+
|
43
|
+
def verify_ssl_mode
|
44
|
+
endpoint&.verify_ssl ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
|
45
|
+
end
|
46
|
+
|
47
|
+
def full_hostname(endpoint)
|
48
|
+
if on_premise?
|
49
|
+
"receptor://#{endpoint.receptor_node}"
|
50
|
+
else
|
51
|
+
endpoint.host.tap { |host| host << ":#{endpoint.port}" if endpoint.port }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "topological_inventory/providers/common/topology_api_client"
|
2
|
+
|
3
|
+
module TopologicalInventory
|
4
|
+
module Providers
|
5
|
+
module Common
|
6
|
+
module Mixins
|
7
|
+
module TopologyApi
|
8
|
+
# @identity attr_reader is expected
|
9
|
+
def topology_api
|
10
|
+
@topology_api ||= TopologicalInventory::Providers::Common::TopologyApiClient.new(identity)
|
11
|
+
end
|
12
|
+
|
13
|
+
def update_task(task_id, source_id: nil, state:, status:, target_type: nil, target_source_ref: nil, context: nil)
|
14
|
+
topology_api.update_task(task_id,
|
15
|
+
:source_id => source_id,
|
16
|
+
:state => state,
|
17
|
+
:status => status,
|
18
|
+
:target_type => target_type,
|
19
|
+
:target_source_ref => target_source_ref,
|
20
|
+
:context => context)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module TopologicalInventory
|
2
|
+
module Providers
|
3
|
+
module Common
|
4
|
+
module Mixins
|
5
|
+
module XRhHeaders
|
6
|
+
def account_number_by_identity(identity)
|
7
|
+
return @account_number if @account_number
|
8
|
+
return if identity.try(:[], 'x-rh-identity').nil?
|
9
|
+
|
10
|
+
identity_hash = JSON.parse(Base64.decode64(identity['x-rh-identity']))
|
11
|
+
@account_number = identity_hash.dig('identity', 'account_number')
|
12
|
+
rescue JSON::ParserError => e
|
13
|
+
logger.error_ext(operation, "Failed to parse identity header: #{e.message}")
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def identity_by_account_number(account_number)
|
18
|
+
@identity ||= {"x-rh-identity" => Base64.strict_encode64({"identity" => {"account_number" => account_number, "user" => {"is_org_admin" => true}}}.to_json)}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require "topological_inventory/providers/common/logging"
|
2
|
+
require "topological_inventory/providers/common/operations/health_check"
|
3
|
+
|
4
|
+
module TopologicalInventory
|
5
|
+
module Providers
|
6
|
+
module Common
|
7
|
+
module Operations
|
8
|
+
class AsyncWorker
|
9
|
+
include Logging
|
10
|
+
|
11
|
+
def initialize(processor, queue = nil)
|
12
|
+
@processor = processor
|
13
|
+
@queue = queue || Queue.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def start
|
17
|
+
return if thread.present?
|
18
|
+
|
19
|
+
@thread = Thread.new { listen }
|
20
|
+
end
|
21
|
+
|
22
|
+
def stop
|
23
|
+
thread&.exit
|
24
|
+
end
|
25
|
+
|
26
|
+
def enqueue(msg)
|
27
|
+
queue << msg
|
28
|
+
end
|
29
|
+
|
30
|
+
def listen
|
31
|
+
loop do
|
32
|
+
# the queue thread waits for a message to come during `Queue#pop`
|
33
|
+
msg = queue.pop
|
34
|
+
process_message(msg)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
attr_reader :thread, :queue, :processor
|
41
|
+
|
42
|
+
def process_message(msg)
|
43
|
+
processor.process!(msg)
|
44
|
+
rescue => err
|
45
|
+
model, method = msg.message.to_s.split(".")
|
46
|
+
logger.error("#{model}##{method}: async worker failure: #{err.cause}\n#{err}\n#{err.backtrace.join("\n")}")
|
47
|
+
ensure
|
48
|
+
msg.ack
|
49
|
+
TopologicalInventory::Providers::Common::Operations::HealthCheck.touch_file
|
50
|
+
logger.debug("Operations::AsyncWorker queue length: #{queue.length}") if queue.length >= 20 && queue.length % 5 == 0
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -1,194 +1,169 @@
|
|
1
1
|
require "topological_inventory/providers/common/logging"
|
2
2
|
require "active_support/core_ext/numeric/time"
|
3
|
-
require "topological_inventory/providers/common/
|
3
|
+
require "topological_inventory/providers/common/mixins/sources_api"
|
4
|
+
require "topological_inventory/providers/common/mixins/x_rh_headers"
|
4
5
|
|
5
6
|
module TopologicalInventory
|
6
7
|
module Providers
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
module Common
|
9
|
+
module Operations
|
10
|
+
class Source
|
11
|
+
include Logging
|
12
|
+
include Mixins::SourcesApi
|
13
|
+
include Mixins::XRhHeaders
|
11
14
|
|
12
|
-
|
15
|
+
STATUS_AVAILABLE, STATUS_UNAVAILABLE = %w[available unavailable].freeze
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
17
|
+
ERROR_MESSAGES = {
|
18
|
+
:authentication_not_found => "Authentication not found in Sources API",
|
19
|
+
:endpoint_or_application_not_found => "Endpoint or Application not found in Sources API",
|
20
|
+
}.freeze
|
18
21
|
|
19
|
-
|
20
|
-
|
22
|
+
LAST_CHECKED_AT_THRESHOLD = 5.minutes.freeze
|
23
|
+
AUTH_NOT_NECESSARY = "n/a".freeze
|
21
24
|
|
22
|
-
|
25
|
+
attr_accessor :identity, :operation, :params, :request_context, :source_id, :account_number
|
23
26
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
27
|
+
def initialize(params = {}, request_context = nil)
|
28
|
+
self.operation = 'Source'
|
29
|
+
self.params = params
|
30
|
+
self.request_context = request_context
|
31
|
+
self.source_id = params['source_id']
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
+
self.account_number = params['external_tenant']
|
34
|
+
self.identity = identity_by_account_number(account_number)
|
35
|
+
end
|
33
36
|
|
34
|
-
|
37
|
+
def availability_check
|
38
|
+
self.operation += '#availability_check'
|
35
39
|
|
36
|
-
|
40
|
+
return if params_missing?
|
37
41
|
|
38
|
-
|
42
|
+
return if checked_recently?
|
39
43
|
|
40
|
-
|
41
|
-
end
|
44
|
+
status, error_message = connection_status
|
42
45
|
|
43
|
-
|
44
|
-
|
45
|
-
def required_params
|
46
|
-
%w[source_id]
|
47
|
-
end
|
46
|
+
update_source_and_subresources(status, error_message)
|
48
47
|
|
49
|
-
|
50
|
-
is_missing = false
|
51
|
-
required_params.each do |attr|
|
52
|
-
if (is_missing = params[attr].blank?)
|
53
|
-
logger.availability_check("Missing #{attr} for the availability_check request [Source ID: #{source_id}]", :error)
|
54
|
-
break
|
55
|
-
end
|
48
|
+
logger.availability_check("Completed: Source #{source_id} is #{status}")
|
56
49
|
end
|
57
50
|
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
def checked_recently?
|
62
|
-
checked_recently = if endpoint.present?
|
63
|
-
endpoint.last_checked_at.present? && endpoint.last_checked_at >= LAST_CHECKED_AT_THRESHOLD.ago
|
64
|
-
elsif application.present?
|
65
|
-
application.last_checked_at.present? && application.last_checked_at >= LAST_CHECKED_AT_THRESHOLD.ago
|
66
|
-
end
|
51
|
+
private
|
67
52
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
end
|
53
|
+
def required_params
|
54
|
+
%w[source_id]
|
55
|
+
end
|
72
56
|
|
73
|
-
|
74
|
-
|
75
|
-
|
57
|
+
def params_missing?
|
58
|
+
is_missing = false
|
59
|
+
required_params.each do |attr|
|
60
|
+
if (is_missing = params[attr].blank?)
|
61
|
+
logger.availability_check("Missing #{attr} for the availability_check request [Source ID: #{source_id}]", :error)
|
62
|
+
break
|
63
|
+
end
|
64
|
+
end
|
76
65
|
|
77
|
-
|
78
|
-
if endpoint
|
79
|
-
endpoint_connection_check
|
80
|
-
elsif application
|
81
|
-
application_connection_check
|
66
|
+
is_missing
|
82
67
|
end
|
83
|
-
end
|
84
68
|
|
85
|
-
|
86
|
-
|
69
|
+
def checked_recently?
|
70
|
+
checked_recently = if endpoint.present?
|
71
|
+
endpoint.last_checked_at.present? && endpoint.last_checked_at >= LAST_CHECKED_AT_THRESHOLD.ago
|
72
|
+
elsif application.present?
|
73
|
+
application.last_checked_at.present? && application.last_checked_at >= LAST_CHECKED_AT_THRESHOLD.ago
|
74
|
+
end
|
87
75
|
|
88
|
-
|
89
|
-
connection_check
|
90
|
-
end
|
76
|
+
logger.availability_check("Skipping, last check at #{endpoint.last_checked_at || application.last_checked_at} [Source ID: #{source_id}] ") if checked_recently
|
91
77
|
|
92
|
-
|
93
|
-
case application.availability_status
|
94
|
-
when "available"
|
95
|
-
[STATUS_AVAILABLE, nil]
|
96
|
-
when "unavailable"
|
97
|
-
[STATUS_UNAVAILABLE, "Application id #{application.id} unavailable"]
|
78
|
+
checked_recently
|
98
79
|
end
|
99
|
-
end
|
100
80
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
end
|
105
|
-
|
106
|
-
def update_source_and_subresources(status, error_message = nil)
|
107
|
-
logger.availability_check("Updating source [#{source_id}] status [#{status}] message [#{error_message}]")
|
81
|
+
def connection_status
|
82
|
+
# we need either an endpoint or application to check the source.
|
83
|
+
return [STATUS_UNAVAILABLE, ERROR_MESSAGES[:endpoint_or_application_not_found]] unless endpoint || application
|
108
84
|
|
109
|
-
|
85
|
+
check_time
|
86
|
+
if endpoint
|
87
|
+
endpoint_connection_check
|
88
|
+
elsif application
|
89
|
+
application_connection_check
|
90
|
+
end
|
91
|
+
end
|
110
92
|
|
111
|
-
|
112
|
-
|
113
|
-
end
|
93
|
+
def endpoint_connection_check
|
94
|
+
return [STATUS_UNAVAILABLE, ERROR_MESSAGES[:authentication_not_found]] unless authentication
|
114
95
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
source.last_checked_at = check_time
|
119
|
-
source.last_available_at = check_time if status == STATUS_AVAILABLE
|
96
|
+
# call down into the operations pod implementation of `Source#connection_check`
|
97
|
+
connection_check
|
98
|
+
end
|
120
99
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
100
|
+
def application_connection_check
|
101
|
+
case application.availability_status
|
102
|
+
when "available"
|
103
|
+
[STATUS_AVAILABLE, nil]
|
104
|
+
when "unavailable"
|
105
|
+
[STATUS_UNAVAILABLE, "Application id #{application.id} unavailable"]
|
106
|
+
end
|
107
|
+
end
|
125
108
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
return
|
109
|
+
# @return [Array<String, String|nil] - STATUS_[UN]AVAILABLE, error message
|
110
|
+
def connection_check
|
111
|
+
raise NotImplementedError, "#{__method__} must be implemented in a subclass"
|
130
112
|
end
|
131
113
|
|
132
|
-
|
114
|
+
def update_source_and_subresources(status, error_message = nil)
|
115
|
+
logger.availability_check("Updating source [#{source_id}] status [#{status}] message [#{error_message}]")
|
133
116
|
|
134
|
-
|
135
|
-
endpoint_update.availability_status_error = error_message.to_s
|
136
|
-
endpoint_update.last_checked_at = check_time
|
137
|
-
endpoint_update.last_available_at = check_time if status == STATUS_AVAILABLE
|
117
|
+
update_source(status)
|
138
118
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
end
|
119
|
+
update_endpoint(status, error_message) if endpoint
|
120
|
+
update_application(status) if application
|
121
|
+
end
|
143
122
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
123
|
+
def update_source(status)
|
124
|
+
source = ::SourcesApiClient::Source.new
|
125
|
+
source.availability_status = status
|
126
|
+
source.last_checked_at = check_time
|
127
|
+
source.last_available_at = check_time if status == STATUS_AVAILABLE
|
148
128
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
129
|
+
sources_api.update_source(source_id, source)
|
130
|
+
rescue ::SourcesApiClient::ApiError => e
|
131
|
+
logger.availability_check("Failed to update Source id:#{source_id} - #{e.message}", :error)
|
132
|
+
end
|
153
133
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
end
|
134
|
+
def update_endpoint(status, error_message)
|
135
|
+
if endpoint.nil?
|
136
|
+
logger.availability_check("Failed to update Endpoint for Source id:#{source_id}. Endpoint not found", :error)
|
137
|
+
return
|
138
|
+
end
|
160
139
|
|
161
|
-
|
162
|
-
@authentication ||= if endpoint.receptor_node.present?
|
163
|
-
AUTH_NOT_NECESSARY
|
164
|
-
else
|
165
|
-
api_client.fetch_authentication(source_id, endpoint)
|
166
|
-
end
|
167
|
-
rescue => e
|
168
|
-
logger.availability_check("Failed to fetch Authentication for Source #{source_id}: #{e.message}", :error)
|
169
|
-
nil
|
170
|
-
end
|
140
|
+
endpoint_update = ::SourcesApiClient::Endpoint.new
|
171
141
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
nil
|
177
|
-
end
|
142
|
+
endpoint_update.availability_status = status
|
143
|
+
endpoint_update.availability_status_error = error_message.to_s
|
144
|
+
endpoint_update.last_checked_at = check_time
|
145
|
+
endpoint_update.last_available_at = check_time if status == STATUS_AVAILABLE
|
178
146
|
|
179
|
-
|
180
|
-
|
181
|
-
|
147
|
+
sources_api.update_endpoint(endpoint.id, endpoint_update)
|
148
|
+
rescue ::SourcesApiClient::ApiError => e
|
149
|
+
logger.availability_check("Failed to update Endpoint(ID: #{endpoint.id}) - #{e.message}", :error)
|
150
|
+
end
|
182
151
|
|
183
|
-
|
184
|
-
|
185
|
-
|
152
|
+
def update_application(status)
|
153
|
+
application_update = ::SourcesApiClient::Application.new
|
154
|
+
application_update.last_checked_at = check_time
|
155
|
+
application_update.last_available_at = check_time if status == STATUS_AVAILABLE
|
186
156
|
|
187
|
-
|
188
|
-
|
157
|
+
sources_api.update_application(application.id, application_update)
|
158
|
+
rescue ::SourcesApiClient::ApiError => e
|
159
|
+
logger.availability_check("Failed to update Application id: #{application.id} - #{e.message}", :error)
|
160
|
+
end
|
161
|
+
|
162
|
+
def check_time
|
163
|
+
@check_time ||= Time.now.utc
|
164
|
+
end
|
189
165
|
end
|
190
166
|
end
|
191
167
|
end
|
192
168
|
end
|
193
|
-
end
|
194
169
|
end
|