lib/gooddata/lcm/actions/create_segment_masters.rb in gooddata-0.6.51 vs lib/gooddata/lcm/actions/create_segment_masters.rb in gooddata-0.6.52

- old
+ new

@@ -13,33 +13,33 @@ PARAMS = define_params(self) do description 'Client Used for Connecting to GD' param :gdc_gd_client, instance_of(Type::GdClientType), required: true + description 'Development Client Used for Connecting to GD' + param :development_client, instance_of(Type::GdClientType), required: true + description 'Organization Name' param :organization, instance_of(Type::StringType), required: true description 'ADS Client' param :ads_client, instance_of(Type::AdsClientType), required: true - # description 'Queries Used' - # param :query, instance_of(Type::ReleaseQueryType), required: false - description 'Segments to manage' param :segments, array_of(instance_of(Type::SegmentType)), required: true description 'Tokens' param :tokens, instance_of(Type::TokensType), required: true + + description 'Table Name' + param :release_table_name, instance_of(Type::StringType), required: false end DEFAULT_TABLE_NAME = 'LCM_RELEASE' class << self def call(params) - # Check if all required parameters were passed - BaseAction.check_params(PARAMS, params) - results = [] client = params.gdc_gd_client development_client = params.development_client @@ -48,14 +48,11 @@ domain_segments = domain.segments # TODO: Support for 'per segment' provisioning segments = params.segments - # Output param with info about which projects should be synchronized - synchronize_projects = [] - - segments.map do |segment_in| # rubocop:disable Metrics/BlockLength + synchronize_projects = segments.map do |segment_in| # rubocop:disable Metrics/BlockLength segment_id = segment_in.segment_id development_pid = segment_in.development_pid driver = segment_in.driver.downcase token = params.tokens[driver.to_sym] || fail("Token for driver '#{driver}' was not specified") @@ -73,36 +70,20 @@ # Create new master project params.gdc_logger.info "Creating master project - name: '#{master_name}' development_project: '#{development_pid}', segment: '#{segment_id}', driver: '#{driver}'" project = client.create_project(title: master_name, auth_token: token, driver: driver == 'vertica' ? 'vertica' : 'Pg') - # Do we have hash with synchronization info for current development project? - synchronize_info = synchronize_projects.find do |info| - info[:from] == development_pid - end - - # If not, create new one - unless synchronize_info - synchronize_info = { - segment: segment_id, - from: development_pid, - to: [] - } - synchronize_projects << synchronize_info - end - - # Add target project (new master for segment) into synchronization info - synchronize_info[:to] << { pid: project.pid } - # Does segment exists? If not, create new one and set initial master if segment segment_in[:is_new] = false + status = 'untouched' else params.gdc_logger.info "Creating segment #{segment_id}, master #{project.pid}" segment = domain.create_segment(segment_id: segment_id, master_project: project) segment.synchronize_clients segment_in[:is_new] = true + status = 'created' end master_project = nil begin @@ -113,10 +94,11 @@ if master_project.nil? || master_project.deleted? segment.master_project = project segment.save segment_in[:is_new] = true + status = 'modified' end segment_in[:master_pid] = project.pid segment_in[:version] = version segment_in[:timestamp] = Time.now.utc.iso8601 @@ -129,13 +111,17 @@ segment_id: segment_id, name: master_name, development_pid: development_pid, master_pid: project.pid, driver: driver, - status: 'created' + status: status } - project + { + segment: segment_id, + from: development_pid, + to: [{ pid: project.pid }] + } end # Return results { results: results,