brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rich...@apache.org
Subject [19/26] git commit: Adds --publicAddress flag to Main, used in Launcher and WebServer
Date Tue, 10 Jun 2014 02:25:40 GMT
Adds --publicAddress flag to Main, used in Launcher and WebServer


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

Branch: refs/heads/master
Commit: 2217c76be51b5032dab4874dae07738b5a3de247
Parents: b522e59
Author: Sam Corbett <sam.corbett@cloudsoftcorp.com>
Authored: Mon Jun 9 14:48:59 2014 +0100
Committer: Sam Corbett <sam.corbett@cloudsoftcorp.com>
Committed: Mon Jun 9 14:48:59 2014 +0100

----------------------------------------------------------------------
 usage/cli/src/main/java/brooklyn/cli/Main.java  | 16 ++++++++++
 .../brooklyn/launcher/BrooklynLauncher.java     | 15 ++++++++-
 .../brooklyn/launcher/BrooklynWebServer.java    | 33 ++++++++++++++------
 3 files changed, 53 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2217c76b/usage/cli/src/main/java/brooklyn/cli/Main.java
----------------------------------------------------------------------
diff --git a/usage/cli/src/main/java/brooklyn/cli/Main.java b/usage/cli/src/main/java/brooklyn/cli/Main.java
index d9069a4..4c9b359 100644
--- a/usage/cli/src/main/java/brooklyn/cli/Main.java
+++ b/usage/cli/src/main/java/brooklyn/cli/Main.java
@@ -15,6 +15,8 @@ import java.io.IOException;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.net.InetAddress;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -56,6 +58,7 @@ import com.google.common.annotations.Beta;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Objects;
 import com.google.common.base.Objects.ToStringHelper;
+import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableList;
 
 /**
@@ -219,6 +222,10 @@ public class Main {
                 description = "Specifies the IP address of the NIC to bind the Brooklyn Management
Console to")
         public String bindAddress = null;
 
+        @Option(name = { "-pa", "--publicAddress" },
+                description = "Specifies the IP address or URL that the Brooklyn Management
Console Rest API will be available on")
+        public String publicAddress = null;
+
         @Option(name = { "--noConsoleSecurity" },
                 description = "Whether to disable security for the web console with no security
(i.e. no authentication required)")
         public Boolean noConsoleSecurity = false;
@@ -445,6 +452,15 @@ public class Main {
                 InetAddress ip = Networking.getInetAddressWithFixedName(bindAddress);
                 launcher.bindAddress(ip);
             }
+            if (Strings.isNonEmpty(publicAddress)) {
+                URI address;
+                try {
+                     address = new URI(publicAddress);
+                } catch (URISyntaxException e) {
+                    throw Throwables.propagate(e);
+                }
+                launcher.publicAddress(address);
+            }
             if (explicitManagementContext!=null) {
                 launcher.managementContext(explicitManagementContext);
             }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2217c76b/usage/launcher/src/main/java/brooklyn/launcher/BrooklynLauncher.java
----------------------------------------------------------------------
diff --git a/usage/launcher/src/main/java/brooklyn/launcher/BrooklynLauncher.java b/usage/launcher/src/main/java/brooklyn/launcher/BrooklynLauncher.java
index 3452b7f..5157d13 100644
--- a/usage/launcher/src/main/java/brooklyn/launcher/BrooklynLauncher.java
+++ b/usage/launcher/src/main/java/brooklyn/launcher/BrooklynLauncher.java
@@ -12,6 +12,7 @@ import java.io.File;
 import java.io.IOException;
 import java.io.StringReader;
 import java.net.InetAddress;
+import java.net.URI;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
@@ -101,6 +102,7 @@ public class BrooklynLauncher {
     private boolean startWebApps = true;
     private PortRange port = PortRanges.fromString("8081+");
     private InetAddress bindAddress = null;
+    private URI publicAddress = null;
     private Map<String,String> webApps = new LinkedHashMap<String,String>();
     private Map<String, ?> webconsoleFlags = Maps.newLinkedHashMap();
     private Boolean skipSecurityFilter = null;
@@ -302,7 +304,17 @@ public class BrooklynLauncher {
         this.bindAddress = bindAddress;
         return this;
     }
-    
+
+    /**
+     * Specifies the address that the management context's REST API will be available on.
Defaults
+     * to {@link #bindAddress} if it is not 0.0.0.0.
+     * @see #bindAddress(java.net.InetAddress)
+     */
+    public BrooklynLauncher publicAddress(URI publicAddress) {
+        this.publicAddress = publicAddress;
+        return this;
+    }
+
     /**
      * Specifies additional flags to be passed to {@link BrooklynWebServer}.
      */ 
