Merge "Add new services PostgreSQL and Tomcat"

This commit is contained in:
Jenkins 2014-03-05 08:02:03 +00:00 committed by Gerrit Code Review
commit 6cedf3aa6a
22 changed files with 1115 additions and 6 deletions

View File

@ -0,0 +1,23 @@
FormatVersion: 2.0.0
Version: 1.0.0
Name: Configure database access credentails
Parameters:
database: $database
username: $username
password: $password
host: $databaseHost
Body: |
return configure('{0} {1} {2} {3}'.format(args.database, args.username, args.password, args.host)).stdout
Scripts:
configure:
Type: Application
Version: 1.0.0
EntryPoint: Linux/configureAccessToPostgreSql.sh
Files:
- <Linux/common.sh>
Options:
captureStdout: true
captureStderr: false

View File

@ -0,0 +1,22 @@
FormatVersion: 2.0.0
Version: 1.0.0
Name: Add database and user to PostgreSql
Parameters:
database: $database
username: $username
password: $password
Body: |
return configure('{0} {1} {2}'.format(args.database, args.username, args.password)).stdout
Scripts:
configure:
Type: Application
Version: 1.0.0
EntryPoint: Linux/configurePostgreSqlDatabase.sh
Files:
- <Linux/common.sh>
Options:
captureStdout: true
captureStderr: false

View File

@ -0,0 +1,21 @@
FormatVersion: 2.0.0
Version: 1.0.0
Name: Deploy PostgreSql
Parameters:
appName: $appName
Body: |
return deploy(args.appName).stdout
Scripts:
deploy:
Type: Application
Version: 1.0.0
EntryPoint: Linux/deployPostgreSql.sh
Files:
- <Linux/installer.sh>
- <Linux/common.sh>
Options:
captureStdout: true
captureStderr: false

View File

@ -0,0 +1,21 @@
FormatVersion: 2.0.0
Version: 1.0.0
Name: Deploy Tomcat
Parameters:
appName: $appName
Body: |
return deploy(args.appName).stdout
Scripts:
deploy:
Type: Application
Version: 1.0.0
EntryPoint: Linux/deployTomcat.sh
Files:
- <Linux/installer.sh>
- <Linux/common.sh>
Options:
captureStdout: true
captureStderr: false

View File

@ -0,0 +1,21 @@
FormatVersion: 2.0.0
Version: 1.0.0
Name: Deploy Tomcat
Parameters:
repository: $repository
Body: |
return installApp(args.repository).stdout
Scripts:
installApp:
Type: Application
Version: 1.0.0
EntryPoint: Linux/deployTomcatApp.sh
Files:
- <Linux/installer.sh>
- <Linux/common.sh>
Options:
captureStdout: true
captureStderr: false

View File

@ -0,0 +1,19 @@
FormatVersion: 2.0.0
Version: 1.0.0
Name: Deploy Tomcat
Parameters:
appName: $appName
Body: |
return getIp(args.appName).stdout
Scripts:
getIp:
Type: Application
Version: 1.0.0
EntryPoint: Linux/getIp.sh
Files: []
Options:
captureStdout: true
captureStderr: false

View File

@ -1,22 +1,22 @@
{
"Resources": {
"${instanceName}-FloatingIP": {
"${lbName}-FloatingIP": {
"Type": "OS::Neutron::FloatingIP",
"Properties": {
"floating_network_id": "$externalNetworkId"
}
},
"${instanceName}-FloatingIpAssoc": {
"${lbName}-FloatingIpAssoc": {
"Type": "OS::Neutron::FloatingIPAssociation",
"Properties": {
"floatingip_id": { "Ref" : "${instanceName}-FloatingIP" },
"floatingip_id": { "Ref" : "${lbName}-FloatingIP" },
"port_id": {"Fn::Select": ["port_id", {"Fn::GetAtt": ["${lbName}-Pool", "vip"]}]}
}
}
},
"Outputs": {
"${instanceName}-FloatingIPaddress": {
"Value": {"Fn::GetAtt": ["${instanceName}-FloatingIP", "floating_ip_address"]},
"${lbName}-FloatingIPaddress": {
"Value": {"Fn::GetAtt": ["${lbName}-FloatingIP", "floating_ip_address"]},
"Description": "Floating IP assigned"
}
}

View File

@ -0,0 +1,17 @@
{
"Resources": {
"$MuranoSecurityGroup-{envName}": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"SecurityGroupIngress": [
{
"ToPort": "5432",
"IpProtocol": "tcp",
"FromPort": "5432",
"CidrIp": "0.0.0.0/0"
}
]
}
}
}
}

View File

@ -0,0 +1,17 @@
{
"Resources": {
"$MuranoSecurityGroup-{envName}": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"SecurityGroupIngress": [
{
"ToPort": "8080",
"IpProtocol": "tcp",
"FromPort": "8080",
"CidrIp": "0.0.0.0/0"
}
]
}
}
}
}

