brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [31/50] brooklyn-server git commit: Cleanup logging
Date Mon, 01 Feb 2016 17:49:01 GMT
Cleanup logging

- Don't warn about "already deployed" when setting config
  during construction (after setting owner!)
- DynamicCluster.addNode manages it immediately
- ssh logging: trace only in SshjTool and ScriptHelper;
  debug in "script runner", such as SshMachineLocation.execWithLogging
- Drop some log levels
- toStrings on LocalManagementContext and LocalSubscriptionManager
- logging subscriptions: avoid duplicate info in log message
- Repeater: avoid multiple logs when pass first time, and give
  more info about max num attempts etc


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/03f0209a
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/03f0209a
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/03f0209a

Branch: refs/heads/0.4.0
Commit: 03f0209a820d854d121e2f90674597bd05e0ef84
Parents: f8b3954
Author: Aled Sage <aled.sage@gmail.com>
Authored: Wed Oct 10 21:33:38 2012 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Thu Oct 11 10:05:46 2012 +0100

----------------------------------------------------------------------
 .../brooklyn/entity/basic/AbstractEntity.groovy |  9 +++++++-
 .../brooklyn/entity/group/DynamicCluster.java   |  3 ++-
 .../event/adapter/ConfigSensorAdapter.groovy    |  6 +++++
 .../event/adapter/HttpPollHelper.groovy         |  5 ++---
 .../location/basic/SshMachineLocation.java      |  4 ++--
 .../location/geo/MaxMindHostGeoLookup.java      |  2 +-
 .../internal/LocalManagementContext.java        | 23 ++++++++++++--------
 .../internal/LocalSubscriptionManager.java      | 18 ++++++++++-----
 .../java/brooklyn/util/internal/Repeater.groovy | 18 ++++++++++++---
 .../brooklyn/util/internal/ssh/SshjTool.java    | 20 ++++++++---------
 .../java/brooklyn/util/text/Identifiers.java    | 14 ++++++++++--
 .../entity/basic/SoftwareProcessEntity.groovy   | 19 +++++++++-------
 .../entity/basic/lifecycle/ScriptHelper.java    | 11 ++++------
 13 files changed, 99 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/03f0209a/core/src/main/java/brooklyn/entity/basic/AbstractEntity.groovy
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/basic/AbstractEntity.groovy b/core/src/main/java/brooklyn/entity/basic/AbstractEntity.groovy
index 8498d42..5829b25 100644
--- a/core/src/main/java/brooklyn/entity/basic/AbstractEntity.groovy
+++ b/core/src/main/java/brooklyn/entity/basic/AbstractEntity.groovy
@@ -83,6 +83,11 @@ public abstract class AbstractEntity extends GroovyObjectSupport implements
Enti
     // an exception will be thrown.
     boolean previouslyOwned = false
 
+    /**
+     * Whether we are still being constructed, in which case never warn in "assertNotYetOwned"

+     */
+    private boolean preConfigured = true;
+    
     private final EntityDynamicType entityType;
     
     protected transient ExecutionContext execution
@@ -141,6 +146,8 @@ public abstract class AbstractEntity extends GroovyObjectSupport implements
Enti
             def checkWeGetThis = configure(flags);
             assert this == checkWeGetThis : "$this configure method does not return itself;
returns $checkWeGetThis instead"
 
+            preConfigured = false;
+            
         } finally { this.@skipInvokeMethodEffectorInterception.set(false) }
     }
 
