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)
This commit is contained in:
Daan Hoogland 2021-12-22 18:03:04 +01:00
commit 2a331b3742
4 changed files with 27 additions and 9 deletions

View File

@ -26,6 +26,7 @@ import java.util.Map;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import com.cloud.capacity.CapacityVO;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.Configurable;
@ -353,12 +354,16 @@ public class FirstFitPlanner extends AdapterBase implements DeploymentClusterPla
return;
}
String configurationName = ClusterCPUCapacityDisableThreshold.key();
float configurationValue = ClusterCPUCapacityDisableThreshold.value();
if (capacity == Capacity.CAPACITY_TYPE_CPU) {
clustersCrossingThreshold =
capacityDao.listClustersCrossingThreshold(capacity, plan.getDataCenterId(), ClusterCPUCapacityDisableThreshold.key(), cpu_requested);
} else if (capacity == Capacity.CAPACITY_TYPE_MEMORY) {
clustersCrossingThreshold =
capacityDao.listClustersCrossingThreshold(capacity, plan.getDataCenterId(), ClusterMemoryCapacityDisableThreshold.key(), ram_requested);
configurationName = ClusterMemoryCapacityDisableThreshold.key();
configurationValue = ClusterMemoryCapacityDisableThreshold.value();
}
if (clustersCrossingThreshold != null && clustersCrossingThreshold.size() != 0) {
@ -367,8 +372,11 @@ public class FirstFitPlanner extends AdapterBase implements DeploymentClusterPla
// Remove clusters crossing disabled threshold
clusterListForVmAllocation.removeAll(clustersCrossingThreshold);
s_logger.debug("Cannot allocate cluster list " + clustersCrossingThreshold.toString() + " for vm creation since their allocated percentage" +
" crosses the disable capacity threshold defined at each cluster/ at global value for capacity Type : " + capacity + ", skipping these clusters");
String warnMessageForClusterReachedCapacityThreshold = String.format(
"Cannot allocate cluster list %s for VM creation since their allocated percentage crosses the disable capacity threshold defined at each cluster at"
+ " Global Settings Configuration [name: %s, value: %s] for capacity Type : %s, skipping these clusters", clustersCrossingThreshold.toString(),
configurationName, String.valueOf(configurationValue), CapacityVO.getCapacityName(capacity));
s_logger.warn(warnMessageForClusterReachedCapacityThreshold);
}
}

View File

@ -1146,7 +1146,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
final SearchBuilder<ClusterVO> sb = _clusterDao.createSearchBuilder();
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ);
sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
sb.and("hypervisorType", sb.entity().getHypervisorType(), SearchCriteria.Op.EQ);
@ -1159,7 +1159,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
}
if (name != null) {
sc.setParameters("name", "%" + name + "%");
sc.setParameters("name", name);
}
if (podId != null) {

View File

@ -110,6 +110,9 @@ public interface UserVmManager extends UserVmService {
Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> startVirtualMachine(long vmId, Long podId, Long clusterId, Long hostId, Map<VirtualMachineProfile.Param, Object> additionalParams, String deploymentPlannerToUse)
throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException;
Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> startVirtualMachine(long vmId, Long podId, Long clusterId, Long hostId, Map<VirtualMachineProfile.Param, Object> additionalParams, String deploymentPlannerToUse, boolean isExplicitHost)
throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException;
boolean upgradeVirtualMachine(Long id, Long serviceOfferingId, Map<String, String> customParameters) throws ResourceUnavailableException,
ConcurrentOperationException, ManagementServerException,
VirtualMachineMigrationException;

View File

@ -1081,7 +1081,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
params = new HashMap();
params.put(VirtualMachineProfile.Param.BootIntoSetup, Boolean.TRUE);
}
return startVirtualMachine(vmId, null, null, hostId, params, null).first();
return startVirtualMachine(vmId, null, null, hostId, params, null, false).first();
}
} catch (ResourceUnavailableException e) {
throw new CloudRuntimeException("Unable to reboot the VM: " + vmId, e);
@ -5068,6 +5068,13 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
public Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> startVirtualMachine(long vmId, Long podId, Long clusterId, Long hostId,
Map<VirtualMachineProfile.Param, Object> additionalParams, String deploymentPlannerToUse)
throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException {
return startVirtualMachine(vmId, podId, clusterId, hostId, additionalParams, deploymentPlannerToUse, true);
}
@Override
public Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> startVirtualMachine(long vmId, Long podId, Long clusterId, Long hostId,
Map<VirtualMachineProfile.Param, Object> additionalParams, String deploymentPlannerToUse, boolean isExplicitHost)
throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException {
// Input validation
final Account callerAccount = CallContext.current().getCallingAccount();
UserVO callerUser = _userDao.findById(CallContext.current().getCallingUserId());
@ -5123,7 +5130,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
boolean isRootAdmin = _accountService.isRootAdmin(callerAccount.getId());
Pod destinationPod = getDestinationPod(podId, isRootAdmin);
Cluster destinationCluster = getDestinationCluster(clusterId, isRootAdmin);
Host destinationHost = getDestinationHost(hostId, isRootAdmin);
Host destinationHost = getDestinationHost(hostId, isRootAdmin, isExplicitHost);
DataCenterDeployment plan = null;
boolean deployOnGivenHost = false;
if (destinationHost != null) {
@ -5276,10 +5283,10 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
return destinationCluster;
}
private Host getDestinationHost(Long hostId, boolean isRootAdmin) {
private Host getDestinationHost(Long hostId, boolean isRootAdmin, boolean isExplicitHost) {
Host destinationHost = null;
if (hostId != null) {
if (!isRootAdmin) {
if (isExplicitHost && !isRootAdmin) {
throw new PermissionDeniedException(
"Parameter " + ApiConstants.HOST_ID + " can only be specified by a Root Admin, permission denied");
}
@ -5622,7 +5629,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
boolean isRootAdmin = _accountService.isRootAdmin(callerId);
Long hostId = cmd.getHostId();
getDestinationHost(hostId, isRootAdmin);
getDestinationHost(hostId, isRootAdmin, true);
String ipAddress = cmd.getIpAddress();
String ip6Address = cmd.getIp6Address();