View File

@ -0,0 +1,49 @@
version: 0.1
service_display_name: PostgreSQL
description: >-
<strong> PostgreSQL database
full_service_name: postgreSql
author: Mirantis Inc.
service_version: 1
enabled: True
ui:
- PostgreSql.yaml
workflows:
- PostgreSql.xml
- Networking.xml
heat:
- Linux.template
- LinuxSecurity.template
- PostgreSqlSecurity.template
- InstancePort.template
- InstancePortWSubnet.template
- Network.template
- NNSecurity.template
- Param.template
- RouterInterface.template
- Subnet.template
- DefaultSecurity.template
- Keypair.template
- LoadBalancer.template
- FloatingIP.template
- FloatingIPwithLB.template
agent:
- DeployPostgreSql.template
- ConfigurePostgreSqlDatabase.template
- ConfigureAccessToPostgreSql.template
- GetIP.template
scripts:
- Linux/common.sh
- Linux/installer.sh
- Linux/deployPostgreSql.sh
- Linux/configurePostgreSqlDatabase.sh
- Linux/configureAccessToPostgreSql.sh
- Linux/getIp.sh

View File

@ -0,0 +1,26 @@
#!/bin/bash
function include(){
curr_dir=$(cd $(dirname "$0") && pwd)
inc_file_path=$curr_dir/$1
if [ -f "$inc_file_path" ]; then
. $inc_file_path
else
echo -e "$inc_file_path not found!"
exit 1
fi
}
include "common.sh"
get_os
[[ $? -ne 0 ]] && exit 1
if [[ "$DistroBasedOn" != "redhat" ]]; then
DEBUGLVL=4
log "ERROR: We are sorry, only \"redhat\" based distribution of Linux supported for this service type, exiting!"
exit 1
fi
sed -e "s/YOURUSERNAMEHERE/$2/" -i /usr/share/tomcat/webapps/app/META-INF/context.xml
sed -e "s/YOURPASSWORDHERE/$3/" -i /usr/share/tomcat/webapps/app/META-INF/context.xml
sed -e "s/YOURHOSTHERE/$4/" -i /usr/share/tomcat/webapps/app/META-INF/context.xml
sed -e "s/YOURDATABASEHERE/$1/" -i /usr/share/tomcat/webapps/app/META-INF/context.xml

View File

@ -0,0 +1,28 @@
#!/bin/bash
function include(){
curr_dir=$(cd $(dirname "$0") && pwd)
inc_file_path=$curr_dir/$1
if [ -f "$inc_file_path" ]; then
. $inc_file_path
else
echo -e "$inc_file_path not found!"
exit 1
fi
}
include "common.sh"
get_os
[[ $? -ne 0 ]] && exit 1
if [[ "$DistroBasedOn" != "redhat" ]]; then
DEBUGLVL=4
log "ERROR: We are sorry, only \"redhat\" based distribution of Linux supported for this service type, exiting!"
exit 1
fi
su -c "psql -d postgres -c \"CREATE DATABASE $1\"" -s /bin/sh postgres
su -c "psql -d postgres -c \"CREATE USER $2 WITH PASSWORD '$3'\"" -s /bin/sh postgres
su -c "psql -d postgres -c \"GRANT ALL PRIVILEGES ON DATABASE $1 to $2;\"" -s /bin/sh postgres
echo "host $1 $2 all md5" >> /var/lib/pgsql/data/pg_hba.conf
systemctl restart postgresql.service

View File

@ -0,0 +1,31 @@
#!/bin/bash
function include(){
curr_dir=$(cd $(dirname "$0") && pwd)
inc_file_path=$curr_dir/$1
if [ -f "$inc_file_path" ]; then
. $inc_file_path
else
echo -e "$inc_file_path not found!"
exit 1
fi
}
include "common.sh"
get_os
[[ $? -ne 0 ]] && exit 1
if [[ "$DistroBasedOn" != "redhat" ]]; then
DEBUGLVL=4
log "ERROR: We are sorry, only \"redhat\" based distribution of Linux supported for this service type, exiting!"
exit 1
fi
bash installer.sh -p sys -i "postgresql-server postgresql-contrib"
postgresql-setup initdb
sed -e "s/^#listen_addresses =.*$/listen_addresses = \'*\'/" -i /var/lib/pgsql/data/postgresql.conf
add_fw_rule '-I INPUT 1 -p tcp -m tcp --dport 5432 -j ACCEPT -m comment --comment "by murano, PostgreSQL"'
systemctl enable postgresql.service
systemctl start postgresql.service

