Skip to content

Commit a310ee2

Browse files
Apply suggestions from code review
Co-authored-by: Abhisar Sinha <63767682+abh1sar@users.noreply.github.com> Co-authored-by: dahn <daan.hoogland@gmail.com>
1 parent f237082 commit a310ee2

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ public UserVm resetVMPassword(ResetVMPasswordCmd cmd, String password) throws Re
883883
private boolean resetVMPasswordInternal(Long vmId, String password) throws ResourceUnavailableException, InsufficientCapacityException {
884884
VMInstanceVO vmInstance = _vmDao.findById(vmId);
885885

886-
if (password == null || password.isEmpty()) {
886+
if (StringUtils.isBlank(password)) {
887887
return false;
888888
}
889889

@@ -3726,7 +3726,7 @@ public void removeInstanceFromInstanceGroup(long vmId) {
37263726
}
37273727

37283728
private boolean validPassword(String password) {
3729-
if (password == null || password.isEmpty()) {
3729+
if (StringUtils.isBlank(password)) {
37303730
return false;
37313731
}
37323732
for (int i = 0; i < password.length(); i++) {
@@ -4547,11 +4547,11 @@ private UserVm getUncheckedUserVmResource(DataCenter zone, String hostName, Stri
45474547
logger.error("error during resource reservation and allocation", e);
45484548
throw new CloudRuntimeException(e);
45494549
} finally {
4550-
closeCheckeReservation(checkedReservations);
4550+
closeCheckedReservations(checkedReservations);
45514551
}
45524552
}
45534553

4554-
private void closeCheckeReservation(List<CheckedReservation> checkedReservations) {
4554+
private void closeCheckedReservations(List<CheckedReservation> checkedReservations) {
45554555
for (CheckedReservation checkedReservation : checkedReservations) {
45564556
try {
45574557
checkedReservation.close();
@@ -4577,7 +4577,7 @@ private void assignInstanceToGroup(String group, long id) {
45774577
}
45784578

45794579
private long verifyAndGetDiskSize(DiskOffering diskOffering, Long diskSize) {
4580-
long size = 0L;
4580+
long size;
45814581
if (diskOffering == null) {
45824582
throw new InvalidParameterValueException("Specified disk offering cannot be found");
45834583
}
@@ -5118,7 +5118,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
51185118
sc_nic.addAnd("macAddress", SearchCriteria.Op.EQ, vmNetworkStat.getMacAddress());
51195119
NicVO nic = _nicDao.search(sc_nic, null).get(0);
51205120
List<VlanVO> vlan = _vlanDao.listVlansByNetworkId(nic.getNetworkId());
5121-
if (vlan == null || vlan.isEmpty() || vlan.get(0).getVlanType() != VlanType.DirectAttached)
5121+
if (CollectionUtils.isEmpty(vlan) || vlan.get(0).getVlanType() != VlanType.DirectAttached)
51225122
{
51235123
break; // only get network statistics for DirectAttached network (shared networks in Basic zone and Advanced zone with/without SG)
51245124
}
@@ -5298,7 +5298,7 @@ private void addUserVMCmdlineArgs(Long vmId, VirtualMachineProfile profile, Depl
52985298
if (dc.getDns2() != null) {
52995299
buf.append(" dns2=").append(dc.getDns2());
53005300
}
5301-
logger.info("cmdline details: "+ buf);
5301+
logger.info("cmdline details: {}”, buf);
53025302
}
53035303

53045304
@Override
@@ -5744,7 +5744,7 @@ public Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> startVirtualMach
57445744

57455745
//overwrite BootIntoSetup
57465746
Object paramValue = additionalParams.get(VirtualMachineProfile.Param.BootIntoSetup);
5747-
logger.trace("It was specified whether to enter setup mode: {}", paramValue.toString());
5747+
logger.trace("It was specified whether to enter setup mode: {}", paramValue);
57485748
params = createParameterInParameterMap(params, VirtualMachineProfile.Param.BootIntoSetup, paramValue);
57495749
}
57505750

@@ -5988,7 +5988,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
59885988
SearchCriteria<VolumeVO> sc_volume = _volsDao.createSearchCriteria();
59895989
sc_volume.addAnd("path", SearchCriteria.Op.LIKE, vmDiskStat.getPath() + "%");
59905990
List<VolumeVO> volumes = _volsDao.search(sc_volume, null);
5991-
if ((volumes == null) || (volumes.isEmpty())) {
5991+
if (CollectionUtils.isEmpty(volumes)) {
59925992
break;
59935993
}
59945994
VolumeVO volume = volumes.get(0);
@@ -9222,7 +9222,7 @@ public void finalizeUnmanage(VirtualMachine vm) {
92229222

92239223
private void encryptAndStorePassword(UserVmVO vm, String password) {
92249224
String sshPublicKeys = vm.getDetail(VmDetailConstants.SSH_PUBLIC_KEY);
9225-
if (sshPublicKeys != null && !sshPublicKeys.isEmpty() && password != null && !password.equals("saved_password")) {
9225+
if (!StringUtils.isEmpty(sshPublicKeys) && password != null && !password.equals("saved_password")) {
92269226
if (!sshPublicKeys.startsWith("ssh-rsa")) {
92279227
logger.warn("Only RSA public keys can be used to encrypt a vm password.");
92289228
return;

0 commit comments

Comments
 (0)