Search in sources :

Example 6 with CreateObjectAnswer

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

the class Ovm3StorageProcessor method deleteVolume.

@Override
public Answer deleteVolume(DeleteCommand cmd) {
    LOGGER.debug("execute deleteVolume: " + cmd.getClass());
    DataTO data = cmd.getData();
    VolumeObjectTO volume = (VolumeObjectTO) data;
    try {
        String poolUuid = data.getDataStore().getUuid();
        String uuid = volume.getUuid();
        String path = getVirtualDiskPath(uuid, poolUuid);
        StoragePlugin sp = new StoragePlugin(c);
        sp.storagePluginDestroy(poolUuid, path);
        LOGGER.debug("Volume deletion success: " + path);
    } catch (Ovm3ResourceException e) {
        LOGGER.info("Volume deletion failed: " + e.toString(), e);
        return new CreateObjectAnswer(e.toString());
    }
    return new Answer(cmd);
}
Also used : CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) ResignatureAnswer(org.apache.cloudstack.storage.command.ResignatureAnswer) Answer(com.cloud.agent.api.Answer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) SnapshotAndCopyAnswer(org.apache.cloudstack.storage.command.SnapshotAndCopyAnswer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) DataTO(com.cloud.agent.api.to.DataTO) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) StoragePlugin(com.cloud.hypervisor.ovm3.objects.StoragePlugin)

Example 7 with CreateObjectAnswer

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

the class XenServerStorageProcessor method createSnapshot.

@Override
public Answer createSnapshot(final CreateObjectCommand cmd) {
    final Connection conn = hypervisorResource.getConnection();
    final SnapshotObjectTO snapshotTO = (SnapshotObjectTO) cmd.getData();
    final long snapshotId = snapshotTO.getId();
    final String snapshotName = snapshotTO.getName();
    String details = "create snapshot operation Failed for snapshotId: " + snapshotId;
    String snapshotUUID = null;
    try {
        final String volumeUUID = snapshotTO.getVolume().getPath();
        final VDI volume = VDI.getByUuid(conn, volumeUUID);
        final VDI snapshot = volume.snapshot(conn, new HashMap<String, String>());
        if (snapshotName != null) {
            snapshot.setNameLabel(conn, snapshotName);
        }
        snapshotUUID = snapshot.getUuid(conn);
        final String preSnapshotUUID = snapshotTO.getParentSnapshotPath();
        //check if it is a empty snapshot
        if (preSnapshotUUID != null) {
            final SR sr = volume.getSR(conn);
            final String srUUID = sr.getUuid(conn);
            final String type = sr.getType(conn);
            final Boolean isISCSI = IsISCSI(type);
            final String snapshotParentUUID = getVhdParent(conn, srUUID, snapshotUUID, isISCSI);
            try {
                final String preSnapshotParentUUID = getVhdParent(conn, srUUID, preSnapshotUUID, isISCSI);
                if (snapshotParentUUID != null && snapshotParentUUID.equals(preSnapshotParentUUID)) {
                    // this is empty snapshot, remove it
                    snapshot.destroy(conn);
                    snapshotUUID = preSnapshotUUID;
                }
            } catch (final Exception e) {
                s_logger.debug("Failed to get parent snapshot", e);
            }
        }
        final SnapshotObjectTO newSnapshot = new SnapshotObjectTO();
        newSnapshot.setPath(snapshotUUID);
        return new CreateObjectAnswer(newSnapshot);
    } catch (final XenAPIException e) {
        details += ", reason: " + e.toString();
        s_logger.warn(details, e);
    } catch (final Exception e) {
        details += ", reason: " + e.toString();
        s_logger.warn(details, e);
    }
    return new CreateObjectAnswer(details);
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) Connection(com.xensource.xenapi.Connection) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) XenAPIException(com.xensource.xenapi.Types.XenAPIException) VDI(com.xensource.xenapi.VDI) XenAPIException(com.xensource.xenapi.Types.XenAPIException) InternalErrorException(com.cloud.exception.InternalErrorException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SR(com.xensource.xenapi.SR)

Example 8 with CreateObjectAnswer

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

the class SimulatorStorageProcessor method createSnapshot.

@Override
public Answer createSnapshot(CreateObjectCommand cmd) {
    String snapshotName = UUID.randomUUID().toString();
    SnapshotObjectTO newSnapshot = new SnapshotObjectTO();
    newSnapshot.setPath(snapshotName);
    return new CreateObjectAnswer(newSnapshot);
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer)

Example 9 with CreateObjectAnswer

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

the class SimulatorStorageProcessor method createVolume.

@Override
public Answer createVolume(CreateObjectCommand cmd) {
    VolumeObjectTO volume = (VolumeObjectTO) cmd.getData();
    VolumeObjectTO newVol = new VolumeObjectTO();
    newVol.setPath(volume.getName());
    return new CreateObjectAnswer(newVol);
}
Also used : CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO)

Example 10 with CreateObjectAnswer

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

the class SolidFirePrimaryDataStoreDriver method takeSnapshot.

