Introduction
Some users wish to perform maintenance on servers used in a JS7 - Agent Cluster without shutting down the related Subagent(s).
- One option is to disable a given Subagent. The related operation is available from the Manage Controllers/Agents view for each Subagent.
- In an active-passive Subagent Cluster the next Subagent will become active.
- In an active-active Subagent Cluster the remaining Subagents will share the load.
- Disabling a Subagent is an operation applied to all Subagent Clusters that include the given Subagent. The operation might not be applicable in a situation when an active Subagent should be disabled in a specific Subagent Cluster only.
- To switch a Subagent in a specific Subagent Cluster users can run a script that will use the JS7 - REST Web Service API to perform the following actions:
- In an active-passive Subagent Cluster the next standby Subagent or a specific standby Subagent will become active.
- For an active-active Subagent Cluster the operation makes no sense as all Subagents will be used independently of their precedence.
The following explanations focus on a solution using a Unix shell script.
Switch Subagent Cluster Script
The script is provided for download and can be used to automate switching Subagents in a given Subagent Cluster.
- The script is available for Linux and MacOS® using bash shell.
- The script terminates with exit code 0 to signal successful switching, with exit code 1 for command line argument errors and with exit code 4 for non-recoverable errors. Exit code 3 signals that no matching Subagent Cluster has been found.
- The script is intended as a baseline example for customization by JS7 users and by SOS within the scope of professional services.
Prerequisites
The Script requires the jq utility to be available from the operating system.
jq is ships with the MIT license, see https://opensource.org/licenses/MIT.
Download
Download: switch-subagent-cluster.sh
Usage
Invoking the script without arguments displays the usage clause:
Usage: switch-subagent-cluster.sh [Options] [Switches] Options: --url=<url> | required: JOC Cockpit URL --controller-id=<identifier> | required: Controller ID --user=<account> | required: JOC Cockpit user account --password=<password> | optional: JOC Cockpit password --ca-cert=<path> | optional: path to CA Certificate used for JOC Cockpit login --client-cert=<path> | optional: path to Client Certificate used for login --client-key=<path> | optional: path to Client Key used for login --agent-cluster-id=<identifier> | required: ID of the Agent Cluster --subagent-cluster-id=<identifier> | required: ID of the Subagent Cluster --active=<identifier> | optional: Identifier of the Subagent that should become active --log-dir=<directory> | optional: path to the directory holding the script's batch log files Switches: -h | --help | displays usage -v | --verbose | displays verbose output -p | --password | asks for password -c | --check | checks which Subagents are configured and displays results -s | --switch | specifies that active Subagent and next standby Subagent should be switched --show-logs | shows log output if --log-dir is used --make-dirs | creates directories if they do not exist
Options
--url
- Specifies the URL by which JOC Cockpit is accessible using
<http|https>://<host>:<port>
. - Example: http://centostest-primary.sos:4446
- Example: https://centostest-primary.sos:4443
- Specifies the URL by which JOC Cockpit is accessible using
--controller-id
- Specifies the identification of the Controller that holds related orders.
--user
- Specifies the user account for login to JOC Cockpit. If JS7 - Identity Services are available for Client authentication certificates that are specified with the
--client-cert
and--client-key
options then their common name (CN) attribute has to match the user account. - If a user account is specified then a password can be specified using the
--password
option or interactive keyboard input can be prompted using the-p
switch.
- Specifies the user account for login to JOC Cockpit. If JS7 - Identity Services are available for Client authentication certificates that are specified with the
--password
- Specifies the password used for the account specified with the
--user
option to login to JOC Cockpit. - Consider use of the
-p
switch offering a secure option for interactive keyboard input.
- Specifies the password used for the account specified with the
--cacert
- Specifies the path to a .pem file that holds the Root CA Certificate and optionally Intermediate CA Certificates to verify HTTPS connections to JOC Cockpit.
--client-cert
- Specifies the path to a .pem file that holds the Client Certificate if HTTPS mutual authentication is used..
--client-key
- Specifies the path to a .pem file that holds the Client Privae Key if HTTPS mutual authentication is used..
--agent-cluster-id
- Specifies the Identifier of an existing Agent Cluster.
--subagent-cluster-id
- Specifies the identifier of an existing Subagent Cluster.
--active
- Specifies the Subagent ID of a specific Subagent that should be assigned the active role.
- The Subagent will be assigned the highest priority in the Subagent Cluster.
- The option cannot be used with the
--switch
and--check
switches.
--log-dir
- If a log directory is specified then the script will log information about processing steps to a log file in this directory.
- File names are created according to the pattern:
set_job_resource.<yyyy>-<MM>-<dd>T<hh>-<mm>-<ss>.log
- For example:
set_job_resource.2022-03-19T20-50-45.log
Switches
-h | --help
- Displays usage.
-p | --password
- Asks the user for interactive keyboard input of the password used for the account specified with the
--user
option.. - The switch is used to secure interactive input as an alternative to use of the option
--password=<password>
.
- Asks the user for interactive keyboard input of the password used for the account specified with the
-c | --check
- Displays the list of Subagents in the given Subagent Cluster without modifying the Subagent Cluster.
- The switch cannot be used with the
--switch
switch and not with the--active
option..
-s | --switch
- Specifies that the Subagent with highest priority and the next Subagent should switch the active role.
- The switch cannot be used with the
--check
switch and with the--active
option..
-v | --verbose
- Displays verbose log output.
--show-logs
- Displays the log output created by the script if the
--log-dir
option is used.
- Displays the log output created by the script if the
--make-dirs
- If directories are missing that are indicated with the
--log-dir
option then they will be created.
- If directories are missing that are indicated with the
Exit Codes
0:
cancellation of orders successfully initiated1
: argument errors3
: no Subagent Cluster found4
: JS7 REST Web Service is not reachable or reports errors
Examples
The following examples illustrate typical use cases.
Display the list of Subagents and priorities in a given Subagent Cluster
./switch-subagent-cluster.sh \ --url=http://joc-2-0-primary:7446 \ --user=root \ --password=root \ --controller-id=controller \ --agent-cluster-id=agent_cluster_001 \ --subagent-cluster-id=active-passive-all-agents \ --check # displays the list of Subagents und priorities in the given Subagent Cluster # does not modify the Subagent Cluster
Switch the active role from the Subagent with highest priority to the Subagent with next priority
./switch-subagent-cluster.sh \ --url=http://joc-2-0-primary:7446 \ --user=root \ --password=root \ --controller-id=controller \ --agent-cluster-id=agent_cluster_001 \ --subagent-cluster-id=active-passive-all-agents \ --switch # switches the active role from the Subagent with the highest priority in the given Subagent Cluster to the Subagent with the next priority
Switch the active role to a specific Subagent in an active-passive Subagent Cluster
./switch-subagent-cluster.sh \ --url=http://joc-2-0-primary:7446 \ --user=root \ --password=root \ --controller-id=controller \ --agent-cluster-id=agent_cluster_001 \ --subagent-cluster-id=active-passive-all-agents \ --active=secondary_director_001 # makes the Subagent with ID "secondary_director_001" the active Subagent in the given Subagent Cluster