Skip to content

Commit 9d6351e

Browse files
committed
cluster management test - add node
Signed-off-by: May Rosenbaum <mayro1595@gmail.com>
1 parent 40e0e0a commit 9d6351e

File tree

7 files changed

+593
-9
lines changed

7 files changed

+593
-9
lines changed

cli/README.md

Lines changed: 87 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ This command-line tool provides a simple way to config an orion database server.
66
1. Run from `orion-sdk` root folder
77
2. Run `make binary` to create an executable file named bcdbadmin under `bin` directory.
88

9+
910
## Commands
1011

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

1516

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

28+
###
29+
<a id="get_config_command"></a>
2630
#### Get Config Command
2731
1. Run from 'orion-sdk' root folder.
2832
2. For Get Config Run `bin/bcdbadmin config get [args]`.
@@ -45,11 +49,65 @@ Running
4549
`bin/bcdbadmin config get -d "connection-session-config.yaml" -c "local/config"`
4650
reads the connection and session details needed for connecting to a server from `connection-session-config.yaml` and
4751
sends a config TX.
48-
It creates directories in `local/config` with the respective certificates, a yaml file, named shared_cluster_config.yml, that includes the cluster configuration
49-
and a yaml file, named version.yml, that includes the version.
52+
It creates directories in `local/config` with the respective certificates, a yaml file, named `shared_cluster_config.yml`, that includes the cluster configuration
53+
and a yaml file, named `version.yml`, that includes the version.
54+
55+
56+
###
57+
<a id="get_last_config_block_command"></a>
58+
#### Get Last Config Block Command
59+
1. Run from 'orion-sdk' root folder.
60+
2. For Get last config block Run `bin/bcdbadmin config getLastConfigBlock [args]`.
61+
62+
Replace `[args]` with flags.
63+
64+
###
65+
##### Flags
66+
| Flags | Description |
67+
|-----------------------------------|----------------------------------------------------------------------------|
68+
| `-d, --db-connection-config-path` | the absolute or relative path of CLI connection configuration file |
69+
| `-c, --cluster-config-path` | the absolute or relative path to which the last config block will be saved |
70+
71+
Both flags are necessary flags. If any flag is missing, the cli will raise an error.
72+
73+
###
74+
##### Example:
5075

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

5282

83+
###
84+
<a id="get_cluster_status_command"></a>
85+
#### Get Cluster Status Command
86+
1. Run from 'orion-sdk' root folder.
87+
2. For Get last config block Run `bin/bcdbadmin config getClusterStatus [args]`.
88+
89+
Replace `[args]` with flags.
90+
91+
###
92+
##### Flags
93+
| Flags | Description |
94+
|-----------------------------------|----------------------------------------------------------------------------|
95+
| `-d, --db-connection-config-path` | the absolute or relative path of CLI connection configuration file |
96+
97+
The flag above is a necessary flag. If the flag is missing, the cli will raise an error.
98+
99+
###
100+
##### Example:
101+
102+
Running
103+
`bin/bcdbadmin config getClusterStatus -d "connection-session-config.yaml"`
104+
reads the connection and session details needed for connecting to a server from `connection-session-config.yaml` and
105+
sends a config TX.
106+
It prints the output (the cluster status) to the screen.
107+
108+
109+
###
110+
<a id="set_config_command"></a>
53111
#### Set Config Command
54112
1. Run from 'orion-sdk' root folder.
55113
2. For Set Config Run:
@@ -77,4 +135,30 @@ Running
77135
`bin/bcdbadmin config set -d "connection-session-config.yaml" -c "local/new_cluster_config.yml"`
78136
reads the connection and session details needed for connecting to a server from `connection-session-config.yaml` and
79137
sends a config TX.
80-
It reads the `local/new_cluster_config.yml` to fetch the new cluster configuration and set it.
138+
It reads the `local/new_cluster_config.yml` to fetch the new cluster configuration and set it.
139+
140+
141+
###
142+
#### Using the set config command to manage the cluster configuration
143+
In addition to reconfiguring parameters, the above commands can be used to add or remove a node.
144+
145+
The following steps describe how to add a node to the cluster:
146+
1. Run from 'orion-sdk' root folder.
147+
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).
148+
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.
149+
150+
Note: it is possible to create a new file or to edit the `shared_cluster_config.yml` obtained in the previous step.
151+
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).
152+
153+
After this step the cluster configuration should contain 4 nodes.
154+
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).
155+
6. Edit the `config.yml` file of 4th node and change the boostrap method and file:
156+
```yaml
157+
- bootstrap:
158+
method: join
159+
file: [the path for last_config_block.yml file]
160+
```
161+
8. Start the 4th node.
162+
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).
163+
164+
Make sure there are 4 nodes in the resulting configuration.

cli/commands/config.go

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func configCmd() *cobra.Command {
2828
panic(err.Error())
2929
}
3030

