<commit_before>heat_template_version: 2013-05-23

description: |
  Heat template to deploy a multi-server Node.js deployment

parameter_groups:
- label: Server Settings
  parameters:
  - image
  - flavor

- label: Node.js Application Settings
  parameters:
  - revision
  - packages
  - repo
  - deploy_key

- label: rax-dev-params
  parameters:
  - destination
  - child_template
  - load_balancer_hostname
  - server_hostnames
  - kitchen
  - chef_version

parameters:
  server_hostnames:
    label: Server Name
    description: Server Name
    type: string
    default: nodejs-%index%
    constraints:
    - length:
        min: 1
        max: 64
    - allowed_pattern: "^[a-zA-Z][a-zA-Z0-9%-]*$"
      description: |
        Must begin with a letter and contain only alphanumeric characters.

  database_username:
    label: Database Username
    description: Database Username
    type: string
    default: 'nodejs'

  load_balancer_hostname:
    label: Load Balancer Hostname
    description: Hostname for the Cloud Load Balancer
    type: string
    default: nodejs-app-load-balancer
    constraints:
    - length:
        min: 1
        max: 64
    - allowed_pattern: "^[a-zA-Z][a-zA-Z0-9-]*$"
      description: |
        Must begin with a letter and contain only alphanumeric characters.

  nodejs_app_server_count:
    label: Server Count
    description: |
      Required: Number of servers to spin up as a part of this deployment.
    type: number
    default: 2
    constraints:
    - range:
        min: 1
        max: 25
      description: Must be between 1 and 25 servers.

  image:
    label: Operating System
    description: |
      Required: Server image used for all servers that are created as a part of
      this deployment.
    type: string
    default: Ubuntu 12.04 LTS (Precise Pangolin)
    constraints:
    - allowed_values:
      - Ubuntu 12.04 LTS (Precise Pangolin)
      description: Must be a supported operating system.

  flavor:
    label: Server Size
    description: |
      Required: Rackspace Cloud Server flavor to use. The size is based on the
      amount of RAM for the provisioned server.
    type: string
    default: 4 GB Performance
    constraints:
    - allowed_values:
      - 1 GB Performance
      - 2 GB Performance
      - 4 GB Performance
      - 8 GB Performance
      - 15 GB Performance
      - 30 GB Performance
      - 60 GB Performance
      - 90 GB Performance
      - 512MB Standard Instance
      - 1GB Standard Instance
      - 2GB Standard Instance
      - 4GB Standard Instance
      - 8GB Standard Instance
      - 15GB Standard Instance
      - 30GB Standard Instance
      description: |
        Must be a valid Rackspace Cloud Server flavor for the region you have
        selected to deploy into.

  db_flavor:
    label: Cloud Database Size
    description: |
      Required: Rackspace Cloud Database Flavor. Size is based on amount of RAM
      for the provisioned instance.
    type: string
    default: 1GB Instance
    constraints:
    - allowed_values:
      - 512MB Instance
      - 1GB Instance
      - 2GB Instance
      - 4GB Instance
      - 8GB Instance
      - 16GB Instance
      description: |
        Must be a valid Rackspace Cloud Database flavor for the region you have
        selected to deploy into.

  datastore_version:
    label: MySQL Version
    type: string
    description: |
      Required: Version of MySQL to run on the Cloud Databases instance.
    default: "5.6"
    constraints:
    - allowed_values:
      - "5.6"
      - "5.1"

  db_size:
    label: Database Size
    description: |
      Required: Amount of storage required for your Rackspace Cloud Database,
      in GB.
    type: number
    default: 10
    constraints:
    - range:
        min: 10
        max: 150
    description: |
        Database instance size, in GB. min 10, max 150

  revision:
    label: Revision
    description: |
      Optional: Git Branch/Ref to deploy. Default: HEAD
    type: string
    default: HEAD

  packages:
    label: System Packages
    description: |
      Optional: Additional system packages to install. For a list of available
      packages, see: http://packages.ubuntu.com/precise/allpackages
    type: string
    default: ''

  repo:
    label: Git Repository
    description: |
      Optional: URL to your git repository. Use the https:// syntax for public
      repositories, use git@ syntax for private repositories.
    type: string
    default: ''

  deploy_key:
    label: Git Deploy Key
    description: |
      Optional: If you specified a private repository, provide your private
      deploy key here.
    type: string
    default: ''

  destination:
    label: Site Path
    description: Path to setup your application on your servers.
    default: /var/www/vhosts/application
    type: string

  kitchen:
    description: URL for the kitchen to use
    type: string
    default: https://github.com/rackspace-orchestration-templates/nodejs-clouddb

  chef_version:
    description: Version of chef client to use
    type: string
    default: 11.16.0

  child_template:
    type: string
    default: https://raw.github.com/rackspace-orchestration-templates/nodejs-clouddb/master/node-web.yaml

