process the missing power report of a VM that exists in CloudStack but not in 
hypervisor


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/5d732177
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/5d732177
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/5d732177

Branch: refs/heads/master
Commit: 5d73217723571c78aaef8e3cf36f4666749737ad
Parents: fda7219
Author: Kelven Yang <[email protected]>
Authored: Thu Jan 23 17:43:28 2014 -0800
Committer: Kelven Yang <[email protected]>
Committed: Fri Feb 28 15:35:57 2014 -0800

----------------------------------------------------------------------
 api/src/com/cloud/vm/VirtualMachine.java        |  7 ++++--
 .../com/cloud/vm/VirtualMachineManagerImpl.java |  3 ++-
 .../vm/VirtualMachinePowerStateSyncImpl.java    | 25 ++++++++++++++++++++
 3 files changed, 32 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5d732177/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 d6e70a8..2d98aa9 100755
--- a/api/src/com/cloud/vm/VirtualMachine.java
+++ b/api/src/com/cloud/vm/VirtualMachine.java
@@ -33,8 +33,11 @@ import com.cloud.utils.fsm.StateObject;
  */
 public interface VirtualMachine extends RunningOn, ControlledEntity, Identity, 
InternalIdentity, StateObject<VirtualMachine.State> {
 
-    public enum PowerState {
-        PowerUnknown, PowerOn, PowerOff,
+       public enum PowerState {
+           PowerUnknown,
+           PowerOn,
+           PowerOff,
+        PowerReportMissing
     }
 
     public enum State {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5d732177/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
----------------------------------------------------------------------
diff --git 
a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java 
b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
index 1b0d6ca..f944d7e 100755
--- a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -3974,6 +3974,7 @@ public class VirtualMachineManagerImpl extends 
ManagerBase implements VirtualMac
                     break;
 
                 case PowerOff:
+                case PowerReportMissing:
                     handlePowerOffReportWithNoPendingJobsOnVM(vm);
                     break;
 
@@ -4094,7 +4095,7 @@ public class VirtualMachineManagerImpl extends 
ManagerBase implements VirtualMac
                     VM_SYNC_ALERT_SUBJECT, "VM " + vm.getHostName() + "(" + 
vm.getInstanceName() + ") state is sync-ed (" + vm.getState()
                             + " -> Stopped) from out-of-context transition.");
 
-            s_logger.info("VM " + vm.getInstanceName() + " is sync-ed to at 
Stopped state according to power-on report from hypervisor");
+            s_logger.info("VM " + vm.getInstanceName() + " is sync-ed to at 
Stopped state according to power-off report from hypervisor");
 
             // TODO: we need to forcely release all resource allocation
             break;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5d732177/engine/orchestration/src/com/cloud/vm/VirtualMachinePowerStateSyncImpl.java
----------------------------------------------------------------------
diff --git 
a/engine/orchestration/src/com/cloud/vm/VirtualMachinePowerStateSyncImpl.java 
b/engine/orchestration/src/com/cloud/vm/VirtualMachinePowerStateSyncImpl.java
index 453890c..fd0077c 100644
--- 
a/engine/orchestration/src/com/cloud/vm/VirtualMachinePowerStateSyncImpl.java
+++ 
b/engine/orchestration/src/com/cloud/vm/VirtualMachinePowerStateSyncImpl.java
@@ -17,6 +17,7 @@
 package com.cloud.vm;
 
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import javax.inject.Inject;
@@ -78,6 +79,30 @@ public class VirtualMachinePowerStateSyncImpl implements 
VirtualMachinePowerStat
             } else {
                 if (s_logger.isDebugEnabled())
                     s_logger.debug("VM power state does not change, skip DB 
writing. vm id: " + entry.getKey());
+               }
+       }
+
+        // for all running/stopping VMs, we provide monitoring of missing 
report
+        List<VMInstanceVO> vmsThatAreMissingReport = 
_instanceDao.findByHostInStates(hostId, VirtualMachine.State.Running,
+                VirtualMachine.State.Stopping);
+        java.util.Iterator<VMInstanceVO> it = 
vmsThatAreMissingReport.iterator();
+        while (it.hasNext()) {
+            VMInstanceVO instance = it.next();
+            if (translatedInfo.get(instance.getId()) != null)
+                it.remove();
+        }
+
+        if (vmsThatAreMissingReport.size() > 0) {
+            for (VMInstanceVO instance : vmsThatAreMissingReport) {
+                if (_instanceDao.updatePowerState(instance.getId(), hostId, 
VirtualMachine.PowerState.PowerReportMissing)) {
+                    if (s_logger.isDebugEnabled())
+                        s_logger.debug("VM state report is updated. host: " + 
hostId + ", vm id: " + instance.getId() + ", power state: PowerReportMissing ");
+
+                    _messageBus.publish(null, 
VirtualMachineManager.Topics.VM_POWER_STATE, PublishScope.GLOBAL, 
instance.getId());
+                } else {
+                    if (s_logger.isDebugEnabled())
+                        s_logger.debug("VM power state does not change, skip 
DB writing. vm id: " + instance.getId());
+                }
             }
         }
     }

Reply via email to