Search in sources :

Example 1 with PrimaryDataStoreDriver

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

the class CapacityManagerImpl method getUsedBytes.

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

Example 2 with PrimaryDataStoreDriver

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

the class SnapshotServiceImpl method revertSnapshot.

@Override
public boolean revertSnapshot(SnapshotInfo snapshot) {
    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");
    }
    PrimaryDataStore store = (PrimaryDataStore) snapshotOnPrimaryStore.getDataStore();
    AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<SnapshotResult>();
    RevertSnapshotContext<CommandResult> context = new RevertSnapshotContext<CommandResult>(null, snapshot, future);
    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 (InterruptedException e) {
        s_logger.debug("revert snapshot is failed: " + e.toString());
    } catch (ExecutionException e) {
        s_logger.debug("revert snapshot is failed: " + e.toString());
    }
    return false;
}
Also used : SnapshotResult(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult) 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) PrimaryDataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)

Example 3 with PrimaryDataStoreDriver

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

the class SnapshotServiceImpl method takeSnapshot.

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

Example 4 with PrimaryDataStoreDriver

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

the class XenServerStorageMotionStrategy method handleManagedVolumePreMigration.

/**
     * Tell the underlying storage plug-in to create a new volume, put it in the VAG of the destination cluster, and
     * send a command to the destination cluster to create an SR and to attach to the SR from all hosts in the cluster.
     */
private String handleManagedVolumePreMigration(VolumeInfo volumeInfo, StoragePool storagePool, Host destHost) {
    final PrimaryDataStoreDriver pdsd = (PrimaryDataStoreDriver) volumeInfo.getDataStore().getDriver();
    VolumeDetailVO volumeDetailVo = new VolumeDetailVO(volumeInfo.getId(), PrimaryDataStoreDriver.BASIC_CREATE, Boolean.TRUE.toString(), false);
    volumeDetailsDao.persist(volumeDetailVo);
    pdsd.createAsync(volumeInfo.getDataStore(), volumeInfo, null);
    volumeDetailVo = new VolumeDetailVO(volumeInfo.getId(), PrimaryDataStoreDriver.BASIC_GRANT_ACCESS, Boolean.TRUE.toString(), false);
    volumeDetailsDao.persist(volumeDetailVo);
    pdsd.grantAccess(volumeInfo, destHost, volumeInfo.getDataStore());
    final Map<String, String> details = new HashMap<>();
    final String iqn = getBasicIqn(volumeInfo.getId());
    details.put(CreateStoragePoolCommand.DATASTORE_NAME, iqn);
    details.put(CreateStoragePoolCommand.IQN, iqn);
    details.put(CreateStoragePoolCommand.STORAGE_HOST, storagePool.getHostAddress());
    details.put(CreateStoragePoolCommand.STORAGE_PORT, String.valueOf(storagePool.getPort()));
    final CreateStoragePoolCommand cmd = new CreateStoragePoolCommand(true, storagePool);
    cmd.setDetails(details);
    cmd.setCreateDatastore(true);
    final Answer answer = agentMgr.easySend(destHost.getId(), cmd);
    if (answer == null || !answer.getResult()) {
        String errMsg = "Error interacting with host (related to CreateStoragePoolCommand)" + (StringUtils.isNotBlank(answer.getDetails()) ? ": " + answer.getDetails() : "");
        s_logger.error(errMsg);
        throw new CloudRuntimeException(errMsg);
    }
    return iqn;
}
Also used : MigrateWithStorageCompleteAnswer(com.cloud.agent.api.MigrateWithStorageCompleteAnswer) MigrateWithStorageSendAnswer(com.cloud.agent.api.MigrateWithStorageSendAnswer) Answer(com.cloud.agent.api.Answer) MigrateWithStorageReceiveAnswer(com.cloud.agent.api.MigrateWithStorageReceiveAnswer) MigrateWithStorageAnswer(com.cloud.agent.api.MigrateWithStorageAnswer) PrimaryDataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver) HashMap(java.util.HashMap) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeDetailVO(com.cloud.storage.VolumeDetailVO) CreateStoragePoolCommand(com.cloud.agent.api.CreateStoragePoolCommand)

