Module: Katello::Concerns::PulpDatabaseUnit::ClassMethods
- Defined in:
- app/models/katello/concerns/pulp_database_unit.rb
Instance Method Summary collapse
- #association_name ⇒ Object
- #backend_identifier_field ⇒ Object
- #content_type ⇒ Object
- #content_unit_association_id ⇒ Object
- #content_unit_class ⇒ Object
- #content_units_name ⇒ Object
- #copy_repository_associations(source_repo, dest_repo) ⇒ Object
- #db_columns_copy ⇒ Object
- #db_values_copy(source_repo, dest_repo) ⇒ Object
- #immutable_unit_types ⇒ Object
- #import_all(unit_ids, repository = nil, options = {}) ⇒ Object
- #import_for_repository(repo, options = {}) ⇒ Object
- #in_repositories(repos) ⇒ Object
- #installable_for_content_facet(facet, env = nil, content_view = nil) ⇒ Object
- #installable_for_hosts(hosts = nil) ⇒ Object
- #orphaned ⇒ Object
- #prn_identifier_field ⇒ Object
- #pulp_data(pulp_id) ⇒ Object
- #repository_association ⇒ Object
- #repository_association_class ⇒ Object
- #repository_association_class_name ⇒ Object
- #repository_association_units ⇒ Object
- #unit_id_field ⇒ Object
- #with_identifiers(ids) ⇒ Object
- #with_pulp_id(unit_pulp_ids) ⇒ Object
Instance Method Details
#association_name ⇒ Object
26 27 28 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 26 def association_name self.name.demodulize.underscore end |
#backend_identifier_field ⇒ Object
42 43 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 42 def backend_identifier_field end |
#content_type ⇒ Object
38 39 40 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 38 def content_type self::CONTENT_TYPE end |
#content_unit_association_id ⇒ Object
61 62 63 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 61 def content_unit_association_id "#{self.name.demodulize.underscore}_id".to_sym #Rpm => rpm_id end |
#content_unit_class ⇒ Object
49 50 51 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 49 def content_unit_class "::Katello::Pulp::#{self.name.demodulize}".constantize end |
#content_units_name ⇒ Object
69 70 71 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 69 def content_units_name self.name.demodulize.pluralize.underscore.to_sym end |
#copy_repository_associations(source_repo, dest_repo) ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 84 def copy_repository_associations(source_repo, dest_repo) delete_query = "delete from #{repository_association_class.table_name} where repository_id = #{dest_repo.id} and #{unit_id_field} not in (select #{unit_id_field} from #{repository_association_class.table_name} where repository_id = #{source_repo.id})" ActiveRecord::Base.transaction do ActiveRecord::Base.connection.execute(delete_query) self.repository_association_class.import(db_columns_copy, db_values_copy(source_repo, dest_repo), validate: false) end end |
#db_columns_copy ⇒ Object
93 94 95 96 97 98 99 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 93 def db_columns_copy columns = [unit_id_field] columns << backend_identifier_field if backend_identifier_field columns << :repository_id columns << prn_identifier_field if prn_identifier_field columns end |
#db_values_copy(source_repo, dest_repo) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 101 def db_values_copy(source_repo, dest_repo) db_values = [] existing_unit_ids = self.repository_association_class.where(repository: dest_repo).pluck(unit_id_field) if existing_unit_ids.empty? new_units = self.repository_association_class.where(repository: source_repo) else new_units = self.repository_association_class.where(repository: source_repo).where.not("#{unit_id_field} in (?) ", existing_unit_ids) end unit_backend_identifier_field = backend_identifier_field unit_identifier_field = unit_id_field unit_prn_field = prn_identifier_field new_units.each do |unit| values = [unit[unit_identifier_field]] values << unit[unit_backend_identifier_field] if unit_backend_identifier_field values << dest_repo.id values << unit[unit_prn_field] if unit_prn_field db_values << values end db_values end |
#immutable_unit_types ⇒ Object
57 58 59 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 57 def immutable_unit_types [Katello::Rpm, Katello::Srpm] end |
#import_all(unit_ids, repository = nil, options = {}) ⇒ Object
78 79 80 81 82 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 78 def import_all(unit_ids, repository = nil, = {}) content_type = [:content_type] || self.content_type filtered_indexing = [:filtered_indexing] || false Katello::ContentUnitIndexer.new(content_type: Katello::RepositoryTypeManager.find_content_type(content_type), repository: repository, pulp_content_ids: unit_ids).import_all(filtered_indexing) end |
#import_for_repository(repo, options = {}) ⇒ Object
73 74 75 76 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 73 def import_for_repository(repo, = {}) content_type = [:content_type] || self.content_type Katello::ContentUnitIndexer.new(content_type: Katello::RepositoryTypeManager.find_content_type(content_type), repository: repo).import_all end |
#in_repositories(repos) ⇒ Object
163 164 165 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 163 def in_repositories(repos) where(:id => repository_association_class.where(:repository_id => repos).select(unit_id_field)) end |
#installable_for_content_facet(facet, env = nil, content_view = nil) ⇒ Object
122 123 124 125 126 127 128 129 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 122 def installable_for_content_facet(facet, env = nil, content_view = nil) repos = if env && content_view Katello::Repository.in_environment(env).in_content_views([content_view]) else facet.bound_repositories.pluck(:id) end facet.send("applicable_#{content_units_name}".to_sym).in_repositories(repos) end |
#installable_for_hosts(hosts = nil) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 131 def installable_for_hosts(hosts = nil) # Main goal of this query # 1) Get me the applicable content units for these set of hosts # 2) Now further prune this list. Only include units from repos that have been "enabled" on those hosts. # In other words, prune the list to only include the units in the "bound" repositories signified by # the inner join between ContentFacetRepository and Repository<Unit> facet_repos = Katello::ContentFacetRepository.joins(:content_facet => :host).select(:repository_id) facet_content_units = content_facet_association_class.joins(:content_facet => :host).select(content_unit_association_id) if hosts hosts = ::Host.where(id: hosts) if hosts.is_a?(Array) facet_repos = facet_repos.where(hosts: { id: hosts }).reorder(nil) facet_content_units = facet_content_units.where(hosts: { id: hosts }).reorder(nil) end self.joins(repository_association_units). where(repository_association_class.table_name => { :repository_id => facet_repos, content_unit_association_id => facet_content_units }).distinct end |
#orphaned ⇒ Object
159 160 161 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 159 def orphaned left_joins(repository_association.to_sym).where("#{repository_association_class.table_name}.#{unit_id_field}" => nil) end |
#prn_identifier_field ⇒ Object
45 46 47 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 45 def prn_identifier_field self::PRN_IDENTIFIER_FIELD if self.const_defined?(:PRN_IDENTIFIER_FIELD) end |
#pulp_data(pulp_id) ⇒ Object
167 168 169 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 167 def pulp_data(pulp_id) content_unit_class.new(pulp_id) end |
#repository_association ⇒ Object
53 54 55 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 53 def repository_association repository_association_class_name.demodulize.pluralize.underscore end |
#repository_association_class ⇒ Object
34 35 36 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 34 def repository_association_class repository_association_class_name.constantize end |
#repository_association_class_name ⇒ Object
30 31 32 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 30 def repository_association_class_name "::Katello::Repository#{self.name.demodulize}" end |
#repository_association_units ⇒ Object
65 66 67 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 65 def repository_association_units repository_association_class.name.demodulize.pluralize.underscore.to_sym end |
#unit_id_field ⇒ Object
175 176 177 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 175 def unit_id_field "#{self.name.demodulize.underscore}_id" end |
#with_identifiers(ids) ⇒ Object
152 153 154 155 156 157 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 152 def with_identifiers(ids) ids = [ids] unless ids.is_a?(Array) ids.map!(&:to_s) id_integers = ids.map { |string| Integer(string) rescue -1 } where("#{self.table_name}.id in (?) or #{self.table_name}.pulp_id in (?)", id_integers, ids) end |
#with_pulp_id(unit_pulp_ids) ⇒ Object
171 172 173 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 171 def with_pulp_id(unit_pulp_ids) where('pulp_id in (?)', unit_pulp_ids) end |