Skip to content
This repository was archived by the owner on Oct 9, 2023. It is now read-only.

Commit 2a216f5

Browse files
authored
Cannot abort an already terminated execution (#454)
Signed-off-by: Katrina Rogan <[email protected]>
1 parent a96084f commit 2a216f5

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

pkg/manager/impl/execution_manager.go

+3
Original file line numberDiff line numberDiff line change
@@ -1650,6 +1650,9 @@ func (m *ExecutionManager) TerminateExecution(
16501650
logger.Infof(ctx, "couldn't find execution [%+v] to save termination cause", request.Id)
16511651
return nil, err
16521652
}
1653+
if common.IsExecutionTerminal(core.WorkflowExecution_Phase(core.WorkflowExecution_Phase_value[executionModel.Phase])) {
1654+
return nil, errors.NewFlyteAdminError(codes.PermissionDenied, "Cannot abort an already terminate workflow execution")
1655+
}
16531656

16541657
err = transformers.SetExecutionAborting(&executionModel, request.Cause, getUser(ctx))
16551658
if err != nil {

pkg/manager/impl/execution_manager_test.go

+32
Original file line numberDiff line numberDiff line change
@@ -2912,6 +2912,38 @@ func TestTerminateExecution_DatabaseError(t *testing.T) {
29122912
assert.EqualError(t, err, expectedError.Error())
29132913
}
29142914

2915+
func TestTerminateExecution_AlreadyTerminated(t *testing.T) {
2916+
var expectedError = errors.New("expected error")
2917+
2918+
mockExecutor := workflowengineMocks.WorkflowExecutor{}
2919+
mockExecutor.OnAbortMatch(mock.Anything, mock.Anything).Return(expectedError)
2920+
mockExecutor.OnID().Return("customMockExecutor")
2921+
r := plugins.NewRegistry()
2922+
r.RegisterDefault(plugins.PluginIDWorkflowExecutor, &mockExecutor)
2923+
2924+
repository := repositoryMocks.NewMockRepository()
2925+
repository.ExecutionRepo().(*repositoryMocks.MockExecutionRepo).SetGetCallback(
2926+
func(ctx context.Context, input interfaces.Identifier) (models.Execution, error) {
2927+
return models.Execution{
2928+
Phase: core.WorkflowExecution_SUCCEEDED.String(),
2929+
}, nil
2930+
})
2931+
execManager := NewExecutionManager(repository, r, getMockExecutionsConfigProvider(), getMockStorageForExecTest(context.Background()), mockScope.NewTestScope(), mockScope.NewTestScope(), &mockPublisher, mockExecutionRemoteURL, nil, nil, nil, nil, &eventWriterMocks.WorkflowExecutionEventWriter{})
2932+
resp, err := execManager.TerminateExecution(context.Background(), admin.ExecutionTerminateRequest{
2933+
Id: &core.WorkflowExecutionIdentifier{
2934+
Project: "project",
2935+
Domain: "domain",
2936+
Name: "name",
2937+
},
2938+
Cause: "abort cause",
2939+
})
2940+
2941+
assert.Nil(t, resp)
2942+
s, ok := status.FromError(err)
2943+
assert.True(t, ok)
2944+
assert.Equal(t, codes.PermissionDenied, s.Code())
2945+
}
2946+
29152947
func TestGetExecutionData(t *testing.T) {
29162948
repository := repositoryMocks.NewMockRepository()
29172949
startedAt := time.Date(2018, 8, 30, 0, 0, 0, 0, time.UTC)

0 commit comments

Comments
 (0)