Pages

Monday, January 13, 2014

SchedulerService API Example


The SchedulerService interface API being used to retrieve, manipulate the schedule task parameters and also execute the schedule task job pro-grammatically in OIM repository as follows:



Pre-Requisite:

Initial Setup.

Please follow the link and setup the OIM client environment to use to create the OIM Objects.


Client Code Setup

SchedulerService  API Usage:

1. Retrieving the Schedule Task Job Parameters.

2. Update the Schedule Task Parameters.

3. Executing the Schedule Task Pro-grammatically. 

4. Retrieving the Job History.

5. Retrieving the Last Job History.


Tasks Needs to be Performed:

1.    Create the OIMClient Handle


OIMClient client= new OIMClient();
client.login(username,password.toCharArray());

2.    Get SchedulerService service object

SchedulerService schedulerService = client.getService(SchedulerService.class);

3.  Retrieving the Schedule Task Job Parameters. 


String scheduleJobName="AD User Target Recon";
JobDetails jobdetails=schedulerService.getJobDetail(scheduleJobName);
HashMap<String, JobParameter> params= jobdetails.getParams();
           

4.  Updating the Schedule Task Parameter. 


String parameterName="Search Filter";
String parameterValue="(objectclass=inetorgperson)";
//Retrieving the Job Parameter Object
JobParameter jobParam= params.get(parameterName);
//Updating the Job Parameter Value in the Object
jobParam.setValue(parameterValue);
params.put(parameterName, jobParam);

//Udating the Schedule Task Parameters in OIM
schedulerService.updateJob(jobdetails);

5.  Executing the Schedule Task. 

// Invoking the Schedule Task

schedulerService.triggerNow(scheduleJobName);


6.  Retrieving the Schedule Job History

        List<JobHistory> history= schedulerService.getHistoryOfJob(jobName);
        if(history != null && !history.isEmpty())
        {
            for (JobHistory jobHistory : history)
            { // Retrieving the Error Data
                System.out.println("Error Data :"+new String(jobHistory.getErrorData() != null ? jobHistory.getErrorData() : "Success".getBytes()));
                try
                {
                   //Retrieving the Error Message
                    Exception exp=jobHistory.getExceptionObject();
                    if(exp != null)
                    {
                       System.out.println("Exception Message :"+.getMessage());
                    }
                   
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }

7. Retrieving the Schedule Job Last Run History.


        JobHistory  history = schedulerService.getLastHistoryOfJob(jobName);
        if(history != null){
        // Retrieving the Error Data
        System.out.println("Error Data :"+new String(history.getErrorData() != null ? history.getErrorData() : "Success".getBytes()));
        // Exception Message
        System.out.println("Exception Message :"+history.getExceptionObject() != null ? history.getExceptionObject().getMessage() : "Empty");
                   
       }

              

10 comments:

  1. Hi, how can i retrieve the execution status of a scheduled task?
    br,
    max

    ReplyDelete
  2. Hi

    invoke the jobdetails.isTaskStatus() method and it return true or false. If the value return true and its running.

    ReplyDelete
    Replies
    1. hello,
      Thank you for your quick response. Is it possible to retrieve the error message if something goes wrong?

      attached a screenshot: https://dl.dropboxusercontent.com/u/12345677/exec_status.PNG

      br,
      max

      Delete
    2. Hi Max.

      I have added code to retrieve the job history for Error Data and Exception message based on the Scheduler Job Name. Please let me know if you need more info.

      Delete
    3. Hi,
      great, thank you very much!
      br,
      max

      Delete
    4. Hi IDM OIM,

      Can you share the code also to me, as the attached image not working.


      Thank you

      Delete
  3. Good morning, I’m working with the SchedulerService interface and I need to pause and resume a job, I found in this interface pauseJob(java.lang.String jobName) and resumeJob(java.lang.String jobName) methods so I used them but when a job was running the method pause did nothing, I proved the triggerNow and
    stopJob methods and they worked. Do I need to configure something? Or what would be the process to accomplish this goal?

    Thanks in advance.

    ReplyDelete
  4. Hi,

    Did you see any errors after executing the pauseJob in the oim server log. Please post the log and I will look into the log and let you know the details to you.

    ReplyDelete
  5. HI ,
    I am getting "Error(74,47): variable jobdetails might not have been initialized" this error kindly help.

    thanks in advance.

    ReplyDelete