From ffd5f1a777ac9af5b65b1fcd357684d7dafcce87 Mon Sep 17 00:00:00 2001 From: Sanjay Tripathi Date: Thu, 6 Jun 2013 16:43:04 +0530 Subject: [PATCH] CLOUDSTACK-2288: NPE while creating volume from snapshot when the primary storage is in maintenance state. Signed-off-by: Prasanna Santhanam --- server/src/com/cloud/storage/VolumeManagerImpl.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/server/src/com/cloud/storage/VolumeManagerImpl.java b/server/src/com/cloud/storage/VolumeManagerImpl.java index a293da5c9a7..30fb322f415 100644 --- a/server/src/com/cloud/storage/VolumeManagerImpl.java +++ b/server/src/com/cloud/storage/VolumeManagerImpl.java @@ -527,7 +527,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager { @DB protected VolumeInfo createVolumeFromSnapshot(VolumeVO volume, - SnapshotVO snapshot) { + SnapshotVO snapshot) throws StorageUnavailableException { Account account = _accountDao.findById(volume.getAccountId()); final HashSet poolsToAvoid = new HashSet(); @@ -555,6 +555,12 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager { } } + if (pool == null) { + String msg = "There are no available storage pools to store the volume in"; + s_logger.info(msg); + throw new StorageUnavailableException(msg, -1); + } + VolumeInfo vol = volFactory.getVolume(volume.getId()); DataStore store = dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary); SnapshotInfo snapInfo = snapshotFactory.getSnapshot(snapshot.getId(), DataStoreRole.Image); @@ -605,7 +611,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager { } } - protected VolumeVO createVolumeFromSnapshot(VolumeVO volume, long snapshotId) { + protected VolumeVO createVolumeFromSnapshot(VolumeVO volume, long snapshotId) throws StorageUnavailableException { VolumeInfo createdVolume = null; SnapshotVO snapshot = _snapshotDao.findById(snapshotId); createdVolume = createVolumeFromSnapshot(volume,