@@ -423,6 +435,7 @@ public class BrooklynLauncher {
         try {
             webServer = new BrooklynWebServer(webconsoleFlags, managementContext);
             webServer.setBindAddress(bindAddress);
+            webServer.setPublicAddress(publicAddress);
             webServer.setPort(port);
             webServer.putAttributes(brooklynProperties);
             if (skipSecurityFilter != Boolean.TRUE) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2217c76b/usage/launcher/src/main/java/brooklyn/launcher/BrooklynWebServer.java
----------------------------------------------------------------------
diff --git a/usage/launcher/src/main/java/brooklyn/launcher/BrooklynWebServer.java b/usage/launcher/src/main/java/brooklyn/launcher/BrooklynWebServer.java
index bdc9803..28c588b 100644
--- a/usage/launcher/src/main/java/brooklyn/launcher/BrooklynWebServer.java
+++ b/usage/launcher/src/main/java/brooklyn/launcher/BrooklynWebServer.java
@@ -36,7 +36,7 @@ import brooklyn.location.PortRange;
 import brooklyn.location.basic.LocalhostMachineProvisioningLocation;
 import brooklyn.location.basic.PortRanges;
 import brooklyn.management.ManagementContext;
-import brooklyn.management.internal.AbstractManagementContext;
+import brooklyn.management.internal.ManagementContextInternal;
 import brooklyn.rest.BrooklynRestApi;
 import brooklyn.rest.BrooklynWebConfig;
 import brooklyn.rest.security.BrooklynPropertiesSecurityFilter;
@@ -97,7 +97,7 @@ public class BrooklynWebServer {
     protected volatile int actualPort = -1;
     /** actual NIC where this is listening; in the case of 0.0.0.0 being passed in as bindAddress,
      * this will revert to one address (such as localhost) */
-    protected InetAddress actualAddress = null; 
+    protected InetAddress actualAddress = null;
 
     @SetFromFlag
     protected String war = BROOKLYN_WAR_URL;
@@ -106,7 +106,11 @@ public class BrooklynWebServer {
      * (e.g. 0.0.0.0 if security is configured, or loopback if no security) */
     @SetFromFlag
     protected InetAddress bindAddress = null;
-    
+
+    /** The URI that this server's management context will be publically available on. */
+    @SetFromFlag
+    protected URI publicAddress = null;
+
     /**
      * map of context-prefix to file
      */
@@ -203,10 +207,11 @@ public class BrooklynWebServer {
     
     /** URL for accessing this web server (root context) */
     public String getRootUrl() {
+        String address = (publicAddress != null) ? publicAddress.toString() : getAddress().getHostName();
         if (getActualPort()>0){
             String protocol = getHttpsEnabled()?"https":"http";
-            return protocol+"://"+getAddress().getHostName()+":"+getActualPort()+"/";
-        }else{
+            return protocol+"://"+address+":"+getActualPort()+"/";
+        } else {
             return null;
         }
     }
@@ -225,13 +230,21 @@ public class BrooklynWebServer {
         return this;
     }
 
-    /** InetAddress to which server should bind; 
+    /** InetAddress to which server should bind;
      * defaults to 0.0.0.0 (although common call path is to set to 127.0.0.1 when security
is not set) */
     public BrooklynWebServer setBindAddress(InetAddress address) {
         bindAddress = address;
         return this;
     }
-    
+
+    /**
+     * Sets the public address that the server's management context's REST API will be available
on
+     */
+    public BrooklynWebServer setPublicAddress(URI address) {
+        publicAddress = address;
+        return this;
+    }
+
     /** @deprecated use setAttribute */
     public BrooklynWebServer addAttribute(String field, Object value) {
         return setAttribute(field, value);
@@ -296,7 +309,7 @@ public class BrooklynWebServer {
             actualAddress = BrooklynNetworkUtils.getLocalhostInetAddress();
             server = new Server(actualPort);
         }
-        
+
         // use a nice name in the thread pool (otherwise this is exactly the same as Server
defaults)
         QueuedThreadPool threadPool = new QueuedThreadPool();
         threadPool.setName("brooklyn-jetty-server-"+actualPort+"-"+threadPool.getName());
@@ -364,8 +377,8 @@ public class BrooklynWebServer {
         //reinit required because grails wipes our language extension bindings
         BrooklynLanguageExtensions.reinit();
 
-        if (managementContext instanceof AbstractManagementContext) {
-            ((AbstractManagementContext) managementContext).setManagementNodeUri(new URI(getRootUrl()));
+        if (managementContext instanceof ManagementContextInternal) {
+            ((ManagementContextInternal) managementContext).setManagementNodeUri(new URI(getRootUrl()));
         }
 
         log.info("Started Brooklyn console at "+getRootUrl()+", running " + war + (wars !=
null ? " and " + wars.values() : ""));


Mime
View raw message