Class: Katello::Pulp3::ModuleStream
Constant Summary
collapse
- PULPCORE_CONTENT_TYPE =
"rpm.modulemd".freeze
Instance Attribute Summary
#backend_data, #uuid
Class Method Summary
collapse
included
backend_unit_identifier, content_api_create, content_type, content_unit_list, create_content, #fetch_backend_data, fetch_content_list, find_duplicate_unit, #initialize, katello_name_from_pulpcore_name, model_class, page_options, pulp_data, pulp_units_batch_all, pulp_units_batch_for_repo, pulp_units_for_ids, supports_id_fetch?, unit_identifier
Class Method Details
.add_timestamps(rows) ⇒ Object
77
78
79
80
81
82
83
|
# File 'app/services/katello/pulp3/module_stream.rb', line 77
def self.add_timestamps(rows)
rows.each do |row|
row[:created_at] = DateTime.now
row[:updated_at] = DateTime.now
end
rows
end
|
.build_artifacts(katello_id, artifacts_json) ⇒ Object
28
29
30
31
32
33
34
|
# File 'app/services/katello/pulp3/module_stream.rb', line 28
def self.build_artifacts(katello_id, artifacts_json)
return [] if artifacts_json.empty?
artifacts = artifacts_json.map do |name|
{ name: name, module_stream_id: katello_id }
end
add_timestamps(artifacts)
end
|
.build_profile_rpms(katello_id, profiles_json) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'app/services/katello/pulp3/module_stream.rb', line 47
def self.build_profile_rpms(katello_id, profiles_json)
return [] if profiles_json.nil?
profile_rpms = profiles_json.map do |profile, artifacts_json|
profile_id = Katello::ModuleProfile.find_by(module_stream_id: katello_id, name: profile).id
if artifacts_json.is_a?(::Hash)
artifacts_json['rpms'].map do |rpm|
{name: rpm, module_profile_id: profile_id}
end
else
artifacts_json.map do |rpm|
{name: rpm, module_profile_id: profile_id}
end
end
end
add_timestamps(profile_rpms.flatten)
end
|
.build_profiles(katello_id, profiles_json) ⇒ Object
36
37
38
39
40
41
42
43
44
45
|
# File 'app/services/katello/pulp3/module_stream.rb', line 36
def self.build_profiles(katello_id, profiles_json)
return [] if profiles_json.empty?
profiles = profiles_json.map do |profile, _rpms|
{
module_stream_id: katello_id,
name: profile,
}
end
add_timestamps(profiles)
end
|
.build_stream_rpms(katello_id, package_hrefs) ⇒ Object
17
18
19
20
21
22
23
24
25
26
|
# File 'app/services/katello/pulp3/module_stream.rb', line 17
def self.build_stream_rpms(katello_id, package_hrefs)
package_ids = Katello::Rpm.where(:pulp_id => package_hrefs).pluck(:id)
rpms = package_ids.map do |package_id|
{
module_stream_id: katello_id,
rpm_id: package_id,
}
end
add_timestamps(rpms)
end
|
.content_api ⇒ Object
7
8
9
|
# File 'app/services/katello/pulp3/module_stream.rb', line 7
def self.content_api
PulpRpmClient::ContentModulemdsApi.new(Katello::Pulp3::Api::Yum.new(SmartProxy.pulp_primary!).api_client)
end
|
.generate_model_row(unit) ⇒ Object
67
68
69
70
71
72
73
74
75
|
# File 'app/services/katello/pulp3/module_stream.rb', line 67
def self.generate_model_row(unit)
shared_attributes = unit.keys & Katello::ModuleStream.column_names
to_return = unit.select { |key, _v| shared_attributes.include?(key) }
to_return['pulp_id'] = unit['pulp_href']
to_return['pulp_prn'] = unit['prn']
to_return[:created_at] = DateTime.now
to_return[:updated_at] = DateTime.now
to_return
end
|
.ids_for_repository(repo_id) ⇒ Object
11
12
13
14
15
|
# File 'app/services/katello/pulp3/module_stream.rb', line 11
def self.ids_for_repository(repo_id)
repo = Katello::Pulp3::Repository::Yum.new(Katello::Repository.find(repo_id), SmartProxy.pulp_primary)
repo_content_list = repo.content_list
repo_content_list.map { |content| content.try(:pulp_href) }
end
|
.insert_child_associations(units, pulp_id_to_id) ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'app/services/katello/pulp3/module_stream.rb', line 85
def self.insert_child_associations(units, pulp_id_to_id)
artifacts = []
profiles = []
stream_rpms = []
units.each do |unit|
katello_id = pulp_id_to_id[unit[unit_identifier]]
artifacts += build_artifacts(katello_id, unit['artifacts'])
profiles += build_profiles(katello_id, unit['profiles'])
stream_rpms += build_stream_rpms(katello_id, unit['packages'])
end
Katello::ModuleStreamArtifact.insert_all(artifacts, unique_by: [:module_stream_id, :name]) if artifacts.any?
Katello::ModuleProfile.insert_all(profiles, unique_by: [:module_stream_id, :name]) if profiles.any?
Katello::ModuleStreamRpm.insert_all(stream_rpms, unique_by: [:module_stream_id, :rpm_id]) if stream_rpms.any?
profile_rpms = []
units.each do |unit|
katello_id = pulp_id_to_id[unit[unit_identifier]]
profile_rpms += build_profile_rpms(katello_id, unit['profiles'])
end
Katello::ModuleProfileRpm.insert_all(profile_rpms, unique_by: [:module_profile_id, :name]) if profile_rpms.any?
end
|