Skip to content

Commit 29c61e6

Browse files
author
Alena Prokharchyk
committed
bug 14369: remove host entry when destroy CPVM/SSVM instances
status 14369: resolved fixed
1 parent 4a9155d commit 29c61e6

4 files changed

Lines changed: 41 additions & 8 deletions

File tree

‎server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,18 @@ public boolean rebootProxy(long proxyVmId) {
13321332
public boolean destroyProxy(long vmId) {
13331333
ConsoleProxyVO proxy = _consoleProxyDao.findById(vmId);
13341334
try {
1335-
return _itMgr.expunge(proxy, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
1335+
//expunge the vm
1336+
boolean result = _itMgr.expunge(proxy, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
1337+
if (result) {
1338+
HostVO host = _hostDao.findByTypeNameAndZoneId(proxy.getDataCenterIdToDeployIn(), proxy.getHostName(),
1339+
Host.Type.ConsoleProxy);
1340+
if (host != null) {
1341+
s_logger.debug("Removing host entry for proxy id=" + vmId);
1342+
result = result && _hostDao.remove(host.getId());
1343+
}
1344+
}
1345+
1346+
return result;
13361347
} catch (ResourceUnavailableException e) {
13371348
s_logger.warn("Unable to expunge " + proxy, e);
13381349
return false;

‎server/src/com/cloud/host/dao/HostDao.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,7 @@ public interface HostDao extends GenericDao<HostVO, Long>, StateDao<Status, Stat
6868

6969
boolean updateResourceState(ResourceState oldState, ResourceState.Event event, ResourceState newState, Host vo);
7070

71-
HostVO findByGuid(String guid);
71+
HostVO findByGuid(String guid);
72+
73+
HostVO findByTypeNameAndZoneId(long zoneId, String name, Host.Type type);
7274
}

‎server/src/com/cloud/host/dao/HostDaoImpl.java‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
9292
protected final SearchBuilder<HostVO> UnmanagedApplianceSearch;
9393
protected final SearchBuilder<HostVO> MaintenanceCountSearch;
9494
protected final SearchBuilder<HostVO> ClusterStatusSearch;
95-
protected final SearchBuilder<HostVO> ConsoleProxyHostSearch;
95+
protected final SearchBuilder<HostVO> TypeNameZoneSearch;
9696
protected final SearchBuilder<HostVO> AvailHypevisorInZone;
9797

9898
protected final SearchBuilder<HostVO> DirectConnectSearch;
@@ -187,10 +187,11 @@ public HostDaoImpl() {
187187
ClusterStatusSearch.and("status", ClusterStatusSearch.entity().getStatus(), SearchCriteria.Op.EQ);
188188
ClusterStatusSearch.done();
189189

190-
ConsoleProxyHostSearch = createSearchBuilder();
191-
ConsoleProxyHostSearch.and("name", ConsoleProxyHostSearch.entity().getName(), SearchCriteria.Op.EQ);
192-
ConsoleProxyHostSearch.and("type", ConsoleProxyHostSearch.entity().getType(), SearchCriteria.Op.EQ);
193-
ConsoleProxyHostSearch.done();
190+
TypeNameZoneSearch = createSearchBuilder();
191+
TypeNameZoneSearch.and("name", TypeNameZoneSearch.entity().getName(), SearchCriteria.Op.EQ);
192+
TypeNameZoneSearch.and("type", TypeNameZoneSearch.entity().getType(), SearchCriteria.Op.EQ);
193+
TypeNameZoneSearch.and("zoneId", TypeNameZoneSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
194+
TypeNameZoneSearch.done();
194195

195196
PodSearch = createSearchBuilder();
196197
PodSearch.and("pod", PodSearch.entity().getPodId(), SearchCriteria.Op.EQ);
@@ -705,5 +706,14 @@ public boolean updateResourceState(ResourceState oldState, ResourceState.Event e
705706

706707
return result > 0;
707708
}
709+
710+
@Override
711+
public HostVO findByTypeNameAndZoneId(long zoneId, String name, Host.Type type) {
712+
SearchCriteria<HostVO> sc = TypeNameZoneSearch.create();
713+
sc.setParameters("type", type);
714+
sc.setParameters("name", name);
715+
sc.setParameters("zoneId", zoneId);
716+
return findOneBy(sc);
717+
}
708718

709719
}

‎server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,17 @@ public boolean destroySecStorageVm(long vmId) {
974974
SecondaryStorageVmVO ssvm = _secStorageVmDao.findById(vmId);
975975

976976
try {
977-
return _itMgr.expunge(ssvm, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
977+
boolean result = _itMgr.expunge(ssvm, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
978+
if (result) {
979+
HostVO host = _hostDao.findByTypeNameAndZoneId(ssvm.getDataCenterIdToDeployIn(), ssvm.getHostName(),
980+
Host.Type.SecondaryStorageVM);
981+
if (host != null) {
982+
s_logger.debug("Removing host entry for ssvm id=" + vmId);
983+
result = result && _hostDao.remove(host.getId());
984+
}
985+
}
986+
987+
return result;
978988
} catch (ResourceUnavailableException e) {
979989
s_logger.warn("Unable to expunge " + ssvm, e);
980990
return false;

0 commit comments

Comments
 (0)