---
heat_template_version: "2013-05-23"
######################################################################
###################### Template Input Section ########################
######################################################################
parameters:
  # Common
  nfs_share:
    type: string
    description: Ip address of the NFS server that hosts the shared installation scripts for dB2.
  
  # WAS Parameters
  was_admin_user:
    type: string
    description: User name of the WebSphere Admin User.
  was_admin_password:
    type: string
    description: Password of the WebSphere Admin User.  
  was_app_server_name:
    type: string
    default: was_app_server
    description: Name of the application server.
  was_hostname:
    type: string
    default: was_node
    description: Name of the application server.
  was_cluster_number:
    type: string
    default: 1
    description: Number of cluster instances.                  
  
  # DB2-Parameters
  dB2_hostname:
    type: string
    default: dB2-hostname
    description: dB2 hostname.
  dB2_port: 
    type: string
    default: 7090
    description: dB2 port.  

  # IHS-Parameter  
  ihs_admin_password: 
    type: string
    description: dB2 password.
  ihs_keystore_password:
    type: string
    description: Keystore password. 
  ihs_timeout:  
    type: string
    default: 100000
    description: Timeout.
    
  # Dmgr-Parameter
  dmgr_admin_user:
    type: string
  dmgr_admin_password:
    type: string
  bluepages_fqn_hostname:  
    type: string
    default: bluepages.ibm.com          

