Search in sources :

Example 1 with PrimaryDataStoreTO

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

the class AncientDataMotionStrategy method addFullCloneFlagOnVMwareDest.

/**
     * Adds {@code 'vmware.create.full.clone'} value for a given primary storage, whose HV is VMware, on datastore's {@code fullCloneFlag} field
     * @param dataTO Dest data store TO
     * @return dataTO including fullCloneFlag, if provided
     */
protected DataTO addFullCloneFlagOnVMwareDest(DataTO dataTO) {
    if (dataTO != null && dataTO.getHypervisorType().equals(Hypervisor.HypervisorType.VMware)) {
        DataStoreTO dataStoreTO = dataTO.getDataStore();
        if (dataStoreTO != null && dataStoreTO instanceof PrimaryDataStoreTO) {
            PrimaryDataStoreTO primaryDataStoreTO = (PrimaryDataStoreTO) dataStoreTO;
            Boolean value = CapacityManager.VmwareCreateCloneFull.valueIn(primaryDataStoreTO.getId());
            primaryDataStoreTO.setFullCloneFlag(value);
        }
    }
    return dataTO;
}
Also used : PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO)

Example 2 with PrimaryDataStoreTO

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

the class KVMStorageProcessor method handleDownloadTemplateToPrimaryStorage.

@Override
public Answer handleDownloadTemplateToPrimaryStorage(DirectDownloadCommand cmd) {
    final PrimaryDataStoreTO pool = cmd.getDestPool();
    DirectTemplateDownloader downloader;
    KVMPhysicalDisk template;
    KVMStoragePool destPool = null;
    try {
        s_logger.debug("Verifying temporary location for downloading the template exists on the host");
        String temporaryDownloadPath = resource.getDirectDownloadTemporaryDownloadPath();
        if (!isLocationAccessible(temporaryDownloadPath)) {
            String msg = "The temporary location path for downloading templates does not exist: " + temporaryDownloadPath + " on this host";
            s_logger.error(msg);
            return new DirectDownloadAnswer(false, msg, true);
        }
        Long templateSize = null;
        if (StringUtils.isNotBlank(cmd.getUrl())) {
            String url = cmd.getUrl();
            templateSize = UriUtils.getRemoteSize(url);
        }
        s_logger.debug("Checking for free space on the host for downloading the template with physical size: " + templateSize + " and virtual size: " + cmd.getTemplateSize());
        if (!isEnoughSpaceForDownloadTemplateOnTemporaryLocation(templateSize)) {
            String msg = "Not enough space on the defined temporary location to download the template " + cmd.getTemplateId();
            s_logger.error(msg);
            return new DirectDownloadAnswer(false, msg, true);
        }
        destPool = storagePoolMgr.getStoragePool(pool.getPoolType(), pool.getUuid());
        downloader = getDirectTemplateDownloaderFromCommand(cmd, destPool, temporaryDownloadPath);
        s_logger.debug("Trying to download template");
        Pair<Boolean, String> result = downloader.downloadTemplate();
        if (!result.first()) {
            s_logger.warn("Couldn't download template");
            return new DirectDownloadAnswer(false, "Unable to download template", true);
        }
        String tempFilePath = result.second();
        if (!downloader.validateChecksum()) {
            s_logger.warn("Couldn't validate template checksum");
            return new DirectDownloadAnswer(false, "Checksum validation failed", false);
        }
        final TemplateObjectTO destTemplate = cmd.getDestData();
        String destTemplatePath = (destTemplate != null) ? destTemplate.getPath() : null;
        if (!storagePoolMgr.connectPhysicalDisk(pool.getPoolType(), pool.getUuid(), destTemplatePath, null)) {
            s_logger.warn("Unable to connect physical disk at path: " + destTemplatePath + ", in storage pool id: " + pool.getUuid());
        }
        template = storagePoolMgr.createPhysicalDiskFromDirectDownloadTemplate(tempFilePath, destTemplatePath, destPool, cmd.getFormat(), cmd.getWaitInMillSeconds());
        if (!storagePoolMgr.disconnectPhysicalDisk(pool.getPoolType(), pool.getUuid(), destTemplatePath)) {
            s_logger.warn("Unable to disconnect physical disk at path: " + destTemplatePath + ", in storage pool id: " + pool.getUuid());
        }
    } catch (CloudRuntimeException e) {
        s_logger.warn("Error downloading template " + cmd.getTemplateId() + " due to: " + e.getMessage());
        return new DirectDownloadAnswer(false, "Unable to download template: " + e.getMessage(), true);
    } catch (IllegalArgumentException e) {
        return new DirectDownloadAnswer(false, "Unable to create direct downloader: " + e.getMessage(), true);
    }
    return new DirectDownloadAnswer(true, template.getSize(), template.getName());
}
Also used : HttpsDirectTemplateDownloader(com.cloud.agent.direct.download.HttpsDirectTemplateDownloader) DirectTemplateDownloader(com.cloud.agent.direct.download.DirectTemplateDownloader) NfsDirectTemplateDownloader(com.cloud.agent.direct.download.NfsDirectTemplateDownloader) MetalinkDirectTemplateDownloader(com.cloud.agent.direct.download.MetalinkDirectTemplateDownloader) HttpDirectTemplateDownloader(com.cloud.agent.direct.download.HttpDirectTemplateDownloader) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) DirectDownloadAnswer(org.apache.cloudstack.agent.directdownload.DirectDownloadAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO)

