You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sj...@apache.org on 2015/06/05 16:29:26 UTC

[1/6] incubator-brooklyn git commit: add support to control java version installed

Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master 7066d94e8 -> 1a2819384


add support to control java version installed


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

Branch: refs/heads/master
Commit: 42f4929aa012c02863d2add81b99b5c1575ccaf1
Parents: 9595ddc
Author: Andrea Turli <an...@gmail.com>
Authored: Thu Apr 30 15:36:58 2015 +0200
Committer: Andrea Turli <an...@gmail.com>
Committed: Mon Jun 1 11:56:39 2015 +0200

----------------------------------------------------------------------
 .../basic/AbstractSoftwareProcessSshDriver.java |  84 +++++------
 .../java/JavaSoftwareProcessSshDriver.java      | 139 ++++++++-----------
 .../java/brooklyn/entity/java/UsesJava.java     |  18 ++-
 ...SoftwareProcessSshDriverIntegrationTest.java |  32 ++---
 .../nosql/cassandra/CassandraNodeSshDriver.java |  32 ++---
 .../nosql/riak/RiakNodeIntegrationTest.java     |   7 +-
 .../nosql/riak/RiakNodeSoftlayerLiveTest.java   |   9 +-
 7 files changed, 143 insertions(+), 178 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/42f4929a/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessSshDriver.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessSshDriver.java b/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessSshDriver.java
index 597a967..3ebad57 100644
--- a/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessSshDriver.java
+++ b/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessSshDriver.java
@@ -30,11 +30,17 @@ import java.util.Set;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Predicates;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+
 import brooklyn.config.BrooklynLogging;
 import brooklyn.entity.basic.lifecycle.NaiveScriptRunner;
 import brooklyn.entity.basic.lifecycle.ScriptHelper;
 import brooklyn.entity.drivers.downloads.DownloadResolver;
-import brooklyn.entity.drivers.downloads.DownloadResolverManager;
 import brooklyn.entity.effector.EffectorTasks;
 import brooklyn.entity.software.SshEffectorTasks;
 import brooklyn.event.feed.ConfigToAttributes;
@@ -54,20 +60,13 @@ import brooklyn.util.text.StringPredicates;
 import brooklyn.util.text.Strings;
 import brooklyn.util.time.Duration;
 
-import com.google.common.base.Predicates;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-
 /**
  * An abstract SSH implementation of the {@link AbstractSoftwareProcessDriver}.
- * 
+ *
  * This provides conveniences for clients implementing the install/customize/launch/isRunning/stop lifecycle
  * over SSH.  These conveniences include checking whether software is already installed,
  * creating/using a PID file for some operations, and reading ssh-specific config from the entity
- * to override/augment ssh flags on the session.  
+ * to override/augment ssh flags on the session.
  */
 public abstract class AbstractSoftwareProcessSshDriver extends AbstractSoftwareProcessDriver implements NaiveScriptRunner {
 
@@ -81,51 +80,36 @@ public abstract class AbstractSoftwareProcessSshDriver extends AbstractSoftwareP
     private final Object installDirSetupMutex = new Object();
 
     protected volatile DownloadResolver resolver;
-    
+
     /** include this flag in newScript creation to prevent entity-level flags from being included;
      * any SSH-specific flags passed to newScript override flags from the entity,
      * and flags from the entity override flags on the location
      * (where there aren't conflicts, flags from all three are used however) */
-    public static final String IGNORE_ENTITY_SSH_FLAGS = SshEffectorTasks.IGNORE_ENTITY_SSH_FLAGS.getName(); 
+    public static final String IGNORE_ENTITY_SSH_FLAGS = SshEffectorTasks.IGNORE_ENTITY_SSH_FLAGS.getName();
 
     public AbstractSoftwareProcessSshDriver(EntityLocal entity, SshMachineLocation machine) {
         super(entity, machine);
-        
+
         // FIXME this assumes we own the location, and causes warnings about configuring location after deployment;
         // better would be to wrap the ssh-execution-provider to supply these flags
         if (getSshFlags()!=null && !getSshFlags().isEmpty())
             machine.configure(getSshFlags());
-        
-        // ensure these are set using the routines below, not a global ConfigToAttributes.apply() 
+
+        // ensure these are set using the routines below, not a global ConfigToAttributes.apply()
         getInstallDir();
         getRunDir();
     }
 
-    /** returns location (tighten type, since we know it is an ssh machine location here) */    
+    /** returns location (tighten type, since we know it is an ssh machine location here) */
     public SshMachineLocation getLocation() {
         return (SshMachineLocation) super.getLocation();
     }
 
-    /**
-     * Name to be used in the local repo, when looking for the download file.
-     */
-    public String getDownloadFilename() {
-        return getEntity().getEntityType().getSimpleName().toLowerCase() + "-"+getVersion() + ".tar.gz";
-    }
-
-    /**
-     * Suffix to use when looking up the file in the local repo.
-     * Ignored if {@link getDownloadFilename()} returns non-null.
-     */
-    public String getDownloadFileSuffix() {
-        return "tar.gz";
-    }
-    
     protected void setInstallDir(String installDir) {
         this.installDir = installDir;
         entity.setAttribute(SoftwareProcess.INSTALL_DIR, installDir);
     }
-    
+
     public String getInstallDir() {
         if (installDir != null) return installDir;
 
@@ -157,16 +141,16 @@ public abstract class AbstractSoftwareProcessSshDriver extends AbstractSoftwareP
             return installDir;
         }
     }
