brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [17/50] brooklyn-library git commit: code review cleanup of Controller so that domain=null means serve all domains
Date Mon, 01 Feb 2016 17:46:20 GMT
code review cleanup of Controller so that domain=null means serve all domains


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

Branch: refs/heads/0.4.0
Commit: 4e8721cc17ea215eed68bdaffbed40212f17f813
Parents: 8830359
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Fri Sep 28 13:39:50 2012 -0400
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Fri Sep 28 13:39:50 2012 -0400

----------------------------------------------------------------------
 .../entity/proxy/AbstractController.java        | 12 ++++--
 .../entity/proxy/nginx/NginxController.groovy   |  9 +---
 .../proxy/nginx/NginxIntegrationTest.groovy     | 43 ++++++++++++++++++++
 3 files changed, 54 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/4e8721cc/software/webapp/src/main/java/brooklyn/entity/proxy/AbstractController.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/main/java/brooklyn/entity/proxy/AbstractController.java b/software/webapp/src/main/java/brooklyn/entity/proxy/AbstractController.java
index 4b85c2c..d1e5de3 100644
--- a/software/webapp/src/main/java/brooklyn/entity/proxy/AbstractController.java
+++ b/software/webapp/src/main/java/brooklyn/entity/proxy/AbstractController.java
@@ -61,7 +61,7 @@ public abstract class AbstractController extends SoftwareProcessEntity implement
     
     @SetFromFlag("domain")
     public static final BasicAttributeSensorAndConfigKey<String> DOMAIN_NAME = new
BasicAttributeSensorAndConfigKey<String>(
-            String.class, "proxy.domainName", "Domain name that this controller responds
to", null);
+            String.class, "proxy.domainName", "Domain name that this controller responds
to, or null if it responds to all domains", null);
         
     @SetFromFlag("ssl")
     public static final BasicConfigKey<ProxySslConfig> SSL_CONFIG = 
@@ -153,6 +153,7 @@ public abstract class AbstractController extends SoftwareProcessEntity
implement
         return getAttribute(PROTOCOL);
     }
 
+    /** returns primary domain this controller responds to, or null if it responds to all
domains */
     public String getDomain() {
         return getAttribute(DOMAIN_NAME);
     }
@@ -161,6 +162,7 @@ public abstract class AbstractController extends SoftwareProcessEntity
implement
         return getAttribute(PROXY_HTTP_PORT);
     }
 
+    /** primary URL this controller serves, if one can / has been inferred */
     public String getUrl() {
         return getAttribute(ROOT_URL);
     }
@@ -176,9 +178,12 @@ public abstract class AbstractController extends SoftwareProcessEntity
implement
         return getConfig(SSL_CONFIG)!=null ? "https" : "http";
     }
     
+    /** returns URL, if it can be inferred; null otherwise */
     protected String inferUrl() {
         String protocol = checkNotNull(getProtocol(), "protocol must not be null");
-        String domain = checkNotNull(getDomain(), "domain must not be null");
+        String domain = getDomain();
+        if (domain==null) domain = getAttribute(HOSTNAME);
+        if (domain==null) return null;
         Integer port = checkNotNull(getPort(), "port must not be null");
         return protocol+"://"+domain+":"+port+"/";
     }
@@ -195,7 +200,7 @@ public abstract class AbstractController extends SoftwareProcessEntity
implement
         super.preStart();
         
         setAttribute(PROTOCOL, inferProtocol());
-        setAttribute(DOMAIN_NAME, elvis(getConfig(DOMAIN_NAME), getAttribute(HOSTNAME)));
+        setAttribute(DOMAIN_NAME);
         setAttribute(ROOT_URL, inferUrl());
         
         checkNotNull(getPortNumberSensor(), "port number sensor must not be null");
@@ -206,6 +211,7 @@ public abstract class AbstractController extends SoftwareProcessEntity
implement
         super.postStart();
         LOG.info("Adding policy {} to {} on AbstractController.start", serverPoolMemberTrackerPolicy,
this);
         addPolicy(serverPoolMemberTrackerPolicy);
+        if (getUrl()==null) setAttribute(ROOT_URL, inferUrl());
         reset();
         isActive = true;
         update();

