Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit bc1300f

Browse files
committed
Merge branch 'main' into em-2067-monitors-enable-disable
Signed-off-by: Eamonn Mansour <[email protected]>
2 parents 74c6453 + a75c4ff commit bc1300f

16 files changed

+1339
-22
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,28 @@ galasactl monitors set --name myCustomMonitor --is-enabled false
477477

478478
For a complete list of supported parameters see [here](./docs/generated/galasactl_monitors_set.md).
479479

480+
## monitors get
481+
482+
This command can be used to get the details of monitors, like resource cleanup monitors, that are available in the Galasa service.
483+
484+
By default, the output of `monitors get` will be in a "summary" format. To change the output format, you can supply the `--format` flag followed by the format that you wish the output to be displayed in. For a list of supported formats, view the command's help information by running `galasactl monitors get --help`.
485+
486+
### Examples
487+
488+
To get a list of all monitors that are currently available in the Galasa service, run the following command:
489+
490+
```
491+
galasactl monitors get
492+
```
493+
494+
If you would like to get a specific monitor, you can supply the name of the monitor with the `--name` flag. For example, the following command can be used to get a monitor named "myCustomMonitor":
495+
496+
```
497+
galasactl monitors get --name myCustomMonitor
498+
```
499+
500+
For a complete list of supported parameters see [here](./docs/generated/galasactl_monitors_get.md).
501+
480502
## properties get
481503
This command retrieves details of properties in a namespace.
482504

docs/generated/errors-list.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -214,19 +214,21 @@ The `galasactl` tool can generate the following errors:
214214
- GAL1215E: An attempt to update a user '{}' failed. Unexpected http status code {} received from the server. Error details from the server are not in a valid json format. Cause: '{}'
215215
- GAL1216E: An attempt to update a user '{}' failed. Unexpected http status code {} received from the server. Error details from the server are: '{}'
216216
- GAL1217E: An attempt to update a user '{}' failed. Unexpected http status code {} received from the server. Error details from the server are not in the json format.
217-
- GAL1218E: Failed to update a monitor named '{}'. Sending the put request to the Galasa service failed. Cause is {}
218-
- GAL1219E: Failed to update a monitor named '{}'. Unexpected http status code {} received from the server.
219-
- GAL1220E: Failed to update a monitor named '{}'. Unexpected http status code {} received from the server. Error details from the server could not be read. Cause: {}
220-
- GAL1221E: Failed to update a monitor named '{}'. Unexpected http status code {} received from the server. Error details from the server are not in a valid json format. Cause: '{}'
221-
- GAL1222E: Failed to update a monitor named '{}'. Unexpected http status code {} received from the server. Error details from the server are: '{}'
222-
- GAL1223E: Failed to update a monitor named '{}'. Unexpected http status code {} received from the server. Error details from the server are not in the json format.
217+
- GAL1218E: Failed to get monitors. Sending the get request to the Galasa service failed. Cause is {}
218+
- GAL1219E: Failed to get monitors. Unexpected http status code {} received from the server.
219+
- GAL1220E: Failed to get monitors. Unexpected http status code {} received from the server. Error details from the server could not be read. Cause: {}
220+
- GAL1221E: Failed to get monitors. Unexpected http status code {} received from the server. Error details from the server are not in a valid json format. Cause: '{}'
221+
- GAL1222E: Failed to get monitors. Unexpected http status code {} received from the server. Error details from the server are: '{}'
222+
- GAL1223E: Failed to get monitors. Unexpected http status code {} received from the server. Error details from the server are not in the json format.
223223
- GAL1224E: Galasa Monitor named {} is not known on the Galasa service.
224224
- GAL1225E: Invalid monitor name provided. The name provided with the --name flag cannot be empty and must only contain characters in the following ranges: 'a'-'z', 'A'-'Z', '0'-'9', '-' (dash), '_' (underscore).
225225
- GAL1226E: Invalid '--is-enabled' value provided. Supported values are 'true' and 'false'. Check your command parameters and try again.
226-
- GAL1227E: Internal failure. Contents of gzip could not be decoded. {} error: {}
227-
- GAL1228E: Internal failure. Contents of gzip could not be encoded and compressed. {} error: {}
228-
- GAL1229E: Internal failure. Contents of gzip could not be flushed while encoding and compressing. {} error: {}
229-
- GAL1230E: Internal failure. Gzip file could not be closed while encoding and compressing. {} error: {}
226+
- GAL1227E: Failed to update a monitor named '{}'. Sending the put request to the Galasa service failed. Cause is {}
227+
- GAL1228E: Failed to update a monitor named '{}'. Unexpected http status code {} received from the server.
228+
- GAL1229E: Failed to update a monitor named '{}'. Unexpected http status code {} received from the server. Error details from the server could not be read. Cause: {}
229+
- GAL1230E: Failed to update a monitor named '{}'. Unexpected http status code {} received from the server. Error details from the server are not in a valid json format. Cause: '{}'
230+
- GAL1231E: Failed to update a monitor named '{}'. Unexpected http status code {} received from the server. Error details from the server are: '{}'
231+
- GAL1232E: Failed to update a monitor named '{}'. Unexpected http status code {} received from the server. Error details from the server are not in the json format.
230232
- GAL2000W: Warning: Maven configuration file settings.xml should contain a reference to a Galasa repository so that the galasa OBR can be resolved. The official release repository is '{}', and 'pre-release' repository is '{}'
231233
- GAL2501I: Downloaded {} artifacts to folder '{}'
232234

