Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
wip: adding cli tool
Browse files Browse the repository at this point in the history
  • Loading branch information
howardgao committed Oct 23, 2024
1 parent e9b2cb6 commit 37016c8
Show file tree
Hide file tree
Showing 12 changed files with 2,414 additions and 31 deletions.
6 changes: 6 additions & 0 deletions .cli.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

CLI_VERSION=1.0.0
CLI_NAME='Api Server CLI'

# to trust jolokia certs
NODE_TLS_REJECT_UNAUTHORIZED='0'
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,7 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# tmp dir
tmp

209 changes: 209 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,212 @@ To undeploy, run
```sh
./undeploy.sh
```

# Jolokia api-server Cli tool (work in progress)

The Jolokia api-server comes with a cli (command line interface) tool. When the cli tool starts it connects to the api-server and can access the jolokia endpoints.

The cli tool takes a **command** and requests the api-server using [its api](src/config/openapi.yml) to invoke on the target jolokia endpint, gets back the response and printing the result to the console in JSON format.

It can run in `interactive mode` or in `non-interactive` mode.

To build the cli tool run

```
yarn build
```

which will build both the api-server and cli tool.

To install the cli tool runnable locally run:

```
npm link
```

It will create the cli runnable `jolokia-api-server-cli`

## Running the cli tool

The cli tool needs a running api-server.

To start the cli tool run

```
jolokia-api-server-cli [options]
```

or you can use `yarn`

```
yarn start-cli [options]
```

## Using Cli tool in non-interactive mode

In this mode, the tool starts and execute a command and then exits.

The syntax for non-interactive mode is:

```
jolokia-api-server-cli <command> -l <api-server-url> -e <jolokia-endpoint-url>
```

If `-l` option is omitted the default is ` https://localhost:9443`

The `-e` option is the target jolokia url. for example

```
-e http://user:password@127.0.0.1:8161
```

If the port number part is omitted, the default
is `80` for http and `443` for https.

The `command` is the command to be executed.

Note in non-interactive mode the `command` need be quoted as it contains spaces.

Example:

```
jolokia-api-server-cli "get queue TEST -a MessageCount RoutingType" -e http://user:pass@127.0.0.1:8161
```

