Skip to content

Commit dad0ff4

Browse files
committed
Merge branch 'improve-logs-in-avoid-planner' into '4.16.0.0-scclouds'
Improve logs in avoid planner Closes apache#558 See merge request scclouds/scclouds!223
2 parents 3559588 + 9c89062 commit dad0ff4

File tree

5 files changed

+444
-364
lines changed

5 files changed

+444
-364
lines changed

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121
import java.util.HashSet;
2222
import java.util.Set;
2323

24+
import org.apache.log4j.Logger;
25+
2426
import com.cloud.dc.DataCenter;
2527
import com.cloud.dc.Pod;
28+
import com.cloud.exception.CloudException;
2629
import com.cloud.exception.InsufficientCapacityException;
2730
import com.cloud.exception.InsufficientServerCapacityException;
2831
import com.cloud.exception.ResourceUnavailableException;
@@ -75,7 +78,7 @@ public enum PlannerResourceUsage {
7578

7679
public static class ExcludeList implements Serializable {
7780
private static final long serialVersionUID = -482175549460148301L;
78-
81+
private static final Logger LOGGER = Logger.getLogger(ExcludeList.class);
7982
private Set<Long> _dcIds;
8083
private Set<Long> _podIds;
8184
private Set<Long> _clusterIds;
@@ -104,13 +107,27 @@ public ExcludeList(Set<Long> dcIds, Set<Long> podIds, Set<Long> clusterIds, Set<
104107
}
105108
}
106109

110+
private void logAvoid(Class<?> scope, CloudException e) {
111+
try {
112+
Long id = null;
113+
if (e instanceof InsufficientCapacityException) {
114+
id = ((InsufficientCapacityException) e).getId();
115+
} else {
116+
id = ((ResourceUnavailableException) e).getResourceId();
117+
}
118+
LOGGER.trace(String.format("Adding %s [%s] to the avoid set due to [%s].", scope.getSimpleName(), id, e.getMessage()));
119+
} catch (Exception ex) {
120+
LOGGER.trace(String.format("Failed to log avoided component due to [%s].", ex.getMessage()));
121+
}
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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@
151151
import com.cloud.deploy.DeploymentPlanner;
152152
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
153153
import com.cloud.deploy.DeploymentPlanningManager;
154+
import com.cloud.deploy.DeploymentPlanningManagerImpl;
154155
import com.cloud.deployasis.dao.UserVmDeployAsIsDetailsDao;
155156
import com.cloud.event.EventTypes;
156157
import com.cloud.event.UsageEventUtils;
@@ -220,6 +221,7 @@
220221
import com.cloud.uservm.UserVm;
221222
import com.cloud.utils.DateUtil;
222223
import com.cloud.utils.Journal;
224+
import com.cloud.utils.LogUtils;
223225
import com.cloud.utils.Pair;
224226
import com.cloud.utils.Predicate;
225227
import com.cloud.utils.ReflectionUse;
@@ -1022,6 +1024,7 @@ private void setupAgentSecurity(final Host vmHost, final Map<String, String> ssh
10221024
public void orchestrateStart(final String vmUuid, final Map<VirtualMachineProfile.Param, Object> params, final DeploymentPlan planToDeploy, final DeploymentPlanner planner)
10231025
throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
10241026

1027+
s_logger.debug(LogUtils.logGsonWithoutException("Trying to start VM [%s] using plan [%s] and planner [%s].", vmUuid, planToDeploy, planner));
10251028
final CallContext cctxt = CallContext.current();
10261029
final Account account = cctxt.getCallingAccount();
10271030
final User caller = cctxt.getCallingUser();
@@ -1045,10 +1048,7 @@ public void orchestrateStart(final String vmUuid, final Map<VirtualMachineProfil
10451048

10461049
DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), vm.getPodIdToDeployIn(), null, null, null, null, ctx);
10471050
if (planToDeploy != null && planToDeploy.getDataCenterId() != 0) {
1048-
if (s_logger.isDebugEnabled()) {
1049-
s_logger.debug("advanceStart: DeploymentPlan is provided, using dcId:" + planToDeploy.getDataCenterId() + ", podId: " + planToDeploy.getPodId() +
1050-
", clusterId: " + planToDeploy.getClusterId() + ", hostId: " + planToDeploy.getHostId() + ", poolId: " + planToDeploy.getPoolId());
1051-
}
1051+
s_logger.debug(DeploymentPlanningManagerImpl.logDeploymentWithoutException((VirtualMachine) vm, planToDeploy, planToDeploy.getAvoids(), (DeploymentPlanner) plan));
10521052
plan =
10531053
new DataCenterDeployment(planToDeploy.getDataCenterId(), planToDeploy.getPodId(), planToDeploy.getClusterId(), planToDeploy.getHostId(),
10541054
planToDeploy.getPoolId(), planToDeploy.getPhysicalNetworkId(), ctx);
@@ -1069,13 +1069,11 @@ public void orchestrateStart(final String vmUuid, final Map<VirtualMachineProfil
10691069

10701070
if (planToDeploy != null) {
10711071
avoids = planToDeploy.getAvoids();
1072+
s_logger.debug(LogUtils.logGsonWithoutException("Avoiding components [%s] in deployment of VM [%s].", avoids, vmUuid));
10721073
}
10731074
if (avoids == null) {
10741075
avoids = new ExcludeList();
10751076
}
1076-
if (s_logger.isDebugEnabled()) {
1077-
s_logger.debug("Deploy avoids pods: " + avoids.getPodsToAvoid() + ", clusters: " + avoids.getClustersToAvoid() + ", hosts: " + avoids.getHostsToAvoid());
1078-
}
10791077

10801078
boolean planChangedByVolume = false;
10811079
boolean reuseVolume = true;

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

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

2828
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
29+
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
2930
import org.apache.log4j.Logger;
3031
import org.springframework.stereotype.Component;
3132

@@ -205,6 +206,8 @@ public List<Host> allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan pla
205206
// add all hosts that we are not considering to the avoid list
206207
List<HostVO> allhostsInCluster = _hostDao.listAllUpAndEnabledNonHAHosts(type, clusterId, podId, dcId, null);
207208
allhostsInCluster.removeAll(clusterHosts);
209+
s_logger.debug(String.format("Adding hosts [%s] to the avoid set because these hosts does not support HA.",
210+
ReflectionToStringBuilderUtils.reflectOnlySelectedFields(allhostsInCluster, "uuid", "name")));
208211
for (HostVO host : allhostsInCluster) {
209212
avoid.addHost(host.getId());
210213
}
@@ -318,10 +321,8 @@ protected List<Host> allocateTo(DeploymentPlan plan, ServiceOffering offering, V
318321

319322
//find number of guest VMs occupying capacity on this host.
320323
if (_capacityMgr.checkIfHostReachMaxGuestLimit(host)) {
321-
if (s_logger.isDebugEnabled()) {
322-
s_logger.debug("Host name: " + host.getName() + ", hostId: " + host.getId() +
323-
" already has max Running VMs(count includes system VMs), skipping this and trying other available hosts");
324-
}
324+
s_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.",
325+
ReflectionToStringBuilderUtils.reflectOnlySelectedFields(host, "uuid", "name")));
325326
avoid.addHost(host.getId());
326327
continue;
327328
}
@@ -330,7 +331,8 @@ protected List<Host> allocateTo(DeploymentPlan plan, ServiceOffering offering, V
330331
if ((offeringDetails = _serviceOfferingDetailsDao.findDetail(serviceOfferingId, GPU.Keys.vgpuType.toString())) != null) {
331332
ServiceOfferingDetailsVO groupName = _serviceOfferingDetailsDao.findDetail(serviceOfferingId, GPU.Keys.pciDevice.toString());
332333
if(!_resourceMgr.isGPUDeviceAvailable(host.getId(), groupName.getValue(), offeringDetails.getValue())){
333-
s_logger.info("Host name: " + host.getName() + ", hostId: "+ host.getId() +" does not have required GPU devices available");
334+
s_logger.debug(String.format("Adding host [%s] to avoid set, because this host does not have required GPU devices available.",
335+
ReflectionToStringBuilderUtils.reflectOnlySelectedFields(host, "uuid", "name")));
334336
avoid.addHost(host.getId());
335337
continue;
336338
}

0 commit comments

Comments
 (0)