Monday, March 30, 2009

Obtain a list of JPDs?

I'm expanding my search for help with a WLST script that will terminate all the aborted processes in WLI 9.2.2 I have an open case with Oracle, but we haven't come up with my "ideal" solution. What I have right now is a Java program that I can pass a JPD to, and it will terminate all the aborted processes for that JPD. This works ok, but I would like to find a way for the program to find all the JPDs in the environment and then parse through them. Ideally, all of this would be done in WLST, but I can live with Java if it gets the job done. Anyone out there have thoughts on how to do this? Unfortunately, I am a middleware guy and not a Java programmer, so I can't do much with this on my own. The code I have right now is included below:

import com.bea.wli.management.runtime.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import java.util.Date;
import java.text.SimpleDateFormat;
import weblogic.management.MBeanHome;
import java.util.*;
import com.bea.wli.bpm.runtime.ProcessStatus;


public class TerminateProcess {


public static void main(String[] args){

    //Parameters to be configured
    //String JPDURI = "/IDXWEB/processes/Process.jpd";
    //String Provider_URL = "t3://localhost:7001";
    //String Security_Principal = "weblogic";
    //String Security_Credentials = "weblogic";



   if (args.length != 5) {
        System.out.println("Usage: ADMIN_URI JDP_URI ADMIN_USERNAME ADMIN_PASSWORD BATCH_COUNT");
        return;
    }
  String adminURL = args[0];
  System.out.println("Admin URL is$$$ "+adminURL);
  String jpdURI = args[1];
  System.out.println("jpdURI is$$$ "+jpdURI);
  String adminUserName = args[2];
  String adminPassword = args[3];
  int exitCount = Integer.parseInt(args[4]);
  boolean blnExitOnCount = false;//Flag to run the terminate process in batch. If true, it will
                                               //only the number of instances in the exitCount parameter.
                                               //If false, it will terminate all the instances of that JPD.

 try {
    String CONTEXT_FACTORY = "weblogic.jndi.WLInitialContextFactory";
    Properties p = new Properties();
    p.put(Context.INITIAL_CONTEXT_FACTORY, CONTEXT_FACTORY );
    p.put(Context.PROVIDER_URL, adminURL );
    p.put(Context.SECURITY_PRINCIPAL,adminUserName);
    p.put(Context.SECURITY_CREDENTIALS,adminPassword);

    Context ctx = new InitialContext(p);

    MBeanHome home = (MBeanHome)ctx.lookup(MBeanHome.ADMIN_JNDI_NAME);

    Set s = home.getMBeansByType("ProcessRuntime");
    Iterator it = s.iterator();

    while (it.hasNext())
    {
            ProcessRuntimeMBean bean = (ProcessRuntimeMBean)it.next();

            //Query for JPD
            ProcessInstanceQuery query = new ProcessInstanceQuery();
            query.setStatus(ProcessStatus.ABORTED);
            query.setServiceURI(jpdURI);
   ProcessInstanceQueryResult info = bean.getProcessInstances(query);
            String[] instances = info.getInstanceIds();
            System.out.println("Instance Ids " + instances.toString());
            System.out.println("Instance Count " + instances.length);

            for(int i=0;i= exitCount-1))
                {
                    System.exit(0);
                }
            }
    }
    } catch (Exception ex) {
        System.out.println(ex);
        ex.printStackTrace();
    }

}

}

2 comments:

wlsAdmin said...

It seems this isn't possible without writing a query to the WLI database to select all the distinct JPDs in the database. I'll post more as I know it.

Adam Ward said...

If you intend to terminate all aborted processes you do not need to know the list of JPDs. Simply remove it from your query:

// query.setServiceURI(jpdURI);

And all aborted will be returned.