(the -s option can suppress yarn's own output)

## Using Cli tool in interactive mode

In interactive mode the tool starts into a command shell and
accepts user input as a command, then it executes it and went
back to the shell prompt to accept another, until you run the `exit`
command.

The syntax to run the cli in this mode is

```
jolokia-api-server-cli -i
```

When it starts it print the cli title and ready to accept
commands.

With interactive mode the cli can 'caches' a list of jolokia endpoints (added by the `add` command
only available in interactive mode). It takes one of them as `current endpoint` so when user types
a command without specifying target jolokia endpoint, the `current endpoint` will be used.

## Using Cli Commands

### The `get` command

This is the only available command currently. It can retrive
information from a jolokia endpoint.

The syntax of this command is

```
get <path> <name> <-a attributes...> <-o operations...>
```

It takes a `path` argument, a `name` argument, an optional `-a`(attribute) option and an optional
`-o` (operation) option.

The value of path is a string representing a target mbean from which you want to get information.
It takes the form [target endpoint]/[component]. The `target endpoint` in `interactive` mode allows
you to specify which broker you want to retrieve information from. If absent it takes the current broker
cached by the cli. In non-interactive mode that [target endpoint] can be empty if `-e` option is given,
or it is the target remote endpoint name prefix by a `@` char. For example `@broker1/`

The `component` part is the type of the mbean. Currently the supported mbean types are

- `queue`
- `address`
- `acceptor`
- `cluster-connection`

The <name> argument is the mbean name.

The value of `-a` option is a list of attribute names (space or comma separated) to read from the target mbean.
If the value is a `*` it will read all the attributes of the target mbean.

The value of `-o` option is a list of operation names (space or comma separated) to read from the target mbean.
If the value is a `*` it will read all the operations of the target mbean. When retrieving operation informations
the `name` part of the component if optional because operations are defined on the component type rather than
a specific mbean.??

examples:

`get /` - get the broker mbean information

`get /*` - get all mbeans registered with the broker mbean

`get / -a *` - read all the attributes of the broker mbean

`get / -a * -o *` - read information of all attributes and operations of the broker mbean

`get queue` (or `get /queue`) - list all the queue mbeans information

`get acceptor acceptor0 -a *` - read all attributes of acceptor named `acceptor0`

`get queue TEST -a MessageCount RoutingType` - read `MessageCount` and `RoutingType` of queue `TEST`

`get queue -o xxx` - read information of operation xxx of queue TEST

### The `run` command

The `run` command is used to invoke operations on a jolokia endpoint.

The syntax of this command is

```
run <path> <name> <op> <parameters...>
```

It takes a `path` argument, a `name` argument and optional `-a`(attribute) option

### Commands exclusive to Interactive mode

There are several commands that are only available to interactive mode.

#### The `add` command

Add a jolokia endpoint to the cli cache. Syntax:

```
add <endpoint name> <url> -u <user> -p <password>
```

example:

```
add ex-aao-ssl https://ex-aao-ssl-wconsj-0-svc-rte-default.apps-crc.testing -u user -p password
```

#### The `switch` command

To switch current endpoint to another. Syntax:

```
switch <endpoint name>
```

example:

```
switch broker0
```

#### The `list` command

To list all the jolokia endpoints cached in cli and managed on the api-server. Syntax:

```
list
```

With the cached enpoints in this mode, user can run a command against a cached jolokia endpoint.
For example:

`get ex-aao-ssl/queue DLQ -a MessageCount`

will read `MessageCount` attribute of queue DLQ on endpoint `ex-aao-ssl` in the cached endpoint list.
27 changes: 21 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "activemq-artemis-jolokia-api-server",
"version": "0.1.0",
"private": true,
"version": "0.1.2",
"private": false,
"homepage": "https://github.com/artemiscloud/activemq-artemis-jolokia-api-server#readme",
"bugs": {
"url": "https://github.com/artemiscloud/activemq-artemis-jolokia-api-server/issues"
Expand All @@ -11,7 +11,7 @@
"url": "git+ssh://git@github.com:artemiscloud/activemq-activemq-artemis-jolokia-api-server.git"
},
"scripts": {
"build": "yarn clean && tsc -p tsconfig.json && yarn copy-config",
"build": "yarn clean && tsc -p tsconfig.json && yarn copy-config && chmod +x dist/cli/index.js",
"build-api-doc": "yarn openapi-to-md src/config/openapi.yml api.md && yarn pretty-quick",
"clean": "rm -rf dist",
"copy-config": "cp -r src/config dist/config",
Expand All @@ -22,18 +22,26 @@
"test": "NODE_TLS_REJECT_UNAUTHORIZED=0 TZ=UTC jest --runInBand",
"test:coverage": "yarn run test --watch=false --coverage",
"test:generate-output": "yarn test -- --json --outputFile=.jest-test-results.json",
"ts-node": "ts-node -O '{\"module\":\"commonjs\"}'"
"ts-node": "ts-node -O '{\"module\":\"commonjs\"}'",
"apigen": "apigen-ts src/config/openapi.yml src/cli/api-client.ts",
"start-cli": "node --no-warnings ./dist/cli/index.js"
},
"lint-staged": {
"*.{js,ts,tsx}": [
"yarn run pretty-quick --staged",
"eslint --fix"
]
},
"dependencies": {
"dotenv": "^16.4.5",
"commander": "^12.1.0",
"figlet": "^1.7.0"
},
"devDependencies": {
"@types/base-64": "^1.0.2",
"@types/cors": "^2.8.17",
"@types/express": "^4.17.21",
"@types/figlet": "^1.5.8",
"@types/jest": "27.5.2",
"@types/js-yaml": "4.0.5",
"@types/jsonwebtoken": "^9.0.6",
Expand All @@ -42,11 +50,11 @@
"@types/webpack": "5.28.1",
"@typescript-eslint/eslint-plugin": "^5.14.0",
"@typescript-eslint/parser": "^5.14.0",
"apigen-ts": "^0.2.0",
"base-64": "^1.0.0",
"chromatic": "6.10.1",
"copy-webpack-plugin": "11.0.0",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"eslint": "^8.10.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
Expand Down Expand Up @@ -75,6 +83,13 @@
"typescript": "^4.7.4",
"yaml": "^2.4.5"
},
"bin": {
"jolokia-api-server-cli": "./dist/cli/index.js"
},
"files": [
"./dist"
],
"readme": "README.md",
"_id": "activemq-artemis-jolokia-api-server@0.1.0"
"_id": "activemq-artemis-jolokia-api-server@0.1.0",
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
Loading

0 comments on commit 37016c8

Please sign in to comment.