masamune 0.11.1 → 0.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/masamune/actions/elastic_mapreduce.rb +1 -0
- data/lib/masamune/actions/execute.rb +1 -1
- data/lib/masamune/actions/hive.rb +6 -3
- data/lib/masamune/actions/invoke_parallel.rb +1 -1
- data/lib/masamune/actions/postgres.rb +1 -0
- data/lib/masamune/thor.rb +1 -0
- data/lib/masamune/version.rb +1 -1
- data/spec/masamune/actions/elastic_mapreduce_spec.rb +13 -4
- data/spec/masamune/actions/hive_spec.rb +13 -4
- data/spec/masamune/actions/postgres_spec.rb +11 -1
- data/spec/masamune/tasks/hive_thor_spec.rb +29 -26
- data/spec/masamune/tasks/postgres_thor_spec.rb +9 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: dfbc2a3764c6ed9c4a5cb1b82bfa0f7ca22aac53
         | 
| 4 | 
            +
              data.tar.gz: fd95120e7e1a26b847af62c09ce7b0fdcc30b736
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 601caddfc1aadb966c05010a0f833cfc70051a965d60cda3c59ceacde696109536bf02c422695ee2ec0d159b74f55ceda83cc863d2b2a6c03ce4156010f07a25
         | 
| 7 | 
            +
              data.tar.gz: e35f201ff313c4a3d9a98a069ace3cc8ba2e1d425d93ae7ffbbda802fdca968a892b19ce078f2c03bf24ca1e1549b4fe456d30ba66a7dfe8a8f86c69627e66d7
         | 
| @@ -54,6 +54,7 @@ module Masamune::Actions | |
| 54 54 | 
             
                included do |base|
         | 
| 55 55 | 
             
                  base.class_option :jobflow, :aliases => '-j', :desc => 'Elastic MapReduce jobflow ID (Hint: elastic-mapreduce --list)' if defined?(base.class_option)
         | 
| 56 56 | 
             
                  base.after_initialize(:early) do |thor, options|
         | 
| 57 | 
            +
                    next unless options[:initialize]
         | 
| 57 58 | 
             
                    next if thor.configuration.elastic_mapreduce.empty?
         | 
| 58 59 | 
             
                    next unless thor.configuration.elastic_mapreduce.fetch(:enabled, true)
         | 
| 59 60 | 
             
                    jobflow = thor.resolve_jobflow(options[:jobflow] || thor.configuration.elastic_mapreduce[:jobflow])
         | 
| @@ -46,7 +46,7 @@ module Masamune::Actions | |
| 46 46 | 
             
                  end if block_given?
         | 
| 47 47 |  | 
| 48 48 | 
             
                  command = Masamune::Commands::Shell.new(klass.new(self), {fail_fast: false}.merge(opts))
         | 