docs/generated/galasactl_monitors.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ The parent command for operations to manipulate monitors in the Galasa service
2525
### SEE ALSO
2626

2727
* [galasactl](galasactl.md) - CLI for Galasa
28+
* [galasactl monitors get](galasactl_monitors_get.md) - Get monitors from the Galasa service
2829
* [galasactl monitors set](galasactl_monitors_set.md) - Update a monitor in the Galasa service
2930

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
## galasactl monitors get
2+
3+
Get monitors from the Galasa service
4+
5+
### Synopsis
6+
7+
Get a list of monitors or a specific monitor from the Galasa service
8+
9+
```
10+
galasactl monitors get [flags]
11+
```
12+
13+
### Options
14+
15+
```
16+
--format string the output format of the returned monitors. Supported formats are: 'summary', 'yaml'. (default "summary")
17+
-h, --help Displays the options for the 'monitors get' command.
18+
--name string An optional flag that identifies the monitor to be retrieved by name.
19+
```
20+
21+
### Options inherited from parent commands
22+
23+
```
24+
-b, --bootstrap string Bootstrap URL. Should start with 'http://' or 'file://'. If it starts with neither, it is assumed to be a fully-qualified path. If missing, it defaults to use the 'bootstrap.properties' file in your GALASA_HOME. Example: http://example.com/bootstrap, file:///user/myuserid/.galasa/bootstrap.properties , file://C:/Users/myuserid/.galasa/bootstrap.properties
25+
--galasahome string Path to a folder where Galasa will read and write files and configuration settings. The default is '${HOME}/.galasa'. This overrides the GALASA_HOME environment variable which may be set instead.
26+
-l, --log string File to which log information will be sent. Any folder referred to must exist. An existing file will be overwritten. Specify "-" to log to stderr. Defaults to not logging.
27+
--rate-limit-retries int The maximum number of retries that should be made when requests to the Galasa Service fail due to rate limits being exceeded. Must be a whole number. Defaults to 3 retries (default 3)
28+
--rate-limit-retry-backoff-secs float The amount of time in seconds to wait before retrying a command if it failed due to rate limits being exceeded. Defaults to 1 second. (default 1)
29+
```
30+
31+
### SEE ALSO
32+
33+
* [galasactl monitors](galasactl_monitors.md) - Manage monitors in the Galasa service
34+

