Compose a 3-tier Application (CLI)


In this tutorial we will show you how to use the AMP CLI to deploy a three-tier web application.


This tutorial assumes you have installed Cloudsoft AMP, and the AMP CLI.

Once downloaded, you need to login using br login http://localhost:8081/ admin password.

To get help on the available commands, use br --help.


The following YAML describes the topology of a three tier webapp, using a MySQL backing store and a cluster of Tomcat containers behind an Nginx load balancer.

name: My Web Cluster

- type: org.apache.brooklyn.entity.database.mysql.MySqlNode
  id: db
  name: My DB (MySQL)
- type:
  name: My Cluster
  id: cluster
    initialSize: 2
        type: org.apache.brooklyn.entity.webapp.tomcat.TomcatServer
        name: Tomcat Server
              - "jdbc:%s%s?user=%s&password=%s"
              - $brooklyn:component("db").attributeWhenReady("datastore.url")
              - "visitors"
              - "brooklyn"
              - "br00k11n"
  - type: org.apache.brooklyn.enricher.stock.Aggregator
      enricher.sourceSensor: $brooklyn:sensor("webapp.reqs.perSec.windowed")
      enricher.targetSensor: $brooklyn:sensor("webapp.reqs.perSec.perNode")
      enricher.aggregating.fromMembers: true
      transformation: average
- type: org.apache.brooklyn.entity.proxy.nginx.NginxController
  id: nginx
  name: My Load Balancer (nginx)
    loadbalancer.serverpool: $brooklyn:entity("cluster")
    nginx.sticky: false
- type: org.apache.brooklyn.enricher.stock.Propagator
    producer: $brooklyn:entity("nginx")
    - main.uri
    - main.uri.mapped.subnet
    - main.uri.mapped.public

This blueprint is composed of the following items:

  1. A MySQL node, which is configured with the URL of a database creation script.
  2. A DynamicCluster where all its children are of type org.apache.brooklyn.entity.webapp.tomcat.TomcatServer. Each child has a configuration of wars.root, which is the URL of an application war and some java system properties for the application to use. The only system property given here is the connection string to the MySQL node. The connection string is formed using a special syntax (the AMP DSL) to reference the other components in the blueprint; the component db in this case.
  3. A NginxController that act as a load-balancer for the previous cluster ot Tomcat servers. The entity knows about the cluster thanks to loadbalancer.serverpool and the DSL.

In order to deploy this blueprint, a location in which to deploy it is required. Firstly we need to create a location if none are available, then add a location: locationId section to the blueprint. This blueprint should then be saved to a file, three-tier.yaml for example.

Then to deploy the blueprint, run the command:

br deploy three-tier.yaml


This blueprint assume that your location is correctly configured for all the VMs to be able to talk to each other using their internal IPs. However, depending on your location configuration, the VMs might not be on the same network. If that is the case, the deployment will not fail but the load-balancer will have a wrong configuration.

Here are some quick workarounds:

  • You can configure Nginx to use a different sensor to build its configuration. For example, to use the public address, you can add the following line under brooklyn.config of nginx:
member.sensor.hostname: host.address


The CLI is an alternative means of managing applications within AMP and is particularly suitable for automation.