Search in sources :

Example 1 with OriginType

use of org.ovirt.engine.core.common.businessentities.OriginType in project ovirt-engine by oVirt.

the class VmListModel method initImportModelForVmsToImportNamesOnly.

private void initImportModelForVmsToImportNamesOnly(final ImportVmsModel importVmsModel, final ImportVmModel importVmModel) {
    final UIMessages messages = ConstantsManager.getInstance().getMessages();
    final UIConstants constants = ConstantsManager.getInstance().getConstants();
    final List<String> vmsToImport = new ArrayList<>();
    OriginType originType = convertImportSourceToOriginType(importVmsModel.getImportSources().getSelectedItem());
    final List<VM> externalVms = importVmsModel.getVmsToImport();
    for (VM vm : externalVms) {
        vmsToImport.add(vm.getName());
    }
    importVmsModel.clearProblem();
    importVmsModel.startProgress();
    importVmModel.setMessage("");
    AsyncQuery query = new AsyncQuery(returnValue -> {
        if (returnValue instanceof QueryReturnValue) {
            importVmsModel.setError(messages.providerFailure());
            importVmsModel.stopProgress();
        } else {
            List<VM> remoteVms = (List<VM>) returnValue;
            List<VM> remoteDownVms = new ArrayList<>();
            List<VM> nonRetrievedVms = new ArrayList<>();
            // find vms with status=down
            for (VM vm : remoteVms) {
                if (vm.isDown()) {
                    remoteDownVms.add(vm);
                }
            }
            // i.e. they were retrieved with their names only but not with their full info
            if (remoteVms.size() != externalVms.size()) {
                for (VM vm : externalVms) {
                    if (!remoteVms.contains(vm)) {
                        nonRetrievedVms.add(vm);
                    }
                }
            }
            importVmsModel.stopProgress();
            // prepare error message to be displayed in one of the models
            String messageForImportVm = null;
            String messageForImportVms = null;
            if (remoteVms.size() != remoteDownVms.size()) {
                if (!nonRetrievedVms.isEmpty()) {
                    messageForImportVm = constants.nonRetrievedAndRunningVmsWereFilteredOnImportVm();
                    messageForImportVms = constants.nonRetrievedAndRunningVmsWereAllFilteredOnImportVm();
                } else {
                    messageForImportVm = constants.runningVmsWereFilteredOnImportVm();
                    messageForImportVms = constants.runningVmsWereAllFilteredOnImportVm();
                }
            } else if (!nonRetrievedVms.isEmpty()) {
                messageForImportVm = constants.nonRetrievedVmsWereFilteredOnImportVm();
                messageForImportVms = constants.nonRetrievedVmsWereAllFilteredOnImportVm();
            }
            if (remoteDownVms.isEmpty() && messageForImportVms != null) {
                importVmsModel.setError(messageForImportVms);
            }
            if (!importVmsModel.validateArchitectures(remoteDownVms)) {
                return;
            }
            // init and display next dialog - the importVmsModel model
            importVmModel.init(remoteDownVms, importVmsModel.getDataCenters().getSelectedItem().getId());
            setWindow(null);
            setWindow(importVmModel);
            if (messageForImportVm != null) {
                importVmModel.setMessage(messageForImportVm);
            }
        }
    });
    if (!(importVmModel instanceof ImportVmFromExternalSourceModel)) {
        importVmsModel.setError(messages.providerImportFailure());
        importVmsModel.stopProgress();
        return;
    }
    ImportVmFromExternalSourceModel importVmsFromExternalSource = (ImportVmFromExternalSourceModel) importVmModel;
    query.setHandleFailure(true);
    AsyncDataProvider.getInstance().getVmsFromExternalServer(query, importVmsModel.getDataCenters().getSelectedItem().getId(), importVmsFromExternalSource.getProxyHostId(), importVmsFromExternalSource.getUrl(), importVmsFromExternalSource.getUsername(), importVmsFromExternalSource.getPassword(), originType, vmsToImport);
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) OriginType(org.ovirt.engine.core.common.businessentities.OriginType) UIMessages(org.ovirt.engine.ui.uicompat.UIMessages) VM(org.ovirt.engine.core.common.businessentities.VM) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) UIConstants(org.ovirt.engine.ui.uicompat.UIConstants)

Example 2 with OriginType

use of org.ovirt.engine.core.common.businessentities.OriginType in project ovirt-engine by oVirt.

the class OvfTemplateWriter method writeGeneralData.

