This repository was archived by the owner on May 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Add monitors set command #355
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
72e42b3
Add monitors enable command
eamansour 6ea46e2
Add monitors disable command
eamansour 5a140cb
Add monitors enable and disable commands to README
eamansour fefd279
Address review comments
eamansour 74c6453
Use separate bean for updating monitors
eamansour bc1300f
Merge branch 'main' into em-2067-monitors-enable-disable
eamansour d62e4f0
Replace mentions of EnableMonitor with SetMonitor
eamansour 2ac8a78
Remove generated doc for monitors enable and disable commands
eamansour File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| ## galasactl monitors disable | ||
|
|
||
| Disable a monitor in the Galasa service | ||
|
|
||
| ### Synopsis | ||
|
|
||
| Disables a monitor with the given name in the Galasa service | ||
|
|
||
| ``` | ||
| galasactl monitors disable [flags] | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| ``` | ||
| -h, --help Displays the options for the 'monitors disable' command. | ||
| --name string A mandatory flag that identifies the monitor to be manipulated by name. | ||
| ``` | ||
|
|
||
| ### Options inherited from parent commands | ||
|
|
||
| ``` | ||
| -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 | ||
| --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. | ||
| -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. | ||
| --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) | ||
| --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) | ||
| ``` | ||
|
|
||
| ### SEE ALSO | ||
|
|
||
| * [galasactl monitors](galasactl_monitors.md) - Manage monitors in the Galasa service | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| ## galasactl monitors enable | ||
|
|
||
| Enable a monitor in the Galasa service | ||
|
|
||
| ### Synopsis | ||
|
|
||
| Enables a monitor with the given name in the Galasa service | ||
|
|
||
| ``` | ||
| galasactl monitors enable [flags] | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| ``` | ||
| -h, --help Displays the options for the 'monitors enable' command. | ||
| --name string A mandatory flag that identifies the monitor to be manipulated by name. | ||
| ``` | ||
|
|
||
| ### Options inherited from parent commands | ||
|
|
||
| ``` | ||
| -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 | ||
| --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. | ||
| -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. | ||
| --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) | ||
| --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) | ||
| ``` | ||
|
|
||
| ### SEE ALSO | ||
|
|
||
| * [galasactl monitors](galasactl_monitors.md) - Manage monitors in the Galasa service | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| ## galasactl monitors set | ||
|
|
||
| Update a monitor in the Galasa service | ||
|
|
||
| ### Synopsis | ||
|
|
||
| Updates a monitor with the given name in the Galasa service | ||
|
|
||
| ``` | ||
| galasactl monitors set [flags] | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| ``` | ||
| -h, --help Displays the options for the 'monitors set' command. | ||
| --is-enabled string A boolean flag that determines whether the given monitor should be enabled or disabled. Supported values are 'true' and 'false'. | ||
| --name string A mandatory flag that identifies the monitor to be manipulated by name. | ||
| ``` | ||
|
|
||
| ### Options inherited from parent commands | ||
|
|
||
| ``` | ||
| -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 | ||
| --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. | ||
| -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. | ||
| --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) | ||
| --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) | ||
| ``` | ||
|
|
||
| ### SEE ALSO | ||
|
|
||
| * [galasactl monitors](galasactl_monitors.md) - Manage monitors in the Galasa service | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| /* | ||
| * Copyright contributors to the Galasa project | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| */ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "log" | ||
|
|
||
| "github.com/galasa-dev/cli/pkg/api" | ||
| "github.com/galasa-dev/cli/pkg/galasaapi" | ||
| "github.com/galasa-dev/cli/pkg/monitors" | ||
| "github.com/galasa-dev/cli/pkg/spi" | ||
| "github.com/galasa-dev/cli/pkg/utils" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| type MonitorsSetCmdValues struct { | ||
| isEnabledStr string | ||
| } | ||
|
|
||
| type MonitorsSetCommand struct { | ||
| values *MonitorsSetCmdValues | ||
| cobraCommand *cobra.Command | ||
| } | ||
|
|
||
| // ------------------------------------------------------------------------------------------------ | ||
| // Constructors methods | ||
| // ------------------------------------------------------------------------------------------------ | ||
| func NewMonitorsSetCommand( | ||
| factory spi.Factory, | ||
| monitorsSetCommand spi.GalasaCommand, | ||
| commsFlagSet GalasaFlagSet, | ||
| ) (spi.GalasaCommand, error) { | ||
|
|
||
| cmd := new(MonitorsSetCommand) | ||
|
|
||
| err := cmd.init(factory, monitorsSetCommand, commsFlagSet) | ||
| return cmd, err | ||
| } | ||
|
|
||
| // ------------------------------------------------------------------------------------------------ | ||
| // Public methods | ||
| // ------------------------------------------------------------------------------------------------ | ||
| func (cmd *MonitorsSetCommand) Name() string { | ||
| return COMMAND_NAME_MONITORS_SET | ||
| } | ||
|
|
||
| func (cmd *MonitorsSetCommand) CobraCommand() *cobra.Command { | ||
| return cmd.cobraCommand | ||
| } | ||
|
|
||
| func (cmd *MonitorsSetCommand) Values() interface{} { | ||
| return cmd.values | ||
| } | ||
|
|
||
| // ------------------------------------------------------------------------------------------------ | ||
| // Private methods | ||
| // ------------------------------------------------------------------------------------------------ | ||
| func (cmd *MonitorsSetCommand) init(factory spi.Factory, monitorsCommand spi.GalasaCommand, commsFlagSet GalasaFlagSet) error { | ||
| var err error | ||
|
|
||
| cmd.values = &MonitorsSetCmdValues{} | ||
| cmd.cobraCommand, err = cmd.createCobraCmd(factory, monitorsCommand, commsFlagSet.Values().(*CommsFlagSetValues)) | ||
|
|
||
| return err | ||
| } | ||
|
|
||
| func (cmd *MonitorsSetCommand) createCobraCmd( | ||
| factory spi.Factory, | ||
| monitorsCommand spi.GalasaCommand, | ||
| commsFlagSetValues *CommsFlagSetValues, | ||
| ) (*cobra.Command, error) { | ||
|
|
||
| var err error | ||
|
|
||
| monitorsCommandValues := monitorsCommand.Values().(*MonitorsCmdValues) | ||
| monitorsSetCobraCmd := &cobra.Command{ | ||
| Use: "set", | ||
| Short: "Update a monitor in the Galasa service", | ||
| Long: "Updates a monitor with the given name in the Galasa service", | ||
| Aliases: []string{COMMAND_NAME_MONITORS_SET}, | ||
| RunE: func(cobraCommand *cobra.Command, args []string) error { | ||
| return cmd.executeMonitorsSet(factory, monitorsCommand.Values().(*MonitorsCmdValues), commsFlagSetValues) | ||
| }, | ||
| } | ||
|
|
||
| addMonitorNameFlag(monitorsSetCobraCmd, true, monitorsCommandValues) | ||
| isEnabledFlag := "is-enabled" | ||
|
|
||
| monitorsSetCobraCmd.Flags().StringVar(&cmd.values.isEnabledStr, isEnabledFlag, "", "A boolean flag that determines whether the given monitor should be enabled or disabled. Supported values are 'true' and 'false'.") | ||
|
|
||
| monitorsSetCobraCmd.MarkFlagsOneRequired( | ||
| isEnabledFlag, | ||
| ) | ||
|
|
||
| monitorsCommand.CobraCommand().AddCommand(monitorsSetCobraCmd) | ||
|
|
||
| return monitorsSetCobraCmd, err | ||
| } | ||
|
|
||
| func (cmd *MonitorsSetCommand) executeMonitorsSet( | ||
| factory spi.Factory, | ||
| monitorsCmdValues *MonitorsCmdValues, | ||
| commsFlagSetValues *CommsFlagSetValues, | ||
| ) error { | ||
|
|
||
| var err error | ||
| // Operations on the file system will all be relative to the current folder. | ||
| fileSystem := factory.GetFileSystem() | ||
|
|
||
| err = utils.CaptureLog(fileSystem, commsFlagSetValues.logFileName) | ||
| if err == nil { | ||
| commsFlagSetValues.isCapturingLogs = true | ||
|
|
||
| log.Println("Galasa CLI - Update monitors in the Galasa service") | ||
|
|
||
| env := factory.GetEnvironment() | ||
|
|
||
| var galasaHome spi.GalasaHome | ||
| galasaHome, err = utils.NewGalasaHome(fileSystem, env, commsFlagSetValues.CmdParamGalasaHomePath) | ||
| if err == nil { | ||
|
|
||
| var commsClient api.APICommsClient | ||
| commsClient, err = api.NewAPICommsClient( | ||
| commsFlagSetValues.bootstrap, | ||
| commsFlagSetValues.maxRetries, | ||
| commsFlagSetValues.retryBackoffSeconds, | ||
| factory, | ||
| galasaHome, | ||
| ) | ||
|
|
||
| if err == nil { | ||
|
|
||
| byteReader := factory.GetByteReader() | ||
|
|
||
| setMonitorsFunc := func(apiClient *galasaapi.APIClient) error { | ||
| return monitors.SetMonitor( | ||
| monitorsCmdValues.name, | ||
| cmd.values.isEnabledStr, | ||
| apiClient, | ||
| byteReader, | ||
| ) | ||
| } | ||
| err = commsClient.RunAuthenticatedCommandWithRateLimitRetries(setMonitorsFunc) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return err | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.