From d9ce49b1f18c14a7acfb7a81316d4f6555717851 Mon Sep 17 00:00:00 2001 From: Vijayendra Bhamidipati Date: Mon, 8 Jul 2013 13:15:23 -0700 Subject: [PATCH] CLOUDSTACK-3264: [ZWPS]NPE while finding storage pools for migration Description: Filter primary storage pools based on zonewide/clusterwide configuration when considering pools to list for storage migration of volumes. --- .../allocator/AbstractStoragePoolAllocator.java | 3 +++ .../allocator/ClusterScopeStoragePoolAllocator.java | 3 +++ .../storage/allocator/LocalStoragePoolAllocator.java | 3 +++ .../storage/allocator/RandomStoragePoolAllocator.java | 5 +++++ server/src/com/cloud/server/ManagementServerImpl.java | 10 ++++++++-- 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/engine/storage/src/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocator.java b/engine/storage/src/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocator.java index e16703ecf2f..89e09748ea3 100755 --- a/engine/storage/src/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocator.java +++ b/engine/storage/src/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocator.java @@ -145,6 +145,9 @@ public abstract class AbstractStoragePoolAllocator extends AdapterBase implement protected List reOrder(List pools, VirtualMachineProfile vmProfile, DeploymentPlan plan) { + if (pools == null) { + return null; + } Account account = null; if (vmProfile.getVirtualMachine() != null) { account = vmProfile.getOwner(); diff --git a/engine/storage/src/org/apache/cloudstack/storage/allocator/ClusterScopeStoragePoolAllocator.java b/engine/storage/src/org/apache/cloudstack/storage/allocator/ClusterScopeStoragePoolAllocator.java index 0933adcd3bc..41afa837b52 100644 --- a/engine/storage/src/org/apache/cloudstack/storage/allocator/ClusterScopeStoragePoolAllocator.java +++ b/engine/storage/src/org/apache/cloudstack/storage/allocator/ClusterScopeStoragePoolAllocator.java @@ -59,6 +59,9 @@ public class ClusterScopeStoragePoolAllocator extends AbstractStoragePoolAllocat Long podId = plan.getPodId(); Long clusterId = plan.getClusterId(); + if (clusterId == null) { + return null; + } if (dskCh.getTags() != null && dskCh.getTags().length != 0) { s_logger.debug("Looking for pools in dc: " + dcId + " pod:" + podId + " cluster:" + clusterId + " having tags:" + Arrays.toString(dskCh.getTags())); diff --git a/engine/storage/src/org/apache/cloudstack/storage/allocator/LocalStoragePoolAllocator.java b/engine/storage/src/org/apache/cloudstack/storage/allocator/LocalStoragePoolAllocator.java index ef9e84eee15..4056fe756a1 100644 --- a/engine/storage/src/org/apache/cloudstack/storage/allocator/LocalStoragePoolAllocator.java +++ b/engine/storage/src/org/apache/cloudstack/storage/allocator/LocalStoragePoolAllocator.java @@ -96,6 +96,9 @@ public class LocalStoragePoolAllocator extends AbstractStoragePoolAllocator { } } } else { + if (plan.getClusterId() == null) { + return null; + } List availablePools = _storagePoolDao.findLocalStoragePoolsByTags(plan.getDataCenterId(), plan.getPodId(), plan.getClusterId(), dskCh.getTags()); for (StoragePoolVO pool : availablePools) { diff --git a/plugins/storage-allocators/random/src/org/apache/cloudstack/storage/allocator/RandomStoragePoolAllocator.java b/plugins/storage-allocators/random/src/org/apache/cloudstack/storage/allocator/RandomStoragePoolAllocator.java index 76ce6631c74..fda787f479d 100644 --- a/plugins/storage-allocators/random/src/org/apache/cloudstack/storage/allocator/RandomStoragePoolAllocator.java +++ b/plugins/storage-allocators/random/src/org/apache/cloudstack/storage/allocator/RandomStoragePoolAllocator.java @@ -46,6 +46,11 @@ public class RandomStoragePoolAllocator extends AbstractStoragePoolAllocator { long dcId = plan.getDataCenterId(); Long podId = plan.getPodId(); Long clusterId = plan.getClusterId(); + + if (clusterId == null) { + return null; + } + s_logger.debug("Looking for pools in dc: " + dcId + " pod:" + podId + " cluster:" + clusterId); List pools = _storagePoolDao.listBy(dcId, podId, clusterId, ScopeType.CLUSTER); if (pools.size() == 0) { diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 36b38791e24..58e4b44ac8b 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -1258,8 +1258,14 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe // Get all the pools available. Only shared pools are considered because only a volume on a shared pools // can be live migrated while the virtual machine stays on the same host. - List storagePools = _poolDao.findPoolsByTags(volume.getDataCenterId(), - volume.getPodId(), srcVolumePool.getClusterId(), null); + List storagePools = null; + + if (srcVolumePool.getClusterId() == null) { + storagePools = _poolDao.findZoneWideStoragePoolsByTags(volume.getDataCenterId(), null); + } else { + storagePools = _poolDao.findPoolsByTags(volume.getDataCenterId(), volume.getPodId(), srcVolumePool.getClusterId(), null); + } + storagePools.remove(srcVolumePool); for (StoragePoolVO pool : storagePools) { if (pool.isShared()) {