Example 3 with PrimaryDataStoreTO

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

the class KVMStorageProcessor method deleteSnapshot.

@Override
public Answer deleteSnapshot(final DeleteCommand cmd) {
    String snap_full_name = "";
    try {
        SnapshotObjectTO snapshotTO = (SnapshotObjectTO) cmd.getData();
        PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) snapshotTO.getDataStore();
        VolumeObjectTO volume = snapshotTO.getVolume();
        KVMStoragePool primaryPool = storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid());
        KVMPhysicalDisk disk = storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), volume.getPath());
        String snapshotFullPath = snapshotTO.getPath();
        String snapshotName = snapshotFullPath.substring(snapshotFullPath.lastIndexOf("/") + 1);
        snap_full_name = disk.getName() + "@" + snapshotName;
        if (primaryPool.getType() == StoragePoolType.RBD) {
            Rados r = radosConnect(primaryPool);
            IoCTX io = r.ioCtxCreate(primaryPool.getSourceDir());
            Rbd rbd = new Rbd(io);
            RbdImage image = rbd.open(disk.getName());
            try {
                s_logger.info("Attempting to remove RBD snapshot " + snap_full_name);
                if (image.snapIsProtected(snapshotName)) {
                    s_logger.debug("Unprotecting RBD snapshot " + snap_full_name);
                    image.snapUnprotect(snapshotName);
                }
                image.snapRemove(snapshotName);
                s_logger.info("Snapshot " + snap_full_name + " successfully removed from " + primaryPool.getType().toString() + "  pool.");
            } catch (RbdException e) {
                s_logger.error("Failed to remove snapshot " + snap_full_name + ", with exception: " + e.toString() + ", RBD error: " + ErrorCode.getErrorMessage(e.getReturnValue()));
            } finally {
                rbd.close(image);
                r.ioCtxDestroy(io);
            }
        } else if (primaryPool.getType() == StoragePoolType.NetworkFilesystem || primaryPool.getType() == StoragePoolType.Filesystem) {
            s_logger.info(String.format("Deleting snapshot (id=%s, name=%s, path=%s, storage type=%s) on primary storage", snapshotTO.getId(), snapshotTO.getName(), snapshotTO.getPath(), primaryPool.getType()));
            deleteSnapshotViaManageSnapshotScript(snapshotName, disk);
        } else {
            s_logger.warn("Operation not implemented for storage pool type of " + primaryPool.getType().toString());
            throw new InternalErrorException("Operation not implemented for storage pool type of " + primaryPool.getType().toString());
        }
        return new Answer(cmd, true, "Snapshot " + snap_full_name + " removed successfully.");
    } catch (RadosException e) {
        s_logger.error("Failed to remove snapshot " + snap_full_name + ", with exception: " + e.toString() + ", RBD error: " + ErrorCode.getErrorMessage(e.getReturnValue()));
        return new Answer(cmd, false, "Failed to remove snapshot " + snap_full_name);
    } catch (RbdException e) {
        s_logger.error("Failed to remove snapshot " + snap_full_name + ", with exception: " + e.toString() + ", RBD error: " + ErrorCode.getErrorMessage(e.getReturnValue()));
        return new Answer(cmd, false, "Failed to remove snapshot " + snap_full_name);
    } catch (Exception e) {
        s_logger.error("Failed to remove snapshot " + snap_full_name + ", with exception: " + e.toString());
        return new Answer(cmd, false, "Failed to remove snapshot " + snap_full_name);
    }
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) Rados(com.ceph.rados.Rados) InternalErrorException(com.cloud.exception.InternalErrorException) RadosException(com.ceph.rados.exceptions.RadosException) RbdException(com.ceph.rbd.RbdException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) LibvirtException(org.libvirt.LibvirtException) QemuImgException(org.apache.cloudstack.utils.qemu.QemuImgException) FileNotFoundException(java.io.FileNotFoundException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException) RadosException(com.ceph.rados.exceptions.RadosException) ResignatureAnswer(org.apache.cloudstack.storage.command.ResignatureAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) 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) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) Answer(com.cloud.agent.api.Answer) DirectDownloadAnswer(org.apache.cloudstack.agent.directdownload.DirectDownloadAnswer) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) Rbd(com.ceph.rbd.Rbd) RbdImage(com.ceph.rbd.RbdImage) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) IoCTX(com.ceph.rados.IoCTX) RbdException(com.ceph.rbd.RbdException)

