diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java index a30e23669b8..8a6b15c1b80 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java @@ -101,6 +101,7 @@ import org.ovirt.engine.core.common.businessentities.network.Network; import org.ovirt.engine.core.common.businessentities.network.VmInterfaceType; import org.ovirt.engine.core.common.businessentities.network.VmNic; +import org.ovirt.engine.core.common.businessentities.profiles.ProfileBase; import org.ovirt.engine.core.common.businessentities.storage.CinderDisk; import org.ovirt.engine.core.common.businessentities.storage.DiskImage; import org.ovirt.engine.core.common.businessentities.storage.DiskInterface; @@ -192,7 +193,7 @@ public class AddVmCommand extends VmManagementCommand private List poolDomains; private String mdevType; // the value of the deprecated custom property mdev_type, if specified - private Map srcVmNicIdToTargetVmNicIdMapping = new HashMap<>(); + private final Map srcVmNicIdToTargetVmNicIdMapping = new HashMap<>(); @Inject private InClusterUpgradeValidator clusterUpgradeValidator; @@ -1016,7 +1017,7 @@ private DiskImage makeNewImage(Guid storageId, DiskImage image) { .stream() .filter(p -> image.getDiskProfileIds().contains(p.getId())) .findFirst() - .map(p -> p.getId()) + .map(ProfileBase::getId) .orElse(null)); return newImage; @@ -1260,7 +1261,6 @@ protected boolean areParametersLegal() { final VmStatic vmStaticData = getParameters().getVmStaticData(); if (vmStaticData != null) { - if (!isLegalClusterId(vmStaticData.getClusterId())) { return false; } @@ -1440,7 +1440,7 @@ protected void addVmCinderDisks(Collection templateDisks) { params, cloneContext().withoutExecutionContext().withoutLock()); if (!actionReturnValue.getSucceeded()) { - log.error("Error cloning Cinder disk '{}': {}", cinderDisk.getDiskAlias()); + log.error("Error cloning Cinder disk '{}'", cinderDisk.getDiskAlias()); getReturnValue().setFault(actionReturnValue.getFault()); return; } @@ -1464,7 +1464,7 @@ protected void addManagedBlockDisks(Collection templateDisks) { params, cloneContext().withoutExecutionContext().withoutLock()); if (!actionReturnValue.getSucceeded()) { - log.error("Error cloning Managed block disk '{}': {}", managedBlockDisk.getDiskAlias()); + log.error("Error cloning Managed block disk '{}'", managedBlockDisk.getDiskAlias()); getReturnValue().setFault(actionReturnValue.getFault()); return; } @@ -1681,7 +1681,7 @@ private void addVmPermission() { if (!permissionsToAdd.isEmpty()) { List permissionsList = permissionsToAdd.asPermissionList(); multiLevelAdministrationHandler - .addPermission(permissionsList.toArray(new Permission[permissionsList.size()])); + .addPermission(permissionsList.toArray(new Permission[0])); getCompensationContext().snapshotNewEntities(permissionsList); } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolMonitor.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolMonitor.java index 7a5cbc45c38..e605bb6d2bc 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolMonitor.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolMonitor.java @@ -50,11 +50,11 @@ public class VmPoolMonitor implements BackendService { private static final Logger log = LoggerFactory.getLogger(VmPoolMonitor.class); - private ScheduledFuture poolMonitoringJob; + private ScheduledFuture poolMonitoringJob; private long vmPoolMonitorIntervalInMinutes; - private Set startingVms = ConcurrentHashMap.newKeySet(); + private final Set startingVms = ConcurrentHashMap.newKeySet(); @Inject private VmPoolHandler vmPoolHandler; diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/snapshots/CreateSnapshotCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/snapshots/CreateSnapshotCommand.java index 88b8d9f9570..d22d30e6fab 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/snapshots/CreateSnapshotCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/snapshots/CreateSnapshotCommand.java @@ -1,7 +1,6 @@ package org.ovirt.engine.core.bll.snapshots; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.Date; import java.util.List; @@ -34,7 +33,6 @@ import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.dao.DiskImageDao; import org.ovirt.engine.core.dao.ImageDao; -import org.ovirt.engine.core.dao.StorageDomainDao; import org.ovirt.engine.core.dao.VmDao; import org.ovirt.engine.core.utils.transaction.TransactionSupport; @@ -54,8 +52,6 @@ public class CreateSnapshotCommand extends B @Inject private VmDao vmDao; @Inject - private StorageDomainDao storageDomainDao; - @Inject private CommandCoordinatorUtil commandCoordinatorUtil; @Inject private ImagesHandler imagesHandler; @@ -99,7 +95,7 @@ protected boolean performImageVdsmOperation() { Guid.newGuid() : getParameters().getDestinationImageId()); persistCommandIfNeeded(); newDiskImage = cloneDiskImage(getDestinationImageId()); - newDiskImage.setStorageIds(new ArrayList<>(Arrays.asList(getDestinationStorageDomainId()))); + newDiskImage.setStorageIds(new ArrayList<>(Collections.singletonList(getDestinationStorageDomainId()))); getParameters().setStorageDomainId(getDestinationStorageDomainId()); getParameters().setImageId(getDestinationImageId()); getParameters().setImageGroupID(getImageGroupId()); diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/disk/AddDiskCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/disk/AddDiskCommand.java index 5c147babc65..2603826eb83 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/disk/AddDiskCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/disk/AddDiskCommand.java @@ -492,7 +492,7 @@ private ActionParametersBase buildManagedBlockParams() { AddManagedBlockStorageDiskParameters parameters = new AddManagedBlockStorageDiskParameters( getParameters().getDiskInfo(), - getVm() == null ? false: shouldDiskBePlugged()); + getVm() != null && shouldDiskBePlugged()); parameters.setPlugDiskToVm(getParameters().getPlugDiskToVm()); parameters.setStorageDomainId(getParameters().getStorageDomainId()); parameters.setParentParameters(getParameters()); diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/disk/image/ImagesHandler.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/disk/image/ImagesHandler.java index 06c4df93910..230a2162eb4 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/disk/image/ImagesHandler.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/disk/image/ImagesHandler.java @@ -2,7 +2,6 @@ import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Date; @@ -24,7 +23,6 @@ import org.ovirt.engine.core.bll.profiles.DiskProfileHelper; import org.ovirt.engine.core.bll.storage.connection.StorageHelperDirector; import org.ovirt.engine.core.bll.storage.utils.VdsCommandsHelper; -import org.ovirt.engine.core.bll.utils.ClusterUtils; import org.ovirt.engine.core.bll.utils.VmDeviceUtils; import org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator; import org.ovirt.engine.core.common.FeatureSupported; @@ -136,9 +134,6 @@ public class ImagesHandler { @Inject private StorageHelperDirector storageHelperDirector; - @Inject - private ClusterUtils clusterUtils; - @Inject private VdsCommandsHelper vdsCommandsHelper; @@ -290,11 +285,7 @@ public static Map> buildStorageToDiskMap(Collection diskList = storageToDisksMap.get(storageDomainId); - if (diskList == null) { - diskList = new ArrayList<>(); - storageToDisksMap.put(storageDomainId, diskList); - } + List diskList = storageToDisksMap.computeIfAbsent(storageDomainId, k -> new ArrayList<>()); diskList.add(disk); } return storageToDisksMap; @@ -329,7 +320,7 @@ private void addDiskImage(DiskImage image, boolean active, ImageStorageDomainMap * @return map object is the collection is not null */ public static Map getDiskImagesByIdMap(Collection diskImages) { - return diskImages.stream().collect(Collectors.toMap(d -> d.getImageId(), Function.identity())); + return diskImages.stream().collect(Collectors.toMap(DiskImage::getImageId, Function.identity())); } /** @@ -1035,7 +1026,7 @@ public VDSReturnValue teardownImage(Guid storagePoolId, } public Set getVolumeChain(Guid vmId, Guid vdsId, DiskImage activeImage) { - Map[] vms = null; + Map[] vms = null; try { vms = getVms(vdsId, vmId); } catch (EngineException e) { @@ -1047,7 +1038,7 @@ public Set getVolumeChain(Guid vmId, Guid vdsId, DiskImage activeImage) { return null; } - Map vm = vms[0]; + Map vm = vms[0]; if (vm == null || vm.get(VdsProperties.vm_guid) == null) { log.error("Received incomplete VM information"); return null; @@ -1062,7 +1053,7 @@ public Set getVolumeChain(Guid vmId, Guid vdsId, DiskImage activeImage) { Set images = new HashSet<>(); for (Object o : (Object[]) vm.get(VdsProperties.Devices)) { - Map device = (Map) o; + Map device = (Map) o; if (VmDeviceType.DISK.getName().equals(device.get(VdsProperties.Device)) && !device.get(VdsProperties.ImageId).equals("mapper") && activeImage.getId().equals(Guid.createGuidFromString( @@ -1094,8 +1085,8 @@ public boolean isSnapshotUsed(VM vm, DiskImage image) { return true; } - private Map[] getVms(Guid vdsId, Guid vmId) { - return (Map[]) fullListAdapter.getVmFullList( + private Map[] getVms(Guid vdsId, Guid vmId) { + return (Map[]) fullListAdapter.getVmFullList( vdsId, Collections.singletonList(vmId), true) @@ -1115,7 +1106,7 @@ public Map mapChainToNewIDs(Guid sourceImageGroupID, DiskImage newImage = DiskImage.copyOf(diskImage); newImage.setParentId(nextParentId); newImage.setId(newImageGroupID); - newImage.setStorageIds(Arrays.asList(targetStorageDomainID)); + newImage.setStorageIds(Collections.singletonList(targetStorageDomainID)); nextParentId = Guid.newGuid(); newImage.setImageId(nextParentId); newImage.setVmSnapshotId(null); @@ -1139,8 +1130,7 @@ public Guid getHostForMeasurement(Guid storagePoolID, Guid imageGroupID) { } } - return vdsCommandsHelper.getHostForExecution(storagePoolID, - vds -> FeatureSupported.isMeasureVolumeSupported(vds)); + return vdsCommandsHelper.getHostForExecution(storagePoolID, FeatureSupported::isMeasureVolumeSupported); } public Version getSpmCompatibilityVersion(Guid storagePoolId) { diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/utils/ovf/OvfManager.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/utils/ovf/OvfManager.java index 19aa445d713..8424a892342 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/utils/ovf/OvfManager.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/utils/ovf/OvfManager.java @@ -39,7 +39,7 @@ @Singleton public class OvfManager { - private Logger log = LoggerFactory.getLogger(OvfManager.class); + private final Logger log = LoggerFactory.getLogger(OvfManager.class); @Inject private OvfVmIconDefaultsProvider iconDefaultsProvider; diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VM.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VM.java index 1b8fd3760e2..bd04459503a 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VM.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VM.java @@ -79,8 +79,8 @@ public VM(VmStatic vmStatic, VmDynamic vmDynamic, VmStatistics vmStatistics) { this.setStaticData(vmStatic); this.setDynamicData(vmDynamic); this.setStatisticsData(vmStatistics); - this.setvNumaNodeList(new ArrayList()); - this.setDiskMap(new HashMap()); + this.setvNumaNodeList(new ArrayList<>()); + this.setDiskMap(new HashMap<>()); this.setCdPath(""); this.setWgtCdPath(""); this.setFloppyPath(""); @@ -1125,7 +1125,7 @@ public double getDiskSize() { if (diskSize == 0) { for (Disk disk : getDiskMap().values()) { if (DiskStorageType.IMAGE == disk.getDiskStorageType()) { - diskSize += disk.getSize() / Double.valueOf(1024 * 1024 * 1024); + diskSize += disk.getSize() / (double) (1024 * 1024 * 1024); } } } @@ -1284,9 +1284,7 @@ public boolean equals(Object obj) { } VM eq = (VM) ((obj instanceof VM) ? obj : null); if (eq != null) { - if (eq.getId().equals(this.getId())) { - return true; - } + return eq.getId().equals(this.getId()); } return false; } diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/storage/DiskVmElement.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/storage/DiskVmElement.java index 8a8a5220742..d092ca80ffa 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/storage/DiskVmElement.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/storage/DiskVmElement.java @@ -12,6 +12,7 @@ import org.ovirt.engine.core.compat.Guid; public class DiskVmElement implements BusinessEntity { + private static final long serialVersionUID = -8986247555459576804L; /** * The vm device id of the disk vm element, this will be consisted of the disk id along with the vm id */ diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmDeviceCommonUtils.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmDeviceCommonUtils.java index 93b1d8401b6..7a3bde49a95 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmDeviceCommonUtils.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmDeviceCommonUtils.java @@ -2,7 +2,6 @@ import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.LinkedList; @@ -32,14 +31,9 @@ public class VmDeviceCommonUtils { - static final String NETWORK_CHAR = "N"; - static final String CDROM_CHAR = "D"; - static final String DRIVE_CHAR = "C"; - /** Expected unit: MiB */ public static final String SPEC_PARAM_SIZE = "size"; public static final String SPEC_PARAM_NODE = "node"; - public static final String VIDEO_HEADS = "heads"; public static boolean isNetwork(VmDevice device) { return device.getType() == VmDeviceGeneralType.INTERFACE; @@ -87,7 +81,7 @@ public static VmDevice createVirtioSerialDeviceForVm(Guid vmId) { VmDeviceGeneralType.CONTROLLER, VmDeviceType.VIRTIOSERIAL.getName(), "", - new HashMap(), + new HashMap<>(), true, true, false, @@ -210,7 +204,7 @@ private static List sortInterfacesByName(List pluggedInterfa deviceIdToIfaceName.put(iface.getId(), iface.getName()); } - Collections.sort(pluggedInterfaces, Comparator.comparing(d -> deviceIdToIfaceName.get(d.getId().getDeviceId()))); + pluggedInterfaces.sort(Comparator.comparing(d -> deviceIdToIfaceName.get(d.getId().getDeviceId()))); return pluggedInterfaces; } @@ -284,7 +278,7 @@ public static Map extractDiskVmElements(VM vm) { public static boolean isInWhiteList(VmDeviceGeneralType type, String device) { String expr = getDeviceTypeSearchExpr(type, device); String whiteList = Config.getValue(ConfigValues.ManagedDevicesWhiteList); - return whiteList.indexOf(expr) >= 0; + return whiteList.contains(expr); } private static String getDeviceTypeSearchExpr(VmDeviceGeneralType type, String device) { diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/ImageDao.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/ImageDao.java index 6a80b72922d..1486985ae1e 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/ImageDao.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/ImageDao.java @@ -8,11 +8,11 @@ * {@code ImageDao} defines a type for performing CRUD operations on instances of {@link Image}. */ public interface ImageDao extends GenericDao, StatusAwareDao { - public void updateStatusOfImagesByImageGroupId(Guid imageGroupId, ImageStatus status); + void updateStatusOfImagesByImageGroupId(Guid imageGroupId, ImageStatus status); - public void updateImageVmSnapshotId(Guid id, Guid vmSnapshotId); + void updateImageVmSnapshotId(Guid id, Guid vmSnapshotId); - public void updateImageSize(Guid id, long size); + void updateImageSize(Guid id, long size); - public Integer getMaxSequenceNumber(Guid imageGroupId); + Integer getMaxSequenceNumber(Guid imageGroupId); } diff --git a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/builder/vminfo/LibvirtVmXmlBuilder.java b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/builder/vminfo/LibvirtVmXmlBuilder.java index 1566b0fb775..96ad36c8d6b 100644 --- a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/builder/vminfo/LibvirtVmXmlBuilder.java +++ b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/builder/vminfo/LibvirtVmXmlBuilder.java @@ -93,7 +93,7 @@ * Also note that there should not be any call to VDSM from this class. If the generated XML * needs to contain information that the engine does not know about then either this information * should be added to the hosts/VMs monitoring or to GetCapabilities, or to represent the data - * using place-holders that are replaced by VDSM (see {@link #writeLease(XmlTextWriter, VM)}). + * using place-holders that are replaced by VDSM (see {@link #writeLease(String, String, String, String)}). */ public class LibvirtVmXmlBuilder { @@ -250,15 +250,15 @@ private void init(VM vm, VmInfoBuildUtils vmInfoBuildUtils, Guid hostId) { hostNumaNodesSupplier = new MemoizingSupplier<>(() -> vmInfoBuildUtils.getVdsNumaNodes(hostId)); hostVgpuPlacementSupplier = new MemoizingSupplier<>(() -> vmInfoBuildUtils.vgpuPlacement(hostId)); VdsDynamic vds = vmInfoBuildUtils.getVdsDynamic(hostId); - tscFrequencySupplier = new MemoizingSupplier<>(() -> vds.getTscFrequency()); - cpuFlagsSupplier = new MemoizingSupplier<>(() -> vds.getCpuFlags()); - cpuModelSupplier = new MemoizingSupplier<>(() -> vds.getCpuModel()); - incrementalBackupSupplier = new MemoizingSupplier<>(() -> vds.isBackupEnabled()); + tscFrequencySupplier = new MemoizingSupplier<>(vds::getTscFrequency); + cpuFlagsSupplier = new MemoizingSupplier<>(vds::getCpuFlags); + cpuModelSupplier = new MemoizingSupplier<>(vds::getCpuModel); + incrementalBackupSupplier = new MemoizingSupplier<>(vds::isBackupEnabled); kernelFipsModeSupplier = new MemoizingSupplier<>(() -> vmInfoBuildUtils.isKernelFipsMode(vds)); } else { - hostDevicesSupplier = new MemoizingSupplier<>(() -> Collections.emptyMap()); + hostDevicesSupplier = new MemoizingSupplier<>(Collections::emptyMap); hostStatisticsSupplier = new MemoizingSupplier<>(() -> null); - hostNumaNodesSupplier = new MemoizingSupplier<>(() -> Collections.emptyList()); + hostNumaNodesSupplier = new MemoizingSupplier<>(Collections::emptyList); hostVgpuPlacementSupplier = new MemoizingSupplier<>(() -> null); tscFrequencySupplier = new MemoizingSupplier<>(() -> null); cpuFlagsSupplier = new MemoizingSupplier<>(() -> ""); @@ -882,7 +882,7 @@ private void writeFeatures() { private void writeMemoryBacking() { Optional hugepageSizeOpt = HugePageUtils.getHugePageSize(vm.getStaticData()); - if (!hugepageSizeOpt.isPresent()) { + if (hugepageSizeOpt.isEmpty()) { return; } @@ -1007,7 +1007,7 @@ private void writeMDevMetadata() { writer.writeStartElement(OVIRT_VM_URI, "device"); writer.writeAttributeString("devtype", "hostdev"); writer.writeAttributeString("uuid", address); - data.forEach((key, value) -> writer.writeElement(OVIRT_VM_URI, key, value.toString())); + data.forEach((key, value) -> writer.writeElement(OVIRT_VM_URI, key, value)); writer.writeEndElement(); }); } @@ -1036,7 +1036,7 @@ private void writeMinGuaranteedMemoryMetadata() { private void writeClusterVersionMetadata() { writer.writeStartElement(OVIRT_VM_URI, "clusterVersion"); Version version = vm.getCompatibilityVersion(); - writer.writeRaw(String.valueOf(version.getMajor()) + "." + String.valueOf(version.getMinor())); + writer.writeRaw(version.getMajor() + "." + version.getMinor()); writer.writeEndElement(); } @@ -1323,7 +1323,7 @@ private List overrideDevicesForRunOnce(List devices) { } @SafeVarargs - private final void updateBootOrder(List ... bootableDevices) { + private void updateBootOrder(List ... bootableDevices) { List managedAndPluggedBootableDevices = Arrays.stream(bootableDevices) .flatMap(Collection::stream) .filter(VmDevice::isManaged) @@ -1872,7 +1872,6 @@ private void writePciHostDevice(VmHostDevice device, HostDevice hostDevice) { private void writeNvdimmHostDevice(VmHostDevice device, HostDevice hostDevice) { Map specParams = hostDevice.getSpecParams(); - String mode = (String)specParams.get(VdsProperties.MODE); String numaNode = (String)specParams.get(VdsProperties.NUMA_NODE); String targetNode = vmInfoBuildUtils.getMatchingNumaNode(getNumaTuneSetting(), vmNumaNodesSupplier, numaNode); if (targetNode == null) { @@ -1884,7 +1883,7 @@ private void writeNvdimmHostDevice(VmHostDevice device, HostDevice hostDevice) { // If we didn't specify alignsize, libvirt would select one based on memory page size. // Better to set it ourselves, to the memory block size. // See also VmInfoBuildUtils::getNvdimmAlignedSize(). - alignSize = new Long(vm.getClusterArch().getHotplugMemorySizeFactorMb() * 1024 * 1024); + alignSize = (long) vm.getClusterArch().getHotplugMemorySizeFactorMb() * 1024 * 1024; } Long size = vmInfoBuildUtils.getNvdimmAlignedSize(vm, hostDevice); if (size == null) { diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/popup/vm/VmRunOncePopupWidget.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/popup/vm/VmRunOncePopupWidget.java index 3dc9a3434cf..9da4dce7f67 100644 --- a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/popup/vm/VmRunOncePopupWidget.java +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/popup/vm/VmRunOncePopupWidget.java @@ -3,6 +3,7 @@ import org.gwtbootstrap3.client.ui.Button; import org.gwtbootstrap3.client.ui.Column; import org.gwtbootstrap3.client.ui.Container; +import org.ovirt.engine.core.common.businessentities.BootSequence; import org.ovirt.engine.core.common.businessentities.VDS; import org.ovirt.engine.core.common.businessentities.storage.RepoImage; import org.ovirt.engine.ui.common.CommonApplicationConstants; @@ -452,7 +453,7 @@ void initComboBox() { sysPrepDomainNameComboBox = new ComboBox<>(sysPrepDomainNameListBoxEditor, sysPrepDomainNameTextBoxEditor); - defaultHostEditor = new ListModelListBoxEditor<>(new NameRenderer()); + defaultHostEditor = new ListModelListBoxEditor<>(new NameRenderer<>()); emulatedMachine = new ListModelTypeAheadChangeableListBoxEditor( new ListModelTypeAheadChangeableListBoxEditor.NullSafeSuggestBoxRenderer() { @@ -500,9 +501,8 @@ public void edit(final RunOnceModel object) { runOnceModel = object; emulatedMachine.setNullReplacementString(getDefaultEmulatedMachineLabel()); - object.getClusterEmulatedMachine().getEntityChangedEvent().addListener((ev, sender, args) -> { - emulatedMachine.setNullReplacementString(getDefaultEmulatedMachineLabel()); - }); + object.getClusterEmulatedMachine().getEntityChangedEvent().addListener((ev, sender, args) -> + emulatedMachine.setNullReplacementString(getDefaultEmulatedMachineLabel())); // Update Linux options panel final EntityModel isLinuxOptionsAvailable = object.getIsLinuxOptionsAvailable(); @@ -677,7 +677,7 @@ private void updateBootSequenceItems() { bootSequenceBox.setVisibleItemCount(bootSequenceModel.getItems().size()); // Set items - for (EntityModel bootItem : bootSequenceModel.getItems()) { + for (EntityModel bootItem : bootSequenceModel.getItems()) { bootSequenceBox.addItem(bootItem.getTitle()); updateItemAvailability(bootItem.getTitle(), bootItem.getIsChangable()); } diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/BootSequenceModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/BootSequenceModel.java index 9ed375187cd..7389701f9d2 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/BootSequenceModel.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/BootSequenceModel.java @@ -39,20 +39,20 @@ public void setItems(ObservableCollection> value) { super.setItems(value); } - public EntityModel getHardDiskOption() { + public EntityModel getHardDiskOption() { return getBootSequenceOption(BootSequence.C); } - public EntityModel getNetworkOption() { + public EntityModel getNetworkOption() { return getBootSequenceOption(BootSequence.N); } - public EntityModel getCdromOption() { + public EntityModel getCdromOption() { return getBootSequenceOption(BootSequence.D); } - private EntityModel getBootSequenceOption(BootSequence bootSequenceOption) { - for (EntityModel a : getItems()) { + private EntityModel getBootSequenceOption(BootSequence bootSequenceOption) { + for (EntityModel a : getItems()) { if (a.getEntity() == bootSequenceOption) { return a; } @@ -63,9 +63,9 @@ private EntityModel getBootSequenceOption(BootSequence bootSequenceOption) { public BootSequence getSequence() { StringBuilder str = new StringBuilder(); - for (EntityModel a : getItems()) { + for (EntityModel a : getItems()) { if (a.getIsChangable()) { - BootSequence bs = (BootSequence) a.getEntity(); + BootSequence bs = a.getEntity(); str.append(bs.toString()); } } diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/RunOnceModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/RunOnceModel.java index ab474c01b32..abb3db03871 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/RunOnceModel.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/RunOnceModel.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.TreeSet; @@ -606,37 +607,37 @@ public RunOnceModel(VM vm, ICommandTarget commandTarget) { this.commandTarget = commandTarget; // Boot Options tab - setAttachFloppy(new EntityModel()); + setAttachFloppy(new EntityModel<>()); getAttachFloppy().getEntityChangedEvent().addListener(this); - setFloppyImage(new ListModel()); + setFloppyImage(new ListModel<>()); getFloppyImage().getSelectedItemChangedEvent().addListener(this); - setAttachIso(new EntityModel()); + setAttachIso(new EntityModel<>()); getAttachIso().getEntityChangedEvent().addListener(this); - setIsoImage(new SortedListModel(new LexoNumericNameableComparator())); + setIsoImage(new SortedListModel<>(new LexoNumericNameableComparator())); getIsoImage().getSelectedItemChangedEvent().addListener(this); - setAttachWgt(new EntityModel()); - setAttachSysprep(new EntityModel()); + setAttachWgt(new EntityModel<>()); + setAttachSysprep(new EntityModel<>()); getAttachSysprep().getEntityChangedEvent().addListener(this); - setDisplayProtocol(new ListModel>()); + setDisplayProtocol(new ListModel<>()); setBootSequence(new BootSequenceModel()); // Linux Boot Options tab - setKernel_parameters(new EntityModel()); - setKernelImage(new ListModel()); - setInitrdImage(new ListModel()); + setKernel_parameters(new EntityModel<>()); + setKernelImage(new ListModel<>()); + setInitrdImage(new ListModel<>()); // Initial Boot tab - Sysprep setIsCloudInitEnabled(new EntityModel<>(false)); - setSysPrepDomainName(new ListModel()); - setSysPrepSelectedDomainName(new EntityModel()); + setSysPrepDomainName(new ListModel<>()); + setSysPrepSelectedDomainName(new EntityModel<>()); setSysPrepUserName(new EntityModel().setIsChangeable(false)); setSysPrepPassword(new EntityModel().setIsChangeable(false)); setSysPrepPasswordVerification(new EntityModel().setIsChangeable(false)); setIsSysprepEnabled(new EntityModel<>(false)); - setIsSysprepPossible(new EntityModel()); + setIsSysprepPossible(new EntityModel<>()); setIsVmFirstRun(new EntityModel<>(false)); getIsVmFirstRun().getEntityChangedEvent().addListener(this); @@ -644,7 +645,7 @@ public RunOnceModel(VM vm, ICommandTarget commandTarget) { getUseAlternateCredentials().getEntityChangedEvent().addListener(this); // Initial Boot tab - Cloud-Init - setIsCloudInitPossible(new EntityModel()); + setIsCloudInitPossible(new EntityModel<>()); setVmInitModel(new VmInitModel()); @@ -657,40 +658,40 @@ public RunOnceModel(VM vm, ICommandTarget commandTarget) { setRunAsStateless(new EntityModel<>(false)); // Display Protocol tab - setRunOnceHeadlessModeIsSelected(new EntityModel()); + setRunOnceHeadlessModeIsSelected(new EntityModel<>()); getRunOnceHeadlessModeIsSelected().getEntityChangedEvent().addListener(this); - setDisplayConsole_Spice_IsSelected(new EntityModel()); + setDisplayConsole_Spice_IsSelected(new EntityModel<>()); getDisplayConsole_Spice_IsSelected().getEntityChangedEvent().addListener(this); - setDisplayConsole_Vnc_IsSelected(new EntityModel()); + setDisplayConsole_Vnc_IsSelected(new EntityModel<>()); getDisplayConsole_Vnc_IsSelected().getEntityChangedEvent().addListener(this); - setVncKeyboardLayout(new ListModel()); + setVncKeyboardLayout(new ListModel<>()); getVncKeyboardLayout().getSelectedItemChangedEvent().addListener(this); initVncKeyboardLayout(); getVncKeyboardLayout().setSelectedItem(vm.getDefaultVncKeyboardLayout()); - setSpiceFileTransferEnabled(new EntityModel()); + setSpiceFileTransferEnabled(new EntityModel<>()); getSpiceFileTransferEnabled().setEntity(vm.isSpiceFileTransferEnabled()); getSpiceFileTransferEnabled().setIsChangeable(true); getSpiceFileTransferEnabled().setIsAvailable(true); - setSpiceCopyPasteEnabled(new EntityModel()); + setSpiceCopyPasteEnabled(new EntityModel<>()); getSpiceCopyPasteEnabled().setEntity(vm.isSpiceCopyPasteEnabled()); getSpiceCopyPasteEnabled().setIsChangeable(true); getSpiceCopyPasteEnabled().setIsAvailable(true); // System tab - setEmulatedMachine(new ListModel()); + setEmulatedMachine(new ListModel<>()); getEmulatedMachine().setSelectedItem(vm.getCustomEmulatedMachine()); setClusterEmulatedMachine(new EntityModel<>()); - setCustomCpu(new ListModel()); + setCustomCpu(new ListModel<>()); getCustomCpu().setSelectedItem(vm.getCustomCpuName()); // Host tab - setDefaultHost(new ListModel()); + setDefaultHost(new ListModel<>()); getDefaultHost().getSelectedItemChangedEvent().addListener(this); - setIsAutoAssign(new EntityModel()); + setIsAutoAssign(new EntityModel<>()); getIsAutoAssign().getEntityChangedEvent().addListener(this); // availability/visibility @@ -779,7 +780,7 @@ public void init() { if (hasSpiceSupport) { getDisplayProtocol().setItems(Arrays.asList(vncProtocol, qxlProtocol)); } else { - getDisplayProtocol().setItems(Arrays.asList(vncProtocol)); + getDisplayProtocol().setItems(Collections.singletonList(vncProtocol)); getDisplayConsole_Spice_IsSelected().setIsAvailable(false); } @@ -1105,7 +1106,7 @@ public void eventRaised(Event ev, Object sender, EventArgs if (ev.matchesDefinition(ListModel.selectedItemChangedEventDefinition)) { if (sender == getIsoImage()) { - IsoImage_SelectedItemChanged(); + isoImage_SelectedItemChanged(); } else if (sender == getFloppyImage()) { floppyImage_SelectedItemChanged(); } @@ -1140,7 +1141,7 @@ public void eventRaised(Event ev, Object sender, EventArgs getSpiceFileTransferEnabled().setIsChangeable(false); getSpiceCopyPasteEnabled().setIsChangeable(false); } else if (sender == getIsAutoAssign()) { - isAutoAssign_EntityChanged(sender, args); + isAutoAssign_EntityChanged(); } } } @@ -1180,15 +1181,11 @@ private void floppyImage_SelectedItemChanged() { updateInitialRunFields(); } - private void sysprepImage_SelectedItemChanged() { + private void isoImage_SelectedItemChanged() { updateInitialRunFields(); } - private void IsoImage_SelectedItemChanged() { - updateInitialRunFields(); - } - - private void isAutoAssign_EntityChanged(Object sender, EventArgs args) { + private void isAutoAssign_EntityChanged() { if (!getIsAutoAssign().getEntity()) { getDefaultHost().setIsChangeable(true); } diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/UnitVmModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/UnitVmModel.java index 0f7ed0487d9..77318e1aefb 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/UnitVmModel.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/UnitVmModel.java @@ -271,7 +271,7 @@ public void setIcon(NotChangableForVmInPoolEntityModel icon) public void setVmAttachedToPool(boolean value) { if (value) { // ==Header== - getDataCenterWithClustersList().setIsChangeable(!value); + getDataCenterWithClustersList().setIsChangeable(false); getBaseTemplate().setIsChangeable(false); getTemplateWithVersion().setIsChangeable(false); getOSType().setIsChangeable(false); @@ -1052,14 +1052,12 @@ public enum GraphicsTypes { VNC(GraphicsType.VNC), SPICE_AND_VNC(GraphicsType.SPICE, GraphicsType.VNC); - private Set backingTypes; + private final Set backingTypes; - private GraphicsTypes(GraphicsType ... backingTypes) { + GraphicsTypes(GraphicsType ... backingTypes) { this.backingTypes = new HashSet<>(); if (backingTypes != null) { - for (GraphicsType backingType : backingTypes) { - this.backingTypes.add(backingType); - } + Collections.addAll(this.backingTypes, backingTypes); } } @@ -1500,13 +1498,13 @@ public void setIsCustomPropertiesTabAvailable(boolean value) { } } - private final VmModelBehaviorBase behavior; + private final VmModelBehaviorBase behavior; - public VmModelBehaviorBase getBehavior() { + public VmModelBehaviorBase getBehavior() { return behavior; } - private void setBehavior(VmModelBehaviorBase value) { + private void setBehavior(VmModelBehaviorBase value) { } private CpuPinningPolicy originalCpuPinningPolicy; @@ -1730,7 +1728,7 @@ public void setAffinityGroupList(ListModel affinityGroupList) { this.affinityGroupList = affinityGroupList; } - public UnitVmModel(VmModelBehaviorBase behavior, ListModel parentModel) { + public UnitVmModel(VmModelBehaviorBase behavior, ListModel parentModel) { this.behavior = behavior; this.behavior.setModel(this); @@ -1738,53 +1736,53 @@ public UnitVmModel(VmModelBehaviorBase behavior, ListModel parentModel) { setAdvancedMode(new EntityModel<>(false)); setValid(new EntityModel<>(true)); setAttachedToInstanceType(new EntityModel<>(true)); - setStorageDomain(new NotChangableForVmInPoolListModel()); - setName(new NotChangableForVmInPoolEntityModel()); + setStorageDomain(new NotChangableForVmInPoolListModel<>()); + setName(new NotChangableForVmInPoolEntityModel<>()); getName().getEntityChangedEvent().addListener(this); - setNumOfMonitors(new NotChangableForVmInPoolListModel()); - setAllowConsoleReconnect(new NotChangableForVmInPoolEntityModel()); - setVmId(new NotChangableForVmInPoolEntityModel()); - setDescription(new NotChangableForVmInPoolEntityModel()); - setComment(new NotChangableForVmInPoolEntityModel()); - setMinAllocatedMemory(new NotChangableForVmInPoolEntityModel()); - setIsUsbEnabled(new NotChangableForVmInPoolEntityModel()); - setConsoleDisconnectAction(new NotChangableForVmInPoolListModel()); - setConsoleDisconnectActionDelay(new NotChangableForVmInPoolEntityModel()); + setNumOfMonitors(new NotChangableForVmInPoolListModel<>()); + setAllowConsoleReconnect(new NotChangableForVmInPoolEntityModel<>()); + setVmId(new NotChangableForVmInPoolEntityModel<>()); + setDescription(new NotChangableForVmInPoolEntityModel<>()); + setComment(new NotChangableForVmInPoolEntityModel<>()); + setMinAllocatedMemory(new NotChangableForVmInPoolEntityModel<>()); + setIsUsbEnabled(new NotChangableForVmInPoolEntityModel<>()); + setConsoleDisconnectAction(new NotChangableForVmInPoolListModel<>()); + setConsoleDisconnectActionDelay(new NotChangableForVmInPoolEntityModel<>()); getConsoleDisconnectActionDelay().setIsChangeable(false, constants.consoleDisconnectActionDelayDisabledReason()); getConsoleDisconnectAction().getSelectedItemChangedEvent().addListener(this); - setIsStateless(new NotChangableForVmInPoolEntityModel()); - setIsRunAndPause(new NotChangableForVmInPoolEntityModel()); - setIsHeadlessModeEnabled(new NotChangableForVmInPoolEntityModel()); - setIsSmartcardEnabled(new NotChangableForVmInPoolEntityModel()); - setIsDeleteProtected(new NotChangableForVmInPoolEntityModel()); - setSsoMethodNone(new NotChangableForVmInPoolEntityModel()); - setSsoMethodGuestAgent(new NotChangableForVmInPoolEntityModel()); - setConsoleDeviceEnabled(new NotChangableForVmInPoolEntityModel()); - setCopyPermissions(new NotChangableForVmInPoolEntityModel()); + setIsStateless(new NotChangableForVmInPoolEntityModel<>()); + setIsRunAndPause(new NotChangableForVmInPoolEntityModel<>()); + setIsHeadlessModeEnabled(new NotChangableForVmInPoolEntityModel<>()); + setIsSmartcardEnabled(new NotChangableForVmInPoolEntityModel<>()); + setIsDeleteProtected(new NotChangableForVmInPoolEntityModel<>()); + setSsoMethodNone(new NotChangableForVmInPoolEntityModel<>()); + setSsoMethodGuestAgent(new NotChangableForVmInPoolEntityModel<>()); + setConsoleDeviceEnabled(new NotChangableForVmInPoolEntityModel<>()); + setCopyPermissions(new NotChangableForVmInPoolEntityModel<>()); setSealTemplate(new NotChangableForVmInPoolEntityModel<>(false)); setIsSealed(new EntityModel<>(false)); getIsSealed().setIsAvailable(false); //rng - setIsRngEnabled(new NotChangableForVmInPoolEntityModel()); + setIsRngEnabled(new NotChangableForVmInPoolEntityModel<>()); getIsRngEnabled().getEntityChangedEvent().addListener(this); - setRngBytes(new NotChangableForVmInPoolEntityModel()); - setRngPeriod(new NotChangableForVmInPoolEntityModel()); - setRngSourceUrandom(new NotChangableForVmInPoolEntityModel()); - setRngSourceHwrng(new NotChangableForVmInPoolEntityModel()); + setRngBytes(new NotChangableForVmInPoolEntityModel<>()); + setRngPeriod(new NotChangableForVmInPoolEntityModel<>()); + setRngSourceUrandom(new NotChangableForVmInPoolEntityModel<>()); + setRngSourceHwrng(new NotChangableForVmInPoolEntityModel<>()); // by default not available - only for new VM getCopyPermissions().setIsAvailable(false); getCopyPermissions().setEntity(false); - setVncKeyboardLayout(new NotChangableForVmInPoolListModel()); - setVmType(new NotChangableForVmInPoolListModel()); + setVncKeyboardLayout(new NotChangableForVmInPoolListModel<>()); + setVmType(new NotChangableForVmInPoolListModel<>()); getVmType().setItems(Arrays.asList(VmType.values())); getVmType().setSelectedItem(VmType.Server); getVmType().setIsChangeable(false); getVmType().getSelectedItemChangedEvent().addListener(this); // element should only appear in webadmin add & edit VM dialogs - setLabelList(new ListModel