Skip to content

Commit b140003

Browse files
committed
Fix MaxCpuUsage placement strategy NPE
1 parent bfdaa75 commit b140003

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

docker/src/main/java/brooklyn/location/docker/strategy/MaxCpuUsagePlacementStrategy.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import brooklyn.config.ConfigKey;
2222
import brooklyn.entity.basic.ConfigKeys;
23+
import brooklyn.entity.basic.SoftwareProcess;
2324
import brooklyn.entity.container.docker.DockerHost;
2425
import brooklyn.entity.container.docker.DockerInfrastructure;
2526
import brooklyn.location.docker.DockerHostLocation;
@@ -52,7 +53,10 @@ public boolean apply(DockerHostLocation input) {
5253
}
5354
if (maxCpu == null) maxCpu = DEFAULT_MAX_CPU_USAGE;
5455

56+
Boolean serviceUp = input.getOwner().getAttribute(SoftwareProcess.SERVICE_UP);
5557
Double currentCpu = input.getOwner().getAttribute(DockerHost.CPU_USAGE);
58+
if (!Boolean.TRUE.equals(serviceUp) || currentCpu == null) return false; // reject
59+
5660
boolean accept = currentCpu < maxCpu;
5761
if (LOG.isDebugEnabled()) {
5862
LOG.debug("Location {} CPU usage is {}: {}", new Object[] { input, currentCpu, accept ? "accepted" : "rejected" });

0 commit comments

Comments
 (0)