Appreciations accepted

Vladlen Litvinov, the author: If you have some job offer for me, I'm ready to discuss it. View Vladlen Litvinov's profile on LinkedIn

Password

Tuesday, December 24, 2013

Interactive script for IBM BPM offline installation of PAs (Import Part)

I continue the theme about automation of deploying of snapshots because some people interested in.
Here you can find the script for export.

Now I am publishing the shell script for importing of a snapshot for offline installation.

But, before we must create one utility for this.
Fact in that, during deploying we must migrate our old instances of Process Application.

This possible only using the file in our package what is named migrationInstructions.xml.
Its format is:

<?xml version="1.0" encoding="UTF-8"?>
<p:migrationInstructions xmlns:p="
http://lombardisoftware.com/schema/teamworks/7.0.0/migrationInstructions.xsd">
   <instruction snapshotId="2064.589cd42f-c714-4c17-ae0f-663b6db85b4c" action="migrate"/>
</p:migrationInstructions>


where

snapshotID - id of old default snapshot,
action - what we need to do during deploying with the instances.

Unfortunately, we cannot get snapshotId using scripts. So I wrote the utility for this.
You can compile it using Integration Designer. If you cannot - I can send to you.
This utility is for Oracle. For others DBs you can write yourself.

Its source:

package ru.vl.defaultSNID;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class DefaultSNID
{
   private static String CONN_STRING = null;
   private static String PANAME = null;

   public static void main(String[] args)
   {
  Connection connection = null;
  try {
   
  // Load the Oracle JDBC driver
   
  String driverName = "oracle.jdbc.driver.OracleDriver";
  Class.forName(driverName);
    
  if (args.length != 2)
  {
       throw new RuntimeException("The application needs two arguments: jdbc_conn_string & PA acronym. Exiting...");
     }
     CONN_STRING = args[0];
     PANAME = args[1];
    
  // Create a connection to the database

  String url = CONN_STRING;
  connection = DriverManager.getConnection(url);

  //System.out.println("Successfully Connected to the database!");
  PreparedStatement ps = connection.prepareStatement("select s.acronym snname, s.snapshot_id snid from lsw_snapshot s, lsw_project p where s.project_id = p.project_id and p.short_name = ? and s.is_default = 'T'");
  ps.setString(1, PANAME);
     ResultSet rs = ps.executeQuery();

     while (rs.next()) {
       String SNNAME = rs.getString("snname");
       String SNID = rs.getString("snid");
       System.out.println(SNNAME + " " + SNID);
     }
     connection.close();
    
  }
  catch (ClassNotFoundException e)
  {
   System.out.println("Could not find the database driver " + e.getMessage());
  }
  catch (SQLException e)
  {
   System.out.println("Could not connect to the database " + e.getMessage());
  }
  
   }
}


Using: java -jar defaultSNID.jar $DATA_SOURCE $PANAME > Default.log

where

$DATA_SOURCE - connection string
$PANAME - PA acronym

Output: <PA acronym> <snapshotID>

Now, the same script. Don't judge strictly, I am not a programmer. The script works by happy path.
If you found some mistakes, send them to me. I will be grateful to you.

One remark: Export folder used like a buffer folder for manipulating with our package,
Archive folder is the folder for storing of snapshots.
Our snapshot for deploying we must upload to the folder with the script.

The script:

1. Shows you the list of snapshots in PS for choice.
2. Checks existing of a new package.
3. Reads snapshotID for default
4. Creates migrationInstructions.xml and adds it to the package.
5. Installs the new snapshot with migration of instances.
6. Stops, undeploys and deletes the old snapshot.  

#!/bin/sh
# V.Litvinov 2013

# Change this to your data
HOSTNAME=host <hostname of Process Server server/use DMserver for cluster>
PORT=8880 <SOAP port>
USER=was_admin <username>
PASSWORD=password <password>
DM_HOME=/opt/ibm/bpm80/profiles/PSDeploymentManager <PS_PROFILE_HOME (use DM profile for custer)>
EXP_FOLDER=/opt/ibm/import/inbox <Export folder>
ARH_FOLDER=/opt/ibm/import/archive <Archive folder>

DATA_SOURCE=jdbc:oracle:thin:User/password@hostname:1521:BPMSID <Connection string>

echo
echo "***************************************************************"
echo "*  INTERACTIVE SCRIPT FOR IBM BPM OFFLINE INSTALLATION OF PAs *"
echo "*                      (Import Part)                          *"
echo "***************************************************************"
echo