@Override
public void takeSnapshot(SnapshotInfo snapshotInfo, AsyncCompletionCallback<CreateCmdResult> callback) {
    CreateCmdResult result = null;
    try {
        VolumeInfo volumeInfo = snapshotInfo.getBaseVolume();
        VolumeVO volumeVO = volumeDao.findById(volumeInfo.getId());
        long sfVolumeId = Long.parseLong(volumeVO.getFolder());
        long storagePoolId = volumeVO.getPoolId();
        SolidFireUtil.SolidFireConnection sfConnection = SolidFireUtil.getSolidFireConnection(storagePoolId, storagePoolDetailsDao);
        SolidFireUtil.SolidFireVolume sfVolume = SolidFireUtil.getVolume(sfConnection, sfVolumeId);
        StoragePoolVO storagePool = storagePoolDao.findById(storagePoolId);
        long capacityBytes = storagePool.getCapacityBytes();
        // getUsedBytes(StoragePool) will not include the bytes of the proposed new volume or snapshot because
        // updateSnapshotDetails has not yet been called for this new volume or snapshot
        long usedBytes = getUsedBytes(storagePool);
        long sfVolumeSize = sfVolume.getTotalSize();
        usedBytes += sfVolumeSize;
        // that is serving as the volume the snapshot is of (either a new SolidFire volume or a SolidFire snapshot).
        if (usedBytes > capacityBytes) {
            throw new CloudRuntimeException("Insufficient amount of space remains in this primary storage to take a snapshot");
        }
        storagePool.setUsedBytes(usedBytes);
        SnapshotObjectTO snapshotObjectTo = (SnapshotObjectTO) snapshotInfo.getTO();
        if (shouldTakeSnapshot(snapshotInfo.getId())) {
            // We are supposed to take a SolidFire snapshot to serve as the back-end for our CloudStack volume snapshot.
            String sfNewSnapshotName = volumeInfo.getName() + "-" + snapshotInfo.getUuid();
            long sfNewSnapshotId = SolidFireUtil.createSnapshot(sfConnection, sfVolumeId, sfNewSnapshotName, getSnapshotAttributes(snapshotInfo));
            updateSnapshotDetails(snapshotInfo.getId(), sfVolumeId, sfNewSnapshotId, storagePoolId, sfVolumeSize);
            snapshotObjectTo.setPath("SfSnapshotId=" + sfNewSnapshotId);
        } else {
            // We are supposed to create a new SolidFire volume to serve as the back-end for our CloudStack volume snapshot.
            String sfNewVolumeName = volumeInfo.getName() + "-" + snapshotInfo.getUuid();
            final Iops iops = getIops(MIN_IOPS_FOR_SNAPSHOT_VOLUME, MAX_IOPS_FOR_SNAPSHOT_VOLUME, storagePoolId);
            long sfNewVolumeId = SolidFireUtil.createVolume(sfConnection, sfNewVolumeName, sfVolume.getAccountId(), sfVolumeSize, sfVolume.isEnable512e(), getSnapshotAttributes(snapshotInfo), iops.getMinIops(), iops.getMaxIops(), iops.getBurstIops());
            SolidFireUtil.SolidFireVolume sfNewVolume = SolidFireUtil.getVolume(sfConnection, sfNewVolumeId);
            updateSnapshotDetails(snapshotInfo.getId(), sfNewVolumeId, storagePoolId, sfVolumeSize, sfNewVolume.getIqn());
            snapshotObjectTo.setPath("SfVolumeId=" + sfNewVolumeId);
        }
        // Now that we have successfully created a volume or a snapshot, update the space usage in the cloud.storage_pool table
        // (even though cloud.storage_pool.used_bytes is likely no longer in use).
        storagePoolDao.update(storagePoolId, storagePool);
        CreateObjectAnswer createObjectAnswer = new CreateObjectAnswer(snapshotObjectTo);
        result = new CreateCmdResult(null, createObjectAnswer);
        result.setResult(null);
    } catch (Exception ex) {
        LOGGER.debug(SolidFireUtil.LOG_PREFIX + "Failed to take CloudStack snapshot: " + snapshotInfo.getId(), ex);
        result = new CreateCmdResult(null, new CreateObjectAnswer(ex.toString()));
        result.setResult(ex.toString());
    }
    callback.complete(result);
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeVO(com.cloud.storage.VolumeVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) SolidFireUtil(org.apache.cloudstack.storage.datastore.util.SolidFireUtil)

Aggregations

CreateObjectAnswer (org.apache.cloudstack.storage.command.CreateObjectAnswer)20 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)11 SnapshotObjectTO (org.apache.cloudstack.storage.to.SnapshotObjectTO)11 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)10 DataTO (com.cloud.agent.api.to.DataTO)6 VolumeVO (com.cloud.storage.VolumeVO)5 InternalErrorException (com.cloud.exception.InternalErrorException)4 Ovm3ResourceException (com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)4 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)4 Answer (com.cloud.agent.api.Answer)3 StoragePlugin (com.cloud.hypervisor.ovm3.objects.StoragePlugin)3 URISyntaxException (java.net.URISyntaxException)3 PrimaryDataStoreTO (org.apache.cloudstack.storage.to.PrimaryDataStoreTO)3 RadosException (com.ceph.rados.exceptions.RadosException)2 RbdException (com.ceph.rbd.RbdException)2 CopyVolumeAnswer (com.cloud.agent.api.storage.CopyVolumeAnswer)2 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)2 CreatePrivateTemplateAnswer (com.cloud.agent.api.storage.CreatePrivateTemplateAnswer)2 DownloadAnswer (com.cloud.agent.api.storage.DownloadAnswer)2 Connection (com.xensource.xenapi.Connection)2