View File

@ -0,0 +1,29 @@
#!/bin/bash
function include(){
curr_dir=$(cd $(dirname "$0") && pwd)
inc_file_path=$curr_dir/$1
if [ -f "$inc_file_path" ]; then
. $inc_file_path
else
echo -e "$inc_file_path not found!"
exit 1
fi
}
include "common.sh"
get_os
[[ $? -ne 0 ]] && exit 1
if [[ "$DistroBasedOn" != "redhat" ]]; then
DEBUGLVL=4
log "ERROR: We are sorry, only \"redhat\" based distribution of Linux supported for this service type, exiting!"
exit 1
fi
bash installer.sh -p sys -i "tomcat tomcat-webapps tomcat-admin-webapps"
add_fw_rule '-I INPUT 1 -p tcp -m tcp --dport 8080 -j ACCEPT -m comment --comment "by murano, Tomcat"'
systemctl enable tomcat.service
systemctl start tomcat.service

View File

@ -0,0 +1,30 @@
#!/bin/bash
function include(){
curr_dir=$(cd $(dirname "$0") && pwd)
inc_file_path=$curr_dir/$1
if [ -f "$inc_file_path" ]; then
. $inc_file_path
else
echo -e "$inc_file_path not found!"
exit 1
fi
}
include "common.sh"
get_os
[[ $? -ne 0 ]] && exit 1
if [[ "$DistroBasedOn" != "redhat" ]]; then
DEBUGLVL=4
log "ERROR: We are sorry, only \"redhat\" based distribution of Linux supported for this service type, exiting!"
exit 1
fi
bash installer.sh -p sys -i "java-devel"
cd /usr/share/tomcat/webapps
git clone $1 app
cd app/WEB-INF/classes
for f in $(find . -name "*.java"); do
javac -cp /usr/share/tomcat/lib/tomcat-servlet-3.0-api.jar "$f"
done

View File

@ -0,0 +1,2 @@
#!/bin/sh
curl -s http://169.254.169.254/latest/meta-data/local-ipv4

View File

@ -0,0 +1,44 @@
version: 0.1
service_display_name: Tomcat
description: >-
<strong> Tomcat application
full_service_name: tomcat
author: Mirantis Inc.
service_version: 1
enabled: True
ui:
- Tomcat.yaml
workflows:
- Tomcat.xml
- Networking.xml
heat:
- Linux.template
- LinuxSecurity.template
- TomcatSecurity.template
- InstancePort.template
- InstancePortWSubnet.template
- Network.template
- NNSecurity.template
- Param.template
- RouterInterface.template
- Subnet.template
- DefaultSecurity.template
- Keypair.template
- LoadBalancer.template
- FloatingIP.template
- FloatingIPwithLB.template
agent:
- DeployTomcat.template
- DeployTomcatApp.template
scripts:
- Linux/common.sh
- Linux/installer.sh
- Linux/deployTomcat.sh
- Linux/deployTomcatApp.sh

View File