echo Wait, please........
echo

# Reading Information about PAs using wasadmin
#$DM_HOME/bin/wsadmin.sh -lang jython -conntype SOAP -port $PORT -host $HOSTNAME -user $USER -password $PASSWORD -c "print AdminTask.BPMListProcessApplications('[]')" > PAPP.log

# Creating List of PAs (except Toolkits)
#declare -a ARRAY
#exec 10<PAPP.log
#let count=0
#while read LINE <&10; do
#if [ -n "$LINE" ]
#then
#    if [[ ${LINE:0:7} = 'Acronym' ]]
#    then
# ARRAY[$count]=${LINE:9}
# ((count++))
#    fi

#    if [[ ${LINE:0:13} = 'Toolkit: true' ]]
#    then
# ARRAY[$count-1]=''
# count=$count-1
#    fi
#fi
#done
#exec 10>&-

# Changing of working PA
#echo LIST OF YOUR PROCESS APPLICATIONS
#echo =================================
#for (( i=0;i<$count;i++ )); do
#echo $i '    '  ${ARRAY[${i}]}
#done
#echo =================================
#echo -n "Enter the number of PA > "
#read pa
#PANAME=${ARRAY[${pa}]}
PANAME='ISMART'
echo "You changed PA $PANAME"

#Searching of an archive file in the current folder
FILENAME=`find . -maxdepth 1 -name "$PANAME*.zip"`
FILENAME=${FILENAME:2}
echo
echo File $FILENAME found. Loading....

# Reading information about Default Snapshot from DB
java -jar defaultSNID.jar $DATA_SOURCE $PANAME > Default.log
unset ARRAY
exec 12<Default.log
let count=0
while read LINE <&12; do
if [ -n "$LINE" ]
    then
 ARRAY[$count]=${LINE}
 ((count++))
fi
done
exec 12>&-