| 49 | 
            -
                  opts.fetch(:interactive,  | 
| 49 | 
            +
                  opts.fetch(:interactive, false) ? command.replace(opts) : command.execute
         | 
| 50 50 | 
             
                end
         | 
| 51 51 | 
             
              end
         | 
| 52 52 | 
             
            end
         | 
| @@ -63,12 +63,15 @@ module Masamune::Actions | |
| 63 63 |  | 
| 64 64 | 
             
                included do |base|
         | 
| 65 65 | 
             
                  base.after_initialize do |thor, options|
         | 
| 66 | 
            +
                    next unless options[:initialize]
         | 
| 66 67 | 
             
                    thor.create_hive_database_if_not_exists
         | 
| 67 | 
            -
                    if options[:dry_run]
         | 
| 68 | 
            -
                      raise ::Thor::InvocationError, 'Dry run of hive failed' unless thor.hive(exec: 'SHOW TABLES;', safe: true, fail_fast: false).success?
         | 
| 69 | 
            -
                    end
         | 
| 70 68 | 
             
                    thor.load_hive_schema
         | 
| 71 69 | 
             
                  end if defined?(base.after_initialize)
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                  base.after_initialize(:later) do |thor, options|
         | 
| 72 | 
            +
                    next unless options[:dry_run]
         | 
| 73 | 
            +
                    raise ::Thor::InvocationError, 'Dry run of hive failed' unless thor.hive(exec: 'SHOW TABLES;', safe: true, fail_fast: false).success?
         | 
| 74 | 
            +
                  end if defined?(base.after_initialize)
         | 
| 72 75 | 
             
                end
         | 
| 73 76 | 
             
              end
         | 
| 74 77 | 
             
            end
         | 
| @@ -40,7 +40,7 @@ module Masamune::Actions | |
| 40 40 | 
             
                  bail_fast task_group, opts if opts[:version]
         | 
| 41 41 | 
             
                  Parallel.each(task_group, in_processes: max_tasks) do |task_name|
         | 
| 42 42 | 
             
                    begin
         | 
| 43 | 
            -
                      execute(thor_wrapper, task_name, *task_args(opts), interactive:  | 
| 43 | 
            +
                      execute(thor_wrapper, task_name, *task_args(opts), interactive: true, detach: false)
         | 
| 44 44 | 
             
                    rescue SystemExit
         | 
| 45 45 | 
             
                    end
         | 
| 46 46 | 
             
                  end
         | 
    
        data/lib/masamune/thor.rb
    CHANGED
    
    | @@ -101,6 +101,7 @@ module Masamune | |
| 101 101 | 
             
                    class_option :config, :desc => 'Configuration file'
         | 
| 102 102 | 
             
                    class_option :version, :desc => 'Print version and exit', :type => :boolean
         | 
| 103 103 | 
             
                    class_option :lock, :desc => 'Optional job lock name', :type => :string
         | 
| 104 | 
            +
                    class_option :initialize, :aliases => '--init', :desc => 'Initialize configured data stores', :type => :boolean, :default => false
         | 
| 104 105 | 
             
                    class_option :'--', :desc => 'Extra pass through arguments'
         | 
| 105 106 | 
             
                    def initialize(_args=[], _options={}, _config={})
         | 
| 106 107 | 
             
                      self.environment.parent = self
         | 
    
        data/lib/masamune/version.rb
    CHANGED
    
    
| @@ -51,7 +51,7 @@ describe Masamune::Actions::ElasticMapreduce do | |
| 51 51 | 
             
              end
         | 
| 52 52 |  | 
| 53 53 | 
             
              describe '.after_initialize' do
         | 
| 54 | 
            -
                let(:options) { {} }
         | 
| 54 | 
            +
                let(:options) { {initialize: true} }
         | 
| 55 55 |  | 
| 56 56 | 
             
                subject(:after_initialize_invoke) do
         | 
| 57 57 | 
             
                  instance.after_initialize_invoke(options)
         | 
| @@ -72,9 +72,18 @@ describe Masamune::Actions::ElasticMapreduce do | |
| 72 72 | 
             
                  it { expect { subject }.to raise_error Thor::RequiredArgumentMissingError, /No value provided for required options '--jobflow'/ }
         | 
| 73 73 | 
             
                end
         | 
| 74 74 |  | 
| 75 | 
            -
                context 'when jobflow  | 
| 75 | 
            +
                context 'when jobflow is present without initialize' do
         | 
| 76 76 | 
             
                  let(:configuration) { {enabled: true} }
         | 
| 77 77 | 
             
                  let(:options) { {jobflow: 'j-XYZ'} }
         | 
| 78 | 
            +
                  before do
         | 
| 79 | 
            +
                    expect(instance).to_not receive(:elastic_mapreduce)
         | 
| 80 | 
            +
                  end
         | 
| 81 | 
            +
                  it { expect { subject }.to_not raise_error }
         | 
| 82 | 
            +
                end
         | 
| 83 | 
            +
             | 
| 84 | 
            +
                context 'when jobflow does not exist' do
         | 
| 85 | 
            +
                  let(:configuration) { {enabled: true} }
         | 
| 86 | 
            +
                  let(:options) { {initialize: true, jobflow: 'j-XYZ'} }
         | 
| 78 87 | 
             
                  before do
         | 
| 79 88 | 
             
                    mock_command(/\Aelastic-mapreduce/, mock_failure)
         | 
| 80 89 | 
             
                  end
         | 
| @@ -83,7 +92,7 @@ describe Masamune::Actions::ElasticMapreduce do | |
| 83 92 |  | 
| 84 93 | 
             
                context 'when jobflow exists' do
         | 
| 85 94 | 
             
                  let(:configuration) { {enabled: true} }
         | 
| 86 | 
            -
                  let(:options) { {jobflow: 'j-XYZ'} }
         | 
| 95 | 
            +
                  let(:options) { {initialize: true, jobflow: 'j-XYZ'} }
         | 
| 87 96 | 
             
                  before do
         | 
| 88 97 | 
             
                    mock_command(/\Aelastic-mapreduce/, mock_success)
         | 
| 89 98 | 
             
                  end
         | 
| @@ -95,7 +104,7 @@ describe Masamune::Actions::ElasticMapreduce do | |
| 95 104 |  | 
| 96 105 | 
             
                context 'when jobflow is symbolic' do
         | 
| 97 106 | 
             
                  let(:configuration) { {enabled: true, jobflows: {'build' => 'j-XYZ'}} }
         | 
| 98 | 
            -
                  let(:options) { {jobflow: 'build', } }
         | 
| 107 | 
            +
                  let(:options) { {initialize: true, jobflow: 'build', } }
         | 
| 99 108 | 
             
                  before do
         | 
| 100 109 | 
             
                    mock_command(/\Aelastic-mapreduce/, mock_success)
         | 
| 101 110 | 
             
                  end
         | 
| @@ -68,13 +68,22 @@ describe Masamune::Actions::Hive do | |
| 68 68 | 
             
              end
         | 
| 69 69 |  | 
| 70 70 | 
             
              describe '.after_initialize' do
         | 
| 71 | 
            -
                let(:options) { {} }
         | 
| 71 | 
            +
                let(:options) { {initialize: true} }
         | 
| 72 72 | 
             
                let(:configuration) { {database: 'test'} }
         | 
| 73 73 |  | 
| 74 74 | 
             
                subject(:after_initialize_invoke) do
         | 
| 75 75 | 
             
                  instance.after_initialize_invoke(options)
         | 
| 76 76 | 
             
                end
         | 
| 77 77 |  | 
| 78 | 
            +
                context 'without --initialize' do
         | 
| 79 | 
            +
                  let(:options) { {} }
         | 
| 80 | 
            +
                  before do
         | 
| 81 | 
            +
                    expect(instance).to_not receive(:hive)
         | 
| 82 | 
            +
                    after_initialize_invoke
         | 
| 83 | 
            +
                  end
         | 
| 84 | 
            +
                  it 'should not call hive' do; end
         | 
| 85 | 
            +
                end
         | 
| 86 | 
            +
             | 
| 78 87 | 
             
                context 'with default database' do
         | 
| 79 88 | 
             
                  let(:configuration) { {database: 'default'} }
         | 
| 80 89 | 
             
                  before do
         | 
| @@ -103,12 +112,12 @@ describe Masamune::Actions::Hive do | |
| 103 112 | 
             
                  it 'should call hive with create database' do; end
         | 
| 104 113 | 
             
                end
         | 
| 105 114 |  | 
| 106 | 
            -
                context 'with  | 
| 107 | 
            -
                  let(:options) { {dry_run: true} }
         | 
| 115 | 
            +
                context 'with dry_run' do
         | 
| 116 | 
            +
                  let(:options) { {initialize: true, dry_run: true} }
         | 
| 108 117 | 
             
                  before do
         | 
| 109 118 | 
             
                    expect(instance).to receive(:hive).with(exec: 'CREATE DATABASE IF NOT EXISTS test;', :database => nil).once.and_return(mock_success)
         | 
| 110 | 
            -
                    expect(instance).to receive(:hive).with(exec: 'SHOW TABLES;', safe: true, fail_fast: false).once.and_return(mock_success)
         | 
| 111 119 | 
             
                    expect(instance).to receive(:hive).with(file: an_instance_of(String)).once.and_return(mock_success)
         | 
| 120 | 
            +
                    expect(instance).to receive(:hive).with(exec: 'SHOW TABLES;', safe: true, fail_fast: false).once.and_return(mock_success)
         | 
| 112 121 | 
             
                    after_initialize_invoke
         | 
| 113 122 | 
             
                  end
         | 
| 114 123 | 
             
                  it 'should call hive with show tables' do; end
         | 
| @@ -58,7 +58,7 @@ describe Masamune::Actions::Postgres do | |
| 58 58 | 
             
              end
         | 
| 59 59 |  | 
| 60 60 | 
             
              describe '.after_initialize' do
         | 
| 61 | 
            -
                let(:options) { {} }
         | 
| 61 | 
            +
                let(:options) { {initialize: true} }
         | 
| 62 62 | 
             
                let(:setup_files) { [] }
         | 
| 63 63 | 
             
                let(:schema_files) { [] }
         | 
| 64 64 | 
             
                let(:configuration) { {database: 'test', setup_files: setup_files, schema_files: schema_files} }
         | 
| @@ -67,6 +67,16 @@ describe Masamune::Actions::Postgres do | |
| 67 67 | 
             
                  instance.after_initialize_invoke(options)
         | 
| 68 68 | 
             
                end
         | 
| 69 69 |  | 
| 70 | 
            +
                context 'without --initialize' do
         | 
| 71 | 
            +
                  let(:options) { {} }
         | 
| 72 | 
            +
                  before do
         | 
| 73 | 
            +
                    expect(instance).to_not receive(:postgres_admin)
         | 
| 74 | 
            +
                    expect(instance).to_not receive(:postgres)
         | 
| 75 | 
            +
                    after_initialize_invoke
         | 
| 76 | 
            +
                  end
         | 
| 77 | 
            +
                  it 'should not call postgres_admin or postgres' do; end
         | 
| 78 | 
            +
                end
         | 
| 79 | 
            +
             | 
| 70 80 | 
             
                context 'when database does not exist' do
         | 
| 71 81 | 
             
                  before do
         | 
| 72 82 | 
             
                    expect(postgres_helper).to receive(:database_exists?).and_return(false)
         | 
| @@ -34,42 +34,45 @@ describe Masamune::Tasks::HiveThor do | |
| 34 34 | 
             
                it_behaves_like 'command usage'
         | 
| 35 35 | 
             
              end
         | 
| 36 36 |  | 
| 37 | 
            -
              context 'with  | 
| 38 | 
            -
                 | 
| 37 | 
            +
              context 'with --file and --initialize' do
         | 
| 38 | 
            +
                let(:options) { ['--file=zombo.hql', '--initialize'] }
         | 
| 39 | 
            +
                it do
         | 
| 39 40 | 
             
                  expect_any_instance_of(described_class).to receive(:hive).with(exec: 'CREATE DATABASE IF NOT EXISTS masamune;', database: nil).and_return(mock_success)
         | 
| 40 41 | 
             
                  expect_any_instance_of(described_class).to receive(:hive).with(file: instance_of(String)).and_return(mock_success)
         | 
| 42 | 
            +
                  expect_any_instance_of(described_class).to receive(:hive).with(hash_including(file: File.expand_path('zombo.hql'))).once.and_return(mock_success)
         | 
| 43 | 
            +
                  cli_invocation
         | 
| 41 44 | 
             
                end
         | 
| 45 | 
            +
              end
         | 
| 42 46 |  | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 | 
            -
             | 
| 47 | 
            -
             | 
| 48 | 
            -
                  end
         | 
| 47 | 
            +
              context 'with --file' do
         | 
| 48 | 
            +
                let(:options) { ['--file=zombo.hql'] }
         | 
| 49 | 
            +
                it do
         | 
| 50 | 
            +
                  expect_any_instance_of(described_class).to receive(:hive).with(hash_including(file: File.expand_path('zombo.hql'))).once.and_return(mock_success)
         | 
| 51 | 
            +
                  cli_invocation
         | 
| 49 52 | 
             
                end
         | 
| 53 | 
            +
              end
         | 
| 50 54 |  | 
| 51 | 
            -
             | 
| 52 | 
            -
             | 
| 53 | 
            -
             | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 56 | 
            -
                  end
         | 
| 55 | 
            +
              context 'with --output' do
         | 
| 56 | 
            +
                let(:options) { ['--output=report.txt'] }
         | 
| 57 | 
            +
                it do
         | 
| 58 | 
            +
                  expect_any_instance_of(described_class).to receive(:hive).with(hash_including(output: File.expand_path('report.txt'))).once.and_return(mock_success)
         | 
| 59 | 
            +
                  cli_invocation
         | 
| 57 60 | 
             
                end
         | 
| 61 | 
            +
              end
         | 
| 58 62 |  | 
| 59 | 
            -
             | 
| 60 | 
            -
             | 
| 61 | 
            -
             | 
| 62 | 
            -
             | 
| 63 | 
            -
             | 
| 64 | 
            -
                  end
         | 
| 63 | 
            +
              context 'with --variables=YEAR:2015 MONTH:1' do
         | 
| 64 | 
            +
                let(:options) { ['--variables=YEAR:2015', 'MONTH:1'] }
         | 
| 65 | 
            +
                it do
         | 
| 66 | 
            +
                  expect_any_instance_of(described_class).to receive(:hive).with(hash_including(variables: { 'YEAR' => '2015', 'MONTH' => '1'})).once.and_return(mock_success)
         | 
| 67 | 
            +
                  cli_invocation
         | 
| 65 68 | 
             
                end
         | 
| 69 | 
            +
              end
         | 
| 66 70 |  | 
| 67 | 
            -
             | 
| 68 | 
            -
             | 
| 69 | 
            -
             | 
| 70 | 
            -
             | 
| 71 | 
            -
             | 
| 72 | 
            -
                  end
         | 
| 71 | 
            +
              context 'with -X YEAR:2015 MONTH:1' do
         | 
| 72 | 
            +
                let(:options) { ['-X', 'YEAR:2015', 'MONTH:1'] }
         | 
| 73 | 
            +
                it do
         | 
| 74 | 
            +
                  expect_any_instance_of(described_class).to receive(:hive).with(hash_including(variables: { 'YEAR' => '2015', 'MONTH' => '1'})).once.and_return(mock_success)
         | 
| 75 | 
            +
                  cli_invocation
         | 
| 73 76 | 
             
                end
         | 
| 74 77 | 
             
              end
         | 
| 75 78 | 
             
            end
         | 
| @@ -31,10 +31,18 @@ describe Masamune::Tasks::PostgresThor do | |
| 31 31 | 
             
                it_behaves_like 'command usage'
         | 
| 32 32 | 
             
              end
         | 
| 33 33 |  | 
| 34 | 
            +
              context 'with --file and --initialize' do
         | 
| 35 | 
            +
                let(:options) { ['--file=zombo.hql', '--initialize'] }
         | 
| 36 | 
            +
                it do
         | 
| 37 | 
            +
                  expect_any_instance_of(described_class).to receive(:postgres).with(file: instance_of(String)).once.and_return(mock_success)
         | 
| 38 | 
            +
                  expect_any_instance_of(described_class).to receive(:postgres).with(hash_including(file: 'zombo.hql')).once.and_return(mock_success)
         | 
| 39 | 
            +
                  cli_invocation
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
              end
         | 
| 42 | 
            +
             | 
| 34 43 | 
             
              context 'with --file' do
         | 
| 35 44 | 
             
                let(:options) { ['--file=zombo.hql'] }
         | 
| 36 45 | 
             
                it do
         | 
| 37 | 
            -
                  expect_any_instance_of(described_class).to receive(:postgres).with(file: instance_of(String)).once.and_return(mock_success)
         | 
| 38 46 | 
             
                  expect_any_instance_of(described_class).to receive(:postgres).with(hash_including(file: 'zombo.hql')).once.and_return(mock_success)
         | 
| 39 47 | 
             
                  cli_invocation
         | 
| 40 48 | 
             
                end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: masamune
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.11. | 
| 4 | 
            +
              version: 0.11.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Michael Andrews
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2015-04- | 
| 11 | 
            +
            date: 2015-04-20 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: thor
         |