Search in sources :

Example 31 with PrimaryDataStoreTO

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

the class Xenserver625StorageProcessor 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 PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) destVolume.getDataStore();
    final DataStoreTO srcStore = srcVolume.getDataStore();
    if (srcStore instanceof NfsTO) {
        final NfsTO nfsStore = (NfsTO) srcStore;
        final String volumePath = srcVolume.getPath();
        int index = volumePath.lastIndexOf("/");
        final String volumeDirectory = volumePath.substring(0, index);
        String volumeUuid = volumePath.substring(index + 1);
        index = volumeUuid.indexOf(".");
        if (index != -1) {
            volumeUuid = volumeUuid.substring(0, index);
        }
        URI uri = null;
        try {
            uri = new URI(nfsStore.getUrl());
        } catch (final Exception e) {
            return new CopyCmdAnswer(e.toString());
        }
        final SR srcSr = createFileSr(conn, uri.getHost() + ":" + uri.getPath(), volumeDirectory);
        Task task = null;
        try {
            final SR primaryStoragePool = hypervisorResource.getStorageRepository(conn, primaryStore.getUuid());
            final VDI srcVdi = VDI.getByUuid(conn, volumeUuid);
            task = srcVdi.copyAsync(conn, primaryStoragePool, 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 VolumeObjectTO newVol = new VolumeObjectTO();
            destVdi.setNameLabel(conn, srcVolume.getName());
            newVol.setPath(destVdi.getUuid(conn));
            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());
        } finally {
            if (task != null) {
                try {
                    task.destroy(conn);
                } catch (final Exception e) {
                    s_logger.warn("unable to destroy task(" + task.toString() + ") due to " + e.toString());
                }
            }
            if (srcSr != null) {
                hypervisorResource.removeSR(conn, srcSr);
            }
        }
    }
    s_logger.debug("unsupported protocol");
    return new CopyCmdAnswer("unsupported protocol");
}
Also used : DataStoreTO(com.cloud.agent.api.to.DataStoreTO) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) Task(com.xensource.xenapi.Task) Connection(com.xensource.xenapi.Connection) 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) 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 32 with PrimaryDataStoreTO

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

the class Xenserver625StorageProcessor method copyTemplateToPrimaryStorage.

@Override
public Answer copyTemplateToPrimaryStorage(final CopyCommand cmd) {
    final DataTO srcData = cmd.getSrcTO();
    final DataTO destData = cmd.getDestTO();
    final int wait = cmd.getWait();
    final DataStoreTO srcStore = srcData.getDataStore();
    final Connection conn = hypervisorResource.getConnection();
    SR srcSr = null;
    SR destSr = null;
    boolean removeSrAfterCopy = false;
    Task task = null;
    try {
        if (srcStore instanceof NfsTO && srcData.getObjectType() == DataObjectType.TEMPLATE) {
            final NfsTO srcImageStore = (NfsTO) srcStore;
            final TemplateObjectTO srcTemplate = (TemplateObjectTO) srcData;
            final String storeUrl = srcImageStore.getUrl();
            final URI uri = new URI(storeUrl);
            String volumePath = srcData.getPath();
            volumePath = StringUtils.stripEnd(volumePath, "/");
            final String[] splits = volumePath.split("/");
            String volumeDirectory = volumePath;
            if (splits.length > 4) {
                // "template/tmpl/dcid/templateId/templatename"
                final int index = volumePath.lastIndexOf("/");
                volumeDirectory = volumePath.substring(0, index);
            }
            srcSr = createFileSr(conn, uri.getHost() + ":" + uri.getPath(), volumeDirectory);
            final Set<VDI> setVdis = srcSr.getVDIs(conn);
            if (setVdis.size() != 1) {
                return new CopyCmdAnswer("Expected 1 VDI template, but found " + setVdis.size() + " VDI templates on: " + uri.getHost() + ":" + uri.getPath() + "/" + volumeDirectory);
            }
            final VDI srcVdi = setVdis.iterator().next();
            boolean managed = false;
            String storageHost = null;
            String managedStoragePoolName = null;
            String managedStoragePoolRootVolumeName = null;
            String managedStoragePoolRootVolumeSize = null;
            String chapInitiatorUsername = null;
            String chapInitiatorSecret = null;
            final PrimaryDataStoreTO destStore = (PrimaryDataStoreTO) destData.getDataStore();
            Map<String, String> details = destStore.getDetails();
            if (details != null) {
                managed = Boolean.parseBoolean(details.get(PrimaryDataStoreTO.MANAGED));
                if (managed) {
                    storageHost = details.get(PrimaryDataStoreTO.STORAGE_HOST);
                    managedStoragePoolName = details.get(PrimaryDataStoreTO.MANAGED_STORE_TARGET);
                    managedStoragePoolRootVolumeName = details.get(PrimaryDataStoreTO.MANAGED_STORE_TARGET_ROOT_VOLUME);
                    managedStoragePoolRootVolumeSize = details.get(PrimaryDataStoreTO.VOLUME_SIZE);
                    chapInitiatorUsername = details.get(PrimaryDataStoreTO.CHAP_INITIATOR_USERNAME);
                    chapInitiatorSecret = details.get(PrimaryDataStoreTO.CHAP_INITIATOR_SECRET);
                    removeSrAfterCopy = Boolean.parseBoolean(details.get(PrimaryDataStoreTO.REMOVE_AFTER_COPY));
                }
            }
            if (managed) {
                details = new HashMap<String, String>();
                details.put(DiskTO.STORAGE_HOST, storageHost);
                details.put(DiskTO.IQN, managedStoragePoolName);
                details.put(DiskTO.VOLUME_SIZE, managedStoragePoolRootVolumeSize);
                details.put(DiskTO.CHAP_INITIATOR_USERNAME, chapInitiatorUsername);
                details.put(DiskTO.CHAP_INITIATOR_SECRET, chapInitiatorSecret);
                destSr = hypervisorResource.prepareManagedSr(conn, details);
            } else {
                final String srName = destStore.getUuid();
                final Set<SR> srs = SR.getByNameLabel(conn, srName);
                if (srs.size() != 1) {
                    final String msg = "There are " + srs.size() + " SRs with same name: " + srName;
                    s_logger.warn(msg);
                    return new CopyCmdAnswer(msg);
                } else {
                    destSr = srs.iterator().next();
                }
            }
            task = srcVdi.copyAsync(conn, destSr, null, null);
            // poll every 1 seconds ,
            hypervisorResource.waitForTask(conn, task, 1000, wait * 1000);
            hypervisorResource.checkForSuccess(conn, task);
            final VDI tmplVdi = Types.toVDI(task, conn);
            final String uuidToReturn;
            final Long physicalSize = tmplVdi.getPhysicalUtilisation(conn);
            if (managed) {
                uuidToReturn = tmplVdi.getUuid(conn);
                tmplVdi.setNameLabel(conn, managedStoragePoolRootVolumeName);
            } else {
                final VDI snapshotVdi = tmplVdi.snapshot(conn, new HashMap<String, String>());
                uuidToReturn = snapshotVdi.getUuid(conn);
                snapshotVdi.setNameLabel(conn, "Template " + srcTemplate.getName());
                tmplVdi.destroy(conn);
            }
            destSr.scan(conn);
            try {
                Thread.sleep(5000);
            } catch (final Exception e) {
            }
            final TemplateObjectTO newVol = new TemplateObjectTO();
            newVol.setUuid(uuidToReturn);
            newVol.setPath(uuidToReturn);
            if (physicalSize != null) {
                newVol.setSize(physicalSize);
            }
            newVol.setFormat(Storage.ImageFormat.VHD);
            return new CopyCmdAnswer(newVol);
        }
    } catch (final Exception e) {
        final String msg = "Catch Exception " + e.getClass().getName() + " for template due to " + e.toString();
        s_logger.warn(msg, e);
        return new CopyCmdAnswer(msg);
    } finally {
        if (task != null) {
            try {
                task.destroy(conn);
            } catch (final Exception e) {
                s_logger.debug("unable to destroy task (" + task.toWireString() + ") due to " + e.toString());
            }
        }
        if (srcSr != null) {
            hypervisorResource.removeSR(conn, srcSr);
        }
        if (removeSrAfterCopy && destSr != null) {
            hypervisorResource.removeSR(conn, destSr);
        }
    }
    return new CopyCmdAnswer("not implemented yet");
}
Also used : DataStoreTO(com.cloud.agent.api.to.DataStoreTO) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) Task(com.xensource.xenapi.Task) Connection(com.xensource.xenapi.Connection) 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) DataTO(com.cloud.agent.api.to.DataTO) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) VDI(com.xensource.xenapi.VDI) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) SR(com.xensource.xenapi.SR)

