Search in sources :

Example 36 with NfsTO

use of com.cloud.legacymodel.to.NfsTO in project cosmic by MissionCriticalCloud.

the class XenServerStorageProcessor 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 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 = destData.getDataStore().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);
    }
    try {
        final SR 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);
        }
        // Get the absolute path of the snapshot on the secondary storage.
        String snapshotInstallPath = snapshot.getPath();
        final int index = snapshotInstallPath.lastIndexOf(nfsImageStore.getPathSeparator());
        final String snapshotName = snapshotInstallPath.substring(index + 1);
        if (!snapshotName.startsWith("VHD-") && !snapshotName.endsWith(".vhd")) {
            snapshotInstallPath = snapshotInstallPath + ".vhd";
        }
        final URI snapshotURI = new URI(secondaryStorageUrl + nfsImageStore.getPathSeparator() + snapshotInstallPath);
        final String snapshotPath = snapshotURI.getHost() + ":" + snapshotURI.getPath();
        final String srUuid = primaryStorageSR.getUuid(conn);
        volumeUUID = copy_vhd_from_secondarystorage(conn, snapshotPath, srUuid, wait);
        result = true;
        final VDI volume = VDI.getByUuid(conn, volumeUUID);
        final VDI.Record vdir = volume.getRecord(conn);
        final VolumeObjectTO newVol = new VolumeObjectTO();
        newVol.setPath(volumeUUID);
        newVol.setSize(vdir.virtualSize);
        return new CopyCmdAnswer(newVol);
    } catch (final 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);
    }
    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(com.cloud.legacymodel.to.SnapshotObjectTO) PrimaryDataStoreTO(com.cloud.legacymodel.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) InternalErrorException(com.cloud.legacymodel.exceptions.InternalErrorException) NfsTO(com.cloud.legacymodel.to.NfsTO) URI(java.net.URI) XenAPIException(com.xensource.xenapi.Types.XenAPIException) InternalErrorException(com.cloud.legacymodel.exceptions.InternalErrorException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) DataTO(com.cloud.legacymodel.to.DataTO) PrimaryDataStoreTO(com.cloud.legacymodel.to.PrimaryDataStoreTO) VolumeObjectTO(com.cloud.legacymodel.to.VolumeObjectTO) VDI(com.xensource.xenapi.VDI) CopyCmdAnswer(com.cloud.legacymodel.communication.answer.CopyCmdAnswer) SR(com.xensource.xenapi.SR)

Example 37 with NfsTO

use of com.cloud.legacymodel.to.NfsTO in project cosmic by MissionCriticalCloud.

the class XenServerStorageProcessor method createTemplateFromVolume.

