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 fa56d43e43..50ebd78cf5 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,16 @@ public boolean isSuccessful() { @ProtoField(id = 25) private List history = new LinkedList<>(); + private String idempotencyKey; + + public String getIdempotencyKey() { + return idempotencyKey; + } + + public void setIdempotencyKey(String idempotencyKey) { + this.idempotencyKey = idempotencyKey; + } + public List getHistory() { return history; } 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(); } 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 613a01870a..da96269331 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<>();