Search in sources :

Example 36 with NoTransitionException

use of com.cloud.utils.fsm.NoTransitionException in project cloudstack by apache.

the class DataObjectManagerImpl method createAsynCallback.

protected Void createAsynCallback(AsyncCallbackDispatcher<DataObjectManagerImpl, CreateCmdResult> callback, CreateContext<CreateCmdResult> context) {
    CreateCmdResult result = callback.getResult();
    DataObject objInStrore = context.objInStrore;
    CreateCmdResult upResult = new CreateCmdResult(null, null);
    if (result.isFailed()) {
        upResult.setResult(result.getResult());
        context.getParentCallback().complete(upResult);
        return null;
    }
    try {
        objectInDataStoreMgr.update(objInStrore, ObjectInDataStoreStateMachine.Event.OperationSuccessed);
    } catch (NoTransitionException e) {
        try {
            objectInDataStoreMgr.update(objInStrore, ObjectInDataStoreStateMachine.Event.OperationFailed);
        } catch (Exception e1) {
            s_logger.debug("failed to change state", e1);
        }
        upResult.setResult(e.toString());
        context.getParentCallback().complete(upResult);
        return null;
    } catch (ConcurrentOperationException e) {
        try {
            objectInDataStoreMgr.update(objInStrore, ObjectInDataStoreStateMachine.Event.OperationFailed);
        } catch (Exception e1) {
            s_logger.debug("failed to change state", e1);
        }
        upResult.setResult(e.toString());
        context.getParentCallback().complete(upResult);
        return null;
    }
    context.getParentCallback().complete(result);
    return null;
}
Also used : DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 37 with NoTransitionException

use of com.cloud.utils.fsm.NoTransitionException in project cloudstack by apache.

the class DataObjectManagerImpl method copyCallback.

protected Void copyCallback(AsyncCallbackDispatcher<DataObjectManagerImpl, CopyCommandResult> callback, CopyContext<CreateCmdResult> context) {
    CopyCommandResult result = callback.getResult();
    DataObject destObj = context.destObj;
    if (result.isFailed()) {
        try {
            objectInDataStoreMgr.update(destObj, Event.OperationFailed);
        } catch (NoTransitionException e) {
            s_logger.debug("Failed to update copying state", e);
        } catch (ConcurrentOperationException e) {
            s_logger.debug("Failed to update copying state", e);
        }
        CreateCmdResult res = new CreateCmdResult(null, null);
        res.setResult(result.getResult());
        context.getParentCallback().complete(res);
    }
    try {
        objectInDataStoreMgr.update(destObj, ObjectInDataStoreStateMachine.Event.OperationSuccessed);
    } catch (NoTransitionException e) {
        s_logger.debug("Failed to update copying state: ", e);
        try {
            objectInDataStoreMgr.update(destObj, ObjectInDataStoreStateMachine.Event.OperationFailed);
        } catch (Exception e1) {
            s_logger.debug("failed to further change state to OperationFailed", e1);
        }
        CreateCmdResult res = new CreateCmdResult(null, null);
        res.setResult("Failed to update copying state: " + e.toString());
        context.getParentCallback().complete(res);
    } catch (ConcurrentOperationException e) {
        s_logger.debug("Failed to update copying state: ", e);
        try {
            objectInDataStoreMgr.update(destObj, ObjectInDataStoreStateMachine.Event.OperationFailed);
        } catch (Exception e1) {
            s_logger.debug("failed to further change state to OperationFailed", e1);
        }
        CreateCmdResult res = new CreateCmdResult(null, null);
        res.setResult("Failed to update copying state: " + e.toString());
        context.getParentCallback().complete(res);
    }
    CreateCmdResult res = new CreateCmdResult(result.getPath(), null);
    context.getParentCallback().complete(res);
    return null;
}
Also used : DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 38 with NoTransitionException

use of com.cloud.utils.fsm.NoTransitionException in project cloudstack by apache.

the class SnapshotServiceImpl method createSnapshotAsyncCallback.

