brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [09/18] incubator-brooklyn git commit: Adds ControlledDynamicWebAppCluster.CONTROLLED_GROUP
Date Tue, 11 Aug 2015 20:42:47 GMT
Adds ControlledDynamicWebAppCluster.CONTROLLED_GROUP


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

Branch: refs/heads/master
Commit: 70dfb20d2c88f82061efca1b8e2bc9349ee170bb
Parents: f2e3291
Author: Aled Sage <aled.sage@gmail.com>
Authored: Mon May 25 22:25:30 2015 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Tue Aug 11 20:04:29 2015 +0100

----------------------------------------------------------------------
 .../webapp/ControlledDynamicWebAppCluster.java  |  5 ++++
 .../ControlledDynamicWebAppClusterImpl.java     | 18 ++++++++++++++-
 .../ControlledDynamicWebAppClusterTest.java     | 24 ++++++++++++++++++++
 .../test/entity/TestJavaWebAppEntity.java       |  3 ++-
 4 files changed, 48 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/70dfb20d/software/webapp/src/main/java/brooklyn/entity/webapp/ControlledDynamicWebAppCluster.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/main/java/brooklyn/entity/webapp/ControlledDynamicWebAppCluster.java
b/software/webapp/src/main/java/brooklyn/entity/webapp/ControlledDynamicWebAppCluster.java
index c747efe..7da9e11 100644
--- a/software/webapp/src/main/java/brooklyn/entity/webapp/ControlledDynamicWebAppCluster.java
+++ b/software/webapp/src/main/java/brooklyn/entity/webapp/ControlledDynamicWebAppCluster.java
@@ -69,6 +69,10 @@ public interface ControlledDynamicWebAppCluster extends DynamicGroup, Entity,
St
     public static BasicAttributeSensorAndConfigKey<LoadBalancer> CONTROLLER = new BasicAttributeSensorAndConfigKey<LoadBalancer>(
         LoadBalancer.class, "controlleddynamicwebappcluster.controller", "Controller for
the cluster; if null a default will created (using controllerSpec)");
 
+    @SetFromFlag("controlledGroup")
+    public static BasicAttributeSensorAndConfigKey<Group> CONTROLLED_GROUP = new BasicAttributeSensorAndConfigKey<Group>(
+        Group.class, "controlleddynamicwebappcluster.controlledgroup", "The group of web
servers that the controller should point at; if null, will use the CLUSTER");
+
     @SuppressWarnings({ "unchecked", "rawtypes" })
     @SetFromFlag("controllerSpec")
     public static BasicAttributeSensorAndConfigKey<EntitySpec<? extends LoadBalancer>>
CONTROLLER_SPEC = new BasicAttributeSensorAndConfigKey(
@@ -105,4 +109,5 @@ public interface ControlledDynamicWebAppCluster extends DynamicGroup,
Entity, St
     
     public DynamicWebAppCluster getCluster();
     
+    public Group getControlledGroup();
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/70dfb20d/software/webapp/src/main/java/brooklyn/entity/webapp/ControlledDynamicWebAppClusterImpl.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/main/java/brooklyn/entity/webapp/ControlledDynamicWebAppClusterImpl.java
b/software/webapp/src/main/java/brooklyn/entity/webapp/ControlledDynamicWebAppClusterImpl.java
index 9a4c212..d02d292 100644
--- a/software/webapp/src/main/java/brooklyn/entity/webapp/ControlledDynamicWebAppClusterImpl.java
+++ b/software/webapp/src/main/java/brooklyn/entity/webapp/ControlledDynamicWebAppClusterImpl.java
@@ -27,6 +27,7 @@ import org.slf4j.LoggerFactory;
 
 import brooklyn.enricher.Enrichers;
 import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
 import brooklyn.entity.basic.Attributes;
 import brooklyn.entity.basic.ConfigurableEntityFactory;
 import brooklyn.entity.basic.DynamicGroupImpl;
@@ -83,6 +84,7 @@ public class ControlledDynamicWebAppClusterImpl extends DynamicGroupImpl
impleme
         ConfigToAttributes.apply(this, CONTROLLER);
         ConfigToAttributes.apply(this, CONTROLLER_SPEC);
         ConfigToAttributes.apply(this, WEB_CLUSTER_SPEC);
+        ConfigToAttributes.apply(this, CONTROLLED_GROUP);
         
         ConfigurableEntityFactory<? extends WebAppService> webServerFactory = getAttribute(FACTORY);
         EntitySpec<? extends WebAppService> webServerSpec = getAttribute(MEMBER_SPEC);
@@ -136,6 +138,15 @@ public class ControlledDynamicWebAppClusterImpl extends DynamicGroupImpl
impleme
             setAttribute(CONTROLLER, controller);
         }
         
+        Group controlledGroup = getAttribute(CONTROLLED_GROUP);
+        if (controlledGroup == null) {
+            log.debug("using cluster as controlledGroup for {}", this);
+            controlledGroup = cluster;
+            setAttribute(CONTROLLED_GROUP, cluster);
+        } else {
+            log.debug("using custom controlledGroup {} for {}", controlledGroup, this);
+        }
+        
         doBind();
     }
 
@@ -183,6 +194,11 @@ public class ControlledDynamicWebAppClusterImpl extends DynamicGroupImpl
impleme
     }
     
     @Override
