Search in sources :

Example 1 with PrimaryDataStoreDriver

use of com.cloud.engine.subsystem.api.storage.PrimaryDataStoreDriver in project cosmic by MissionCriticalCloud.

the class SnapshotServiceImpl method takeSnapshot.

@Override
public SnapshotResult takeSnapshot(final SnapshotInfo snap) {
    final SnapshotObject snapshot = (SnapshotObject) snap;
    SnapshotObject snapshotOnPrimary = null;
    try {
        snapshotOnPrimary = (SnapshotObject) snap.getDataStore().create(snapshot);
    } catch (final Exception e) {
        s_logger.debug("Failed to create snapshot state on data store due to " + e.getMessage());
        throw new CloudRuntimeException(e);
    }
    try {
        snapshotOnPrimary.processEvent(Snapshot.Event.CreateRequested);
    } catch (final NoTransitionException e) {
        s_logger.debug("Failed to change snapshot state: " + e.toString());
        throw new CloudRuntimeException(e);
    }
    try {
        snapshotOnPrimary.processEvent(Event.CreateOnlyRequested);
    } catch (final Exception e) {
        s_logger.debug("Failed to change snapshot state: " + e.toString());
        try {
            snapshotOnPrimary.processEvent(Snapshot.Event.OperationFailed);
        } catch (final NoTransitionException e1) {
            s_logger.debug("Failed to change snapshot state: " + e1.toString());
        }
        throw new CloudRuntimeException(e);
    }
    final AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<>();
    try {
        final CreateSnapshotContext<CommandResult> context = new CreateSnapshotContext<>(null, snap.getBaseVolume(), snapshotOnPrimary, future);
        final AsyncCallbackDispatcher<SnapshotServiceImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().createSnapshotAsyncCallback(null, null)).setContext(context);
        final PrimaryDataStoreDriver primaryStore = (PrimaryDataStoreDriver) snapshotOnPrimary.getDataStore().getDriver();
        primaryStore.takeSnapshot(snapshot, caller);
    } catch (final Exception e) {
        s_logger.debug("Failed to take snapshot: " + snapshot.getId(), e);
        try {
            snapshot.processEvent(Snapshot.Event.OperationFailed);
            snapshot.processEvent(Event.OperationFailed);
        } catch (final NoTransitionException e1) {
            s_logger.debug("Failed to change state for event: OperationFailed", e);
        }
        throw new CloudRuntimeException("Failed to take snapshot" + snapshot.getId());
    }
    final SnapshotResult result;
    try {
        result = future.get();
        return result;
    } catch (final InterruptedException e) {
        s_logger.debug("Failed to create snapshot", e);
        throw new CloudRuntimeException("Failed to create snapshot", e);
    } catch (final ExecutionException e) {
        s_logger.debug("Failed to create snapshot", e);
        throw new CloudRuntimeException("Failed to create snapshot", e);
    }
}
Also used : SnapshotResult(com.cloud.engine.subsystem.api.storage.SnapshotResult) CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) CommandResult(com.cloud.storage.command.CommandResult) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) PrimaryDataStoreDriver(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreDriver) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with PrimaryDataStoreDriver

use of com.cloud.engine.subsystem.api.storage.PrimaryDataStoreDriver in project cosmic by MissionCriticalCloud.

the class CapacityManagerImpl method getUsedBytes.

@Override
public long getUsedBytes(final StoragePoolVO pool) {
    final DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(pool.getStorageProviderName());
    final DataStoreDriver storeDriver = storeProvider.getDataStoreDriver();
    if (storeDriver instanceof PrimaryDataStoreDriver) {
        final PrimaryDataStoreDriver primaryStoreDriver = (PrimaryDataStoreDriver) storeDriver;
        return primaryStoreDriver.getUsedBytes(pool);
    }
    throw new CloudRuntimeException("Storage driver in CapacityManagerImpl.getUsedBytes(StoragePoolVO) is not a PrimaryDataStoreDriver.");
}
Also used : PrimaryDataStoreDriver(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreDriver) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStoreProvider(com.cloud.engine.subsystem.api.storage.DataStoreProvider) DataStoreDriver(com.cloud.engine.subsystem.api.storage.DataStoreDriver) PrimaryDataStoreDriver(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreDriver)

Example 3 with PrimaryDataStoreDriver

use of com.cloud.engine.subsystem.api.storage.PrimaryDataStoreDriver in project cosmic by MissionCriticalCloud.

the class CapacityManagerImpl method getUsedIops.

