Search in sources :

Example 1 with StoragePoolDomainAndGroupIdBaseVDSCommandParameters

use of org.ovirt.engine.core.common.vdscommands.StoragePoolDomainAndGroupIdBaseVDSCommandParameters in project ovirt-engine by oVirt.

the class ImportVmCommand method getMemoryDiskImageId.

private Guid getMemoryDiskImageId(Guid imageGroupId) {
    if (!memoryDiskImageMap.containsKey(imageGroupId)) {
        StoragePoolDomainAndGroupIdBaseVDSCommandParameters getVolumesParameters = new StoragePoolDomainAndGroupIdBaseVDSCommandParameters(getParameters().getStoragePoolId(), getParameters().getSourceDomainId(), imageGroupId);
        List<Guid> volumesList = (List<Guid>) runVdsCommand(VDSCommandType.GetVolumesList, getVolumesParameters).getReturnValue();
        // Memory disks have exactly one volume
        memoryDiskImageMap.put(imageGroupId, volumesList.get(0));
    }
    return memoryDiskImageMap.get(imageGroupId);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) StoragePoolDomainAndGroupIdBaseVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.StoragePoolDomainAndGroupIdBaseVDSCommandParameters) Guid(org.ovirt.engine.core.compat.Guid)

Example 2 with StoragePoolDomainAndGroupIdBaseVDSCommandParameters

use of org.ovirt.engine.core.common.vdscommands.StoragePoolDomainAndGroupIdBaseVDSCommandParameters in project ovirt-engine by oVirt.

the class GetUnregisteredDiskQuery method executeQueryCommand.

@Override
protected void executeQueryCommand() {
    Guid storagePoolId = getParameters().getStoragePoolId();
    Guid storageDomainId = getParameters().getStorageDomainId();
    Guid diskId = getParameters().getDiskId();
    StorageDomain storageDomain = storageDomainDao.get(storageDomainId);
    if (storageDomain == null) {
        getQueryReturnValue().setExceptionString(EngineMessage.STORAGE_DOMAIN_DOES_NOT_EXIST.toString());
        getQueryReturnValue().setSucceeded(false);
        return;
    }
    if (storageDomain.getStorageType().isCinderDomain()) {
        QueryReturnValue returnValue = runInternalQuery(QueryType.GetUnregisteredCinderDiskByIdAndStorageDomainId, new GetCinderEntityByStorageDomainIdParameters(diskId, getParameters().getStorageDomainId()));
        setReturnValue(returnValue.getReturnValue());
        return;
    }
    // Now get the list of volumes for each new image.
    StoragePoolDomainAndGroupIdBaseVDSCommandParameters getVolumesParameters = new StoragePoolDomainAndGroupIdBaseVDSCommandParameters(storagePoolId, storageDomainId, diskId);
    VDSReturnValue volumesListReturn = runVdsCommand(VDSCommandType.GetVolumesList, getVolumesParameters);
    if (!volumesListReturn.getSucceeded()) {
        getQueryReturnValue().setExceptionString(volumesListReturn.getExceptionString());
        getQueryReturnValue().setSucceeded(false);
        return;
    }
    @SuppressWarnings("unchecked") List<Guid> volumesList = (List<Guid>) volumesListReturn.getReturnValue();
    // image. If there are multiple volumes, skip the image and move on to the next.
    if (volumesList.size() != 1) {
        getQueryReturnValue().setSucceeded(false);
        return;
    }
    Guid volumeId = volumesList.get(0);
    // Get the information about the volume from VDSM.
    GetImageInfoVDSCommandParameters imageInfoParameters = new GetImageInfoVDSCommandParameters(storagePoolId, storageDomainId, diskId, volumeId);
    VDSReturnValue imageInfoReturn = runVdsCommand(VDSCommandType.GetImageInfo, imageInfoParameters);
    if (!imageInfoReturn.getSucceeded()) {
        getQueryReturnValue().setExceptionString(imageInfoReturn.getExceptionString());
        getQueryReturnValue().setSucceeded(false);
        return;
    }
    DiskImage newDiskImage = (DiskImage) imageInfoReturn.getReturnValue();
    if (!fetchQcowCompat(storagePoolId, storageDomainId, diskId, volumeId, newDiskImage)) {
        getQueryReturnValue().setSucceeded(false);
        return;
    }
    if (StringUtils.isNotEmpty(newDiskImage.getDescription())) {
        try {
            metadataDiskDescriptionHandler.enrichDiskByJsonDescription(newDiskImage.getDescription(), newDiskImage);
        } catch (IOException | DecoderException e) {
            log.warn("Could not parse the description ({}) of disk ID '{}'. The description is expected to be in " + "JSON format.", newDiskImage.getDescription(), newDiskImage.getId());
            log.debug("Exception while parsing JSON for disk", e);
        }
    }
    newDiskImage.setStoragePoolId(storagePoolId);
    getQueryReturnValue().setReturnValue(newDiskImage);
    getQueryReturnValue().setSucceeded(true);
}
Also used : GetImageInfoVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.GetImageInfoVDSCommandParameters) Guid(org.ovirt.engine.core.compat.Guid) StoragePoolDomainAndGroupIdBaseVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.StoragePoolDomainAndGroupIdBaseVDSCommandParameters) IOException(java.io.IOException) GetCinderEntityByStorageDomainIdParameters(org.ovirt.engine.core.common.action.GetCinderEntityByStorageDomainIdParameters) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) DecoderException(org.apache.commons.codec.DecoderException) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) List(java.util.List) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Aggregations

List (java.util.List)2 StoragePoolDomainAndGroupIdBaseVDSCommandParameters (org.ovirt.engine.core.common.vdscommands.StoragePoolDomainAndGroupIdBaseVDSCommandParameters)2 Guid (org.ovirt.engine.core.compat.Guid)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 DecoderException (org.apache.commons.codec.DecoderException)1 GetCinderEntityByStorageDomainIdParameters (org.ovirt.engine.core.common.action.GetCinderEntityByStorageDomainIdParameters)1 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)1 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)1 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)1 GetImageInfoVDSCommandParameters (org.ovirt.engine.core.common.vdscommands.GetImageInfoVDSCommandParameters)1 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)1