155155import org.apache.commons.collections.MapUtils;
156156import org.apache.commons.lang.math.NumberUtils;
157157import org.apache.commons.lang3.ObjectUtils;
158- import org.apache.commons.lang3.StringUtils;
159158import org.apache.commons.lang3.builder.ToStringBuilder;
160159import org.apache.commons.lang3.builder.ToStringStyle;
161160import org.jetbrains.annotations.NotNull;
376375import com.cloud.utils.Journal;
377376import com.cloud.utils.NumbersUtil;
378377import com.cloud.utils.Pair;
378+ import com.cloud.utils.StringUtils;
379379import com.cloud.utils.component.ComponentContext;
380380import com.cloud.utils.component.ManagerBase;
381381import com.cloud.utils.concurrency.NamedThreadFactory;
@@ -619,7 +619,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
619619 @Inject
620620 BackupScheduleDao backupScheduleDao;
621621 @Inject
622- private StatsCollector statsCollector;
622+ StatsCollector statsCollector;
623623 @Inject
624624 private UserDataDao userDataDao;
625625 @Inject
@@ -903,10 +903,10 @@ public UserVm resetVMPassword(ResetVMPasswordCmd cmd, String password) throws Re
903903 }
904904
905905 private boolean resetVMPasswordInternal(Long vmId, String password) throws ResourceUnavailableException, InsufficientCapacityException {
906- Long userId = CallContext.current().getCallingUserId();
906+ long userId = CallContext.current().getCallingUserId();
907907 VMInstanceVO vmInstance = _vmDao.findById(vmId);
908908
909- if (password == null || password.equals("" )) {
909+ if (StringUtils.isEmpty(password )) {
910910 return false;
911911 }
912912
@@ -1091,7 +1091,7 @@ protected void removeEncryptedPasswordFromUserVmVoDetails(long vmId) {
10911091 }
10921092
10931093 private boolean resetVMSSHKeyInternal(Long vmId, String sshPublicKeys, String keypairnames) throws ResourceUnavailableException, InsufficientCapacityException {
1094- Long userId = CallContext.current().getCallingUserId();
1094+ long userId = CallContext.current().getCallingUserId();
10951095 VMInstanceVO vmInstance = _vmDao.findById(vmId);
10961096
10971097 VMTemplateVO template = _templateDao.findByIdIncludingRemoved(vmInstance.getTemplateId());
@@ -1263,7 +1263,7 @@ public UserVm upgradeVirtualMachine(UpgradeVMCmd cmd) throws ResourceAllocationE
12631263 if (vmInstance == null) {
12641264 throw new InvalidParameterValueException("unable to find an Instance with id " + vmId);
12651265 } else if (!(vmInstance.getState().equals(State.Stopped))) {
1266- throw new InvalidParameterValueException("Unable to upgrade Instance " + vmInstance.toString() + " " + " in state " + vmInstance.getState()
1266+ throw new InvalidParameterValueException("Unable to upgrade Instance " + vmInstance + " " + " in state " + vmInstance.getState()
12671267 + "; make sure the Instance is stopped");
12681268 }
12691269
@@ -1756,7 +1756,7 @@ public UserVm updateDefaultNicForVirtualMachine(UpdateDefaultNicForVMCmd cmd) th
17561756 oldNetworkOfferingId = oldDefaultNetwork.getNetworkOfferingId();
17571757 }
17581758 NicVO existingVO = _nicDao.findById(existing.id);
1759- Integer chosenID = nic.getDeviceId();
1759+ int chosenID = nic.getDeviceId();
17601760 Integer existingID = existing.getDeviceId();
17611761
17621762 Network newdefault = null;
@@ -2136,14 +2136,14 @@ private boolean upgradeRunningVirtualMachine(Long vmId, Long newServiceOfferingI
21362136
21372137 // Check vm flag
21382138 if (!vmInstance.isDynamicallyScalable()) {
2139- throw new CloudRuntimeException(String.format("Unable to scale %s as it does not have tools to support dynamic scaling.", vmInstance.toString() ));
2139+ throw new CloudRuntimeException(String.format("Unable to scale %s as it does not have tools to support dynamic scaling.", vmInstance));
21402140 }
21412141
21422142 // Check disable threshold for cluster is not crossed
21432143 HostVO host = _hostDao.findById(vmInstance.getHostId());
21442144 _hostDao.loadDetails(host);
21452145 if (_capacityMgr.checkIfClusterCrossesThreshold(host.getClusterId(), cpuDiff, memoryDiff)) {
2146- throw new CloudRuntimeException(String.format("Unable to scale %s due to insufficient resources.", vmInstance.toString() ));
2146+ throw new CloudRuntimeException(String.format("Unable to scale %s due to insufficient resources.", vmInstance));
21472147 }
21482148
21492149 while (retry-- != 0) { // It's != so that it can match -1.
@@ -2180,7 +2180,7 @@ private boolean upgradeRunningVirtualMachine(Long vmId, Long newServiceOfferingI
21802180 success = true;
21812181 return success;
21822182 } catch (InsufficientCapacityException | ResourceUnavailableException | ConcurrentOperationException e) {
2183- logger.error(String.format("Unable to scale %s due to [%s].", vmInstance.toString() , e.getMessage()), e);
2183+ logger.error(String.format("Unable to scale %s due to [%s].", vmInstance, e.getMessage()), e);
21842184 } finally {
21852185 if (!success) {
21862186 // Decrement CPU and Memory count accordingly.
@@ -4485,7 +4485,7 @@ private UserVm getUncheckedUserVmResource(DataCenter zone, String hostName, Stri
44854485 }
44864486
44874487 NetworkOffering ntwkOffering = _networkOfferingDao.findById(network.getNetworkOfferingId());
4488- Long physicalNetworkId = _networkModel.findPhysicalNetworkId(zone.getId(), ntwkOffering.getTags(), ntwkOffering.getTrafficType());
4488+ long physicalNetworkId = _networkModel.findPhysicalNetworkId(zone.getId(), ntwkOffering.getTags(), ntwkOffering.getTrafficType());
44894489
44904490 String provider = _ntwkSrvcDao.getProviderForServiceInNetwork(network.getId(), Service.Connectivity);
44914491 if (!_networkModel.isProviderEnabledInPhysicalNetwork(physicalNetworkId, provider)) {
@@ -4703,7 +4703,7 @@ protected long configureCustomRootDiskSize(Map<String, String> customParameters,
47034703 }
47044704
47054705 if (customParameters.containsKey(VmDetailConstants.ROOT_DISK_SIZE)) {
4706- Long rootDiskSize = NumbersUtil.parseLong(customParameters.get(VmDetailConstants.ROOT_DISK_SIZE), -1);
4706+ long rootDiskSize = NumbersUtil.parseLong(customParameters.get(VmDetailConstants.ROOT_DISK_SIZE), -1);
47074707 if (rootDiskSize <= 0) {
47084708 throw new InvalidParameterValueException("Root disk size should be a positive number.");
47094709 }
@@ -4822,7 +4822,7 @@ private UserVmVO commitUserVm(final boolean isImport, final DataCenter zone, fin
48224822 final Map<String, Map<Integer, String>> extraDhcpOptionMap, final Map<Long, DiskOffering> dataDiskTemplateToDiskOfferingMap,
48234823 final Map<String, String> userVmOVFPropertiesMap, final VirtualMachine.PowerState powerState, final boolean dynamicScalingEnabled, String vmType, final Long rootDiskOfferingId, String sshkeypairs,
48244824 List<VmDiskInfo> dataDiskInfoList, Volume volume, Snapshot snapshot) throws InsufficientCapacityException {
4825- Long selectedGuestOsId = guestOsId != null ? guestOsId : template.getGuestOSId();
4825+ long selectedGuestOsId = guestOsId != null ? guestOsId : template.getGuestOSId();
48264826 UserVmVO vm = new UserVmVO(id, instanceName, displayName, template.getId(), hypervisorType, selectedGuestOsId, offering.isOfferHA(),
48274827 offering.getLimitCpuUse(), owner.getDomainId(), owner.getId(), userId, offering.getId(), userData, userDataId, userDataDetails, hostName);
48284828 vm.setUuid(uuidName);
@@ -5381,7 +5381,7 @@ private void addUserVMCmdlineArgs(Long vmId, VirtualMachineProfile profile, Depl
53815381 if (dc.getDns2() != null) {
53825382 buf.append(" dns2=").append(dc.getDns2());
53835383 }
5384- logger.info("cmdline details: "+ buf.toString() );
5384+ logger.info("cmdline details: "+ buf);
53855385 }
53865386
53875387 @Override
@@ -5641,7 +5641,7 @@ private void checkForceStopVmPermission(Account callingAccount) {
56415641 public UserVm stopVirtualMachine(long vmId, boolean forced) throws ConcurrentOperationException {
56425642 // Input validation
56435643 Account caller = CallContext.current().getCallingAccount();
5644- Long userId = CallContext.current().getCallingUserId();
5644+ long userId = CallContext.current().getCallingUserId();
56455645
56465646 // if account is removed, return error
56475647 if (caller != null && caller.getRemoved() != null) {
@@ -6919,7 +6919,7 @@ protected void addExtraConfig(UserVm vm, String extraConfig) {
69196919 } else if (hypervisorType.equals(HypervisorType.VMware)) {
69206920 persistExtraConfigVmware(decodedUrl, vm);
69216921 } else {
6922- String msg = String.format("This hypervisor %s is not supported for use with this feature", hypervisorType.toString() );
6922+ String msg = String.format("This hypervisor %s is not supported for use with this feature", hypervisorType);
69236923 throw new CloudRuntimeException(msg);
69246924 }
69256925 }
@@ -7265,7 +7265,7 @@ private DeployDestination chooseVmMigrationDestination(VMInstanceVO vm, Host src
72657265 vm.setLastHostId(null); // Last host does not have higher priority in vm migration
72667266 final ServiceOfferingVO offering = serviceOfferingDao.findById(vm.getId(), vm.getServiceOfferingId());
72677267 final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm, null, offering, null, null);
7268- final Long srcHostId = srcHost.getId();
7268+ final long srcHostId = srcHost.getId();
72697269 final Host host = _hostDao.findById(srcHostId);
72707270 ExcludeList excludes = new ExcludeList();
72717271 excludes.addHost(srcHostId);
@@ -7918,7 +7918,7 @@ public UserVm moveVmToUser(final AssignVMCmd cmd) throws ResourceAllocationExcep
79187918
79197919 Long domainId = cmd.getDomainId();
79207920 Long projectId = cmd.getProjectId();
7921- Long oldAccountId = vm.getAccountId();
7921+ long oldAccountId = vm.getAccountId();
79227922 String newAccountName = cmd.getAccountName();
79237923 final Account oldAccount = _accountService.getActiveAccountById(oldAccountId);
79247924 final Account newAccount = _accountMgr.finalizeOwner(caller, newAccountName, domainId, projectId);
@@ -8547,7 +8547,7 @@ protected void selectApplicableNetworkToCreateVm(Account newAccount, DataCenterV
85478547 protected void addDefaultSecurityGroupToSecurityGroupIdList(Account newAccount, List<Long> securityGroupIdList) {
85488548 logger.debug("Adding default security group to security group list if not already in it.");
85498549
8550- Long newAccountId = newAccount.getId();
8550+ long newAccountId = newAccount.getId();
85518551 SecurityGroup defaultGroup = _securityGroupMgr.getDefaultSecurityGroup(newAccountId);
85528552 boolean defaultGroupPresent = false;
85538553
@@ -8694,7 +8694,7 @@ protected NetworkVO createApplicableNetworkToCreateVm(Account newAccount, DataCe
86948694 logger.trace("Creating an applicable network to create the VM.");
86958695
86968696 NetworkVO defaultNetwork;
8697- Long zoneId = zone.getId();
8697+ long zoneId = zone.getId();
86988698 Account caller = CallContext.current().getCallingAccount();
86998699 NetworkOfferingVO requiredOffering = getOfferingWithRequiredAvailabilityForNetworkCreation();
87008700 String requiredOfferingTags = requiredOffering.getTags();
@@ -9454,7 +9454,7 @@ private boolean checkStatusOfVolumeSnapshots(VirtualMachine vm, Volume.Type type
94549454 }
94559455 logger.debug("Found {} no. of volumes of type {} for vm with VM ID {}", listVolumes.size(), type, vm);
94569456 for (VolumeVO volume : listVolumes) {
9457- Long volumeId = volume.getId();
9457+ long volumeId = volume.getId();
94589458 logger.debug("Checking status of snapshots for Volume: {}", volume);
94599459 List<SnapshotVO> ongoingSnapshots = _snapshotDao.listByStatus(volumeId, Snapshot.State.Creating, Snapshot.State.CreatedOnPrimary, Snapshot.State.BackingUp);
94609460 int ongoingSnapshotsCount = ongoingSnapshots.size();
@@ -9473,20 +9473,20 @@ private void checkForUnattachedVolumes(long vmId, List<VolumeVO> volumes) {
94739473
94749474 for (VolumeVO volume : volumes) {
94759475 if (volume.getInstanceId() == null || vmId != volume.getInstanceId() || volume.getVolumeType() != Volume.Type.DATADISK) {
9476- sb.append(volume.toString() + "; ");
9476+ sb.append(volume + "; ");
94779477 }
94789478 }
94799479
94809480 if (!StringUtils.isEmpty(sb.toString())) {
9481- throw new InvalidParameterValueException("The following supplied volumes are not DATADISK attached to the VM: " + sb.toString() );
9481+ throw new InvalidParameterValueException("The following supplied volumes are not DATADISK attached to the VM: " + sb);
94829482 }
94839483 }
94849484
94859485 private void validateVolumes(List<VolumeVO> volumes) {
94869486
94879487 for (VolumeVO volume : volumes) {
94889488 if (!(volume.getVolumeType() == Volume.Type.ROOT || volume.getVolumeType() == Volume.Type.DATADISK)) {
9489- throw new InvalidParameterValueException("Please specify volume of type " + Volume.Type.DATADISK.toString() + " or " + Volume.Type.ROOT.toString() );
9489+ throw new InvalidParameterValueException("Please specify volume of type " + Volume.Type.DATADISK + " or " + Volume.Type.ROOT);
94909490 }
94919491 if (volume.isDeleteProtection()) {
94929492 throw new InvalidParameterValueException(String.format(
@@ -9580,7 +9580,7 @@ public UserVm importVM(final DataCenter zone, final Host host, final VirtualMach
95809580
95819581 final String uuidName = _uuidMgr.generateUuid(UserVm.class, null);
95829582 final Host lastHost = powerState != VirtualMachine.PowerState.PowerOn ? host : null;
9583- final Boolean dynamicScalingEnabled = checkIfDynamicScalingCanBeEnabled(null, serviceOffering, template, zone.getId());
9583+ final boolean dynamicScalingEnabled = checkIfDynamicScalingCanBeEnabled(null, serviceOffering, template, zone.getId());
95849584 return commitUserVm(true, zone, host, lastHost, template, hostName, displayName, owner,
95859585 null, null, userData, null, null, isDisplayVm, keyboard,
95869586 accountId, userId, serviceOffering, template.getFormat().equals(ImageFormat.ISO), guestOsId, sshPublicKeys, networkNicMap,
@@ -9642,7 +9642,7 @@ private void updateDetailsWithRootDiskAttributes(Map<String, String> details, Vm
96429642 }
96439643
96449644 private void checkRootDiskSizeAgainstBackup(Long instanceVolumeSize,DiskOffering rootDiskOffering, Long backupVolumeSize) {
9645- Long instanceRootDiskSize = rootDiskOffering.isCustomized() ? instanceVolumeSize : rootDiskOffering.getDiskSize() / GiB_TO_BYTES;
9645+ long instanceRootDiskSize = rootDiskOffering.isCustomized() ? instanceVolumeSize : rootDiskOffering.getDiskSize() / GiB_TO_BYTES;
96469646 if (instanceRootDiskSize < backupVolumeSize) {
96479647 throw new InvalidParameterValueException(
96489648 String.format("Instance volume root disk size %d[GiB] cannot be less than the backed-up volume size %d[GiB].",
@@ -9719,7 +9719,7 @@ public UserVm allocateVMFromBackup(CreateVMFromBackupCmd cmd) throws Insufficien
97199719 Long size = cmd.getSize();
97209720
97219721 Long diskOfferingId = cmd.getDiskOfferingId();
9722- Boolean isIso = template.getFormat().equals(ImageFormat.ISO);
9722+ boolean isIso = template.getFormat().equals(ImageFormat.ISO);
97239723 if (diskOfferingId != null) {
97249724 if (!isIso) {
97259725 throw new InvalidParameterValueException(ApiConstants.DISK_OFFERING_ID + " parameter is supported for creating instance from backup only for ISO. For creating VMs with templates, please use the parameter " + ApiConstants.DATADISKS_DETAILS);
0 commit comments