cloudsoft.io

Compose a 3-tier Application (CLI)

Objectives

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

Pre-requisites

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.

Instructions

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

services:
- type: org.apache.brooklyn.entity.database.mysql.MySqlNode
  id: db
  name: My DB (MySQL)
  brooklyn.config:
    datastore.creation.script.url: https://raw.githubusercontent.com/apache/brooklyn-library/master/examples/simple-web-cluster/src/main/resources/visitors-creation-script.sql
- type: org.apache.brooklyn.entity.group.DynamicCluster
  name: My Cluster
  id: cluster
  brooklyn.config:
    initialSize: 2
    memberSpec:
      $brooklyn:entitySpec:
        type: org.apache.brooklyn.entity.webapp.tomcat.TomcatServer
        name: Tomcat Server
        brooklyn.config:
          wars.root: http://search.maven.org/remotecontent?filepath=org/apache/brooklyn/example/brooklyn-example-hello-world-sql-webapp/0.9.0/brooklyn-example-hello-world-sql-webapp-0.9.0.war
          java.sysprops:
            brooklyn.example.db.url:
              $brooklyn:formatString:
              - "jdbc:%s%s?user=%s&password=%s"
              - $brooklyn:component("db").attributeWhenReady("datastore.url")
              - "visitors"
              - "brooklyn"
              - "br00k11n"
  brooklyn.enrichers:
  - type: org.apache.brooklyn.enricher.stock.Aggregator
    brooklyn.config:
      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)
  brooklyn.config:
    loadbalancer.serverpool: $brooklyn:entity("cluster")
    nginx.sticky: false
brooklyn.enrichers:
- type: org.apache.brooklyn.enricher.stock.Propagator
  brooklyn.config:
    producer: $brooklyn:entity("nginx")
    propagating:
    - 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

Gotchas

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

Summary

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

Next