From 129896c4bb29f6b4b420c80ae42cc118c5257675 Mon Sep 17 00:00:00 2001 From: manan164 <1897158+manan164@users.noreply.github.com> Date: Mon, 20 Nov 2023 23:11:57 +0530 Subject: [PATCH 1/6] Workflow idempotency changes --- .../workflow/IdempotencyStrategy.java | 18 +++++++++++++++++ .../workflow/StartWorkflowRequest.java | 20 +++++++++++++++++++ .../conductor/common/run/Workflow.java | 11 ++++++++++ .../conductor/model/WorkflowModel.java | 11 ++++++++++ .../conductor/grpc/AbstractProtoMapper.java | 4 ++++ grpc/src/main/proto/model/workflow.proto | 1 + 6 files changed, 65 insertions(+) create mode 100644 common/src/main/java/com/netflix/conductor/common/metadata/workflow/IdempotencyStrategy.java diff --git a/common/src/main/java/com/netflix/conductor/common/metadata/workflow/IdempotencyStrategy.java b/common/src/main/java/com/netflix/conductor/common/metadata/workflow/IdempotencyStrategy.java new file mode 100644 index 0000000000..a3d4397253 --- /dev/null +++ b/common/src/main/java/com/netflix/conductor/common/metadata/workflow/IdempotencyStrategy.java @@ -0,0 +1,18 @@ +/* + * Copyright 2020 Netflix, Inc. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package com.netflix.conductor.common.metadata.workflow; + +public enum IdempotencyStrategy { + FAIL, + RETURN_EXISTING +} diff --git a/common/src/main/java/com/netflix/conductor/common/metadata/workflow/StartWorkflowRequest.java b/common/src/main/java/com/netflix/conductor/common/metadata/workflow/StartWorkflowRequest.java index 5112fea6b5..fc99ce84e6 100644 --- a/common/src/main/java/com/netflix/conductor/common/metadata/workflow/StartWorkflowRequest.java +++ b/common/src/main/java/com/netflix/conductor/common/metadata/workflow/StartWorkflowRequest.java @@ -57,6 +57,26 @@ public class StartWorkflowRequest { @ProtoField(id = 9) private String createdBy; + private String idempotencyKey; + + private IdempotencyStrategy idempotencyStrategy; + + public String getIdempotencyKey() { + return idempotencyKey; + } + + public void setIdempotencyKey(String idempotencyKey) { + this.idempotencyKey = idempotencyKey; + } + + public IdempotencyStrategy getIdempotencyStrategy() { + return idempotencyStrategy; + } + + public void setIdempotencyStrategy(IdempotencyStrategy idempotencyStrategy) { + this.idempotencyStrategy = idempotencyStrategy; + } + public String getName() { return name; } diff --git a/common/src/main/java/com/netflix/conductor/common/run/Workflow.java b/common/src/main/java/com/netflix/conductor/common/run/Workflow.java index dc2455f0dd..8c79628ff4 100644 --- a/common/src/main/java/com/netflix/conductor/common/run/Workflow.java +++ b/common/src/main/java/com/netflix/conductor/common/run/Workflow.java @@ -126,6 +126,17 @@ public boolean isSuccessful() { @ProtoField(id = 25) private List history = new LinkedList<>(); + @ProtoField(id = 26) + private String idempotencyKey; + + public String getIdempotencyKey() { + return idempotencyKey; + } + + public void setIdempotencyKey(String idempotencyKey) { + this.idempotencyKey = idempotencyKey; + } + public List getHistory() { return history; } diff --git a/core/src/main/java/com/netflix/conductor/model/WorkflowModel.java b/core/src/main/java/com/netflix/conductor/model/WorkflowModel.java index 7e35e7b380..def0318d73 100644 --- a/core/src/main/java/com/netflix/conductor/model/WorkflowModel.java +++ b/core/src/main/java/com/netflix/conductor/model/WorkflowModel.java @@ -102,6 +102,7 @@ public boolean isSuccessful() { private String failedTaskId; private Status previousStatus; + private String idempotencyKey; private List history = new LinkedList<>(); @@ -449,6 +450,14 @@ public TaskModel getTaskByRefName(String refName) { return found.getLast(); } + public String getIdempotencyKey() { + return idempotencyKey; + } + + public void setIdempotencyKey(String idempotencyKey) { + this.idempotencyKey = idempotencyKey; + } + public void externalizeInput(String path) { this.inputPayload = this.input; this.input = new HashMap<>(); @@ -511,6 +520,7 @@ && getStatus() == that.getStatus() && Objects.equals(getCreateTime(), that.getCreateTime()) && Objects.equals(getUpdatedTime(), that.getUpdatedTime()) && Objects.equals(getCreatedBy(), that.getCreatedBy()) + && getIdempotencyKey() == that.getIdempotencyKey() && Objects.equals(getUpdatedBy(), that.getUpdatedBy()); } @@ -538,6 +548,7 @@ public int hashCode() { getVariables(), getLastRetriedTime(), getOwnerApp(), + getIdempotencyKey(), getCreateTime(), getUpdatedTime(), getCreatedBy(), diff --git a/grpc/src/main/java/com/netflix/conductor/grpc/AbstractProtoMapper.java b/grpc/src/main/java/com/netflix/conductor/grpc/AbstractProtoMapper.java index 2ff3d1d3f2..74b21af579 100644 --- a/grpc/src/main/java/com/netflix/conductor/grpc/AbstractProtoMapper.java +++ b/grpc/src/main/java/com/netflix/conductor/grpc/AbstractProtoMapper.java @@ -1082,6 +1082,9 @@ public WorkflowPb.Workflow toProto(Workflow from) { for (Workflow elem : from.getHistory()) { to.addHistory( toProto(elem) ); } + if (from.getIdempotencyKey() != null) { + to.setIdempotencyKey( from.getIdempotencyKey() ); + } return to.build(); } @@ -1122,6 +1125,7 @@ public Workflow fromProto(WorkflowPb.Workflow from) { to.setVariables(variablesMap); to.setLastRetriedTime( from.getLastRetriedTime() ); to.setHistory( from.getHistoryList().stream().map(this::fromProto).collect(Collectors.toCollection(ArrayList::new)) ); + to.setIdempotencyKey( from.getIdempotencyKey() ); return to; } diff --git a/grpc/src/main/proto/model/workflow.proto b/grpc/src/main/proto/model/workflow.proto index cf0793ea05..99a899dd81 100644 --- a/grpc/src/main/proto/model/workflow.proto +++ b/grpc/src/main/proto/model/workflow.proto @@ -39,4 +39,5 @@ message Workflow { map variables = 23; int64 last_retried_time = 24; repeated Workflow history = 25; + string idempotency_key = 26; } From f72dcba04d65b0b6432b138c2e70bf56a70d49b8 Mon Sep 17 00:00:00 2001 From: manan164 <1897158+manan164@users.noreply.github.com> Date: Tue, 21 Nov 2023 18:43:22 +0530 Subject: [PATCH 2/6] changes --- .../common/validation/ErrorResponse.java | 11 +++++++++++ .../core/exception/ApplicationException.java | 16 ++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/common/src/main/java/com/netflix/conductor/common/validation/ErrorResponse.java b/common/src/main/java/com/netflix/conductor/common/validation/ErrorResponse.java index 5ed6256e1d..6c247aca11 100644 --- a/common/src/main/java/com/netflix/conductor/common/validation/ErrorResponse.java +++ b/common/src/main/java/com/netflix/conductor/common/validation/ErrorResponse.java @@ -13,6 +13,7 @@ package com.netflix.conductor.common.validation; import java.util.List; +import java.util.Map; public class ErrorResponse { @@ -23,6 +24,16 @@ public class ErrorResponse { private boolean retryable; private List validationErrors; + private Map metadata; + + public Map getMetadata() { + return metadata; + } + + public void setMetadata(Map metadata) { + this.metadata = metadata; + } + public int getStatus() { return status; } diff --git a/core/src/main/java/com/netflix/conductor/core/exception/ApplicationException.java b/core/src/main/java/com/netflix/conductor/core/exception/ApplicationException.java index f1a086d403..e0aee23526 100644 --- a/core/src/main/java/com/netflix/conductor/core/exception/ApplicationException.java +++ b/core/src/main/java/com/netflix/conductor/core/exception/ApplicationException.java @@ -39,6 +39,16 @@ public int getStatusCode() { } } + public Map getMetadata() { + return metadata; + } + + public void setMetadata(Map metadata) { + this.metadata = metadata; + } + + private Map metadata; + private final Code code; public boolean isRetryable() { @@ -64,6 +74,12 @@ public ApplicationException(Code code, String message) { this.code = code; } + public ApplicationException(Code code, String message, Map metadata) { + super(message); + this.code = code; + this.metadata = metadata; + } + public int getHttpStatusCode() { return this.code.getStatusCode(); } From 68c810523aff92bfa6b9dbf17e702d28b7475c0d Mon Sep 17 00:00:00 2001 From: manan164 <1897158+manan164@users.noreply.github.com> Date: Mon, 27 Nov 2023 21:55:25 +0530 Subject: [PATCH 3/6] changes --- .../com/netflix/conductor/common/run/Workflow.java | 12 ++++++++++++ .../com/netflix/conductor/model/WorkflowModel.java | 14 ++++++++++++++ grpc/src/main/proto/model/workflow.proto | 1 + 3 files changed, 27 insertions(+) diff --git a/common/src/main/java/com/netflix/conductor/common/run/Workflow.java b/common/src/main/java/com/netflix/conductor/common/run/Workflow.java index 8c79628ff4..9a31583a29 100644 --- a/common/src/main/java/com/netflix/conductor/common/run/Workflow.java +++ b/common/src/main/java/com/netflix/conductor/common/run/Workflow.java @@ -18,6 +18,7 @@ import javax.validation.constraints.Max; import javax.validation.constraints.Min; +import com.netflix.conductor.common.metadata.workflow.IdempotencyStrategy; import org.apache.commons.lang3.StringUtils; import com.netflix.conductor.annotations.protogen.ProtoEnum; @@ -129,6 +130,9 @@ public boolean isSuccessful() { @ProtoField(id = 26) private String idempotencyKey; + @ProtoField(id = 27) + private String idempotencyStrategy; + public String getIdempotencyKey() { return idempotencyKey; } @@ -137,6 +141,14 @@ public void setIdempotencyKey(String idempotencyKey) { this.idempotencyKey = idempotencyKey; } + public String getIdempotencyStrategy() { + return idempotencyStrategy; + } + + public void setIdempotencyStrategy(String idempotencyStrategy) { + this.idempotencyStrategy = idempotencyStrategy; + } + public List getHistory() { return history; } diff --git a/core/src/main/java/com/netflix/conductor/model/WorkflowModel.java b/core/src/main/java/com/netflix/conductor/model/WorkflowModel.java index def0318d73..0e7b4a3773 100644 --- a/core/src/main/java/com/netflix/conductor/model/WorkflowModel.java +++ b/core/src/main/java/com/netflix/conductor/model/WorkflowModel.java @@ -15,6 +15,7 @@ import java.util.*; import java.util.stream.Collectors; +import com.netflix.conductor.common.metadata.workflow.IdempotencyStrategy; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; @@ -104,6 +105,8 @@ public boolean isSuccessful() { private Status previousStatus; private String idempotencyKey; + private String idempotencyStrategy; + private List history = new LinkedList<>(); public List getHistory() { @@ -458,6 +461,15 @@ public void setIdempotencyKey(String idempotencyKey) { this.idempotencyKey = idempotencyKey; } + + public String getIdempotencyStrategy() { + return idempotencyStrategy; + } + + public void setIdempotencyStrategy(String idempotencyStrategy) { + this.idempotencyStrategy = idempotencyStrategy; + } + public void externalizeInput(String path) { this.inputPayload = this.input; this.input = new HashMap<>(); @@ -521,6 +533,7 @@ && getStatus() == that.getStatus() && Objects.equals(getUpdatedTime(), that.getUpdatedTime()) && Objects.equals(getCreatedBy(), that.getCreatedBy()) && getIdempotencyKey() == that.getIdempotencyKey() + && getIdempotencyStrategy() == that.getIdempotencyStrategy() && Objects.equals(getUpdatedBy(), that.getUpdatedBy()); } @@ -549,6 +562,7 @@ public int hashCode() { getLastRetriedTime(), getOwnerApp(), getIdempotencyKey(), + getIdempotencyStrategy(), getCreateTime(), getUpdatedTime(), getCreatedBy(), diff --git a/grpc/src/main/proto/model/workflow.proto b/grpc/src/main/proto/model/workflow.proto index 99a899dd81..94927acf99 100644 --- a/grpc/src/main/proto/model/workflow.proto +++ b/grpc/src/main/proto/model/workflow.proto @@ -40,4 +40,5 @@ message Workflow { int64 last_retried_time = 24; repeated Workflow history = 25; string idempotency_key = 26; + string idempotency_strategy = 27; } From 1a17091259b2bd407831349d429f4b2b507c13fb Mon Sep 17 00:00:00 2001 From: manan164 <1897158+manan164@users.noreply.github.com> Date: Wed, 29 Nov 2023 10:44:56 +0530 Subject: [PATCH 4/6] review comments. --- .../com/netflix/conductor/common/run/Workflow.java | 13 ------------- .../netflix/conductor/grpc/AbstractProtoMapper.java | 4 ---- 2 files changed, 17 deletions(-) diff --git a/common/src/main/java/com/netflix/conductor/common/run/Workflow.java b/common/src/main/java/com/netflix/conductor/common/run/Workflow.java index 9a31583a29..eddff2dee6 100644 --- a/common/src/main/java/com/netflix/conductor/common/run/Workflow.java +++ b/common/src/main/java/com/netflix/conductor/common/run/Workflow.java @@ -18,7 +18,6 @@ import javax.validation.constraints.Max; import javax.validation.constraints.Min; -import com.netflix.conductor.common.metadata.workflow.IdempotencyStrategy; import org.apache.commons.lang3.StringUtils; import com.netflix.conductor.annotations.protogen.ProtoEnum; @@ -127,12 +126,8 @@ public boolean isSuccessful() { @ProtoField(id = 25) private List history = new LinkedList<>(); - @ProtoField(id = 26) private String idempotencyKey; - @ProtoField(id = 27) - private String idempotencyStrategy; - public String getIdempotencyKey() { return idempotencyKey; } @@ -141,14 +136,6 @@ public void setIdempotencyKey(String idempotencyKey) { this.idempotencyKey = idempotencyKey; } - public String getIdempotencyStrategy() { - return idempotencyStrategy; - } - - public void setIdempotencyStrategy(String idempotencyStrategy) { - this.idempotencyStrategy = idempotencyStrategy; - } - public List getHistory() { return history; } diff --git a/grpc/src/main/java/com/netflix/conductor/grpc/AbstractProtoMapper.java b/grpc/src/main/java/com/netflix/conductor/grpc/AbstractProtoMapper.java index 74b21af579..2ff3d1d3f2 100644 --- a/grpc/src/main/java/com/netflix/conductor/grpc/AbstractProtoMapper.java +++ b/grpc/src/main/java/com/netflix/conductor/grpc/AbstractProtoMapper.java @@ -1082,9 +1082,6 @@ public WorkflowPb.Workflow toProto(Workflow from) { for (Workflow elem : from.getHistory()) { to.addHistory( toProto(elem) ); } - if (from.getIdempotencyKey() != null) { - to.setIdempotencyKey( from.getIdempotencyKey() ); - } return to.build(); } @@ -1125,7 +1122,6 @@ public Workflow fromProto(WorkflowPb.Workflow from) { to.setVariables(variablesMap); to.setLastRetriedTime( from.getLastRetriedTime() ); to.setHistory( from.getHistoryList().stream().map(this::fromProto).collect(Collectors.toCollection(ArrayList::new)) ); - to.setIdempotencyKey( from.getIdempotencyKey() ); return to; } From bfa708f81f7749ad77983bbe2253f9c7db9ee981 Mon Sep 17 00:00:00 2001 From: manan164 <1897158+manan164@users.noreply.github.com> Date: Wed, 29 Nov 2023 10:46:31 +0530 Subject: [PATCH 5/6] removing from proto --- grpc/src/main/proto/model/workflow.proto | 2 -- 1 file changed, 2 deletions(-) diff --git a/grpc/src/main/proto/model/workflow.proto b/grpc/src/main/proto/model/workflow.proto index 94927acf99..cf0793ea05 100644 --- a/grpc/src/main/proto/model/workflow.proto +++ b/grpc/src/main/proto/model/workflow.proto @@ -39,6 +39,4 @@ message Workflow { map variables = 23; int64 last_retried_time = 24; repeated Workflow history = 25; - string idempotency_key = 26; - string idempotency_strategy = 27; } From 7cafbb8436d92479b7a3d69c676b42638bd78ae6 Mon Sep 17 00:00:00 2001 From: manan164 <1897158+manan164@users.noreply.github.com> Date: Wed, 29 Nov 2023 11:26:07 +0530 Subject: [PATCH 6/6] remove idempotencyStrategy from workflow model --- .../com/netflix/conductor/model/WorkflowModel.java | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/core/src/main/java/com/netflix/conductor/model/WorkflowModel.java b/core/src/main/java/com/netflix/conductor/model/WorkflowModel.java index 0e7b4a3773..def0318d73 100644 --- a/core/src/main/java/com/netflix/conductor/model/WorkflowModel.java +++ b/core/src/main/java/com/netflix/conductor/model/WorkflowModel.java @@ -15,7 +15,6 @@ import java.util.*; import java.util.stream.Collectors; -import com.netflix.conductor.common.metadata.workflow.IdempotencyStrategy; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; @@ -105,8 +104,6 @@ public boolean isSuccessful() { private Status previousStatus; private String idempotencyKey; - private String idempotencyStrategy; - private List history = new LinkedList<>(); public List getHistory() { @@ -461,15 +458,6 @@ public void setIdempotencyKey(String idempotencyKey) { this.idempotencyKey = idempotencyKey; } - - public String getIdempotencyStrategy() { - return idempotencyStrategy; - } - - public void setIdempotencyStrategy(String idempotencyStrategy) { - this.idempotencyStrategy = idempotencyStrategy; - } - public void externalizeInput(String path) { this.inputPayload = this.input; this.input = new HashMap<>(); @@ -533,7 +521,6 @@ && getStatus() == that.getStatus() && Objects.equals(getUpdatedTime(), that.getUpdatedTime()) && Objects.equals(getCreatedBy(), that.getCreatedBy()) && getIdempotencyKey() == that.getIdempotencyKey() - && getIdempotencyStrategy() == that.getIdempotencyStrategy() && Objects.equals(getUpdatedBy(), that.getUpdatedBy()); } @@ -562,7 +549,6 @@ public int hashCode() { getLastRetriedTime(), getOwnerApp(), getIdempotencyKey(), - getIdempotencyStrategy(), getCreateTime(), getUpdatedTime(), getCreatedBy(),