abh1sar commented on code in PR #12779:
URL: https://github.com/apache/cloudstack/pull/12779#discussion_r2922121455
##########
server/src/main/java/com/cloud/vm/UserVmManagerImpl.java:
##########
@@ -2452,18 +2428,14 @@ public boolean configure(String name, Map<String,
Object> params) throws Configu
final int DAILY_TIME = 60 * 24;
if (_usageAggregationRange == DAILY_TIME) {
_dailyOrHourly = true;
- } else if (_usageAggregationRange == HOURLY_TIME) {
- _dailyOrHourly = true;
- } else {
- _dailyOrHourly = false;
- }
+ } else _dailyOrHourly = _usageAggregationRange == HOURLY_TIME;
Review Comment:
```
if (_usageAggregationRange == DAILY_TIME || _usageAggregationRange
== HOURLY_TIME) {
_dailyOrHourly = true;
}
```
##########
server/src/main/java/com/cloud/vm/UserVmManagerImpl.java:
##########
@@ -4614,13 +4547,17 @@ private UserVm getUncheckedUserVmResource(DataCenter
zone, String hostName, Stri
logger.error("error during resource reservation and allocation",
e);
throw new CloudRuntimeException(e);
} finally {
- for (CheckedReservation checkedReservation : checkedReservations) {
- try {
- checkedReservation.close();
- } catch (Exception e) {
- logger.error("error during resource reservation and
allocation", e);
- throw new CloudRuntimeException(e);
- }
+ closeCheckeReservation(checkedReservations);
Review Comment:
```suggestion
closeCheckedReservations(checkedReservations);
```
##########
server/src/main/java/com/cloud/vm/UserVmManagerImpl.java:
##########
@@ -903,10 +881,9 @@ public UserVm resetVMPassword(ResetVMPasswordCmd cmd,
String password) throws Re
}
private boolean resetVMPasswordInternal(Long vmId, String password) throws
ResourceUnavailableException, InsufficientCapacityException {
- Long userId = CallContext.current().getCallingUserId();
VMInstanceVO vmInstance = _vmDao.findById(vmId);
- if (password == null || password.equals("")) {
+ if (password == null || password.isEmpty()) {
Review Comment:
```suggestion
if (StringUtils.isBlank(password)) {
```
##########
server/src/main/java/com/cloud/vm/UserVmManagerImpl.java:
##########
@@ -5186,7 +5118,7 @@ public void
doInTransactionWithoutResult(TransactionStatus status) {
sc_nic.addAnd("macAddress", SearchCriteria.Op.EQ,
vmNetworkStat.getMacAddress());
NicVO nic = _nicDao.search(sc_nic, null).get(0);
List<VlanVO> vlan =
_vlanDao.listVlansByNetworkId(nic.getNetworkId());
- if (vlan == null || vlan.size() == 0 ||
vlan.get(0).getVlanType() != VlanType.DirectAttached)
+ if (vlan == null || vlan.isEmpty() ||
vlan.get(0).getVlanType() != VlanType.DirectAttached)
Review Comment:
```suggestion
if (CollectionUtils.isEmpty(vlan) ||
vlan.get(0).getVlanType() != VlanType.DirectAttached)
```
##########
server/src/main/java/com/cloud/vm/UserVmManagerImpl.java:
##########
@@ -6066,7 +5988,7 @@ public void
doInTransactionWithoutResult(TransactionStatus status) {
SearchCriteria<VolumeVO> sc_volume =
_volsDao.createSearchCriteria();
sc_volume.addAnd("path", SearchCriteria.Op.LIKE,
vmDiskStat.getPath() + "%");
List<VolumeVO> volumes =
_volsDao.search(sc_volume, null);
- if ((volumes == null) || (volumes.size() == 0)) {
+ if ((volumes == null) || (volumes.isEmpty())) {
Review Comment:
```suggestion
if (CollectionUtils.isEmpty(volumes)) {
```
##########
server/src/main/java/com/cloud/vm/UserVmManagerImpl.java:
##########
@@ -3769,7 +3726,7 @@ public void removeInstanceFromInstanceGroup(long vmId) {
}
private boolean validPassword(String password) {
- if (password == null || password.length() == 0) {
+ if (password == null || password.isEmpty()) {
Review Comment:
```suggestion
if (StringUtils.isBlank(password)) {
```
##########
server/src/main/java/com/cloud/vm/UserVmManagerImpl.java:
##########
@@ -4858,11 +4795,7 @@ private UserVmVO commitUserVm(final boolean isImport,
final DataCenter zone, fin
validateRootDiskResize(hypervisorType, rootDiskSize, templateVO,
vm, customParameters);
}
- if (isDisplayVm != null) {
- vm.setDisplayVm(isDisplayVm);
- } else {
- vm.setDisplayVm(true);
- }
+ vm.setDisplayVm(isDisplayVm == null || isDisplayVm);
Review Comment:
```suggestion
vm.setDisplayVm(!Boolean.FALSE.equals(isDisplayVm));
```
##########
server/src/main/java/com/cloud/vm/UserVmManagerImpl.java:
##########
@@ -3449,7 +3411,7 @@ public UserVm rebootVirtualMachine(RebootVMCmd cmd)
throws InsufficientCapacityE
throw new InvalidParameterValueException("Booting into a hardware
setup menu is not implemented on " + vmInstance.getHypervisorType());
}
- UserVm userVm =
rebootVirtualMachine(CallContext.current().getCallingUserId(), vmId, enterSetup
== null ? false : cmd.getBootIntoSetup(), cmd.isForced());
+ UserVm userVm = rebootVirtualMachine(vmId, enterSetup != null &&
cmd.getBootIntoSetup(), cmd.isForced());
Review Comment:
```
boolean enterSetup = Boolean.TRUE.equals(cmd.getBootIntoSetup());
if (enterSetup &&
!HypervisorType.VMware.equals(vmInstance.getHypervisorType())) {
throw new InvalidParameterValueException("Booting into a
hardware setup menu is not implemented on " + vmInstance.getHypervisorType());
}
UserVm userVm = rebootVirtualMachine(vmId, enterSetup,
cmd.isForced());
```
##########
server/src/main/java/com/cloud/vm/UserVmManagerImpl.java:
##########
@@ -5560,9 +5486,9 @@ public boolean finalizeStart(VirtualMachineProfile
profile, long hostId, Command
}
Answer answer = cmds.getAnswer("restoreVMSnapshot");
- if (answer != null && answer instanceof RestoreVMSnapshotAnswer) {
+ if (answer instanceof RestoreVMSnapshotAnswer) {
RestoreVMSnapshotAnswer restoreVMSnapshotAnswer =
(RestoreVMSnapshotAnswer) answer;
Review Comment:
can't answer be null here?
##########
server/src/main/java/com/cloud/vm/UserVmManagerImpl.java:
##########
@@ -5598,7 +5524,7 @@ public void finalizeExpunge(VirtualMachine vm) {
}
private void checkForceStopVmPermission(Account callingAccount) {
- if (!AllowUserForceStopVm.valueIn(callingAccount.getId())) {
+ if (callingAccount == null ||
!AllowUserForceStopVm.valueIn(callingAccount.getId())) {
Review Comment:
we can check the config's global value if callingAccount is null
##########
server/src/main/java/com/cloud/vm/UserVmManagerImpl.java:
##########
@@ -9321,7 +9222,7 @@ public void finalizeUnmanage(VirtualMachine vm) {
private void encryptAndStorePassword(UserVmVO vm, String password) {
String sshPublicKeys = vm.getDetail(VmDetailConstants.SSH_PUBLIC_KEY);
- if (sshPublicKeys != null && !sshPublicKeys.equals("") && password !=
null && !password.equals("saved_password")) {
+ if (sshPublicKeys != null && !sshPublicKeys.isEmpty() && password !=
null && !password.equals("saved_password")) {
Review Comment:
```suggestion
if (!StringUtils.isEmpty(sshPublicKeys) && password != null &&
!password.equals("saved_password")) {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]