Class: GoodData::LCM2::SetMasterProject

Inherits:
BaseAction show all
Defined in:
lib/gooddata/lcm/actions/set_master_project.rb

Constant Summary collapse

DESCRIPTION =
'Set master project'
PARAMS =
define_params(self) do
  description 'Organization Name'
  param :organization, instance_of(Type::StringType), required: false

  description 'Domain'
  param :domain, instance_of(Type::StringType), required: false

  description 'ADS Client'
  param :ads_client, instance_of(Type::AdsClientType), required: false

  description 'Table Name'
  param :release_table_name, instance_of(Type::StringType), required: false

  description 'Segments to manage'
  param :segments, array_of(instance_of(Type::SegmentType)), required: true

  description 'DataProduct to manage'
  param :data_product, instance_of(Type::GDDataProductType), required: false

  description 'Released master project should be used in next rollout'
  param :set_master_project, instance_of(Type::StringType), required: false
end

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



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/gooddata/lcm/actions/set_master_project.rb', line 39

def call(params)
  results = []
  domain_name = params.organization || params.domain
  data_product = params.data_product
  params.segments.each do |segment_in|
    version = get_latest_version(params, domain_name, data_product.data_product_id, segment_in.segment_id) + 1
    segment_in[:data_product_id] = data_product.data_product_id
    segment_in[:master_pid] = params.set_master_project
    segment_in[:version] = version
    segment_in[:timestamp] = Time.now.utc.iso8601

    results << {
      data_product_id: data_product.data_product_id,
      segment_id: segment_in.segment_id,
      version: version
    }
  end
  results
end

.get_latest_version(params, domain_name, data_product_id, segment_id) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/gooddata/lcm/actions/set_master_project.rb', line 59

def get_latest_version(params, domain_name, data_product_id, segment_id)
  if params.ads_client
    current_master = GoodData::LCM2::Helpers.latest_master_project_from_ads(
      params.release_table_name,
      params.ads_client,
      segment_id
    )
  else
    current_master = GoodData::LCM2::Helpers.latest_master_project_from_nfs(domain_name, data_product_id, segment_id)
  end
  return 0 unless current_master

  current_master[:version].to_i
end