You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2015/09/15 18:53:20 UTC

[01/15] incubator-brooklyn git commit: for ExplicitUser provider, create sooner

Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master 7ca278166 -> 5bb7cc693


for ExplicitUser provider, create sooner

and use config key to expose the provider(s)


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

Branch: refs/heads/master
Commit: a57dbe4aa73f8b5bac8f7d295fad70444d5b45f8
Parents: 3c08a7e
Author: Alex Heneveld <al...@cloudsoft.io>
Authored: Fri Sep 4 12:21:44 2015 +0100
Committer: Alex Heneveld <al...@cloudsoft.io>
Committed: Fri Sep 4 12:21:44 2015 +0100

----------------------------------------------------------------------
 .../org/apache/brooklyn/launcher/BrooklynLauncher.java    |  6 ++++--
 .../java/org/apache/brooklyn/rest/BrooklynWebConfig.java  |  3 +++
 .../BrooklynUserWithRandomPasswordSecurityProvider.java   | 10 ++++++++--
 .../security/provider/DelegatingSecurityProvider.java     | 10 ++++++++++
 4 files changed, 25 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a57dbe4a/usage/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynLauncher.java
----------------------------------------------------------------------
diff --git a/usage/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynLauncher.java b/usage/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynLauncher.java
index f9e8e8f..7425865 100644
--- a/usage/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynLauncher.java
+++ b/usage/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynLauncher.java
@@ -753,6 +753,8 @@ public class BrooklynLauncher {
             LOG.info("Starting Brooklyn web-console on loopback because security is explicitly disabled and no bind address specified");
             bindAddress = Networking.LOOPBACK;
         } else if (BrooklynWebConfig.hasNoSecurityOptions(brooklynProperties)) {
+            LOG.info("No security provider options specified. Define a security provider or users to prevent a random password being created and logged.");
+            
             if (bindAddress==null) {
                 LOG.info("Starting Brooklyn web-console with passwordless access on localhost and protected access from any other interfaces (no bind address specified)");
             } else {
@@ -765,8 +767,8 @@ public class BrooklynLauncher {
                 }
             }
             brooklynProperties.put(
-                    BrooklynWebConfig.SECURITY_PROVIDER_CLASSNAME,
-                    BrooklynUserWithRandomPasswordSecurityProvider.class.getName());
+                    BrooklynWebConfig.SECURITY_PROVIDER_INSTANCE,
+                    new BrooklynUserWithRandomPasswordSecurityProvider(managementContext));
         } else {
             LOG.debug("Starting Brooklyn using security properties: "+brooklynProperties.submap(ConfigPredicates.startingWith(BrooklynWebConfig.BASE_NAME_SECURITY)).asMapWithStringKeys());
         }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a57dbe4a/usage/rest-server/src/main/java/org/apache/brooklyn/rest/BrooklynWebConfig.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/main/java/org/apache/brooklyn/rest/BrooklynWebConfig.java b/usage/rest-server/src/main/java/org/apache/brooklyn/rest/BrooklynWebConfig.java
index 4fa13d0..c2aaebd 100644
--- a/usage/rest-server/src/main/java/org/apache/brooklyn/rest/BrooklynWebConfig.java
+++ b/usage/rest-server/src/main/java/org/apache/brooklyn/rest/BrooklynWebConfig.java
@@ -25,6 +25,7 @@ import org.apache.brooklyn.core.config.ConfigKeys;
 import org.apache.brooklyn.core.config.ConfigPredicates;
 import org.apache.brooklyn.rest.security.provider.DelegatingSecurityProvider;
 import org.apache.brooklyn.rest.security.provider.ExplicitUsersSecurityProvider;
