gd_bam 0.0.15 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. data/README.md +313 -5
  2. data/bin/bam +126 -48
  3. data/lib/bam/version.rb +1 -1
  4. data/lib/bam.rb +51 -0
  5. data/lib/base/errors.rb +15 -0
  6. data/lib/base/flow.rb +37 -0
  7. data/lib/base/graph.rb +23 -0
  8. data/lib/base/metadata.rb +107 -0
  9. data/lib/base/project.rb +95 -0
  10. data/lib/base/repo.rb +35 -0
  11. data/lib/base/sink.rb +44 -0
  12. data/lib/base/step.rb +47 -0
  13. data/lib/base/tap.rb +167 -0
  14. data/lib/base/taps.rb +19 -0
  15. data/lib/cloud_connect/dsl/cc.rb +42 -0
  16. data/lib/cloud_connect/dsl/es_helpers.rb +49 -0
  17. data/lib/cloud_connect/dsl/helpers.rb +199 -0
  18. data/lib/{nodes → cloud_connect/dsl}/nodes.rb +106 -16
  19. data/lib/cloud_connect/dsl/sf_helpers.rb +39 -0
  20. data/lib/cloud_connect/dsl/structure_helpers.rb +94 -0
  21. data/lib/commands/commands.rb +110 -0
  22. data/lib/commands/deployment.rb +217 -0
  23. data/lib/commands/docs_commands.rb +41 -0
  24. data/lib/commands/gd_commands.rb +95 -0
  25. data/lib/commands/scaffold_commands.rb +103 -0
  26. data/lib/commands/sf_commands.rb +37 -0
  27. data/lib/commands/validators.rb +19 -0
  28. data/lib/compatibility.rb +19 -0
  29. data/lib/compiler/compiler.rb +76 -0
  30. data/lib/compiler/etl_visitor.rb +165 -0
  31. data/lib/dsl/dsl.rb +125 -0
  32. data/lib/generators/downloaders.rb +449 -0
  33. data/lib/generators/etl.rb +261 -0
  34. data/lib/generators/validators.rb +445 -0
  35. data/lib/graphs/docentize.grf +1 -1
  36. data/lib/graphs/dummy.grf +1 -1
  37. data/lib/graphs/goodsales_v2/docentize.grf +47 -0
  38. data/lib/graphs/goodsales_v2/dummy.grf +46 -0
  39. data/lib/graphs/goodsales_v2/load_history.grf +579 -0
  40. data/lib/graphs/goodsales_v2/process_account.grf +47 -0
  41. data/lib/graphs/goodsales_v2/process_activity.grf +222 -0
  42. data/lib/graphs/goodsales_v2/process_activity_dim.grf +88 -0
  43. data/lib/graphs/goodsales_v2/process_activity_owner.grf +48 -0
  44. data/lib/graphs/goodsales_v2/process_forecast.grf +20 -0
  45. data/lib/graphs/goodsales_v2/process_opp_records.grf +84 -0
  46. data/lib/graphs/goodsales_v2/process_opportunity.grf +46 -0
  47. data/lib/graphs/goodsales_v2/process_opportunity_line_item.grf +171 -0
  48. data/lib/graphs/goodsales_v2/process_opportunity_snapshot.grf +94 -0
  49. data/lib/graphs/goodsales_v2/process_owner.grf +48 -0
  50. data/lib/graphs/goodsales_v2/process_stage.grf +51 -0
  51. data/lib/graphs/goodsales_v2/process_stage_history.grf +184 -0
  52. data/lib/graphs/goodsales_v2/process_velocity_duration.grf +140 -0
  53. data/lib/graphs/process_account.grf +1 -1
  54. data/lib/graphs/process_activity.grf +1 -1
  55. data/lib/graphs/process_activity_dim.grf +1 -1
  56. data/lib/graphs/process_activity_owner.grf +1 -1
  57. data/lib/graphs/process_forecast.grf +1 -1
  58. data/lib/graphs/process_opp_records.grf +1 -1
  59. data/lib/graphs/process_opportunity.grf +1 -1
  60. data/lib/graphs/process_opportunity_line_item.grf +1 -1
  61. data/lib/graphs/process_opportunity_snapshot.grf +1 -1
  62. data/lib/graphs/process_owner.grf +1 -1
  63. data/lib/graphs/process_stage.grf +1 -1
  64. data/lib/graphs/process_stage_history.grf +1 -1
  65. data/lib/graphs/process_velocity_duration.grf +1 -1
  66. data/lib/nodes/clover_gen.rb +59 -946
  67. data/lib/nodes/dependency.rb +95 -96
  68. data/lib/runtime.rb +7 -648
  69. data/lib/utils/utils.rb +66 -0
  70. data/templates/flow.rb.erb +7 -6
  71. data/templates/join_template.grf.erb +1 -1
  72. data/templates/reformat_template.grf.erb +1 -1
  73. data/templates/sink.json.erb +28 -0
  74. data/templates/tap.json.erb +3 -5
  75. data/templates/workspace.prm.erb +4 -0
  76. metadata +50 -8
  77. data/lib/contract_checkers/contract_checkers.rb +0 -53
  78. data/lib/dsl/project_dsl.rb +0 -259
  79. data/lib/repo/1_config.json +0 -8
  80. data/templates/dataset.json.erb +0 -13
  81. data/templates/source.json.erb +0 -22
