Class: ThreeScaleToolbox::Commands::ServiceCommand::CopyCommand::CreateOrUpdateTargetServiceTask

Inherits:
Object
  • Object
show all
Includes:
Task
Defined in:
lib/3scale_toolbox/commands/service_command/copy_command/create_or_update_service_task.rb

Instance Attribute Summary

Attributes included from Task

#context

Instance Method Summary collapse

Methods included from Task

#delete_mapping_rules, #find_source_service, #force_delete_mapping_rules, #initialize, #invalidate_target_methods, #invalidate_target_metrics, #option_target_system_name, #source, #source_hits, #source_methods, #source_metrics, #source_metrics_and_methods, #source_remote, #source_service_ref, #target, #target=, #target_hits, #target_methods, #target_metrics, #target_metrics_and_methods, #target_remote

Instance Method Details

#callObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/3scale_toolbox/commands/service_command/copy_command/create_or_update_service_task.rb', line 8

def call
  service = Entities::Service.find(remote: target_remote,
                                   ref: target_service_ref)
  if service == source
    raise ThreeScaleToolbox::Error, 'Source and destination services are the same: ' \
      "ID: #{source.id} system_name: #{source.attrs['system_name']}"
  end

  if service.nil?
    service = Entities::Service.create(remote: target_remote,
                                       service_params: create_attrs)
    # Notify that mapping rules should be deleted before being copied
    force_delete_mapping_rules
  else
    service.update update_attrs
  end

  # assign target service for other tasks to have it available
  self.target = service

  puts "new service id #{service.id}"
end