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. SAP does not warrant that this is the most effective way to solve your problem. For more information on RedwoodScript, see the API documentation.
{
// get the process server
ProcessServer prodProcessServer = jcsSession.getProcessServerByName("TR2_ProcessServer");
//stop the test process server
prodProcessServer.stop();
//start the production process server
prodProcessServer.start();
jcsSession.persist();
}
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
Queue queue = jcsSession.getQueueByName("TR50_Queue");
ProcessServer proc = jcsSession.getProcessServerByName("TR5_ProcessServer");
//create a queue provider
proc.createQueueProvider(queue);
//save data in the database
jcsSession.persist();
//go through all queue providers of the process server
for (Iterator it = proc.getQueueProviders(); it.hasNext();)
{
QueueProvider provider = (QueueProvider) it.next();
//print the queues
jcsOut.println(provider.getQueue().getName());
}
}
When you add a job 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 job definition type as well as the service
ProcessServer proc = jcsSession.getProcessServerByName("TR5_ProcessServer");
JobDefinitionType jobDefType = jcsSession.getJobDefinitionTypeByName("KSH");
Service procservice = jcsSession.getServiceByName("PlatformAgentService");
//add job definition type and service to process server
proc.createProcessServerJobDefinitionType(jobDefType);
proc.createProcessServerService(procservice);
//add the mandatory process server parameters required by the ''PlatformAgentService'' service.
ProcessServerParameter RemoteHostName = proc.createProcessServerParameter();
RemoteHostName.setName("RemoteHostName");
RemoteHostName.setValue("192.168.1.3");
ProcessServerParameter SharedSecret = proc.createProcessServerParameter();
SharedSecret.setName("SharedSecret");
SharedSecret.setValue("SomeBase64");
jcsSession.persist();
}
{
String query = "select ProcessServer.* from ProcessServer where Name <> 'System'"
for (Iterator it = jcsSession.executeObjectQuery(query, null); it.hasNext();)
{
ProcessServer proc = (ProcessServer) it.next();
jcsOut.println("Stopping process server "+ proc.getName()+", which has the status "+ proc.getStatus()+".");
proc.stop();
jcsSession.persist();
}
}