Class: Bosh::Director::DeploymentPlan::PackageValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh/director/deployment_plan/package_validator.rb

Defined Under Namespace

Classes: Fault

Instance Method Summary collapse

Constructor Details

#initialize(logger) ⇒ PackageValidator

Returns a new instance of PackageValidator.



4
5
6
7
# File 'lib/bosh/director/deployment_plan/package_validator.rb', line 4

def initialize(logger)
  @faults = {}
  @logger = logger
end

Instance Method Details

#handle_faultsObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/bosh/director/deployment_plan/package_validator.rb', line 32

def handle_faults
  return if @faults.empty?

  msg = "\n"
  unique_stemcells = @faults.map { |_, faults| faults.map { |fault| fault.stemcell } }.flatten.to_set

  @faults.each do |release_desc, faults|
    if unique_stemcells.size > 1
      msg += message_for_multiple_stemcells(release_desc, faults)
    else
      msg += message_for_single_stemcell(release_desc, faults)
    end
  end

  raise PackageMissingSourceCode, msg
end

#validate(release_version_model, stemcell_model) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/bosh/director/deployment_plan/package_validator.rb', line 9

def validate(release_version_model, stemcell_model)
  release_desc = "#{release_version_model.release.name}/#{release_version_model.version}"

  @logger.debug("Validating packages for release '#{release_desc}'")
  release_version_model.packages.each do |package|
    packages_list = Bosh::Director::PackageDependenciesManager.new(release_version_model).transitive_dependencies(package)
    packages_list << package
    packages_list.each do |needed_package|
      if needed_package.sha1.nil? || needed_package.blobstore_id.nil?
        compiled_packages_list = Bosh::Director::Models::CompiledPackage.where(:package_id => needed_package.id,
          :stemcell_os => stemcell_model.operating_system).all
        compiled_packages_list = compiled_packages_list.select do |compiled_package|
          Bosh::Common::Version::StemcellVersion.match(compiled_package.stemcell_version, stemcell_model.version)
        end
        if compiled_packages_list.empty?
          @faults[release_desc] ||= Set.new
          @faults[release_desc] << Fault.new(needed_package, stemcell_model)
        end
      end
    end
  end
end