Creating Java job jar
Describes how to create the jar used with a Java job.
A Java job can use any jar that is created according to the following rules and procedure.
1. Include HCL Workload Automation jar in build path
The class that implements the Dynamic Workload Console interface is in the following jar:- On the server
<TWA_home>/TWA/TWS/applicationJobPlugIn/com.ibm.scheduling.agent.java_<version>.jar
- On a dynamic agent
<TWA_home>/TWA/TWS/JavaExt/eclipse/plugins/com.ibm.scheduling.agent.java_<version>.jar
where
<version>
is the HCL Workload Automation version related to the latest fix pack applied.
This jar must be included in your Java build path.
2. Create your class which implements TWSExecutable
Create a class which implements a class calledTWSExecutable
,
which has a signature as follows:public abstract interface TWSExecutable
{
public abstract void validateParameters(Parameters paramParameters)
throws Exception;
public abstract void execute(Parameters paramParameters)
throws Exception;
}
Note: This class can be used on agents either at V8.5.1
Fix pack 1 or V8.6.
This class implements two methods:
- validateParameters
- This is the method which is called first when a Java job is executed. It validates the parameters input when the job was defined. If an exception occurs it is written to the job log.
- execute
- This is the method which actually runs the job.
validateParameters
class:- getParameter
- Supplied with the argument of one of the parameters, it returns the actual value.
- getParameterList
- Returns a list of all the parameters defined as name/value pairs.
- getOutputFile
- Returns the path of the output job log. Note: If you want to write to the log you must always remember to close it.
3. Optionally supply information to the person defining the job
The interface includes a button Get Class Information. To implement this button use the classTWSExecutableInformation
,
which has a signature as follows:public abstract interface TWSExecutableInformation
{
public abstract String getInformation();
}
Note: This class can be used only on V8.6.
This
class is implemented when the user clicks the Get Class Information button,
so you can use it to supply help information about the job in the
jar that the user has selected.4. Include any required libraries
If your Java job requires any libraries or other files, copy them to the folder where you have saved the jar. When the person defining the job identifies the jar, the product loads not just the jar, but also everything else in the folder on the agent.The following is an example of the code discussed in this
topic:
package com.test.Trial;
import java.io.BufferedWriter;
import java.io.FileWriter;
import com.ibm.scheduling.agent.java.jobexecutor.TWSExecutable;
import com.ibm.scheduling.agent.java.jobexecutor.TWSExecutableInformation;
import com.ibm.scheduling.agent.java.parametersdomain.Parameters;
public class Trial implements TWSExecutable, TWSExecutableInformation{
/*
* Writes the parameter "parm1" to the log
*/
@Override
public void execute(Parameters arg0) throws Exception {
String parm1 = arg0.getParameter("parm1");
String filename = arg0.getOutputFile();
BufferedWriter out = new BufferedWriter(new FileWriter(filename));
out.write(parm1);
out.close();
}
/*
* Validates the parameter "parm1", throwing the exception to the log
*/
@Override
public void validateParameters(Parameters arg0) throws Exception {
String parm1 = arg0.getParameter("parm1");
if(parm1.equals("XXX"))
throw new Exception("The parameter parm1 is not correct");
}
/*
* Tells the user of the interface who has clicked the Get Class
* Information button what the class does.
*/
@Override
public String getInformation() {
String msg = "This class writes the parm1 parameter in the output log";
return msg;
}
}