diff --git a/.gitignore b/.gitignore deleted file mode 100644 index bec8f46..0000000 --- a/.gitignore +++ /dev/null @@ -1,26 +0,0 @@ -\#*\# -*~ -*.swp -*.swo -.DS_Store - -*.class - -target/ -test-output/ - -.project -.classpath -.settings/ -.metadata/ - -.idea/ -*.iml - -prodDb.* - -*.log -brooklyn*.log.* - -ignored -*.bak diff --git a/README.md b/README.md new file mode 100644 index 0000000..9a1809f --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +This content has **moved** now that Brooklyn is an Apache project. Please visit [brooklyn.io](brooklyn.io). diff --git a/global-web-fabric/.gitignore b/global-web-fabric/.gitignore deleted file mode 100644 index 14fb0b8..0000000 --- a/global-web-fabric/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -brooklyn-example-global-web-fabric/ -brooklyn-example-global-web-fabric.tar.gz \ No newline at end of file diff --git a/global-web-fabric/README.txt b/global-web-fabric/README.txt deleted file mode 100644 index f2e017e..0000000 --- a/global-web-fabric/README.txt +++ /dev/null @@ -1,20 +0,0 @@ -Instructions for running examples -================================= - -The commands below assume that the `brooklyn` script is on your $PATH, this project has been built, -and you are in this directory. Adjust to taste for other configurations. - - export BROOKLYN_CLASSPATH=$(pwd)/target/classes - - # Launch the app in aws-ec2 regions eu-west-1 and us-east-1 - brooklyn launch --app brooklyn.demo.GlobalWebFabricExample --location "aws-ec2:eu-west-1,aws-ec2:us-east-1" - ---- - -The aws-ec2 credentials are retrieved from ~/.brooklyn/brooklyn.properties - -This file should contain something like: - brooklyn.jclouds.aws-ec2.identity=AKA50M30N3S1DFR0MAW55 - brooklyn.jclouds.aws-ec2.credential=aT0Ps3cr3tC0D3wh1chAW5w1llG1V3y0uTOus333 - -Brooklyn defaults to using ~/.ssh/id_rsa and ~/.ssh/id_rsa.pub. \ No newline at end of file diff --git a/global-web-fabric/pom.xml b/global-web-fabric/pom.xml deleted file mode 100644 index 297bc8d..0000000 --- a/global-web-fabric/pom.xml +++ /dev/null @@ -1,72 +0,0 @@ - - 4.0.0 - jar - brooklyn-example-global-web-fabric - Brooklyn Global Web Fabric Example - - - io.brooklyn.example - brooklyn-examples-parent - 0.6.0 - ../pom.xml - - - - - io.brooklyn - brooklyn-all - ${project.version} - with-dependencies - - - - - - - maven-dependency-plugin - - - - copy - process-classes - - copy - - - - - - ${project.groupId} - brooklyn-example-hello-world-webapp - ${project.version} - war - true - target/classes - hello-world-webapp.war - - - - - - - - maven-clean-plugin - - - - ${project.basedir} - - ${project.artifactId}/ - brooklyn*.log - brooklyn*.log.* - stacktrace.log - - - - - - - - - diff --git a/global-web-fabric/resources/vmc-delete-all.sh b/global-web-fabric/resources/vmc-delete-all.sh deleted file mode 100755 index 8c2ae54..0000000 --- a/global-web-fabric/resources/vmc-delete-all.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -# deletes all vmc applications against the current target (if no args) or against all targets specified - -vmc_delete_all() { - for x in `vmc apps | grep brooklyn | awk '{print $2}'` ; do vmc delete $x ; done -} - -if [ -z "$1" ]; then - vmc_delete_all -else - for x in $@ ; do - vmc target $x - vmc_delete_all - done -fi diff --git a/global-web-fabric/src/main/java/brooklyn/demo/GlobalWebFabricExample.java b/global-web-fabric/src/main/java/brooklyn/demo/GlobalWebFabricExample.java deleted file mode 100644 index aa61f5d..0000000 --- a/global-web-fabric/src/main/java/brooklyn/demo/GlobalWebFabricExample.java +++ /dev/null @@ -1,77 +0,0 @@ -package brooklyn.demo; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Arrays; -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import brooklyn.config.StringConfigMap; -import brooklyn.entity.basic.AbstractApplication; -import brooklyn.entity.basic.Entities; -import brooklyn.entity.dns.geoscaling.GeoscalingDnsService; -import brooklyn.entity.group.DynamicFabric; -import brooklyn.entity.proxy.AbstractController; -import brooklyn.entity.proxying.EntitySpec; -import brooklyn.entity.proxying.EntitySpecs; -import brooklyn.entity.webapp.ElasticJavaWebAppService; -import brooklyn.launcher.BrooklynLauncher; -import brooklyn.location.basic.PortRanges; -import brooklyn.util.CommandLineUtil; - -import com.google.common.base.Joiner; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; - -public class GlobalWebFabricExample extends AbstractApplication { - - public static final Logger log = LoggerFactory.getLogger(GlobalWebFabricExample.class); - - public static final String WAR_PATH = "classpath://hello-world-webapp.war"; - - static final List DEFAULT_LOCATIONS = ImmutableList.of( - "aws-ec2:eu-west-1", - "aws-ec2:ap-southeast-1", - "aws-ec2:us-west-1" ); - - @Override - public void init() { - 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("smartSubdomainName", "brooklyn")); - - DynamicFabric webFabric = addChild(EntitySpec.create(DynamicFabric.class) - .displayName("Web Fabric") - .configure(DynamicFabric.FACTORY, new ElasticJavaWebAppService.Factory()) - - //specify the WAR file to use - .configure(ElasticJavaWebAppService.ROOT_WAR, WAR_PATH) - - //load-balancer instances must run on 80 to work with GeoDNS (default is 8000) - .configure(AbstractController.PROXY_HTTP_PORT, PortRanges.fromInteger(80))); - - //tell GeoDNS what to monitor - geoDns.setTargetEntityProvider(webFabric); - } - - public static void main(String[] argv) { - List args = Lists.newArrayList(argv); - String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+"); - String locations = CommandLineUtil.getCommandLineOption(args, "--locations", Joiner.on(",").join(DEFAULT_LOCATIONS)); - - BrooklynLauncher launcher = BrooklynLauncher.newInstance() - .application(EntitySpecs.appSpec(GlobalWebFabricExample.class).displayName("Brooklyn Global Web Fabric Example")) - .webconsolePort(port) - .locations(Arrays.asList(locations)) - .start(); - - Entities.dumpInfo(launcher.getApplications()); - } -} diff --git a/global-web-fabric/src/main/java/brooklyn/demo/ReadMe.java b/global-web-fabric/src/main/java/brooklyn/demo/ReadMe.java deleted file mode 100644 index e3bd5ae..0000000 --- a/global-web-fabric/src/main/java/brooklyn/demo/ReadMe.java +++ /dev/null @@ -1,10 +0,0 @@ -package brooklyn.demo; - -public class ReadMe { - -/* This class exists only so that javadoc is generated and artifacts can be staged at sonatype for deployment to maven central. - * See: https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide - * - * (The actual examples are in other classes in this package / project.) */ - -} diff --git a/hadoop-and-whirr/.gitignore b/hadoop-and-whirr/.gitignore deleted file mode 100644 index 8e27592..0000000 --- a/hadoop-and-whirr/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -brooklyn-example-hadoop-and-whirr/ -brooklyn-example-hadoop-and-whirr.tar.gz \ No newline at end of file diff --git a/hadoop-and-whirr/README.txt b/hadoop-and-whirr/README.txt deleted file mode 100644 index 535d8ce..0000000 --- a/hadoop-and-whirr/README.txt +++ /dev/null @@ -1,33 +0,0 @@ -Instructions for running examples -================================= - -The commands below assume that the `brooklyn` script is already on your $PATH, and you are in the "examples" directory: - - cd hadoop-and-whirr - export BROOKLYN_CLASSPATH=$(pwd)/target/classes - - # Runs hadoop in aws-ec2 us-east-1 - brooklyn launch --app brooklyn.extras.whirr.WhirrHadoopExample --stopOnKeyPress --location aws-ec2:us-east-1 - - # Runs whirr with a custom recipe in aws-ec2 us-east-1 - brooklyn launch --app brooklyn.extras.whirr.WhirrExample --stopOnKeyPress --location aws-ec2:us-east-1 - - # Runs a web-cluster along with hadoop in aws-ec2, region us-east-1 - brooklyn launch --app brooklyn.extras.whirr.WebClusterWithHadoopExample --location aws-ec2:us-east-1 - - # Runs web-clusters in eu-west-1 and us-east-1, along with hadoop - brooklyn -v launch --app brooklyn.extras.whirr.WebFabricWithHadoopExample --stopOnKeyPress --location "aws-ec2:eu-west-1,aws-ec2:us-east-1" - ---- - -The aws-ec2 credentials are retrieved from ~/.brooklyn/brooklyn.properties - -This file should contain something like: - brooklyn.jclouds.aws-ec2.identity=AKA50M30N3S1DFR0MAW55 - brooklyn.jclouds.aws-ec2.credential=aT0Ps3cr3tC0D3wh1chAW5w1llG1V3y0uTOus333 - -Brooklyn defaults to using ~/.ssh/id_rsa and ~/.ssh/id_rsa.pub - ---- - -For more information, please visit: http://brooklyncentral.github.com/use/examples/whirrhadoop/ diff --git a/hadoop-and-whirr/pom.xml b/hadoop-and-whirr/pom.xml deleted file mode 100644 index d80c1eb..0000000 --- a/hadoop-and-whirr/pom.xml +++ /dev/null @@ -1,78 +0,0 @@ - - 4.0.0 - jar - brooklyn-example-hadoop-and-whirr - Brooklyn Hadoop and Whirr Example - - - io.brooklyn.example - brooklyn-examples-parent - 0.6.0 - ../pom.xml - - - - - io.brooklyn - brooklyn-all - ${project.version} - with-dependencies - - - org.apache.whirr - whirr-elasticsearch - ${whirr.version} - - - - - - - maven-dependency-plugin - - - - copy - process-classes - - copy - - - - - - ${project.groupId} - brooklyn-example-hello-world-hadoop-webapp - ${project.version} - war - true - target/classes - hello-world-hadoop-webapp.war - - - - - - - - maven-clean-plugin - - - - ${project.basedir} - - ${project.artifactId}/ - brooklyn*.log - brooklyn*.log.* - stacktrace.log - - - - - - - - - diff --git a/hadoop-and-whirr/src/main/java/brooklyn/extras/whirr/ReadMe.java b/hadoop-and-whirr/src/main/java/brooklyn/extras/whirr/ReadMe.java deleted file mode 100644 index 3f342f8..0000000 --- a/hadoop-and-whirr/src/main/java/brooklyn/extras/whirr/ReadMe.java +++ /dev/null @@ -1,10 +0,0 @@ -package brooklyn.extras.whirr; - -public class ReadMe { - -/* This class exists only so that javadoc is generated and artifacts can be staged at sonatype for deployment to maven central. - * See: https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide - * - * (The actual examples are in other classes in this package / project.) */ - -} diff --git a/hadoop-and-whirr/src/main/java/brooklyn/extras/whirr/WebClusterWithHadoopExample.java b/hadoop-and-whirr/src/main/java/brooklyn/extras/whirr/WebClusterWithHadoopExample.java deleted file mode 100644 index 628d0e2..0000000 --- a/hadoop-and-whirr/src/main/java/brooklyn/extras/whirr/WebClusterWithHadoopExample.java +++ /dev/null @@ -1,190 +0,0 @@ -package brooklyn.extras.whirr; - -import java.io.File; -import java.io.IOException; -import java.net.URI; -import java.net.URLEncoder; -import java.util.Collection; -import java.util.List; -import java.util.Set; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import brooklyn.config.StringConfigMap; -import brooklyn.entity.Entity; -import brooklyn.entity.Group; -import brooklyn.entity.basic.AbstractApplication; -import brooklyn.entity.basic.DynamicGroup; -import brooklyn.entity.basic.Entities; -import brooklyn.entity.basic.StartableApplication; -import brooklyn.entity.proxying.EntitySpec; -import brooklyn.entity.proxying.EntitySpecs; -import brooklyn.entity.trait.Startable; -import brooklyn.entity.webapp.ControlledDynamicWebAppCluster; -import brooklyn.entity.webapp.DynamicWebAppCluster; -import brooklyn.entity.webapp.jboss.JBoss7Server; -import brooklyn.event.SensorEvent; -import brooklyn.event.SensorEventListener; -import brooklyn.event.feed.http.HttpPollValue; -import brooklyn.event.feed.http.HttpPolls; -import brooklyn.extras.whirr.hadoop.WhirrHadoopCluster; -import brooklyn.launcher.BrooklynLauncher; -import brooklyn.location.Location; -import brooklyn.policy.autoscaling.AutoScalerPolicy; -import brooklyn.policy.basic.AbstractPolicy; -import brooklyn.util.CommandLineUtil; -import brooklyn.util.exceptions.Exceptions; - -import com.google.common.base.Charsets; -import com.google.common.base.Joiner; -import com.google.common.base.Predicates; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import com.google.common.io.Files; - -/** - * Starts hadoop and a webapp using hadoop in the location supplied (just one location), - * configuring the webapp to connect to hadoop - */ -public class WebClusterWithHadoopExample extends AbstractApplication implements StartableApplication { - - private static final Logger log = LoggerFactory.getLogger(WebClusterWithHadoopExample.class); - - static final List DEFAULT_LOCATIONS = ImmutableList.of( - // note the 1d: we need our machines to be in the same availability zone - // so they can see each other on the internal IPs (where hadoop binds) - // (cross-site magic is shown in the hadoop fabric example) - // ((also note some availability zones don't work, that's amazon for you...)) - // most other clouds "just work" :) - "aws-ec2:us-east-1c"); - - public static final String WAR_PATH = "classpath://hello-world-hadoop-webapp.war"; - - private WhirrHadoopCluster hadoopCluster; - private ControlledDynamicWebAppCluster webCluster; - private DynamicGroup webVms; - - public WebClusterWithHadoopExample() { - } - - @Override - public void init() { - StringConfigMap config = getManagementContext().getConfig(); - - hadoopCluster = addChild(EntitySpec.create(WhirrHadoopCluster.class) - .configure("size", 2) - .configure("memory", 2048) - .configure("name", "Whirr Hadoop Cluster")); - - // TODO Can't just set RECIPE config in spec, because that overwrites defaults in WhirrHadoopCluster! - // specify hadoop version (1.0.2 has a nice, smaller hadoop client jar) - hadoopCluster.addRecipeLine("whirr.hadoop.version=1.0.2"); - // for this example we'll allow access from anywhere - hadoopCluster.addRecipeLine("whirr.client-cidrs=0.0.0.0/0"); - hadoopCluster.addRecipeLine("whirr.firewall-rules=8020,8021,50010"); - - webCluster = addChild(EntitySpec.create(ControlledDynamicWebAppCluster.class) - .configure("war", WAR_PATH) - .policy(AutoScalerPolicy.builder() - .metric(DynamicWebAppCluster.AVERAGE_REQUESTS_PER_SECOND) - .sizeRange(1, 5) - .metricRange(10, 100) - .build())); - - webVms = addChild(EntitySpec.create(DynamicGroup.class) - .displayName("Web VMs") - .configure(DynamicGroup.ENTITY_FILTER, Predicates.instanceOf(JBoss7Server.class))); - } - - @Override - public void start(Collection locations) { - Iterables.getOnlyElement(locations); - log.debug("starting "+this); - super.start(locations); - - // start the web cluster, and hadoop cluster, in the single location (above) - // then register a policy to configure the appservers to use hadoop - log.debug("started "+this+", now starting policy"); - PrepVmsForHadoop.newPolicyFromGroupToHadoop(webVms, hadoopCluster); - } - - public static class PrepVmsForHadoop extends AbstractPolicy { - WhirrHadoopCluster hadoopCluster; - String hadoopSiteXmlContents; - Set configuredIds = Sets.newLinkedHashSet(); - - public PrepVmsForHadoop(WhirrHadoopCluster hadoopCluster) { - this.hadoopCluster = hadoopCluster; - } - - public void start() { - //read the contents, and disable socks proxy since we're in the same cluster - try { - File hadoopSiteXmlFile = new File(System.getProperty("user.home")+"/.whirr/"+ - hadoopCluster.getClusterSpec().getClusterName()+"/hadoop-site.xml"); - hadoopSiteXmlContents = Files.toString(hadoopSiteXmlFile, Charsets.UTF_8); - hadoopSiteXmlContents = hadoopSiteXmlContents.replaceAll("<\\?xml.*\\?>\\s*", ""); - hadoopSiteXmlContents = hadoopSiteXmlContents.replaceAll("hadoop.socks.server", "ignore.hadoop.socks.server"); - - subscribeToMembers((Group)entity, Startable.SERVICE_UP, new SensorEventListener() { - @Override public void onEvent(SensorEvent event) { - log.debug("hadoop set up policy recieved {}", event); - if (event.getValue() != null && !configuredIds.contains(event.getSource().getId())) - setupMachine(event.getSource()); - }}); - } catch (IOException e) { - throw Exceptions.propagate(e); - } - } - - public void setupMachine(Entity e) { - try { - if (!e.getAttribute(Startable.SERVICE_UP)) return; - if (!configuredIds.add(e.getId())) return; - if (log.isDebugEnabled()) log.debug("setting up machine for hadoop at {}", e); - - URI updateConfigUri = new URI(e.getAttribute(JBoss7Server.ROOT_URL)+ - "configure.jsp?"+ - "key=brooklyn.example.hadoop.site.xml.contents"+"&"+ - "value="+URLEncoder.encode(hadoopSiteXmlContents)); - - HttpPollValue result = HttpPolls.executeSimpleGet(updateConfigUri); - if (log.isDebugEnabled()) log.debug("http config update for {} got: {}, {}", new Object[] {e, result.getResponseCode(), new String(result.getContent())}); - } catch (Exception err) { - log.warn("unable to configure "+e+" for hadoop", err); - configuredIds.remove(e.getId()); - } - } - - public static PrepVmsForHadoop newPolicyFromGroupToHadoop(DynamicGroup target, WhirrHadoopCluster hadoopCluster) { - log.debug("creating policy for hadoop clusters target {} hadoop ", target, hadoopCluster); - PrepVmsForHadoop prepVmsForHadoop = new PrepVmsForHadoop(hadoopCluster); - target.addPolicy(prepVmsForHadoop); - prepVmsForHadoop.start(); - log.debug("running policy over existing members {}", target.getMembers()); - for (Entity member : target.getMembers()) { - prepVmsForHadoop.setupMachine(member); - } - return prepVmsForHadoop; - } - } - - public static void main(String[] argv) { - List args = Lists.newArrayList(argv); - String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+"); - String location = CommandLineUtil.getCommandLineOption(args, "--location", Joiner.on(",").join(DEFAULT_LOCATIONS)); - - BrooklynLauncher launcher = BrooklynLauncher.newInstance() - .application(EntitySpecs.appSpec(StartableApplication.class) - .displayName("Brooklyn Global Web Fabric with Hadoop Example") - .impl(WebClusterWithHadoopExample.class)) - .webconsolePort(port) - .location(location) - .start(); - - Entities.dumpInfo(launcher.getApplications()); - } -} diff --git a/hadoop-and-whirr/src/main/java/brooklyn/extras/whirr/WebFabricWithHadoopExample.java b/hadoop-and-whirr/src/main/java/brooklyn/extras/whirr/WebFabricWithHadoopExample.java deleted file mode 100644 index 2c43185..0000000 --- a/hadoop-and-whirr/src/main/java/brooklyn/extras/whirr/WebFabricWithHadoopExample.java +++ /dev/null @@ -1,260 +0,0 @@ -package brooklyn.extras.whirr; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.io.File; -import java.io.StringReader; -import java.net.InetAddress; -import java.net.URI; -import java.util.Collection; -import java.util.List; -import java.util.Set; -import java.util.concurrent.atomic.AtomicBoolean; - -import org.apache.whirr.service.hadoop.HadoopCluster; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import brooklyn.config.StringConfigMap; -import brooklyn.entity.Entity; -import brooklyn.entity.Group; -import brooklyn.entity.basic.AbstractApplication; -import brooklyn.entity.basic.DynamicGroup; -import brooklyn.entity.basic.Entities; -import brooklyn.entity.basic.StartableApplication; -import brooklyn.entity.dns.geoscaling.GeoscalingDnsService; -import brooklyn.entity.group.DynamicFabric; -import brooklyn.entity.proxy.AbstractController; -import brooklyn.entity.proxying.EntitySpec; -import brooklyn.entity.proxying.EntitySpecs; -import brooklyn.entity.trait.Startable; -import brooklyn.entity.webapp.ElasticJavaWebAppService; -import brooklyn.entity.webapp.jboss.JBoss7Server; -import brooklyn.event.SensorEvent; -import brooklyn.event.SensorEventListener; -import brooklyn.event.feed.http.HttpPollValue; -import brooklyn.event.feed.http.HttpPolls; -import brooklyn.extras.whirr.hadoop.WhirrHadoopCluster; -import brooklyn.launcher.BrooklynLauncher; -import brooklyn.location.Location; -import brooklyn.location.basic.PortRanges; -import brooklyn.location.basic.SshMachineLocation; -import brooklyn.management.Task; -import brooklyn.policy.basic.AbstractPolicy; -import brooklyn.util.CommandLineUtil; -import brooklyn.util.task.ParallelTask; - -import com.google.common.base.Charsets; -import com.google.common.base.Joiner; -import com.google.common.base.Predicates; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import com.google.common.io.Files; - -/** - * Starts hadoop in the first location supplied, and the hadoop-friendly webapp in all other locations. - * Webapp get configured via the configure.jsp page, plus supplying the proxy command, to connect to hadoop. - */ -public class WebFabricWithHadoopExample extends AbstractApplication implements StartableApplication { - - private static final Logger log = LoggerFactory.getLogger(WebFabricWithHadoopExample.class); - - static final List DEFAULT_LOCATIONS = ImmutableList.of( - // hadoop location - "aws-ec2:eu-west-1", - - //web locations - "aws-ec2:eu-west-1", - "aws-ec2:ap-southeast-1", - "aws-ec2:us-west-1"); - - public static final String WAR_PATH = "classpath://hello-world-hadoop-webapp.war"; - - private WhirrHadoopCluster hadoopCluster; - private GeoscalingDnsService geoDns; - private DynamicFabric webFabric; - private DynamicGroup webVms; - - public WebFabricWithHadoopExample() { - } - - @Override - public void init() { - StringConfigMap config = getManagementContext().getConfig(); - - hadoopCluster = addChild(EntitySpec.create(WhirrHadoopCluster.class) - .configure("size", 2) - .configure("memory", 2048) - .configure("name", "Whirr Hadoop Cluster")); - - // TODO Can't just set RECIPE config in spec, because that overwrites defaults in WhirrHadoopCluster! - // specify hadoop version (1.0.2 has a nice, smaller hadoop client jar) - hadoopCluster.addRecipeLine("whirr.hadoop.version=1.0.2"); - - 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("smartSubdomainName", "brooklyn")); - - webFabric = addChild(EntitySpec.create(DynamicFabric.class) - .displayName("Web Fabric") - .configure("factory", new ElasticJavaWebAppService.Factory()) - //specify the WAR file to use - .configure(ElasticJavaWebAppService.ROOT_WAR, WAR_PATH) - //load-balancer instances must run on 80 to work with GeoDNS (default is 8000) - .configure(AbstractController.PROXY_HTTP_PORT, PortRanges.fromInteger(80)) - ); -// .policy(AutoScalerPolicy.builder() -// .metric(DynamicWebAppCluster.AVERAGE_REQUESTS_PER_SECOND) -// .sizeRange(1, 5) -// .metricRange(10, 100) -// .build())); - - webVms = addChild(EntitySpec.create(DynamicGroup.class) - .displayName("Web VMs") - .configure(DynamicGroup.ENTITY_FILTER, Predicates.instanceOf(JBoss7Server.class))); - - //tell GeoDNS what to monitor - geoDns.setTargetEntityProvider(webFabric); - } - - @Override - public void start(Collection locations) { - if (locations.isEmpty()) throw new IllegalStateException("location required to start "+this); - final Location hadoopLocation = Iterables.getFirst(locations, null); - // start hadoop in first, web in others (unless there is just one location supplied) - final List webLocations = (locations.size() > 1) ? ImmutableList.copyOf(Iterables.skip(locations, 1)) : ImmutableList.of(hadoopLocation); - - Task> starts = getExecutionContext().submit(new ParallelTask( - new Runnable() { - public void run() { - webFabric.start(webLocations); - } - }, - new Runnable() { - public void run() { - hadoopCluster.start(ImmutableList.of(hadoopLocation)); - // collect the hadoop-site.xml and feed it to all existing and new appservers, - // and start the proxies there - PrepVmsForHadoop.newPolicyFromGroupToHadoop(webVms, hadoopCluster); - } - })); - starts.blockUntilEnded(); - } - - public static class PrepVmsForHadoop extends AbstractPolicy { - WhirrHadoopCluster hadoopCluster; - Set configuredIds = Sets.newLinkedHashSet(); - - public PrepVmsForHadoop(WhirrHadoopCluster hadoopCluster) { - this.hadoopCluster = hadoopCluster; - } - - public static PrepVmsForHadoop newPolicyFromGroupToHadoop(DynamicGroup target, WhirrHadoopCluster hadoopCluster) { - log.debug("creating policy for hadoop clusters target {} hadoop ", target, hadoopCluster); - PrepVmsForHadoop prepVmsForHadoop = new PrepVmsForHadoop(hadoopCluster); - target.addPolicy(prepVmsForHadoop); - prepVmsForHadoop.start(); - log.debug("running policy over existing members {}", target.getMembers()); - for (Entity member : target.getMembers()) { - prepVmsForHadoop.setupMachine(member); - } - return prepVmsForHadoop; - } - - public void start() { - subscribeToMembers((Group)entity, Startable.SERVICE_UP, new SensorEventListener() { - // track if previously up, so only execute when transitions from false->true - private final AtomicBoolean up = new AtomicBoolean(); - - @Override public void onEvent(SensorEvent event) { - log.debug("hadoop set up policy recieved {}", event); - if (Boolean.TRUE.equals(event.getValue()) && !up.get()) { - up.set(true); - setupMachine(event.getSource()); - } - }}); - } - - public void setupMachine(Entity e) { - try { - if (log.isDebugEnabled()) log.debug("setting up machine for hadoop at {}", e); - if (!e.getAttribute(Startable.SERVICE_UP)) return; - if (!configuredIds.add(e.getId())) return; - SshMachineLocation ssh = (SshMachineLocation) Iterables.getOnlyElement(e.getLocations()); - // TODO would prefer to extract content from HadoopNameNodeClusterActionHandler (but that class would need refactoring) - ssh.copyTo(new File(System.getProperty("user.home")+"/.whirr/"+hadoopCluster.getClusterSpec().getClusterName()+"/hadoop-site.xml"), "/tmp/hadoop-site.xml"); - - File identity = hadoopCluster.getClusterSpec().getPrivateKeyFile(); - if (identity == null){ - identity = File.createTempFile("hadoop", "key"); - identity.deleteOnExit(); - Files.write(hadoopCluster.getClusterSpec().getPrivateKey(), identity, Charsets.UTF_8); - } - if (log.isDebugEnabled()) log.debug("http config update for {}, identity file: {}", e, identity); - ssh.copyTo(identity, "/tmp/hadoop-proxy-private-key"); - - //copied from HadoopProxy, would prefer to reference (but again refactoring there is needed) - String user = hadoopCluster.getClusterSpec().getClusterUser(); - InetAddress namenode = HadoopCluster.getNamenodePublicAddress(hadoopCluster.getCluster()); - String server = namenode.getHostName(); - // TODO: the `ssh -D` command keeps failing because of incorrect ssh key. Tested in "aws-ec2:us-west-2", AMI ubuntu-saucy-13.10-i386-server-20131015 (ami-aae67f9a) - String proxyCommand = Joiner.on(" ").join(ImmutableList.of( - "ssh", - "-i", "/tmp/hadoop-proxy-private-key", - "-o", "ConnectTimeout=10", - "-o", "ServerAliveInterval=60", - "-o", "StrictHostKeyChecking=no", - "-o", "UserKnownHostsFile=/dev/null", - "-o", "StrictHostKeyChecking=no", - "-N", - "-D 6666", - String.format("%s@%s", user, server))); - if (log.isDebugEnabled()) log.debug("http config update for {}, proxy command: {}", e, proxyCommand); - - String hadoopProxyForeverContent = - "#!/bin/bash"+"\n"+ - "while [ true ] ; do"+"\n"+ - " date"+"\n"+ - " echo starting proxy for hadoop to "+String.format("%s@%s", user, server)+"\n"+ - " nohup "+proxyCommand+"\n"+ - " echo proxy ended"+"\n"+ - "done"+"\n"; - - ssh.copyTo(new StringReader(hadoopProxyForeverContent), "/tmp/hadoop-proxy-forever.sh"); - - // TODO: the `nohup hadoop-proxy-forever.sh &` script is not returning. Tested in "aws-ec2:us-west-2", AMI ubuntu-saucy-13.10-i386-server-20131015 (ami-aae67f9a) - ssh.execCommands("chmod", ImmutableList.of("chmod 600 /tmp/hadoop-proxy-private-key", "chmod +x /tmp/hadoop-proxy-forever.sh", "nohup /tmp/hadoop-proxy-forever.sh < /dev/null &")); - - URI updateConfigUri = new URI(e.getAttribute(JBoss7Server.ROOT_URL)+ - "configure.jsp?key=brooklyn.example.hadoop.site.xml.url&value=file:///tmp/hadoop-site.xml"); - - HttpPollValue result = HttpPolls.executeSimpleGet(updateConfigUri); - if (log.isDebugEnabled()) log.debug("http config update for {} got: {}, {}", new Object[] {e, result.getResponseCode(), new String(result.getContent())}); - } catch (Exception err) { - log.warn("unable to configure "+e+" for hadoop", err); - configuredIds.remove(e.getId()); - } - } - } - - public static void main(String[] argv) { - List args = Lists.newArrayList(argv); - String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+"); - String location = CommandLineUtil.getCommandLineOption(args, "--location", Joiner.on(",").join(DEFAULT_LOCATIONS)); - - BrooklynLauncher launcher = BrooklynLauncher.newInstance() - .application(EntitySpecs.appSpec(StartableApplication.class) - .displayName("Brooklyn Global Web Fabric with Hadoop Example") - .impl(WebFabricWithHadoopExample.class)) - .webconsolePort(port) - .location(location) - .start(); - - Entities.dumpInfo(launcher.getApplications()); - } -} diff --git a/hadoop-and-whirr/src/main/java/brooklyn/extras/whirr/WhirrExample.java b/hadoop-and-whirr/src/main/java/brooklyn/extras/whirr/WhirrExample.java deleted file mode 100644 index 0b69216..0000000 --- a/hadoop-and-whirr/src/main/java/brooklyn/extras/whirr/WhirrExample.java +++ /dev/null @@ -1,54 +0,0 @@ -package brooklyn.extras.whirr; - -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import brooklyn.entity.basic.AbstractApplication; -import brooklyn.entity.basic.Entities; -import brooklyn.entity.basic.StartableApplication; -import brooklyn.entity.proxying.EntitySpec; -import brooklyn.entity.proxying.EntitySpecs; -import brooklyn.extras.whirr.core.WhirrCluster; -import brooklyn.launcher.BrooklynLauncher; -import brooklyn.util.CommandLineUtil; - -import com.google.common.collect.Lists; - -public class WhirrExample extends AbstractApplication { - - private static final Logger LOG = LoggerFactory.getLogger(WhirrExample.class); - - public static final String DEFAULT_LOCATION = "aws-ec2:eu-west-1"; - - public static final String RECIPE = - "whirr.cluster-name=brooklyn-whirr"+"\n"+ - "whirr.hardware-min-ram=1024"+"\n"+ - "whirr.instance-templates=1 noop, 1 elasticsearch"+"\n"; - - @Override - public void init() { - addChild(EntitySpec.create(WhirrCluster.class) - .configure("recipe", RECIPE)); - } - - public static void main(String[] argv) throws Exception { - List args = Lists.newArrayList(argv); - String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+"); - String location = CommandLineUtil.getCommandLineOption(args, "--location", DEFAULT_LOCATION); - - BrooklynLauncher launcher = BrooklynLauncher.newInstance() - .application(EntitySpecs.appSpec(WhirrExample.class)) - .webconsolePort(port) - .location(location) - .start(); - - StartableApplication app = (StartableApplication) launcher.getApplications().get(0); - Entities.dumpInfo(app); - - LOG.info("Press return to shut down the cluster"); - System.in.read(); //wait for the user to type a key - app.stop(); - } -} diff --git a/hadoop-and-whirr/src/main/java/brooklyn/extras/whirr/WhirrHadoopExample.java b/hadoop-and-whirr/src/main/java/brooklyn/extras/whirr/WhirrHadoopExample.java deleted file mode 100644 index 5de1879..0000000 --- a/hadoop-and-whirr/src/main/java/brooklyn/extras/whirr/WhirrHadoopExample.java +++ /dev/null @@ -1,51 +0,0 @@ -package brooklyn.extras.whirr; - -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import brooklyn.entity.basic.AbstractApplication; -import brooklyn.entity.basic.Entities; -import brooklyn.entity.basic.StartableApplication; -import brooklyn.entity.proxying.EntitySpec; -import brooklyn.entity.proxying.EntitySpecs; -import brooklyn.extras.whirr.hadoop.WhirrHadoopCluster; -import brooklyn.launcher.BrooklynLauncher; -import brooklyn.util.CommandLineUtil; - -import com.google.common.collect.Lists; - -public class WhirrHadoopExample extends AbstractApplication { - - private static final Logger LOG = LoggerFactory.getLogger(WhirrHadoopExample.class); - - public static final String DEFAULT_LOCATION = "aws-ec2:eu-west-1"; - - @Override - public void init() { - addChild(EntitySpec.create(WhirrHadoopCluster.class) - .displayName("brooklyn-hadoop-example") - .configure("size", 2) - .configure("memory", 2048)); - } - - public static void main(String[] argv) throws Exception { - List args = Lists.newArrayList(argv); - String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+"); - String location = CommandLineUtil.getCommandLineOption(args, "--location", DEFAULT_LOCATION); - - BrooklynLauncher launcher = BrooklynLauncher.newInstance() - .application(EntitySpecs.appSpec(WhirrHadoopExample.class)) - .webconsolePort(port) - .location(location) - .start(); - - StartableApplication app = (StartableApplication) launcher.getApplications().get(0); - Entities.dumpInfo(app); - - LOG.info("Press return to shut down the cluster"); - System.in.read(); //wait for the user to type a key - app.stop(); - } -} diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 14fdc26..0000000 --- a/pom.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - 4.0.0 - pom - - io.brooklyn.example - brooklyn-examples-parent - - Brooklyn Examples Aggregator Project - - Brooklyn examples module, building the Brooklyn examples. - - - - io.brooklyn - brooklyn-parent - 0.6.0 - ../pom.xml - - - - - - sonatype-nexus-snapshots - Sonatype Nexus Snapshots - https://oss.sonatype.org/content/repositories/snapshots - false - true - - - - - webapps - simple-web-cluster - global-web-fabric - hadoop-and-whirr - simple-messaging-pubsub - simple-nosql-cluster - - - diff --git a/simple-messaging-pubsub/.gitignore b/simple-messaging-pubsub/.gitignore deleted file mode 100644 index 7a8040d..0000000 --- a/simple-messaging-pubsub/.gitignore +++ /dev/null @@ -1 +0,0 @@ -resources/lib/ \ No newline at end of file diff --git a/simple-messaging-pubsub/README.txt b/simple-messaging-pubsub/README.txt deleted file mode 100644 index e27992e..0000000 --- a/simple-messaging-pubsub/README.txt +++ /dev/null @@ -1,29 +0,0 @@ -Instructions for running examples -================================= - -The commands below assume that the `brooklyn` script is already on your $PATH, and you are in the "examples" directory: - - cd simple-messaging-pubsub - export BROOKLYN_CLASSPATH=$(pwd)/target/classes - - # Launches a qpid broker on localhost - brooklyn -v launch --app brooklyn.demo.StandaloneQpidBrokerExample --location localhost - - # You can get the broker's URL from the brooklyn web-console at http://localhost:8081 - # by looking at the broker entity's sensors or from the verbose output from the application startup - URL="amqp://guest:guest@/localhost?brokerlist='tcp://localhost:5672'" - - # Test subscribing, to receive a message from the broker - java -cp "./resources/lib/*:./target/classes" brooklyn.demo.Subscribe ${URL} - - # Test publishing a message to the broker - java -cp "./resources/lib/*:./target/classes" brooklyn.demo.Publish ${URL} - -To test a Kafka distributed messaging cluster example, use the following command: - - # Launches a Kafka cluster on AWS EC2 with two brokers - brooklyn -v launch --app brooklyn.demo.KafkaClusterExample --location aws-ec2:eu-west-1 - ---- - -For more information, please visit: http://brooklyncentral.github.com/use/examples/messaging/ diff --git a/simple-messaging-pubsub/pom.xml b/simple-messaging-pubsub/pom.xml deleted file mode 100644 index c0c509d..0000000 --- a/simple-messaging-pubsub/pom.xml +++ /dev/null @@ -1,106 +0,0 @@ - - 4.0.0 - jar - brooklyn-example-simple-messaging-pubsub - Brooklyn Simple Messaging Publish-Subscribe Example - - - io.brooklyn.example - brooklyn-examples-parent - 0.6.0 - ../pom.xml - - - - - oracle - http://download.oracle.com/maven - - - - - - io.brooklyn - brooklyn-all - ${project.version} - provided - - - - com.google.guava - guava - - - org.apache.geronimo.specs - geronimo-jms_1.1_spec - 1.1.1 - - - org.apache.qpid - qpid-client - 0.14 - - - - - - - maven-dependency-plugin - - - copy - process-classes - - copy - - - - - org.apache.qpid - qpid-bdbstore - 0.14 - - - com.sleepycat - je - 5.0.34 - - - ${project.build.directory}/classes - - - - copy-dependencies - process-classes - - copy-dependencies - - - - geronimo-jms_1.1_spec,guava,jsr305,log4j,qpid-client,qpid-common,slf4j-api,slf4j-log4j12 - - ${project.basedir}/resources/lib - - - - - - maven-clean-plugin - - - - ${project.basedir} - - ${project.artifactId}/ - brooklyn*.log - brooklyn*.log.* - stacktrace.log - resources/lib/ - - - - - - - - diff --git a/simple-messaging-pubsub/src/main/java/brooklyn/demo/KafkaClusterExample.java b/simple-messaging-pubsub/src/main/java/brooklyn/demo/KafkaClusterExample.java deleted file mode 100644 index 889048f..0000000 --- a/simple-messaging-pubsub/src/main/java/brooklyn/demo/KafkaClusterExample.java +++ /dev/null @@ -1,40 +0,0 @@ -package brooklyn.demo; - -import java.util.List; - -import brooklyn.entity.basic.ApplicationBuilder; -import brooklyn.entity.basic.Entities; -import brooklyn.entity.messaging.kafka.KafkaCluster; -import brooklyn.entity.proxying.EntitySpec; -import brooklyn.launcher.BrooklynLauncher; -import brooklyn.util.CommandLineUtil; - -import com.google.common.collect.Lists; - -/** Kafka Cluster Application */ -public class KafkaClusterExample extends ApplicationBuilder { - - public static final String DEFAULT_LOCATION = "localhost"; - - /** Configure the application. */ - protected void doBuild() { - addChild(EntitySpec.create(KafkaCluster.class) - .configure("startTimeout", 300) // 5 minutes - .configure("initialSize", 2)); - // TODO set application display name? - } - - public static void main(String[] argv) { - List args = Lists.newArrayList(argv); - String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+"); - String location = CommandLineUtil.getCommandLineOption(args, "--location", DEFAULT_LOCATION); - - BrooklynLauncher launcher = BrooklynLauncher.newInstance() - .application(new KafkaClusterExample().appDisplayName("Kafka cluster application")) - .webconsolePort(port) - .location(location) - .start(); - - Entities.dumpInfo(launcher.getApplications()); - } -} diff --git a/simple-messaging-pubsub/src/main/java/brooklyn/demo/Publish.java b/simple-messaging-pubsub/src/main/java/brooklyn/demo/Publish.java deleted file mode 100644 index d94edb5..0000000 --- a/simple-messaging-pubsub/src/main/java/brooklyn/demo/Publish.java +++ /dev/null @@ -1,53 +0,0 @@ -package brooklyn.demo; - -import javax.jms.Connection; -import javax.jms.MessageProducer; -import javax.jms.Queue; -import javax.jms.Session; -import javax.jms.TextMessage; - -import org.apache.qpid.client.AMQConnectionFactory; -import org.apache.qpid.configuration.ClientProperties; - -import com.google.common.base.Preconditions; -import com.google.common.base.Throwables; - -/** Publishes messages to a queue on a Qpid broker at a given URL. */ -public class Publish { - public static final String QUEUE = "'amq.direct'/'testQueue'; { node: { type: queue } }"; - - public static void main(String...argv) throws Exception { - Preconditions.checkElementIndex(0, argv.length, "Must specify broker URL"); - String url = argv[0]; - - // Set Qpid client properties - System.setProperty(ClientProperties.AMQP_VERSION, "0-10"); - System.setProperty(ClientProperties.DEST_SYNTAX, "ADDR"); - - // Connect to the broker - AMQConnectionFactory factory = new AMQConnectionFactory(url); - Connection connection = factory.createConnection(); - connection.start(); - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - - try { - // Create a producer for the queue - Queue destination = session.createQueue(QUEUE); - MessageProducer messageProducer = session.createProducer(destination); - - // Send 100 messages - for (int n = 0; n < 100; n++) { - String body = String.format("test message %03d", n+1); - TextMessage message = session.createTextMessage(body); - messageProducer.send(message); - System.out.printf("Sent message %s\n", body); - } - } catch (Exception e) { - System.err.printf("Error while sending - %s\n", e.getMessage()); - System.err.printf("Cause: %s\n", Throwables.getStackTraceAsString(e)); - } finally { - session.close(); - connection.close(); - } - } -} diff --git a/simple-messaging-pubsub/src/main/java/brooklyn/demo/StandaloneQpidBrokerExample.java b/simple-messaging-pubsub/src/main/java/brooklyn/demo/StandaloneQpidBrokerExample.java deleted file mode 100644 index 1927998..0000000 --- a/simple-messaging-pubsub/src/main/java/brooklyn/demo/StandaloneQpidBrokerExample.java +++ /dev/null @@ -1,55 +0,0 @@ -package brooklyn.demo; - -import java.util.List; - -import brooklyn.entity.basic.AbstractApplication; -import brooklyn.entity.basic.Entities; -import brooklyn.entity.messaging.amqp.AmqpServer; -import brooklyn.entity.messaging.qpid.QpidBroker; -import brooklyn.entity.proxying.EntitySpec; -import brooklyn.entity.proxying.EntitySpecs; -import brooklyn.launcher.BrooklynLauncher; -import brooklyn.util.CommandLineUtil; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Lists; - -/** Qpid Broker Application */ -public class StandaloneQpidBrokerExample extends AbstractApplication { - - public static final String CUSTOM_CONFIG_PATH = "classpath://custom-config.xml"; - public static final String PASSWD_PATH = "classpath://passwd"; - public static final String QPID_BDBSTORE_JAR_PATH = "classpath://qpid-bdbstore-0.14.jar"; - public static final String BDBSTORE_JAR_PATH = "classpath://je-5.0.34.jar"; - - public static final String DEFAULT_LOCATION = "localhost"; - - @Override - public void init() { - // Configure the Qpid broker entity - QpidBroker broker = addChild(EntitySpec.create(QpidBroker.class) - .configure("amqpPort", 5672) - .configure("amqpVersion", AmqpServer.AMQP_0_10) - .configure("runtimeFiles", ImmutableMap.builder() - .put(QpidBroker.CONFIG_XML, CUSTOM_CONFIG_PATH) - .put(QpidBroker.PASSWD, PASSWD_PATH) - .put("lib/opt/qpid-bdbstore-0.14.jar", QPID_BDBSTORE_JAR_PATH) - .put("lib/opt/je-5.0.34.jar", BDBSTORE_JAR_PATH) - .build()) - .configure("queue", "testQueue")); - } - - public static void main(String[] argv) { - List args = Lists.newArrayList(argv); - String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+"); - String location = CommandLineUtil.getCommandLineOption(args, "--location", DEFAULT_LOCATION); - - BrooklynLauncher launcher = BrooklynLauncher.newInstance() - .application(EntitySpecs.appSpec(StandaloneQpidBrokerExample.class).displayName("Qpid app")) - .webconsolePort(port) - .location(location) - .start(); - - Entities.dumpInfo(launcher.getApplications()); - } -} diff --git a/simple-messaging-pubsub/src/main/java/brooklyn/demo/Subscribe.java b/simple-messaging-pubsub/src/main/java/brooklyn/demo/Subscribe.java deleted file mode 100644 index 7899f47..0000000 --- a/simple-messaging-pubsub/src/main/java/brooklyn/demo/Subscribe.java +++ /dev/null @@ -1,58 +0,0 @@ -package brooklyn.demo; - -import javax.jms.Connection; -import javax.jms.MessageConsumer; -import javax.jms.Queue; -import javax.jms.Session; -import javax.jms.TextMessage; - -import org.apache.qpid.client.AMQConnectionFactory; -import org.apache.qpid.configuration.ClientProperties; - -import com.google.common.base.Preconditions; -import com.google.common.base.Throwables; - -/** Receives messages from a queue on a Qpid broker at a given URL. */ -public class Subscribe { - public static final String QUEUE = "'amq.direct'/'testQueue'; { node: { type: queue } }"; - private static final long MESSAGE_TIMEOUT_MILLIS = 15000L; - private static final int MESSAGE_COUNT = 100; - - public static void main(String...argv) throws Exception { - Preconditions.checkElementIndex(0, argv.length, "Must specify broker URL"); - String url = argv[0]; - - // Set Qpid client properties - System.setProperty(ClientProperties.AMQP_VERSION, "0-10"); - System.setProperty(ClientProperties.DEST_SYNTAX, "ADDR"); - - // Connect to the broker - AMQConnectionFactory factory = new AMQConnectionFactory(url); - Connection connection = factory.createConnection(); - connection.start(); - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - - System.out.printf("Waiting up to %s milliseconds to receive %s messages\n", MESSAGE_TIMEOUT_MILLIS, MESSAGE_COUNT); - try { - // Create a producer for the queue - Queue destination = session.createQueue(QUEUE); - MessageConsumer messageConsumer = session.createConsumer(destination); - - // Try and receive 100 messages - for (int n = 0; n < MESSAGE_COUNT; n++) { - TextMessage msg = (TextMessage) messageConsumer.receive(MESSAGE_TIMEOUT_MILLIS); - if (msg == null) { - System.out.printf("No message received in %s milliseconds, exiting", MESSAGE_TIMEOUT_MILLIS); - break; - } - System.out.printf("Got message %d: '%s'\n", n+1, msg.getText()); - } - } catch (Exception e) { - System.err.printf("Error while receiving - %s\n", e.getMessage()); - System.err.printf("Cause: %s\n", Throwables.getStackTraceAsString(e)); - } finally { - session.close(); - connection.close(); - } - } -} diff --git a/simple-messaging-pubsub/src/main/resources/custom-config.xml b/simple-messaging-pubsub/src/main/resources/custom-config.xml deleted file mode 100644 index 13ed7ce..0000000 --- a/simple-messaging-pubsub/src/main/resources/custom-config.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - ${QPID_HOME}/lib/plugins - ${QPID_HOME}/cache - - - false - - - - true - - false - - - - - - org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase - - - passwordFile - ${QPID_HOME}/etc/passwd - - - - - - false - - - localhost - - localhost - - - org.apache.qpid.server.store.berkeleydb.BDBMessageStore - ${QPID_HOME}/store/localhost - - - - - - true - - ON - diff --git a/simple-messaging-pubsub/src/main/resources/passwd b/simple-messaging-pubsub/src/main/resources/passwd deleted file mode 100644 index 814b1e6..0000000 --- a/simple-messaging-pubsub/src/main/resources/passwd +++ /dev/null @@ -1,3 +0,0 @@ -# Custom password file -guest:guest -admin:password diff --git a/simple-nosql-cluster/.gitignore b/simple-nosql-cluster/.gitignore deleted file mode 100644 index 7a8040d..0000000 --- a/simple-nosql-cluster/.gitignore +++ /dev/null @@ -1 +0,0 @@ -resources/lib/ \ No newline at end of file diff --git a/simple-nosql-cluster/README.md b/simple-nosql-cluster/README.md deleted file mode 100644 index 7a4e724..0000000 --- a/simple-nosql-cluster/README.md +++ /dev/null @@ -1,23 +0,0 @@ -Instructions for running examples -================================= - -The commands below assume that the `brooklyn` script is already on your $PATH, and you are in the `examples` directory: - - cd simple-nosql-cluster - export BROOKLYN_CLASSPATH=$(pwd)/target/classes - - # Launches a Redis cluster on AWS EC2 - brooklyn -v launch --app brooklyn.demo.SimpleRedisCluster --location aws-ec2:eu-west-1 - - # Launches a Cassandra cluster on AWS EC2 - brooklyn -v launch --app brooklyn.demo.SimpleCassandraCluster --location aws-ec2:eu-west-1 - - # Launches a CouchDB cluster on AWS EC2 - brooklyn -v launch --app brooklyn.demo.SimpleCouchDBCluster --location aws-ec2:eu-west-1 - - # Launches a CumulusRDF application backed by a cassandra cluster on AWS EC2 - brooklyn -v launch --app brooklyn.demo.CumulusRDFApplication --location aws-ec2:eu-west-1 - --------- - -For more information, please visit the (http://brooklyncentral.github.com/use/examples/nosql/)[NoSQL examples page] diff --git a/simple-nosql-cluster/pom.xml b/simple-nosql-cluster/pom.xml deleted file mode 100644 index ea8252e..0000000 --- a/simple-nosql-cluster/pom.xml +++ /dev/null @@ -1,70 +0,0 @@ - - 4.0.0 - jar - brooklyn-example-simple-nosql-cluster - - Brooklyn NoSQL Cluster Examples - - Various NoSQL cluster-based applications, managed by Brooklyn. - - - - io.brooklyn.example - brooklyn-examples-parent - 0.6.0 - ../pom.xml - - - - - io.brooklyn - brooklyn-all - ${project.version} - - - - com.google.guava - guava - - - - io.brooklyn - brooklyn-logback-xml - ${project.version} - true - - - - - - - maven-clean-plugin - - - - ${project.basedir} - - ${project.artifactId}/ - brooklyn*.log - brooklyn*.log.* - stacktrace.log - resources/lib/ - - - - - - - - org.apache.maven.plugins - maven-assembly-plugin - - - src/main/assembly/assembly.xml - - - - - - diff --git a/simple-nosql-cluster/src/main/assembly/assembly.xml b/simple-nosql-cluster/src/main/assembly/assembly.xml deleted file mode 100644 index 5c39fee..0000000 --- a/simple-nosql-cluster/src/main/assembly/assembly.xml +++ /dev/null @@ -1,45 +0,0 @@ - - dist - - dir - tar.gz - - - - - - false - lib - false - - - - - - src/main/assembly/scripts - - 0755 - - * - - - - src/main/assembly/files - - - ** - - - - target - - - *.jar - - - *-tests.jar - - - - - diff --git a/simple-nosql-cluster/src/main/assembly/files/conf/logback.xml b/simple-nosql-cluster/src/main/assembly/files/conf/logback.xml deleted file mode 100644 index 37dad9c..0000000 --- a/simple-nosql-cluster/src/main/assembly/files/conf/logback.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - diff --git a/simple-nosql-cluster/src/main/assembly/scripts/start.sh b/simple-nosql-cluster/src/main/assembly/scripts/start.sh deleted file mode 100644 index 1018d73..0000000 --- a/simple-nosql-cluster/src/main/assembly/scripts/start.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -if [ ! -z "$JAVA_HOME" ] ; then - JAVA=$JAVA_HOME/bin/java -else - JAVA=`which java` -fi - -if [ ! -x "$JAVA" ] ; then - echo Cannot find java. Set JAVA_HOME or add java to path. - exit 1 -fi - -if [[ ! `ls brooklyn-*.jar 2> /dev/null` ]] ; then - echo Command must be run from the directory where the JAR is installed. - exit 4 -fi - -$JAVA -Xms256m -Xmx1024m -XX:MaxPermSize=1024m \ - -classpath "conf/:*:lib/*" \ - "$@" diff --git a/simple-nosql-cluster/src/main/java/brooklyn/demo/CumulusRDFApplication.java b/simple-nosql-cluster/src/main/java/brooklyn/demo/CumulusRDFApplication.java deleted file mode 100644 index 3464513..0000000 --- a/simple-nosql-cluster/src/main/java/brooklyn/demo/CumulusRDFApplication.java +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Copyright 2012-2013 by Cloudsoft Corp. - * - * Licensed 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 brooklyn.demo; - -import java.util.Collection; -import java.util.List; -import java.util.Map; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import brooklyn.catalog.Catalog; -import brooklyn.catalog.CatalogConfig; -import brooklyn.config.ConfigKey; -import brooklyn.entity.Effector; -import brooklyn.entity.Entity; -import brooklyn.entity.basic.AbstractApplication; -import brooklyn.entity.basic.Attributes; -import brooklyn.entity.basic.ConfigKeys; -import brooklyn.entity.basic.Entities; -import brooklyn.entity.basic.EntityInternal; -import brooklyn.entity.basic.Lifecycle; -import brooklyn.entity.basic.SoftwareProcess; -import brooklyn.entity.basic.StartableApplication; -import brooklyn.entity.effector.EffectorBody; -import brooklyn.entity.effector.Effectors; -import brooklyn.entity.java.UsesJava; -import brooklyn.entity.java.UsesJmx; -import brooklyn.entity.nosql.cassandra.CassandraCluster; -import brooklyn.entity.nosql.cassandra.CassandraFabric; -import brooklyn.entity.nosql.cassandra.CassandraNode; -import brooklyn.entity.proxying.EntitySpec; -import brooklyn.entity.software.SshEffectorTasks; -import brooklyn.entity.trait.Startable; -import brooklyn.entity.webapp.JavaWebAppService; -import brooklyn.entity.webapp.tomcat.TomcatServer; -import brooklyn.event.SensorEvent; -import brooklyn.event.SensorEventListener; -import brooklyn.event.basic.DependentConfiguration; -import brooklyn.launcher.BrooklynLauncher; -import brooklyn.location.Location; -import brooklyn.location.basic.PortRanges; -import brooklyn.policy.PolicySpec; -import brooklyn.policy.ha.ServiceFailureDetector; -import brooklyn.policy.ha.ServiceReplacer; -import brooklyn.policy.ha.ServiceRestarter; -import brooklyn.util.CommandLineUtil; -import brooklyn.util.ResourceUtils; -import brooklyn.util.collections.MutableList; -import brooklyn.util.collections.MutableMap; -import brooklyn.util.config.ConfigBag; -import brooklyn.util.exceptions.Exceptions; -import brooklyn.util.task.DynamicTasks; -import brooklyn.util.text.Strings; -import brooklyn.util.text.TemplateProcessor; - -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; -import com.google.common.net.HostAndPort; - -/** CumulusRDF application with Cassandra cluster. */ -@Catalog(name="Cumulus RDF Application", description="CumulusRDF Application on a Tomcat server using a multi-region Cassandra fabric") -public class CumulusRDFApplication extends AbstractApplication { - - private static final Logger log = LoggerFactory.getLogger(CumulusRDFApplication.class); - - @CatalogConfig(label="Cumulus Configuration File (URL)", priority=1) - public static final ConfigKey CUMULUS_RDF_CONFIG_URL = ConfigKeys.newConfigKey( - "cumulus.config.url", "URL for the YAML configuration file for CumulusRDF", "classpath://cumulus.yaml"); - - @CatalogConfig(label="Cassandra Thrift Port", priority=1) - public static final ConfigKey CASSANDRA_THRIFT_PORT = ConfigKeys.newConfigKey( - "cumulus.cassandra.port", "Port to contact the Cassandra cluster on", 9160); - - @CatalogConfig(label="Cassandra Cluster Size", priority=1) - public static final ConfigKey CASSANDRA_CLUSTER_SIZE = ConfigKeys.newConfigKey( - "cumulus.cassandra.cluster.size", "Initial size of the Cassandra cluster", 2); - - @CatalogConfig(label="Multi-region Fabric", priority=1) - public static final ConfigKey MULTI_REGION_FABRIC = ConfigKeys.newConfigKey( - "cumulus.cassandra.fabric", "Deploy a multi-region Cassandra fabric", false); - - public static final String DEFAULT_LOCATIONS = "aws-ec2:us-east-1,rackspace-cloudservers-uk"; - - private Effector cumulusConfig = Effectors.effector(Void.class, "cumulusConfig") - .description("Configure the CumulusRDF web application") - .buildAbstract(); - - private Entity cassandra; - private TomcatServer webapp; - private HostAndPort endpoint; - - /** - * Create the application entities: - *
    - *
  • A {@link CassandraFabric} of {@link CassandraCluster}s containing {@link CassandraNode}s - *
  • A {@link TomcatServer} - *