@Override
protected void writeGeneralData() {
    super.writeGeneralData();
    _writer.writeElement(TEMPLATE_ID, vmTemplate.getId().toString());
    OriginType originType = vmTemplate.getOrigin();
    _writer.writeElement(ORIGIN, originType == null ? "" : String.valueOf(originType.getValue()));
    _writer.writeElement(TEMPLATE_DEFAULT_DISPLAY_TYPE, String.valueOf(vmTemplate.getDefaultDisplayType().getValue()));
    _writer.writeElement(IS_DISABLED, String.valueOf(vmTemplate.isDisabled()));
    _writer.writeElement(TRUSTED_SERVICE, String.valueOf(vmTemplate.isTrustedService()));
    _writer.writeElement(TEMPLATE_TYPE, vmTemplate.getTemplateType().name());
    _writer.writeElement(BASE_TEMPLATE_ID, vmTemplate.getBaseTemplateId().toString());
    _writer.writeElement(TEMPLATE_VERSION_NUMBER, String.valueOf(vmTemplate.getTemplateVersionNumber()));
    _writer.writeElement(TEMPLATE_VERSION_NAME, vmTemplate.getTemplateVersionName());
}
Also used : OriginType(org.ovirt.engine.core.common.businessentities.OriginType)

Example 3 with OriginType

use of org.ovirt.engine.core.common.businessentities.OriginType in project ovirt-engine by oVirt.

the class VmBaseMapperTest method testMapOriginTypeRhev.

@Test
public void testMapOriginTypeRhev() {
    String s = VmBaseMapper.map(OriginType.RHEV, null);
    assertEquals("rhev", s);
    OriginType s2 = VmMapper.map(s, OriginType.RHEV);
    assertEquals(OriginType.RHEV, s2);
}
Also used : OriginType(org.ovirt.engine.core.common.businessentities.OriginType) Test(org.junit.Test)

Example 4 with OriginType

use of org.ovirt.engine.core.common.businessentities.OriginType in project ovirt-engine by oVirt.

the class VmDaoTest method testGetVmsByOrigins.

@Test
public void testGetVmsByOrigins() {
    Guid heVmId = Guid.newGuid();
    List<OriginType> list1 = Arrays.asList(OriginType.HOSTED_ENGINE, OriginType.MANAGED_HOSTED_ENGINE);
    List<OriginType> list2 = Collections.singletonList(OriginType.HOSTED_ENGINE);
    List<OriginType> list3 = Collections.singletonList(OriginType.MANAGED_HOSTED_ENGINE);
    int count1 = dao.getVmsByOrigins(list1).size();
    int count2 = dao.getVmsByOrigins(list2).size();
    int count3 = dao.getVmsByOrigins(list3).size();
    createHostedEngineVm(heVmId);
    assertEquals(count1 + 1, dao.getVmsByOrigins(list1).size());
    assertEquals(count2 + 1, dao.getVmsByOrigins(list2).size());
    assertEquals(count3, dao.getVmsByOrigins(list3).size());
    dao.remove(heVmId);
}
Also used : OriginType(org.ovirt.engine.core.common.businessentities.OriginType) Guid(org.ovirt.engine.core.compat.Guid) Test(org.junit.Test)

Example 5 with OriginType

use of org.ovirt.engine.core.common.businessentities.OriginType in project ovirt-engine by oVirt.

the class VmBaseMapper method mapVmBaseModelToEntity.

/**
 * Common for VM and template
 */
