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

No comments: