Sunday, April 14, 2013

Creating the Scheduler in OIM11G



1) Creating the Scheduler Metadata xml

While creating a scheduled task, you have to create a metadata xml file about the task, which holds the information about the scheduled task, like task name, class name, parameter, etc.
<scheduledTasks xmlns="http://xmlns.oracle.com/oim/scheduler">
<task>
<name>ThiagoSampleScheduler</name>
<class>com.oim.ThiagoSampleScheduler</class>
<description>List User Logins</description>
<retry>5</retry>
</task>
</scheduledTasks>




=============================================================================================
2)IMPORT METADATA:

Make sure the file name is the same as the SchedulerName.

Create a folder of storing this xml, say SchedulerMetaData. in that folder create another folder "db". Place the xml file inside this folder.

Now we can import the xml file into the OIM MetaDataStore.

First export thr OIM_ORACLE_HOME
export OIM_ORACLE_HOME=/oracle/Middleware/Oracle_IDM1
Now change directory to $OIM_ORACLE_HOME/server/bin

Make some changes  to the weblogic.properties file.
# Weblogic Server Name on which OIM application is running 
wls_servername=oim_server1
# If you are importing or exporting any out of box event handlers, value is oim. 
# For rest of the out of box metadata, value is OIMMetadata. 
# If you are importing or exporting any custom data, always use application name as OIMMetadata.
application_name=OIMMetadata
# Directory location from which XML file should be imported.
# Lets say I want to import User.xml and it is in the location /scratc/asmaram/temp/oim/file/User.xml, 
# I should give from location value as /scratc/asmaram/temp/oim. Make sure no other files exist 
# in this folder or in its sub folders. Import utility tries to recursively import all the files under the 
# from location folder. This property is only used by weblogicImportMetadata.sh
metadata_from_loc=/oracle/ThiagoLeoncioSchedulerMetaDataplace
# Directory location to which XML file should be exported to
metadata_to_loc=@metadata_to_loc
# For example /file/User.xml to export user entity definition. You can specify multiple xml files as comma separated values.
# This property is only used by weblogicExportMetadata.sh and weblogicDeleteMetadata.sh scripts
metadata_files=@metadata_files

Now run the weblogicImportMetadata.sh

While running provide the weblogic details.
Starting import metadata script .... 
Please enter your username :weblogicuserrelated
Please enter your password :pwdrelated
Please enter your server URL [t3://localhost:7001] :
Connecting to t3://localhost:7001 with userid weblogicuserrelated ...
Successfully connected to Admin Server 'AdminServer' that belongs to domain 'oim_domain'.

NOTE: You can also 'remove' these inputs above, updating weblogicImportMetadata.py with all these details and it will be straight forward.

=============================================================================================
3)Java Class
package com.ThiagoLeoncio.oim;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import oracle.iam.identity.usermgmt.api.UserManager;
import oracle.iam.identity.usermgmt.vo.User;
import oracle.iam.platform.Platform;
import oracle.iam.platform.entitymgr.vo.SearchCriteria;
import oracle.iam.platform.entitymgr.vo.SearchCriteria.Operator;
import oracle.iam.scheduler.vo.TaskSupport;
public class ThiagoSampleScheduler extends TaskSupport {
 @Override
 public void execute(HashMap arg0) throws Exception {
  UserManager usrMgr = Platform.getService(UserManager.class);
  SearchCriteria sc = new SearchCriteria("User Login", "*", Operator.EQUAL);
  Set<String> retAttrs = new HashSet<String>();
  retAttrs.add("User Login");
  List<User> users = usrMgr.search(sc, retAttrs, null);
  for(User user : users){
   System.out.println("THiago Sample search user is:"user.getLogin());
  }
 } 
 @Override
 public HashMap getAttributes() {
  // TODO Auto-generated method stub
  return null;
 }
 @Override
 public void setAttributes() {
  // TODO Auto-generated method stub
 }
}

=============================================================================================
4)DEPLOY STEP:
After writing the code, deploy one jar file related, either from JDEV or using the jar command.
We have to now create this into a plugin

Create a new folder for the plugin, say ThiagoSampleScheduler. Create a folder named lib in it and place the jar file in it.

=============================================================================================
5) Create the Plugin xml file

Now we have to create a plugin.xml file, specifying the plugin class and pluginpoint.

Create a file named plugin.xml, in the SampleScheduler folder which we created earlier.

