-
Notifications
You must be signed in to change notification settings - Fork 669
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added Update Execution cli Signed-off-by: Prafulla Mahindrakar <[email protected]> * Added unit tests Signed-off-by: Prafulla Mahindrakar <[email protected]> * reset Signed-off-by: Prafulla Mahindrakar <[email protected]> * nit Signed-off-by: Prafulla Mahindrakar <[email protected]>
- Loading branch information
1 parent
f079e1d
commit a101cd6
Showing
10 changed files
with
373 additions
and
7 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package execution | ||
|
||
//go:generate pflags UpdateConfig --default-var UConfig --bind-default-var | ||
var ( | ||
UConfig = &UpdateConfig{} | ||
) | ||
|
||
// UpdateConfig | ||
type UpdateConfig struct { | ||
Archive bool `json:"archive" pflag:",archive execution."` | ||
Activate bool `json:"activate" pflag:",activate execution."` | ||
DryRun bool `json:"dryRun" pflag:",execute command without making any modifications."` | ||
} |
57 changes: 57 additions & 0 deletions
57
flytectl/cmd/config/subcommand/execution/updateconfig_flags.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
144 changes: 144 additions & 0 deletions
144
flytectl/cmd/config/subcommand/execution/updateconfig_flags_test.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,73 @@ | ||
package update | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/flyteorg/flytectl/clierrors" | ||
"github.com/flyteorg/flytectl/cmd/config" | ||
"github.com/flyteorg/flytectl/cmd/config/subcommand/execution" | ||
cmdCore "github.com/flyteorg/flytectl/cmd/core" | ||
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" | ||
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core" | ||
"github.com/flyteorg/flytestdlib/logger" | ||
) | ||
|
||
const ( | ||
updateExecutionShort = "Update execution status" | ||
updateExecutionLong = ` | ||
Activating an execution shows it in the cli and UI: | ||
:: | ||
flytectl update execution -p flytectldemo -d development oeh94k9r2r --activate | ||
Archiving execution hides it from cli and UI: | ||
:: | ||
flytectl update execution -p flytectldemo -d development oeh94k9r2r --archive | ||
Usage | ||
` | ||
) | ||
|
||
func updateExecutionFunc(ctx context.Context, args []string, cmdCtx cmdCore.CommandContext) error { | ||
project := config.GetConfig().Project | ||
domain := config.GetConfig().Domain | ||
if len(args) != 1 { | ||
return fmt.Errorf(clierrors.ErrExecutionNotPassed) | ||
} | ||
executionName := args[0] | ||
activateExec := execution.UConfig.Activate | ||
archiveExec := execution.UConfig.Archive | ||
if activateExec && archiveExec { | ||
return fmt.Errorf(clierrors.ErrInvalidStateUpdate) | ||
} | ||
|
||
var executionState admin.ExecutionStatus_ExecutionState | ||
if activateExec { | ||
executionState = admin.ExecutionStatus_EXECUTION_ACTIVE | ||
} else if archiveExec { | ||
executionState = admin.ExecutionStatus_EXECUTION_ARCHIVED | ||
} | ||
|
||
if execution.UConfig.DryRun { | ||
logger.Debugf(ctx, "skipping UpdateExecution request (DryRun)") | ||
} else { | ||
_, err := cmdCtx.AdminClient().UpdateExecution(ctx, &admin.ExecutionUpdateRequest{ | ||
Id: &core.WorkflowExecutionIdentifier{ | ||
Project: project, | ||
Domain: domain, | ||
Name: executionName, | ||
}, | ||
Status: &admin.ExecutionStatus{State: executionState}, | ||
}) | ||
if err != nil { | ||
fmt.Printf(clierrors.ErrFailedExecutionUpdate, executionName, err) | ||
return err | ||
} | ||
} | ||
fmt.Printf("updated execution %s successfully to state %s\n", executionName, executionState.String()) | ||
|
||
return nil | ||
} |
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,71 @@ | ||
package update | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/flyteorg/flytectl/cmd/config/subcommand/execution" | ||
"github.com/flyteorg/flytectl/cmd/testutils" | ||
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
func UpdateExecutionSetup() { | ||
ctx = testutils.Ctx | ||
cmdCtx = testutils.CmdCtx | ||
mockClient = testutils.MockClient | ||
} | ||
|
||
func TestExecutionUpdate(t *testing.T) { | ||
testutils.Setup() | ||
UpdateExecutionSetup() | ||
args = []string{"execution1"} | ||
// Activate | ||
execution.UConfig.Activate = true | ||
mockClient.OnUpdateExecutionMatch(mock.Anything, mock.Anything).Return(&admin.ExecutionUpdateResponse{}, nil) | ||
assert.Nil(t, updateExecutionFunc(ctx, args, cmdCtx)) | ||
// Archive | ||
execution.UConfig.Activate = false | ||
execution.UConfig.Archive = true | ||
assert.Nil(t, updateExecutionFunc(ctx, args, cmdCtx)) | ||
// Reset | ||
execution.UConfig.Activate = false | ||
execution.UConfig.Archive = false | ||
|
||
// Dry run | ||
execution.UConfig.DryRun = true | ||
assert.Nil(t, updateExecutionFunc(ctx, args, cmdCtx)) | ||
mockClient.AssertNotCalled(t, "UpdateExecution", mock.Anything) | ||
|
||
// Reset | ||
execution.UConfig.DryRun = false | ||
} | ||
|
||
func TestExecutionUpdateValidationFailure(t *testing.T) { | ||
testutils.Setup() | ||
UpdateExecutionSetup() | ||
args = []string{"execution1"} | ||
execution.UConfig.Activate = true | ||
execution.UConfig.Archive = true | ||
assert.NotNil(t, updateExecutionFunc(ctx, args, cmdCtx)) | ||
// Reset | ||
execution.UConfig.Activate = false | ||
execution.UConfig.Archive = false | ||
} | ||
|
||
func TestExecutionUpdateFail(t *testing.T) { | ||
testutils.Setup() | ||
UpdateExecutionSetup() | ||
args = []string{"execution1"} | ||
mockClient.OnUpdateExecutionMatch(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed to update")) | ||
assert.NotNil(t, updateExecutionFunc(ctx, args, cmdCtx)) | ||
} | ||
|
||
func TestExecutionUpdateInvalidArgs(t *testing.T) { | ||
testutils.Setup() | ||
UpdateExecutionSetup() | ||
args = []string{} | ||
assert.NotNil(t, updateExecutionFunc(ctx, args, cmdCtx)) | ||
} |
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
Oops, something went wrong.