@Override
public Answer createTemplateFromVolume(final CopyCommand cmd) {
    final Connection conn = hypervisorResource.getConnection();
    final VolumeObjectTO volume = (VolumeObjectTO) cmd.getSrcTO();
    final TemplateObjectTO template = (TemplateObjectTO) cmd.getDestTO();
    final NfsTO destStore = (NfsTO) cmd.getDestTO().getDataStore();
    final int wait = cmd.getWait();
    final String secondaryStoragePoolURL = destStore.getUrl();
    final String volumeUUID = volume.getPath();
    final String userSpecifiedName = template.getName();
    String details = null;
    SR tmpltSR = null;
    boolean result = false;
    String secondaryStorageMountPath = null;
    String installPath = null;
    try {
        final URI uri = new URI(secondaryStoragePoolURL);
        secondaryStorageMountPath = uri.getHost() + ":" + uri.getPath();
        installPath = template.getPath();
        if (!hypervisorResource.createSecondaryStorageFolder(conn, secondaryStorageMountPath, installPath)) {
            details = " Filed to create folder " + installPath + " in secondary storage";
            s_logger.warn(details);
            return new CopyCmdAnswer(details);
        }
        final VDI vol = getVDIbyUuid(conn, volumeUUID);
        // create template SR
        final URI tmpltURI = new URI(secondaryStoragePoolURL + "/" + installPath);
        tmpltSR = hypervisorResource.createNfsSRbyURI(conn, tmpltURI, false);
        // copy volume to template SR
        final VDI tmpltVDI = hypervisorResource.cloudVDIcopy(conn, vol, tmpltSR, wait);
        // scan makes XenServer pick up VDI physicalSize
        tmpltSR.scan(conn);
        if (userSpecifiedName != null) {
            tmpltVDI.setNameLabel(conn, userSpecifiedName);
        }
        final String tmpltUUID = tmpltVDI.getUuid(conn);
        final String tmpltFilename = tmpltUUID + ".vhd";
        final long virtualSize = tmpltVDI.getVirtualSize(conn);
        final long physicalSize = tmpltVDI.getPhysicalUtilisation(conn);
        // create the template.properties file
        final String templatePath = secondaryStorageMountPath + "/" + installPath;
        result = hypervisorResource.postCreatePrivateTemplate(conn, templatePath, tmpltFilename, tmpltUUID, userSpecifiedName, null, physicalSize, virtualSize, template.getId());
        if (!result) {
            throw new CloudRuntimeException("Could not create the template.properties file on secondary storage dir: " + tmpltURI);
        }
        installPath = installPath + "/" + tmpltFilename;
        hypervisorResource.removeSR(conn, tmpltSR);
        tmpltSR = null;
        final TemplateObjectTO newTemplate = new TemplateObjectTO();
        newTemplate.setPath(installPath);
        newTemplate.setFormat(ImageFormat.VHD);
        newTemplate.setSize(virtualSize);
        newTemplate.setPhysicalSize(physicalSize);
        newTemplate.setName(tmpltUUID);
        final CopyCmdAnswer answer = new CopyCmdAnswer(newTemplate);
        return answer;
    } catch (final Exception e) {
        if (tmpltSR != null) {
            hypervisorResource.removeSR(conn, tmpltSR);
        }
        if (secondaryStorageMountPath != null) {
            hypervisorResource.deleteSecondaryStorageFolder(conn, secondaryStorageMountPath, installPath);
        }
        details = "Creating template from volume " + volumeUUID + " failed due to " + e.toString();
        s_logger.error(details, e);
    }
    return new CopyCmdAnswer(details);
}
Also used : Connection(com.xensource.xenapi.Connection) NfsTO(com.cloud.legacymodel.to.NfsTO) URI(java.net.URI) XenAPIException(com.xensource.xenapi.Types.XenAPIException) InternalErrorException(com.cloud.legacymodel.exceptions.InternalErrorException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) VolumeObjectTO(com.cloud.legacymodel.to.VolumeObjectTO) VDI(com.xensource.xenapi.VDI) TemplateObjectTO(com.cloud.legacymodel.to.TemplateObjectTO) CopyCmdAnswer(com.cloud.legacymodel.communication.answer.CopyCmdAnswer) SR(com.xensource.xenapi.SR)

Example 38 with NfsTO

use of com.cloud.legacymodel.to.NfsTO in project cosmic by MissionCriticalCloud.

the class XenServerStorageProcessor method copyVolumeFromImageCacheToPrimary.

@Override
public Answer copyVolumeFromImageCacheToPrimary(final CopyCommand cmd) {
    final Connection conn = hypervisorResource.getConnection();
    final DataTO srcData = cmd.getSrcTO();
    final DataTO destData = cmd.getDestTO();
    final int wait = cmd.getWait();
    final VolumeObjectTO srcVolume = (VolumeObjectTO) srcData;
    final VolumeObjectTO destVolume = (VolumeObjectTO) destData;
    final DataStoreTO srcStore = srcVolume.getDataStore();
    if (srcStore instanceof NfsTO) {
        final NfsTO nfsStore = (NfsTO) srcStore;
        try {
            final SR primaryStoragePool = hypervisorResource.getStorageRepository(conn, destVolume.getDataStore().getUuid());
            final String srUuid = primaryStoragePool.getUuid(conn);
            final URI uri = new URI(nfsStore.getUrl());
            final String volumePath = uri.getHost() + ":" + uri.getPath() + nfsStore.getPathSeparator() + srcVolume.getPath();
            final String uuid = copy_vhd_from_secondarystorage(conn, volumePath, srUuid, wait);
            final VolumeObjectTO newVol = new VolumeObjectTO();
            newVol.setPath(uuid);
            newVol.setSize(srcVolume.getSize());
            return new CopyCmdAnswer(newVol);
        } catch (final Exception e) {
            final String msg = "Catch Exception " + e.getClass().getName() + " due to " + e.toString();
            s_logger.warn(msg, e);
            return new CopyCmdAnswer(e.toString());
        }
    }
    s_logger.debug("unsupported protocol");
    return new CopyCmdAnswer("unsupported protocol");
}
Also used : PrimaryDataStoreTO(com.cloud.legacymodel.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) DataTO(com.cloud.legacymodel.to.DataTO) Connection(com.xensource.xenapi.Connection) VolumeObjectTO(com.cloud.legacymodel.to.VolumeObjectTO) NfsTO(com.cloud.legacymodel.to.NfsTO) URI(java.net.URI) CopyCmdAnswer(com.cloud.legacymodel.communication.answer.CopyCmdAnswer) XenAPIException(com.xensource.xenapi.Types.XenAPIException) InternalErrorException(com.cloud.legacymodel.exceptions.InternalErrorException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) SR(com.xensource.xenapi.SR)

