|
| 1 | +# encoding: UTF-8 |
| 2 | +# frozen_string_literal: true |
| 3 | +# |
| 4 | +# Copyright (c) 2010-2017 GoodData Corporation. All rights reserved. |
| 5 | +# This source code is licensed under the BSD-style license found in the |
| 6 | +# LICENSE file in the root directory of this source tree. |
| 7 | + |
| 8 | +require_relative 'base_action' |
| 9 | + |
| 10 | +module GoodData |
| 11 | + module LCM2 |
| 12 | + class SetMasterProject < BaseAction |
| 13 | + DESCRIPTION = 'Set master project' |
| 14 | + |
| 15 | + PARAMS = define_params(self) do |
| 16 | + description 'Organization Name' |
| 17 | + param :organization, instance_of(Type::StringType), required: false |
| 18 | + |
| 19 | + description 'Domain' |
| 20 | + param :domain, instance_of(Type::StringType), required: false |
| 21 | + |
| 22 | + description 'ADS Client' |
| 23 | + param :ads_client, instance_of(Type::AdsClientType), required: false |
| 24 | + |
| 25 | + description 'Table Name' |
| 26 | + param :release_table_name, instance_of(Type::StringType), required: false |
| 27 | + |
| 28 | + description 'Segments to manage' |
| 29 | + param :segments, array_of(instance_of(Type::SegmentType)), required: true |
| 30 | + |
| 31 | + description 'DataProduct to manage' |
| 32 | + param :data_product, instance_of(Type::GDDataProductType), required: false |
| 33 | + |
| 34 | + description 'Released master project should be used in next rollout' |
| 35 | + param :set_master_project, instance_of(Type::StringType), required: false |
| 36 | + end |
| 37 | + |
| 38 | + class << self |
| 39 | + def call(params) |
| 40 | + results = [] |
| 41 | + domain_name = params.organization || params.domain |
| 42 | + data_product = params.data_product |
| 43 | + params.segments.each do |segment_in| |
| 44 | + version = get_latest_version(params, domain_name, data_product.data_product_id, segment_in.segment_id) + 1 |
| 45 | + segment_in[:data_product_id] = data_product.data_product_id |
| 46 | + segment_in[:master_pid] = params.set_master_project |
| 47 | + segment_in[:version] = version |
| 48 | + segment_in[:timestamp] = Time.now.utc.iso8601 |
| 49 | + |
| 50 | + results << { |
| 51 | + data_product_id: data_product.data_product_id, |
| 52 | + segment_id: segment_in.segment_id, |
| 53 | + version: version |
| 54 | + } |
| 55 | + end |
| 56 | + results |
| 57 | + end |
| 58 | + |
| 59 | + def get_latest_version(params, domain_name, data_product_id, segment_id) |
| 60 | + if params.ads_client |
| 61 | + current_master = GoodData::LCM2::Helpers.latest_master_project_from_ads( |
| 62 | + params.release_table_name, |
| 63 | + params.ads_client, |
| 64 | + segment_id |
| 65 | + ) |
| 66 | + else |
| 67 | + current_master = GoodData::LCM2::Helpers.latest_master_project_from_nfs(domain_name, data_product_id, segment_id) |
| 68 | + end |
| 69 | + return 0 unless current_master |
| 70 | + |
| 71 | + current_master[:version].to_i |
| 72 | + end |
| 73 | + end |
| 74 | + end |
| 75 | + end |
| 76 | +end |
0 commit comments