Sha256: 4312b72fac31d9d9f19a6c5cfae4c7f94048473d95bb39b472166d1fd0c552d8

Contents?: true

Size: 1.52 KB

Versions: 37

Compression:

Stored size: 1.52 KB

Contents

module Katello
  module Host
    class PackageProfileUploader
      def initialize(profile_string:, host: nil)
        @profile_string = profile_string
        @host = host
      end

      def upload
        profile = JSON.parse(@profile_string)
        #free the huge string from the memory
        @profile_string = 'TRIMMED'.freeze
        import_package_profile(profile)
      end

      def import_package_profile(profile)
        self.class.import_package_profile_for_host(@host&.id, profile)
      end

      def trigger_applicability_generation
        ::Katello::Host::ContentFacet.trigger_applicability_generation(@host&.id)
      end

      def self.import_package_profile_for_host(host_id, profile)
        host = ::Host.find_by(:id => host_id)
        if host.nil?
          Rails.logger.warn("Host with ID %s not found; continuing" % host_id)
        elsif host.content_facet.nil? || host.content_facet.uuid.nil?
          Rails.logger.warn("Host with ID %s has no content facet; continuing" % host_id)
        else
          begin
            simple_packages = profile.map { |item| ::Katello::SimplePackage.new(item) }
            host.import_package_profile(simple_packages)
          rescue ActiveRecord::InvalidForeignKey # this happens if the host gets deleted in between the "find_by" and "import_package_profile"
            Rails.logger.warn("Host installed package list with ID %s was not able to be written to the DB (host likely is deleted); continuing" % host_id)
          end
        end
      end
    end # of class
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
katello-4.14.2 app/services/katello/host/package_profile_uploader.rb
katello-4.15.0 app/services/katello/host/package_profile_uploader.rb
katello-4.15.0.rc2 app/services/katello/host/package_profile_uploader.rb
katello-4.15.0.rc1 app/services/katello/host/package_profile_uploader.rb
katello-4.14.1 app/services/katello/host/package_profile_uploader.rb
katello-4.14.0 app/services/katello/host/package_profile_uploader.rb
katello-4.14.0.rc3 app/services/katello/host/package_profile_uploader.rb
katello-4.14.0.rc2 app/services/katello/host/package_profile_uploader.rb
katello-4.14.0.rc1.1 app/services/katello/host/package_profile_uploader.rb
katello-4.14.0.rc1 app/services/katello/host/package_profile_uploader.rb
katello-4.13.1 app/services/katello/host/package_profile_uploader.rb
katello-4.13.0 app/services/katello/host/package_profile_uploader.rb
katello-4.12.1 app/services/katello/host/package_profile_uploader.rb
katello-4.13.0.rc1 app/services/katello/host/package_profile_uploader.rb
katello-4.12.0 app/services/katello/host/package_profile_uploader.rb
katello-4.12.0.rc3 app/services/katello/host/package_profile_uploader.rb
katello-4.12.0.rc2 app/services/katello/host/package_profile_uploader.rb
katello-4.12.0.rc1 app/services/katello/host/package_profile_uploader.rb
katello-4.11.1 app/services/katello/host/package_profile_uploader.rb
katello-4.11.0 app/services/katello/host/package_profile_uploader.rb