|
11 | 11 | require_relative 'version' |
12 | 12 |
|
13 | 13 | require 'logger' |
| 14 | +require 'parallel' |
14 | 15 | require 'socket' |
15 | 16 |
|
16 | 17 | module OctocatalogDiff |
@@ -116,16 +117,46 @@ def self.cli(argv = ARGV, logger = Logger.new(STDERR), opts = {}) |
116 | 117 | end |
117 | 118 |
|
118 | 119 | # Compile catalogs and do catalog-diff |
119 | | - catalog_diff = OctocatalogDiff::API::V1.catalog_diff(options.merge(logger: logger)) |
| 120 | + node_set = options.delete(:node) |
| 121 | + node_set = [node_set] unless node_set.is_a?(Array) |
| 122 | + |
| 123 | + # run multiple node diffs in parallel |
| 124 | + catalog_diffs = if node_set.size == 1 |
| 125 | + [run_octocatalog_diff(node_set.first, options, logger)] |
| 126 | + else |
| 127 | + ::Parallel.map(node_set, in_threads: 4) { |node| run_octocatalog_diff(node, options, logger) } |
| 128 | + end |
| 129 | + |
| 130 | + # Return the resulting diff object if requested (generally for testing) |
| 131 | + # or otherwise return exit code |
| 132 | + return catalog_diffs.first if opts[:INTEGRATION] |
| 133 | + |
| 134 | + all_diffs = catalog_diffs.map(&:diffs) |
| 135 | + |
| 136 | + all_diffs.each do |diff| |
| 137 | + next unless diff.any? |
| 138 | + return EXITCODE_SUCCESS_WITH_DIFFS |
| 139 | + end |
| 140 | + |
| 141 | + EXITCODE_SUCCESS_NO_DIFFS |
| 142 | + end |
| 143 | + |
| 144 | + # Run the octocatalog-diff process for a given node. Return the diffs for a contribution to |
| 145 | + # the final exit status. |
| 146 | + # node - String with the node |
| 147 | + # options - All of the currently defined options |
| 148 | + # logger - Logger object |
| 149 | + def self.run_octocatalog_diff(node, options, logger) |
| 150 | + options_copy = options.merge(node: node) |
| 151 | + catalog_diff = OctocatalogDiff::API::V1.catalog_diff(options_copy.merge(logger: logger)) |
120 | 152 | diffs = catalog_diff.diffs |
121 | 153 |
|
122 | 154 | # Display diffs |
123 | | - printer_obj = OctocatalogDiff::Cli::Printer.new(options, logger) |
| 155 | + printer_obj = OctocatalogDiff::Cli::Printer.new(options_copy, logger) |
124 | 156 | printer_obj.printer(diffs, catalog_diff.from.compilation_dir, catalog_diff.to.compilation_dir) |
125 | 157 |
|
126 | | - # Return the resulting diff object if requested (generally for testing) or otherwise return exit code |
127 | | - return catalog_diff if opts[:INTEGRATION] |
128 | | - diffs.any? ? EXITCODE_SUCCESS_WITH_DIFFS : EXITCODE_SUCCESS_NO_DIFFS |
| 158 | + # Return catalog-diff object. |
| 159 | + catalog_diff |
129 | 160 | end |
130 | 161 |
|
131 | 162 | # Parse command line options with 'optparse'. Returns a hash with the parsed arguments. |
|
0 commit comments