@Override
public long getUsedIops(final StoragePoolVO pool) {
    final DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(pool.getStorageProviderName());
    final DataStoreDriver storeDriver = storeProvider.getDataStoreDriver();
    if (storeDriver instanceof PrimaryDataStoreDriver) {
        final PrimaryDataStoreDriver primaryStoreDriver = (PrimaryDataStoreDriver) storeDriver;
        return primaryStoreDriver.getUsedIops(pool);
    }
    throw new CloudRuntimeException("Storage driver in CapacityManagerImpl.getUsedIops(StoragePoolVO) is not a PrimaryDataStoreDriver.");
}
Also used : PrimaryDataStoreDriver(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreDriver) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStoreProvider(com.cloud.engine.subsystem.api.storage.DataStoreProvider) DataStoreDriver(com.cloud.engine.subsystem.api.storage.DataStoreDriver) PrimaryDataStoreDriver(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreDriver)

Example 4 with PrimaryDataStoreDriver

use of com.cloud.engine.subsystem.api.storage.PrimaryDataStoreDriver in project cosmic by MissionCriticalCloud.

the class StorageManagerImpl method getVolumeSizeIncludingHypervisorSnapshotReserve.

private long getVolumeSizeIncludingHypervisorSnapshotReserve(final Volume volume, final StoragePool pool) {
    final DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(pool.getStorageProviderName());
    final DataStoreDriver storeDriver = storeProvider.getDataStoreDriver();
    if (storeDriver instanceof PrimaryDataStoreDriver) {
        final PrimaryDataStoreDriver primaryStoreDriver = (PrimaryDataStoreDriver) storeDriver;
        return primaryStoreDriver.getVolumeSizeIncludingHypervisorSnapshotReserve(volume, pool);
    }
    return volume.getSize();
}
Also used : PrimaryDataStoreDriver(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreDriver) DataStoreProvider(com.cloud.engine.subsystem.api.storage.DataStoreProvider) DataStoreDriver(com.cloud.engine.subsystem.api.storage.DataStoreDriver) PrimaryDataStoreDriver(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreDriver)

Example 5 with PrimaryDataStoreDriver

use of com.cloud.engine.subsystem.api.storage.PrimaryDataStoreDriver in project cosmic by MissionCriticalCloud.

the class SnapshotServiceImpl method revertSnapshot.

@Override
public boolean revertSnapshot(final SnapshotInfo snapshot) {
    final SnapshotInfo snapshotOnPrimaryStore = _snapshotFactory.getSnapshot(snapshot.getId(), DataStoreRole.Primary);
    if (snapshotOnPrimaryStore == null) {
        throw new CloudRuntimeException("Cannot find an entry for snapshot " + snapshot.getId() + " on primary storage pools");
    }
    final PrimaryDataStore store = (PrimaryDataStore) snapshotOnPrimaryStore.getDataStore();
    final AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<>();
    final RevertSnapshotContext<CommandResult> context = new RevertSnapshotContext<>(null, snapshot, future);
    final AsyncCallbackDispatcher<SnapshotServiceImpl, CommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().revertSnapshotCallback(null, null)).setContext(context);
    ((PrimaryDataStoreDriver) store.getDriver()).revertSnapshot(snapshot, snapshotOnPrimaryStore, caller);
    SnapshotResult result = null;
    try {
        result = future.get();
        if (result.isFailed()) {
            throw new CloudRuntimeException(result.getResult());
        }
        return true;
    } catch (final InterruptedException e) {
        s_logger.debug("revert snapshot is failed: " + e.toString());
    } catch (final ExecutionException e) {
        s_logger.debug("revert snapshot is failed: " + e.toString());
    }
    return false;
}
Also used : SnapshotResult(com.cloud.engine.subsystem.api.storage.SnapshotResult) CommandResult(com.cloud.storage.command.CommandResult) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) SnapshotInfo(com.cloud.engine.subsystem.api.storage.SnapshotInfo) PrimaryDataStoreDriver(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreDriver) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore)

Aggregations

PrimaryDataStoreDriver (com.cloud.engine.subsystem.api.storage.PrimaryDataStoreDriver)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 DataStoreDriver (com.cloud.engine.subsystem.api.storage.DataStoreDriver)3 DataStoreProvider (com.cloud.engine.subsystem.api.storage.DataStoreProvider)3 CopyCommandResult (com.cloud.engine.subsystem.api.storage.CopyCommandResult)2 SnapshotResult (com.cloud.engine.subsystem.api.storage.SnapshotResult)2 AsyncCallFuture (com.cloud.framework.async.AsyncCallFuture)2 CommandResult (com.cloud.storage.command.CommandResult)2 ExecutionException (java.util.concurrent.ExecutionException)2 CreateCmdResult (com.cloud.engine.subsystem.api.storage.CreateCmdResult)1 PrimaryDataStore (com.cloud.engine.subsystem.api.storage.PrimaryDataStore)1 SnapshotInfo (com.cloud.engine.subsystem.api.storage.SnapshotInfo)1 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)1