Search in sources :

Example 26 with CommandResult

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());
}
Also used : MigrateWithStorageAnswer(com.cloud.agent.api.MigrateWithStorageAnswer) MigrateWithStorageCommand(com.cloud.agent.api.MigrateWithStorageCommand) HashMap(java.util.HashMap) VMInstanceVO(com.cloud.vm.VMInstanceVO) Host(com.cloud.host.Host) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) Test(org.junit.Test)

Example 27 with CommandResult

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());
}
Also used : MigrateWithStorageAnswer(com.cloud.agent.api.MigrateWithStorageAnswer) MigrateWithStorageCommand(com.cloud.agent.api.MigrateWithStorageCommand) HashMap(java.util.HashMap) VMInstanceVO(com.cloud.vm.VMInstanceVO) Host(com.cloud.host.Host) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) Test(org.junit.Test)

Example 28 with CommandResult

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);
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) SolidFireUtil(org.apache.cloudstack.storage.datastore.util.SolidFireUtil) SnapshotDetailsVO(com.cloud.storage.dao.SnapshotDetailsVO) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)

Example 29 with 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;
}
Also used : CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) CommandResult(org.apache.cloudstack.storage.command.CommandResult)

Example 30 with CommandResult

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;
}
Also used : SnapshotResult(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)

Aggregations

CommandResult (org.apache.cloudstack.storage.command.CommandResult)37 CopyCommandResult (org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)35 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)17 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)15 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)12 ExecutionException (java.util.concurrent.ExecutionException)11 SnapshotInfo (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo)9 AsyncCallFuture (org.apache.cloudstack.framework.async.AsyncCallFuture)9 PrimaryDataStore (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)8 SnapshotResult (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult)7 VolumeVO (com.cloud.storage.VolumeVO)6 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)6 HashMap (java.util.HashMap)6 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)5 Answer (com.cloud.agent.api.Answer)4 MigrateWithStorageAnswer (com.cloud.agent.api.MigrateWithStorageAnswer)4 MigrateWithStorageCommand (com.cloud.agent.api.MigrateWithStorageCommand)4 VirtualMachineTO (com.cloud.agent.api.to.VirtualMachineTO)4 Host (com.cloud.host.Host)4 VMInstanceVO (com.cloud.vm.VMInstanceVO)4