######################################################################
#################### Resource Definition Section #####################
######################################################################
resources:  
  
  ####################################################################
  ################ Software Config Definition Section ################
  ####################################################################
  was_sw_config:
    type: OS::Heat::SoftwareConfig::Chef
    properties:
      cookbook: http://www.cookbooks.ibm.com/hot/chef/connections.zip
      role: was_role      
      inputs:
        admin_user:
          type: string
          mapping: was/admin_user
        admin_password:
          type: string
          mapping: was/admin_password
        nfs_share:
          type: string
          mapping: was/nfs_share
        app_server_name:
          type: string
          mapping: was/app_server_name
        node_name:
          type: string
          mapping: was/node_name
        cluster_number:
          type: string
          mapping: was/cluster_number
        server_node:
          type: string
          mapping: was/server_node
      outputs:           
        was_hostname:        
          type: string
          mapping: was/was_hostname
        was_server_node:
          type: string
          mapping: was/was_server_node  
          
  dB2_sw_config:
    type: OS::Heat::SoftwareConfig::Chef
    properties:
      cookbook: http://www.cookbooks.ibm.com/hot/chef/connections.zip
      role: dB2_role      
      inputs:
        # User driven
        nfs_share:
          type: string
          mapping: dB2/nfs_share
        dB2_hostname:
          type: string
          mapping: dB2/dB2_hostname
        dB2_port:
          type: string
          mapping: dB2/dB2_port
      outputs:
        dB2_hostname:
          type: string
          mapping: dB2/dB2_hostname
        dB2_port:
          type: string
          mapping: dB2/dB2_port

  pre_dmgr_sw_config:
    type: OS::Heat::SoftwareConfig::Chef
    properties:
      cookbook: http://www.cookbooks.ibm.com/hot/chef/connections.zip
      role: pre_dmgr_role      
      inputs:
        # User driven parameter        
        dmgr_admin_user:
          type: string
          mapping: dmgr/admin_user
        dmgr_admin_password: 
          type: string
          mapping: dmgr/dmgr_admin_password
        nfs_share:
          type: string
          mapping: dmgr/nfs_share
      outputs:
        nodename:
          type: string
          mapping: dmgr/nodename
        cellname:
          type: string
          mapping: dmgr/cellname
        dmgr_hostname:
          type: string
          mapping: dmgr/hostname
        fqn_hostname:                             
          type: string
          mapping: dmgr/fqn_hostname    
          
  dmgr_sw_config:
    type: OS::Heat::SoftwareConfig::Chef
    properties:
      cookbook: http://www.cookbooks.ibm.com/hot/chef/connections.zip
      role: dmgr_role      
      inputs:        
        # User driven
        dmgr_admin_user:
          type: string
          mapping: dmgr/admin_user
        dmgr_admin_password: 
          type: string
          mapping: dmgr/dmgr_admin_password
        
        # Automation driven parameter
        was1_node_name:
          type: string
          mapping: dmgr/was1_node_name
        was1_server_node:
          type: string
          mapping: dmgr/was1_server_node
        was2_node_name:
          type: string
          mapping: dmgr/was2_node_name
        was2_server_node:
          type: string
          mapping: dmgr/was2_server_node
        was3_node_name:
          type: string
          mapping: dmgr/was3_node_name
        was3_server_node:
          type: string
          mapping: dmgr/was3_server_node
        was4_node_name:
          type: string
          mapping: dmgr/was4_node_name
        was4_server_node:
          type: string
          mapping: dmgr/was4_server_node        
      outputs:
        user_app_secondaryNodesNames:
          type: string
          mapping: dmgr/secondaryNodesNames
        user_app_serverInfo:
          type: string
          mapping: dmgr/user_app_serverInfo
        user_app_dbUserPassword:
          type: string
          mapping: dmgr/user_app_dbUserPassword
        user_app_firstNodeName:
          type: string
          mapping: dmgr/user_app_firstNodeName
        user_app_clusterName:
          type: string
          mapping: dmgr/user_app_clusterName
        user_was_dmHostname:
          type: string
          mapping: dmgr/user_was_dmHostname
        user_was_profileName:
          type: string
          mapping: dmgr/user_was_profileName
        user_was_dmCellName:
          type: string
          mapping: dmgr/user_was_dmCellName
        user_nodesHostnamelist:
          type: string
          mapping: dmgr/user_nodesHostnamelist
        user_nodesServerlist:
          type: string
          mapping: dmgr/user_nodesServerlist
          
  post_dmgr_sw_config:
    type: OS::Heat::SoftwareConfig::Chef
    properties:
      cookbook: http://www.cookbooks.ibm.com/hot/chef/connections.zip
      role: post_dmgr_role      
      inputs:
        # User driven parameter        
        dmgr_admin_user:
          type: string
          mapping: dmgr/admin_user
        dmgr_admin_password: 
          type: string
          mapping: dmgr/dmgr_admin_password
        domain_name:
          type: string
          mapping: dmgr/domain_name
        bluepages_fqn_hostname:
          type: string
          mapping: dmgr/bluepages_fqn_hostname  
                      
  ihs_sw_config:
    type: OS::Heat::SoftwareConfig::Chef
    properties:
      cookbook: http://www.cookbooks.ibm.com/hot/chef/connections.zip
      role: ihs_role      
      inputs:
        # User driven input fields    
        ihs_admin_password: 
          type: string
          mapping: ihs/ihs_admin_password    
        ihs_keystore_password:
          type: string
          mapping: ihs/ihs_keystore_password     
        ihs_timeout:
          type: string       
          mapping: ihs/ihs_timeout
          
        # Automation driven input fields
        dmgr_hostname:
          type: string       
          mapping: ihs/dmgr_hostname  
      outputs:
        ihs_public_hostname:
          type: string
          mapping: ihs/ihs_public_hostname
        ihs_node_name:
          type: string
          mapping: ihs/node_name  
          
  ####################################################################
  ############## Software Deployment Definition Section ##############
  ####################################################################
  clust1_software_deployment:
    type: OS::Heat::SoftwareDeployment::Chef
    properties:
      apply_config: { get_resource: was_sw_config }
      server: { get_resource: clust1 }
      input_values:
        admin_user: { get_param: was_admin_user }
        admin_password: { get_param: was_admin_password }
        nfs_share: { get_param: nfs_share }
        app_server_name: { get_param: was_app_server_name }
        node_name: { get_param: was_hostname }
        cluster_number: { get_param: was_cluster_number }        
        dmgr_hostname: { get_attr: [ pre_dmgr_software_deployment, dmgr_hostname ]}        
   
  clust2_software_deployment:
    type: OS::Heat::SoftwareDeployment::Chef
    properties:
      apply_config: { get_resource: was_sw_config }
      server: { get_resource: clust2 }
      input_values:
        admin_user: { get_param: was_admin_user }
        admin_password: { get_param: was_admin_password }
        nfs_share: { get_param: nfs_share }
        app_server_name: { get_param: was_app_server_name }
        node_name: { get_param: was_hostname }
        cluster_number: { get_param: was_cluster_number }
        dmgr_hostname: { get_attr: [ pre_dmgr_software_deployment, dmgr_hostname ]}        
    
  clust3_software_deployment:
    type: OS::Heat::SoftwareDeployment::Chef
    properties:
      apply_config: { get_resource: was_sw_config }
      server: { get_resource: clust3 }
      input_values:
        admin_user: { get_param: was_admin_user }
        admin_password: { get_param: was_admin_password }
        nfs_share: { get_param: nfs_share }
        app_server_name: { get_param: was_app_server_name }
        node_name: { get_param: was_hostname }
        cluster_number: { get_param: was_cluster_number }
        dmgr_hostname: { get_attr: [ pre_dmgr_software_deployment, dmgr_hostname ]}        
        
  clust4_software_deployment:
    type: OS::Heat::SoftwareDeployment::Chef
    properties:
      apply_config: { get_resource: was_sw_config }
      server: { get_resource: clust4 }
      input_values:
        admin_user: { get_param: was_admin_user }
        admin_password: { get_param: was_admin_password }
        nfs_share: { get_param: nfs_share }
        app_server_name: { get_param: was_app_server_name }
        node_name: { get_param: was_hostname }
        cluster_number: { get_param: was_cluster_number }
        dmgr_hostname: { get_attr: [ pre_dmgr_software_deployment, dmgr_hostname ]} 
        
  dB2_software_deployment:
    type: OS::Heat::SoftwareDeployment::Chef
    properties:
      apply_config: { get_resource: dB2_sw_config }
      server: { get_resource: dB2 }
      input_values:
        nfs_share: { get_param: nfs_share }        
        dB2_port: { get_param: dB2_port }
        dB2_hostname: { get_param: dB2_hostname }
        
  ihs_software_deployment:
    type: OS::Heat::SoftwareDeployment::Chef
    properties:
      apply_config: { get_resource: ihs_sw_config }
      server: { get_resource: ihs }
      input_values:
        ihs_admin_password: { get_param: ihs_admin_password }
        ihs_keystore_password: { get_param: ihs_keystore_password }
        ihs_timeout: { get_param: ihs_timeout }
        dmgr_hostname: { get_attr: [ post_dmgr_software_deployment, dmgr_hostname ]}        
        
  pre_dmgr_software_deployment:
    type: OS::Heat::SoftwareDeployment::Chef
    properties:
      apply_config: { get_resource: pre_dmgr_sw_config }
      server: { get_resource: was_dmgr }
      input_values:
        dmgr_admin_user: { get_param: dmgr_admin_user }
        dmgr_admin_password: { get_param: dmgr_admin_password }        
        nfs_share: { get_param: nfs_share }
          
  dmgr_software_deployment:
    type: OS::Heat::SoftwareDeployment::Chef
    depends_on: { get_resource: pre_dmgr_software_deployment }
    properties:
      apply_config: { get_resource: was_dmgr_sw_config }
      server: { get_resource: was_dmgr }
      input_values:        
        # User driven
        dmgr_admin_user: { get_param: dmgr_admin_user }
        dmgr_admin_password: { get_param: dmgr_admin_password }
        
        # Automation driven
        was1_node_name: { get_attr: [ clust1_software_deployment, was_hostname ]}
        was1_server_node: { get_attr: [ clust1_software_deployment, was_server_node ]}
        was2_node_name: { get_attr: [ clust2_software_deployment, was_hostname ]}
        was2_server_node: { get_attr: [ clust2_software_deployment, was_server_node ]}
        was3_node_name: { get_attr: [ clust3_software_deployment, was_hostname ]}
        was3_server_node: { get_attr: [ clust3_software_deployment, was_server_node ]}
        was4_node_name: { get_attr: [ clust4_software_deployment, was_hostname ]}
        was4_server_node: { get_attr: [ clust4_software_deployment, was_server_node ]}
  
  post_dmgr_software_deployment:
    type: OS::Heat::SoftwareDeployment::Chef
    depends_on: { get_resource: was_dmgr_software_deployment }
    properties:
      apply_config: { get_resource: post_dmgr_sw_config }
      server: { get_resource: was_dmgr }
      input_values:
        # User driven 
        dmgr_admin_user: { get_param: dmgr_admin_user }
        dmgr_admin_password: { get_param: dmgr_admin_password }
        domain_name: { get_param: domain_name }
        bluepages_fqn_hostname: { get_param: bluepages_fqn_hostname }
        
        # Automation driven
        was1_node_name: { get_attr: [ clust1_software_deployment, was_hostname ]}
        was1_server_node: { get_attr: [ clust1_software_deployment, was_server_node ]}
        was2_node_name: { get_attr: [ clust2_software_deployment, was_hostname ]}
        was2_server_node: { get_attr: [ clust2_software_deployment, was_server_node ]}
        was3_node_name: { get_attr: [ clust3_software_deployment, was_hostname ]}
        was3_server_node: { get_attr: [ clust3_software_deployment, was_server_node ]}
        was4_node_name: { get_attr: [ clust4_software_deployment, was_hostname ]}
        was4_server_node: { get_attr: [ clust4_software_deployment, was_server_node ]}
        
  
  ####################################################################
  ################## Node Definition Section #########################
  ####################################################################
  clust1:
    properties:
      flavor: "4"
      image: was-master-130911-1421h
      key_name: connections-key
      networks:
        -
          port:
            get_resource: clust1_port_private
    type: "OS::Nova::Server"
  clust1_floating_ip:
    properties:
      floating_network_id: 2970c64a-06f1-4cec-93e6-d2a46fe0b628
      port_id:
        get_resource: clust1_port_private
    type: "OS::Neutron::FloatingIP"
  clust1_port_private:
    properties:
      network_id: 213c1bed-1634-48dc-9172-a9b87258454e
    type: "OS::Neutron::Port"
  
  clust2:
    properties:
      flavor: "4"
      image: was-master-130911-1421h
      key_name: connections-key
      networks:
        -
          port:
            get_resource: clust2_port_private      
    type: "OS::Nova::Server"
  clust2_floating_ip:
    properties:
      floating_network_id: 2970c64a-06f1-4cec-93e6-d2a46fe0b628
      port_id:
        get_resource: clust2_port_private
    type: "OS::Neutron::FloatingIP"
  clust2_port_private:
    properties:
      network_id: 213c1bed-1634-48dc-9172-a9b87258454e
    type: "OS::Neutron::Port"
  clust3:
    properties:
      flavor: "4"
      image: was-master-130911-1421h
      key_name: connections-key
      networks:
        -
          port:
            get_resource: clust3_port_private
    type: "OS::Nova::Server"
  clust3_floating_ip:
    properties:
      floating_network_id: 2970c64a-06f1-4cec-93e6-d2a46fe0b628
      port_id:
        get_resource: clust3_port_private
    type: "OS::Neutron::FloatingIP"
  clust3_port_private:
    properties:
      network_id: 213c1bed-1634-48dc-9172-a9b87258454e
    type: "OS::Neutron::Port"
  clust4:
    properties:
      flavor: "4"
      image: was-master-130911-1421h
      key_name: connections-key
      networks:
        -
          port:
            get_resource: clust4_port_private
    type: "OS::Nova::Server"
  clust4_floating_ip:
    properties:
      floating_network_id: 2970c64a-06f1-4cec-93e6-d2a46fe0b628
      port_id:
        get_resource: clust4_port_private
    type: "OS::Neutron::FloatingIP"
  clust4_port_private:
    properties:
      network_id: 213c1bed-1634-48dc-9172-a9b87258454e
    type: "OS::Neutron::Port"
  dB2_server:
    properties:
      flavor: "4"
      image: was-master-130911-1421h
      key_name: connections-key
      networks:
        -
          port:
            get_resource: dB2_server_port_private
    type: "OS::Nova::Server"
  dB2_server_floating_ip:
    properties:
      floating_network_id: 2970c64a-06f1-4cec-93e6-d2a46fe0b628
      port_id:
        get_resource: dB2_server_port_private
    type: "OS::Neutron::FloatingIP"
  dB2_server_port_private:
    properties:
      network_id: 213c1bed-1634-48dc-9172-a9b87258454e
    type: "OS::Neutron::Port"
  ihs_server:
    properties:
      flavor: "4"
      image: was-master-130911-1421h
      key_name: connections-key
      networks:
        -
          port:
            get_resource: ihs_server_port_private
    type: "OS::Nova::Server"
  ihs_server_floating_ip:
    properties:
      floating_network_id: 2970c64a-06f1-4cec-93e6-d2a46fe0b628
      port_id:
        get_resource: ihs_server_port_private
    type: "OS::Neutron::FloatingIP"
  ihs_server_port_private:
    properties:
      network_id: 213c1bed-1634-48dc-9172-a9b87258454e
    type: "OS::Neutron::Port"
  was_dmgr:
    properties:
      flavor: "4"
      image: was-master-130911-1421h
      key_name: connections-key
      networks:
        -
          port:
            get_resource: was_dmgr_port_private      
    type: "OS::Nova::Server"
  was_dmgr_floating_ip:
    properties:
      floating_network_id: 2970c64a-06f1-4cec-93e6-d2a46fe0b628
      port_id:
        get_resource: was_dmgr_port_private
    type: "OS::Neutron::FloatingIP"
  was_dmgr_port_private:
    properties:
      network_id: 213c1bed-1634-48dc-9172-a9b87258454e
    type: "OS::Neutron::Port"
    
####################################################################
################## Template Output Section #########################
####################################################################    
outputs:
  dmgr_hostname:
    value: { get_attr: [post_dmgr_software_deployment, user_was_dmHostname] }
    description: Hostname of the deployment manager.
  dB2_hostname:
    value: { get_attr: [dB2_software_deployment, dB2_hostname] }
    description: Hostname of the dB2 instance.
  was1_hostname:
    value: { get_attr: [clust1_software_deployment, was_hostname] }
    description: Hostname of the Websphere Server in Cluster 1.
  was2_hostname:
    value: { get_attr: [clust2_software_deployment, was_hostname] }
    description: Hostname of the Websphere Server in Cluster 2.
  was3_hostname:
    value: { get_attr: [clust3_software_deployment, was_hostname] }
    description: Hostname of the Websphere Server in Cluster 3.
  was4_hostname:
    value: { get_attr: [clust4_software_deployment, was_hostname] }
    description: Hostname of the Websphere Server in Cluster 4.
  ihs_hostname:
    value: { get_attr: [ihs_software_deployment, ihs_public_hostname] }
    description: Hostname of the IHS server.