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/actions/help.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/any.rb,
lib/gooddata/lcm/types/special/enum.rb,
lib/gooddata/lcm/user_bricks_helper.rb,
lib/gooddata/lcm/actions/base_action.rb,
lib/gooddata/lcm/actions/hello_world.rb,
lib/gooddata/lcm/helpers/tags_helper.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/actions/collect_meta.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/purge_clients.rb,
lib/gooddata/lcm/types/class/gd_client.rb,
lib/gooddata/lcm/types/class/gd_logger.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/types/class/gd_product.rb,
lib/gooddata/lcm/types/class/gd_project.rb,
lib/gooddata/lcm/types/class/smart_hash.rb,
lib/gooddata/lcm/actions/collect_clients.rb,
lib/gooddata/lcm/actions/segments_filter.rb,
lib/gooddata/lcm/actions/synchronize_cas.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/execute_schedules.rb,
lib/gooddata/lcm/actions/provision_clients.rb,
lib/gooddata/lcm/actions/synchronize_users.rb,
lib/gooddata/lcm/actions/collect_ca_metrics.rb,
lib/gooddata/lcm/actions/set_master_project.rb,
lib/gooddata/lcm/actions/collect_ldm_objects.rb,
lib/gooddata/lcm/actions/synchronize_clients.rb,
lib/gooddata/lcm/helpers/safe_failure_helper.rb,
lib/gooddata/lcm/types/complex/release_query.rb,
lib/gooddata/lcm/actions/collect_data_product.rb,
lib/gooddata/lcm/actions/ensure_release_table.rb,
lib/gooddata/lcm/actions/update_release_table.rb,
lib/gooddata/lcm/helpers/release_table_helper.rb,
lib/gooddata/lcm/actions/synchronize_processes.rb,
lib/gooddata/lcm/actions/synchronize_schedules.rb,
lib/gooddata/lcm/actions/update_metric_formats.rb,
lib/gooddata/lcm/actions/collect_tagged_objects.rb,
lib/gooddata/lcm/actions/create_segment_masters.rb,
lib/gooddata/lcm/actions/collect_client_projects.rb,
lib/gooddata/lcm/actions/collect_segment_clients.rb,
lib/gooddata/lcm/actions/synchronize_label_types.rb,
lib/gooddata/lcm/actions/synchronize_tag_objects.rb,
lib/gooddata/lcm/actions/synchronize_user_groups.rb,
lib/gooddata/lcm/types/complex/update_preference.rb,
lib/gooddata/lcm/actions/synchronize_new_segments.rb,
lib/gooddata/lcm/actions/synchronize_user_filters.rb,
lib/gooddata/lcm/types/complex/users_brick_config.rb,
lib/gooddata/lcm/actions/collect_users_brick_users.rb,
lib/gooddata/lcm/actions/import_object_collections.rb,
lib/gooddata/lcm/actions/synchronize_color_palette.rb,
lib/gooddata/lcm/actions/migrate_gdc_date_dimension.rb,
lib/gooddata/lcm/types/complex/synchronization_info.rb,
lib/gooddata/lcm/types/special/enum/synchronize_ldm.rb,
lib/gooddata/lcm/actions/synchronize_etls_in_segment.rb,
lib/gooddata/lcm/actions/synchronize_dataset_mappings.rb,
lib/gooddata/lcm/actions/ensure_technical_users_domain.rb,
lib/gooddata/lcm/actions/ensure_technical_users_project.rb,
lib/gooddata/lcm/actions/collect_dynamic_schedule_params.rb,
lib/gooddata/lcm/actions/rename_existing_client_projects.rb,
lib/gooddata/lcm/actions/collect_multiple_projects_column.rb,
lib/gooddata/lcm/actions/synchronize_attribute_drillpaths.rb
Defined Under Namespace
Modules: Dsl, Type
Classes: ApplyCustomMaql, AssociateClients, BaseAction, CollectClientProjects, CollectClients, CollectComputedAttributeMetrics, CollectDataProduct, CollectDymanicScheduleParams, CollectLdmObjects, CollectMeta, CollectMultipleProjectsColumn, CollectSegmentClients, CollectSegments, CollectTaggedObjects, CollectUsersBrickUsers, CreateSegmentMasters, EnsureReleaseTable, EnsureTechnicalUsersDomain, EnsureTechnicalUsersProject, ExecuteSchedules, HelloWorld, Help, Helpers, ImportObjectCollections, MigrateGdcDateDimension, ProvisionClients, PurgeClients, RenameExistingClientProjects, SegmentsFilter, SetMasterProject, SmartHash, SynchronizeAttributeDrillpath, SynchronizeClients, SynchronizeColorPalette, SynchronizeComputedAttributes, SynchronizeDataSetMapping, SynchronizeETLsInSegment, SynchronizeLabelTypes, SynchronizeLdm, SynchronizeMeta, SynchronizeNewSegments, SynchronizeProcesses, SynchronizeSchedules, SynchronizeTagObjects, SynchronizeUserFilters, SynchronizeUserGroups, SynchronizeUsers, UpdateMetricFormats, UpdateReleaseTable, UserBricksHelper
Constant Summary
collapse
- MODES =
{
hello: [
HelloWorld
],
help: [
Help
],
release: [
EnsureReleaseTable,
CollectDataProduct,
SegmentsFilter,
CreateSegmentMasters,
EnsureTechnicalUsersDomain,
EnsureTechnicalUsersProject,
SynchronizeLdm,
CollectLdmObjects,
CollectMeta,
CollectTaggedObjects,
CollectComputedAttributeMetrics,
ImportObjectCollections,
SynchronizeComputedAttributes,
SynchronizeDataSetMapping,
SynchronizeProcesses,
SynchronizeSchedules,
SynchronizeColorPalette,
SynchronizeUserGroups,
SynchronizeNewSegments,
UpdateReleaseTable
],
release_set_master_project: [
EnsureReleaseTable,
CollectDataProduct,
SegmentsFilter,
SetMasterProject,
UpdateReleaseTable
],
provision: [
EnsureReleaseTable,
CollectDataProduct,
CollectSegments,
CollectClientProjects,
PurgeClients,
CollectClients,
AssociateClients,
RenameExistingClientProjects,
ProvisionClients,
UpdateMetricFormats,
EnsureTechnicalUsersDomain,
EnsureTechnicalUsersProject,
CollectDymanicScheduleParams,
SynchronizeDataSetMapping,
SynchronizeETLsInSegment
],
rollout: [
EnsureReleaseTable,
CollectDataProduct,
CollectSegments,
CollectSegmentClients,
EnsureTechnicalUsersDomain,
EnsureTechnicalUsersProject,
SynchronizeLdm,
SynchronizeDataSetMapping,
MigrateGdcDateDimension,
SynchronizeClients,
UpdateMetricFormats,
SynchronizeComputedAttributes,
CollectDymanicScheduleParams,
SynchronizeETLsInSegment
],
users: [
CollectDataProduct,
CollectMultipleProjectsColumn,
CollectSegments,
SynchronizeUsers
],
user_filters: [
CollectDataProduct,
CollectMultipleProjectsColumn,
CollectUsersBrickUsers,
CollectSegments,
SynchronizeUserFilters
],
schedules_execution: [
ExecuteSchedules
]
}
- MODE_NAMES =
MODES.keys
Class Method Summary
collapse
Class Method Details
.check_unused_params(actions, params) ⇒ Object
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
|
# File 'lib/gooddata/lcm/lcm2.rb', line 411
def check_unused_params(actions, params)
default_params = [
:client_gdc_hostname,
:client_gdc_protocol,
:fail_early,
:gdc_logger,
:gdc_password,
:gdc_username,
:strict
]
action_params = actions.map do |action|
action.const_get(:PARAMS).keys.map(&:downcase)
end
action_params.flatten!.uniq!
param_names = params.keys.map(&:downcase)
unused_params = param_names - (action_params + default_params)
if unused_params.any?
GoodData.logger.warn("Following params are not used by any action: #{JSON.pretty_generate(unused_params)}")
rows = []
actions.each do |action|
action_params = action.const_get(:PARAMS)
action_params.each do |_k, v|
rows << [action.short_name, v[:name], v[:description], v[:type].class.short_name]
end
end
table = Terminal::Table.new :headings => ['Action', 'Parameter', 'Description', 'Parameter Type'], :rows => rows
GoodData.logger.info("\n#{table}")
end
end
|
.convert_params(params) ⇒ Object
175
176
177
178
179
180
181
182
183
184
185
|
# File 'lib/gooddata/lcm/lcm2.rb', line 175
def convert_params(params)
GoodData::Helpers.symbolize_keys!(params)
params.keys.each do |k|
params[k.downcase] = params[k]
end
params.reject! do |k, _|
k.downcase != k
end
convert_to_smart_hash(params)
end
|
.convert_to_smart_hash(params) ⇒ Object
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
# File 'lib/gooddata/lcm/lcm2.rb', line 187
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
207
208
209
210
211
212
213
214
215
|
# File 'lib/gooddata/lcm/lcm2.rb', line 207
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
|
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
|
# File 'lib/gooddata/lcm/lcm2.rb', line 281
def perform(mode, params = {})
params = convert_params(params)
GoodData.gd_logger.brick = mode
final_mode = if params.set_master_project && mode == 'release'
'release_set_master_project'
else
mode
end
actions = get_mode_actions(final_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
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
skip_actions = (params.skip_actions || [])
actions = actions.reject do |action|
skip_actions.include?(action.name.split('::').last)
end
sync_mode = params.fetch(:sync_mode, nil)
if mode == 'users' && %w[add_to_organization remove_from_organization].include?(sync_mode)
actions = actions.reject do |action|
%w[CollectDataProduct CollectSegments].include?(action.name.split('::').last)
end
end
check_unused_params(actions, params)
print_action_names(mode, actions)
errors = []
results = []
actions.each do |action|
GoodData.logger.info("\n")
begin
out = run_action action, params
rescue Exception => e errors << {
action: action,
err: e,
backtrace: e.backtrace
}
break if fail_early
results << nil
end
next unless out
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)
print_action_result(action, res)
results << res
end
brick_results = {}
actions.each_with_index do |action, index|
brick_results[action.short_name] = results[index]
end
result = {
actions: actions.map(&:short_name),
results: brick_results,
params: params,
success: errors.empty?
}
if errors.any?
error_message = JSON.pretty_generate(errors)
if strict_mode
raise GoodData::LcmExecutionError.new(errors[0][:err], error_message)
else
GoodData.logger.error(error_message)
end
end
result
end
|
.print_action_names(mode, actions) ⇒ Object
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
# File 'lib/gooddata/lcm/lcm2.rb', line 217
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
GoodData.logger.info("\n#{table}")
end
|
.print_action_result(action, messages) ⇒ Object
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
|
# File 'lib/gooddata/lcm/lcm2.rb', line 236
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|
unless message
GoodData.logger.warn("Found an empty message in the results of the #{action.name} action")
next
end
row = []
keys.each do |heading|
row << message[heading]
end
row
end
rows ||= []
rows.compact!
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
GoodData.logger.info("\n#{table}")
end
|
.print_actions_result(actions, results) ⇒ Object
273
274
275
276
277
278
279
|
# File 'lib/gooddata/lcm/lcm2.rb', line 273
def print_actions_result(actions, results)
actions.each_with_index do |action, index|
print_action_result(action, results[index])
GoodData.logger.info
end
nil
end
|
.run_action(action, params) ⇒ Object