use of org.ovirt.engine.ui.uicommonweb.models.templates.TemplateWithVersion in project ovirt-engine by oVirt.
the class BaseVmListModelTest method setUpUnitVmModelExpectations.
protected void setUpUnitVmModelExpectations(UnitVmModel model) {
when(model.getVmType().getSelectedItem()).thenReturn(VM_TYPE);
VmTemplate template = new VmTemplate();
template.setId(TEMPLATE_GUID);
TemplateWithVersion templateWithVersion = mock(TemplateWithVersion.class);
when(templateWithVersion.getTemplateVersion()).thenReturn(template);
when(model.getTemplateWithVersion().getSelectedItem()).thenReturn(templateWithVersion);
when(model.getName().getEntity()).thenReturn(VM_NAME);
InstanceType instanceType = new VmTemplate();
instanceType.setId(INSTANCE_TYPE_ID);
when(model.getInstanceTypes().getSelectedItem()).thenReturn(instanceType);
when(model.getOSType().getSelectedItem()).thenReturn(OS_TYPE);
when(model.getNumOfMonitors().getSelectedItem()).thenReturn(NUM_OF_MONITORS);
when(model.getDescription().getEntity()).thenReturn(DESCRIPTION);
when(model.getComment().getEntity()).thenReturn(COMMENT);
when(model.getEmulatedMachine().getSelectedItem()).thenReturn(EMULATED_MACHINE);
when(model.getCustomCpu().getSelectedItem()).thenReturn(CUSTOM_CPU_NAME);
when(model.getMemSize().getEntity()).thenReturn(MEM_SIZE);
when(model.getMaxMemorySize().getEntity()).thenReturn(MAX_MEMORY_SIZE);
when(model.getMinAllocatedMemory().getEntity()).thenReturn(MIN_MEM);
when(model.getSelectedCluster().getId()).thenReturn(CLUSTER_ID);
ListModel<TimeZoneModel> timeZoneModelListModel = mockTimeZoneListModel();
when(model.getTimeZone()).thenReturn(timeZoneModelListModel);
when(model.getNumOfSockets().getSelectedItem()).thenReturn(NUM_OF_SOCKETS);
when(model.getCoresPerSocket().getSelectedItem()).thenReturn(CORES_PER_SOCKET);
when(model.getThreadsPerCore().getSelectedItem()).thenReturn(THREADS_PER_CORE);
SerialNumberPolicyModel serialNumberPolicyModel = mockSerialNumberPolicyModel();
when(model.getSerialNumberPolicy()).thenReturn(serialNumberPolicyModel);
when(model.getAllowConsoleReconnect().getEntity()).thenReturn(true);
when(model.getIsSingleQxlEnabled().getEntity()).thenReturn(true);
when(model.getTotalCPUCores().getEntity()).thenReturn(Integer.toString(TOTAL_CPU));
when(model.getUsbPolicy().getSelectedItem()).thenReturn(USB_POLICY);
when(model.getIsStateless().getEntity()).thenReturn(true);
when(model.getIsSmartcardEnabled().getEntity()).thenReturn(true);
when(model.getIsDeleteProtected().getEntity()).thenReturn(true);
when(model.extractSelectedSsoMethod()).thenReturn(SSO_METHOD);
when(model.getBootSequence()).thenReturn(BOOT_SEQUENCE);
ListModel<RepoImage> cdListModel = mockCdListModel();
when(model.getCdImage()).thenReturn(cdListModel);
when(model.getIsHighlyAvailable().getEntity()).thenReturn(true);
when(model.getInitrd_path().getEntity()).thenReturn(INITRD_PATH);
when(model.getKernel_path().getEntity()).thenReturn(KERNEL_PATH);
when(model.getKernel_parameters().getEntity()).thenReturn(KERNEL_PARAMS);
when(model.getCustomPropertySheet().serialize()).thenReturn(CUSTOM_PROPERTIES);
ListModel<Quota> quotaListModel = mockQuotaListModel();
when(model.getQuota()).thenReturn(quotaListModel);
when(model.getVncKeyboardLayout().getSelectedItem()).thenReturn(VNC_KEYBOARD_LAYOUT);
when(model.getDisplayType().getSelectedItem()).thenReturn(DISPLAY_TYPE);
EntityModel<Integer> priorityEntityModel = mockEntityModel(PRIORITY);
when(model.getPriority().getSelectedItem()).thenReturn(priorityEntityModel);
when(model.getIsRunAndPause().getEntity()).thenReturn(true);
VDS defaultHost = new VDS();
defaultHost.setId(HOST_ID);
when(model.getDefaultHost().getSelectedItem()).thenReturn(defaultHost);
when(model.getDefaultHost().getSelectedItems()).thenReturn(Collections.singletonList(defaultHost));
when(model.getIsAutoAssign().getEntity()).thenReturn(false);
when(model.getMigrationMode().getSelectedItem()).thenReturn(MIGRATION_SUPPORT);
when(model.getSelectedMigrationDowntime()).thenReturn(MIGRATION_DOWNTIME);
when(model.getBootMenuEnabled().getEntity()).thenReturn(true);
when(model.getSpiceFileTransferEnabled().getEntity()).thenReturn(true);
when(model.getSpiceCopyPasteEnabled().getEntity()).thenReturn(true);
ListModel<CpuProfile> cpuProfiles = mockCpuProfiles();
when(model.getCpuProfiles()).thenReturn(cpuProfiles);
when(model.getNumaNodeCount().getEntity()).thenReturn(0);
when(model.getNumaTuneMode().getSelectedItem()).thenReturn(NumaTuneMode.INTERLEAVE);
when(model.getAutoConverge().getSelectedItem()).thenReturn(true);
when(model.getMigrateCompressed().getSelectedItem()).thenReturn(true);
when(model.getIcon().getEntity()).thenReturn(new IconWithOsDefault(LARGE_ICON_DATA, LARGE_OS_DEFAULT_ICON_DATA, SMALL_ICON_ID, ValidationResult.ok()));
when(model.getIoThreadsEnabled().getEntity()).thenReturn(true);
when(model.getConsoleDisconnectAction().getSelectedItem()).thenReturn(ConsoleDisconnectAction.REBOOT);
when(model.getCustomCompatibilityVersion().getSelectedItem()).thenReturn(Version.v3_6);
when(model.getOverrideMigrationPolicy().getEntity()).thenReturn(false);
when(model.getLease().getSelectedItem()).thenReturn(null);
}
use of org.ovirt.engine.ui.uicommonweb.models.templates.TemplateWithVersion in project ovirt-engine by oVirt.
the class VmModelBehaviorBase method initStorageDomains.
public void initStorageDomains() {
if (getModel().getDisks() == null) {
return;
}
TemplateWithVersion templateWithVersion = getModel().getTemplateWithVersion().getSelectedItem();
if (templateWithVersion != null && !templateWithVersion.getTemplateVersion().getId().equals(Guid.Empty)) {
postInitStorageDomains();
} else {
getModel().getStorageDomain().setItems(new ArrayList<>());
getModel().getStorageDomain().setSelectedItem(null);
getModel().getStorageDomain().setIsChangeable(false);
}
}
use of org.ovirt.engine.ui.uicommonweb.models.templates.TemplateWithVersion in project ovirt-engine by oVirt.
the class VmModelBehaviorBase method initTemplateWithVersion.
/**
* @param templates empty list is allowed
* @param previousTemplateId template ID to select, if null -> autodetect based on the model (ignored if latest is set)
* @param useLatest if true, explicitly selects the latest template
* @param addLatest if add to all templates also the "latest" or not
*/
protected void initTemplateWithVersion(List<VmTemplate> templates, Guid previousTemplateId, boolean useLatest, boolean addLatest) {
List<TemplateWithVersion> templatesWithVersion = createTemplateWithVersionsAddLatest(templates, addLatest);
if (previousTemplateId == null && !useLatest) {
TemplateWithVersion previouslySelectedTemplate = getModel().getTemplateWithVersion().getSelectedItem();
if (previouslySelectedTemplate != null && previouslySelectedTemplate.getTemplateVersion() != null) {
previousTemplateId = previouslySelectedTemplate.getTemplateVersion().getId();
useLatest = previouslySelectedTemplate.getTemplateVersion() instanceof LatestVmTemplate;
}
}
TemplateWithVersion templateToSelect = computeTemplateWithVersionToSelect(templatesWithVersion, previousTemplateId, useLatest, addLatest);
getModel().getTemplateWithVersion().setItems(templatesWithVersion, templateToSelect);
}
use of org.ovirt.engine.ui.uicommonweb.models.templates.TemplateWithVersion in project ovirt-engine by oVirt.
the class VmModelBehaviorBase method setupTemplateWithVersion.
protected void setupTemplateWithVersion(final Guid templateId, final boolean useLatest, final boolean isVersionChangeable) {
AsyncDataProvider.getInstance().getTemplateById(new AsyncQuery<>(rawTemplate -> {
if (isVersionChangeable) {
// only used by pools therefore query is limited to admin-portal permissions.
AsyncDataProvider.getInstance().getVmTemplatesByBaseTemplateId(new AsyncQuery<>(templatesChain -> initTemplateWithVersion(templatesChain, templateId, useLatest)), rawTemplate.getBaseTemplateId());
} else {
final VmTemplate template = useLatest ? new LatestVmTemplate(rawTemplate) : rawTemplate;
if (template.isBaseTemplate()) {
TemplateWithVersion templateCouple = new TemplateWithVersion(template, template);
setReadOnlyTemplateWithVersion(templateCouple);
} else {
AsyncDataProvider.getInstance().getTemplateById(new AsyncQuery<>(baseTemplate -> {
TemplateWithVersion templateCouple = new TemplateWithVersion(baseTemplate, template);
setReadOnlyTemplateWithVersion(templateCouple);
}), template.getBaseTemplateId());
}
}
}), templateId);
}
use of org.ovirt.engine.ui.uicommonweb.models.templates.TemplateWithVersion in project ovirt-engine by oVirt.
the class VmModelBehaviorBase method createTemplateWithVersionsAddLatest.
/**
* @param templates raw templates from backend, latest not included
* @return model ready for 'Template' comobox, including latest
*/
private static List<TemplateWithVersion> createTemplateWithVersionsAddLatest(List<VmTemplate> templates, boolean addLatest) {
final Map<Guid, VmTemplate> baseIdToBaseTemplateMap = new HashMap<>();
final Map<Guid, VmTemplate> baseIdToLastVersionMap = new HashMap<>();
for (VmTemplate template : templates) {
if (template.isBaseTemplate()) {
baseIdToBaseTemplateMap.put(template.getId(), template);
baseIdToLastVersionMap.put(template.getId(), template);
}
}
final List<TemplateWithVersion> result = new ArrayList<>();
for (VmTemplate template : templates) {
// update last version map
if (baseIdToLastVersionMap.get(template.getBaseTemplateId()).getTemplateVersionNumber() < template.getTemplateVersionNumber()) {
baseIdToLastVersionMap.put(template.getBaseTemplateId(), template);
}
final VmTemplate baseTemplate = baseIdToBaseTemplateMap.get(template.getBaseTemplateId());
result.add(new TemplateWithVersion(baseTemplate, template));
}
// add latest
if (addLatest) {
for (Map.Entry<Guid, VmTemplate> pair : baseIdToLastVersionMap.entrySet()) {
VmTemplate baseTemplate = baseIdToBaseTemplateMap.get(pair.getKey());
VmTemplate latestTemplate = new LatestVmTemplate(pair.getValue());
result.add(new TemplateWithVersion(baseTemplate, latestTemplate));
}
}
Collections.sort(result);
return result;
}
Aggregations