masamune 0.13.4 → 0.13.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0b1cfbf2086afb91e515f3350cdefd9edc38b5c5
4
- data.tar.gz: 7fd27c38a43dbfaa2b4a75db79207c9da2d412ca
3
+ metadata.gz: 77626a3f01664f620bc080cac5edf5118d5ab70b
4
+ data.tar.gz: f32fca25218d4d6c8e990a0f2456ae8fa82c7b7b
5
5
  SHA512:
6
- metadata.gz: 665f24b4261a0e9f05367d031de278cf3561e9993b004339feafb0022da22d43ed54be8682b9706e9ffb420ec0ec72bc9167bb54cf3b2e3f68065b05db91dcdb
7
- data.tar.gz: 7ab3d42d09761b855abd75210d96c841709bba94bbe591c90844d3199328ffaa84f405708a9b7df198bd14a08c501e21f9fd0dff347f97f84478a63f7c47dc61
6
+ metadata.gz: 1010e89677ee57f4dc5b18fe5992f11233f24ada91eac3132eec0f5a288ac1bfb2981f2ce645603a2a63d4d1b01dc28d48163ba58cbab8832481d5004dbb633a
7
+ data.tar.gz: 0cdcf98d169c4b674d494098c25c00f8cec223a035f69936f103531527b24ea2872444daf5ac84ed8a9375795414c52cab6dfbb48eb419dbe816363df0e74194
@@ -32,7 +32,7 @@ module Masamune::Actions
32
32
 
33
33
  command = Masamune::Commands::Interactive.new(environment, :interactive => opts.fetch(:interactive, false))
34
34
  command = Masamune::Commands::ElasticMapReduce.new(command, opts)
35
- command = Masamune::Commands::RetryWithBackoff.new(command, opts)
35
+ command = Masamune::Commands::RetryWithBackoff.new(command, configuration.elastic_mapreduce.slice(:retries, :backoff).merge(opts))
36
36
  command = Masamune::Commands::Shell.new(command, opts)
37
37
 
38
38
  command.interactive? ? command.replace : command.execute
@@ -30,7 +30,7 @@ module Masamune::Actions
30
30
  opts.merge!(block: block.to_proc) if block_given?
31
31
 
32
32
  command = Masamune::Commands::HadoopFilesystem.new(environment, opts)
33
- command = Masamune::Commands::RetryWithBackoff.new(command, opts)
33
+ command = Masamune::Commands::RetryWithBackoff.new(command, configuration.hadoop_filesystem.slice(:retries, :backoff).merge(opts))
34
34
  command = Masamune::Commands::Shell.new(command, opts)
35
35
 
36
36
  command.execute
@@ -32,7 +32,7 @@ module Masamune::Actions
32
32
  end
33
33
 
34
34
  command = Masamune::Commands::ElasticMapReduce.new(command, opts.except(:extra)) if configuration.elastic_mapreduce[:jobflow]
35
- command = Masamune::Commands::RetryWithBackoff.new(command, opts)
35
+ command = Masamune::Commands::RetryWithBackoff.new(command, configuration.hadoop_streaming.slice(:retries, :backoff).merge(opts))
36
36
  command = Masamune::Commands::Shell.new(command, opts)
37
37
 
38
38
  command.execute
@@ -36,7 +36,7 @@ module Masamune::Actions
36
36
 
37
37
  command = Masamune::Commands::Hive.new(environment, opts)
38
38
  command = Masamune::Commands::ElasticMapReduce.new(command, opts.except(:extra)) if configuration.elastic_mapreduce[:jobflow]
39
- command = Masamune::Commands::RetryWithBackoff.new(command, opts)
39
+ command = Masamune::Commands::RetryWithBackoff.new(command, configuration.hive.slice(:retries, :backoff).merge(opts))
40
40
  command = Masamune::Commands::Shell.new(command, opts)
41
41
 
42
42
  command.interactive? ? command.replace : command.execute
@@ -36,6 +36,7 @@ module Masamune::Actions
36
36
  opts.merge!(block: block.to_proc) if block_given?
37
37
 
38
38
  command = Masamune::Commands::Postgres.new(environment, opts)
39
+ command = Masamune::Commands::RetryWithBackoff.new(command, configuration.postgres.slice(:retries, :backoff).merge(opts))
39
40
  command = Masamune::Commands::Shell.new(command, opts)
40
41
 
41
42
  command.interactive? ? command.replace : command.execute
@@ -50,14 +51,14 @@ module Masamune::Actions
50
51
  def load_postgres_setup_files
51
52
  configuration.postgres[:setup_files].each do |file|
52
53
  configuration.with_quiet do
53
- postgres(file: file)
54
+ postgres(file: file, retries: 0)
54
55
  end
55
56
  end if configuration.postgres.has_key?(:setup_files)
56
57
  end
57
58
 
58
59
  def load_postgres_schema
59
60
  transform = define_schema(catalog, :postgres)
60
- postgres(file: transform.to_file)
61
+ postgres(file: transform.to_file, retries: 0)
61
62
  rescue => e
62
63
  logger.error(e)
63
64
  logger.error("Could not load schema")
@@ -31,7 +31,7 @@ module Masamune::Actions
31
31
  opts.merge!(block: block.to_proc) if block_given?
32
32
 
33
33
  command = Masamune::Commands::S3Cmd.new(environment, opts)
34
- command = Masamune::Commands::RetryWithBackoff.new(command, opts)
34
+ command = Masamune::Commands::RetryWithBackoff.new(command, configuration.s3cmd.slice(:retries, :backoff).merge(opts))
35
35
  command = Masamune::Commands::Shell.new(command, opts)
36
36
 
37
37
  command.execute
@@ -39,7 +39,7 @@ module Masamune::Helpers
39
39
  end
40
40
 
41
41
  def database_exists?
42
- @database_exists ||= postgres(exec: 'SELECT version();', fail_fast: false).success?
42
+ @database_exists ||= postgres(exec: 'SELECT version();', fail_fast: false, retries: 0).success?
43
43
  end
44
44
 
45
45
  def table_exists?(table)
@@ -64,7 +64,7 @@ module Masamune::Helpers
64
64
 
65
65
  def update_tables
66
66
  return unless @cache.empty?
67
- postgres(exec: 'SELECT table_name FROM information_schema.tables;', tuple_output: true) do |line|
67
+ postgres(exec: 'SELECT table_name FROM information_schema.tables;', tuple_output: true, retries: 0) do |line|
68
68
  table = line.strip
69
69
  next if table =~ /\Apg_/
70
70
  @cache[table] ||= nil
@@ -73,7 +73,7 @@ module Masamune::Helpers
73
73
 
74
74
  def update_table_last_modified_at(table, column)
75
75
  return if @cache[table].present?
76
- postgres(exec: "SELECT MAX(#{column}) FROM #{table};", tuple_output: true) do |line|
76
+ postgres(exec: "SELECT MAX(#{column}) FROM #{table};", tuple_output: true, retries: 0) do |line|
77
77
  begin
78
78
  @cache[table] = Time.parse(line.strip).at_beginning_of_minute.utc
79
79
  rescue ArgumentError
@@ -38,9 +38,11 @@ module Masamune::Tasks
38
38
  method_option :exec, :aliases => '-e', :desc => 'SQL from command line'
39
39
  method_option :output, :aliases => '-o', :desc => 'Save SQL output to file'
40
40
  method_option :csv, :type => :boolean, :desc => 'Report SQL output in CSV format', :default => false
41
+ method_option :retry, :type => :boolean, :desc => 'Retry SQL query in event of failure', :default => false
41
42
  def psql_exec
42
43
  postgres_options = options.dup.with_indifferent_access
43
44
  postgres_options.merge!(print: true)
45
+ postgres_options.merge!(retries: 0) unless options[:retry]
44
46
  postgres(postgres_options)
45
47
  end
46
48
  default_task :psql_exec
@@ -23,8 +23,6 @@
23
23
  CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
24
24
  CREATE EXTENSION IF NOT EXISTS hstore;
25
25
 
26
- SET TIMEZONE TO 'UTC';
27
-
28
26
  CREATE OR REPLACE FUNCTION json_to_hstore(JSON)
29
27
  RETURNS HSTORE AS $$
30
28
  SELECT HSTORE(RTRIM(LTRIM(REPLACE($1::TEXT, ':', '=>'), '{'), '}'))
@@ -21,5 +21,5 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  module Masamune
24
- VERSION = '0.13.4'
24
+ VERSION = '0.13.5'
25
25
  end
@@ -48,6 +48,15 @@ describe Masamune::Actions::ElasticMapreduce do
48
48
  subject { instance.elastic_mapreduce }
49
49
 
50
50
  it { is_expected.to be_success }
51
+
52
+ context 'with retries and backoff' do
53
+ before do
54
+ allow(instance).to receive_message_chain(:configuration, :elastic_mapreduce).and_return(retries: 1, backoff: 10)
55
+ expect(Masamune::Commands::RetryWithBackoff).to receive(:new).with(anything, hash_including(retries: 1, backoff: 10)).once.and_call_original
56
+ end
57
+
58
+ it { is_expected.to be_success }
59
+ end
51
60
  end
52
61
 
53
62
  describe '.after_initialize' do
@@ -40,5 +40,14 @@ describe Masamune::Actions::HadoopFilesystem do
40
40
  subject { instance.hadoop_filesystem }
41
41
 
42
42
  it { is_expected.to be_success }
43
+
44
+ context 'with retries and backoff' do
45
+ before do
46
+ allow(instance).to receive_message_chain(:configuration, :hadoop_filesystem).and_return(retries: 1, backoff: 10)
47
+ expect(Masamune::Commands::RetryWithBackoff).to receive(:new).with(anything, hash_including(retries: 1, backoff: 10)).once.and_call_original
48
+ end
49
+
50
+ it { is_expected.to be_success }
51
+ end
43
52
  end
44
53
  end
@@ -39,6 +39,8 @@ describe Masamune::Actions::HadoopStreaming do
39
39
 
40
40
  describe '.hadoop_streaming' do
41
41
  before do
42
+ allow(instance).to receive_message_chain(:configuration, :hadoop_streaming).and_return({})
43
+ allow(instance).to receive_message_chain(:configuration, :elastic_mapreduce).and_return({})
42
44
  mock_command(/\Ahadoop/, mock_success)
43
45
  end
44
46
 
@@ -48,7 +50,7 @@ describe Masamune::Actions::HadoopStreaming do
48
50
 
49
51
  context 'with jobflow' do
50
52
  before do
51
- allow(instance).to receive_message_chain(:configuration, :elastic_mapreduce).and_return({jobflow: 'j-XYZ'})
53
+ allow(instance).to receive_message_chain(:configuration, :elastic_mapreduce).and_return(jobflow: 'j-XYZ')
52
54
  mock_command(/\Ahadoop/, mock_failure)
53
55
  mock_command(/\Aelastic-mapreduce/, mock_success, StringIO.new('ssh fakehost exit'))
54
56
  mock_command(/\Assh fakehost hadoop/, mock_success)
@@ -61,7 +63,7 @@ describe Masamune::Actions::HadoopStreaming do
61
63
  let(:extra) { ['-D', 'EXTRA'] }
62
64
 
63
65
  before do
64
- allow(instance).to receive_message_chain(:configuration, :elastic_mapreduce).and_return({jobflow: 'j-XYZ'})
66
+ allow(instance).to receive_message_chain(:configuration, :elastic_mapreduce).and_return(jobflow: 'j-XYZ')
65
67
  mock_command(/\Ahadoop/, mock_failure)
66
68
  mock_command(/\Aelastic-mapreduce/, mock_success, StringIO.new('ssh fakehost exit'))
67
69
  mock_command(/\Assh fakehost -D EXTRA hadoop/, mock_failure)
@@ -70,5 +72,14 @@ describe Masamune::Actions::HadoopStreaming do
70
72
 
71
73
  it { is_expected.to be_success }
72
74
  end
75
+
76
+ context 'with retries and backoff' do
77
+ before do
78
+ allow(instance).to receive_message_chain(:configuration, :hadoop_streaming).and_return(retries: 1, backoff: 10)
79
+ expect(Masamune::Commands::RetryWithBackoff).to receive(:new).with(anything, hash_including(retries: 1, backoff: 10)).once.and_call_original
80
+ end
81
+
82
+ it { is_expected.to be_success }
83
+ end
73
84
  end
74
85
  end
@@ -65,6 +65,15 @@ describe Masamune::Actions::Hive do
65
65
 
66
66
  it { is_expected.to be_success }
67
67
  end
68
+
69
+ context 'with retries and backoff' do
70
+ before do
71
+ allow(instance).to receive_message_chain(:configuration, :hive).and_return(retries: 1, backoff: 10)
72
+ expect(Masamune::Commands::RetryWithBackoff).to receive(:new).with(anything, hash_including(retries: 1, backoff: 10)).once.and_call_original
73
+ end
74
+
75
+ it { is_expected.to be_success }
76
+ end
68
77
  end
69
78
 
70
79
  describe '.after_initialize' do
@@ -55,6 +55,15 @@ describe Masamune::Actions::Postgres do
55
55
  subject { instance.postgres }
56
56
 
57
57
  it { is_expected.to be_success }
58
+
59
+ context 'with retries and backoff' do
60
+ before do
61
+ allow(instance).to receive_message_chain(:configuration, :postgres).and_return(retries: 1, backoff: 10)
62
+ expect(Masamune::Commands::RetryWithBackoff).to receive(:new).with(anything, hash_including(retries: 1, backoff: 10)).once.and_call_original
63
+ end
64
+
65
+ it { is_expected.to be_success }
66
+ end
58
67
  end
59
68
 
60
69
  describe '.after_initialize' do
@@ -81,7 +90,7 @@ describe Masamune::Actions::Postgres do
81
90
  before do
82
91
  expect(postgres_helper).to receive(:database_exists?).and_return(false)
83
92
  expect(instance).to receive(:postgres_admin).with(action: :create, database: 'test', safe: true).once
84
- expect(instance).to receive(:postgres).with(file: 'catalog.psql').once
93
+ expect(instance).to receive(:postgres).with(file: 'catalog.psql', retries: 0).once
85
94
  after_initialize_invoke
86
95
  end
87
96
  it 'should call posgres_admin once' do; end
@@ -91,7 +100,7 @@ describe Masamune::Actions::Postgres do
91
100
  before do
92
101
  expect(postgres_helper).to receive(:database_exists?).and_return(true)
93
102
  expect(instance).to receive(:postgres_admin).never
94
- expect(instance).to receive(:postgres).with(file: 'catalog.psql').once
103
+ expect(instance).to receive(:postgres).with(file: 'catalog.psql', retries: 0).once
95
104
  after_initialize_invoke
96
105
  end
97
106
  it 'should not call postgres_admin' do; end
@@ -101,8 +110,8 @@ describe Masamune::Actions::Postgres do
101
110
  let(:setup_files) { ['setup.psql'] }
102
111
  before do
103
112
  expect(postgres_helper).to receive(:database_exists?).and_return(true)
104
- expect(instance).to receive(:postgres).with(file: setup_files.first).once
105
- expect(instance).to receive(:postgres).with(file: 'catalog.psql').once
113
+ expect(instance).to receive(:postgres).with(file: setup_files.first, retries: 0).once
114
+ expect(instance).to receive(:postgres).with(file: 'catalog.psql', retries: 0).once
106
115
  after_initialize_invoke
107
116
  end
108
117
  it 'should call postgres with setup_files' do; end
@@ -124,7 +133,7 @@ describe Masamune::Actions::Postgres do
124
133
  before do
125
134
  filesystem.touch!('schema_1.psql', 'schema_2.psql')
126
135
  expect(postgres_helper).to receive(:database_exists?).and_return(true)
127
- expect(instance).to receive(:postgres).with(file: 'catalog.psql').once
136
+ expect(instance).to receive(:postgres).with(file: 'catalog.psql', retries: 0).once
128
137
  after_initialize_invoke
129
138
  end
130
139
  it 'should call postgres with schema_files' do; end
@@ -135,7 +144,7 @@ describe Masamune::Actions::Postgres do
135
144
  before do
136
145
  filesystem.touch!('schema.rb')
137
146
  expect(postgres_helper).to receive(:database_exists?).and_return(true)
138
- expect(instance).to receive(:postgres).with(file: 'catalog.psql').once
147
+ expect(instance).to receive(:postgres).with(file: 'catalog.psql', retries: 0).once
139
148
  after_initialize_invoke
140
149
  end
141
150
  it 'should call postgres with schema_files' do; end
@@ -40,5 +40,14 @@ describe Masamune::Actions::S3Cmd do
40
40
  subject { instance.s3cmd 'ls', 's3://fake-bucket' }
41
41
 
42
42
  it { is_expected.to be_success }
43
+
44
+ context 'with retries and backoff' do
45
+ before do
46
+ allow(instance).to receive_message_chain(:configuration, :s3cmd).and_return(retries: 1, backoff: 10)
47
+ expect(Masamune::Commands::RetryWithBackoff).to receive(:new).with(anything, hash_including(retries: 1, backoff: 10)).once.and_call_original
48
+ end
49
+
50
+ it { is_expected.to be_success }
51
+ end
43
52
  end
44
53
  end
@@ -26,10 +26,30 @@ describe Masamune::Helpers::Postgres do
26
26
  let(:environment) { double }
27
27
  let(:instance) { described_class.new(environment) }
28
28
 
