Skip to content

Commit 6f27b1f

Browse files
SadiJrSadiJrGaOrtigaJoaoJandre
authored
Improve logs when adding components to avoid set (#7214)
Co-authored-by: SadiJr <sadi@scclouds.com.br> Co-authored-by: GaOrtiga <49285692+GaOrtiga@users.noreply.github.com> Co-authored-by: João Jandre <48719461+JoaoJandre@users.noreply.github.com>
1 parent c8a4575 commit 6f27b1f

File tree

5 files changed

+455
-384
lines changed

5 files changed

+455
-384
lines changed

api/src/main/java/com/cloud/deploy/DeploymentPlanner.java

+21-3
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@
2121
import java.util.HashSet;
2222
import java.util.Set;
2323

24+
import org.apache.logging.log4j.Logger;
25+
import org.apache.logging.log4j.LogManager;
26+
2427
import com.cloud.dc.DataCenter;
2528
import com.cloud.dc.Pod;
29+
import com.cloud.exception.CloudException;
2630
import com.cloud.exception.InsufficientCapacityException;
2731
import com.cloud.exception.InsufficientServerCapacityException;
2832
import com.cloud.exception.ResourceUnavailableException;
@@ -75,7 +79,7 @@ public enum PlannerResourceUsage {
7579

7680
public static class ExcludeList implements Serializable {
7781
private static final long serialVersionUID = -482175549460148301L;
78-
82+
protected static Logger LOGGER = LogManager.getLogger(ExcludeList.class);
7983
private Set<Long> _dcIds;
8084
private Set<Long> _podIds;
8185
private Set<Long> _clusterIds;
@@ -104,13 +108,26 @@ public ExcludeList(Set<Long> dcIds, Set<Long> podIds, Set<Long> clusterIds, Set<
104108
}
105109
}
106110

111+
private void logAvoid(Class<?> scope, CloudException e) {
112+
Long id = null;
113+
if (e instanceof InsufficientCapacityException) {
114+
id = ((InsufficientCapacityException) e).getId();
115+
} else if (e instanceof ResourceUnavailableException) {
116+
id = ((ResourceUnavailableException) e).getResourceId();
117+
} else {
118+
LOGGER.debug("Failed to log avoided component due to unexpected exception type [{}].", e.getMessage());
119+
return;
120+
}
121+
LOGGER.debug("Adding {} [{}] to the avoid set due to [{}].", scope.getSimpleName(), id, e.getMessage());
122+
}
123+
107124
public boolean add(InsufficientCapacityException e) {
108125
Class<?> scope = e.getScope();
109126

110127
if (scope == null) {
111128
return false;
112129
}
113-
130+
logAvoid(scope, e);
114131
if (Host.class.isAssignableFrom(scope)) {
115132
addHost(e.getId());
116133
} else if (Pod.class.isAssignableFrom(scope)) {
@@ -128,13 +145,14 @@ public boolean add(InsufficientCapacityException e) {
128145
return true;
129146
}
130147

148+
131149
public boolean add(ResourceUnavailableException e) {
132150
Class<?> scope = e.getScope();
133151

134152
if (scope == null) {
135153
return false;
136154
}
137-
155+
logAvoid(scope, e);
138156
if (Host.class.isAssignableFrom(scope)) {
139157
addHost(e.getResourceId());
140158
} else if (Pod.class.isAssignableFrom(scope)) {

engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@
165165
import com.cloud.deploy.DeploymentPlanner;
166166
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
167167
import com.cloud.deploy.DeploymentPlanningManager;
168+
import com.cloud.deploy.DeploymentPlanningManagerImpl;
168169
import com.cloud.deployasis.dao.UserVmDeployAsIsDetailsDao;
169170
import com.cloud.event.EventTypes;
170171
import com.cloud.event.UsageEventUtils;
@@ -237,6 +238,7 @@
237238
import com.cloud.uservm.UserVm;
238239
import com.cloud.utils.DateUtil;
239240
import com.cloud.utils.Journal;
241+
import com.cloud.utils.LogUtils;
240242
import com.cloud.utils.Pair;
241243
import com.cloud.utils.Predicate;
242244
import com.cloud.utils.ReflectionUse;
@@ -1093,6 +1095,7 @@ protected void checkAndAttemptMigrateVmAcrossCluster(final VMInstanceVO vm, fina
10931095
public void orchestrateStart(final String vmUuid, final Map<VirtualMachineProfile.Param, Object> params, final DeploymentPlan planToDeploy, final DeploymentPlanner planner)
10941096
throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
10951097

1098+
logger.debug(() -> LogUtils.logGsonWithoutException("Trying to start VM [%s] using plan [%s] and planner [%s].", vmUuid, planToDeploy, planner));
10961099
final CallContext cctxt = CallContext.current();
10971100
final Account account = cctxt.getCallingAccount();
10981101
final User caller = cctxt.getCallingUser();
@@ -1116,10 +1119,8 @@ public void orchestrateStart(final String vmUuid, final Map<VirtualMachineProfil
11161119

11171120
DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), vm.getPodIdToDeployIn(), null, null, null, null, ctx);
11181121
if (planToDeploy != null && planToDeploy.getDataCenterId() != 0) {
1119-
if (logger.isDebugEnabled()) {
1120-
logger.debug("advanceStart: DeploymentPlan is provided, using dcId:" + planToDeploy.getDataCenterId() + ", podId: " + planToDeploy.getPodId() +
1121-
", clusterId: " + planToDeploy.getClusterId() + ", hostId: " + planToDeploy.getHostId() + ", poolId: " + planToDeploy.getPoolId());
1122-
}
1122+
VMInstanceVO finalVm = vm;
1123+
logger.debug(() -> DeploymentPlanningManagerImpl.logDeploymentWithoutException(finalVm, planToDeploy, planToDeploy.getAvoids(), planner));
11231124
plan =
11241125
new DataCenterDeployment(planToDeploy.getDataCenterId(), planToDeploy.getPodId(), planToDeploy.getClusterId(), planToDeploy.getHostId(),
11251126
planToDeploy.getPoolId(), planToDeploy.getPhysicalNetworkId(), ctx);
@@ -1140,13 +1141,12 @@ public void orchestrateStart(final String vmUuid, final Map<VirtualMachineProfil
11401141

11411142
if (planToDeploy != null) {
11421143
avoids = planToDeploy.getAvoids();
1144+
ExcludeList finalAvoids = avoids;
1145+
logger.debug(() -> LogUtils.logGsonWithoutException("Avoiding components [%s] in deployment of VM [%s].", finalAvoids, vmUuid));
11431146
}
11441147
if (avoids == null) {
11451148
avoids = new ExcludeList();
11461149
}
1147-
if (logger.isDebugEnabled()) {
1148-
logger.debug("Deploy avoids pods: " + avoids.getPodsToAvoid() + ", clusters: " + avoids.getClustersToAvoid() + ", hosts: " + avoids.getHostsToAvoid());
1149-
}
11501150

11511151
boolean planChangedByVolume = false;
11521152
boolean reuseVolume = true;

server/src/main/java/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import com.cloud.utils.exception.CloudRuntimeException;
2929
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
30+
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
3031
import org.springframework.stereotype.Component;
3132

3233
import com.cloud.agent.manager.allocator.HostAllocator;
@@ -210,6 +211,10 @@ public List<Host> allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan pla
210211
// add all hosts that we are not considering to the avoid list
211212
List<HostVO> allhostsInCluster = _hostDao.listAllUpAndEnabledNonHAHosts(type, clusterId, podId, dcId, null);
212213
allhostsInCluster.removeAll(clusterHosts);
214+
215+
logger.debug(() -> String.format("Adding hosts [%s] to the avoid set because these hosts do not support HA.",
216+
ReflectionToStringBuilderUtils.reflectOnlySelectedFields(allhostsInCluster, "uuid", "name")));
217+
213218
for (HostVO host : allhostsInCluster) {
214219
avoid.addHost(host.getId());
215220
}
@@ -325,10 +330,8 @@ protected List<Host> allocateTo(DeploymentPlan plan, ServiceOffering offering, V
325330

326331
//find number of guest VMs occupying capacity on this host.
327332
if (_capacityMgr.checkIfHostReachMaxGuestLimit(host)) {
328-
if (logger.isDebugEnabled()) {
329-
logger.debug("Host name: " + host.getName() + ", hostId: " + host.getId() +
330-
" already has max Running VMs(count includes system VMs), skipping this and trying other available hosts");
331-
}
333+
logger.debug(() -> String.format("Adding host [%s] to the avoid set because this host already has the max number of running (user and/or system) VMs.",
334+
ReflectionToStringBuilderUtils.reflectOnlySelectedFields(host, "uuid", "name")));
332335
avoid.addHost(host.getId());
333336
continue;
334337
}
@@ -337,7 +340,8 @@ protected List<Host> allocateTo(DeploymentPlan plan, ServiceOffering offering, V
337340
if ((offeringDetails = _serviceOfferingDetailsDao.findDetail(serviceOfferingId, GPU.Keys.vgpuType.toString())) != null) {
338341
ServiceOfferingDetailsVO groupName = _serviceOfferingDetailsDao.findDetail(serviceOfferingId, GPU.Keys.pciDevice.toString());
339342
if(!_resourceMgr.isGPUDeviceAvailable(host.getId(), groupName.getValue(), offeringDetails.getValue())){
340-
logger.info("Host name: " + host.getName() + ", hostId: "+ host.getId() +" does not have required GPU devices available");
343+
logger.debug(String.format("Adding host [%s] to avoid set, because this host does not have required GPU devices available.",
344+
ReflectionToStringBuilderUtils.reflectOnlySelectedFields(host, "uuid", "name")));
341345
avoid.addHost(host.getId());
342346
continue;
343347
}

0 commit comments

Comments
 (0)