-    
+
     protected void setInstallLabel() {
-        if (getEntity().getConfigRaw(SoftwareProcess.INSTALL_UNIQUE_LABEL, false).isPresentAndNonNull()) return; 
-        getEntity().setConfig(SoftwareProcess.INSTALL_UNIQUE_LABEL, 
+        if (getEntity().getConfigRaw(SoftwareProcess.INSTALL_UNIQUE_LABEL, false).isPresentAndNonNull()) return;
+        getEntity().setConfig(SoftwareProcess.INSTALL_UNIQUE_LABEL,
             getEntity().getEntityType().getSimpleName()+
             (Strings.isNonBlank(getVersion()) ? "_"+getVersion() : "")+
             (Strings.isNonBlank(getInstallLabelExtraSalt()) ? "_"+getInstallLabelExtraSalt() : "") );
     }
 
-    /** allows subclasses to return extra salt (ie unique hash) 
+    /** allows subclasses to return extra salt (ie unique hash)
      * for cases where install dirs need to be distinct e.g. based on extra plugins being placed in the install dir;
      * {@link #setInstallLabel()} uses entity-type simple name and version already
      * <p>
@@ -181,10 +165,10 @@ public abstract class AbstractSoftwareProcessSshDriver extends AbstractSoftwareP
         this.runDir = runDir;
         entity.setAttribute(SoftwareProcess.RUN_DIR, runDir);
     }
-    
+
     public String getRunDir() {
         if (runDir != null) return runDir;
-        
+
         String existingVal = getEntity().getAttribute(SoftwareProcess.RUN_DIR);
         if (Strings.isNonBlank(existingVal)) { // e.g. on rebind
             runDir = existingVal;
@@ -213,14 +197,14 @@ public abstract class AbstractSoftwareProcessSshDriver extends AbstractSoftwareP
         if (Strings.isNonBlank(oldVal) && !oldVal.equals(val)) {
             log.info("Resetting expandedInstallDir (to "+val+" from "+oldVal+") for "+getEntity());
         }
-        
+
         expandedInstallDir = val;
         getEntity().setAttribute(SoftwareProcess.EXPANDED_INSTALL_DIR, val);
     }
-    
+
     public String getExpandedInstallDir() {
         if (expandedInstallDir != null) return expandedInstallDir;
-        
+
         String existingVal = getEntity().getAttribute(SoftwareProcess.EXPANDED_INSTALL_DIR);
         if (Strings.isNonBlank(existingVal)) { // e.g. on rebind
             expandedInstallDir = existingVal;
@@ -258,7 +242,7 @@ public abstract class AbstractSoftwareProcessSshDriver extends AbstractSoftwareP
     @Override
     public int execute(Map flags2, List<String> script, String summaryForLogging) {
         // TODO replace with SshEffectorTasks.ssh ?; remove the use of flags
-        
+
         Map flags = Maps.newLinkedHashMap();
         if (!flags2.containsKey(IGNORE_ENTITY_SSH_FLAGS)) {
             flags.putAll(getSshFlags());
@@ -276,7 +260,7 @@ public abstract class AbstractSoftwareProcessSshDriver extends AbstractSoftwareP
                 Tasks.addTagDynamically(BrooklynTaskTags.tagForEnvStream(BrooklynTaskTags.STREAM_ENV, environment));
             }
             if (BrooklynTaskTags.stream(Tasks.current(), BrooklynTaskTags.STREAM_STDIN)==null) {
-                Tasks.addTagDynamically(BrooklynTaskTags.tagForStreamSoft(BrooklynTaskTags.STREAM_STDIN, 
+                Tasks.addTagDynamically(BrooklynTaskTags.tagForStreamSoft(BrooklynTaskTags.STREAM_STDIN,
                     Streams.byteArrayOfString(Strings.join(script, "\n"))));
             }
             if (BrooklynTaskTags.stream(Tasks.current(), BrooklynTaskTags.STREAM_STDOUT)==null) {
@@ -334,7 +318,6 @@ public abstract class AbstractSoftwareProcessSshDriver extends AbstractSoftwareP
     }
 
 
-    
     /**
      * @param sshFlags Extra flags to be used when making an SSH connection to the entity's machine.
      *                 If the map contains the key {@link #IGNORE_ENTITY_SSH_FLAGS} then only the
@@ -374,13 +357,12 @@ public abstract class AbstractSoftwareProcessSshDriver extends AbstractSoftwareP
         return result;
     }
 
-    
     /**
      * Input stream will be closed automatically.
      * <p>
      * If using {@link SshjTool} usage, consider using {@link KnownSizeInputStream} to avoid having
-     * to write out stream once to find its size!  
-     * 
+     * to write out stream once to find its size!
+     *
      * @see #copyResource(Map, String, String) for parameter descriptions.
      */
     @SuppressWarnings({ "rawtypes", "unchecked" })
@@ -519,7 +501,7 @@ public abstract class AbstractSoftwareProcessSshDriver extends AbstractSoftwareP
     protected ScriptHelper newScript(Map<String, ?> flags, String phase) {
         if (!Entities.isManaged(getEntity()))
             throw new IllegalStateException(getEntity()+" is no longer managed; cannot create script to run here ("+phase+")");
-        
+
         if (!Iterables.all(flags.keySet(), StringPredicates.equalToAny(VALID_FLAGS))) {
             throw new IllegalArgumentException("Invalid flags passed: " + flags);
         }
@@ -530,7 +512,7 @@ public abstract class AbstractSoftwareProcessSshDriver extends AbstractSoftwareP
                 s.header.prepend("set -x");
             }
             if (INSTALLING.equals(phase)) {
-                // mutexId should be global because otherwise package managers will contend with each other 
+                // mutexId should be global because otherwise package managers will contend with each other
                 s.useMutex(getLocation(), "installation lock at host", "installing "+elvis(entity,this));
                 s.header.append(
                         "export INSTALL_DIR=\""+getInstallDir()+"\"",
@@ -639,8 +621,8 @@ public abstract class AbstractSoftwareProcessSshDriver extends AbstractSoftwareP
                     );
                 } else {
                     s.footer.prepend(
-                            "test -f "+pidFile+" || exit 1", 
-                            "ps -p $(cat "+pidFile+") || exit 1" 
+                            "test -f "+pidFile+" || exit 1",
+                            "ps -p $(cat "+pidFile+") || exit 1"
                     );
                 }
                 // no pid, not running; no process; can't restart, 1 is not running

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/42f4929a/software/base/src/main/java/brooklyn/entity/java/JavaSoftwareProcessSshDriver.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/entity/java/JavaSoftwareProcessSshDriver.java b/software/base/src/main/java/brooklyn/entity/java/JavaSoftwareProcessSshDriver.java
index d2a11c9..08ccfcb 100644
--- a/software/base/src/main/java/brooklyn/entity/java/JavaSoftwareProcessSshDriver.java
+++ b/software/base/src/main/java/brooklyn/entity/java/JavaSoftwareProcessSshDriver.java
@@ -30,6 +30,17 @@ import java.util.Set;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Function;
+import com.google.common.base.Joiner;
+import com.google.common.base.Optional;
+import com.google.common.base.Splitter;
+import com.google.common.base.Throwables;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.gson.internal.Primitives;
+
 import brooklyn.entity.basic.AbstractSoftwareProcessSshDriver;
 import brooklyn.entity.basic.Attributes;
 import brooklyn.entity.basic.Entities;
@@ -52,16 +63,6 @@ import brooklyn.util.task.system.ProcessTaskWrapper;
 import brooklyn.util.text.StringEscapes.BashStringEscapes;
 import brooklyn.util.text.Strings;
 
-import com.google.common.base.Function;
-import com.google.common.base.Joiner;
-import com.google.common.base.Optional;
-import com.google.common.base.Throwables;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.gson.internal.Primitives;
-
 /**
  * The SSH implementation of the {@link brooklyn.entity.java.JavaSoftwareProcessDriver}.
  */
@@ -102,7 +103,7 @@ public abstract class JavaSoftwareProcessSshDriver extends AbstractSoftwareProce
     @Override
     public Map<String, String> getShellEnvironment() {
         List<String> javaOpts = getJavaOpts();
-        
+
         for (String it : javaOpts) {
             BashStringEscapes.assertValidForDoubleQuotingInBash(it);
         }
@@ -210,7 +211,7 @@ public abstract class JavaSoftwareProcessSshDriver extends AbstractSoftwareProce
 
     /**
      * Return extra Java system properties (-D defines) used by the application.
-     * 
+     *
      * Override as needed; default is an empty map.
      */
     protected Map getCustomJavaSystemProperties() {
@@ -246,17 +247,17 @@ public abstract class JavaSoftwareProcessSshDriver extends AbstractSoftwareProce
 
     /**
      * Return the configuration properties required to enable JMX for a Java application.
-     * 
+     *
      * These should be set as properties in the {@code JAVA_OPTS} environment variable when calling the
      * run script for the application.
      */
     protected Map<String, ?> getJmxJavaSystemProperties() {
         MutableMap.Builder<String, Object> result = MutableMap.<String, Object> builder();
-        
+
         if (isJmxEnabled()) {
             new JmxSupport(getEntity(), getRunDir()).applyJmxJavaSystemProperties(result);
         }
-        
+
         return result.build();
     }
 
@@ -272,69 +273,32 @@ public abstract class JavaSoftwareProcessSshDriver extends AbstractSoftwareProce
     }
 
     /**
-     * Checks for the presence of Java 6 or 7 on the entity's location, installing if necessary.
-     * @return true if Java 6 or 7 was found on the machine or if it was installed correctly, otherwise false.
+     * Checks for the presence of Java on the entity's location, installing if necessary.
+     * @return true if the required version of Java was found on the machine or if it was installed correctly,
+     * otherwise false.
      */
-    protected boolean checkForAndInstallJava6or7() {
-        Optional<String> version = getCurrentJavaVersion();
-        if (version.isPresent() && (version.get().startsWith("1.8") || version.get().startsWith("1.7") || version.get().startsWith("1.6"))) {
-            log.debug("Java version {} already installed at {}@{}", new Object[]{version.get(), getEntity(), getLocation()});
-            return true;
+    protected boolean checkForAndInstallJava(String requiredVersion) {
+        int requiredJavaMinor;
+        if (requiredVersion.contains(".")) {
+            List<String> requiredVersionParts = Splitter.on(".").splitToList(requiredVersion);
+            requiredJavaMinor = Integer.valueOf(requiredVersionParts.get(1));
+        } else if (requiredVersion.length() == 1) {
+            requiredJavaMinor = Integer.valueOf(requiredVersion);
         } else {
-            // Let's hope not!
-            if (version.isPresent()) {
-                log.debug("Found old Java version {} on {}@{}. Going to install latest Java version.",
-                        new Object[]{version.get(), getEntity(), getLocation()});
-            }
-            return tryJavaInstall("latest", BashCommands.installJava7Or6OrFail()) == 0;
+            log.error("java version required {} is not supported", requiredVersion);
+            throw new IllegalArgumentException("Required java version " + requiredVersion + " not supported");
         }
-    }
-
-    /**
-     * Checks for the presence of Java 7 or 8 on the entity's location, installing if necessary.
-     * @return true if Java 7 or 8 was found on the machine or if it was installed correctly, otherwise false.
-     */
-    protected boolean checkForAndInstallJava7or8() {
-        Optional<String> version = getCurrentJavaVersion();
-        if (version.isPresent() && (version.get().startsWith("1.8") || version.get().startsWith("1.7"))) {
-            log.debug("Java version {} already installed at {}@{}", new Object[]{version.get(), getEntity(), getLocation()});
-            return true;
-        } else {
-            // Let's hope not!
-            if (version.isPresent()) {
-                log.debug("Found old Java version {} on {}@{}. Going to install latest Java version.",
-                        new Object[]{version.get(), getEntity(), getLocation()});
+        Optional<String> installedJavaVersion = getInstalledJavaVersion();
+        if (installedJavaVersion.isPresent()) {
+            List<String> installedVersionParts = Splitter.on(".").splitToList(installedJavaVersion.get());
+            int javaMajor = Integer.valueOf(installedVersionParts.get(0));
+            int javaMinor = Integer.valueOf(installedVersionParts.get(1));
+            if (javaMajor == 1 && javaMinor >= requiredJavaMinor) {
+                log.debug("Java {} already installed at {}@{}", new Object[]{installedJavaVersion.get(), getEntity(), getLocation()});
+                return true;
             }
-            return tryJavaInstall("latest", BashCommands.installJava7OrFail()) == 0;
-        }
-    }
-
-    /**
-     * Checks for the presence of Java 6 on the entity's location, installing if necessary.
-     * @return true if Java 6 was found on the machine or if it was installed correctly, otherwise false.
-     */
-    protected boolean checkForAndInstallJava6() {
-        Optional<String> version = getCurrentJavaVersion();
-        if (version.isPresent() && version.get().startsWith("1.6")) {
-            log.debug("Java 6 already installed at {}@{}", getEntity(), getLocation());
-            return true;
-        } else {
-            return tryJavaInstall("6", BashCommands.installJava6OrFail()) == 0;
-        }
-    }
-
-    /**
-     * Checks for the presence of Java 7 on the entity's location, installing if necessary.
-     * @return true if Java 7 was found on the machine or if it was installed correctly, otherwise false.
-     */
-    protected boolean checkForAndInstallJava7() {
-        Optional<String> version = getCurrentJavaVersion();
-        if (version.isPresent() && version.get().startsWith("1.7")) {
-            log.debug("Java 7 already installed at {}@{}", getEntity(), getLocation());
-            return true;
-        } else {
-            return tryJavaInstall("7", BashCommands.installJava7OrFail()) == 0;
         }
+        return tryJavaInstall(requiredVersion, BashCommands.installJava(requiredJavaMinor)) == 0;
     }
 
     protected int tryJavaInstall(String version, String command) {
@@ -350,17 +314,25 @@ public abstract class JavaSoftwareProcessSshDriver extends AbstractSoftwareProce
                 log.warn("Installation of Java {} failed at {}@{}: {}",
                         new Object[]{version, getEntity(), getLocation(), installCommand.getStderr()});
             }
-           return result;
+            return result;
         } finally {
             getLocation().releaseMutex("installing");
         }
     }
 
     /**
+    * @deprecated since 0.7.0; instead use {@link #getInstalledJavaVersion()}
+    */
+    @Deprecated
+    protected Optional<String> getCurrentJavaVersion() {
+        return getInstalledJavaVersion();
+    }
+
+    /**
      * Checks for the version of Java installed on the entity's location over SSH.
      * @return An Optional containing the version portion of `java -version`, or absent if no Java found.
      */
-    protected Optional<String> getCurrentJavaVersion() {
+    protected Optional<String> getInstalledJavaVersion() {
         log.debug("Checking Java version at {}@{}", getEntity(), getLocation());
         // sed gets stdin like 'java version "1.7.0_45"'
         ProcessTaskWrapper<Integer> versionCommand = Entities.submit(getEntity(), SshTasks.newSshExecTaskFactory(
@@ -400,13 +372,16 @@ public abstract class JavaSoftwareProcessSshDriver extends AbstractSoftwareProce
     /**
      * Checks for Java 6 or 7, installing Java 7 if neither are found. Override this method to
      * check for and install specific versions of Java.
-     * 
-     * @see #checkForAndInstallJava6()
-     * @see #checkForAndInstallJava7()
-     * @see #checkForAndInstallJava6or7()
+     *
+     * @see #checkForAndInstallJava(String)
      */
     public boolean installJava() {
-        return checkForAndInstallJava6or7();
+        if (entity instanceof UsesJava) {
+            String version = entity.getConfig(UsesJava.JAVA_VERSION_REQUIRED);
+            return checkForAndInstallJava(version);
+        }
+        // by default it installs jdk7
+        return checkForAndInstallJava("1.7");
     }
 
     public void installJmxSupport() {
@@ -415,10 +390,10 @@ public abstract class JavaSoftwareProcessSshDriver extends AbstractSoftwareProce
             new JmxSupport(getEntity(), getRunDir()).install();
         }
     }
-    
+
     public void checkJavaHostnameBug() {
         checkNoHostnameBug();
-        
+
         try {
             ProcessTaskWrapper<Integer> hostnameTask = DynamicTasks.queue(SshEffectorTasks.ssh("echo FOREMARKER; hostname -f; echo AFTMARKER")).block();
             String stdout = Strings.getFragmentBetween(hostnameTask.getStdout(), "FOREMARKER", "AFTMARKER");

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/42f4929a/software/base/src/main/java/brooklyn/entity/java/UsesJava.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/entity/java/UsesJava.java b/software/base/src/main/java/brooklyn/entity/java/UsesJava.java
index a0d97f8..1f824a1 100644
--- a/software/base/src/main/java/brooklyn/entity/java/UsesJava.java
+++ b/software/base/src/main/java/brooklyn/entity/java/UsesJava.java
@@ -18,15 +18,15 @@
  */
 package brooklyn.entity.java;
 
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Maps;
+
 import brooklyn.config.ConfigKey;
 import brooklyn.entity.basic.ConfigKeys;
 import brooklyn.event.basic.MapConfigKey;
 import brooklyn.event.basic.SetConfigKey;
 import brooklyn.util.flags.SetFromFlag;
 
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Maps;
-
 public interface UsesJava {
 
     /** system properties (-D) to append to JAVA_OPTS; normally accessed through {@link JavaEntityMethods#javaSysProp(String)} */
@@ -51,14 +51,18 @@ public interface UsesJava {
      *   <li>If value contains "=" then see if there's a default that matches the section up to the "=".
      *       If there is, then remove the original and just include this.
      *       e.g. "-XX:MaxPermSize=512m" could be overridden in this way.
-     * </ul> 
+     * </ul>
      */
     @SetFromFlag("javaOpts")
-    public static final SetConfigKey<String> JAVA_OPTS = new SetConfigKey<String>(String.class, 
+    public static final SetConfigKey<String> JAVA_OPTS = new SetConfigKey<String>(String.class,
             "java.opts", "Java command line options", ImmutableSet.<String>of());
 
-    public static final ConfigKey<Boolean> CHECK_JAVA_HOSTNAME_BUG = ConfigKeys.newBooleanConfigKey( 
+    public static final ConfigKey<Boolean> CHECK_JAVA_HOSTNAME_BUG = ConfigKeys.newBooleanConfigKey(
             "java.check.hostname.bug", "Check whether hostname is too long and will likely crash Java" +
                     "due to bug 7089443", true);
 
-}
\ No newline at end of file
+    @SetFromFlag("javaVersionRequired")
+    ConfigKey<String> JAVA_VERSION_REQUIRED = ConfigKeys.newStringConfigKey("java.version.required", "Java version required", "1.7");
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/42f4929a/software/base/src/test/java/brooklyn/entity/java/JavaSoftwareProcessSshDriverIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/base/src/test/java/brooklyn/entity/java/JavaSoftwareProcessSshDriverIntegrationTest.java b/software/base/src/test/java/brooklyn/entity/java/JavaSoftwareProcessSshDriverIntegrationTest.java
index 291ae6c..021e2ac 100644
--- a/software/base/src/test/java/brooklyn/entity/java/JavaSoftwareProcessSshDriverIntegrationTest.java
+++ b/software/base/src/test/java/brooklyn/entity/java/JavaSoftwareProcessSshDriverIntegrationTest.java
@@ -29,6 +29,9 @@ import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableList;
+
 import brooklyn.entity.basic.ApplicationBuilder;
 import brooklyn.entity.basic.BrooklynConfigKeys;
 import brooklyn.entity.basic.Entities;
@@ -48,9 +51,6 @@ import brooklyn.util.collections.MutableMap;
 import brooklyn.util.os.Os;
 import brooklyn.util.text.Strings;
 
-import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableList;
-
 public class JavaSoftwareProcessSshDriverIntegrationTest {
 
     private static final long TIMEOUT_MS = 10 * 1000;
@@ -76,7 +76,7 @@ public class JavaSoftwareProcessSshDriverIntegrationTest {
     public void setup() {
         setup(new LocalManagementContext());
     }
-    
+
     protected void setup(ManagementContext mgmt) {
         app = ApplicationBuilder.newManagedApp(TestApplication.class, mgmt);
         localhost = mgmt.getLocationManager().createLocation(
@@ -96,7 +96,7 @@ public class JavaSoftwareProcessSshDriverIntegrationTest {
             public void run() {
                 assertTrue(entity.getAttribute(SoftwareProcess.SERVICE_UP));
             }});
-        
+
         entity.stop();
         assertFalse(entity.getAttribute(SoftwareProcess.SERVICE_UP));
     }
@@ -106,7 +106,7 @@ public class JavaSoftwareProcessSshDriverIntegrationTest {
         SshMachineLocation sshLocation = app.getManagementContext().getLocationManager().createLocation(
                 LocationSpec.create(SshMachineLocation.class).configure("address", "localhost"));
         JavaSoftwareProcessSshDriver driver = new ConcreteJavaSoftwareProcessSshDriver(app, sshLocation);
-        Optional<String> version = driver.getCurrentJavaVersion();
+        Optional<String> version = driver.getInstalledJavaVersion();
         assertNotNull(version);
         assertTrue(version.isPresent());
         LOG.info("{}.testGetJavaVersion found: {} on localhost", getClass(), version.get());
@@ -119,11 +119,11 @@ public class JavaSoftwareProcessSshDriverIntegrationTest {
         LocalManagementContext mgmt = new LocalManagementContext();
         mgmt.getBrooklynProperties().put(BrooklynConfigKeys.ONBOX_BASE_DIR, dir);
         setup(mgmt);
-        
+
         doTestSpecifiedDirectory(dir, dir);
         Os.deleteRecursively(dir);
     }
-    
+
     @Test(groups = "Integration")
     public void testStartsInAppSpecifiedDirectoryUnderHome() {
         String dir = Os.mergePathsUnix("~/.brooklyn-test-"+Strings.makeRandomId(4));
@@ -134,7 +134,7 @@ public class JavaSoftwareProcessSshDriverIntegrationTest {
             Os.deleteRecursively(dir);
         }
     }
-    
+
     @Test(groups = "Integration")
     public void testStartsInDifferentRunAndInstallSpecifiedDirectories() {
         String dir1 = Os.mergePathsUnix(Os.tmp(), "/brooklyn-test-"+Strings.makeRandomId(4));
@@ -145,7 +145,7 @@ public class JavaSoftwareProcessSshDriverIntegrationTest {
         Os.deleteRecursively(dir1);
         Os.deleteRecursively(dir2);
     }
-    
+
     @Test(groups = "Integration")
     public void testStartsInLegacySpecifiedDirectory() {
         String dir1 = Os.mergePathsUnix(Os.tmp(), "/brooklyn-test-"+Strings.makeRandomId(4));
@@ -155,33 +155,33 @@ public class JavaSoftwareProcessSshDriverIntegrationTest {
         mgmt.getBrooklynProperties().put("brooklyn.dirs.install", dir1);
         mgmt.getBrooklynProperties().put("brooklyn.dirs.run", dir2);
         setup(mgmt);
-        
+
         app.setConfig(BrooklynConfigKeys.RUN_DIR, dir2);
         doTestSpecifiedDirectory(dir1, dir2);
         Os.deleteRecursively(dir1);
         Os.deleteRecursively(dir2);
     }
-    
+
     protected void doTestSpecifiedDirectory(final String installDirPrefix, final String runDirPrefix) {
         final MyEntity entity = app.createAndManageChild(EntitySpec.create(MyEntity.class));
         app.start(ImmutableList.of(localhost));
         Asserts.succeedsEventually(MutableMap.of("timeout", TIMEOUT_MS), new Runnable() {
             public void run() {
                 assertTrue(entity.getAttribute(SoftwareProcess.SERVICE_UP));
-                
+
                 String installDir = entity.getAttribute(SoftwareProcess.INSTALL_DIR);
                 Assert.assertNotNull(installDir);
-                
+
                 String runDir = entity.getAttribute(SoftwareProcess.RUN_DIR);
                 Assert.assertNotNull(runDir);
             }});
-        
+
         String installDir = entity.getAttribute(SoftwareProcess.INSTALL_DIR);
         String runDir = entity.getAttribute(SoftwareProcess.RUN_DIR);
         LOG.info("dirs for " + app + " are: install=" + installDir + ", run=" + runDir);
         assertTrue(installDir.startsWith(Os.tidyPath(installDirPrefix)), "INSTALL_DIR is "+installDir+", does not start with expected prefix "+installDirPrefix);
         assertTrue(runDir.startsWith(Os.tidyPath(runDirPrefix)), "RUN_DIR is "+runDir+", does not start with expected prefix "+runDirPrefix);
-        
+
         entity.stop();
         assertFalse(entity.getAttribute(SoftwareProcess.SERVICE_UP));
     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/42f4929a/software/nosql/src/main/java/brooklyn/entity/nosql/cassandra/CassandraNodeSshDriver.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/main/java/brooklyn/entity/nosql/cassandra/CassandraNodeSshDriver.java b/software/nosql/src/main/java/brooklyn/entity/nosql/cassandra/CassandraNodeSshDriver.java
index 9a54c8a..44651ba 100644
--- a/software/nosql/src/main/java/brooklyn/entity/nosql/cassandra/CassandraNodeSshDriver.java
+++ b/software/nosql/src/main/java/brooklyn/entity/nosql/cassandra/CassandraNodeSshDriver.java
@@ -30,6 +30,10 @@ import java.util.Set;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+
 import brooklyn.entity.Entity;
 import brooklyn.entity.basic.Attributes;
 import brooklyn.entity.basic.Entities;
@@ -61,10 +65,6 @@ import brooklyn.util.text.TemplateProcessor;
 import brooklyn.util.time.Duration;
 import brooklyn.util.time.Time;
 
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-
 /**
  * Start a {@link CassandraNode} in a {@link Location} accessible over ssh.
  */
@@ -112,20 +112,20 @@ public class CassandraNodeSshDriver extends JavaSoftwareProcessSshDriver impleme
     public String getCassandraRackdcConfigFileName() { return entity.getConfig(CassandraNode.CASSANDRA_RACKDC_CONFIG_FILE_NAME); }
 
     public String getMirrorUrl() { return entity.getConfig(CassandraNode.MIRROR_URL); }
-    
+
     protected String getDefaultUnpackedDirectoryName() {
         return "apache-cassandra-"+getVersion();
     }
-    
+
     protected boolean isV2() {
         String version = getVersion();
         return version.startsWith("2.");
     }
-    
+
     @Override
     public boolean installJava() {
         if (isV2()) {
-            return checkForAndInstallJava7or8();
+            return checkForAndInstallJava("1.8");
         } else {
             return super.installJava();
         }
@@ -186,8 +186,8 @@ public class CassandraNodeSshDriver extends JavaSoftwareProcessSshDriver impleme
                 .add("mkdir -p brooklyn_commands")
                 .add(String.format("sed -i.bk 's/log4j.appender.R.File=.*/log4j.appender.R.File=%s/g' %s/conf/log4j-server.properties", logFileEscaped, getRunDir()))
                 .add(String.format("sed -i.bk '/JMX_PORT/d' %s/conf/cassandra-env.sh", getRunDir()))
-                // Script sets 180k on Linux which gives Java error:  The stack size specified is too small, Specify at least 228k 
-                .add(String.format("sed -i.bk 's/-Xss180k/-Xss280k/g' %s/conf/cassandra-env.sh", getRunDir())); 
+                // Script sets 180k on Linux which gives Java error:  The stack size specified is too small, Specify at least 228k
+                .add(String.format("sed -i.bk 's/-Xss180k/-Xss280k/g' %s/conf/cassandra-env.sh", getRunDir()));
 
         newScript(CUSTOMIZING)
                 .body.append(commands.build())
@@ -224,7 +224,7 @@ public class CassandraNodeSshDriver extends JavaSoftwareProcessSshDriver impleme
     protected void customizeInitialSeeds() {
         if (entity.getConfig(CassandraNode.INITIAL_SEEDS)==null) {
             if (isClustered()) {
-                entity.setConfig(CassandraNode.INITIAL_SEEDS, 
+                entity.setConfig(CassandraNode.INITIAL_SEEDS,
                     DependentConfiguration.attributeWhenReady(entity.getParent(), CassandraDatacenter.CURRENT_SEEDS));
             } else {
                 entity.setConfig(CassandraNode.INITIAL_SEEDS, MutableSet.<Entity>of(entity));
@@ -290,7 +290,7 @@ public class CassandraNodeSshDriver extends JavaSoftwareProcessSshDriver impleme
                     }
                 }
             } while (true);
-            
+
             // TODO should look at last start time... but instead we always wait
             CassandraDatacenter.DELAY_BETWEEN_STARTS.countdownTimer().waitForExpiryUnchecked();
         }
@@ -307,7 +307,7 @@ public class CassandraNodeSshDriver extends JavaSoftwareProcessSshDriver impleme
                     .execute();
             if (!isClustered()) {
                 InputStream creationScript = DatastoreMixins.getDatabaseCreationScript(entity);
-                if (creationScript!=null) { 
+                if (creationScript!=null) {
                     Tasks.setBlockingDetails("Pausing to ensure Cassandra (singleton) has started before running creation script");
                     Time.sleep(Duration.seconds(20));
                     Tasks.resetBlockingDetails();
@@ -341,7 +341,7 @@ public class CassandraNodeSshDriver extends JavaSoftwareProcessSshDriver impleme
         }
         return result;
     }
-    
+
     protected String launchEssentialCommand() {
         if (isV2()) {
             return String.format("./bin/cassandra -p %s > ./cassandra-console.log 2>&1", getPidFile());
@@ -372,7 +372,7 @@ public class CassandraNodeSshDriver extends JavaSoftwareProcessSshDriver impleme
                 .put("cassandra.config", getCassandraConfigFileName())
                 .build();
     }
-    
+
     @Override
     public Map<String, String> getShellEnvironment() {
         return MutableMap.<String, String>builder()
@@ -416,5 +416,5 @@ public class CassandraNodeSshDriver extends JavaSoftwareProcessSshDriver impleme
     public String getResolvedAddress(String hostname) {
         return resolvedAddressCache.or(BrooklynAccessUtils.resolvedAddressSupplier(getEntity(), getMachine(), hostname));
     }
-    
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/42f4929a/software/nosql/src/test/java/brooklyn/entity/nosql/riak/RiakNodeIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/test/java/brooklyn/entity/nosql/riak/RiakNodeIntegrationTest.java b/software/nosql/src/test/java/brooklyn/entity/nosql/riak/RiakNodeIntegrationTest.java
index 1b92e25..002739c 100644
--- a/software/nosql/src/test/java/brooklyn/entity/nosql/riak/RiakNodeIntegrationTest.java
+++ b/software/nosql/src/test/java/brooklyn/entity/nosql/riak/RiakNodeIntegrationTest.java
@@ -24,6 +24,8 @@ import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import com.google.common.collect.ImmutableList;
+
 import brooklyn.entity.basic.Entities;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.entity.trait.Startable;
@@ -31,8 +33,6 @@ import brooklyn.location.basic.LocalhostMachineProvisioningLocation;
 import brooklyn.test.EntityTestUtils;
 import brooklyn.test.entity.TestApplication;
 
-import com.google.common.collect.ImmutableList;
-
 public class RiakNodeIntegrationTest {
 
     private TestApplication app;
@@ -52,7 +52,8 @@ public class RiakNodeIntegrationTest {
 
     @Test(groups = "Integration")
     public void testCanStartAndStop() throws Exception {
-        RiakNode entity = app.createAndManageChild(EntitySpec.create(RiakNode.class));
+        RiakNode entity = app.createAndManageChild(EntitySpec.create(RiakNode.class)
+                .configure(RiakNode.SUGGESTED_VERSION, "2.1.1"));
         app.start(ImmutableList.of(localhostProvisioningLocation));
 
         EntityTestUtils.assertAttributeEqualsEventually(entity, Startable.SERVICE_UP, true);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/42f4929a/software/nosql/src/test/java/brooklyn/entity/nosql/riak/RiakNodeSoftlayerLiveTest.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/test/java/brooklyn/entity/nosql/riak/RiakNodeSoftlayerLiveTest.java b/software/nosql/src/test/java/brooklyn/entity/nosql/riak/RiakNodeSoftlayerLiveTest.java
index 3ddd4b8..123ef7f 100644
--- a/software/nosql/src/test/java/brooklyn/entity/nosql/riak/RiakNodeSoftlayerLiveTest.java
+++ b/software/nosql/src/test/java/brooklyn/entity/nosql/riak/RiakNodeSoftlayerLiveTest.java
@@ -18,12 +18,14 @@
  */
 package brooklyn.entity.nosql.riak;
 
+import org.testng.annotations.BeforeMethod;
+
+import com.google.common.collect.ImmutableList;
+
 import brooklyn.entity.AbstractSoftlayerLiveTest;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.location.Location;
 import brooklyn.test.EntityTestUtils;
-import com.google.common.collect.ImmutableList;
-import org.testng.annotations.BeforeMethod;
 
 public class RiakNodeSoftlayerLiveTest extends AbstractSoftlayerLiveTest {
 
@@ -34,7 +36,8 @@ public class RiakNodeSoftlayerLiveTest extends AbstractSoftlayerLiveTest {
 
     @Override
     protected void doTest(Location loc) throws Exception {
-        RiakNode entity = app.createAndManageChild(EntitySpec.create(RiakNode.class));
+        RiakNode entity = app.createAndManageChild(EntitySpec.create(RiakNode.class)
+                .configure(RiakNode.SUGGESTED_VERSION, "2.1.1"));
         app.start(ImmutableList.of(loc));
 
         EntityTestUtils.assertAttributeEqualsEventually(entity, RiakNode.SERVICE_UP, true);


[4/6] incubator-brooklyn git commit: This closes #619

Posted by sj...@apache.org.
This closes #619


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

Branch: refs/heads/master
Commit: 2bc7193b16f1e724564efa628c703cfd5049e835
Parents: 7066d94 42f4929
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Authored: Fri Jun 5 14:50:33 2015 +0100
Committer: Sam Corbett <sa...@cloudsoftcorp.com>
Committed: Fri Jun 5 14:50:33 2015 +0100

----------------------------------------------------------------------
 .../basic/AbstractSoftwareProcessSshDriver.java |  84 +++++------
 .../java/JavaSoftwareProcessSshDriver.java      | 139 ++++++++-----------
 .../java/brooklyn/entity/java/UsesJava.java     |  18 ++-
 ...SoftwareProcessSshDriverIntegrationTest.java |  32 ++---
 .../nosql/cassandra/CassandraNodeSshDriver.java |  32 ++---
 .../nosql/riak/RiakNodeIntegrationTest.java     |   7 +-
 .../nosql/riak/RiakNodeSoftlayerLiveTest.java   |   9 +-
 7 files changed, 143 insertions(+), 178 deletions(-)
----------------------------------------------------------------------



[6/6] incubator-brooklyn git commit: This closes #680

Posted by sj...@apache.org.
This closes #680


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

Branch: refs/heads/master
Commit: 1a281938475b15a7e95016dc0aa15caa7e592787
Parents: 87b2903 b07d256
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Authored: Fri Jun 5 15:02:32 2015 +0100
Committer: Sam Corbett <sa...@cloudsoftcorp.com>
Committed: Fri Jun 5 15:02:32 2015 +0100

----------------------------------------------------------------------
 core/src/test/java/brooklyn/util/BrooklynMavenArtifactsTest.java | 2 --
 1 file changed, 2 deletions(-)
----------------------------------------------------------------------



[3/6] incubator-brooklyn git commit: Removes unnecessary sleep and logging from testBadExampleWar

Posted by sj...@apache.org.
Removes unnecessary sleep and logging from testBadExampleWar


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

Branch: refs/heads/master
Commit: b07d256c8a78e236dc1a52efdc0da2b564a70a57
Parents: 7066d94
Author: Martin Harris <gi...@nakomis.com>
Authored: Fri Jun 5 12:35:34 2015 +0530
Committer: Martin Harris <gi...@nakomis.com>
Committed: Fri Jun 5 12:35:34 2015 +0530

----------------------------------------------------------------------
 core/src/test/java/brooklyn/util/BrooklynMavenArtifactsTest.java | 2 --
 1 file changed, 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/b07d256c/core/src/test/java/brooklyn/util/BrooklynMavenArtifactsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/util/BrooklynMavenArtifactsTest.java b/core/src/test/java/brooklyn/util/BrooklynMavenArtifactsTest.java
index d1f0ef4..0fcfdf7 100644
--- a/core/src/test/java/brooklyn/util/BrooklynMavenArtifactsTest.java
+++ b/core/src/test/java/brooklyn/util/BrooklynMavenArtifactsTest.java
@@ -52,8 +52,6 @@ public class BrooklynMavenArtifactsTest {
     @Test(groups="Integration")
     // runs without internet but doesn't assert what it should, and can take a long time, so integration
     public void testBadExampleWar() {
-        Time.sleep(Duration.FIVE_SECONDS);
-        log.info("boo!");
         String url = BrooklynMavenArtifacts.localUrl("example", "brooklyn-example-GOODBYE-world-sql-webapp", "war");
         Assert.assertFalse(ResourceUtils.create(this).doesUrlExist(url), "should not exist: "+url);
     }


[5/6] incubator-brooklyn git commit: This closes #679

Posted by sj...@apache.org.
This closes #679


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

Branch: refs/heads/master
Commit: 87b29039381b487f269231257f5fe14bf2005994
Parents: 2bc7193 223c391
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Authored: Fri Jun 5 14:55:48 2015 +0100
Committer: Sam Corbett <sa...@cloudsoftcorp.com>
Committed: Fri Jun 5 14:55:48 2015 +0100

----------------------------------------------------------------------
 .../main/java/brooklyn/util/flags/TypeCoercions.java    | 12 ++++++++++++
 .../java/brooklyn/util/internal/TypeCoercionsTest.java  |  6 ++++++
 2 files changed, 18 insertions(+)
----------------------------------------------------------------------



[2/6] incubator-brooklyn git commit: added type coercions for String to BigDecimal and BigInteger

Posted by sj...@apache.org.
added type coercions for String to BigDecimal and BigInteger


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

Branch: refs/heads/master
Commit: 223c3916ecbf7604eb297960e968200a8f2e4015
Parents: 5dd08aa
Author: U-VIRTUSTREAM\Michael_Sc <Mi...@T440GER1390.virtustream.local>
Authored: Wed Jun 3 17:52:43 2015 +0200
Committer: U-VIRTUSTREAM\Michael_Sc <Mi...@T440GER1390.virtustream.local>
Committed: Wed Jun 3 17:52:43 2015 +0200

----------------------------------------------------------------------
 .../main/java/brooklyn/util/flags/TypeCoercions.java    | 12 ++++++++++++
 .../java/brooklyn/util/internal/TypeCoercionsTest.java  |  6 ++++++
 2 files changed, 18 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/223c3916/core/src/main/java/brooklyn/util/flags/TypeCoercions.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/util/flags/TypeCoercions.java b/core/src/main/java/brooklyn/util/flags/TypeCoercions.java
index 48bb495..d93528a 100644
--- a/core/src/main/java/brooklyn/util/flags/TypeCoercions.java
+++ b/core/src/main/java/brooklyn/util/flags/TypeCoercions.java
@@ -665,12 +665,24 @@ public class TypeCoercions {
                 return input.intValue();
             }
         });
+        registerAdapter(String.class, BigDecimal.class, new Function<String,BigDecimal>() {
+            @Override
+            public BigDecimal apply(String input) {
+                return new BigDecimal(input);
+            }
+        });
         registerAdapter(Double.class, BigDecimal.class, new Function<Double,BigDecimal>() {
             @Override
             public BigDecimal apply(Double input) {
                 return BigDecimal.valueOf(input);
             }
         });
+        registerAdapter(String.class, BigInteger.class, new Function<String,BigInteger>() {
+            @Override
+            public BigInteger apply(String input) {
+                return new BigInteger(input);
+            }
+        });
         registerAdapter(Long.class, BigInteger.class, new Function<Long,BigInteger>() {
             @Override
             public BigInteger apply(Long input) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/223c3916/core/src/test/java/brooklyn/util/internal/TypeCoercionsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/util/internal/TypeCoercionsTest.java b/core/src/test/java/brooklyn/util/internal/TypeCoercionsTest.java
index 3c09e1b..9b2f6b0 100644
--- a/core/src/test/java/brooklyn/util/internal/TypeCoercionsTest.java
+++ b/core/src/test/java/brooklyn/util/internal/TypeCoercionsTest.java
@@ -151,6 +151,12 @@ public class TypeCoercionsTest {
     }
 
     @Test
+    public void testCoerceStringToBigNumber() {
+    	assertEquals(TypeCoercions.coerce("0.5", BigDecimal.class), BigDecimal.valueOf(0.5));
+    	assertEquals(TypeCoercions.coerce("1", BigInteger.class), BigInteger.valueOf(1));
+    }
+
+    @Test
     public void testCoerceStringToEnum() {
         assertEquals(TypeCoercions.coerce("STARTING", Lifecycle.class), Lifecycle.STARTING);
         assertEquals(TypeCoercions.coerce("Starting", Lifecycle.class), Lifecycle.STARTING);