cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anthon...@apache.org
Subject git commit: updated refs/heads/master to 02e22db
Date Thu, 20 Nov 2014 00:36:03 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/master 414081154 -> 02e22dba7


CLOUDSTACK-7742:
root cause:
when vmsync reports system VM is down, CCP doesn't release the VM resource before starting
it.
fix:
make sure cleanup is called for a VM when it is reported as Stopped


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

Branch: refs/heads/master
Commit: 02e22dba7d36a1be04f715efdf5dcaa085f00241
Parents: 4140811
Author: Anthony Xu <anthony.xu@citrix.com>
Authored: Wed Nov 19 16:27:51 2014 -0800
Committer: Anthony Xu <anthony.xu@citrix.com>
Committed: Wed Nov 19 16:30:56 2014 -0800

----------------------------------------------------------------------
 .../com/cloud/vm/VirtualMachineManagerImpl.java | 42 ++++++++++----------
 .../src/com/cloud/dc/dao/DataCenterDaoImpl.java |  1 +
 .../cloud/dc/dao/DataCenterIpAddressDao.java    |  2 +
 .../dc/dao/DataCenterIpAddressDaoImpl.java      | 16 ++++++++
 4 files changed, 40 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/02e22dba/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 fa8b7b6..be88b4e 100755
--- a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -1283,13 +1283,27 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
         s_logger.debug("Cleaning up resources for the vm " + vm + " in " + state + " state");
         try {
             if (state == State.Starting) {
-                Step step = work.getStep();
-                if (step == Step.Starting && !cleanUpEvenIfUnableToStop) {
-                    s_logger.warn("Unable to cleanup vm " + vm + "; work state is incorrect:
" + step);
-                    return false;
-                }
+                if (work != null) {
+                    Step step = work.getStep();
+                    if (step == Step.Starting && !cleanUpEvenIfUnableToStop) {
+                        s_logger.warn("Unable to cleanup vm " + vm + "; work state is incorrect:
" + step);
+                        return false;
+                    }
+
+                    if (step == Step.Started || step == Step.Starting || step == Step.Release)
{
+                        if (vm.getHostId() != null) {
+                            if (!sendStop(guru, profile, cleanUpEvenIfUnableToStop, false))
{
+                                s_logger.warn("Failed to stop vm " + vm + " in " + State.Starting
+ " state as a part of cleanup process");
+                                return false;
+                            }
+                        }
+                    }
 
-                if (step == Step.Started || step == Step.Starting || step == Step.Release)
{
+                    if (step != Step.Release && step != Step.Prepare && step
!= Step.Started && step != Step.Starting) {
+                        s_logger.debug("Cleanup is not needed for vm " + vm + "; work state
is incorrect: " + step);
+                        return true;
+                     }
+                } else {
                     if (vm.getHostId() != null) {
                         if (!sendStop(guru, profile, cleanUpEvenIfUnableToStop, false)) {
                             s_logger.warn("Failed to stop vm " + vm + " in " + State.Starting
+ " state as a part of cleanup process");
@@ -1298,10 +1312,6 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
                     }
                 }
 
-                if (step != Step.Release && step != Step.Prepare && step
!= Step.Started && step != Step.Starting) {
-                    s_logger.debug("Cleanup is not needed for vm " + vm + "; work state is
incorrect: " + step);
-                    return true;
-                }
             } else if (state == State.Stopping) {
                 if (vm.getHostId() != null) {
                     if (!sendStop(guru, profile, cleanUpEvenIfUnableToStop, false)) {
@@ -1453,20 +1463,10 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
             if (!cleanUpEvenIfUnableToStop) {
                 throw new CloudRuntimeException("We cannot stop " + vm + " when it is in
state " + vm.getState());
             }
-            boolean doCleanup = false;
+            boolean doCleanup = true;
             if (s_logger.isDebugEnabled()) {
                 s_logger.debug("Unable to transition the state but we're moving on because
it's forced stop");
             }
-            if ((state == State.Starting) || (state == State.Migrating) || (state == State.Stopping))
{
-                if (work != null) {
-                    doCleanup = true;
-                } else {
-                    if (s_logger.isDebugEnabled()) {
-                        s_logger.debug("Unable to cleanup VM: " + vm + " ,since outstanding
work item is not found");
-                    }
-                    throw new CloudRuntimeException("Work item not found, We cannot stop
" + vm + " when it is in state " + vm.getState());
-                }
-            }
 
             if (doCleanup) {
                 if (cleanup(vmGuru, new VirtualMachineProfileImpl(vm), work, Event.StopRequested,
cleanUpEvenIfUnableToStop)) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/02e22dba/engine/schema/src/com/cloud/dc/dao/DataCenterDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/dc/dao/DataCenterDaoImpl.java b/engine/schema/src/com/cloud/dc/dao/DataCenterDaoImpl.java
index 67da956..373446e 100755
--- a/engine/schema/src/com/cloud/dc/dao/DataCenterDaoImpl.java
+++ b/engine/schema/src/com/cloud/dc/dao/DataCenterDaoImpl.java
@@ -250,6 +250,7 @@ public class DataCenterDaoImpl extends GenericDaoBase<DataCenterVO,
Long> implem
 
     @Override
     public Pair<String, Long> allocatePrivateIpAddress(long dcId, long podId, long
instanceId, String reservationId) {
+        _ipAllocDao.releaseIpAddress(instanceId);
         DataCenterIpAddressVO vo = _ipAllocDao.takeIpAddress(dcId, podId, instanceId, reservationId);
         if (vo == null) {
             return null;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/02e22dba/engine/schema/src/com/cloud/dc/dao/DataCenterIpAddressDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/dc/dao/DataCenterIpAddressDao.java b/engine/schema/src/com/cloud/dc/dao/DataCenterIpAddressDao.java
index 5a1572e..7f1ec4d 100644
--- a/engine/schema/src/com/cloud/dc/dao/DataCenterIpAddressDao.java
+++ b/engine/schema/src/com/cloud/dc/dao/DataCenterIpAddressDao.java
@@ -33,6 +33,8 @@ public interface DataCenterIpAddressDao extends GenericDao<DataCenterIpAddressVO
 
     public void releaseIpAddress(long nicId, String reservationId);
 
+    public void releaseIpAddress(long nicId);
+
     boolean mark(long dcId, long podId, String ip);
 
     List<DataCenterIpAddressVO> listByPodIdDcIdIpAddress(long podId, long dcId, String
ipAddress);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/02e22dba/engine/schema/src/com/cloud/dc/dao/DataCenterIpAddressDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/dc/dao/DataCenterIpAddressDaoImpl.java b/engine/schema/src/com/cloud/dc/dao/DataCenterIpAddressDaoImpl.java
index 80936c0..9bc373f 100755
--- a/engine/schema/src/com/cloud/dc/dao/DataCenterIpAddressDaoImpl.java
+++ b/engine/schema/src/com/cloud/dc/dao/DataCenterIpAddressDaoImpl.java
@@ -178,6 +178,22 @@ public class DataCenterIpAddressDaoImpl extends GenericDaoBase<DataCenterIpAddre
     }
 
     @Override
+    public void releaseIpAddress(long nicId) {
+        if (s_logger.isDebugEnabled()) {
+            s_logger.debug("Releasing ip address for instance=" + nicId);
+        }
+        SearchCriteria<DataCenterIpAddressVO> sc = AllFieldsSearch.create();
+        sc.setParameters("instance", nicId);
+
+        DataCenterIpAddressVO vo = createForUpdate();
+        vo.setTakenAt(null);
+        vo.setInstanceId(null);
+        vo.setReservationId(null);
+        update(vo, sc);
+    }
+
+
+    @Override
     public List<DataCenterIpAddressVO> listByPodIdDcId(long podId, long dcId) {
         SearchCriteria<DataCenterIpAddressVO> sc = AllFieldsSearch.create();
         sc.setParameters("pod", podId);


Mime
View raw message