use of org.apache.cloudstack.storage.command.CommandResult in project cloudstack by apache.
the class VmwareStorageMotionStrategyTest method testMigrateWithinClusterSuccess.
@Test
public void testMigrateWithinClusterSuccess() throws Exception {
Host srcHost = mock(Host.class);
Host destHost = mock(Host.class);
when(srcHost.getClusterId()).thenReturn(1L);
when(destHost.getClusterId()).thenReturn(1L);
Map<VolumeInfo, DataStore> volumeMap = new HashMap<VolumeInfo, DataStore>();
VirtualMachineTO to = mock(VirtualMachineTO.class);
when(to.getId()).thenReturn(6L);
VMInstanceVO instance = mock(VMInstanceVO.class);
when(instanceDao.findById(6L)).thenReturn(instance);
MockContext<CommandResult> context = new MockContext<CommandResult>(null, null, volumeMap);
AsyncCallbackDispatcher<VmwareStorageMotionStrategyTest, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().mockCallBack(null, null)).setContext(context);
MigrateWithStorageAnswer migAnswerMock = mock(MigrateWithStorageAnswer.class);
when(migAnswerMock.getResult()).thenReturn(true);
when(agentMgr.send(anyLong(), isA(MigrateWithStorageCommand.class))).thenReturn(migAnswerMock);
strategy.copyAsync(volumeMap, to, srcHost, destHost, caller);
assertTrue("Migration within cluster isn't successful.", result.isSuccess());
}
use of org.apache.cloudstack.storage.command.CommandResult in project cloudstack by apache.
the class VmwareStorageMotionStrategyTest method testMigrateWithinClusterFailure.
@Test
public void testMigrateWithinClusterFailure() throws Exception {
Host srcHost = mock(Host.class);
Host destHost = mock(Host.class);
when(srcHost.getClusterId()).thenReturn(1L);
when(destHost.getClusterId()).thenReturn(1L);
Map<VolumeInfo, DataStore> volumeMap = new HashMap<VolumeInfo, DataStore>();
VirtualMachineTO to = mock(VirtualMachineTO.class);
when(to.getId()).thenReturn(6L);
VMInstanceVO instance = mock(VMInstanceVO.class);
when(instanceDao.findById(6L)).thenReturn(instance);
MockContext<CommandResult> context = new MockContext<CommandResult>(null, null, volumeMap);
AsyncCallbackDispatcher<VmwareStorageMotionStrategyTest, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().mockCallBack(null, null)).setContext(context);
MigrateWithStorageAnswer migAnswerMock = mock(MigrateWithStorageAnswer.class);
when(migAnswerMock.getResult()).thenReturn(false);
when(agentMgr.send(anyLong(), isA(MigrateWithStorageCommand.class))).thenReturn(migAnswerMock);
strategy.copyAsync(volumeMap, to, srcHost, destHost, caller);
assertFalse("Migration within cluster didn't fail.", result.isSuccess());
}
use of org.apache.cloudstack.storage.command.CommandResult in project cloudstack by apache.
the class SolidFirePrimaryDataStoreDriver method revertSnapshot.
@Override
public void revertSnapshot(SnapshotInfo snapshot, SnapshotInfo snapshot2, AsyncCompletionCallback<CommandResult> callback) {
VolumeInfo volumeInfo = snapshot.getBaseVolume();
VolumeVO volumeVO = volumeDao.findById(volumeInfo.getId());
if (volumeVO == null || volumeVO.getRemoved() != null) {
String errMsg = "The volume that the snapshot belongs to no longer exists.";
CommandResult commandResult = new CommandResult();
commandResult.setResult(errMsg);
callback.complete(commandResult);
return;
}
SolidFireUtil.SolidFireConnection sfConnection = SolidFireUtil.getSolidFireConnection(volumeVO.getPoolId(), storagePoolDetailsDao);
long sfVolumeId = Long.parseLong(volumeInfo.getFolder());
SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(snapshot.getId(), SolidFireUtil.SNAPSHOT_ID);
long sfSnapshotId = Long.parseLong(snapshotDetails.getValue());
SolidFireUtil.rollBackVolumeToSnapshot(sfConnection, sfVolumeId, sfSnapshotId);
SolidFireUtil.SolidFireVolume sfVolume = SolidFireUtil.getVolume(sfConnection, sfVolumeId);
updateVolumeDetails(volumeVO.getId(), sfVolume.getTotalSize(), sfVolume.getScsiNaaDeviceId());
CommandResult commandResult = new CommandResult();
callback.complete(commandResult);
}
use of org.apache.cloudstack.storage.command.CommandResult in project cloudstack by apache.
the class FakePrimaryDataStoreDriver method deleteAsync.
@Override
public void deleteAsync(DataStore store, DataObject data, AsyncCompletionCallback<CommandResult> callback) {
CommandResult result = new CommandResult();
result.setSuccess(true);
callback.complete(result);
return;
}
use of org.apache.cloudstack.storage.command.CommandResult in project cloudstack by apache.
the class SnapshotServiceImpl method revertSnapshotCallback.
protected Void revertSnapshotCallback(AsyncCallbackDispatcher<SnapshotServiceImpl, CommandResult> callback, RevertSnapshotContext<CommandResult> context) {
CommandResult result = callback.getResult();
AsyncCallFuture<SnapshotResult> future = context.future;
SnapshotResult res = null;
try {
if (result.isFailed()) {
s_logger.debug("revert snapshot failed" + result.getResult());
res = new SnapshotResult(context.snapshot, null);
res.setResult(result.getResult());
} else {
res = new SnapshotResult(context.snapshot, null);
}
} catch (Exception e) {
s_logger.debug("Failed to in revertSnapshotCallback", e);
res.setResult(e.toString());
}
future.complete(res);
return null;
}
Aggregations