Product Documentation

FairCom Replication Using JSON RPC API

Previous Topic

Next Topic

How to Run the Demo

A demo is included in your product package to give you an idea of how the replication solution operates. This demo is a good starting point to familiarize yourself with the basic concepts of this comprehensive replication solution. The demo is located in the following folder:

drivers\java.rest.replication

This demo is useful to developers who want to experiment with the replication RPC API. You can read the Replication RPC API Developer's Guide to learn more about using this extensive API to control replication in your c-tree environment.

Overview

For testing, you will need to set up three servers:

  1. Replication server (the central point for replication)
  2. c-tree server to be the source for replication
  3. c-tree server to be the the target for replication

To simplify the c-tree replication tutorial, the example configuration in this document places all of these servers on a single computer. Although this is not considered a “real world” configuration, it is useful for learning.

It is recommended that you follow the example configuration shown below when using this demo for the first time. Notice that each server must be installed in a separate folder.

Requirements:

To run this demo with the default configuration you will need the following:

  • 1 Replication server with cthttpd configured to listen on http 8080 port (see section 2)
  • 1 c-tree server with a Replication agent configured with server name FAIRCOMS, as described in the Replication Manager Quick Start.
  • 1 c-tree server with a Replication agent configured with server name FAIRCOM2 and SQL_PORT to 6598
  • ctdb_tutorial4 executable (located in the c.nav or ctree.ctdb directory of the FAIRCOMS node) - You will need to generate this file by running the batch/makefile for that tutorial.
  • Java SDK version 8+

Separate Folders

The first task in using the example is to install and two copies of c-tree on your test computer. Each should be placed in a separate folder.

Configuring Replication Manager

You will not start either of the servers or the Replication Manager until you have edited their configuration files. There are up to three configuration files that need to be edited in the server/config folder of each of the three servers (“source”, “target”, and “Memphis”). Additionally, the demo program itself needs to be configured by editing a few lines of its source code.

1. Configure and Build the Demo

  1. Edit the following file to match your environment:

    drivers\java.rest.replication\ReplFileDemo\src\main\java\replfiledemo\ReplFileDemo.java

    In particular, change the following:

    Change the memphisURL variable to match the location of your Memphis server and the primaryDbeName and secondaryDbeName variables to match your server names.

    Change variables primaryFileDir and secondaryFileDir if the files are not located in the default server directory (LOCAL_DIRECTORY in ctsrvr.cfg).

    If you are using the recommended example configuration, the relevant lines of the Java program should look like this:

    public class ReplFileDemo

    {

    static boolean debug = false;

    static String memphisURL = "http://localhost:8080/ReplicationManager/";

    static String memphisUser = "admin";

    static String memphisPassword = "ADMIN";

    static String primaryDbeName = "FAIRCOMS";

    static String secondaryDbeName = "FAIRCOM2";

    static String dbName = "ctreeSQL";

    static String planName = "ReplPlan1";

    static String primaryFileDir = null; // default to LOCAL_DIRECTORY

    static List<String> primaryFileNames = Arrays.asList("custmast.dat","custordr.dat","itemmast.dat","ordritem.dat");

    static String secondaryFileDir = null; // default to LOCAL_DIRECTORY

  2. After saving your changes, build the project by invoking:

    gradlew build

2. Configure the c-tree and Memphis servers

Configure the Memphis server and the Source and Target c-tree servers. To do this, you need to change various lines in three configuration files (ctagent.json, cthttpd.json, and ctsrvr.cfg) in the server/config folder of each of the three servers (Memphis, source, and target). In other words, you need to look at a few lines in each of nine different files. To simplify this task, here is our example configuration, with each of the nine files listed and the lines that should be validated for each of them:

Memphis:

ctagent.json

accept_conn true

memphis_sql_port 7000

memphis_host 127.0.0.1

cthttpd.json

listening_http_port 8080

listening_https_port 8443

mqtt_listening_port n/a

mqtt_websocket_port n/a

ctsrvr.cfg

SERVER_NAME MEMPHIS

SERVER_PORT 5532

PLUGIN cthttpd (uncomment)

PLUGIN ctagent (uncomment)

SQL_PORT 7000

Source c-tree server:

ctagent.json

accept_conn true

memphis_sql_port 7000

memphis_host 127.0.0.1

cthttpd.json

listening_http_port 8084

listening_https_port 8445

mqtt_listening_port 1884

mqtt_websocket_port 8082

ctsrvr.cfg

SERVER_NAME FAIRCOMS

SERVER_PORT 5598

PLUGIN cthttpd (uncomment)

PLUGIN ctagent (uncomment)

SQL_PORT 6597

Target c-tree server:

ctagent.json

accept_conn true

memphis_sql_port 7000

memphis_host 127.0.0.1

cthttpd.json

listening_http_port 8083

listening_https_port 8444

mqtt_listening_port 1883

mqtt_websocket_port 8081

ctsrvr.cfg

SERVER_NAME FAIRCOM2

SERVER_PORT 5597

PLUGIN cthttpd (uncomment)

PLUGIN ctagent (uncomment)

SQL_PORT 6598


Note that this configuration assumes that all nodes are being run on the same computer.

Some notes about the above settings for the Source and Target Servers:

  • MEMPHIS_HOST tells them where to find Memphis (on what computer).
  • MEMPHIS_SQL_PORT tells them which port to use to connect to Memphis.
  • Enabling the “cthttpd” and “ctagent” plug-ins make it possible for them to connect to Memphis.
  • ACCEPT_CONN tells them to accept connections originating from Memphis.
  • The other PORT lines must be made unique to keep the servers from conflicting with each other.

3. Start the Servers

  1. Start the Memphis server by launching Memphis.exe or Memphis in the ReplicationManager folder and wait for the database creation to complete. This can be determined by monitoring the ReplicationManager/data/CTSTATUS.FCS file for the line “Memphis agent is ready”.
  2. Start the source and target c-tree servers after the Memphis database has been created.

4. Create Files

Create files by running ctdb_Tutorial4.exe on FAIRCOMS. The easiest way to do this is to run BuildTutorials.bat or make run in the drivers/c.nav/tutorials/cmdline/ directory.

5. Run the Demo

Execute the commands shown below to perform the following actions.

To set up (but not start) replication:

gradlew run --args=setup

To get the current replication status:

gradlew run --args=status

To redeploy all files in the replication plan:

gradlew run --args=redeploy

To resync all files in the replication plan:

gradlew run --args=resync

To stop the replication plan:

gradlew run --args=stop

To stop replication and remove all replication plans and publications:

gradlew run --args=cleanup

You are now ready to view the Replication RPC API Developer's Guide to learn more about using this API to control replication in your c-tree environment.

TOCIndex