Project

General

Profile

Batch Processes

Introduction

4GL programs can be executed in batch mode. This is a non-interactive ChUI session where SESSION:BATCH-MODE is true. In FWD, batch mode sessions are fully supported.

There are 3 mechanisms to launch batch processes:

  • Automatic launching via the Scheduler (which is a replacement for "cron"). The FWD Client will be spawned by the FWD Application Server.
    • At server startup.
    • At one specific time in the future.
    • Periodically, at some specific scheduled interval or times.
  • Manual or scripted invocation of the ServerDriver Java class using the -b<batch_process_account_name> argument. The FWD Client will be spawned by the FWD Application Server in response to the user or some external program.
  • Manual or scripted invocation of the ClientDriver Java class using the client:mode:batch bootstrap configuration value set to true. In this case the FWD Client is explicitly launched by the user or some external program.

Batch processes can be started manually/scripted or automatically. This section describes how each case works. It is a prerequisite for any batch process launching that batch process account has been setup properly.

Automatic Launching from the FWD Server

For automatic startup, in addition to the setup of the batch process account, the batch process must be setup for automatic start, so that it can be launched by the FWD server.

All of these cases are configured and launched via the Scheduler. This has the advantage that the filesystem keystores and bootstrap configuration files are not needed. The downside of this approach is that the directory must be pre-configured for the exact cases needed and there is limited control over the process environment of the launched batch process.

At Server Startup

Automatic start of a batch process at server startup is implemented using now for the mode. This example will start the batch process once, automatically after the FWD server has started:

 <node class="container" name="scheduler">
     <node class="job" name="start_appserver">
       <node-attribute name="type"          value="process"/>
       <node-attribute name="target"        value="batch_process_name"/>
       <node-attribute name="enabled"       value="TRUE"/>
       <node-attribute name="mode"          value="now"/>
     </node>
   </node>

Make sure to replace the batch_process_name with the name of the FWD process account.

Once At a Specific Time

Automatic start of a batch process at server startup is implemented using one_time for the mode. The idea is to start the batch process once, at the specific date/time configured. This example does a one-time launch of the batch process at 00:30 on January 1, 2022:

 <node class="container" name="scheduler">
     <node class="job" name="start_appserver">
       <node-attribute name="type"          value="process"/>
       <node-attribute name="target"        value="batch_process_name"/>
       <node-attribute name="enabled"       value="TRUE"/>
       <node-attribute name="mode"          value="one_time"/>
       <node-attribute name="hour"          value="0"/>
       <node-attribute name="minute"        value="30"/>
       <node-attribute name="year"          value="2022"/>
       <node-attribute name="month"         value="0"/>
       <node-attribute name="day-of-month"  value="1"/>
     </node>
   </node>

Make sure to replace the batch_process_name with the name of the FWD process account.

Periodically, At an Interval or At Specific Times

Automatic start of a batch process at an interval or at specific times is implemented using recurring for the mode. This example will start the batch process every Sunday at 20:00:

 <node class="container" name="scheduler">
     <node class="job" name="start_appserver">
       <node-attribute name="type"          value="process"/>
       <node-attribute name="target"        value="batch_process_name"/>
       <node-attribute name="enabled"       value="TRUE"/>
       <node-attribute name="mode"          value="recurring"/>
       <node-attribute name="hour"          value="20"/>
       <node-attribute name="day-of-week"   value="1"/>
     </node>
   </node>

Make sure to replace the batch_process_name with the name of the FWD process account.

Manual or Scripted Invocation of the ServerDriver

For batch process launching via the ServerDriver, in addition to the setup of the batch process account, the batch process must be setup for automatic start, so that it can be launched by the FWD server.

This has the advantage that the filesystem keystores and bootstrap configuration files are not needed. In addition, no scheduler configuration is needed. The downside of this approach is that the directory must be pre-configured for the exact cases needed and there is limited control over the process environment of the launched batch process.

Once this is available, the batch process can be launched as follows:

java ... com.goldencode.p2j.main.ServerDriver -b batch_process_name server.xml net:connection:secure=true net:server:secure_port=3333 net:server:insecure_port=3433

The ports, configuration and pathing will be specific to the given installation.

If the standard project template is being used (e.g. a project build on the Hotel ChUI or Hotel GUI templates), then the batch process can be started by running the server.sh or server.cmd script with the accept a -b <batch_process_name> argument, to execute the equivalent ServerDriver command.

To see the exact Java command used to to this, run ./server.sh -t -b batch_process_name and it will display the ServerDriver command without executing it.

Manual or Scripted Invocation of the ClientDriver

It is possible to launch the batch process manually using the ClientDriver. This has the advantage of flexibility, since it can be handled using scripts and there is less configuration/hard coding in the server's directory.xml. It also gives more control over the FWD Client's environment.

This extra flexibility comes with the added requirement of some configuration that must exist in the filesystem. In particular, it is required to have the private key and certificate in an external store, plus the server and root CA certificate in a different store. For example:

  • srv-certs.store will hold the root CA certificate and the FWD server certificate
  • batch_process_name.store will hold the certificate and private key for the batch_process_name alias.

This configuration can be kept separately in a deploy/batch/ folder, with sub-folders for each process. This subfolder, like deploy/batch/batch_process_name, will have:

  • the srv-certs.store file (required)
  • the batch_process_name.store file (required)
  • a client.xml file which will hold the configuration for the batch process which will be launched (optional, can be replaced using command line bootstrap configuration overrides)

The structure of the client.xml follows the bootstrap configuration, from the client category.

For example, the structure can be:

<?xml version="1.0"?>
<node type="client">
   <client>
      <mode batch="true" />
      <driver background="true" />
      <cmd-line-option startup-procedure="batch_program_to_start.p"/>
   </client>

   <security>
      <truststore filename="srv-certs.store" />
      <truststore alias="standard" />
      <keystore filename="batch_process_name.store" />
      <keystore processalias="batch_process_name" />
   </security>

   <access>
      <password truststore="[password-truststore]" />
      <password keystore="[password-keystore]" />
      <password keyentry="[password-keyentry]"/>
   </access>
</node>

Where you will need to customize:

  • batch_program_to_start.p, with the converted legacy program to run
  • srv-certs.store, with the name of the trust store holding the root CA and server certificate
  • standard, with the certificate alias for the FWD server
  • batch_process_name.store, with the name of the store holding the certificate and private key for the batch process alias.
  • processalias, with the certificate alias for the batch process account.
  • truststore, with the password for the trust-store (srv-certs.store).
  • keystore, with the password for the process certificate store (batch_process_name.store).
  • keyentry, with the password for the private key inside the keystore (batch_process_name.store).

The command to launch it (from within the same folder where the stores and client.xml exists, this assumes deploy/batch/batch_process_name) might be:

java -XX:+HeapDumpOnOutOfMemoryError -Djava.library.path=../../lib/ -classpath ../../lib/p2j.jar com.goldencode.p2j.main.ClientDriver net:server:host=localhost net:connection:secure=false net:server:secure_port=3333 net:server:insecure_port=3433  ./client.xml

The configuration and paths would be customized to the installation. Except for the creation of the batch process account, no other directory configuration is required to launch the batch process in this manual mode.

If the standard project template is being used (e.g. a project build on the Hotel ChUI or Hotel GUI templates), then the batch process can be started by copying the client.sh or client.cmd script into the deploy/batch/batch_process_name/ directory and executing it as a normal FWD client.


© 2004-2021 Golden Code Development Corporation. ALL RIGHTS RESERVED.