Search in sources :

Example 11 with SnapshotResult

use of org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult in project cloudstack by apache.

the class SnapshotServiceImpl method deleteSnapshot.

@Override
public boolean deleteSnapshot(SnapshotInfo snapInfo) {
    snapInfo.processEvent(ObjectInDataStoreStateMachine.Event.DestroyRequested);
    AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<SnapshotResult>();
    DeleteSnapshotContext<CommandResult> context = new DeleteSnapshotContext<CommandResult>(null, snapInfo, future);
    AsyncCallbackDispatcher<SnapshotServiceImpl, CommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().deleteSnapshotCallback(null, null)).setContext(context);
    DataStore store = snapInfo.getDataStore();
    store.getDriver().deleteAsync(store, snapInfo, caller);
    SnapshotResult result = null;
    try {
        result = future.get();
        if (result.isFailed()) {
            throw new CloudRuntimeException(result.getResult());
        }
        return true;
    } catch (InterruptedException e) {
        s_logger.debug("delete snapshot is failed: " + e.toString());
    } catch (ExecutionException e) {
        s_logger.debug("delete snapshot is failed: " + e.toString());
    }
    return false;
}
Also used : AsyncCallFuture(org.apache.cloudstack.framework.async.AsyncCallFuture) SnapshotResult(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) ExecutionException(java.util.concurrent.ExecutionException) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)

Example 12 with SnapshotResult

use of org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult in project cloudstack by apache.

the class SnapshotServiceImpl method deleteSnapshotCallback.

protected Void deleteSnapshotCallback(AsyncCallbackDispatcher<SnapshotServiceImpl, CommandResult> callback, DeleteSnapshotContext<CommandResult> context) {
    CommandResult result = callback.getResult();
    AsyncCallFuture<SnapshotResult> future = context.future;
    SnapshotInfo snapshot = context.snapshot;
    SnapshotResult res = null;
    try {
        if (result.isFailed()) {
            s_logger.debug("delete snapshot failed" + result.getResult());
            snapshot.processEvent(ObjectInDataStoreStateMachine.Event.OperationFailed);
            res = new SnapshotResult(context.snapshot, null);
            res.setResult(result.getResult());
        } else {
            snapshot.processEvent(ObjectInDataStoreStateMachine.Event.OperationSuccessed);
            res = new SnapshotResult(context.snapshot, null);
        }
    } catch (Exception e) {
        s_logger.debug("Failed to in deleteSnapshotCallback", e);
        res.setResult(e.toString());
    }
    future.complete(res);
    return null;
}
Also used : SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) 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)

Example 13 with SnapshotResult

use of org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult 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 14 with SnapshotResult

use of org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult 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 15 with SnapshotResult

use of org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult 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

SnapshotResult (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult)15 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)12 SnapshotInfo (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo)11 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)10 ExecutionException (java.util.concurrent.ExecutionException)10 CopyCommandResult (org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)9 CommandResult (org.apache.cloudstack.storage.command.CommandResult)7 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)5 AsyncCallFuture (org.apache.cloudstack.framework.async.AsyncCallFuture)5 SnapshotVO (com.cloud.storage.SnapshotVO)4 PrimaryDataStore (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)3 SnapshotDataStoreVO (org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)3 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 DB (com.cloud.utils.db.DB)2 CreateCmdResult (org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult)2 PrimaryDataStoreDriver (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver)2 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)2 HostVO (com.cloud.host.HostVO)1 CreateSnapshotPayload (com.cloud.storage.CreateSnapshotPayload)1 SnapshotDetailsVO (com.cloud.storage.dao.SnapshotDetailsVO)1