Sunday, November 17, 2013

Disabling a Schedule Task

Version: Oracle Identity Manager 11g R1
There are several ways to disable a schedule task from running. Here are several ways to do so:
  1. OIM API
  2. Manually disable through the OIM console
  3. Modify the schedule task metadata
  4. Disable the scheduler from running
1. Disable a schedule task through the use of OIM API.
All the out of the box schedule tasks have key of -1.
Since the method to update a schedule task takes in a key, passing -1
will update all the out of the box schedule task.
import Thor.API.Exceptions.tcAPIException;
import Thor.API.Exceptions.tcAttributeMissingException;
import Thor.API.Exceptions.tcColumnNotFoundException;
import Thor.API.Exceptions.tcInvalidAttributeException;
import Thor.API.Exceptions.tcScheduledTaskNotFoundException;
import Thor.API.Operations.tcSchedulerOperationsIntf;
import Thor.API.tcResultSet;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map.Entry;
import javax.security.auth.login.LoginException;
import oracle.iam.platform.OIMClient;

public class OIMDisableScheduleTasks 
{
    public static void main(String[] args) throws LoginException, tcAPIException, tcColumnNotFoundException, tcScheduledTaskNotFoundException, tcInvalidAttributeException, tcAttributeMissingException
    {
        String ctxFactory = "weblogic.jndi.WLInitialContextFactory";
        String oimServerURL = "t3://localhost:14000";
        String authwlConfigPath = "/home/oracle/Oracle/Middleware/Oracle_IDM1/designconsole/config/authwl.conf";
        String username = "xelsysadm"; //OIM Administrator 
        String password = "Password1"; //Administrator Password

        System.setProperty("java.security.auth.login.config", authwlConfigPath);
        Hashtable<String,String> env = new Hashtable<String,String>();
        env.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL, ctxFactory);
        env.put(OIMClient.JAVA_NAMING_PROVIDER_URL, oimServerURL);
        OIMClient oimClient = new OIMClient(env);
        oimClient.login(username, password.toCharArray()); //login to OIM

        //Accessing Oracle Identity Manager Services
        tcSchedulerOperationsIntf schedulerOps = oimClient.getService(tcSchedulerOperationsIntf.class);
        HashMap searchCriteria = new HashMap();
        searchCriteria.put("Task Scheduler.Key", "*");
        tcResultSet scheduleTasksTcResultSet = schedulerOps.findScheduleTasks(searchCriteria);
        printTcResultSetRecords(scheduleTasksTcResultSet);
        
        //Disable tasks
        HashMap updateTaskParam = new HashMap();
        updateTaskParam.put("Task Scheduler.Disable", "0");
        String[] columnNames = scheduleTasksTcResultSet.getColumnNames();
        int numRows = scheduleTasksTcResultSet.getTotalRowCount();
        HashMap scheduleTaskKeys = new HashMap();
        
        for(int i =0; i < numRows; i++)
        {
            scheduleTasksTcResultSet.goToRow(i);
            Long taskScheduleKey = Long.valueOf(scheduleTasksTcResultSet.getStringValue("Task Scheduler.Key"));
            String taskScheduleName = scheduleTasksTcResultSet.getStringValue("Task Scheduler.Name");
            int isDisabled =  Integer.valueOf(scheduleTasksTcResultSet.getStringValue("Task Scheduler.Disable"));
            System.out.println(String.format("Disabling Schedule Task: {Key, Name, PreviousStatus} = {%s, %s, %s}", taskScheduleKey, taskScheduleName, isDisabled));
            scheduleTaskKeys.put(taskScheduleKey,taskScheduleKey);
        }

        System.out.println(scheduleTaskKeys);
        Iterator it = scheduleTaskKeys.entrySet().iterator();
        while(it.hasNext())
        {
            Entry entry = (Entry) it.next();
            Long taskScheduleKey = (Long) entry.getValue();
            schedulerOps.updateScheduleTask(taskScheduleKey, updateTaskParam);
        }        
        oimClient.logout();
    }
    
    public static void printTcResultSetRecords(tcResultSet tcResultSetObj) throws tcAPIException, tcColumnNotFoundException
    {
        String[] columnNames = tcResultSetObj.getColumnNames();
        int numRows = tcResultSetObj.getTotalRowCount();
        
        for(int i =0; i < numRows; i++)
        {
            tcResultSetObj.goToRow(i);
            for(String columnName: columnNames)
            {
                System.out.println(columnName + " = " + tcResultSetObj.getStringValue(columnName));
            }
            System.out.println();
        }
    }

}

2. Disable schedule tasks by modifying the metadata of each schedule task.
Use OIM deployment manager to get the metadata. Then modify the xml metadata and import them back.
<taskStatus>false</taskStatus>        <!--Disabled-->
<taskStatus>true</taskStatus>         <!--Enabled-->

3. Disable schedule tasks through the OIM Console.

4. The scheduler is responsible for running schedule jobs. By disabling the scheduler, you prevent any jobs from running.

To disable the scheduler, access this page:
http://OIM_HOST:OIM_PORT/SchedulerService-web/status

2 comments:

  1. This is really too useful and has more ideas from your blog. Keep sharing more blog like this, thank you. We are waiting for your new blog and for useful information. ERPTREE.Com

    ReplyDelete
  2. Oracle Stack: Disabling A Schedule Task >>>>> Download Now

    >>>>> Download Full

    Oracle Stack: Disabling A Schedule Task >>>>> Download LINK

    >>>>> Download Now

    Oracle Stack: Disabling A Schedule Task >>>>> Download Full

    >>>>> Download LINK pl

    ReplyDelete