ghost-openstack-blueprint.yaml 9.52 KB
Newer Older
Daniel Baur's avatar
Daniel Baur committed
1 2 3 4 5 6 7 8 9 10
########################################
# Ghost Blueprint
# - nginx as loadbalancer
# - ghost webapp on nodejs
# - postgresql as db backend
########################################

tosca_definitions_version: cloudify_dsl_1_0

imports:
Daniel Baur's avatar
Daniel Baur committed
11 12 13
  - http://www.getcloudify.org/spec/cloudify/3.2/types.yaml
  - http://www.getcloudify.org/spec/openstack-plugin/1.2/plugin.yaml
  - http://www.getcloudify.org/spec/diamond-plugin/1.2/plugin.yaml
Daniel Baur's avatar
Daniel Baur committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
  - types/ghost.yaml
  - types/nginx.yaml

#####################################################################################
# inputs section allows the user to use same
# blueprint for creating different deployments, each one
# with its own parameters.
# to specify deployment inputs run:
#   - cfy deployments create -b <blueprint_id> -d <deployment_id> -i inputs.yaml
#####################################################################################
inputs:

  image:
    description: >
      Image to be used when launching agent VM's
  flavor:
    description: >
      Flavor of the agent VM's
  agent_user:
    description: >
      User for connecting to agent VM's
node_types:

  ###########################################################
  # We define a type that inherits openstack's default
  # server, and adds monitoring capabillities on top of it.
  ###########################################################

  ghost.nodes.MonitoredServer:
    derived_from: cloudify.openstack.nodes.Server
    properties:
      cloudify_agent:
        default:
          user: { get_input: agent_user }
      server:
        default:
          image: { get_input: image }
          flavor: { get_input: flavor }
    interfaces:

      ###########################################################
      # We are infact telling cloudify to install a diamond
      # monitoring agent on the server.
      #
      # (see https://github.com/BrightcoveOS/Diamond)
      ###########################################################

      cloudify.interfaces.monitoring_agent:
          install:
            implementation: diamond.diamond_agent.tasks.install
            inputs:
              diamond_config:
                default:
                  interval: 1
          start: diamond.diamond_agent.tasks.start
          stop: diamond.diamond_agent.tasks.stop
          uninstall: diamond.diamond_agent.tasks.uninstall

      ###########################################################
      # Adding some collectors. These collectors are necessary
      # for the Cloudify UI to display the deafult metrics.
      ###########################################################

      cloudify.interfaces.monitoring:
        start:
          implementation: diamond.diamond_agent.tasks.add_collectors
          inputs:
            collectors_config:
              default:
                CPUCollector: {}
                MemoryCollector: {}
                LoadAverageCollector: {}
                DiskUsageCollector:
                  config:
                    devices: x?vd[a-z]+[0-9]*$
                NetworkCollector: {}

node_templates:

  postgre_host:
    type: ghost.nodes.MonitoredServer
    relationships:

      ###########################################################
      # Attaching the postgre security group to the postgre host
      ###########################################################

Daniel Baur's avatar
Daniel Baur committed
101
      - target: postgre_security_group
Daniel Baur's avatar
Daniel Baur committed
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
        type: cloudify.openstack.server_connected_to_security_group

  nodejs_host:
    type: ghost.nodes.MonitoredServer

    ###########################################################
    # Setting the nodejs_host initial number of instances to 2.
    # The default values for instances.deploy is 1.
    ###########################################################

    instances:
      deploy: 2

    relationships:

      ###########################################################
      # Attaching the ghost security group to
      # the ghost host
      ###########################################################

      - target: ghost_security_group
        type: cloudify.openstack.server_connected_to_security_group

  nginx_frontend_host:
    type: ghost.nodes.MonitoredServer
    relationships:

      ###########################################################
      # Attaching a floating ip to the nginx frontend host
      ###########################################################

      - type: cloudify.openstack.server_connected_to_floating_ip
Daniel Baur's avatar
Daniel Baur committed
134
        target: frontend_floatingip
