Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ha dont make halt #623

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions dcmgr/lib/dcmgr/constants/instance.rb
Expand Up @@ -12,6 +12,7 @@ module Dcmgr::Constants::Instance
STATE_STOPPING = "stopping".freeze
STATE_STOPPED = "stopped".freeze
STATE_INITIALIZING = "initializing".freeze
STATE_MIGRATING = "migrating".freeze

STATES=[STATE_INITIALIZING,
STATE_SCHEDULING,
Expand All @@ -23,9 +24,11 @@ module Dcmgr::Constants::Instance
STATE_HALTING,
STATE_HALTED,
STATE_STOPPING,
STATE_STOPPED].freeze
STATE_STOPPED,
STATE_MIGRATING,
].freeze

MIGRATION_STATES=[STATE_RUNNING].freeze
MIGRATION_STATES=[STATE_RUNNING, STATE_HALTED].freeze

STATUS_ONLINE = "online".freeze
STATUS_OFFLINE = "offline".freeze
Expand Down
26 changes: 18 additions & 8 deletions dcmgr/lib/dcmgr/endpoints/12.03/instances.rb
Expand Up @@ -727,9 +727,7 @@ def set_monitoring_parameters(instance)

put '/:id/move' do
instance = find_by_uuid(:Instance, params[:id])
case instance.state
when *C::Instance::MIGRATION_STATES
else
if ! C::Instance::MIGRATION_STATES.member?(instance.state.to_s)
raise E::InvalidInstanceState, "Unsupported instance state for migration: #{instance.state}"
end

Expand All @@ -742,13 +740,25 @@ def set_monitoring_parameters(instance)
raise "host_node_id has to be set"
end

instance.state = 'migrating'
instance.state = C::Instance::STATE_MIGRATING
case instance.state
when C::Instance::RUNNING
on_after_commit do
Dcmgr.messaging.submit("migration-handle.#{dest_host_node.node_id}", 'run_vol_store',
instance.canonical_uuid)
end
when C::Instance::HALTED
# switch host node association.
instance.host_node = dest_host_node
on_after_commit do
Dcmgr.messaging.submit("migration-handle.#{dest_host_node.node_id}", 'initialize_halted_instance',
instance.canonical_uuid)
end
else
raise "Invalid instance state to start migration: #{instance.canonical_uuid}: #{instance.state}"
end
instance.save_changes

on_after_commit do
Dcmgr.messaging.submit("migration-handle.#{dest_host_node.node_id}", 'run_vol_store',
instance.canonical_uuid)
end
respond_with({:instance_id=>instance.canonical_uuid,
})
end
Expand Down
81 changes: 48 additions & 33 deletions dcmgr/lib/dcmgr/node_modules/scheduler.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions dcmgr/lib/dcmgr/rpc/hva_handler.rb
Expand Up @@ -267,6 +267,9 @@ def setup_shared_volume_instance(&blk)
:attach_volume_to_host, [@hva_ctx, volume_id])
end
}

setup_metadata_drive
check_interface
end
end

Expand Down Expand Up @@ -368,9 +371,6 @@ def wait_volumes_available
rpc.request('sta-collector', 'update_volume', volume_id, {:state=>:attaching, :attached_at=>nil})
end

setup_metadata_drive

check_interface
task_session.invoke(@hva_ctx.hypervisor_driver_class,
:run_instance, [@hva_ctx])
# Node specific instance_started event for netfilter and general instance_started event for openflow
Expand Down
18 changes: 16 additions & 2 deletions dcmgr/lib/dcmgr/rpc/migration_handler.rb
Expand Up @@ -20,9 +20,7 @@ class MigrationHandler < EndpointBuilder
# incoming VM does not have to deal with chaging instance &
# volume state.
setup_shared_volume_instance
setup_metadata_drive

check_interface
dest_params = task_session.invoke(@hva_ctx.hypervisor_driver_class,
:run_migration_instance, [@hva_ctx])
@hva_ctx.logger.info("Started migration waiting instance: #{dest_params}")
Expand Down Expand Up @@ -65,6 +63,22 @@ class MigrationHandler < EndpointBuilder
}
}

job :initialize_halted_instance, proc {
@hva_ctx = HvaContext.new(self)
@inst_id = request.args[0]

@hva_ctx.logger.info("Start to initialize instance")
@inst = rpc.request('hva-collector', 'get_instance', @inst_id)

unless %w(migrating).member?(@inst[:state].to_s)
raise "Invalid instance state: #{@inst[:state]}"
end
# it does not need to handle volume's state here.
setup_volume_instance
update_instance_state({:state=>:halted})
@hva_ctx.logger.info("Finish to initialize instance")
}

def event
@event ||= Isono::NodeModules::EventChannel.new(@node)
end
Expand Down
18 changes: 18 additions & 0 deletions documents/instance-state.plantuml
@@ -0,0 +1,18 @@
@startuml
title Wakame-vdc Instance State Diagram

[*] --> initializing
initializing --> starting
starting --> running
running --> stopping : poweroff
stopping --> halted
halted --> starting : poweron
running --> migrating : move (hot)
migrating --> running : move (hot)
halted --> migrating : move (cold)
migrating --> halted : move (cold)
running --> shuttingdown : terminate
shuttingdown --> terminated
terminated --> [*]

@enduml