Updated example after removal of deprecated EntityFactory class

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

Branch: refs/heads/master
Commit: a6a776ce168dd2d0c200e79002c0bcecf6df3a38
Parents: 138f6b3
Author: Andrew Donald Kennedy <andrew.kenn...@cloudsoftcorp.com>
Authored: Mon Aug 15 17:35:54 2016 +0100
Committer: Andrew Donald Kennedy <andrew.kenn...@cloudsoftcorp.com>
Committed: Tue Aug 16 12:34:59 2016 +0100

----------------------------------------------------------------------
 .../brooklyn/demo/GlobalWebFabricExample.java   | 41 +++++----
 .../webapp/ControlledDynamicWebAppCluster.java  |  2 +-
 .../entity/webapp/ElasticJavaWebAppService.java | 60 -------------
 .../webapp/ElasticCustomLocationTest.java       | 89 --------------------
 ...ElasticJavaWebAppServiceIntegrationTest.java | 68 ---------------
 5 files changed, 21 insertions(+), 239 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/a6a776ce/examples/global-web-fabric/src/main/java/org/apache/brooklyn/demo/GlobalWebFabricExample.java
----------------------------------------------------------------------
diff --git 
a/examples/global-web-fabric/src/main/java/org/apache/brooklyn/demo/GlobalWebFabricExample.java
 
b/examples/global-web-fabric/src/main/java/org/apache/brooklyn/demo/GlobalWebFabricExample.java
index 99faf04..9f83ca2 100644
--- 
a/examples/global-web-fabric/src/main/java/org/apache/brooklyn/demo/GlobalWebFabricExample.java
+++ 
b/examples/global-web-fabric/src/main/java/org/apache/brooklyn/demo/GlobalWebFabricExample.java
@@ -25,6 +25,11 @@ import java.util.List;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
+
 import org.apache.brooklyn.api.catalog.Catalog;
 import org.apache.brooklyn.api.catalog.CatalogConfig;
 import org.apache.brooklyn.api.entity.EntitySpec;
@@ -39,29 +44,25 @@ import 
org.apache.brooklyn.core.sensor.PortAttributeSensorAndConfigKey;
 import org.apache.brooklyn.entity.dns.geoscaling.GeoscalingDnsService;
 import org.apache.brooklyn.entity.group.DynamicRegionsFabric;
 import org.apache.brooklyn.entity.proxy.AbstractController;
-import org.apache.brooklyn.entity.webapp.ElasticJavaWebAppService;
+import org.apache.brooklyn.entity.webapp.DynamicWebAppCluster;
 import org.apache.brooklyn.entity.webapp.JavaWebAppService;
 import org.apache.brooklyn.launcher.BrooklynLauncher;
 import org.apache.brooklyn.util.CommandLineUtil;
 import org.apache.brooklyn.util.core.BrooklynMavenArtifacts;
 import org.apache.brooklyn.util.core.ResourceUtils;
 
