Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: Fix IDE warnings #650

Merged
merged 1 commit into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -192,7 +193,7 @@ public class AddVmCommand<T extends AddVmParameters> extends VmManagementCommand
private List<StorageDomain> poolDomains;
private String mdevType; // the value of the deprecated custom property mdev_type, if specified

private Map<Guid, Guid> srcVmNicIdToTargetVmNicIdMapping = new HashMap<>();
private final Map<Guid, Guid> srcVmNicIdToTargetVmNicIdMapping = new HashMap<>();

@Inject
private InClusterUpgradeValidator clusterUpgradeValidator;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1260,7 +1261,6 @@ protected boolean areParametersLegal() {
final VmStatic vmStaticData = getParameters().getVmStaticData();

if (vmStaticData != null) {

if (!isLegalClusterId(vmStaticData.getClusterId())) {
return false;
}
Expand Down Expand Up @@ -1440,7 +1440,7 @@ protected void addVmCinderDisks(Collection<DiskImage> 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;
}
Expand All @@ -1464,7 +1464,7 @@ protected void addManagedBlockDisks(Collection<DiskImage> 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;
}
Expand Down Expand Up @@ -1681,7 +1681,7 @@ private void addVmPermission() {
if (!permissionsToAdd.isEmpty()) {
List<Permission> permissionsList = permissionsToAdd.asPermissionList();
multiLevelAdministrationHandler
.addPermission(permissionsList.toArray(new Permission[permissionsList.size()]));
.addPermission(permissionsList.toArray(new Permission[0]));

getCompensationContext().snapshotNewEntities(permissionsList);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Guid> startingVms = ConcurrentHashMap.newKeySet();
private final Set<Guid> startingVms = ConcurrentHashMap.newKeySet();

@Inject
private VmPoolHandler vmPoolHandler;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -54,8 +52,6 @@ public class CreateSnapshotCommand<T extends CreateSnapshotParameters> extends B
@Inject
private VmDao vmDao;
@Inject
private StorageDomainDao storageDomainDao;
@Inject
private CommandCoordinatorUtil commandCoordinatorUtil;
@Inject
private ImagesHandler imagesHandler;
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -136,9 +134,6 @@ public class ImagesHandler {
@Inject
private StorageHelperDirector storageHelperDirector;

@Inject
private ClusterUtils clusterUtils;

@Inject
private VdsCommandsHelper vdsCommandsHelper;

Expand Down Expand Up @@ -290,11 +285,7 @@ public static Map<Guid, List<DiskImage>> buildStorageToDiskMap(Collection<DiskIm
for (DiskImage disk : images) {
DiskImage diskImage = diskInfoDestinationMap.get(disk.getId());
Guid storageDomainId = diskImage.getStorageIds().get(0);
List<DiskImage> diskList = storageToDisksMap.get(storageDomainId);
if (diskList == null) {
diskList = new ArrayList<>();
storageToDisksMap.put(storageDomainId, diskList);
}
List<DiskImage> diskList = storageToDisksMap.computeIfAbsent(storageDomainId, k -> new ArrayList<>());
diskList.add(disk);
}
return storageToDisksMap;
Expand Down Expand Up @@ -329,7 +320,7 @@ private void addDiskImage(DiskImage image, boolean active, ImageStorageDomainMap
* @return map object is the collection is not null
*/
public static Map<Guid, DiskImage> getDiskImagesByIdMap(Collection<DiskImage> diskImages) {
return diskImages.stream().collect(Collectors.toMap(d -> d.getImageId(), Function.identity()));
return diskImages.stream().collect(Collectors.toMap(DiskImage::getImageId, Function.identity()));
}

/**
Expand Down Expand Up @@ -1035,7 +1026,7 @@ public VDSReturnValue teardownImage(Guid storagePoolId,
}

public Set<Guid> getVolumeChain(Guid vmId, Guid vdsId, DiskImage activeImage) {
Map[] vms = null;
Map<String, Object>[] vms = null;
try {
vms = getVms(vdsId, vmId);
} catch (EngineException e) {
Expand All @@ -1047,7 +1038,7 @@ public Set<Guid> getVolumeChain(Guid vmId, Guid vdsId, DiskImage activeImage) {
return null;
}

Map vm = vms[0];
Map<String, Object> vm = vms[0];
if (vm == null || vm.get(VdsProperties.vm_guid) == null) {
log.error("Received incomplete VM information");
return null;
Expand All @@ -1062,7 +1053,7 @@ public Set<Guid> getVolumeChain(Guid vmId, Guid vdsId, DiskImage activeImage) {

Set<Guid> images = new HashSet<>();
for (Object o : (Object[]) vm.get(VdsProperties.Devices)) {
Map device = (Map<String, Object>) o;
Map<String, Object> device = (Map<String, Object>) o;
if (VmDeviceType.DISK.getName().equals(device.get(VdsProperties.Device))
&& !device.get(VdsProperties.ImageId).equals("mapper")
&& activeImage.getId().equals(Guid.createGuidFromString(
Expand Down Expand Up @@ -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<String, Object>[] getVms(Guid vdsId, Guid vmId) {
return (Map<String, Object>[]) fullListAdapter.getVmFullList(
vdsId,
Collections.singletonList(vmId),
true)
Expand All @@ -1115,7 +1106,7 @@ public Map<DiskImage, DiskImage> 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);
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<VmNumaNode>());
this.setDiskMap(new HashMap<Guid, Disk>());
this.setvNumaNodeList(new ArrayList<>());
this.setDiskMap(new HashMap<>());
this.setCdPath("");
this.setWgtCdPath("");
this.setFloppyPath("");
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.ovirt.engine.core.compat.Guid;

public class DiskVmElement implements BusinessEntity<VmDeviceId> {
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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -87,7 +81,7 @@ public static VmDevice createVirtioSerialDeviceForVm(Guid vmId) {
VmDeviceGeneralType.CONTROLLER,
VmDeviceType.VIRTIOSERIAL.getName(),
"",
new HashMap<String, Object>(),
new HashMap<>(),
true,
true,
false,
Expand Down Expand Up @@ -210,7 +204,7 @@ private static List<VmDevice> sortInterfacesByName(List<VmDevice> 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;
}
Expand Down Expand Up @@ -284,7 +278,7 @@ public static Map<VmDeviceId, DiskVmElement> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
* {@code ImageDao} defines a type for performing CRUD operations on instances of {@link Image}.
*/
public interface ImageDao extends GenericDao<Image, Guid>, StatusAwareDao<Guid, ImageStatus> {
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);
}
Loading