@ -0,0 +1,93 @@
unitTemplates:
- {}
forms:
- serviceConfiguration:
fields:
- name: name
type: string
label: Service Name
description: >-
To identify your service in logs please specify a service name
- name: database
type: string
label: Database
description: >-
Please, provide database name that is going to be created
- name: username
type: string
label: Username
description: >-
Please, provide username that is going to be used to connect to the database
- name: password
type: password
label: Password
descriptionTitle: Password
description: >-
Please, provide password that is going to be used to connect to the database
- name: dcInstances
type: instance
hidden: true
attributeNames: units
initial: 1
- name: assignFloatingIP
type: floatingip
label: Assign Floating IP
description: >-
Select to true to assign floating IP automatically
initial: false
required: false
widgetMedia:
css: {all: [muranodashboard/css/checkbox.css]}
- name: unitNamingPattern
type: string
label: Hostname template
description: >-
For your convenience all instance hostnames can be named
in the same way. Enter a name and use # character for incrementation.
For example, host# turns into host1, host2, etc. Please follow Windows
hostname restrictions.
required: false
regexpValidator: '^(([a-zA-Z0-9#][a-zA-Z0-9-#]*[a-zA-Z0-9#])\.)*([A-Za-z0-9#]|[A-Za-z0-9#][A-Za-z0-9-#]*[A-Za-z0-9#])$'
# FIXME: does not work for # turning into 2-digit numbers
maxLength: 15
helpText: Optional field for a machine hostname template
# temporaryHack
widgetMedia:
js: [muranodashboard/js/support_placeholder.js]
css: {all: [muranodashboard/css/support_placeholder.css]}
- instanceConfiguration:
fields:
- name: title
type: string
required: false
hidden: true
attributeNames: false
descriptionTitle: Instance Configuration
description: Specify some instance parameters on which service would be created.
- name: flavor
type: flavor
label: Instance flavor
description: >-
Select registered in Openstack flavor. Consider that service performance
depends on this parameter.
required: false
- name: osImage
type: image
imageType: linux
label: Instance image
description: >-
Select valid image for a service. Image should already be prepared and
registered in glance.
- name: keyPair
type: keypair
label: Key Pair
description: >-
Select the Key Pair to control access to instances. You can login to
instances using this KeyPair after the deployment of service.
required: false
- name: availabilityZone
type: azone
label: Availability zone
description: Select availability zone where service would be installed.
required: false

View File

@ -0,0 +1,101 @@
unitTemplates:
- {}
forms:
- serviceConfiguration:
fields:
- name: name
type: string
label: Service Name
description: >-
To identify your service in logs please specify a service name
- name: repository
type: string
label: Git repository
description: >-
URL of a git repository with the application you want to deploy.
regexpValidator: '/(\w+://)(.+@)*([\w\d\.]+)(:[\d]+)?/*(.*)/i'
errorMessages:
invalid: Enter correct git repository url
helpText: Enter a valid git repository URL
- name: psqlDatabase
type: psqlDatabase
label: Database
description: >-
Select database to connect with
- name: dcInstances
type: instance
label: Instance Count
description: >-
Several instances with application running on Tomcat can be created at one time.
attributeNames: units
minValue: 1
maxValue: 100
initial: 1
helpText: Enter an integer value between 2 and 100
- name: loadBalancerPort
type: integer
label: Load Balancer port
initial: 8080
hidden: true
- name: assignFloatingIP
type: floatingip
label: Assign Floating IP
description: >-
Select to true to assign floating IP automatically
initial: false
required: false
widgetMedia:
css: {all: [muranodashboard/css/checkbox.css]}
- name: unitNamingPattern
type: string
label: Hostname template
description: >-
For your convenience all instance hostnames can be named
in the same way. Enter a name and use # character for incrementation.
For example, host# turns into host1, host2, etc. Please follow Windows
hostname restrictions.
required: false
regexpValidator: '^(([a-zA-Z0-9#][a-zA-Z0-9-#]*[a-zA-Z0-9#])\.)*([A-Za-z0-9#]|[A-Za-z0-9#][A-Za-z0-9-#]*[A-Za-z0-9#])$'
# FIXME: does not work for # turning into 2-digit numbers
maxLength: 15
helpText: Optional field for a machine hostname template
# temporaryHack
widgetMedia:
js: [muranodashboard/js/support_placeholder.js]
css: {all: [muranodashboard/css/support_placeholder.css]}
- instanceConfiguration:
fields:
- name: title
type: string
required: false
hidden: true
attributeNames: false
descriptionTitle: Instance Configuration
description: Specify some instance parameters on which service would be created.
- name: flavor
type: flavor
label: Instance flavor
description: >-
Select registered in Openstack flavor. Consider that service performance
depends on this parameter.
required: false
- name: osImage
type: image
imageType: linux
label: Instance image
description: >-
Select valid image for a service. Image should already be prepared and
registered in glance.
- name: keyPair
type: keypair
label: Key Pair
description: >-
Select the Key Pair to control access to instances. You can login to
instances using this KeyPair after the deployment of service.
required: false
- name: availabilityZone
type: azone
label: Availability zone
description: Select availability zone where service would be installed.
required: false

View File

