Search in sources :

Example 36 with CopyCmdAnswer

use of org.apache.cloudstack.storage.command.CopyCmdAnswer 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 37 with CopyCmdAnswer

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

the class SimulatorStorageProcessor method copyVolumeFromImageCacheToPrimary.

@Override
public Answer copyVolumeFromImageCacheToPrimary(CopyCommand cmd) {
    VolumeObjectTO volume = new VolumeObjectTO();
    volume.setPath(UUID.randomUUID().toString());
    volume.setSize(100);
    volume.setFormat(Storage.ImageFormat.RAW);
    return new CopyCmdAnswer(volume);
}
Also used : VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Example 38 with CopyCmdAnswer

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

the class SimulatorStorageProcessor method createTemplateFromVolume.

@Override
public Answer createTemplateFromVolume(CopyCommand cmd) {
    DataTO destData = cmd.getDestTO();
    VolumeObjectTO srcData = (VolumeObjectTO) cmd.getSrcTO();
    TemplateObjectTO template = new TemplateObjectTO();
    template.setPath(template.getName());
    template.setFormat(Storage.ImageFormat.RAW);
    template.setSize(srcData.getSize());
    DataStoreTO imageStore = destData.getDataStore();
    if (!(imageStore instanceof NfsTO)) {
        return new CopyCmdAnswer("unsupported protocol");
    }
    return new CopyCmdAnswer(template);
}
Also used : DataStoreTO(com.cloud.agent.api.to.DataStoreTO) DataTO(com.cloud.agent.api.to.DataTO) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) NfsTO(com.cloud.agent.api.to.NfsTO) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Example 39 with CopyCmdAnswer

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

the class NfsSecondaryStorageResource method copyFromNfsToS3.

protected Answer copyFromNfsToS3(CopyCommand cmd) {
    final DataTO srcData = cmd.getSrcTO();
    final DataTO destData = cmd.getDestTO();
    DataStoreTO srcDataStore = srcData.getDataStore();
    NfsTO srcStore = (NfsTO) srcDataStore;
    DataStoreTO destDataStore = destData.getDataStore();
    final S3TO s3 = (S3TO) destDataStore;
    try {
        final String templatePath = determineStorageTemplatePath(srcStore.getUrl(), srcData.getPath(), _nfsVersion);
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Found " + srcData.getObjectType() + " from directory " + templatePath + " to upload to S3.");
        }
        final String bucket = s3.getBucketName();
        File srcFile = findFile(templatePath);
        if (srcFile == null) {
            return new CopyCmdAnswer("Can't find src file:" + templatePath);
        }
        ImageFormat format = getTemplateFormat(srcFile.getName());
        String key = destData.getPath() + S3Utils.SEPARATOR + srcFile.getName();
        putFile(s3, srcFile, bucket, key).waitForCompletion();
        DataTO retObj = null;
        if (destData.getObjectType() == DataObjectType.TEMPLATE) {
            TemplateObjectTO newTemplate = new TemplateObjectTO();
            newTemplate.setPath(key);
            newTemplate.setSize(getVirtualSize(srcFile, format));
            newTemplate.setPhysicalSize(srcFile.length());
            newTemplate.setFormat(format);
            retObj = newTemplate;
        } else if (destData.getObjectType() == DataObjectType.VOLUME) {
            VolumeObjectTO newVol = new VolumeObjectTO();
            newVol.setPath(key);
            newVol.setSize(srcFile.length());
            retObj = newVol;
        } else if (destData.getObjectType() == DataObjectType.SNAPSHOT) {
            SnapshotObjectTO newSnapshot = new SnapshotObjectTO();
            newSnapshot.setPath(key);
            retObj = newSnapshot;
        }
        return new CopyCmdAnswer(retObj);
    } catch (Exception e) {
        s_logger.error("failed to upload" + srcData.getPath(), e);
        return new CopyCmdAnswer("failed to upload" + srcData.getPath() + 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) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) NfsTO(com.cloud.agent.api.to.NfsTO) S3TO(com.cloud.agent.api.to.S3TO) File(java.io.File) S3Utils.putFile(com.cloud.utils.storage.S3.S3Utils.putFile) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException) ImageFormat(com.cloud.storage.Storage.ImageFormat)

Example 40 with CopyCmdAnswer

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

the class Ovm3StorageProcessor method createTemplateFromSnapshot.

/**
     * Copies from secondary to secondary
     */
@Override
public Answer createTemplateFromSnapshot(CopyCommand cmd) {
    LOGGER.debug("execute createTemplateFromSnapshot: " + cmd.getClass());
    try {
        // src.getPath contains the uuid of the snapshot.
        DataTO srcData = cmd.getSrcTO();
        SnapshotObjectTO srcSnap = (SnapshotObjectTO) srcData;
        String secPoolUuid = pool.setupSecondaryStorage(srcData.getDataStore().getUrl());
        String srcFile = config.getAgentSecStoragePath() + "/" + secPoolUuid + "/" + srcSnap.getPath();
        // dest
        DataTO destData = cmd.getDestTO();
        TemplateObjectTO destTemplate = (TemplateObjectTO) destData;
        String secPoolUuidTemplate = pool.setupSecondaryStorage(destData.getDataStore().getUrl());
        String destDir = config.getAgentSecStoragePath() + "/" + secPoolUuidTemplate + "/" + destTemplate.getPath();
        String destFile = destDir + "/" + destTemplate.getUuid() + ".raw";
        CloudstackPlugin csp = new CloudstackPlugin(c);
        csp.ovsMkdirs(destDir);
        Linux host = new Linux(c);
        host.copyFile(srcFile, destFile);
        TemplateObjectTO newVol = new TemplateObjectTO();
        newVol.setUuid(destTemplate.getUuid());
        newVol.setPath(destTemplate.getUuid());
        newVol.setFormat(ImageFormat.RAW);
        return new CopyCmdAnswer(newVol);
    } 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) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) CloudstackPlugin(com.cloud.hypervisor.ovm3.objects.CloudstackPlugin) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Aggregations

CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)78 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)49 NfsTO (com.cloud.agent.api.to.NfsTO)40 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)38 DataTO (com.cloud.agent.api.to.DataTO)37 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)37 TemplateObjectTO (org.apache.cloudstack.storage.to.TemplateObjectTO)34 PrimaryDataStoreTO (org.apache.cloudstack.storage.to.PrimaryDataStoreTO)30 InternalErrorException (com.cloud.exception.InternalErrorException)27 SnapshotObjectTO (org.apache.cloudstack.storage.to.SnapshotObjectTO)25 Connection (com.xensource.xenapi.Connection)18 XenAPIException (com.xensource.xenapi.Types.XenAPIException)18 XmlRpcException (org.apache.xmlrpc.XmlRpcException)18 SR (com.xensource.xenapi.SR)17 VDI (com.xensource.xenapi.VDI)17 URI (java.net.URI)16 UnsupportedEncodingException (java.io.UnsupportedEncodingException)10 ConfigurationException (javax.naming.ConfigurationException)10 IOException (java.io.IOException)9 CopyCommand (org.apache.cloudstack.storage.command.CopyCommand)9