diff --git a/README.md b/README.md index a230432..a50f70b 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,5 @@ This is the core [Apache Brooklyn](http://brooklyn.apache.org/) integration for deployment and in-life management of a three tier webapp. See the [Apache Brooklyn documentation](http://brooklyn.apache.org/v/latest/start/policies.html) for further details of this blueprint. + +**IMPORTANT:** Suitable for deployment on [Ubuntu 20.04](https://releases.ubuntu.com/20.04/). diff --git a/catalog/catalog.bom b/catalog/catalog.bom index 3429b3c..ad077cb 100644 --- a/catalog/catalog.bom +++ b/catalog/catalog.bom @@ -1,3 +1,9 @@ brooklyn.catalog: + bundle: io.brooklyn.three-tier-webapp.brooklyn-three-tier-webapp + name: Brooklyn Three Tier App Types + version: 1.1.0-SNAPSHOT # version of this blueprint. items: - - classpath://three-tier-webapp/three-tier-webapp.bom \ No newline at end of file + - classpath://common-types/tomcat9.bom + - classpath://common-types/mysql5.bom + - classpath://common-types/nginx.bom + - classpath://three-tier-webapp/three-tier-webapp.bom \ No newline at end of file diff --git a/catalog/common-types/mysql5.bom b/catalog/common-types/mysql5.bom new file mode 100644 index 0000000..ab02da9 --- /dev/null +++ b/catalog/common-types/mysql5.bom @@ -0,0 +1,167 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +brooklyn.catalog: + version: 1.0.0-SNAPSHOT + publish: + name: &mysql5Name MySQL 5 Server + description: &mysql5Description This is the MySQL 5 blueprint type. + license_code: Apache-2.0 + + items: + - id: org.apache.brooklyn.entity.database.mysql5 + name: *mysql5Name + iconUrl: classpath://icons/mysql.png + item: + name: *mysql5Name + type: org.apache.brooklyn.entity.software.base.VanillaSoftwareProcess + + brooklyn.parameters: + - name: creation.script.sql.url + label: SQL creation script URL + description: | + If supplied, the server will download a creation SQL script from this URL and + initialize the DB with it. + To have the orchestration server download it, or to use a classpath URL with a bundled resource, + use files.customize writing from that URL to creation-script.sql instead of this. + type: string + default: "" + - name: mysql.url + type: string + label: Database pack URL + default: "https://artifactory.cloudsoftcorp.com/artifactory/libs-release-local/io/cloudsoft/packs/mysql5/1.0.0/mysql5-1.0.0-tar.gz" + description: | + Publicly accessible URL of MySQL to install. + If this is not supplied, callers should typically set files.customize to install, + including multiple archives bundled with the blueprint. + - name: install.command + pinned: false + - name: customize.command + pinned: false + - name: launch.command + pinned: false + - name: checkRunning.command + pinned: false + - name: stop.command + pinned: false + + brooklyn.config: + dontRequireTtyForSudo: true + start.timeout: 20m + sshMonitoring.enabled: false + mysql.port: 3306 + + shell.env: + CREATION_SCRIPT_URL: $brooklyn:config("creation.script.sql.url") + DB_URL: $brooklyn:config("mysql.url") + + install.command: | + MYSQL_CFG=/etc/mysql/mysql.conf.d/ + sudo test -d "$MYSQL_CFG" && MYSQL_EXISTS="0" + + if [ "$MYSQL_EXISTS" ]; then + echo "MySQL already installed." + else + echo "Installing MySQL." + while sudo fuser /var/{lib/{dpkg,apt/lists},cache/apt/archives}/{lock,lock-frontend} >/dev/null 2>&1; do + echo 'Waiting for release of dpkg/apt locks...'; + sleep 5 + done + + which curl || sudo apt --assume-yes install curl + + ## Install the MySQL server + if [ ! -z "${DB_URL}" ] ; then + curl -L -k -f -o mysql.tar.gz "${DB_URL}" + fi + tar xf mysql.tar.gz + PREV=`pwd` + cd mysql + while sudo fuser /var/{lib/{dpkg,apt/lists},cache/apt/archives}/{lock,lock-frontend} >/dev/null 2>&1; do + echo 'Waiting for release of dpkg/apt locks...'; + sleep 5 + done + sudo ./dbmanager.sh install + cd $PREV + + sudo systemctl stop mysql + + cat >/tmp/zz-bind-address.cnf < /dev/null 2>&1 + if [ $? != 0 ] ; then + echo "MySQL is running when configure is called. Skipping configuration assuming it has already been done. If this is not correct then stop the DB before invoking this." + else + echo "Configuring MySQL..." + # When MySQL is up `systemctl status mysql` returns `Active: active (running)` + sudo systemctl start mysql + + if [ ! -z "${CREATION_SCRIPT_URL}" ] ; then + echo "Fetching and running creation script from ${CREATION_SCRIPT_URL}..." + curl -L -k -f -o creation-script-from-url.sql ${CREATION_SCRIPT_URL} + sudo mysql -u root < creation-script-from-url.sql + fi + fi + + launch.command: | + sudo systemctl status mysql | grep 'running' > /dev/null 2>&1 + if [ $? == 0 ]; then + echo "MySQL is up. All is well with the world." + else + echo "MySQL is down. Starting it..." + sudo systemctl start mysql + fi + + stop.command: | + sudo systemctl status mysql | grep 'running' > /dev/null 2>&1 + if [ $? == 0 ]; then + echo "MySQL is up. Shutting it down..." + sudo systemctl stop mysql + else + echo "MySQL is already down." + fi + + checkRunning.command: + sudo /etc/init.d/mysql status | grep -i -e 'active' -e 'uptime' + + brooklyn.initializers: + - type: org.apache.brooklyn.core.sensor.StaticSensor + brooklyn.config: + name: datastore.driver + static.value: "com.mysql.jdbc.Driver" + + brooklyn.enrichers: + - type: org.apache.brooklyn.enricher.stock.Transformer + brooklyn.config: + enricher.sourceSensor: $brooklyn:sensor("host.name") + enricher.targetSensor: $brooklyn:sensor("datastore.url") + enricher.targetValue: + $brooklyn:formatString: + - "mysql://%s:%s" + - $brooklyn:attributeWhenReady("host.name") + - $brooklyn:config("mysql.port") diff --git a/catalog/common-types/nginx.bom b/catalog/common-types/nginx.bom new file mode 100644 index 0000000..c00fecc --- /dev/null +++ b/catalog/common-types/nginx.bom @@ -0,0 +1,86 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +brooklyn.catalog: + version: 1.1.0-SNAPSHOT # BROOKLYN_THREE_TIER_WEBAPP_VERSION + publish: + name: &nginXName NginX + description: &nginXDescription A single Nginx server. Provides HTTP and reverse proxy services. + license_code: Apache-2.0 + + items: + - id: org.apache.brooklyn.entity.proxy.nginx + name: *nginXName + iconUrl: classpath://icons/nginx.jpeg + item: + name: *nginXName + type: org.apache.brooklyn.entity.software.base.VanillaSoftwareProcess + + brooklyn.parameters: + - name: app.port + label: NginX Port + description: | + If supplied, the server will download a creation SQL script from this URL and + initialize the DB with it. + To have the orchestration server download it, or to use a classpath URL with a bundled resource, + use files.customize writing from that URL to creation-script.sql instead of this. + type: string + default: 8080 + - name: nginx.sticky + description: Whether to use sticky sessions (no sure where this is used) + type: boolean + default: true + + brooklyn.config: + dontRequireTtyForSudo: true + start.timeout: 20m + sshMonitoring.enabled: false + app.port: 8080 + + shell.env: + APP_PORT: $brooklyn:config("app.port") + + install.command: | + sudo apt -y update + sudo apt -y install nginx + + customize.command: | + echo customize + + #sudo systemctl enable postgresql.service + + launch.command: | + sudo systemctl start nginx + + stop.command: | + sudo systemctl stop nginx + + checkRunning.command: + sudo systemctl status nginx | grep -i -e 'active' -e 'online' + + brooklyn.enrichers: + - type: org.apache.brooklyn.enricher.stock.Transformer + brooklyn.config: + enricher.sourceSensor: $brooklyn:sensor("host.name") + enricher.targetSensor: $brooklyn:sensor("main.uri") + enricher.targetValue: + $brooklyn:formatString: + - "http://%s:%s" + - $brooklyn:attributeWhenReady("host.name") + - $brooklyn:config("app.port") + diff --git a/catalog/common-types/tomcat9.bom b/catalog/common-types/tomcat9.bom new file mode 100644 index 0000000..a704563 --- /dev/null +++ b/catalog/common-types/tomcat9.bom @@ -0,0 +1,182 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +brooklyn.catalog: + # BROOKLYN_THREE_TIER_WEBAPP_VERSION + publish: + name: &tomcat9Name Apache Tomcat 9 Server + description: &tomcat9Description This is the Apache Tomcat 9 blueprint type. + license_code: Apache-2.0 + + items: + - id: org.apache.brooklyn.entity.webapp.tomcat9 + name: *tomcat9Name + iconUrl: classpath://icons/tomcat9.png + item: + name: *tomcat9Name + type: org.apache.brooklyn.entity.software.base.VanillaSoftwareProcess + + brooklyn.parameters: + - name: root.war + type: string + label: WAR URL + default: "" + description: | + Publicly accessible URL of WAR to install as the root application. + If this is not supplied, callers should typically set files.customize to install, + including multiple WARs and WARs bundled with the blueprint. + pinned: true + - name: tomcat.gz + type: string + label: WAR URL + default: https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.52/bin/apache-tomcat-9.0.52.tar.gz + description: | + Publicly accessible URL of Apache Tomcat to install. + If this is not supplied, callers should typically set files.customize to install, + including multiple archives bundled with the blueprint. + pinned: true + - name: catalina.properties + label: Java system properties + type: java.util.Map + default: {} + + - name: install.command + pinned: false + - name: customize.command + pinned: false + - name: launch.command + pinned: false + - name: checkRunning.command + pinned: false + - name: stop.command + pinned: false + + brooklyn.config: + dontRequireTtyForSudo: true + start.timeout: 20m + sshMonitoring.enabled: false + app.port: 8080 + + shell.env: + APP_PORT: $brooklyn:config("app.port") + ROOT_WAR: $brooklyn:config("root.war") + TOMCAT_GZ: $brooklyn:config("tomcat.gz") + CATALINA_PROPERTIES: $brooklyn:config("catalina.properties") + + install.command: | + CATALINA=/usr/local/tomcat + sudo test -d "$CATALINA" && CATALINA_EXISTS="0" + + if [ "$CATALINA_EXISTS" ]; then + echo "Tomcat already installed." + else + echo "Installing Tomcat..." + while sudo fuser /var/{lib/{dpkg,apt/lists},cache/apt/archives}/lock >/dev/null 2>&1; do + echo Waiting for other instances of apt to complete... + sleep 5 + done + + which curl || sudo apt --assume-yes install curl + + # Install java if needed + if ( which java ) ; then + echo "Java already installed." + else + echo "Trying to install java." + # occasionally AWS comes up without this repo + sudo add-apt-repository -y ppa:openjdk-r/ppa || echo could not add repo, will continue trying java install anyway + sudo apt-get update || echo could not apt-get update, will continue trying java install anyway + + sudo apt --assume-yes install openjdk-8-jdk-headless + sudo apt --assume-yes install openjdk-8-jre-headless + fi + + # Install Apache Tomcat + cd ${INSTALL_DIR} + sudo mkdir /usr/local/tomcat + if [ ! -z "${TOMCAT_GZ}" ] ; then + echo "Downloading TOMCAT from ${TOMCAT_GZ}" + curl -L -k -f -o tomcat.tar.gz "${TOMCAT_GZ}" + fi + sudo tar xf tomcat.tar.gz -C /usr/local/tomcat --strip-components=1 + sudo chmod 750 /usr/local/tomcat/bin + sudo sed --in-place 's#io.brooklyn.three-tier-webapp brooklyn-three-tier-webapp - 1.0.2-SNAPSHOT + 1.1.0-SNAPSHOT bundle diff --git a/resources/icons/mysql.png b/resources/icons/mysql.png new file mode 100644 index 0000000..bc09926 Binary files /dev/null and b/resources/icons/mysql.png differ diff --git a/resources/icons/nginx.jpeg b/resources/icons/nginx.jpeg new file mode 100644 index 0000000..07153a3 Binary files /dev/null and b/resources/icons/nginx.jpeg differ diff --git a/resources/icons/tomcat9.png b/resources/icons/tomcat9.png new file mode 100644 index 0000000..dad39e5 Binary files /dev/null and b/resources/icons/tomcat9.png differ diff --git a/tests/three-tier-webapp/three-tier-webapp.tests.bom b/tests/three-tier-webapp/three-tier-webapp.tests.bom index ba69024..cafee7b 100644 --- a/tests/three-tier-webapp/three-tier-webapp.tests.bom +++ b/tests/three-tier-webapp/three-tier-webapp.tests.bom @@ -17,7 +17,7 @@ # under the License. # brooklyn.catalog: - version: 1.0.2-SNAPSHOT # BROOKLYN_THREE_TIER_WEBAPP_VERSION + version: 1.1.0-SNAPSHOT # BROOKLYN_THREE_TIER_WEBAPP_VERSION items: - "https://raw.githubusercontent.com/brooklyncentral/common-catalog-utils/master/common-tests/src/main/resources/commontests/common.tests.bom" - id: brooklyn-three-tier-webapp-tests