Search in sources :

Example 1 with CommandResult

use of org.apache.cloudstack.storage.command.CommandResult in project cloudstack by apache.

the class VolumeOrchestrator method migrateVolumes.

@Override
public void migrateVolumes(VirtualMachine vm, VirtualMachineTO vmTo, Host srcHost, Host destHost, Map<Volume, StoragePool> volumeToPool) {
    // Check if all the vms being migrated belong to the vm.
    // Check if the storage pool is of the right type.
    // Create a VolumeInfo to DataStore map too.
    Map<VolumeInfo, DataStore> volumeMap = new HashMap<VolumeInfo, DataStore>();
    for (Map.Entry<Volume, StoragePool> entry : volumeToPool.entrySet()) {
        Volume volume = entry.getKey();
        StoragePool storagePool = entry.getValue();
        StoragePool destPool = (StoragePool) dataStoreMgr.getDataStore(storagePool.getId(), DataStoreRole.Primary);
        if (volume.getInstanceId() != vm.getId()) {
            throw new CloudRuntimeException("Volume " + volume + " that has to be migrated doesn't belong to the" + " instance " + vm);
        }
        if (destPool == null) {
            throw new CloudRuntimeException("Failed to find the destination storage pool " + storagePool.getId());
        }
        volumeMap.put(volFactory.getVolume(volume.getId()), (DataStore) destPool);
    }
    AsyncCallFuture<CommandResult> future = volService.migrateVolumes(volumeMap, vmTo, srcHost, destHost);
    try {
        CommandResult result = future.get();
        if (result.isFailed()) {
            s_logger.debug("Failed to migrated vm " + vm + " along with its volumes. " + result.getResult());
            throw new CloudRuntimeException("Failed to migrated vm " + vm + " along with its volumes. ");
        }
    } catch (InterruptedException e) {
        s_logger.debug("Failed to migrated vm " + vm + " along with its volumes.", e);
    } catch (ExecutionException e) {
        s_logger.debug("Failed to migrated vm " + vm + " along with its volumes.", e);
    }
}
Also used : StoragePool(com.cloud.storage.StoragePool) HashMap(java.util.HashMap) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) CommandResult(org.apache.cloudstack.storage.command.CommandResult) VmWorkMigrateVolume(com.cloud.vm.VmWorkMigrateVolume) VmWorkAttachVolume(com.cloud.vm.VmWorkAttachVolume) Volume(com.cloud.storage.Volume) 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) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with CommandResult

use of org.apache.cloudstack.storage.command.CommandResult in project cloudstack by apache.

the class BaseImageStoreDriverImpl method deleteAsync.

@Override
public void deleteAsync(DataStore dataStore, DataObject data, AsyncCompletionCallback<CommandResult> callback) {
    CommandResult result = new CommandResult();
    try {
        DeleteCommand cmd = new DeleteCommand(data.getTO());
        EndPoint ep = _epSelector.select(data);
        Answer answer = null;
        if (ep == null) {
            String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
            LOGGER.error(errMsg);
            answer = new Answer(cmd, false, errMsg);
        } else {
            answer = ep.sendMessage(cmd);
        }
        if (answer != null && !answer.getResult()) {
            result.setResult(answer.getDetails());
        }
    } catch (Exception ex) {
        LOGGER.debug("Unable to destoy " + data.getType().toString() + ": " + data.getId(), ex);
        result.setResult(ex.toString());
    }
    callback.complete(result);
}
Also used : DeleteCommand(org.apache.cloudstack.storage.command.DeleteCommand) GetDatadisksAnswer(com.cloud.agent.api.storage.GetDatadisksAnswer) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) Answer(com.cloud.agent.api.Answer) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) URISyntaxException(java.net.URISyntaxException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SQLException(java.sql.SQLException) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)

Example 3 with CommandResult

use of org.apache.cloudstack.storage.command.CommandResult in project cloudstack by apache.

the class ScaleIOPrimaryDataStoreDriver method revertSnapshot.

@Override
public void revertSnapshot(SnapshotInfo snapshot, SnapshotInfo snapshotOnPrimaryStore, AsyncCompletionCallback<CommandResult> callback) {
    LOGGER.debug("Reverting to PowerFlex volume snapshot");
    Preconditions.checkArgument(snapshot != null, "snapshotInfo cannot be null");
    VolumeInfo volumeInfo = snapshot.getBaseVolume();
    Preconditions.checkArgument(volumeInfo != null, "volumeInfo cannot be null");
    VolumeVO volumeVO = volumeDao.findById(volumeInfo.getId());
    try {
        if (volumeVO == null || volumeVO.getRemoved() != null) {
            String errMsg = "The volume that the snapshot belongs to no longer exists.";
            CommandResult commandResult = new CommandResult();
            commandResult.setResult(errMsg);
            callback.complete(commandResult);
            return;
        }
        long storagePoolId = volumeVO.getPoolId();
        final ScaleIOGatewayClient client = getScaleIOClient(storagePoolId);
        String snapshotVolumeId = ScaleIOUtil.getVolumePath(snapshot.getPath());
        final String destVolumeId = ScaleIOUtil.getVolumePath(volumeVO.getPath());
        client.revertSnapshot(snapshotVolumeId, destVolumeId);
        CommandResult commandResult = new CommandResult();
        callback.complete(commandResult);
    } catch (Exception ex) {
        LOGGER.debug("Unable to revert to PowerFlex snapshot: " + snapshot.getId(), ex);
        throw new CloudRuntimeException(ex.getMessage());
    }
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ScaleIOGatewayClient(org.apache.cloudstack.storage.datastore.client.ScaleIOGatewayClient) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)

