** TODO: this examples page is deprecated; code is out-of-date, and better examples are described on the web site. need to figure out if this page should be kept at all (indeed if the “guide” is even still relevant)**
If you have a Maven-based project, integrate this XML fragment with your pom.xml:
{% highlight xml %} io.brooklyn brooklyn-all 0.8.0-incubating
The code below starts a Tomcat server on the local machine.
The main
method defines the application, and passes it to the BrooklynLauncher
to be managed. It is then started in a localhost location (other locations are shown in the next section).
The Tomcat's configuration indicates that the given WAR should be deployed to the Tomcat server when it is started.
{% highlight java %} {% readj example_files/tomcat_simple.java %} {% endhighlight %}
The wars
config is also supported (with config keys ROOT_WAR
and NAMED_WARS
the long-hand syntax); they accept EARs and other common archives, and can be described as files or as URLs (as Strings), with URLs supporting an optional classpath://org/acme/resources/xxx.war
syntax.
To start a tomcat node or cluster in Amazon EC2, the application is identical to that for localhost. The only difference is the location supplied.
The Brooklyn CLI can be used to launch the application in your choice of location, such as:
{% highlight bash %} brooklyn launch --app TomcatServerApp --location localhost brooklyn launch --app TomcatServerApp --location aws-ec2:eu-west-1 {% endhighlight %}
The code below starts a Tomcat cluster along with an Nginx instance, where each Tomcat server in the cluster is registered with the Nginx instance.
{% highlight java %} {% readj example_files/tomcat_nginx.java %} {% endhighlight %}
This creates a cluster that of Tomcat servers, along with an Nginx instance. The NginxController
instance is notified whenever a member of the cluster joins or leaves; the entity is configured to look at the HTTP_PORT
attribute of that instance so that the Nginx configuration can be updated with the ip:port of the cluster member.
The ControlledDynamicWebAppCluster
entity used above can also be used with a DynamicFabric to start a web-cluster in each location.
{% highlight java %} {% readj example_files/tomcat_multi-location.java %} {% endhighlight %}
Source code for (more up-to-date!) examples is available for download from GitHub. To retrieve the source, execute the following command:
git clone git@github.com:apache/incubator-brooklyn.git cd incubator-brooklyn/examples
You can also browse the code on the web.