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
- Configuring a Process Server
- Process Server Parameters
Redwood Script