Skip to content

Commit 2583d86

Browse files
author
Daan Hoogland
committed
co-pilot's comments addressed
1 parent d1067a6 commit 2583d86

2 files changed

Lines changed: 26 additions & 34 deletions

File tree

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

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,10 +1146,14 @@ private UserVm rebootVirtualMachine(long vmId, boolean enterSetup, boolean force
11461146
return null;
11471147
}
11481148

1149-
if (vm.getState() != State.Running || vm.getHostId() == null) {
1149+
if (vm.getState() != State.Running) {
11501150
logger.error("Vm {} is not in Running state, failed to reboot", vm);
11511151
return null;
11521152
}
1153+
if ( null == vm.getHostId() ) {
1154+
logger.error("Vm {} , is in state 'Running', but doesn't have a host id, failed to reboot", vm);
1155+
return null;
1156+
}
11531157

11541158
collectVmDiskAndNetworkStatistics(vm, State.Running);
11551159

@@ -1160,9 +1164,9 @@ private UserVm rebootVirtualMachine(long vmId, boolean enterSetup, boolean force
11601164
try {
11611165
startRoutersIfNeeded(vm, vmId);
11621166
} catch (ConcurrentOperationException e) {
1163-
throw new CloudRuntimeException("Concurrent operations on starting router. " + e);
1167+
throw new CloudRuntimeException("Concurrent operations on starting router. ", e);
11641168
} catch (Exception ex) {
1165-
throw new CloudRuntimeException("Router start failed due to" + ex);
1169+
throw new CloudRuntimeException("Router start failed due to", ex);
11661170
} finally {
11671171
if (logger.isInfoEnabled()) {
11681172
logger.info("Rebooting vm {}{}.", vm, enterSetup ? " entering hardware setup menu" : " as is");
@@ -1190,15 +1194,16 @@ private void startRoutersIfNeeded(UserVmVO vm, long vmId) throws ConcurrentOpera
11901194

11911195
// List all networks of vm
11921196
List<Long> vmNetworks = _vmNetworkMapDao.getNetworks(vmId);
1193-
List<DomainRouterVO> routers = new ArrayList<>();
1194-
// List the stopped routers
1197+
Map<Long, DomainRouterVO> routersById = new LinkedHashMap<>();
11951198
for (long vmNetworkId : vmNetworks) {
1196-
List<DomainRouterVO> router = _routerDao.listStopped(vmNetworkId);
1197-
routers.addAll(router);
1199+
List<DomainRouterVO> routers = _routerDao.listStopped(vmNetworkId);
1200+
for (DomainRouterVO router : routers) {
1201+
routersById.putIfAbsent(router.getId(), router);
1202+
}
11981203
}
11991204

12001205
// Safe to start the stopped router serially, consistent with deploy/start behavior
1201-
for (DomainRouterVO routerToStart : routers) {
1206+
for (DomainRouterVO routerToStart : routersById.values()) {
12021207
logger.warn("Trying to start router {} as part of vm: {} reboot", routerToStart, vm);
12031208
_virtualNetAppliance.startRouter(routerToStart.getId(), true);
12041209
}
@@ -2477,10 +2482,7 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
24772482

24782483
_executor = Executors.newScheduledThreadPool(wrks, new NamedThreadFactory("UserVm-Scavenger"));
24792484

2480-
String vmIpWorkers = configs.get(VmIpFetchTaskWorkers.value().toString());
2481-
int vmipwrks = NumbersUtil.parseInt(vmIpWorkers, 10);
2482-
2483-
_vmIpFetchExecutor = Executors.newScheduledThreadPool(vmipwrks, new NamedThreadFactory("UserVm-ipfetch"));
2485+
_vmIpFetchExecutor = Executors.newScheduledThreadPool(VmIpFetchTaskWorkers.value(), new NamedThreadFactory("UserVm-ipfetch"));
24842486

24852487
String aggregationRange = configs.get("usage.stats.job.aggregation.range");
24862488
int _usageAggregationRange = NumbersUtil.parseInt(aggregationRange, 1440);
@@ -2799,12 +2801,10 @@ protected void runInContext() {
27992801
if (scanLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION)) {
28002802
try {
28012803
List<UserVmVO> vms = _vmDao.findDestroyedVms(new Date(System.currentTimeMillis() - ((long)_expungeDelay << 10)));
2802-
if (logger.isInfoEnabled()) {
2803-
if (vms.isEmpty()) {
2804-
logger.trace("Found no Instances to expunge.");
2805-
} else {
2806-
logger.info("Found " + vms.size() + " Instances to expunge.");
2807-
}
2804+
if (vms.isEmpty()) {
2805+
logger.trace("Found no Instances to expunge.");
2806+
} else {
2807+
logger.info("Found " + vms.size() + " Instances to expunge.");
28082808
}
28092809
for (UserVmVO vm : vms) {
28102810
try {
@@ -2875,7 +2875,7 @@ protected void verifyVmLimits(UserVmVO vmInstance, Map<String, String> details)
28752875
}
28762876
if (newGpu > currentGpu) {
28772877
_resourceLimitMgr.incrementVmGpuResourceCount(owner.getAccountId(), vmInstance.isDisplay(), svcOffering, template, newGpu - currentGpu);
2878-
} else if (newGpu > 0 && currentGpu > newGpu){
2878+
} else if (currentGpu > newGpu) {
28792879
_resourceLimitMgr.decrementVmGpuResourceCount(owner.getAccountId(), vmInstance.isDisplay(), svcOffering, template, currentGpu - newGpu);
28802880
}
28812881
} catch (ResourceAllocationException e) {
@@ -3144,9 +3144,8 @@ private void generateNetworkUsageForVm(VirtualMachine vm, boolean isDisplay, Str
31443144
NetworkVO network = _networkDao.findById(nic.getNetworkId());
31453145
long isDefault = (nic.isDefaultNic()) ? 1 : 0;
31463146
UsageEventUtils.publishUsageEvent(eventType, vm.getAccountId(), vm.getDataCenterId(), vm.getId(),
3147-
Long.toString(nic.getId()), network.getNetworkOfferingId(), null, isDefault, vm.getClass().getName(), vm.getUuid(), true);
3147+
Long.toString(nic.getId()), network.getNetworkOfferingId(), null, isDefault, vm.getClass().getName(), vm.getUuid(), isDisplay);
31483148
}
3149-
31503149
}
31513150

31523151
@Override
@@ -3482,7 +3481,7 @@ public UserVm rebootVirtualMachine(RebootVMCmd cmd) throws InsufficientCapacityE
34823481
throw new InvalidParameterValueException("Booting into a hardware setup menu is not implemented on " + vmInstance.getHypervisorType());
34833482
}
34843483

3485-
UserVm userVm = rebootVirtualMachine(vmId, cmd.getBootIntoSetup(), cmd.isForced());
3484+
UserVm userVm = rebootVirtualMachine(vmId, enterSetup, cmd.isForced());
34863485
if (userVm != null ) {
34873486
// update the vmIdCountMap if the vm is in advanced shared network with out services
34883487
final List<NicVO> nics = _nicDao.listByVmId(vmId);
@@ -4558,11 +4557,6 @@ private UserVm getUncheckedUserVmResource(DataCenter zone, String hostName, Stri
45584557

45594558
long id = _vmDao.getNextInSequence(Long.class, "id");
45604559

4561-
if (hostName != null) {
4562-
// Check is hostName is RFC compliant
4563-
checkNameForRFCCompliance(hostName);
4564-
}
4565-
45664560
String instanceName = null;
45674561
String instanceSuffix = _instance;
45684562
String uuidName = _uuidMgr.generateUuid(UserVm.class, customId);
@@ -4700,7 +4694,9 @@ protected long configureCustomRootDiskSize(Map<String, String> customParameters,
47004694
if (rootDiskSize <= 0) {
47014695
throw new InvalidParameterValueException("Root disk size should be a positive number.");
47024696
}
4703-
rootDiskSize = (rootDiskSizeCustomParam == null ? 0 : rootDiskSizeCustomParam) * GiB_TO_BYTES;
4697+
if (rootDiskSizeCustomParam != null) {
4698+
rootDiskSize = rootDiskSizeCustomParam * GiB_TO_BYTES;
4699+
}
47044700
_volumeService.validateVolumeSizeInBytes(rootDiskSize);
47054701
return rootDiskSize;
47064702
} else {
@@ -5912,7 +5908,8 @@ protected String getCurrentVmPasswordOrDefineNewPassword(String newPassword, Use
59125908
/**
59135909
* Create or overwrite a parameter in the list
59145910
* @param params the list of parameters
5915-
* @param parameter the parameter to creat/overwrite
5911+
* @param parameterMap the original map of parameters to take the existing parameters from if params is null
5912+
* @param parameter the parameter to create or overwrite
59165913
* @param parameterValue the value to give to the parameter
59175914
* @return the resulting updated list of parameters
59185915
*/

utils/src/main/java/com/cloud/utils/StringUtils.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,4 @@ public static String getFirstValueFromCommaSeparatedString(String inputString) {
438438

439439
return null;
440440
}
441-
442-
public static boolean isBlank(String str) {
443-
return org.apache.commons.lang3.StringUtils.isBlank(str);
444-
}
445-
446441
}

0 commit comments

Comments
 (0)