resources:
  ssh_key:
    type: "OS::Nova::KeyPair"
    properties:
      name: { get_param: "OS::stack_id" }
      save_private_key: true

  load_balancer:
    type: "Rackspace::Cloud::LoadBalancer"
    depends_on: nodejs_app_servers
    properties:
      name:
        str_replace:
          template: '%lbname%_%stackid%'
          params:
            '%lbname%': { get_param: load_balancer_hostname }
            '%stackid%': { get_param: 'OS::stack_id' }

      nodes:
      - addresses: { get_attr: [nodejs_app_servers, privateIPv4] }
        port: 80
        condition: ENABLED
      port: 80
      healthMonitor:
        type: HTTP
        delay: 10
        timeout: 5
        attemptsBeforeDeactivation: 2
        path: /
        statusRegex: ^[2345]0[0-9]$
      protocol: HTTP
      algorithm: ROUND_ROBIN
      contentCaching: DISABLED
      virtualIps:
      - type: PUBLIC
        ipVersion: IPV4
      metadata:
        rax-heat: { get_param: "OS::stack_id" }

  database_user_password:
    type: "OS::Heat::RandomString"
    properties:
      length: 16
      sequence: lettersdigits

  db_admin_password:
    type: "OS::Heat::RandomString"
    properties:
      length: 16
      sequence: lettersdigits

  database_server:
    type: OS::Trove::Instance
    properties:
      name:
        str_replace:
          template: "nodejs_app_db_%stackid%"
          params:
            "%stackid%": { get_param: "OS::stack_id" }
      flavor: { get_param: db_flavor }
      size: { get_param: db_size }
      datastore_type: mysql
      datastore_version: { get_param: datastore_version }
      databases:
      - name: nodejs_db
      users:
      - name: { get_param: database_username }
        password: { get_resource: database_user_password }
        databases: [ nodejs_db ]

  nodejs_app_servers:
    type: "OS::Heat::ResourceGroup"
    depends_on: database_server
    properties:
      count: { get_param: nodejs_app_server_count }
      resource_def:
        type: ./node-web.yaml
        properties:
          hostname: { get_param: server_hostnames }
          ssh_key_name: { get_resource: ssh_key }
          ssh_private_key: { get_attr: [ssh_key, private_key] }
          kitchen: { get_param: kitchen }
          chef_version: { get_param: chef_version }
          revision: { get_param: revision }
          packages: { get_param: packages }
          repo: { get_param: repo }
          deploy_key: { get_param: deploy_key }
          destination: { get_param: destination }
          db_server_ip: { get_attr: [database_server, hostname] }
          database_username: { get_param: database_username }
          database_user_password: { get_resource: database_user_password }

outputs:
  load_balancer_ip:
    description: Load Balancer IP
    value: { get_attr: [load_balancer, PublicIp] }

  nodejs_url:
    description: "Node.js URL"
    value:
      str_replace:
        template: "http://%ip%"
        params:
          "%ip%": { get_attr: [load_balancer, PublicIp] }

  database_server_ip:
    description: Database Server IP
    value: { get_attr: [database_server, hostname] }

  mysql_root_password:
    description: MySQL Root Password
    value: { get_attr: [db_admin_password, value] }

  node_server_ips:
    description: Node.js Server IPs
    value: { get_attr: [nodejs_app_servers, accessIPv4] }

  private_key:
    description: SSH Private Key
    value: { get_attr: [ssh_key, private_key] }<commit_msg>update description of output database_server_ip<commit_after>heat_template_version: 2013-05-23

description: |
  Heat template to deploy a multi-server Node.js deployment

