You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by an...@apache.org on 2014/11/20 01:29:40 UTC
git commit: updated refs/heads/4.5 to ab19edf
Repository: cloudstack
Updated Branches:
refs/heads/4.5 bd7996532 -> ab19edf09
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/ab19edf0
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/ab19edf0
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/ab19edf0
Branch: refs/heads/4.5
Commit: ab19edf09d4f87f2807c52ba279aeb013f2545f9
Parents: bd79965
Author: Anthony Xu <an...@citrix.com>
Authored: Wed Nov 19 16:27:51 2014 -0800
Committer: Anthony Xu <an...@citrix.com>
Committed: Wed Nov 19 16:27:51 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/ab19edf0/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 4d687d9..8eac2bb 100755
--- a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -1276,13 +1276,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");
@@ -1291,10 +1305,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)) {
@@ -1446,20 +1456,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/ab19edf0/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/ab19edf0/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/ab19edf0/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);