Jobs

This page describes user-defined scheduled tasks in OIM. OIM administrator runs this job from WEB GUI, the "Job Details" page.

Create code

OIM Jobs are implemented as special Java classes. These classes should:

  1. extend the oracle.iam.scheduler.vo.TaskSupport class;
  2. implement the method public void execute(HashMap attrs);

The execute() method may accept some application-specific parameters in the HashMap attrs method argument.

Lets, suppose we want our job to accept three parameters: height, weight and color. The job will just print the values of this parameters. We assume the first two parameters are required, and the third is optional.

Lets call this class some.package.MyTask. The code of the class may look like this:

package some.package;
 
import oracle.iam.scheduler.vo.TaskSupport;
 
public class MyTask extends TaskSupport {
  @Override public void execute(HashMap attrs) throws Exception {
    String height = attrs.get("height");
    String width = attrs.get("width");
    String color = attrs.get("color");
    System.out.printl("Height: " + height
      + " width: " + width
      + " color: " + (color == null ? "<undefined>" : color));
  }
}

Deploy code

Now deploy this class to OIM server.

In our simplistic example we defined only one job class, and no other Java classes and/or resources are required to run the job. In reality you will probably need to create more job classes with a number of auxiliary Java classes and resource files.

The most simple deployment method is to package all classes and resources into some jar file, then put this jar to this magic place in $OIM_ORACLE_HOME. OIM detects changes in this directory and loads data automatically.

cp mytasks.jar $OIM_ORACLE_HOME/server/JavaTasks

Define Job type

Now we describe our Job to OIM.

We need to define the following data:

  1. job name - any unique name for the type, for example, MyTask
  2. java class - the full name of the Java class we defined at the previous step
  3. retry count - the maximum number of times OIM will retry failed scheduled job
  4. description - any arbitrary description text
  5. parameters - the job instance parameter definitions

The data needs to be sent to OIM as XML text.

For our example job the Job definition XML may look like in the example below. Remember, we define the height and weight parameters as required, and the color parameter as optional.

<?xml version='1.0' encoding='UTF-8'?>
<scheduledTasks xmlns="http://xmlns.oracle.com">
  <task xmlns="">
    <name>MyTask</name>
    <class>some.package.MyTask</class>
    <retry>5</retry>
    <parameters>
      <string-param required="true" encrypted="false">height</string-param>
      <string-param required="true" encrypted="false">weight</string-param>
      <string-param required="false" encrypted="false">color</string-param>
    </parameters>
  </task>
</scheduledTasks>

Register Job type in OIM

The Job definition we just created must be stored in some place in MDS. We can choose any path as MDS document location, for example, /db/MyTask.xml.

There are basically two methods of doing that:

  1. using MDS import
  2. using OIM import

With MDS import

For example, assuming we put our definition to some.xml:

oimtool --host <hostname> --md-import some.xml /db/MyTask.xml

See MDS page for more detail.

With OIM import

Before using OIM importing to register a Job type, we need to slightly modify our XML file:

<?xml version="1.0" encoding="UTF-8"?>
<xl-ddm-data version="2.0.1.0">
  <scheduledTask repo-type="MDS" name="MyTask" mds-path="/db" mds-file="MyTask.xml">
    <completeXml>
      <scheduledTasks xmlns="http://xmlns.oracle.com/oim/scheduler">
        <task>
          <name>MyTask</name>
          <class>some.package.MyTask</class>
          <retry>5</retry>
          <parameters>
            <string-param required="true" encrypted="false">height</string-param>
            <string-param required="true" encrypted="false">weight</string-param>
            <string-param required="false" encrypted="false">color</string-param>
          </parameters>
        </task>
      </scheduledTasks>
    </completeXml>
  </scheduledTask>
</xl-ddm-data>

For example, assuming we put this definition to some.xml:

oimtool --host <hostname> --import some.xml /db/MyTask.xml

Create instances

For example, the code below creates a Job instance named "MyJobInstance" with parameters height="100", weight="200", and color="blue"

oracle.iam.scheduler.vo.ScheduledTask task = new oracle.iam.scheduler.vo.ScheduledTask();
task.setClassName(some.package.MyTask.getName());
task.setName("MyTask");
task.setRetryCount(5);
 
HashMap<String, JobParameter> attributes = new HashMap<String, JobParameter>();
JobParameter jp = new JobParameter();
jp.setName("height");
jp.setDataType("String");
jp.setRequired(true);
jp.setValue("100");
attributes.put("height", jp);
 
jp = new JobParameter();
jp.setName("width");
jp.setDataType("String");
jp.setRequired(true);
jp.setValue("200");
attributes.put("width", jp);
 
jp = new JobParameter();
jp.setName("color");
jp.setDataType("String");
jp.setRequired(false);
jp.setValue("blue");
attributes.put(name, jp);
 
JobDetails job = new JobDetails(task, "MyJobInstance", attributes);
SchedulerService service = oimClient.getService(SchedulerService.class);
service.addJob(job);

Delete instances

SchedulerService service = oimClient.getService(SchedulerService.class);
JobDetails job = service.getJobDetail("MyJobInstance");
service.deleteJob(job);

Query instances

Get list of all jobs

SchedulerService service = oimClient.getService(SchedulerService.class);
String[] allJobNames = service.getAllJobs();

Select job names matching a pattern.

SchedulerService service = oimClient.getService(SchedulerService.class);
String[] allJobNames = service.getAllJobs();

Running

SchedulerService service = oimClient.getService(SchedulerService.class);
String name =  "Evaluate User Policies";
service.deleteTrigger(name);
service.resumeJob(name);
service.triggerNow(name);
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License