parameter_groups:
- label: Server Settings
  parameters:
  - image
  - flavor

- label: Node.js Application Settings
  parameters:
  - revision
  - packages
  - repo
  - deploy_key

- label: rax-dev-params
  parameters:
  - destination
  - child_template
  - load_balancer_hostname
  - server_hostnames
  - kitchen
  - chef_version

parameters:
  server_hostnames:
    label: Server Name
    description: Server Name
    type: string
    default: nodejs-%index%
    constraints:
    - length:
        min: 1
        max: 64
    - allowed_pattern: "^[a-zA-Z][a-zA-Z0-9%-]*$"
      description: |
        Must begin with a letter and contain only alphanumeric characters.

  database_username:
    label: Database Username
    description: Database Username
    type: string
    default: 'nodejs'

  load_balancer_hostname:
    label: Load Balancer Hostname
    description: Hostname for the Cloud Load Balancer
    type: string
    default: nodejs-app-load-balancer
    constraints:
    - length:
        min: 1
        max: 64
    - allowed_pattern: "^[a-zA-Z][a-zA-Z0-9-]*$"
      description: |
        Must begin with a letter and contain only alphanumeric characters.

  nodejs_app_server_count:
    label: Server Count
    description: |
      Required: Number of servers to spin up as a part of this deployment.
    type: number
    default: 2
    constraints:
    - range:
        min: 1
        max: 25
      description: Must be between 1 and 25 servers.

  image:
    label: Operating System
    description: |
      Required: Server image used for all servers that are created as a part of
      this deployment.
    type: string
    default: Ubuntu 12.04 LTS (Precise Pangolin)
    constraints:
    - allowed_values:
      - Ubuntu 12.04 LTS (Precise Pangolin)
      description: Must be a supported operating system.

  flavor:
    label: Server Size
    description: |
      Required: Rackspace Cloud Server flavor to use. The size is based on the
      amount of RAM for the provisioned server.
    type: string
    default: 4 GB Performance
    constraints:
    - allowed_values:
      - 1 GB Performance
      - 2 GB Performance
      - 4 GB Performance
      - 8 GB Performance
      - 15 GB Performance
      - 30 GB Performance
      - 60 GB Performance
      - 90 GB Performance
      - 512MB Standard Instance
      - 1GB Standard Instance
      - 2GB Standard Instance
      - 4GB Standard Instance
      - 8GB Standard Instance
      - 15GB Standard Instance
      - 30GB Standard Instance
      description: |
        Must be a valid Rackspace Cloud Server flavor for the region you have
        selected to deploy into.

  db_flavor:
    label: Cloud Database Size
    description: |
      Required: Rackspace Cloud Database Flavor. Size is based on amount of RAM
      for the provisioned instance.
    type: string
    default: 1GB Instance
    constraints:
    - allowed_values:
      - 512MB Instance
      - 1GB Instance
      - 2GB Instance
      - 4GB Instance
      - 8GB Instance
      - 16GB Instance
      description: |
        Must be a valid Rackspace Cloud Database flavor for the region you have
        selected to deploy into.

  datastore_version:
    label: MySQL Version
    type: string
    description: |
      Required: Version of MySQL to run on the Cloud Databases instance.
    default: "5.6"
    constraints:
    - allowed_values:
      - "5.6"
      - "5.1"

  db_size:
    label: Database Size
    description: |
      Required: Amount of storage required for your Rackspace Cloud Database,
      in GB.
    type: number
    default: 10
    constraints:
    - range:
        min: 10
        max: 150
    description: |
        Database instance size, in GB. min 10, max 150

  revision:
    label: Revision
    description: |
      Optional: Git Branch/Ref to deploy. Default: HEAD
    type: string
    default: HEAD

  packages:
    label: System Packages
    description: |
      Optional: Additional system packages to install. For a list of available
      packages, see: http://packages.ubuntu.com/precise/allpackages
    type: string
    default: ''

  repo:
    label: Git Repository
    description: |
      Optional: URL to your git repository. Use the https:// syntax for public
      repositories, use git@ syntax for private repositories.
    type: string
    default: ''

  deploy_key:
    label: Git Deploy Key
    description: |
      Optional: If you specified a private repository, provide your private
      deploy key here.
    type: string
    default: ''

  destination:
    label: Site Path
    description: Path to setup your application on your servers.
    default: /var/www/vhosts/application
    type: string

  kitchen:
    description: URL for the kitchen to use
    type: string
    default: https://github.com/rackspace-orchestration-templates/nodejs-clouddb

  chef_version:
    description: Version of chef client to use
    type: string
    default: 11.16.0

  child_template:
    type: string
    default: https://raw.github.com/rackspace-orchestration-templates/nodejs-clouddb/master/node-web.yaml

