Controlling Job Servers with RedwoodScript
RedwoodScript lets you control Job Servers. You can edit all Job Servers, regardless of the total number, with a few lines of code. The following examples illustrate how you can use RedwoodScript to control Job Servers.
Starting and Stopping Job Servers
{
// get the Job Server in the Global Partition (needless to specify Partition)
ProcessServer pServer = jcsSession.getProcessServerByName("TR2_ProcessServer");
//stop the test Job Server
pServer.stop();
jcsSession.persist();
//start the production Job Server
pServer.start();
jcsSession.persist();
}
Adding a Job Server to a Queue
The following example can be used to add a Job Server into a Queue and display all Queues the Job Server is currently serving.
{
// get the queue and the Job Server in Partition RW_DEMO
Partition Partition = jcsSession.getPartitionByName("RW_DEMO");
Queue queue = jcsSession.getQueueByName(partition, "TR50_Queue");
ProcessServer pServer = jcsSession.getProcessServerByName(partition, "TR5_ProcessServer");
//create a queue provider
pServer.createQueueProvider(queue);
//save data in the database
jcsSession.persist();
//go through all queue providers of the Job Server
for (QueueProvider provider : pServer.getQueueProviders())
{
//print the queues
jcsOut.println(provider.getQueue().getName());
}
}
Adding a Definition Type
Assume you need to add a Service to a Job Server with RedwoodScript.
Note: The Job Server must be shut down for this code to work.
{
//get the Job Server, the Definition Type as well as the service
Partition Partition = jcsSession.getPartitionByName("RW_DEMO");
ProcessServer pServer = jcsSession.getProcessServerByName(partition, "TR5_ProcessServer");
JobDefinitionType jdType = jcsSession.getJobDefinitionTypeByName("KSH");
Service psService = jcsSession.getServiceByName("PlatformAgentService");
//add Definition Type and service to Job Server
pServer.createProcessServerJobDefinitionType(jdType);
pServer.createProcessServerService(psService);
//add the mandatory Job Server parameters required by the ''PlatformAgentService'' service.
ProcessServerParameter RemoteHostName = pServer.createProcessServerParameter();
RemoteHostName.setName("RemoteHostName");
RemoteHostName.setValue("192.168.1.3");
ProcessServerParameter SharedSecret = pServer.createProcessServerParameter();
SharedSecret.setName("SharedSecret");
SharedSecret.setValue("SomeBase64");
jcsSession.persist();
}
Shutting Down All Job Servers
This example retrieves the list of Job Servers using executeObjectQuery
.
{
String query = "select ProcessServer.* from ProcessServer where Name <> 'System'";
for (ProcessServer pServer : jcsSession.executeObjectQuery(ProcessServer.TYPE, query))
{
jcsOut.println("Stopping Job Server " + pServer.getName() + ", which has the status " + pServer.getStatus() + ".");
pServer.stop();
jcsSession.persist();
}
}
Deleting Processes that Ran on a Job Server
Assume you want to delete all the Jobs from a Job Server because you want to delete the Job Server. The following example illustrates how to delete all Jobs that ran on Job Server MSLN_WINS3
.
{
String query = "select Job.* from Job where ProcessServer = ?";
for (Job process : jcsSession.executeObjectQuery(Job.TYPE, query, new Object[] {jcsSession.getProcessServerByName("MSLN_WINS3").getUniqueId()}))
{
if(process != null)
{
jcsOut.println("Deleting process " + process.getDescription() +
", which has the status " + process.getStatus() + ".");
process.deleteObject();
}
jcsSession.persist();
}
}
Adding a Database Object Reference to a JDBC Job Server
When you create a JDBC Job Server, you must link the Job Server to a database object that contains the connection settings for the JDBC connection. The following code adds a database reference for database Example.MSLN_DB2
to Example.MSLN_JDBC1
.
{
Partition p = jcsSession.getPartitionByName("Example");
Database db = jcsSession.getDatabaseByName(p, "MSLN_DB2");
ProcessServer ps = jcsSession.getProcessServerByName(p, "MSLN_JDBC1");
ObjectReference objRef = ps.createObjectReference(db);
objRef.setName(Database.OBJECT_REFERENCE_NAME_JDBC_PROCESSSERVER);
jcsSession.persist();
}