Example 4 with PrimaryDataStoreTO

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

the class KVMStorageProcessor method copyVolumeFromImageCacheToPrimary.

@Override
public Answer copyVolumeFromImageCacheToPrimary(final CopyCommand cmd) {
    final DataTO srcData = cmd.getSrcTO();
    final DataTO destData = cmd.getDestTO();
    final DataStoreTO srcStore = srcData.getDataStore();
    final DataStoreTO destStore = destData.getDataStore();
    final VolumeObjectTO srcVol = (VolumeObjectTO) srcData;
    final ImageFormat srcFormat = srcVol.getFormat();
    final PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) destStore;
    if (!(srcStore instanceof NfsTO)) {
        return new CopyCmdAnswer("can only handle nfs storage");
    }
    final NfsTO nfsStore = (NfsTO) srcStore;
    final String srcVolumePath = srcData.getPath();
    final String secondaryStorageUrl = nfsStore.getUrl();
    KVMStoragePool secondaryStoragePool = null;
    KVMStoragePool primaryPool = null;
    try {
        try {
            primaryPool = storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid());
        } catch (final CloudRuntimeException e) {
            if (e.getMessage().contains("not found")) {
                primaryPool = storagePoolMgr.createStoragePool(primaryStore.getUuid(), primaryStore.getHost(), primaryStore.getPort(), primaryStore.getPath(), null, primaryStore.getPoolType());
            } else {
                return new CopyCmdAnswer(e.getMessage());
            }
        }
        Map<String, String> details = cmd.getOptions2();
        String path = details != null ? details.get(DiskTO.IQN) : null;
        storagePoolMgr.connectPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), path, details);
        final String volumeName = UUID.randomUUID().toString();
        final int index = srcVolumePath.lastIndexOf(File.separator);
        final String volumeDir = srcVolumePath.substring(0, index);
        String srcVolumeName = srcVolumePath.substring(index + 1);
        secondaryStoragePool = storagePoolMgr.getStoragePoolByURI(secondaryStorageUrl + File.separator + volumeDir);
        if (!srcVolumeName.endsWith(".qcow2") && srcFormat == ImageFormat.QCOW2) {
            srcVolumeName = srcVolumeName + ".qcow2";
        }
        final KVMPhysicalDisk volume = secondaryStoragePool.getPhysicalDisk(srcVolumeName);
        volume.setFormat(PhysicalDiskFormat.valueOf(srcFormat.toString()));
        final KVMPhysicalDisk newDisk = storagePoolMgr.copyPhysicalDisk(volume, path != null ? path : volumeName, primaryPool, cmd.getWaitInMillSeconds());
        storagePoolMgr.disconnectPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), path);
        final VolumeObjectTO newVol = new VolumeObjectTO();
        newVol.setFormat(ImageFormat.valueOf(newDisk.getFormat().toString().toUpperCase()));
        newVol.setPath(path != null ? path : volumeName);
        return new CopyCmdAnswer(newVol);
    } catch (final CloudRuntimeException e) {
        s_logger.debug("Failed to copyVolumeFromImageCacheToPrimary: ", e);
        return new CopyCmdAnswer(e.toString());
    } finally {
        if (secondaryStoragePool != null) {
            storagePoolMgr.deleteStoragePool(secondaryStoragePool.getType(), secondaryStoragePool.getUuid());
        }
    }
}
Also used : PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) NfsTO(com.cloud.agent.api.to.NfsTO) ImageFormat(com.cloud.storage.Storage.ImageFormat) DataTO(com.cloud.agent.api.to.DataTO) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Example 5 with PrimaryDataStoreTO

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

