Fix port config check when skipping install
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/5c2f36f3 Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/5c2f36f3 Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/5c2f36f3 Branch: refs/heads/master Commit: 5c2f36f37f2ce53530d17b8c30fce32f81af4153 Parents: 32e9911 Author: Andrew Kennedy <[email protected]> Authored: Fri Aug 29 01:32:58 2014 +0100 Committer: Andrew Kennedy <[email protected]> Committed: Sat Aug 30 17:25:36 2014 +0100 ---------------------------------------------------------------------- .../basic/PortAttributeSensorAndConfigKey.java | 58 ++++++++++---------- .../basic/AbstractSoftwareProcessDriver.java | 2 +- 2 files changed, 31 insertions(+), 29 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/5c2f36f3/core/src/main/java/brooklyn/event/basic/PortAttributeSensorAndConfigKey.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/brooklyn/event/basic/PortAttributeSensorAndConfigKey.java b/core/src/main/java/brooklyn/event/basic/PortAttributeSensorAndConfigKey.java index fbee6ba..0f4e3f4 100644 --- a/core/src/main/java/brooklyn/event/basic/PortAttributeSensorAndConfigKey.java +++ b/core/src/main/java/brooklyn/event/basic/PortAttributeSensorAndConfigKey.java @@ -50,13 +50,13 @@ import com.google.common.collect.Iterables; * To convert at runtime a single port is chosen, respecting the entity. */ public class PortAttributeSensorAndConfigKey extends AttributeSensorAndConfigKey<PortRange,Integer> { + private static final long serialVersionUID = 4680651022807491321L; - + public static final Logger LOG = LoggerFactory.getLogger(PortAttributeSensorAndConfigKey.class); static { - // ensure type coercions are registered - PortRanges.init(); + PortRanges.init(); // Ensure type coercions are registered } public PortAttributeSensorAndConfigKey(String name) { @@ -89,49 +89,51 @@ public class PortAttributeSensorAndConfigKey extends AttributeSensorAndConfigKey lo = Maybe.of(locations.iterator().next()); } if (LOG.isTraceEnabled()) { - LOG.trace("Convert config to sensor for {} found locations: {}. Selected: {}", - new Object[] {entity, locations, lo}); + LOG.trace("Convert config to sensor for {} found locations: {}. Selected: {}", new Object[] {entity, locations, lo}); } if (lo.isPresent()) { Location l = lo.get(); Boolean skip = Optional.fromNullable(entity.getConfig(BrooklynConfigKeys.SKIP_INSTALLATION)).or(false); - if (l instanceof PortSupplier && !skip) { - int p = ((PortSupplier)l).obtainPort(value); - if (p!=-1) { - LOG.debug(""+entity+" choosing port "+p+" for "+getName()); + if (l instanceof PortSupplier) { + int p = ((PortSupplier) l).obtainPort(value); + if (p != -1) { + LOG.debug("{}: choosing port {} for {}", new Object[] { entity, p, getName() }); return p; } - int rangeSize = Iterables.size(value); - if (rangeSize==0) - LOG.warn(""+entity+" no port available for "+getName()+" (empty range "+value+")"); - else if (rangeSize==1) { - Integer pp = value.iterator().next(); - if (pp>1024) - LOG.warn(""+entity+" port "+pp+" not available for "+getName()); - else - LOG.warn(""+entity+" port "+pp+" not available for "+getName()+" (root may be required?)"); - } else { - LOG.warn(""+entity+" no port available for "+getName()+" (tried range "+value+")"); + // If we are not skipping install, fail now + if (!skip) { + int rangeSize = Iterables.size(value); + if (rangeSize == 0) { + LOG.warn("{}: no port available for {} (empty range {})", new Object[] { entity, getName(), value }); + } else if (rangeSize == 1) { + Integer pp = value.iterator().next(); + if (pp > 1024) { + LOG.warn("{}: port {} not available for {}", new Object[] { entity, pp, getName() }); + } else { + LOG.warn("{}: port {} not available for {} (root may be required?)", new Object[] { entity, pp, getName() }); + } + } else { + LOG.warn("{}: no port available for {} (tried range {})", new Object[] { entity, getName(), value }); + } + return null; // Definitively, no ports available } - // definitively, no ports available - return null; } - // ports may be available, we just can't tell from the location + // Ports may be available, we just can't tell from the location Integer v = (value.isEmpty() ? null : value.iterator().next()); - LOG.debug(""+entity+" choosing port "+v+" (unconfirmed) for "+getName()); + LOG.debug("{}: choosing port {} (unconfirmed) for {}", new Object[] { entity, v, getName() }); return v; } else { - LOG.warn(""+entity+" ports not applicable, or not yet applicable, because has multiple locations "+locations+"; ignoring "+getName()); + LOG.warn("{}: ports not applicable, or not yet applicable, because has multiple locations {}; ignoring ", new Object[] { entity, locations, getName() }); } } else { - LOG.warn(""+entity+" ports not applicable, or not yet applicable, bacause has no locations; ignoring "+getName()); + LOG.warn("{}: ports not applicable, or not yet applicable, bacause has no locations; ignoring {}", entity, getName()); } return null; } - + @Override protected Integer convertConfigToSensor(PortRange value, ManagementContext managementContext) { - LOG.warn("ports not applicable, bacause given managementContext rather than entity; ignoring "+getName()); + LOG.warn("ports not applicable, bacause given managementContext rather than entity; ignoring {}", getName()); return null; } } http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/5c2f36f3/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessDriver.java ---------------------------------------------------------------------- diff --git a/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessDriver.java b/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessDriver.java index 609c624..c32e1fc 100644 --- a/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessDriver.java +++ b/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessDriver.java @@ -79,7 +79,7 @@ public abstract class AbstractSoftwareProcessDriver implements SoftwareProcessDr */ @Override public void start() { - DynamicTasks.queue("post-launch", new Runnable() { public void run() { + DynamicTasks.queue("pre-install", new Runnable() { public void run() { preInstall(); }});
