You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ke...@apache.org on 2013/06/13 19:06:13 UTC
git commit: updated refs/heads/vmsync to d52e0c2
Updated Branches:
refs/heads/vmsync 0f26d5a05 -> d52e0c2eb
Add out-of-band sync for powner on events
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/d52e0c2e
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/d52e0c2e
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/d52e0c2e
Branch: refs/heads/vmsync
Commit: d52e0c2ebdd7bf81ee91f43c6c8e285f04cdcf9e
Parents: 0f26d5a
Author: Kelven Yang <ke...@gmail.com>
Authored: Thu Jun 13 10:05:59 2013 -0700
Committer: Kelven Yang <ke...@gmail.com>
Committed: Thu Jun 13 10:05:59 2013 -0700
----------------------------------------------------------------------
api/src/com/cloud/vm/VirtualMachine.java | 10 ++++
.../com/cloud/vm/VirtualMachineManagerImpl.java | 60 ++++++++++++++++++--
2 files changed, 65 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d52e0c2e/api/src/com/cloud/vm/VirtualMachine.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/vm/VirtualMachine.java b/api/src/com/cloud/vm/VirtualMachine.java
index 58ecdc1..3ac9aed 100755
--- a/api/src/com/cloud/vm/VirtualMachine.java
+++ b/api/src/com/cloud/vm/VirtualMachine.java
@@ -104,6 +104,12 @@ public interface VirtualMachine extends RunningOn, ControlledEntity, Identity, I
s_fsm.addTransition(State.Expunging, VirtualMachine.Event.ExpungeOperation, State.Expunging);
s_fsm.addTransition(State.Error, VirtualMachine.Event.DestroyRequested, State.Expunging);
s_fsm.addTransition(State.Error, VirtualMachine.Event.ExpungeOperation, State.Expunging);
+
+ s_fsm.addTransition(State.Stopping, VirtualMachine.Event.FollowAgentPowerOnReport, State.Running);
+ s_fsm.addTransition(State.Stopped, VirtualMachine.Event.FollowAgentPowerOnReport, State.Running);
+ s_fsm.addTransition(State.Running, VirtualMachine.Event.FollowAgentPowerOnReport, State.Running);
+
+ s_fsm.addTransition(State.Migrating, VirtualMachine.Event.FollowAgentPowerOnReport, State.Running);
}
public static boolean isVmStarted(State oldState, Event e, State newState) {
@@ -166,6 +172,10 @@ public interface VirtualMachine extends RunningOn, ControlledEntity, Identity, I
OperationFailedToError,
OperationRetry,
AgentReportMigrated,
+
+ // added for new VMSync logic
+ FollowAgentPowerOnReport,
+ FollowAgentPowerOffReport,
};
public enum Type {
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d52e0c2e/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
index af29307..e50027d 100755
--- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -2646,6 +2646,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
*/
}
+
+ // take the chance to scan stalled VM
+ scanStalledVMInTransitionState(agentId);
processed = true;
}
}
@@ -3411,6 +3414,10 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
}
+ //
+ // PowerState report handling for out-of-band changes and handling of left-over transitional VM states
+ //
+
@MessageHandler(topic=TopicConstants.VM_POWER_STATE)
private void HandlePownerStateReport(Object target, String subject, String senderAddress, Object args) {
assert(args != null);
@@ -3447,33 +3454,60 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
}
private void HandlePowerOnReportWithNoPendingJobsOnVM(VMInstanceVO vm) {
-
- // TODO :
+ //
// 1) handle left-over transitional VM states
// 2) handle out of band VM live migration
// 3) handle out of sync stationary states, marking VM from Stopped to Running with
// alert messages
-
+ //
switch(vm.getState()) {
- case Starting:
+ case Starting :
+ try {
+ stateTransitTo(vm, VirtualMachine.Event.FollowAgentPowerOnReport, vm.getPowerHostId());
+ } catch(NoTransitionException e) {
+ s_logger.warn("Unexpected VM state transition exception, race-condition?", e);
+ }
+ // TODO we need to alert admin or user about this risky state transition
break;
case Running :
+ try {
+ if(vm.getHostId() != null && vm.getHostId().longValue() != vm.getPowerHostId().longValue())
+ s_logger.info("Detected out of band VM migration from host " + vm.getHostId() + " to host " + vm.getPowerHostId());
+ stateTransitTo(vm, VirtualMachine.Event.FollowAgentPowerOnReport, vm.getPowerHostId());
+ } catch(NoTransitionException e) {
+ s_logger.warn("Unexpected VM state transition exception, race-condition?", e);
+ }
break;
case Stopping :
case Stopped :
+ try {
+ stateTransitTo(vm, VirtualMachine.Event.FollowAgentPowerOnReport, vm.getPowerHostId());
+ } catch(NoTransitionException e) {
+ s_logger.warn("Unexpected VM state transition exception, race-condition?", e);
+ }
+ // TODO we need to alert admin or user about this risky state transition
break;
case Destroyed :
case Expunging :
+ s_logger.info("Receive power on report when VM is in destroyed or expunging state. vm: "
+ + vm.getId() + ", state: " + vm.getState());
break;
case Migrating :
+ try {
+ stateTransitTo(vm, VirtualMachine.Event.FollowAgentPowerOnReport, vm.getPowerHostId());
+ } catch(NoTransitionException e) {
+ s_logger.warn("Unexpected VM state transition exception, race-condition?", e);
+ }
break;
case Error :
default :
+ s_logger.info("Receive power on report when VM is in error or unexpected state. vm: "
+ + vm.getId() + ", state: " + vm.getState());
break;
}
}
@@ -3485,13 +3519,15 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
// 2) handle out of sync stationary states, schedule force-stop to release resources
//
switch(vm.getState()) {
- case Starting:
+ case Starting :
break;
case Running :
break;
case Stopping :
+ break;
+
case Stopped :
break;
@@ -3507,4 +3543,18 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
break;
}
}
+
+ private void scanStalledVMInTransitionState(long hostId) {
+ //
+ // TODO check VM that is stuck in Starting, Stopping, Migrating states, we won't check
+ // VMs in expunging state (this need to be handled specially)
+ //
+ // checking condition
+ // 1) no pending VmWork job
+ // 2) no power state update for some time
+ // 3) on hostId host
+
+
+
+ }
}