From d660bc7e8da57d94049d55e53ffe18df8016e4e5 Mon Sep 17 00:00:00 2001 From: Rajesh Battala Date: Fri, 28 Jun 2013 14:31:33 +0530 Subject: [PATCH] CLOUDSTACK-3089 [ZWPS] NPE while cancelling the Storage Maintenance Signed-off-by: Edison Su --- .../storage/StoragePoolAutomationImpl.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/server/src/com/cloud/storage/StoragePoolAutomationImpl.java b/server/src/com/cloud/storage/StoragePoolAutomationImpl.java index b2cb1f54f93..f6b39f1fe47 100644 --- a/server/src/com/cloud/storage/StoragePoolAutomationImpl.java +++ b/server/src/com/cloud/storage/StoragePoolAutomationImpl.java @@ -23,12 +23,7 @@ import java.util.List; import javax.inject.Inject; -import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; -import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle; -import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; -import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider; -import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProviderManager; -import org.apache.cloudstack.engine.subsystem.api.storage.Scope; +import org.apache.cloudstack.engine.subsystem.api.storage.*; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.log4j.Logger; @@ -137,6 +132,7 @@ public class StoragePoolAutomationImpl implements StoragePoolAutomation { //Handeling the Zone wide and cluster wide primay storage List hosts = new ArrayList(); // 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()); } else { @@ -366,8 +362,16 @@ public class StoragePoolAutomationImpl implements StoragePoolAutomation { .findById(store.getId()); StoragePool pool = (StoragePool)store; - List hosts = _resourceMgr.listHostsInClusterByStatus( + //Handeling the Zone wide and cluster wide primay storage + 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()); + } else { + hosts = _resourceMgr.listHostsInClusterByStatus( pool.getClusterId(), Status.Up); + } + if (hosts == null || hosts.size() == 0) { return true; }