diff --git a/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java b/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java index 66001ad408b..32f9a9aa101 100644 --- a/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java +++ b/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java @@ -248,12 +248,11 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { protected Answer cloneVolume(DataObject template, DataObject volume) { CopyCommand cmd = new CopyCommand(template.getTO(), volume.getTO(), 0); - StoragePool pool = (StoragePool)volume.getDataStore(); - try { - Answer answer = storageMgr.sendToPool(pool, null, cmd); + EndPoint ep = this.selector.select(volume.getDataStore()); + Answer answer = ep.sendMessage(cmd); return answer; - } catch (StorageUnavailableException e) { + } catch (Exception e) { s_logger.debug("Failed to send to storage pool", e); throw new CloudRuntimeException("Failed to send to storage pool", e); } @@ -302,16 +301,17 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { destData.getType() == DataObjectType.SNAPSHOT) { answer = copySnapshot(srcData, destData); } + + if (answer != null && !answer.getResult()) { + errMsg = answer.getDetails(); + } } catch (Exception e) { s_logger.debug("copy failed", e); errMsg = e.toString(); } CopyCommandResult result = new CopyCommandResult(null, answer); - if (!answer.getResult()) { - result.setResult(answer.getDetails()); - } + result.setResult(errMsg); callback.complete(result); - return null; } diff --git a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/VolumeTest.java b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/VolumeTest.java index cceceda35ba..c4a1d01b1a3 100644 --- a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/VolumeTest.java +++ b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/VolumeTest.java @@ -240,9 +240,11 @@ public class VolumeTest extends CloudStackTestNGBase { List hosts = new ArrayList(); hosts.add(this.host); Mockito.when(resourceMgr.listAllUpAndEnabledHosts((Type) Mockito.any(), Mockito.anyLong(), Mockito.anyLong(), Mockito.anyLong())).thenReturn(hosts); - Mockito.when(epSelector.select(Mockito.any(DataObject.class))).thenReturn(new LocalHostEndpoint()); + RemoteHostEndPoint ep = RemoteHostEndPoint.getHypervisorHostEndPoint(this.host.getId(), this.host.getPrivateIpAddress()); Mockito.when(epSelector.select(Mockito.any(DataObject.class), Mockito.any(DataObject.class))).thenReturn(ep); + Mockito.when(epSelector.select(Mockito.any(DataObject.class))).thenReturn(ep); + Mockito.when(epSelector.select(Mockito.any(DataStore.class))).thenReturn(ep); } public DataStore createPrimaryDataStore() { diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java index 07a5430aa6d..1f049cd8c09 100644 --- a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java +++ b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java @@ -401,12 +401,12 @@ public class VolumeServiceImpl implements VolumeService { } private class CreateVolumeFromBaseImageContext extends AsyncRpcConext { - private final VolumeObject vo; + private final DataObject vo; private final AsyncCallFuture future; private final DataStore primaryStore; private final DataObject templateOnStore; private final SnapshotInfo snapshot; - public CreateVolumeFromBaseImageContext(AsyncCompletionCallback callback, VolumeObject vo, + public CreateVolumeFromBaseImageContext(AsyncCompletionCallback callback, DataObject vo, DataStore primaryStore, DataObject templateOnStore, AsyncCallFuture future, SnapshotInfo snapshot) { @@ -426,14 +426,13 @@ public class VolumeServiceImpl implements VolumeService { @DB protected void createVolumeFromBaseImageAsync(VolumeInfo volume, DataObject templateOnPrimaryStore, PrimaryDataStore pd, AsyncCallFuture future) { - VolumeObject vo = (VolumeObject)volume; - CreateVolumeFromBaseImageContext context = new CreateVolumeFromBaseImageContext(null, vo, pd, templateOnPrimaryStore, future, null); - AsyncCallbackDispatcher caller = AsyncCallbackDispatcher.create(this); - caller.setCallback(caller.getTarget().createVolumeFromBaseImageCallBack(null, null)) - .setContext(context); - DataObject volumeOnPrimaryStorage = pd.create(volume); - volume.processEvent(Event.CreateOnlyRequested); + volumeOnPrimaryStorage.processEvent(Event.CreateOnlyRequested); + + CreateVolumeFromBaseImageContext context = new CreateVolumeFromBaseImageContext(null, volumeOnPrimaryStorage, pd, templateOnPrimaryStore, future, null); + AsyncCallbackDispatcher caller = AsyncCallbackDispatcher.create(this); + caller.setCallback(caller.getTarget().createVolumeFromBaseImageCallBack(null, null)); + caller.setContext(context); motionSrv.copyAsync(context.templateOnStore, volumeOnPrimaryStorage, caller); return; @@ -441,9 +440,9 @@ public class VolumeServiceImpl implements VolumeService { @DB protected Void createVolumeFromBaseImageCallBack(AsyncCallbackDispatcher callback, CreateVolumeFromBaseImageContext context) { - VolumeObject vo = context.vo; + DataObject vo = context.vo; CopyCommandResult result = callback.getResult(); - VolumeApiResult volResult = new VolumeApiResult(vo); + VolumeApiResult volResult = new VolumeApiResult((VolumeObject)vo); if (result.isSuccess()) { vo.processEvent(Event.OperationSuccessed, result.getAnswer()); @@ -516,7 +515,7 @@ public class VolumeServiceImpl implements VolumeService { protected Void createVolumeFromSnapshotCallback(AsyncCallbackDispatcher callback, CreateVolumeFromBaseImageContext context) { CopyCommandResult result = callback.getResult(); - VolumeInfo volume = context.vo; + VolumeInfo volume = (VolumeInfo)context.vo; SnapshotInfo snapshot = context.snapshot; VolumeApiResult apiResult = new VolumeApiResult(volume); Event event = null;