+    public Group getControlledGroup() {
+        return getAttribute(CONTROLLED_GROUP);
+    }
+    
+    @Override
     public void start(Collection<? extends Location> locations) {
         ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING);
 
@@ -195,7 +211,7 @@ public class ControlledDynamicWebAppClusterImpl extends DynamicGroupImpl
impleme
             addLocations(locations);
 
             LoadBalancer loadBalancer = getController();
-            loadBalancer.bind(MutableMap.of("serverPool", getCluster()));
+            loadBalancer.bind(MutableMap.of("serverPool", getControlledGroup()));
 
             List<Entity> childrenToStart = MutableList.<Entity>of(getCluster());
             // Set controller as child of cluster, if it does not already have a parent

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/70dfb20d/software/webapp/src/test/java/brooklyn/entity/webapp/ControlledDynamicWebAppClusterTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/entity/webapp/ControlledDynamicWebAppClusterTest.java
b/software/webapp/src/test/java/brooklyn/entity/webapp/ControlledDynamicWebAppClusterTest.java
index e98d094..d841f1b 100644
--- a/software/webapp/src/test/java/brooklyn/entity/webapp/ControlledDynamicWebAppClusterTest.java
+++ b/software/webapp/src/test/java/brooklyn/entity/webapp/ControlledDynamicWebAppClusterTest.java
@@ -30,6 +30,9 @@ import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import brooklyn.entity.BrooklynAppUnitTestSupport;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.Attributes;
+import brooklyn.entity.basic.BasicGroup;
 import brooklyn.entity.basic.Entities;
 import brooklyn.entity.basic.Lifecycle;
 import brooklyn.entity.basic.SoftwareProcess;
@@ -43,6 +46,7 @@ import brooklyn.test.Asserts;
 import brooklyn.test.entity.TestJavaWebAppEntity;
 
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 
 public class ControlledDynamicWebAppClusterTest extends BrooklynAppUnitTestSupport {
@@ -83,6 +87,26 @@ public class ControlledDynamicWebAppClusterTest extends BrooklynAppUnitTestSuppo
     }
     
     @Test
+    public void testUsesCustomControlledGroup() {
+        TestJavaWebAppEntity webServer = app.createAndManageChild(EntitySpec.create(TestJavaWebAppEntity.class));
+        webServer.setAttribute(Attributes.SUBNET_HOSTNAME, "myhostname");
+        webServer.setAttribute(Attributes.HTTP_PORT, 1234);
+        
+        TrackingAbstractController controller = app.createAndManageChild(EntitySpec.create(TrackingAbstractController.class));
+        Group controlledGroup = app.createAndManageChild(EntitySpec.create(BasicGroup.class));
+        controlledGroup.addMember(webServer);
+        
+        ControlledDynamicWebAppCluster cluster = app.createAndManageChild(EntitySpec.create(ControlledDynamicWebAppCluster.class)
+                .configure("initialSize", 0)
+                .configure(ControlledDynamicWebAppCluster.CONTROLLER, controller)
+                .configure(ControlledDynamicWebAppCluster.CONTROLLED_GROUP, controlledGroup)
+                .configure("memberSpec", EntitySpec.create(JBoss7Server.class).configure("war",
getTestWar())));
+        app.start(locs);
+
+        assertEquals(controller.getUpdates(), ImmutableList.of(ImmutableSet.of("myhostname:1234")));
+    }
+    
+    @Test
     public void testUsesCustomControllerSpec() {
         EntitySpec<TrackingAbstractController> controllerSpec = EntitySpec.create(TrackingAbstractController.class).displayName("mycustom");
         ControlledDynamicWebAppCluster cluster = app.createAndManageChild(EntitySpec.create(ControlledDynamicWebAppCluster.class)

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/70dfb20d/software/webapp/src/test/java/brooklyn/test/entity/TestJavaWebAppEntity.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/test/entity/TestJavaWebAppEntity.java
b/software/webapp/src/test/java/brooklyn/test/entity/TestJavaWebAppEntity.java
index 3fa4015..a13ac9d 100644
--- a/software/webapp/src/test/java/brooklyn/test/entity/TestJavaWebAppEntity.java
+++ b/software/webapp/src/test/java/brooklyn/test/entity/TestJavaWebAppEntity.java
@@ -28,6 +28,7 @@ import brooklyn.entity.basic.Lifecycle;
 import brooklyn.entity.basic.ServiceStateLogic;
 import brooklyn.entity.basic.SoftwareProcess;
 import brooklyn.entity.basic.SoftwareProcessDriverLifecycleEffectorTasks;
+import brooklyn.entity.basic.EntityLocal;
 import brooklyn.entity.java.VanillaJavaApp;
 import brooklyn.entity.proxying.ImplementedBy;
 import brooklyn.entity.webapp.WebAppService;
@@ -38,7 +39,7 @@ import brooklyn.util.config.ConfigBag;
  * Mock web application server entity for testing.
  */
 @ImplementedBy(TestJavaWebAppEntityImpl.class)
-public interface TestJavaWebAppEntity extends VanillaJavaApp, WebAppService {
+public interface TestJavaWebAppEntity extends VanillaJavaApp, WebAppService, EntityLocal
{
 
     /**
      * Injects the test entity's customised lifecycle tasks.


Mime
View raw message