Search in sources :

Example 16 with SnapshotObjectTO

use of org.apache.cloudstack.storage.to.SnapshotObjectTO in project cloudstack by apache.

the class Xenserver625StorageProcessor method createVolumeFromSnapshot.

@Override
public Answer createVolumeFromSnapshot(final CopyCommand cmd) {
    final Connection conn = hypervisorResource.getConnection();
    final DataTO srcData = cmd.getSrcTO();
    final SnapshotObjectTO snapshot = (SnapshotObjectTO) srcData;
    final DataTO destData = cmd.getDestTO();
    final PrimaryDataStoreTO pool = (PrimaryDataStoreTO) destData.getDataStore();
    final VolumeObjectTO volume = (VolumeObjectTO) destData;
    final DataStoreTO imageStore = srcData.getDataStore();
    if (srcData.getDataStore() instanceof PrimaryDataStoreTO && destData.getDataStore() instanceof PrimaryDataStoreTO) {
        return createVolumeFromSnapshot2(cmd);
    }
    if (!(imageStore instanceof NfsTO)) {
        return new CopyCmdAnswer("unsupported protocol");
    }
    final NfsTO nfsImageStore = (NfsTO) imageStore;
    final String primaryStorageNameLabel = pool.getUuid();
    final String secondaryStorageUrl = nfsImageStore.getUrl();
    final int wait = cmd.getWait();
    boolean result = false;
    // Generic error message.
    String details = null;
    String volumeUUID = null;
    if (secondaryStorageUrl == null) {
        details += " because the URL passed: " + secondaryStorageUrl + " is invalid.";
        return new CopyCmdAnswer(details);
    }
    SR srcSr = null;
    VDI destVdi = null;
    SR primaryStorageSR = null;
    try {
        if (pool.isManaged()) {
            Map<String, String> destDetails = cmd.getOptions2();
            final String iScsiName = destDetails.get(DiskTO.IQN);
            final String storageHost = destDetails.get(DiskTO.STORAGE_HOST);
            final String chapInitiatorUsername = destDetails.get(DiskTO.CHAP_INITIATOR_USERNAME);
            final String chapInitiatorSecret = destDetails.get(DiskTO.CHAP_INITIATOR_SECRET);
            final String srType = CitrixResourceBase.SRType.LVMOISCSI.toString();
            primaryStorageSR = hypervisorResource.getIscsiSR(conn, iScsiName, storageHost, iScsiName, chapInitiatorUsername, chapInitiatorSecret, false, srType, true);
        } else {
            primaryStorageSR = hypervisorResource.getSRByNameLabelandHost(conn, primaryStorageNameLabel);
        }
        if (primaryStorageSR == null) {
            throw new InternalErrorException("Could not create volume from snapshot because the primary Storage SR could not be created from the name label: " + primaryStorageNameLabel);
        }
        final String nameLabel = "cloud-" + UUID.randomUUID().toString();
        destVdi = createVdi(conn, nameLabel, primaryStorageSR, volume.getSize());
        volumeUUID = destVdi.getUuid(conn);
        final String snapshotInstallPath = snapshot.getPath();
        final int index = snapshotInstallPath.lastIndexOf(File.separator);
        final String snapshotDirectory = snapshotInstallPath.substring(0, index);
        final String snapshotUuid = getSnapshotUuid(snapshotInstallPath);
        final URI uri = new URI(secondaryStorageUrl);
        srcSr = createFileSr(conn, uri.getHost() + ":" + uri.getPath(), snapshotDirectory);
        final String[] parents = snapshot.getParents();
        final List<VDI> snapshotChains = new ArrayList<VDI>();
        if (parents != null) {
            for (int i = 0; i < parents.length; i++) {
                final String snChainPath = parents[i];
                final String uuid = getSnapshotUuid(snChainPath);
                final VDI chain = VDI.getByUuid(conn, uuid);
                snapshotChains.add(chain);
            }
        }
        final VDI snapshotVdi = VDI.getByUuid(conn, snapshotUuid);
        snapshotChains.add(snapshotVdi);
        for (final VDI snapChain : snapshotChains) {
            final Task task = snapChain.copyAsync(conn, null, null, destVdi);
            // poll every 1 seconds ,
            hypervisorResource.waitForTask(conn, task, 1000, wait * 1000);
            hypervisorResource.checkForSuccess(conn, task);
            task.destroy(conn);
        }
        result = true;
        destVdi = VDI.getByUuid(conn, volumeUUID);
        final VDI.Record vdir = destVdi.getRecord(conn);
        final VolumeObjectTO newVol = new VolumeObjectTO();
        newVol.setPath(volumeUUID);
        newVol.setSize(vdir.virtualSize);
        return new CopyCmdAnswer(newVol);
    } catch (final Types.XenAPIException e) {
        details += " due to " + e.toString();
        s_logger.warn(details, e);
    } catch (final Exception e) {
        details += " due to " + e.getMessage();
        s_logger.warn(details, e);
    } finally {
        if (srcSr != null) {
            hypervisorResource.skipOrRemoveSR(conn, srcSr);
        }
        if (pool.isManaged()) {
            hypervisorResource.removeSR(conn, primaryStorageSR);
        }
        if (!result && destVdi != null) {
            try {
                destVdi.destroy(conn);
            } catch (final Exception e) {
                s_logger.debug("destroy dest vdi failed", e);
            }
        }
    }
    if (!result) {
        // Is this logged at a higher level?
        s_logger.error(details);
    }
    // In all cases return something.
    return new CopyCmdAnswer(details);
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) Types(com.xensource.xenapi.Types) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) Task(com.xensource.xenapi.Task) Connection(com.xensource.xenapi.Connection) ArrayList(java.util.ArrayList) InternalErrorException(com.cloud.exception.InternalErrorException) NfsTO(com.cloud.agent.api.to.NfsTO) URI(java.net.URI) XenAPIException(com.xensource.xenapi.Types.XenAPIException) InternalErrorException(com.cloud.exception.InternalErrorException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) DataTO(com.cloud.agent.api.to.DataTO) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) VDI(com.xensource.xenapi.VDI) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) SR(com.xensource.xenapi.SR)

Example 17 with SnapshotObjectTO

use of org.apache.cloudstack.storage.to.SnapshotObjectTO 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 18 with SnapshotObjectTO

use of org.apache.cloudstack.storage.to.SnapshotObjectTO in project cloudstack by apache.

the class SimulatorStorageProcessor method backupSnapshot.

@Override
public Answer backupSnapshot(CopyCommand cmd) {
    DataTO srcData = cmd.getSrcTO();
    DataTO destData = cmd.getDestTO();
    SnapshotObjectTO snapshot = (SnapshotObjectTO) srcData;
    DataStoreTO imageStore = destData.getDataStore();
    if (!(imageStore instanceof NfsTO)) {
        return new CopyCmdAnswer("unsupported protocol");
    }
    int index = snapshot.getPath().lastIndexOf("/");
    String snapshotName = snapshot.getPath().substring(index + 1);
    String snapshotRelPath = "snapshots";
    SnapshotObjectTO newSnapshot = new SnapshotObjectTO();
    newSnapshot.setPath(snapshotRelPath + File.separator + snapshotName);
    return new CopyCmdAnswer(newSnapshot);
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) DataTO(com.cloud.agent.api.to.DataTO) NfsTO(com.cloud.agent.api.to.NfsTO) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Example 19 with SnapshotObjectTO

use of org.apache.cloudstack.storage.to.SnapshotObjectTO 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)

Example 20 with SnapshotObjectTO

use of org.apache.cloudstack.storage.to.SnapshotObjectTO in project cloudstack by apache.

the class KVMStorageProcessor method backupSnapshotForObjectStore.

protected Answer backupSnapshotForObjectStore(final CopyCommand cmd) {
    final DataTO destData = cmd.getDestTO();
    final DataStoreTO imageStore = destData.getDataStore();
    final DataTO cacheData = cmd.getCacheTO();
    if (cacheData == null) {
        return new CopyCmdAnswer("Failed to copy to object store without cache store");
    }
    final DataStoreTO cacheStore = cacheData.getDataStore();
    ((SnapshotObjectTO) destData).setDataStore(cacheStore);
    final CopyCmdAnswer answer = (CopyCmdAnswer) backupSnapshot(cmd);
    if (!answer.getResult()) {
        return answer;
    }
    final SnapshotObjectTO snapshotOnCacheStore = (SnapshotObjectTO) answer.getNewData();
    snapshotOnCacheStore.setDataStore(cacheStore);
    ((SnapshotObjectTO) destData).setDataStore(imageStore);
    final CopyCommand newCpyCmd = new CopyCommand(snapshotOnCacheStore, destData, cmd.getWaitInMillSeconds(), cmd.executeInSequence());
    return copyToObjectStore(newCpyCmd);
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) DataTO(com.cloud.agent.api.to.DataTO) CopyCommand(org.apache.cloudstack.storage.command.CopyCommand) SnapshotAndCopyCommand(org.apache.cloudstack.storage.command.SnapshotAndCopyCommand) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Aggregations

SnapshotObjectTO (org.apache.cloudstack.storage.to.SnapshotObjectTO)44 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)33 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)23 DataTO (com.cloud.agent.api.to.DataTO)22 NfsTO (com.cloud.agent.api.to.NfsTO)21 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)20 PrimaryDataStoreTO (org.apache.cloudstack.storage.to.PrimaryDataStoreTO)19 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)16 InternalErrorException (com.cloud.exception.InternalErrorException)14 CreateObjectAnswer (org.apache.cloudstack.storage.command.CreateObjectAnswer)14 Answer (com.cloud.agent.api.Answer)12 TemplateObjectTO (org.apache.cloudstack.storage.to.TemplateObjectTO)11 Connection (com.xensource.xenapi.Connection)9 XenAPIException (com.xensource.xenapi.Types.XenAPIException)9 VDI (com.xensource.xenapi.VDI)9 XmlRpcException (org.apache.xmlrpc.XmlRpcException)9 SR (com.xensource.xenapi.SR)8 URI (java.net.URI)7 ConfigurationException (javax.naming.ConfigurationException)7 S3TO (com.cloud.agent.api.to.S3TO)6