Friday, October 10, 2008

Running Task Scheduler from DOS

Sometimes Scheduler does not run the tasks properly (older versions of OIM). So, here is a way to run the task scheduler from dos prompt:


===========================
Running
===========================
This tool runs on the Xellerate Server. The Xellerate Server directory, for example C:\oracle\xellerate, is denoted by ${xl.home} below.
First create a directory "RunSchedulerTask" and then copy these files (source code below)

"RunSchedulerTask.java"
"build.xml"
To run, simply open a command-line prompt, change directory to RunSchedulerTask, and run ant:
${xl.home}\ant\bin\ant.bat run -Dxl.home="${xl.home}" -Dargs="<classname> <username> <password> <task-file.properties>"


Where
classname is the full classname of the scheduler task to run
username is the Xellerate login (eg xelsysadm)
password is the login password (eg xelsysadm)
task-file.properties is the properties file containing the Scheduler Task attributes
Example
To run the AD Group Lookup reconciliation:
Create a Task attributes file "ADGroupLookupRecon.properties" and add the following lines:
Server=MyActiveDirectoryServerItResourceInstance

LookupCodeName=Lookup.ADReconliation.GroupLookup

==================================
Run Ant
==================================
${xl.home}\ant\bin\ant.bat run -Dxl.home="${xl.home}" -Dargs="com.thortech.xl.schedule.tasks.ADGroupLookupReconTask xelsysadm xelsysadm ADGroupLookupRecon.properties"



===========================
RunSchedulerTask.java
===========================

import Thor.API.Security.LoginHandler.LoginSession;
import Thor.API.Security.XLClientSecurityAssociation;
import Thor.API.tcUtilityFactory;
import com.thortech.util.logging.Logger;
import com.thortech.xl.client.dataobj.tcDataBaseClient;
import com.thortech.xl.scheduler.tasks.SchedulerBaseTask;
import com.thortech.xl.util.config.ConfigurationClient;
import java.io.*;
import java.util.Properties;

/*
* RunSchedulerTask.java
*
* Runs an Xellerate Scheduler task from the command-line.
*
*/
public class RunSchedulerTask
{
public static void help()
{
System.out.println("");
System.out.println("Runs an Xellerate Scheduler task " +
"from the command-line.");
System.out.println("");
System.out.println("Usage:");
System.out.println("RunSchedulerTask " +
"[classname] [username] [password] [task-attributes.properties]");
System.out.println(" classname : Full classname of " +
"the scheduler task class");
System.out.println(" username : Xellerate login name");
System.out.println(" password : Xellerate login password");
System.out.println(" task-attributes.properties: " +
"properties file path, contains key-value pairs of task attributes.");
}

/*
* arg[0] : recon class name. Class must derived from SchedulerBaseTask
* arg[1] : username (eg xelsysadm)
* arg[2] : password (eg xelsysadm)
* arg[3] : task attributes file (file contains key=value on each line)
*/
public static void main(String args[])
{
if (args.length < 3)
{
help();
return;
}

try
{
// Create a new instance of the scheduler task
SchedulerBaseTask task = (SchedulerBaseTask) Class.forName(
args[0]).newInstance();

// Login to Xellerate
Properties jndi = ConfigurationClient.getComplexSettingByPath(
"Discovery.CoreServer").getAllSettings();
tcUtilityFactory tcutilityfactory = new tcUtilityFactory(
jndi, args[1], args[2]);

task.setUtilityFactory(tcutilityfactory);

// Load the task scheduler attributes file
Properties attributes = new Properties();
if (args.length > 3)
{
attributes.load( new FileInputStream( new File(args[3]) ));
task.setTaskAttributeMap(attributes);
}

// Get a database handle
LoginSession loginsession = tcutilityfactory.getLoginSession();
XLClientSecurityAssociation.setGlobalLoginSession(loginsession);

tcDataBaseClient clientDB = new tcDataBaseClient();
String s = clientDB.getDatabaseName();

task.setDataBase(clientDB);

// Run
task.runAsThread();

// Print Success/Failure
boolean success = task.isSuccess();
if (!success)
{
System.out.println("TASK FAILED");

String message = task.getStatus();
System.out.println("Status: " + message);

Exception ex = task.getResult();
if (ex != null)
{
System.out.println("Exception: " + ex.getMessage());
}
}
}
catch (Exception ex)
{
ex.printStackTrace();
}

// Not sure why we need to manually exit, but without this java just hangs
System.exit(0);
}
}

==================================
Build.xml
==================================
<!--
xl.home property must be set to the xellerate home directory, example:
ant -Dxl.home="C:\xellerate9\xellerate" compile
-->
<project name="IDM" default="compile" basedir=".">
<property name="xl.home" value="C:\xellerate9\xellerate"/>

<path id="classpath.server.xellerate">
<pathelement location="${xl.home}/lib/xlAdapterUtilities.jar"/>
<pathelement location="${xl.home}/lib/xlAPI.jar"/>
<pathelement location="${xl.home}/lib/xlAuthentication.jar"/>
<pathelement location="${xl.home}/lib/xlCrypto.jar"/>
<pathelement location="${xl.home}/lib/xlDataObjects.jar"/>
<pathelement location="${xl.home}/lib/xlDataObjectBeans.jar"/>
<pathelement location="${xl.home}/lib/xlScheduler.jar"/>
<pathelement location="${xl.home}/lib/xlLogger.jar"/>
<pathelement location="${xl.home}/lib/xlUtils.jar"/>
<pathelement location="${xl.home}/lib/xlVO.jar"/>
<pathelement location="${xl.home}/ext/log4j-1.2.8.jar"/>
</path>

<path id="classpath.client.xellerate">
<fileset dir="${xl.home}/lib">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${xl.home}/ext">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${xl.home}/ScheduleTask">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${xl.home}/JavaTasks">
<include name="**/*.jar"/>
</fileset>
</path>

<target name="init">
<copy todir="config"><fileset dir="${xl.home}/config"/></copy>
</target>

<target name="compile">
<javac srcdir="." destdir="." debug="on">
<classpath>
<path refid="classpath.server.xellerate"/>
</classpath>
</javac>
</target>

<target name="run" depends="init,compile">
<java classname="RunSchedulerTask" fork="true">
<classpath>
<path location="."/>
<path refid="classpath.client.xellerate"/>
</classpath>

<sysproperty key="java.security.auth.login.config"
value="${xl.home}/config/auth.conf"/>
<sysproperty key="XL.RedirectSysOutErrToFile" value="false"/>
<arg line="${args}" />
</java>
</target>
</project>

source courtesy:http://zerointech.com/xellerate-idm-run-schedulertask.html

No comments: