masamune 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +54 -0
- data/Rakefile +15 -0
- data/bin/masamune-elastic-mapreduce +4 -0
- data/bin/masamune-hive +4 -0
- data/bin/masamune-psql +4 -0
- data/bin/masamune-shell +4 -0
- data/lib/masamune.rb +56 -0
- data/lib/masamune/accumulate.rb +60 -0
- data/lib/masamune/actions.rb +38 -0
- data/lib/masamune/actions/data_flow.rb +131 -0
- data/lib/masamune/actions/date_parse.rb +75 -0
- data/lib/masamune/actions/elastic_mapreduce.rb +68 -0
- data/lib/masamune/actions/execute.rb +52 -0
- data/lib/masamune/actions/filesystem.rb +37 -0
- data/lib/masamune/actions/hadoop_filesystem.rb +40 -0
- data/lib/masamune/actions/hadoop_streaming.rb +41 -0
- data/lib/masamune/actions/hive.rb +74 -0
- data/lib/masamune/actions/postgres.rb +76 -0
- data/lib/masamune/actions/postgres_admin.rb +34 -0
- data/lib/masamune/actions/s3cmd.rb +44 -0
- data/lib/masamune/actions/transform.rb +89 -0
- data/lib/masamune/after_initialize_callbacks.rb +55 -0
- data/lib/masamune/cached_filesystem.rb +110 -0
- data/lib/masamune/commands.rb +37 -0
- data/lib/masamune/commands/elastic_mapreduce.rb +119 -0
- data/lib/masamune/commands/hadoop_filesystem.rb +57 -0
- data/lib/masamune/commands/hadoop_streaming.rb +116 -0
- data/lib/masamune/commands/hive.rb +178 -0
- data/lib/masamune/commands/interactive.rb +37 -0
- data/lib/masamune/commands/postgres.rb +128 -0
- data/lib/masamune/commands/postgres_admin.rb +72 -0
- data/lib/masamune/commands/postgres_common.rb +33 -0
- data/lib/masamune/commands/retry_with_backoff.rb +60 -0
- data/lib/masamune/commands/s3cmd.rb +70 -0
- data/lib/masamune/commands/shell.rb +202 -0
- data/lib/masamune/configuration.rb +195 -0
- data/lib/masamune/data_plan.rb +31 -0
- data/lib/masamune/data_plan/builder.rb +66 -0
- data/lib/masamune/data_plan/elem.rb +190 -0
- data/lib/masamune/data_plan/engine.rb +162 -0
- data/lib/masamune/data_plan/rule.rb +292 -0
- data/lib/masamune/data_plan/set.rb +176 -0
- data/lib/masamune/environment.rb +164 -0
- data/lib/masamune/filesystem.rb +567 -0
- data/lib/masamune/has_environment.rb +40 -0
- data/lib/masamune/helpers.rb +27 -0
- data/lib/masamune/helpers/postgres.rb +84 -0
- data/lib/masamune/io.rb +33 -0
- data/lib/masamune/last_element.rb +53 -0
- data/lib/masamune/method_logger.rb +41 -0
- data/lib/masamune/multi_io.rb +39 -0
- data/lib/masamune/schema.rb +36 -0
- data/lib/masamune/schema/catalog.rb +233 -0
- data/lib/masamune/schema/column.rb +527 -0
- data/lib/masamune/schema/dimension.rb +133 -0
- data/lib/masamune/schema/event.rb +121 -0
- data/lib/masamune/schema/fact.rb +133 -0
- data/lib/masamune/schema/map.rb +265 -0
- data/lib/masamune/schema/row.rb +133 -0
- data/lib/masamune/schema/store.rb +115 -0
- data/lib/masamune/schema/table.rb +308 -0
- data/lib/masamune/schema/table_reference.rb +76 -0
- data/lib/masamune/spec_helper.rb +23 -0
- data/lib/masamune/string_format.rb +34 -0
- data/lib/masamune/tasks/elastic_mapreduce_thor.rb +60 -0
- data/lib/masamune/tasks/hive_thor.rb +55 -0
- data/lib/masamune/tasks/postgres_thor.rb +47 -0
- data/lib/masamune/tasks/shell_thor.rb +63 -0
- data/lib/masamune/template.rb +77 -0
- data/lib/masamune/thor.rb +186 -0
- data/lib/masamune/thor_loader.rb +38 -0
- data/lib/masamune/topological_hash.rb +34 -0
- data/lib/masamune/transform.rb +47 -0
- data/lib/masamune/transform/bulk_upsert.psql.erb +64 -0
- data/lib/masamune/transform/bulk_upsert.rb +52 -0
- data/lib/masamune/transform/consolidate_dimension.rb +54 -0
- data/lib/masamune/transform/deduplicate_dimension.psql.erb +52 -0
- data/lib/masamune/transform/deduplicate_dimension.rb +53 -0
- data/lib/masamune/transform/define_event_view.hql.erb +51 -0
- data/lib/masamune/transform/define_event_view.rb +60 -0
- data/lib/masamune/transform/define_index.psql.erb +34 -0
- data/lib/masamune/transform/define_schema.hql.erb +23 -0
- data/lib/masamune/transform/define_schema.psql.erb +79 -0
- data/lib/masamune/transform/define_schema.rb +56 -0
- data/lib/masamune/transform/define_table.hql.erb +34 -0
- data/lib/masamune/transform/define_table.psql.erb +95 -0
- data/lib/masamune/transform/define_table.rb +40 -0
- data/lib/masamune/transform/define_unique.psql.erb +30 -0
- data/lib/masamune/transform/insert_reference_values.psql.erb +43 -0
- data/lib/masamune/transform/insert_reference_values.rb +64 -0
- data/lib/masamune/transform/load_dimension.rb +47 -0
- data/lib/masamune/transform/load_fact.rb +45 -0
- data/lib/masamune/transform/operator.rb +96 -0
- data/lib/masamune/transform/relabel_dimension.psql.erb +76 -0
- data/lib/masamune/transform/relabel_dimension.rb +39 -0
- data/lib/masamune/transform/rollup_fact.psql.erb +79 -0
- data/lib/masamune/transform/rollup_fact.rb +149 -0
- data/lib/masamune/transform/snapshot_dimension.psql.erb +75 -0
- data/lib/masamune/transform/snapshot_dimension.rb +74 -0
- data/lib/masamune/transform/stage_dimension.psql.erb +39 -0
- data/lib/masamune/transform/stage_dimension.rb +83 -0
- data/lib/masamune/transform/stage_fact.psql.erb +80 -0
- data/lib/masamune/transform/stage_fact.rb +111 -0
- data/lib/masamune/version.rb +25 -0
- data/spec/fixtures/aggregate.sql.erb +25 -0
- data/spec/fixtures/comment.sql.erb +27 -0
- data/spec/fixtures/invalid.sql.erb +23 -0
- data/spec/fixtures/relative.sql.erb +23 -0
- data/spec/fixtures/simple.sql.erb +28 -0
- data/spec/fixtures/whitespace.sql.erb +30 -0
- data/spec/masamune/actions/elastic_mapreduce_spec.rb +108 -0
- data/spec/masamune/actions/execute_spec.rb +50 -0
- data/spec/masamune/actions/hadoop_filesystem_spec.rb +44 -0
- data/spec/masamune/actions/hadoop_streaming_spec.rb +74 -0
- data/spec/masamune/actions/hive_spec.rb +117 -0
- data/spec/masamune/actions/postgres_admin_spec.rb +58 -0
- data/spec/masamune/actions/postgres_spec.rb +134 -0
- data/spec/masamune/actions/s3cmd_spec.rb +44 -0
- data/spec/masamune/actions/transform_spec.rb +144 -0
- data/spec/masamune/after_initialization_callbacks_spec.rb +61 -0
- data/spec/masamune/cached_filesystem_spec.rb +167 -0
- data/spec/masamune/commands/hadoop_filesystem_spec.rb +50 -0
- data/spec/masamune/commands/hadoop_streaming_spec.rb +106 -0
- data/spec/masamune/commands/hive_spec.rb +117 -0
- data/spec/masamune/commands/postgres_admin_spec.rb +69 -0
- data/spec/masamune/commands/postgres_spec.rb +100 -0
- data/spec/masamune/commands/retry_with_backoff_spec.rb +116 -0
- data/spec/masamune/commands/s3cmd_spec.rb +50 -0
- data/spec/masamune/commands/shell_spec.rb +101 -0
- data/spec/masamune/configuration_spec.rb +102 -0
- data/spec/masamune/data_plan/builder_spec.rb +91 -0
- data/spec/masamune/data_plan/elem_spec.rb +102 -0
- data/spec/masamune/data_plan/engine_spec.rb +356 -0
- data/spec/masamune/data_plan/rule_spec.rb +407 -0
- data/spec/masamune/data_plan/set_spec.rb +517 -0
- data/spec/masamune/environment_spec.rb +65 -0
- data/spec/masamune/filesystem_spec.rb +1421 -0
- data/spec/masamune/helpers/postgres_spec.rb +95 -0
- data/spec/masamune/schema/catalog_spec.rb +613 -0
- data/spec/masamune/schema/column_spec.rb +696 -0
- data/spec/masamune/schema/dimension_spec.rb +137 -0
- data/spec/masamune/schema/event_spec.rb +75 -0
- data/spec/masamune/schema/fact_spec.rb +117 -0
- data/spec/masamune/schema/map_spec.rb +593 -0
- data/spec/masamune/schema/row_spec.rb +28 -0
- data/spec/masamune/schema/store_spec.rb +49 -0
- data/spec/masamune/schema/table_spec.rb +395 -0
- data/spec/masamune/string_format_spec.rb +60 -0
- data/spec/masamune/tasks/elastic_mapreduce_thor_spec.rb +57 -0
- data/spec/masamune/tasks/hive_thor_spec.rb +75 -0
- data/spec/masamune/tasks/postgres_thor_spec.rb +42 -0
- data/spec/masamune/tasks/shell_thor_spec.rb +51 -0
- data/spec/masamune/template_spec.rb +77 -0
- data/spec/masamune/thor_spec.rb +238 -0
- data/spec/masamune/transform/bulk_upsert.dimension_spec.rb +200 -0
- data/spec/masamune/transform/consolidate_dimension_spec.rb +62 -0
- data/spec/masamune/transform/deduplicate_dimension_spec.rb +84 -0
- data/spec/masamune/transform/define_event_view_spec.rb +84 -0
- data/spec/masamune/transform/define_schema_spec.rb +83 -0
- data/spec/masamune/transform/define_table.dimension_spec.rb +306 -0
- data/spec/masamune/transform/define_table.fact_spec.rb +291 -0
- data/spec/masamune/transform/define_table.table_spec.rb +525 -0
- data/spec/masamune/transform/insert_reference_values.dimension_spec.rb +111 -0
- data/spec/masamune/transform/insert_reference_values.fact_spec.rb +149 -0
- data/spec/masamune/transform/load_dimension_spec.rb +76 -0
- data/spec/masamune/transform/load_fact_spec.rb +89 -0
- data/spec/masamune/transform/relabel_dimension_spec.rb +102 -0
- data/spec/masamune/transform/rollup_fact_spec.rb +333 -0
- data/spec/masamune/transform/snapshot_dimension_spec.rb +103 -0
- data/spec/masamune/transform/stage_dimension_spec.rb +115 -0
- data/spec/masamune/transform/stage_fact_spec.rb +204 -0
- data/spec/masamune_spec.rb +32 -0
- data/spec/spec_helper.rb +41 -0
- data/spec/support/masamune/example_group.rb +36 -0
- data/spec/support/masamune/mock_command.rb +99 -0
- data/spec/support/masamune/mock_delegate.rb +51 -0
- data/spec/support/masamune/mock_filesystem.rb +96 -0
- data/spec/support/masamune/thor_mute.rb +35 -0
- data/spec/support/rspec/example/action_example_group.rb +34 -0
- data/spec/support/rspec/example/task_example_group.rb +80 -0
- data/spec/support/rspec/example/transform_example_group.rb +36 -0
- data/spec/support/shared_examples/postgres_common_examples.rb +53 -0
- metadata +462 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4aa0472dd6fa4bb472d79caf9a6c17a4570baad2
|
4
|
+
data.tar.gz: 853b036996129473d7f9f8dee3129f198988face
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b48a634347ae17d3a214be9ee13b021a7099c992b6e23382347ab44019b7d5209e6c3d73af0957067fff8abb9b3365c6a40fe880ef88cb56f67f4f7cfcab62cc
|
7
|
+
data.tar.gz: 861919413965988c50128a731f05e0ba9fd1bc9a5fc7a410038b23ce1e2e06fb4624889b11fb0142f321d0d2a8cc657e15a22f06a7efbc646674a4e99c228c16
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014-2015, VMware, Inc. All Rights Reserved.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
[![Build Status](https://secure.travis-ci.org/socialcast/masamune.png?branch=master)](http://travis-ci.org/socialcast/masamune)
|
2
|
+
[![License](http://img.shields.io/license/MIT.png?color=green)](http://opensource.org/licenses/MIT)
|
3
|
+
|
4
|
+
Masamune
|
5
|
+
========
|
6
|
+
A Dataflow Programming Library.
|
7
|
+
|
8
|
+
Description
|
9
|
+
------------
|
10
|
+
Masamune provides a [dataflow programming](http://en.wikipedia.org/wiki/Dataflow_programming) framework on top of [Thor](http://whatisthor.com/). In the framework, dataflows are constructed as Thor tasks that transform source data into the target data. Source and target data descriptions are encoded as annotations associated with the Thor command. From these source and target annotations, Masamune constructs a data dependency tree that describes how to automatically construct a target data set.
|
11
|
+
|
12
|
+
Usage
|
13
|
+
----------
|
14
|
+
|
15
|
+
Describe your dataflow as source, target data transformations:
|
16
|
+
```ruby
|
17
|
+
class ExampleThor < Thor
|
18
|
+
# Mix in Masamune specific Data Flow Behavior
|
19
|
+
include Masamune::Thor
|
20
|
+
include Masamune::Actions::DataFlow
|
21
|
+
|
22
|
+
# Mix in Masamune Actions for Data Processing
|
23
|
+
include Masamune::Actions::Streaming
|
24
|
+
include Masamune::Actions::Hive
|
25
|
+
|
26
|
+
# Describe a Data Processing Job
|
27
|
+
desc 'extract_logs', 'Organize log files by YYYY-MM-DD'
|
28
|
+
|
29
|
+
target fs.path(:target_dir, '%Y-%m-%d', mkdir: true)
|
30
|
+
source fs.path(:source_dir, '%Y%m%d*.log')
|
31
|
+
def extract_logs
|
32
|
+
targets.missing.each do |target|
|
33
|
+
target.sources.each do |source|
|
34
|
+
# Transform source into target
|
35
|
+
fs.copy(source.path, target.path)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
Execute your dataflow with the goal of processing all data from the start of the year:
|
43
|
+
|
44
|
+
```
|
45
|
+
thor extract_logs --start '1 year ago'
|
46
|
+
```
|
47
|
+
|
48
|
+
Contributing
|
49
|
+
---------------
|
50
|
+
|
51
|
+
* Fork the project
|
52
|
+
* Fix the issue
|
53
|
+
* Add unit tests
|
54
|
+
* Submit pull request on github
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
Bundler::GemHelper.install_tasks
|
10
|
+
|
11
|
+
require 'rspec/core/rake_task'
|
12
|
+
|
13
|
+
RSpec::Core::RakeTask.new(:spec)
|
14
|
+
|
15
|
+
task :default => :spec
|
data/bin/masamune-hive
ADDED
data/bin/masamune-psql
ADDED
data/bin/masamune-shell
ADDED
data/lib/masamune.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
#
|
3
|
+
# Copyright (c) 2014-2015, VMware, Inc. All Rights Reserved.
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
# THE SOFTWARE.
|
22
|
+
|
23
|
+
module Masamune
|
24
|
+
require 'masamune/environment'
|
25
|
+
require 'masamune/has_environment'
|
26
|
+
require 'masamune/io'
|
27
|
+
require 'masamune/template'
|
28
|
+
require 'masamune/commands'
|
29
|
+
require 'masamune/accumulate'
|
30
|
+
require 'masamune/last_element'
|
31
|
+
require 'masamune/actions'
|
32
|
+
require 'masamune/helpers'
|
33
|
+
require 'masamune/configuration'
|
34
|
+
require 'masamune/data_plan'
|
35
|
+
require 'masamune/thor'
|
36
|
+
require 'masamune/thor_loader'
|
37
|
+
require 'masamune/filesystem'
|
38
|
+
require 'masamune/cached_filesystem'
|
39
|
+
require 'masamune/method_logger'
|
40
|
+
require 'masamune/after_initialize_callbacks'
|
41
|
+
require 'masamune/schema'
|
42
|
+
require 'masamune/transform'
|
43
|
+
require 'masamune/topological_hash'
|
44
|
+
|
45
|
+
extend self
|
46
|
+
extend Masamune::HasEnvironment
|
47
|
+
|
48
|
+
def load(config_file, &block)
|
49
|
+
Masamune::Environment.new.tap do |env|
|
50
|
+
env.configure do |config|
|
51
|
+
config.load(config_file)
|
52
|
+
end
|
53
|
+
env.catalog.instance_eval &block
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
#
|
3
|
+
# Copyright (c) 2014-2015, VMware, Inc. All Rights Reserved.
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
# THE SOFTWARE.
|
22
|
+
|
23
|
+
module Masamune
|
24
|
+
module Accumulate
|
25
|
+
def accumulate(method, accumulator, *args)
|
26
|
+
accumulator.call(self, *args).tap do |elems|
|
27
|
+
send(method, *args) do |elem|
|
28
|
+
elems << elem
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
module ClassMethods
|
34
|
+
def method_accumulate(method, accumulator = lambda { |_, *args| Array.new })
|
35
|
+
self.class_eval do
|
36
|
+
new_method = "#{method}_with_accumulate".to_sym
|
37
|
+
old_method = "#{method}_without_accumulate".to_sym
|
38
|
+
alias_method old_method, method
|
39
|
+
|
40
|
+
define_method(new_method) do |*args, &block|
|
41
|
+
if block
|
42
|
+
instance = accumulator.call(self, *args)
|
43
|
+
send(old_method, *args) do |elem|
|
44
|
+
next if instance.respond_to?(:add?) && !instance.add?(elem)
|
45
|
+
block.call elem
|
46
|
+
end
|
47
|
+
else
|
48
|
+
accumulate(old_method, accumulator, *args)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
alias_method method, new_method
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.included(base)
|
57
|
+
base.extend ClassMethods
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
#
|
3
|
+
# Copyright (c) 2014-2015, VMware, Inc. All Rights Reserved.
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
# THE SOFTWARE.
|
22
|
+
|
23
|
+
module Masamune
|
24
|
+
module Actions
|
25
|
+
require 'masamune/actions/hive'
|
26
|
+
require 'masamune/actions/s3cmd'
|
27
|
+
require 'masamune/actions/hadoop_streaming'
|
28
|
+
require 'masamune/actions/hadoop_filesystem'
|
29
|
+
require 'masamune/actions/postgres'
|
30
|
+
require 'masamune/actions/postgres_admin'
|
31
|
+
require 'masamune/actions/filesystem'
|
32
|
+
require 'masamune/actions/date_parse'
|
33
|
+
require 'masamune/actions/data_flow'
|
34
|
+
require 'masamune/actions/elastic_mapreduce'
|
35
|
+
require 'masamune/actions/execute'
|
36
|
+
require 'masamune/actions/transform'
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
#
|
3
|
+
# Copyright (c) 2014-2015, VMware, Inc. All Rights Reserved.
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
# THE SOFTWARE.
|
22
|
+
|
23
|
+
require 'chronic'
|
24
|
+
require 'active_support/concern'
|
25
|
+
|
26
|
+
module Masamune::Actions
|
27
|
+
module DataFlow
|
28
|
+
extend ActiveSupport::Concern
|
29
|
+
|
30
|
+
include Masamune::Actions::DateParse
|
31
|
+
|
32
|
+
def engine
|
33
|
+
self.class.engine
|
34
|
+
end
|
35
|
+
|
36
|
+
def targets
|
37
|
+
engine.targets(current_command_name)
|
38
|
+
end
|
39
|
+
|
40
|
+
def sources
|
41
|
+
engine.sources(current_command_name)
|
42
|
+
end
|
43
|
+
|
44
|
+
def target
|
45
|
+
targets.first
|
46
|
+
end
|
47
|
+
|
48
|
+
def source
|
49
|
+
sources.first
|
50
|
+
end
|
51
|
+
|
52
|
+
# TODO sources from file or input array
|
53
|
+
def parse_file_type(key)
|
54
|
+
return Set.new unless key
|
55
|
+
value = options[key] or return Set.new
|
56
|
+
File.exists?(value) or raise Thor::MalformattedArgumentError, "Expected file value for '--#{key}'; got #{value}"
|
57
|
+
Set.new File.read(value).split(/\s+/)
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
included do |base|
|
63
|
+
base.extend ClassMethods
|
64
|
+
base.class_eval do
|
65
|
+
class_option :sources, :desc => 'File of data sources to process'
|
66
|
+
class_option :targets, :desc => 'File of data targets to process'
|
67
|
+
class_option :resolve, :type => :boolean, :desc => 'Recursively resolve data dependencies', :default => true
|
68
|
+
end
|
69
|
+
|
70
|
+
base.after_initialize(:final) do |thor, options|
|
71
|
+
# Only execute this block if DataPlan::Engine is not currently executing
|
72
|
+
next if thor.engine.executing?
|
73
|
+
thor.engine.environment = thor.environment
|
74
|
+
thor.engine.filesystem.environment = thor.environment
|
75
|
+
|
76
|
+
raise Thor::RequiredArgumentMissingError, "No value provided for required options '--start' or '--at'" unless options[:start] || options[:at] || options[:sources] || options[:targets]
|
77
|
+
raise Thor::MalformattedArgumentError, "Cannot specify both option '--sources' and option '--targets'" if options[:sources] && options[:targets]
|
78
|
+
|
79
|
+
desired_sources = Masamune::DataPlan::Set.new thor.current_command_name, thor.parse_file_type(:sources)
|
80
|
+
desired_targets = Masamune::DataPlan::Set.new thor.current_command_name, thor.parse_file_type(:targets)
|
81
|
+
|
82
|
+
if thor.start_time && thor.stop_time
|
83
|
+
desired_targets.merge thor.engine.targets_for_date_range(thor.current_command_name, thor.start_time, thor.stop_time)
|
84
|
+
end
|
85
|
+
|
86
|
+
thor.engine.prepare(thor.current_command_name, options.merge(sources: desired_sources, targets: desired_targets))
|
87
|
+
thor.engine.execute(thor.current_command_name, options)
|
88
|
+
exit 0 if thor.top_level?
|
89
|
+
end if defined?(base.after_initialize)
|
90
|
+
end
|
91
|
+
|
92
|
+
module ClassMethods
|
93
|
+
@@namespaces = []
|
94
|
+
@@commands = []
|
95
|
+
@@sources = []
|
96
|
+
@@targets = []
|
97
|
+
|
98
|
+
def skip
|
99
|
+
@@namespaces << namespace
|
100
|
+
@@sources << {skip: true}
|
101
|
+
@@targets << {skip: true}
|
102
|
+
end
|
103
|
+
|
104
|
+
def source(source_options = {})
|
105
|
+
@@namespaces << namespace
|
106
|
+
@@sources << source_options
|
107
|
+
end
|
108
|
+
|
109
|
+
def target(target_options = {})
|
110
|
+
@@targets << target_options
|
111
|
+
end
|
112
|
+
|
113
|
+
def create_command(*a)
|
114
|
+
super.tap do
|
115
|
+
@@commands += a
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def engine
|
120
|
+
@@engine ||= Masamune::DataPlan::Builder.instance.build(@@namespaces, @@commands, @@sources, @@targets)
|
121
|
+
end
|
122
|
+
|
123
|
+
private
|
124
|
+
|
125
|
+
# If internal call to Thor::Base.start fails, exit
|
126
|
+
def exit_on_failure?
|
127
|
+
true
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
#
|
3
|
+
# Copyright (c) 2014-2015, VMware, Inc. All Rights Reserved.
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
# THE SOFTWARE.
|
22
|
+
|
23
|
+
require 'chronic'
|
24
|
+
require 'active_support/concern'
|
25
|
+
|
26
|
+
module Masamune::Actions
|
27
|
+
module DateParse
|
28
|
+
extend ActiveSupport::Concern
|
29
|
+
|
30
|
+
def parse_datetime_type(key)
|
31
|
+
value = options[key]
|
32
|
+
Chronic.parse(value).tap do |datetime_value|
|
33
|
+
console("Using '#{datetime_value}' for --#{key}") if value != datetime_value
|
34
|
+
end or raise Thor::MalformattedArgumentError, "Expected date time value for '--#{key}'; got #{value}"
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
included do |base|
|
40
|
+
base.class_eval do
|
41
|
+
attr_accessor :start_value
|
42
|
+
attr_accessor :stop_value
|
43
|
+
attr_accessor :exact_value
|
44
|
+
|
45
|
+
class_option :start, :aliases => '-a', :desc => 'Start time'
|
46
|
+
class_option :stop, :aliases => '-b', :desc => 'Stop time'
|
47
|
+
class_option :at, :desc => 'Exact time'
|
48
|
+
|
49
|
+
no_tasks do
|
50
|
+
def start_date
|
51
|
+
(start_value || exact_value).try(:to_date)
|
52
|
+
end
|
53
|
+
|
54
|
+
def start_time
|
55
|
+
(start_value || exact_value).try(:to_time)
|
56
|
+
end
|
57
|
+
|
58
|
+
def stop_date
|
59
|
+
(stop_value || exact_value).try(:to_date)
|
60
|
+
end
|
61
|
+
|
62
|
+
def stop_time
|
63
|
+
(stop_value || exact_value).try(:to_time)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
base.after_initialize(:latest) do |thor, options|
|
69
|
+
thor.start_value = thor.parse_datetime_type(:start) if options[:start]
|
70
|
+
thor.exact_value = thor.parse_datetime_type(:at) if options[:at]
|
71
|
+
thor.stop_value = thor.parse_datetime_type(:stop) if options[:stop]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|