Friday, January 12, 2018

OIM: Create and deploy scheduled task

The following posts covers all aspects of developing and deploying a scheduled task in OIM and creating a scheduled job.

The post will cover the following tasks in detail:
>> How to create a scheduled task ?
>> How to package a scheduled task ?
>> How to deploy a scheduled task ? 
>> How to create a scheduled job ?

How to create a scheduled task
This includes the following items:
> Developing java class and creating jar file
> Creating plugin file
> Creating metadata file


Developing java class and jar files:
1. Create a java project in IDE of your choice
2. Import the following jars in your project class path:
common-logging.jar
eclipselink.jar
jrf-api.jar
oimclient.jar
spring.jar
wlfullclient.jar
3. Create a java class and extend the class oracle.iam.scheduler.vo.TaskSupport
4. You will have to implement the abstract methods of this class: execute, getAttributes and setAttributes
5. Don't worry about getAttributes and setAttributes. Remember, we are learning the basics and trying to get out first scheduled job up and running.
6. Execute method is what is called when the scheduled job is executed.
7. This method has an input argument as a HashMap, this map contains the value provided by you on the schedule job UI (The UI parameters are configured in an xml file, that we will see lator).
8. Implement your custom logic in this method:
      How to get the data from UI
String lookupName = (String) hashMap.get("Lookup Name");
      How to initializa API and write custom logic
       UserManager userManager = Platform.getService(UserManager.class);

       How to add custom logger
 Create LOGGER
 Add in logging.xml

  9. Create the jar file using IDE.

Creating plugin file: Always call it plugin.xml for ease of use
Create an xml file and change the bold parameters only, this file is self-explanatory. 

<?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.rohit.st.demo.SchedulerDemo" version="1.0" name="SchedulerDemo"/>
</plugins>
   </oimplugins>

Creating metadata file: This goes in MDS datastore, so provide a business friendly name
Create an xml file and change the bold parameters only, this file is self-explanatory. 
<scheduledTasks xmlns="http://xmlns.oracle.com/oim/scheduler">
<task>
<name>SchedulerDemo</name>
<class>com.rohit.st.demo.SchedulerDemo</class>
<description>SchedulerDemo</description>
<retry>5</retry>
<parameters>
<string-param required="true" encrypted="false" helpText="Lookup Name">Lookup Name</string-param>
<string-param required="true" encrypted="false" helpText="First Name">First Name</string-param>
<string-param required="true" encrypted="false" helpText="Last Name">Last Name</string-param>
</parameters>
</task>
</scheduledTasks>

How to package a scheduled task
1. Create a directory (let us call is SchedulerDemo directory, call anything)
2. Create the following directories inside the SchedulerDemo directory.
       lib - place your jar file in this directory
       config
       resources
3. Also place plugin.xml directly inside SchedulerDemo directory.
4. Create the zip file.
5. Place the zip file on the OIM server in the environment where you want to deploy it.

How to deploy a scheduled task
Deploying plugin:
6. Next you need to register the plugin(This zip file that you created will be deployed in OIM as a plugin).
7. Set ANT_HOME environment variable.
    export ANT_HOME=/apps/oracle/middleware/modules/org.apache.ant_1.7.1 (env specific)
8. Update PATH environment variable.
     export PATH=$JAVA_HOME/bin:$ANT_HOME/bin:$PATH

9. Navigate to $OIM_HOME/server/plugin_utility
10. Edit/Check ant.properties and set the following values:
    wls.home
    oim.home
    mw.home
11. Execute the following command:
    ant -f pluginregistration.xml register
12. In a new environment, sometimes an error is encountered:
     /pluginregistration.xml:72: Class not found: oracle.iam.platform.utils.ant.PasswordInputHandler
In which case, cross check your ant.properties and if the error persists, navigate to the location $WLS_HOME/server/lib
and run: java -jar wljarbuilder.jar
13. Once this is done, navigate back to $OIM_HOME/server/plugin_utility and execute ant -f pluginregistration.xml register
14. You will need to provide the following values to the script
    User name: xelsysadm
    Password: xelsysadm's password (enc specific)
    URL:  t3://OIM_HOST:OIM_PORT (env specific). like t3://rohitdemo:14000
15. Checkpoint: Once the script run successfully, query the plugins table to see that the plugin was deployed.

Registering Metadata:
Now you need to import the metadata file that you created inside the MDS data store. We will use weblogicImportMetadata utility to do the same.

16. Place the metadata file on the server.
17. Navigate to  $OIM_HOME/server/bin
18. Take a backup of weblogic.properties file
19. Edit weblogic.properties file 
20. Set the value of 'metadata_to_loc'
21. Set OIM_ORACLE_HOME same as OIM_HOME
22. Execute command:
 ./weblogicImportMetadata.sh
Provide the following values:
weblogic (NOT xelsysadm)
weblogic's password
t3://OIM_HOST:OIM_POST (NOT weblogic port but OIM's port)

How to create a scheduled job 
1. Create from sysadmin console
2. Search for task name configured in metadata file