Example 5 with PrimaryDataStoreDriver

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

the class XenServerStorageMotionStrategy method handleManagedVolumePostMigration.

private void handleManagedVolumePostMigration(VolumeInfo volumeInfo, Host srcHost, VolumeObjectTO volumeTO) {
    final Map<String, String> details = new HashMap<>();
    details.put(DeleteStoragePoolCommand.DATASTORE_NAME, volumeInfo.get_iScsiName());
    final DeleteStoragePoolCommand cmd = new DeleteStoragePoolCommand();
    cmd.setDetails(details);
    cmd.setRemoveDatastore(true);
    final Answer answer = agentMgr.easySend(srcHost.getId(), cmd);
    if (answer == null || !answer.getResult()) {
        String errMsg = "Error interacting with host (related to DeleteStoragePoolCommand)" + (StringUtils.isNotBlank(answer.getDetails()) ? ": " + answer.getDetails() : "");
        s_logger.error(errMsg);
        throw new CloudRuntimeException(errMsg);
    }
    final PrimaryDataStoreDriver pdsd = (PrimaryDataStoreDriver) volumeInfo.getDataStore().getDriver();
    pdsd.revokeAccess(volumeInfo, srcHost, volumeInfo.getDataStore());
    VolumeDetailVO volumeDetailVo = new VolumeDetailVO(volumeInfo.getId(), PrimaryDataStoreDriver.BASIC_DELETE, Boolean.TRUE.toString(), false);
    volumeDetailsDao.persist(volumeDetailVo);
    pdsd.deleteAsync(volumeInfo.getDataStore(), volumeInfo, null);
    VolumeVO volumeVO = volDao.findById(volumeInfo.getId());
    volumeVO.setPath(volumeTO.getPath());
    volDao.update(volumeVO.getId(), volumeVO);
}
Also used : MigrateWithStorageCompleteAnswer(com.cloud.agent.api.MigrateWithStorageCompleteAnswer) MigrateWithStorageSendAnswer(com.cloud.agent.api.MigrateWithStorageSendAnswer) Answer(com.cloud.agent.api.Answer) MigrateWithStorageReceiveAnswer(com.cloud.agent.api.MigrateWithStorageReceiveAnswer) MigrateWithStorageAnswer(com.cloud.agent.api.MigrateWithStorageAnswer) VolumeVO(com.cloud.storage.VolumeVO) HashMap(java.util.HashMap) PrimaryDataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DeleteStoragePoolCommand(com.cloud.agent.api.DeleteStoragePoolCommand) VolumeDetailVO(com.cloud.storage.VolumeDetailVO)

Aggregations

PrimaryDataStoreDriver (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver)9 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)6 DataStoreDriver (org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver)4 DataStoreProvider (org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider)4 Answer (com.cloud.agent.api.Answer)3 MigrateWithStorageAnswer (com.cloud.agent.api.MigrateWithStorageAnswer)3 MigrateWithStorageCompleteAnswer (com.cloud.agent.api.MigrateWithStorageCompleteAnswer)3 MigrateWithStorageReceiveAnswer (com.cloud.agent.api.MigrateWithStorageReceiveAnswer)3 MigrateWithStorageSendAnswer (com.cloud.agent.api.MigrateWithStorageSendAnswer)3 VolumeDetailVO (com.cloud.storage.VolumeDetailVO)3 HashMap (java.util.HashMap)3 DeleteStoragePoolCommand (com.cloud.agent.api.DeleteStoragePoolCommand)2 ExecutionException (java.util.concurrent.ExecutionException)2 CopyCommandResult (org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)2 SnapshotResult (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult)2 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)2 AsyncCallFuture (org.apache.cloudstack.framework.async.AsyncCallFuture)2 CommandResult (org.apache.cloudstack.storage.command.CommandResult)2 CreateStoragePoolCommand (com.cloud.agent.api.CreateStoragePoolCommand)1 StoragePool (com.cloud.storage.StoragePool)1