You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ma...@apache.org on 2013/08/29 09:22:33 UTC

git commit: Update OpenStack Tomcat Cartridge

Updated Branches:
  refs/heads/master 54e305810 -> 44c3d76d1


Update OpenStack Tomcat Cartridge

JIRA ID : STRATOS-51


Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/44c3d76d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/44c3d76d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/44c3d76d

Branch: refs/heads/master
Commit: 44c3d76d157761fc0a59b55beebe63520c914c78
Parents: 54e3058
Author: Manula Thantriwatte <ma...@wso2.com>
Authored: Thu Aug 29 12:50:54 2013 +0530
Committer: Manula Thantriwatte <ma...@wso2.com>
Committed: Thu Aug 29 12:50:54 2013 +0530

----------------------------------------------------------------------
 .../tomcat/openstack/get-launch-params.rb       |  35 +++
 .../tomcat/openstack/healthcheck.sh             |  10 +
 .../tomcat/openstack/stratos-init.sh            | 289 +++++++++++++++++++
 tools/stratos-installer/cartridges/tomcat.xml   |  45 +++
 4 files changed, 379 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/44c3d76d/tools/cartridge_create/init_scripts/tomcat/openstack/get-launch-params.rb
----------------------------------------------------------------------
diff --git a/tools/cartridge_create/init_scripts/tomcat/openstack/get-launch-params.rb b/tools/cartridge_create/init_scripts/tomcat/openstack/get-launch-params.rb
new file mode 100755
index 0000000..068e6c6
--- /dev/null
+++ b/tools/cartridge_create/init_scripts/tomcat/openstack/get-launch-params.rb
@@ -0,0 +1,35 @@
+#! /usr/bin/ruby
+
+### get-launch-params.rb
+
+# The following script obtains the launch parameters from 
+# the file /tmp/payload/launch-params, then parses out the 
+# parameters for this instance by using the launch index
+# of this particular EC2 instance.
+#
+# Pass the command the -e flag to output the instance 
+# parameters as exports of shell variables. Any other 
+# arguments are ignored.
+
+def get_launch_params(launch_params_file)
+  IO.readlines launch_params_file
+end
+
+export_stmt = ""
+
+launch_params = get_launch_params(
+  "/var/lib/cloud/instance/payload/launch-params")
+
+if launch_params.length > 0
+  instance_params_str = launch_params[0]
+
+  instance_params = instance_params_str.split(',')
+
+  export_stmt = "export " if ARGV.length > 0 && ARGV.include?("-e")
+
+  instance_params.each { |param|
+    puts export_stmt + param
+  }
+
+end
+

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/44c3d76d/tools/cartridge_create/init_scripts/tomcat/openstack/healthcheck.sh
----------------------------------------------------------------------
diff --git a/tools/cartridge_create/init_scripts/tomcat/openstack/healthcheck.sh b/tools/cartridge_create/init_scripts/tomcat/openstack/healthcheck.sh
new file mode 100755
index 0000000..c420d10
--- /dev/null
+++ b/tools/cartridge_create/init_scripts/tomcat/openstack/healthcheck.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+var=`nc -z localhost 8080; echo $?`;
+if [ $var -eq 0 ]
+then
+    echo "port 8080 is available" > /dev/null 2>&1
+else
+    echo "port 8080 is not available" > /dev/null 2>&1
+    /etc/init.d/apache2 restart
+fi

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/44c3d76d/tools/cartridge_create/init_scripts/tomcat/openstack/stratos-init.sh
----------------------------------------------------------------------
diff --git a/tools/cartridge_create/init_scripts/tomcat/openstack/stratos-init.sh b/tools/cartridge_create/init_scripts/tomcat/openstack/stratos-init.sh
new file mode 100755
index 0000000..ba30b44
--- /dev/null
+++ b/tools/cartridge_create/init_scripts/tomcat/openstack/stratos-init.sh
@@ -0,0 +1,289 @@
+#!/bin/bash
+
+# ----------------------------------------------------------------------------
+#  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.
+
+# ----------------------------------------------------------------------------
+
+# This script will be called from /etc/rc.local when the cartridge
+# instance is spawned. It will initiate all the tasks that needs to 
+# be run to bring the cartridge instance to operational state.
+
+export LOG=/var/log/stratos-cartridge.log
+instance_path=/var/lib/cloud/instance
+PUBLIC_IP=""
+KEY=`uuidgen`
+CRON_DURATION=1
+RETRY_COUNT=30
+SLEEP_DURATION=3
+
+if [ ! -d ${instance_path}/payload ]; then
+
+    echo "creating payload dir ... " >> $LOG
+    mkdir ${instance_path}/payload
+    echo "payload dir created ... " >> $LOG
+    cp ${instance_path}/user-data.txt ${instance_path}/payload/user-data.zip
+    echo "payload copied  ... "  >> $LOG
+    unzip -d ${instance_path}/payload ${instance_path}/payload/user-data.zip
+    echo "unzippeddd..." >> $LOG
+
+    for i in `/usr/bin/ruby /opt/get-launch-params.rb`
+    do
+    echo "exporting to bashrc $i ... " >> $LOG
+        echo "export" ${i} >> /home/ubuntu/.bashrc
+    done
+    source /home/ubuntu/.bashrc
+
+fi
+
+
+echo ---------------------------- >> $LOG
+echo "getting public ip from metadata service" >> $LOG
+
+wget http://169.254.169.254/latest/meta-data/public-ipv4
+files="`cat public-ipv4`"
+if [[ -z ${files} ]]; then
+    echo "getting public ip" >> $LOG
+    for i in {1..30}
+    do
+      rm -f ./public-ipv4
+      wget http://169.254.169.254/latest/meta-data/public-ipv4
+      files="`cat public-ipv4`"
+      if [ -z $files ]; then
+          echo "Public ip is not yet assigned. Wait and continue for $i the time ..." >> $LOG
+          sleep $SLEEP_DURATION
+      else
+          echo "Public ip assigned" >> $LOG
+          break
+      fi
+    done
+
+    if [ -z $files ]; then
+      echo "Public ip is not yet assigned. So exit" >> $LOG
+      exit 0
+    fi
+    for x in $files
+    do
+        PUBLIC_IP="$x"
+    done
+
+
+else 
+   PUBLIC_IP="$files"
+fi
+
+
+for i in `/usr/bin/ruby /opt/get-launch-params.rb`
+do
+    export ${i}
+done
+
+
+echo "Restarting apache..." >> $LOG
+
+/etc/init.d/apache2 restart
+
+echo "Apache restarted..." >> $LOG
+
+
+echo "Logging sys variables .. PUBLIC_IP:${PUBLIC_IP}, HOST_NAME:${HOST_NAME}, KEY:${KEY}, PORTS=${PORTS}, BAM:${BAM_IP}, GITREPO:${GIT_REPO}" >> $LOG
+
+mkdir -p  /etc/agent/conf
+
+echo "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:agen=\"http://service.agent.cartridge.stratos.apache.org\">
+  <soapenv:Header/>
+  <soapenv:Body>
+     <agen:register>
+        <registrant> 
+           <alarmingLowerRate>${ALARMING_LOWER_RATE}</alarmingLowerRate>
+           <alarmingUpperRate>${ALARMING_UPPER_RATE}</alarmingUpperRate>
+           <hostName>${HOST_NAME}</hostName>
+           <key>${KEY}</key>
+          <maxInstanceCount>${MAX}</maxInstanceCount>
+	  <maxRequestsPerSecond>${MAX_REQUESTS_PER_SEC}</maxRequestsPerSecond>
+          <minInstanceCount>${MIN}</minInstanceCount> " > /etc/agent/conf/request.xml
+
+IFS='|' read -ra PT <<< "${PORTS}"
+for i in "${PT[@]}"; do
+IFS=':' read -ra PP <<< "$i"
+echo "          <portMappings>
+                        <primaryPort>${PP[1]}</primaryPort>
+                        <proxyPort>${PP[2]}</proxyPort>
+                        <type>${PP[0]}</type>
+                </portMappings>">> /etc/agent/conf/request.xml
+done
+
+echo "          <remoteHost>${PUBLIC_IP}</remoteHost>
+           <service>${SERVICE}</service>
+	   <remoteHost>${PUBLIC_IP}</remoteHost>
+           <roundsToAverage>${ROUNDS_TO_AVERAGE}</roundsToAverage>
+           <scaleDownFactor>${SCALE_DOWN_FACTOR}</scaleDownFactor>
+           <tenantRange>${TENANT_RANGE}</tenantRange>
+        </registrant>
+     </agen:register>
+  </soapenv:Body>
+</soapenv:Envelope>
+" >> /etc/agent/conf/request.xml
+
+echo "Creating repoinfo request  " >> $LOG
+echo "TENANT_ID and SERVICE ${TENANT_ID} and ${SERVICE} " >> $LOG
+set -- "${HOST_NAME}" 
+IFS="."; declare -a Array=($*)
+ALIAS="${Array[0]}"
+echo "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://org.apache.axis2/xsd\">
+   <soapenv:Header/>
+   <soapenv:Body>
+      <xsd:getRepositoryCredentials>
+         <xsd:tenantId>${TENANT_ID}</xsd:tenantId>
+         <xsd:cartridgeType>${SERVICE}</xsd:cartridgeType>
+         <xsd:alias>${ALIAS}</xsd:alias>
+      </xsd:getRepositoryCredentials>
+   </soapenv:Body>
+</soapenv:Envelope>" > /opt/repoinforequest.xml
+
+echo "Repoinfo request created " >> $LOG
+
+echo "Private Key....Copying to .ssh  " >> $LOG
+
+cp ${instance_path}/payload/id_rsa /root/.ssh/id_rsa
+chmod 0600 /root/.ssh/id_rsa
+echo "StrictHostKeyChecking no" >> /root/.ssh/config
+
+
+
+
+#echo "Getting repo username password from repoInfoService" >> $LOG
+#curl -X POST -H "Content-Type: text/xml" -d @/etc/agent/conf/request.xml --silent --output /dev/null "${CARTRIDGE_AGENT_EPR}"
+
+echo "Git repo sync" >> $LOG
+
+# If repo is available do a git pull, else clone
+
+echo "#!/bin/bash
+if [ -d \"${APP_PATH}/.git\" ]; then
+    cd ${APP_PATH}
+
+    curl -X POST -H \"Content-Type: text/xml\" -H \"SOAPAction: urn:getRepositoryCredentials\" -d @/opt/repoinforequest.xml --silent  \"${REPO_INFO_EPR}\" --insecure > /tmp/git.xml
+   sed '1,5d' /tmp/git.xml > /tmp/git1.xml
+   sed '2d' /tmp/git1.xml > /tmp/git.xml
+   username=\`xml_grep 'ax29:userName' /tmp/git.xml --text_only\`
+   password=\`xml_grep 'ax29:password' /tmp/git.xml --text_only\`
+   repo=\`xml_grep 'ax29:url' /tmp/git.xml --text_only\`
+   rm /tmp/git1.xml
+   rm /tmp/git.xml
+   url=\`echo \$repo |sed 's/http.*\/\///g' |sed 's/\:.*//g' |sed 's/\/.*//g'\`
+   echo \"machine \${url} login \${username} password \${password}\" > ~/.netrc
+   sudo echo \"machine \${url} login \${username} password \${password}\" > /root/.netrc
+   chmod 600 ~/.netrc
+   sudo chmod 600 /root/.netrc
+   git config --global --bool --add http.sslVerify false
+   sudo git pull
+   rm ~/.netrc
+   sudo rm /root/.netrc
+
+else
+   curl -X POST -H \"Content-Type: text/xml\" -H \"SOAPAction: urn:getRepositoryCredentials\" -d @/opt/repoinforequest.xml --silent  \"${REPO_INFO_EPR}\" --insecure > /tmp/git.xml
+   sed '1,5d' /tmp/git.xml > /tmp/git1.xml
+   sed '2d' /tmp/git1.xml > /tmp/git.xml
+   username=\`xml_grep 'ax29:userName' /tmp/git.xml --text_only\`
+   password=\`xml_grep 'ax29:password' /tmp/git.xml --text_only\`
+   repo=\`xml_grep 'ax29:url' /tmp/git.xml --text_only\`
+   rm /tmp/git1.xml
+   rm /tmp/git.xml
+   url=\`echo \$repo |sed 's/http.*\/\///g' |sed 's/\:.*//g' |sed 's/\/.*//g'\`
+   echo \"machine \${url} login \${username} password \${password}\" > ~/.netrc
+   sudo echo \"machine \${url} login \${username} password \${password}\" > /root/.netrc
+   chmod 600 ~/.netrc
+   sudo chmod 600 /root/.netrc
+    git config --global --bool --add http.sslVerify false
+    cd ${APP_PATH}
+    sudo mv ROOT ../
+    sudo git clone \${repo} ${APP_PATH}
+    sudo mv ../ROOT .
+   rm ~/.netrc
+   sudo rm /root/.netrc
+ 
+
+fi" > /opt/git.sh
+echo "File created.." >> $LOG
+chmod 755 /opt/git.sh
+                       
+
+
+while true
+do
+var=`nc -z localhost 8080; echo $?`;
+if [ $var -eq 0 ]
+   then
+       echo "port 8080 is available" >> $LOG
+       break
+   else
+       echo "port 8080 is not available" >> $LOG
+   fi
+   sleep 1
+done
+
+
+while true
+do
+var=`nc -z localhost 8443; echo $?`;
+if [ $var -eq 0 ]
+   then
+       echo "port 8443 is available" >> $LOG
+       break
+   else
+       echo "port 8443 is not available" >> $LOG
+   fi
+   sleep 1
+done
+
+
+
+echo "Sending register request to Cartridge agent service" >> $LOG
+
+curl -X POST -H "Content-Type: text/xml" -H "SOAPAction: urn:register" -d @/etc/agent/conf/request.xml -k --silent --output /dev/null "${CARTRIDGE_AGENT_EPR}"
+
+echo "Registered cartridge..." >> $LOG
+
+echo "running git clone........" >> $LOG
+su - ubuntu /opt/git.sh
+
+
+echo "setting up logging conf" >> $LOG
+
+
+echo "host:     ${BAM_IP}
+thriftPort:     ${BAM_PORT}
+
+#cartridge configs
+cartridgeAlias:  ${CARTRIDGE_ALIAS}
+tenantName:      ${HOST_NAME}
+tenantId:        ${TENANT_ID}
+localIP:         ${PUBLIC_IP}" > /opt/cartridge_data_publisher_1.0.2/conf/data_publisher.conf
+
+
+
+echo "started loggin ........."
+cd /opt/cartridge_data_publisher_1.0.2/dist/Debug/GNU-Linux-x86/
+nohup ./cartridge_data_publisher_1.0.2 /var/lib/tomcat7/logs/catalina.out >> /var/log/stratos-data-publisher.log  &
+
+echo "logging started........."
+
+
+# ========================== // End of script ===========================================================
+

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/44c3d76d/tools/stratos-installer/cartridges/tomcat.xml
----------------------------------------------------------------------
diff --git a/tools/stratos-installer/cartridges/tomcat.xml b/tools/stratos-installer/cartridges/tomcat.xml
new file mode 100644
index 0000000..cd2cca1
--- /dev/null
+++ b/tools/stratos-installer/cartridges/tomcat.xml
@@ -0,0 +1,45 @@
+<!-- Use below section to specify properties that are needed in order to start Cartridges.  -->
+    <cartridges>
+
+        <!-- You can have 1..n cartridge elements. -->
+        <cartridge type="tomcat" host="tomcat.STRATOS_DOMAIN" provider="apache" version="7" multiTenant="false">
+            <!-- cartridge element can have 0..n properties, and they'll be overwritten by the properties
+                 specified under iaasProvider child elements of cartridge element. -->
+
+            <displayName>TOMCAT</displayName>
+            <description>TOMCAT Cartridge</description>
+            <!-- A cartridge element should add a reference to an existing IaaS provider (specified
+                 in the above &lt;iaasProviders&gt; section) or it can create a completely new IaaS
+                 Provider (which should have a unique "type" attribute. -->
+            <iaasProvider type="openstack" >
+                <imageId>RegionOne/9701eb18-d7e1-4a53-a2bf-a519899d451c</imageId>
+                <property name="keyPair" value="manula_openstack"/>
+                <property name="instanceType" value="RegionOne/2"/>
+                <property name="securityGroups" value="im-security-group1"/>
+                <!--<property name="payload" value="resources/as.txt"/>-->
+            </iaasProvider>
+            <!--<iaasProvider type="ec2" >
+                <imageId>us-east-1/ami-ef49e786</imageId>           
+                <property name="keyPair" value="aa"/>
+                <property name="securityGroups" value="default"/>
+                <property name="instanceType" value="m1.large"/>
+                <property name="payload" value="resources/as-ec2.txt"/>
+            </iaasProvider>-->
+            <deployment baseDir="/var/lib/tomcat7/webapps">
+                <dir>www=copy#app#files#here</dir>
+                <dir>simplesamlphp=copy#saml#libraries#here</dir>
+		<dir>sql=copy#saml#libraries#here</dir>
+            </deployment>
+	   <portMapping>
+               <http port="8080" proxyPort="8280"/>
+               <https port="8443" proxyPort="8243"/>
+           </portMapping>
+            <!--<appTypes>
+                <property name="axis2services" isBothmapping="false"/>
+                <property name="webapps" isBothmapping="true"/>
+                <property name="jaxwebapps" isBothmapping="true"/>
+                <property name="jaggeryapps" isBothmapping="true"/>
+            </appTypes>-->
+        </cartridge>
+
+    </cartridges>