-import com.google.common.base.Joiner;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
-
 @Catalog(name="Global Web Fabric",
-description="Deploys a WAR to multiple clusters, showing how Brooklyn fabrics 
work",
-iconUrl="classpath://brooklyn/demo/glossy-3d-blue-web-icon.png")
+        description="Deploys a WAR to multiple clusters, showing how Brooklyn 
fabrics work",
+        iconUrl="classpath://brooklyn/demo/glossy-3d-blue-web-icon.png")
 public class GlobalWebFabricExample extends AbstractApplication {
 
     public static final Logger log = 
LoggerFactory.getLogger(GlobalWebFabricExample.class);
-    
+
     static final List<String> DEFAULT_LOCATIONS = ImmutableList.of(
             "aws-ec2:eu-west-1",
             "aws-ec2:ap-southeast-1",
             "aws-ec2:us-west-1" );
-    
+
     public static final String DEFAULT_WAR_PATH = 
ResourceUtils.create(GlobalWebFabricExample.class)
         // take this war, from the classpath, or via maven if not on the 
classpath
         .firstAvailableUrl(
@@ -71,34 +72,32 @@ public class GlobalWebFabricExample extends 
AbstractApplication {
 
     @CatalogConfig(label="WAR (URL)", priority=2)
     public static final ConfigKey<String> WAR_PATH = ConfigKeys.newConfigKey(
-        "app.war", "URL to the application archive which should be deployed", 
-        DEFAULT_WAR_PATH);    
+        "app.war", "URL to the application archive which should be deployed",
+        DEFAULT_WAR_PATH);
 
     // load-balancer instances must run on some port to work with GeoDNS, port 
80 to work without special, so make that default
     // (but included here in case it runs on a different port on all machines, 
or use a range to work with multiple localhosts)
     @CatalogConfig(label="Proxy server HTTP port")
     public static final PortAttributeSensorAndConfigKey PROXY_HTTP_PORT =
         new 
PortAttributeSensorAndConfigKey(AbstractController.PROXY_HTTP_PORT, 
PortRanges.fromInteger(80));
-    
+
     @Override
     public void initApp() {
         StringConfigMap config = getManagementContext().getConfig();
-        
+
         GeoscalingDnsService geoDns = 
addChild(EntitySpec.create(GeoscalingDnsService.class)
                 .displayName("GeoScaling DNS")
                 .configure("username", 
checkNotNull(config.getFirst("brooklyn.geoscaling.username"), "username"))
                 .configure("password", 
checkNotNull(config.getFirst("brooklyn.geoscaling.password"), "password"))
-                .configure("primaryDomainName", 
checkNotNull(config.getFirst("brooklyn.geoscaling.primaryDomain"), 
"primaryDomain")) 
+                .configure("primaryDomainName", 
checkNotNull(config.getFirst("brooklyn.geoscaling.primaryDomain"), 
"primaryDomain"))
                 .configure("smartSubdomainName", "brooklyn"));
-        
+
         DynamicRegionsFabric webFabric = 
addChild(EntitySpec.create(DynamicRegionsFabric.class)
                 .displayName("Web Fabric")
-                .configure(DynamicRegionsFabric.FACTORY, new 
ElasticJavaWebAppService.Factory())
-                
-                //specify the WAR file to use
-                .configure(JavaWebAppService.ROOT_WAR, 
Entities.getRequiredUrlConfig(this, WAR_PATH)) );
+                .configure(DynamicRegionsFabric.MEMBER_SPEC, 
EntitySpec.create(DynamicWebAppCluster.class))
+                .configure(JavaWebAppService.ROOT_WAR, 
Entities.getRequiredUrlConfig(this, WAR_PATH)));
 
-        //tell GeoDNS what to monitor
+        // tell GeoDNS what to monitor
         geoDns.setTargetEntityProvider(webFabric);
     }
 
@@ -112,7 +111,7 @@ public class GlobalWebFabricExample extends 
AbstractApplication {
                 .webconsolePort(port)
                 .locations(Arrays.asList(locations))
                 .start();
-         
+
         Entities.dumpInfo(launcher.getApplications());
     }
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/a6a776ce/software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/ControlledDynamicWebAppCluster.java
----------------------------------------------------------------------
diff --git 
a/software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/ControlledDynamicWebAppCluster.java
 