Add the following contents in the file.
<?xml version="1.0" encoding="UTF-8"?>
<oimplugins xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<plugins pluginpoint="oracle.iam.scheduler.vo.TaskSupport">
<plugin pluginclass= "com.oim.ThiagoSampleScheduler"
version="1.0.1" name="ThiaggoSampleScheduler">
</plugin>
</plugins>
</oimplugins>
Now the folder should have the following structure.

./SampleScheduler/
                   plugin.xml
                   lib/
                        SampleScheduler.jar

Create a zip of this folder.
=============================================================================================


6) Registering the plugin

Now that we have the plugin zip file, we have to register it in OIM.

Change directory to $OIM_SERVER_HOME/server/plugin_utility

In the ant.properties, set the WLS_HOME and the OIM_HOME variable values.
Make sure the wlfullclient.jar is created in the weblogic server lib. Instructions for this can be found in my previous blog.

To register the plugin use the following command.
ant -f pluginregistration.xml register
Make sure ant is added into the PATH already. 

Provide the OIM server details when asked.

    [input] Enter the oim user id: 
xelsysadm
    [input]Enter the oim user password:  
    [input] Enter the server url [t3://<host>:<port>] :
t3://thiagoleoncioserver:14000
    [input] Enter name (complete file name with path) of the plugin file: 
/thiagoleoncio/SampleScheduler.zip
     [echo] 
     [echo] Plugin Registered
BUILD SUCCESSFUL


=============================================================================================
7) Last part:Creating Scheduled Job in OIM console

Login to OIM console.
Go to Advanced tab--> System Management> Scheduler Job -->Click on the new Scheduled Job icon in the left panel.



Then Scheduled Job creation is completed. Check also article: Tips coding Scheduled Job

I hope this helps you,
Thiago Leoncio


Saturday, April 6, 2013

OIM11G: Scheduler Service - coding part


Scheduler Service


   Today III help you guys with some codes(different ways) to work with this opensource code that was added into OIM 10G &11G API to control the scheduler:


1)Running

SchedulerService schschservice = oimClient.getService(SchedulerService.class);
String jobnamestring = "Disable/Delete User After End Date";
schschservice.deleteTrigger(jobnamestring);
schschservice.resumeJob(jobnamestring);
schschservice.triggerNow(jobnamestring);


2)Reeschedule Job

triggersOfJob = schservice.getTriggersOfJob(jobjobnamestringInString);
trigger = new Trigger(jobnamestring,jobStartTime, repeatInterval, repeatCount,jobEndTime);
trigger.setLastModifyDate(lastTriggerModifyDate);
Jobdetails.setLastModifyDate(new Date(System.currentTimeMillis()));
schservice.updateJob(jobnamestring);
schservice.scheduleJob(jobnamestring, trigger);


3)Delete instances

SchedulerService schschservice = oimClient.getService(SchedulerService.class);
JobDetails job = schschservice.getJobDetail(jobnamestring);
schschservice.deleteJob(jobnamestring);


4)Get list of job triggers involved:

Trigger triggers[] = service.getTriggersOfJob(jobnameInString);
for(Trigger triggerX : triggers ) {
   System.out.println("The Name of the trigger is:  " + triggerX.getName() );
}

5)Query instances
Collect a list of:

SchedulerService schschservice = oimClient.getService(SchedulerService.class);
String[] todososJobs = schschservice.getAllJobs();


6)If you want to match them:

SchedulerService schschservice = oimClient.getService(SchedulerService.class);
String[] todososjobs = schschservice.getAllJobs();


7)Important Note:
resetRunningJobStatus(),schservice.stop(); and schservice.start(); are void methods not to stop your current job, but the entire scheduler service that you can manually control by this URL http://thiagoleoncioserver:14001/SchedulerService-web/status

So, before coding be aware of this!

**Next article I pretend to explain you guys how to register , import and create your own scheduledJob.**


Reference:
R1.0)http://docs.oracle.com/cd/E28389_01/apirefs.1111/e17334/oracle/iam/scheduler/api/SchedulerService.html

R2.0)Expression can be set based on Quartz: http://quartz-scheduler.org/documentation/quartz-1.x/tutorials/crontrigger

R3.0)You can add new configurable child elements. For the information about new child elements, refer to the following URL:
http://www.quartz-scheduler.org/

I hope all of this really helps you,
Thiago Leoncio.