protected static void mapVmBaseModelToEntity(org.ovirt.engine.core.common.businessentities.VmBase entity, VmBase model) {
    mapCommonModelToEntity(entity, model);
    if (model.isSetId()) {
        entity.setId(GuidUtils.asGuid(model.getId()));
    }
    if (model.isSetComment()) {
        entity.setComment(model.getComment());
    }
    if (model.isSetCluster() && model.getCluster().getId() != null) {
        entity.setClusterId(GuidUtils.asGuid(model.getCluster().getId()));
    }
    if (model.isSetOs()) {
        if (model.getOs().isSetType()) {
            entity.setOsId(VmMapper.mapOsType(model.getOs().getType()));
        }
        if (model.getOs().isSetKernel()) {
            entity.setKernelUrl(model.getOs().getKernel());
        }
        if (model.getOs().isSetInitrd()) {
            entity.setInitrdUrl(model.getOs().getInitrd());
        }
        if (model.getOs().isSetCmdline()) {
            entity.setKernelParams(model.getOs().getCmdline());
        }
    }
    if (model.isSetBios()) {
        if (model.getBios().isSetBootMenu()) {
            entity.setBootMenuEnabled(model.getBios().getBootMenu().isEnabled());
        }
    }
    if (model.isSetCpuShares()) {
        entity.setCpuShares(model.getCpuShares());
    }
    if (model.isSetDisplay()) {
        if (model.getDisplay().isSetAllowOverride()) {
            entity.setAllowConsoleReconnect(model.getDisplay().isAllowOverride());
        }
        if (model.getDisplay().isSetKeyboardLayout()) {
            String layout = model.getDisplay().getKeyboardLayout();
            if (layout.isEmpty()) {
                // uniquely represent unset keyboard layout as null
                layout = null;
            }
            entity.setVncKeyboardLayout(layout);
        }
        if (model.getDisplay().isSetFileTransferEnabled()) {
            entity.setSpiceFileTransferEnabled(model.getDisplay().isFileTransferEnabled());
        }
        if (model.getDisplay().isSetCopyPasteEnabled()) {
            entity.setSpiceCopyPasteEnabled(model.getDisplay().isCopyPasteEnabled());
        }
        if (model.getDisplay().isSetDisconnectAction()) {
            DisplayDisconnectAction action = DisplayDisconnectAction.fromValue(model.getDisplay().getDisconnectAction());
            entity.setConsoleDisconnectAction(map(action, null));
        }
    }
    if (model.isSetTimeZone()) {
        if (model.getTimeZone().isSetName()) {
            String timezone = model.getTimeZone().getName();
            if (timezone.isEmpty()) {
                // normalize default timezone representation
                timezone = null;
            }
            entity.setTimeZone(timezone);
        }
    }
    if (model.isSetOrigin()) {
        entity.setOrigin(VmMapper.map(model.getOrigin(), (OriginType) null));
    }
    if (model.isSetStateless()) {
        entity.setStateless(model.isStateless());
    }
    if (model.isSetDeleteProtected()) {
        entity.setDeleteProtected(model.isDeleteProtected());
    }
    if (model.isSetSso() && model.getSso().isSetMethods()) {
        entity.setSsoMethod(SsoMapper.map(model.getSso(), null));
    }
    if (model.isSetType()) {
        entity.setVmType(mapVmType(model.getType()));
    }
    if (model.isSetStorageErrorResumeBehaviour()) {
        entity.setResumeBehavior(mapResumeBehavior(model.getStorageErrorResumeBehaviour()));
    }
    if (model.isSetTunnelMigration()) {
        entity.setTunnelMigration(model.isTunnelMigration());
    }
    if (model.isSetSerialNumber()) {
        SerialNumberMapper.copySerialNumber(model.getSerialNumber(), entity);
    }
    if (model.isSetStartPaused()) {
        entity.setRunAndPause(model.isStartPaused());
    }
    if (model.isSetCpuProfile() && model.getCpuProfile().isSetId()) {
        entity.setCpuProfileId(GuidUtils.asGuid(model.getCpuProfile().getId()));
    }
    if (model.isSetCustomProperties()) {
        entity.setCustomProperties(CustomPropertiesParser.parse(model.getCustomProperties().getCustomProperties()));
    }
    if (model.isSetLargeIcon() && model.getLargeIcon().isSetId()) {
        entity.setLargeIconId(GuidUtils.asGuid(model.getLargeIcon().getId()));
    }
    if (model.isSetSmallIcon() && model.getSmallIcon().isSetId()) {
        entity.setSmallIconId(GuidUtils.asGuid(model.getSmallIcon().getId()));
    }
    if (model.isSetQuota() && model.getQuota().isSetId()) {
        entity.setQuotaId(GuidUtils.asGuid(model.getQuota().getId()));
    }
    if (model.isSetLease()) {
        entity.setLeaseStorageDomainId(StorageDomainLeaseMapper.map(model.getLease()));
    }
}
Also used : OriginType(org.ovirt.engine.core.common.businessentities.OriginType) DisplayDisconnectAction(org.ovirt.engine.api.model.DisplayDisconnectAction)

Aggregations

OriginType (org.ovirt.engine.core.common.businessentities.OriginType)6 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)1 List (java.util.List)1 DisplayDisconnectAction (org.ovirt.engine.api.model.DisplayDisconnectAction)1 VM (org.ovirt.engine.core.common.businessentities.VM)1 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)1 Guid (org.ovirt.engine.core.compat.Guid)1 UIConstants (org.ovirt.engine.ui.uicompat.UIConstants)1 UIMessages (org.ovirt.engine.ui.uicompat.UIMessages)1