From 7773fc8269c4469bd1d655700549597e02dd884b Mon Sep 17 00:00:00 2001 From: Haytham Abuelfutuh Date: Sun, 16 Apr 2023 09:48:42 -0700 Subject: [PATCH] Enrich TerminateExecution error to tell propeller the execution already terminated (#551) * Enrich TerminateWorkflow error to tell propeller the execution already terminated Signed-off-by: Haytham Abuelfutuh * Fix unit test Signed-off-by: Haytham Abuelfutuh --------- Signed-off-by: Haytham Abuelfutuh --- flyteadmin/pkg/manager/impl/execution_manager.go | 4 +++- flyteadmin/pkg/manager/impl/execution_manager_test.go | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/flyteadmin/pkg/manager/impl/execution_manager.go b/flyteadmin/pkg/manager/impl/execution_manager.go index 4f4689715f..bf926319c0 100644 --- a/flyteadmin/pkg/manager/impl/execution_manager.go +++ b/flyteadmin/pkg/manager/impl/execution_manager.go @@ -1544,8 +1544,9 @@ func (m *ExecutionManager) TerminateExecution( logger.Infof(ctx, "couldn't find execution [%+v] to save termination cause", request.Id) return nil, err } + if common.IsExecutionTerminal(core.WorkflowExecution_Phase(core.WorkflowExecution_Phase_value[executionModel.Phase])) { - return nil, errors.NewFlyteAdminError(codes.PermissionDenied, "Cannot abort an already terminate workflow execution") + return nil, errors.NewAlreadyInTerminalStateError(ctx, "Cannot abort an already terminate workflow execution", executionModel.Phase) } err = transformers.SetExecutionAborting(&executionModel, request.Cause, getUser(ctx)) @@ -1553,6 +1554,7 @@ func (m *ExecutionManager) TerminateExecution( logger.Debugf(ctx, "failed to add abort metadata for execution [%+v] with err: %v", request.Id, err) return nil, err } + err = m.db.ExecutionRepo().Update(ctx, executionModel) if err != nil { logger.Debugf(ctx, "failed to save abort cause for terminated execution: %+v with err: %v", request.Id, err) diff --git a/flyteadmin/pkg/manager/impl/execution_manager_test.go b/flyteadmin/pkg/manager/impl/execution_manager_test.go index e8d16d348a..a3c384312f 100644 --- a/flyteadmin/pkg/manager/impl/execution_manager_test.go +++ b/flyteadmin/pkg/manager/impl/execution_manager_test.go @@ -3231,7 +3231,7 @@ func TestTerminateExecution_AlreadyTerminated(t *testing.T) { assert.Nil(t, resp) s, ok := status.FromError(err) assert.True(t, ok) - assert.Equal(t, codes.PermissionDenied, s.Code()) + assert.Equal(t, codes.FailedPrecondition, s.Code()) } func TestGetExecutionData(t *testing.T) {