@ -22,7 +22,7 @@
</rule>
</rule>
<rule match="$[?(@.networking.state.ready_for_cf and @.networking.topology == 'routed')].services[?(@.type not in ('webServerFarm', 'aspNetAppFarm') and @.assignFloatingIP)].units[?(not @.temp.floatingIpAssigned)]"
<rule match="$[?(@.networking.state.ready_for_cf and @.networking.topology == 'routed')].services[?(@.type not in ('webServerFarm', 'aspNetAppFarm', 'tomcat') and @.assignFloatingIP)].units[?(not @.temp.floatingIpAssigned)]"
desc="Units of non-farms services which have no floating assigned yet">
<report entity="unit">
<parameter name="id"><select path="id"/></parameter>

View File

@ -0,0 +1,269 @@
<workflow>
<rule match="$[?(@.networking.state.ready_for_cf)].services[?(@.type == 'postgreSql' and @.keyPair)].units[?(@.state.hostname and not @.temp.KeyPairMapping)]"
desc="This rule allows to set Key Pair for all VMs with this service">
<update-cf-stack template="Keypair" error="exception">
<parameter name="mappings">
<map>
<mapping name="instanceName"><select path="state.hostname"/></mapping>
<mapping name="keyName"><select path="::keyPair"/></mapping>
</map>
</parameter>
<success>
<set path="temp.KeyPairMapping"><true/></set>
</success>
<failure>
<report entity="unit" level="error">
<parameter name="id"><select path="id"/></parameter>
<parameter name="text">Unable to assign Key Pair on unit <select path="state.hostname"/> (<select path="name"/>) due to <format-error error="exception"/></parameter>
</report>
<stop/>
</failure>
</update-cf-stack>
</rule>
<!-- Provisioning rules -->
<rule match="$.services[?(@.type == 'postgreSql' and not @.securityTemplates)]">
<set path="securityTemplates">
<list>
<text>LinuxSecurity</text>
<text>PostgreSqlSecurity</text>
</list>
</set>
</rule>
<rule match="$[?(@.networking.state.ready_for_cf)].services[?(@.type == 'postgreSql')].units[?(@.state.hostname and not @.temp.instanceName)]"
desc="Units of PostgreSql service having hostname and image names assigned but without instances">
<report entity="unit">
<parameter name="id"><select path="id"/></parameter>
<parameter name="text">
Creating Linux instance <select path="state.hostname"/> (<select path="name"/>)
</parameter>
</report>
<!-- HEAT rules definitions -->
<!-- Rule #1 -->
<update-cf-stack template="Linux" error="exception">
<parameter name="mappings">
<map>
<mapping name="instanceName">
<select path="state.hostname"/>
</mapping>
<mapping name="userData">
<prepare-user-data template="Linux" initFile="linux_init.sh">
<parameter name="hostname">
<select path="state.hostname"/>
</parameter>
<parameter name="unit">
<select path="id"/>
</parameter>
<parameter name="service">
<select path="::id"/>
</parameter>
</prepare-user-data>
</mapping>
<mapping name="instanceType">
<select path="::flavor" default="m1.medium"/>
</mapping>
<mapping name="imageName">
<select path="::osImage.name"/>
</mapping>
<mapping name="availabilityZone">
<select path="::availabilityZone" default="nova"/>
</mapping>
</map>
</parameter>
<success>
<set path="temp.instanceName">
<select path="name"/>
</set>
<report entity="unit">
<parameter name="id">
<select path="id"/>
</parameter>
<parameter name="text">
Linux instance <select path="state.hostname"/> (<select path="name"/>) created
</parameter>
</report>
</success>
<failure>
<report entity="unit" level="error">
<parameter name="id">
<select path="id"/>
</parameter>
<parameter name="text">
Unable to deploy Linux instance <select path="state.hostname"/> (<select path="name"/>) due to <format-error error="exception"/>
</parameter>
</report>
<stop/>
</failure>
</update-cf-stack>
<!-- Rule #2 -->
<report entity="unit">
<parameter name="id">
<select path="id"/>
</parameter>
<parameter name="text">
Configuring security groups on <select path="state.hostname"/> (<select path="name"/>)
</parameter>
</report>
</rule>
<!-- Agent rules -->
<rule match="$.services[?(@.type == 'postgreSql')].units[?(@.temp.instanceName and not @.state.PostgreSQLInstalled)]"
desc="Units of PostgreSql service which have got an instance deployed but have not got PostgreSQL service installed">
<report entity="unit">
<parameter name="id">
<select path="id"/>
</parameter>
<parameter name="text">
Installing PostgreSql on unit <select path="state.hostname"/> (<select path="name"/>)
</parameter>
</report>
<!-- Commands sequence -->
<!-- Command #1-->
<send-command template="DeployPostgreSql" error="exception">
<parameter name="unit">
<select path="id"/>
</parameter>
<parameter name="service">
<select path="::id"/>
</parameter>
<success>
<set path="state.PostgreSQLInstalled"><true/></set>
<report entity="unit">
<parameter name="id">
<select path="id"/>
</parameter>
<parameter name="text">
PostgreSql deployed on <select path="state.hostname"/> (<select path="name"/>)
</parameter>
</report>
</success>
<failure>
<report entity="unit" level="error">
<parameter name="id">
<select path="id"/>
</parameter>
<parameter name="text">
Unable to deploy PostgreSql on <select path="state.hostname"/> (<select path="name"/>) due to <format-error error="exception"/>
</parameter>
</report>
<stop/>
</failure>
</send-command>
</rule>
<rule match="$.services[?(@.type == 'postgreSql')].units[?(@.state.PostgreSQLInstalled and not @.state.databaseConfigured)]"
desc="Units of PostgreSQL which have got PostgreSQL installed but database is not yet created">
<report entity="unit">
<parameter name="id"><select path="id"/></parameter>
<parameter name="text">Configuring database <select path="::database"/> on unit <select path="state.hostname"/> (<select path="name"/>)</parameter>
</report>
<send-command template="ConfigurePostgreSqlDatabase" error="exception">
<parameter name="unit">
<select path="id"/>
</parameter>
<parameter name="service">
<select path="::id"/>
</parameter>
<parameter name="mappings">
<map>
<mapping name="database">
<select path="::database"/>
</mapping>
<mapping name="username">
<select path="::username"/>
</mapping>
<mapping name="password">
<select path="::password"/>
</mapping>
</map>
</parameter>
<success>
<set path="state.databaseConfigured"><true/></set>
<report entity="unit">
<parameter name="id"><select path="id"/></parameter>
<parameter name="text">Database <select path="::database"/> has been configured on unit <select path="state.hostname"/> (<select path="name"/>)</parameter>
</report>
</success>
<failure>
<report entity="unit" level="error">
<parameter name="id"><select path="id"/></parameter>
<parameter name="text">Unable to configure database on <select path="state.hostname"/> (<select path="name"/>) <format-error error="exception"/></parameter>
</report>
<stop/>
</failure>
</send-command>
</rule>
<rule match="$.services[?(@.type == 'postgreSql')].units[?(@.temp.instanceName and not @.state.unitIp)]"
desc="Units of PostgreSql service which have got an instance deployed">
<send-command template="GetIP" result="ip" error="exception">
<parameter name="unit">
<select path="id"/>
</parameter>
<parameter name="service">
<select path="::id"/>
</parameter>
<success>
<set path="state.unitIp"><select source="ip" path="0" /></set>
<set path="::databaseHost"><select source="ip" path="0" /></set>
</success>
</send-command>
</rule>
<rule match="$.services[?(@.type == 'tomcat' and @.psqlDatabase)].units[?(not @.database)]"
desc="Reinitialize units with database">
<set path="database">
<select path="::psqlDatabase"/>
</set>
</rule>
<rule match="$.services[?(@.type == 'postgreSql')].units[?(@.state.unitIp and @.state.PostgreSQLInstalled and @.state.databaseConfigured)]">
<set path="#currentDatabase">
<select path="::"/>
</set>
<rule>
<parameter name="match">/$.services[?(@.type == 'tomcat' and @.psqlDatabase == '<select path="id" source="currentDatabase"/>')].units[?(@.temp.instanceName and not @.state.database)]</parameter>
<send-command template="ConfigureAccessToPostgreSql" error="exception">
<parameter name="unit">
<select path="id"/>
</parameter>
<parameter name="service">
<select path="::id"/>
</parameter>
<parameter name="mappings">
<map>
<mapping name="database">
<select path="database" source="currentDatabase"/>
</mapping>
<mapping name="username">
<select path="username" source="currentDatabase"/>
</mapping>
<mapping name="password">
<select path="password" source="currentDatabase"/>
</mapping>
<mapping name="databaseHost">
<select path="databaseHost" source="currentDatabase"/>
</mapping>
</map>
</parameter>
<success>
<set path="state.database"><select path="database" source="currentDatabase"/></set>
<report entity="unit">
<parameter name="id"><select path="id"/></parameter>
<parameter name="text">Unit <select path="state.hostname"/> has been configured to work with database <select path="database"/></parameter>
</report>
</success>
<failure>
<report entity="unit" level="error">
<parameter name="id"><select path="id"/></parameter>
<parameter name="text">Unable to configure unit <select path="state.hostname"/> to work with database <select path="database"/> due to <format-error error="exception"/></parameter>
</report>
<stop/>
</failure>
</send-command>
</rule>
</rule>
</workflow>