let count=${#ARRAY[0]}
for (( i=1;i<$count;i++ )); do
    if [[ ${ARRAY[0]:${i}:1} = ' ' ]]
    then
 SNNAMEDB=${ARRAY[0]:0:${i}}
 SNID=${ARRAY[0]:${i}+1}
 ((count++))
    fi
done

echo
echo "Default snapshot Name: "$SNNAMEDB
echo "Default snapshot ID  : "$SNID

rm Default.log
echo '<?xml version="1.0" encoding="UTF-8"?>' > migrationInstructions.xml
echo '<p:migrationInstructions xmlns:p="
http://lombardisoftware.com/schema/teamworks/7.0.0/migrationInstructions.xsd">' >> migrationInstructions.xml
echo '   <instruction snapshotId="2064.'$SNID'" action="migrate"/>' >> migrationInstructions.xml
echo '</p:migrationInstructions>' >> migrationInstructions.xml

echo
echo The file migrationInstruction.xml has been created
mkdir temp
unzip -o $FILENAME -d temp/
mv migrationInstructions.xml temp/META-INF
cd temp/
echo
zip -r -f ../$FILENAME .
echo
cd ..
rm -R temp/
echo
echo The file migrationInstruction.xml has been added into $FILENAME

cp $FILENAME $EXP_FOLDER
echo
echo Starting installation $FILENAME on Process Server

#-------------------------------------------------------------
# Installation the snapshot on Process Server using wasadmin
$DM_HOME/bin/wsadmin.sh -lang jython -conntype SOAP -port $PORT -host $HOSTNAME -user $USER -password $PASSWORD -c "print AdminTask.BPMInstallOfflinePackage('[-inputFile $EXP_FOLDER/$FILENAME]')" > BPMInstallOfflinePackage.log

# Verifing the result of BPMInstallOfflinePackage
unset ARRAY
exec 14<BPMInstallOfflinePackage.log
let count=0
bpmc="BPMInstallOfflinePackage not passed. See logs"
while read LINE <&14; do
if [ -n "$LINE" ]
then
     if [[ ${LINE:0:32} = 'BPMInstallOfflinePackage passed.' ]]
     then
  bpmc="BPMInstallOfflinePackage passed successfully"
     fi
 ARRAY[$count]=${LINE}
 ((count++))
fi
done
exec 14>&-

echo
echo RESULT OF BPMInstallOfflinePackage
echo ==================================
echo $bpmc
echo
if [[ ${bpmc:0:45} = 'BPMInstallOfflinePackage not passed. See logs' ]]
then
 for (( i=0;i<$count;i++ )); do
 echo ${ARRAY[${i}]}
 done
else

echo
echo Stopping old snapshot $SNNAMEDB on Process Server

#-------------------------------------------------------------
# Stopping the snapshot on Process Server using wasadmin
$DM_HOME/bin/wsadmin.sh -lang jython -conntype SOAP -port $PORT -host $HOSTNAME -user $USER -password $PASSWORD -c "print AdminTask.BPMStop('[-containerAcronym $PANAME -containerSnapshotAcronym $SNNAMEDB]')" > BPMStop.log

# Verifing the result of BPMStop
unset ARRAY
exec 15<BPMStop.log
let count=0
bpmc="BPMStop not passed. See logs"
while read LINE <&15; do
if [ -n "$LINE" ]
then
     if [[ ${LINE:0:15} = 'BPMStop passed.' ]]
     then
  bpmc="BPMStop passed successfully"
     fi
 ARRAY[$count]=${LINE}
 ((count++))
fi
done
exec 15>&-

echo
echo RESULT OF BPMStop
echo ==================================
echo $bpmc
echo
if [[ ${bpmc:0:28} = 'BPMStop not passed. See logs' ]]
then
 for (( i=0;i<$count;i++ )); do
 echo ${ARRAY[${i}]}
 done
fi

echo
echo Undeploying old snapshot $SNNAMEDB on Process Server

#-------------------------------------------------------------
# Undeploying the snapshot on Process Server using wasadmin
$DM_HOME/bin/wsadmin.sh -lang jython -conntype SOAP -port $PORT -host $HOSTNAME -user $USER -password $PASSWORD -c "print AdminTask.BPMUndeploy('[-containerAcronym $PANAME -containerSnapshotAcronym $SNNAMEDB]')" > BPMUndeploy.log

# Verifing the result of BPMUndeploy
unset ARRAY
exec 16<BPMUndeploy.log
let count=0
bpmc="BPMUndeploy not passed. See logs"
while read LINE <&16; do
if [ -n "$LINE" ]
then
     if [[ ${LINE:0:19} = 'BPMUndeploy passed.' ]]
     then
  bpmc="BPMUndeploy passed successfully"
     fi
 ARRAY[$count]=${LINE}
 ((count++))
fi
done
exec 16>&-

echo
echo RESULT OF BPMUndeploy
echo ==================================
echo $bpmc
echo
if [[ ${bpmc:0:32} = 'BPMUndeploy not passed. See logs' ]]
then
 for (( i=0;i<$count;i++ )); do
 echo ${ARRAY[${i}]}
 done
fi

# Delete snapshot on Process Server using wasadmin
$DM_HOME/bin/wsadmin.sh -lang jython -conntype SOAP -port $PORT -host $HOSTNAME -user $USER -password $PASSWORD -c "AdminTask.BPMDeleteSnapshot  ('[-containerAcronym $PANAME -containerSnapshotAcronyms $SNNAMEDB]')" > BPMDeleteSnapshot.log

# Verifing the result of BPMDeleteSnapshot
unset ARRAY
exec 13<BPMDeleteSnapshot.log
let count=0
bpmc="BPMDeleteSnapshot not passed. See logs"
while read LINE <&13; do
if [ -n "$LINE" ]
then
     if [[ ${LINE:1:25} = 'BPMDeleteSnapshot passed.' ]]
     then
  bpmc="BPMDeleteSnapshot passed successfully"
     fi
 ARRAY[$count]=${LINE}
 ((count++))
fi
done
exec 13>&-

echo
echo RESULT OF BPMDeleteSnapshot
echo ==================================
echo $bpmc
echo
if [[ ${bpmc:0:45} = 'BPMDeleteSnapshot not passed. See logs' ]]
then
 for (( i=0;i<$count;i++ )); do
 echo ${ARRAY[${i}]}
 done
fi

fi
echo
echo -n "Press Enter for exit > "
read

# Deleting of temporary files
rm BPMInstallOfflinePackage.log
rm PAPP.log
rm BPMStop.log
rm BPMUndeploy.log
rm BPMDeleteSnapshot.log
cp $FILENAME $ARH_FOLDER
cd $EXP_FOLDER
rm $FILENAME
cd ..


It is only example. This is a way for your creation. 

No comments:

Post a Comment