class RR::BaseRunner

This class implements the base functionality for runners that process table specs.

Constants

DEFAULT_OPTIONS

Default options if not overriden in command line

Attributes

options[RW]

Provided options. Possible values:

  • :config_file: path to config file

  • :table_specs: array of table specification strings

report_printer_arg[RW]

The specified option parameter for the report printer

report_printer_class[RW]

The class for the selected report printer

selected_progress_printer[RW]

Returns the command line selected ScanProgressPrinters class

session[W]

Public Class Methods

run(args) click to toggle source

Entry points for executing a processing run. args: the array of command line options that were provided by the user.

# File lib/rubyrep/base_runner.rb, line 182
def self.run(args)
  runner = new

  status = runner.process_options(args)
  if runner.options
    runner.execute
  end
  status
end

Public Instance Methods

add_specific_options(opts) click to toggle source

Intended to be overwritten by derived classes that need to add additional options to the provided OptionParser object.

# File lib/rubyrep/base_runner.rb, line 135
def add_specific_options(opts)
end
create_processor(left_table, right_table) click to toggle source

Creates a processor that does something with the given table. A processor needs to implement a run method that yields for progress reporting purposes pairs of diff_type and row as defined under RR::DirectTableScan#run.

# File lib/rubyrep/base_runner.rb, line 129
def create_processor(left_table, right_table)
  # not implemented in the base class
end
execute() click to toggle source

Executes a run based on the established options.

# File lib/rubyrep/base_runner.rb, line 165
def execute
  session.configuration.exclude_rubyrep_tables
  table_pairs.each do |table_pair|
    report_printer.scan table_pair[:left], table_pair[:right] do
      processor = create_processor              table_pair[:left], table_pair[:right]
      processor.progress_printer = progress_printer
      processor.run do |diff_type, row|
        report_printer.report_difference diff_type, row
      end
    end
  end
  signal_scanning_completion
end
prepare_table_pairs(table_pairs) click to toggle source

Intended to be overwritten by derived classes that need to modify the table_pairs.

Returns the new table pairs array.

# File lib/rubyrep/base_runner.rb, line 142
def prepare_table_pairs(table_pairs)
  table_pairs
end
process_options(args) click to toggle source

Parses the given command line parameter array. Returns the status (as per UNIX conventions: 1 if parameters were invalid, 0 otherwise)

# File lib/rubyrep/base_runner.rb, line 57
    def process_options(args)
      status = 0
      self.options = DEFAULT_OPTIONS.clone

      parser = OptionParser.new do |opts|
        opts.banner = <<EOS
Usage: #{$0} #{self.class.name.sub(/^.*::(.*)Runner$/, '\\1').downcase} [options] [table_spec] [table_spec] ...

  #{summary_description}

  table_spec can be either:
    * a specific table name (e. g. 'users') or
    * a pair of (specific) table names (e. g.: 'users,users_backup')
        (In this case the first table in the 'left' database is compared
         with the second table in the 'right' database.)
    * a regular expression (e. g. '/^user/') [case insensitive match]
  If no table_specs are provided via command line, the ones from the
  configuration file are used.
EOS
        opts.separator ""
        opts.separator "  Specific options:"

        ScanReportPrinters.on_printer_selection(opts) do |printer_class, arg|
          self.report_printer_class = printer_class
          self.report_printer_arg = arg
        end

        ScanProgressPrinters.on_printer_selection(opts) do |printer|
          self.selected_progress_printer = printer
        end

        opts.on("-c", "--config", "=CONFIG_FILE",
          "Mandatory. Path to configuration file.") do |arg|
          options[:config_file] = arg
        end
        
        add_specific_options(opts)

        opts.on_tail("--help", "Show this message") do
          $stderr.puts opts
          self.options = nil
        end
      end

      begin
        unprocessed_args = parser.parse!(args)
        if options # this will be +nil+ if the --help option is specified
          options[:table_specs] = unprocessed_args
          raise("Please specify configuration file") unless options.include?(:config_file)
        end
      rescue Exception => e
        $stderr.puts "Command line parsing failed: #{e}"
        $stderr.puts parser.help
        self.options = nil
        status = 1
      end

      return status
    end
progress_printer() click to toggle source

Returns the active ScanProgressPrinter class (as selected through the command line options OR if none was selected, the default one).

# File lib/rubyrep/base_runner.rb, line 41
def progress_printer
  if selected_progress_printer
    selected_progress_printer
  else
    printer_key = session.configuration.options[:scan_progress_printer]
    ScanProgressPrinters.printers[printer_key][:printer_class]
  end
end
report_printer() click to toggle source

Returns the active ScanReportPrinters instance (as selected through the command line options OR if none was selected, the default one).

# File lib/rubyrep/base_runner.rb, line 28
def report_printer
  unless @report_printer
    printer_class = report_printer_class || ScanReportPrinters::ScanSummaryReporter
    @report_printer ||= printer_class.new(session, report_printer_arg)
  end
  @report_printer
end
session() click to toggle source

Returns the active Session. Loads config file and creates session if necessary.

# File lib/rubyrep/base_runner.rb, line 148
def session
  unless @session
    load options[:config_file]
    @session = Session.new Initializer.configuration
  end
  @session
end
signal_scanning_completion() click to toggle source

Signals scan completion to the (active) scan report printer if it supports that method.

# File lib/rubyrep/base_runner.rb, line 119
def signal_scanning_completion
  if report_printer.respond_to? :scanning_finished
    report_printer.scanning_finished
  end
end
summary_description() click to toggle source

Returns the default command summary description (nothing). Should be overwritten by child classes.

# File lib/rubyrep/base_runner.rb, line 52
def summary_description; ""; end
table_pairs() click to toggle source

Returns the table pairs that should be processed. Refer to TableSpecRsolver#resolve for format of return value.

# File lib/rubyrep/base_runner.rb, line 160
def table_pairs
  prepare_table_pairs(session.configured_table_pairs(options[:table_specs]))
end