29
+ describe '#database_exists' do
30
+ let(:mock_status) { }
31
+
32
+ before do
33
+ expect(instance).to receive(:postgres).with(hash_including(exec: 'SELECT version();', fail_fast: false, retries: 0)).and_return(mock_status)
34
+ end
35
+
36
+ subject { instance.database_exists? }
37
+
38
+ context 'when database exists' do
39
+ let(:mock_status) { mock_success }
40
+ it { is_expected.to eq(true) }
41
+ end
42
+
43
+ context 'when database does not exist' do
44
+ let(:mock_status) { mock_failure }
45
+ it { is_expected.to eq(false) }
46
+ end
47
+ end
48
+
29
49
  describe '#table_exists' do
30
50
  before do
31
51
  expect(instance).to receive(:database_exists?).and_return(true)
32
- expect(instance).to receive(:postgres).with(hash_including(:exec, :tuple_output)).and_yield(' foo').and_yield(' bar').and_yield(' baz')
52
+ expect(instance).to receive(:postgres).with(hash_including(exec: 'SELECT table_name FROM information_schema.tables;', tuple_output: true, retries: 0)).and_yield(' foo').and_yield(' bar').and_yield(' baz')
33
53
  end
34
54
 
35
55
  subject { instance.table_exists?(table) }
@@ -56,7 +76,7 @@ describe Masamune::Helpers::Postgres do
56
76
  context 'with last_modified_at option' do
57
77
  before do
58
78
  expect(instance).to receive(:table_exists?).and_return(true)
59
- expect(instance).to receive(:postgres).with(hash_including(:exec, :tuple_output)).and_yield(output)
79
+ expect(instance).to receive(:postgres).with(hash_including(exec: 'SELECT MAX(last_modified_at) FROM foo;', tuple_output: true, retries: 0)).and_yield(output)
60
80
  end
61
81
 
62
82
  let(:options) { { last_modified_at: 'last_modified_at' } }
@@ -34,6 +34,15 @@ describe Masamune::Tasks::HiveThor do
34
34
  it_behaves_like 'command usage'
35
35
  end
36
36
 
37
+ context 'without arguments' do
38
+ let(:options) { [] }
39
+
40
+ it do
41
+ expect_any_instance_of(described_class).to receive(:hive).with(hash_including(retries: 0)).once.and_return(mock_success)
42
+ cli_invocation
43
+ end
44
+ end
45
+
37
46
  context 'with --file and --initialize' do
38
47
  let(:options) { ['--file=zombo.hql', '--initialize'] }
39
48
  it do
@@ -75,4 +84,12 @@ describe Masamune::Tasks::HiveThor do
75
84
  cli_invocation
76
85
  end
77
86
  end
87
+
88
+ context 'with --retry' do
89
+ let(:options) { ['--retry'] }
90
+ it do
91
+ expect_any_instance_of(described_class).to receive(:hive).with(hash_excluding(retries: 0)).once.and_return(mock_success)
92
+ cli_invocation
93
+ end
94
+ end
78
95
  end
@@ -31,10 +31,19 @@ describe Masamune::Tasks::PostgresThor do
31
31
  it_behaves_like 'command usage'
32
32
  end
33
33
 
34
+ context 'without arguments' do
35
+ let(:options) { [] }
36
+
37
+ it do
38
+ expect_any_instance_of(described_class).to receive(:postgres).with(hash_including(retries: 0)).once.and_return(mock_success)
39
+ cli_invocation
40
+ end
41
+ end
42
+
34
43
  context 'with --file and --initialize' do
35
44
  let(:options) { ['--file=zombo.hql', '--initialize'] }
36
45
  it do
37
- expect_any_instance_of(described_class).to receive(:postgres).with(file: instance_of(String)).once.and_return(mock_success)
46
+ expect_any_instance_of(described_class).to receive(:postgres).with(file: instance_of(String), retries: 0).once.and_return(mock_success)
38
47
  expect_any_instance_of(described_class).to receive(:postgres).with(hash_including(file: 'zombo.hql')).once.and_return(mock_success)
39
48
  cli_invocation
40
49
  end
@@ -47,4 +56,12 @@ describe Masamune::Tasks::PostgresThor do
47
56
  cli_invocation
48
57
  end
49
58
  end
59
+
60
+ context 'with --retry' do
61
+ let(:options) { ['--retry'] }
62
+ it do
63
+ expect_any_instance_of(described_class).to receive(:postgres).with(hash_excluding(retries: 0)).once.and_return(mock_success)
64
+ cli_invocation
65
+ end
66
+ end
50
67
  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.13.4
4
+ version: 0.13.5
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-10-06 00:00:00.000000000 Z
11
+ date: 2015-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor