Search in sources :

Example 36 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());
            }
            if (dest.getDiskProvisioningStrictnessFlag() != null) {
                paramsCopy.put(VmwareStorageProcessorConfigurableFields.DISK_PROVISIONING_STRICTNESS, dest.getDiskProvisioningStrictnessFlag().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)

Example 37 with PrimaryDataStoreTO

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

the class DirectDownloadManagerImpl method downloadTemplate.

@Override
public void downloadTemplate(long templateId, long poolId, long hostId) {
    VMTemplateVO template = vmTemplateDao.findById(templateId);
    StoragePoolVO pool = primaryDataStoreDao.findById(poolId);
    HostVO host = hostDao.findById(hostId);
    if (pool == null) {
        throw new CloudRuntimeException("Storage pool " + poolId + " could not be found");
    }
    if (template == null) {
        throw new CloudRuntimeException("Template " + templateId + " could not be found");
    }
    if (host == null) {
        throw new CloudRuntimeException("Host " + hostId + " could not be found");
    }
    if (!template.isDirectDownload()) {
        throw new CloudRuntimeException("Template " + templateId + " is not marked for direct download");
    }
    Map<String, String> details = template.getDetails();
    String url = template.getUrl();
    String checksum = template.getChecksum();
    Map<String, String> headers = getHeadersFromDetails(details);
    DataStore store = dataStoreManager.getDataStore(poolId, DataStoreRole.Primary);
    if (store == null) {
        throw new CloudRuntimeException("Data store " + poolId + " could not be found");
    }
    PrimaryDataStore primaryDataStore = (PrimaryDataStore) store;
    PrimaryDataStoreTO to = (PrimaryDataStoreTO) primaryDataStore.getTO();
    DownloadProtocol protocol = getProtocolFromUrl(url);
    DirectDownloadCommand cmd = getDirectDownloadCommandFromProtocol(protocol, url, templateId, to, checksum, headers);
    cmd.setTemplateSize(template.getSize());
    cmd.setFormat(template.getFormat());
    if (tmplFactory.getTemplate(templateId, store) != null) {
        cmd.setDestData((TemplateObjectTO) tmplFactory.getTemplate(templateId, store).getTO());
    }
    int cmdTimeOut = StorageManager.PRIMARY_STORAGE_DOWNLOAD_WAIT.value();
    cmd.setWait(cmdTimeOut);
    Answer answer = sendDirectDownloadCommand(cmd, template, poolId, host);
    VMTemplateStoragePoolVO sPoolRef = vmTemplatePoolDao.findByPoolTemplate(poolId, templateId, null);
    if (sPoolRef == null) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Not found (templateId:" + templateId + " poolId: " + poolId + ") in template_spool_ref, persisting it");
        }
        DirectDownloadAnswer ans = (DirectDownloadAnswer) answer;
        sPoolRef = new VMTemplateStoragePoolVO(poolId, templateId, null);
        sPoolRef.setDownloadPercent(100);
        sPoolRef.setDownloadState(VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
        sPoolRef.setState(ObjectInDataStoreStateMachine.State.Ready);
        sPoolRef.setTemplateSize(ans.getTemplateSize());
        sPoolRef.setLocalDownloadPath(ans.getInstallPath());
        sPoolRef.setInstallPath(ans.getInstallPath());
        vmTemplatePoolDao.persist(sPoolRef);
    } else {
        // For managed storage, update after template downloaded and copied to the disk
        DirectDownloadAnswer ans = (DirectDownloadAnswer) answer;
        sPoolRef.setDownloadPercent(100);
        sPoolRef.setDownloadState(VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
        sPoolRef.setState(ObjectInDataStoreStateMachine.State.Ready);
        sPoolRef.setTemplateSize(ans.getTemplateSize());
        sPoolRef.setLocalDownloadPath(ans.getInstallPath());
        sPoolRef.setInstallPath(ans.getInstallPath());
        vmTemplatePoolDao.update(sPoolRef.getId(), sPoolRef);
    }
}
Also used : DirectDownloadCommand(org.apache.cloudstack.agent.directdownload.DirectDownloadCommand) HttpDirectDownloadCommand(org.apache.cloudstack.agent.directdownload.HttpDirectDownloadCommand) MetalinkDirectDownloadCommand(org.apache.cloudstack.agent.directdownload.MetalinkDirectDownloadCommand) HttpsDirectDownloadCommand(org.apache.cloudstack.agent.directdownload.HttpsDirectDownloadCommand) NfsDirectDownloadCommand(org.apache.cloudstack.agent.directdownload.NfsDirectDownloadCommand) VMTemplateVO(com.cloud.storage.VMTemplateVO) HostVO(com.cloud.host.HostVO) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) Answer(com.cloud.agent.api.Answer) DirectDownloadAnswer(org.apache.cloudstack.agent.directdownload.DirectDownloadAnswer) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DownloadProtocol(org.apache.cloudstack.agent.directdownload.DirectDownloadCommand.DownloadProtocol) DirectDownloadAnswer(org.apache.cloudstack.agent.directdownload.DirectDownloadAnswer) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)

Example 38 with PrimaryDataStoreTO

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

the class StorageSystemDataMotionStrategy method needCacheStorage.

private boolean needCacheStorage(DataObject srcData, DataObject destData) {
    DataTO srcTO = srcData.getTO();
    DataStoreTO srcStoreTO = srcTO.getDataStore();
    DataTO destTO = destData.getTO();
    DataStoreTO destStoreTO = destTO.getDataStore();
    // both snapshot and volume are on primary datastore - no need for a cache storage as hypervisor will copy directly
    if (srcStoreTO instanceof PrimaryDataStoreTO && destStoreTO instanceof PrimaryDataStoreTO) {
        return false;
    }
    if (srcStoreTO instanceof NfsTO || srcStoreTO.getRole() == DataStoreRole.ImageCache) {
        return false;
    }
    if (destStoreTO instanceof NfsTO || destStoreTO.getRole() == DataStoreRole.ImageCache) {
        return false;
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("needCacheStorage true; dest at " + destTO.getPath() + ", dest role " + destStoreTO.getRole().toString() + "; src at " + srcTO.getPath() + ", src role " + srcStoreTO.getRole().toString());
    }
    return true;
}
Also used : 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) NfsTO(com.cloud.agent.api.to.NfsTO)

Example 39 with PrimaryDataStoreTO

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

the class LibvirtComputingResource method getVolumePath.

public String getVolumePath(final Connect conn, final DiskTO volume, boolean diskOnHostCache) throws LibvirtException, URISyntaxException {
    final DataTO data = volume.getData();
    final DataStoreTO store = data.getDataStore();
    if (volume.getType() == Volume.Type.ISO && data.getPath() != null && (store instanceof NfsTO || store instanceof PrimaryDataStoreTO && data instanceof TemplateObjectTO && !((TemplateObjectTO) data).isDirectDownload())) {
        if (data.getPath().startsWith(ConfigDrive.CONFIGDRIVEDIR) && diskOnHostCache) {
            String configDrivePath = getConfigPath() + "/" + data.getPath();
            return configDrivePath;
        }
        final String isoPath = store.getUrl().split("\\?")[0] + File.separator + data.getPath();
        final int index = isoPath.lastIndexOf("/");
        final String path = isoPath.substring(0, index);
        final String name = isoPath.substring(index + 1);
        final KVMStoragePool secondaryPool = _storagePoolMgr.getStoragePoolByURI(path);
        final KVMPhysicalDisk isoVol = secondaryPool.getPhysicalDisk(name);
        return isoVol.getPath();
    } else {
        return data.getPath();
    }
}
Also used : PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) DataTO(com.cloud.agent.api.to.DataTO) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) KVMPhysicalDisk(com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) NfsTO(com.cloud.agent.api.to.NfsTO)

Example 40 with PrimaryDataStoreTO

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

the class LibvirtCopyVolumeCommandWrapper method handleCopyDataFromVolumeToSecondaryStorageUsingSrcDetails.

private Answer handleCopyDataFromVolumeToSecondaryStorageUsingSrcDetails(CopyVolumeCommand command, LibvirtComputingResource libvirtComputingResource) {
    KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
    PrimaryDataStoreTO srcPrimaryDataStore = null;
    KVMStoragePool secondaryStoragePool = null;
    Map<String, String> srcDetails = command.getSrcDetails();
    String srcPath = srcDetails.get(DiskTO.IQN);
    if (srcPath == null) {
        return new CopyVolumeAnswer(command, false, "No IQN was specified", null, null);
    }
    try {
        LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
        String destVolumeName = libvirtUtilitiesHelper.generateUUIDName() + ".qcow2";
        String destVolumePath = command.getVolumePath() + File.separator;
        String secondaryStorageUrl = command.getSecondaryStorageURL();
        secondaryStoragePool = storagePoolMgr.getStoragePoolByURI(secondaryStorageUrl);
        secondaryStoragePool.createFolder(File.separator + destVolumePath);
        storagePoolMgr.deleteStoragePool(secondaryStoragePool.getType(), secondaryStoragePool.getUuid());
        secondaryStoragePool = storagePoolMgr.getStoragePoolByURI(secondaryStorageUrl + File.separator + destVolumePath);
        VolumeObjectTO srcVolumeObjectTO = (VolumeObjectTO) command.getSrcData();
        srcPrimaryDataStore = (PrimaryDataStoreTO) srcVolumeObjectTO.getDataStore();
        storagePoolMgr.connectPhysicalDisk(srcPrimaryDataStore.getPoolType(), srcPrimaryDataStore.getUuid(), srcPath, srcDetails);
        KVMPhysicalDisk srcPhysicalDisk = storagePoolMgr.getPhysicalDisk(srcPrimaryDataStore.getPoolType(), srcPrimaryDataStore.getUuid(), srcPath);
        storagePoolMgr.copyPhysicalDisk(srcPhysicalDisk, destVolumeName, secondaryStoragePool, command.getWait() * 1000);
        return new CopyVolumeAnswer(command, true, null, null, destVolumePath + destVolumeName);
    } catch (final CloudRuntimeException e) {
        return new CopyVolumeAnswer(command, false, e.toString(), null, null);
    } finally {
        try {
            if (srcPrimaryDataStore != null) {
                storagePoolMgr.disconnectPhysicalDisk(srcPrimaryDataStore.getPoolType(), srcPrimaryDataStore.getUuid(), srcPath);
            }
        } catch (Exception e) {
            LOGGER.warn("Unable to disconnect from the source device.", e);
        }
        if (secondaryStoragePool != null) {
            storagePoolMgr.deleteStoragePool(secondaryStoragePool.getType(), secondaryStoragePool.getUuid());
        }
    }
}
Also used : KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) KVMPhysicalDisk(com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

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