Class: Katello::Pulp3::Repository::Apt

Inherits:
Katello::Pulp3::Repository show all
Defined in:
app/services/katello/pulp3/repository/apt.rb

Constant Summary collapse

UNIT_LIMIT =
10_000
SIGNING_SERVICE_NAME =
'katello_deb_sign'.freeze

Constants inherited from Katello::Pulp3::Repository

COPY_UNIT_PAGE_SIZE

Instance Attribute Summary

Attributes inherited from Katello::Pulp3::Repository

#repo, #smart_proxy

Instance Method Summary collapse

Methods inherited from Katello::Pulp3::Repository

#add_content, #add_content_for_repo, #api, api, #append_proxy_cacert, #common_remote_options, #compute_remote_options, #content_service, #copy_all, #copy_units_by_href, #copy_version, #core_api, #create, #create_distribution, #create_mirror_entities, #create_options, #create_publication, #create_remote, #create_version, #delete_distributions, #delete_distributions_by_path, #delete_remote, #delete_repository, #delete_version, #distribution_needs_update?, #distribution_reference, #fail_missing_publication, #generate_backend_object_name, #get_distribution, #get_remote, #initialize, instance_for_type, #list, #lookup_distributions, #lookup_publication, #lookup_version, publication_href?, #published?, #read, #read_distribution, #refresh_distributions, #refresh_if_needed, #refresh_mirror_entities, #relative_path, #remote_partial_update, #remove_content, #repair, #repository_import_content, #repository_reference, #retain_package_versions_count, #save_distribution_references, #secure_distribution_options, #should_purge_empty_contents?, #skip_types, #specific_create_options, #ssl_remote_options, #sync, #unit_keys, #update, #update_distribution, #update_remote, version_href?, #version_zero?, #with_mirror_adapter

Methods included from ServiceCommon

#create_remote, #create_test_remote, #ignore_404_exception, #reformat_api_exception, #test_remote_name

Methods included from Util::HttpProxy

#proxy, #proxy_host, #proxy_port, #proxy_scheme, #proxy_uri

Constructor Details

This class inherits a constructor from Katello::Pulp3::Repository

Instance Method Details

#add_debs(source_repo_ids, filters, filter_list_map) ⇒ Object



196
197
198
199
200
201
202
203
204
# File 'app/services/katello/pulp3/repository/apt.rb', line 196

def add_debs(source_repo_ids, filters, filter_list_map)
  if (filter_list_map[:whitelist_ids].empty? && filters.select { |filter| filter.inclusion }.empty?)
    filter_list_map[:whitelist_ids] += source_repo_ids.collect do |source_repo_id|
      source_repo = ::Katello::Repository.find(source_repo_id)
      source_repo.debs.pluck(:pulp_id).sort
    end
  end
  filter_list_map
end

#add_filter_content(source_repo_ids, filters, filter_list_map) ⇒ Object



181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'app/services/katello/pulp3/repository/apt.rb', line 181

def add_filter_content(source_repo_ids, filters, filter_list_map)
  filters.each do |filter|
    if filter.inclusion
      source_repo_ids.each do |repo_id|
        filter_list_map[:whitelist_ids] += filter.content_unit_pulp_ids(::Katello::Repository.find(repo_id))
      end
    else
      source_repo_ids.each do |repo_id|
        filter_list_map[:blacklist_ids] += filter.content_unit_pulp_ids(::Katello::Repository.find(repo_id))
      end
    end
  end
  filter_list_map
end

#copy_api_data_dup(data) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/services/katello/pulp3/repository/apt.rb', line 102

def copy_api_data_dup(data)
  data_dup = PulpDebClient::Copy.new
  data_dup.dependency_solving = data.dependency_solving
  data_dup.config = []
  data.config.each do |repo_config|
    config_hash = {
      source_repo_version: repo_config[:source_repo_version],
      dest_repo: repo_config[:dest_repo],
      content: []
    }
    config_hash[:dest_base_version] = repo_config[:dest_base_version] if repo_config[:dest_base_version]
    data_dup.config << config_hash
  end
  data_dup
end

#copy_content_chunked(data) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'app/services/katello/pulp3/repository/apt.rb', line 118

