From a8360e41c0c99793b1f6b0a4e0cb10dbc3d00a9c Mon Sep 17 00:00:00 2001 From: Prachi Damle Date: Tue, 30 Jul 2013 17:14:04 -0700 Subject: [PATCH] CLOUDSTACK-3942 NPE from findStoragePool method Changes: - Added null checks for podId Conflicts: server/src/com/cloud/storage/StorageManagerImpl.java --- server/src/com/cloud/storage/StorageManagerImpl.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index a8cfcc0d19c..25ef70ba95d 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -403,6 +403,16 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C @Override public StoragePool findStoragePool(DiskProfile dskCh, final DataCenterVO dc, Pod pod, Long clusterId, Long hostId, VMInstanceVO vm, final Set avoid) { + Long podId = null; + if (pod != null) { + podId = pod.getId(); + } else if (clusterId != null) { + ClusterVO cluster = _clusterDao.findById(clusterId); + if (cluster != null) { + podId = cluster.getPodId(); + } + } + VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); for (StoragePoolAllocator allocator : _storagePoolAllocators) { @@ -410,7 +420,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C for (StoragePool pool : avoid) { avoidList.addPool(pool.getId()); } - DataCenterDeployment plan = new DataCenterDeployment(dc.getId(), pod.getId(), clusterId, hostId, null, null); + DataCenterDeployment plan = new DataCenterDeployment(dc.getId(), podId, clusterId, hostId, null, null); final List poolList = allocator.allocateToPool(dskCh, profile, plan, avoidList, 1); if (poolList != null && !poolList.isEmpty()) {