http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/4e8721cc/software/webapp/src/main/java/brooklyn/entity/proxy/nginx/NginxController.groovy
----------------------------------------------------------------------
diff --git a/software/webapp/src/main/java/brooklyn/entity/proxy/nginx/NginxController.groovy
b/software/webapp/src/main/java/brooklyn/entity/proxy/nginx/NginxController.groovy
index d82c7c1..2e32eef 100644
--- a/software/webapp/src/main/java/brooklyn/entity/proxy/nginx/NginxController.groovy
+++ b/software/webapp/src/main/java/brooklyn/entity/proxy/nginx/NginxController.groovy
@@ -203,7 +203,7 @@ public class NginxController extends AbstractController {
         
         // If no servers, then defaults to returning 404
         // TODO Give nicer page back 
-        if (!isExclusive()) {
+        if (getDomain()!=null || serverPoolAddresses==null || serverPoolAddresses.isEmpty())
{
             config.append("  server {\n");
             config.append("    listen "+getPort()+";\n")
             config.append("    return 404;\n")
@@ -222,7 +222,7 @@ public class NginxController extends AbstractController {
             config.append("  }\n")
             config.append("  server {\n");
             config.append("    listen "+getPort()+";\n")
-            if (!isExclusive())
+            if (getDomain()!=null)
                 config.append("    server_name "+getDomain()+";\n")
             config.append("    location / {\n");
             config.append("      proxy_pass "+(globalSslConfig && globalSslConfig.targetIsSsl
? "https" : "http")+"://"+getId()+";\n");
@@ -364,9 +364,4 @@ public class NginxController extends AbstractController {
         }
     }
 
-    /** true iff this nginx server is routing for exactly one domain with no mappings, with
downstream servers; 
-     * in such cases, forward all inbound traffic */    
-    protected boolean isExclusive() {
-        return serverPoolAddresses && !findUrlMappings();
-    }
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/4e8721cc/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxIntegrationTest.groovy
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxIntegrationTest.groovy
b/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxIntegrationTest.groovy
index 5dd7eda..e2a1a44 100644
--- a/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxIntegrationTest.groovy
+++ b/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxIntegrationTest.groovy
@@ -110,6 +110,49 @@ public class NginxIntegrationTest {
         }
     }
     
+    /**
+     * Test that the Nginx proxy works, serving all domains, if no domain is set
+     */
+    @Test(groups = "Integration")
+    public void testDomainless() {
+        def template = { Map properties -> new JBoss7Server(properties) }
+        URL war = getClass().getClassLoader().getResource("hello-world.war")
+        Preconditions.checkState war != null, "Unable to locate resource $war"
+        
+        serverPool = new DynamicCluster(owner:app, factory:template, initialSize:1)
+        serverPool.setConfig(JavaWebAppService.ROOT_WAR, war.path)
+        
+        nginx = new NginxController([
+                "owner" : app,
+                "serverPool" : serverPool,
+                "portNumberSensor" : WebAppService.HTTP_PORT,
+            ])
+        
+        app.start([ new LocalhostMachineProvisioningLocation() ])
+        
+        // App-servers and nginx has started
+        assertAttributeEventually(serverPool, SoftwareProcessEntity.SERVICE_UP, true);
+        serverPool.members.each {
+            assertAttributeEventually(it, SoftwareProcessEntity.SERVICE_UP, true);
+        }
+        assertAttributeEventually(nginx, SoftwareProcessEntity.SERVICE_UP, true);
+
+        // URLs reachable
+        assertUrlStatusCodeEventually(nginx.getAttribute(NginxController.ROOT_URL), 200);
+        serverPool.members.each {
+            assertUrlStatusCodeEventually(it.getAttribute(WebAppService.ROOT_URL), 200);
+        }
+
+        app.stop();
+
+        // Services have stopped
+        assertFalse(nginx.getAttribute(SoftwareProcessEntity.SERVICE_UP));
+        assertFalse(serverPool.getAttribute(SoftwareProcessEntity.SERVICE_UP));
+        serverPool.members.each {
+            assertFalse(it.getAttribute(SoftwareProcessEntity.SERVICE_UP));
+        }
+    }
+    
     @Test(groups = "Integration")
     public void testTwoNginxesGetDifferentPorts() {
         def serverFactory = { throw new UnsupportedOperationException(); }


Mime
View raw message