(1) Elasticsearch Resync Utility

This utility syncs titles and work orders from a CMS database instance to an Elasticsearch instance. Titles
and work ordersare read from the database several at a time using multiple simultaneous threads. The
Elasticsearch indices are also updated in parallel in a pipelined fashion.

Running the Application
----
From the root directory where this utility has been installed -- referred to here as ${resync_home} --
execute the following command lines to run this application:

See notes about the configuration files that need to be changed below.
--

IN LINUX/UNIX
--
${resync_home}/bin/elasticsearch_sync.sh <command> [<parameter 1, parameter 2, ..., parameter N]

USAGE:
ResyncManagerMain <command> [<parameter 1, parameter 2, ..., parameter N]
  Commands:
  START
  STOP
  STATUS
  CLEAN
usage: ResyncManagerMain
 -a,--all                          Resyncs all titles and all work orders.
 -c,--concurrency <arg>            Sets the number of parallel threads or
                                   writing to Elasticsearch. Defaults to
                                   5.
 -db,--database <arg>              Explicitly specify database.
 -g,--geo                          Only use when running on georedundant
                                   site. Keeps Elasticsearch in sync with
                                   last database streaming.
 -h,--help                         Show help.
 -p,--variableprocesslimit <arg>   Max number of processids to use in
                                   variable isntance query, defaults to 50
 -q,--queuelimit <arg>             Sets the internal queue size and intern
                                   the SQL query batch size. Defaults to
                                   100.
 -s,--starttime <arg>              All entries that were updated later
                                   than starttime are selected for
                                   synchronization. Expected format is
                                   yyyy-MM-dd HH:mm:ss.
 -t,--titles                       Sync titles only.
 -v,--variableconcurrency <arg>    Sets the number of parallel connections
                                   to DB while gathering VARIABLE INSTANCE
                                   information. Defaults to 20.
 -w,--workflow                     Sync workflow only.
  
--

Configuration files
----
There are 2 configuration files which need to be set up locally to run this utility successfully. In the
Linux\Unix environment, these files don't really have to be modified, but instead are managed by the command-
line script. In the Windows environment, these files must be managed by direct editing.

--
${resync_home}/conf/sync.properties
--
Contains JDBC connection information for the CMS database to be read from and resynced to an Elasticsearch
instance. Please make sure this file is correctly configured locally before running the utility.

In the Linux\Unix environment, this file is automatically managed by command-line parameters of the
command-line script. You generally do not need to modify this file directly at all.

--
/opt/tandbergtv/cms/conf/contentMgmt/Elasticsearch.properties
--
Contains the connection information for the Elasticsearch instance to be updated. You must
ensure this file exists and is properly configured for a running Elasticsearch instance. Since this
is the same configuration file used by CMS itself, anyone able to run CMS locally should already have
this file locally.



(2) Elasticsearch Resync Utility - Geo-Redundancy

This utility syncs titles and work orders from a CMS database instance to an Elasticsearch instance on
a secondary site in a geo-redundant environment. This script will call ./elasticsearch_sync.sh with
prespecified parameters. This script keeps track of the last time Elasticsearch sync was run.

Running the Application
----
From the root directory where this utility has been installed -- referred to here as ${resync_home} --
execute the following command lines to run this application.

In a geo-redundant system, there will already be a cron job running this script every minute. To edit
the cron job, run "crontab -l" as root user on the app1 and app2 systems and modify accordingly.
--

IN LINUX/UNIX
--
${resync_home}/bin/elasticsearch_sync_geo.sh



(3) Elasticsearch CMS Title Resync Utility

This utility syncs all titles from a CMS database instance to an Elasticsearch instance. Titles
are read from the database several at a time using multiple simultaneous threads. The Elasticsearch
index is also updated in parallel in a pipelined fashion.

Running the Application
----
From the root directory where this utility has been installed -- referred to here as ${resync_home} --
execute the following command lines to run this application:
--

IN LINUX/UNIX
--
${resync_home}/bin/content_elasticsearch_sync.sh <command> [database]

USAGE:
ResyncManagerMain <command> [database]
  Commands:
  START
  STOP
  STATUS
  CLEAN
  
  Optional parameter is to specify database:
		example: ./workflow_elasticsearch_sync.sh dbserver


After resync is finished, CLEAN must be run before resync can be run again.
  
--

