From c85e13fbf91ebc1d7eebed4904547359d199ec6e Mon Sep 17 00:00:00 2001 From: anthony Date: Mon, 7 Feb 2011 18:31:16 -0800 Subject: [PATCH] bug 7635: stop vms if this host is the last one in cluster , when put this host into maintenance mode status 7635: resolved fixed --- .../com/cloud/agent/manager/AgentManagerImpl.java | 11 ++++++++++- server/src/com/cloud/host/dao/HostDao.java | 4 +++- server/src/com/cloud/host/dao/HostDaoImpl.java | 13 +++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/server/src/com/cloud/agent/manager/AgentManagerImpl.java b/server/src/com/cloud/agent/manager/AgentManagerImpl.java index fc68160ebfc..655585da28f 100755 --- a/server/src/com/cloud/agent/manager/AgentManagerImpl.java +++ b/server/src/com/cloud/agent/manager/AgentManagerImpl.java @@ -112,6 +112,7 @@ import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.OperationTimedoutException; import com.cloud.exception.UnsupportedVersionException; import com.cloud.ha.HighAvailabilityManager; +import com.cloud.ha.HighAvailabilityManager.WorkType; import com.cloud.host.DetailVO; import com.cloud.host.Host; import com.cloud.host.Host.Type; @@ -2071,13 +2072,21 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, final Host.Type type = host.getType(); if (type == Host.Type.Routing) { + final List vms = _vmDao.listByHostId(hostId); if (vms.size() == 0) { return true; } + + List hosts = _hostDao.listBy(host.getClusterId(), host.getPodId(), host.getDataCenterId()); for (final VMInstanceVO vm : vms) { - _haMgr.scheduleMigration(vm); + if( hosts == null || hosts.isEmpty()) { + // for the last host in this cluster, stop all the VMs + _haMgr.scheduleStop(vm, hostId, WorkType.ForceStop); + } else { + _haMgr.scheduleMigration(vm); + } } } diff --git a/server/src/com/cloud/host/dao/HostDao.java b/server/src/com/cloud/host/dao/HostDao.java index 0b6c6f4c794..1d9695ef612 100644 --- a/server/src/com/cloud/host/dao/HostDao.java +++ b/server/src/com/cloud/host/dao/HostDao.java @@ -151,5 +151,7 @@ public interface HostDao extends GenericDao { * @param statuses the host needs to be in. * @return ids of the host meeting the search parameters. */ - List listBy(Long dataCenterId, Long podId, Long clusterId, Type hostType, Status... statuses); + List listBy(Long dataCenterId, Long podId, Long clusterId, Type hostType, Status... statuses); + + List listBy(Long clusterId, Long podId, long dcId); } diff --git a/server/src/com/cloud/host/dao/HostDaoImpl.java b/server/src/com/cloud/host/dao/HostDaoImpl.java index bfdb5682a91..93e94f99f88 100644 --- a/server/src/com/cloud/host/dao/HostDaoImpl.java +++ b/server/src/com/cloud/host/dao/HostDaoImpl.java @@ -313,6 +313,19 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao return listBy(sc); } + @Override + public List listBy(Long clusterId, Long podId, long dcId) { + SearchCriteria sc = TypePodDcStatusSearch.create(); + if (podId != null) { + sc.setParameters("pod", podId); + } + if (clusterId != null) { + sc.setParameters("cluster", clusterId); + } + sc.setParameters("dc", dcId); + return listBy(sc); + } + @Override public List listByCluster(long clusterId) { SearchCriteria sc = ClusterSearch.create();