Search in sources :

Example 21 with NfsTO

use of com.cloud.agent.api.to.NfsTO in project cloudstack by apache.

the class Ovm3StorageProcessor method execute.

public final Answer execute(final CopyCommand cmd) {
    LOGGER.debug("execute: " + cmd.getClass());
    DataTO srcData = cmd.getSrcTO();
    DataStoreTO srcStore = srcData.getDataStore();
    DataTO destData = cmd.getDestTO();
    DataStoreTO destStore = destData.getDataStore();
    String msg = "Not implemented yet";
    try {
        /* target and source are NFS and TEMPLATE */
        if ((srcStore instanceof NfsTO) && (srcData.getObjectType() == DataObjectType.TEMPLATE) && (destData.getObjectType() == DataObjectType.TEMPLATE)) {
            return copyTemplateToPrimaryStorage(cmd);
        /* we assume the cache for templates is local */
        } else if ((srcData.getObjectType() == DataObjectType.TEMPLATE) && (destData.getObjectType() == DataObjectType.VOLUME)) {
            if (srcStore.getUrl().equals(destStore.getUrl())) {
                return cloneVolumeFromBaseTemplate(cmd);
            } else {
                msg = "Primary to Primary doesn't match";
                LOGGER.debug(msg);
            }
        } else if ((srcData.getObjectType() == DataObjectType.SNAPSHOT) && (destData.getObjectType() == DataObjectType.SNAPSHOT)) {
            return backupSnapshot(cmd);
        } else if ((srcData.getObjectType() == DataObjectType.SNAPSHOT) && (destData.getObjectType() == DataObjectType.TEMPLATE)) {
            return createTemplateFromSnapshot(cmd);
        } else if ((srcData.getObjectType() == DataObjectType.SNAPSHOT) && (destData.getObjectType() == DataObjectType.VOLUME)) {
            return createVolumeFromSnapshot(cmd);
        } else {
            msg = "Unable to do stuff for " + srcStore.getClass() + ":" + srcData.getObjectType() + " to " + destStore.getClass() + ":" + destData.getObjectType();
            LOGGER.debug(msg);
        }
    } catch (Exception e) {
        msg = "Catch Exception " + e.getClass().getName() + " for template due to " + e.toString();
        LOGGER.warn(msg, e);
        return new CopyCmdAnswer(msg);
    }
    LOGGER.warn(msg + " " + cmd.getClass());
    return new CopyCmdAnswer(msg);
}
Also used : DataStoreTO(com.cloud.agent.api.to.DataStoreTO) DataTO(com.cloud.agent.api.to.DataTO) NfsTO(com.cloud.agent.api.to.NfsTO) URISyntaxException(java.net.URISyntaxException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Example 22 with NfsTO

use of com.cloud.agent.api.to.NfsTO 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 23 with NfsTO

use of com.cloud.agent.api.to.NfsTO in project cloudstack by apache.

the class Ovm3StorageProcessorTest method volume.

private VolumeObjectTO volume(final String uuid, final String dsuuid, final String storeUrl, final String path) {
    VolumeObjectTO volume = new VolumeObjectTO();
    NfsTO nfsDataStore = new NfsTO();
    nfsDataStore.setUuid(dsuuid);
    nfsDataStore.setUrl(storeUrl);
    volume.setDataStore(nfsDataStore);
    volume.setPath(path);
    volume.setUuid(uuid);
    return volume;
}
Also used : VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) NfsTO(com.cloud.agent.api.to.NfsTO)

Example 24 with NfsTO

use of com.cloud.agent.api.to.NfsTO in project cloudstack by apache.

the class Ovm3StorageProcessorTest method snapshot.

private SnapshotObjectTO snapshot(final String uuid, final String dsuuid, final String storeUrl, final String path) {
    SnapshotObjectTO volume = new SnapshotObjectTO();
    NfsTO nfsDataStore = new NfsTO();
    nfsDataStore.setUuid(dsuuid);
    nfsDataStore.setUrl(storeUrl);
    volume.setDataStore(nfsDataStore);
    volume.setPath(path);
    // volume.setUuid(uuid);
    return volume;
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) NfsTO(com.cloud.agent.api.to.NfsTO)

Example 25 with NfsTO

use of com.cloud.agent.api.to.NfsTO 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)

Aggregations

NfsTO (com.cloud.agent.api.to.NfsTO)142 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)110 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)79 DataTO (com.cloud.agent.api.to.DataTO)71 InternalErrorException (com.cloud.exception.InternalErrorException)58 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)52 PrimaryDataStoreTO (org.apache.cloudstack.storage.to.PrimaryDataStoreTO)39 TemplateObjectTO (org.apache.cloudstack.storage.to.TemplateObjectTO)38 XmlRpcException (org.apache.xmlrpc.XmlRpcException)37 XenAPIException (com.xensource.xenapi.Types.XenAPIException)36 URI (java.net.URI)36 Connection (com.xensource.xenapi.Connection)34 SR (com.xensource.xenapi.SR)34 VDI (com.xensource.xenapi.VDI)34 CopyCmdAnswer (com.cloud.storage.command.CopyCmdAnswer)32 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)32 Answer (com.cloud.agent.api.Answer)29 IOException (java.io.IOException)28 File (java.io.File)27 PrimaryDataStoreTO (com.cloud.storage.to.PrimaryDataStoreTO)26