Class: GoodData::LCM2::MigrateGdcDateDimension
- Inherits:
-
BaseAction
show all
- Defined in:
- lib/gooddata/lcm/actions/migrate_gdc_date_dimension.rb
Constant Summary
collapse
- DESCRIPTION =
'Migrate Gdc Date Dimension'
- DATE_DIMENSION_CUSTOM_V2 =
'urn:custom_v2:date'
- DATE_DIMENSION_OLD =
%w[urn:gooddata:date urn:custom:date]
- PARAMS =
define_params(self) do
description 'Client Used for Connecting to GD'
param :gdc_gd_client, instance_of(Type::GdClientType), required: true
description 'Specifies how to synchronize LDM and resolve possible conflicts'
param :synchronize_ldm, instance_of(Type::SynchronizeLDM), required: false, default: 'diff_against_master_with_fallback'
description 'Synchronization Info'
param :synchronize, array_of(instance_of(Type::SynchronizationInfoType)), required: true, generated: true
description 'Abort on error'
param :abort_on_error, instance_of(Type::StringType), required: false
description 'Logger'
param :gdc_logger, instance_of(Type::GdLogger), required: false
description 'Collect synced status'
param :collect_synced_status, instance_of(Type::BooleanType), required: false
description 'Sync failed list'
param :sync_failed_list, instance_of(Type::HashType), required: false
description 'Number Of Threads'
param :number_of_threads_migrate_dates, instance_of(Type::StringType), required: false, default: '10'
end
i[from to status]
Constants inherited
from BaseAction
BaseAction::FAILED_CLIENTS, BaseAction::FAILED_PROJECTS, BaseAction::FAILED_SEGMENTS, BaseAction::SYNC_FAILED_LIST
Constants included
from Dsl::Dsl
Dsl::Dsl::DEFAULT_OPTS, Dsl::Dsl::TYPES
Class Method Summary
collapse
Methods inherited from BaseAction
add_failed_client, add_failed_project, add_failed_segment, add_new_clients_to_project_client_mapping, check_params, collect_synced_status, continue_on_error, print_result, process_failed_project, process_failed_projects, sync_failed_client, sync_failed_project, sync_failed_segment, without_check
Methods included from Dsl::Dsl
#define_params, #define_type, #process
Class Method Details
.call(params) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/gooddata/lcm/actions/migrate_gdc_date_dimension.rb', line 42
def call(params)
results = []
params.synchronize.map do |segment_info|
next if sync_failed_segment(segment_info[:segment_id], params)
result = migrate_date_dimension(params, segment_info)
results.concat(result)
end
{
results: results
}
end
|
.contain_v2?(blueprint) ⇒ Boolean
132
133
134
|
# File 'lib/gooddata/lcm/actions/migrate_gdc_date_dimension.rb', line 132
def contain_v2?(blueprint)
get_date_dimensions(blueprint).any? { |e| e[:urn] == DATE_DIMENSION_CUSTOM_V2 }
end
|
.get_date_dimension(blueprint, id) ⇒ Object
Get date dimension from blue print. Return nil if date dimension not existing
137
138
139
140
|
# File 'lib/gooddata/lcm/actions/migrate_gdc_date_dimension.rb', line 137
def get_date_dimension(blueprint, id)
date_dimensions = get_date_dimensions(blueprint)
date_dimensions.find { |d| d[:id] == id }
end
|
.get_date_dimensions(blueprint) ⇒ Object
142
143
144
|
# File 'lib/gooddata/lcm/actions/migrate_gdc_date_dimension.rb', line 142
def get_date_dimensions(blueprint)
GoodData::Model::ProjectBlueprint.date_dimensions(blueprint)
end
|
.get_upgrade_dates(src_blueprint, dest_blueprint) ⇒ Object
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/gooddata/lcm/actions/migrate_gdc_date_dimension.rb', line 100
def get_upgrade_dates(src_blueprint, dest_blueprint)
dest_dates = get_date_dimensions(dest_blueprint) if dest_blueprint
src_dates = get_date_dimensions(src_blueprint) if src_blueprint
upgrade_datasets = []
return upgrade_datasets if dest_dates.empty? || src_dates.empty?
dest_dates.each do |dest|
src_dim = get_date_dimension(src_blueprint, dest[:id])
next unless src_dim
upgrade_datasets << src_dim[:identifier] if upgrade?(src_dim, dest) && src_dim[:identifier]
end
upgrade_datasets
end
|
.get_upgrade_message(upgrade_datasets) ⇒ Object
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/gooddata/lcm/actions/migrate_gdc_date_dimension.rb', line 117
def get_upgrade_message(upgrade_datasets)
{
upgrade: {
dateDatasets: {
upgrade: "exact",
datasets: upgrade_datasets
}
}
}
end
|
.migrate_date_dimension(params, segment_info) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/gooddata/lcm/actions/migrate_gdc_date_dimension.rb', line 56
def migrate_date_dimension(params, segment_info)
results = []
client = params.gdc_gd_client
number_of_threads = Integer(params.number_of_threads_migrate_dates || '10')
GoodData.logger.info "Number of threads using migration dates #{number_of_threads}" if number_of_threads != 10
latest_blueprint = segment_info[:from_blueprint]
return results unless contain_v2?(latest_blueprint)
previous_blueprint = segment_info[:previous_master]&.blueprint
master_upgrade_datasets = get_upgrade_dates(latest_blueprint, previous_blueprint) if params[:synchronize_ldm].downcase == 'diff_against_master' && previous_blueprint
unless master_upgrade_datasets&.empty?
collect_synced_status = collect_synced_status(params)
failed_projects = ThreadSafe::Array.new
segment_info[:to].pmap(number_of_threads) do |entry|
pid = entry[:pid]
next if sync_failed_project(pid, params)
to_project = client.projects(pid) || fail("Invalid 'to' project specified - '#{pid}'")
GoodData.logger.info "Migrating date dimension, project: '#{to_project.title}', PID: #{pid}"
to_blueprint = to_project.blueprint
upgrade_datasets = get_upgrade_dates(latest_blueprint, to_blueprint)
next if upgrade_datasets.empty?
message = get_upgrade_message(upgrade_datasets)
failed_message = "Failed to migrate date dimension for project #{pid}"
update_status = to_project.upgrade_custom_v2(message)
process_failed_project(pid, failed_message, failed_projects, collect_synced_status) if collect_synced_status && update_status != 'OK'
results << {
from: segment_info[:from],
to: pid,
status: update_status
}
end
process_failed_projects(failed_projects, short_name, params) if collect_synced_status
end
results
end
|
.upgrade?(src_dim, dest_dim) ⇒ Boolean
128
129
130
|
# File 'lib/gooddata/lcm/actions/migrate_gdc_date_dimension.rb', line 128
def upgrade?(src_dim, dest_dim)
src_dim[:urn] == DATE_DIMENSION_CUSTOM_V2 && DATE_DIMENSION_OLD.any? { |e| dest_dim[:urn] == e }
end
|