Daniel Baur's avatar
Daniel Baur committed
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170

      ###########################################################
      # Attaching the nginx frontend security group to
      # the nginx frontend host
      ###########################################################

      - type: cloudify.openstack.server_connected_to_security_group
        target: nginx_frontend_security_group

  postgre:
    type: ghost.nodes.PostgreSQL
    relationships:
      - type: cloudify.relationships.contained_in
        target: postgre_host

  nodejs:
    type: ghost.nodes.NodeJSServer
    relationships:
      - type: cloudify.relationships.contained_in
        target: nodejs_host

  ghost:
    type: ghost.nodes.GhostApplicationModule
    relationships:

      ################################
      # Setting the postgre connection
      ################################

      - type: node_connected_to_postgre
        target: postgre

      ################################
      # Setting the nodejs connection
      ################################

171 172
      - type: node_contained_in_nodejs
        target: nodejs
Daniel Baur's avatar
Daniel Baur committed
173 174

      ################################
175
      # Setting the nginx connection
Daniel Baur's avatar
Daniel Baur committed
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
      ################################

      - type: app_connected_to_nginx
        target: nginx

  nginx:
    type: nginx.nodes.Proxy
    relationships:
      - target: nginx_frontend_host
        type: cloudify.relationships.contained_in

  ###########################################################
  # A security group to enable access to the nodejs host
  # using the port of the ghost application.
  #
  # This security group will be attached to the nodejs_host
  ###########################################################

  ghost_security_group:
    type: cloudify.openstack.nodes.SecurityGroup
    properties:
      security_group:
        name: ghost_security_group
      rules:
        - remote_ip_prefix: 0.0.0.0/0
          port: 2368


  ###########################################################
  # A security group to enable access to the postgre host
  # using the port of the postgre node.
  #
  # We need this so that the ghost application can
  # comminicate with PostgreSQL DB, since they are running on
  # different hosts.
  ###########################################################

  postgre_security_group:
    type: cloudify.openstack.nodes.SecurityGroup
    properties:
      security_group:
        name: postgre_security_group
      rules:
        - remote_ip_prefix: 0.0.0.0/0
          port: 5432

  ###########################################################
  # A security group to enable access to the nginx frontend
  # host.
  #
  # This security group will be attached to the
  # nginx_frontend_host
  ###########################################################

  nginx_frontend_security_group:
    type: cloudify.openstack.nodes.SecurityGroup
    properties:
      security_group:
        name: nginx_frontend_security_group
      rules:
        - remote_ip_prefix: 0.0.0.0/0
          port: 80

  ###########################################################
  # A floating ip to be attached to the nginx frontend host,
  # since eventually we want to be able to access the application
  # from any machine, on any network.
  ###########################################################

  frontend_floatingip:
    type: cloudify.openstack.nodes.FloatingIP


###########################################################
# This outputs section exposes the application endpoint.
# You can access it by running:
#   - cfy deployments -d <deployment_id> outputs
###########################################################

outputs:
  endpoint:
    description: Web application endpoint
    value:
      ip_address: { get_attribute: [ frontend_floatingip, floating_ip_address ] }
Daniel Baur's avatar
Daniel Baur committed
260 261 262 263 264 265 266 267 268 269
      port: 80
	  
groups:
  nodejs:
    # adding the some_vm node template that was previously configured
    members: [nodejs_host]
    policies:
      cpu_threshold:
        # using the 'host_failure' policy type
        type: cloudify.policies.types.threshold
Daniel Baur's avatar
Daniel Baur committed
270 271 272 273 274 275
            # policy specific configuration
            properties:
                # Configure it
                service: system
                threshold: 50
                upper_bound: true
Daniel Baur's avatar
Daniel Baur committed
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298

        # Name of the service we want to shortlist (using regular expressions) and
        # watch - every Diamond event has the service field set to some value.
        # In our case, the ExampleCollector sends events with this value set to "example".
        service:
           - system

        triggers:
          heal_trigger:
            # using the 'execute_workflow' policy trigger
            type: cloudify.policies.triggers.execute_workflow
            parameters:
              # configuring this trigger to execute the scale workflow
              workflow: scale

              # The heal workflow will get
              # its parameters from the event that triggered
              # its execution
              workflow_parameters:
                # 'node_id' will be the node instance id
                # of the node that failed. In our case, it will be
                # something like 'some_vm_afd34'
                node_id: { get_property: [SELF, node_id] }
Daniel Baur's avatar
Daniel Baur committed
299 300
                delta: 1
                scale_compute: true