bug 14369: remove host entry when destroy CPVM/SSVM instances

status 14369: resolved fixed
This commit is contained in:
Alena Prokharchyk 2012-03-20 13:51:18 -07:00
parent 4a9155df1b
commit 29c61e6341
4 changed files with 41 additions and 8 deletions

View File

@ -1332,7 +1332,18 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
public boolean destroyProxy(long vmId) { public boolean destroyProxy(long vmId) {
ConsoleProxyVO proxy = _consoleProxyDao.findById(vmId); ConsoleProxyVO proxy = _consoleProxyDao.findById(vmId);
try { 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) { } catch (ResourceUnavailableException e) {
s_logger.warn("Unable to expunge " + proxy, e); s_logger.warn("Unable to expunge " + proxy, e);
return false; return false;

View File

@ -69,4 +69,6 @@ public interface HostDao extends GenericDao<HostVO, Long>, StateDao<Status, Stat
boolean updateResourceState(ResourceState oldState, ResourceState.Event event, ResourceState newState, Host vo); boolean updateResourceState(ResourceState oldState, ResourceState.Event event, ResourceState newState, Host vo);
HostVO findByGuid(String guid); HostVO findByGuid(String guid);
HostVO findByTypeNameAndZoneId(long zoneId, String name, Host.Type type);
} }

View File

@ -92,7 +92,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
protected final SearchBuilder<HostVO> UnmanagedApplianceSearch; protected final SearchBuilder<HostVO> UnmanagedApplianceSearch;
protected final SearchBuilder<HostVO> MaintenanceCountSearch; protected final SearchBuilder<HostVO> MaintenanceCountSearch;
protected final SearchBuilder<HostVO> ClusterStatusSearch; protected final SearchBuilder<HostVO> ClusterStatusSearch;
protected final SearchBuilder<HostVO> ConsoleProxyHostSearch; protected final SearchBuilder<HostVO> TypeNameZoneSearch;
protected final SearchBuilder<HostVO> AvailHypevisorInZone; protected final SearchBuilder<HostVO> AvailHypevisorInZone;
protected final SearchBuilder<HostVO> DirectConnectSearch; protected final SearchBuilder<HostVO> DirectConnectSearch;
@ -187,10 +187,11 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
ClusterStatusSearch.and("status", ClusterStatusSearch.entity().getStatus(), SearchCriteria.Op.EQ); ClusterStatusSearch.and("status", ClusterStatusSearch.entity().getStatus(), SearchCriteria.Op.EQ);
ClusterStatusSearch.done(); ClusterStatusSearch.done();
ConsoleProxyHostSearch = createSearchBuilder(); TypeNameZoneSearch = createSearchBuilder();
ConsoleProxyHostSearch.and("name", ConsoleProxyHostSearch.entity().getName(), SearchCriteria.Op.EQ); TypeNameZoneSearch.and("name", TypeNameZoneSearch.entity().getName(), SearchCriteria.Op.EQ);
ConsoleProxyHostSearch.and("type", ConsoleProxyHostSearch.entity().getType(), SearchCriteria.Op.EQ); TypeNameZoneSearch.and("type", TypeNameZoneSearch.entity().getType(), SearchCriteria.Op.EQ);
ConsoleProxyHostSearch.done(); TypeNameZoneSearch.and("zoneId", TypeNameZoneSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
TypeNameZoneSearch.done();
PodSearch = createSearchBuilder(); PodSearch = createSearchBuilder();
PodSearch.and("pod", PodSearch.entity().getPodId(), SearchCriteria.Op.EQ); PodSearch.and("pod", PodSearch.entity().getPodId(), SearchCriteria.Op.EQ);
@ -706,4 +707,13 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
return result > 0; return result > 0;
} }
@Override
public HostVO findByTypeNameAndZoneId(long zoneId, String name, Host.Type type) {
SearchCriteria<HostVO> sc = TypeNameZoneSearch.create();
sc.setParameters("type", type);
sc.setParameters("name", name);
sc.setParameters("zoneId", zoneId);
return findOneBy(sc);
}
} }

View File

@ -974,7 +974,17 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
SecondaryStorageVmVO ssvm = _secStorageVmDao.findById(vmId); SecondaryStorageVmVO ssvm = _secStorageVmDao.findById(vmId);
try { 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) { } catch (ResourceUnavailableException e) {
s_logger.warn("Unable to expunge " + ssvm, e); s_logger.warn("Unable to expunge " + ssvm, e);
return false; return false;