31-
configCmd.AddCommand(getConfigCmd(), setConfigCmd())
31+
configCmd.AddCommand(getConfigCmd(), setConfigCmd(), getLastConfigBlockCmd(), getClusterStatusCmd())
3232

3333
return configCmd
3434
}
@@ -65,6 +65,33 @@ func setConfigCmd() *cobra.Command {
6565
return setConfigCmd
6666
}
6767

68+
func getLastConfigBlockCmd() *cobra.Command {
69+
getLastConfigBlockCmd := &cobra.Command{
70+
Use: "getLastConfigBlock",
71+
Short: "Get last configuration block",
72+
Example: "cli config getLastConfigBlock -d <path-to-connection-and-session-config> -c <path-to-last-config-block-output>",
73+
RunE: getLastConfigBlock,
74+
}
75+
76+
getLastConfigBlockCmd.PersistentFlags().StringP("last-config-block-path", "c", "", "set the absolute or relative path of the last configuration block file")
77+
if err := getLastConfigBlockCmd.MarkPersistentFlagRequired("last-config-block-path"); err != nil {
78+
panic(err.Error())
79+
}
80+
81+
return getLastConfigBlockCmd
82+
}
83+
84+
func getClusterStatusCmd() *cobra.Command {
85+
getClusterStatusCmd := &cobra.Command{
86+
Use: "getClusterStatus",
87+
Short: "Get cluster status",
88+
Example: "cli config getClusterStatus -d <path-to-connection-and-session-config>",
89+
RunE: getClusterStatus,
90+
}
91+
92+
return getClusterStatusCmd
93+
}
94+
6895
func getConfig(cmd *cobra.Command, args []string) error {
6996
cliConfigPath, err := cmd.Flags().GetString("db-connection-config-path")
7097
if err != nil {
@@ -181,6 +208,86 @@ func setConfig(cmd *cobra.Command, args []string) error {
181208
return nil
182209
}
183210

211+
func getLastConfigBlock(cmd *cobra.Command, args []string) error {
212+
cliConfigPath, err := cmd.Flags().GetString("db-connection-config-path")
213+
if err != nil {
214+
return errors.Wrapf(err, "failed to fetch the path of CLI connection configuration file")
215+
}
216+
217+
getLastConfigBlockPath, err := cmd.Flags().GetString("last-config-block-path")
218+
if err != nil {
219+
return errors.Wrapf(err, "failed to fetch the path to which the last configuration block will be saved")
220+
}
221+
222+
params := cliConfigParams{
223+
cliConfigPath: cliConfigPath,
224+
cliConfig: cliConnectionConfig{},
225+
db: nil,
226+
session: nil,
227+
}
228+
229+
err = params.CreateDbAndOpenSession()
230+
if err != nil {
231+
return err
232+
}
233+
234+
tx, err := params.session.ConfigTx()
235+
if err != nil {
236+
return errors.Wrapf(err, "failed to instanciate a config TX")
237+
}
238+
defer abort(tx)
239+
240+
blk, err := tx.GetLastConfigBlock()
241+
if err != nil {
242+
return errors.Wrapf(err, "failed to fetch the last config block")
243+
}
244+
245+
err = os.MkdirAll(getLastConfigBlockPath, 0755)
246+
if err != nil {
247+
errors.Wrapf(err, "failed to create output directory")
248+
}
249+
250+
err = os.WriteFile(path.Join(getLastConfigBlockPath, "last_config_block.yml"), blk, 0644)
251+
if err != nil {
252+
return errors.Wrapf(err, "failed to create last config block yaml file")
253+
}
254+
255+
return nil
256+
}
257+
258+
func getClusterStatus(cmd *cobra.Command, args []string) error {
259+
cliConfigPath, err := cmd.Flags().GetString("db-connection-config-path")
260+
if err != nil {
261+
return errors.Wrapf(err, "failed to fetch the path of CLI connection configuration file")
262+
}
263+
264+
params := cliConfigParams{
265+
cliConfigPath: cliConfigPath,
266+
cliConfig: cliConnectionConfig{},
267+
db: nil,
268+
session: nil,
269+
}
270+
271+
err = params.CreateDbAndOpenSession()
272+
if err != nil {
273+
return err
274+
}
275+
276+
tx, err := params.session.ConfigTx()
277+
if err != nil {
278+
return errors.Wrapf(err, "failed to instanciate a config TX")
279+
}
280+
defer abort(tx)
281+
282+
status, err := tx.GetClusterStatus()
283+
if err != nil {
284+
return errors.Wrapf(err, "failed to fetch the cluster status")
285+
}
286+
287+
cmd.Printf("Cluster status is: %s\n", status)
288+
return nil
289+
}
290+
184291
func abort(tx bcdb.TxContext) {
185292
_ = tx.Abort()
186293
}

0 commit comments

Comments
 (0)