resources:
  ssh_key:
    type: "OS::Nova::KeyPair"
    properties:
      name: { get_param: "OS::stack_id" }
      save_private_key: true

  load_balancer:
    type: "Rackspace::Cloud::LoadBalancer"
    depends_on: nodejs_app_servers
    properties:
      name:
        str_replace:
          template: '%lbname%_%stackid%'
          params:
            '%lbname%': { get_param: load_balancer_hostname }
            '%stackid%': { get_param: 'OS::stack_id' }

      nodes:
      - addresses: { get_attr: [nodejs_app_servers, privateIPv4] }
        port: 80
        condition: ENABLED
      port: 80
      healthMonitor:
        type: HTTP
        delay: 10
        timeout: 5
        attemptsBeforeDeactivation: 2
        path: /
        statusRegex: ^[2345]0[0-9]$
      protocol: HTTP
      algorithm: ROUND_ROBIN
      contentCaching: DISABLED
      virtualIps:
      - type: PUBLIC
        ipVersion: IPV4
      metadata:
        rax-heat: { get_param: "OS::stack_id" }

  database_user_password:
    type: "OS::Heat::RandomString"
    properties:
      length: 16
      sequence: lettersdigits

  db_admin_password:
    type: "OS::Heat::RandomString"
    properties:
      length: 16
      sequence: lettersdigits

  database_server:
    type: OS::Trove::Instance
    properties:
      name:
        str_replace:
          template: "nodejs_app_db_%stackid%"
          params:
            "%stackid%": { get_param: "OS::stack_id" }
      flavor: { get_param: db_flavor }
      size: { get_param: db_size }
      datastore_type: mysql
      datastore_version: { get_param: datastore_version }
      databases:
      - name: nodejs_db
      users:
      - name: { get_param: database_username }
        password: { get_resource: database_user_password }
        databases: [ nodejs_db ]

  nodejs_app_servers:
    type: "OS::Heat::ResourceGroup"
    depends_on: database_server
    properties:
      count: { get_param: nodejs_app_server_count }
      resource_def:
        type: ./node-web.yaml
        properties:
          hostname: { get_param: server_hostnames }
          ssh_key_name: { get_resource: ssh_key }
          ssh_private_key: { get_attr: [ssh_key, private_key] }
          kitchen: { get_param: kitchen }
          chef_version: { get_param: chef_version }
          revision: { get_param: revision }
          packages: { get_param: packages }
          repo: { get_param: repo }
          deploy_key: { get_param: deploy_key }
          destination: { get_param: destination }
          db_server_ip: { get_attr: [database_server, hostname] }
          database_username: { get_param: database_username }
          database_user_password: { get_resource: database_user_password }

outputs:
  load_balancer_ip:
    description: Load Balancer IP
    value: { get_attr: [load_balancer, PublicIp] }

  nodejs_url:
    description: "Node.js URL"
    value:
      str_replace:
        template: "http://%ip%"
        params:
          "%ip%": { get_attr: [load_balancer, PublicIp] }

  database_server_ip:
    description: Database Server hostname
    value: { get_attr: [database_server, hostname] }

  mysql_root_password:
    description: MySQL Root Password
    value: { get_attr: [db_admin_password, value] }

  node_server_ips:
    description: Node.js Server IPs
    value: { get_attr: [nodejs_app_servers, accessIPv4] }

  private_key:
    description: SSH Private Key
    value: { get_attr: [ssh_key, private_key] }
{'fraction_non_alphanumeric': 0.07748100391434493, 'fraction_numerical': 0.012894312687082661, 'mean_word_length': 2.403134182174339, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3047629', 'n_tokens_mistral': 5364, 'n_tokens_neox': 5135, 'n_words': 1542}