Interactive Glassfish configuration and application deployment
The Yellowfire project like most projects provides deployments tasks as part of the development process but I wanted to provide administrators or users with a less technical alternative. My first stab at the task was to create batch files that provides the calls to asadmin that created all the configuration within Glassfish.
<pre>@REM "Delete the connection pools" CALL %GLASSFISH_HOME%\bin\asadmin --port 4949 delete-jdbc-connection-pool --cascade=true pool.yellowfire.online CALL %GLASSFISH_HOME%\bin\asadmin --port 4949 delete-jdbc-connection-pool --cascade=true pool.yellowfire.security CALL %GLASSFISH_HOME%\bin\asadmin --port 4949 delete-jdbc-connection-pool --cascade=true pool.training.online CALL %GLASSFISH_HOME%\bin\asadmin --port 4949 delete-jdbc-connection-pool --cascade=true pool.training.archive @REM "Create the connection pools" CALL %GLASSFISH_HOME%\bin\asadmin --port 4949 create-jdbc-connection-pool --datasourceclassname com.microsoft.sqlserver.jdbc.SQLServerDataSource --restype javax.sql.DataSource --steadypoolsize 1 --statementcachesize 50 --ping true --description "" --property databaseName=race:serverName=localhost\\SQLSERVER2008R2:user=race:password=race pool.yellowfire.online CALL %GLASSFISH_HOME%\bin\asadmin --port 4949 create-jdbc-connection-pool --datasourceclassname com.microsoft.sqlserver.jdbc.SQLServerDataSource --restype javax.sql.DataSource --steadypoolsize 1 --statementcachesize 50 --ping true --description "" --property databaseName=race:serverName=localhost\\SQLSERVER2008R2:user=race:password=race pool.yellowfire.security CALL %GLASSFISH_HOME%\bin\asadmin --port 4949 create-jdbc-connection-pool --datasourceclassname com.microsoft.sqlserver.jdbc.SQLServerDataSource --restype javax.sql.DataSource --steadypoolsize 1 --statementcachesize 50 --ping true --description "" --property databaseName=race:serverName=localhost\\SQLSERVER2008R2:user=training:password=training pool.training.online CALL %GLASSFISH_HOME%\bin\asadmin --port 4949 create-jdbc-connection-pool --datasourceclassname com.microsoft.sqlserver.jdbc.SQLServerDataSource --restype javax.sql.DataSource --steadypoolsize 1 --statementcachesize 50 --ping true --description "" --property databaseName=race:serverName=localhost\\SQLSERVER2008R2:user=archive:password=archive pool.training.archive @REM "Create the jdbc resources" CALL %GLASSFISH_HOME%\bin\asadmin --port 4949 create-jdbc-resource --connectionpoolid pool.yellowfire.online --enabled true yellowfire.ds CALL %GLASSFISH_HOME%\bin\asadmin --port 4949 create-jdbc-resource --connectionpoolid pool.yellowfire.security --enabled true yellowfire.security.ds CALL %GLASSFISH_HOME%\bin\asadmin --port 4949 create-jdbc-resource --connectionpoolid pool.training.online --enabled true yellowfire.training.online.ds CALL %GLASSFISH_HOME%\bin\asadmin --port 4949 create-jdbc-resource --connectionpoolid pool.training.archive --enabled true yellowfire.training.archive.ds</pre>
I could simplify the process by refactoring out the location of the Glassfish server and the domain port as follows:-
<pre>delete-jdbc-connection-pool --cascade=true pool.yellowfire.online delete-jdbc-connection-pool --cascade=true pool.yellowfire.security delete-jdbc-connection-pool --cascade=true pool.training.online delete-jdbc-connection-pool --cascade=true pool.training.archive create-jdbc-connection-pool --datasourceclassname com.microsoft.sqlserver.jdbc.SQLServerDataSource --restype javax.sql.DataSource --steadypoolsize 1 --statementcachesize 50 --ping true --description "" --property databaseName=race:serverName=localhost\\SQLSERVER2008R2:user=race:password=race pool.yellowfire.online create-jdbc-connection-pool --datasourceclassname com.microsoft.sqlserver.jdbc.SQLServerDataSource --restype javax.sql.DataSource --steadypoolsize 1 --statementcachesize 50 --ping true --description "" --property databaseName=race:serverName=localhost\\SQLSERVER2008R2:user=race:password=race pool.yellowfire.security create-jdbc-connection-pool --datasourceclassname com.microsoft.sqlserver.jdbc.SQLServerDataSource --restype javax.sql.DataSource --steadypoolsize 1 --statementcachesize 50 --ping true --description "" --property databaseName=race:serverName=localhost\\SQLSERVER2008R2:user=training:password=training pool.training.online create-jdbc-connection-pool --datasourceclassname com.microsoft.sqlserver.jdbc.SQLServerDataSource --restype javax.sql.DataSource --steadypoolsize 1 --statementcachesize 50 --ping true --description "" --property databaseName=race:serverName=localhost\\SQLSERVER2008R2:user=archive:password=archive pool.training.archive create-jdbc-resource --connectionpoolid pool.yellowfire.online --enabled true yellowfire.ds create-jdbc-resource --connectionpoolid pool.yellowfire.security --enabled true yellowfire.security.ds create-jdbc-resource --connectionpoolid pool.training.online --enabled true yellowfire.training.online.ds create-jdbc-resource --connectionpoolid pool.training.archive --enabled true yellowfire.training.archive.ds</pre>
But I was still left with a problem that the values for the database server were still hard coded into the files which meant either manually updating the files or implementing some obscure parameter passing that needed to be documented.
Luckily while I was searching the internet for the latest build systems like Gradle, Gant, and Maven, I stumbled on AntForm. Immediately I knew that I could use this handy piece of software to develop the deployment wizards that I needed to make the process more intuitive for people that would deploy the application but were not hardcore Mavenites with a degree in Java-nese.
Currently the deployment wizard implements the application deployment target.
<pre><?xml version="1.0"?>
<project default="test">
<property file="properties.txt"/>
<property file="properties2.txt"/>
<property file="files.properties"/>
<property file="table.properties"/>
<property environment="env"/>
<property name="glassfish.home" value="${env.GLASSFISH_HOME}" />
<property name="glassfish.port" value="4848" />
<property name="application.file" value="../yellowfire-ear/target/yellowfire-0.0.1.ear" />
<property name="application.context.root" value="yellowfire" />
<path id="runtime.cp">
<pathelement location="./modules/"/>
<fileset dir="antform" includes="antform.jar"/>
</path>
<taskdef name="antform" classname="com.sardak.antform.AntForm"
classpath="./modules/antform/antform.jar"/>
<taskdef name="antmenu" classname="com.sardak.antform.AntMenu"
classpath="./modules/antform/antform.jar"/>
<!-- test the taskdef with a mail-like user form -->
<target name="test" description="Yellowfire deployment wizard">
<antform title="Yellowfire deployement wizard"
save="properties.txt"
stylesheet="modules/css/style.test"
image="modules/images/phoenix-100x78.png"
icon="modules/images/fire-icon-64x76.png"
lookAndFeel="com.sun.java.swing.plaf.windows.WindowsLookAndFeel"
loop="true"
>
<textProperty label="Glassfish Home : " property="glassfish.home" />
<textProperty label="Domain Port : " property="glassfish.port" />
<separator/>
<radioSelectionProperty
label="Database server: "
property="db.server.type"
values="Microsoft SQL Server; MySQL; Oracle"
separator=";"/>
<textProperty label="Server : " property="db.server.name" />
<textProperty label="Port : " property="db.server.port" />
<textProperty label="User : " property="db.server.user" />
<textProperty label="Password : " property="db.server.pwd" password="true" />
<multilineTextProperty label="Properties: " property="db.server.properties"/>
<separator/>
<fileSelectionProperty required="true" label="Deployment: " property="application.file"/>
<booleanProperty label="Only deploy latest: " property="application.deploy.only"/>
<buttonbar>
<button type="ok" label="Deploy" target="deploy"/>
<button type="reset" label="Reset" />
<button type="cancel" label="Cancel" loopexit="true" />
</buttonbar>
</antform>
</target>
<target name="deploy">
<antcall target="deploy.application" />
</target>
<target name="deploy.application">
<exec executable="${glassfish.home}/bin/asadmin.bat">
<arg line="--port ${glassfish.port} deploy --force true --contextroot ${application.context.root} --upload true ${application.file}"/>
</exec>
</target>
</project></pre>
The next step once, I have the have MySQL dump and restore wrapped up is to get the wizard to create the JDBC resources.

Trackbacks / Pingbacks