Configuration files
----
There are 2 configuration files which need to be set up locally to run this utility successfully. In the
Linux\Unix environment, these files don't really have to be modified, but instead are managed by the command-
line script. In the Windows environment, these files must be managed by direct editing.

--
${resync_home}/conf/sync.properties
--
Contains JDBC connection information for the CMS database to be read from and resynced to an Elasticsearch
instance. Please make sure this file is correctly configured locally before running the utility.

In the Linux\Unix environment, this file is automatically managed by command-line parameters of the
command-line script. You generally do not need to modify this file directly at all.

--
/opt/tandbergtv/cms/conf/contentMgmt/Elasticsearch.properties
--
Contains the connection information for the Elasticsearch instance to be updated. You must
ensure this file exists and is properly configured for a running Elasticsearch instance. Since this
is the same configuration file used by CMS itself, anyone able to run CMS locally should already have
this file locally.



(4) Workflow Elasticsearch Sync Utility

This utility syncs Workorder processes from RDBMS to Elasticsearch. Work orders are read from RDBMS in batches and 
synchronized to Elasticsearch based on last update date of Workorder in RDBMS. If Workorder selected from RDBMS 
is found to be inactive, that record is deleted from Elasticsearch.
In case Elasticsearch instance is not reachable, the utility will halt.

Installing the utility
----------------------
To install, unzip the archive in a folder.

Configuration
-------------
1. Utility expects that your hosts file is set up properly so that DBSERVER points to Postgres server and instance is expected to be ttv.
To use an instance other than ttv, please edit the shell/batch script and modify system property hibernate.connection.url

2. /opt/tandbergtv/cms/conf/workflow/WFSElasticsearch.properties contains the connection information for the Elasticsearch instance to 
be updated. This file must exist and properly configured for a running Elasticsearch instance.


Running the utility
-------------------
Execute the shell/batch script provided in the scripts folder.

If you are running the utility on linux environment:
	i. Give execute permission on files

${resync_home}/bin/workflow_elasticsearch_sync.sh <database> [<parameter 1, parameter 2, ..., parameter N]
When running the utility, one may pass parameters. All but one parameters are optional. First parameter is always DB Server IP or Host Name
Required parameter
	IP Address of DB Server
		example: ./workflow_elasticsearch_sync.sh dbserver
Optional parameters are
    queuelimit			Sets the internal queue size and intern the SQL query batch size. Defaults to 100.
    concurrency			Sets the number of parallel threads or writing to Elasticsearch. Defaults to 5.
    starttime			All workorders that were updated later than starttime are selected for synchronization. Expected format is yyyy-MM-dd HH:mm:ss Defaults to "1900-01-01 00:00:00"
    variableconcurrency	Sets the number of parallel connections to DB while gathering VARIABLE INSTANCE information. Defaults to 20.
		example: ./workflow_elasticsearch_sync.sh dbserver -starttime "2011-01-01 12:30:00"

The utility maintains a bookmark mechanism so that if it is interrupted, it can resume where it left off; as long as same parameters (or lack of them) is passed to subsequent runs. If previous run was complete and the utility is invoked again, a fresh re-run is executed. 



(5) Asset Id Resync Utility

CMS stores in a special table the metadata field values that are used by all metadata plugins to uniquely
identify an asset. These are the fields that are specified in the plugin mapping.dat files. Indexes 
are created on these fields in the table to speed-up the asset uniqueness query in CMS. 
This utility when run, will first checks if the table index fields match the identifier fields specified in 
all the metadata plugins. If they are out-of-sync, the utility will clear the table, reload the identifier field values
from all master title metadata, and recreate the indexes. If there are in-sync, the utility will exit and do
nothing. You can use "-force" option to run the utility regardless of whether table indexes are in-sync or not.

Run this tool whenever you make any changes to the fields specified in the metadata plugin mapping.dat file,
e.g adding a new metadata plugin. You do not need to run this tool if all the new fields are already specified in
the other existing plugins. 

Running the Application
----
From the root directory where this utility has been installed -- referred to here as ${resync_home} --
execute the following command lines to run this application:

IN LINUX/UNIX
--
${resync_home}/bin/spec_ids_database_sync.sh

--
note: use "-force" option to ignore the check on the table indexes.


Configuration
----
There is only 1 configuration file which need to be set up locally to run this utility successfully.

--
${resync_home}/conf/sync.properties
--
Contains JDBC connection information for the CMS database.Please make sure this file is correctly configured
locally before running the utility.
