Class: Batali::Command::Resolve
- Inherits:
-
Batali::Command
- Object
- Bogo::Cli::Command
- Batali::Command
- Batali::Command::Resolve
- Defined in:
- lib/batali/command/resolve.rb
Overview
Resolve cookbooks
Constant Summary
Constants inherited from Batali::Command
Instance Method Summary collapse
-
#execute! ⇒ Object
Resolve dependencies and constraints.
-
#infrastructure_resolution(solv) ⇒ TrueClass
Generate manifest comprised of units for entire infrastructure.
- #score_keeper ⇒ ScoreKeeper
-
#single_path_resolution(solv) ⇒ TrueClass
Generate manifest comprised of units for single path resolution.
Methods inherited from Batali::Command
#batali_file, #cache_directory, #dry_run, #infrastructure?, #initialize, #manifest
Constructor Details
This class inherits a constructor from Batali::Command
Instance Method Details
#execute! ⇒ Object
Resolve dependencies and constraints. Output results to stdout and dump serialized manifest
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/batali/command/resolve.rb', line 11 def execute! system = Grimoire::System.new run_action 'Loading sources' do UnitLoader.new( :file => batali_file, :system => system, :cache => cache_directory(:git) ).populate! nil end requirements = Grimoire::RequirementList.new( :name => :batali_resolv, :requirements => batali_file.cookbook.map{ |ckbk| [ckbk.name, (ckbk.constraint.nil? || ckbk.constraint.empty? ? ['> 0'] : ckbk.constraint)] } ) solv = Grimoire::Solver.new( :requirements => requirements, :system => system, :score_keeper => score_keeper ) if(infrastructure?) infrastructure_resolution(solv) else single_path_resolution(solv) end end |
#infrastructure_resolution(solv) ⇒ TrueClass
Generate manifest comprised of units for entire infrastructure
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/batali/command/resolve.rb', line 120 def infrastructure_resolution(solv) ui.info 'Performing infrastructure path resolution.' if(manifest.infrastructure == false) ui.ask 'Current manifest is resolved single path. Convert to infrastructure?' end run_action 'Resolving dependency constraints' do solv.prune_world! nil end run_action 'Writing infrastructure manifest file' do File.open(manifest.path, 'w') do |file| manifest = Manifest.new( :cookbook => solv.world.units.values.flatten, :infrastructure => true ) file.write MultiJson.dump(manifest, :pretty => true) nil end end ui.info 'Infrastructure manifest solution:' solv.world.units.sort_by(&:first).each do |name, units| ui.puts "#{name} <#{units.map(&:version).sort.map(&:to_s).join(', ')}>" end end |
#score_keeper ⇒ ScoreKeeper
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/batali/command/resolve.rb', line 40 def score_keeper memoize(:score_keeper) do sk_manifest = Manifest.new(:cookbook => manifest.cookbook) unless(config[:least_impact]) sk_manifest.cookbook.clear end sk_manifest.cookbook.delete_if do |unit| arguments.include?(unit.name) end ScoreKeeper.new(:manifest => sk_manifest) end end |
#single_path_resolution(solv) ⇒ TrueClass
Generate manifest comprised of units for single path resolution
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/batali/command/resolve.rb', line 57 def single_path_resolution(solv) original_units = Smash[ [manifest.cookbook].flatten.compact.map do |unit| [unit.name, unit.version] end ] ui.info 'Performing single path resolution.' if(manifest.infrastructure) ui.confirm 'Current manifest is resolved for infrastucture. Convert to single path?' end results = [] run_action 'Resolving dependency constraints' do results = solv.generate! nil end if(results.empty?) ui.error 'No solutions found defined requirements!' else ideal_solution = results.pop dry_run('manifest file write') do run_action 'Writing manifest' do manifest = Manifest.new( :cookbook => ideal_solution.units, :infrastructure => false ) File.open('batali.manifest', 'w') do |file| file.write MultiJson.dump(manifest, :pretty => true) end nil end end # ui.info "Number of solutions collected for defined requirements: #{results.size + 1}" ui.info 'Ideal solution:' solution_units = Smash[ideal_solution.units.map{|unit| [unit.name, unit]}] manifest_units = Smash[manifest.cookbook.map{|unit| [unit.name, unit]}] (solution_units.keys + manifest_units.keys).compact.uniq.sort.each do |unit_name| if(manifest_units[unit_name]) if(solution_units[unit_name]) if(solution_units[unit_name].same?(manifest_units[unit_name])) ui.puts "#{unit_name} <#{solution_units[unit_name].version}>" else u_diff = manifest_units[unit_name].diff(solution_units[unit_name]) version_output = u_diff[:version] ? u_diff[:version].join(' -> ') : solution_units[unit_name].version u_diff.delete(:version) unless(u_diff.empty?) diff_output = "[#{u_diff.values.map{|v| v.join(' -> ')}.join(' | ')}]" end ui.puts ui.color("#{unit_name} <#{version_output}> #{diff_output}" , :yellow) end else ui.puts ui.color("#{unit_name} <#{manifest_units[unit_name].version}>", :red) end else ui.puts ui.color("#{unit_name} <#{solution_units[unit_name].version}>", :green) end end end end |