Skip to content

Commit

Permalink
cluster management test - add node
Browse files Browse the repository at this point in the history
Signed-off-by: May Rosenbaum <mayro1595@gmail.com>
  • Loading branch information
MayRosenbaum committed Dec 6, 2023
1 parent 40e0e0a commit 9d6351e
Show file tree
Hide file tree
Showing 7 changed files with 593 additions and 9 deletions.
90 changes: 87 additions & 3 deletions cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ This command-line tool provides a simple way to config an orion database server.
1. Run from `orion-sdk` root folder
2. Run `make binary` to create an executable file named bcdbadmin under `bin` directory.


## Commands

Here we list and describe the available commands.
We give a short explanation of their usage and describe the flags for each command.
We provide real-world examples demonstrating how to use the CLI tool for various tasks.



### Version Command
This command prints the version of the CLI tool.
1. Run from `orion-sdk` root folder.
Expand All @@ -23,6 +25,8 @@ This command prints the version of the CLI tool.
### Config Command
This command enables to config an orion server or ask for the configuration of an orion server.

###
<a id="get_config_command"></a>
#### Get Config Command
1. Run from 'orion-sdk' root folder.
2. For Get Config Run `bin/bcdbadmin config get [args]`.
Expand All @@ -45,11 +49,65 @@ Running
`bin/bcdbadmin config get -d "connection-session-config.yaml" -c "local/config"`
reads the connection and session details needed for connecting to a server from `connection-session-config.yaml` and
sends a config TX.
It creates directories in `local/config` with the respective certificates, a yaml file, named shared_cluster_config.yml, that includes the cluster configuration
and a yaml file, named version.yml, that includes the version.
It creates directories in `local/config` with the respective certificates, a yaml file, named `shared_cluster_config.yml`, that includes the cluster configuration
and a yaml file, named `version.yml`, that includes the version.


###
<a id="get_last_config_block_command"></a>
#### Get Last Config Block Command
1. Run from 'orion-sdk' root folder.
2. For Get last config block Run `bin/bcdbadmin config getLastConfigBlock [args]`.

Replace `[args]` with flags.

###
##### Flags
| Flags | Description |
|-----------------------------------|----------------------------------------------------------------------------|
| `-d, --db-connection-config-path` | the absolute or relative path of CLI connection configuration file |
| `-c, --cluster-config-path` | the absolute or relative path to which the last config block will be saved |

Both flags are necessary flags. If any flag is missing, the cli will raise an error.

###
##### Example:

Running
`bin/bcdbadmin config getLastconfigBlock -d "connection-session-config.yaml" -c "local/config"`
reads the connection and session details needed for connecting to a server from `connection-session-config.yaml` and
sends a config TX.
It creates a yaml file, named `last_config_block.yml`, under the `local/config` directory.


###
<a id="get_cluster_status_command"></a>
#### Get Cluster Status Command
1. Run from 'orion-sdk' root folder.
2. For Get last config block Run `bin/bcdbadmin config getClusterStatus [args]`.

Replace `[args]` with flags.

###
##### Flags
| Flags | Description |
|-----------------------------------|----------------------------------------------------------------------------|
| `-d, --db-connection-config-path` | the absolute or relative path of CLI connection configuration file |

The flag above is a necessary flag. If the flag is missing, the cli will raise an error.

###
##### Example:

Running
`bin/bcdbadmin config getClusterStatus -d "connection-session-config.yaml"`
reads the connection and session details needed for connecting to a server from `connection-session-config.yaml` and
sends a config TX.
It prints the output (the cluster status) to the screen.


###
<a id="set_config_command"></a>
#### Set Config Command
1. Run from 'orion-sdk' root folder.
2. For Set Config Run:
Expand Down Expand Up @@ -77,4 +135,30 @@ Running
`bin/bcdbadmin config set -d "connection-session-config.yaml" -c "local/new_cluster_config.yml"`
reads the connection and session details needed for connecting to a server from `connection-session-config.yaml` and
sends a config TX.
It reads the `local/new_cluster_config.yml` to fetch the new cluster configuration and set it.
It reads the `local/new_cluster_config.yml` to fetch the new cluster configuration and set it.


###
#### Using the set config command to manage the cluster configuration
In addition to reconfiguring parameters, the above commands can be used to add or remove a node.

