From 31f67c2b3cb46359dbe1ff279141f8031a88e564 Mon Sep 17 00:00:00 2001 From: Mike Tutkowski Date: Thu, 29 Jan 2015 18:40:17 -0700 Subject: [PATCH] If the HypervisorType of a storage pool is Any, we need to retrieve hosts in the given zone for each HypervisorType. --- .../src/com/cloud/resource/ResourceManager.java | 2 ++ .../com/cloud/resource/ResourceManagerImpl.java | 11 +++++++++++ .../cloud/storage/StoragePoolAutomationImpl.java | 15 +++++++++++++-- .../cloud/resource/MockResourceManagerImpl.java | 6 ++++++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/engine/components-api/src/com/cloud/resource/ResourceManager.java b/engine/components-api/src/com/cloud/resource/ResourceManager.java index 4f43adb3f56..849387e598a 100644 --- a/engine/components-api/src/com/cloud/resource/ResourceManager.java +++ b/engine/components-api/src/com/cloud/resource/ResourceManager.java @@ -105,6 +105,8 @@ public interface ResourceManager extends ResourceService { public List listAllUpAndEnabledHostsInOneZoneByHypervisor(HypervisorType type, long dcId); + public List listAllUpAndEnabledHostsInOneZone(long dcId); + public List listAllHostsInOneZoneByType(Host.Type type, long dcId); public List listAllHostsInAllZonesByType(Type type); diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java index b0215e7138f..d6dbff9eceb 100644 --- a/server/src/com/cloud/resource/ResourceManagerImpl.java +++ b/server/src/com/cloud/resource/ResourceManagerImpl.java @@ -2531,6 +2531,17 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, return sc.list(); } + @Override + public List listAllUpAndEnabledHostsInOneZone(long dcId) { + QueryBuilder sc = QueryBuilder.create(HostVO.class); + + sc.and(sc.entity().getDataCenterId(), Op.EQ, dcId); + sc.and(sc.entity().getStatus(), Op.EQ, Status.Up); + sc.and(sc.entity().getResourceState(), Op.EQ, ResourceState.Enabled); + + return sc.list(); + } + @Override public boolean isHostGpuEnabled(long hostId) { SearchCriteria sc = _gpuAvailability.create(); diff --git a/server/src/com/cloud/storage/StoragePoolAutomationImpl.java b/server/src/com/cloud/storage/StoragePoolAutomationImpl.java index 59bd2a54656..e08646704ce 100644 --- a/server/src/com/cloud/storage/StoragePoolAutomationImpl.java +++ b/server/src/com/cloud/storage/StoragePoolAutomationImpl.java @@ -38,6 +38,7 @@ import com.cloud.agent.api.ModifyStoragePoolCommand; import com.cloud.alert.AlertManager; import com.cloud.host.HostVO; import com.cloud.host.Status; +import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.resource.ResourceManager; import com.cloud.server.ManagementServer; import com.cloud.storage.dao.StoragePoolHostDao; @@ -128,7 +129,12 @@ public class StoragePoolAutomationImpl implements StoragePoolAutomation { // if the storage scope is ZONE wide, then get all the hosts for which hypervisor ZWSP created to send Modifystoragepoolcommand //TODO: if it's zone wide, this code will list a lot of hosts in the zone, which may cause performance/OOM issue. if (pool.getScope().equals(ScopeType.ZONE)) { - hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(pool.getHypervisor(), pool.getDataCenterId()); + if (HypervisorType.Any.equals(pool.getHypervisor())) { + hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZone(pool.getDataCenterId()); + } + else { + hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(pool.getHypervisor(), pool.getDataCenterId()); + } } else { hosts = _resourceMgr.listHostsInClusterByStatus(pool.getClusterId(), Status.Up); } @@ -290,7 +296,12 @@ public class StoragePoolAutomationImpl implements StoragePoolAutomation { List hosts = new ArrayList(); // if the storage scope is ZONE wide, then get all the hosts for which hypervisor ZWSP created to send Modifystoragepoolcommand if (poolVO.getScope().equals(ScopeType.ZONE)) { - hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(poolVO.getHypervisor(), pool.getDataCenterId()); + if (HypervisorType.Any.equals(pool.getHypervisor())) { + hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZone(pool.getDataCenterId()); + } + else { + hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(poolVO.getHypervisor(), pool.getDataCenterId()); + } } else { hosts = _resourceMgr.listHostsInClusterByStatus(pool.getClusterId(), Status.Up); } diff --git a/server/test/com/cloud/resource/MockResourceManagerImpl.java b/server/test/com/cloud/resource/MockResourceManagerImpl.java index 2646af079a6..fd102767b26 100644 --- a/server/test/com/cloud/resource/MockResourceManagerImpl.java +++ b/server/test/com/cloud/resource/MockResourceManagerImpl.java @@ -552,6 +552,12 @@ public class MockResourceManagerImpl extends ManagerBase implements ResourceMana return null; } + @Override + public List listAllUpAndEnabledHostsInOneZone(long dcId) { + // TODO Auto-generated method stub + return null; + } + @Override public boolean releaseHostReservation(Long hostId) { // TODO Auto-generated method stub