Example 33 with PrimaryDataStoreTO

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

the class VmwareResource method examineStorageSubSystemCommandFullCloneFlagForVmware.

/**
     * Examine StorageSubSystem command to get full clone flag, if provided
     * @param cmd command to execute
     * @param params params
     * @return copy of params including new values, if suitable
     */
protected EnumMap<VmwareStorageProcessorConfigurableFields, Object> examineStorageSubSystemCommandFullCloneFlagForVmware(CopyCommand cmd, EnumMap<VmwareStorageProcessorConfigurableFields, Object> params) {
    EnumMap<VmwareStorageProcessorConfigurableFields, Object> paramsCopy = new EnumMap<VmwareStorageProcessorConfigurableFields, Object>(params);
    HypervisorType hypervisor = cmd.getDestTO().getHypervisorType();
    if (hypervisor != null && hypervisor.equals(HypervisorType.VMware)) {
        DataStoreTO destDataStore = cmd.getDestTO().getDataStore();
        if (destDataStore instanceof PrimaryDataStoreTO) {
            PrimaryDataStoreTO dest = (PrimaryDataStoreTO) destDataStore;
            if (dest.isFullCloneFlag() != null) {
                paramsCopy.put(VmwareStorageProcessorConfigurableFields.FULL_CLONE_FLAG, dest.isFullCloneFlag().booleanValue());
            }
        }
    }
    return paramsCopy;
}
Also used : HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) VmwareStorageProcessorConfigurableFields(com.cloud.storage.resource.VmwareStorageProcessor.VmwareStorageProcessorConfigurableFields) EnumMap(java.util.EnumMap)

Aggregations

PrimaryDataStoreTO (org.apache.cloudstack.storage.to.PrimaryDataStoreTO)33 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)24 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)21 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)20 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)19 NfsTO (com.cloud.agent.api.to.NfsTO)19 InternalErrorException (com.cloud.exception.InternalErrorException)19 DataTO (com.cloud.agent.api.to.DataTO)17 SnapshotObjectTO (org.apache.cloudstack.storage.to.SnapshotObjectTO)11 TemplateObjectTO (org.apache.cloudstack.storage.to.TemplateObjectTO)10 LibvirtException (org.libvirt.LibvirtException)10 Connection (com.xensource.xenapi.Connection)9 SR (com.xensource.xenapi.SR)9 XenAPIException (com.xensource.xenapi.Types.XenAPIException)9 VDI (com.xensource.xenapi.VDI)9 URI (java.net.URI)9 XmlRpcException (org.apache.xmlrpc.XmlRpcException)9 IOException (java.io.IOException)8 RadosException (com.ceph.rados.exceptions.RadosException)7 RbdException (com.ceph.rbd.RbdException)7