Class: Wakame::Actions::MigrateService

Inherits:
Wakame::Action show all
Defined in:
lib/wakame/actions/migrate_service.rb

Constant Summary

Constants included from AttributeHelper

AttributeHelper::CLASS_TYPE_KEY, AttributeHelper::CONVERT_CLASSES, AttributeHelper::PRIMITIVE_CLASSES

Instance Attribute Summary

Attributes inherited from Wakame::Action

#action_manager

Instance Method Summary collapse

Methods inherited from Wakame::Action

#acquire_lock, #actor_request, #agent_monitor, #all_subactions_complete?, #flush_subactions, #master, #notes, #notify, #on_canceled, #service_cluster, #status=, #subactions, #sync_actor_request, #trigger_action, #walk_subactions

Methods included from ThreadImmutable

#bind_thread, included, #target_thread, #target_thread?, #thread_check

Methods included from AttributeHelper

#dump_attrs, #retrieve_attr_attribute

Constructor Details

#initialize(svc, dest_cloud_host = nil) ⇒ MigrateService

Returns a new instance of MigrateService.

Raises:

  • (ArgumentError)


5
6
7
8
9
# File 'lib/wakame/actions/migrate_service.rb', line 5

def initialize(svc, dest_cloud_host=nil)
  raise ArgumentError unless svc.is_a?(Service::ServiceInstance)
  @svc = svc
  @dest_cloud_host = dest_cloud_host
end

Instance Method Details

#on_failedObject



36
37
38
39
40
41
42
43
# File 'lib/wakame/actions/migrate_service.rb', line 36

def on_failed
  StatusDB.barrier {
    @svc.update_status(Service::STATUS_FAIL)
    if @new_svc
      @new_svc.update_status(Service::STATUS_FAIL)
    end
  }
end

#runObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/wakame/actions/migrate_service.rb', line 11

def run
  acquire_lock { |list|
    list << @svc.resource.class
  }

  if @svc.status == Service::STATUS_MIGRATING 
    Wakame.log.info("Ignore to migrate the service as is already MIGRATING: #{@svc.resource.class}")
    return
  end

  StatusDB.barrier {
    @svc.update_status(Service::STATUS_MIGRATING)
  }
  if @svc.resource.duplicable
    clone_service()
    flush_subactions
    trigger_action(StopService.new(@svc))
  else
    trigger_action(StopService.new(@svc))
    flush_subactions
    clone_service()
  end
  flush_subactions
end