From 29c61e6341cf4d32a7178e8bf22dc325bf6bf79c Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Tue, 20 Mar 2012 13:51:18 -0700 Subject: [PATCH] bug 14369: remove host entry when destroy CPVM/SSVM instances status 14369: resolved fixed --- .../consoleproxy/ConsoleProxyManagerImpl.java | 13 +++++++++++- server/src/com/cloud/host/dao/HostDao.java | 4 +++- .../src/com/cloud/host/dao/HostDaoImpl.java | 20 ++++++++++++++----- .../SecondaryStorageManagerImpl.java | 12 ++++++++++- 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index b2a8a76bfa8..70c1a9dba2b 100755 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -1332,7 +1332,18 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx public boolean destroyProxy(long vmId) { ConsoleProxyVO proxy = _consoleProxyDao.findById(vmId); try { - return _itMgr.expunge(proxy, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount()); + //expunge the vm + boolean result = _itMgr.expunge(proxy, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount()); + if (result) { + HostVO host = _hostDao.findByTypeNameAndZoneId(proxy.getDataCenterIdToDeployIn(), proxy.getHostName(), + Host.Type.ConsoleProxy); + if (host != null) { + s_logger.debug("Removing host entry for proxy id=" + vmId); + result = result && _hostDao.remove(host.getId()); + } + } + + return result; } catch (ResourceUnavailableException e) { s_logger.warn("Unable to expunge " + proxy, e); return false; diff --git a/server/src/com/cloud/host/dao/HostDao.java b/server/src/com/cloud/host/dao/HostDao.java index eb5565c7971..e555f0e54b4 100755 --- a/server/src/com/cloud/host/dao/HostDao.java +++ b/server/src/com/cloud/host/dao/HostDao.java @@ -68,5 +68,7 @@ public interface HostDao extends GenericDao, StateDao implements HostDao protected final SearchBuilder UnmanagedApplianceSearch; protected final SearchBuilder MaintenanceCountSearch; protected final SearchBuilder ClusterStatusSearch; - protected final SearchBuilder ConsoleProxyHostSearch; + protected final SearchBuilder TypeNameZoneSearch; protected final SearchBuilder AvailHypevisorInZone; protected final SearchBuilder DirectConnectSearch; @@ -187,10 +187,11 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao ClusterStatusSearch.and("status", ClusterStatusSearch.entity().getStatus(), SearchCriteria.Op.EQ); ClusterStatusSearch.done(); - ConsoleProxyHostSearch = createSearchBuilder(); - ConsoleProxyHostSearch.and("name", ConsoleProxyHostSearch.entity().getName(), SearchCriteria.Op.EQ); - ConsoleProxyHostSearch.and("type", ConsoleProxyHostSearch.entity().getType(), SearchCriteria.Op.EQ); - ConsoleProxyHostSearch.done(); + TypeNameZoneSearch = createSearchBuilder(); + TypeNameZoneSearch.and("name", TypeNameZoneSearch.entity().getName(), SearchCriteria.Op.EQ); + TypeNameZoneSearch.and("type", TypeNameZoneSearch.entity().getType(), SearchCriteria.Op.EQ); + TypeNameZoneSearch.and("zoneId", TypeNameZoneSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); + TypeNameZoneSearch.done(); PodSearch = createSearchBuilder(); PodSearch.and("pod", PodSearch.entity().getPodId(), SearchCriteria.Op.EQ); @@ -705,5 +706,14 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao return result > 0; } + + @Override + public HostVO findByTypeNameAndZoneId(long zoneId, String name, Host.Type type) { + SearchCriteria sc = TypeNameZoneSearch.create(); + sc.setParameters("type", type); + sc.setParameters("name", name); + sc.setParameters("zoneId", zoneId); + return findOneBy(sc); + } } diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java index 1b65c754ceb..94675004a1b 100755 --- a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java +++ b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java @@ -974,7 +974,17 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V SecondaryStorageVmVO ssvm = _secStorageVmDao.findById(vmId); try { - return _itMgr.expunge(ssvm, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount()); + boolean result = _itMgr.expunge(ssvm, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount()); + if (result) { + HostVO host = _hostDao.findByTypeNameAndZoneId(ssvm.getDataCenterIdToDeployIn(), ssvm.getHostName(), + Host.Type.SecondaryStorageVM); + if (host != null) { + s_logger.debug("Removing host entry for ssvm id=" + vmId); + result = result && _hostDao.remove(host.getId()); + } + } + + return result; } catch (ResourceUnavailableException e) { s_logger.warn("Unable to expunge " + ssvm, e); return false;