@@ -0,0 +1,261 @@
1
+ module GoodData
2
+ module Bam
3
+ module Generators
4
+ module Etl
5
+
6
+ include GoodData::Bam
7
+ include GoodData::CloudConnect
8
+
9
+
10
+ def self.create_es_readmap(metadata, tap)
11
+ e = Es::Entity.new("x", {
12
+ :file => "none",
13
+ :fields => metadata[:fields].map do |f|
14
+ name = f[:name]
15
+ if name == "Id"
16
+ Es::Field.new('Id', 'recordid')
17
+ elsif name == "Snapshot"
18
+ Es::SnapshotField.new('Snapshot', 'snapshot')
19
+ else
20
+ Es::Field.new(name, 'attribute')
21
+ end
22
+ end,
23
+ :timeframe => Es::Timeframe::parse("latest")
24
+ })
25
+
26
+
27
+ stuff = {
28
+ :entityName => tap[:id],
29
+ :fieldsMapping => tap[:fields].inject({}) do |memo, field|
30
+ name = field[:name]
31
+ memo[name] = name
32
+ memo
33
+ end,
34
+ :eventStoreFieldToTypeMapping => tap[:fields].inject({}) do |memo, field|
35
+ name = field[:name]
36
+ if name == "Id"
37
+ memo[name] = "recordid"
38
+ elsif name == "Snapshot"
39
+ memo[name] = "snapshot"
40
+ else
41
+ memo[name] = "attribute"
42
+ end
43
+
44
+ memo
45
+ end,
46
+ :outputMetadataName => "es_metadata"
47
+ }
48
+
49
+ read_map = {
50
+ :columns => e.to_extract_fragment('pid')["readTask"]["readMap"].first[:columns],
51
+ :populates => e.to_extract_fragment('pid')["readTask"]["readMap"].first[:populates]
52
+ }
53
+ if tap.has_key?(:time_intervals)
54
+ [stuff, read_map, tap[:time_intervals]]
55
+ else
56
+ [stuff, read_map, nil]
57
+ end
58
+
59
+ end
60
+
61
+ def self.create_file_uploading_graph(file, sink, input_name, state={})
62
+ File.open(file, "w") do |file|
63
+ builder = Builder::XmlMarkup.new(:target=>file, :indent=>2)
64
+ builder.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
65
+ builder.Graph({
66
+ :name => "GoodData Data loader"
67
+ }) do
68
+ builder.Global do
69
+ Helpers::property_file(builder, {:id => "workspace_params", :fileURL => "workspace.prm"})
70
+ builder.Metadata({:id => "load_metadata"}) do |builder|
71
+ Helpers::csv_metadata(builder, state[:metadata][input_name])
72
+ end
73
+ end
74
+ builder.Phase(:number => 0) do
75
+ gd_dataset = sink[:gd_name] || sink[:id]
76
+ to_svinstvo = GoodData::CloverGenerator::build_gd_dataset_loader_json(sink)
77
+ Core::build_node2(builder, Nodes.reader2({:name => "CSV Loader", :id => "loader", :fileURL => "${PROJECT}/data/#{input_name}.csv"}))
78
+ Core::build_node2(builder, Nodes.writer2({:name => "GD Loader", :id => "writer", :fileURL => sink[:target]}))
79
+ Core::build_node2(builder, Nodes.edge2({:toNode => "writer:0", :fromNode => "loader:0", :metadata => "load_metadata"}))
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ def self.create_gd_uploading_graph(file, sink, input_name, state={})
86
+ File.open(file, "w") do |file|
87
+ builder = Builder::XmlMarkup.new(:target=>file, :indent=>2)
88
+ builder.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
89
+ builder.Graph({
90
+ :name => "GoodData Data loader"
91
+ }) do
92
+ builder.Global do
93
+ Helpers::property_file(builder, {:id => "workspace_params", :fileURL => "workspace.prm"})
94
+ builder.Metadata({:id => "load_metadata"}) do |builder|
95
+ Helpers::csv_metadata(builder, state[:metadata][input_name])
96
+ end
97
+ end
98
+ builder.Phase(:number => 0) do
99
+ gd_dataset = sink[:gd_name] || sink[:id]
100
+ to_svinstvo = GoodData::CloverGenerator::build_gd_dataset_loader_json(sink)
101
+ Core::build_node2(builder, Nodes.reader2({:name => "CSV Loader", :id => "loader", :fileURL => "${PROJECT}/data/#{input_name}.csv"}))
102
+ Core::build_node2(builder, Nodes.edge2({:toNode => "gd_load:0", :fromNode => "loader:0", :metadata => "load_metadata"}))
103
+ Core::build_node2(builder, Nodes.gd_loader2({:name => "GD Loader", :id => "gd_load", :dataset => "dataset.#{gd_dataset}", :datasetFieldMappings => to_svinstvo.to_json}))
104
+ end
105
+ end
106
+ end
107
+ end
108
+
109
+ def self.create_file_downloading_graph(file, tap, options={})
110
+ s3_backup = options[:params][:s3_backup]
111
+
112
+ File.open(file, "w") do |file|
113
+ builder = Builder::XmlMarkup.new(:target=>file, :indent=>2)
114
+ builder.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
115
+ builder.Graph({
116
+ :name => "File Downloader"
117
+ }) do
118
+ builder.Global do
119
+ Helpers::property_file(builder, {:id => "workspace_params", :fileURL => "workspace.prm"})
120
+
121
+ builder.Metadata({:id => "file_metadata"}) do |builder|
122
+ Helpers::csv_metadata(builder, Metadata.get_source_metadata(tap))
123
+ end
124
+ builder.Metadata({:id => "clover_metadata"}) do |builder|
125
+ Helpers::csv_metadata(builder, Metadata.get_target_metadata(tap))
126
+ end
127
+ end
128
+
129
+ builder.Phase(:number => 0) do
130
+ Core::build_node2(builder, Nodes.reader2({:name => "reader", :id => "reader", :fileURL => tap[:source] }))
131
+
132
+ Core::build_node2(builder, Nodes.copy2({:name => "copy", :id => "copy"}))
133
+ Core::build_node2(builder, Nodes.edge2({:toNode => "copy:0", :fromNode => "reader:0", :metadata => "file_metadata"}))
134
+
135
+ transformation_source = "function integer transform() {\n" + (Tap.source_target_mappging(tap).map {|t| "$out.0.#{t.last} = $in.0.#{t.first};"}.join("\n")) + "\nreturn OK;\n}"
136
+ Core::build_node2(builder, Nodes.reformat2({:name => "Reformat", :id => "reformat", :transformation => transformation_source}))
137
+ Core::build_node2(builder, Nodes.edge2({:toNode => "reformat:0", :fromNode => "copy:0", :metadata => "file_metadata"}))
138
+
139
+ Core::build_node2(builder, Nodes.writer2({:name => "CSV Writer", :id => "csv", :fileURL => "data/#{tap[:id]}.csv", :outputFieldNames => "true"}))
140
+ Core::build_node2(builder, Nodes.edge2({:toNode => "csv:0", :fromNode => "reformat:0", :metadata => "clover_metadata"}))
141
+
142
+ if s3_backup then Core::build_node2(builder, Nodes.writer2({:name => "s3 Writer", :id => "s3", :fileURL => "bucket", :outputFieldNames => true})) end
143
+ if s3_backup then Core::build_node2(builder, Nodes.edge2({:toNode => "s3:0", :fromNode => "copy:1", :metadata => "file_metadata"})) end
144
+ end
145
+ end
146
+ end
147
+ end
148
+
149
+ def self.create_sf_downloading_graph(file, tap, options={})
150
+ s3_backup = options[:params][:s3_backup]
151
+
152
+ File.open(file, "w") do |file|
153
+ builder = Builder::XmlMarkup.new(:target=>file, :indent=>2)
154
+ builder.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
155
+ builder.Graph({
156
+ :name => "Goodsales Salesforce Downloader"
157
+ }) do
158
+ builder.Global do
159
+
160
+ builder.Metadata({:id => "clover_metadata"}) do |builder|
161
+ Helpers::csv_metadata(builder, Metadata.get_target_metadata(tap))
162
+ end
163
+
164
+ builder.Metadata({:id => "sf_metadata"}) do |builder|
165
+ Helpers::csv_metadata(builder, Metadata.get_source_metadata(tap))
166
+ end
167
+
168
+ Helpers::sf_connection(builder, {})
169
+ Helpers::property(builder, {:id => "SFDC_CLIENT_ID", :value => "gooddata/gooddata/"})
170
+ Helpers::property(builder, {:id => "SFDC_LOGIN_HOSTNAME", :value => options[:params][:sf_server] || "login.salesforce.com"})
171
+ Helpers::property(builder, {:id => "SFDC_NAME", :value => "Salesforce connection"})
172
+ Helpers::property(builder, {:id => "SFDC_PASSWORD", :value => options[:params][:sf_password]})
173
+ Helpers::property(builder, {:id => "SFDC_TOKEN", :value => options[:params][:sf_token]})
174
+ Helpers::property(builder, {:id => "SFDC_USERNAME", :value => options[:params][:sf_login]})
175
+ Helpers::property_file(builder, {:id => "workspace_params", :fileURL => "workspace.prm"})
176
+ end
177
+
178
+ builder.Phase(:number => 0) do
179
+ fields = tap[:fields]
180
+ mapping = "{\"xmlFieldsMapping\":{\"xmlFields\":["
181
+ add = fields.map do |f|
182
+ "{\"xmlFieldMapping\":{\"name\":\"#{f[:name]}\",\"label\":\"#{f[:label]}\",\"xmlPath\":\"#{f[:name]}\",\"metadataField\":\"#{f[:name]}\"}}"
183
+ end
184
+
185
+ stuff = mapping + add.join(",") + "]}}"
186
+ mandatory_fields = fields.reject {|f| f[:is_mandatory] == false }.map {|f| f[:name] + ";"}.join
187
+
188
+ Core::build_node2(builder, Nodes.sfdc_reader2({:name => "SF Writer", :id => "sf", :soql => Helpers::generate_select(tap), :sfdcConnection => "SFDC", :fieldsMapping => stuff, :mandatoryFields => mandatory_fields}))
189
+
190
+ Core::build_node2(builder, Nodes.copy2({:name => "copy", :id => "copy"}))
191
+ Core::build_node2(builder, Nodes.edge2({:toNode => "copy:0", :fromNode => "sf:0", :metadata => "sf_metadata"}))
192
+
193
+ transformation_source = "function integer transform() {\n" + (Tap.source_target_mappging(tap).map {|t| "$out.0.#{t.last} = $in.0.#{t.first};"}.join("\n")) + "\nreturn OK;\n}"
194
+ Core::build_node2(builder, Nodes.reformat2({:name => "Reformat", :id => "reformat", :transformation => transformation_source}))
195
+ Core::build_node2(builder, Nodes.edge2({:toNode => "reformat:0", :fromNode => "copy:0", :metadata => "sf_metadata"}))
196
+
197
+ Core::build_node2(builder, Nodes.writer2({:name => "CSV Writer", :id => "csv", :fileURL => "data/#{tap[:id]}.csv", :outputFieldNames => "true"}))
198
+ Core::build_node2(builder, Nodes.edge2({:toNode => "csv:0", :fromNode => "reformat:0", :metadata => "clover_metadata"}))
199
+ if s3_backup
200
+ Core::build_node2(builder, Nodes.writer2({:name => "s3 Writer", :id => "s3", :fileURL => "bucket", :outputFieldNames => true}))
201
+ Core::build_node2(builder, Nodes.edge2({:toNode => "s3:0", :fromNode => "copy:1", :metadata => "sf_metadata"}))
202
+ end
203
+ end
204
+ end
205
+ end
206
+ end
207
+
208
+ def self.create_es_downloading_graph(file, tap, options={})
209
+ s3_backup = options[:params][:s3_backup]
210
+
211
+ metadata_from_es = Metadata.get_source_metadata(tap)
212
+ output_metadata = Metadata.get_target_metadata(tap)
213
+ id = tap[:id]
214
+
215
+ File.open(file, "w") do |file|
216
+ builder = Builder::XmlMarkup.new(:target=>file, :indent=>2)
217
+ builder.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
218
+ builder.Graph({
219
+ :name => "GoodData EventStore Downloader"
220
+ }) do
221
+ builder.Global do
222
+ Helpers::property_file(builder, {:id => "workspace_params", :fileURL => "workspace.prm"})
223
+
224
+ builder.Metadata({:id => "es_metadata"}) do |builder|
225
+ Helpers::csv_metadata(builder, metadata_from_es)
226
+ end
227
+
228
+ builder.Metadata({:id => "output_metadata"}) do |builder|
229
+ Helpers::csv_metadata(builder, output_metadata)
230
+ end
231
+ end
232
+
233
+ builder.Phase(:number => 0) do
234
+ stuff, read_map, time_frames = create_es_readmap(metadata_from_es, tap)
235
+
236
+ if time_frames.blank?
237
+ Core::build_node2(builder, Nodes.es_reader2({:name => "ES Reader", :id => "es", :entityFieldsMapping => stuff.to_json , :readMap => read_map.to_json}))
238
+ else
239
+ Core::build_node2(builder, Nodes.es_reader2({:name => "ES Reader", :id => "es", :entityFieldsMapping => stuff.to_json , :readMap => read_map.to_json, :timeIntervals => time_frames.to_json}))
240
+ end
241
+
242
+ transformation_source = if Metadata::has_field?(metadata_from_es, "Snapshot")
243
+ "function integer transform() {\n" + (Tap.source_target_mappging(tap).map {|t| "$out.0.#{t.last} = $in.0.#{t.first};"}.join("\n")) + "\n$out.0.Snapshot = date2str(dateAdd(str2date(\"1900-01-01\", \"yyyy-MM-dd\"), str2long($in.0.Snapshot), day), \"yyyy-MM-dd\");\nreturn OK;\n}"
244
+ else
245
+ "function integer transform() {\n" + (Tap.source_target_mappging(tap).map {|t| "$out.0.#{t.last} = $in.0.#{t.first};"}.join("\n")) + "\nreturn OK;\n}"
246
+ end
247
+ Core::build_node2(builder, Nodes.reformat2({:name => "Reformat", :id => "reformat", :transformation => transformation_source}))
248
+ Core::build_node2(builder, Nodes.edge2({:toNode => "reformat:0", :fromNode => "es:0", :metadata => "es_metadata"}))
249
+
250
+ Core::build_node2(builder, Nodes.copy2({:name => "Copy", :id => "copy"}))
251
+ Core::build_node2(builder, Nodes.edge2({:toNode => "copy:0", :fromNode => "reformat:0", :metadata => "output_metadata"}))
252
+ Core::build_node2(builder, Nodes.writer2({:name => "CSV Writer", :id => "csv", :fileURL => "${PROJECT}/data/#{tap[:id]}.csv", :outputFieldNames => "true", :makeDirs => "true"}))
253
+ Core::build_node2(builder, Nodes.edge2({:toNode => "csv:0", :fromNode => "copy:0", :metadata => "output_metadata"}))
254
+ end
255
+ end
256
+ end
257
+ end
258
+ end
259
+ end
260
+ end
261
+ end