Module: GoodData::LCM2
- Defined in:
- lib/gooddata/lcm/lcm2.rb,
lib/gooddata/lcm/dsl/dsl.rb,
lib/gooddata/lcm/types/param.rb,
lib/gooddata/lcm/dsl/type_dsl.rb,
lib/gooddata/lcm/dsl/params_dsl.rb,
lib/gooddata/lcm/types/base_type.rb,
lib/gooddata/lcm/types/class/class.rb,
lib/gooddata/lcm/types/scalar/bool.rb,
lib/gooddata/lcm/types/scalar/hash.rb,
lib/gooddata/lcm/types/special/enum.rb,
lib/gooddata/lcm/actions/base_action.rb,
lib/gooddata/lcm/actions/hello_world.rb,
lib/gooddata/lcm/actions/print_modes.rb,
lib/gooddata/lcm/actions/print_types.rb,
lib/gooddata/lcm/types/scalar/object.rb,
lib/gooddata/lcm/types/scalar/string.rb,
lib/gooddata/lcm/types/special/array.rb,
lib/gooddata/lcm/helpers/check_helper.rb,
lib/gooddata/lcm/types/complex/tokens.rb,
lib/gooddata/lcm/types/scalar/integer.rb,
lib/gooddata/lcm/actions/print_actions.rb,
lib/gooddata/lcm/actions/purge_clients.rb,
lib/gooddata/lcm/types/class/gd_client.rb,
lib/gooddata/lcm/types/complex/complex.rb,
lib/gooddata/lcm/types/complex/segment.rb,
lib/gooddata/lcm/types/class/ads_client.rb,
lib/gooddata/lcm/actions/collect_clients.rb,
lib/gooddata/lcm/actions/ensure_segments.rb,
lib/gooddata/lcm/actions/segments_filter.rb,
lib/gooddata/lcm/actions/synchronize_ldm.rb,
lib/gooddata/lcm/actions/collect_segments.rb,
lib/gooddata/lcm/actions/synchronize_meta.rb,
lib/gooddata/lcm/actions/apply_custom_maql.rb,
lib/gooddata/lcm/actions/associate_clients.rb,
lib/gooddata/lcm/actions/provision_clients.rb,
lib/gooddata/lcm/actions/synchronize_clients.rb,
lib/gooddata/lcm/types/complex/release_query.rb,
lib/gooddata/lcm/actions/ensure_release_table.rb,
lib/gooddata/lcm/actions/update_release_table.rb,
lib/gooddata/lcm/actions/synchronize_processes.rb,
lib/gooddata/lcm/actions/synchronize_schedules.rb,
lib/gooddata/lcm/actions/create_segment_masters.rb,
lib/gooddata/lcm/actions/collect_segment_clients.rb,
lib/gooddata/lcm/actions/synchronize_label_types.rb,
lib/gooddata/lcm/types/complex/update_preference.rb,
lib/gooddata/lcm/actions/synchronize_new_segments.rb,
lib/gooddata/lcm/actions/synchronize_color_palette.rb,
lib/gooddata/lcm/types/complex/synchronization_info.rb,
lib/gooddata/lcm/actions/synchronize_etls_in_segment.rb,
lib/gooddata/lcm/actions/ensure_technical_users_domain.rb,
lib/gooddata/lcm/actions/ensure_technical_users_project.rb,
lib/gooddata/lcm/actions/synchronize_attribute_drillpaths.rb
Defined Under Namespace
Modules: Dsl, Type
Classes: ApplyCustomMaql, AssociateClients, BaseAction, CollectClients, CollectSegmentClients, CollectSegments, CreateSegmentMasters, EnsureReleaseTable, EnsureSegments, EnsureTechnicalUsersDomain, EnsureTechnicalUsersProject, HelloWorld, Helpers, PrintActions, PrintModes, PrintTypes, ProvisionClients, PurgeClients, SegmentsFilter, SmartHash, SynchronizeAttributeDrillpath, SynchronizeClients, SynchronizeColorPalette, SynchronizeETLsInSegment, SynchronizeLabelTypes, SynchronizeLdm, SynchronizeMeta, SynchronizeNewSegments, SynchronizeProcesses, SynchronizeSchedules, UpdateReleaseTable
Constant Summary
collapse
- MODES =
{
actions: [
PrintActions
],
hello: [
HelloWorld
],
modes: [
PrintModes
],
info: [
PrintTypes,
PrintActions,
PrintModes
],
types: [
PrintTypes
],
release: [
EnsureReleaseTable,
SegmentsFilter,
CreateSegmentMasters,
EnsureTechnicalUsersDomain,
EnsureTechnicalUsersProject,
SynchronizeLdm,
SynchronizeMeta,
SynchronizeLabelTypes,
SynchronizeAttributeDrillpath,
SynchronizeProcesses,
SynchronizeSchedules,
SynchronizeColorPalette,
SynchronizeNewSegments,
UpdateReleaseTable
],
provision: [
EnsureReleaseTable,
CollectSegments,
SegmentsFilter,
PurgeClients,
CollectClients,
AssociateClients,
ProvisionClients,
EnsureTechnicalUsersDomain,
EnsureTechnicalUsersProject,
SynchronizeAttributeDrillpath,
SynchronizeETLsInSegment,
SynchronizeColorPalette
],
rollout: [
EnsureReleaseTable,
CollectSegments,
SegmentsFilter,
CollectSegmentClients,
EnsureTechnicalUsersDomain,
EnsureTechnicalUsersProject,
SynchronizeLdm,
SynchronizeAttributeDrillpath,
ApplyCustomMaql,
SynchronizeColorPalette,
SynchronizeClients,
SynchronizeETLsInSegment
]
}
- MODE_NAMES =
MODES.keys
Class Method Summary
collapse
Class Method Details
.convert_params(params) ⇒ Object
133
134
135
136
137
|
# File 'lib/gooddata/lcm/lcm2.rb', line 133
def convert_params(params)
GoodData::Helpers.symbolize_keys!(params)
convert_to_smart_hash(params)
end
|
.convert_to_smart_hash(params) ⇒ Object
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
# File 'lib/gooddata/lcm/lcm2.rb', line 139
def convert_to_smart_hash(params)
if params.is_a?(Hash)
res = SmartHash.new
params.each_pair do |k, v|
if v.is_a?(Hash) || v.is_a?(Array)
res[k] = convert_to_smart_hash(v)
else
res[k] = v
end
end
res
elsif params.is_a?(Array)
params.map do |item|
convert_to_smart_hash(item)
end
else
params
end
end
|
.get_mode_actions(mode) ⇒ Object
159
160
161
162
163
164
165
166
167
|
# File 'lib/gooddata/lcm/lcm2.rb', line 159
def get_mode_actions(mode)
mode = mode.to_sym
actions = MODES[mode]
if mode == :generic_lifecycle
[]
else
actions || fail("Invalid mode specified '#{mode}', supported modes are: '#{MODE_NAMES.join(', ')}'")
end
end
|
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
|
# File 'lib/gooddata/lcm/lcm2.rb', line 228
def perform(mode, params = {})
params = convert_params(params)
actions = get_mode_actions(mode)
if params.actions
actions = params.actions.map do |action|
"GoodData::LCM2::#{action}".split('::').inject(Object) do |o, c|
begin
o.const_get(c)
rescue NameError
fail NameError, "Cannot find action 'GoodData::LCM2::#{action}'"
end
end
end
end
print_action_names(mode, actions)
new_params = params
fail_early = if params.key?(:fail_early)
params.fail_early.to_b
else
true
end
strict_mode = if params.key?(:strict)
params.strict.to_b
else
true
end
errors = []
results = []
actions.each do |action|
puts
begin
out = action.send(:call, params)
rescue => e
errors << {
action: action,
err: e
}
break if fail_early
end
res = out.is_a?(Array) ? out : out[:results]
out_params = out.is_a?(Hash) ? out[:params] || {} : {}
new_params = convert_to_smart_hash(out_params)
params.merge!(new_params)
puts
print_action_result(action, res)
results << res
end
fail(JSON.pretty_generate(errors)) if strict_mode && errors.any?
if actions.length > 1
puts
puts 'SUMMARY'
puts
print_actions_result(actions, results)
end
brick_results = {}
actions.each_with_index do |action, index|
brick_results[action.short_name] = results[index]
end
{
actions: actions.map(&:short_name),
results: brick_results,
params: params
}
end
|
.print_action_names(mode, actions) ⇒ Object
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
# File 'lib/gooddata/lcm/lcm2.rb', line 169
def print_action_names(mode, actions)
title = "Actions to be performed for mode '#{mode}'"
headings = %w(# NAME DESCRIPTION)
rows = []
actions.each_with_index do |action, index|
rows << [index, action.short_name, action.const_defined?(:DESCRIPTION) && action.const_get(:DESCRIPTION)]
end
table = Terminal::Table.new :title => title, :headings => headings do |t|
rows.each_with_index do |row, index|
t << row
t.add_separator if index < rows.length - 1
end
end
puts "\n#{table}"
end
|
.print_action_result(action, messages) ⇒ Object
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
# File 'lib/gooddata/lcm/lcm2.rb', line 188
def print_action_result(action, messages)
title = "Result of #{action.short_name}"
keys = if action.const_defined?('RESULT_HEADER')
action.const_get('RESULT_HEADER')
else
GoodData.logger.warn("Action #{action.name} does not have RESULT_HEADERS, inferring headers from results.")
(messages.first && messages.first.keys) || []
end
headings = keys.map(&:upcase)
rows = messages && messages.map do |message|
row = []
keys.each do |heading|
row << message[heading]
end
row
end
rows ||= []
table = Terminal::Table.new :title => title, :headings => headings do |t|
rows.each_with_index do |row, index|
t << row
t.add_separator if index < rows.length - 1
end
end
puts "\n#{table}"
end
|
.print_actions_result(actions, results) ⇒ Object
220
221
222
223
224
225
226
|
# File 'lib/gooddata/lcm/lcm2.rb', line 220
def print_actions_result(actions, results)
actions.each_with_index do |action, index|
print_action_result(action, results[index])
puts
end
nil
end
|