Class: GoodData::LCM2::SynchronizeETLsInSegment

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

Constant Summary collapse

DESCRIPTION =
'Synchronize ETLs (CC/Ruby) In Segment'
PARAMS =
define_params(self) do
  description 'Client Used for Connecting to GD'
  param :gdc_gd_client, instance_of(Type::GdClientType), required: true
end
RESULT_HEADER =

will be updated later based on the way etl synchronization

[
  :segment,
  :master_project,
  :client_id,
  :client_project,
  :status
]

Constants included from Dsl::Dsl

Dsl::Dsl::DEFAULT_OPTS, Dsl::Dsl::TYPES

Class Method Summary collapse

Methods inherited from BaseAction

check_params

Methods included from Dsl::Dsl

#define_params, #define_type, #process

Class Method Details

.call(params) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/gooddata/lcm/actions/synchronize_etls_in_segment.rb', line 29

def call(params)
  # Check if all required parameters were passed
  BaseAction.check_params(PARAMS, params)

  client = params.gdc_gd_client
  domain_name = params.organization || params.domain
  domain = client.domain(domain_name) || fail("Invalid domain name specified - #{domain_name}")
  synchronize_segments = params.synchronize.group_by do |info|
    info[:segment_id]
  end

  results = synchronize_segments.flat_map do |segment_id, synchronize|
    segment = domain.segments(segment_id)
    res = segment.synchronize_processes(
      synchronize.flat_map do |info|
        info[:to].flat_map do |to|
          to[:pid]
        end
      end
    )

    res = GoodData::Helpers.symbolize_keys(res)
    res[:syncedResult][:clients].flat_map do |item|
      item = item[:client]
      {
        segment: segment_id,
        master_project: segment.master_project_id,
        client_id: item[:id],
        client_project: item[:project].split('/').last,
        status: 'ok'
      }
    end
  end

  params.synchronize.each do |info|
    to_projects = info.to
    to_projects.each do |entry|
      pid = entry[:pid]
      to_project = client.projects(pid) || fail("Invalid 'to' project specified - '#{pid}'")
      to_project.schedules.each do |schedule|
        schedule.update_params(params.additional_params || {})
        schedule.update_hidden_params(params.additional_hidden_params || {})
        schedule.save
      end
    end
  end

  results
end