@@ -413,7 +420,7 @@ public abstract class AbstractEntity extends GroovyObjectSupport implements
Enti
     }
 
     protected void assertNotYetOwned() {
-        if (getApplication()?.isDeployed())
+        if (!preConfigured && getApplication()?.isDeployed())
             LOG.warn("configuration being made to $this after deployment; may not be supported
in future versions");
         //throw new IllegalStateException("Cannot set configuration $key on active entity
$this")
     }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/03f0209a/core/src/main/java/brooklyn/entity/group/DynamicCluster.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/group/DynamicCluster.java b/core/src/main/java/brooklyn/entity/group/DynamicCluster.java
index 600786b..a2a31b9 100644
--- a/core/src/main/java/brooklyn/entity/group/DynamicCluster.java
+++ b/core/src/main/java/brooklyn/entity/group/DynamicCluster.java
@@ -143,7 +143,7 @@ public class DynamicCluster extends AbstractGroup implements Cluster {
             int currentSize = getCurrentSize();
             int delta = desiredSize - currentSize;
             if (delta != 0) {
-                logger.info("Resize {} from {} to {}; delta = {}", new Object[] {this, currentSize,
desiredSize, delta});
+                logger.info("Resize {} from {} to {}", new Object[] {this, currentSize, desiredSize});
             } else {
                 if (logger.isDebugEnabled()) logger.debug("Resize no-op {} from {} to {}",
new Object[] {this, currentSize, desiredSize});
             }
@@ -245,6 +245,7 @@ public class DynamicCluster extends AbstractGroup implements Cluster {
         if (entity==null || !(entity instanceof Entity)) 
             throw new IllegalStateException("EntityFactory factory routine did not return
an entity, in "+this+" ("+entity+")");
         
+        getManagementContext().manage(entity);
         addMember(entity);
         return entity;
     }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/03f0209a/core/src/main/java/brooklyn/event/adapter/ConfigSensorAdapter.groovy
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/event/adapter/ConfigSensorAdapter.groovy b/core/src/main/java/brooklyn/event/adapter/ConfigSensorAdapter.groovy
index e50c9dc..5d243a1 100644
--- a/core/src/main/java/brooklyn/event/adapter/ConfigSensorAdapter.groovy
+++ b/core/src/main/java/brooklyn/event/adapter/ConfigSensorAdapter.groovy
@@ -28,4 +28,10 @@ public class ConfigSensorAdapter extends AbstractSensorAdapter {
         }
 	}
 	
+    //for selectively applying once (e.g. sub-classes of DynamicWebAppCluster that don't
want to set HTTP_PORT etc!)
+    public static void apply(EntityLocal entity, AttributeSensorAndConfigKey key) {
+        if (entity.getAttribute(key)==null) {
+            entity.setAttribute(key)
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/03f0209a/core/src/main/java/brooklyn/event/adapter/HttpPollHelper.groovy
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/event/adapter/HttpPollHelper.groovy b/core/src/main/java/brooklyn/event/adapter/HttpPollHelper.groovy
index c499614..ce6f850 100644
--- a/core/src/main/java/brooklyn/event/adapter/HttpPollHelper.groovy
+++ b/core/src/main/java/brooklyn/event/adapter/HttpPollHelper.groovy
@@ -36,13 +36,12 @@ protected class HttpPollHelper extends AbstractPollHelper {
 	
 	@Override
 	AbstractSensorEvaluationContext executePollOnSuccess() {
-        if (log.isDebugEnabled()) log.debug "http polling for {} sensors at {}", adapter.entity,
adapter.baseUrl+" "+adapter.urlVars
+        if (log.isTraceEnabled()) log.trace("http polling for {} sensors at {}", adapter.entity,
adapter.baseUrl+" "+adapter.urlVars);
 		HttpURLConnection connection = getConnection();
         TrustingSslSocketFactory.configure(connection);
 		connection.connect()
 		def result = new HttpResponseContext(connection)
-        if (log.isDebugEnabled()) log.debug "http poll for {} returned status {}", adapter.entity,
result.responseCode
-        if (log.isTraceEnabled()) log.trace "http poll for {} returned content: {}", adapter.entity,
result.content
+        if (log.isTraceEnabled()) log.trace("http poll for {} returned status {}", adapter.entity,
result.responseCode);
 		return result
 	}
 	

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/03f0209a/core/src/main/java/brooklyn/location/basic/SshMachineLocation.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/location/basic/SshMachineLocation.java b/core/src/main/java/brooklyn/location/basic/SshMachineLocation.java
index f5a64a7..edda7be 100644
--- a/core/src/main/java/brooklyn/location/basic/SshMachineLocation.java
+++ b/core/src/main/java/brooklyn/location/basic/SshMachineLocation.java
@@ -325,7 +325,7 @@ public class SshMachineLocation extends AbstractLocation implements MachineLocat
     }
     
     protected int execWithLogging(Map<String,?> props, String summaryForLogging, List<String>
commands, Map<String,?> env, ExecRunner execCommand) {
-        logSsh.debug("{} on machine {}: {}", new Object[] {summaryForLogging, this, commands});
+        if (logSsh.isDebugEnabled()) logSsh.debug("{} on machine {}: {}", new Object[] {summaryForLogging,
this, commands});
         
         Preconditions.checkNotNull(address, "host address must be specified for ssh");
         if (commands.isEmpty()) {
@@ -375,7 +375,7 @@ public class SshMachineLocation extends AbstractLocation implements MachineLocat
             try {  
                 int result = execCommand.exec(ssh, flags, commands, env);
                 ssh.disconnect();
-                if (logSsh.isDebugEnabled()) logSsh.debug("{} on machine {} completed: {}",
new Object[] {summaryForLogging, this, result});
+                if (logSsh.isDebugEnabled()) logSsh.debug("{} on machine {} completed: return
status {}", new Object[] {summaryForLogging, this, result});
 
                 return result;
             } finally { Tasks.setBlockingDetails(null); }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/03f0209a/core/src/main/java/brooklyn/location/geo/MaxMindHostGeoLookup.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/location/geo/MaxMindHostGeoLookup.java b/core/src/main/java/brooklyn/location/geo/MaxMindHostGeoLookup.java
index 409c8a6..2c75a33 100644
--- a/core/src/main/java/brooklyn/location/geo/MaxMindHostGeoLookup.java
+++ b/core/src/main/java/brooklyn/location/geo/MaxMindHostGeoLookup.java
@@ -60,7 +60,7 @@ public class MaxMindHostGeoLookup implements HostGeoLookup {
             name.append(" ("); name.append(l.countryCode); name.append(")");
             
             HostGeoInfo geo = new HostGeoInfo(address.getHostName(), name.toString(), l.latitude,
l.longitude);
-            log.info("Geo info lookup (MaxMind DB) for "+address+" returned: "+geo);
+            log.debug("Geo info lookup (MaxMind DB) for "+address+" returned: "+geo);
             return geo;
         } catch (Exception e) {
             if (log.isDebugEnabled())

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/03f0209a/core/src/main/java/brooklyn/management/internal/LocalManagementContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/management/internal/LocalManagementContext.java b/core/src/main/java/brooklyn/management/internal/LocalManagementContext.java
index 010466c..4940e58 100644
--- a/core/src/main/java/brooklyn/management/internal/LocalManagementContext.java
+++ b/core/src/main/java/brooklyn/management/internal/LocalManagementContext.java
@@ -1,9 +1,6 @@
 package brooklyn.management.internal;
 
 import static brooklyn.util.GroovyJavaMethods.elvis;
-
-import brooklyn.entity.drivers.BasicEntityDriverFactory;
-import brooklyn.entity.drivers.EntityDriverFactory;
 import groovy.util.ObservableList;
 
 import java.util.ArrayList;
@@ -25,6 +22,7 @@ import brooklyn.management.ManagementContext;
 import brooklyn.management.SubscriptionManager;
 import brooklyn.management.Task;
 import brooklyn.util.task.BasicExecutionManager;
+import brooklyn.util.text.Identifiers;
 
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
@@ -35,14 +33,16 @@ import com.google.common.collect.Sets;
 public class LocalManagementContext extends AbstractManagementContext {
     private static final Logger log = LoggerFactory.getLogger(LocalManagementContext.class);
 
+    private static final Object MANAGED_LOCALLY = new Object();
+    
     private ExecutionManager execution;
     private SubscriptionManager subscriptions;
 
-    protected Map<String,Entity> entitiesById = Maps.newLinkedHashMap();
-    protected ObservableList entities = new ObservableList();
-    protected Set<Application> applications = Sets.newLinkedHashSet();
+    protected final Map<String,Entity> entitiesById = Maps.newLinkedHashMap();
+    protected final ObservableList entities = new ObservableList();
+    protected final Set<Application> applications = Sets.newLinkedHashSet();
 
-    private static final Object MANAGED_LOCALLY = new Object();
+    private final String tostring = "LocalManagementContext("+Identifiers.getBase64IdFromValue(System.identityHashCode(this),
5)+")";
 
     protected synchronized boolean manageNonRecursive(Entity e) {
         ((AbstractEntity)e).managementData = MANAGED_LOCALLY;
@@ -55,7 +55,7 @@ public class LocalManagementContext extends AbstractManagementContext {
             }
             return false;
         } else {
-            log.debug("{} starting management of entity {}", this, e);
+            if (log.isDebugEnabled()) log.debug("{} starting management of entity {}", this,
e);
             if (e instanceof Application) {
                 applications.add((Application)e);
                 ((AbstractApplication)e).setManagementContext(this);
@@ -79,7 +79,7 @@ public class LocalManagementContext extends AbstractManagementContext {
             log.error("{} call to stop management of entity {} removed different entity {}",
new Object[] { this, e, old });
             return true;
         } else {
-            log.debug("{} stopped management of entity {}", this, e);
+            if (log.isDebugEnabled()) log.debug("{} stopped management of entity {}", this,
e);
             return true;
         }
     }
@@ -126,4 +126,9 @@ public class LocalManagementContext extends AbstractManagementContext
{
     public void removeEntitySetListener(CollectionChangeListener<Entity> listener)
{
         entities.removePropertyChangeListener(new GroovyObservablesPropertyChangeToCollectionChangeAdapter(listener));
     }
+    
+    @Override
+    public String toString() {
+        return tostring;
+    }
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/03f0209a/core/src/main/java/brooklyn/management/internal/LocalSubscriptionManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/management/internal/LocalSubscriptionManager.java
b/core/src/main/java/brooklyn/management/internal/LocalSubscriptionManager.java
index 7d48850..6e21cb4 100644
--- a/core/src/main/java/brooklyn/management/internal/LocalSubscriptionManager.java
+++ b/core/src/main/java/brooklyn/management/internal/LocalSubscriptionManager.java
@@ -27,6 +27,7 @@ import brooklyn.management.SubscriptionManager;
 import brooklyn.util.internal.LanguageUtils;
 import brooklyn.util.task.BasicExecutionManager;
 import brooklyn.util.task.SingleThreadedScheduler;
+import brooklyn.util.text.Identifiers;
 
 import com.google.common.base.Objects;
 import com.google.common.base.Predicate;
@@ -74,14 +75,16 @@ public class LocalSubscriptionManager implements SubscriptionManager {
 
     protected final ExecutionManager em;
     
-    protected ConcurrentMap<String, Subscription> allSubscriptions = new ConcurrentHashMap<String,
Subscription>();
-    protected ConcurrentMap<Object, Set<Subscription>> subscriptionsBySubscriber
= new ConcurrentHashMap<Object, Set<Subscription>>();
-    protected ConcurrentMap<Object, Set<Subscription>> subscriptionsByToken =
new ConcurrentHashMap<Object, Set<Subscription>>();
+    protected final ConcurrentMap<String, Subscription> allSubscriptions = new ConcurrentHashMap<String,
Subscription>();
+    protected final ConcurrentMap<Object, Set<Subscription>> subscriptionsBySubscriber
= new ConcurrentHashMap<Object, Set<Subscription>>();
+    protected final ConcurrentMap<Object, Set<Subscription>> subscriptionsByToken
= new ConcurrentHashMap<Object, Set<Subscription>>();
     
     private final AtomicLong totalEventsPublishedCount = new AtomicLong();
     
     private final AtomicLong totalEventsDeliveredCount = new AtomicLong();
     
+    private final String tostring = "SubscriptionContext("+Identifiers.getBase64IdFromValue(System.identityHashCode(this),
5)+")";
+
     public LocalSubscriptionManager(ExecutionManager m) {
         this.em = m;
     }
@@ -131,7 +134,7 @@ public class LocalSubscriptionManager implements SubscriptionManager {
         s.eventFilter = (Predicate) flags.remove("eventFilter");
         s.flags = flags;
         
-        if (LOG.isDebugEnabled()) LOG.debug("Creating subscription {} for {} on {} {} in
{}", new Object[] {s, s.subscriber, producer, sensor, this});
+        if (LOG.isDebugEnabled()) LOG.debug("Creating subscription {} for {} on {} {} in
{}", new Object[] {s.id, s.subscriber, producer, sensor, this});
         allSubscriptions.put(s.id, s);
         LanguageUtils.addToMapOfSets(subscriptionsByToken, makeEntitySensorToken(s.producer,
s.sensor), s);
         if (s.subscriber!=null) {
@@ -229,7 +232,7 @@ public class LocalSubscriptionManager implements SubscriptionManager {
         
         //note, generating the notifications must be done in the calling thread to preserve
order
         //e.g. emit(A); emit(B); should cause onEvent(A); onEvent(B) in that order
-        if (LOG.isTraceEnabled()) LOG.trace("{} got a {} event", this, event);
+        if (LOG.isTraceEnabled()) LOG.trace("{} got event {}", this, event);
         totalEventsPublishedCount.incrementAndGet();
         
         Set<Subscription> subs = (Set<Subscription>) ((Set<?>) getSubscriptionsForEntitySensor(event.getSource(),
event.getSensor()));
@@ -247,4 +250,9 @@ public class LocalSubscriptionManager implements SubscriptionManager {
             }
         }
     }
+    
+    @Override
+    public String toString() {
+        return tostring;
+    }
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/03f0209a/core/src/main/java/brooklyn/util/internal/Repeater.groovy
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/util/internal/Repeater.groovy b/core/src/main/java/brooklyn/util/internal/Repeater.groovy
index 28825d2..c08d8ef 100644
--- a/core/src/main/java/brooklyn/util/internal/Repeater.groovy
+++ b/core/src/main/java/brooklyn/util/internal/Repeater.groovy
@@ -9,6 +9,7 @@ import java.util.concurrent.TimeUnit
 import org.slf4j.Logger
 import org.slf4j.LoggerFactory
 
+import brooklyn.util.Time;
 import brooklyn.util.flags.FlagUtils
 import brooklyn.util.flags.SetFromFlag
 
@@ -225,7 +226,6 @@ public class Repeater {
 
         while (true) {
             iterations++
-            if (log.isDebugEnabled()) log.debug "{}: iteration {}", description, iterations
 
             try {
                 body.call()
@@ -244,8 +244,19 @@ public class Repeater {
                 if (rethrowExceptionImmediately) throw e
             }
             if (done) {
-                if (log.isDebugEnabled()) log.debug "{}: condition satisfied", description
+                if (log.isDebugEnabled()) log.debug("{}: condition satisfied", description)
                 return true
+            } else {
+                if (log.isDebugEnabled()) {
+                    String msg = String.format("%s: unsatisfied during iteration %s %s",
description, iterations,
+                            (iterationLimit > 0 ? "(max "+iterationLimit+" attempts)"
: "") + 
+                            (endTime > 0 ? "("+Time.makeTimeString(endTime - System.currentTimeMillis())+"
remaining)" : ""));
+                    if (iterations == 1) {
+                        log.debug(msg);
+                    } else {
+                        log.trace(msg);
+                    }
+                }
             }
 
             if (iterationLimit > 0 && iterations == iterationLimit) {
@@ -261,7 +272,8 @@ public class Repeater {
 
             if (endTime > 0) {
 				if (System.currentTimeMillis() > endTime) {
-                    if (log.isDebugEnabled()) log.debug "{}: condition not satisfied and
deadline passed", description
+                    if (log.isDebugEnabled()) log.debug("{}: condition not satisfied and
deadline {} passed", 
+                            description, Time.makeTimeString(endTime - System.currentTimeMillis()));
 	                if (rethrowException && lastError) {
 	                    log.error("{}: error caught checking condition: {}", description, lastError.getMessage())
 	                    throw lastError

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/03f0209a/core/src/main/java/brooklyn/util/internal/ssh/SshjTool.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/util/internal/ssh/SshjTool.java b/core/src/main/java/brooklyn/util/internal/ssh/SshjTool.java
index 8413cae..f6141be 100644
--- a/core/src/main/java/brooklyn/util/internal/ssh/SshjTool.java
+++ b/core/src/main/java/brooklyn/util/internal/ssh/SshjTool.java
@@ -307,6 +307,7 @@ public class SshjTool implements SshTool {
         try {
             acquire(sshClientConnection);
         } catch (Exception e) {
+            LOG.debug(toString()+" failed to connect (rethrowing)", e);
             throw propagate(e, "failed to connect");
         }
     }
@@ -318,7 +319,7 @@ public class SshjTool implements SshTool {
 
     @Override
     public void disconnect() {
-        if (LOG.isTraceEnabled()) LOG.trace("Disconnecting {}", toString());
+        if (LOG.isTraceEnabled()) LOG.trace("Disconnecting {}", this);
         try {
             sshClientConnection.clear();
         } catch (Exception e) {
@@ -428,7 +429,7 @@ public class SshjTool implements SshTool {
         
         String scriptContents = toScript(commands, env);
         
-        if (LOG.isDebugEnabled()) LOG.debug("Running shell command at "+host+" as script:
{}", scriptContents);
+        if (LOG.isTraceEnabled()) LOG.trace("Running shell command at {} as script: {}",
host, scriptContents);
         
         createFile(ImmutableMap.of("permissions", "0700"), scriptPath, scriptContents);
         
@@ -455,10 +456,10 @@ public class SshjTool implements SshTool {
                 .add("exit $?")
                 .build();
         
-        if (LOG.isDebugEnabled()) LOG.debug("Running shell command at "+host+": {}", allcmds);
+        if (LOG.isTraceEnabled()) LOG.trace("Running shell command at {}: {}", host, allcmds);
         
         Integer result = acquire(new ShellAction(allcmds, out, err));
-        if (LOG.isDebugEnabled()) LOG.debug("Running shell command at "+host+" completed,
exit code: {}", result);
+        if (LOG.isTraceEnabled()) LOG.trace("Running shell command at {} completed: return
status {}", host, result);
         return result != null ? result : -1;
     }
 
@@ -479,10 +480,10 @@ public class SshjTool implements SshTool {
         List<String> allcmds = toCommandSequence(commands, env);
         String singlecmd = Joiner.on(separator).join(allcmds);
 
-        if (LOG.isDebugEnabled()) LOG.debug("Running command at "+host+": {}", singlecmd);
+        if (LOG.isTraceEnabled()) LOG.trace("Running command at {}: {}", host, singlecmd);
         
         Command result = acquire(new ExecAction(singlecmd, out, err));
-        if (LOG.isDebugEnabled()) LOG.debug("Running command at "+host+" completed, exit
code: {}", result.getExitStatus());
+        if (LOG.isTraceEnabled()) LOG.trace("Running command at {} completed: exit code {}",
host, result.getExitStatus());
         return result.getExitStatus();
     }
 
@@ -553,7 +554,7 @@ public class SshjTool implements SshTool {
                     LOG.warn("<< " + errorMessage + " (attempt " + (i + 1) + " of "
+ sshTries + "): " + from.getMessage());
                     throw propagate(from, errorMessage + " (out of retries - max " + sshTries
+ ")");
                 } else {
-                    LOG.debug("<< " + errorMessage + " (attempt " + (i + 1) + " of
" + sshTries + "): " + from.getMessage());
+                    if (LOG.isDebugEnabled()) LOG.debug("<< " + errorMessage + " (attempt
" + (i + 1) + " of " + sshTries + "): " + from.getMessage());
                     backoffForAttempt(i + 1, errorMessage + ": " + from.getMessage());
                     if (connection != sshClientConnection)
                         connect();
@@ -707,10 +708,7 @@ public class SshjTool implements SshTool {
     }
 
     private SshException propagate(Exception e, String message) throws SshException {
-        message += ": " + e.getMessage();
-        // it's not necessarily an error yet, that's up to the caller
-        LOG.debug("<< PROPAGATING: " + message, e);
-        throw new SshException("(" + toString() + ") " + message, e);
+        throw new SshException("(" + toString() + ") " + message + ":" + e.getMessage(),
e);
     }
     
     protected void allocatePTY(Session s) throws ConnectionException, TransportException
{

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/03f0209a/core/src/main/java/brooklyn/util/text/Identifiers.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/util/text/Identifiers.java b/core/src/main/java/brooklyn/util/text/Identifiers.java
index e29391c..05cc171 100644
--- a/core/src/main/java/brooklyn/util/text/Identifiers.java
+++ b/core/src/main/java/brooklyn/util/text/Identifiers.java
@@ -112,7 +112,7 @@ public class Identifiers {
     }
 
     public static String makeRandomBase64Id(int length) {
-        StringBuffer s = new StringBuffer();
+        StringBuilder s = new StringBuilder();
         while (length>0) {
             appendBase64IdFromValueOfLength(randomLong(), length>10 ? 10 : length, s);
             length -= 10;
@@ -123,7 +123,7 @@ public class Identifiers {
         return getBase64IdFromValue(value, 10);
     }
     public static String getBase64IdFromValue(long value, int length) {
-        StringBuffer s = new StringBuffer();
+        StringBuilder s = new StringBuilder();
         appendBase64IdFromValueOfLength(value, length, s);
         return s.toString();
     }
@@ -137,4 +137,14 @@ public class Identifiers {
             idx = idx >> 6;
         }
     }
+    public static void appendBase64IdFromValueOfLength(long value, int length, StringBuilder
sb) {
+        if (length>11)
+            throw new IllegalArgumentException("can't get a Base64 string longer than 11
chars from a long");
+        long idx = value;
+        for (int i=0; i<length; i++) {
+            byte x = (byte)(idx & 63);
+            sb.append(BASE64_VALID_CHARS.charAt(x));
+            idx = idx >> 6;
+        }
+    }    
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/03f0209a/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcessEntity.groovy
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcessEntity.groovy
b/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcessEntity.groovy
index 77db4e8..14739f0 100644
--- a/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcessEntity.groovy
+++ b/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcessEntity.groovy
@@ -156,7 +156,7 @@ public abstract class SoftwareProcessEntity extends AbstractEntity implements
St
                 .run()) {
             throw new IllegalStateException("Timeout waiting for SERVICE_UP from ${this}");
         }
-        log.debug("Detected SERVICE_UP for software ${this}")
+        log.debug("Detected SERVICE_UP for software {}", this)
     }
 
     public void checkModifiable() {
@@ -171,7 +171,6 @@ public abstract class SoftwareProcessEntity extends AbstractEntity implements
St
 
     @Override
 	public void start(Collection<? extends Location> locations) {
-        log.info("Starting software process entity "+this+" at "+locations);
 		setAttribute(SERVICE_STATE, Lifecycle.STARTING)
 		if (!sensorRegistry) sensorRegistry = new SensorRegistry(this)
 
@@ -184,7 +183,9 @@ public abstract class SoftwareProcessEntity extends AbstractEntity implements
St
 	}
 
 	public void startInLocation(Collection<Location> locations) {
-		Preconditions.checkArgument locations.size() == 1
+		if (locations.size() != 1) {
+            throw new IllegalArgumentException("Expected one location when starting "+this+",
but given "+locations);
+		}
 		Location location = Iterables.getOnlyElement(locations)
 		startInLocation(location)
 	}
@@ -210,7 +211,7 @@ public abstract class SoftwareProcessEntity extends AbstractEntity implements
St
 	public void startInLocation(MachineProvisioningLocation location) {
 		Map<String,Object> flags = obtainProvisioningFlags(location);
         if (!(location in LocalhostMachineProvisioningLocation))
-            LOG.info("SoftwareProcessEntity {} obtaining a new location instance in {} with
ports {}", this, location, flags.inboundPorts)
+            LOG.info("Starting {}, obtaining a new location instance in {} with ports {}",
this, location, flags.inboundPorts)
 		provisioningLoc = location;
         SshMachineLocation machine;
         Tasks.withBlockingDetails("Provisioning machine in "+location) {
@@ -218,10 +219,10 @@ public abstract class SoftwareProcessEntity extends AbstractEntity implements
St
         }
 		if (machine == null) throw new NoMachinesAvailableException(location)
 		if (LOG.isDebugEnabled())
-		    LOG.debug("SoftwareProcessEntity {} obtained new location instance {}, details {}",
this, machine,
+		    LOG.debug("While starting {}, obtained new location instance {}, details {}", this,
machine,
 		            machine.getUser()+":"+Entities.sanitize(machine.getConfig()))
         if (!(location in LocalhostMachineProvisioningLocation))
-            LOG.info("SoftwareProcessEntity {} obtained a new location instance {}, now preparing
process there", this, machine)
+            LOG.info("While starting {}, obtained a new location instance {}, now preparing
process there", this, machine)
 		startInLocation(machine)
 	}
 
@@ -236,7 +237,7 @@ public abstract class SoftwareProcessEntity extends AbstractEntity implements
St
                 if (p != null && !p.isEmpty()) ports += p.iterator().next()
             }
         }
-        log.debug("getRequiredOpenPorts detected default ${ports} for ${this}")
+        log.debug("getRequiredOpenPorts detected default {} for {}", ports, this)
         ports
     }
 
@@ -254,6 +255,8 @@ public abstract class SoftwareProcessEntity extends AbstractEntity implements
St
 	}
 
     public void startInLocation(SshMachineLocation machine) {
+        log.info("Starting {} on machine {}", this, machine);
+        
         locations.add(machine)
         initDriver(machine)
         
@@ -325,7 +328,7 @@ public abstract class SoftwareProcessEntity extends AbstractEntity implements
St
             log.warn("Skipping stop of software process entity "+this+" when already stopped");
             return;
         }
-        log.info("Stopping software process entity "+this);
+        log.info("Stopping {} in {}", this, getLocations());
 		setAttribute(SERVICE_STATE, Lifecycle.STOPPING)
 		if (sensorRegistry!=null) sensorRegistry.deactivateAdapters();
         setAttribute(SERVICE_UP, false)

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/03f0209a/software/base/src/main/java/brooklyn/entity/basic/lifecycle/ScriptHelper.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/entity/basic/lifecycle/ScriptHelper.java
b/software/base/src/main/java/brooklyn/entity/basic/lifecycle/ScriptHelper.java
index 034fc00..a1263e7 100644
--- a/software/base/src/main/java/brooklyn/entity/basic/lifecycle/ScriptHelper.java
+++ b/software/base/src/main/java/brooklyn/entity/basic/lifecycle/ScriptHelper.java
@@ -15,7 +15,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import brooklyn.util.GroovyJavaMethods;
-import brooklyn.util.MutableMap;
 import brooklyn.util.RuntimeInterruptedException;
 import brooklyn.util.mutex.WithMutexes;
 import brooklyn.util.task.Tasks;
@@ -191,9 +190,8 @@ public class ScriptHelper {
         }
 
         List<String> lines = getLines();
-        if (log.isDebugEnabled()) {
-            log.debug("executing: {} - {}", summary, lines);
-        }
+        if (log.isTraceEnabled()) log.trace("executing: {} - {}", summary, lines);
+        
         int result;
         try {
             mutexAcquire.run();
@@ -212,9 +210,8 @@ public class ScriptHelper {
         } finally {
             mutexRelease.run();
         }
-        if (log.isDebugEnabled()) {
-            log.debug("finished executing: {} - result code {}", summary, result);
-        }
+        if (log.isTraceEnabled()) log.trace("finished executing: {} - result code {}", summary,
result);
+        
         if (!resultCodeCheck.apply(result)) {
             throw new IllegalStateException(format("Execution failed, invalid result %s for
%s", result, summary));
         }


Mime
View raw message