From b14000367a428ea603380aa21b9694f676c178ff Mon Sep 17 00:00:00 2001 From: Andrew Kennedy Date: Thu, 4 Dec 2014 13:52:39 +0100 Subject: [PATCH] Fix MaxCpuUsage placement strategy NPE --- .../docker/strategy/MaxCpuUsagePlacementStrategy.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docker/src/main/java/brooklyn/location/docker/strategy/MaxCpuUsagePlacementStrategy.java b/docker/src/main/java/brooklyn/location/docker/strategy/MaxCpuUsagePlacementStrategy.java index 5b1c694b..a77286dc 100644 --- a/docker/src/main/java/brooklyn/location/docker/strategy/MaxCpuUsagePlacementStrategy.java +++ b/docker/src/main/java/brooklyn/location/docker/strategy/MaxCpuUsagePlacementStrategy.java @@ -20,6 +20,7 @@ import brooklyn.config.ConfigKey; import brooklyn.entity.basic.ConfigKeys; +import brooklyn.entity.basic.SoftwareProcess; import brooklyn.entity.container.docker.DockerHost; import brooklyn.entity.container.docker.DockerInfrastructure; import brooklyn.location.docker.DockerHostLocation; @@ -52,7 +53,10 @@ public boolean apply(DockerHostLocation input) { } if (maxCpu == null) maxCpu = DEFAULT_MAX_CPU_USAGE; + Boolean serviceUp = input.getOwner().getAttribute(SoftwareProcess.SERVICE_UP); Double currentCpu = input.getOwner().getAttribute(DockerHost.CPU_USAGE); + if (!Boolean.TRUE.equals(serviceUp) || currentCpu == null) return false; // reject + boolean accept = currentCpu < maxCpu; if (LOG.isDebugEnabled()) { LOG.debug("Location {} CPU usage is {}: {}", new Object[] { input, currentCpu, accept ? "accepted" : "rejected" });