Controlling Process Servers with RedwoodScript
When you have a lot of repetitive tasks to perform, it is often easier to use script. RedwoodScript allows you to control process servers, and you can edit all process servers, regardless of the total number, with a few lines of code. The following examples illustrate how you can use RedwoodScript to control process servers. Redwood does not warrant that this is the most effective way to solve your problem. For more information on RedwoodScript, see the API documentation.
Example
Starting and Stopping Process Servers
{
// get the process server in the Global partition (needless to specify partition)
ProcessServer pServer = jcsSession.getProcessServerByName("TR2_ProcessServer");
//stop the test process server
pServer.stop();
jcsSession.persist();
//start the production process server
pServer.start();
jcsSession.persist();
}
Adding a Process Server to a Queue
The following example can be used to add a process server into a queue and display all queues the process server is currently serving.
{
// get the queue and the process server in partition Part
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 process server
for (QueueProvider provider : pServer.getQueueProviders())
{
//print the queues
jcsOut.println(provider.getQueue().getName());
}
}
Adding a Definition Type
When you add a definition type to a process server in the user interface, the process server automatically gets the respective service. This is not the case in RedwoodScript, the service has to be added as well. The process server needs to be shutdown for the code to work.
{
//get the process 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 process server
pServer.createProcessServerJobDefinitionType(jdType);
pServer.createProcessServerService(psService);
//add the mandatory process 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();
}
Shutdown All Process Servers
Retrieve the process servers using executeObjectQuery.
{
String query = "select ProcessServer.* from ProcessServer where Name <> 'System'";
for (ProcessServer pServer : jcsSession.executeObjectQuery(ProcessServer.TYPE, query))
{
jcsOut.println("Stopping process server " + pServer.getName() + ", which has the status " + pServer.getStatus() + ".");
pServer.stop();
jcsSession.persist();
}
}
Delete Processes that ran on a Process Server
You want to delete all the processes of a process server because you want to delete the process server, you may proceed as follows:
The following example illustrates how to delete all the processes that ran on process 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 Process Server
When you create a JDBC process server, you must link the process server to a database object which 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();
}
See Also
- Process Server Parameters
- Process Server Services
- Files
- Creating Platform Process Servers
- Privileges Required to use Process Servers
- Creating AS/400 Process Servers
- Creating a Process Server
- Configuring a Process Server
- Process Server Parameters
Redwood Script