+import org.apache.brooklyn.rest.security.provider.SecurityProvider;
 
 public class BrooklynWebConfig {
 
@@ -39,6 +40,8 @@ public class BrooklynWebConfig {
     public final static ConfigKey<String> SECURITY_PROVIDER_CLASSNAME = ConfigKeys.newStringConfigKey(
             BASE_NAME_SECURITY+".provider", "class name of a Brooklyn SecurityProvider",
             ExplicitUsersSecurityProvider.class.getCanonicalName());
+    public final static ConfigKey<SecurityProvider> SECURITY_PROVIDER_INSTANCE = ConfigKeys.newConfigKey(SecurityProvider.class,
+            SECURITY_PROVIDER_CLASSNAME.getName()+".internal.instance", "instance of a pre-configured security provider");
     
     /**
      * Explicitly set the users/passwords, e.g. in brooklyn.properties:

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a57dbe4a/usage/rest-server/src/main/java/org/apache/brooklyn/rest/security/provider/BrooklynUserWithRandomPasswordSecurityProvider.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/main/java/org/apache/brooklyn/rest/security/provider/BrooklynUserWithRandomPasswordSecurityProvider.java b/usage/rest-server/src/main/java/org/apache/brooklyn/rest/security/provider/BrooklynUserWithRandomPasswordSecurityProvider.java
index 3d13f7b..d5be027 100644
--- a/usage/rest-server/src/main/java/org/apache/brooklyn/rest/security/provider/BrooklynUserWithRandomPasswordSecurityProvider.java
+++ b/usage/rest-server/src/main/java/org/apache/brooklyn/rest/security/provider/BrooklynUserWithRandomPasswordSecurityProvider.java
@@ -20,12 +20,13 @@ package org.apache.brooklyn.rest.security.provider;
 
 import javax.servlet.http.HttpSession;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.rest.filter.BrooklynPropertiesSecurityFilter;
+import org.apache.brooklyn.util.javalang.JavaClassNames;
 import org.apache.brooklyn.util.net.Networking;
 import org.apache.brooklyn.util.text.Identifiers;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class BrooklynUserWithRandomPasswordSecurityProvider extends AbstractSecurityProvider implements SecurityProvider {
 
@@ -64,4 +65,9 @@ public class BrooklynUserWithRandomPasswordSecurityProvider extends AbstractSecu
             return false;
         }
     }
+    
+    @Override
+    public String toString() {
+        return JavaClassNames.cleanSimpleClassName(this);
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a57dbe4a/usage/rest-server/src/main/java/org/apache/brooklyn/rest/security/provider/DelegatingSecurityProvider.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/main/java/org/apache/brooklyn/rest/security/provider/DelegatingSecurityProvider.java b/usage/rest-server/src/main/java/org/apache/brooklyn/rest/security/provider/DelegatingSecurityProvider.java
index 52baab4..8b2b9da 100644
--- a/usage/rest-server/src/main/java/org/apache/brooklyn/rest/security/provider/DelegatingSecurityProvider.java
+++ b/usage/rest-server/src/main/java/org/apache/brooklyn/rest/security/provider/DelegatingSecurityProvider.java
@@ -27,6 +27,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.config.StringConfigMap;
+import org.apache.brooklyn.core.internal.BrooklynProperties;
 import org.apache.brooklyn.rest.BrooklynWebConfig;
 import org.apache.brooklyn.util.text.Strings;
 
@@ -67,6 +68,12 @@ public class DelegatingSecurityProvider implements SecurityProvider {
     private synchronized SecurityProvider loadDelegate() {
         StringConfigMap brooklynProperties = mgmt.getConfig();
 
+        SecurityProvider presetDelegate = brooklynProperties.getConfig(BrooklynWebConfig.SECURITY_PROVIDER_INSTANCE);
+        if (presetDelegate!=null) {
+            log.info("REST using pre-set security provider " + presetDelegate);
+            return presetDelegate;
+        }
+        
         String className = brooklynProperties.getConfig(BrooklynWebConfig.SECURITY_PROVIDER_CLASSNAME);
 
         if (delegate != null && BrooklynWebConfig.hasNoSecurityOptions(mgmt.getConfig())) {
@@ -107,6 +114,9 @@ public class DelegatingSecurityProvider implements SecurityProvider {
             log.warn("REST unable to instantiate security provider " + className + "; all logins are being disallowed", e);
             delegate = new BlackholeSecurityProvider();
         }
+        
+        ((BrooklynProperties)mgmt.getConfig()).put(BrooklynWebConfig.SECURITY_PROVIDER_INSTANCE, delegate);
+        
         return delegate;
     }
 


[08/15] incubator-brooklyn git commit: jsgui - tidy catalog error messages and check server status more often

Posted by he...@apache.org.
jsgui - tidy catalog error messages and check server status more often

(latter one allows it to switch back from "server not responsive" faster)


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/40959c6c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/40959c6c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/40959c6c

Branch: refs/heads/master
Commit: 40959c6c7721cb577afc84d4ae8ad6d0044af424
Parents: b961165
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Fri Sep 11 10:11:53 2015 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Fri Sep 11 10:54:39 2015 +0100

----------------------------------------------------------------------
 usage/jsgui/src/main/webapp/assets/css/base.css                   | 3 +++
 .../src/main/webapp/assets/js/model/server-extended-status.js     | 2 +-
 usage/jsgui/src/main/webapp/assets/js/view/catalog.js             | 2 +-
 usage/jsgui/src/main/webapp/assets/tpl/catalog/add-location.html  | 3 +--
 usage/jsgui/src/main/webapp/assets/tpl/catalog/add-yaml.html      | 3 +--
 5 files changed, 7 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/40959c6c/usage/jsgui/src/main/webapp/assets/css/base.css
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/main/webapp/assets/css/base.css b/usage/jsgui/src/main/webapp/assets/css/base.css
index 745540c..04a488d 100644
--- a/usage/jsgui/src/main/webapp/assets/css/base.css
+++ b/usage/jsgui/src/main/webapp/assets/css/base.css
@@ -1165,6 +1165,9 @@ tr.app-add-wizard-config-entry {
     padding: 7px;
     border-radius: 3px;
 }
+.catalog-error-message {
+    white-space: pre-wrap;
+}
 
 .float-right {
     float: right;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/40959c6c/usage/jsgui/src/main/webapp/assets/js/model/server-extended-status.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/main/webapp/assets/js/model/server-extended-status.js b/usage/jsgui/src/main/webapp/assets/js/model/server-extended-status.js
index e774294..aa9e5fa 100644
--- a/usage/jsgui/src/main/webapp/assets/js/model/server-extended-status.js
+++ b/usage/jsgui/src/main/webapp/assets/js/model/server-extended-status.js
@@ -58,7 +58,7 @@ define(["backbone", "brooklyn", "view/viewutils"], function (Backbone, Brooklyn,
             var that = this;
             // to debug:
 //            serverExtendedStatus.onLoad(function() { log("loaded server status:"); log(that.attributes); })
-            ViewUtils.fetchModelRepeatedlyWithDelay(this, { doitnow: true });
+            ViewUtils.fetchModelRepeatedlyWithDelay(this, { doitnow: true, backoffMaxPeriod: 3000 });
         },
 
         isUp: function() { return this.get("up") },

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/40959c6c/usage/jsgui/src/main/webapp/assets/js/view/catalog.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/main/webapp/assets/js/view/catalog.js b/usage/jsgui/src/main/webapp/assets/js/view/catalog.js
index 51d8a0a..7d4ab2a 100644
--- a/usage/jsgui/src/main/webapp/assets/js/view/catalog.js
+++ b/usage/jsgui/src/main/webapp/assets/js/view/catalog.js
@@ -210,7 +210,7 @@ define([
                         self.$(".catalog-save-error")
                             .removeClass("hide")
                             .find(".catalog-error-message")
-                            .html(Brooklyn.util.extractError(xhr, "Error adding catalog item: " + error));
+                            .html(_.escape(Brooklyn.util.extractError(xhr, "Could not add catalog item:\n'n" + error)));
                     });
             }
         });

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/40959c6c/usage/jsgui/src/main/webapp/assets/tpl/catalog/add-location.html
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/main/webapp/assets/tpl/catalog/add-location.html b/usage/jsgui/src/main/webapp/assets/tpl/catalog/add-location.html
index e57b83a..4748617 100644
--- a/usage/jsgui/src/main/webapp/assets/tpl/catalog/add-location.html
+++ b/usage/jsgui/src/main/webapp/assets/tpl/catalog/add-location.html
@@ -30,8 +30,7 @@ under the License.
 
     <p class="catalog-save-error hide">
         <span class="alert-error">
-            <strong>Error:</strong><br/>
-            <span class="catalog-error-message"></span>
+            <span class="catalog-error-message"><strong>Error</strong></span>
         </span>
     </p>
 </form>

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/40959c6c/usage/jsgui/src/main/webapp/assets/tpl/catalog/add-yaml.html
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/main/webapp/assets/tpl/catalog/add-yaml.html b/usage/jsgui/src/main/webapp/assets/tpl/catalog/add-yaml.html
index 9c64e90..bcd2d17 100644
--- a/usage/jsgui/src/main/webapp/assets/tpl/catalog/add-yaml.html
+++ b/usage/jsgui/src/main/webapp/assets/tpl/catalog/add-yaml.html
@@ -23,8 +23,7 @@ under the License.
     <button class='catalog-submit-button btn' data-loading-text='Saving...'>Submit</button>
     <p class="catalog-save-error hide">
         <span class="alert-error">
-            <strong>Error:</strong><br/>
-            <span class="catalog-error-message"></span>
+            <span class="catalog-error-message"><strong>Error</strong></span>
         </span>
     </p>
 </form>


[09/15] incubator-brooklyn git commit: don't show type when collapsing UserFacingExceptions

Posted by he...@apache.org.
don't show type when collapsing UserFacingExceptions


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/02d86fce
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/02d86fce
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/02d86fce

Branch: refs/heads/master
Commit: 02d86fce841a83e5e809dbe719e27db5be4ec23a
Parents: 40959c6
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Fri Sep 11 10:19:05 2015 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Fri Sep 11 10:54:40 2015 +0100

----------------------------------------------------------------------
 .../java/org/apache/brooklyn/util/exceptions/Exceptions.java    | 5 +++--
 .../apache/brooklyn/util/exceptions/UserFacingException.java    | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/02d86fce/utils/common/src/main/java/org/apache/brooklyn/util/exceptions/Exceptions.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/exceptions/Exceptions.java b/utils/common/src/main/java/org/apache/brooklyn/util/exceptions/Exceptions.java
index eac137d..c185890 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/util/exceptions/Exceptions.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/util/exceptions/Exceptions.java
@@ -64,12 +64,13 @@ public class Exceptions {
     private static List<Class<? extends Throwable>> BORING_PREFIX_THROWABLE_EXACT_TYPES = ImmutableList.<Class<? extends Throwable>>of(
         IllegalStateException.class, RuntimeException.class, CompoundRuntimeException.class);
 
-    /** Returns whether this is throwable either known to be boring or to have an unuseful prefix;
-     * null is *not* boring. */
+    /** Returns whether this is throwable either known to be boring or to have an unhelpful type name (prefix)
+     * which should be suppressed. null is accepted but treated as not boring. */
     public static boolean isPrefixBoring(Throwable t) {
         if (t==null) return false;
         if (isBoring(t))
             return true;
+        if (t instanceof UserFacingException) return true;
         for (Class<? extends Throwable> type: BORING_PREFIX_THROWABLE_EXACT_TYPES)
             if (t.getClass().equals(type)) return true;
         return false;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/02d86fce/utils/common/src/main/java/org/apache/brooklyn/util/exceptions/UserFacingException.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/exceptions/UserFacingException.java b/utils/common/src/main/java/org/apache/brooklyn/util/exceptions/UserFacingException.java
index 34673e6..1830ac8 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/util/exceptions/UserFacingException.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/util/exceptions/UserFacingException.java
@@ -19,7 +19,7 @@
 package org.apache.brooklyn.util.exceptions;
 
 /** marker interface, to show that an exception is suitable for pretty-printing to an end-user,
- * without including a stack trace */
+ * without the prefix (type) including a stack trace */
 public class UserFacingException extends RuntimeException {
 
     private static final long serialVersionUID = 2216885527195571323L;


[03/15] incubator-brooklyn git commit: refactor ExplicitUsersSecurityProvider.java so it is easier to share logic

Posted by he...@apache.org.
refactor ExplicitUsersSecurityProvider.java so it is easier to share logic


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/1e24fb52
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/1e24fb52
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/1e24fb52

Branch: refs/heads/master
Commit: 1e24fb52506c13582f2948ffe6a1b2da6b858db0
Parents: c217303
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Tue Sep 8 14:27:06 2015 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Tue Sep 8 14:36:54 2015 +0100

----------------------------------------------------------------------
 .../provider/ExplicitUsersSecurityProvider.java | 37 ++++++++++++++------
 1 file changed, 26 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1e24fb52/usage/rest-server/src/main/java/org/apache/brooklyn/rest/security/provider/ExplicitUsersSecurityProvider.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/main/java/org/apache/brooklyn/rest/security/provider/ExplicitUsersSecurityProvider.java b/usage/rest-server/src/main/java/org/apache/brooklyn/rest/security/provider/ExplicitUsersSecurityProvider.java
index 4874a1f..a0795cb 100644
--- a/usage/rest-server/src/main/java/org/apache/brooklyn/rest/security/provider/ExplicitUsersSecurityProvider.java
+++ b/usage/rest-server/src/main/java/org/apache/brooklyn/rest/security/provider/ExplicitUsersSecurityProvider.java
@@ -46,6 +46,7 @@ public class ExplicitUsersSecurityProvider extends AbstractSecurityProvider impl
 
     public ExplicitUsersSecurityProvider(ManagementContext mgmt) {
         this.mgmt = mgmt;
+        initialize();
     }
 
     private synchronized void initialize() {
@@ -56,8 +57,6 @@ public class ExplicitUsersSecurityProvider extends AbstractSecurityProvider impl
         allowedUsers = new LinkedHashSet<String>();
         String users = properties.getConfig(BrooklynWebConfig.USERS);
         if (users == null) {
-            // TODO unfortunately this is only activated *when* someone tries to log in
-            // (NB it seems like this class is not even instantiated until first log in)
             LOG.warn("REST has no users configured; no one will be able to log in!");
         } else if ("*".equals(users)) {
             LOG.info("REST allowing any user (so long as valid password is set)");
@@ -70,14 +69,11 @@ public class ExplicitUsersSecurityProvider extends AbstractSecurityProvider impl
             LOG.info("REST allowing users: " + allowedUsers);
         }
     }
-
     
     @Override
     public boolean authenticate(HttpSession session, String user, String password) {
         if (session==null || user==null) return false;
         
-        initialize();
-        
         if (!allowAnyUserWithValidPass) {
             if (!allowedUsers.contains(user)) {
                 LOG.debug("REST rejecting unknown user "+user);
@@ -85,16 +81,35 @@ public class ExplicitUsersSecurityProvider extends AbstractSecurityProvider impl
             }
         }
 
+        if (checkExplicitUserPassword(mgmt, user, password)) {
+            return allow(session, user);
+        }
+        return false;
+    }
+
+    /** checks the supplied candidate user and password against the
+     * expect password (or SHA-256 + SALT thereof) defined as brooklyn properties.
+     */
+    public static boolean checkExplicitUserPassword(ManagementContext mgmt, String user, String password) {
         BrooklynProperties properties = (BrooklynProperties) mgmt.getConfig();
-        String expectedP = properties.getConfig(BrooklynWebConfig.PASSWORD_FOR_USER(user));
+        String expectedPassword = properties.getConfig(BrooklynWebConfig.PASSWORD_FOR_USER(user));
         String salt = properties.getConfig(BrooklynWebConfig.SALT_FOR_USER(user));
         String expectedSha256 = properties.getConfig(BrooklynWebConfig.SHA256_FOR_USER(user));
         
-        if (expectedP != null) {
-            return expectedP.equals(password) && allow(session, user);
-        } else if (expectedSha256 != null) {
-            String hashedPassword = PasswordHasher.sha256(salt, password);
-            return expectedSha256.equals(hashedPassword) && allow(session, user);
+        return checkPassword(password, expectedPassword, expectedSha256, salt);
+    }
+    /** 
+     * checks a candidate password against the expected credential defined for a given user.
+     * the expected credentials can be supplied as an expectedPassword OR as
+     * a combination of the SHA-256 hash of the expected password plus a defined salt.
+     * the combination of the SHA+SALT allows credentials to be supplied in a non-plaintext manner.
+     */
+    public static boolean checkPassword(String candidatePassword, String expectedPassword, String expectedPasswordSha256, String salt) {
+        if (expectedPassword != null) {
+            return expectedPassword.equals(candidatePassword);
+        } else if (expectedPasswordSha256 != null) {
+            String hashedCandidatePassword = PasswordHasher.sha256(salt, candidatePassword);
+            return expectedPasswordSha256.equals(hashedCandidatePassword);
         }
 
         return false;


[04/15] incubator-brooklyn git commit: update ops docs - add REST reference, update others

Posted by he...@apache.org.
update ops docs - add REST reference, update others


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

Branch: refs/heads/master
Commit: bbe83662e64582a4ddc180e098e6160905b1093a
Parents: 1e24fb5
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Tue Sep 8 14:26:32 2015 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Tue Sep 8 14:47:57 2015 +0100

----------------------------------------------------------------------
 docs/guide/ops/cli-reference.md           | 201 +++++++++++++++++++++++++
 docs/guide/ops/index.md                   |   9 +-
 docs/guide/ops/install-on-server.md       | 131 ----------------
 docs/guide/ops/launch.md                  | 201 -------------------------
 docs/guide/ops/production-installation.md | 103 +++++++++++++
 docs/guide/ops/requirements.md            |   2 +-
 docs/guide/ops/rest.md                    |  89 +++++++++++
 7 files changed, 399 insertions(+), 337 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/bbe83662/docs/guide/ops/cli-reference.md
----------------------------------------------------------------------
diff --git a/docs/guide/ops/cli-reference.md b/docs/guide/ops/cli-reference.md
new file mode 100644
index 0000000..c4fd929
--- /dev/null
+++ b/docs/guide/ops/cli-reference.md
@@ -0,0 +1,201 @@
+---
+title: CLI Reference
+layout: website-normal
+---
+
+## Launch command
+
+To launch Brooklyn, from the directory where Brooklyn is unpacked, run:
+
+{% highlight bash %}
+% nohup bin/brooklyn launch > /dev/null 2&>1 &
+{% endhighlight %}
+
+With no configuration, this will launch the Brooklyn web console and REST API on [`http://localhost:8081/`](http://localhost:8081/).
+No password is set, but the server is listening only on the loopback network interface for security.
+Once [security is configured](brooklyn_properties.html), Brooklyn will listen on all network interfaces by default.
+By default, Brooklyn will write log messages at the INFO level or above to `brooklyn.info.log` and messgages at the
+DEBUG level or above to `brooklyn.debug.log`. Redirecting the output to `/dev/null` prevents the default console output
+being written to `nohup.out`.
+
+You may wish to [add Brooklyn to your path](#path-setup);
+assuming you've done this, to get information the supported CLI options 
+at any time, just run `brooklyn help`:
+
+{% highlight bash %}
+% bin/brooklyn help
+
+usage: brooklyn [(-q | --quiet)] [(-v | --verbose)] <command> [<args>]
+
+The most commonly used brooklyn commands are:
+    help     Display help information about brooklyn
+    info     Display information about brooklyn
+    launch   Starts a brooklyn application. Note that a BROOKLYN_CLASSPATH environment variable needs to be set up beforehand to point to the user application classpath.
+
+See 'brooklyn help <command>' for more information on a specific command.
+{% endhighlight %}
+
+It is important that Brooklyn is launched with either `nohup ... &` or `... & disown`, to ensure 
+it keeps running after the shell terminates.
+
+
+### Other CLI Arguments
+
+The CLI arguments for [persistence and HA](persistence/) are described separately.
+
+
+### Path Setup
+
+In order to have easy access to the cli it is useful to configure the PATH environment 
+variable to also point to the cli's bin directory:
+
+{% highlight bash %}
+BROOKLYN_HOME=/path/to/brooklyn/
+export PATH=$PATH:$BROOKLYN_HOME/usage/dist/target/brooklyn-dist/bin/
+{% endhighlight %}
+
+
+### Memory Usage
+
+The amount of memory required by the Brooklyn process depends on the usage 
+- for example the number of entities/VMs under management.
+
+For a standard Brooklyn deployment, the defaults are to start with 256m, and to grow to 1g of memory.
+These numbers can be overridden by setting the environment variable `JAVA_OPTS` before launching
+the `brooklyn script`:
+
+    JAVA_OPTS=-Xms1g -Xmx1g -XX:MaxPermSize=256m
+
+Brooklyn stores a task history in-memory using [soft references](http://docs.oracle.com/javase/7/docs/api/java/lang/ref/SoftReference.html).
+This means that, once the task history is large, Brooklyn will continually use the maximum allocated 
+memory. It will only expunge tasks from memory when this space is required for other objects within the
+Brooklyn process.
+
+
+## Configuration
+
+### Configuration Files
+
+Brooklyn reads configuration from a variety of places. It aggregates the configuration.
+The list below shows increasing precedence (i.e. the later ones will override values
+from earlier ones, if exactly the same property is specified multiple times).
+
+1. `classpath://brooklyn/location-metadata.properties` is shipped as part of Brooklyn, containing 
+   generic metadata such as jurisdiction and geographic information about Cloud providers.        
+1. The file `~/.brooklyn/location-metadata.properties` (unless `--noGlobalBrooklynProperties` is specified).
+   This is intended to contain custom metadata about additional locations.
+1. The file `~/.brooklyn/brooklyn.properties` (unless `--noGlobalBrooklynProperties` is specified).
+1. Another properties file, if the `--localBrooklynProperties <local brooklyn.properties file>` is specified.
+1. Shell environment variables
+1. System properties, supplied with ``-D`` on the brooklyn (Java) command-line.
+
+These properties are described in more detail [here](brooklyn_properties.html).
+
+
+### Extending the Classpath
+
+The default Brooklyn directory structure includes:
+
+* `./conf/`: for configuration resources.
+* `./lib/patch/`: for Jar files containing patches.
+* `./lib/brooklyn/`: for the brooklyn libraries.
+* `./lib/dropins/`: for additional Jars.
+
+Resources added to `conf/` will be available on the classpath.
+
+A patch can be applied by adding a Jar to the `lib/patch/` directory, and restarting Brooklyn.
+All jars in this directory will be at the head of the classpath.
+
+Additional Jars should be added to `lib/dropins/`, prior to starting Brooklyn. These jars will 
+be at the end of the classpath.
+
+The initial classpath, as set in the `brooklyn` script, is:
+
+    conf:lib/patch/*:lib/brooklyn/*:lib/dropins/*
+
+Additional entries can be added at the head of the classpath by setting the environment variable 
+`BROOKLYN_CLASSPATH` before running the `brooklyn` script. 
+
+
+### Replacing the web-console
+
+*Work in progress.*
+
+The Brooklyn web-console is loaded from the classpath as the resource `classpath://brooklyn.war`.
+
+To replace this, an alternative WAR with that name can be added at the head of the classpath.
+However, this approach is likely to change in a future release - consider this feature as "beta".
+
+
+## Cloud Explorer
+
+The `brooklyn` command line tool includes support for querying (and managing) cloud
+compute resources and blob-store resources. 
+
+For example, `brooklyn cloud-compute list-instances --location aws-ec2:eu-west-1`
+will use the AWS credentials from `brooklyn.properties` and list the VM instances
+running in the given EC2 region.
+
+Use `brooklyn help` and `brooklyn help cloud-compute` to find out more information.
+
+This functionality is not intended as a generic cloud management CLI, but instead 
+solves specific Brooklyn use-cases. The main use-case is discovering the valid 
+configuration options on a given cloud, such as for `imageId` and `hardwareId`.
+
+
+### Cloud Compute
+
+The command `brooklyn cloud-compute` has the following options:
+
+* `list-images`: lists VM images within the given cloud, which can be chosen when
+  provisioning new VMs.
+  This is useful for finding the possible values for the `imageId` configuration.
+
+* `get-image <imageId1> <imageId2> ...`: retrieves metadata about the specific images.
+
+* `list-hardware-profiles`: lists the ids and the details of the hardware profiles
+  available when provisioning. 
+  This is useful for finding the possible values for the `hardwareId` configuration.
+
+* `default-template`: retrieves metadata about the image and hardware profile that will
+  be used by Brooklyn for that location, if no additional configuration options
+  are supplied.
+
+* `list-instances`: lists the VM instances within the given cloud.
+
+* `terminate-instances <instanceId1> <instanceId2> ...`: Terminates the instances with
+  the given ids.
+
+
+### Blob Store
+
+The command `brooklyn cloud-blobstore` is used to access a given object store, such as S3
+or Swift. It has the following options:
+
+* `list-containers`: lists the containers (i.e. buckets in S3 terminology) within the 
+  given object store.
+
+* `list-container <containerName>`: lists all the blobs (i.e. objects) contained within 
+  the given container.
+
+* `blob --container <containerName> --blob <blobName>`: retrieves the given blob
+  (i.e. object), including metadata and its contents.
+
+  
+## Running from a Source Build
+
+Here is an example of the commands you might run to get the Brooklyn code, 
+compile it and launch an application:
+
+{% highlight bash %}
+git clone https://github.com/apache/incubator-brooklyn.git
+cd brooklyn
+mvn clean install -DskipTests
+BROOKLYN_HOME=$(pwd)
+export PATH=${PATH}:${BROOKLYN_HOME}/usage/dist/target/brooklyn-dist/bin/
+export BROOKLYN_CLASSPATH=${BROOKLYN_HOME}/examples/simple-web-cluster/target/classes
+nohup brooklyn launch --app brooklyn.demo.SingleWebServerExample --location localhost &
+{% endhighlight %}
+
+
+  

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/bbe83662/docs/guide/ops/index.md
----------------------------------------------------------------------
diff --git a/docs/guide/ops/index.md b/docs/guide/ops/index.md
index 1cb28aa..1f74074 100644
--- a/docs/guide/ops/index.md
+++ b/docs/guide/ops/index.md
@@ -2,16 +2,17 @@
 title: Operations
 layout: website-normal
 children:
-- requirements.md
-- install-on-server.md
-- launch.md
+- cli-reference.md
 - brooklyn_properties.md
 - locations/
 - persistence/
 - high-availability.md
 - catalog/
+- rest.md
 - logging.md
+- requirements.md
+- production-installation.md
 - troubleshooting/
 ---
 
-{% include list-children.html %}
\ No newline at end of file
+{% include list-children.html %}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/bbe83662/docs/guide/ops/install-on-server.md
----------------------------------------------------------------------
diff --git a/docs/guide/ops/install-on-server.md b/docs/guide/ops/install-on-server.md
deleted file mode 100644
index 48a527e..0000000
--- a/docs/guide/ops/install-on-server.md
+++ /dev/null
@@ -1,131 +0,0 @@
----
-layout: website-normal
-title: Installing Apache Brooklyn
----
-
-{% include fields.md %}
-
-Here we present two *alternatives* to install Apache Brooklyn:
-
-- [Running the *installation script*](#script)
-- [Manual installation](#manual)
-
-
-## <a id="script"></a> Running the Installation Script
-
-There is a simple bash script available to help with the installation process. 
-
-#### Script prerequisites
-The script assumes that the server is a recent *RHEL/CentOS 6.x Linux* or *Ubuntu 12.04* installation, but other Linux variants have been tested successfully.
-
-The script will install Java 7 and other required packages if they are not present. 
-You must have root access over [passwordless SSH]({{ site.path.guide }}/ops/locations/ssh-keys.html) 
-to install Brooklyn, but the service runs as an ordinary user once installed. 
-
-To manage the Brooklyn service you must also be able to connect to port 8081 remotely.
-
-Once the above prerequisites are satisfied, you should be able to run successfully:
-{% highlight bash %}
-$ curl -o brooklyn-install.sh -L https://github.com/apache/incubator-brooklyn/raw/master/brooklyn-install.sh
-$ chmod +x ./brooklyn-install.sh
-$ ./brooklyn-install.sh -s -r <your-server-ip>
-{% endhighlight %}
-
-
-## <a id="manual"></a> Manual Installation
-
-1. [Set up the prerequisites](#prerequisites)
-1. [Download Apache Brooklyn](#download)
-1. [Configuring brooklyn.properties](#configuring-properties)
-1. [Configuring default.catalog.bom](#configuring-catalog)
-1. [Test the installation](#confirm)
-
-
-### <a id="prerequisites"></a>Set up the Prerequisites
-
-Before installing Brooklyn, it is recommended to configure the host as follows. 
-
-* install Java JRE or JDK (version 7 or later)
-* install an [SSH key]({{ site.path.guide }}/ops/locations/ssh-keys.html), if not available
-* enable [passwordless ssh login]({{ site.path.guide }}/ops/locations/ssh-keys.html)
-* create a `~/.brooklyn` directory on the host with `$ mkdir ~/.brooklyn`
-* check your `iptables` or other firewall service, making sure that incoming connections on port 8443 is not blocked
-* check that the [linux kernel entropy]({{ site.path.website }}/documentation/increase-entropy.html) is sufficient
-
-
-### <a id="download"></a>Download Apache Brooklyn
-
-Download Brooklyn and obtain a binary build as described on [the download page]({{site.path.website}}/download/).
-
-{% if brooklyn_version contains 'SNAPSHOT' %}
-Expand the `tar.gz` archive (note: as this is a -SNAPSHOT version, your filename will be slightly different):
-{% else %}
-Expand the `tar.gz` archive:
-{% endif %}
-
-{% if brooklyn_version contains 'SNAPSHOT' %}
-{% highlight bash %}
-$ tar -zxf apache-brooklyn-dist-{{ site.brooklyn-stable-version }}-timestamp-dist.tar.gz
-{% endhighlight %}
-{% else %}
-{% highlight bash %}
-$ tar -zxf apache-brooklyn-{{ site.brooklyn-stable-version }}-dist.tar.gz
-{% endhighlight %}
-{% endif %}
-
-This will create a `apache-brooklyn-{{ site.brooklyn-stable-version }}` folder.
-
-Let's setup some paths for easy commands.
-
-{% highlight bash %}
-$ cd apache-brooklyn-{{ site.brooklyn-stable-version }}
-$ BROOKLYN_DIR="$(pwd)"
-$ export PATH=$PATH:$BROOKLYN_DIR/bin/
-{% endhighlight %}
-
-
-### <a id="configuring-properties"></a>Configuring brooklyn.properties
-
-Brooklyn deploys applications to Locations. *Locations* can be clouds, machines with fixed IPs or localhost (for testing).
-
-By default Brooklyn loads configuration parameters (including credentials for any cloud accounts) from 
-
-`~/.brooklyn/brooklyn.properties` 
-
-The `brooklyn.properties` is the main configuration file for deployment locations. Contains the connection details and credentials for all public or on-premises cloud providers, as well as controlling some application startup and security options.
-
-Create a `.brooklyn` folder in your home directory and download the template [brooklyn.properties]({{brooklyn_properties_url_path}}) to that folder.
-
-{% highlight bash %}
-$ mkdir -p ~/.brooklyn
-$ wget -O ~/.brooklyn/brooklyn.properties {{brooklyn_properties_url_live}}
-$ chmod 600 ~/.brooklyn/brooklyn.properties
-{% endhighlight %}
-
-You may need to edit `~/.brooklyn/brooklyn.properties` to ensure that brooklyn can access cloud locations for application deployment.
-
-
-### <a id="configuring-catalog"></a>Configuring the Catalog
-
-By default Brooklyn loads the catalog of available application components and services from 
-`default.catalog.bom` on the classpath. The initial catalog is in `conf/brooklyn/` in the dist.
-If you have a preferred catalog, simply replace that file.
-
-
-### <a id="confirm"></a>Confirm Installation
-
-We can do a quick test drive by launching Brooklyn:
-
-{% highlight bash %}
-$ brooklyn launch
-{% endhighlight %}
-
-Brooklyn will output the address of the management interface:
-
-{% highlight bash %}
-INFO  Starting brooklyn web-console on loopback interface because no security config is set
-
-INFO  Started Brooklyn console at http://127.0.0.1:8081/, running classpath://brooklyn.war and []
-{% endhighlight %}
-
-Stop Brooklyn with ctrl-c.

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/bbe83662/docs/guide/ops/launch.md
----------------------------------------------------------------------
diff --git a/docs/guide/ops/launch.md b/docs/guide/ops/launch.md
deleted file mode 100644
index bdfa47d..0000000
--- a/docs/guide/ops/launch.md
+++ /dev/null
@@ -1,201 +0,0 @@
----
-title: Launching Brooklyn
-layout: website-normal
----
-
-## Launch command
-
-To launch Brooklyn, from the directory where Brooklyn is unpacked, run:
-
-{% highlight bash %}
-% nohup bin/brooklyn launch > /dev/null 2&>1 &
-{% endhighlight %}
-
-With no configuration, this will launch the Brooklyn web console and REST API on [`http://localhost:8081/`](http://localhost:8081/).
-No password is set, but the server is listening only on the loopback network interface for security.
-Once [security is configured](brooklyn_properties.html), Brooklyn will listen on all network interfaces by default.
-By default, Brooklyn will write log messages at the INFO level or above to `brooklyn.info.log` and messgages at the
-DEBUG level or above to `brooklyn.debug.log`. Redirecting the output to `/dev/null` prevents the default console output
-being written to `nohup.out`.
-
-You may wish to [add Brooklyn to your path](#path-setup);
-assuming you've done this, to get information the supported CLI options 
-at any time, just run `brooklyn help`:
-
-{% highlight bash %}
-% bin/brooklyn help
-
-usage: brooklyn [(-q | --quiet)] [(-v | --verbose)] <command> [<args>]
-
-The most commonly used brooklyn commands are:
-    help     Display help information about brooklyn
-    info     Display information about brooklyn
-    launch   Starts a brooklyn application. Note that a BROOKLYN_CLASSPATH environment variable needs to be set up beforehand to point to the user application classpath.
-
-See 'brooklyn help <command>' for more information on a specific command.
-{% endhighlight %}
-
-It is important that Brooklyn is launched with either `nohup ... &` or `... & disown`, to ensure 
-it keeps running after the shell terminates.
-
-
-### Other CLI Arguments
-
-The CLI arguments for [persistence and HA](persistence/) are described separately.
-
-
-### Path Setup
-
-In order to have easy access to the cli it is useful to configure the PATH environment 
-variable to also point to the cli's bin directory:
-
-{% highlight bash %}
-BROOKLYN_HOME=/path/to/brooklyn/
-export PATH=$PATH:$BROOKLYN_HOME/usage/dist/target/brooklyn-dist/bin/
-{% endhighlight %}
-
-
-### Memory Usage
-
-The amount of memory required by the Brooklyn process depends on the usage 
-- for example the number of entities/VMs under management.
-
-For a standard Brooklyn deployment, the defaults are to start with 256m, and to grow to 1g of memory.
-These numbers can be overridden by setting the environment variable `JAVA_OPTS` before launching
-the `brooklyn script`:
-
-    JAVA_OPTS=-Xms1g -Xmx1g -XX:MaxPermSize=256m
-
-Brooklyn stores a task history in-memory using [soft references](http://docs.oracle.com/javase/7/docs/api/java/lang/ref/SoftReference.html).
-This means that, once the task history is large, Brooklyn will continually use the maximum allocated 
-memory. It will only expunge tasks from memory when this space is required for other objects within the
-Brooklyn process.
-
-
-## Configuration
-
-### Configuration Files
-
-Brooklyn reads configuration from a variety of places. It aggregates the configuration.
-The list below shows increasing precedence (i.e. the later ones will override values
-from earlier ones, if exactly the same property is specified multiple times).
-
-1. `classpath://brooklyn/location-metadata.properties` is shipped as part of Brooklyn, containing 
-   generic metadata such as jurisdiction and geographic information about Cloud providers.        
-1. The file `~/.brooklyn/location-metadata.properties` (unless `--noGlobalBrooklynProperties` is specified).
-   This is intended to contain custom metadata about additional locations.
-1. The file `~/.brooklyn/brooklyn.properties` (unless `--noGlobalBrooklynProperties` is specified).
-1. Another properties file, if the `--localBrooklynProperties <local brooklyn.properties file>` is specified.
-1. Shell environment variables
-1. System properties, supplied with ``-D`` on the brooklyn (Java) command-line.
-
-These properties are described in more detail [here](brooklyn_properties.html).
-
-
-### Extending the Classpath
-
-The default Brooklyn directory structure includes:
-
-* `./conf/`: for configuration resources.
-* `./lib/patch/`: for Jar files containing patches.
-* `./lib/brooklyn/`: for the brooklyn libraries.
-* `./lib/dropins/`: for additional Jars.
-
-Resources added to `conf/` will be available on the classpath.
-
-A patch can be applied by adding a Jar to the `lib/patch/` directory, and restarting Brooklyn.
-All jars in this directory will be at the head of the classpath.
-
-Additional Jars should be added to `lib/dropins/`, prior to starting Brooklyn. These jars will 
-be at the end of the classpath.
-
-The initial classpath, as set in the `brooklyn` script, is:
-
-    conf:lib/patch/*:lib/brooklyn/*:lib/dropins/*
-
-Additional entries can be added at the head of the classpath by setting the environment variable 
-`BROOKLYN_CLASSPATH` before running the `brooklyn` script. 
-
-
-### Replacing the web-console
-
-*Work in progress.*
-
-The Brooklyn web-console is loaded from the classpath as the resource `classpath://brooklyn.war`.
-
-To replace this, an alternative WAR with that name can be added at the head of the classpath.
-However, this approach is likely to change in a future release - consider this feature as "beta".
-
-
-## Cloud Explorer
-
-The `brooklyn` command line tool includes support for querying (and managing) cloud
-compute resources and blob-store resources. 
-
-For example, `brooklyn cloud-compute list-instances --location aws-ec2:eu-west-1`
-will use the AWS credentials from `brooklyn.properties` and list the VM instances
-running in the given EC2 region.
-
-Use `brooklyn help` and `brooklyn help cloud-compute` to find out more information.
-
-This functionality is not intended as a generic cloud management CLI, but instead 
-solves specific Brooklyn use-cases. The main use-case is discovering the valid 
-configuration options on a given cloud, such as for `imageId` and `hardwareId`.
-
-
-### Cloud Compute
-
-The command `brooklyn cloud-compute` has the following options:
-
-* `list-images`: lists VM images within the given cloud, which can be chosen when
-  provisioning new VMs.
-  This is useful for finding the possible values for the `imageId` configuration.
-
-* `get-image <imageId1> <imageId2> ...`: retrieves metadata about the specific images.
-
-* `list-hardware-profiles`: lists the ids and the details of the hardware profiles
-  available when provisioning. 
-  This is useful for finding the possible values for the `hardwareId` configuration.
-
-* `default-template`: retrieves metadata about the image and hardware profile that will
-  be used by Brooklyn for that location, if no additional configuration options
-  are supplied.
-
-* `list-instances`: lists the VM instances within the given cloud.
-
-* `terminate-instances <instanceId1> <instanceId2> ...`: Terminates the instances with
-  the given ids.
-
-
-### Blob Store
-
-The command `brooklyn cloud-blobstore` is used to access a given object store, such as S3
-or Swift. It has the following options:
-
-* `list-containers`: lists the containers (i.e. buckets in S3 terminology) within the 
-  given object store.
-
-* `list-container <containerName>`: lists all the blobs (i.e. objects) contained within 
-  the given container.
-
-* `blob --container <containerName> --blob <blobName>`: retrieves the given blob
-  (i.e. object), including metadata and its contents.
-
-  
-## Running from a Source Build
-
-Here is an example of the commands you might run to get the Brooklyn code, 
-compile it and launch an application:
-
-{% highlight bash %}
-git clone https://github.com/apache/incubator-brooklyn.git
-cd brooklyn
-mvn clean install -DskipTests
-BROOKLYN_HOME=$(pwd)
-export PATH=${PATH}:${BROOKLYN_HOME}/usage/dist/target/brooklyn-dist/bin/
-export BROOKLYN_CLASSPATH=${BROOKLYN_HOME}/examples/simple-web-cluster/target/classes
-nohup brooklyn launch --app brooklyn.demo.SingleWebServerExample --location localhost &
-{% endhighlight %}
-
-
-  

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/bbe83662/docs/guide/ops/production-installation.md
----------------------------------------------------------------------
diff --git a/docs/guide/ops/production-installation.md b/docs/guide/ops/production-installation.md
new file mode 100644
index 0000000..b0110d5
--- /dev/null
+++ b/docs/guide/ops/production-installation.md
@@ -0,0 +1,103 @@
+---
+layout: website-normal
+title: Production Installation
+---
+
+{% include fields.md %}
+
+To install Apache Brooklyn on a production server:
+
+1. [Set up the prerequisites](#prerequisites)
+1. [Download Apache Brooklyn](#download)
+1. [Configuring brooklyn.properties](#configuring-properties)
+1. [Configuring default.catalog.bom](#configuring-catalog)
+1. [Test the installation](#confirm)
+
+This guide covers the basics. You may also wish to configure:
+
+* [Logging](logging.md)
+* [Persistence](persistence/)
+* [High availability](high-availability.md)
+
+
+### <a id="prerequisites"></a>Set up the Prerequisites
+
+Check that the server meets the [requirements](requirements.md).
+Then configure the server as follows:
+
+* install Java JRE or JDK (version 7 or later)
+* install an [SSH key]({{ site.path.guide }}/ops/locations/ssh-keys.html), if not available
+* enable [passwordless ssh login]({{ site.path.guide }}/ops/locations/ssh-keys.html)
+* create a `~/.brooklyn` directory on the host with `$ mkdir ~/.brooklyn`
+* check your `iptables` or other firewall service, making sure that incoming connections on port 8443 is not blocked
+* check that the [linux kernel entropy]({{ site.path.website }}/documentation/increase-entropy.html) is sufficient
+
+
+### <a id="download"></a>Download Apache Brooklyn
+
+Download Brooklyn and obtain a binary build as described on [the download page]({{site.path.website}}/download/).
+
+{% if brooklyn_version contains 'SNAPSHOT' %}
+Expand the `tar.gz` archive (note: as this is a -SNAPSHOT version, your filename will be slightly different):
+{% else %}
+Expand the `tar.gz` archive:
+{% endif %}
+
+{% if brooklyn_version contains 'SNAPSHOT' %}
+{% highlight bash %}
+% tar -zxf apache-brooklyn-dist-{{ site.brooklyn-stable-version }}-timestamp-dist.tar.gz
+{% endhighlight %}
+{% else %}
+{% highlight bash %}
+% tar -zxf apache-brooklyn-{{ site.brooklyn-stable-version }}-dist.tar.gz
+{% endhighlight %}
+{% endif %}
+
+This will create a `apache-brooklyn-{{ site.brooklyn-stable-version }}` folder.
+
+Let's setup some paths for easy commands.
+
+{% highlight bash %}
+% cd apache-brooklyn-{{ site.brooklyn-stable-version }}
+% BROOKLYN_DIR="$(pwd)"
+% export PATH=$PATH:$BROOKLYN_DIR/bin/
+{% endhighlight %}
+
+
+### <a id="configuring-properties"></a>Configuring brooklyn.properties
+
+Set up `brooklyn.properties` as described [here](brooklyn_properties.md):
+
+* Configure the users who should have access
+* Turn on HTTPS
+* Supply credentials for any pre-defined clouds
+
+It may be useful to use the following script to install an initial `brooklyn.properties`:
+
+{% highlight bash %}
+% mkdir -p ~/.brooklyn
+% wget -O ~/.brooklyn/brooklyn.properties {{brooklyn_properties_url_live}}
+% chmod 600 ~/.brooklyn/brooklyn.properties
+{% endhighlight %}
+
+
+### <a id="configuring-catalog"></a>Configuring the Catalog
+
+By default Brooklyn loads the catalog of available application components and services from 
+`default.catalog.bom` on the classpath. The initial catalog is in `conf/brooklyn/` in the dist.
+If you have a preferred catalog, simply replace that file.
+
+[More information on the catalog is available here.](catalog/)
+
+
+### <a id="confirm"></a>Confirm Installation
+
+Launch Brooklyn in a disconnected session so it will remain running after you have logged out:
+
+{% highlight bash %}
+% nohup bin/brooklyn launch > /dev/null 2&>1 &
+{% endhighlight %}
+
+Apache Brooklyn should now be running on port 8081 (or other port if so specified).
+
+

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/bbe83662/docs/guide/ops/requirements.md
----------------------------------------------------------------------
diff --git a/docs/guide/ops/requirements.md b/docs/guide/ops/requirements.md
index e86629e..634e4e6 100644
--- a/docs/guide/ops/requirements.md
+++ b/docs/guide/ops/requirements.md
@@ -15,7 +15,7 @@ For dev/test or when there are only a handful of VMs being managed, a small VM i
 For example, an AWS m3.medium with one vCPU, 3.75GiB RAM and 4GB disk.
 
 For larger production uses, a more appropriate machine spec would be two or more cores,
-at least 8GB RAM and 20GB disk. The disk is just for logs, a small amount of persisted state, and
+at least 8GB RAM and 100GB disk. The disk is just for logs, a small amount of persisted state, and
 any binaries for custom blueprints/integrations.
 
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/bbe83662/docs/guide/ops/rest.md
----------------------------------------------------------------------
diff --git a/docs/guide/ops/rest.md b/docs/guide/ops/rest.md
new file mode 100644
index 0000000..c1d7b64
--- /dev/null
+++ b/docs/guide/ops/rest.md
@@ -0,0 +1,89 @@
+---
+title: REST API
+layout: website-normal
+---
+
+Apache Brooklyn exposes a powerful REST API, 
+allowing it to be scripted from bash or integrated with other systems.
+
+For many commands, the REST call follows the same structure as the web console URL
+scheme, but with the `#` at the start of the path removed; for instance the catalog
+item `cluster` in the web console is displayed at:
+
+<!-- BROOKLYN_VERSION_BELOW -->
+    http://localhost:8081/#v1/catalog/entities/cluster:0.9.0-SNAPSHOT
+
+And in the REST API it is accessed at:
+
+<!-- BROOKLYN_VERSION_BELOW -->
+    http://localhost:8081/v1/catalog/entities/cluster:0.9.0-SNAPSHOT
+
+A full reference for the REST API is automatically generated by the server at runtime.
+It can be found in the Brooklyn web console, under the Script tab.
+
+Here we include some of the most common REST examples and other advice for working with the REST API.
+
+
+### Tooling Tips
+
+For command-line access, we recommend `curl`, with tips below. 
+
+For navigating in a browser we recommend getting a plugin for 
+working with REST; these are available for most browsers and
+make it easier to authenticate, set headers, and see JSON responses.
+
+For manipulating JSON responses on the command-line,
+the library `jq` from [stedolan's github](https://stedolan.github.io/jq/)
+is very useful, and available in most package repositories, including `port` and `brew` on Mac.
+
+
+### Common REST Examples
+
+Here are some useful snippets:
+
+* List applications
+  
+      curl http://localhost:8081/v1/applications
+
+* Deploy an application from `__FILE__`
+
+      curl http://localhost:8081/v1/applications --data-binary @__FILE__
+
+* Get details of a task with ID `__ID__` (where the `id` is returned by the above,
+  optionally piped to `jq .id`)
+
+      curl http://localhost:8081/v1/activities/__ID__
+
+* Get the value of sensor `service.state` on entity `e1` in application `app1`
+  (note you can use either the entity's ID or its name)
+  
+      curl http://localhost:8081/v1/applications/app1/entities/e1/sensors/service.state
+
+* Get all sensor values (using the pseudo-sensor `current-state`)
+
+      curl http://localhost:8081/v1/applications/app1/entities/e1/sensors/service.state
+
+* Invoke an effector `eff` on `e1`, with argument `arg1` equal to `hi`
+  (note if no arguments, you must specify `-d ""`; for multiple args, just use multiple `-d` entries,
+  or a JSON file with `--data-binary @...`)
+
+      curl http://localhost:8081/v1/applications/app1/entities/e1/effectors/eff -d arg1=hi
+
+* Add an item to the catalog from `__FILE__`
+
+      curl http://localhost:8081/v1/catalog --data-binary @__FILE__
+
+
+### Curl Cheat Sheet
+
+* if authentication is required, use `--user username:password`
+* to see detailed output, including headers, code, and errors, use `-v`
+* where the request is not a simple HTTP GET, use `-X POST` or `-X DELETE`
+* to pass key-value data to a post, use `-d key=value`
+* where you are posting from a file `__FILE__`, use `--data-binary @__FILE__` (implies a POST) or `-T __FILE__ -X POST`
+* to add a header, use `-H "key: value"`, for example `-H "Brooklyn-Allow-Non-Master-Access: true"`
+* to specify that a specific content-type is being uploaded, use `-H "Content-Type: application/json"` (or `application/yaml`)
+* to specify the content-type required for the result, use `-H "Accept: application/json"` 
+  (or `application/yaml`, or for sensor values, `text/plain`)
+
+


[02/15] incubator-brooklyn git commit: misc better api usability, javadoc, and debugging, esp around feeds

Posted by he...@apache.org.
misc better api usability, javadoc, and debugging, esp around feeds

sensors have a default persistence mode,
`Entities.dumpInfo` will list feeds (which aren't persisted),
`EntityInitializer` explains its lifecycle better,
and CAMP gives a slightly more useful error


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

Branch: refs/heads/master
Commit: c217303e526ccc166b7dcfc4b970cb6dbfb547f3
Parents: a57dbe4
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Tue Sep 8 13:31:56 2015 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Tue Sep 8 13:31:56 2015 +0100

----------------------------------------------------------------------
 .../brooklyn/api/entity/EntityInitializer.java  |  9 +++++
 .../BasicAssemblyTemplateInstantiator.java      |  2 +-
 .../apache/brooklyn/core/entity/Entities.java   | 37 ++++++++++++++++++--
 .../apache/brooklyn/core/sensor/Sensors.java    |  2 +-
 4 files changed, 45 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c217303e/api/src/main/java/org/apache/brooklyn/api/entity/EntityInitializer.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/brooklyn/api/entity/EntityInitializer.java b/api/src/main/java/org/apache/brooklyn/api/entity/EntityInitializer.java
index 24ae8d3..a9f407a 100644
--- a/api/src/main/java/org/apache/brooklyn/api/entity/EntityInitializer.java
+++ b/api/src/main/java/org/apache/brooklyn/api/entity/EntityInitializer.java
@@ -20,12 +20,21 @@ package org.apache.brooklyn.api.entity;
 
 import java.util.Map;
 
+import org.apache.brooklyn.api.objs.EntityAdjunct;
+import org.apache.brooklyn.api.policy.Policy;
+import org.apache.brooklyn.api.sensor.Feed;
+
 /** 
  * Instances of this class supply logic which can be used to initialize entities. 
  * These can be added to an {@link EntitySpec} programmatically, or declared as part
  * of YAML recipes in a <code>brooklyn.initializers</code> section.
  * In the case of the latter, implementing classes should define a no-arg constructor
  * or a {@link Map} constructor so that YAML parameters can be supplied.
+ * <p>
+ * Note that initializers are only invoked on first creation; they are not called 
+ * during a rebind. Instead, the typical pattern is that initializers will create
+ * {@link EntityAdjunct} instances such as {@link Policy} and {@link Feed}
+ * which will be attached during rebind.
  **/ 
 public interface EntityInitializer {
     

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c217303e/camp/camp-base/src/main/java/org/apache/brooklyn/camp/spi/instantiate/BasicAssemblyTemplateInstantiator.java
----------------------------------------------------------------------
diff --git a/camp/camp-base/src/main/java/org/apache/brooklyn/camp/spi/instantiate/BasicAssemblyTemplateInstantiator.java b/camp/camp-base/src/main/java/org/apache/brooklyn/camp/spi/instantiate/BasicAssemblyTemplateInstantiator.java
index 28eac3a..82751c3 100644
--- a/camp/camp-base/src/main/java/org/apache/brooklyn/camp/spi/instantiate/BasicAssemblyTemplateInstantiator.java
+++ b/camp/camp-base/src/main/java/org/apache/brooklyn/camp/spi/instantiate/BasicAssemblyTemplateInstantiator.java
@@ -30,7 +30,7 @@ public class BasicAssemblyTemplateInstantiator implements AssemblyTemplateInstan
 //        template.getPlatformComponentTemplates().links().iterator().next().resolve();
         
         // platforms should set a bunch of instantiators, or else let the ComponentTemplates do this!
-        throw new UnsupportedOperationException("Basic instantiator not yet supported");
+        throw new UnsupportedOperationException("No instantiator could be found which understands the submitted plan. Basic instantiator not yet supported.");
     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c217303e/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java b/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java
index c1a77ad..c2c2195 100644
--- a/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java
+++ b/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java
@@ -58,6 +58,7 @@ import org.apache.brooklyn.api.mgmt.TaskFactory;
 import org.apache.brooklyn.api.policy.Policy;
 import org.apache.brooklyn.api.sensor.AttributeSensor;
 import org.apache.brooklyn.api.sensor.Enricher;
+import org.apache.brooklyn.api.sensor.Feed;
 import org.apache.brooklyn.api.sensor.Sensor;
 import org.apache.brooklyn.config.ConfigKey;
 import org.apache.brooklyn.config.ConfigKey.HasConfigKey;
@@ -318,7 +319,10 @@ public class Entities {
 
         out.append(currentIndentation+tab+tab+"locations = "+e.getLocations()+"\n");
 
-        Set<ConfigKey<?>> keys = Sets.newLinkedHashSet( ((EntityInternal)e).getConfigMap().getLocalConfig().keySet() );
+        Set<ConfigKey<?>> keys = Sets.newLinkedHashSet(
+            ((EntityInternal)e).config().getLocalBag().getAllConfigAsConfigKeyMap().keySet()
+            //((EntityInternal)e).getConfigMap().getLocalConfig().keySet() 
+            );
         for (ConfigKey<?> it : sortConfigKeys(keys)) {
             // use the official config key declared on the type if available
             // (since the map sometimes contains <object> keys
@@ -385,6 +389,13 @@ public class Entities {
             }
         }
 
+        if (!((EntityInternal)e).feeds().getFeeds().isEmpty()) {
+            out.append(currentIndentation+tab+tab+"Feeds:\n");
+            for (Feed feed : ((EntityInternal)e).feeds().getFeeds()) {
+                dumpInfo(feed, out, currentIndentation+tab+tab+tab, tab);
+            }
+        }
+
         for (Entity it : e.getChildren()) {
             dumpInfo(it, out, currentIndentation+tab, tab);
         }
@@ -477,6 +488,26 @@ public class Entities {
 
         out.flush();
     }
+    public static void dumpInfo(Feed feed, String currentIndentation, String tab) throws IOException {
+        dumpInfo(feed, new PrintWriter(System.out), currentIndentation, tab);
+    }
+    public static void dumpInfo(Feed feed, Writer out, String currentIndentation, String tab) throws IOException {
+        out.append(currentIndentation+feed.toString()+"\n");
+
+        // TODO create a FeedType cf EnricherType ?
+        for (ConfigKey<?> key : sortConfigKeys(((BrooklynObjectInternal)feed).config().getBag().getAllConfigAsConfigKeyMap().keySet())) {
+            Maybe<Object> val = ((BrooklynObjectInternal)feed).config().getRaw(key);
+            if (!isTrivial(val)) {
+                out.append(currentIndentation+tab+tab+key);
+                out.append(" = ");
+                if (isSecret(key.getName())) out.append("xxxxxxxx");
+                else out.append(""+val.get());
+                out.append("\n");
+            }
+        }
+
+        out.flush();
+    }
 
     public static void dumpInfo(Policy pol) {
         try {
@@ -963,7 +994,7 @@ public class Entities {
     }
 
     public static <T> Supplier<T> attributeSupplier(Entity entity, AttributeSensor<T> sensor) {
-        return EntityAndAttribute.supplier(entity, sensor);
+        return EntityAndAttribute.create(entity, sensor);
     }
 
     public static <T> Supplier<T> attributeSupplier(EntityAndAttribute<T> tuple) { return tuple; }
@@ -1061,7 +1092,7 @@ public class Entities {
 
     /** Logs a warning if an entity has a value for a config key. */
     public static void warnOnIgnoringConfig(Entity entity, ConfigKey<?> key) {
-        if (entity.getConfigRaw(key, true).isPresentAndNonNull())
+        if (((EntityInternal)entity).config().getRaw(key).isPresentAndNonNull())
             log.warn("Ignoring "+key+" set on "+entity+" ("+entity.getConfig(key)+")");
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c217303e/core/src/main/java/org/apache/brooklyn/core/sensor/Sensors.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/sensor/Sensors.java b/core/src/main/java/org/apache/brooklyn/core/sensor/Sensors.java
index 05227d0..823689d 100644
--- a/core/src/main/java/org/apache/brooklyn/core/sensor/Sensors.java
+++ b/core/src/main/java/org/apache/brooklyn/core/sensor/Sensors.java
@@ -56,7 +56,7 @@ public class Sensors {
         private String name;
         private TypeToken<T> type;
         private String description;
-        private SensorPersistenceMode persistence;
+        private SensorPersistenceMode persistence = SensorPersistenceMode.REQUIRED;
         
         protected Builder() { // use builder(type, name) instead
         }


[07/15] incubator-brooklyn git commit: better warnings on plan parse failures

Posted by he...@apache.org.
better warnings on plan parse failures


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

Branch: refs/heads/master
Commit: b9611658cce8d56be164692b55e615a31828b5a3
Parents: 2009a04
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Thu Sep 10 14:01:04 2015 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Thu Sep 10 14:02:02 2015 +0100

----------------------------------------------------------------------
 .../core/catalog/internal/CatalogInitialization.java        | 3 +++
 .../org/apache/brooklyn/core/plan/PlanToSpecFactory.java    | 9 +++++++--
 2 files changed, 10 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/b9611658/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
index 041037f..525e903 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
@@ -208,6 +208,9 @@ public class CatalogInitialization implements ManagementContextInjectable {
                     // once up and running the typical way to add items is via the REST API
                     hasRunFinalInitialization = true;
                 }
+            } catch (Throwable e) {
+                log.warn("Error populating catalog (rethrowing): "+e, e);
+                throw Exceptions.propagate(e);
             } finally {
                 if (!hasRunFinalInitialization) {
                     hasRunTransientOfficialInitialization = true;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/b9611658/core/src/main/java/org/apache/brooklyn/core/plan/PlanToSpecFactory.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/plan/PlanToSpecFactory.java b/core/src/main/java/org/apache/brooklyn/core/plan/PlanToSpecFactory.java
index a2e6500..491a74e 100644
--- a/core/src/main/java/org/apache/brooklyn/core/plan/PlanToSpecFactory.java
+++ b/core/src/main/java/org/apache/brooklyn/core/plan/PlanToSpecFactory.java
@@ -95,11 +95,16 @@ public class PlanToSpecFactory {
         Collection<Exception> otherProblemsFromTransformers = new ArrayList<Exception>();
         for (PlanToSpecTransformer t: transformers) {
             try {
-                return Maybe.of(f.apply(t));
+                T result = f.apply(t);
+                if (result==null) {
+                    transformersWhoDontSupport.add(t.getShortDescription() + " (returned null)");
+                    continue;
+                }
+                return Maybe.of(result);
             } catch (PlanNotRecognizedException e) {
                 transformersWhoDontSupport.add(t.getShortDescription() +
                     (Strings.isNonBlank(e.getMessage()) ? " ("+e.getMessage()+")" : ""));
-            } catch (Exception e) {
+            } catch (Throwable e) {
                 Exceptions.propagateIfFatal(e);
                 otherProblemsFromTransformers.add(new IllegalArgumentException("Transformer for "+t.getShortDescription()+" gave an error creating this plan: "+
                     Exceptions.collapseText(e), e));


[06/15] incubator-brooklyn git commit: fix archive builder inclusion of "/" as an entry, and improve api and javadoc

Posted by he...@apache.org.
fix archive builder inclusion of "/" as an entry, and improve api and javadoc

a "/" entry can cause the java FileTreeWalker to recurse infinitely and stack overflow


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/2009a041
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/2009a041
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/2009a041

Branch: refs/heads/master
Commit: 2009a041de953f4467b1ebf9f9b8e1ddfce3d1ba
Parents: a340dbc
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Thu Sep 10 14:00:15 2015 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Thu Sep 10 14:02:00 2015 +0100

----------------------------------------------------------------------
 .../brooklyn/util/core/file/ArchiveBuilder.java | 61 +++++++++++++-------
 .../util/core/file/ArchiveBuilderTest.java      | 44 ++++++++------
 .../java/org/apache/brooklyn/util/os/Os.java    |  3 +-
 3 files changed, 67 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2009a041/core/src/main/java/org/apache/brooklyn/util/core/file/ArchiveBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/util/core/file/ArchiveBuilder.java b/core/src/main/java/org/apache/brooklyn/util/core/file/ArchiveBuilder.java
index b880682..5213d8e 100644
--- a/core/src/main/java/org/apache/brooklyn/util/core/file/ArchiveBuilder.java
+++ b/core/src/main/java/org/apache/brooklyn/util/core/file/ArchiveBuilder.java
@@ -36,6 +36,7 @@ import java.util.zip.ZipOutputStream;
 import org.apache.brooklyn.util.core.file.ArchiveUtils.ArchiveType;
 import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.apache.brooklyn.util.os.Os;
+import org.apache.brooklyn.util.text.Strings;
 
 import com.google.common.annotations.Beta;
 import com.google.common.collect.Iterables;
@@ -179,22 +180,24 @@ public class ArchiveBuilder {
     }
 
     /**
-     * Add the file located at the {@code fileSubPath}, relative to the {@code baseDir} on the local system,
-     * to the archive.
+     * Add a file located at the {@code fileSubPath}, relative to the {@code baseDir} on the local system,
+     * as {@code fileSubPath} in the archive. For most archives directories are supported.
      * <p>
      * Uses the {@code fileSubPath} as the name of the file in the archive. Note that the
      * file is found by concatenating the two path components using {@link Os#mergePaths(String...)},
      * thus {@code fileSubPath} should not be absolute or point to a location above the current directory.
      * <p>
-     * Use {@link #entry(String, String)} directly or {@link #entries(Map)} for complete
-     * control over file locations and names in the archive.
+     * For a simpler addition mechanism, use {@link #addAt(File, String)}.
+     * <p>
+     * For complete control over file locations and names in the archive.
+     * use {@link #entry(String, String)} directly or {@link #entries(Map)} for complete
      *
      * @see #entry(String, String)
      */
     public ArchiveBuilder addFromLocalBaseDir(File baseDir, String fileSubPath) {
         checkNotNull(baseDir, "baseDir");
         checkNotNull(fileSubPath, "filePath");
-        return entry(Os.mergePaths(".", fileSubPath), Os.mergePaths(baseDir.getPath(), fileSubPath));
+        return entry(fileSubPath, Os.mergePaths(baseDir.getPath(), fileSubPath));
     }
     /** @deprecated since 0.7.0 use {@link #addFromLocalBaseDir(File, String)}, or
      * one of the other add methods if adding relative to baseDir was not intended */ @Deprecated
@@ -207,12 +210,22 @@ public class ArchiveBuilder {
         return addFromLocalBaseDir(baseDir, fileSubPath);
     }
      
-    /** adds the given file to the archive, preserving its name but putting under the given directory in the archive (may be <code>""</code> or <code>"./"</code>) */
+    /** 
+     * Adds the given file or directory to the archive, preserving its name but putting under the given directory in the archive (may be <code>""</code> or <code>"./"</code>).
+     * See also {@link #addDirContentsAt(File, String)} and {@link #addFromLocalBaseDir(File, String)}. */
     public ArchiveBuilder addAt(File file, String archiveParentDir) {
         checkNotNull(archiveParentDir, "archiveParentDir");
         checkNotNull(file, "file");
         return entry(Os.mergePaths(archiveParentDir, file.getName()), file);
     }
+    
+    /** 
+     * Adds the given file or directory to the root of the archive, preserving its name.
+     * To add the contents of a directory without the dir name, use {@link #addDirContentsAtRoot(File)}.
+     * See also {@link #addAt(File, String)}. */
+    public ArchiveBuilder addAtRoot(File file) {
+        return addAt(file, "");
+    }
 
     /**
      * Add the contents of the directory named {@code dirName} to the archive.
@@ -226,9 +239,7 @@ public class ArchiveBuilder {
 
     /**
      * Add the contents of the directory {@code dir} to the archive.
-     * The directory's name is not included; use {@link #addAtRoot(File)} if you want that behaviour. 
-     * <p>
-     * Uses {@literal .} as the parent directory name for the contents.
+     * The directory's name is not included; use {@link #addAt(File, String)} with <code>""</code> as the second argument if you want that behavior. 
      *
      * @see #entry(String, File)
      */
@@ -237,6 +248,11 @@ public class ArchiveBuilder {
         if (!dir.isDirectory()) throw new IllegalArgumentException(dir+" is not a directory; cannot add contents to archive");
         return entry(archiveParentDir, dir);
     }
+    /** See {@link #addDirContentsAt(File, String)} and {@link #addAtRoot(File)}. */
+    public ArchiveBuilder addDirContentsAtRoot(File dir) {
+        return addDirContentsAt(dir, "");
+    }
+
     /**
      * As {@link #addDirContentsAt(File, String)}, 
      * using {@literal .} as the parent directory name for the contents.
@@ -389,17 +405,20 @@ public class ArchiveBuilder {
         
         String name = path.replace("\\", "/");
         if (isDirectory) {
-            name += "/";
-            JarEntry entry = new JarEntry(name);
-            
-            long lastModified=-1;
-            for (File source: sources)
-                if (source.lastModified()>lastModified)
-                    lastModified = source.lastModified();
-            
-            entry.setTime(lastModified);
-            target.putNextEntry(entry);
-            target.closeEntry();
+            name = Strings.removeAllFromEnd(name, "/");
+            if (name.length()>0) {
+                name += "/";
+                JarEntry entry = new JarEntry(name);
+
+                long lastModified=-1;
+                for (File source: sources)
+                    if (source.lastModified()>lastModified)
+                        lastModified = source.lastModified();
+
+                entry.setTime(lastModified);
+                target.putNextEntry(entry);
+                target.closeEntry();
+            }
 
             for (File source: sources) {
                 if (!source.isDirectory()) {
@@ -407,7 +426,7 @@ public class ArchiveBuilder {
                 }
                 Iterable<File> children = Files.fileTreeTraverser().children(source);
                 for (File child : children) {
-                    addToArchive(Os.mergePaths(path, child.getName()), Collections.singleton(child), target);
+                    addToArchive(Os.mergePaths(name, child.getName()), Collections.singleton(child), target);
                 }
             }
             return;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2009a041/core/src/test/java/org/apache/brooklyn/util/core/file/ArchiveBuilderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/util/core/file/ArchiveBuilderTest.java b/core/src/test/java/org/apache/brooklyn/util/core/file/ArchiveBuilderTest.java
index d0ab8e2..26db9a0 100644
--- a/core/src/test/java/org/apache/brooklyn/util/core/file/ArchiveBuilderTest.java
+++ b/core/src/test/java/org/apache/brooklyn/util/core/file/ArchiveBuilderTest.java
@@ -24,6 +24,7 @@ import static org.testng.Assert.assertTrue;
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.List;
@@ -135,31 +136,32 @@ public class ArchiveBuilderTest {
         assertTrue(names.contains("./data04.txt"));
         input.close();
     }
+
     @Test
-    public void testCreateZipFromFiles() throws Exception {
+    public void testCreateZipFromFilesWithNoDir() throws Exception {
         ArchiveBuilder builder = ArchiveBuilder.zip();
         for (String fileName : Arrays.asList("data01.txt", "data02.txt", "data03.txt")) {
-            builder.addAt(new File(tmpDir, fileName), ".");
+            builder.addAt(new File(tmpDir, fileName), "");
         }
-        File archive = builder.create();
-        archive.deleteOnExit();
+        buildAndValidatePrefix(builder, "data");
+    }
 
-        List<ZipEntry> entries = Lists.newArrayList();
-        ZipInputStream input = new ZipInputStream(new FileInputStream(archive));
-        ZipEntry entry = input.getNextEntry();
-        while (entry != null) {
-            entries.add(entry);
-            entry = input.getNextEntry();
+    @Test
+    public void testCreateZipFromFilesInSlash() throws Exception {
+        ArchiveBuilder builder = ArchiveBuilder.zip();
+        for (String fileName : Arrays.asList("data01.txt", "data02.txt", "data03.txt")) {
+            builder.addAt(new File(tmpDir, fileName), "/");
         }
-        assertEquals(entries.size(), 3);
-        Iterable<ZipEntry> directories = Iterables.filter(entries, isDirectory);
-        Iterable<ZipEntry> files = Iterables.filter(entries, Predicates.not(isDirectory));
-        assertTrue(Iterables.isEmpty(directories));
-        assertEquals(Iterables.size(files), 3);
-        for (ZipEntry file : files) {
-            assertTrue(file.getName().startsWith(Os.mergePathsUnix(".", "data")));
+        buildAndValidatePrefix(builder, "/data");
+    }
+
+    @Test
+    public void testCreateZipFromFilesInDot() throws Exception {
+        ArchiveBuilder builder = ArchiveBuilder.zip();
+        for (String fileName : Arrays.asList("data01.txt", "data02.txt", "data03.txt")) {
+            builder.addAt(new File(tmpDir, fileName), ".");
         }
-        input.close();
+        buildAndValidatePrefix(builder, Os.mergePathsUnix(".", "data"));
     }
 
     @Test
@@ -169,6 +171,10 @@ public class ArchiveBuilderTest {
         for (String fileName : Arrays.asList("data01.txt", "data02.txt", "data03.txt")) {
             builder.addFromLocalBaseDir(parentDir, Os.mergePaths(baseDir, fileName));
         }
+        buildAndValidatePrefix(builder, Os.mergePaths(baseDir, "data"));
+    }
+
+    private void buildAndValidatePrefix(ArchiveBuilder builder, String prefix) throws FileNotFoundException, IOException {
         File archive = builder.create();
         archive.deleteOnExit();
 
@@ -185,7 +191,7 @@ public class ArchiveBuilderTest {
         assertTrue(Iterables.isEmpty(directories));
         assertEquals(Iterables.size(files), 3);
         for (ZipEntry file : files) {
-            assertTrue(file.getName().startsWith(Os.mergePathsUnix(".", baseDir)));
+            assertTrue(file.getName().startsWith(prefix), "File is: "+file+"; missing "+prefix);
         }
         input.close();
     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2009a041/utils/common/src/main/java/org/apache/brooklyn/util/os/Os.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/os/Os.java b/utils/common/src/main/java/org/apache/brooklyn/util/os/Os.java
index 13ba63b..a15ae0b 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/util/os/Os.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/util/os/Os.java
@@ -202,7 +202,8 @@ public class Os {
     }
 
     /** merges paths using forward slash as the "local OS file separator", because it is recognised on windows,
-     * making paths more consistent and avoiding problems with backslashes being escaped */
+     * making paths more consistent and avoiding problems with backslashes being escaped.
+     * empty segments are omitted. */
     public static String mergePaths(String ...items) {
         char separatorChar = '/';
         StringBuilder result = new StringBuilder();


[13/15] incubator-brooklyn git commit: This closes #899

Posted by he...@apache.org.
This closes #899


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

Branch: refs/heads/master
Commit: f34d0a3f17e847b92f714fc6bd15b420cde89ebc
Parents: 9a940c3 fb7a70f
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Tue Sep 15 17:43:43 2015 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Tue Sep 15 17:43:43 2015 +0100

----------------------------------------------------------------------
 docs/guide/dev/env/ide/index.md | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------



[10/15] incubator-brooklyn git commit: allow CAMP to instantiate non-CAMP items, and tidy esp generics and errors

Posted by he...@apache.org.
allow CAMP to instantiate non-CAMP items, and tidy esp generics and errors

previously if a CAMP plan referred to a catalog item, it assumed that item
was parsable as CAMP.  now it can delegate to the plan transformers.
this is messier than it should be because it is also looking to see if the
type is a java type, and we did self-referencing checks; would be nice to
make the resolution logic more straightforward, and shouldn't be too hard.

this also tries to make the generics a bit nicer, with more "? extends T" in places,
for catalog items.  it's a bit better in Eclipse but now introduces awful cases
where maven complains and eclipse doesn't.  we should back out a lot of the generics,
perhaps as part of making the catalog much more forgiving about types.

also adds more + cleaner error reporting when resolving plans.


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

Branch: refs/heads/master
Commit: eee436133cc8a227b6c0da53b6ca597d9f7e360b
Parents: 02d86fc
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Fri Sep 11 10:21:09 2015 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Fri Sep 11 10:54:42 2015 +0100

----------------------------------------------------------------------
 .../brooklyn/api/catalog/BrooklynCatalog.java   |  4 +-
 .../catalog/internal/BasicBrooklynCatalog.java  | 35 ++++++++---
 .../core/location/CatalogLocationResolver.java  |  9 ++-
 .../core/mgmt/EntityManagementUtils.java        |  9 ++-
 .../brooklyn/core/plan/PlanToSpecFactory.java   |  6 +-
 .../core/plan/PlanToSpecTransformer.java        |  2 +-
 .../core/plan/XmlPlanToSpecTransformer.java     |  8 +--
 .../BrooklynAssemblyTemplateInstantiator.java   | 27 +++++----
 .../BrooklynComponentTemplateResolver.java      | 42 +++++++++----
 .../BrooklynEntityDecorationResolver.java       | 11 ++--
 .../spi/creation/BrooklynEntityMatcher.java     |  1 +
 .../spi/creation/CampToSpecTransformer.java     | 64 ++++++++++++--------
 .../CatalogOsgiVersionMoreEntityTest.java       |  3 +-
 .../brooklyn/catalog/CatalogYamlEntityTest.java |  3 +-
 .../catalog/CatalogYamlLocationTest.java        |  5 +-
 .../brooklyn/test/lite/CampYamlLiteTest.java    |  3 +-
 .../main/java/org/apache/brooklyn/cli/Main.java |  3 +-
 .../rest/resources/CatalogResource.java         |  6 +-
 .../rest/transform/CatalogTransformer.java      | 14 ++---
 19 files changed, 157 insertions(+), 98 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/eee43613/api/src/main/java/org/apache/brooklyn/api/catalog/BrooklynCatalog.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/brooklyn/api/catalog/BrooklynCatalog.java b/api/src/main/java/org/apache/brooklyn/api/catalog/BrooklynCatalog.java
index 21002d9..0bc0dfe 100644
--- a/api/src/main/java/org/apache/brooklyn/api/catalog/BrooklynCatalog.java
+++ b/api/src/main/java/org/apache/brooklyn/api/catalog/BrooklynCatalog.java
@@ -21,6 +21,8 @@ package org.apache.brooklyn.api.catalog;
 import java.util.Collection;
 import java.util.NoSuchElementException;
 
+import org.apache.brooklyn.api.internal.AbstractBrooklynObjectSpec;
+
 import com.google.common.base.Predicate;
 
 public interface BrooklynCatalog {
@@ -76,7 +78,7 @@ public interface BrooklynCatalog {
 
     /** creates a spec for the given catalog item, throwing exceptions if any problems */
     // TODO this should be cached on the item and renamed getSpec(...), else we re-create it too often (every time catalog is listed)
-    <T,SpecT> SpecT createSpec(CatalogItem<T,SpecT> item);
+    <T, SpecT extends AbstractBrooklynObjectSpec<? extends T, SpecT>> SpecT createSpec(CatalogItem<T, SpecT> item);
     
     /** throws exceptions if any problems 
      * @deprecated since 0.7.0 use {@link #createSpec(CatalogItem)} */

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/eee43613/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
index b2ec24d..cc4cffe 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
@@ -26,7 +26,6 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import java.util.NoSuchElementException;
-import java.util.Set;
 
 import javax.annotation.Nullable;
 
@@ -34,6 +33,7 @@ import org.apache.brooklyn.api.catalog.BrooklynCatalog;
 import org.apache.brooklyn.api.catalog.CatalogItem;
 import org.apache.brooklyn.api.catalog.CatalogItem.CatalogBundle;
 import org.apache.brooklyn.api.catalog.CatalogItem.CatalogItemType;
+import org.apache.brooklyn.api.internal.AbstractBrooklynObjectSpec;
 import org.apache.brooklyn.api.location.Location;
 import org.apache.brooklyn.api.location.LocationSpec;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
@@ -312,7 +312,7 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
     }
 
     @Override
-    public <T, SpecT> SpecT createSpec(CatalogItem<T, SpecT> item) {
+    public <T, SpecT extends AbstractBrooklynObjectSpec<? extends T, SpecT>> SpecT createSpec(CatalogItem<T, SpecT> item) {
         if (item == null) return null;
         @SuppressWarnings("unchecked")
         CatalogItemDo<T,SpecT> loadedItem = (CatalogItemDo<T, SpecT>) getCatalogItemDo(item.getSymbolicName(), item.getVersion());
@@ -321,7 +321,7 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
         if (specType==null) return null;
 
         if (loadedItem.getPlanYaml() != null) {
-            SpecT yamlSpec = (SpecT) EntityManagementUtils.createCatalogSpec(mgmt, loadedItem);
+            SpecT yamlSpec = EntityManagementUtils.createCatalogSpec(mgmt, loadedItem);
             if (yamlSpec != null) {
                 return yamlSpec;
             }
@@ -348,7 +348,7 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
         }
 
         if (spec==null) 
-            throw new IllegalStateException("Unknown how to create instance of "+this);
+            throw new IllegalStateException("No known mechanism to create instance of "+item);
 
         return spec;
     }
@@ -516,9 +516,11 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
 
         PlanInterpreterGuessingType planInterpreter = new PlanInterpreterGuessingType(null, item, sourceYaml, itemType, libraryBundles, result).reconstruct();
         if (!planInterpreter.isResolved()) {
-            throw Exceptions.create("Could not resolve item "
-                + (Strings.isNonBlank(id) ? id : Strings.isNonBlank(symbolicName) ? symbolicName : Strings.isNonBlank(name) ? name : "<no-name>")
-                + ":\n"+sourceYaml, planInterpreter.getErrors());
+            throw Exceptions.create("Could not resolve item"
+                + (Strings.isNonBlank(id) ? " "+id : Strings.isNonBlank(symbolicName) ? " "+symbolicName : Strings.isNonBlank(name) ? name : "")
+                // better not to show yaml, takes up lots of space, and with multiple plan transformers there might be multiple errors 
+//                + ":\n"+sourceYaml
+                , planInterpreter.getErrors());
         }
         itemType = planInterpreter.getCatalogItemType();
         Map<?, ?> itemAsMap = planInterpreter.getItem();
@@ -543,6 +545,8 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
             } else {
                 symbolicName = setFromItemIfUnset(symbolicName, itemAsMap, "id");
                 symbolicName = setFromItemIfUnset(symbolicName, itemAsMap, "name");
+                // TODO we should let the plan transformer give us this
+                symbolicName = setFromItemIfUnset(symbolicName, itemAsMap, "template_name");
                 if (Strings.isBlank(symbolicName)) {
                     log.error("Can't infer catalog item symbolicName from the following plan:\n" + sourceYaml);
                     throw new IllegalStateException("Can't infer catalog item symbolicName from catalog item metadata");
@@ -563,6 +567,7 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
                 version = CatalogUtils.getVersionFromVersionedId(name);
             } else if (Strings.isBlank(version)) {
                 version = setFromItemIfUnset(version, itemAsMap, "version");
+                version = setFromItemIfUnset(version, itemAsMap, "template_version");
                 if (version==null) {
                     log.warn("No version specified for catalog item " + symbolicName + ". Using default value.");
                     version = null;
@@ -685,6 +690,7 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
         String planYaml;
         boolean resolved = false;
         List<Exception> errors = MutableList.of();
+        List<Exception> entityErrors = MutableList.of();
         
         public PlanInterpreterGuessingType(@Nullable String id, Object item, String itemYaml, @Nullable CatalogItemType optionalCiType, 
                 Collection<CatalogBundle> libraryBundles, List<CatalogItemDtoAbstract<?,?>> itemsDefinedSoFar) {
@@ -731,6 +737,7 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
         /** Returns potentially useful errors encountered while guessing types. 
          * May only be available where the type is known. */
         public List<Exception> getErrors() {
+            if (errors.isEmpty()) return entityErrors;
             return errors;
         }
         
@@ -778,10 +785,12 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
             
             // then try parsing plan - this will use loader
             try {
-                CatalogItem<?, ?> itemToAttempt = createItemBuilder(candidateCiType, getIdWithRandomDefault(), DEFAULT_VERSION)
+                @SuppressWarnings("rawtypes")
+                CatalogItem itemToAttempt = createItemBuilder(candidateCiType, getIdWithRandomDefault(), DEFAULT_VERSION)
                     .plan(candidateYaml)
                     .libraries(libraryBundles)
                     .build();
+                @SuppressWarnings("unchecked")
                 Object spec = EntityManagementUtils.createCatalogSpec(mgmt, itemToAttempt);
                 if (spec!=null) {
                     catalogItemType = candidateCiType;
@@ -800,7 +809,11 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
                     // (when we're not given a key, the previous block should apply)
                     errors.add(e);
                 } else {
-                    // all other cases, the error is probably due to us not getting the type right, ignore it
+                    // all other cases, the error is probably due to us not getting the type right, probably ignore it
+                    // but cache it if we've checked entity, we'll use that as fallback errors
+                    if (candidateCiType==CatalogItemType.ENTITY) {
+                        entityErrors.add(e);
+                    }
                     if (log.isTraceEnabled())
                         log.trace("Guessing type of plan, it looks like it isn't "+candidateCiType+"/"+key+": "+e);
                 }
@@ -810,10 +823,12 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
             if (type!=null && key!=null) {
                 try {
                     String cutDownYaml = key + ":\n" + makeAsIndentedList("type: "+type);
-                    CatalogItem<?, ?> itemToAttempt = createItemBuilder(candidateCiType, getIdWithRandomDefault(), DEFAULT_VERSION)
+                    @SuppressWarnings("rawtypes")
+                    CatalogItem itemToAttempt = createItemBuilder(candidateCiType, getIdWithRandomDefault(), DEFAULT_VERSION)
                             .plan(cutDownYaml)
                             .libraries(libraryBundles)
                             .build();
+                    @SuppressWarnings("unchecked")
                     Object cutdownSpec = EntityManagementUtils.createCatalogSpec(mgmt, itemToAttempt);
                     if (cutdownSpec!=null) {
                         catalogItemType = candidateCiType;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/eee43613/core/src/main/java/org/apache/brooklyn/core/location/CatalogLocationResolver.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/location/CatalogLocationResolver.java b/core/src/main/java/org/apache/brooklyn/core/location/CatalogLocationResolver.java
index 2cc7b9f..db4c0d5 100644
--- a/core/src/main/java/org/apache/brooklyn/core/location/CatalogLocationResolver.java
+++ b/core/src/main/java/org/apache/brooklyn/core/location/CatalogLocationResolver.java
@@ -22,8 +22,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
 
 import java.util.Map;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.apache.brooklyn.api.catalog.CatalogItem;
 import org.apache.brooklyn.api.location.Location;
 import org.apache.brooklyn.api.location.LocationRegistry;
@@ -31,6 +29,8 @@ import org.apache.brooklyn.api.location.LocationResolver;
 import org.apache.brooklyn.api.location.LocationSpec;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Given a location spec in the form {@code brooklyn.catalog:<symbolicName>:<version>}, 
@@ -38,7 +38,6 @@ import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
  */
 public class CatalogLocationResolver implements LocationResolver {
 
-    @SuppressWarnings("unused")
     private static final Logger log = LoggerFactory.getLogger(CatalogLocationResolver.class);
 
     public static final String NAME = "brooklyn.catalog";
@@ -61,8 +60,8 @@ public class CatalogLocationResolver implements LocationResolver {
             log.warn("Use of deprecated catalog item "+item.getSymbolicName()+":"+item.getVersion());
         }
         
-        LocationSpec<?> origLocSpec = managementContext.getCatalog().createSpec((CatalogItem<Location, LocationSpec<?>>)item);
-        LocationSpec<?> locSpec = LocationSpec.create(origLocSpec)
+        LocationSpec origLocSpec = (LocationSpec) managementContext.getCatalog().createSpec((CatalogItem)item);
+        LocationSpec locSpec = LocationSpec.create(origLocSpec)
                 .configure(locationFlags);
         return managementContext.getLocationManager().createLocation(locSpec);
     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/eee43613/core/src/main/java/org/apache/brooklyn/core/mgmt/EntityManagementUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/EntityManagementUtils.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/EntityManagementUtils.java
index b86a0a8..3a46416 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/EntityManagementUtils.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/EntityManagementUtils.java
@@ -96,12 +96,11 @@ public class EntityManagementUtils {
         }).get();
     }
 
-    @SuppressWarnings({ "unchecked", "rawtypes" })
-    public static AbstractBrooklynObjectSpec<?, ?> createCatalogSpec(ManagementContext mgmt, final CatalogItem<?, ?> item) {
-        return PlanToSpecFactory.attemptWithLoaders(mgmt, new Function<PlanToSpecTransformer, AbstractBrooklynObjectSpec<?, ?>>() {
+    public static <T,SpecT extends AbstractBrooklynObjectSpec<? extends T, SpecT>> SpecT createCatalogSpec(ManagementContext mgmt, final CatalogItem<T, SpecT> item) {
+        return PlanToSpecFactory.attemptWithLoaders(mgmt, new Function<PlanToSpecTransformer, SpecT>() {
             @Override
-            public AbstractBrooklynObjectSpec<?, ?> apply(PlanToSpecTransformer input) {
-                return input.createCatalogSpec((CatalogItem)item);
+            public SpecT apply(PlanToSpecTransformer input) {
+                return input.createCatalogSpec(item);
             }
         }).get();
     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/eee43613/core/src/main/java/org/apache/brooklyn/core/plan/PlanToSpecFactory.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/plan/PlanToSpecFactory.java b/core/src/main/java/org/apache/brooklyn/core/plan/PlanToSpecFactory.java
index 491a74e..3328545 100644
--- a/core/src/main/java/org/apache/brooklyn/core/plan/PlanToSpecFactory.java
+++ b/core/src/main/java/org/apache/brooklyn/core/plan/PlanToSpecFactory.java
@@ -25,6 +25,7 @@ import java.util.ServiceLoader;
 
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.apache.brooklyn.util.exceptions.PropagatedRuntimeException;
 import org.apache.brooklyn.util.guava.Maybe;
 import org.apache.brooklyn.util.text.Strings;
 import org.slf4j.Logger;
@@ -106,7 +107,7 @@ public class PlanToSpecFactory {
                     (Strings.isNonBlank(e.getMessage()) ? " ("+e.getMessage()+")" : ""));
             } catch (Throwable e) {
                 Exceptions.propagateIfFatal(e);
-                otherProblemsFromTransformers.add(new IllegalArgumentException("Transformer for "+t.getShortDescription()+" gave an error creating this plan: "+
+                otherProblemsFromTransformers.add(new PropagatedRuntimeException("Transformer for "+t.getShortDescription()+" gave an error creating this plan: "+
                     Exceptions.collapseText(e), e));
             }
         }
@@ -115,7 +116,8 @@ public class PlanToSpecFactory {
         if (!otherProblemsFromTransformers.isEmpty()) {
             // at least one thought he could do it
             log.debug("Plan could not be transformed; failure will be propagated (other transformers tried = "+transformersWhoDontSupport+"): "+otherProblemsFromTransformers);
-            result = Exceptions.create(null, otherProblemsFromTransformers);
+            result = otherProblemsFromTransformers.size()==1 ? Exceptions.create(null, otherProblemsFromTransformers) :
+                Exceptions.create("Plan transformers all failed", otherProblemsFromTransformers);
         } else {
             result = new PlanNotRecognizedException("Invalid plan; format could not be recognized, trying with: "+transformersWhoDontSupport);
         }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/eee43613/core/src/main/java/org/apache/brooklyn/core/plan/PlanToSpecTransformer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/plan/PlanToSpecTransformer.java b/core/src/main/java/org/apache/brooklyn/core/plan/PlanToSpecTransformer.java
index 63d5c1f..c6e3a4a 100644
--- a/core/src/main/java/org/apache/brooklyn/core/plan/PlanToSpecTransformer.java
+++ b/core/src/main/java/org/apache/brooklyn/core/plan/PlanToSpecTransformer.java
@@ -56,6 +56,6 @@ public interface PlanToSpecTransformer extends ManagementContextInjectable {
      * implementations will typically look at the {@link CatalogItem#getCatalogItemType()} first.
      * <p>
      * should throw {@link PlanNotRecognizedException} if this transformer does not know what to do with the plan. */
-    <T,SpecT extends AbstractBrooklynObjectSpec<T, SpecT>> AbstractBrooklynObjectSpec<T, SpecT> createCatalogSpec(CatalogItem<T, SpecT> item) throws PlanNotRecognizedException;
+    <T,SpecT extends AbstractBrooklynObjectSpec<? extends T, SpecT>> SpecT createCatalogSpec(CatalogItem<T, SpecT> item) throws PlanNotRecognizedException;
     
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/eee43613/core/src/test/java/org/apache/brooklyn/core/plan/XmlPlanToSpecTransformer.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/plan/XmlPlanToSpecTransformer.java b/core/src/test/java/org/apache/brooklyn/core/plan/XmlPlanToSpecTransformer.java
index 5fc103d..a535932 100644
--- a/core/src/test/java/org/apache/brooklyn/core/plan/XmlPlanToSpecTransformer.java
+++ b/core/src/test/java/org/apache/brooklyn/core/plan/XmlPlanToSpecTransformer.java
@@ -72,15 +72,15 @@ public class XmlPlanToSpecTransformer implements PlanToSpecTransformer {
         }
     }
 
-    @SuppressWarnings({ "rawtypes", "unchecked" })
+    @SuppressWarnings({ "unchecked" })
     @Override
-    public <T, SpecT extends AbstractBrooklynObjectSpec<T, SpecT>> AbstractBrooklynObjectSpec<T, SpecT> createCatalogSpec(CatalogItem<T, SpecT> item) {
+    public <T, SpecT extends AbstractBrooklynObjectSpec<? extends T, SpecT>> SpecT createCatalogSpec(CatalogItem<T, SpecT> item) {
         if (item.getPlanYaml()==null) throw new PlanNotRecognizedException("Plan is null");
         if (item.getCatalogItemType()==CatalogItemType.ENTITY) {
-            return (EntitySpec)toEntitySpec(parseXml(item.getPlanYaml()), 1);
+            return (SpecT)toEntitySpec(parseXml(item.getPlanYaml()), 1);
         }
         if (item.getCatalogItemType()==CatalogItemType.TEMPLATE) {
-            return (EntitySpec)toEntitySpec(parseXml(item.getPlanYaml()), 0);
+            return (SpecT)toEntitySpec(parseXml(item.getPlanYaml()), 0);
         }
         throw new PlanNotRecognizedException("Type "+item.getCatalogItemType()+" not supported");
     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/eee43613/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynAssemblyTemplateInstantiator.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynAssemblyTemplateInstantiator.java b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynAssemblyTemplateInstantiator.java
index d582c45..63f111a 100644
--- a/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynAssemblyTemplateInstantiator.java
+++ b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynAssemblyTemplateInstantiator.java
@@ -94,11 +94,11 @@ public class BrooklynAssemblyTemplateInstantiator implements AssemblyTemplateSpe
 
         BrooklynComponentTemplateResolver resolver = BrooklynComponentTemplateResolver.Factory.newInstance(
             loader, buildWrapperAppTemplate(template));
-        EntitySpec<? extends Application> app = resolver.resolveSpec(null);
+        EntitySpec<? extends Application> app = resolver.resolveSpec(null, false);
         app.configure(EntityManagementUtils.WRAPPER_APP_MARKER, Boolean.TRUE);
 
         // first build the children into an empty shell app
-        List<EntitySpec<?>> childSpecs = buildTemplateServicesAsSpecs(loader, template, platform);
+        List<EntitySpec<?>> childSpecs = buildTemplateServicesAsSpecs(loader, template, platform, true);
         for (EntitySpec<?> childSpec : childSpecs) {
             app.child(childSpec);
         }
@@ -130,28 +130,30 @@ public class BrooklynAssemblyTemplateInstantiator implements AssemblyTemplateSpe
         return EntityManagementUtils.canPromoteWrappedApplication(app);
     }
 
-    private List<EntitySpec<?>> buildTemplateServicesAsSpecs(BrooklynClassLoadingContext loader, AssemblyTemplate template, CampPlatform platform) {
-        return buildTemplateServicesAsSpecsImpl(loader, template, platform, Sets.<String>newLinkedHashSet());
+    private List<EntitySpec<?>> buildTemplateServicesAsSpecs(BrooklynClassLoadingContext loader, AssemblyTemplate template, CampPlatform platform, boolean canUseOtherTransformers) {
+        return buildTemplateServicesAsSpecsImpl(loader, template, platform, Sets.<String>newLinkedHashSet(), canUseOtherTransformers);
     }
 
-    private List<EntitySpec<?>> buildTemplateServicesAsSpecsImpl(BrooklynClassLoadingContext loader, AssemblyTemplate template, CampPlatform platform, Set<String> encounteredCatalogTypes) {
+    private List<EntitySpec<?>> buildTemplateServicesAsSpecsImpl(BrooklynClassLoadingContext loader, AssemblyTemplate template, CampPlatform platform, Set<String> encounteredCatalogTypes, boolean canUseOtherTransformers) {
         List<EntitySpec<?>> result = Lists.newArrayList();
 
         for (ResolvableLink<PlatformComponentTemplate> ctl: template.getPlatformComponentTemplates().links()) {
             PlatformComponentTemplate appChildComponentTemplate = ctl.resolve();
             BrooklynComponentTemplateResolver entityResolver = BrooklynComponentTemplateResolver.Factory.newInstance(loader, appChildComponentTemplate);
-            EntitySpec<?> spec = resolveSpec(platform, ResourceUtils.create(this), entityResolver, encounteredCatalogTypes);
-
+            EntitySpec<?> spec;
+            spec = resolveCampSpec(platform, ResourceUtils.create(this), entityResolver, encounteredCatalogTypes, canUseOtherTransformers);
             result.add(spec);
         }
         return result;
     }
 
-    static EntitySpec<?> resolveSpec(
+    static EntitySpec<?> resolveCampSpec(
             CampPlatform platform,
             ResourceUtils ru,
             BrooklynComponentTemplateResolver entityResolver,
-            Set<String> encounteredCatalogTypes) {
+            Set<String> encounteredCatalogTypes,
+            boolean canUseOtherTransformers) {
+        
         String brooklynType = entityResolver.getServiceTypeResolver().getBrooklynType(entityResolver.getDeclaredType());
         CatalogItem<Entity, EntitySpec<?>> item = entityResolver.getServiceTypeResolver().getCatalogItem(entityResolver, entityResolver.getDeclaredType());
 
@@ -177,7 +179,7 @@ public class BrooklynAssemblyTemplateInstantiator implements AssemblyTemplateSpe
 
         if (spec == null) {
             // load from java or yaml
-            spec = entityResolver.resolveSpec(encounteredCatalogTypes);
+            spec = entityResolver.resolveSpec(encounteredCatalogTypes, canUseOtherTransformers);
         }
 
         return spec;
@@ -206,11 +208,12 @@ public class BrooklynAssemblyTemplateInstantiator implements AssemblyTemplateSpe
         }
     }
 
-    static EntitySpec<?> resolveCatalogYamlReferenceSpec(
+    static EntitySpec<?> resolveCatalogYamlReferenceCampSpec(
             CampPlatform platform,
             CatalogItem<Entity, EntitySpec<?>> item,
             Set<String> encounteredCatalogTypes) {
         ManagementContext mgmt = getManagementContext(platform);
+
         String yaml = item.getPlanYaml();
         Reader input = new StringReader(yaml);
         BrooklynClassLoadingContext itemLoader = CatalogUtils.newClassLoadingContext(mgmt, item);
@@ -251,7 +254,7 @@ public class BrooklynAssemblyTemplateInstantiator implements AssemblyTemplateSpe
         try {
             AssemblyTemplateInstantiator ati = template.getInstantiator().newInstance();
             if (ati instanceof BrooklynAssemblyTemplateInstantiator) {
-                List<EntitySpec<?>> specs = ((BrooklynAssemblyTemplateInstantiator)ati).buildTemplateServicesAsSpecsImpl(itemLoader, template, platform, encounteredCatalogTypes);
+                List<EntitySpec<?>> specs = ((BrooklynAssemblyTemplateInstantiator)ati).buildTemplateServicesAsSpecsImpl(itemLoader, template, platform, encounteredCatalogTypes, false);
                 if (specs.size() > 1) {
                     throw new UnsupportedOperationException("Only supporting single service in catalog item currently: got "+specs);
                 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/eee43613/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
index 52e6fb1..aef991f 100644
--- a/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
+++ b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
@@ -49,6 +49,7 @@ import org.apache.brooklyn.core.config.ConfigKeys;
 import org.apache.brooklyn.core.entity.AbstractEntity;
 import org.apache.brooklyn.core.mgmt.BrooklynTags;
 import org.apache.brooklyn.core.mgmt.BrooklynTaskTags;
+import org.apache.brooklyn.core.mgmt.EntityManagementUtils;
 import org.apache.brooklyn.core.mgmt.ManagementContextInjectable;
 import org.apache.brooklyn.core.mgmt.classloading.BrooklynClassLoadingContext;
 import org.apache.brooklyn.core.mgmt.classloading.JavaBrooklynClassLoadingContext;
@@ -61,6 +62,7 @@ import org.apache.brooklyn.util.core.config.ConfigBag;
 import org.apache.brooklyn.util.core.flags.FlagUtils;
 import org.apache.brooklyn.util.core.flags.FlagUtils.FlagConfigKeyAndValueRecord;
 import org.apache.brooklyn.util.core.task.Tasks;
+import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.apache.brooklyn.util.guava.Maybe;
 import org.apache.brooklyn.util.javalang.Reflections;
 import org.apache.brooklyn.util.text.Strings;
@@ -217,19 +219,32 @@ public class BrooklynComponentTemplateResolver {
     }
 
     /** resolves the spec, updating the loader if a catalog item is loaded */
-    protected <T extends Entity> EntitySpec<T> resolveSpec(Set<String> encounteredCatalogTypes) {
+    @SuppressWarnings("unchecked")
+    protected <T extends Entity> EntitySpec<T> resolveSpec(Set<String> encounteredCatalogTypes, boolean canUseOtherTransformers) {
         if (alreadyBuilt.getAndSet(true))
             throw new IllegalStateException("Spec can only be used once: "+this);
 
-        EntitySpec<T> spec = createSpec(encounteredCatalogTypes);
-        populateSpec(spec);
-
-        return spec;
+        CatalogItem<Entity, EntitySpec<?>> item = getServiceTypeResolver().getCatalogItem(this, getDeclaredType());
+        try {
+            EntitySpec<T> spec = createSpec(item, encounteredCatalogTypes);
+            populateSpec(spec);
+            return spec;
+        } catch (Exception e) {
+            Exceptions.propagateIfFatal(e);
+            
+            // maybe it requires a different transformer? TODO better would be to know this from a transformer type on the catalog item type
+            if (item!=null && canUseOtherTransformers) {
+                log.debug("Could not resolve child "+item+" as CAMP; trying other transformers: "+e);
+                // should only be called when resolving children. and encountered types should probably be empty. 
+                return (EntitySpec<T>) EntityManagementUtils.createCatalogSpec(mgmt, (CatalogItem) item);
+            } else {
+                throw Exceptions.propagate(e);
+            }
+        }
     }
 
     @SuppressWarnings({ "unchecked" })
-    protected <T extends Entity> EntitySpec<T> createSpec(Set<String> encounteredCatalogTypes) {
-        CatalogItem<Entity, EntitySpec<?>> item = getServiceTypeResolver().getCatalogItem(this, getDeclaredType());
+    protected <T extends Entity> EntitySpec<T> createSpec(CatalogItem<Entity, EntitySpec<?>> item, Set<String> encounteredCatalogTypes) {
         if (item == null) {
             // ignore; presumably a java type or some such?
         } else if (item.isDisabled()) {
@@ -262,11 +277,12 @@ public class BrooklynComponentTemplateResolver {
             }
             return createSpecFromJavaType();
 
-        // Only case that's left is a catalog item with YAML content - try to parse it recursively
-        // including it's OSGi bundles in the loader classpath.
+        // Only case that's left is a catalog item with CAMP YAML content - try to parse it recursively
+        // including its OSGi bundles in the loader classpath.
         } else {
-            // TODO perhaps migrate to catalog.createSpec ?
-            EntitySpec<?> spec = BrooklynAssemblyTemplateInstantiator.resolveCatalogYamlReferenceSpec(getCampPlatform(), item, encounteredCatalogTypes);
+            // TODO if it isn't camp it will throw. better would be to know the transformers type for the item!
+
+            EntitySpec<?> spec = BrooklynAssemblyTemplateInstantiator.resolveCatalogYamlReferenceCampSpec(getCampPlatform(), item, encounteredCatalogTypes);
             spec.catalogItemId(item.getId());
             
             return (EntitySpec<T>)spec;
@@ -319,7 +335,7 @@ public class BrooklynComponentTemplateResolver {
             Iterable<Map<String,?>> children = (Iterable<Map<String,?>>)childrenObj;
             for (Map<String,?> childAttrs : children) {
                 BrooklynComponentTemplateResolver entityResolver = BrooklynComponentTemplateResolver.Factory.newInstance(loader, childAttrs);
-                EntitySpec<? extends Entity> childSpec = BrooklynAssemblyTemplateInstantiator.resolveSpec(getCampPlatform(), ResourceUtils.create(this), entityResolver, encounteredCatalogTypes);
+                EntitySpec<? extends Entity> childSpec = BrooklynAssemblyTemplateInstantiator.resolveCampSpec(getCampPlatform(), ResourceUtils.create(this), entityResolver, encounteredCatalogTypes, true);
                 spec.child(childSpec);
             }
         }
@@ -485,7 +501,7 @@ public class BrooklynComponentTemplateResolver {
                 @SuppressWarnings("unchecked")
                 Map<String, Object> resolvedConfig = (Map<String, Object>)transformSpecialFlags(specConfig.getSpecConfiguration());
                 specConfig.setSpecConfiguration(resolvedConfig);
-                return Factory.newInstance(getLoader(), specConfig.getSpecConfiguration()).resolveSpec(null);
+                return Factory.newInstance(getLoader(), specConfig.getSpecConfiguration()).resolveSpec(null, false);
             }
             if (flag instanceof ManagementContextInjectable) {
                 log.debug("Injecting Brooklyn management context info object: {}", flag);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/eee43613/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynEntityDecorationResolver.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynEntityDecorationResolver.java b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynEntityDecorationResolver.java
index eee5834..a7a7530 100644
--- a/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynEntityDecorationResolver.java
+++ b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynEntityDecorationResolver.java
@@ -109,10 +109,10 @@ public abstract class BrooklynEntityDecorationResolver<DT> {
             String policyType = decoLoader.getTypeName().get();
             ManagementContext mgmt = instantiator.loader.getManagementContext();
             BrooklynCatalog catalog = mgmt.getCatalog();
-            CatalogItem<?, ?> item = getPolicyCatalogItem(catalog, policyType);
+            CatalogItem<Policy, PolicySpec<?>> item = getPolicyCatalogItem(catalog, policyType);
             PolicySpec<? extends Policy> spec;
             if (item != null) {
-                spec = (PolicySpec<? extends Policy>) catalog.createSpec(item);
+                spec = (PolicySpec) catalog.createSpec((CatalogItem) item);
                 spec.configure(decoLoader.getConfigMap());
             } else {
                 // this pattern of creating a spec could be simplified with a "Configurable" superinterface on *Spec  
@@ -121,13 +121,14 @@ public abstract class BrooklynEntityDecorationResolver<DT> {
             }
             decorations.add(spec);
         }
-        private CatalogItem<?, ?> getPolicyCatalogItem(BrooklynCatalog catalog, String policyType) {
+        @SuppressWarnings({ "unchecked", "rawtypes" })
+        private CatalogItem<Policy, PolicySpec<?>> getPolicyCatalogItem(BrooklynCatalog catalog, String policyType) {
             if (CatalogUtils.looksLikeVersionedId(policyType)) {
                 String id = CatalogUtils.getIdFromVersionedId(policyType);
                 String version = CatalogUtils.getVersionFromVersionedId(policyType);
-                return catalog.getCatalogItem(id, version);
+                return (CatalogItem) catalog.getCatalogItem(id, version);
             } else {
-                return catalog.getCatalogItem(policyType, BrooklynCatalog.DEFAULT_VERSION);
+                return (CatalogItem) catalog.getCatalogItem(policyType, BrooklynCatalog.DEFAULT_VERSION);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/eee43613/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynEntityMatcher.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynEntityMatcher.java b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynEntityMatcher.java
index 8a632e6..c0a2e19 100644
--- a/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynEntityMatcher.java
+++ b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynEntityMatcher.java
@@ -64,6 +64,7 @@ public class BrooklynEntityMatcher implements PdpMatcher {
             Service service = (Service)deploymentPlanItem;
 
             String serviceType = service.getServiceType();
+            if (serviceType==null) throw new NullPointerException("Service must declare a type ("+service+")");
             BrooklynClassLoadingContext loader = BasicBrooklynCatalog.BrooklynLoaderTracker.getLoader();
             if (loader == null) loader = JavaBrooklynClassLoadingContext.create(mgmt);
             if (BrooklynComponentTemplateResolver.Factory.supportsType(loader, serviceType))

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/eee43613/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampToSpecTransformer.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampToSpecTransformer.java b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampToSpecTransformer.java
index 7ab200d..9b9f1ec 100644
--- a/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampToSpecTransformer.java
+++ b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampToSpecTransformer.java
@@ -31,13 +31,18 @@ import org.apache.brooklyn.camp.spi.AssemblyTemplate;
 import org.apache.brooklyn.camp.spi.instantiate.AssemblyTemplateInstantiator;
 import org.apache.brooklyn.core.mgmt.classloading.BrooklynClassLoadingContext;
 import org.apache.brooklyn.core.mgmt.classloading.JavaBrooklynClassLoadingContext;
+import org.apache.brooklyn.core.plan.PlanNotRecognizedException;
 import org.apache.brooklyn.core.plan.PlanToSpecTransformer;
 import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class CampToSpecTransformer implements PlanToSpecTransformer {
 
     public static final String YAML_CAMP_PLAN_TYPE = "org.apache.brooklyn.camp/yaml";
 
+    private static final Logger log = LoggerFactory.getLogger(CampToSpecTransformer.class);
+    
     private ManagementContext mgmt;
 
     @Override
@@ -52,34 +57,45 @@ public class CampToSpecTransformer implements PlanToSpecTransformer {
 
     @Override
     public EntitySpec<? extends Application> createApplicationSpec(String plan) {
-      CampPlatform camp = CampCatalogUtils.getCampPlatform(mgmt);
-      AssemblyTemplate at = camp.pdp().registerDeploymentPlan( new StringReader(plan) );
-      AssemblyTemplateInstantiator instantiator;
-      try {
-          instantiator = at.getInstantiator().newInstance();
-      } catch (Exception e) {
-          throw Exceptions.propagate(e);
-      }
-      if (instantiator instanceof AssemblyTemplateSpecInstantiator) {
-          BrooklynClassLoadingContext loader = JavaBrooklynClassLoadingContext.create(mgmt);
-          return ((AssemblyTemplateSpecInstantiator) instantiator).createSpec(at, camp, loader, true);
-      } else {
-          // The unknown instantiator can create the app (Assembly), but not a spec.
-          // Currently, all brooklyn plans should produce the above.
-          if (at.getPlatformComponentTemplates()==null || at.getPlatformComponentTemplates().isEmpty()) {
-              if (at.getCustomAttributes().containsKey("brooklyn.catalog"))
-                  throw new IllegalArgumentException("Unrecognized application blueprint format: expected an application, not a brooklyn.catalog");
-              throw new IllegalArgumentException("Unrecognized application blueprint format: no services defined");
-          }
-          // map this (expected) error to a nicer message
-          throw new IllegalArgumentException("Unrecognized application blueprint format");
-      }
+        try {
+            CampPlatform camp = CampCatalogUtils.getCampPlatform(mgmt);
+            AssemblyTemplate at = camp.pdp().registerDeploymentPlan( new StringReader(plan) );
+            AssemblyTemplateInstantiator instantiator;
+            try {
+                instantiator = at.getInstantiator().newInstance();
+            } catch (Exception e) {
+                throw Exceptions.propagate(e);
+            }
+            if (instantiator instanceof AssemblyTemplateSpecInstantiator) {
+                BrooklynClassLoadingContext loader = JavaBrooklynClassLoadingContext.create(mgmt);
+                return ((AssemblyTemplateSpecInstantiator) instantiator).createSpec(at, camp, loader, true);
+            } else {
+                // The unknown instantiator can create the app (Assembly), but not a spec.
+                // Currently, all brooklyn plans should produce the above.
+                if (at.getPlatformComponentTemplates()==null || at.getPlatformComponentTemplates().isEmpty()) {
+                    if (at.getCustomAttributes().containsKey("brooklyn.catalog"))
+                        throw new IllegalArgumentException("Unrecognized application blueprint format: expected an application, not a brooklyn.catalog");
+                    throw new IllegalArgumentException("Unrecognized application blueprint format: no services defined");
+                }
+                // map this (expected) error to a nicer message
+                throw new IllegalArgumentException("Unrecognized application blueprint format");
+            }
+        } catch (Exception e) {
+            if (e instanceof PlanNotRecognizedException) {
+                if (log.isTraceEnabled())
+                    log.debug("Failed to create entity from CAMP spec:\n" + plan, e);
+            } else {
+                if (log.isDebugEnabled())
+                    log.debug("Failed to create entity from CAMP spec:\n" + plan, e);
+            }
+            throw Exceptions.propagate(e);
+        }
     }
 
     @SuppressWarnings({ "unchecked", "rawtypes" })
     @Override
-    public <T, SpecT extends AbstractBrooklynObjectSpec<T, SpecT>> AbstractBrooklynObjectSpec<T, SpecT> createCatalogSpec(CatalogItem<T, SpecT> item) {
-        return (AbstractBrooklynObjectSpec<T, SpecT>) CampCatalogUtils.createSpec(mgmt, (CatalogItem)item);
+    public <T, SpecT extends AbstractBrooklynObjectSpec<? extends T, SpecT>> SpecT createCatalogSpec(CatalogItem<T, SpecT> item) {
+        return (SpecT) CampCatalogUtils.createSpec(mgmt, (CatalogItem)item);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/eee43613/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityTest.java b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityTest.java
index f93f45b..de40d41 100644
--- a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityTest.java
+++ b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityTest.java
@@ -238,7 +238,8 @@ public class CatalogOsgiVersionMoreEntityTest extends AbstractYamlTest {
         BrooklynCatalog catalog = mgmt().getCatalog();
         Iterable<CatalogItem<Object, Object>> items = catalog.getCatalogItems();
         for (CatalogItem<Object, Object> item: items) {
-            Object spec = catalog.createSpec(item);
+            @SuppressWarnings({ "unchecked", "rawtypes" })
+            Object spec = catalog.createSpec((CatalogItem)item);
             switch (item.getCatalogItemType()) {
                 case TEMPLATE:
                 case ENTITY:

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/eee43613/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityTest.java b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityTest.java
index 0063916..7389190 100644
--- a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityTest.java
+++ b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityTest.java
@@ -525,7 +525,8 @@ public class CatalogYamlEntityTest extends AbstractYamlTest {
         addCatalogOSGiEntity(id);
         BrooklynCatalog catalog = mgmt().getCatalog();
         CatalogItem<?, ?> item = catalog.getCatalogItem(id, TEST_VERSION);
-        Object spec = catalog.createSpec(item);
+        @SuppressWarnings({ "unchecked", "rawtypes" })
+        Object spec = catalog.createSpec((CatalogItem) item);
         Assert.assertNotNull(spec);
     }
     

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/eee43613/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java
index 868a8e6..e5a8457 100644
--- a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java
+++ b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java
@@ -105,8 +105,9 @@ public class CatalogYamlLocationTest extends AbstractYamlTest {
         assertEquals(Iterables.getOnlyElement(libs).getUrl(), Iterables.getOnlyElement(getOsgiLibraries()));
     }
 
+    @SuppressWarnings({ "rawtypes", "unchecked" })
     private void assertAdded(String symbolicName, String expectedJavaType) {
-        CatalogItem<?, ?> item = mgmt().getCatalog().getCatalogItem(symbolicName, TEST_VERSION);
+        CatalogItem item = mgmt().getCatalog().getCatalogItem(symbolicName, TEST_VERSION);
         assertEquals(item.getSymbolicName(), symbolicName);
         assertEquals(countCatalogLocations(), 1);
 
@@ -115,7 +116,7 @@ public class CatalogYamlLocationTest extends AbstractYamlTest {
         assertEquals(def.getId(), symbolicName);
         assertEquals(def.getName(), symbolicName);
         
-        LocationSpec<?> spec = (LocationSpec<?>)mgmt().getCatalog().createSpec(item);
+        LocationSpec spec = (LocationSpec) mgmt().getCatalog().createSpec(item);
         assertEquals(spec.getType().getName(), expectedJavaType);
     }
     

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/eee43613/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/CampYamlLiteTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/CampYamlLiteTest.java b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/CampYamlLiteTest.java
index 2eda1d5..b325c62 100644
--- a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/CampYamlLiteTest.java
+++ b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/CampYamlLiteTest.java
@@ -168,7 +168,8 @@ public class CampYamlLiteTest {
         Assert.assertEquals(bundle.getUrl(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL);
         Assert.assertEquals(bundle.getVersion(), "0.1.0");
 
-        EntitySpec<?> spec1 = (EntitySpec<?>) mgmt.getCatalog().createSpec(retrievedItem);
+        @SuppressWarnings({ "unchecked", "rawtypes" })
+        EntitySpec<?> spec1 = (EntitySpec<?>) mgmt.getCatalog().createSpec((CatalogItem)retrievedItem);
         assertNotNull(spec1);
         Assert.assertEquals(spec1.getConfig().get(TestEntity.CONF_NAME), "sample");
         

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/eee43613/usage/cli/src/main/java/org/apache/brooklyn/cli/Main.java
----------------------------------------------------------------------
diff --git a/usage/cli/src/main/java/org/apache/brooklyn/cli/Main.java b/usage/cli/src/main/java/org/apache/brooklyn/cli/Main.java
index 1b39015..b546d7b 100644
--- a/usage/cli/src/main/java/org/apache/brooklyn/cli/Main.java
+++ b/usage/cli/src/main/java/org/apache/brooklyn/cli/Main.java
@@ -631,7 +631,8 @@ public class Main extends AbstractMain {
                         // and additionally they might contain multiple items in which case
                         // the validation below won't work anyway (you need to go via a deployment plan)
                     } else {
-                        Object spec = catalog.createSpec(item);
+                        @SuppressWarnings({ "unchecked", "rawtypes" })
+                        Object spec = catalog.createSpec((CatalogItem)item);
                         if (spec instanceof EntitySpec) {
                             BrooklynTypes.getDefinedEntityType(((EntitySpec<?>)spec).getType());
                         }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/eee43613/usage/rest-server/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java b/usage/rest-server/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java
index d7c26df..38b7815 100644
--- a/usage/rest-server/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java
+++ b/usage/rest-server/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java
@@ -243,7 +243,7 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
                 Entitlements.getEntitlementContext().user());
         }
 
-        CatalogItem<? extends Entity,EntitySpec<?>> result =
+        CatalogItem<Entity,EntitySpec<?>> result =
                 CatalogUtils.getCatalogItemOptionalVersion(mgmt(), Entity.class, entityId);
 
         if (result==null) {
@@ -263,8 +263,8 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
         //TODO These casts are not pretty, we could just provide separate get methods for the different types?
         //Or we could provide asEntity/asPolicy cast methods on the CataloItem doing a safety check internally
         @SuppressWarnings("unchecked")
-        CatalogItem<? extends Entity, EntitySpec<?>> result =
-              (CatalogItem<? extends Entity, EntitySpec<?>>) brooklyn().getCatalog().getCatalogItem(symbolicName, version);
+        CatalogItem<Entity, EntitySpec<?>> result =
+              (CatalogItem<Entity, EntitySpec<?>>) brooklyn().getCatalog().getCatalogItem(symbolicName, version);
 
         if (result==null) {
             throw WebResourceUtils.notFound("Entity with id '%s:%s' not found", symbolicName, version);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/eee43613/usage/rest-server/src/main/java/org/apache/brooklyn/rest/transform/CatalogTransformer.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/main/java/org/apache/brooklyn/rest/transform/CatalogTransformer.java b/usage/rest-server/src/main/java/org/apache/brooklyn/rest/transform/CatalogTransformer.java
index dae4164..e3e53f9 100644
--- a/usage/rest-server/src/main/java/org/apache/brooklyn/rest/transform/CatalogTransformer.java
+++ b/usage/rest-server/src/main/java/org/apache/brooklyn/rest/transform/CatalogTransformer.java
@@ -58,13 +58,13 @@ public class CatalogTransformer {
 
     private static final org.slf4j.Logger log = LoggerFactory.getLogger(CatalogTransformer.class);
     
-    public static CatalogEntitySummary catalogEntitySummary(BrooklynRestResourceUtils b, CatalogItem<? extends Entity,EntitySpec<?>> item) {
+    public static <T extends Entity> CatalogEntitySummary catalogEntitySummary(BrooklynRestResourceUtils b, CatalogItem<T,EntitySpec<? extends T>> item) {
         Set<EntityConfigSummary> config = Sets.newTreeSet(SummaryComparators.nameComparator());
         Set<SensorSummary> sensors = Sets.newTreeSet(SummaryComparators.nameComparator());
         Set<EffectorSummary> effectors = Sets.newTreeSet(SummaryComparators.nameComparator());
 
         try {
-            EntitySpec<?> spec = b.getCatalog().createSpec(item);
+            EntitySpec<?> spec = (EntitySpec<?>) b.getCatalog().createSpec((CatalogItem) item);
             EntityDynamicType typeMap = BrooklynTypes.getDefinedEntityType(spec.getType());
             EntityType type = typeMap.getSnapshot();
 
@@ -94,17 +94,17 @@ public class CatalogTransformer {
             item.isDeprecated(), makeLinks(item));
     }
 
-    @SuppressWarnings("unchecked")
-    public static CatalogItemSummary catalogItemSummary(BrooklynRestResourceUtils b, CatalogItem<?,?> item) {
+    @SuppressWarnings({ "unchecked", "rawtypes" })
+    public static CatalogItemSummary catalogItemSummary(BrooklynRestResourceUtils b, CatalogItem item) {
         try {
             switch (item.getCatalogItemType()) {
             case TEMPLATE:
             case ENTITY:
-                return catalogEntitySummary(b, (CatalogItem<? extends Entity, EntitySpec<?>>) item);
+                return catalogEntitySummary(b, item);
             case POLICY:
-                return catalogPolicySummary(b, (CatalogItem<? extends Policy, PolicySpec<?>>) item);
+                return catalogPolicySummary(b, item);
             case LOCATION:
-                return catalogLocationSummary(b, (CatalogItem<? extends Location, LocationSpec<?>>) item);
+                return catalogLocationSummary(b, item);
             default:
                 log.warn("Unexpected catalog item type when getting self link (supplying generic item): "+item.getCatalogItemType()+" "+item);
             }


[12/15] incubator-brooklyn git commit: fix instructions for license report

Posted by he...@apache.org.
fix instructions for license report


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/9a940c34
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/9a940c34
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/9a940c34

Branch: refs/heads/master
Commit: 9a940c34220a419a27c2dda78f9fe38d1a1a0fc9
Parents: 7ca2781
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Tue Sep 15 17:38:48 2015 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Tue Sep 15 17:39:21 2015 +0100

----------------------------------------------------------------------
 usage/dist/licensing/README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/9a940c34/usage/dist/licensing/README.md
----------------------------------------------------------------------
diff --git a/usage/dist/licensing/README.md b/usage/dist/licensing/README.md
index d6d295d..636677c 100644
--- a/usage/dist/licensing/README.md
+++ b/usage/dist/licensing/README.md
@@ -39,7 +39,7 @@ If you need to generate a CSV report of license usage, e.g. for use in a spreads
         -DsuppressExcludedDependencies=true \
         -DlicensesPreferred=ASL2,ASL,EPL1,BSD-2-Clause,BSD-3-Clause,CDDL1.1,CDDL1,CDDL \
         -DoverridesFile=licensing/overrides.yaml \
-        -DextrasFile=`cat licensing/extras-files` \
+        -DextrasFiles=`cat licensing/extras-files` \
         -DoutputFile=dependencies-licenses.csv
 
 


[15/15] incubator-brooklyn git commit: This closes #884

Posted by he...@apache.org.
This closes #884


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/5bb7cc69
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/5bb7cc69
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/5bb7cc69

Branch: refs/heads/master
Commit: 5bb7cc6935b302c32adaeec5251628115550bd0c
Parents: 099d88a bbe8366
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Tue Sep 15 17:49:36 2015 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Tue Sep 15 17:49:36 2015 +0100

----------------------------------------------------------------------
 .../brooklyn/api/entity/EntityInitializer.java  |   9 +
 .../BasicAssemblyTemplateInstantiator.java      |   2 +-
 .../apache/brooklyn/core/entity/Entities.java   |  37 +++-
 .../apache/brooklyn/core/sensor/Sensors.java    |   2 +-
 docs/guide/ops/cli-reference.md                 | 201 +++++++++++++++++++
 docs/guide/ops/index.md                         |   9 +-
 docs/guide/ops/install-on-server.md             | 131 ------------
 docs/guide/ops/launch.md                        | 201 -------------------
 docs/guide/ops/production-installation.md       | 103 ++++++++++
 docs/guide/ops/requirements.md                  |   2 +-
 docs/guide/ops/rest.md                          |  89 ++++++++
 .../brooklyn/launcher/BrooklynLauncher.java     |   6 +-
 .../apache/brooklyn/rest/BrooklynWebConfig.java |   3 +
 ...nUserWithRandomPasswordSecurityProvider.java |  10 +-
 .../provider/DelegatingSecurityProvider.java    |  10 +
 .../provider/ExplicitUsersSecurityProvider.java |  37 +++-
 16 files changed, 495 insertions(+), 357 deletions(-)
----------------------------------------------------------------------



[05/15] incubator-brooklyn git commit: fix duration parse for `never` and tests

Posted by he...@apache.org.
fix duration parse for `never` and tests


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

Branch: refs/heads/master
Commit: a340dbc311c19aef84c6b98d4d91b7776932212a
Parents: e92dd1e
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Thu Sep 10 13:52:27 2015 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Thu Sep 10 14:01:59 2015 +0100

----------------------------------------------------------------------
 .../org/apache/brooklyn/util/time/Duration.java |  4 +-
 .../org/apache/brooklyn/util/time/Time.java     | 98 +++++++++++---------
 .../org/apache/brooklyn/util/time/TimeTest.java |  8 +-
 3 files changed, 64 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a340dbc3/utils/common/src/main/java/org/apache/brooklyn/util/time/Duration.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/time/Duration.java b/utils/common/src/main/java/org/apache/brooklyn/util/time/Duration.java
index b11c0b0..e8dee7d 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/util/time/Duration.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/util/time/Duration.java
@@ -28,6 +28,8 @@ import java.util.concurrent.TimeUnit;
 
 import javax.annotation.Nullable;
 
+import org.apache.brooklyn.util.text.Strings;
+
 import com.google.common.base.Function;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Stopwatch;
@@ -138,7 +140,7 @@ public class Duration implements Comparable<Duration>, Serializable {
      * also accepts "forever" (and for those who prefer things exceedingly accurate, "practically_forever"). 
      * Also see {@link #of(Object)}. */
     public static Duration parse(String textualDescription) {
-        if (textualDescription==null) return null;
+        if (Strings.isBlank(textualDescription)) return null;
         if ("null".equalsIgnoreCase(textualDescription)) return null;
         
         if ("forever".equalsIgnoreCase(textualDescription)) return Duration.PRACTICALLY_FOREVER;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a340dbc3/utils/common/src/main/java/org/apache/brooklyn/util/time/Time.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/time/Time.java b/utils/common/src/main/java/org/apache/brooklyn/util/time/Time.java
index b1ab8f3..25bd9de 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/util/time/Time.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/util/time/Time.java
@@ -440,63 +440,73 @@ public class Time {
      * 
      * @throws NumberFormatException if cannot be parsed (or if null)
      */
-    public static double parseElapsedTimeAsDouble(String timeString) {
+    public static double parseElapsedTimeAsDouble(final String timeStringOrig) {
+        String timeString = timeStringOrig;
         if (timeString==null)
             throw new NumberFormatException("GeneralHelper.parseTimeString cannot parse a null string");
         try {
             double d = Double.parseDouble(timeString);
             return d;
         } catch (NumberFormatException e) {
-            //look for a type marker
-            timeString = timeString.trim();
-            String s = Strings.getLastWord(timeString).toLowerCase();
-            timeString = timeString.substring(0, timeString.length()-s.length()).trim();
-            int i=0;
-            while (s.length()>i) {
-                char c = s.charAt(i);
-                if (c=='.' || Character.isDigit(c)) i++;
-                else break;
-            }
-            String num = s.substring(0, i);
-            if (i==0) {
-                num = Strings.getLastWord(timeString).toLowerCase();
-                timeString = timeString.substring(0, timeString.length()-num.length()).trim();
-            } else {
-                s = s.substring(i);
-            }
-            long multiplier = 0;
-            if (num.length()==0) {
-                //must be never or something
-                if (s.equalsIgnoreCase("never") || s.equalsIgnoreCase("off") || s.equalsIgnoreCase("false"))
-                    return -1;
-                throw new NumberFormatException("unrecognised word  '"+s+"' in time string");
-            }
-            if (s.equalsIgnoreCase("ms") || s.equalsIgnoreCase("milli") || s.equalsIgnoreCase("millis")
+            try {
+                //look for a type marker
+                timeString = timeString.trim();
+                String s = Strings.getLastWord(timeString).toLowerCase();
+                timeString = timeString.substring(0, timeString.length()-s.length()).trim();
+                int i=0;
+                while (s.length()>i) {
+                    char c = s.charAt(i);
+                    if (c=='.' || Character.isDigit(c)) i++;
+                    else break;
+                }
+                String num = s.substring(0, i);
+                if (i==0) {
+                    if (Strings.isNonBlank(timeString)) {
+                        num = Strings.getLastWord(timeString).toLowerCase();
+                        timeString = timeString.substring(0, timeString.length()-num.length()).trim();
+                    }
+                } else {
+                    s = s.substring(i);
+                }
+                long multiplier = 0;
+                if (num.length()==0) {
+                    //must be never or something
+                    // TODO does 'never' work?
+                    if (s.equalsIgnoreCase("never") || s.equalsIgnoreCase("off") || s.equalsIgnoreCase("false"))
+                        return -1;
+                    throw new NumberFormatException("unrecognised word  '"+s+"' in time string");
+                }
+                if (s.equalsIgnoreCase("ms") || s.equalsIgnoreCase("milli") || s.equalsIgnoreCase("millis")
                     || s.equalsIgnoreCase("millisec") || s.equalsIgnoreCase("millisecs")
                     || s.equalsIgnoreCase("millisecond") || s.equalsIgnoreCase("milliseconds"))
-                multiplier = 1;
-            else if (s.equalsIgnoreCase("s") || s.equalsIgnoreCase("sec") || s.equalsIgnoreCase("secs")
+                    multiplier = 1;
+                else if (s.equalsIgnoreCase("s") || s.equalsIgnoreCase("sec") || s.equalsIgnoreCase("secs")
                     || s.equalsIgnoreCase("second") || s.equalsIgnoreCase("seconds"))
-                multiplier = 1000;
-            else if (s.equalsIgnoreCase("m") || s.equalsIgnoreCase("min") || s.equalsIgnoreCase("mins")
+                    multiplier = 1000;
+                else if (s.equalsIgnoreCase("m") || s.equalsIgnoreCase("min") || s.equalsIgnoreCase("mins")
                     || s.equalsIgnoreCase("minute") || s.equalsIgnoreCase("minutes"))
-                multiplier = 60*1000;
-            else if (s.equalsIgnoreCase("h") || s.equalsIgnoreCase("hr") || s.equalsIgnoreCase("hrs")
+                    multiplier = 60*1000;
+                else if (s.equalsIgnoreCase("h") || s.equalsIgnoreCase("hr") || s.equalsIgnoreCase("hrs")
                     || s.equalsIgnoreCase("hour") || s.equalsIgnoreCase("hours"))
-                multiplier = 60*60*1000;
-            else if (s.equalsIgnoreCase("d") || s.equalsIgnoreCase("day") || s.equalsIgnoreCase("days"))
-                multiplier = 24*60*60*1000;
-            else
-                throw new NumberFormatException("unknown unit '"+s+"' in time string");
-            double d = Double.parseDouble(num);
-            double dd = 0;
-            if (timeString.length()>0) {
-                dd = parseElapsedTimeAsDouble(timeString);
-                if (dd==-1) {
-                    throw new NumberFormatException("cannot combine '"+timeString+"' with '"+num+" "+s+"'");
+                    multiplier = 60*60*1000;
+                else if (s.equalsIgnoreCase("d") || s.equalsIgnoreCase("day") || s.equalsIgnoreCase("days"))
+                    multiplier = 24*60*60*1000;
+                else
+                    throw new NumberFormatException("Unknown unit '"+s+"' in time string '"+timeStringOrig+"'");
+                double d = Double.parseDouble(num);
+                double dd = 0;
+                if (timeString.length()>0) {
+                    dd = parseElapsedTimeAsDouble(timeString);
+                    if (dd==-1) {
+                        throw new NumberFormatException("Cannot combine '"+timeString+"' with '"+num+" "+s+"'");
+                    }
                 }
+                return d*multiplier + dd;
+            } catch (Exception ex) {
+                if (ex instanceof NumberFormatException) throw ex;
+                log.trace("Details of parse failure:", ex);
+                throw new NumberFormatException("Cannot parse time string '"+timeStringOrig+"'");
             }
-            return d*multiplier + dd;
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a340dbc3/utils/common/src/test/java/org/apache/brooklyn/util/time/TimeTest.java
----------------------------------------------------------------------
diff --git a/utils/common/src/test/java/org/apache/brooklyn/util/time/TimeTest.java b/utils/common/src/test/java/org/apache/brooklyn/util/time/TimeTest.java
index 2cce436..60945cf 100644
--- a/utils/common/src/test/java/org/apache/brooklyn/util/time/TimeTest.java
+++ b/utils/common/src/test/java/org/apache/brooklyn/util/time/TimeTest.java
@@ -152,7 +152,13 @@ public class TimeTest {
         Assert.assertFalse(Time.hasElapsedSince(aFewSecondsAgo, Duration.TEN_SECONDS));
         Assert.assertTrue(Time.hasElapsedSince(-1, Duration.TEN_SECONDS));
     }
-    
+
+    @Test
+    public void testParseTime() {
+        Assert.assertEquals(Time.parseElapsedTime("1s"), 1000);
+        Assert.assertEquals(Time.parseElapsedTime("never"), -1);
+    }
+
     @Test
     public void testMakeDateString() {
         String in1 = "2015-06-15T12:34:56";


[14/15] incubator-brooklyn git commit: This closes #887

Posted by he...@apache.org.
This closes #887


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/099d88ad
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/099d88ad
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/099d88ad

Branch: refs/heads/master
Commit: 099d88ad1f747bf5ed5bbcb4dce9cf347abeb998
Parents: f34d0a3 eee4361
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Tue Sep 15 17:48:30 2015 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Tue Sep 15 17:48:30 2015 +0100

----------------------------------------------------------------------
 .../brooklyn/api/catalog/BrooklynCatalog.java   |  4 +-
 .../catalog/internal/BasicBrooklynCatalog.java  | 35 +++++--
 .../catalog/internal/CatalogInitialization.java |  3 +
 .../core/location/CatalogLocationResolver.java  |  9 +-
 .../core/mgmt/EntityManagementUtils.java        |  9 +-
 .../brooklyn/core/plan/PlanToSpecFactory.java   | 15 ++-
 .../core/plan/PlanToSpecTransformer.java        |  2 +-
 .../brooklyn/util/core/file/ArchiveBuilder.java | 61 +++++++-----
 .../core/plan/XmlPlanToSpecTransformer.java     |  8 +-
 .../util/core/file/ArchiveBuilderTest.java      | 44 +++++----
 .../BrooklynAssemblyTemplateInstantiator.java   | 27 +++---
 .../BrooklynComponentTemplateResolver.java      | 42 ++++++---
 .../BrooklynEntityDecorationResolver.java       | 11 ++-
 .../spi/creation/BrooklynEntityMatcher.java     |  1 +
 .../spi/creation/CampToSpecTransformer.java     | 64 ++++++++-----
 .../CatalogOsgiVersionMoreEntityTest.java       |  3 +-
 .../brooklyn/catalog/CatalogYamlEntityTest.java |  3 +-
 .../catalog/CatalogYamlLocationTest.java        |  5 +-
 .../brooklyn/test/lite/CampYamlLiteTest.java    |  3 +-
 .../main/java/org/apache/brooklyn/cli/Main.java |  3 +-
 usage/jsgui/src/main/webapp/assets/css/base.css |  3 +
 .../assets/js/model/server-extended-status.js   |  2 +-
 .../src/main/webapp/assets/js/view/catalog.js   |  2 +-
 .../webapp/assets/tpl/catalog/add-location.html |  3 +-
 .../webapp/assets/tpl/catalog/add-yaml.html     |  3 +-
 .../rest/resources/CatalogResource.java         |  6 +-
 .../rest/transform/CatalogTransformer.java      | 14 +--
 .../brooklyn/util/exceptions/Exceptions.java    |  5 +-
 .../util/exceptions/UserFacingException.java    |  2 +-
 .../java/org/apache/brooklyn/util/os/Os.java    |  3 +-
 .../org/apache/brooklyn/util/time/Duration.java |  4 +-
 .../org/apache/brooklyn/util/time/Time.java     | 98 +++++++++++---------
 .../org/apache/brooklyn/util/time/TimeTest.java |  8 +-
 33 files changed, 309 insertions(+), 196 deletions(-)
----------------------------------------------------------------------



[11/15] incubator-brooklyn git commit: Update IntelliJ configuration

Posted by he...@apache.org.
Update IntelliJ configuration

Remove reference to Java 1.6 (Brooklyn doesn't support this any more) and add a note about "optimize imports" reconfiguration.

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

Branch: refs/heads/master
Commit: fb7a70f47665720fea1e612fe58c4e5edaf4b154
Parents: 7ca2781
Author: Richard Downer <ri...@apache.org>
Authored: Tue Sep 15 13:32:29 2015 +0100
Committer: Richard Downer <ri...@apache.org>
Committed: Tue Sep 15 13:32:29 2015 +0100

----------------------------------------------------------------------
 docs/guide/dev/env/ide/index.md | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/fb7a70f4/docs/guide/dev/env/ide/index.md
----------------------------------------------------------------------
diff --git a/docs/guide/dev/env/ide/index.md b/docs/guide/dev/env/ide/index.md
index f046abc..b33ef1a 100644
--- a/docs/guide/dev/env/ide/index.md
+++ b/docs/guide/dev/env/ide/index.md
@@ -87,11 +87,11 @@ To develop or debug Brooklyn in IntelliJ, you will need to ensure that the Groov
 via the IntelliJ IDEA | Preferences | Plugins menu. Once installed, you can open Brooklyn from the root folder, 
 (e.g. ``~/myfiles/brooklyn``) which will automatically open the subprojects.
 
-You will need the java compiler 1.7 or higher.
-There have previously been issues where the java 6 compiler incorrectly identified the return type of functions that use
-generics. These issues have been refactored away, however may return in future. 
-If you encounter these problems, ensure that your java compiler is set to level 1.7 or higher, 
-or setup IntelliJ to use the Eclipse compiler (Settings | Compiler | Java Compiler | "Use Compiler" combobox).
+Brooklyn has informally standardized on arranging `import` statements as per Eclipse's default configuration.
+IntelliJ's default configuration is different, which can result in unwanted "noise" in commits where imports are
+shuffled backward and forward between the two types - PRs which do this will likely fail the review. To avoid this,
+reconfigure IntelliJ to organize imports similar to Eclipse. See [this StackOverflow answer](http://stackoverflow.com/a/17194980/68898)
+for a suitable configuration.
 
 
 ## Netbeans