-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #213 from galasa-dev/iss1479
Iss1479 and 1685 - Reset and Cancel an active test run.
- Loading branch information
Showing
18 changed files
with
1,796 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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 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,31 @@ | ||
## galasactl runs cancel | ||
|
||
cancel an active run in the ecosystem | ||
|
||
### Synopsis | ||
|
||
Cancel an active test run in the ecosystem if it is stuck or looping. | ||
|
||
``` | ||
galasactl runs cancel [flags] | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help Displays the options for the 'runs cancel' command. | ||
--name string the name of the test run to cancel | ||
``` | ||
|
||
### 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. | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [galasactl runs](galasactl_runs.md) - Manage test runs in the ecosystem | ||
|
This file contains 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,31 @@ | ||
## galasactl runs reset | ||
|
||
reset an active run in the ecosystem | ||
|
||
### Synopsis | ||
|
||
Reset an active test run in the ecosystem if it is stuck or looping. | ||
|
||
``` | ||
galasactl runs reset [flags] | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help Displays the options for the 'runs reset' command. | ||
--name string the name of the test run to reset | ||
``` | ||
|
||
### 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. | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [galasactl runs](galasactl_runs.md) - Manage test runs in the ecosystem | ||
|
This file contains 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 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,149 @@ | ||
/* | ||
* 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/auth" | ||
"github.com/galasa-dev/cli/pkg/runs" | ||
"github.com/galasa-dev/cli/pkg/utils" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// Objective: Allow the user to do this: | ||
// runs cancel --name U123 | ||
// And then galasactl cancels the run by abandoning it. | ||
|
||
type RunsCancelCommand struct { | ||
values *RunsCancelCmdValues | ||
cobraCommand *cobra.Command | ||
} | ||
|
||
type RunsCancelCmdValues struct { | ||
runName string | ||
} | ||
|
||
// ------------------------------------------------------------------------------------------------ | ||
// Constructors methods | ||
// ------------------------------------------------------------------------------------------------ | ||
func NewRunsCancelCommand(factory Factory, runsCommand GalasaCommand, rootCommand GalasaCommand) (GalasaCommand, error) { | ||
cmd := new(RunsCancelCommand) | ||
err := cmd.init(factory, runsCommand, rootCommand) | ||
return cmd, err | ||
} | ||
|
||
// ------------------------------------------------------------------------------------------------ | ||
// Public methods | ||
// ------------------------------------------------------------------------------------------------ | ||
func (cmd *RunsCancelCommand) Name() string { | ||
return COMMAND_NAME_RUNS_CANCEL | ||
} | ||
|
||
func (cmd *RunsCancelCommand) CobraCommand() *cobra.Command { | ||
return cmd.cobraCommand | ||
} | ||
|
||
func (cmd *RunsCancelCommand) Values() interface{} { | ||
return cmd.values | ||
} | ||
|
||
// ------------------------------------------------------------------------------------------------ | ||
// Private methods | ||
// ------------------------------------------------------------------------------------------------ | ||
func (cmd *RunsCancelCommand) init(factory Factory, runsCommand GalasaCommand, rootCommand GalasaCommand) error { | ||
var err error | ||
cmd.values = &RunsCancelCmdValues{} | ||
cmd.cobraCommand, err = cmd.createRunsCancelCobraCmd( | ||
factory, | ||
runsCommand, | ||
rootCommand.Values().(*RootCmdValues), | ||
) | ||
return err | ||
} | ||
|
||
func (cmd *RunsCancelCommand) createRunsCancelCobraCmd(factory Factory, | ||
runsCommand GalasaCommand, | ||
rootCmdValues *RootCmdValues, | ||
) (*cobra.Command, error) { | ||
|
||
var err error = nil | ||
runsCmdValues := runsCommand.Values().(*RunsCmdValues) | ||
|
||
runsCancelCmd := &cobra.Command{ | ||
Use: "cancel", | ||
Short: "cancel an active run in the ecosystem", | ||
Long: "Cancel an active test run in the ecosystem if it is stuck or looping.", | ||
Args: cobra.NoArgs, | ||
Aliases: []string{"runs cancel"}, | ||
RunE: func(cobraCmd *cobra.Command, args []string) error { | ||
return cmd.executeCancel(factory, runsCmdValues, rootCmdValues) | ||
}, | ||
} | ||
|
||
runsCancelCmd.PersistentFlags().StringVar(&cmd.values.runName, "name", "", "the name of the test run to cancel") | ||
|
||
runsCancelCmd.MarkPersistentFlagRequired("name") | ||
|
||
runsCommand.CobraCommand().AddCommand(runsCancelCmd) | ||
|
||
return runsCancelCmd, err | ||
} | ||
|
||
func (cmd *RunsCancelCommand) executeCancel( | ||
factory Factory, | ||
runsCmdValues *RunsCmdValues, | ||
rootCmdValues *RootCmdValues, | ||
) error { | ||
|
||
var err error | ||
|
||
// Operations on the file system will all be relative to the current folder. | ||
fileSystem := factory.GetFileSystem() | ||
|
||
err = utils.CaptureLog(fileSystem, rootCmdValues.logFileName) | ||
if err == nil { | ||
rootCmdValues.isCapturingLogs = true | ||
|
||
log.Println("Galasa CLI - Cancel an active run by abandoning it.") | ||
|
||
// Get the ability to query environment variables. | ||
env := factory.GetEnvironment() | ||
|
||
var galasaHome utils.GalasaHome | ||
galasaHome, err = utils.NewGalasaHome(fileSystem, env, rootCmdValues.CmdParamGalasaHomePath) | ||
if err == nil { | ||
|
||
// Read the bootstrap properties | ||
var urlService *api.RealUrlResolutionService = new(api.RealUrlResolutionService) | ||
var bootstrapData *api.BootstrapData | ||
bootstrapData, err = api.LoadBootstrap(galasaHome, fileSystem, env, runsCmdValues.bootstrap, urlService) | ||
if err == nil { | ||
|
||
var console = factory.GetStdOutConsole() | ||
timeService := factory.GetTimeService() | ||
|
||
apiServerUrl := bootstrapData.ApiServerURL | ||
log.Printf("The API Server is at '%s'\n", apiServerUrl) | ||
|
||
apiClient := auth.GetAuthenticatedAPIClient(apiServerUrl, fileSystem, galasaHome, timeService, env) | ||
|
||
// Call to process command in unit-testable way. | ||
err = runs.CancelRun( | ||
cmd.values.runName, | ||
timeService, | ||
console, | ||
apiServerUrl, | ||
apiClient, | ||
) | ||
} | ||
} | ||
} | ||
|
||
log.Printf("executeRunsCancel returning %v\n", err) | ||
return err | ||
} |
Oops, something went wrong.