Skip to content

Commit 2a331b3

Browse files
author
Daan Hoogland
committed
Merge release branch 4.16 to main
* 4.16: Allow force reboot VM from user account, to start VM on the same host (#5791) api: Fix search cluster by name (#5782) Enhance log message in FirstFitPlanner (#5762)
2 parents 01f1aae + 39e41f6 commit 2a331b3

4 files changed

Lines changed: 27 additions & 9 deletions

File tree

server/src/main/java/com/cloud/deploy/FirstFitPlanner.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import javax.inject.Inject;
2727
import javax.naming.ConfigurationException;
2828

29+
import com.cloud.capacity.CapacityVO;
2930
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
3031
import org.apache.cloudstack.framework.config.ConfigKey;
3132
import org.apache.cloudstack.framework.config.Configurable;
@@ -353,12 +354,16 @@ protected void removeClustersCrossingThreshold(List<Long> clusterListForVmAlloca
353354
return;
354355
}
355356

357+
String configurationName = ClusterCPUCapacityDisableThreshold.key();
358+
float configurationValue = ClusterCPUCapacityDisableThreshold.value();
356359
if (capacity == Capacity.CAPACITY_TYPE_CPU) {
357360
clustersCrossingThreshold =
358361
capacityDao.listClustersCrossingThreshold(capacity, plan.getDataCenterId(), ClusterCPUCapacityDisableThreshold.key(), cpu_requested);
359362
} else if (capacity == Capacity.CAPACITY_TYPE_MEMORY) {
360363
clustersCrossingThreshold =
361364
capacityDao.listClustersCrossingThreshold(capacity, plan.getDataCenterId(), ClusterMemoryCapacityDisableThreshold.key(), ram_requested);
365+
configurationName = ClusterMemoryCapacityDisableThreshold.key();
366+
configurationValue = ClusterMemoryCapacityDisableThreshold.value();
362367
}
363368

364369
if (clustersCrossingThreshold != null && clustersCrossingThreshold.size() != 0) {
@@ -367,8 +372,11 @@ protected void removeClustersCrossingThreshold(List<Long> clusterListForVmAlloca
367372
// Remove clusters crossing disabled threshold
368373
clusterListForVmAllocation.removeAll(clustersCrossingThreshold);
369374

370-
s_logger.debug("Cannot allocate cluster list " + clustersCrossingThreshold.toString() + " for vm creation since their allocated percentage" +
371-
" crosses the disable capacity threshold defined at each cluster/ at global value for capacity Type : " + capacity + ", skipping these clusters");
375+
String warnMessageForClusterReachedCapacityThreshold = String.format(
376+
"Cannot allocate cluster list %s for VM creation since their allocated percentage crosses the disable capacity threshold defined at each cluster at"
377+
+ " Global Settings Configuration [name: %s, value: %s] for capacity Type : %s, skipping these clusters", clustersCrossingThreshold.toString(),
378+
configurationName, String.valueOf(configurationValue), CapacityVO.getCapacityName(capacity));
379+
s_logger.warn(warnMessageForClusterReachedCapacityThreshold);
372380
}
373381

374382
}

server/src/main/java/com/cloud/server/ManagementServerImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,7 @@ public Pair<List<? extends Cluster>, Integer> searchForClusters(final ListCluste
11461146

11471147
final SearchBuilder<ClusterVO> sb = _clusterDao.createSearchBuilder();
11481148
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
1149-
sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
1149+
sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
11501150
sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ);
11511151
sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
11521152
sb.and("hypervisorType", sb.entity().getHypervisorType(), SearchCriteria.Op.EQ);
@@ -1159,7 +1159,7 @@ public Pair<List<? extends Cluster>, Integer> searchForClusters(final ListCluste
11591159
}
11601160

11611161
if (name != null) {
1162-
sc.setParameters("name", "%" + name + "%");
1162+
sc.setParameters("name", name);
11631163
}
11641164

11651165
if (podId != null) {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> startVirtualMachine(lon
110110
Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> startVirtualMachine(long vmId, Long podId, Long clusterId, Long hostId, Map<VirtualMachineProfile.Param, Object> additionalParams, String deploymentPlannerToUse)
111111
throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException;
112112

113+
Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> startVirtualMachine(long vmId, Long podId, Long clusterId, Long hostId, Map<VirtualMachineProfile.Param, Object> additionalParams, String deploymentPlannerToUse, boolean isExplicitHost)
114+
throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException;
115+
113116
boolean upgradeVirtualMachine(Long id, Long serviceOfferingId, Map<String, String> customParameters) throws ResourceUnavailableException,
114117
ConcurrentOperationException, ManagementServerException,
115118
VirtualMachineMigrationException;

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ private UserVm forceRebootVirtualMachine(long vmId, long hostId, boolean enterSe
10811081
params = new HashMap();
10821082
params.put(VirtualMachineProfile.Param.BootIntoSetup, Boolean.TRUE);
10831083
}
1084-
return startVirtualMachine(vmId, null, null, hostId, params, null).first();
1084+
return startVirtualMachine(vmId, null, null, hostId, params, null, false).first();
10851085
}
10861086
} catch (ResourceUnavailableException e) {
10871087
throw new CloudRuntimeException("Unable to reboot the VM: " + vmId, e);
@@ -5068,6 +5068,13 @@ public Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> startVirtualMach
50685068
public Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> startVirtualMachine(long vmId, Long podId, Long clusterId, Long hostId,
50695069
Map<VirtualMachineProfile.Param, Object> additionalParams, String deploymentPlannerToUse)
50705070
throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException {
5071+
return startVirtualMachine(vmId, podId, clusterId, hostId, additionalParams, deploymentPlannerToUse, true);
5072+
}
5073+
5074+
@Override
5075+
public Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> startVirtualMachine(long vmId, Long podId, Long clusterId, Long hostId,
5076+
Map<VirtualMachineProfile.Param, Object> additionalParams, String deploymentPlannerToUse, boolean isExplicitHost)
5077+
throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException {
50715078
// Input validation
50725079
final Account callerAccount = CallContext.current().getCallingAccount();
50735080
UserVO callerUser = _userDao.findById(CallContext.current().getCallingUserId());
@@ -5123,7 +5130,7 @@ public Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> startVirtualMach
51235130
boolean isRootAdmin = _accountService.isRootAdmin(callerAccount.getId());
51245131
Pod destinationPod = getDestinationPod(podId, isRootAdmin);
51255132
Cluster destinationCluster = getDestinationCluster(clusterId, isRootAdmin);
5126-
Host destinationHost = getDestinationHost(hostId, isRootAdmin);
5133+
Host destinationHost = getDestinationHost(hostId, isRootAdmin, isExplicitHost);
51275134
DataCenterDeployment plan = null;
51285135
boolean deployOnGivenHost = false;
51295136
if (destinationHost != null) {
@@ -5276,10 +5283,10 @@ private Cluster getDestinationCluster(Long clusterId, boolean isRootAdmin) {
52765283
return destinationCluster;
52775284
}
52785285

5279-
private Host getDestinationHost(Long hostId, boolean isRootAdmin) {
5286+
private Host getDestinationHost(Long hostId, boolean isRootAdmin, boolean isExplicitHost) {
52805287
Host destinationHost = null;
52815288
if (hostId != null) {
5282-
if (!isRootAdmin) {
5289+
if (isExplicitHost && !isRootAdmin) {
52835290
throw new PermissionDeniedException(
52845291
"Parameter " + ApiConstants.HOST_ID + " can only be specified by a Root Admin, permission denied");
52855292
}
@@ -5622,7 +5629,7 @@ public UserVm createVirtualMachine(DeployVMCmd cmd) throws InsufficientCapacityE
56225629
boolean isRootAdmin = _accountService.isRootAdmin(callerId);
56235630

56245631
Long hostId = cmd.getHostId();
5625-
getDestinationHost(hostId, isRootAdmin);
5632+
getDestinationHost(hostId, isRootAdmin, true);
56265633

56275634
String ipAddress = cmd.getIpAddress();
56285635
String ip6Address = cmd.getIp6Address();

0 commit comments

Comments
 (0)