Friday, November 21, 2008

Shell scripts with admin.jar

I created an check uri shell script to test if the URI is correct:
#!/bin/sh
if [ $# != 2 ];
then
echo "Start: $0 "
echo "Single instance: (deployer:oc4j:opmn://HOSTNAME:OPMN_REQUEST_PORT/OC4J_CONTAINER)"
echo "Cluster: (deployer:cluster:opmn://HOSTNAME:OPMN_REQUEST_PORT/OC4J_CONTAINER)"
exit 1
fi

export URI=${1}
export PASSWORD=${2}


echo " ... checking the URI ..."
$JAVA_HOME/bin/java -Djava.util.logging.config.file=logging.properties -jar $ORACLE_HOME/j2ee/home/admin_client.jar ${URI} oc4jadmin ${PASSWORD} -validateURI
exit 0


Add Shared Libraries:
#!/bin/sh
if [ $# != 6 ];
then
echo "Start op: $0 "
echo "Example: "
echo "Single instance uri : deployer:oc4j:opmn://HOSTNAME:PORT/CONTAINER_NAME"
echo "Cluster uri : deployer:cluster:opmn://HOSTNAME:PORT/CONTAINER_NAME"
echo "Library sources : 'path/source1.jar path/source2.jar'"
exit 1
fi

export ENV=${1}
export URI=${2}
export PASSWORD=${3}
export LIBRARY_NAME=${4}
export LIBRARY_VERSION=${5}
export LIBRARY_SOURCE=${6}

. ~/${ENV}

check_uri ${ENV} ${URI} ${PASSWORD}
if [ $? == 0 ];
then
$JAVA_HOME/bin/java -Djava.util.logging.config.file=logging.properties -jar $ORACLE_HOME/j2ee/home/admin_client.jar ${URI} oc4jadmin ${PASSWORD} -publishSharedLibrary -name ${LIBRARY_NAME} -version ${LIBRARY_VERSION} -installCodeSources ${LIBRARY_SOURCE}
fi

exit 0


Script to create datasources/connection pools:
#!/bin/sh
if [ $# != 8 ];
then
echo "Start op: $0 "
echo "Example: "
echo "Single instance uri : deployer:oc4j:opmn://HOSTNAME:PORT/CONTAINER_NAME"
echo "Cluster uri : deployer:cluster:opmn://HOSTNAME:PORT/CONTAINER_NAME"
echo "Database connect string: DATABASE_HOSTNAME:PORT:ORACLE_SID"
exit 1
fi

export ENV=${1}
export URI=${2}
export PASSWORD=${3}
export CONNECTION_POOL=${4}
export DATASOURCE=${5}
export DB=${6}
export DB_USER=${7}
export DB_PASSWORD=${8}


. ~/${ENV}

check_uri ${ENV} ${URI} ${PASSWORD}
if [ $? == 0 ];
then
echo " ...create connection pool ${CONNECTION_POOL} ..."
$JAVA_HOME/bin/java -Djava.util.logging.config.file=logging.properties -jar $ORACLE_HOME/j2ee/home/admin_client.jar ${URI} oc4jadmin ${PASSWORD} -addDataSourceConnectionPool -name ${CONNECTION_POOL} -factoryClass oracle.jdbc.pool.OracleDataSource -dbUser ${DB_USER} -dbPassword ${DB_PASSWORD} -url jdbc:oracle:thin:@${DB}

echo " ...create managed data source ${DATASOURCE} ..."
$JAVA_HOME/bin/java -Djava.util.logging.config.file=logging.properties -jar $ORACLE_HOME/j2ee/home/admin_client.jar ${URI} oc4jadmin ${PASSWORD} -addManagedDataSource -name ${DATASOURCE} -jndiLocation jdbc/${CONNECTION_POOL} -connectionPoolName ${CONNECTION_POOL}

echo " ... Test managed data source ${DATASOURCE} ..."
$JAVA_HOME/bin/java -Djava.util.logging.config.file=logging.properties -jar $ORACLE_HOME/j2ee/home/admin_client.jar ${URI} oc4jadmin ${PASSWORD} -testDataSourceConnectionPool -name ${CONNECTION_POOL} -sqlStatement "select * from dual"
fi

exit 0

No comments:

Post a Comment

comment