Example 4 with CommandResult

use of org.apache.cloudstack.storage.command.CommandResult in project cloudstack by apache.

the class SolidFirePrimaryDataStoreDriver method deleteAsync.

@Override
public void deleteAsync(DataStore dataStore, DataObject dataObject, AsyncCompletionCallback<CommandResult> callback) {
    String errMsg = null;
    try {
        if (dataObject.getType() == DataObjectType.VOLUME) {
            deleteVolume((VolumeInfo) dataObject, dataStore.getId());
        } else if (dataObject.getType() == DataObjectType.SNAPSHOT) {
            deleteSnapshot((SnapshotInfo) dataObject, dataStore.getId());
        } else if (dataObject.getType() == DataObjectType.TEMPLATE) {
            deleteTemplate((TemplateInfo) dataObject, dataStore.getId());
        } else {
            errMsg = "Invalid DataObjectType (" + dataObject.getType() + ") passed to deleteAsync";
        }
    } catch (Exception ex) {
        errMsg = ex.getMessage();
        LOGGER.error(errMsg);
    }
    if (callback != null) {
        CommandResult result = new CommandResult();
        result.setResult(errMsg);
        callback.complete(result);
    }
}
Also used : SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)

Example 5 with CommandResult

use of org.apache.cloudstack.storage.command.CommandResult in project cloudstack by apache.

the class ScaleIOPrimaryDataStoreDriver method deleteAsync.

@Override
public void deleteAsync(DataStore dataStore, DataObject dataObject, AsyncCompletionCallback<CommandResult> callback) {
    Preconditions.checkArgument(dataObject != null, "dataObject cannot be null");
    long storagePoolId = dataStore.getId();
    StoragePoolVO storagePool = storagePoolDao.findById(storagePoolId);
    Preconditions.checkArgument(storagePoolId > 0, "storagePoolId should be > 0");
    Preconditions.checkArgument(storagePool != null && storagePool.getHostAddress() != null, "storagePool and host address should not be null");
    String errMsg = null;
    String scaleIOVolumePath = null;
    try {
        boolean deleteResult = false;
        if (dataObject.getType() == DataObjectType.VOLUME) {
            LOGGER.debug("deleteAsync - deleting volume");
            scaleIOVolumePath = ((VolumeInfo) dataObject).getPath();
        } else if (dataObject.getType() == DataObjectType.SNAPSHOT) {
            LOGGER.debug("deleteAsync - deleting snapshot");
            scaleIOVolumePath = ((SnapshotInfo) dataObject).getPath();
        } else if (dataObject.getType() == DataObjectType.TEMPLATE) {
            LOGGER.debug("deleteAsync - deleting template");
            scaleIOVolumePath = ((TemplateInfo) dataObject).getInstallPath();
        } else {
            errMsg = "Invalid DataObjectType (" + dataObject.getType() + ") passed to deleteAsync";
            LOGGER.error(errMsg);
            throw new CloudRuntimeException(errMsg);
        }
        try {
            String scaleIOVolumeId = ScaleIOUtil.getVolumePath(scaleIOVolumePath);
            final ScaleIOGatewayClient client = getScaleIOClient(storagePoolId);
            deleteResult = client.deleteVolume(scaleIOVolumeId);
            if (!deleteResult) {
                errMsg = "Failed to delete PowerFlex volume with id: " + scaleIOVolumeId;
            }
            long usedBytes = storagePool.getUsedBytes();
            usedBytes -= dataObject.getSize();
            storagePool.setUsedBytes(usedBytes < 0 ? 0 : usedBytes);
            storagePoolDao.update(storagePoolId, storagePool);
        } catch (Exception e) {
            errMsg = "Unable to delete PowerFlex volume: " + scaleIOVolumePath + " due to " + e.getMessage();
            LOGGER.warn(errMsg);
            throw new CloudRuntimeException(errMsg, e);
        }
    } catch (Exception ex) {
        errMsg = ex.getMessage();
        LOGGER.error(errMsg);
        if (callback == null) {
            throw ex;
        }
    }
    if (callback != null) {
        CommandResult result = new CommandResult();
        result.setResult(errMsg);
        callback.complete(result);
    }
}
Also used : SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ScaleIOGatewayClient(org.apache.cloudstack.storage.datastore.client.ScaleIOGatewayClient) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)

Aggregations

CommandResult (org.apache.cloudstack.storage.command.CommandResult)37 CopyCommandResult (org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)35 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)17 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)15 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)12 ExecutionException (java.util.concurrent.ExecutionException)11 SnapshotInfo (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo)9 AsyncCallFuture (org.apache.cloudstack.framework.async.AsyncCallFuture)9 PrimaryDataStore (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)8 SnapshotResult (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult)7 VolumeVO (com.cloud.storage.VolumeVO)6 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)6 HashMap (java.util.HashMap)6 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)5 Answer (com.cloud.agent.api.Answer)4 MigrateWithStorageAnswer (com.cloud.agent.api.MigrateWithStorageAnswer)4 MigrateWithStorageCommand (com.cloud.agent.api.MigrateWithStorageCommand)4 VirtualMachineTO (com.cloud.agent.api.to.VirtualMachineTO)4 Host (com.cloud.host.Host)4 VMInstanceVO (com.cloud.vm.VMInstanceVO)4