the class KVMStorageProcessor method createVolumeFromSnapshot.

@Override
public Answer createVolumeFromSnapshot(final CopyCommand cmd) {
    try {
        final DataTO srcData = cmd.getSrcTO();
        final SnapshotObjectTO snapshot = (SnapshotObjectTO) srcData;
        final DataTO destData = cmd.getDestTO();
        final PrimaryDataStoreTO pool = (PrimaryDataStoreTO) destData.getDataStore();
        final DataStoreTO imageStore = srcData.getDataStore();
        final VolumeObjectTO volume = snapshot.getVolume();
        if (!(imageStore instanceof NfsTO || imageStore instanceof PrimaryDataStoreTO)) {
            return new CopyCmdAnswer("unsupported protocol");
        }
        final String snapshotFullPath = snapshot.getPath();
        final int index = snapshotFullPath.lastIndexOf("/");
        final String snapshotPath = snapshotFullPath.substring(0, index);
        final String snapshotName = snapshotFullPath.substring(index + 1);
        KVMPhysicalDisk disk = null;
        if (imageStore instanceof NfsTO) {
            disk = createVolumeFromSnapshotOnNFS(cmd, pool, imageStore, volume, snapshotPath, snapshotName);
        } else {
            disk = createVolumeFromRBDSnapshot(cmd, destData, pool, imageStore, volume, snapshotName, disk);
        }
        if (disk == null) {
            return new CopyCmdAnswer("Could not create volume from snapshot");
        }
        final VolumeObjectTO newVol = new VolumeObjectTO();
        newVol.setPath(disk.getName());
        newVol.setSize(disk.getVirtualSize());
        newVol.setFormat(ImageFormat.valueOf(disk.getFormat().toString().toUpperCase()));
        return new CopyCmdAnswer(newVol);
    } catch (final CloudRuntimeException e) {
        s_logger.debug("Failed to createVolumeFromSnapshot: ", e);
        return new CopyCmdAnswer(e.toString());
    }
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) DataTO(com.cloud.agent.api.to.DataTO) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) NfsTO(com.cloud.agent.api.to.NfsTO) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Aggregations

PrimaryDataStoreTO (org.apache.cloudstack.storage.to.PrimaryDataStoreTO)47 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)35 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)28 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)28 InternalErrorException (com.cloud.exception.InternalErrorException)24 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)24 NfsTO (com.cloud.agent.api.to.NfsTO)23 DataTO (com.cloud.agent.api.to.DataTO)22 TemplateObjectTO (org.apache.cloudstack.storage.to.TemplateObjectTO)15 SnapshotObjectTO (org.apache.cloudstack.storage.to.SnapshotObjectTO)13 IOException (java.io.IOException)12 LibvirtException (org.libvirt.LibvirtException)12 Connection (com.xensource.xenapi.Connection)11 SR (com.xensource.xenapi.SR)11 XenAPIException (com.xensource.xenapi.Types.XenAPIException)11 XmlRpcException (org.apache.xmlrpc.XmlRpcException)11 RadosException (com.ceph.rados.exceptions.RadosException)10 RbdException (com.ceph.rbd.RbdException)10 URI (java.net.URI)10 ConfigurationException (javax.naming.ConfigurationException)10