b/software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/ControlledDynamicWebAppCluster.java
index 47d2ee8..4e55780 100644
--- 
a/software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/ControlledDynamicWebAppCluster.java
+++ 
b/software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/ControlledDynamicWebAppCluster.java
@@ -60,7 +60,7 @@ import org.apache.brooklyn.util.core.flags.SetFromFlag;
 @Catalog(name="Controlled Dynamic Web-app Cluster", description="A cluster of 
load-balanced web-apps, which can be dynamically re-sized")
 @ImplementedBy(ControlledDynamicWebAppClusterImpl.class)
 public interface ControlledDynamicWebAppCluster extends DynamicGroup, Entity, 
Startable, Resizable, MemberReplaceable,
-        Group, ElasticJavaWebAppService, 
JavaWebAppService.CanDeployAndUndeploy, JavaWebAppService.CanRedeployAll {
+        Group, JavaWebAppService, JavaWebAppService.CanDeployAndUndeploy, 
JavaWebAppService.CanRedeployAll {
     
     @SetFromFlag("initialSize")
     public static ConfigKey<Integer> INITIAL_SIZE = 
ConfigKeys.newConfigKeyWithDefault(Cluster.INITIAL_SIZE, 1);

http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/a6a776ce/software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/ElasticJavaWebAppService.java
----------------------------------------------------------------------
diff --git 
a/software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/ElasticJavaWebAppService.java
 
b/software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/ElasticJavaWebAppService.java
deleted file mode 100644
index 53670a7..0000000
--- 
a/software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/ElasticJavaWebAppService.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.entity.webapp;
-
-import java.util.Map;
-
-import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.api.entity.EntitySpec;
-import org.apache.brooklyn.api.location.Location;
-import org.apache.brooklyn.api.location.MachineProvisioningLocation;
-import 
org.apache.brooklyn.core.entity.factory.AbstractConfigurableEntityFactory;
-import org.apache.brooklyn.core.entity.factory.ConfigurableEntityFactory;
-import org.apache.brooklyn.core.entity.factory.EntityFactoryForLocation;
-import org.apache.brooklyn.core.entity.trait.Startable;
-
-public interface ElasticJavaWebAppService extends JavaWebAppService, Startable 
{
-
-    public interface ElasticJavaWebAppServiceAwareLocation {
-        ConfigurableEntityFactory<ElasticJavaWebAppService> 
newWebClusterFactory();
-    }
-
-    /** @deprecated since 0.7.0 use {@link EntitySpec} */
-    @Deprecated
-    public static class Factory extends 
AbstractConfigurableEntityFactory<ElasticJavaWebAppService>
-    implements EntityFactoryForLocation<ElasticJavaWebAppService> {
-
-        private static final long serialVersionUID = 6654647949712073832L;
-
-        public ElasticJavaWebAppService 
newEntity2(@SuppressWarnings("rawtypes") Map flags, Entity parent) {
-            return new ControlledDynamicWebAppClusterImpl(flags, parent);
-        }
-
-        public ConfigurableEntityFactory<ElasticJavaWebAppService> 
newFactoryForLocation(Location l) {
-            if (l instanceof ElasticJavaWebAppServiceAwareLocation) {
-                return 
((ElasticJavaWebAppServiceAwareLocation)l).newWebClusterFactory().configure(config);
-            }
-            //optional, fail fast if location not supported
-            if (!(l instanceof MachineProvisioningLocation))
-                throw new UnsupportedOperationException("cannot create this 
entity in location "+l);
-            return this;
-        }
-    }
-    
-}

http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/a6a776ce/software/webapp/src/test/java/org/apache/brooklyn/entity/webapp/ElasticCustomLocationTest.java
----------------------------------------------------------------------
diff --git 
a/software/webapp/src/test/java/org/apache/brooklyn/entity/webapp/ElasticCustomLocationTest.java
 
b/software/webapp/src/test/java/org/apache/brooklyn/entity/webapp/ElasticCustomLocationTest.java
deleted file mode 100644
index 5eb8496..0000000
--- 
a/software/webapp/src/test/java/org/apache/brooklyn/entity/webapp/ElasticCustomLocationTest.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.entity.webapp;
-
-import java.util.Map;
-
-import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.core.entity.Entities;
-import org.apache.brooklyn.core.entity.factory.ApplicationBuilder;
-import org.apache.brooklyn.core.entity.factory.BasicConfigurableEntityFactory;
-import org.apache.brooklyn.core.entity.factory.ConfigurableEntityFactory;
-import org.apache.brooklyn.core.location.SimulatedLocation;
-import org.apache.brooklyn.core.test.entity.TestApplication;
-import org.apache.brooklyn.core.test.entity.TestEntityImpl;
-import 
org.apache.brooklyn.entity.webapp.ElasticJavaWebAppService.ElasticJavaWebAppServiceAwareLocation;
-import org.apache.brooklyn.util.collections.MutableMap;
-import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableList;
-
-public class ElasticCustomLocationTest {
-
-    public static class MockWebServiceLocation extends SimulatedLocation 
implements ElasticJavaWebAppServiceAwareLocation {
-        public MockWebServiceLocation() {
-        }
-        
-        @Override
-        public ConfigurableEntityFactory<ElasticJavaWebAppService> 
newWebClusterFactory() {
-            return new BasicConfigurableEntityFactory(MockWebService.class);
-        }
-    }
-    
-    public static class MockWebService extends TestEntityImpl implements 
ElasticJavaWebAppService {
-        public MockWebService() {
-        } 
-        // TODO Used by asicConfigurableEntityFactory.newEntity2, via 
MockWebServiceLocation.newWebClusterFactory
-        public MockWebService(Map flags, Entity parent) {
-            super(flags, parent);
-        } 
-    }
-
-    private TestApplication app;
-    
-    @BeforeMethod(alwaysRun=true)
-    public void setUp() throws Exception {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
-    }
-
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() throws Exception {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-
-    @Test
-    public void testElasticClusterCreatesTestEntity() {
-        MockWebServiceLocation l = new MockWebServiceLocation();
-        app.config().set(MockWebService.ROOT_WAR, "WAR0");
-        app.config().set(MockWebService.NAMED_WARS, 
ImmutableList.of("ignore://WARn"));
-        
-        ElasticJavaWebAppService svc = 
-            new 
ElasticJavaWebAppService.Factory().newFactoryForLocation(l).newEntity(MutableMap.of("war",
 "WAR1"), app);
-        Entities.manage(svc);
-        
-        Assert.assertTrue(svc instanceof MockWebService, "expected 
MockWebService, got "+svc);
-        //check config has been set correctly, where overridden, and where 
inherited
-        Assert.assertEquals(svc.getConfig(MockWebService.ROOT_WAR), "WAR1");
-        Assert.assertEquals(svc.getConfig(MockWebService.NAMED_WARS), 
ImmutableList.of("ignore://WARn"));
-    }
-    
-}

http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/a6a776ce/software/webapp/src/test/java/org/apache/brooklyn/entity/webapp/ElasticJavaWebAppServiceIntegrationTest.java
----------------------------------------------------------------------
diff --git 
a/software/webapp/src/test/java/org/apache/brooklyn/entity/webapp/ElasticJavaWebAppServiceIntegrationTest.java
 
b/software/webapp/src/test/java/org/apache/brooklyn/entity/webapp/ElasticJavaWebAppServiceIntegrationTest.java
deleted file mode 100644
index ee76cb8..0000000
--- 
a/software/webapp/src/test/java/org/apache/brooklyn/entity/webapp/ElasticJavaWebAppServiceIntegrationTest.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.entity.webapp;
-
-import org.apache.brooklyn.test.HttpTestUtils;
-import org.apache.brooklyn.test.support.TestResourceUnavailableException;
-import org.apache.brooklyn.util.collections.MutableMap;
-import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-import org.apache.brooklyn.core.entity.Entities;
-import org.apache.brooklyn.core.test.entity.TestApplication;
-import 
org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation;
-
-import com.google.common.collect.ImmutableList;
-
-public class ElasticJavaWebAppServiceIntegrationTest {
-
-    private LocalhostMachineProvisioningLocation loc;
-    private TestApplication app;
-    
-    @BeforeMethod(alwaysRun=true)
-    public void setUp() throws Exception {
-        app = TestApplication.Factory.newManagedInstanceForTests();
-        loc = app.newLocalhostProvisioningLocation();
-    }
-
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() throws Exception {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-
-    public String getTestWar() {
-        
TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), 
"/hello-world.war");
-        return "classpath://hello-world.war";
-    }
-
-    @SuppressWarnings("deprecation")
-    @Test(groups = "Integration")
-    // TODO a new approach to what ElasticJavaWebAppService.Factory does, 
giving a different entity depending on location!
-    public void testLegacyFactory() {
-        ElasticJavaWebAppService svc =
-            new 
ElasticJavaWebAppService.Factory().newEntity(MutableMap.of("war", 
getTestWar()), app);
-        Entities.manage(svc);
-        app.start(ImmutableList.of(loc));
-        
-        String url = svc.getAttribute(ElasticJavaWebAppService.ROOT_URL);
-        Assert.assertNotNull(url);
-        HttpTestUtils.assertContentEventuallyContainsText(url, "Hello");
-    }
-}

Reply via email to