Friday, July 11, 2008

Monitoring OIM Apps / Listeners - Automatic Startups

The code here checks the Peoplesoft listener in OC4J environment that keep crashing unexpectedly in OIM 903 for some reason. The XML messages sent from PeopleSoft gets queued and won't reach OIM. The listener servlet throws the HTTP 500 Internal Server error. So, to restart the listener automatically, we can use the following code. You can set this code to execute at specific intervals to recheck and recycle the app, if in case it is down.

==========================================
PSFTListenerUtility.java
==========================================
import java.io.*;
import java.net.*;
import java.util.HashMap;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.thortech.xl.scheduler.tasks.SchedulerBaseTask;

public class PSFTListenerUtility extends SchedulerBaseTask {

private boolean stop;

public PSFTListenerUtility() {
super("PSFTListenerUtility");
stop = false;
}

@Override
public void execute() {

HashMap myMap = new HashMap();
myMap.put("http://idmdev.bhatiacorp.com:7777/peopleSoftUsrHRM/do/peopleSoftAction", "peopleSoftUsrHRM");
myMap.put("http://idmdev.bhatiacorp.com:7777/peopleSoftUsrCRM/do/peopleSoftAction", "peopleSoftUsrCRM");
myMap.put("http://idmdev.bhatiacorp.com:7777/peopleSoftUsrPRT/do/peopleSoftAction", "peopleSoftUsrPRT");


Iterator iterator = myMap.keySet().iterator();
while (iterator.hasNext()) {
Object key = iterator.next();
String temp = key.toString();
try {
URL url = new URL(temp);
boolean isAlive = getURLOutput(url);
if (!isAlive) {
try {
//restart
String applicationName = (String) myMap.get(key);
logger.debug(" --- REBOOTING PEOPLESOFT LISTENER --- ");
logger.debug(" --- LISTENER NAME: " + applicationName +" --- ");
Runtime.getRuntime().exec("/opt/oracle/product/t01idm_app/opmn/bin/opmnctl startproc application="+applicationName);
} catch (IOException ex) {
Logger.getLogger(PSFTListenerUtility.class.getName()).log(Level.SEVERE, null, ex);
}
}
// Object val = myMap.get(URL);
} catch (MalformedURLException ex) {
Logger.getLogger(PSFTListenerUtility.class.getName()).log(Level.SEVERE, null, ex);
}
}
}

public boolean getURLOutput(URL url) {
BufferedReader in = null;
String inputLine;
boolean isAlive = true;
try {
in = new BufferedReader(new InputStreamReader(url.openStream()));
//for 500 Internal Server error, an exception will be caught.
in.close();
} catch (IOException ex) {
isAlive = false;
logger.debug("PEOPLESOFT LISTENER NOT RUNNING!");
Logger.getLogger(PSFTListenerUtility.class.getName()).log(Level.SEVERE, null, ex);

}

return isAlive;
}

@Override
public boolean stop() {
logger.debug("Entering PSFTListenerUtility.stop()");
logger.warn(" ---- Stopping current task ---- ");
stop = true;
logger.debug("Exiting PSFTListenerUtility.stop()");
return stop;
}
}


courtesy:Askar Zaidi

Monday, July 7, 2008

Executing VBScripts within OIM

Some remote systems are not available to be connected directly within OIM (maybe legacy systems, proprietary systems etc.) For such cases, you may be able to execute scripts on the native systems. These scripts come handy to create, say for example, a home directory in a remote system. So, here is the code you may use to create a connector and execute the script. Modify as needed.

============================================
ADCreateHomeDir.java
============================================

public class ADCreateHomeDir {

public String callScript(String script, String username) {
int exitVal = -1;
try {
Runtime rt = Runtime.getRuntime();
String execute = "cscript " + script + " " + username;
Process proc = rt.exec(execute);
InputStream stderr = proc.getErrorStream();
InputStream stdin = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(stderr);
InputStreamReader isr2 = new InputStreamReader(stdin);
BufferedReader br = new BufferedReader(isr);
BufferedReader br2 = new BufferedReader(isr2);
String line = null;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
while ((line = br2.readLine()) != null) {
System.out.println(line);
}
exitVal = proc.waitFor();
System.out.println("Process exitValue: " + exitVal);
} catch (Throwable t) {
t.printStackTrace();
}
return String.valueOf(exitVal);
}
}

If you need help to develop a VBScript, you may use any commerically available tool such as http://www.wintask.com . This even allows to create a script to send keystrokes and mouse events to a gui app. You may use this or any VBScript to be called by remote manager with a simple java connector and pass parameters.



courtesy:Mark Earnest

Thursday, July 3, 2008

OIM Startup Script for JBOSS

Here is a shell script that you can use to bring up OIM quickly from your home folder.

Usage: jboss {start|stop|restart|help}

=====================================
jboss.sh
=====================================
#!/bin/sh

JBOSS_HOME=/opt/jboss
JAVA_HOME=/opt/j2sdk1.4.2_17
JBOSS_USER=oimuser
XL_HOME=/opt/oracle/xellerate
RUN_AS="su -l $JBOSS_USER -c"
XL_OPTS="-DXL.HomeDir=/opt/oracle/xellerate -Djava.awt.headless=true -Djboss.partition.name=$partition_name$"
XL_CMD_START="$JBOSS_HOME/bin/run.sh $XL_OPTS"
XL_CMD_STOP="$JBOSS_HOME/bin/shutdown.sh -S"
JBOSS_CONSOLE=$JBOSS_HOME/server/default/log/console.log

#
# Check if Jboss home directory exists
#
if [ ! -d "$JBOSS_HOME" ]; then
echo JBOSS_HOME does not exist as a valid directory : $JBOSS_HOME
exit 1
fi

#
# Check if XL home directory exists
#
if [ ! -d "$XL_HOME" ]; then
echo XL_HOME does not exist as a valid directory : $XL_HOME
exit 1
fi

if [ -n "$JBOSS_CONSOLE" -a ! -d "$JBOSS_CONSOLE" ]; then
# ensure the file exists
touch $JBOSS_CONSOLE
if [ ! -z "$SUBIT" ]; then
chown $JBOSS_USER $JBOSS_CONSOLE
fi
fi

if [ -n "$JBOSS_CONSOLE" -a ! -f "$JBOSS_CONSOLE" ]; then
echo "WARNING: location for saving console log invalid: $JBOSS_CONSOLE"
echo "WARNING: ignoring it and using /dev/null"
JBOSS_CONSOLE="/dev/null"
fi

start(){
echo "Starting jboss.."

echo XL_CMD_START = $XL_CMD_START
if [ -z "$RUN_AS" ]; then
eval "$XL_CMD_START > ${JBOSS_CONSOLE} 2>&1 &"
else
$RUN_AS "$XL_CMD_START > ${JBOSS_CONSOLE} 2>&1 &"
fi

}

stop(){
echo "Stopping jboss.."

echo XL_CMD_STOP = $XL_CMD_STOP
if [ -z "$RUN_AS" ]; then
eval "$XL_CMD_STOP > ${JBOSS_CONSOLE} 2>&1 &"
else
$RUN_AS "$XL_CMD_STOP > ${JBOSS_CONSOLE} 2>&1 &"
fi

}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: jboss {start|stop|restart|help}"
exit 1
esac

exit 0


courtesy:Rajesh Mittal