The following steps describe how to add a node to the cluster:
1. Run from 'orion-sdk' root folder.
2. Run `bin/bcdbadmin config get [args]` to get the cluster configuration. Replace `[args]` with corresponding flags as detailed above, see [Get Config Command](#get_config_command).
3. Create a new shared configuration file, named `new_cluster_config.yml`, and add the 4th node to the configuration. Make sure to add the node to both the Members list and the Nodes list.

Note: it is possible to create a new file or to edit the `shared_cluster_config.yml` obtained in the previous step.
4. Run `bin/bcdbadmin config set [args]` to set the new configuration. Replace `[args]` with corresponding flags as detailed above, see [Set Config Command](#set_config_command).

After this step the cluster configuration should contain 4 nodes.
5. Run `bin/bcdbadmin config getLastConfigBlock [args]` to get the last config block. Replace `[args]` with corresponding flags as detailed above, see [Get Last Config Block Command](#get_last_config_block_command).
6. Edit the `config.yml` file of 4th node and change the boostrap method and file:
```yaml
- bootstrap:
method: join
file: [the path for last_config_block.yml file]
```
8. Start the 4th node.
9. Run `bin/bcdbadmin config getClusterStatus [args]` to get the cluster status. Replace `[args]` with corresponding flags as detailed above, see [Get Cluster Status Command](#get_cluster_status_command).

Make sure there are 4 nodes in the resulting configuration.
109 changes: 108 additions & 1 deletion cli/commands/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func configCmd() *cobra.Command {
panic(err.Error())
}

configCmd.AddCommand(getConfigCmd(), setConfigCmd())
configCmd.AddCommand(getConfigCmd(), setConfigCmd(), getLastConfigBlockCmd(), getClusterStatusCmd())

return configCmd
}
Expand Down Expand Up @@ -65,6 +65,33 @@ func setConfigCmd() *cobra.Command {
return setConfigCmd
}

func getLastConfigBlockCmd() *cobra.Command {
getLastConfigBlockCmd := &cobra.Command{
Use: "getLastConfigBlock",
Short: "Get last configuration block",
Example: "cli config getLastConfigBlock -d <path-to-connection-and-session-config> -c <path-to-last-config-block-output>",
RunE: getLastConfigBlock,
}

getLastConfigBlockCmd.PersistentFlags().StringP("last-config-block-path", "c", "", "set the absolute or relative path of the last configuration block file")
if err := getLastConfigBlockCmd.MarkPersistentFlagRequired("last-config-block-path"); err != nil {
panic(err.Error())
}

return getLastConfigBlockCmd
}

func getClusterStatusCmd() *cobra.Command {
getClusterStatusCmd := &cobra.Command{
Use: "getClusterStatus",
Short: "Get cluster status",
Example: "cli config getClusterStatus -d <path-to-connection-and-session-config>",
RunE: getClusterStatus,
}

return getClusterStatusCmd
}

func getConfig(cmd *cobra.Command, args []string) error {
cliConfigPath, err := cmd.Flags().GetString("db-connection-config-path")
if err != nil {
Expand Down Expand Up @@ -181,6 +208,86 @@ func setConfig(cmd *cobra.Command, args []string) error {
return nil
}

func getLastConfigBlock(cmd *cobra.Command, args []string) error {
cliConfigPath, err := cmd.Flags().GetString("db-connection-config-path")
if err != nil {
return errors.Wrapf(err, "failed to fetch the path of CLI connection configuration file")
}

getLastConfigBlockPath, err := cmd.Flags().GetString("last-config-block-path")
if err != nil {
return errors.Wrapf(err, "failed to fetch the path to which the last configuration block will be saved")
}

params := cliConfigParams{
cliConfigPath: cliConfigPath,
cliConfig: cliConnectionConfig{},
db: nil,
session: nil,
}

err = params.CreateDbAndOpenSession()
if err != nil {
return err
}

tx, err := params.session.ConfigTx()
if err != nil {
return errors.Wrapf(err, "failed to instanciate a config TX")
}
defer abort(tx)

blk, err := tx.GetLastConfigBlock()
if err != nil {
return errors.Wrapf(err, "failed to fetch the last config block")
}

err = os.MkdirAll(getLastConfigBlockPath, 0755)
if err != nil {
errors.Wrapf(err, "failed to create output directory")
}

err = os.WriteFile(path.Join(getLastConfigBlockPath, "last_config_block.yml"), blk, 0644)
if err != nil {
return errors.Wrapf(err, "failed to create last config block yaml file")
}

return nil
}

func getClusterStatus(cmd *cobra.Command, args []string) error {
cliConfigPath, err := cmd.Flags().GetString("db-connection-config-path")
if err != nil {
return errors.Wrapf(err, "failed to fetch the path of CLI connection configuration file")
}

params := cliConfigParams{
cliConfigPath: cliConfigPath,
cliConfig: cliConnectionConfig{},
db: nil,
session: nil,
}

err = params.CreateDbAndOpenSession()
if err != nil {
return err
}

tx, err := params.session.ConfigTx()
if err != nil {
return errors.Wrapf(err, "failed to instanciate a config TX")
}
defer abort(tx)

status, err := tx.GetClusterStatus()
if err != nil {
return errors.Wrapf(err, "failed to fetch the cluster status")
}

cmd.Printf("Cluster status is: %s\n", status)
return nil
}

func abort(tx bcdb.TxContext) {
_ = tx.Abort()
}
Expand Down
Loading

0 comments on commit 9d6351e

Please sign in to comment.