Search in sources :

Example 36 with QueryReturnValue

use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.

the class ImportVmTemplateCommand method validate.

@Override
protected boolean validate() {
    if (getVmTemplate() == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
    }
    if (getCluster() == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_CAN_NOT_BE_EMPTY);
    }
    if (!getCluster().getStoragePoolId().equals(getStoragePoolId())) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_IS_NOT_VALID);
    }
    setDescription(getVmTemplateName());
    // check that the storage pool is valid
    if (!validate(createStoragePoolValidator().existsAndUp()) || !validateTemplateArchitecture() || !isClusterCompatible()) {
        return false;
    }
    // set the source domain and check that it is ImportExport type and active
    setSourceDomainId(getParameters().getSourceDomainId());
    StorageDomainValidator sourceDomainValidator = new StorageDomainValidator(getSourceDomain());
    if (!validate(sourceDomainValidator.isDomainExistAndActive())) {
        return false;
    }
    if ((getSourceDomain().getStorageDomainType() != StorageDomainType.ImportExport) && !getParameters().isImagesExistOnTargetStorageDomain()) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_TYPE_ILLEGAL);
    }
    if (!getParameters().isImagesExistOnTargetStorageDomain()) {
        // Set the template images from the Export domain and change each image id storage is to the import domain
        GetAllFromExportDomainQueryParameters tempVar = new GetAllFromExportDomainQueryParameters(getParameters().getStoragePoolId(), getParameters().getSourceDomainId());
        QueryReturnValue qretVal = runInternalQuery(QueryType.GetTemplatesFromExportDomain, tempVar);
        if (!qretVal.getSucceeded()) {
            return false;
        }
        Map<VmTemplate, List<DiskImage>> templates = qretVal.getReturnValue();
        ArrayList<DiskImage> images = new ArrayList<>();
        for (Map.Entry<VmTemplate, List<DiskImage>> entry : templates.entrySet()) {
            if (entry.getKey().getId().equals(getVmTemplate().getId())) {
                images = new ArrayList<>(entry.getValue());
                getVmTemplate().setInterfaces(entry.getKey().getInterfaces());
                getVmTemplate().setOvfVersion(entry.getKey().getOvfVersion());
                break;
            }
        }
        getParameters().setImages(images);
        getVmTemplate().setImages(images);
        ensureDomainMap(getImages(), getParameters().getDestDomainId());
        HashMap<Guid, DiskImage> imageMap = new HashMap<>();
        for (DiskImage image : images) {
            if (Guid.Empty.equals(image.getVmSnapshotId())) {
                return failValidation(EngineMessage.ACTION_TYPE_FAILED_CORRUPTED_VM_SNAPSHOT_ID);
            }
            StorageDomain storageDomain = getStorageDomain(imageToDestinationDomainMap.get(image.getId()));
            StorageDomainValidator validator = new StorageDomainValidator(storageDomain);
            if (!validate(validator.isDomainExistAndActive()) || !validate(validator.domainIsValidDestination())) {
                return false;
            }
            StorageDomainStatic targetDomain = storageDomain.getStorageStaticData();
            changeRawToCowIfSparseOnBlockDevice(targetDomain.getStorageType(), image);
            if (!ImagesHandler.checkImageConfiguration(targetDomain, image, getReturnValue().getValidationMessages())) {
                return false;
            }
            image.setStoragePoolId(getParameters().getStoragePoolId());
            image.setStorageIds(new ArrayList<>(Collections.singletonList(storageDomain.getId())));
            imageMap.put(image.getImageId(), image);
        }
        getVmTemplate().setDiskImageMap(imageMap);
    }
    sourceTemplateId = getVmTemplateId();
    if (getParameters().isImportAsNewEntity()) {
        initImportClonedTemplate();
    }
    VmTemplate duplicateTemplate = vmTemplateDao.get(getParameters().getVmTemplate().getId());
    // check that the template does not exists in the target domain
    if (duplicateTemplate != null) {
        return failValidation(EngineMessage.VMT_CANNOT_IMPORT_TEMPLATE_EXISTS, String.format("$TemplateName %1$s", duplicateTemplate.getName()));
    }
    if (getVmTemplate().isBaseTemplate() && isVmTemplateWithSameNameExist()) {
        return failValidation(EngineMessage.VM_CANNOT_IMPORT_TEMPLATE_NAME_EXISTS);
    }
    if (!validateNoDuplicateDiskImages(getImages())) {
        return false;
    }
    if (getImages() != null && !getImages().isEmpty() && !getParameters().isImagesExistOnTargetStorageDomain()) {
        if (!validateSpaceRequirements(getImages())) {
            return false;
        }
    }
    List<VmNetworkInterface> vmNetworkInterfaces = getVmTemplate().getInterfaces();
    vmNicMacsUtils.replaceInvalidEmptyStringMacAddressesWithNull(vmNetworkInterfaces);
    if (!validate(vmNicMacsUtils.validateMacAddress(vmNetworkInterfaces))) {
        return false;
    }
    // if this is a template version, check base template exist
    if (!getVmTemplate().isBaseTemplate()) {
        VmTemplate baseTemplate = vmTemplateDao.get(getVmTemplate().getBaseTemplateId());
        if (baseTemplate == null) {
            return failValidation(EngineMessage.VMT_CANNOT_IMPORT_TEMPLATE_VERSION_MISSING_BASE);
        }
    }
    if (!setAndValidateDiskProfiles()) {
        return false;
    }
    if (!setAndValidateCpuProfile()) {
        return false;
    }
    if (!validate(vmHandler.validateMaxMemorySize(getVmTemplate(), getEffectiveCompatibilityVersion()))) {
        return false;
    }
    List<EngineMessage> msgs = openStackMetadataAdapter.validate(getVmTemplate().getVmInit());
    if (!CollectionUtils.isEmpty(msgs)) {
        return failValidation(msgs);
    }
    return true;
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) HashMap(java.util.HashMap) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) List(java.util.List) ArrayList(java.util.ArrayList) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Map(java.util.Map) HashMap(java.util.HashMap) ImageStorageDomainMap(org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMap) GetAllFromExportDomainQueryParameters(org.ovirt.engine.core.common.queries.GetAllFromExportDomainQueryParameters)