Example 39 with NfsTO

use of com.cloud.legacymodel.to.NfsTO in project cosmic by MissionCriticalCloud.

the class XenServerStorageProcessor method copyVolumeFromPrimaryToSecondary.

@Override
public Answer copyVolumeFromPrimaryToSecondary(final CopyCommand cmd) {
    final Connection conn = hypervisorResource.getConnection();
    final VolumeObjectTO srcVolume = (VolumeObjectTO) cmd.getSrcTO();
    final VolumeObjectTO destVolume = (VolumeObjectTO) cmd.getDestTO();
    final int wait = cmd.getWait();
    final DataStoreTO destStore = destVolume.getDataStore();
    if (destStore instanceof NfsTO) {
        SR secondaryStorage = null;
        try {
            final NfsTO nfsStore = (NfsTO) destStore;
            final URI uri = new URI(nfsStore.getUrl());
            // Create the volume folder
            if (!hypervisorResource.createSecondaryStorageFolder(conn, uri.getHost() + ":" + uri.getPath(), destVolume.getPath())) {
                throw new InternalErrorException("Failed to create the volume folder.");
            }
            // Create a SR for the volume UUID folder
            secondaryStorage = hypervisorResource.createNfsSRbyURI(conn, new URI(nfsStore.getUrl() + nfsStore.getPathSeparator() + destVolume.getPath()), false);
            // Look up the volume on the source primary storage pool
            final VDI srcVdi = getVDIbyUuid(conn, srcVolume.getPath());
            // Copy the volume to secondary storage
            final VDI destVdi = hypervisorResource.cloudVDIcopy(conn, srcVdi, secondaryStorage, wait);
            final String destVolumeUUID = destVdi.getUuid(conn);
            final VolumeObjectTO newVol = new VolumeObjectTO();
            newVol.setPath(destVolume.getPath() + nfsStore.getPathSeparator() + destVolumeUUID + ".vhd");
            newVol.setSize(srcVolume.getSize());
            return new CopyCmdAnswer(newVol);
        } catch (final Exception e) {
            s_logger.debug("Failed to copy volume to secondary: " + e.toString());
            return new CopyCmdAnswer("Failed to copy volume to secondary: " + e.toString());
        } finally {
            hypervisorResource.removeSR(conn, secondaryStorage);
        }
    }
    return new CopyCmdAnswer("unsupported protocol");
}
Also used : PrimaryDataStoreTO(com.cloud.legacymodel.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) Connection(com.xensource.xenapi.Connection) VolumeObjectTO(com.cloud.legacymodel.to.VolumeObjectTO) VDI(com.xensource.xenapi.VDI) InternalErrorException(com.cloud.legacymodel.exceptions.InternalErrorException) NfsTO(com.cloud.legacymodel.to.NfsTO) URI(java.net.URI) CopyCmdAnswer(com.cloud.legacymodel.communication.answer.CopyCmdAnswer) XenAPIException(com.xensource.xenapi.Types.XenAPIException) InternalErrorException(com.cloud.legacymodel.exceptions.InternalErrorException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) SR(com.xensource.xenapi.SR)

Example 40 with NfsTO

use of com.cloud.legacymodel.to.NfsTO in project cosmic by MissionCriticalCloud.

the class Xenserver625StorageProcessor method copyVolumeFromPrimaryToSecondary.