protected Void createSnapshotAsyncCallback(AsyncCallbackDispatcher<SnapshotServiceImpl, CreateCmdResult> callback, CreateSnapshotContext<CreateCmdResult> context) {
    CreateCmdResult result = callback.getResult();
    SnapshotObject snapshot = (SnapshotObject) context.snapshot;
    AsyncCallFuture<SnapshotResult> future = context.future;
    SnapshotResult snapResult = new SnapshotResult(snapshot, result.getAnswer());
    if (result.isFailed()) {
        s_logger.debug("create snapshot " + context.snapshot.getName() + " failed: " + result.getResult());
        try {
            snapshot.processEvent(Snapshot.Event.OperationFailed);
            snapshot.processEvent(Event.OperationFailed);
        } catch (Exception e) {
            s_logger.debug("Failed to update snapshot state due to " + e.getMessage());
        }
        snapResult.setResult(result.getResult());
        future.complete(snapResult);
        return null;
    }
    try {
        snapshot.processEvent(Event.OperationSuccessed, result.getAnswer());
        snapshot.processEvent(Snapshot.Event.OperationSucceeded);
    } catch (Exception e) {
        s_logger.debug("Failed to create snapshot: ", e);
        snapResult.setResult(e.toString());
        try {
            snapshot.processEvent(Snapshot.Event.OperationFailed);
        } catch (NoTransitionException e1) {
            s_logger.debug("Failed to change snapshot state: " + e1.toString());
        }
    }
    future.complete(snapResult);
    return null;
}
Also used : SnapshotResult(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException)

Example 39 with NoTransitionException

use of com.cloud.utils.fsm.NoTransitionException in project cloudstack by apache.

the class SnapshotServiceImpl method backupSnapshot.

@Override
public SnapshotInfo backupSnapshot(SnapshotInfo snapshot) {
    SnapshotObject snapObj = (SnapshotObject) snapshot;
    AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<SnapshotResult>();
    SnapshotResult result = new SnapshotResult(snapshot, null);
    try {
        snapObj.processEvent(Snapshot.Event.BackupToSecondary);
        DataStore imageStore = findSnapshotImageStore(snapshot);
        if (imageStore == null) {
            throw new CloudRuntimeException("can not find an image stores");
        }
        SnapshotInfo snapshotOnImageStore = (SnapshotInfo) imageStore.create(snapshot);
        snapshotOnImageStore.processEvent(Event.CreateOnlyRequested);
        CopySnapshotContext<CommandResult> context = new CopySnapshotContext<CommandResult>(null, snapshot, snapshotOnImageStore, future);
        AsyncCallbackDispatcher<SnapshotServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().copySnapshotAsyncCallback(null, null)).setContext(context);
        motionSrv.copyAsync(snapshot, snapshotOnImageStore, caller);
    } catch (Exception e) {
        s_logger.debug("Failed to copy snapshot", e);
        result.setResult("Failed to copy snapshot:" + e.toString());
        try {
            snapObj.processEvent(Snapshot.Event.OperationFailed);
        } catch (NoTransitionException e1) {
            s_logger.debug("Failed to change state: " + e1.toString());
        }
        future.complete(result);
    }
    try {
        SnapshotResult res = future.get();
        if (res.isFailed()) {
            throw new CloudRuntimeException(res.getResult());
        }
        SnapshotInfo destSnapshot = res.getSnapshot();
        return destSnapshot;
    } catch (InterruptedException e) {
        s_logger.debug("failed copy snapshot", e);
        throw new CloudRuntimeException("Failed to copy snapshot", e);
    } catch (ExecutionException e) {
        s_logger.debug("Failed to copy snapshot", e);
        throw new CloudRuntimeException("Failed to copy snapshot", e);
    }
}
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) AsyncCallFuture(org.apache.cloudstack.framework.async.AsyncCallFuture) SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) ExecutionException(java.util.concurrent.ExecutionException) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)

Example 40 with NoTransitionException

use of com.cloud.utils.fsm.NoTransitionException in project cloudstack by apache.

the class DefaultVMSnapshotStrategy method revertVMSnapshot.

