From a5a65c7b551ee5cc32588997937267b716eff681 Mon Sep 17 00:00:00 2001 From: Likitha Shetty Date: Fri, 5 Dec 2014 16:00:21 +0530 Subject: [PATCH] CLOUDSTACK-8122. Handle NPE thrown during migration failures. When migration fails instead of returning NULL, throw the exception. --- .../orchestration/VolumeOrchestrator.java | 4 +-- .../cloud/storage/VolumeApiServiceImpl.java | 26 ++++++++++++------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java index e04bd6d4f5f..1b87ccf4490 100644 --- a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java @@ -937,10 +937,10 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati return result.getVolume(); } catch (InterruptedException e) { s_logger.debug("migrate volume failed", e); - return null; + throw new CloudRuntimeException(e.getMessage()); } catch (ExecutionException e) { s_logger.debug("migrate volume failed", e); - return null; + throw new CloudRuntimeException(e.getMessage()); } } diff --git a/server/src/com/cloud/storage/VolumeApiServiceImpl.java b/server/src/com/cloud/storage/VolumeApiServiceImpl.java index c1652ed8722..7fa600a8f36 100644 --- a/server/src/com/cloud/storage/VolumeApiServiceImpl.java +++ b/server/src/com/cloud/storage/VolumeApiServiceImpl.java @@ -1795,6 +1795,8 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic if (jobResult != null) { if (jobResult instanceof ConcurrentOperationException) throw (ConcurrentOperationException)jobResult; + else if (jobResult instanceof RuntimeException) + throw (RuntimeException)jobResult; else if (jobResult instanceof Throwable) throw new RuntimeException("Unexpected exception", (Throwable)jobResult); } @@ -1817,35 +1819,39 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic assert (destPool != null); Volume newVol = null; - if (liveMigrateVolume) { - newVol = liveMigrateVolume(vol, destPool); - } else { - try { + try { + if (liveMigrateVolume) { + newVol = liveMigrateVolume(vol, destPool); + } else { newVol = _volumeMgr.migrateVolume(vol, destPool); - } catch (StorageUnavailableException e) { - s_logger.debug("Failed to migrate volume", e); } + } catch (StorageUnavailableException e) { + s_logger.debug("Failed to migrate volume", e); + throw new CloudRuntimeException(e.getMessage()); + } catch (Exception e) { + s_logger.debug("Failed to migrate volume", e); + throw new CloudRuntimeException(e.getMessage()); } return newVol; } @DB - protected Volume liveMigrateVolume(Volume volume, StoragePool destPool) { + protected Volume liveMigrateVolume(Volume volume, StoragePool destPool) throws StorageUnavailableException { VolumeInfo vol = volFactory.getVolume(volume.getId()); AsyncCallFuture future = volService.migrateVolume(vol, (DataStore)destPool); try { VolumeApiResult result = future.get(); if (result.isFailed()) { s_logger.debug("migrate volume failed:" + result.getResult()); - return null; + throw new StorageUnavailableException("Migrate volume failed: " + result.getResult(), destPool.getId()); } return result.getVolume(); } catch (InterruptedException e) { s_logger.debug("migrate volume failed", e); - return null; + throw new CloudRuntimeException(e.getMessage()); } catch (ExecutionException e) { s_logger.debug("migrate volume failed", e); - return null; + throw new CloudRuntimeException(e.getMessage()); } }