diff --git a/muranorepository/Services/agent_templates/ConfigureAccessToPostgreSql.template b/muranorepository/Services/agent_templates/ConfigureAccessToPostgreSql.template new file mode 100644 index 0000000..051959f --- /dev/null +++ b/muranorepository/Services/agent_templates/ConfigureAccessToPostgreSql.template @@ -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: + - + Options: + captureStdout: true + captureStderr: false diff --git a/muranorepository/Services/agent_templates/ConfigurePostgreSqlDatabase.template b/muranorepository/Services/agent_templates/ConfigurePostgreSqlDatabase.template new file mode 100644 index 0000000..0401116 --- /dev/null +++ b/muranorepository/Services/agent_templates/ConfigurePostgreSqlDatabase.template @@ -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: + - + Options: + captureStdout: true + captureStderr: false diff --git a/muranorepository/Services/agent_templates/DeployPostgreSql.template b/muranorepository/Services/agent_templates/DeployPostgreSql.template new file mode 100644 index 0000000..e9f499f --- /dev/null +++ b/muranorepository/Services/agent_templates/DeployPostgreSql.template @@ -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: + - + - + Options: + captureStdout: true + captureStderr: false diff --git a/muranorepository/Services/agent_templates/DeployTomcat.template b/muranorepository/Services/agent_templates/DeployTomcat.template new file mode 100644 index 0000000..ae8cadc --- /dev/null +++ b/muranorepository/Services/agent_templates/DeployTomcat.template @@ -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: + - + - + Options: + captureStdout: true + captureStderr: false diff --git a/muranorepository/Services/agent_templates/DeployTomcatApp.template b/muranorepository/Services/agent_templates/DeployTomcatApp.template new file mode 100644 index 0000000..1aaf94d --- /dev/null +++ b/muranorepository/Services/agent_templates/DeployTomcatApp.template @@ -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: + - + - + Options: + captureStdout: true + captureStderr: false diff --git a/muranorepository/Services/agent_templates/GetIP.template b/muranorepository/Services/agent_templates/GetIP.template new file mode 100644 index 0000000..3b8b2e0 --- /dev/null +++ b/muranorepository/Services/agent_templates/GetIP.template @@ -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 diff --git a/muranorepository/Services/heat_templates/FloatingIPwithLB.template b/muranorepository/Services/heat_templates/FloatingIPwithLB.template index 6b3b657..8a43ad6 100644 --- a/muranorepository/Services/heat_templates/FloatingIPwithLB.template +++ b/muranorepository/Services/heat_templates/FloatingIPwithLB.template @@ -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" } } diff --git a/muranorepository/Services/heat_templates/PostgreSqlSecurity.template b/muranorepository/Services/heat_templates/PostgreSqlSecurity.template new file mode 100644 index 0000000..6c87d9e --- /dev/null +++ b/muranorepository/Services/heat_templates/PostgreSqlSecurity.template @@ -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" + } + ] + } + } + } +} diff --git a/muranorepository/Services/heat_templates/TomcatSecurity.template b/muranorepository/Services/heat_templates/TomcatSecurity.template new file mode 100644 index 0000000..a018d49 --- /dev/null +++ b/muranorepository/Services/heat_templates/TomcatSecurity.template @@ -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" + } + ] + } + } + } +} diff --git a/muranorepository/Services/postgreSql-manifest.yaml b/muranorepository/Services/postgreSql-manifest.yaml new file mode 100644 index 0000000..5f0250f --- /dev/null +++ b/muranorepository/Services/postgreSql-manifest.yaml @@ -0,0 +1,49 @@ +version: 0.1 +service_display_name: PostgreSQL + +description: >- + 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 diff --git a/muranorepository/Services/scripts/Linux/configureAccessToPostgreSql.sh b/muranorepository/Services/scripts/Linux/configureAccessToPostgreSql.sh new file mode 100644 index 0000000..878bdf9 --- /dev/null +++ b/muranorepository/Services/scripts/Linux/configureAccessToPostgreSql.sh @@ -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 diff --git a/muranorepository/Services/scripts/Linux/configurePostgreSqlDatabase.sh b/muranorepository/Services/scripts/Linux/configurePostgreSqlDatabase.sh new file mode 100644 index 0000000..d6e095b --- /dev/null +++ b/muranorepository/Services/scripts/Linux/configurePostgreSqlDatabase.sh @@ -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 diff --git a/muranorepository/Services/scripts/Linux/deployPostgreSql.sh b/muranorepository/Services/scripts/Linux/deployPostgreSql.sh new file mode 100644 index 0000000..6d8d44c --- /dev/null +++ b/muranorepository/Services/scripts/Linux/deployPostgreSql.sh @@ -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 diff --git a/muranorepository/Services/scripts/Linux/deployTomcat.sh b/muranorepository/Services/scripts/Linux/deployTomcat.sh new file mode 100644 index 0000000..bbcf2ba --- /dev/null +++ b/muranorepository/Services/scripts/Linux/deployTomcat.sh @@ -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 + diff --git a/muranorepository/Services/scripts/Linux/deployTomcatApp.sh b/muranorepository/Services/scripts/Linux/deployTomcatApp.sh new file mode 100644 index 0000000..9ce237e --- /dev/null +++ b/muranorepository/Services/scripts/Linux/deployTomcatApp.sh @@ -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 diff --git a/muranorepository/Services/scripts/Linux/getIp.sh b/muranorepository/Services/scripts/Linux/getIp.sh new file mode 100644 index 0000000..f7113c6 --- /dev/null +++ b/muranorepository/Services/scripts/Linux/getIp.sh @@ -0,0 +1,2 @@ +#!/bin/sh +curl -s http://169.254.169.254/latest/meta-data/local-ipv4 diff --git a/muranorepository/Services/tomcat-manifest.yaml b/muranorepository/Services/tomcat-manifest.yaml new file mode 100644 index 0000000..d2c307d --- /dev/null +++ b/muranorepository/Services/tomcat-manifest.yaml @@ -0,0 +1,44 @@ +version: 0.1 +service_display_name: Tomcat + +description: >- + 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 diff --git a/muranorepository/Services/ui_forms/PostgreSql.yaml b/muranorepository/Services/ui_forms/PostgreSql.yaml new file mode 100644 index 0000000..6bf94ff --- /dev/null +++ b/muranorepository/Services/ui_forms/PostgreSql.yaml @@ -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 diff --git a/muranorepository/Services/ui_forms/Tomcat.yaml b/muranorepository/Services/ui_forms/Tomcat.yaml new file mode 100644 index 0000000..61237f3 --- /dev/null +++ b/muranorepository/Services/ui_forms/Tomcat.yaml @@ -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 diff --git a/muranorepository/Services/workflows/Common.xml b/muranorepository/Services/workflows/Common.xml index 0c861e7..bce649b 100644 --- a/muranorepository/Services/workflows/Common.xml +++ b/muranorepository/Services/workflows/Common.xml @@ -22,7 +22,7 @@ - + + Unable to assign Key Pair on unit ) due to + + + + + + + + + + + LinuxSecurity + PostgreSqlSecurity + + + + + + + + ( + + + + + + + + + + + + + + + + + + + + Linux instance ) created + + + + + + + ( + + + Configuring security groups on ) + + + + + + + + ( + + + + + + PostgreSql deployed on ) + + + + + + + ( + Configuring database ( + + + + + + + + + + + + + has been configured on unit ) + + + + + ( + + + + + + + + + + ')].units[?(@.temp.instanceName and not @.state.database)] + + + + + + + + + + + + + + + + + Unit + + + + + to work with database + + Unable to assign Key Pair on unit ) due to + + + + + + + + + + + LinuxSecurity + TomcatSecurity + + + + + + + + ( + + + + + + + + + + + + + + + + + + + + Linux instance ) created + + + + + + + ( + + + Configuring security groups on ) + + + + + + + + ( + + + + + + Tomcat deployed on ) + + + + + + + ( + Deploying WebApp ( + + + + + + + + + + has been deployed on unit ) + + + + + ( + + + + + + http://-loadBalancerIp: + Unable to create a Server Farm load balancer on unit ) due to + + + + + + + + + + + + + Unable to assign floating IP to