Example 37 with QueryReturnValue

use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.

the class RemoveVmFromImportExportCommand method getVm.

/*
     * get vm from export domain
     */
@Override
public VM getVm() {
    if (exportVm == null) {
        GetAllFromExportDomainQueryParameters tempVar = new GetAllFromExportDomainQueryParameters(getParameters().getStoragePoolId(), getParameters().getStorageDomainId());
        tempVar.setIds(new ArrayList<>(Collections.singletonList(getVmId())));
        QueryReturnValue qretVal = runInternalQuery(QueryType.GetVmsFromExportDomain, tempVar);
        if (qretVal != null && qretVal.getSucceeded()) {
            ArrayList<VM> vms = qretVal.getReturnValue();
            if (!vms.isEmpty()) {
                exportVm = vms.get(0);
                setVm(exportVm);
            }
        }
    }
    return exportVm;
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) VM(org.ovirt.engine.core.common.businessentities.VM) GetAllFromExportDomainQueryParameters(org.ovirt.engine.core.common.queries.GetAllFromExportDomainQueryParameters)

Example 38 with QueryReturnValue

use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.

the class AbstractVmProviderProxy method testConnection.

@Override
public void testConnection() {
    chooseDcForCheckingIfGetNamesFromExternalProviderSupported();
    QueryReturnValue retVal = Backend.getInstance().runInternalQuery(QueryType.GetVmsFromExternalProvider, buildGetVmsFromExternalProviderQueryParameters());
    if (!retVal.getSucceeded()) {
        throw new EngineException(EngineError.PROVIDER_FAILURE, retVal.getExceptionString());
    }
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) EngineException(org.ovirt.engine.core.common.errors.EngineException)

Example 39 with QueryReturnValue

use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.

the class GetUnregisteredBlockStorageDomainsQuery method getDeviceList.

/**
 * Get devices (LUNs) that are visible by the host.
 *
 * @return the list of LUNs.
 */
protected List<LUNs> getDeviceList() {
    List<LUNs> luns = new ArrayList<>();
    QueryReturnValue returnValue = executeGetDeviceList(new GetDeviceListQueryParameters(getParameters().getVdsId(), getParameters().getStorageType(), false, null, false));
    if (returnValue.getSucceeded()) {
        luns.addAll(returnValue.<List<LUNs>>getReturnValue());
    } else {
        throw new RuntimeException(String.format("GetDeviceList execution failed. Exception message: %1$s", returnValue.getExceptionString()));
    }
    return luns;
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) ArrayList(java.util.ArrayList) GetDeviceListQueryParameters(org.ovirt.engine.core.common.queries.GetDeviceListQueryParameters) LUNs(org.ovirt.engine.core.common.businessentities.storage.LUNs)

Example 40 with QueryReturnValue

use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.

the class ConfigureConsoleOptionsQueryTest method mockGetCaCertificate.

void mockGetCaCertificate() {
    QueryReturnValue caCertificateReturnValue = new QueryReturnValue();
    caCertificateReturnValue.setSucceeded(true);
    caCertificateReturnValue.setReturnValue(CA_CERTIFICATE);
    doReturn(caCertificateReturnValue).when(backend).runInternalQuery(eq(QueryType.GetCACertificate), any());
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue)

Aggregations

QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)265 ArrayList (java.util.ArrayList)123 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)97 QueryType (org.ovirt.engine.core.common.queries.QueryType)85 List (java.util.List)74 Guid (org.ovirt.engine.core.compat.Guid)66 Frontend (org.ovirt.engine.ui.frontend.Frontend)64 ConstantsManager (org.ovirt.engine.ui.uicompat.ConstantsManager)54 VM (org.ovirt.engine.core.common.businessentities.VM)49 QueryParametersBase (org.ovirt.engine.core.common.queries.QueryParametersBase)47 HelpTag (org.ovirt.engine.ui.uicommonweb.help.HelpTag)42 HashMap (java.util.HashMap)40 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)39 AsyncDataProvider (org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider)39 Test (org.junit.Test)38 Collection (java.util.Collection)34 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)33 Map (java.util.Map)31 ActionType (org.ovirt.engine.core.common.action.ActionType)31 VDS (org.ovirt.engine.core.common.businessentities.VDS)31