masamune 0.18.1 → 0.18.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/masamune/actions/invoke_parallel.rb +11 -7
- data/lib/masamune/version.rb +1 -1
- data/spec/masamune/actions/aws_emr_spec.rb +15 -4
- data/spec/masamune/actions/hadoop_filesystem_spec.rb +15 -4
- data/spec/masamune/actions/hadoop_streaming_spec.rb +20 -9
- data/spec/masamune/actions/hive_spec.rb +15 -5
- data/spec/masamune/actions/invoke_parallel_spec.rb +43 -2
- data/spec/masamune/actions/postgres_admin_spec.rb +2 -2
- data/spec/masamune/actions/postgres_spec.rb +15 -4
- data/spec/masamune/actions/transform_spec.rb +7 -7
- data/spec/support/masamune/mock_command.rb +12 -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: fb31759e76d58c026aeee2bcf241611e9821da4f
|
4
|
+
data.tar.gz: fb82f3c5215527397b742bd0b8108f9f8d58b4c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8c29df50f07a4d7bbc56b66940bbb1b4352ad8d2489740741cabe056803d196375c75c217d28be4d0feabf257f3a1f84788594163467b36885ae6565aa4e1b2
|
7
|
+
data.tar.gz: 4e0b4decd60fe42953ccd0ac92c7c4077137e4c85db42e238893e769b86c5f159a94f505b13cc0bc681a20d0b819562afb9c121e6f435e06e9010667c51b9c7b
|
@@ -35,13 +35,16 @@ module Masamune::Actions
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def invoke_parallel(*task_group)
|
38
|
-
|
39
|
-
|
38
|
+
per_task_opts = task_group.last.is_a?(Array) ? task_group.pop : [{}]
|
39
|
+
all_task_opts = task_group.last.is_a?(Hash) ? task_group.pop : {}
|
40
|
+
max_tasks = [all_task_opts.delete(:max_tasks), task_group.count].min
|
40
41
|
console("Setting max_tasks to #{max_tasks}")
|
41
|
-
bail_fast task_group,
|
42
|
-
|
42
|
+
bail_fast task_group, all_task_opts if all_task_opts[:version]
|
43
|
+
task_group_by_task_opts = task_group.product(per_task_opts)
|
44
|
+
Parallel.each(task_group_by_task_opts, in_processes: max_tasks) do |task_name, task_opts|
|
45
|
+
task_env = task_opts[:env] || {}
|
43
46
|
begin
|
44
|
-
execute(thor_wrapper, task_name, *task_args(
|
47
|
+
execute(thor_wrapper, task_name, *task_args(all_task_opts.merge(task_opts)), interactive: true, detach: false, env: task_env)
|
45
48
|
rescue SystemExit # rubocop:disable Lint/HandleExceptions
|
46
49
|
end
|
47
50
|
end
|
@@ -55,12 +58,13 @@ module Masamune::Actions
|
|
55
58
|
|
56
59
|
def bail_fast(task_group, opts = {})
|
57
60
|
task_name = task_group.first
|
58
|
-
|
61
|
+
task_env = task_opts[:env] || {}
|
62
|
+
execute($PROGRAM_NAME, task_name, *task_args(opts), env: task_env)
|
59
63
|
exit
|
60
64
|
end
|
61
65
|
|
62
66
|
def task_args(opts = {})
|
63
|
-
opts.map do |k, v|
|
67
|
+
opts.except(:env).map do |k, v|
|
64
68
|
case v
|
65
69
|
when true
|
66
70
|
"--#{k.to_s.tr('_', '-')}"
|
data/lib/masamune/version.rb
CHANGED
@@ -37,18 +37,29 @@ describe Masamune::Actions::AwsEmr do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
describe '.aws_emr' do
|
40
|
-
|
41
|
-
|
40
|
+
subject(:action) { instance.aws_emr }
|
41
|
+
|
42
|
+
context 'when success' do
|
43
|
+
before do
|
44
|
+
mock_command(/\Aaws emr/, mock_success)
|
45
|
+
end
|
46
|
+
|
47
|
+
it { is_expected.to be_success }
|
42
48
|
end
|
43
49
|
|
44
|
-
|
50
|
+
context 'when failure' do
|
51
|
+
before do
|
52
|
+
mock_command(/\Aaws emr/, mock_failure)
|
53
|
+
end
|
45
54
|
|
46
|
-
|
55
|
+
it { expect { action }.to raise_error RuntimeError, 'fail_fast: aws emr ssh' }
|
56
|
+
end
|
47
57
|
|
48
58
|
context 'with retries and backoff' do
|
49
59
|
before do
|
50
60
|
allow(instance).to receive_message_chain(:configuration, :commands, :aws_emr).and_return(retries: 1, backoff: 10)
|
51
61
|
expect(Masamune::Commands::RetryWithBackoff).to receive(:new).with(anything, hash_including(retries: 1, backoff: 10)).once.and_call_original
|
62
|
+
mock_command(/\Aaws emr/, mock_success)
|
52
63
|
end
|
53
64
|
|
54
65
|
it { is_expected.to be_success }
|
@@ -31,18 +31,29 @@ describe Masamune::Actions::HadoopFilesystem do
|
|
31
31
|
let(:instance) { klass.new }
|
32
32
|
|
33
33
|
describe '.hadoop_filesystem' do
|
34
|
-
|
35
|
-
|
34
|
+
subject(:action) { instance.hadoop_filesystem }
|
35
|
+
|
36
|
+
context 'when success' do
|
37
|
+
before do
|
38
|
+
mock_command(/\Ahadoop/, mock_success)
|
39
|
+
end
|
40
|
+
|
41
|
+
it { is_expected.to be_success }
|
36
42
|
end
|
37
43
|
|
38
|
-
|
44
|
+
context 'when failure' do
|
45
|
+
before do
|
46
|
+
mock_command(/\Ahadoop/, mock_failure)
|
47
|
+
end
|
39
48
|
|
40
|
-
|
49
|
+
it { is_expected.not_to be_success }
|
50
|
+
end
|
41
51
|
|
42
52
|
context 'with retries and backoff' do
|
43
53
|
before do
|
44
54
|
allow(instance).to receive_message_chain(:configuration, :commands, :hadoop_filesystem).and_return(retries: 1, backoff: 10)
|
45
55
|
expect(Masamune::Commands::RetryWithBackoff).to receive(:new).with(anything, hash_including(retries: 1, backoff: 10)).once.and_call_original
|
56
|
+
mock_command(/\Ahadoop/, mock_success)
|
46
57
|
end
|
47
58
|
|
48
59
|
it { is_expected.to be_success }
|
@@ -31,21 +31,33 @@ describe Masamune::Actions::HadoopStreaming do
|
|
31
31
|
let(:extra) { [] }
|
32
32
|
let(:instance) { klass.new }
|
33
33
|
|
34
|
+
before do
|
35
|
+
allow(instance).to receive_message_chain(:configuration, :commands, :hadoop_streaming).and_return({})
|
36
|
+
allow(instance).to receive_message_chain(:configuration, :commands, :aws_emr).and_return({})
|
37
|
+
end
|
38
|
+
|
34
39
|
describe '.hadoop_streaming' do
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
40
|
+
subject(:action) { instance.hadoop_streaming(extra: extra) }
|
41
|
+
|
42
|
+
context 'when success' do
|
43
|
+
before do
|
44
|
+
mock_command(/\Ahadoop/, mock_success)
|
45
|
+
end
|
46
|
+
|
47
|
+
it { is_expected.to be_success }
|
39
48
|
end
|
40
49
|
|
41
|
-
|
50
|
+
context 'when failure' do
|
51
|
+
before do
|
52
|
+
mock_command(/\Ahadoop/, mock_failure)
|
53
|
+
end
|
42
54
|
|
43
|
-
|
55
|
+
it { expect { action }.to raise_error RuntimeError, /\Afail_fast: hadoop/ }
|
56
|
+
end
|
44
57
|
|
45
58
|
context 'with cluster_id' do
|
46
59
|
before do
|
47
60
|
allow(instance).to receive_message_chain(:configuration, :commands, :aws_emr).and_return(cluster_id: 'j-XYZ')
|
48
|
-
mock_command(/\Ahadoop/, mock_failure)
|
49
61
|
mock_command(/\Aaws emr/, mock_success, StringIO.new('ssh fakehost exit'))
|
50
62
|
mock_command(/\Assh fakehost hadoop/, mock_success)
|
51
63
|
end
|
@@ -58,9 +70,7 @@ describe Masamune::Actions::HadoopStreaming do
|
|
58
70
|
|
59
71
|
before do
|
60
72
|
allow(instance).to receive_message_chain(:configuration, :commands, :aws_emr).and_return(cluster_id: 'j-XYZ')
|
61
|
-
mock_command(/\Ahadoop/, mock_failure)
|
62
73
|
mock_command(/\Aaws emr/, mock_success, StringIO.new('ssh fakehost exit'))
|
63
|
-
mock_command(/\Assh fakehost -D EXTRA hadoop/, mock_failure)
|
64
74
|
mock_command(/\Assh fakehost hadoop .*? -D EXTRA/, mock_success)
|
65
75
|
end
|
66
76
|
|
@@ -71,6 +81,7 @@ describe Masamune::Actions::HadoopStreaming do
|
|
71
81
|
before do
|
72
82
|
allow(instance).to receive_message_chain(:configuration, :commands, :hadoop_streaming).and_return(retries: 1, backoff: 10)
|
73
83
|
expect(Masamune::Commands::RetryWithBackoff).to receive(:new).with(anything, hash_including(retries: 1, backoff: 10)).once.and_call_original
|
84
|
+
mock_command(/\Ahadoop/, mock_success)
|
74
85
|
end
|
75
86
|
|
76
87
|
it { is_expected.to be_success }
|
@@ -43,18 +43,27 @@ describe Masamune::Actions::Hive do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
describe '.hive' do
|
46
|
-
|
47
|
-
|
46
|
+
subject(:action) { instance.hive }
|
47
|
+
|
48
|
+
context 'when success' do
|
49
|
+
before do
|
50
|
+
mock_command(/\Ahive/, mock_success)
|
51
|
+
end
|
52
|
+
|
53
|
+
it { is_expected.to be_success }
|
48
54
|
end
|
49
55
|
|
50
|
-
|
56
|
+
context 'when failure' do
|
57
|
+
before do
|
58
|
+
mock_command(/\Ahive/, mock_failure)
|
59
|
+
end
|
51
60
|
|
52
|
-
|
61
|
+
it { is_expected.not_to be_success }
|
62
|
+
end
|
53
63
|
|
54
64
|
context 'with cluster_id' do
|
55
65
|
before do
|
56
66
|
allow(instance).to receive_message_chain(:configuration, :commands, :aws_emr).and_return(cluster_id: 'j-XYZ')
|
57
|
-
mock_command(/\Ahive/, mock_failure)
|
58
67
|
mock_command(/\Aaws emr/, mock_success, StringIO.new('ssh fakehost exit'))
|
59
68
|
mock_command(/\Assh fakehost hive/, mock_success)
|
60
69
|
end
|
@@ -68,6 +77,7 @@ describe Masamune::Actions::Hive do
|
|
68
77
|
before do
|
69
78
|
allow(instance).to receive_message_chain(:configuration, :commands, :hive).and_return(retries: 1, backoff: 10)
|
70
79
|
expect(Masamune::Commands::RetryWithBackoff).to receive(:new).with(anything, hash_including(retries: 1, backoff: 10)).once.and_call_original
|
80
|
+
mock_command(/\Ahive/, mock_success)
|
71
81
|
end
|
72
82
|
|
73
83
|
it { is_expected.to be_success }
|
@@ -31,13 +31,54 @@ describe Masamune::Actions::InvokeParallel do
|
|
31
31
|
let(:instance) { klass.new }
|
32
32
|
|
33
33
|
describe '.invoke_parallel' do
|
34
|
-
context 'with a
|
34
|
+
context 'with a single thor command' do
|
35
35
|
before do
|
36
36
|
mock_command(/\Athor list/, mock_success)
|
37
37
|
end
|
38
38
|
|
39
39
|
subject do
|
40
|
-
instance.invoke_parallel('list', max_tasks:
|
40
|
+
instance.invoke_parallel('list', max_tasks: 0)
|
41
|
+
end
|
42
|
+
|
43
|
+
it { expect { subject }.to_not raise_error }
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'with a single thor command and multiple arguments' do
|
47
|
+
before do
|
48
|
+
mock_command(/\Athor list --a/, mock_success)
|
49
|
+
mock_command(/\Athor list --b/, mock_success)
|
50
|
+
end
|
51
|
+
|
52
|
+
subject do
|
53
|
+
instance.invoke_parallel('list', { max_tasks: 0 }, [{ a: true, b: false }, { a: false, b: true }])
|
54
|
+
end
|
55
|
+
|
56
|
+
it { expect { subject }.to_not raise_error }
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'with a single thor command and multiple environments' do
|
60
|
+
before do
|
61
|
+
mock_command(/\AMASAMUNE_ENV=test_1 thor list/, mock_success)
|
62
|
+
mock_command(/\AMASAMUNE_ENV=test_2 thor list/, mock_success)
|
63
|
+
end
|
64
|
+
|
65
|
+
subject do
|
66
|
+
instance.invoke_parallel('list', { max_tasks: 0 }, [{ env: { 'MASAMUNE_ENV' => 'test_1' } }, { env: { 'MASAMUNE_ENV' => 'test_2' } }])
|
67
|
+
end
|
68
|
+
|
69
|
+
it { expect { subject }.to_not raise_error }
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'with a multiple thor command and multiple environments' do
|
73
|
+
before do
|
74
|
+
mock_command(/\AMASAMUNE_ENV=test_1 thor list/, mock_success)
|
75
|
+
mock_command(/\AMASAMUNE_ENV=test_2 thor list/, mock_success)
|
76
|
+
mock_command(/\AMASAMUNE_ENV=test_1 thor help/, mock_success)
|
77
|
+
mock_command(/\AMASAMUNE_ENV=test_2 thor help/, mock_success)
|
78
|
+
end
|
79
|
+
|
80
|
+
subject do
|
81
|
+
instance.invoke_parallel('list', 'help', { max_tasks: 0 }, [{ env: { 'MASAMUNE_ENV' => 'test_1' } }, { env: { 'MASAMUNE_ENV' => 'test_2' } }])
|
41
82
|
end
|
42
83
|
|
43
84
|
it { expect { subject }.to_not raise_error }
|
@@ -37,7 +37,7 @@ describe Masamune::Actions::PostgresAdmin do
|
|
37
37
|
let(:action) { :create }
|
38
38
|
|
39
39
|
before do
|
40
|
-
mock_command(/\
|
40
|
+
mock_command(/\APGOPTIONS=.* createdb/, mock_success)
|
41
41
|
end
|
42
42
|
|
43
43
|
it { is_expected.to be_success }
|
@@ -47,7 +47,7 @@ describe Masamune::Actions::PostgresAdmin do
|
|
47
47
|
let(:action) { :drop }
|
48
48
|
|
49
49
|
before do
|
50
|
-
mock_command(/\
|
50
|
+
mock_command(/\APGOPTIONS=.* dropdb/, mock_success)
|
51
51
|
end
|
52
52
|
|
53
53
|
it { is_expected.to be_success }
|
@@ -46,18 +46,29 @@ describe Masamune::Actions::Postgres do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
describe '.postgres' do
|
49
|
-
|
50
|
-
|
49
|
+
subject(:action) { instance.postgres }
|
50
|
+
|
51
|
+
context 'when success' do
|
52
|
+
before do
|
53
|
+
mock_command(/\APGOPTIONS=.* psql/, mock_success)
|
54
|
+
end
|
55
|
+
|
56
|
+
it { is_expected.to be_success }
|
51
57
|
end
|
52
58
|
|
53
|
-
|
59
|
+
context 'when failure' do
|
60
|
+
before do
|
61
|
+
mock_command(/\APGOPTIONS=.* psql/, mock_failure)
|
62
|
+
end
|
54
63
|
|
55
|
-
|
64
|
+
it { is_expected.not_to be_success }
|
65
|
+
end
|
56
66
|
|
57
67
|
context 'with retries and backoff' do
|
58
68
|
before do
|
59
69
|
allow(instance).to receive_message_chain(:configuration, :commands, :postgres).and_return(retries: 1, backoff: 10)
|
60
70
|
expect(Masamune::Commands::RetryWithBackoff).to receive(:new).with(anything, hash_including(retries: 1, backoff: 10)).once.and_call_original
|
71
|
+
mock_command(/\APGOPTIONS=.* psql/, mock_success)
|
61
72
|
end
|
62
73
|
|
63
74
|
it { is_expected.to be_success }
|
@@ -83,7 +83,7 @@ describe Masamune::Actions::Transform do
|
|
83
83
|
context 'without :map' do
|
84
84
|
before do
|
85
85
|
expect_any_instance_of(Masamune::Schema::Map).to_not receive(:apply)
|
86
|
-
mock_command(/\
|
86
|
+
mock_command(/\APGOPTIONS=.* psql/, mock_success)
|
87
87
|
end
|
88
88
|
|
89
89
|
it { is_expected.to be_success }
|
@@ -104,7 +104,7 @@ describe Masamune::Actions::Transform do
|
|
104
104
|
end
|
105
105
|
|
106
106
|
expect_any_instance_of(Masamune::Schema::Map).to receive(:apply).and_call_original
|
107
|
-
mock_command(/\
|
107
|
+
mock_command(/\APGOPTIONS=.* psql/, mock_success)
|
108
108
|
end
|
109
109
|
|
110
110
|
it { is_expected.to be_success }
|
@@ -113,7 +113,7 @@ describe Masamune::Actions::Transform do
|
|
113
113
|
|
114
114
|
describe '.relabel_dimension' do
|
115
115
|
before do
|
116
|
-
mock_command(/\
|
116
|
+
mock_command(/\APGOPTIONS=.* psql/, mock_success)
|
117
117
|
end
|
118
118
|
|
119
119
|
subject { instance.relabel_dimension(postgres.user_dimension, options) }
|
@@ -123,7 +123,7 @@ describe Masamune::Actions::Transform do
|
|
123
123
|
|
124
124
|
describe '.consolidate_dimension' do
|
125
125
|
before do
|
126
|
-
mock_command(/\
|
126
|
+
mock_command(/\APGOPTIONS=.* psql/, mock_success)
|
127
127
|
end
|
128
128
|
|
129
129
|
subject { instance.consolidate_dimension(postgres.user_dimension, options) }
|
@@ -137,7 +137,7 @@ describe Masamune::Actions::Transform do
|
|
137
137
|
context 'without :map' do
|
138
138
|
before do
|
139
139
|
expect_any_instance_of(Masamune::Schema::Map).to_not receive(:apply)
|
140
|
-
mock_command(/\
|
140
|
+
mock_command(/\APGOPTIONS=.* psql/, mock_success)
|
141
141
|
end
|
142
142
|
|
143
143
|
subject { instance.load_fact(source_file, postgres.visits_hourly_file, postgres.visits_hourly_fact, date, options) }
|
@@ -152,7 +152,7 @@ describe Masamune::Actions::Transform do
|
|
152
152
|
end
|
153
153
|
|
154
154
|
expect_any_instance_of(Masamune::Schema::Map).to receive(:apply).and_call_original
|
155
|
-
mock_command(/\
|
155
|
+
mock_command(/\APGOPTIONS=.* psql/, mock_success)
|
156
156
|
end
|
157
157
|
|
158
158
|
subject { instance.load_fact(source_file, postgres.visits_hourly_file, postgres.visits_hourly_fact, date, options) }
|
@@ -165,7 +165,7 @@ describe Masamune::Actions::Transform do
|
|
165
165
|
let(:date) { DateTime.civil(2014, 8) }
|
166
166
|
|
167
167
|
before do
|
168
|
-
mock_command(/\
|
168
|
+
mock_command(/\APGOPTIONS=.* psql/, mock_success)
|
169
169
|
end
|
170
170
|
|
171
171
|
subject { instance.rollup_fact(postgres.visits_hourly_fact, postgres.visits_daily_fact, date, options) }
|
@@ -46,11 +46,21 @@ module Masamune::MockCommand
|
|
46
46
|
def reset!
|
47
47
|
@patterns = {}
|
48
48
|
end
|
49
|
+
|
50
|
+
def match(pattern)
|
51
|
+
# nop
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def command_env_and_args
|
56
|
+
command_env = @delegate.respond_to?(:command_env) ? @delegate.command_env.map { |key, val| "#{key}=#{val}" } : []
|
57
|
+
(command_env + @delegate.command_args).join(' ')
|
49
58
|
end
|
50
59
|
|
51
60
|
def around_execute(&block)
|
52
61
|
self.class.patterns.each do |pattern, (value, io)|
|
53
|
-
next unless
|
62
|
+
next unless command_env_and_args =~ pattern
|
63
|
+
CommandMatcher.match(pattern)
|
54
64
|
until io.eof?
|
55
65
|
line = io.gets
|
56
66
|
line_no ||= 0
|
@@ -90,6 +100,7 @@ module Masamune::MockCommand
|
|
90
100
|
end
|
91
101
|
|
92
102
|
def mock_command(pattern, value = nil, io = StringIO.new, &block)
|
103
|
+
expect(CommandMatcher).to receive(:match).with(pattern)
|
93
104
|
CommandMatcher.add_pattern(pattern, block_given? ? block.to_proc : value, io, &block)
|
94
105
|
end
|
95
106
|
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.18.
|
4
|
+
version: 0.18.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: 2016-08-
|
11
|
+
date: 2016-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|