@Override
public Answer copyVolumeFromPrimaryToSecondary(final CopyCommand cmd) {
    final Connection conn = hypervisorResource.getConnection();
    final VolumeObjectTO srcVolume = (VolumeObjectTO) cmd.getSrcTO();
    final VolumeObjectTO destVolume = (VolumeObjectTO) cmd.getDestTO();
    final int wait = cmd.getWait();
    final DataStoreTO destStore = destVolume.getDataStore();
    if (destStore instanceof NfsTO) {
        SR secondaryStorage = null;
        Task task = null;
        try {
            final NfsTO nfsStore = (NfsTO) destStore;
            final URI uri = new URI(nfsStore.getUrl());
            // Create the volume folder
            if (!hypervisorResource.createSecondaryStorageFolder(conn, uri.getHost() + ":" + uri.getPath(), destVolume.getPath())) {
                throw new InternalErrorException("Failed to create the volume folder.");
            }
            // Create a SR for the volume UUID folder
            secondaryStorage = createFileSr(conn, uri.getHost() + ":" + uri.getPath(), destVolume.getPath());
            // Look up the volume on the source primary storage pool
            final VDI srcVdi = getVDIbyUuid(conn, srcVolume.getPath());
            // Copy the volume to secondary storage
            task = srcVdi.copyAsync(conn, secondaryStorage, null, null);
            // poll every 1 seconds ,
            hypervisorResource.waitForTask(conn, task, 1000, wait * 1000);
            hypervisorResource.checkForSuccess(conn, task);
            final VDI destVdi = Types.toVDI(task, conn);
            final String destVolumeUUID = destVdi.getUuid(conn);
            final VolumeObjectTO newVol = new VolumeObjectTO();
            newVol.setPath(destVolume.getPath() + File.separator + destVolumeUUID + ".vhd");
            newVol.setSize(srcVolume.getSize());
            return new CopyCmdAnswer(newVol);
        } catch (final Exception e) {
            s_logger.debug("Failed to copy volume to secondary: " + e.toString());
            return new CopyCmdAnswer("Failed to copy volume to secondary: " + e.toString());
        } finally {
            if (task != null) {
                try {
                    task.destroy(conn);
                } catch (final Exception e) {
                    s_logger.warn("unable to destroy task(" + task.toWireString() + ") due to " + e.toString());
                }
            }
            hypervisorResource.removeSR(conn, secondaryStorage);
        }
    }
    return new CopyCmdAnswer("unsupported protocol");
}
Also used : PrimaryDataStoreTO(com.cloud.legacymodel.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) Task(com.xensource.xenapi.Task) Connection(com.xensource.xenapi.Connection) InternalErrorException(com.cloud.legacymodel.exceptions.InternalErrorException) NfsTO(com.cloud.legacymodel.to.NfsTO) URI(java.net.URI) InternalErrorException(com.cloud.legacymodel.exceptions.InternalErrorException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) VolumeObjectTO(com.cloud.legacymodel.to.VolumeObjectTO) VDI(com.xensource.xenapi.VDI) CopyCmdAnswer(com.cloud.legacymodel.communication.answer.CopyCmdAnswer) SR(com.xensource.xenapi.SR)

Aggregations

NfsTO (com.cloud.legacymodel.to.NfsTO)46 DataStoreTO (com.cloud.legacymodel.to.DataStoreTO)36 CopyCmdAnswer (com.cloud.legacymodel.communication.answer.CopyCmdAnswer)32 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)28 DataTO (com.cloud.legacymodel.to.DataTO)26 PrimaryDataStoreTO (com.cloud.legacymodel.to.PrimaryDataStoreTO)26 InternalErrorException (com.cloud.legacymodel.exceptions.InternalErrorException)21 XenAPIException (com.xensource.xenapi.Types.XenAPIException)18 XmlRpcException (org.apache.xmlrpc.XmlRpcException)18 Connection (com.xensource.xenapi.Connection)17 SR (com.xensource.xenapi.SR)17 VDI (com.xensource.xenapi.VDI)17 URI (java.net.URI)17 VolumeObjectTO (com.cloud.legacymodel.to.VolumeObjectTO)16 TemplateObjectTO (com.cloud.legacymodel.to.TemplateObjectTO)14 Answer (com.cloud.legacymodel.communication.answer.Answer)13 SnapshotObjectTO (com.cloud.legacymodel.to.SnapshotObjectTO)10 SecStorageSetupAnswer (com.cloud.legacymodel.communication.answer.SecStorageSetupAnswer)9 CheckHealthAnswer (com.cloud.legacymodel.communication.answer.CheckHealthAnswer)8 GetStorageStatsAnswer (com.cloud.legacymodel.communication.answer.GetStorageStatsAnswer)8