View File

@ -0,0 +1,246 @@
<workflow>
<rule match="$[?(@.networking.state.ready_for_cf)].services[?(@.type == 'tomcat' and @.keyPair)].units[?(@.state.hostname and not @.temp.KeyPairMapping)]"
desc="This rule allows to set Key Pair for all VMs with this service">
<update-cf-stack template="Keypair" error="exception">
<parameter name="mappings">
<map>
<mapping name="instanceName"><select path="state.hostname"/></mapping>
<mapping name="keyName"><select path="::keyPair"/></mapping>
</map>
</parameter>
<success>
<set path="temp.KeyPairMapping"><true/></set>
</success>
<failure>
<report entity="unit" level="error">
<parameter name="id"><select path="id"/></parameter>
<parameter name="text">Unable to assign Key Pair on unit <select path="state.hostname"/> (<select path="name"/>) due to <format-error error="exception"/></parameter>
</report>
<stop/>
</failure>
</update-cf-stack>
</rule>
<!-- Provisioning rules -->
<rule match="$.services[?(@.type == 'tomcat' and not @.securityTemplates)]">
<set path="securityTemplates">
<list>
<text>LinuxSecurity</text>
<text>TomcatSecurity</text>
</list>
</set>
</rule>
<rule match="$[?(@.networking.state.ready_for_cf)].services[?(@.type == 'tomcat')].units[?(@.state.hostname and not @.temp.instanceName)]"
desc="Units of Tomcat service having hostname and image names assigned but without instances">
<report entity="unit">
<parameter name="id"><select path="id"/></parameter>
<parameter name="text">
Creating Linux instance <select path="state.hostname"/> (<select path="name"/>)
</parameter>
</report>
<!-- HEAT rules definitions -->
<!-- Rule #1 -->
<update-cf-stack template="Linux" error="exception">
<parameter name="mappings">
<map>
<mapping name="instanceName">
<select path="state.hostname"/>
</mapping>
<mapping name="userData">
<prepare-user-data template="Linux" initFile="linux_init.sh">
<parameter name="hostname">
<select path="state.hostname"/>
</parameter>
<parameter name="unit">
<select path="id"/>
</parameter>
<parameter name="service">
<select path="::id"/>
</parameter>
</prepare-user-data>
</mapping>
<mapping name="instanceType">
<select path="::flavor" default="m1.medium"/>
</mapping>
<mapping name="imageName">
<select path="::osImage.name"/>
</mapping>
<mapping name="availabilityZone">
<select path="::availabilityZone" default="nova"/>
</mapping>
</map>
</parameter>
<success>
<set path="temp.instanceName">
<select path="name"/>
</set>
<report entity="unit">
<parameter name="id">
<select path="id"/>
</parameter>
<parameter name="text">
Linux instance <select path="state.hostname"/> (<select path="name"/>) created
</parameter>
</report>
</success>
<failure>
<report entity="unit" level="error">
<parameter name="id">
<select path="id"/>
</parameter>
<parameter name="text">
Unable to deploy Linux instance <select path="state.hostname"/> (<select path="name"/>) due to <format-error error="exception"/>
</parameter>
</report>
<stop/>
</failure>
</update-cf-stack>
<!-- Rule #2 -->
<report entity="unit">
<parameter name="id">
<select path="id"/>
</parameter>
<parameter name="text">
Configuring security groups on <select path="state.hostname"/> (<select path="name"/>)
</parameter>
</report>
</rule>
<!-- Agent rules -->
<rule match="$.services[?(@.type == 'tomcat')].units[?(@.temp.instanceName and not @.state.tomcatInstalled)]"
desc="Units of Tomcat service which have got an instance deployed but have not got Tomcat service installed">
<report entity="unit">
<parameter name="id">
<select path="id"/>
</parameter>
<parameter name="text">
Installing Tomcat on unit <select path="state.hostname"/> (<select path="name"/>)
</parameter>
</report>
<!-- Commands sequence -->
<!-- Command #1-->
<send-command template="DeployTomcat" error="exception">
<parameter name="unit">
<select path="id"/>
</parameter>
<parameter name="service">
<select path="::id"/>
</parameter>
<success>
<set path="state.tomcatInstalled"><true/></set>
<report entity="unit">
<parameter name="id">
<select path="id"/>
</parameter>
<parameter name="text">
Tomcat deployed on <select path="state.hostname"/> (<select path="name"/>)
</parameter>
</report>
</success>
<failure>
<report entity="unit" level="error">
<parameter name="id">
<select path="id"/>
</parameter>
<parameter name="text">
Unable to deploy Tomcat on <select path="state.hostname"/> (<select path="name"/>) due to <format-error error="exception"/>
</parameter>
</report>
<stop/>
</failure>
</send-command>
</rule>
<rule match="$.services[?(@.type == 'tomcat')].units[?(@.state.tomcatInstalled and not @.state.appDeployed)]"
desc="Units of Tomcat app services which have got Tomcat installed but not the WebApplication deployed">
<report entity="unit">
<parameter name="id"><select path="id"/></parameter>
<parameter name="text">Deploying WebApp <select path="::name"/> on unit <select path="state.hostname"/> (<select path="name"/>)</parameter>
</report>
<send-command template="DeployTomcatApp" error="exception">
<parameter name="unit">
<select path="id"/>
</parameter>
<parameter name="service">
<select path="::id"/>
</parameter>
<parameter name="mappings">
<map>
<mapping name="repository">
<select path="::repository"/>
</mapping>
</map>
</parameter>
<success>
<set path="state.appDeployed"><true/></set>
<report entity="unit">
<parameter name="id"><select path="id"/></parameter>
<parameter name="text">App <select path="::name"/> has been deployed on unit <select path="state.hostname"/> (<select path="name"/>)</parameter>
</report>
</success>
<failure>
<report entity="unit" level="error">
<parameter name="id"><select path="id"/></parameter>
<parameter name="text">Unable to deploy WebApp on <select path="state.hostname"/> (<select path="name"/>) <format-error error="exception"/></parameter>
</report>
<stop/>
</failure>
</send-command>
</rule>
<rule match="$[?(@.networking.state.ready_for_cf)].services[?(@.type == 'tomcat')].units[?(@.state.hostname and not @.temp.registeredWithLB)]"
desc="Units of Tomcat services which have a hostname assigned but are not registered with LB">
<update-cf-stack template="LoadBalancer" result="outputs" error="exception">
<parameter name="mappings">
<map>
<mapping name="instanceName"><select path="state.hostname"/></mapping>
<mapping name="lbPort"><select path="::loadBalancerPort"/></mapping>
<mapping name="lbName"><select path="::name"/></mapping>
</map>
</parameter>
<success>
<set path="temp.registeredWithLB"><true/></set>
<set path="::uri">http://<select source="outputs"><parameter name="path"><select path="::name"/>-loadBalancerIp</parameter></select>:<select path="::loadBalancerPort"/></set>
</success>
<failure>
<report entity="unit" level="error">
<parameter name="id"><select path="id"/></parameter>
<parameter name="text">Unable to create a Server Farm load balancer on unit <select path="state.hostname"/> (<select path="name"/>) due to <format-error error="exception"/></parameter>
</report>
<stop/>
</failure>
</update-cf-stack>
</rule>
<rule match="$[?(@.networking.state.ready_for_cf and @.networking.topology == 'routed')].services[?(@.type == 'tomcat' and @.assignFloatingIP and not @.floatingip)]"
desc="Tomcat services which have no floating assigned yet">
<report entity="unit">
<parameter name="id"><select path="id"/></parameter>
<parameter name="text">Assigning Floating IP to the to LB</parameter>
</report>
<update-cf-stack template="FloatingIPwithLB" result="outputs" error="exception">
<parameter name="mappings">
<map>
<mapping name="lbName"><select path="name"/></mapping>
<mapping name="externalNetworkId"><select path="/networking.floatingId"/></mapping>
</map>
</parameter>
<success>
<set path="floatingip"><select source="outputs"><parameter name="path"><select path="name"/>-FloatingIPaddress</parameter></select></set>
<report entity="unit">
<parameter name="id"><select path="id"/></parameter>
<parameter name="text">Floating IP has been assigned to LB</parameter>
</report>
</success>
<failure>
<report entity="unit" level="error">
<parameter name="id"><select path="id"/></parameter>
<parameter name="text">Unable to assign floating IP to <select path="name"/> due to <format-error error="exception"/></parameter>
</report>
</failure>
</update-cf-stack>
</rule>
</workflow>