Search in sources :

Example 16 with NoTransitionException

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

the class DataObjectManagerImpl method deleteAsynCallback.

protected Void deleteAsynCallback(AsyncCallbackDispatcher<DataObjectManagerImpl, CommandResult> callback, DeleteContext<CommandResult> context) {
    DataObject destObj = context.obj;
    CommandResult res = callback.getResult();
    if (res.isFailed()) {
        try {
            objectInDataStoreMgr.update(destObj, Event.OperationFailed);
        } catch (NoTransitionException e) {
            s_logger.debug("delete failed", e);
        } catch (ConcurrentOperationException e) {
            s_logger.debug("delete failed", e);
        }
    } else {
        try {
            objectInDataStoreMgr.update(destObj, Event.OperationSuccessed);
        } catch (NoTransitionException e) {
            s_logger.debug("delete failed", e);
        } catch (ConcurrentOperationException e) {
            s_logger.debug("delete failed", e);
        }
    }
    context.getParentCallback().complete(res);
    return null;
}
Also used : DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) CommandResult(org.apache.cloudstack.storage.command.CommandResult)

Example 17 with NoTransitionException

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

the class DataObjectManagerImpl method copyAsync.

@Override
public void copyAsync(DataObject srcData, DataObject destData, AsyncCompletionCallback<CreateCmdResult> callback) {
    try {
        objectInDataStoreMgr.update(destData, ObjectInDataStoreStateMachine.Event.CopyingRequested);
    } catch (NoTransitionException e) {
        s_logger.debug("failed to change state", e);
        try {
            objectInDataStoreMgr.update(destData, 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 change state: " + e.toString());
        callback.complete(res);
    } catch (ConcurrentOperationException e) {
        s_logger.debug("failed to change state", e);
        try {
            objectInDataStoreMgr.update(destData, 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 change state: " + e.toString());
        callback.complete(res);
    }
    CopyContext<CreateCmdResult> anotherCall = new CopyContext<CreateCmdResult>(callback, srcData, destData);
    AsyncCallbackDispatcher<DataObjectManagerImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().copyCallback(null, null)).setContext(anotherCall);
    motionSrv.copyAsync(srcData, destData, caller);
}
Also used : NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 18 with NoTransitionException

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

the class DataObjectManagerImpl method createAsync.

@Override
public void createAsync(DataObject data, DataStore store, AsyncCompletionCallback<CreateCmdResult> callback, boolean noCopy) {
    DataObjectInStore obj = objectInDataStoreMgr.findObject(data, store);
    DataObject objInStore = null;
    boolean freshNewTemplate = false;
    if (obj == null) {
        try {
            objInStore = objectInDataStoreMgr.create(data, store);
            freshNewTemplate = true;
        } catch (Throwable e) {
            obj = objectInDataStoreMgr.findObject(data, store);
            if (obj == null) {
                CreateCmdResult result = new CreateCmdResult(null, null);
                result.setSuccess(false);
                result.setResult(e.toString());
                callback.complete(result);
                return;
            }
        }
    }
    if (!freshNewTemplate && obj.getState() != ObjectInDataStoreStateMachine.State.Ready) {
        try {
            objInStore = waitingForCreated(data, store);
        } catch (Exception e) {
            CreateCmdResult result = new CreateCmdResult(null, null);
            result.setSuccess(false);
            result.setResult(e.toString());
            callback.complete(result);
            return;
        }
        CreateCmdResult result = new CreateCmdResult(null, null);
        callback.complete(result);
        return;
    }
    try {
        ObjectInDataStoreStateMachine.Event event = null;
        if (noCopy) {
            event = ObjectInDataStoreStateMachine.Event.CreateOnlyRequested;
        } else {
            event = ObjectInDataStoreStateMachine.Event.CreateRequested;
        }
        objectInDataStoreMgr.update(objInStore, event);
    } catch (NoTransitionException e) {
        try {
            objectInDataStoreMgr.update(objInStore, ObjectInDataStoreStateMachine.Event.OperationFailed);
        } catch (Exception e1) {
            s_logger.debug("state transation failed", e1);
        }
        CreateCmdResult result = new CreateCmdResult(null, null);
        result.setSuccess(false);
        result.setResult(e.toString());
        callback.complete(result);
        return;
    } catch (ConcurrentOperationException e) {
        try {
            objectInDataStoreMgr.update(objInStore, ObjectInDataStoreStateMachine.Event.OperationFailed);
        } catch (Exception e1) {
            s_logger.debug("state transation failed", e1);
        }
        CreateCmdResult result = new CreateCmdResult(null, null);
        result.setSuccess(false);
        result.setResult(e.toString());
        callback.complete(result);
        return;
    }
    CreateContext<CreateCmdResult> context = new CreateContext<CreateCmdResult>(callback, objInStore);
    AsyncCallbackDispatcher<DataObjectManagerImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().createAsynCallback(null, null)).setContext(context);
    store.getDriver().createAsync(store, objInStore, caller);
    return;
}
Also used : DataObjectInStore(org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore) 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) ObjectInDataStoreStateMachine(org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) Event(org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event)

Example 19 with NoTransitionException

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

the class DataObjectManagerImpl method createInternalStateOnly.

@Override
public DataObject createInternalStateOnly(DataObject data, DataStore store) {
    DataObjectInStore obj = objectInDataStoreMgr.findObject(data, store);
    DataObject objInStore = null;
    if (obj == null) {
        objInStore = objectInDataStoreMgr.create(data, store);
    }
    try {
        ObjectInDataStoreStateMachine.Event event = null;
        event = ObjectInDataStoreStateMachine.Event.CreateRequested;
        objectInDataStoreMgr.update(objInStore, event);
        objectInDataStoreMgr.update(objInStore, ObjectInDataStoreStateMachine.Event.OperationSuccessed);
    } catch (NoTransitionException e) {
        s_logger.debug("Failed to update state", e);
        throw new CloudRuntimeException("Failed to update state", e);
    } catch (ConcurrentOperationException e) {
        s_logger.debug("Failed to update state", e);
        throw new CloudRuntimeException("Failed to update state", e);
    }
    return objInStore;
}
Also used : ObjectInDataStoreStateMachine(org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) DataObjectInStore(org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) Event(org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event)

Example 20 with NoTransitionException

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

the class DefaultVMSnapshotStrategy method processAnswer.

@DB
protected void processAnswer(final VMSnapshotVO vmSnapshot, UserVm userVm, final Answer as, Long hostId) {
    try {
        Transaction.execute(new TransactionCallbackWithExceptionNoReturn<NoTransitionException>() {

            @Override
            public void doInTransactionWithoutResult(TransactionStatus status) throws NoTransitionException {
                if (as instanceof CreateVMSnapshotAnswer) {
                    CreateVMSnapshotAnswer answer = (CreateVMSnapshotAnswer) as;
                    finalizeCreate(vmSnapshot, answer.getVolumeTOs());
                    vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.OperationSucceeded);
                } else if (as instanceof RevertToVMSnapshotAnswer) {
                    RevertToVMSnapshotAnswer answer = (RevertToVMSnapshotAnswer) as;
                    finalizeRevert(vmSnapshot, answer.getVolumeTOs());
                    vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.OperationSucceeded);
                } else if (as instanceof DeleteVMSnapshotAnswer) {
                    DeleteVMSnapshotAnswer answer = (DeleteVMSnapshotAnswer) as;
                    finalizeDelete(vmSnapshot, answer.getVolumeTOs());
                    vmSnapshotDao.remove(vmSnapshot.getId());
                }
            }
        });
    } catch (Exception e) {
        String errMsg = "Error while process answer: " + as.getClass() + " due to " + e.getMessage();
        s_logger.error(errMsg, e);
        throw new CloudRuntimeException(errMsg);
    }
}
Also used : CreateVMSnapshotAnswer(com.cloud.agent.api.CreateVMSnapshotAnswer) RevertToVMSnapshotAnswer(com.cloud.agent.api.RevertToVMSnapshotAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) TransactionStatus(com.cloud.utils.db.TransactionStatus) DeleteVMSnapshotAnswer(com.cloud.agent.api.DeleteVMSnapshotAnswer) ConfigurationException(javax.naming.ConfigurationException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) DB(com.cloud.utils.db.DB)

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