topological_inventory-core 1.1.0 → 1.1.5
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/README.md +1 -1
- data/config/database.yml +5 -3
- data/db/migrate/20200414123737_extract_tasks_source_ref_from_context.rb +5 -0
- data/db/migrate/20200421141934_add_source_updated_at.rb +5 -0
- data/db/migrate/20200428090420_add_request_id_to_task.rb +5 -0
- data/db/migrate/20200505101547_add_forwardable_headers_remove_request_id_on_task.rb +11 -0
- data/db/schema.rb +3 -1
- data/lib/topological_inventory/core/version.rb +1 -1
- data/lib/topological_inventory/schema/default.rb +31 -24
- metadata +38 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc2335e206b9eba3ab955c62d29422156bb4053e737cd9aece9a5b91748b76ea
|
4
|
+
data.tar.gz: 163c7d564a74402c23b5001b885c2e83795263547592f83032c7514f771300a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c16a6361df474d38fc189a159f27a33ee3dd4b21d17cc0ae256128ae8ac6db0eb67d64b4e4103fff64fc8905169b7b86e1448e84df6d3ebf1391960fa721b8e0
|
7
|
+
data.tar.gz: 35e182d151981fa96c604c630c87686d3c0a1a65fc061789be277602c0b1b91e73d74e2fc3f5171b3754af0bf2cfba81a45bba20cbc6b9bd01579a222744fca2
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# Topological Inventory Core
|
2
2
|
|
3
3
|
[](https://travis-ci.org/RedHatInsights/topological_inventory-core)
|
4
4
|
[](https://codeclimate.com/github/RedHatInsights/topological_inventory-core/maintainability)
|
data/config/database.yml
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
default: &default
|
2
2
|
adapter: postgresql
|
3
3
|
encoding: utf8
|
4
|
+
host: localhost
|
5
|
+
port: 5432
|
4
6
|
username: root
|
5
7
|
pool: 5
|
6
8
|
wait_timeout: 5
|
@@ -8,13 +10,13 @@ default: &default
|
|
8
10
|
|
9
11
|
development:
|
10
12
|
<<: *default
|
11
|
-
database:
|
13
|
+
database: topological_inventory_development
|
12
14
|
min_messages: notice
|
13
15
|
|
14
16
|
test:
|
15
17
|
<<: *default
|
16
|
-
database:
|
18
|
+
database: topological_inventory_test
|
17
19
|
|
18
20
|
production:
|
19
21
|
<<: *default
|
20
|
-
database:
|
22
|
+
database: topological_inventory_production
|
@@ -1,6 +1,11 @@
|
|
1
1
|
class ExtractTasksSourceRefFromContext < ActiveRecord::Migration[5.2]
|
2
2
|
def up
|
3
3
|
Task.find_each do |task|
|
4
|
+
if task.context.is_a?(String)
|
5
|
+
say "Found legacy data in Task #{task.id}, converting String to Hash..."
|
6
|
+
task.context = JSON.parse(task.context)
|
7
|
+
end
|
8
|
+
|
4
9
|
source_ref = task.context&.dig('service_instance', 'source_ref')
|
5
10
|
next if source_ref.nil?
|
6
11
|
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class AddForwardableHeadersRemoveRequestIdOnTask < ActiveRecord::Migration[5.2]
|
2
|
+
def up
|
3
|
+
add_column :tasks, :forwardable_headers, :jsonb
|
4
|
+
remove_column :tasks, :x_rh_insights_request
|
5
|
+
end
|
6
|
+
|
7
|
+
def down
|
8
|
+
add_column :tasks, :x_rh_insights_request, :string
|
9
|
+
remove_column :tasks, :forwardable_headers
|
10
|
+
end
|
11
|
+
end
|
data/db/schema.rb
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
#
|
11
11
|
# It's strongly recommended that you check this file into your version control system.
|
12
12
|
|
13
|
-
ActiveRecord::Schema.define(version:
|
13
|
+
ActiveRecord::Schema.define(version: 2020_05_05_101547) do
|
14
14
|
|
15
15
|
# These are extensions that must be enabled in order to support this database
|
16
16
|
enable_extension "plpgsql"
|
@@ -1190,6 +1190,7 @@ ActiveRecord::Schema.define(version: 2020_04_14_123737) do
|
|
1190
1190
|
t.string "target_source_ref"
|
1191
1191
|
t.string "target_type"
|
1192
1192
|
t.bigint "source_id"
|
1193
|
+
t.jsonb "forwardable_headers"
|
1193
1194
|
t.index ["source_id"], name: "index_tasks_on_source_id"
|
1194
1195
|
t.index ["target_type", "target_source_ref"], name: "index_tasks_on_target_type_and_target_source_ref"
|
1195
1196
|
t.index ["tenant_id"], name: "index_tasks_on_tenant_id"
|
@@ -1327,6 +1328,7 @@ ActiveRecord::Schema.define(version: 2020_04_14_123737) do
|
|
1327
1328
|
t.bigint "orchestration_stack_id"
|
1328
1329
|
t.bigint "subscription_id"
|
1329
1330
|
t.bigint "refresh_state_part_id"
|
1331
|
+
t.datetime "source_updated_at"
|
1330
1332
|
t.index ["archived_at"], name: "index_volumes_on_archived_at"
|
1331
1333
|
t.index ["last_seen_at"], name: "index_volumes_on_last_seen_at"
|
1332
1334
|
t.index ["orchestration_stack_id"], name: "index_volumes_on_orchestration_stack_id"
|
@@ -147,63 +147,70 @@ module TopologicalInventory
|
|
147
147
|
return if src_refs.blank?
|
148
148
|
|
149
149
|
# Updating Tasks
|
150
|
-
#
|
151
|
-
|
150
|
+
# service_instance_tasks_update_by_raw_sql(source)
|
151
|
+
service_instance_tasks_update_by_activerecord(tasks_collection, source, src_refs)
|
152
152
|
end
|
153
153
|
|
154
|
-
def task_update_values(svc_instance_id, external_url, status, finished_timestamp)
|
154
|
+
def task_update_values(svc_instance_id, source_ref, external_url, status, task_status, finished_timestamp, source_id)
|
155
155
|
{
|
156
156
|
:state => finished_timestamp.blank? ? 'running' : 'completed',
|
157
|
-
:status =>
|
157
|
+
:status => task_status,
|
158
158
|
:context => {
|
159
|
-
:remote_status => status,
|
160
159
|
:service_instance => {
|
161
|
-
:id
|
162
|
-
:
|
160
|
+
:id => svc_instance_id,
|
161
|
+
:job_status => status,
|
162
|
+
:source_id => source_id,
|
163
|
+
:source_ref => source_ref,
|
164
|
+
:url => external_url
|
163
165
|
}
|
164
166
|
}
|
165
167
|
}
|
166
168
|
end
|
167
169
|
|
168
170
|
# This method is updating one by one using ActiveRecord
|
169
|
-
def
|
171
|
+
def service_instance_tasks_update_by_activerecord(tasks_collection, source, svc_instances_source_ref)
|
170
172
|
service_instances = ServiceInstance.where(:source_id => source.id, :source_ref => svc_instances_source_ref)
|
171
173
|
tasks_by_source_ref = Task.where(:state => 'running', :target_type => 'ServiceInstance', :source_id => source.id, :target_source_ref => service_instances.pluck(:source_ref)).index_by(&:target_source_ref)
|
172
174
|
|
173
175
|
service_instances.select(:id, :external_url, :source_ref, :extra).find_in_batches do |group|
|
174
176
|
ActiveRecord::Base.transaction do
|
175
177
|
group.each do |svc_instance|
|
176
|
-
next if tasks_by_source_ref[svc_instance.source_ref].nil?
|
178
|
+
next if (task = tasks_by_source_ref[svc_instance.source_ref]).nil?
|
177
179
|
|
178
|
-
values = task_update_values(svc_instance.id, svc_instance.external_url, svc_instance.extra['status'], svc_instance.extra['finished'])
|
179
|
-
|
180
|
+
values = task_update_values(svc_instance.id, svc_instance.source_ref, svc_instance.external_url, svc_instance.extra['status'], svc_instance.extra['task_status'], svc_instance.extra['finished'], source.id)
|
181
|
+
# 1) Updating Task
|
182
|
+
task.update(values)
|
183
|
+
|
184
|
+
# 2) Saving to updated records (will be published in Kafka)
|
185
|
+
# - see topological_inventory-persister:Workflow.send_task_updates_to_queue!
|
186
|
+
tasks_collection.updated_records << values.merge(:id => task.id, :forwardable_headers => task.forwardable_headers)
|
180
187
|
end
|
181
188
|
end
|
182
189
|
end
|
183
190
|
end
|
184
191
|
|
185
192
|
# This method is bulk updating by raw SQL query
|
186
|
-
def
|
193
|
+
def service_instance_tasks_update_by_raw_sql(source)
|
187
194
|
# Get running tasks
|
188
|
-
|
189
|
-
.pluck(:
|
190
|
-
|
191
|
-
tasks_values.each do |attrs|
|
192
|
-
tasks_id << attrs[0]
|
193
|
-
tasks_source_ref << attrs[1]
|
194
|
-
end
|
195
|
+
tasks_source_ref = Task.where(:state => 'running', :target_type => 'ServiceInstance', :source_id => source.id)
|
196
|
+
.pluck(:target_source_ref)
|
197
|
+
return if tasks_source_ref.blank?
|
195
198
|
|
196
199
|
# Load saved service instances (IDs needed)
|
197
|
-
|
198
|
-
|
200
|
+
svc_instances_values = ServiceInstance.where(:source_ref => tasks_source_ref)
|
201
|
+
.pluck(:id, :external_url, :source_ref,
|
202
|
+
Arel.sql("extra->'finished'"),
|
203
|
+
Arel.sql("extra->'status'"),
|
204
|
+
Arel.sql("extra->'task_status'"))
|
205
|
+
return if svc_instances_values.blank?
|
199
206
|
|
200
207
|
sql_update_values = []
|
201
208
|
|
202
209
|
# Preparing SQL update values from loaded ServiceInstances
|
203
|
-
|
204
|
-
id, external_url, source_ref, finished_timestamp, status = attrs[0], attrs[1], attrs[2], attrs[3], attrs[4]
|
210
|
+
svc_instances_values.each do |attrs|
|
211
|
+
id, external_url, source_ref, finished_timestamp, status, task_status = attrs[0], attrs[1], attrs[2], attrs[3], attrs[4], attrs[5]
|
205
212
|
|
206
|
-
values = task_update_values(id, external_url, status, finished_timestamp)
|
213
|
+
values = task_update_values(id, external_url, status, task_status, finished_timestamp)
|
207
214
|
sql_update_values << "('#{source_ref}', '#{values[:state]}', '#{values[:status]}', '#{values[:context].to_json}'::json)"
|
208
215
|
end
|
209
216
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: topological_inventory-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Grare
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04
|
11
|
+
date: 2020-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: acts_as_tenant
|
@@ -136,20 +136,48 @@ dependencies:
|
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '3.8'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rubocop
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 0.69.0
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 0.69.0
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rubocop-performance
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '1.3'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '1.3'
|
139
167
|
- !ruby/object:Gem::Dependency
|
140
168
|
name: simplecov
|
141
169
|
requirement: !ruby/object:Gem::Requirement
|
142
170
|
requirements:
|
143
|
-
- - "
|
171
|
+
- - "~>"
|
144
172
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
173
|
+
version: 0.17.1
|
146
174
|
type: :development
|
147
175
|
prerelease: false
|
148
176
|
version_requirements: !ruby/object:Gem::Requirement
|
149
177
|
requirements:
|
150
|
-
- - "
|
178
|
+
- - "~>"
|
151
179
|
- !ruby/object:Gem::Version
|
152
|
-
version:
|
180
|
+
version: 0.17.1
|
153
181
|
- !ruby/object:Gem::Dependency
|
154
182
|
name: webmock
|
155
183
|
requirement: !ruby/object:Gem::Requirement
|
@@ -354,6 +382,9 @@ files:
|
|
354
382
|
- db/migrate/20200317082640_add_tracking_timestamps_to_refresh_state.rb
|
355
383
|
- db/migrate/20200403114310_add_target_and_source_to_task.rb
|
356
384
|
- db/migrate/20200414123737_extract_tasks_source_ref_from_context.rb
|
385
|
+
- db/migrate/20200421141934_add_source_updated_at.rb
|
386
|
+
- db/migrate/20200428090420_add_request_id_to_task.rb
|
387
|
+
- db/migrate/20200505101547_add_forwardable_headers_remove_request_id_on_task.rb
|
357
388
|
- db/schema.rb
|
358
389
|
- db/seeds.rb
|
359
390
|
- lib/tasks/topological_inventory_tasks.rake
|
@@ -385,7 +416,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
385
416
|
- !ruby/object:Gem::Version
|
386
417
|
version: '0'
|
387
418
|
requirements: []
|
388
|
-
rubygems_version: 3.
|
419
|
+
rubygems_version: 3.0.3
|
389
420
|
signing_key:
|
390
421
|
specification_version: 4
|
391
422
|
summary: Core Models and Schema for the Topological Inventory Service.
|