webcontainer.xml revision da97433d5cd26e422a370d186f98659383c06721
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE stax SYSTEM "/stax.dtd">
<!--
! CDDL HEADER START
!
! The contents of this file are subject to the terms of the
! Common Development and Distribution License, Version 1.0 only
! (the "License"). You may not use this file except in compliance
! with the License.
!
! You can obtain a copy of the license at
! trunk/opends/resource/legal-notices/OpenDS.LICENSE
! or https://OpenDS.dev.java.net/OpenDS.LICENSE.
! See the License for the specific language governing permissions
! and limitations under the License.
!
! When distributing Covered Code, include this CDDL HEADER in each
! file and include the License file at
! trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
! add the following below this CDDL HEADER, with the fields enclosed
! by brackets "[]" replaced with your own identifying information:
! Portions Copyright [yyyy] [name of copyright owner]
!
! CDDL HEADER END
!
! Portions Copyright 2008-2009 Sun Microsystems, Inc.
! -->
<stax>
<function name="createWebcontainer" scope="local">
<function-prolog>
This function creates a default webcontainer instance
</function-prolog>
<function-map-args>
<function-arg-def name="location" type="optional" default="STAF_REMOTE_HOSTNAME">
<function-arg-description>
Location of target host
</function-arg-description>
<function-arg-property name="type" value="hostname"/>
</function-arg-def>
<function-arg-def name="wcPath" type="optional" default="'%s' % WC_DIRECTORY">
<function-arg-description>
Pathname to installation root
</function-arg-description>
<function-arg-property name="type" value="filepath"/>
</function-arg-def>
</function-map-args>
<try>
<sequence>
<script>
mylocation=location
</script>
<!-- Copy webcontainer zip archive to remote host -->
<message>
'Copy webcontainer %s to host %s' % (WC_ZIPNAME,location)
</message>
<call function="'copyFile'">
{ 'location' : STAXServiceMachine,
'srcfile' : '%s/%s' % (WC_ZIPPATH,WC_ZIPNAME),
'destfile' : '%s/%s' % (wcPath,WC_ZIPNAME),
'remotehost' : mylocation
}
</call>
<!-- Unzip webcontainer into temporary folder -->
<message>
'Extract temporary webcontainer zip archive to %s %s.' % (location, wcPath)
</message>
<call function="'unZipFile'">
{ 'location' : mylocation,
'zipfile' : '%s/%s' % (wcPath,WC_ZIPNAME),
'unzipdir' : '%s' % wcPath }
</call>
<!-- chmod +x all the .sh file in tomcat bin directory -->
<stafcmd name="'make tomcat shell scripts executable'">
<location>'%s' % mylocation</location>
<service>'fs'</service>
<request>' LIST DIRECTORY %s/%s-%s/bin EXT sh' % \
(wcPath, WC_TYPE, WC_VERSION)</request>
</stafcmd>
<script>
shFilesRC=RC
shFilesResult=" ".join(STAFResult)
</script>
<message>'shFilesResult=%s' % shFilesResult</message>
<process name="'chmod +x tomcat\'s shell scripts'">
<location>'%s' % mylocation</location>
<command mode="'shell'">'chmod +x %s' % shFilesResult</command>
<parms/>
<workdir>'%s/%s-%s/bin' % (wcPath, WC_TYPE, WC_VERSION)</workdir>
<envs>['PATH=/bin:/usr/bin']</envs>
<stderr mode="'stdout'"/>
<stdout/>
<returnstdout/>
</process>
<!-- generate SSL certificate -->
<!-- Check if 'tomcatCertificate' file exists -->
<call function="'GetEntry'">
{
'location' : STAXServiceMachine,
'entry' : '%s/tomcatCertificate' % TMPDIR,
'attribute' : 'TYPE'
}
</call>
<!-- 'tomcatCertificate' file does not exist so generate it -->
<if expr="RC == 48">
<call function="'runCommand'">
{ 'name' : 'Generate a Certificate',
'location' : STAXServiceMachine,
'command' : '%s/bin/keytool' % (LOCAL_JAVA_HOME),
'arguments' : '-genkey -alias tomcat -keyalg rsa \
-dname "cn=tomcat,O=Sun Microsystems,C=US" \
-keystore "%s/tomcatCertificate" \
-storepass "changeit" -keypass "changeit" \
-storetype JKS ' % (TMPDIR),
'path' : '%s/bin' % (LOCAL_JAVA_HOME),
'expectedRC': 0
}
</call>
</if>
<call function="'copyFile'">
{ 'location' : STAXServiceMachine,
'srcfile' : '%s/tomcatCertificate' % (TMPDIR),
'destfile' : '%s/%s-%s/conf/tomcatCertificate' % (wcPath, WC_TYPE, WC_VERSION),
'remotehost' : mylocation
}
</call>
<!-- configure webcontainer's PORTs -->
<message>
'Configure webcontainer ports HTTP %s / HTTPS %s' % (WC_PORT, WC_SSL_PORT)
</message>
<stafcmd name="'get tomcat configuration file'">
<location>'%s' % mylocation</location>
<service>'fs'</service>
<request>' GET FILE %s/%s-%s/conf/server.xml ' % \
(wcPath, WC_TYPE, WC_VERSION)</request>
</stafcmd>
<script>
serverXmlInput=STAFResult
import re
portRegEx = re.compile('8080')
sslPortRegEx = re.compile('8443')
content=portRegEx.sub(WC_PORT, serverXmlInput)
content=sslPortRegEx.sub(WC_SSL_PORT, content)
sslConnectorRegEx = re.compile('&lt;Service name="Catalina"&gt;')
SSL_CONNECTOR = '&lt;Service name="Catalina"&gt;\n \
&lt;Connector port="%s" protocole="HTTP/1.1" \
SSLEnabled="true" maxThreads="150" scheme="https" secure="true" \
clientAuth="false" sslProtocol="SSL" \
keystoreFile="%s/%s-%s/conf/tomcatCertificate" \
keystorePass="changeit" /&gt;' % \
(WC_SSL_PORT, wcPath, WC_TYPE, WC_VERSION)
content=sslConnectorRegEx.sub(SSL_CONNECTOR, content)
serverXmlOutput=open('%s/%s-%s-%s_server.xml' % \
(local.temp,STAF_REMOTE_HOSTNAME,WC_TYPE,WC_VERSION),'w')
serverXmlOutput.write(content)
serverXmlOutput.close()
</script>
<call function="'copyFile'">
{'srcfile' : '%s/%s-%s-%s_server.xml' % (local.temp, STAF_REMOTE_HOSTNAME, WC_TYPE, WC_VERSION),
'destfile' : '%s/%s-%s/conf/server.xml' % (wcPath, WC_TYPE, WC_VERSION),
'remotehost' : '%s' % STAF_REMOTE_HOSTNAME
}
</call>
<!-- configure webcontainer's SSL environement -->
<message>
'Configure webcontainer SSL keystore '
</message>
<if expr="RC != 0">
<return>RC</return>
</if>
</sequence>
<catch exception="'TestExceptionResultFailed'" typevar="eType" var="eInfo">
<sequence>
<message>'caught %s with %s' % (eType,eInfo)</message>
<message>
'Remove temporary webcontainer zip archive from %s %s' % (location,wcPath)
</message>
<call function="'deleteFolder'">
{ 'location' : location ,
'foldername' : '%s' % wcPath }
</call>
</sequence>
</catch>
</try>
</function>
<function name="deployWebApplicationWAR" scope="local">
<function-prolog>
This function deploys a Web Application War file
</function-prolog>
<function-map-args>
<function-arg-def name="location" type="optional" default="STAF_REMOTE_HOSTNAME">
<function-arg-description>
Location of target host
</function-arg-description>
<function-arg-property name="type" value="hostname"/>
</function-arg-def>
<function-arg-def name="wcPath" type="optional" default="'%s' % WC_DIRECTORY">
<function-arg-description>
Pathname to installation root
</function-arg-description>
<function-arg-property name="type" value="filepath"/>
</function-arg-def>
<function-arg-def name="warFilePath" type="required" default="''">
<function-arg-description>
Web application war file path
</function-arg-description>
<function-arg-property name="type" value="filepath"/>
</function-arg-def>
<function-arg-def name="destWarFileName" type="optional" default="'dsml.war'">
<function-arg-description>
Web application war destination file path
</function-arg-description>
<function-arg-property name="type" value="filepath"/>
</function-arg-def>
</function-map-args>
<sequence>
<message>
'setup: deploy web application %s to %s/%s-%s/webapps/%s' % (warFilePath, wcPath, WC_TYPE, WC_VERSION, destWarFileName)
</message>
<call function="'copyFile'">
{ 'location' : STAXServiceMachine,
'srcfile' : '%s' % warFilePath,
'destfile' : '%s/%s-%s/webapps/%s' % (wcPath, WC_TYPE, WC_VERSION, destWarFileName),
'remotehost' : location}
</call>
</sequence>
</function>
<function name="stopWebcontainerWithScript" scope="local">
<function-prolog>
This function stops a webcontainer
</function-prolog>
<function-map-args>
<function-arg-def name="location" type="optional" default="STAF_REMOTE_HOSTNAME">
<function-arg-description>
Location of target host
</function-arg-description>
<function-arg-property name="type" value="hostname"/>
</function-arg-def>
<function-arg-def name="wcPath" type="optional" default="'%s' % WC_DIRECTORY">
<function-arg-description>
Pathname to installation root
</function-arg-description>
<function-arg-property name="type" value="filepath"/>
</function-arg-def>
</function-map-args>
<sequence>
<!-- Build the Command -->
<script>
if wcPath:
wcBinPath='%s/bin' % wcPath
STAFCmd='%s/shutdown%s' % (wcBinPath, scriptExt)
STAFCmdEnv=['CATALINA_HOME=%s' % wcPath,'PATH=/bin:/usr/bin',\
'JAVA_HOME=%s' % JAVA_HOME]
</script>
<message>
'%s' % STAFCmd
</message>
<call function="'runCommand'">
{ 'location' : location,
'command' : STAFCmd,
'envCmd' : STAFCmdEnv,
'name' : STAFCmd,
'path' : wcBinPath
}
</call>
</sequence>
</function>
<function name="startWebcontainerWithScript" scope="local">
<function-prolog>
This function start a webcontainer
</function-prolog>
<function-map-args>
<function-arg-def name="location" type="optional" default="STAF_REMOTE_HOSTNAME">
<function-arg-description>
Location of target host
</function-arg-description>
<function-arg-property name="type" value="hostname"/>
</function-arg-def>
<function-arg-def name="wcPath" type="optional" default="'%s/%s-%s' % (WC_DIRECTORY, WC_TYPE, WC_VERSION)">
<function-arg-description>
Pathname to installation root
</function-arg-description>
<function-arg-property name="type" value="filepath"/>
</function-arg-def>
</function-map-args>
<sequence>
<!-- Build the Command -->
<script>
if wcPath:
wcBinPath='%s/bin' % wcPath
STAFCmd='%s/startup%s' % (wcBinPath, scriptExt)
STAFCmdEnv=['CATALINA_HOME=%s' % wcPath,'PATH=/bin:/usr/bin', \
'JAVA_HOME=%s' % JAVA_HOME]
</script>
<message>
'%s' % STAFCmd
</message>
<!-- On Windows 2003, startup command return 1 and 2008 returns 0 -->
<script>
winVersion = is_windows_platform(location)
if winVersion and winVersion.find('2003') != -1:
expectedRC=1
else:
expectedRC=0
</script>
<call function="'runCommand'">
{ 'location' : location,
'command' : STAFCmd,
'envCmd' : STAFCmdEnv,
'name' : STAFCmd,
'path' : wcBinPath,
'expectedRC' : expectedRC
}
</call>
</sequence>
</function>
<function name="removeWebcontainer" scope="local">
<function-prolog>
This function removes the webcontainer instance
</function-prolog>
<function-map-args>
<function-arg-def name="location" type="optional" default="STAF_REMOTE_HOSTNAME">
<function-arg-description>
Location of target host
</function-arg-description>
<function-arg-property name="type" value="hostname"/>
</function-arg-def>
<function-arg-def name="wcPath" type="optional" default="'%s' % WC_DIRECTORY">
<function-arg-description>
Pathname to installation root
</function-arg-description>
<function-arg-property name="type" value="filepath"/>
</function-arg-def>
</function-map-args>
<try>
<sequence>
<!-- Remove webcontainer directory -->
<message>
'Remove webcontainer from %s %s.' % (location,wcPath)
</message>
<call function="'deleteFolder'">
{ 'location' : location,
'foldername' : '%s/%s-%s' % (wcPath, WC_TYPE, WC_VERSION) }
</call>
<if expr="RC != 0">
<return>RC</return>
</if>
</sequence>
<catch exception="'TestExceptionResultFailed'" typevar="eType" var="eInfo">
<sequence>
<message>'caught %s with %s' % (eType,eInfo)</message>
<message>
'Remove temporary webcontainer zip archive from %s %s' % (location,wcPath)
</message>
<call function="'deleteFolder'">
{ 'location' : location ,
'foldername' : '%s/%s-%s' % (wcPath, WC_TYPE, WC_VERSION) }
</call>
</sequence>
</catch>
</try>
</function>
</stax>