api-tool.jar
This tool is used to run scripts and raise events from systems for which there are no command-line system tools. You download it from Configuration > Software, under the API Downloads section. The script files, which must contain RedwoodScript, should be available to the api-tool. Depending on the platform where you run the api-tool on, you might not be able to create the connection files. Use the jsecret command on a supported platform to create the connection file and copy it over to the system where you want to use the api-tool.
Setting the Return Code
The jcsShell.setReturnCode(int)
method is used to set the return code of the script. You throw an exception if you want to terminate processing; the last effective call to jcsShell.setReturnCode()
will set the return code.
Prerequisites
- Java 1.8 or higher JVM
- Unlimited strength Java Cryptography Extension (JCE) if your server uses TLS and/or SSL.
- TLS options can be set using JVM specific system properties.
Syntax
java -jar api-tool.jar <command> [command-specific-arguments]
<command>:
event <connectionFile> <eventName> [raiseComment] - Raise event <eventName> with optional comment [raiseComment]
script <connectionFile> <scriptFile> - Run script in <scriptFile>
import <connectionFile> <file> [-targetpartition <Partition>] [<ImportRuleSet>]
version - Print the version
-noverify Skip server certificate verification
-cipherlist <list> Override the default cipherlist
Development
Simple Program
Usage javac -cp api-tool.jar <class.java>
Example
The file PrintJobDefinitions.java
contains the following:
import com.redwood.scheduler.api.tool.*;
public class PrintJobDefinitions
{
public static void main(String [] args)
throws Exception
{
ToolConnection tConnection = ToolConnectionFactory.createConnection(args[0], 60000);
ToolResultSet rs = tConnection.executeQuery("select JobDefinition.Name, JobDefinition.UniqueId from JobDefinition", null, null);
while (rs.next())
{
System.out.println(rs.getString(1) + " = " + rs.getString(2));
}
}
}
Compile & run it:
$ javac -cp api-tool.jar PrintJobDefinitions.java
$ java -cp api-tool.jar:. PrintJobDefinitions net/connect.rw
Upload CAR & JAR Files
import com.redwood.scheduler.api.tool.ToolConnection;
import com.redwood.scheduler.api.tool.ToolConnectionFactory;
import java.io.File;
import java.util.Collection;
import java.util.Map;
public class Uploader
{
public static void main(String [] args)
throws Exception
{
if (args.length > 1)
{
ToolConnection tConnection = ToolConnectionFactory.createConnection(args[0], 60000);
if (args[1].toLowerCase().endsWith("car"))
{
System.out.println("Uploading CAR file");
String importSet = "";
if(args.length == 3)
{
importSet = args[2];
}
Map mp = tConnection.uploadCAR(new File(args[1]), importSet);
if (mp.size() > 0)
{
Collection cl = mp.values();
System.out.println("JobId: "+cl.iterator().next());
}
}
else if (args[1].toLowerCase().endsWith("jar")&& args.length == 3)
{
System.out.println("Uploading JAR file");
Map mp = tConnection.uploadJAR(new File(args[1]), args[2]);
if (mp.size() > 0)
{
Collection cl = mp.values();
System.out.println("JobId: "+cl.iterator().next());
}
}
else
{
System.out.println("Invalid Arguments.");
System.out.println("Usage: Main <connection_file> <car_file> [<importRuleSet>]");
System.out.println(" Main <connection_file> <jar_file> <library>");
}
}
else
{
System.out.println("Invalid Arguments.");
System.out.println("Usage: Main <connection_file> <car_file> [<importRuleSet>]");
System.out.println(" Main <connection_file> <jar_file> <library>");
}
}
}
Compile & run it:
$ javac -cp api-tool.jar Uploader.java
$ java -cp api-tool.jar:. Uploader
Invalid Arguments.
Usage: Uploader <connection_file> <car_file> [<importRuleSet>]
Uploader <connection_file> <jar_file> <library>
$ java -cp api-tool.jar:. Uploader net/connect.rw /tmp/JobDefinition_RS_MSLN_DB_Backup.car
$ java -cp api-tool.jar:. Uploader net/connect.rw /tmp/myJar.jar Custom_Example
Example
In the following examples, the connection file created with jsecret -c
is stored in net/connect.rw
.
Submit a Process
The script script.rw used in these examples contains the following:
{
// code to submit a process running System_Sleep
// get the process definition (technical name 'job definition')
JobDefinition aDefinition = jcsSession.getJobDefinitionByName("System_Sleep");
// create the process from the process definition
Job process = aDefinition.prepare();
// submit the process definition and write unsaved data to the database
jcsSession.persist();
}
Run a RedwoodScript
Run a script named script.rw:
java -jar /opt/tools/api-tool.jar script net/connect.rw script.rw
Raise an Event
Raise the event ETL_Complete
java -jar /opt/tools/api-tool.jar event net/connect.rw "ETL_Complete" "ETL completed, please proceed with the next step"
Import a CAR File
java -jar apit-tool.jar import net/connect.rw JobDefinition_Test.car