def copy_content_chunked(data)
  tasks = []
  # Don't chunk if there aren't enough content units
  if data.config.sum { |repo_config| repo_config[:content].size } <= UNIT_LIMIT
    return api.copy_api.copy_content(data)
  end

  unit_copy_counter = 0
  i = 0
  leftover_units = data.config.first[:content].deep_dup

  # Copy data and clear its content fields
  data_dup = copy_api_data_dup(data)

  while i < data_dup.config.size
    # Copy all units within repo or only some?
    if leftover_units.length < UNIT_LIMIT - unit_copy_counter
      copy_amount = leftover_units.length
    else
      copy_amount = UNIT_LIMIT - unit_copy_counter
    end

    data_dup.config[i][:content] = leftover_units.pop(copy_amount)
    unit_copy_counter += copy_amount
    if unit_copy_counter != 0
      tasks << api.copy_api.copy_content(data_dup)
      unit_copy_counter = 0
    end

    if leftover_units.empty?
      # Nothing more to copy -- clear current config's content
      data_dup.config[i][:content] = []
      i += 1
      # Fetch unit list for next data config
      leftover_units = data.config[i][:content].deep_dup unless i == data_dup.config.size
    end
  end

  tasks
end

#copy_content_for_source(source_repository, options = {}) ⇒ Object



242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'app/services/katello/pulp3/repository/apt.rb', line 242

def copy_content_for_source(source_repository, options = {})
  # copy_units_by_href(source_repository.debs.pluck(:pulp_id))
  filters = ContentViewDebFilter.where(:id => options[:filter_ids])

  whitelist_ids = []
  blacklist_ids = []
  filters.each do |filter|
    if filter.inclusion
      whitelist_ids += filter.content_unit_pulp_ids(source_repository)
    else
      blacklist_ids += filter.content_unit_pulp_ids(source_repository)
    end
  end

  whitelist_ids = source_repository.debs.pluck(:pulp_id).sort if (whitelist_ids.empty? && filters.select { |filter| filter.inclusion }.empty?)

  content_unit_hrefs = whitelist_ids - blacklist_ids

  copy_units(content_unit_hrefs.uniq, options[:remove_all])
end

#copy_content_from_mapping(repo_id_map, options = {}) ⇒ Object



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'app/services/katello/pulp3/repository/apt.rb', line 206

def copy_content_from_mapping(repo_id_map, options = {})
  repo_id_map.each do |source_repo_ids, dest_repo_map|
    filters = ContentViewDebFilter.where(:id => options[:filter_ids])

    filter_list_map = { whitelist_ids: [], blacklist_ids: [] }
    filter_list_map = add_filter_content(source_repo_ids, filters, filter_list_map)
    filter_list_map = add_debs(source_repo_ids, filters, filter_list_map)

    whitelist_ids = filter_list_map[:whitelist_ids].flatten&.uniq
    blacklist_ids = filter_list_map[:blacklist_ids].flatten&.uniq
    content_unit_hrefs = whitelist_ids - blacklist_ids

    dest_repo_map[:content_unit_hrefs] = content_unit_hrefs.uniq.sort
  end

  dependency_solving = options[:solve_dependencies] || false

  multi_copy_units(repo_id_map, dependency_solving)
end

#copy_units(content_unit_hrefs, remove_all) ⇒ Object



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'app/services/katello/pulp3/repository/apt.rb', line 226

def copy_units(content_unit_hrefs, remove_all)
  remove_all = true if remove_all.nil?
  tasks = []

  if content_unit_hrefs.sort!.any?
    first_slice = remove_all
    content_unit_hrefs.each_slice(UNIT_LIMIT) do |slice|
      tasks << add_content(slice, first_slice)
      first_slice = false
    end
  else
    tasks << remove_all_content
  end
  tasks
end

#distribution_options(path) ⇒ Object



64
65
66
67
68
69
70
# File 'app/services/katello/pulp3/repository/apt.rb', line 64

def distribution_options(path)
  {
    base_path: path,
    publication: repo.publication_href,
    name: "#{generate_backend_object_name}"
  }
end

#mirror_publication_optionsObject



54
55
56
57
58
59
60
61
62
# File 'app/services/katello/pulp3/repository/apt.rb', line 54

def mirror_publication_options
  {
    # Since we are synchronizing the "default" distribution from the simple publisher on the server,
    # it will be included in the structured publish. Therefore, we MUST NOT use the simple publisher
    # on the proxy, since this would collide!
    #simple: true,
    structured: true # publish real suites (e.g. 'stable')
  }
end

#mirror_remote_optionsObject



33
34
35
36
37
38
39
# File 'app/services/katello/pulp3/repository/apt.rb', line 33

def mirror_remote_options
  super.merge(
    {
      distributions: repo.deb_releases + "#{' default' unless repo.deb_releases.include? 'default'}"
    }
  )
end

#multi_copy_units(repo_id_map, dependency_solving) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'app/services/katello/pulp3/repository/apt.rb', line 76

def multi_copy_units(repo_id_map, dependency_solving)
  tasks = []

  if repo_id_map.values.pluck(:content_unit_hrefs).flatten.any?
    data = PulpDebClient::Copy.new
    data.dependency_solving = dependency_solving
    data.config = []
    repo_id_map.each do |source_repo_ids, dest_repo_id_map|
      dest_repo = ::Katello::Repository.find(dest_repo_id_map[:dest_repo])
      dest_repo_href = ::Katello::Pulp3::Repository::Apt.new(dest_repo, SmartProxy.pulp_primary).repository_reference.repository_href
      content_unit_hrefs = dest_repo_id_map[:content_unit_hrefs]
      # Not needed during incremental update due to dest_base_version
      source_repo_ids.each do |source_repo_id|
        source_repo_version = ::Katello::Repository.find(source_repo_id).version_href
        config = { source_repo_version: source_repo_version, dest_repo: dest_repo_href, content: content_unit_hrefs }
        config[:dest_base_version] = dest_repo_id_map[:base_version] if dest_repo_id_map[:base_version]
        data.config << config
      end
    end
    tasks << copy_content_chunked(data)
  else
    tasks << remove_all_content_from_mapping(repo_id_map)
  end
  tasks.flatten
end

#partial_repo_pathObject



72
73
74
# File 'app/services/katello/pulp3/repository/apt.rb', line 72

def partial_repo_path
  "/pulp/deb/#{repo.relative_path}/".sub('//', '/')
end

#publication_options(repository_version) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/services/katello/pulp3/repository/apt.rb', line 41

def publication_options(repository_version)
  ss = api.signing_services_api.list(name: SIGNING_SERVICE_NAME).results
  popts = super(repository_version)
  popts.merge!(
    {
      structured: true, # publish real suites (e.g. 'stable')
      simple: true # publish all into 'default'-suite
    }
  )
  popts[:signing_service] = ss[0].pulp_href if ss && ss.length == 1
  popts
end

#regenerate_applicabilityObject



263
264
265
266
# File 'app/services/katello/pulp3/repository/apt.rb', line 263

def regenerate_applicability
  # TODO
  fail NotImplementedError
end

#remote_optionsObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/services/katello/pulp3/repository/apt.rb', line 10

def remote_options
  deb_remote_options = {
    policy: root.download_policy,
    distributions: root.deb_releases
  }
  deb_remote_options[:components] = root.deb_components.present? ? root.deb_components : nil
  deb_remote_options[:architectures] = root.deb_architectures.present? ? root.deb_architectures : nil

  if root.url.blank?
    deb_remote_options[:url] = nil
  end

  deb_remote_options[:gpgkey] = root.gpg_key.present? ? root.gpg_key.content : nil

  common_remote_options.merge(deb_remote_options)
end

#remove_all_contentObject



175
176
177
178
179
# File 'app/services/katello/pulp3/repository/apt.rb', line 175

def remove_all_content
  data = PulpDebClient::RepositoryAddRemoveContent.new(
    remove_content_units: ['*'])
  api.repositories_api.modify(repository_reference.repository_href, data)
end

#remove_all_content_from_mapping(repo_id_map) ⇒ Object



159
160
161
162
163
164
165
166
167
# File 'app/services/katello/pulp3/repository/apt.rb', line 159

def remove_all_content_from_mapping(repo_id_map)
  tasks = []
  repo_id_map.each do |_source_repo_ids, dest_repo_id_map|
    dest_repo = ::Katello::Repository.find(dest_repo_id_map[:dest_repo])
    dest_repo_href = ::Katello::Pulp3::Repository::Apt.new(dest_repo, SmartProxy.pulp_primary).repository_reference.repository_href
    tasks << remove_all_content_from_repo(dest_repo_href)
  end
  tasks
end

#remove_all_content_from_repo(repo_href) ⇒ Object



169
170
171
172
173
# File 'app/services/katello/pulp3/repository/apt.rb', line 169

def remove_all_content_from_repo(repo_href)
  data = PulpDebClient::RepositoryAddRemoveContent.new(
    remove_content_units: ['*'])
  api.repositories_api.modify(repo_href, data)
end

#sync_url_params(sync_options) ⇒ Object



27
28
29
30
31
# File 'app/services/katello/pulp3/repository/apt.rb', line 27

def sync_url_params(sync_options)
  params = super
  params[:optimize] = sync_options[:optimize] if sync_options.key?(:optimize)
  params
end