MachineEntity: get locations from ancestors if necessary And improve logging.
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/9e7e83a4 Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/9e7e83a4 Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/9e7e83a4 Branch: refs/heads/master Commit: 9e7e83a4f4fb71393e5db03317c60db44bff14cc Parents: 1af8098 Author: Aled Sage <aled.s...@gmail.com> Authored: Fri Feb 9 10:02:28 2018 +0000 Committer: Aled Sage <aled.s...@gmail.com> Committed: Fri Feb 9 10:02:28 2018 +0000 ---------------------------------------------------------------------- .../core/location/AbstractMachineLocation.java | 8 ++++ .../entity/machine/MachineEntityImpl.java | 40 ++++++++++++++------ 2 files changed, 37 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/9e7e83a4/core/src/main/java/org/apache/brooklyn/core/location/AbstractMachineLocation.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/core/location/AbstractMachineLocation.java b/core/src/main/java/org/apache/brooklyn/core/location/AbstractMachineLocation.java index 17a1217..ae9e819 100644 --- a/core/src/main/java/org/apache/brooklyn/core/location/AbstractMachineLocation.java +++ b/core/src/main/java/org/apache/brooklyn/core/location/AbstractMachineLocation.java @@ -25,14 +25,19 @@ import org.apache.brooklyn.api.location.MachineLocation; import org.apache.brooklyn.api.location.OsDetails; import org.apache.brooklyn.config.ConfigKey; import org.apache.brooklyn.core.config.ConfigKeys; +import org.apache.brooklyn.core.entity.AbstractEntity; import org.apache.brooklyn.util.collections.MutableMap; import org.apache.brooklyn.util.core.mutex.MutexSupport; import org.apache.brooklyn.util.core.mutex.WithMutexes; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.google.common.base.Optional; public abstract class AbstractMachineLocation extends AbstractLocation implements MachineLocation { + private static final Logger LOG = LoggerFactory.getLogger(AbstractMachineLocation.class); + public static final ConfigKey<MachineDetails> MACHINE_DETAILS = ConfigKeys.newConfigKey( MachineDetails.class, "machineDetails"); @@ -74,6 +79,9 @@ public abstract class AbstractMachineLocation extends AbstractLocation implement synchronized (machineDetailsLock) { if (machineDetails == null) { machineDetails = getConfig(MACHINE_DETAILS); + if (machineDetails != null) { + LOG.debug("Location {} using machine-details from config: {}", this, machineDetails); + } } if (machineDetails == null) { boolean detectionEnabled = getConfig(DETECT_MACHINE_DETAILS); http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/9e7e83a4/software/base/src/main/java/org/apache/brooklyn/entity/machine/MachineEntityImpl.java ---------------------------------------------------------------------- diff --git a/software/base/src/main/java/org/apache/brooklyn/entity/machine/MachineEntityImpl.java b/software/base/src/main/java/org/apache/brooklyn/entity/machine/MachineEntityImpl.java index 5fdb28f..79adc2c 100644 --- a/software/base/src/main/java/org/apache/brooklyn/entity/machine/MachineEntityImpl.java +++ b/software/base/src/main/java/org/apache/brooklyn/entity/machine/MachineEntityImpl.java @@ -18,23 +18,28 @@ */ package org.apache.brooklyn.entity.machine; +import java.util.Arrays; +import java.util.Collection; import java.util.concurrent.TimeoutException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - +import org.apache.brooklyn.api.location.Location; +import org.apache.brooklyn.api.location.MachineProvisioningLocation; import org.apache.brooklyn.api.sensor.Feed; import org.apache.brooklyn.core.effector.ssh.SshEffectorTasks; +import org.apache.brooklyn.core.location.Locations; import org.apache.brooklyn.core.location.Machines; import org.apache.brooklyn.entity.software.base.AbstractSoftwareProcessSshDriver; import org.apache.brooklyn.entity.software.base.EmptySoftwareProcessDriver; import org.apache.brooklyn.entity.software.base.EmptySoftwareProcessImpl; +import org.apache.brooklyn.entity.software.base.SoftwareProcess; import org.apache.brooklyn.location.ssh.SshMachineLocation; import org.apache.brooklyn.util.core.task.DynamicTasks; import org.apache.brooklyn.util.core.task.system.ProcessTaskWrapper; import org.apache.brooklyn.util.exceptions.Exceptions; import org.apache.brooklyn.util.guava.Maybe; import org.apache.brooklyn.util.time.Duration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class MachineEntityImpl extends EmptySoftwareProcessImpl implements MachineEntity { @@ -44,22 +49,25 @@ public class MachineEntityImpl extends EmptySoftwareProcessImpl implements Machi @Override protected void initEnrichers() { - LOG.info("Adding machine metrics enrichers"); + LOG.info("Adding machine-metrics enrichers to {}", this); AddMachineMetrics.addMachineMetricsEnrichers(this); super.initEnrichers(); } - + @Override protected void connectSensors() { super.connectSensors(); - - Maybe<SshMachineLocation> location = Machines.findUniqueMachineLocation(getLocations(), SshMachineLocation.class); - if (location.isPresent() && location.get().getOsDetails().isLinux()) { - LOG.info("Adding machine metrics feed"); + + Collection<? extends Location> locations = getAllLocations(); + + Maybe<SshMachineLocation> machine = Machines.findUniqueMachineLocation(locations, SshMachineLocation.class); + if (machine.isPresent() && machine.get().getOsDetails().isLinux()) { + LOG.info("Adding machine-metrics feed to {}, machine {}", this, machine.get()); machineMetrics = AddMachineMetrics.createMachineMetricsFeed(this); } else { - LOG.warn("Not adding machine metrics feed as no suitable location available on entity"); + LOG.warn("Not adding machine-metrics feed as no suitable location available on entity {}: machine={}; locations={}", + new Object[] {this, machine, locations}); } } @@ -76,7 +84,7 @@ public class MachineEntityImpl extends EmptySoftwareProcessImpl implements Machi } public SshMachineLocation getMachine() { - return Machines.findUniqueMachineLocation(getLocations(), SshMachineLocation.class).get(); + return Machines.findUniqueMachineLocation(getAllLocations(), SshMachineLocation.class).get(); } @Override @@ -113,4 +121,14 @@ public class MachineEntityImpl extends EmptySoftwareProcessImpl implements Machi } } + // TODO Logic duplicated from MachineLifecycleEffectorTasks.getLocation(Collection<Location>); + // perhaps move it to a super-type? + protected Collection<? extends Location> getAllLocations() { + Collection<? extends Location> locations = getLocations(); + if (locations.isEmpty()) { + MachineProvisioningLocation<?> provisioner = sensors().get(SoftwareProcess.PROVISIONING_LOCATION); + if (provisioner!=null) locations = Arrays.<Location>asList(provisioner); + } + return Locations.getLocationsCheckingAncestors(locations, this); + } }