@Override
public boolean revertVMSnapshot(VMSnapshot vmSnapshot) {
    VMSnapshotVO vmSnapshotVO = (VMSnapshotVO) vmSnapshot;
    UserVmVO userVm = userVmDao.findById(vmSnapshot.getVmId());
    try {
        vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshotVO, VMSnapshot.Event.RevertRequested);
    } catch (NoTransitionException e) {
        throw new CloudRuntimeException(e.getMessage());
    }
    boolean result = false;
    try {
        VMSnapshotVO snapshot = vmSnapshotDao.findById(vmSnapshotVO.getId());
        List<VolumeObjectTO> volumeTOs = vmSnapshotHelper.getVolumeTOList(userVm.getId());
        String vmInstanceName = userVm.getInstanceName();
        VMSnapshotTO parent = vmSnapshotHelper.getSnapshotWithParents(snapshot).getParent();
        VMSnapshotTO vmSnapshotTO = new VMSnapshotTO(snapshot.getId(), snapshot.getName(), snapshot.getType(), snapshot.getCreated().getTime(), snapshot.getDescription(), snapshot.getCurrent(), parent, true);
        Long hostId = vmSnapshotHelper.pickRunningHost(vmSnapshot.getVmId());
        GuestOSVO guestOS = guestOSDao.findById(userVm.getGuestOSId());
        RevertToVMSnapshotCommand revertToSnapshotCommand = new RevertToVMSnapshotCommand(vmInstanceName, userVm.getUuid(), vmSnapshotTO, volumeTOs, guestOS.getDisplayName());
        HostVO host = hostDao.findById(hostId);
        GuestOSHypervisorVO guestOsMapping = guestOsHypervisorDao.findByOsIdAndHypervisor(guestOS.getId(), host.getHypervisorType().toString(), host.getHypervisorVersion());
        if (guestOsMapping == null) {
            revertToSnapshotCommand.setPlatformEmulator(null);
        } else {
            revertToSnapshotCommand.setPlatformEmulator(guestOsMapping.getGuestOsName());
        }
        RevertToVMSnapshotAnswer answer = (RevertToVMSnapshotAnswer) agentMgr.send(hostId, revertToSnapshotCommand);
        if (answer != null && answer.getResult()) {
            processAnswer(vmSnapshotVO, userVm, answer, hostId);
            result = true;
        } else {
            String errMsg = "Revert VM: " + userVm.getInstanceName() + " to snapshot: " + vmSnapshotVO.getName() + " failed";
            if (answer != null && answer.getDetails() != null)
                errMsg = errMsg + " due to " + answer.getDetails();
            s_logger.error(errMsg);
            throw new CloudRuntimeException(errMsg);
        }
    } catch (OperationTimedoutException e) {
        s_logger.debug("Failed to revert vm snapshot", e);
        throw new CloudRuntimeException(e.getMessage());
    } catch (AgentUnavailableException e) {
        s_logger.debug("Failed to revert vm snapshot", e);
        throw new CloudRuntimeException(e.getMessage());
    } finally {
        if (!result) {
            try {
                vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.OperationFailed);
            } catch (NoTransitionException e1) {
                s_logger.error("Cannot set vm snapshot state due to: " + e1.getMessage());
            }
        }
    }
    return result;
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) RevertToVMSnapshotAnswer(com.cloud.agent.api.RevertToVMSnapshotAnswer) RevertToVMSnapshotCommand(com.cloud.agent.api.RevertToVMSnapshotCommand) GuestOSVO(com.cloud.storage.GuestOSVO) HostVO(com.cloud.host.HostVO) GuestOSHypervisorVO(com.cloud.storage.GuestOSHypervisorVO) VMSnapshotVO(com.cloud.vm.snapshot.VMSnapshotVO) VMSnapshotTO(com.cloud.agent.api.VMSnapshotTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO)

Aggregations

NoTransitionException (com.cloud.utils.fsm.NoTransitionException)47 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)36 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)17 HostVO (com.cloud.host.HostVO)12 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)11 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)11 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)10 DB (com.cloud.utils.db.DB)9 Answer (com.cloud.agent.api.Answer)7 CopyCommandResult (org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)7 CreateCmdResult (org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult)7 VolumeVO (com.cloud.storage.VolumeVO)6 VMInstanceVO (com.cloud.vm.VMInstanceVO)6 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)5 CheckVirtualMachineAnswer (com.cloud.agent.api.CheckVirtualMachineAnswer)5 ClusterVMMetaDataSyncAnswer (com.cloud.agent.api.ClusterVMMetaDataSyncAnswer)5 PlugNicAnswer (com.cloud.agent.api.PlugNicAnswer)5 RebootAnswer (com.cloud.agent.api.RebootAnswer)5 RestoreVMSnapshotAnswer (com.cloud.agent.api.RestoreVMSnapshotAnswer)5 StartAnswer (com.cloud.agent.api.StartAnswer)5