Search in sources :

Example 11 with SnapshotObjectTO

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

the class Ovm3StorageProcessor method backupSnapshot.

/**
     * use the cache, or the normal nfs, also delete the leftovers for us
     * also contains object store storage in xenserver.
     */
@Override
public CopyCmdAnswer backupSnapshot(CopyCommand cmd) {
    LOGGER.debug("execute backupSnapshot: " + cmd.getClass());
    try {
        DataTO srcData = cmd.getSrcTO();
        DataTO destData = cmd.getDestTO();
        SnapshotObjectTO src = (SnapshotObjectTO) srcData;
        SnapshotObjectTO dest = (SnapshotObjectTO) destData;
        // src.getPath contains the uuid of the snapshot.
        String srcFile = getVirtualDiskPath(src.getPath(), src.getDataStore().getUuid());
        // destination
        String storeUrl = dest.getDataStore().getUrl();
        String secPoolUuid = pool.setupSecondaryStorage(storeUrl);
        String destDir = config.getAgentSecStoragePath() + "/" + secPoolUuid + "/" + dest.getPath();
        String destFile = destDir + "/" + src.getPath();
        destFile = destFile.concat(".raw");
        // copy
        Linux host = new Linux(c);
        CloudstackPlugin csp = new CloudstackPlugin(c);
        csp.ovsMkdirs(destDir);
        LOGGER.debug("CopyFrom: " + srcData.getObjectType() + "," + srcFile + " to " + destData.getObjectType() + "," + destFile);
        host.copyFile(srcFile, destFile);
        StoragePlugin sp = new StoragePlugin(c);
        sp.storagePluginDestroy(secPoolUuid, srcFile);
        SnapshotObjectTO newSnap = new SnapshotObjectTO();
        // newSnap.setPath(destFile);
        // damnit frickin crap, no reference whatsoever... could use parent ?
        newSnap.setPath(dest.getPath() + "/" + src.getPath() + ".raw");
        newSnap.setParentSnapshotPath(null);
        return new CopyCmdAnswer(newSnap);
    } catch (Ovm3ResourceException e) {
        String msg = "Error backupSnapshot: " + e.getMessage();
        LOGGER.info(msg);
        return new CopyCmdAnswer(msg);
    }
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) DataTO(com.cloud.agent.api.to.DataTO) Linux(com.cloud.hypervisor.ovm3.objects.Linux) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) CloudstackPlugin(com.cloud.hypervisor.ovm3.objects.CloudstackPlugin) StoragePlugin(com.cloud.hypervisor.ovm3.objects.StoragePlugin) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Example 12 with SnapshotObjectTO

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

the class Ovm3StorageProcessor method createVolumeFromSnapshot.

/**
     * SnapshotObjectTO secondary to VolumeObjectTO primary in xenserver,
     */
@Override
public Answer createVolumeFromSnapshot(CopyCommand cmd) {
    LOGGER.debug("execute createVolumeFromSnapshot: " + cmd.getClass());
    try {
        DataTO srcData = cmd.getSrcTO();
        DataStoreTO srcStore = srcData.getDataStore();
        NfsTO srcImageStore = (NfsTO) srcStore;
        // source, should contain snap dir/filename
        SnapshotObjectTO srcSnap = (SnapshotObjectTO) srcData;
        String secPoolUuid = pool.setupSecondaryStorage(srcImageStore.getUrl());
        String srcFile = config.getAgentSecStoragePath() + "/" + secPoolUuid + "/" + srcSnap.getPath();
        // dest
        DataTO destData = cmd.getDestTO();
        VolumeObjectTO destVol = (VolumeObjectTO) destData;
        String primaryPoolUuid = destData.getDataStore().getUuid();
        String destFile = getVirtualDiskPath(destVol.getUuid(), ovmObject.deDash(primaryPoolUuid));
        Linux host = new Linux(c);
        host.copyFile(srcFile, destFile);
        VolumeObjectTO newVol = new VolumeObjectTO();
        newVol.setUuid(destVol.getUuid());
        // newVol.setPath(destFile);
        newVol.setPath(destVol.getUuid());
        newVol.setFormat(ImageFormat.RAW);
        return new CopyCmdAnswer(newVol);
    /* we assume the cache for templates is local */
    } catch (Ovm3ResourceException e) {
        LOGGER.debug("Failed to createVolumeFromSnapshot: ", e);
        return new CopyCmdAnswer(e.toString());
    }
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) DataTO(com.cloud.agent.api.to.DataTO) Linux(com.cloud.hypervisor.ovm3.objects.Linux) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) NfsTO(com.cloud.agent.api.to.NfsTO) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Example 13 with SnapshotObjectTO

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

the class XenServerStorageProcessor method deleteSnapshot.

@Override
public Answer deleteSnapshot(final DeleteCommand cmd) {
    final SnapshotObjectTO snapshot = (SnapshotObjectTO) cmd.getData();
    final DataStoreTO store = snapshot.getDataStore();
    if (store.getRole() == DataStoreRole.Primary) {
        final Connection conn = hypervisorResource.getConnection();
        final VDI snapshotVdi = getVDIbyUuid(conn, snapshot.getPath());
        if (snapshotVdi == null) {
            return new Answer(null);
        }
        String errMsg = null;
        try {
            deleteVDI(conn, snapshotVdi);
        } catch (final BadServerResponse e) {
            s_logger.debug("delete snapshot failed:" + e.toString());
            errMsg = e.toString();
        } catch (final XenAPIException e) {
            s_logger.debug("delete snapshot failed:" + e.toString());
            errMsg = e.toString();
        } catch (final XmlRpcException e) {
            s_logger.debug("delete snapshot failed:" + e.toString());
            errMsg = e.toString();
        }
        return new Answer(cmd, false, errMsg);
    }
    return new Answer(cmd, false, "unsupported storage type");
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) Answer(com.cloud.agent.api.Answer) ResignatureAnswer(org.apache.cloudstack.storage.command.ResignatureAnswer) IntroduceObjectAnswer(org.apache.cloudstack.storage.command.IntroduceObjectAnswer) AttachPrimaryDataStoreAnswer(org.apache.cloudstack.storage.command.AttachPrimaryDataStoreAnswer) DettachAnswer(org.apache.cloudstack.storage.command.DettachAnswer) SnapshotAndCopyAnswer(org.apache.cloudstack.storage.command.SnapshotAndCopyAnswer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) VDI(com.xensource.xenapi.VDI) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 14 with SnapshotObjectTO

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

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

the class Xenserver625StorageProcessor method createTemplateFromSnapshot2.

public Answer createTemplateFromSnapshot2(final CopyCommand cmd) {
    final Connection conn = hypervisorResource.getConnection();
    final SnapshotObjectTO snapshotObjTO = (SnapshotObjectTO) cmd.getSrcTO();
    final TemplateObjectTO templateObjTO = (TemplateObjectTO) cmd.getDestTO();
    if (!(snapshotObjTO.getDataStore() instanceof PrimaryDataStoreTO) || !(templateObjTO.getDataStore() instanceof NfsTO)) {
        return null;
    }
    NfsTO destStore = null;
    PrimaryDataStoreTO srcStore = null;
    URI destUri = null;
    try {
        srcStore = (PrimaryDataStoreTO) snapshotObjTO.getDataStore();
        destStore = (NfsTO) templateObjTO.getDataStore();
        destUri = new URI(destStore.getUrl());
    } catch (final Exception ex) {
        s_logger.debug("Invalid URI", ex);
        return new CopyCmdAnswer("Invalid URI: " + ex.toString());
    }
    SR srcSr = null;
    SR destSr = null;
    final String destDir = templateObjTO.getPath();
    VDI destVdi = null;
    boolean result = false;
    try {
        final Map<String, String> srcDetails = cmd.getOptions();
        final String iScsiName = srcDetails.get(DiskTO.IQN);
        final String storageHost = srcDetails.get(DiskTO.STORAGE_HOST);
        final String chapInitiatorUsername = srcDetails.get(DiskTO.CHAP_INITIATOR_USERNAME);
        final String chapInitiatorSecret = srcDetails.get(DiskTO.CHAP_INITIATOR_SECRET);
        String srType = null;
        srType = CitrixResourceBase.SRType.LVMOISCSI.toString();
        srcSr = hypervisorResource.getIscsiSR(conn, iScsiName, storageHost, iScsiName, chapInitiatorUsername, chapInitiatorSecret, false, srType, true);
        final String destNfsPath = destUri.getHost() + ":" + destUri.getPath();
        final String localDir = "/var/cloud_mount/" + UUID.nameUUIDFromBytes(destNfsPath.getBytes());
        mountNfs(conn, destNfsPath, localDir);
        makeDirectory(conn, localDir + "/" + destDir);
        destSr = createFileSR(conn, localDir + "/" + destDir);
        // there should only be one VDI in this SR
        final VDI srcVdi = srcSr.getVDIs(conn).iterator().next();
        destVdi = srcVdi.copy(conn, destSr);
        final String nameLabel = "cloud-" + UUID.randomUUID().toString();
        destVdi.setNameLabel(conn, nameLabel);
        // scan makes XenServer pick up VDI physicalSize
        destSr.scan(conn);
        final String templateUuid = destVdi.getUuid(conn);
        final String templateFilename = templateUuid + ".vhd";
        final long virtualSize = destVdi.getVirtualSize(conn);
        final long physicalSize = destVdi.getPhysicalUtilisation(conn);
        // create the template.properties file
        String templatePath = destNfsPath + "/" + destDir;
        templatePath = templatePath.replaceAll("//", "/");
        result = hypervisorResource.postCreatePrivateTemplate(conn, templatePath, templateFilename, templateUuid, nameLabel, null, physicalSize, virtualSize, templateObjTO.getId());
        if (!result) {
            throw new CloudRuntimeException("Could not create the template.properties file on secondary storage dir");
        }
        final TemplateObjectTO newTemplate = new TemplateObjectTO();
        newTemplate.setPath(destDir + "/" + templateFilename);
        newTemplate.setFormat(Storage.ImageFormat.VHD);
        newTemplate.setHypervisorType(HypervisorType.XenServer);
        newTemplate.setSize(virtualSize);
        newTemplate.setPhysicalSize(physicalSize);
        newTemplate.setName(templateUuid);
        result = true;
        return new CopyCmdAnswer(newTemplate);
    // } catch (Exception ex) {
    // s_logger.error("Failed to create a template from a snapshot",
    // ex);
    //
    // return new
    // CopyCmdAnswer("Failed to create a template from a snapshot: " +
    // ex.toString());
    } catch (final BadServerResponse e) {
        s_logger.error("Failed to create a template from a snapshot due to incomprehensible server response", e);
        return new CopyCmdAnswer("Failed to create a template from a snapshot: " + e.toString());
    } catch (final XenAPIException e) {
        s_logger.error("Failed to create a template from a snapshot due to xenapi error", e);
        return new CopyCmdAnswer("Failed to create a template from a snapshot: " + e.toString());
    } catch (final XmlRpcException e) {
        s_logger.error("Failed to create a template from a snapshot due to rpc error", e);
        return new CopyCmdAnswer("Failed to create a template from a snapshot: " + e.toString());
    } finally {
        if (!result) {
            if (destVdi != null) {
                try {
                    destVdi.destroy(conn);
                } catch (final Exception e) {
                    s_logger.debug("Cleaned up leftover VDI on destination storage due to failure: ", e);
                }
            }
        }
        if (srcSr != null) {
            hypervisorResource.removeSR(conn, srcSr);
        }
        if (destSr != null) {
            hypervisorResource.removeSR(conn, destSr);
        }
    }
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) NfsTO(com.cloud.agent.api.to.NfsTO) URI(java.net.URI) InternalErrorException(com.cloud.exception.InternalErrorException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VDI(com.xensource.xenapi.VDI) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) XmlRpcException(org.apache.xmlrpc.XmlRpcException) SR(com.xensource.xenapi.SR)

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