brooklyn.catalog:
  version: "1.1.0"

  items:
  - id: amp-networking-riak-node
    item:
      type: org.apache.brooklyn.entity.nosql.riak.RiakNode
      brooklyn.config:
        version: 2.0.5
        # The cluster configures its own security groups when this parameter is true.
        configInternalNetworking: false
        provisioning.properties:
          osFamily: centos
          osVersionRegex: 7\..*
        # The cluster won't form if firewalld is running.
        # See https://issues.apache.org/jira/browse/BROOKLYN-252.
        preInstallCommand: "sudo systemctl stop firewalld ; sudo systemctl disable firewalld"

  - id: amp-networking-riak-cluster
    item:
      type: org.apache.brooklyn.entity.nosql.riak.RiakCluster
      brooklyn.config:
        initialSize: 3
        memberSpec:
          $brooklyn:entitySpec:
            type: amp-networking-riak-node

  - id: amp-networking-tomcat-node
    item:
      type: org.apache.brooklyn.entity.webapp.tomcat.TomcatServer
      brooklyn.config:
        wars.root: "https://repository.apache.org/content/repositories/releases/org/apache/brooklyn/example/brooklyn-example-hello-world-sql-webapp/0.12.0/brooklyn-example-hello-world-sql-webapp-0.12.0.war"

  - id: amp-networking-web-cluster
    item:
      type: org.apache.brooklyn.entity.webapp.DynamicWebAppCluster
      name: Application Servers
      brooklyn.config:
        initialSize: 3
        memberSpec:
          $brooklyn:entitySpec:
            type: amp-networking-tomcat-node

  - id: amp-networking-example-app
    description: |
      Comprises an Nginx load balancer fronting a cluster of Apache Tomcat servers that run a web application
      that communicates with a cluster of Riak nodes. Network security is configured so that each tier grants
      the minimal access required to the other components. Only the Nginx server may be accessed from the
      public internet.
    item:
      type: org.apache.brooklyn.entity.stock.BasicApplication
      name: AMP Networking Demo Application
      brooklyn.children:
      - type: amp-networking-riak-cluster
        name: Back Office
        id: riak-cluster
        brooklyn.initializers:
        - type: io.cloudsoft.amp.networking.NetworkSecurityCustomizer
          brooklyn.config:
            networks:
            - back-office
            networks-ingress:
            - network: application-servers
              exposing:
              - riak.webPort

      - type: amp-networking-web-cluster
        id: application-servers
        name: Application Servers
        brooklyn.config:
          java.sysprops:
            brooklyn.example.riak.nodes: $brooklyn:component("riak-cluster").attributeWhenReady("riak.cluster.nodeList")
        brooklyn.initializers:
        - type: io.cloudsoft.amp.networking.NetworkSecurityCustomizer
          brooklyn.config:
            networks:
            - application-servers
            networks-ingress:
            - network: frontend
              exposing:
              - http.port

      - type: org.apache.brooklyn.entity.proxy.nginx.NginxController
        name: Load Balancer
        brooklyn.config:
          serverPool: $brooklyn:entity("application-servers")
        brooklyn.initializers:
        - type: io.cloudsoft.amp.networking.NetworkSecurityCustomizer
          brooklyn.config:
            networks:
            - frontend
            - public
            networks-ingress:
            - network: public
              exposing:
              - proxy.http.port
