Skip to content

Commit b9932a0

Browse files
Likitha Shettyyadvr
authored andcommitted
CLOUDSTACK-8122. Handle NPE thrown during migration failures.
When migration fails instead of returning NULL, throw the exception. (cherry picked from commit a5a65c7) Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent bcbfe3b commit b9932a0

2 files changed

Lines changed: 18 additions & 12 deletions

File tree

‎engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -934,10 +934,10 @@ public Volume migrateVolume(Volume volume, StoragePool destPool) throws StorageU
934934
return result.getVolume();
935935
} catch (InterruptedException e) {
936936
s_logger.debug("migrate volume failed", e);
937-
return null;
937+
throw new CloudRuntimeException(e.getMessage());
938938
} catch (ExecutionException e) {
939939
s_logger.debug("migrate volume failed", e);
940-
return null;
940+
throw new CloudRuntimeException(e.getMessage());
941941
}
942942
}
943943

‎server/src/com/cloud/storage/VolumeApiServiceImpl.java‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,6 +1817,8 @@ public Volume migrateVolume(MigrateVolumeCmd cmd) {
18171817
if (jobResult != null) {
18181818
if (jobResult instanceof ConcurrentOperationException)
18191819
throw (ConcurrentOperationException)jobResult;
1820+
else if (jobResult instanceof RuntimeException)
1821+
throw (RuntimeException)jobResult;
18201822
else if (jobResult instanceof Throwable)
18211823
throw new RuntimeException("Unexpected exception", (Throwable)jobResult);
18221824
}
@@ -1839,35 +1841,39 @@ private Volume orchestrateMigrateVolume(long volumeId, long destPoolId, boolean
18391841
assert (destPool != null);
18401842

18411843
Volume newVol = null;
1842-
if (liveMigrateVolume) {
1843-
newVol = liveMigrateVolume(vol, destPool);
1844-
} else {
1845-
try {
1844+
try {
1845+
if (liveMigrateVolume) {
1846+
newVol = liveMigrateVolume(vol, destPool);
1847+
} else {
18461848
newVol = _volumeMgr.migrateVolume(vol, destPool);
1847-
} catch (StorageUnavailableException e) {
1848-
s_logger.debug("Failed to migrate volume", e);
18491849
}
1850+
} catch (StorageUnavailableException e) {
1851+
s_logger.debug("Failed to migrate volume", e);
1852+
throw new CloudRuntimeException(e.getMessage());
1853+
} catch (Exception e) {
1854+
s_logger.debug("Failed to migrate volume", e);
1855+
throw new CloudRuntimeException(e.getMessage());
18501856
}
18511857
return newVol;
18521858
}
18531859

18541860
@DB
1855-
protected Volume liveMigrateVolume(Volume volume, StoragePool destPool) {
1861+
protected Volume liveMigrateVolume(Volume volume, StoragePool destPool) throws StorageUnavailableException {
18561862
VolumeInfo vol = volFactory.getVolume(volume.getId());
18571863
AsyncCallFuture<VolumeApiResult> future = volService.migrateVolume(vol, (DataStore)destPool);
18581864
try {
18591865
VolumeApiResult result = future.get();
18601866
if (result.isFailed()) {
18611867
s_logger.debug("migrate volume failed:" + result.getResult());
1862-
return null;
1868+
throw new StorageUnavailableException("Migrate volume failed: " + result.getResult(), destPool.getId());
18631869
}
18641870
return result.getVolume();
18651871
} catch (InterruptedException e) {
18661872
s_logger.debug("migrate volume failed", e);
1867-
return null;
1873+
throw new CloudRuntimeException(e.getMessage());
18681874
} catch (ExecutionException e) {
18691875
s_logger.debug("migrate volume failed", e);
1870-
return null;
1876+
throw new CloudRuntimeException(e.getMessage());
18711877
}
18721878
}
18731879

0 commit comments

Comments
 (0)