- */ - @Override - public void init() { - // Cassandra cluster - EntitySpec clusterSpec = EntitySpec.create(CassandraCluster.class) - .configure(CassandraCluster.MEMBER_SPEC, EntitySpec.create(CassandraNode.class) - .configure(UsesJmx.JMX_AGENT_MODE, UsesJmx.JmxAgentModes.JMX_RMI_CUSTOM_AGENT) - .configure(UsesJmx.JMX_PORT, PortRanges.fromString("11099+")) - .configure(UsesJmx.RMI_REGISTRY_PORT, PortRanges.fromString("9001+")) - .configure(CassandraNode.THRIFT_PORT, PortRanges.fromInteger(getConfig(CASSANDRA_THRIFT_PORT))) - .policy(PolicySpec.create(ServiceFailureDetector.class)) - .policy(PolicySpec.create(ServiceRestarter.class) - .configure(ServiceRestarter.FAILURE_SENSOR_TO_MONITOR, ServiceFailureDetector.ENTITY_FAILED))) - .policy(PolicySpec.create(ServiceReplacer.class) - .configure(ServiceReplacer.FAILURE_SENSOR_TO_MONITOR, ServiceRestarter.ENTITY_RESTART_FAILED)); - - if (getConfig(MULTI_REGION_FABRIC)) { - cassandra = addChild(EntitySpec.create(CassandraFabric.class) - .configure(CassandraCluster.CLUSTER_NAME, "Brooklyn") - .configure(CassandraCluster.INITIAL_SIZE, getConfig(CASSANDRA_CLUSTER_SIZE)) // per location - .configure(CassandraCluster.ENDPOINT_SNITCH_NAME, "brooklyn.entity.nosql.cassandra.customsnitch.MultiCloudSnitch") - .configure(CassandraNode.CUSTOM_SNITCH_JAR_URL, "classpath://brooklyn/entity/nosql/cassandra/cassandra-multicloud-snitch.jar") - .configure(CassandraFabric.MEMBER_SPEC, clusterSpec)); - } else { - cassandra = addChild(EntitySpec.create(clusterSpec) - .configure(CassandraCluster.CLUSTER_NAME, "Brooklyn") - .configure(CassandraCluster.INITIAL_SIZE, getConfig(CASSANDRA_CLUSTER_SIZE))); - } - - // Tomcat web-app server - webapp = addChild(EntitySpec.create(TomcatServer.class) - .configure(UsesJmx.JMX_AGENT_MODE, UsesJmx.JmxAgentModes.JMX_RMI_CUSTOM_AGENT) - .configure(UsesJmx.JMX_PORT, PortRanges.fromString("11099+")) - .configure(UsesJmx.RMI_REGISTRY_PORT, PortRanges.fromString("9001+")) - .configure(JavaWebAppService.ROOT_WAR, "classpath://cumulusrdf.war") - .configure(UsesJava.JAVA_SYSPROPS, MutableMap.of("cumulusrdf.config-file", "/tmp/cumulus.yaml"))); - - // Add an effector to tomcat to reconfigure with a new YAML config file - ((EntityInternal) webapp).getMutableEntityType().addEffector(cumulusConfig, new EffectorBody() { - @Override - public Void call(ConfigBag parameters) { - // Process the YAML template given in the application config - String url = Entities.getRequiredUrlConfig(CumulusRDFApplication.this, CUMULUS_RDF_CONFIG_URL); - Map config = MutableMap.of("cassandraHostname", endpoint.getHostText(), "cassandraThriftPort", endpoint.getPort()); - String contents = TemplateProcessor.processTemplateContents(ResourceUtils.create(CumulusRDFApplication.this).getResourceAsString(url), config); - - // Copy the file contents to the remote machine - return DynamicTasks.queue(SshEffectorTasks.put("/tmp/cumulus.yaml").contents(contents)).get(); - } - }); - - // Listen for HOSTNAME changes from the Cassandra fabric to show at least one node is available - subscribe(cassandra, CassandraCluster.HOSTNAME, new SensorEventListener() { - @Override - public void onEvent(SensorEvent event) { - if (Strings.isNonBlank(event.getValue())) { - synchronized (endpoint) { - String hostname = Entities.submit(CumulusRDFApplication.this, DependentConfiguration.attributeWhenReady(cassandra, CassandraCluster.HOSTNAME)).getUnchecked(); - Integer thriftPort = Entities.submit(CumulusRDFApplication.this, DependentConfiguration.attributeWhenReady(cassandra, CassandraCluster.THRIFT_PORT)).getUnchecked(); - HostAndPort current = HostAndPort.fromParts(hostname, thriftPort); - - // Check if the cluster access point has changed - if (!current.equals(endpoint)) { - log.info("Setting cluster endpoint to {}", current.toString()); - endpoint = current; - - // Reconfigure the CumulusRDF application and restart tomcat if necessary - webapp.invoke(cumulusConfig, MutableMap.of()); - if (webapp.getAttribute(Startable.SERVICE_UP)) { - webapp.restart(); - } - } - } - } - } - }); - } - - /** - * Controls the startup locations for the webapp and the cassandra fabric. - * - * @see AbstractApplication#start(Collection) - */ - @Override - public void start(Collection locations) { - addLocations(locations); - - // The web application only needs to run in one location, use the first - // TODO use a multi-region web cluster - Collection first = MutableList.copyOf(Iterables.limit(locations, 1)); - - setAttribute(Attributes.SERVICE_STATE, Lifecycle.STARTING); - try { - Entities.invokeEffector(this, cassandra, Startable.START, MutableMap.of("locations", locations)).getUnchecked(); - Entities.invokeEffector(this, webapp, Startable.START, MutableMap.of("locations", first)).getUnchecked(); - } catch (Exception e) { - setAttribute(Attributes.SERVICE_STATE, Lifecycle.ON_FIRE); - throw Exceptions.propagate(e); - } - setAttribute(SERVICE_UP, true); - setAttribute(Attributes.SERVICE_STATE, Lifecycle.RUNNING); - - log.info("Started CumulusRDF in " + locations); - } - - - public static void main(String[] argv) { - List args = Lists.newArrayList(argv); - String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+"); - String location = CommandLineUtil.getCommandLineOption(args, "--location", DEFAULT_LOCATIONS); - - BrooklynLauncher launcher = BrooklynLauncher.newInstance() - .application(EntitySpec.create(StartableApplication.class, CumulusRDFApplication.class).displayName("CumulusRDF application using Cassandra")) - .webconsolePort(port) - .location(location) - .start(); - - Entities.dumpInfo(launcher.getApplications()); - } -} diff --git a/simple-nosql-cluster/src/main/java/brooklyn/demo/HighAvailabilityCassandraCluster.java b/simple-nosql-cluster/src/main/java/brooklyn/demo/HighAvailabilityCassandraCluster.java deleted file mode 100644 index cdb4926..0000000 --- a/simple-nosql-cluster/src/main/java/brooklyn/demo/HighAvailabilityCassandraCluster.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2012-2013 by Cloudsoft Corp. - * - * Licensed 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 brooklyn.demo; - -import java.util.List; - -import brooklyn.catalog.Catalog; -import brooklyn.catalog.CatalogConfig; -import brooklyn.config.ConfigKey; -import brooklyn.entity.basic.ConfigKeys; -import brooklyn.entity.basic.AbstractApplication; -import brooklyn.entity.basic.Entities; -import brooklyn.entity.basic.StartableApplication; -import brooklyn.entity.nosql.cassandra.CassandraCluster; -import brooklyn.entity.nosql.cassandra.CassandraNode; -import brooklyn.entity.proxying.EntitySpec; -import brooklyn.launcher.BrooklynLauncher; -import brooklyn.policy.PolicySpec; -import brooklyn.policy.ha.ServiceFailureDetector; -import brooklyn.policy.ha.ServiceReplacer; -import brooklyn.policy.ha.ServiceRestarter; -import brooklyn.util.CommandLineUtil; - -import com.google.common.collect.Lists; - -@Catalog(name="HA Cassandra Cluster Application", description="Deploy a Cassandra cluster with a High Availability architecture.") -public class HighAvailabilityCassandraCluster extends AbstractApplication { - - public static final String DEFAULT_LOCATION_SPEC = "aws-ec2:us-east-1"; - - @CatalogConfig(label="Number of Availability Zones", priority=1) - public static final ConfigKey NUM_AVAILABILITY_ZONES = ConfigKeys.newConfigKey( - "cassandra.cluster.numAvailabilityZones", "Number of availability zones to spread the cluster across", 3); - - @CatalogConfig(label="Initial Cluster Size", priority=2) - public static final ConfigKey CASSANDRA_CLUSTER_SIZE = ConfigKeys.newConfigKey( - "cassandra.cluster.initialSize", "Initial size of the Cassandra cluster", 6); - - - @Override - public void init() { - addChild(EntitySpec.create(CassandraCluster.class) - .configure(CassandraCluster.CLUSTER_NAME, "Brooklyn") - .configure(CassandraCluster.INITIAL_SIZE, getConfig(CASSANDRA_CLUSTER_SIZE)) - .configure(CassandraCluster.ENABLE_AVAILABILITY_ZONES, true) - .configure(CassandraCluster.NUM_AVAILABILITY_ZONES, getConfig(NUM_AVAILABILITY_ZONES)) - //See https://github.com/brooklyncentral/brooklyn/issues/973 - //.configure(CassandraCluster.AVAILABILITY_ZONE_NAMES, ImmutableList.of("us-east-1b", "us-east-1c", "us-east-1e")) - .configure(CassandraCluster.ENDPOINT_SNITCH_NAME, "GossipingPropertyFileSnitch") - .configure(CassandraCluster.MEMBER_SPEC, EntitySpec.create(CassandraNode.class) - .policy(PolicySpec.create(ServiceFailureDetector.class)) - .policy(PolicySpec.create(ServiceRestarter.class) - .configure(ServiceRestarter.FAILURE_SENSOR_TO_MONITOR, ServiceFailureDetector.ENTITY_FAILED))) - .policy(PolicySpec.create(ServiceReplacer.class) - .configure(ServiceReplacer.FAILURE_SENSOR_TO_MONITOR, ServiceRestarter.ENTITY_RESTART_FAILED))); - } - - public static void main(String[] argv) { - List args = Lists.newArrayList(argv); - String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+"); - String location = CommandLineUtil.getCommandLineOption(args, "--location", DEFAULT_LOCATION_SPEC); - - BrooklynLauncher launcher = BrooklynLauncher.newInstance() - .application(EntitySpec.create(StartableApplication.class, HighAvailabilityCassandraCluster.class) - .displayName("Cassandra")) - .webconsolePort(port) - .location(location) - .start(); - - Entities.dumpInfo(launcher.getApplications()); - } -} diff --git a/simple-nosql-cluster/src/main/java/brooklyn/demo/SimpleCassandraCluster.java b/simple-nosql-cluster/src/main/java/brooklyn/demo/SimpleCassandraCluster.java deleted file mode 100644 index 83c7d61..0000000 --- a/simple-nosql-cluster/src/main/java/brooklyn/demo/SimpleCassandraCluster.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2012-2013 by Cloudsoft Corp. - * - * Licensed 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 brooklyn.demo; - -import java.util.List; - -import brooklyn.entity.basic.AbstractApplication; -import brooklyn.entity.basic.Entities; -import brooklyn.entity.basic.StartableApplication; -import brooklyn.entity.nosql.cassandra.CassandraCluster; -import brooklyn.entity.proxying.EntitySpec; -import brooklyn.launcher.BrooklynLauncher; -import brooklyn.util.CommandLineUtil; - -import com.google.common.collect.Lists; - -public class SimpleCassandraCluster extends AbstractApplication { - - private static final String DEFAULT_LOCATION = "localhost"; - - @Override - public void init() { - addChild(EntitySpec.create(CassandraCluster.class) - .configure(CassandraCluster.INITIAL_SIZE, 1) - .configure(CassandraCluster.CLUSTER_NAME, "Brooklyn")); - } - - public static void main(String[] argv) { - List args = Lists.newArrayList(argv); - String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+"); - String location = CommandLineUtil.getCommandLineOption(args, "--location", DEFAULT_LOCATION); - - BrooklynLauncher launcher = BrooklynLauncher.newInstance() - .application(EntitySpec.create(StartableApplication.class, SimpleCassandraCluster.class) - .displayName("Cassandra")) - .webconsolePort(port) - .location(location) - .start(); - - Entities.dumpInfo(launcher.getApplications()); - } -} diff --git a/simple-nosql-cluster/src/main/java/brooklyn/demo/SimpleCouchDBCluster.java b/simple-nosql-cluster/src/main/java/brooklyn/demo/SimpleCouchDBCluster.java deleted file mode 100644 index 80bfb7e..0000000 --- a/simple-nosql-cluster/src/main/java/brooklyn/demo/SimpleCouchDBCluster.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2012-2013 by Cloudsoft Corp. - * - * Licensed 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 brooklyn.demo; - -import brooklyn.entity.basic.ApplicationBuilder; -import brooklyn.entity.nosql.couchdb.CouchDBCluster; -import brooklyn.entity.proxying.EntitySpec; - -/** CouchDB cluster. */ -public class SimpleCouchDBCluster extends ApplicationBuilder { - - /** Create entities. */ - protected void doBuild() { - addChild(EntitySpec.create(CouchDBCluster.class) - .configure("initialSize", "2") - .configure("clusterName", "Brooklyn") - .configure("httpPort", "8000+")); - } - -} diff --git a/simple-nosql-cluster/src/main/java/brooklyn/demo/SimpleMongoDBReplicaSet.java b/simple-nosql-cluster/src/main/java/brooklyn/demo/SimpleMongoDBReplicaSet.java deleted file mode 100644 index 98eb7dd..0000000 --- a/simple-nosql-cluster/src/main/java/brooklyn/demo/SimpleMongoDBReplicaSet.java +++ /dev/null @@ -1,24 +0,0 @@ -package brooklyn.demo; - -import brooklyn.entity.basic.ApplicationBuilder; -import brooklyn.entity.nosql.mongodb.MongoDBReplicaSet; -import brooklyn.entity.nosql.mongodb.MongoDBServer; -import brooklyn.entity.proxying.EntitySpec; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SimpleMongoDBReplicaSet extends ApplicationBuilder { - - protected void doBuild() { - addChild(EntitySpec.create(MongoDBReplicaSet.class) - .configure("name", "Simple MongoDB replica set") - .configure("initialSize", 3) - .configure("replicaSetName", "simple-replica-set") - .configure("memberSpec", EntitySpec.create(MongoDBServer.class) - .configure("mongodbConfTemplateUrl", "classpath:///mongodb.conf") - .configure("enableRestInterface", true) - .configure("port", "27017+"))); - } - -} diff --git a/simple-nosql-cluster/src/main/java/brooklyn/demo/SimpleRedisCluster.java b/simple-nosql-cluster/src/main/java/brooklyn/demo/SimpleRedisCluster.java deleted file mode 100644 index f2ccfe1..0000000 --- a/simple-nosql-cluster/src/main/java/brooklyn/demo/SimpleRedisCluster.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2012-2013 by Cloudsoft Corp. - * - * Licensed 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 brooklyn.demo; - -import brooklyn.entity.basic.ApplicationBuilder; -import brooklyn.entity.nosql.redis.RedisCluster; -import brooklyn.entity.proxying.EntitySpec; - -/** Redis cluster. */ -public class SimpleRedisCluster extends ApplicationBuilder { - - /** Create entities. */ - protected void doBuild() { - addChild(EntitySpec.create(RedisCluster.class) - .configure("initialSize", "2") - .configure("clusterName", "Brooklyn")); - } - -} diff --git a/simple-nosql-cluster/src/main/java/brooklyn/demo/WideAreaCassandraCluster.java b/simple-nosql-cluster/src/main/java/brooklyn/demo/WideAreaCassandraCluster.java deleted file mode 100644 index 02a9451..0000000 --- a/simple-nosql-cluster/src/main/java/brooklyn/demo/WideAreaCassandraCluster.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2012-2013 by Cloudsoft Corp. - * - * Licensed 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 brooklyn.demo; - -import java.util.Arrays; -import java.util.List; - -import brooklyn.catalog.Catalog; -import brooklyn.catalog.CatalogConfig; -import brooklyn.config.ConfigKey; -import brooklyn.entity.basic.ConfigKeys; -import brooklyn.entity.basic.AbstractApplication; -import brooklyn.entity.basic.Entities; -import brooklyn.entity.basic.StartableApplication; -import brooklyn.entity.nosql.cassandra.CassandraCluster; -import brooklyn.entity.nosql.cassandra.CassandraFabric; -import brooklyn.entity.nosql.cassandra.CassandraNode; -import brooklyn.entity.proxying.EntitySpec; -import brooklyn.launcher.BrooklynLauncher; -import brooklyn.policy.PolicySpec; -import brooklyn.policy.ha.ServiceFailureDetector; -import brooklyn.policy.ha.ServiceReplacer; -import brooklyn.policy.ha.ServiceRestarter; -import brooklyn.util.CommandLineUtil; - -import com.google.common.collect.Lists; - -@Catalog(name="Wide Area Cassandra Cluster Application", description="Deploy a Cassandra cluster across multiple geographies.") -public class WideAreaCassandraCluster extends AbstractApplication { - - public static final String DEFAULT_LOCATION_SPEC = "aws-ec2:us-east-1,rackspace-cloudservers-uk"; - - @CatalogConfig(label="Initial Cluster Size (per location)", priority=2) - public static final ConfigKey CASSANDRA_CLUSTER_SIZE = ConfigKeys.newConfigKey( - "cassandra.cluster.initialSize", "Initial size of the Cassandra clusterss", 2); - - - - @Override - public void init() { - addChild(EntitySpec.create(CassandraFabric.class) - .configure(CassandraCluster.CLUSTER_NAME, "Brooklyn") - .configure(CassandraCluster.INITIAL_SIZE, getConfig(CASSANDRA_CLUSTER_SIZE)) // per location - .configure(CassandraCluster.ENDPOINT_SNITCH_NAME, "brooklyn.entity.nosql.cassandra.customsnitch.MultiCloudSnitch") - .configure(CassandraNode.CUSTOM_SNITCH_JAR_URL, "classpath://brooklyn/entity/nosql/cassandra/cassandra-multicloud-snitch.jar") - .configure(CassandraFabric.MEMBER_SPEC, EntitySpec.create(CassandraCluster.class) - .configure(CassandraCluster.MEMBER_SPEC, EntitySpec.create(CassandraNode.class) - .policy(PolicySpec.create(ServiceFailureDetector.class)) - .policy(PolicySpec.create(ServiceRestarter.class) - .configure(ServiceRestarter.FAILURE_SENSOR_TO_MONITOR, ServiceFailureDetector.ENTITY_FAILED))) - .policy(PolicySpec.create(ServiceReplacer.class) - .configure(ServiceReplacer.FAILURE_SENSOR_TO_MONITOR, ServiceRestarter.ENTITY_RESTART_FAILED)))); - } - - public static void main(String[] argv) { - List args = Lists.newArrayList(argv); - String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+"); - String locations = CommandLineUtil.getCommandLineOption(args, "--location", DEFAULT_LOCATION_SPEC); - - BrooklynLauncher launcher = BrooklynLauncher.newInstance() - .application(EntitySpec.create(StartableApplication.class, WideAreaCassandraCluster.class) - .displayName("Cassandra")) - .webconsolePort(port) - .locations(Arrays.asList(locations)) - .start(); - - Entities.dumpInfo(launcher.getApplications()); - } -} diff --git a/simple-nosql-cluster/src/main/resources/cumulus.yaml b/simple-nosql-cluster/src/main/resources/cumulus.yaml deleted file mode 100644 index bf6c38c..0000000 --- a/simple-nosql-cluster/src/main/resources/cumulus.yaml +++ /dev/null @@ -1,8 +0,0 @@ -[#ftl] -storage-layout: "flat" -cassandra-hosts: "${cassandraHostname}:${cassandraThriftPort?c}" -cassandra-keyspace: "KeyspaceCumulus" -proxy-mode: "false" -triples-subject: -1 -triples-object: 5000 -query-limit: 50000 \ No newline at end of file diff --git a/simple-nosql-cluster/src/main/resources/cumulusrdf-0.6.1-pre.jar b/simple-nosql-cluster/src/main/resources/cumulusrdf-0.6.1-pre.jar deleted file mode 100644 index ab97408..0000000 Binary files a/simple-nosql-cluster/src/main/resources/cumulusrdf-0.6.1-pre.jar and /dev/null differ diff --git a/simple-nosql-cluster/src/main/resources/cumulusrdf.war b/simple-nosql-cluster/src/main/resources/cumulusrdf.war deleted file mode 100644 index 04a0a6f..0000000 Binary files a/simple-nosql-cluster/src/main/resources/cumulusrdf.war and /dev/null differ diff --git a/simple-nosql-cluster/src/main/resources/mongodb.conf b/simple-nosql-cluster/src/main/resources/mongodb.conf deleted file mode 100644 index b0c88f2..0000000 --- a/simple-nosql-cluster/src/main/resources/mongodb.conf +++ /dev/null @@ -1,13 +0,0 @@ -# MongoDB configuration file - -# Startup configuration. -verbose = true - -# Use less disk space. -smallfiles = true - -# Disable journalling. By default: -# - journal is false on 32 and true on 64 bit systems. -# - nojournal is true on 32 and false on 64 bit systems. -journal = false -nojournal = true \ No newline at end of file diff --git a/simple-open-loop-policy/README.txt b/simple-open-loop-policy/README.txt deleted file mode 100644 index 65fb390..0000000 --- a/simple-open-loop-policy/README.txt +++ /dev/null @@ -1,55 +0,0 @@ -Instructions for Running Examples -================================= - -The commands below assume that the `brooklyn` script is on your $PATH, this project has been built, -and you are in this directory. Adjust to taste for other configurations. - - export BROOKLYN_CLASSPATH=$(pwd)/target/classes - - # Three-tier: auto-scaling app-server cluster fronted by nginx, MySql backend wired up, on localhost - brooklyn launch --app brooklyn.demo.WebClusterDatabaseOpenLoopExample --location localhost - -The above requires passwordless `ssh localhost` and requires `gcc` to build `nginx`. -You could instead target your favourite cloud, where this has been tried and tested: - - -Redistributable embedded example: - - # To build a redistributable tar.gz with a start.sh script - # which invokes the `main` method in the example class to start - # (the redistributable will be at: target/brooklyn-*-bin.tar.gz ) - mvn clean assembly:assembly - -For more information, please visit: - - http://brooklyncentral.github.com/use/examples/webcluster/ - - -Developer Notes -=============== - -This example sends an SMS message when the cluster has reached its max size (and where the auto-scaler policy -would continue to increase the size if it were not capped). The message is sent using clickatell.com, -using http://smsj.sourceforge.net. - -Because smsj is not available on maven central, a custom local maven repo has been built (and checked in to git): - - wget http://sourceforge.net/projects/smsj/files/smsj/smsj-snapshot-20051126/smsj-20051126.jar/download - - mvn org.apache.maven.plugins:maven-install-plugin:2.3.1:install-file \ - -Dfile=smsj-20051126.jar \ - -DgroupId=io.brooklyn \ - -DartifactId=org.marre.smsj \ - -Dversion=1.0.0-20051126 \ - -Dpackaging=jar \ - -DlocalRepositoryPath=localrepo - -And in the pom, this local repo is referenced: - - - - brooklyn-examples-localrepo - file://${basedir}/localrepo - - - diff --git a/simple-open-loop-policy/localrepo/io/brooklyn/org.marre.smsj/1.0.0-20051126/org.marre.smsj-1.0.0-20051126.jar b/simple-open-loop-policy/localrepo/io/brooklyn/org.marre.smsj/1.0.0-20051126/org.marre.smsj-1.0.0-20051126.jar deleted file mode 100644 index a076a47..0000000 Binary files a/simple-open-loop-policy/localrepo/io/brooklyn/org.marre.smsj/1.0.0-20051126/org.marre.smsj-1.0.0-20051126.jar and /dev/null differ diff --git a/simple-open-loop-policy/localrepo/io/brooklyn/org.marre.smsj/1.0.0-20051126/org.marre.smsj-1.0.0-20051126.pom b/simple-open-loop-policy/localrepo/io/brooklyn/org.marre.smsj/1.0.0-20051126/org.marre.smsj-1.0.0-20051126.pom deleted file mode 100644 index 7361303..0000000 --- a/simple-open-loop-policy/localrepo/io/brooklyn/org.marre.smsj/1.0.0-20051126/org.marre.smsj-1.0.0-20051126.pom +++ /dev/null @@ -1,9 +0,0 @@ - - - 4.0.0 - io.brooklyn - org.marre.smsj - 1.0.0-20051126 - POM was created from install:install-file - diff --git a/simple-open-loop-policy/localrepo/io/brooklyn/org.marre.smsj/maven-metadata-local.xml b/simple-open-loop-policy/localrepo/io/brooklyn/org.marre.smsj/maven-metadata-local.xml deleted file mode 100644 index 4611327..0000000 --- a/simple-open-loop-policy/localrepo/io/brooklyn/org.marre.smsj/maven-metadata-local.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - io.brooklyn - org.marre.smsj - - 1.0.0-20051126 - - 1.0.0-20051126 - - 20130206095028 - - diff --git a/simple-open-loop-policy/pom.xml b/simple-open-loop-policy/pom.xml deleted file mode 100644 index 490de07..0000000 --- a/simple-open-loop-policy/pom.xml +++ /dev/null @@ -1,133 +0,0 @@ - - 4.0.0 - jar - brooklyn-example-simple-open-loop-policy - Brooklyn Simple Web Cluster Example - - - - io.brooklyn.example - brooklyn-examples-parent - 0.6.0 - ../pom.xml - - - - - brooklyn-examples-localrepo - file://${basedir}/localrepo - - - - - - io.brooklyn - org.marre.smsj - 1.0.0-20051126 - - - io.brooklyn - brooklyn-all - ${project.version} - - - io.brooklyn - brooklyn-logback-xml - ${project.version} - true - - - - io.brooklyn - brooklyn-test-support - ${project.version} - test - - - - - - - maven-dependency-plugin - - - - copy - process-classes - - copy - - - - - - ${project.groupId} - brooklyn-example-hello-world-webapp - ${project.version} - war - true - target/classes - hello-world-webapp.war - - - ${project.groupId} - brooklyn-example-hello-world-sql-webapp - ${project.version} - war - true - target/classes - hello-world-sql-webapp.war - - - - - - - - - maven-clean-plugin - - - - ${project.basedir} - - ${project.artifactId}/ - brooklyn*.log - brooklyn*.log.* - stacktrace.log - - - - - - - - - - - - - diff --git a/simple-open-loop-policy/resources/jmeter-test-plan.jmx b/simple-open-loop-policy/resources/jmeter-test-plan.jmx deleted file mode 100644 index 5487b8f..0000000 --- a/simple-open-loop-policy/resources/jmeter-test-plan.jmx +++ /dev/null @@ -1,125 +0,0 @@ - - - - - - false - false - - - - - - - - continue - - false - -1 - - 8 - 1 - 1326116677000 - 1326116677000 - false - - - - - - 20 - - - - - - - localhost - 8000 - - - - - - GET - true - false - true - false - false - - - - - - false - - - - - false - - saveConfig - - - true - true - true - - true - true - true - true - false - true - true - false - false - true - false - false - false - false - false - 0 - true - - - - - - - false - - saveConfig - - - true - true - true - - true - true - true - true - false - true - true - false - false - true - false - false - false - false - false - 0 - true - - - - - - - - diff --git a/simple-open-loop-policy/src/main/java/brooklyn/demo/Sms.java b/simple-open-loop-policy/src/main/java/brooklyn/demo/Sms.java deleted file mode 100644 index abaa506..0000000 --- a/simple-open-loop-policy/src/main/java/brooklyn/demo/Sms.java +++ /dev/null @@ -1,45 +0,0 @@ -package brooklyn.demo; - -import java.io.IOException; - -import org.marre.SmsSender; -import org.marre.sms.SmsException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class Sms { - - private static final Logger LOG = LoggerFactory.getLogger(Sms.class); - - private final String username; - private final String password; - private final String apiid; - private final String sender; - - public Sms(String username, String password, String apiid) { - this.username = username; - this.password = password; - this.apiid = apiid; - this.sender = null; - } - - /** - * - * @param receiver International number to reciever without leading "+" - * @param msg The message that you want to send - * @throws IOException - * @throws SmsException - */ - public void sendSms(String receiver, String msg) throws SmsException, IOException { - // Send SMS with clickatell - SmsSender smsSender = SmsSender.getClickatellSender(username, password, apiid); - - smsSender.connect(); - try { - String msgid = smsSender.sendTextSms(msg, receiver, sender); - LOG.debug("Sent SMS via {}@clickatell to {}, msg {}; id {}", new Object[] {username, receiver, msg, msgid}); - } finally { - smsSender.disconnect(); - } - } -} diff --git a/simple-open-loop-policy/src/main/java/brooklyn/demo/WebClusterDatabaseOpenLoopExample.java b/simple-open-loop-policy/src/main/java/brooklyn/demo/WebClusterDatabaseOpenLoopExample.java deleted file mode 100644 index 2c96ec6..0000000 --- a/simple-open-loop-policy/src/main/java/brooklyn/demo/WebClusterDatabaseOpenLoopExample.java +++ /dev/null @@ -1,140 +0,0 @@ -package brooklyn.demo; - -import static brooklyn.entity.java.JavaEntityMethods.javaSysProp; -import static brooklyn.event.basic.DependentConfiguration.attributeWhenReady; -import static brooklyn.event.basic.DependentConfiguration.formatString; - -import java.io.IOException; -import java.util.List; - -import org.marre.sms.SmsException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import brooklyn.enricher.basic.SensorPropagatingEnricher; -import brooklyn.enricher.basic.SensorTransformingEnricher; -import brooklyn.entity.basic.ApplicationBuilder; -import brooklyn.entity.basic.Entities; -import brooklyn.entity.basic.StartableApplication; -import brooklyn.entity.database.mysql.MySqlNode; -import brooklyn.entity.proxying.EntitySpecs; -import brooklyn.entity.webapp.ControlledDynamicWebAppCluster; -import brooklyn.entity.webapp.DynamicWebAppCluster; -import brooklyn.entity.webapp.JavaWebAppService; -import brooklyn.entity.webapp.WebAppService; -import brooklyn.entity.webapp.WebAppServiceConstants; -import brooklyn.event.SensorEvent; -import brooklyn.event.SensorEventListener; -import brooklyn.event.basic.BasicAttributeSensor; -import brooklyn.event.basic.BasicNotificationSensor; -import brooklyn.launcher.BrooklynLauncher; -import brooklyn.launcher.BrooklynServerDetails; -import brooklyn.location.Location; -import brooklyn.location.basic.PortRanges; -import brooklyn.policy.autoscaling.AutoScalerPolicy; -import brooklyn.policy.autoscaling.MaxPoolSizeReachedEvent; -import brooklyn.util.CommandLineUtil; - -import com.google.common.base.Functions; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; - -/** - * Launches a 3-tier app with nginx, clustered jboss, and mysql. - **/ -public class WebClusterDatabaseOpenLoopExample extends ApplicationBuilder { - - public static final Logger LOG = LoggerFactory.getLogger(WebClusterDatabaseOpenLoopExample.class); - - public static final String WAR_PATH = "classpath://hello-world-sql-webapp.war"; - - public static final String DB_SETUP_SQL_URL = "classpath://visitors-creation-script.sql"; - - public static final String DB_TABLE = "visitors"; - public static final String DB_USERNAME = "brooklyn"; - public static final String DB_PASSWORD = "br00k11n"; - - // TODO Replace these with your details, for a clickatell.com account that has credit to send SMS messages - public static final String CLICKATELL_USERNAME = "brooklyndemo.uk"; - public static final String CLICKATELL_PASSWORD = "NAYLLHRLZEBYYA"; - public static final String CLICKATELL_APIID = "3411519"; - public static final String SMS_RECEIVER = "441234567890"; - - public static final BasicAttributeSensor APPSERVERS_COUNT = Sensors.newIntegerSensor( - "appservers.count", "Number of app servers deployed"); - - public static final BasicNotificationSensor MAX_SIZE_REACHED = new BasicNotificationSensor( - MaxPoolSizeReachedEvent.class, "cluster.maxPoolSizeReached", ""); - - protected void doBuild() { - MySqlNode mysql = addChild(EntitySpec.create(MySqlNode.class) - .configure("creationScriptUrl", DB_SETUP_SQL_URL)); - - ControlledDynamicWebAppCluster web = addChild(EntitySpec.create(ControlledDynamicWebAppCluster.class) - .configure(WebAppService.HTTP_PORT, PortRanges.fromString("8080+")) - .configure(JavaWebAppService.ROOT_WAR, WAR_PATH) - .configure(javaSysProp("brooklyn.example.db.url"), - formatString("jdbc:%s%s?user=%s\\&password=%s", - attributeWhenReady(mysql, MySqlNode.MYSQL_URL), - DB_TABLE, DB_USERNAME, DB_PASSWORD))); - - // Subscribe not notifications about the auto-scaler policy reaching its max cluster size - getManagementContext().getSubscriptionManager().subscribe( - web.getCluster(), - MAX_SIZE_REACHED, - new SensorEventListener() { - @Override public void onEvent(SensorEvent event) { - onMaxPoolSizeReached(event.getValue()); - } - }); - - // simple scaling policy - web.getCluster().addPolicy(AutoScalerPolicy.builder(). - metric(DynamicWebAppCluster.REQUESTS_PER_SECOND_IN_WINDOW_PER_NODE). - metricRange(10, 100). - sizeRange(1, 5). - maxSizeReachedSensor(MAX_SIZE_REACHED). -// maxReachedNotificationDelay(1000). - build()); - - // expose some KPI's - getApp().addEnricher(SensorPropagatingEnricher.newInstanceListeningTo(web, - WebAppServiceConstants.ROOT_URL, - DynamicWebAppCluster.REQUESTS_PER_SECOND_IN_WINDOW)); - getApp().addEnricher(new SensorTransformingEnricher(web, - DynamicWebAppCluster.GROUP_SIZE, APPSERVERS_COUNT, Functions.identity())); - } - - private void onMaxPoolSizeReached(MaxPoolSizeReachedEvent event) { - String msg = "Max-pool-size-reached: "+event; - System.out.println("*** "+msg); - - try { - new Sms(CLICKATELL_USERNAME, CLICKATELL_PASSWORD, CLICKATELL_APIID).sendSms(SMS_RECEIVER, msg); - } catch (SmsException e) { - LOG.warn("Error sending SMS message: "+e.getMessage(), e); - } catch (IOException e) { - LOG.warn("Error sending SMS message", e); - } - } - - public static void main(String[] argv) { - List args = Lists.newArrayList(argv); - String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+"); - String location = CommandLineUtil.getCommandLineOption(args, "--location", "localhost"); - - BrooklynServerDetails server = BrooklynLauncher.newLauncher() - .webconsolePort(port) - .launch(); - - Location loc = server.getManagementContext().getLocationRegistry().resolve(location); - - StartableApplication app = new WebClusterDatabaseOpenLoopExample() - .appDisplayName("Brooklyn WebApp Cluster with Database example") - .manage(server.getManagementContext()); - - app.start(ImmutableList.of(loc)); - - Entities.dumpInfo(app); - } -} diff --git a/simple-open-loop-policy/src/main/resources/visitors-creation-script.sql b/simple-open-loop-policy/src/main/resources/visitors-creation-script.sql deleted file mode 100644 index f3bdd4a..0000000 --- a/simple-open-loop-policy/src/main/resources/visitors-creation-script.sql +++ /dev/null @@ -1,17 +0,0 @@ -create database visitors; -use visitors; -create user 'brooklyn' identified by 'br00k11n'; -grant usage on *.* to 'brooklyn'@'%' identified by 'br00k11n'; -# ''@localhost is sometimes set up, overriding brooklyn@'%', so do a second explicit grant -grant usage on *.* to 'brooklyn'@'localhost' identified by 'br00k11n'; -grant all privileges on visitors.* to 'brooklyn'@'%'; -flush privileges; - -CREATE TABLE MESSAGES ( - id INT NOT NULL AUTO_INCREMENT, - NAME VARCHAR(30) NOT NULL, - MESSAGE VARCHAR(400) NOT NULL, - PRIMARY KEY (ID) - ); - -INSERT INTO MESSAGES values (default, 'Isaac Asimov', 'I grew up in Brooklyn' ); diff --git a/simple-open-loop-policy/src/test/java/brooklyn/demo/SmsTest.java b/simple-open-loop-policy/src/test/java/brooklyn/demo/SmsTest.java deleted file mode 100644 index 486fbcc..0000000 --- a/simple-open-loop-policy/src/test/java/brooklyn/demo/SmsTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package brooklyn.demo; - -import org.marre.sms.SmsException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.annotations.Test; - -public class SmsTest { - - private static final Logger LOG = LoggerFactory.getLogger(SmsTest.class); - - @Test(groups="Integration") - public void testSendSms() throws Exception { - // http://api.clickatell.com/http/sendmsg?user=brooklyndemo.uk&password=PASSWORD&api_id=3411519&to=447709428472&text=Message - // Note this account has *no* credit card details; sending a message will result in a standard message from Clickatell.com, - // rather than receiving the actual message body. - // - // TODO It's started failing with "Error 301, No Credit Left" - // How to commit something that passes but without exposing credit card details?! - Sms sender = new Sms("brooklyndemo.uk", "NAYLLHRLZEBYYA", "3411519"); - try { - sender.sendSms("447709428472", "test sms sent in brooklyn"); - } catch (SmsException e) { - if (e.toString().contains("Error 301, No Credit Left")) { - // fair enough; let's not fail the test for this reason - LOG.warn("Cannot test SMS because no credit left on account: "+e.toString()); - } else { - throw e; - } - } - } -} diff --git a/simple-web-cluster/.gitignore b/simple-web-cluster/.gitignore deleted file mode 100644 index 9a3d6d6..0000000 --- a/simple-web-cluster/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -brooklyn-example-simple-web-cluster/ -brooklyn-example-simple-web-cluster.tar.gz diff --git a/simple-web-cluster/README.txt b/simple-web-cluster/README.txt deleted file mode 100644 index 0b238a4..0000000 --- a/simple-web-cluster/README.txt +++ /dev/null @@ -1,44 +0,0 @@ -Instructions for Running Examples -================================= - -The commands below assume that the `brooklyn` script is on your $PATH, this project has been built, -and you are in this directory. Adjust to taste for other configurations. - - export BROOKLYN_CLASSPATH=$(pwd)/target/classes - - # Three-tier: auto-scaling app-server cluster fronted by nginx, MySql backend wired up, on localhost - brooklyn launch --app brooklyn.demo.WebClusterDatabaseExample --location localhost - -The above requires passwordless `ssh localhost` and requires `gcc` to build `nginx`. -You could instead target your favourite cloud, where this has been tried and tested: - - # Same three-tier, but in Amazon California, prompting for credentials - # (the location arg can be changed for any example, of course, and other clouds are available) - export JCLOUDS_AWS_EC2_IDENTITY=AKA50M30N3S1DFR0MAW55 - export JCLOUDS_AWS_EC2_CREDENTIAL=aT0Ps3cr3tC0D3wh1chAW5w1llG1V3y0uTOus333 - brooklyn launch --app brooklyn.demo.WebClusterDatabaseExample --location aws-ec2:us-west-1 - - -Other examples: - - # A very simple app: a single web-server - brooklyn launch --app brooklyn.demo.SingleWebServerExample --location localhost - - # A simple app: just load-balancer and appservers - brooklyn launch --app brooklyn.demo.WebClusterExample --location localhost - - # Three-tier example - brooklyn launch --app brooklyn.demo.WebClusterDatabaseExample --location localhost - - -Redistributable embedded example: - - # To build a redistributable tar.gz with a start.sh script - # which invokes the `main` method in the example class to start - # (the redistributable will be at: target/brooklyn-*-bin.tar.gz ) - mvn clean assembly:assembly - -For more information, please visit: - - http://brooklyncentral.github.com/use/examples/webcluster/ - diff --git a/simple-web-cluster/pom.xml b/simple-web-cluster/pom.xml deleted file mode 100644 index aef5bc0..0000000 --- a/simple-web-cluster/pom.xml +++ /dev/null @@ -1,109 +0,0 @@ - - 4.0.0 - jar - brooklyn-example-simple-web-cluster - Brooklyn Simple Web Cluster Example - - - - io.brooklyn.example - brooklyn-examples-parent - 0.6.0 - ../pom.xml - - - - - io.brooklyn - brooklyn-all - ${project.version} - - - io.brooklyn - brooklyn-logback-xml - ${project.version} - true - - - - - - - maven-dependency-plugin - - - - copy - process-classes - - copy - - - - - - ${project.groupId} - brooklyn-example-hello-world-webapp - ${project.version} - war - true - target/classes - hello-world-webapp.war - - - ${project.groupId} - brooklyn-example-hello-world-sql-webapp - ${project.version} - war - true - target/classes - hello-world-sql-webapp.war - - - - - - - - - maven-clean-plugin - - - - ${project.basedir} - - ${project.artifactId}/ - brooklyn*.log - brooklyn*.log.* - stacktrace.log - - - - - - - - org.apache.maven.plugins - maven-assembly-plugin - - - src/main/assembly/assembly.xml - - - - - - - diff --git a/simple-web-cluster/resources/jmeter-test-plan.jmx b/simple-web-cluster/resources/jmeter-test-plan.jmx deleted file mode 100644 index 5487b8f..0000000 --- a/simple-web-cluster/resources/jmeter-test-plan.jmx +++ /dev/null @@ -1,125 +0,0 @@ - - - - - - false - false - - - - - - - - continue - - false - -1 - - 8 - 1 - 1326116677000 - 1326116677000 - false - - - - - - 20 - - - - - - - localhost - 8000 - - - - - - GET - true - false - true - false - false - - - - - - false - - - - - false - - saveConfig - - - true - true - true - - true - true - true - true - false - true - true - false - false - true - false - false - false - false - false - 0 - true - - - - - - - false - - saveConfig - - - true - true - true - - true - true - true - true - false - true - true - false - false - true - false - false - false - false - false - 0 - true - - - - - - - - diff --git a/simple-web-cluster/src/main/assembly/assembly.xml b/simple-web-cluster/src/main/assembly/assembly.xml deleted file mode 100644 index 678879a..0000000 --- a/simple-web-cluster/src/main/assembly/assembly.xml +++ /dev/null @@ -1,55 +0,0 @@ - - bin - - - tar.gz - - - - - - - false - lib - false - - - - - - - src/main/assembly/scripts - - 0755 - - * - - - - - src/main/assembly/files - - - * - - - - - target - - - *.jar - - - - - diff --git a/simple-web-cluster/src/main/assembly/files/README.txt b/simple-web-cluster/src/main/assembly/files/README.txt deleted file mode 100644 index 889760b..0000000 --- a/simple-web-cluster/src/main/assembly/files/README.txt +++ /dev/null @@ -1,31 +0,0 @@ -Brooklyn Example -================ - -To use, configure your cloud credentials then run ./start.sh in this directory. -You can then access the management context in your browser, typically on localhost:8081. - - -### Cloud Credentials - -To run, you'll need to specify credentials for your preferred cloud. This can be done -in `~/.brooklyn/brooklyn.properties`: - - brooklyn.jclouds.aws-ec2.identity=AKXXXXXXXXXXXXXXXXXX - brooklyn.jclouds.aws-ec2.credential=secret01xxxxxxxxxxxxxxxxxxxxxxxxxxx - -Alternatively these can be set as shell environment parameters or JVM system properties. - -Many other clouds are supported also, as well as pre-existing machines ("bring your own nodes"), -custom endpoints for private clouds, and specifying custom keys and passphrases. -For more information see: - - https://github.com/brooklyncentral/brooklyn/blob/master/docs/use/guide/defining-applications/common-usage.md#off-the-shelf-locations - - -### Run - -Usage: - - ./start.sh [--port 8081+] location - -Where location might be `localhost` (the defaul), or `aws-ec2:us-east-1`, `openstack:endpoint`, etc. diff --git a/simple-web-cluster/src/main/assembly/scripts/start.sh b/simple-web-cluster/src/main/assembly/scripts/start.sh deleted file mode 100755 index 8d27b39..0000000 --- a/simple-web-cluster/src/main/assembly/scripts/start.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -if [ -z "$BROOKLYN_APP_CLASS" ] ; then - BROOKLYN_APP_CLASS=brooklyn.demo.WebClusterDatabaseExample -fi - -if [ -z "$JAVA" ] ; then - JAVA=`which java` -fi -if [ ! -z "$JAVA_HOME" ] ; then - JAVA=$JAVA_HOME/bin/java -else - JAVA=`which java` -fi -if [ ! -x "$JAVA" ] ; then - echo Cannot find java. Set JAVA_HOME or add java to path. - exit 1 -fi - -if [[ ! `ls *.jar 2> /dev/null` || ! `ls lib/*.jar 2> /dev/null` ]] ; then - echo Command must be run from the directory where it is installed. - exit 1 -fi - -$JAVA -Xms256m -Xmx1024m -XX:MaxPermSize=1024m -classpath "*:lib/*" $BROOKLYN_APP_CLASS "$@" diff --git a/simple-web-cluster/src/main/java/brooklyn/demo/SingleWebServerExample.java b/simple-web-cluster/src/main/java/brooklyn/demo/SingleWebServerExample.java deleted file mode 100644 index 9e290ef..0000000 --- a/simple-web-cluster/src/main/java/brooklyn/demo/SingleWebServerExample.java +++ /dev/null @@ -1,49 +0,0 @@ -package brooklyn.demo; - -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import brooklyn.entity.basic.AbstractApplication; -import brooklyn.entity.basic.Attributes; -import brooklyn.entity.basic.Entities; -import brooklyn.entity.proxying.EntitySpec; -import brooklyn.entity.proxying.EntitySpecs; -import brooklyn.entity.webapp.JavaWebAppService; -import brooklyn.entity.webapp.jboss.JBoss7Server; -import brooklyn.launcher.BrooklynLauncher; -import brooklyn.location.basic.PortRanges; -import brooklyn.util.CommandLineUtil; - -import com.google.common.collect.Lists; - -/** This example starts one web app on 8080, waits for a keypress, then stops it. */ -public class SingleWebServerExample extends AbstractApplication { - - public static final Logger LOG = LoggerFactory.getLogger(SingleWebServerExample.class); - - private static final String WAR_PATH = "classpath://hello-world-webapp.war"; - - @Override - public void init() { - addChild(EntitySpec.create(JBoss7Server.class) - .configure(JavaWebAppService.ROOT_WAR, WAR_PATH) - .configure(Attributes.HTTP_PORT, PortRanges.fromString("8080+"))); - } - - // Shows how to use ApplicationBuilder without sub-classing, but for CLI usage one should sub-class - public static void main(String[] argv) throws Exception { - List args = Lists.newArrayList(argv); - String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+"); - String location = CommandLineUtil.getCommandLineOption(args, "--location", "localhost"); - - BrooklynLauncher launcher = BrooklynLauncher.newInstance() - .application(EntitySpecs.appSpec(SingleWebServerExample.class).displayName("Brooklyn WebApp example")) - .webconsolePort(port) - .location(location) - .start(); - - Entities.dumpInfo(launcher.getApplications()); - } -} diff --git a/simple-web-cluster/src/main/java/brooklyn/demo/WebClusterDatabaseExample.java b/simple-web-cluster/src/main/java/brooklyn/demo/WebClusterDatabaseExample.java deleted file mode 100644 index 695012f..0000000 --- a/simple-web-cluster/src/main/java/brooklyn/demo/WebClusterDatabaseExample.java +++ /dev/null @@ -1,101 +0,0 @@ -package brooklyn.demo; - -import static brooklyn.entity.java.JavaEntityMethods.javaSysProp; -import static brooklyn.event.basic.DependentConfiguration.attributeWhenReady; -import static brooklyn.event.basic.DependentConfiguration.formatString; - -import java.util.List; -import java.util.concurrent.TimeUnit; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import brooklyn.enricher.HttpLatencyDetector; -import brooklyn.enricher.basic.SensorPropagatingEnricher; -import brooklyn.enricher.basic.SensorTransformingEnricher; -import brooklyn.entity.basic.AbstractApplication; -import brooklyn.entity.basic.Entities; -import brooklyn.entity.basic.StartableApplication; -import brooklyn.entity.database.mysql.MySqlNode; -import brooklyn.entity.proxying.EntitySpec; -import brooklyn.entity.webapp.ControlledDynamicWebAppCluster; -import brooklyn.entity.webapp.DynamicWebAppCluster; -import brooklyn.entity.webapp.JavaWebAppService; -import brooklyn.entity.webapp.WebAppService; -import brooklyn.entity.webapp.WebAppServiceConstants; -import brooklyn.event.AttributeSensor; -import brooklyn.event.basic.Sensors; -import brooklyn.launcher.BrooklynLauncher; -import brooklyn.location.basic.PortRanges; -import brooklyn.policy.autoscaling.AutoScalerPolicy; -import brooklyn.util.CommandLineUtil; - -import com.google.common.base.Functions; -import com.google.common.collect.Lists; - -/** - * Launches a 3-tier app with nginx, clustered jboss, and mysql. - **/ -public class WebClusterDatabaseExample extends AbstractApplication { - - public static final Logger LOG = LoggerFactory.getLogger(WebClusterDatabaseExample.class); - - public static final String WAR_PATH = "classpath://hello-world-sql-webapp.war"; - - public static final String DB_SETUP_SQL_URL = "classpath://visitors-creation-script.sql"; - - public static final String DB_TABLE = "visitors"; - public static final String DB_USERNAME = "brooklyn"; - public static final String DB_PASSWORD = "br00k11n"; - - public static final AttributeSensor APPSERVERS_COUNT = Sensors.newIntegerSensor( - "appservers.count", "Number of app servers deployed"); - - @Override - public void init() { - MySqlNode mysql = addChild(EntitySpec.create(MySqlNode.class) - .configure("creationScriptUrl", DB_SETUP_SQL_URL)); - - ControlledDynamicWebAppCluster web = addChild(EntitySpec.create(ControlledDynamicWebAppCluster.class) - .configure(WebAppService.HTTP_PORT, PortRanges.fromString("8080+")) - .configure(JavaWebAppService.ROOT_WAR, WAR_PATH) - .configure(javaSysProp("brooklyn.example.db.url"), - formatString("jdbc:%s%s?user=%s\\&password=%s", - attributeWhenReady(mysql, MySqlNode.DB_URL), - DB_TABLE, DB_USERNAME, DB_PASSWORD)) ); - - web.addEnricher(HttpLatencyDetector.builder(). - url(ControlledDynamicWebAppCluster.ROOT_URL). - rollup(10, TimeUnit.SECONDS). - build()); - - // simple scaling policy - web.getCluster().addPolicy(AutoScalerPolicy.builder(). - metric(DynamicWebAppCluster.REQUESTS_PER_SECOND_IN_WINDOW_PER_NODE). - metricRange(10, 100). - sizeRange(1, 5). - build()); - - // expose some KPI's - addEnricher(SensorPropagatingEnricher.newInstanceListeningTo(web, - WebAppServiceConstants.ROOT_URL, - DynamicWebAppCluster.REQUESTS_PER_SECOND_IN_WINDOW, - HttpLatencyDetector.REQUEST_LATENCY_IN_SECONDS_IN_WINDOW)); - addEnricher(SensorTransformingEnricher.newInstanceTransforming(web, - DynamicWebAppCluster.GROUP_SIZE, Functions.identity(), APPSERVERS_COUNT)); - } - - public static void main(String[] argv) { - List args = Lists.newArrayList(argv); - String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+"); - String location = CommandLineUtil.getCommandLineOption(args, "--location", "localhost"); - - BrooklynLauncher launcher = BrooklynLauncher.newInstance() - .application(EntitySpec.create(StartableApplication.class, WebClusterDatabaseExample.class).displayName("Brooklyn WebApp Cluster with Database example")) - .webconsolePort(port) - .location(location) - .start(); - - Entities.dumpInfo(launcher.getApplications()); - } -} diff --git a/simple-web-cluster/src/main/java/brooklyn/demo/WebClusterDatabaseExampleApp.java b/simple-web-cluster/src/main/java/brooklyn/demo/WebClusterDatabaseExampleApp.java deleted file mode 100644 index 34180f7..0000000 --- a/simple-web-cluster/src/main/java/brooklyn/demo/WebClusterDatabaseExampleApp.java +++ /dev/null @@ -1,153 +0,0 @@ -package brooklyn.demo; - -import static brooklyn.event.basic.DependentConfiguration.attributeWhenReady; -import static brooklyn.event.basic.DependentConfiguration.formatString; - -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import brooklyn.catalog.Catalog; -import brooklyn.catalog.CatalogConfig; -import brooklyn.config.ConfigKey; -import brooklyn.enricher.HttpLatencyDetector; -import brooklyn.enricher.basic.SensorPropagatingEnricher; -import brooklyn.enricher.basic.SensorTransformingEnricher; -import brooklyn.entity.basic.AbstractApplication; -import brooklyn.entity.basic.ConfigKeys; -import brooklyn.entity.basic.Entities; -import brooklyn.entity.basic.StartableApplication; -import brooklyn.entity.database.mysql.MySqlNode; -import brooklyn.entity.group.DynamicCluster; -import brooklyn.entity.java.JavaEntityMethods; -import brooklyn.entity.proxying.EntitySpec; -import brooklyn.entity.webapp.ControlledDynamicWebAppCluster; -import brooklyn.entity.webapp.DynamicWebAppCluster; -import brooklyn.entity.webapp.JavaWebAppService; -import brooklyn.entity.webapp.WebAppService; -import brooklyn.entity.webapp.WebAppServiceConstants; -import brooklyn.event.AttributeSensor; -import brooklyn.event.basic.Sensors; -import brooklyn.launcher.BrooklynLauncher; -import brooklyn.location.basic.PortRanges; -import brooklyn.policy.autoscaling.AutoScalerPolicy; -import brooklyn.util.BrooklynMavenArtifacts; -import brooklyn.util.CommandLineUtil; -import brooklyn.util.ResourceUtils; - -import com.google.common.base.Functions; -import com.google.common.collect.Lists; - -/** - * Launches a 3-tier app with nginx, clustered jboss, and mysql. - *

- * Includes some advanced features such as KPI / derived sensors, - * and annotations for use in a catalog. - *

- * This variant also increases minimum size to 2. - * Note the policy min size must have the same value, - * otherwise it fights with cluster set up trying to reduce the cluster size! - **/ -@Catalog(name="Elastic Java Web + DB", - description="Deploys a WAR to a load-balanced elastic Java AppServer cluster, " + - "with an auto-scaling policy, " + - "wired to a database initialized with the provided SQL; " + - "defaults to a 'Hello World' chatroom app.", - iconUrl="classpath://brooklyn/demo/glossy-3d-blue-web-icon.png") -public class WebClusterDatabaseExampleApp extends AbstractApplication implements StartableApplication { - - public static final Logger LOG = LoggerFactory.getLogger(WebClusterDatabaseExampleApp.class); - - public static final String DEFAULT_LOCATION = "localhost"; - - public static final String DEFAULT_WAR_PATH = ResourceUtils.create(WebClusterDatabaseExampleApp.class) - // take this war, from the classpath, or via maven if not on the classpath - .firstAvailableUrl( - "classpath://hello-world-sql-webapp.war", - BrooklynMavenArtifacts.localUrl("example", "brooklyn-example-hello-world-sql-webapp", "war")) - .or("classpath://hello-world-sql-webapp.war"); - - @CatalogConfig(label="WAR (URL)", priority=2) - public static final ConfigKey WAR_PATH = ConfigKeys.newConfigKey( - "app.war", "URL to the application archive which should be deployed", - DEFAULT_WAR_PATH); - - // TODO to expose in catalog we need to let the keystore url be specified (not hard) - // and also confirm that this works for nginx (might be a bit fiddly); - // booleans in the gui are working (With checkbox) - @CatalogConfig(label="HTTPS") - public static final ConfigKey USE_HTTPS = ConfigKeys.newConfigKey( - "app.https", "Whether the application should use HTTPS only or just HTTP only (default)", false); - - public static final String DEFAULT_DB_SETUP_SQL_URL = "classpath://visitors-creation-script.sql"; - - @CatalogConfig(label="DB Setup SQL (URL)", priority=1) - public static final ConfigKey DB_SETUP_SQL_URL = ConfigKeys.newConfigKey( - "app.db_sql", "URL to the SQL script to set up the database", - DEFAULT_DB_SETUP_SQL_URL); - - public static final String DB_TABLE = "visitors"; - public static final String DB_USERNAME = "brooklyn"; - public static final String DB_PASSWORD = "br00k11n"; - - AttributeSensor APPSERVERS_COUNT = Sensors.newIntegerSensor( - "appservers.count", "Number of app servers deployed"); - public static final AttributeSensor REQUESTS_PER_SECOND_IN_WINDOW = - WebAppServiceConstants.REQUESTS_PER_SECOND_IN_WINDOW; - public static final AttributeSensor ROOT_URL = WebAppServiceConstants.ROOT_URL; - - @Override - public void init() { - MySqlNode mysql = addChild( - EntitySpec.create(MySqlNode.class) - .configure(MySqlNode.CREATION_SCRIPT_URL, Entities.getRequiredUrlConfig(this, DB_SETUP_SQL_URL))); - - ControlledDynamicWebAppCluster web = addChild( - EntitySpec.create(ControlledDynamicWebAppCluster.class) - .configure(WebAppService.HTTP_PORT, PortRanges.fromString("8080+")) - // to specify a diferrent appserver: -// .configure(ControlledDynamicWebAppCluster.MEMBER_SPEC, EntitySpec.create(TomcatServer.class)) - .configure(JavaWebAppService.ROOT_WAR, Entities.getRequiredUrlConfig(this, WAR_PATH)) - .configure(JavaEntityMethods.javaSysProp("brooklyn.example.db.url"), - formatString("jdbc:%s%s?user=%s\\&password=%s", - attributeWhenReady(mysql, MySqlNode.MYSQL_URL), DB_TABLE, DB_USERNAME, DB_PASSWORD)) - .configure(DynamicCluster.INITIAL_SIZE, 2) - .configure(WebAppService.ENABLED_PROTOCOLS, Arrays.asList(getConfig(USE_HTTPS) ? "https" : "http")) ); - - web.addEnricher(HttpLatencyDetector.builder(). - url(ROOT_URL). - rollup(10, TimeUnit.SECONDS). - build()); - - web.getCluster().addPolicy(AutoScalerPolicy.builder(). - metric(DynamicWebAppCluster.REQUESTS_PER_SECOND_IN_WINDOW_PER_NODE). - metricRange(10, 100). - sizeRange(2, 5). - build()); - - addEnricher(SensorPropagatingEnricher.newInstanceListeningTo(web, - WebAppServiceConstants.ROOT_URL, - DynamicWebAppCluster.REQUESTS_PER_SECOND_IN_WINDOW, - HttpLatencyDetector.REQUEST_LATENCY_IN_SECONDS_IN_WINDOW)); - addEnricher(SensorTransformingEnricher.newInstanceTransforming(web, - DynamicWebAppCluster.GROUP_SIZE, Functions.identity(), APPSERVERS_COUNT)); - } - - public static void main(String[] argv) { - List args = Lists.newArrayList(argv); - String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+"); - String location = CommandLineUtil.getCommandLineOption(args, "--location", DEFAULT_LOCATION); - - BrooklynLauncher launcher = BrooklynLauncher.newInstance() - .application(EntitySpec.create(StartableApplication.class, WebClusterDatabaseExampleApp.class) - .displayName("Brooklyn WebApp Cluster with Database example")) - .webconsolePort(port) - .location(location) - .start(); - - Entities.dumpInfo(launcher.getApplications()); - } -} diff --git a/simple-web-cluster/src/main/java/brooklyn/demo/WebClusterDatabaseExampleGroovy.groovy b/simple-web-cluster/src/main/java/brooklyn/demo/WebClusterDatabaseExampleGroovy.groovy deleted file mode 100644 index 542cd8a..0000000 --- a/simple-web-cluster/src/main/java/brooklyn/demo/WebClusterDatabaseExampleGroovy.groovy +++ /dev/null @@ -1,75 +0,0 @@ -package brooklyn.demo; - -import static brooklyn.entity.java.JavaEntityMethods.javaSysProp -import static brooklyn.event.basic.DependentConfiguration.attributeWhenReady -import static brooklyn.event.basic.DependentConfiguration.formatString - -import org.slf4j.Logger -import org.slf4j.LoggerFactory - -import brooklyn.entity.basic.AbstractApplication -import brooklyn.entity.basic.Entities -import brooklyn.entity.database.mysql.MySqlNode -import brooklyn.entity.proxying.EntitySpecs -import brooklyn.entity.webapp.ControlledDynamicWebAppCluster -import brooklyn.entity.webapp.DynamicWebAppCluster -import brooklyn.launcher.BrooklynLauncher -import brooklyn.policy.autoscaling.AutoScalerPolicy -import brooklyn.util.CommandLineUtil - -import com.google.common.collect.Lists - -/** - * Launches a 3-tier app with nginx, clustered jboss, and mysql. - *

- * This variant of {@link WebClusterDatabaseExample} demonstrates Groovy language conveniences. - **/ -public class WebClusterDatabaseExampleGroovy extends AbstractApplication { - - public static final Logger LOG = LoggerFactory.getLogger(WebClusterDatabaseExampleGroovy.class); - - public static final String DEFAULT_LOCATION = "localhost"; - - public static final String WAR_PATH = "classpath://hello-world-sql-webapp.war"; - - public static final String DB_SETUP_SQL_URL = "classpath://visitors-creation-script.sql"; - - public static final String DB_TABLE = "visitors"; - public static final String DB_USERNAME = "brooklyn"; - public static final String DB_PASSWORD = "br00k11n"; - - @Override - public void init() { - MySqlNode mysql = addChild(MySqlNode, - creationScriptUrl: DB_SETUP_SQL_URL); - - ControlledDynamicWebAppCluster web = addChild(ControlledDynamicWebAppCluster, - war: WAR_PATH, - httpPort: "8080+", - (javaSysProp("brooklyn.example.db.url")): - formatString("jdbc:%s%s?user=%s\\&password=%s", - attributeWhenReady(mysql, MySqlNode.MYSQL_URL), - DB_TABLE, DB_USERNAME, DB_PASSWORD)); - - web.getCluster().addPolicy(AutoScalerPolicy.builder(). - metric(DynamicWebAppCluster.AVERAGE_REQUESTS_PER_SECOND). - sizeRange(1, 5). - metricRange(10, 100). - build()); - } - - public static void main(String[] argv) { - List args = Lists.newArrayList(argv); - String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+"); - String location = CommandLineUtil.getCommandLineOption(args, "--location", DEFAULT_LOCATION); - - BrooklynLauncher launcher = BrooklynLauncher.newInstance() - .application(EntitySpecs.appSpec(WebClusterDatabaseExampleGroovy.class).displayName("Brooklyn WebApp Cluster with Database example")) - .webconsolePort(port) - .location(location) - .start(); - - Entities.dumpInfo(launcher.getApplications()); - } - -} diff --git a/simple-web-cluster/src/main/java/brooklyn/demo/WebClusterExample.java b/simple-web-cluster/src/main/java/brooklyn/demo/WebClusterExample.java deleted file mode 100644 index 3fa6558..0000000 --- a/simple-web-cluster/src/main/java/brooklyn/demo/WebClusterExample.java +++ /dev/null @@ -1,79 +0,0 @@ -package brooklyn.demo; - -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import brooklyn.config.BrooklynProperties; -import brooklyn.entity.basic.AbstractApplication; -import brooklyn.entity.basic.Entities; -import brooklyn.entity.proxy.nginx.NginxController; -import brooklyn.entity.proxying.EntitySpec; -import brooklyn.entity.proxying.EntitySpecs; -import brooklyn.entity.webapp.ControlledDynamicWebAppCluster; -import brooklyn.entity.webapp.DynamicWebAppCluster; -import brooklyn.entity.webapp.jboss.JBoss7Server; -import brooklyn.launcher.BrooklynLauncher; -import brooklyn.policy.autoscaling.AutoScalerPolicy; -import brooklyn.util.CommandLineUtil; - -import com.google.common.collect.Lists; - -/** - * Launches a clustered and load-balanced set of web servers. - * Demonstrates syntax, so many of the options used here are the defaults. - * (So the class could be much simpler, as in WebClusterExampleAlt.) - *

- * Requires: - * -Xmx512m -Xms128m -XX:MaxPermSize=256m - * and brooklyn-all jar, and this jar or classes dir, on classpath. - **/ -public class WebClusterExample extends AbstractApplication { - public static final Logger LOG = LoggerFactory.getLogger(WebClusterExample.class); - - static BrooklynProperties config = BrooklynProperties.Factory.newDefault(); - - public static final String DEFAULT_LOCATION = "localhost"; - - public static final String WAR_PATH = "classpath://hello-world-webapp.war"; - - private NginxController nginxController; - private ControlledDynamicWebAppCluster web; - - @Override - public void init() { - nginxController = addChild(EntitySpec.create(NginxController.class) - //.configure("domain", "webclusterexample.brooklyn.local") - .configure("port", "8000+")); - - web = addChild(ControlledDynamicWebAppCluster.Spec.newInstance() - .displayName("WebApp cluster") - .controller(nginxController) - .initialSize(1) - .memberSpec(EntitySpec.create(JBoss7Server.class) - .configure("httpPort", "8080+") - .configure("war", WAR_PATH))); - - web.getCluster().addPolicy(AutoScalerPolicy.builder() - .metric(DynamicWebAppCluster.AVERAGE_REQUESTS_PER_SECOND) - .sizeRange(1, 5) - .metricRange(10, 100) - .build()); - } - - public static void main(String[] argv) { - List args = Lists.newArrayList(argv); - String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+"); - String location = CommandLineUtil.getCommandLineOption(args, "--location", DEFAULT_LOCATION); - - // TODO Want to parse, to handle multiple locations - BrooklynLauncher launcher = BrooklynLauncher.newInstance() - .application(EntitySpecs.appSpec(WebClusterExample.class).displayName("Brooklyn WebApp Cluster example")) - .webconsolePort(port) - .location(location) - .start(); - - Entities.dumpInfo(launcher.getApplications()); - } -} diff --git a/simple-web-cluster/src/main/java/brooklyn/demo/legacy/SingleWebServerExample.groovy b/simple-web-cluster/src/main/java/brooklyn/demo/legacy/SingleWebServerExample.groovy deleted file mode 100644 index 3d0b804..0000000 --- a/simple-web-cluster/src/main/java/brooklyn/demo/legacy/SingleWebServerExample.groovy +++ /dev/null @@ -1,41 +0,0 @@ -package brooklyn.demo.legacy; - -import org.slf4j.Logger -import org.slf4j.LoggerFactory - -import brooklyn.entity.basic.AbstractApplication -import brooklyn.entity.webapp.jboss.JBoss7Server -import brooklyn.entity.webapp.jboss.JBoss7ServerImpl -import brooklyn.location.Location -import brooklyn.location.basic.LocalhostMachineProvisioningLocation - -/** - * This example starts one web app on 8080, waits for a keypress, then stops it. - * - * @deprecated in 0.5; see {@link brooklyn.demo.SingleWebServerExample} - */ -@Deprecated -public class SingleWebServerExample extends AbstractApplication { - - public static final Logger LOG = LoggerFactory.getLogger(SingleWebServerExample) - - private static final String WAR_PATH = "classpath://hello-world-webapp.war" - - JBoss7Server web = new JBoss7ServerImpl(this, war: WAR_PATH, httpPort: 8080) - - public static void main(String[] args) { - SingleWebServerExample app = new SingleWebServerExample(); - Location loc = new LocalhostMachineProvisioningLocation(); - - LOG.info("created, now starting..."); - app.start([loc]); - LOG.info("started, visit "+app.web.getAttribute(JBoss7Server.ROOT_URL)+"; waiting for keypress to quit"); - - System.out.println("---- press enter to quit ----"); - System.in.read(); - LOG.info("now ending..."); - app.stop(); - LOG.info("ended."); - } - -} diff --git a/simple-web-cluster/src/main/java/brooklyn/demo/legacy/WebClusterDatabaseExample.groovy b/simple-web-cluster/src/main/java/brooklyn/demo/legacy/WebClusterDatabaseExample.groovy deleted file mode 100644 index 4c9343c..0000000 --- a/simple-web-cluster/src/main/java/brooklyn/demo/legacy/WebClusterDatabaseExample.groovy +++ /dev/null @@ -1,84 +0,0 @@ -package brooklyn.demo.legacy - -import static brooklyn.entity.java.JavaEntityMethods.javaSysProp -import static brooklyn.entity.webapp.WebAppServiceConstants.HTTP_PORT -import static brooklyn.event.basic.DependentConfiguration.attributeWhenReady -import static brooklyn.event.basic.DependentConfiguration.formatString - -import java.util.List; - -import groovy.transform.InheritConstructors - -import org.slf4j.Logger -import org.slf4j.LoggerFactory - -import com.google.common.collect.Lists; - -import brooklyn.entity.basic.AbstractApplication -import brooklyn.entity.basic.Entities -import brooklyn.entity.database.mysql.MySqlNode -import brooklyn.entity.database.mysql.MySqlNodeImpl -import brooklyn.entity.webapp.ControlledDynamicWebAppCluster -import brooklyn.entity.webapp.ControlledDynamicWebAppClusterImpl -import brooklyn.entity.webapp.DynamicWebAppCluster -import brooklyn.launcher.BrooklynLauncher -import brooklyn.launcher.BrooklynServerDetails -import brooklyn.location.Location -import brooklyn.policy.autoscaling.AutoScalerPolicy -import brooklyn.util.CommandLineUtil - -/** - * Launches a 3-tier app with nginx, clustered jboss, and mysql. - * - * @deprecated in 0.5; see {@link brooklyn.demo.WebClusterDatabaseExample} - */ -@Deprecated -public class WebClusterDatabaseExample extends AbstractApplication { - - public static final Logger LOG = LoggerFactory.getLogger(WebClusterDatabaseExample) - - public static final String WAR_PATH = "classpath://hello-world-sql-webapp.war" - - public static final String DB_SETUP_SQL_URL = "classpath://visitors-creation-script.sql" - - public static final String DB_TABLE = "visitors" - public static final String DB_USERNAME = "brooklyn" - public static final String DB_PASSWORD = "br00k11n" - - - ControlledDynamicWebAppCluster web = new ControlledDynamicWebAppClusterImpl(this, war: WAR_PATH); - MySqlNode mysql = new MySqlNodeImpl(this, creationScriptUrl: DB_SETUP_SQL_URL); - - { - web.configure(HTTP_PORT, "8080+"). - configure(javaSysProp("brooklyn.example.db.url"), - formatString("jdbc:%s%s?user=%s\\&password=%s", - attributeWhenReady(mysql, MySqlNode.MYSQL_URL), - DB_TABLE, DB_USERNAME, DB_PASSWORD)); - - web.cluster.addPolicy(AutoScalerPolicy.builder(). - metric(DynamicWebAppCluster.REQUESTS_PER_SECOND_LAST_PER_NODE). - sizeRange(1, 5). - metricRange(10, 100). - build()); - } - - public WebClusterDatabaseExample(Map properties){ - super(properties); - } - - public static void main(String[] argv) { - List args = Lists.newArrayList(argv); - String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+"); - String location = CommandLineUtil.getCommandLineOption(args, "--location", "localhost"); - - BrooklynLauncher launcher = BrooklynLauncher.newInstance() - .application(new WebClusterDatabaseExample(name:'Brooklyn WebApp Cluster with Database example')) - .webconsolePort(port) - .location(location) - .start(); - - Entities.dumpInfo(launcher.getApplications()); - } - -} diff --git a/simple-web-cluster/src/main/java/brooklyn/demo/legacy/WebClusterDatabaseExampleAlt.groovy b/simple-web-cluster/src/main/java/brooklyn/demo/legacy/WebClusterDatabaseExampleAlt.groovy deleted file mode 100644 index d78bdbf..0000000 --- a/simple-web-cluster/src/main/java/brooklyn/demo/legacy/WebClusterDatabaseExampleAlt.groovy +++ /dev/null @@ -1,111 +0,0 @@ -package brooklyn.demo.legacy - -import org.slf4j.Logger -import org.slf4j.LoggerFactory - -import brooklyn.config.BrooklynProperties -import brooklyn.entity.Entity -import brooklyn.entity.basic.AbstractApplication -import brooklyn.entity.basic.Entities -import brooklyn.entity.database.mysql.MySqlNode -import brooklyn.entity.database.mysql.MySqlNodeImpl -import brooklyn.entity.proxy.nginx.NginxControllerImpl -import brooklyn.entity.webapp.ControlledDynamicWebAppCluster -import brooklyn.entity.webapp.ControlledDynamicWebAppClusterImpl -import brooklyn.entity.webapp.DynamicWebAppCluster -import brooklyn.entity.webapp.JavaWebAppService -import brooklyn.entity.webapp.jboss.JBoss7Server -import brooklyn.entity.webapp.jboss.JBoss7ServerImpl -import brooklyn.event.basic.DependentConfiguration -import brooklyn.launcher.BrooklynLauncher -import brooklyn.policy.autoscaling.AutoScalerPolicy -import brooklyn.util.CommandLineUtil - -import com.google.common.collect.Lists - -/** - * Shows some alternative syntaxes compared with WebClusterDatabaseExample. - * (Inline SQL; different ports (nginx on 8080 now); policy added programmatically. - *

- * Run with: - * java -Xmx512m -Xms128m -XX:MaxPermSize=256m - *

- * This jar or classes dir, and brooklyn-all jar, on classpath. - * - * @deprecated in 0.5; see {@link brooklyn.demo.WebClusterDatabaseExample} - */ -@Deprecated -public class WebClusterDatabaseExampleAlt extends AbstractApplication { - public static final Logger LOG = LoggerFactory.getLogger(WebClusterDatabaseExampleAlt) - - static BrooklynProperties config = BrooklynProperties.Factory.newDefault() - - public static final String WAR_PATH = "classpath://hello-world-sql-webapp.war" - - public static final String DB_USERNAME = "brooklyn" - public static final String DB_PASSWORD = "br00k11n" - - public static final String DB_SETUP_SQL = """ -create database visitors; -use visitors; -create user '${DB_USERNAME}' identified by '${DB_PASSWORD}'; -grant usage on *.* to '${DB_USERNAME}'@'%' identified by '${DB_PASSWORD}'; -# ''@localhost is sometimes set up, overriding brooklyn@'%', so do a second explicit grant -grant usage on *.* to '${DB_USERNAME}'@'localhost' identified by '${DB_PASSWORD}'; -grant all privileges on visitors.* to '${DB_USERNAME}'@'%'; -flush privileges; - -CREATE TABLE MESSAGES ( - id INT NOT NULL AUTO_INCREMENT, - NAME VARCHAR(30) NOT NULL, - MESSAGE VARCHAR(400) NOT NULL, - PRIMARY KEY (ID) - ); - -INSERT INTO MESSAGES values (default, 'Isaac Asimov', 'I grew up in Brooklyn' ); -"""; - - public WebClusterDatabaseExampleAlt(Map props=[:]) { - super(props) - setConfig(JavaWebAppService.ROOT_WAR, WAR_PATH) - } - - MySqlNode mysql = new MySqlNodeImpl(this, creationScriptContents: DB_SETUP_SQL); - - protected JavaWebAppService newWebServer(Map flags, Entity cluster) { - JBoss7Server jb7 = new JBoss7ServerImpl(flags).configure(httpPort: "8000+"); - jb7.setConfig(JBoss7Server.JAVA_SYSPROPS, ["brooklyn.example.db.url": - //"jdbc:mysql://localhost/visitors?user=brooklyn&password=br00k11n" - DependentConfiguration.valueWhenAttributeReady(mysql, MySqlNode.MYSQL_URL, - { "jdbc:"+it+"visitors?user=${DB_USERNAME}\\&password=${DB_PASSWORD}" }) ]); - jb7.setParent(cluster); - return jb7; - } - - ControlledDynamicWebAppCluster web = new ControlledDynamicWebAppClusterImpl(this, - controller: new NginxControllerImpl(port: 8080), - factory: this.&newWebServer ) - - AutoScalerPolicy policy = AutoScalerPolicy.builder() - .metric(DynamicWebAppCluster.REQUESTS_PER_SECOND_LAST_PER_NODE) - .sizeRange(1, 5) - .metricRange(10, 100) - .build(); - - - public static void main(String[] argv) { - List args = Lists.newArrayList(argv); - String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+"); - String location = CommandLineUtil.getCommandLineOption(args, "--location", "localhost"); - WebClusterDatabaseExampleAlt app = new WebClusterDatabaseExampleAlt(name:'Brooklyn WebApp Cluster with Database example') - - BrooklynLauncher launcher = BrooklynLauncher.newInstance() - .application(app) - .webconsolePort(port) - .location(location) - .start(); - - app.web.cluster.addPolicy(app.policy) - Entities.dumpInfo(launcher.getApplications()); - } -} diff --git a/simple-web-cluster/src/main/java/brooklyn/demo/legacy/WebClusterDatabaseExampleAltJava.java b/simple-web-cluster/src/main/java/brooklyn/demo/legacy/WebClusterDatabaseExampleAltJava.java deleted file mode 100644 index 08469ba..0000000 --- a/simple-web-cluster/src/main/java/brooklyn/demo/legacy/WebClusterDatabaseExampleAltJava.java +++ /dev/null @@ -1,106 +0,0 @@ -package brooklyn.demo.legacy; - -import static brooklyn.event.basic.DependentConfiguration.valueWhenAttributeReady; - -import java.io.IOException; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import brooklyn.config.BrooklynProperties; -import brooklyn.entity.basic.AbstractApplication; -import brooklyn.entity.basic.Entities; -import brooklyn.entity.basic.EntityLocal; -import brooklyn.entity.database.mysql.MySqlNode; -import brooklyn.entity.database.mysql.MySqlNodeImpl; -import brooklyn.entity.webapp.ControlledDynamicWebAppCluster; -import brooklyn.entity.webapp.ControlledDynamicWebAppClusterImpl; -import brooklyn.entity.webapp.DynamicWebAppCluster; -import brooklyn.entity.webapp.WebAppService; -import brooklyn.entity.webapp.jboss.JBoss7Server; -import brooklyn.launcher.BrooklynLauncher; -import brooklyn.policy.autoscaling.AutoScalerPolicy; -import brooklyn.util.CommandLineUtil; - -import com.google.common.base.Function; -import com.google.common.collect.Lists; - -/** - * Launches a 3-tier app with nginx, clustered jboss, and mysql. - *

- * Same as the {@link WebClusterDatabaseExample} but pure Java. - *

- * Requires: - * -Xmx512m -Xms128m -XX:MaxPermSize=256m - * and brooklyn-all jar, and this jar or classes dir, on classpath. - * - * @deprecated in 0.5; see {@link brooklyn.demo.WebClusterDatabaseExample} - */ -@Deprecated -public class WebClusterDatabaseExampleAltJava extends AbstractApplication { - public static final Logger LOG = LoggerFactory.getLogger(WebClusterDatabaseExampleAltJava.class); - - static BrooklynProperties config = BrooklynProperties.Factory.newDefault(); - - public static final String WAR_PATH = "classpath://hello-world-sql-webapp.war"; - - public static final String DB_USERNAME = "brooklyn"; - public static final String DB_PASSWORD = "br00k11n"; - - public static final String DB_SETUP_SQL_URL = "classpath://visitors-creation-script.sql"; - - public static String makeJdbcUrl(String dbUrl) { - //jdbc:mysql://192.168.1.2:3306/visitors?user=brooklyn&password=br00k11n - return "jdbc:"+dbUrl+"visitors"+"?"+ - "user="+DB_USERNAME+"\\&"+ - "password="+DB_PASSWORD; - } - - public WebClusterDatabaseExampleAltJava() { - } - - ControlledDynamicWebAppCluster web = new ControlledDynamicWebAppClusterImpl(this); - MySqlNodeImpl mysql = new MySqlNodeImpl(this); - - { - ((EntityLocal)web).setConfig(ControlledDynamicWebAppCluster.ROOT_WAR, WAR_PATH); - mysql.setConfig(MySqlNode.CREATION_SCRIPT_URL, DB_SETUP_SQL_URL); - web.getFactory().setConfig(WebAppService.HTTP_PORT, "8080+"); - Map jvmSysProps = new LinkedHashMap(); - jvmSysProps.put("brooklyn.example.db.url", valueWhenAttributeReady(mysql, MySqlNode.MYSQL_URL, - new Function() { - @Override - public Object apply(Object input) { - return makeJdbcUrl(""+input); - } - })); - web.getFactory().setConfig(JBoss7Server.JAVA_SYSPROPS, jvmSysProps); - - web.getCluster().addPolicy(AutoScalerPolicy.builder() - .metric(DynamicWebAppCluster.REQUESTS_PER_SECOND_LAST_PER_NODE) - .sizeRange(1, 5) - .metricRange(10, 100) - .build()); - } - - public static void main(String[] argv) throws IOException { - List args = Lists.newArrayList(argv); - String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+"); - String location = CommandLineUtil.getCommandLineOption(args, "--location", "localhost"); - - WebClusterDatabaseExampleAltJava app = new WebClusterDatabaseExampleAltJava(); - app.setDisplayName("Brooklyn WebApp Cluster with Database example"); - - BrooklynLauncher launcher = BrooklynLauncher.newInstance() - .application(app) - .webconsolePort(port) - .location(location) - .start(); - - Entities.dumpInfo(launcher.getApplications()); - } - -} diff --git a/simple-web-cluster/src/main/java/brooklyn/demo/legacy/WebClusterExample.groovy b/simple-web-cluster/src/main/java/brooklyn/demo/legacy/WebClusterExample.groovy deleted file mode 100644 index 013a091..0000000 --- a/simple-web-cluster/src/main/java/brooklyn/demo/legacy/WebClusterExample.groovy +++ /dev/null @@ -1,79 +0,0 @@ -package brooklyn.demo.legacy - -import org.slf4j.Logger -import org.slf4j.LoggerFactory - -import brooklyn.config.BrooklynProperties -import brooklyn.entity.basic.AbstractApplication -import brooklyn.entity.basic.Entities -import brooklyn.entity.proxy.nginx.NginxController -import brooklyn.entity.proxy.nginx.NginxControllerImpl -import brooklyn.entity.webapp.ControlledDynamicWebAppCluster -import brooklyn.entity.webapp.ControlledDynamicWebAppClusterImpl -import brooklyn.entity.webapp.DynamicWebAppCluster -import brooklyn.entity.webapp.jboss.JBoss7ServerFactory -import brooklyn.launcher.BrooklynLauncher -import brooklyn.policy.autoscaling.AutoScalerPolicy -import brooklyn.util.CommandLineUtil - -import com.google.common.collect.Lists - -/** - * Launches a clustered and load-balanced set of web servers. - * Demonstrates syntax, so many of the options used here are the defaults. - * (So the class could be much simpler, as in WebClusterExampleAlt.) - *

- * Requires: - * -Xmx512m -Xms128m -XX:MaxPermSize=256m - * and brooklyn-all jar, and this jar or classes dir, on classpath. - * - * @deprecated in 0.5; see {@link brooklyn.demo.WebClusterExample} - */ -@Deprecated -public class WebClusterExample extends AbstractApplication { - public static final Logger LOG = LoggerFactory.getLogger(WebClusterExample) - - static BrooklynProperties config = BrooklynProperties.Factory.newDefault() - - public static final String WAR_PATH = "classpath://hello-world-webapp.war" - - public WebClusterExample(Map props=[:]) { - super(props) - } - - - NginxController nginxController = new NginxControllerImpl(this, -// domain: 'webclusterexample.brooklyn.local', - port:"8000+") - - JBoss7ServerFactory jbossFactory = new JBoss7ServerFactory(httpPort: "8080+", war: WAR_PATH); - - ControlledDynamicWebAppCluster web = new ControlledDynamicWebAppClusterImpl(this, - name: "WebApp cluster", - controller: nginxController, - initialSize: 1, - factory: jbossFactory) - - AutoScalerPolicy policy = AutoScalerPolicy.builder() - .metric(DynamicWebAppCluster.REQUESTS_PER_SECOND_LAST_PER_NODE) - .sizeRange(1, 5) - .metricRange(10, 100) - .build(); - - - public static void main(String[] argv) { - List args = Lists.newArrayList(argv); - String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+"); - String location = CommandLineUtil.getCommandLineOption(args, "--location", "localhost"); - WebClusterExample app = new WebClusterExample(name:'Brooklyn WebApp Cluster example') - - BrooklynLauncher launcher = BrooklynLauncher.newInstance() - .application(app) - .webconsolePort(port) - .location(location) - .start(); - - app.web.cluster.addPolicy(app.policy) - Entities.dumpInfo(launcher.getApplications()); - } -} diff --git a/simple-web-cluster/src/main/java/brooklyn/demo/legacy/WebClusterExampleAlt.groovy b/simple-web-cluster/src/main/java/brooklyn/demo/legacy/WebClusterExampleAlt.groovy deleted file mode 100644 index 5f0dd45..0000000 --- a/simple-web-cluster/src/main/java/brooklyn/demo/legacy/WebClusterExampleAlt.groovy +++ /dev/null @@ -1,62 +0,0 @@ -package brooklyn.demo.legacy - -import groovy.transform.InheritConstructors - -import org.slf4j.Logger -import org.slf4j.LoggerFactory - -import brooklyn.entity.basic.AbstractApplication -import brooklyn.entity.basic.Entities -import brooklyn.entity.webapp.ControlledDynamicWebAppCluster -import brooklyn.entity.webapp.ControlledDynamicWebAppClusterImpl -import brooklyn.entity.webapp.DynamicWebAppCluster -import brooklyn.launcher.BrooklynLauncher -import brooklyn.policy.autoscaling.AutoScalerPolicy -import brooklyn.util.CommandLineUtil - -import com.google.common.collect.Lists - -/** - * Launches a clustered and load-balanced set of web servers. - * (Simplified variant of WebClusterExample.) - *

- * Requires: - * -Xmx512m -Xms128m -XX:MaxPermSize=256m - * and brooklyn-all jar, and this jar or classes dir, on classpath. - * - * @deprecated in 0.5; see {@link brooklyn.demo.WebClusterExample} - */ -@Deprecated -public class WebClusterExampleAlt extends AbstractApplication { - - public static final Logger LOG = LoggerFactory.getLogger(WebClusterExampleAlt) - - public static final String WAR_PATH = "classpath://hello-world-webapp.war" - - ControlledDynamicWebAppCluster web = new ControlledDynamicWebAppClusterImpl(this, war: WAR_PATH); - { - web.addPolicy(AutoScalerPolicy.builder() - .metric(DynamicWebAppCluster.REQUESTS_PER_SECOND_LAST_PER_NODE) - .sizeRange(1, 5) - .metricRange(10, 100) - .build()); - } - - public WebClusterExampleAlt(Map properties){ - super(properties); - } - - public static void main(String[] argv) { - List args = Lists.newArrayList(argv); - String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+"); - String location = CommandLineUtil.getCommandLineOption(args, "--location", "localhost"); - - BrooklynLauncher launcher = BrooklynLauncher.newInstance() - .application(new WebClusterExampleAlt(name:'Brooklyn WebApp Cluster example')) - .webconsolePort(port) - .location(location) - .start(); - - Entities.dumpInfo(launcher.getApplications()); - } -} diff --git a/simple-web-cluster/src/main/resources/brooklyn/demo/glossy-3d-blue-web-icon.png b/simple-web-cluster/src/main/resources/brooklyn/demo/glossy-3d-blue-web-icon.png deleted file mode 100644 index 542a1de..0000000 Binary files a/simple-web-cluster/src/main/resources/brooklyn/demo/glossy-3d-blue-web-icon.png and /dev/null differ diff --git a/simple-web-cluster/src/main/resources/logback-custom.xml b/simple-web-cluster/src/main/resources/logback-custom.xml deleted file mode 100644 index 39e7f16..0000000 --- a/simple-web-cluster/src/main/resources/logback-custom.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - diff --git a/simple-web-cluster/src/main/resources/visitors-creation-script.sql b/simple-web-cluster/src/main/resources/visitors-creation-script.sql deleted file mode 100644 index e1a1de0..0000000 --- a/simple-web-cluster/src/main/resources/visitors-creation-script.sql +++ /dev/null @@ -1,23 +0,0 @@ -create database visitors; -use visitors; - -# not necessary to create user if we grant (and not supported in some dialects) -# create user 'brooklyn' identified by 'br00k11n'; - -grant usage on *.* to 'brooklyn'@'%' identified by 'br00k11n'; - -# ''@localhost is sometimes set up, overriding brooklyn@'%', so do a second explicit grant -grant usage on *.* to 'brooklyn'@'localhost' identified by 'br00k11n'; - -grant all privileges on visitors.* to 'brooklyn'@'%'; - -flush privileges; - -CREATE TABLE MESSAGES ( - id BIGINT NOT NULL AUTO_INCREMENT, - NAME VARCHAR(30) NOT NULL, - MESSAGE VARCHAR(400) NOT NULL, - PRIMARY KEY (ID) - ); - -INSERT INTO MESSAGES values (default, 'Isaac Asimov', 'I grew up in Brooklyn' ); diff --git a/webapps/hello-world-hadoop-jar/pom.xml b/webapps/hello-world-hadoop-jar/pom.xml deleted file mode 100644 index c190fb7..0000000 --- a/webapps/hello-world-hadoop-jar/pom.xml +++ /dev/null @@ -1,42 +0,0 @@ - - 4.0.0 - - brooklyn-example-hello-world-hadoop-jar - jar - - Jar Code for Hadoop Webapp - - - UTF-8 - UTF-8 - 1.0.2 - - - - brooklyn-example-hello-world-hadoop-jar - - - - io.brooklyn.example - brooklyn-examples-webapps-parent - 0.6.0 - ../pom.xml - - - - - org.apache.hadoop - hadoop-core - ${hadoop.version} - - - commons-cli - commons-cli - 1.2 - - - - - diff --git a/webapps/hello-world-hadoop-jar/src/main/java/brooklyn/demo/webapp/hello/DemoUtils.java b/webapps/hello-world-hadoop-jar/src/main/java/brooklyn/demo/webapp/hello/DemoUtils.java deleted file mode 100644 index 8f78ee1..0000000 --- a/webapps/hello-world-hadoop-jar/src/main/java/brooklyn/demo/webapp/hello/DemoUtils.java +++ /dev/null @@ -1,30 +0,0 @@ -package brooklyn.demo.webapp.hello; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.PrintWriter; -import java.io.StringWriter; - -public class DemoUtils { - - - public static String stringFromInputStream(InputStream is) throws IOException { - BufferedReader reader = new BufferedReader(new InputStreamReader(is)); - StringBuffer sb = new StringBuffer(); - String line; - while ((line = reader.readLine()) != null) - sb.append(line).append("\n"); - return sb.toString(); - } - - public static String getStackTrace(Throwable t) { - StringWriter s = new StringWriter(); - PrintWriter pw = new PrintWriter(s); - t.printStackTrace(pw); - pw.flush(); - return s.getBuffer().toString(); - } - -} diff --git a/webapps/hello-world-hadoop-jar/src/main/java/brooklyn/demo/webapp/hello/HadoopWordCount.java b/webapps/hello-world-hadoop-jar/src/main/java/brooklyn/demo/webapp/hello/HadoopWordCount.java deleted file mode 100644 index 7a5c948..0000000 --- a/webapps/hello-world-hadoop-jar/src/main/java/brooklyn/demo/webapp/hello/HadoopWordCount.java +++ /dev/null @@ -1,147 +0,0 @@ -package brooklyn.demo.webapp.hello; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.StringTokenizer; - -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.fs.FSDataOutputStream; -import org.apache.hadoop.fs.FileStatus; -import org.apache.hadoop.fs.FileSystem; -import org.apache.hadoop.fs.Path; -import org.apache.hadoop.io.IntWritable; -import org.apache.hadoop.io.Text; -import org.apache.hadoop.mapreduce.Job; -import org.apache.hadoop.mapreduce.Mapper; -import org.apache.hadoop.mapreduce.Reducer; -import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; -import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; -import org.apache.hadoop.util.GenericOptionsParser; - -public class HadoopWordCount { - - public static class TokenizerMapper extends Mapper{ - - private final static IntWritable one = new IntWritable(1); - private Text word = new Text(); - - public void map(Object key, Text value, Context context) throws IOException, InterruptedException { - StringTokenizer itr = new StringTokenizer(value.toString()); - while (itr.hasMoreTokens()) { - String w = itr.nextToken(); - // words (in our world) consist of [A-Za-z0-9_]+ - w = w.replaceAll("[^A-Za-z0-9_]+", " ").replaceAll("\\s+", " ").trim().toLowerCase(); - if (w.length()>0) { - StringTokenizer itr2 = new StringTokenizer(w); - while (itr2.hasMoreTokens()) { - String w2 = itr2.nextToken(); - word.set(w2); - context.write(word, one); - } - } - } - } - } - - public static class IntSumReducer - extends Reducer { - private IntWritable result = new IntWritable(); - - public void reduce(Text key, Iterable values, - Context context - ) throws IOException, InterruptedException { - int sum = 0; - for (IntWritable val : values) { - sum += val.get(); - } - result.set(sum); - context.write(key, result); - } - } - - public static Job makeJob(Configuration conf) throws IOException { - Job job = new Job(conf, "word count"); - job.setJarByClass(HadoopWordCount.class); - job.setMapperClass(TokenizerMapper.class); - job.setCombinerClass(IntSumReducer.class); - job.setReducerClass(IntSumReducer.class); - job.setOutputKeyClass(Text.class); - job.setOutputValueClass(IntWritable.class); - return job; - } - - public static String stringFromInputStream(InputStream is) throws IOException { - BufferedReader reader = new BufferedReader(new InputStreamReader(is)); - StringBuffer sb = new StringBuffer(); - String line; - while ((line = reader.readLine()) != null) - sb.append(line).append("\n"); - return sb.toString(); - } - - public static Job runWordCountWithArgs(Configuration conf, String ...args) throws FileNotFoundException, IOException, InterruptedException { - if (args.length > 2) { - System.err.println("Usage: wordcount [/tmp/sample.txt] [/tmp/out]"); - System.exit(2); - } - if (args.length > 0 && (args[0].equals("-h") || args[0].equals("--help"))) { - System.err.println("Usage: wordcount [/tmp/sample.txt] [/tmp/out]"); - System.exit(0); - } - - FileSystem fsClient = FileSystem.get(conf); - - // read from /tmp/sample.txt (by default), creating it if it doesn't exist - String inN = args.length > 0 ? args[0] : "/tmp/sample.txt"; - Path in = new Path(inN); - if (!fsClient.exists(in)) { - FSDataOutputStream inS = fsClient.create(in); - - String textForInputFile = "This is a test.\nHow is this test working?\nSeems this is okay to me.\n"; - if (new File(inN).exists()) { - //upload from local file system - textForInputFile = stringFromInputStream(new FileInputStream(inN)); - } - inS.write(textForInputFile.getBytes()); - inS.close(); - } - - // write to /tmp/out (by default), wipe it if it exists - String outN = args.length > 1 ? args[1] : "/tmp/out"; - Path out = new Path(outN); - if (fsClient.exists(out)) { - fsClient.delete(out, true); -// if (!out.delete()) { -// Runtime.getRuntime().exec(new String[] { "rm", "-rf", "/tmp/out" }).waitFor(); -// } - } - - Job job = makeJob(conf); - FileInputFormat.addInputPath(job, new Path(inN)); - FileOutputFormat.setOutputPath(job, new Path(outN)); - return job; - } - - public static void main(String[] args) throws Exception { - Configuration conf = new Configuration(); -// String confFileName = System.getProperty("user.home")+"/"+".whirr"+"/"+"whirr-hadoop-sample-"+System.getProperty("user.name")+"/"+"hadoop-site.xml"; -// conf.addResource(new URL("file://"+confFileName)); -// conf.set("mapred.jar", "/tmp/jar-for-my-hadoop-app.jar"); - - String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs(); - Job job = runWordCountWithArgs(conf, otherArgs); - - boolean result = job.waitForCompletion(true); - if (!result) System.out.println("Job returned non-zero result code."); - - for (FileStatus f: FileSystem.get(conf).listStatus(new Path(args.length > 1 ? args[1] : "/tmp/out"))) { - if (!f.isDir()) - System.out.println("Output "+f.getPath()+":\n"+stringFromInputStream(FileSystem.get(conf).open(f.getPath()))); - } - } - -} diff --git a/webapps/hello-world-hadoop/pom.xml b/webapps/hello-world-hadoop/pom.xml deleted file mode 100644 index 773327c..0000000 --- a/webapps/hello-world-hadoop/pom.xml +++ /dev/null @@ -1,70 +0,0 @@ - - 4.0.0 - brooklyn-example-hello-world-hadoop-webapp - war - hello-world-hadoop-webapp Maven Webapp - - - io.brooklyn.example - brooklyn-examples-webapps-parent - 0.6.0 - ../pom.xml - - - - - mysql - mysql-connector-java - 5.1.18 - - - org.apache.hadoop - hadoop-client - 1.0.2 - - - io.brooklyn.example - brooklyn-example-hello-world-hadoop-jar - ${project.version} - - - org.slf4j - slf4j-api - 1.5.11 - - - - - brooklyn-example-hello-world-hadoop-webapp - - - maven-dependency-plugin - - - - copy - process-classes - - copy - - - - - - ${project.groupId} - brooklyn-example-hello-world-hadoop-jar - ${project.version} - jar - true - target/classes - brooklyn-example-hello-world-hadoop-jar.jar - - - - - - - - - - diff --git a/webapps/hello-world-hadoop/src/main/java/brooklyn/demo/webapp/hello/SerializeHelloWorldHadoopJar.java b/webapps/hello-world-hadoop/src/main/java/brooklyn/demo/webapp/hello/SerializeHelloWorldHadoopJar.java deleted file mode 100644 index f065f33..0000000 --- a/webapps/hello-world-hadoop/src/main/java/brooklyn/demo/webapp/hello/SerializeHelloWorldHadoopJar.java +++ /dev/null @@ -1,64 +0,0 @@ -package brooklyn.demo.webapp.hello; - -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.URL; -import java.util.concurrent.atomic.AtomicBoolean; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * The remote hadoop needs access to a jar file containing the code. - * We jump through some maven hoops to have that JAR in our classpath, - * then on the web server we serialize that JAR then pass the filename - * to the JobConf which gets sent to hadoop. - */ -public class SerializeHelloWorldHadoopJar { - - public static final Logger LOG = LoggerFactory.getLogger(SerializeHelloWorldHadoopJar.class); - - private static final String JAR_RESOURCE_NAME = "brooklyn-example-hello-world-hadoop-jar.jar"; - private static AtomicBoolean initialized = new AtomicBoolean(false); - private static String jarFileName; - - public static void init() { - if (initialized.get()) return; - synchronized (initialized) { - if (initialized.get()) return; - try { - URL u = SerializeHelloWorldHadoopJar.class.getClassLoader().getResource(JAR_RESOURCE_NAME); - if (u==null) { - throw new FileNotFoundException("jar "+JAR_RESOURCE_NAME+" not on classpath"); - } else { - OutputStream out = new FileOutputStream("/tmp/brooklyn-example-hello-world-hadoop-jar.jar"); - copy(u.openStream(), out); - out.close(); - jarFileName = "/tmp/brooklyn-example-hello-world-hadoop-jar.jar"; - } - } catch (Exception e) { - LOG.warn("Cannot copy "+JAR_RESOURCE_NAME+"; hadoop will likely fail: "+e); - } - initialized.set(true); - } - } - - public static String getJarName() { - init(); - return jarFileName; - } - - private static void copy(InputStream input, OutputStream output) throws IOException { - byte[] buf = new byte[1024]; - int bytesRead = input.read(buf); - while (bytesRead != -1) { - output.write(buf, 0, bytesRead); - bytesRead = input.read(buf); - } - output.flush(); - } - -} diff --git a/webapps/hello-world-hadoop/src/main/webapp/WEB-INF/web.xml b/webapps/hello-world-hadoop/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 9f88c1f..0000000 --- a/webapps/hello-world-hadoop/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - Archetype Created Web Application - diff --git a/webapps/hello-world-hadoop/src/main/webapp/available.jsp b/webapps/hello-world-hadoop/src/main/webapp/available.jsp deleted file mode 100644 index 9cc73ab..0000000 --- a/webapps/hello-world-hadoop/src/main/webapp/available.jsp +++ /dev/null @@ -1,55 +0,0 @@ - - -Sample "Hello, World" Application - - - - - - - - -
- - -

Sample Brooklyn Deployed "Hello, World" Application

-

This is the home page for a sample application used to illustrate -how web applications can be deployed to multi-cloud environments using Brooklyn. -

- -

-The following apps are available: -

- -

    -<% -String url=System.getProperty("brooklyn.example.db.url"); -//URL should be supplied e.g. "-Dbrooklyn.example.db.url=jdbc:mysql://localhost/visitors?user=brooklyn&password=br00k11n" -//(note quoting needed due to ampersand) -if (url!=null) { -%> -
  • SQL database chatroom
  • -<% } %> - -<% -String hadoopConfigUrl=System.getProperty("brooklyn.example.hadoop.site.xml.url"); -String hadoopConfigContents=System.getProperty("brooklyn.example.hadoop.site.xml.contents"); -boolean hasHadoop = (hadoopConfigUrl!=null || hadoopConfigContents!=null); -//URL or contents should be supplied e.g. -Dbrooklyn.example.hadoop.site.xml.url=file://tmp/hadoop-site.xml -if (hasHadoop) { -%> -
  • Hadoop chatroom
  • -
  • Hadoop wordcount (inevitably!) run over the chats
  • -<% } %> - -<% -if (!hasHadoop && url==null) { -%> -
  • None. Try one of the other Brooklyn examples to see SQL or Hadoop.
  • -<% } %> -
- -

Or you can supply or edit the configuration.

- - - diff --git a/webapps/hello-world-hadoop/src/main/webapp/configure.jsp b/webapps/hello-world-hadoop/src/main/webapp/configure.jsp deleted file mode 100644 index 5730b4f..0000000 --- a/webapps/hello-world-hadoop/src/main/webapp/configure.jsp +++ /dev/null @@ -1,104 +0,0 @@ -<%@ page language="java" import="java.sql.*"%> - - - -Sample Application Database JSP Page - - - - - - - - -
- - -

Sample Brooklyn Deployed WebApp

-This is the output of a JSP page that is part of the Hello, World application, -deployed by brooklyn, to allow configuration. -
- -<% -if (request.getParameter("key")!=null) { - String key = request.getParameter("key"); - String value = request.getParameter("value"); - Object oldValue = System.getProperties().setProperty(key, value); -%> -

Applied new value for '<%= key %>'.

-<% } %> - - - - - - - - - - - - - - - - - - - - - - - - - - - -
KeyCurrent/New ValueSample Value
brooklyn.example.db.url -
- - " width="30"> - -
-
jdbc:mysql://localhost/visitors?user=brooklyn&password=br00k11n
brooklyn.example.hadoop.site.xml.url -
- - " width="30"> - -
-
file:///tmp/hadoop-site.xml
brooklyn.example.hadoop.site.xml.contents -
- - - -
-
-
-<configuration>
-  <property>
-    <name>mapred.job.tracker</name>
-    <value>ec2-184-169-225-252.us-west-1.compute.amazonaws.com:8021</value>
-  </property>
-  <property>
-    <name>fs.default.name</name>
-    <value>hdfs://ec2-184-169-225-252.us-west-1.compute.amazonaws.com:8020/</value>
-  </property>
-  <property>
-    <name>hadoop.socks.server</name>
-    <value>localhost:6666</value>
-  </property>
-  <property>
-    <name>fs.s3n.awsAccessKeyId</name>
-    <value>XXX</value>
-  <property>
-    <name>fs.s3.awsSecretAccessKey</name>
-    <value>XXX</value>
-  </property>
-</configuration>
-
-
- -

Click here to go back to the main page.

- - - diff --git a/webapps/hello-world-hadoop/src/main/webapp/db.jsp b/webapps/hello-world-hadoop/src/main/webapp/db.jsp deleted file mode 100644 index 39b0c70..0000000 --- a/webapps/hello-world-hadoop/src/main/webapp/db.jsp +++ /dev/null @@ -1,105 +0,0 @@ -<%@ page language="java" import="java.sql.*"%> - - - -Sample Application Database JSP Page - - - - - - - - -
- - -

Sample Brooklyn Deployed WebApp (Database JSP)

-This is the output of a JSP page that is part of the Hello, World application, -deployed by brooklyn, to show SQL database interactivity. -
- -<% -String url=System.getProperty("brooklyn.example.db.url"); -//URL should be supplied e.g. ""-Dbrooklyn.example.db.url=jdbc:mysql://localhost/visitors?user=brooklyn&password=br00k11n" -//(note quoting needed due to ampersand) -if (url==null) { -%> -

(There is no database included as part of this example.)

-<% } else { /* begin database-enabled block */ %> - -
-

Visitors:

-
    - -<% -Connection con=null; -ResultSet rst=null; -Statement stmt=null; -int i=0; - -try { - - String DRIVER = "com.mysql.jdbc.Driver"; - Class.forName(DRIVER).newInstance(); - - con=DriverManager.getConnection(url); - stmt=con.createStatement(); - - if (request.getParameter("name")!=null) { - //add a message - stmt.execute("INSERT INTO MESSAGES values (default, '"+ - //better escaping and security desired... - //this essentially does StringEscapeUtils.escapeSql (either brooklyn.util or apache commons) - request.getParameter("name").replaceAll("'", "''")+ - "', '"+ - request.getParameter("message").replaceAll("'", "''")+ - "')"); - } - - rst=stmt.executeQuery("select * from MESSAGES"); - while (rst.next()) { -%> -
  • <%= rst.getString(2) %>: <%= rst.getString(3) %>
  • -<% - i++; - } -} catch (Exception e) { - i=-1; -%> -
  • The database does not appear to be connected.
  • -
  • ERROR: <%= e %>
  • -<% -} finally { - if (rst!=null) rst.close(); - if (stmt!=null) stmt.close(); - if (con!=null) con.close(); -} - -if (i==0) { -%> -
  • None.
  • -<% -} -%> - -
- -
- -

Please enter a message:

- -
- - - -
Name:
Message:
- -
- -<% } /* end of database-enabled block */ %> - -
-

Click here to go back to the main page.

- - diff --git a/webapps/hello-world-hadoop/src/main/webapp/hadoop-chat.jsp b/webapps/hello-world-hadoop/src/main/webapp/hadoop-chat.jsp deleted file mode 100644 index efae9ce..0000000 --- a/webapps/hello-world-hadoop/src/main/webapp/hadoop-chat.jsp +++ /dev/null @@ -1,94 +0,0 @@ -<%@ page language="java" import="java.sql.*"%> - - - -Sample Application HDFS JSP Page - - - - - - - - -
- - -

Sample Brooklyn Deployed WebApp (Hadoop JSP)

-This is the output of a JSP page that is part of the Hello, World application, -deployed by brooklyn, to show hadoop hdfs used as the data store. -
- -<% -String hadoopConfigUrl=System.getProperty("brooklyn.example.hadoop.site.xml.url"); -String hadoopConfigContents=System.getProperty("brooklyn.example.hadoop.site.xml.contents"); -if (hadoopConfigUrl==null && hadoopConfigContents==null) { -%> -

There is no hadoop included as part of this example. Set brooklyn.example.hadoop.site.xml.url - or brooklyn.example.hadoop.site.xml.contents to proceed.

-<% } else { /* begin hadoop-enabled block */ - -try { - org.apache.hadoop.conf.Configuration conf = new org.apache.hadoop.conf.Configuration(); - conf.setClassLoader(brooklyn.demo.webapp.hello.HadoopWordCount.class.getClassLoader()); - if (hadoopConfigUrl!=null) conf.addResource(new java.net.URL(hadoopConfigUrl)); - if (hadoopConfigContents!=null) conf.addResource(new java.io.ByteArrayInputStream(hadoopConfigContents.getBytes())); - org.apache.hadoop.fs.FileSystem fsClient = org.apache.hadoop.fs.FileSystem.get(conf); - if (fsClient==null) throw new NullPointerException("Can't access fsClient"); - - if (request.getParameter("name")!=null) { - java.io.OutputStream os1 = fsClient.create(new org.apache.hadoop.fs.Path("chats", ""+System.currentTimeMillis()+"-"+((int)(Math.random()*10000)))); - os1.write(request.getParameter("name").getBytes()); - os1.write(" : ".getBytes()); - os1.write(request.getParameter("message").getBytes()); - os1.flush(); os1.close(); - } -%> -
-

Visitors:

-
    -<% - org.apache.hadoop.fs.FileStatus[] files = fsClient.listStatus(new org.apache.hadoop.fs.Path("chats")); - if (files==null) files = new org.apache.hadoop.fs.FileStatus[0]; - for (org.apache.hadoop.fs.FileStatus f: files) { -%> -
  • <%= brooklyn.demo.webapp.hello.DemoUtils.stringFromInputStream(fsClient.open(f.getPath())) %>
  • -<% - } - if (files.length==0) { - %> -
  • None.
  • - <% - } - %> - -
-
- -

Please enter a message:

- -
- - - -
Name:
Message:
- -
- -<% -} catch (Exception e) { -%> - Error connecting to Hadoop.
- ERROR: <%= e %>

-
 <%= brooklyn.demo.webapp.hello.DemoUtils.getStackTrace(e) %>
-<% -} -} -%> - -
-

Click here to run a map-reduce job counting the words in these comments.

-

Click here to go back to the main page.

- - - diff --git a/webapps/hello-world-hadoop/src/main/webapp/hadoop-wordcount.jsp b/webapps/hello-world-hadoop/src/main/webapp/hadoop-wordcount.jsp deleted file mode 100644 index 944b254..0000000 --- a/webapps/hello-world-hadoop/src/main/webapp/hadoop-wordcount.jsp +++ /dev/null @@ -1,103 +0,0 @@ -<%@ page language="java" import="java.sql.*"%> - - - -Sample Application Database JSP Page - - - - - - - - -
- - -

Sample Brooklyn Deployed WebApp (Hadoop JSP)

-This is the output of a JSP page that is part of the Hello, World application, -deployed by brooklyn, to show a hadoop map-reduce task run. -
- -<% -String hadoopConfigUrl=System.getProperty("brooklyn.example.hadoop.site.xml.url"); -String hadoopConfigContents=System.getProperty("brooklyn.example.hadoop.site.xml.contents"); -if (hadoopConfigUrl==null && hadoopConfigContents==null) { -%> -

There is no hadoop included as part of this example. Set brooklyn.example.hadoop.site.xml.url - or brooklyn.example.hadoop.site.xml.contents to proceed.

-<% } else { /* begin hadoop-enabled block */ - -try { - org.apache.hadoop.conf.Configuration conf = new org.apache.hadoop.conf.Configuration(); - conf.setClassLoader(brooklyn.demo.webapp.hello.HadoopWordCount.class.getClassLoader()); - if (hadoopConfigUrl!=null) conf.addResource(new java.net.URL(hadoopConfigUrl)); - if (hadoopConfigContents!=null) conf.addResource(new java.io.ByteArrayInputStream(hadoopConfigContents.getBytes())); - org.apache.hadoop.fs.FileSystem fsClient = org.apache.hadoop.fs.FileSystem.get(conf); - if (fsClient==null) throw new NullPointerException("Can't access fsClient"); - - org.apache.hadoop.mapreduce.Job job = brooklyn.demo.webapp.hello.HadoopWordCount.makeJob(conf); - String jar = brooklyn.demo.webapp.hello.SerializeHelloWorldHadoopJar.getJarName(); - if (jar!=null) { ((org.apache.hadoop.mapred.JobConf)job.getConfiguration()).setJar(jar); } - else { %>JAR not available. Map-Reduce submission will likely fail.<% } - org.apache.hadoop.fs.FileStatus[] files = fsClient.listStatus(new org.apache.hadoop.fs.Path("chats")); - if (files==null) files = new org.apache.hadoop.fs.FileStatus[0]; - for (org.apache.hadoop.fs.FileStatus f: files) { - org.apache.hadoop.mapreduce.lib.input.FileInputFormat.addInputPath(job, f.getPath()); - } - - org.apache.hadoop.fs.Path outp = new org.apache.hadoop.fs.Path("out-"+((int)(Math.random()*10000))); - org.apache.hadoop.mapreduce.lib.output.FileOutputFormat.setOutputPath(job, outp); - - %>

Running Map-Reduce... <% - out.flush(); - - boolean result = job.waitForCompletion(true); - - %> finished: <% - if (!result) { - %> Job failed. Consult the logs for more information.

<% - } else { - %> Success.

<% - } - - %>

Output from map reduce is as follows:

<% - - files = fsClient.listStatus(outp); - if (files==null) files = new org.apache.hadoop.fs.FileStatus[0]; - for (org.apache.hadoop.fs.FileStatus f: files) { - try { - if (!f.isDir() && f.getLen()>0) { - %> - <%= f.getPath() %>:
-
<%= brooklyn.demo.webapp.hello.DemoUtils.stringFromInputStream(fsClient.open(f.getPath())) %>
- <% - } - } catch (Exception e) { - %> Error: <%= e %><% - } - } - if (files.length==0) { - %> - No output. - <% - } - - fsClient.delete(outp, true); - -} catch (Exception e) { -%> - Error connecting to Hadoop.
- ERROR: <%= e %>
-
 <%= brooklyn.demo.webapp.hello.DemoUtils.getStackTrace(e) %>
-<% -} -} -%> - -
-

Click here to view the chat room.

-

Click here to go back to the main page.

- - - diff --git a/webapps/hello-world-hadoop/src/main/webapp/images/bridge-small.png b/webapps/hello-world-hadoop/src/main/webapp/images/bridge-small.png deleted file mode 100644 index 4149c3c..0000000 Binary files a/webapps/hello-world-hadoop/src/main/webapp/images/bridge-small.png and /dev/null differ diff --git a/webapps/hello-world-hadoop/src/main/webapp/index.html b/webapps/hello-world-hadoop/src/main/webapp/index.html deleted file mode 100644 index c9f7a1f..0000000 --- a/webapps/hello-world-hadoop/src/main/webapp/index.html +++ /dev/null @@ -1,25 +0,0 @@ - - -Sample "Hello, World" Application - - - - - - - - -
- - -

Sample Brooklyn Deployed "Hello, World" Application

-

This is the home page for a sample application used to illustrate -how web applications can be deployed to multi-cloud environments using Brooklyn. -

- -

-See the available illustrations here. -

- - - diff --git a/webapps/hello-world-sql/pom.xml b/webapps/hello-world-sql/pom.xml deleted file mode 100644 index e0d2e66..0000000 --- a/webapps/hello-world-sql/pom.xml +++ /dev/null @@ -1,25 +0,0 @@ - - 4.0.0 - brooklyn-example-hello-world-sql-webapp - war - hello-world-sql-webapp Maven Webapp - - - io.brooklyn.example - brooklyn-examples-webapps-parent - 0.6.0 - ../pom.xml - - - - - mysql - mysql-connector-java - 5.1.18 - - - - - brooklyn-example-hello-world-sql-webapp - - diff --git a/webapps/hello-world-sql/src/main/webapp/WEB-INF/web.xml b/webapps/hello-world-sql/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 9f88c1f..0000000 --- a/webapps/hello-world-sql/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - Archetype Created Web Application - diff --git a/webapps/hello-world-sql/src/main/webapp/available.jsp b/webapps/hello-world-sql/src/main/webapp/available.jsp deleted file mode 100644 index fee83e6..0000000 --- a/webapps/hello-world-sql/src/main/webapp/available.jsp +++ /dev/null @@ -1,51 +0,0 @@ - - -Sample "Hello, World" Application - - - - - - - - -
- - -

Sample Brooklyn Deployed "Hello, World" Application

-

This is the home page for a sample application used to illustrate -how web applications can be deployed to multi-cloud environments using Brooklyn. -

- -

-The following apps are available: -

- -

    -<% -String url=System.getProperty("brooklyn.example.db.url"); -//URL should be supplied e.g. "-Dbrooklyn.example.db.url=jdbc:mysql://localhost/visitors?user=brooklyn&password=br00k11n" -//(note quoting needed due to ampersand) -if (url!=null) { -%> -
  • SQL database chatroom
  • -<% } %> - -<% -String hadoop=System.getProperty("brooklyn.example.hadoop.site.xml.url"); -//URL should be supplied e.g. -Dbrooklyn.example.hadoop.site.xml.url=file://tmp/hadoop-site.xml -if (hadoop!=null) { -%> -
  • Hadoop chatroom
  • -
  • Hadoop wordcount (inevitably!) run over the chats
  • -<% } %> - -<% -if (hadoop==null && url==null) { -%> -
  • None. Try one of the other Brooklyn examples to see SQL or Hadoop.
  • -<% } %> -
- - - diff --git a/webapps/hello-world-sql/src/main/webapp/db.jsp b/webapps/hello-world-sql/src/main/webapp/db.jsp deleted file mode 100644 index 39b0c70..0000000 --- a/webapps/hello-world-sql/src/main/webapp/db.jsp +++ /dev/null @@ -1,105 +0,0 @@ -<%@ page language="java" import="java.sql.*"%> - - - -Sample Application Database JSP Page - - - - - - - - -
- - -

Sample Brooklyn Deployed WebApp (Database JSP)

-This is the output of a JSP page that is part of the Hello, World application, -deployed by brooklyn, to show SQL database interactivity. -
- -<% -String url=System.getProperty("brooklyn.example.db.url"); -//URL should be supplied e.g. ""-Dbrooklyn.example.db.url=jdbc:mysql://localhost/visitors?user=brooklyn&password=br00k11n" -//(note quoting needed due to ampersand) -if (url==null) { -%> -

(There is no database included as part of this example.)

-<% } else { /* begin database-enabled block */ %> - -
-

Visitors:

-
    - -<% -Connection con=null; -ResultSet rst=null; -Statement stmt=null; -int i=0; - -try { - - String DRIVER = "com.mysql.jdbc.Driver"; - Class.forName(DRIVER).newInstance(); - - con=DriverManager.getConnection(url); - stmt=con.createStatement(); - - if (request.getParameter("name")!=null) { - //add a message - stmt.execute("INSERT INTO MESSAGES values (default, '"+ - //better escaping and security desired... - //this essentially does StringEscapeUtils.escapeSql (either brooklyn.util or apache commons) - request.getParameter("name").replaceAll("'", "''")+ - "', '"+ - request.getParameter("message").replaceAll("'", "''")+ - "')"); - } - - rst=stmt.executeQuery("select * from MESSAGES"); - while (rst.next()) { -%> -
  • <%= rst.getString(2) %>: <%= rst.getString(3) %>
  • -<% - i++; - } -} catch (Exception e) { - i=-1; -%> -
  • The database does not appear to be connected.
  • -
  • ERROR: <%= e %>
  • -<% -} finally { - if (rst!=null) rst.close(); - if (stmt!=null) stmt.close(); - if (con!=null) con.close(); -} - -if (i==0) { -%> -
  • None.
  • -<% -} -%> - -
- -
- -

Please enter a message:

- -
- - - -
Name:
Message:
- -
- -<% } /* end of database-enabled block */ %> - -
-

Click here to go back to the main page.

- - diff --git a/webapps/hello-world-sql/src/main/webapp/hadoop-chat.jsp b/webapps/hello-world-sql/src/main/webapp/hadoop-chat.jsp deleted file mode 100644 index c5e6bdf..0000000 --- a/webapps/hello-world-sql/src/main/webapp/hadoop-chat.jsp +++ /dev/null @@ -1,92 +0,0 @@ -<%@ page language="java" import="java.sql.*"%> - - - -Sample Application HDFS JSP Page - - - - - - - - -
- - -

Sample Brooklyn Deployed WebApp (Database JSP)

-This is the output of a JSP page that is part of the Hello, World application, -deployed by brooklyn, to show hadoop hdfs used as the data store. -
- -<% -String hadoop=System.getProperty("brooklyn.example.hadoop.site.xml.url"); -if (hadoop==null) { -%> -

(There is no hadoop included as part of this example.)

-<% } else { /* begin hadoop-enabled block */ - - -try { - org.apache.hadoop.conf.Configuration conf = new org.apache.hadoop.conf.Configuration(); - conf.setClassLoader(brooklyn.demo.webapp.hello.HadoopWordCount.class.getClassLoader()); - conf.addResource(new java.net.URL(hadoop)); - org.apache.hadoop.fs.FileSystem fsClient = org.apache.hadoop.fs.FileSystem.get(conf); - if (fsClient==null) throw new NullPointerException("Can't access fsClient at "+hadoop); - - if (request.getParameter("name")!=null) { - java.io.OutputStream os1 = fsClient.create(new org.apache.hadoop.fs.Path("chats", ""+System.currentTimeMillis()+"-"+((int)(Math.random()*10000)))); - os1.write(request.getParameter("name").getBytes()); - os1.write(" : ".getBytes()); - os1.write(request.getParameter("message").getBytes()); - os1.flush(); os1.close(); - } -%> -
-

Visitors:

-
    -<% - org.apache.hadoop.fs.FileStatus[] files = fsClient.listStatus(new org.apache.hadoop.fs.Path("chats")); - if (files==null) files = new org.apache.hadoop.fs.FileStatus[0]; - for (org.apache.hadoop.fs.FileStatus f: files) { -%> -
  • <%= brooklyn.demo.webapp.hello.DemoUtils.stringFromInputStream(fsClient.open(f.getPath())) %>
  • -<% - } - if (files.length==0) { - %> -
  • None.
  • - <% - } - %> - -
-
- -

Please enter a message:

- -
- - - -
Name:
Message:
- -
- -<% -} catch (Exception e) { -%> - Error connecting to Hadoop.
- ERROR: <%= e %>

-
 <%= brooklyn.demo.webapp.hello.DemoUtils.getStackTrace(e) %>
-<% -} -} -%> - -
-

Click here to run a map-reduce job counting the words in these comments.

-

Click here to go back to the main page.

- - - diff --git a/webapps/hello-world-sql/src/main/webapp/hadoop-wordcount.jsp b/webapps/hello-world-sql/src/main/webapp/hadoop-wordcount.jsp deleted file mode 100644 index 3b71a2c..0000000 --- a/webapps/hello-world-sql/src/main/webapp/hadoop-wordcount.jsp +++ /dev/null @@ -1,96 +0,0 @@ -<%@ page language="java" import="java.sql.*"%> - - - -Sample Application Database JSP Page - - - - - - - - -
- - -

Sample Brooklyn Deployed WebApp (Database JSP)

-This is the output of a JSP page that is part of the Hello, World application, -deployed by brooklyn, to show a hadoop map-reduce task run. -
- -<% -String hadoop=System.getProperty("brooklyn.example.hadoop.site.xml.url"); -String hadoopJar=System.getProperty("brooklyn.example.hadoop.custom.jar.url"); -if (hadoop==null) { -%> -

There is no hadoop included as part of this example. Set brooklyn.example.hadoop.site.xml.url to proceed.

-<% } else if (hadoopJar==null) { -%> -

brooklyn.example.hadoop.custom.jar.url must be set to point to the Jar.

-<%} else { /* begin hadoop-enabled block */ - -try { - org.apache.hadoop.conf.Configuration conf = new org.apache.hadoop.conf.Configuration(); - conf.setClassLoader(brooklyn.demo.webapp.hello.HadoopWordCount.class.getClassLoader()); - conf.addResource(new java.net.URL(hadoop)); - org.apache.hadoop.fs.FileSystem fsClient = org.apache.hadoop.fs.FileSystem.get(conf); - if (fsClient==null) throw new NullPointerException("Can't access fsClient at "+hadoop); - - org.apache.hadoop.mapreduce.Job job = brooklyn.demo.webapp.hello.HadoopWordCount.makeJob(conf); - ((org.apache.hadoop.mapred.JobConf)job.getConfiguration()).setJar(hadoopJar); - org.apache.hadoop.fs.FileStatus[] files = fsClient.listStatus(new org.apache.hadoop.fs.Path("chats")); - if (files==null) files = new org.apache.hadoop.fs.FileStatus[0]; - for (org.apache.hadoop.fs.FileStatus f: files) { - org.apache.hadoop.mapreduce.lib.input.FileInputFormat.addInputPath(job, f.getPath()); - } - - org.apache.hadoop.fs.Path outp = new org.apache.hadoop.fs.Path("out-"+((int)(Math.random()*10000))); - org.apache.hadoop.mapreduce.lib.output.FileOutputFormat.setOutputPath(job, outp); - - boolean result = job.waitForCompletion(true); - - if (!result) { - %>

Map reduce job returned non-zero result code.

<% - } - - %>

Output from map reduce is as follows:

<% - - files = fsClient.listStatus(outp); - if (files==null) files = new org.apache.hadoop.fs.FileStatus[0]; - for (org.apache.hadoop.fs.FileStatus f: files) { - try { - if (!f.isDir() && f.getLen()>0) { - %> - <%= f.getPath() %>:
-
<%= brooklyn.demo.webapp.hello.DemoUtils.stringFromInputStream(fsClient.open(f.getPath())) %>
- <% - } - } catch (Exception e) { - %> Error: <%= e %><% - } - } - if (files.length==0) { - %> - No output. - <% - } - - fsClient.delete(outp, true); - -} catch (Exception e) { -%> - Error connecting to Hadoop.
- ERROR: <%= e %>
-
 <%= brooklyn.demo.webapp.hello.DemoUtils.getStackTrace(e) %>
-<% -} -} -%> - -
-

Click here to view the chat room.

-

Click here to go back to the main page.

- - - diff --git a/webapps/hello-world-sql/src/main/webapp/images/bridge-small.png b/webapps/hello-world-sql/src/main/webapp/images/bridge-small.png deleted file mode 100644 index 4149c3c..0000000 Binary files a/webapps/hello-world-sql/src/main/webapp/images/bridge-small.png and /dev/null differ diff --git a/webapps/hello-world-sql/src/main/webapp/index.html b/webapps/hello-world-sql/src/main/webapp/index.html deleted file mode 100644 index c9f7a1f..0000000 --- a/webapps/hello-world-sql/src/main/webapp/index.html +++ /dev/null @@ -1,25 +0,0 @@ - - -Sample "Hello, World" Application - - - - - - - - -
- - -

Sample Brooklyn Deployed "Hello, World" Application

-

This is the home page for a sample application used to illustrate -how web applications can be deployed to multi-cloud environments using Brooklyn. -

- -

-See the available illustrations here. -

- - - diff --git a/webapps/hello-world-webapp/pom.xml b/webapps/hello-world-webapp/pom.xml deleted file mode 100644 index 61bc5da..0000000 --- a/webapps/hello-world-webapp/pom.xml +++ /dev/null @@ -1,17 +0,0 @@ - - 4.0.0 - war - brooklyn-example-hello-world-webapp - hello-world-webapp Maven Webapp - - - io.brooklyn.example - brooklyn-examples-webapps-parent - 0.6.0 - ../pom.xml - - - - brooklyn-example-hello-world-webapp - - diff --git a/webapps/hello-world-webapp/src/main/webapp/WEB-INF/web.xml b/webapps/hello-world-webapp/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 9f88c1f..0000000 --- a/webapps/hello-world-webapp/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - Archetype Created Web Application - diff --git a/webapps/hello-world-webapp/src/main/webapp/available.jsp b/webapps/hello-world-webapp/src/main/webapp/available.jsp deleted file mode 100644 index 6f696c2..0000000 --- a/webapps/hello-world-webapp/src/main/webapp/available.jsp +++ /dev/null @@ -1,58 +0,0 @@ - - -Sample "Hello, World" Application - - - - - - - - -
- - -

Sample Brooklyn Deployed "Hello, World" Application

-

This is the home page for a sample application used to illustrate -how web applications can be deployed to multi-cloud environments using Brooklyn. -

- -

-The following apps are available: -

- -

    -<% -String dburl=System.getProperty("brooklyn.example.db.url"); -//URL should be supplied e.g. "-Dbrooklyn.example.db.url=jdbc:mysql://localhost/visitors?user=brooklyn&password=br00k11n" -//(note quoting needed due to ampersand) -if (dburl!=null) { -%> -
  • SQL database chatroom
  • -<% } %> - -<% -String hadoop=System.getProperty("brooklyn.example.hadoop.site.xml.url"); -//URL should be supplied e.g. -Dbrooklyn.example.hadoop.site.xml.url=file://tmp/hadoop-site.xml -if (hadoop!=null) { -%> -
  • Hadoop chatroom
  • -
  • Hadoop wordcount (inevitably!) run over the chats
  • -<% } %> - -<% -boolean primes = true; -if (primes) { -%> -
  • Prime number counting (compute)
  • -<% } %> - -<% -if (hadoop==null && dburl==null && primes==false) { -%> -
  • None. Try one of the other Brooklyn examples to see SQL or Hadoop.
  • -<% } %> -
- - - diff --git a/webapps/hello-world-webapp/src/main/webapp/db.jsp b/webapps/hello-world-webapp/src/main/webapp/db.jsp deleted file mode 100644 index 39b0c70..0000000 --- a/webapps/hello-world-webapp/src/main/webapp/db.jsp +++ /dev/null @@ -1,105 +0,0 @@ -<%@ page language="java" import="java.sql.*"%> - - - -Sample Application Database JSP Page - - - - - - - - -
- - -

Sample Brooklyn Deployed WebApp (Database JSP)

-This is the output of a JSP page that is part of the Hello, World application, -deployed by brooklyn, to show SQL database interactivity. -
- -<% -String url=System.getProperty("brooklyn.example.db.url"); -//URL should be supplied e.g. ""-Dbrooklyn.example.db.url=jdbc:mysql://localhost/visitors?user=brooklyn&password=br00k11n" -//(note quoting needed due to ampersand) -if (url==null) { -%> -

(There is no database included as part of this example.)

-<% } else { /* begin database-enabled block */ %> - -
-

Visitors:

-
    - -<% -Connection con=null; -ResultSet rst=null; -Statement stmt=null; -int i=0; - -try { - - String DRIVER = "com.mysql.jdbc.Driver"; - Class.forName(DRIVER).newInstance(); - - con=DriverManager.getConnection(url); - stmt=con.createStatement(); - - if (request.getParameter("name")!=null) { - //add a message - stmt.execute("INSERT INTO MESSAGES values (default, '"+ - //better escaping and security desired... - //this essentially does StringEscapeUtils.escapeSql (either brooklyn.util or apache commons) - request.getParameter("name").replaceAll("'", "''")+ - "', '"+ - request.getParameter("message").replaceAll("'", "''")+ - "')"); - } - - rst=stmt.executeQuery("select * from MESSAGES"); - while (rst.next()) { -%> -
  • <%= rst.getString(2) %>: <%= rst.getString(3) %>
  • -<% - i++; - } -} catch (Exception e) { - i=-1; -%> -
  • The database does not appear to be connected.
  • -
  • ERROR: <%= e %>
  • -<% -} finally { - if (rst!=null) rst.close(); - if (stmt!=null) stmt.close(); - if (con!=null) con.close(); -} - -if (i==0) { -%> -
  • None.
  • -<% -} -%> - -
- -
- -

Please enter a message:

- -
- - - -
Name:
Message:
- -
- -<% } /* end of database-enabled block */ %> - -
-

Click here to go back to the main page.

- - diff --git a/webapps/hello-world-webapp/src/main/webapp/hadoop-chat.jsp b/webapps/hello-world-webapp/src/main/webapp/hadoop-chat.jsp deleted file mode 100644 index c5e6bdf..0000000 --- a/webapps/hello-world-webapp/src/main/webapp/hadoop-chat.jsp +++ /dev/null @@ -1,92 +0,0 @@ -<%@ page language="java" import="java.sql.*"%> - - - -Sample Application HDFS JSP Page - - - - - - - - -
- - -

Sample Brooklyn Deployed WebApp (Database JSP)

-This is the output of a JSP page that is part of the Hello, World application, -deployed by brooklyn, to show hadoop hdfs used as the data store. -
- -<% -String hadoop=System.getProperty("brooklyn.example.hadoop.site.xml.url"); -if (hadoop==null) { -%> -

(There is no hadoop included as part of this example.)

-<% } else { /* begin hadoop-enabled block */ - - -try { - org.apache.hadoop.conf.Configuration conf = new org.apache.hadoop.conf.Configuration(); - conf.setClassLoader(brooklyn.demo.webapp.hello.HadoopWordCount.class.getClassLoader()); - conf.addResource(new java.net.URL(hadoop)); - org.apache.hadoop.fs.FileSystem fsClient = org.apache.hadoop.fs.FileSystem.get(conf); - if (fsClient==null) throw new NullPointerException("Can't access fsClient at "+hadoop); - - if (request.getParameter("name")!=null) { - java.io.OutputStream os1 = fsClient.create(new org.apache.hadoop.fs.Path("chats", ""+System.currentTimeMillis()+"-"+((int)(Math.random()*10000)))); - os1.write(request.getParameter("name").getBytes()); - os1.write(" : ".getBytes()); - os1.write(request.getParameter("message").getBytes()); - os1.flush(); os1.close(); - } -%> -
-

Visitors:

-
    -<% - org.apache.hadoop.fs.FileStatus[] files = fsClient.listStatus(new org.apache.hadoop.fs.Path("chats")); - if (files==null) files = new org.apache.hadoop.fs.FileStatus[0]; - for (org.apache.hadoop.fs.FileStatus f: files) { -%> -
  • <%= brooklyn.demo.webapp.hello.DemoUtils.stringFromInputStream(fsClient.open(f.getPath())) %>
  • -<% - } - if (files.length==0) { - %> -
  • None.
  • - <% - } - %> - -
-
- -

Please enter a message:

- -
- - - -
Name:
Message:
- -
- -<% -} catch (Exception e) { -%> - Error connecting to Hadoop.
- ERROR: <%= e %>

-
 <%= brooklyn.demo.webapp.hello.DemoUtils.getStackTrace(e) %>
-<% -} -} -%> - -
-

Click here to run a map-reduce job counting the words in these comments.

-

Click here to go back to the main page.

- - - diff --git a/webapps/hello-world-webapp/src/main/webapp/hadoop-wordcount.jsp b/webapps/hello-world-webapp/src/main/webapp/hadoop-wordcount.jsp deleted file mode 100644 index 3b71a2c..0000000 --- a/webapps/hello-world-webapp/src/main/webapp/hadoop-wordcount.jsp +++ /dev/null @@ -1,96 +0,0 @@ -<%@ page language="java" import="java.sql.*"%> - - - -Sample Application Database JSP Page - - - - - - - - -
- - -

Sample Brooklyn Deployed WebApp (Database JSP)

-This is the output of a JSP page that is part of the Hello, World application, -deployed by brooklyn, to show a hadoop map-reduce task run. -
- -<% -String hadoop=System.getProperty("brooklyn.example.hadoop.site.xml.url"); -String hadoopJar=System.getProperty("brooklyn.example.hadoop.custom.jar.url"); -if (hadoop==null) { -%> -

There is no hadoop included as part of this example. Set brooklyn.example.hadoop.site.xml.url to proceed.

-<% } else if (hadoopJar==null) { -%> -

brooklyn.example.hadoop.custom.jar.url must be set to point to the Jar.

-<%} else { /* begin hadoop-enabled block */ - -try { - org.apache.hadoop.conf.Configuration conf = new org.apache.hadoop.conf.Configuration(); - conf.setClassLoader(brooklyn.demo.webapp.hello.HadoopWordCount.class.getClassLoader()); - conf.addResource(new java.net.URL(hadoop)); - org.apache.hadoop.fs.FileSystem fsClient = org.apache.hadoop.fs.FileSystem.get(conf); - if (fsClient==null) throw new NullPointerException("Can't access fsClient at "+hadoop); - - org.apache.hadoop.mapreduce.Job job = brooklyn.demo.webapp.hello.HadoopWordCount.makeJob(conf); - ((org.apache.hadoop.mapred.JobConf)job.getConfiguration()).setJar(hadoopJar); - org.apache.hadoop.fs.FileStatus[] files = fsClient.listStatus(new org.apache.hadoop.fs.Path("chats")); - if (files==null) files = new org.apache.hadoop.fs.FileStatus[0]; - for (org.apache.hadoop.fs.FileStatus f: files) { - org.apache.hadoop.mapreduce.lib.input.FileInputFormat.addInputPath(job, f.getPath()); - } - - org.apache.hadoop.fs.Path outp = new org.apache.hadoop.fs.Path("out-"+((int)(Math.random()*10000))); - org.apache.hadoop.mapreduce.lib.output.FileOutputFormat.setOutputPath(job, outp); - - boolean result = job.waitForCompletion(true); - - if (!result) { - %>

Map reduce job returned non-zero result code.

<% - } - - %>

Output from map reduce is as follows:

<% - - files = fsClient.listStatus(outp); - if (files==null) files = new org.apache.hadoop.fs.FileStatus[0]; - for (org.apache.hadoop.fs.FileStatus f: files) { - try { - if (!f.isDir() && f.getLen()>0) { - %> - <%= f.getPath() %>:
-
<%= brooklyn.demo.webapp.hello.DemoUtils.stringFromInputStream(fsClient.open(f.getPath())) %>
- <% - } - } catch (Exception e) { - %> Error: <%= e %><% - } - } - if (files.length==0) { - %> - No output. - <% - } - - fsClient.delete(outp, true); - -} catch (Exception e) { -%> - Error connecting to Hadoop.
- ERROR: <%= e %>
-
 <%= brooklyn.demo.webapp.hello.DemoUtils.getStackTrace(e) %>
-<% -} -} -%> - -
-

Click here to view the chat room.

-

Click here to go back to the main page.

- - - diff --git a/webapps/hello-world-webapp/src/main/webapp/images/bridge-small.png b/webapps/hello-world-webapp/src/main/webapp/images/bridge-small.png deleted file mode 100644 index 4149c3c..0000000 Binary files a/webapps/hello-world-webapp/src/main/webapp/images/bridge-small.png and /dev/null differ diff --git a/webapps/hello-world-webapp/src/main/webapp/index.html b/webapps/hello-world-webapp/src/main/webapp/index.html deleted file mode 100644 index c9f7a1f..0000000 --- a/webapps/hello-world-webapp/src/main/webapp/index.html +++ /dev/null @@ -1,25 +0,0 @@ - - -Sample "Hello, World" Application - - - - - - - - -
- - -

Sample Brooklyn Deployed "Hello, World" Application

-

This is the home page for a sample application used to illustrate -how web applications can be deployed to multi-cloud environments using Brooklyn. -

- -

-See the available illustrations here. -

- - - diff --git a/webapps/hello-world-webapp/src/main/webapp/primes.jsp b/webapps/hello-world-webapp/src/main/webapp/primes.jsp deleted file mode 100644 index ee1d838..0000000 --- a/webapps/hello-world-webapp/src/main/webapp/primes.jsp +++ /dev/null @@ -1,59 +0,0 @@ -<%@ page language="java"%> - - - -Sample Application Compute JSP Page - - - - - - - - -
- - -

Sample Brooklyn Deployed WebApp (Compute Primes JSP)

-This is the output of a JSP page that is part of the Hello, World application, -deployed by brooklyn, to show compute load by generating primes. -
- -<% -Object nx = request.getParameter("n"); -if (nx==null) { -%> -

Please supply a value n in the URL, to compute primes up to n.

-
- - -
Count primes up to:
- -
- -<% -} else { - long n = Long.parseLong(""+nx); - long startTime = System.currentTimeMillis(); - int count = 0; - for (long k=2; k<=n; k++) { - // check if k prime - boolean prime = true; - for (long j=2; j*j<=k; j++) { - if (k%j==0) { - prime = false; - break; - } - } - if (prime) count++; - } - long totalTime = System.currentTimeMillis() - startTime; -%> -

There are <%= count %> primes less than or equal to <%= n %>.

-

Computation took <%= totalTime %> ms.

-<% -} -%> - - - diff --git a/webapps/pom.xml b/webapps/pom.xml deleted file mode 100644 index 50f715a..0000000 --- a/webapps/pom.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - 4.0.0 - pom - brooklyn-examples-webapps-parent - Brooklyn Examples Support Aggregator Project - Webapps - - Brooklyn examples module, building the Brooklyn examples. - - - - io.brooklyn.example - brooklyn-examples-parent - 0.6.0 - ../pom.xml - - - - UTF-8 - - - - hello-world-webapp - hello-world-sql - hello-world-hadoop-jar - hello-world-hadoop - -