pkg/cmd/commandCollection.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const (
4040
COMMAND_NAME_LOCAL = "local"
4141
COMMAND_NAME_LOCAL_INIT = "local init"
4242
COMMAND_NAME_MONITORS = "monitors"
43+
COMMAND_NAME_MONITORS_GET = "monitors get"
4344
COMMAND_NAME_MONITORS_SET = "monitors set"
4445
COMMAND_NAME_PROPERTIES = "properties"
4546
COMMAND_NAME_PROPERTIES_GET = "properties get"
@@ -440,16 +441,19 @@ func (commands *commandCollectionImpl) addMonitorsCommands(factory spi.Factory,
440441

441442
var err error
442443
var monitorsCommand spi.GalasaCommand
444+
var monitorsGetCommand spi.GalasaCommand
443445
var monitorsSetCommand spi.GalasaCommand
444446

445447
monitorsCommand, err = NewMonitorsCmd(rootCommand, commsFlagSet)
446448

447449
if err == nil {
450+
monitorsGetCommand, err = NewMonitorsGetCommand(factory, monitorsCommand, commsFlagSet)
448451
monitorsSetCommand, err = NewMonitorsSetCommand(factory, monitorsCommand, commsFlagSet)
449452
}
450453

451454
if err == nil {
452455
commands.commandMap[monitorsCommand.Name()] = monitorsCommand
456+
commands.commandMap[monitorsGetCommand.Name()] = monitorsGetCommand
453457
commands.commandMap[monitorsSetCommand.Name()] = monitorsSetCommand
454458
}
455459

pkg/cmd/monitorsGet.go

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
/*
2+
* Copyright contributors to the Galasa project
3+
*
4+
* SPDX-License-Identifier: EPL-2.0
5+
*/
6+
package cmd
7+
8+
import (
9+
"log"
10+
11+
"github.com/galasa-dev/cli/pkg/api"
12+
"github.com/galasa-dev/cli/pkg/galasaapi"
13+
"github.com/galasa-dev/cli/pkg/monitors"
14+
"github.com/galasa-dev/cli/pkg/spi"
15+
"github.com/galasa-dev/cli/pkg/utils"
16+
"github.com/spf13/cobra"
17+
)
18+
19+
type MonitorsGetCmdValues struct {
20+
outputFormat string
21+
}
22+
23+
type MonitorsGetCommand struct {
24+
values *MonitorsGetCmdValues
25+
cobraCommand *cobra.Command
26+
}
27+
28+
// ------------------------------------------------------------------------------------------------
29+
// Constructors methods
30+
// ------------------------------------------------------------------------------------------------
31+
func NewMonitorsGetCommand(
32+
factory spi.Factory,
33+
monitorsGetCommand spi.GalasaCommand,
34+
commsFlagSet GalasaFlagSet,
35+
) (spi.GalasaCommand, error) {
36+
37+
cmd := new(MonitorsGetCommand)
38+
39+
err := cmd.init(factory, monitorsGetCommand, commsFlagSet)
40+
return cmd, err
41+
}
42+
43+
// ------------------------------------------------------------------------------------------------
44+
// Public methods
45+
// ------------------------------------------------------------------------------------------------
46+
func (cmd *MonitorsGetCommand) Name() string {
47+
return COMMAND_NAME_MONITORS_GET
48+
}
49+
50+
func (cmd *MonitorsGetCommand) CobraCommand() *cobra.Command {
51+
return cmd.cobraCommand
52+
}
53+
54+
func (cmd *MonitorsGetCommand) Values() interface{} {
55+
return cmd.values
56+
}
57+
58+
// ------------------------------------------------------------------------------------------------
59+
// Private methods
60+
// ------------------------------------------------------------------------------------------------
61+
func (cmd *MonitorsGetCommand) init(factory spi.Factory, monitorsCommand spi.GalasaCommand, commsFlagSet GalasaFlagSet) error {
62+
var err error
63+
64+
cmd.values = &MonitorsGetCmdValues{}
65+
cmd.cobraCommand, err = cmd.createCobraCmd(factory, monitorsCommand, commsFlagSet.Values().(*CommsFlagSetValues))
66+
67+
return err
68+
}
69+
70+
func (cmd *MonitorsGetCommand) createCobraCmd(
71+
factory spi.Factory,
72+
monitorsCommand spi.GalasaCommand,
73+
commsFlagSetValues *CommsFlagSetValues,
74+
) (*cobra.Command, error) {
75+
76+
var err error
77+
78+
monitorsCommandValues := monitorsCommand.Values().(*MonitorsCmdValues)
79+
monitorsGetCobraCmd := &cobra.Command{
80+
Use: "get",
81+
Short: "Get monitors from the Galasa service",
82+
Long: "Get a list of monitors or a specific monitor from the Galasa service",
83+
Aliases: []string{COMMAND_NAME_MONITORS_GET},
84+
RunE: func(cobraCommand *cobra.Command, args []string) error {
85+
return cmd.executeMonitorsGet(factory, monitorsCommand.Values().(*MonitorsCmdValues), commsFlagSetValues)
86+
},
87+
}
88+
89+
addMonitorNameFlag(monitorsGetCobraCmd, false, monitorsCommandValues)
90+
91+
formatters := monitors.GetFormatterNamesAsString()
92+
monitorsGetCobraCmd.Flags().StringVar(&cmd.values.outputFormat, "format", "summary", "the output format of the returned monitors. Supported formats are: "+formatters+".")
93+
94+
monitorsCommand.CobraCommand().AddCommand(monitorsGetCobraCmd)
95+
96+
return monitorsGetCobraCmd, err
97+
}
98+
99+
func (cmd *MonitorsGetCommand) executeMonitorsGet(
100+
factory spi.Factory,
101+
monitorsCmdValues *MonitorsCmdValues,
102+
commsFlagSetValues *CommsFlagSetValues,
103+
) error {
104+
105+
var err error
106+
// Operations on the file system will all be relative to the current folder.
107+
fileSystem := factory.GetFileSystem()
108+
109+
err = utils.CaptureLog(fileSystem, commsFlagSetValues.logFileName)
110+
if err == nil {
111+
commsFlagSetValues.isCapturingLogs = true
112+
113+
log.Println("Galasa CLI - Get monitors from the Galasa service")
114+
115+
env := factory.GetEnvironment()
116+
117+
var galasaHome spi.GalasaHome
118+
galasaHome, err = utils.NewGalasaHome(fileSystem, env, commsFlagSetValues.CmdParamGalasaHomePath)
119+
if err == nil {
120+
121+
var commsClient api.APICommsClient
122+
commsClient, err = api.NewAPICommsClient(
123+
commsFlagSetValues.bootstrap,
124+
commsFlagSetValues.maxRetries,
125+
commsFlagSetValues.retryBackoffSeconds,
126+
factory,
127+
galasaHome,
128+
)
129+
130+
if err == nil {
131+
132+
var console = factory.GetStdOutConsole()
133+
byteReader := factory.GetByteReader()
134+
135+
getMonitorsFunc := func(apiClient *galasaapi.APIClient) error {
136+
return monitors.GetMonitors(monitorsCmdValues.name, cmd.values.outputFormat, console, apiClient, byteReader)
137+
}
138+
err = commsClient.RunAuthenticatedCommandWithRateLimitRetries(getMonitorsFunc)
139+
}
140+
}
141+
}
142+
143+
return err
144+
}

pkg/cmd/monitorsGet_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright contributors to the Galasa project
3+
*
4+
* SPDX-License-Identifier: EPL-2.0
5+
*/
6+
package cmd
7+
8+
import (
9+
"testing"
10+
11+
"github.com/galasa-dev/cli/pkg/utils"
12+
"github.com/stretchr/testify/assert"
13+
)
14+
15+
func TestCommandListContainsMonitorsGetCommand(t *testing.T) {
16+
/// Given...
17+
factory := utils.NewMockFactory()
18+
commands, _ := NewCommandCollection(factory)
19+
20+
// When...
21+
monitorsCommand, err := commands.GetCommand(COMMAND_NAME_MONITORS_GET)
22+
assert.Nil(t, err)
23+
24+
// Then...
25+
assert.NotNil(t, monitorsCommand)
26+
assert.Equal(t, COMMAND_NAME_MONITORS_GET, monitorsCommand.Name())
27+
assert.NotNil(t, monitorsCommand.Values())
28+
assert.IsType(t, &MonitorsGetCmdValues{}, monitorsCommand.Values())
29+
}
30+
31+
func TestMonitorsGetHelpFlagSetCorrectly(t *testing.T) {
32+
// Given...
33+
factory := utils.NewMockFactory()
34+
commandCollection, _ := setupTestCommandCollection(COMMAND_NAME_MONITORS_GET, factory, t)
35+
36+
var args []string = []string{"monitors", "get", "--help"}
37+
38+
// When...
39+
err := commandCollection.Execute(args)
40+
41+
// Then...
42+
checkOutput("Get a list of monitors or a specific monitor from the Galasa service", "", factory, t)
43+
44+
assert.Nil(t, err)
45+
}
46+
47+
func TestMonitorsGetNoFlagsReturnsOk(t *testing.T) {
48+
// Given...
49+
factory := utils.NewMockFactory()
50+
commandCollection, _ := setupTestCommandCollection(COMMAND_NAME_MONITORS_GET, factory, t)
51+
52+
var args []string = []string{"monitors", "get"}
53+
54+
// When...
55+
err := commandCollection.Execute(args)
56+
57+
// Then...
58+
assert.Nil(t, err)
59+
60+
// Check what the user saw is reasonable.
61+
checkOutput("", "", factory, t)
62+
}
63+

0 commit comments

Comments
 (0)