From 5952cac6e3dad896a24a5082be328b3d443723b4 Mon Sep 17 00:00:00 2001 From: sangeetanadgir Date: Mon, 14 Oct 2024 14:17:01 +0530 Subject: [PATCH] ONECOND-2338-Remove Decoded Auth Token from Response --- .../conductor/common/run/WorkflowDetails.java | 493 ++++++++++++++++++ .../netflix/conductor/dao/ExecutionDAO.java | 7 +- .../conductor/service/ExecutionService.java | 5 + .../dao/es5/ElasticSearch5ExecutionDAO.java | 10 +- .../dao/Elasticsearch6RestExecutionDAO.java | 10 +- .../server/resources/WorkflowResource.java | 4 +- .../conductor/aurora/AuroraExecutionDAO.java | 23 +- .../dao/dynomite/RedisExecutionDAO.java | 10 +- 8 files changed, 540 insertions(+), 22 deletions(-) create mode 100644 common/src/main/java/com/netflix/conductor/common/run/WorkflowDetails.java diff --git a/common/src/main/java/com/netflix/conductor/common/run/WorkflowDetails.java b/common/src/main/java/com/netflix/conductor/common/run/WorkflowDetails.java new file mode 100644 index 0000000000..e507526981 --- /dev/null +++ b/common/src/main/java/com/netflix/conductor/common/run/WorkflowDetails.java @@ -0,0 +1,493 @@ +/** + * Copyright 2016 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.run; + +import com.netflix.conductor.common.metadata.Auditable; +import com.netflix.conductor.common.metadata.tasks.Task; +import org.postgresql.util.PGobject; + +import java.util.*; + +public class WorkflowDetails extends Auditable { + + public enum WorkflowStatus { + RUNNING(false, false), COMPLETED(true, true), FAILED(true, false), TIMED_OUT(true, false), TERMINATED(true, false), CANCELLED(true, false), PAUSED(false, true), RESET(true, false); + + private boolean terminal; + + private boolean successful; + + WorkflowStatus(boolean terminal, boolean successful){ + this.terminal = terminal; + this.successful = successful; + } + + public boolean isTerminal(){ + return terminal; + } + + public boolean isSuccessful(){ + return successful; + } + } + + private long revision = 1; + + private WorkflowStatus status = WorkflowStatus.RUNNING; + + private long endTime; + + private String workflowId; + + private String parentWorkflowId; + + private String parentWorkflowTaskId; + + private List tasks = new LinkedList<>(); + + private Map input = new HashMap<>(); + + private Map output = new HashMap<>();; + + private Map attributes = new HashMap<>();; + + private String workflowType; + + private int version; + + private String correlationId; + + private String reRunFromWorkflowId; + + private String reasonForIncompletion; + + private int schemaVersion; + + private String event; + + private Map taskToDomain = new HashMap<>(); + + private List workflowIds = new ArrayList<>(); + + private String contextToken; + + private String contextUser; + + private String clientId; + + private Set tags = new HashSet<>(); + + private int restartCount; + + private int rerunCount; + + private String cancelledBy; + + private String traceId; + + private boolean resetTags; + + private int jobPriority = 5; + + private Map variables = new HashMap<>(); + + private Map metaConfigs = new HashMap<>(); + + private Map priorityConfig = new HashMap<>(); + + private PGobject jsonDataWorkflowIds; + + + public WorkflowDetails(){ + + } + /** + * @return the status + */ + public WorkflowStatus getStatus() { + return status; + } + + /** + * @param status the status to set + */ + public void setStatus(WorkflowStatus status) { + this.status = status; + } + + /** + * @return the startTime + */ + public long getStartTime() { + return getCreateTime(); + } + + /** + * @param startTime the startTime to set + */ + public void setStartTime(long startTime) { + this.setCreateTime(startTime); + } + + /** + * @return the endTime + */ + public long getEndTime() { + return endTime; + } + + /** + * @param endTime the endTime to set + */ + public void setEndTime(long endTime) { + this.endTime = endTime; + } + + /** + * @return the duration of the workflow + */ + public long getDuration() { + return getEndTime() - getStartTime(); + } + + /** + * @return the workflowId + */ + public String getWorkflowId() { + return workflowId; + } + /** + * @param workflowId the workflowId to set + */ + public void setWorkflowId(String workflowId) { + this.workflowId = workflowId; + } + /** + * @return the tasks which are scheduled, in progress or completed. + */ + public List getTasks() { + return tasks; + } + /** + * @param tasks the tasks to set + */ + public void setTasks(List tasks) { + this.tasks = tasks; + } + + /** + * @return the input + */ + public Map getInput() { + return input; + } + /** + * @param input the input to set + */ + public void setInput(Map input) { + this.input = input; + } + /** + * @return the task to domain map + */ + public Map getTaskToDomain() { + return taskToDomain; + } + /** + * @param taskToDomain the task to domain map + */ + public void setTaskToDomain(Map taskToDomain) { + this.taskToDomain = taskToDomain; + } + /** + * @return the output + */ + public Map getOutput() { + return output; + } + /** + * @param output the output to set + */ + public void setOutput(Map output) { + this.output = output; + } + + /** + * + * @return The correlation id used when starting the workflow + */ + public String getCorrelationId() { + return correlationId; + } + + /** + * + * @param correlationId the correlation id + */ + public void setCorrelationId(String correlationId) { + this.correlationId = correlationId; + } + + /** + * + * @return Workflow Type / Definition + */ + public String getWorkflowType() { + return workflowType; + } + + /** + * + * @param workflowType Workflow type + */ + public void setWorkflowType(String workflowType) { + this.workflowType = workflowType; + } + + + /** + * @return the version + */ + public int getVersion() { + return version; + } + /** + * @param version the version to set + */ + public void setVersion(int version) { + this.version = version; + } + + public String getReRunFromWorkflowId() { + return reRunFromWorkflowId; + } + + public void setReRunFromWorkflowId(String reRunFromWorkflowId) { + this.reRunFromWorkflowId = reRunFromWorkflowId; + } + + public String getReasonForIncompletion() { + return reasonForIncompletion; + } + + public void setReasonForIncompletion(String reasonForIncompletion) { + this.reasonForIncompletion = reasonForIncompletion; + } + + /** + * @return the parentWorkflowId + */ + public String getParentWorkflowId() { + return parentWorkflowId; + } + /** + * @param parentWorkflowId the parentWorkflowId to set + */ + public void setParentWorkflowId(String parentWorkflowId) { + this.parentWorkflowId = parentWorkflowId; + } + + /** + * @return whether this workflow is a sub-workflow. + */ + public boolean isSubWorkflow() { + final String parentId = getParentWorkflowId(); + + return parentId != null ? !parentId.isEmpty() : false; + } + + /** + * @return the parentWorkflowTaskId + */ + public String getParentWorkflowTaskId() { + return parentWorkflowTaskId; + } + /** + * @param parentWorkflowTaskId the parentWorkflowTaskId to set + */ + public void setParentWorkflowTaskId(String parentWorkflowTaskId) { + this.parentWorkflowTaskId = parentWorkflowTaskId; + } + /** + * @return the schemaVersion Version of the schema for the workflow definition + */ + public int getSchemaVersion() { + return schemaVersion; + } + /** + * @param schemaVersion the schemaVersion to set + */ + public void setSchemaVersion(int schemaVersion) { + this.schemaVersion = schemaVersion; + } + + /** + * + * @return Name of the event that started the workflow + */ + public String getEvent() { + return event; + } + + /** + * + * @param event Name of the event that started the workflow + */ + public void setEvent(String event) { + this.event = event; + } + + public List getWorkflowIds() { + return workflowIds; + } + + public void setWorkflowIds(List workflowIds) { + this.workflowIds = workflowIds; + } + + public String getContextToken() { + return contextToken; + } + + public void setContextToken(String contextToken) { + this.contextToken = contextToken; + } + + public String getContextUser() { + return contextUser; + } + + public void setContextUser(String contextUser) { + this.contextUser = contextUser; + } + + public String getClientId() { + return clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public Set getTags() { + return tags; + } + + public void setTags(Set tags) { + this.tags = tags; + } + + public int getRestartCount() { + return restartCount; + } + + public void setRestartCount(int restartCount) { + this.restartCount = restartCount; + } + + public void incRestartCount() { + this.restartCount++; + } + + public String getCancelledBy() { + return cancelledBy; + } + + public void setCancelledBy(String cancelledBy) { + this.cancelledBy = cancelledBy; + } + + public int getRerunCount() { + return rerunCount; + } + + public void setRerunCount(int rerunCount) { + this.rerunCount = rerunCount; + } + + public void incRerunCount() { + this.rerunCount++; + } + + public String getTraceId() { + return traceId; + } + + public void setTraceId(String traceId) { + this.traceId = traceId; + } + + public int getJobPriority() { + return jobPriority; + } + + public void setJobPriority(int jobPriority) { + this.jobPriority = jobPriority; + } + + public Map getAttributes() { + return attributes; + } + + public void setAttributes(Map attributes) { + this.attributes = attributes; + } + + public boolean getResetTags() { + return resetTags; + } + + public void setResetTags(boolean resetTags) { + this.resetTags = resetTags; + } + + public PGobject getJsonDataWorkflowIds() { + return jsonDataWorkflowIds; + } + + public void setJsonDataWorkflowIds(PGobject jsonDataWorkflowIds) { + this.jsonDataWorkflowIds = jsonDataWorkflowIds; + } + + @Override + public String toString() { + return workflowType + "." + version + "/" + workflowId + "." + status; + } + + public Map getVariables() { + return variables; + } + + public void setVariables(Map variables) { + this.variables = variables; + } + + public Map getMetaConfigs() { + return metaConfigs; + } + + public void setMetaConfigs(Map metaConfigs) { + this.metaConfigs = metaConfigs; + } + + public Map getPriorityConfig() { + return priorityConfig; + } + + public void setPriorityConfig(Map priorityConfig) { + this.priorityConfig = priorityConfig; + } +} diff --git a/core/src/main/java/com/netflix/conductor/dao/ExecutionDAO.java b/core/src/main/java/com/netflix/conductor/dao/ExecutionDAO.java index 568c094315..7a10ee69bc 100644 --- a/core/src/main/java/com/netflix/conductor/dao/ExecutionDAO.java +++ b/core/src/main/java/com/netflix/conductor/dao/ExecutionDAO.java @@ -24,10 +24,7 @@ import com.netflix.conductor.common.metadata.tasks.Task; import com.netflix.conductor.common.metadata.tasks.TaskDef; import com.netflix.conductor.common.metadata.tasks.TaskExecLog; -import com.netflix.conductor.common.run.TaskDetails; -import com.netflix.conductor.common.run.Workflow; -import com.netflix.conductor.common.run.WorkflowError; -import com.netflix.conductor.common.run.WorkflowErrorRegistry; +import com.netflix.conductor.common.run.*; import com.netflix.conductor.core.events.queue.Message; import java.util.Collections; @@ -215,6 +212,8 @@ default List getPendingSystemTasks(String taskType) { */ Workflow getWorkflow(String workflowId, boolean includeTasks); + WorkflowDetails getWorkflowDetails(String workflowId, boolean includeTasks); + /** * * @param workflowName Name of the workflow diff --git a/core/src/main/java/com/netflix/conductor/service/ExecutionService.java b/core/src/main/java/com/netflix/conductor/service/ExecutionService.java index 094a51454b..0b5c7c05e9 100644 --- a/core/src/main/java/com/netflix/conductor/service/ExecutionService.java +++ b/core/src/main/java/com/netflix/conductor/service/ExecutionService.java @@ -25,6 +25,7 @@ import com.netflix.conductor.common.metadata.workflow.WorkflowDef; import com.netflix.conductor.common.run.SearchResult; import com.netflix.conductor.common.run.Workflow; +import com.netflix.conductor.common.run.WorkflowDetails; import com.netflix.conductor.common.run.WorkflowSummary; import com.netflix.conductor.core.config.Configuration; import com.netflix.conductor.core.events.queue.Message; @@ -339,6 +340,10 @@ public Workflow getExecutionStatus(String workflowId, boolean includeTasks) { return edao.getWorkflow(workflowId, includeTasks); } + public WorkflowDetails getExecutionStatusDetails(String workflowId, boolean includeTasks) { + return edao.getWorkflowDetails(workflowId, includeTasks); + } + public List getRunningWorkflows(String workflowName) { return edao.getRunningWorkflowIds(workflowName); } diff --git a/es5-persistence/src/main/java/com/netflix/conductor/dao/es5/ElasticSearch5ExecutionDAO.java b/es5-persistence/src/main/java/com/netflix/conductor/dao/es5/ElasticSearch5ExecutionDAO.java index f37bf94d15..5fdf1be4a5 100644 --- a/es5-persistence/src/main/java/com/netflix/conductor/dao/es5/ElasticSearch5ExecutionDAO.java +++ b/es5-persistence/src/main/java/com/netflix/conductor/dao/es5/ElasticSearch5ExecutionDAO.java @@ -24,10 +24,7 @@ import com.netflix.conductor.common.metadata.tasks.Task; import com.netflix.conductor.common.metadata.tasks.TaskDef; import com.netflix.conductor.common.metadata.tasks.TaskExecLog; -import com.netflix.conductor.common.run.TaskDetails; -import com.netflix.conductor.common.run.Workflow; -import com.netflix.conductor.common.run.WorkflowError; -import com.netflix.conductor.common.run.WorkflowErrorRegistry; +import com.netflix.conductor.common.run.*; import com.netflix.conductor.core.config.Configuration; import com.netflix.conductor.core.events.queue.Message; import com.netflix.conductor.core.execution.ApplicationException; @@ -385,6 +382,11 @@ public Workflow getWorkflow(String workflowId) { return getWorkflow(workflowId, true); } + @Override + public WorkflowDetails getWorkflowDetails(String workflowId, boolean includeTasks) { + return null; + } + @Override public Workflow getWorkflow(String workflowId, boolean includeTasks) { if (logger.isDebugEnabled()) diff --git a/es6rest-persistence/src/main/java/com/netflix/conductor/dao/es6rest/dao/Elasticsearch6RestExecutionDAO.java b/es6rest-persistence/src/main/java/com/netflix/conductor/dao/es6rest/dao/Elasticsearch6RestExecutionDAO.java index 1c50b0a9d8..b61b60599c 100644 --- a/es6rest-persistence/src/main/java/com/netflix/conductor/dao/es6rest/dao/Elasticsearch6RestExecutionDAO.java +++ b/es6rest-persistence/src/main/java/com/netflix/conductor/dao/es6rest/dao/Elasticsearch6RestExecutionDAO.java @@ -25,13 +25,10 @@ import com.netflix.conductor.common.metadata.tasks.Task; import com.netflix.conductor.common.metadata.tasks.TaskDef; import com.netflix.conductor.common.metadata.tasks.TaskExecLog; -import com.netflix.conductor.common.run.TaskDetails; -import com.netflix.conductor.common.run.Workflow; -import com.netflix.conductor.common.run.WorkflowError; +import com.netflix.conductor.common.run.*; import com.netflix.conductor.core.config.Configuration; import com.netflix.conductor.core.events.queue.Message; import com.netflix.conductor.core.execution.ApplicationException; -import com.netflix.conductor.common.run.WorkflowErrorRegistry; import com.netflix.conductor.dao.ExecutionDAO; import com.netflix.conductor.dao.IndexDAO; import com.netflix.conductor.dao.MetadataDAO; @@ -497,6 +494,11 @@ public Workflow getWorkflow(String workflowId, boolean includeTasks) { return workflow; } + @Override + public WorkflowDetails getWorkflowDetails(String workflowId, boolean includeTasks) { + return null; + } + @Override public List getRunningWorkflowIds(String workflowName) { if (logger.isDebugEnabled()) diff --git a/jersey/src/main/java/com/netflix/conductor/server/resources/WorkflowResource.java b/jersey/src/main/java/com/netflix/conductor/server/resources/WorkflowResource.java index d986c5956f..6fb6b2f8bb 100644 --- a/jersey/src/main/java/com/netflix/conductor/server/resources/WorkflowResource.java +++ b/jersey/src/main/java/com/netflix/conductor/server/resources/WorkflowResource.java @@ -336,10 +336,10 @@ public List getWorkflows(@PathParam("name") String name, @PathParam("c @ApiImplicitParams({@ApiImplicitParam(name = "Deluxe-Owf-Context", dataType = "string", paramType = "header"), @ApiImplicitParam(name = "Platform-Trace-Id", dataType = "string", paramType = "header")}) @Consumes(MediaType.WILDCARD) - public Workflow getExecutionStatus( + public WorkflowDetails getExecutionStatus( @PathParam("workflowId") String workflowId, @QueryParam("includeTasks") @DefaultValue("true") boolean includeTasks) throws Exception { - return service.getExecutionStatus(workflowId, includeTasks); + return service.getExecutionStatusDetails(workflowId, includeTasks); } @DELETE diff --git a/postgresql-persistence/src/main/java/com/netflix/conductor/aurora/AuroraExecutionDAO.java b/postgresql-persistence/src/main/java/com/netflix/conductor/aurora/AuroraExecutionDAO.java index e0f2331b62..92c41378e0 100644 --- a/postgresql-persistence/src/main/java/com/netflix/conductor/aurora/AuroraExecutionDAO.java +++ b/postgresql-persistence/src/main/java/com/netflix/conductor/aurora/AuroraExecutionDAO.java @@ -9,10 +9,7 @@ import com.netflix.conductor.common.metadata.tasks.Task; import com.netflix.conductor.common.metadata.tasks.TaskDef; import com.netflix.conductor.common.metadata.tasks.TaskExecLog; -import com.netflix.conductor.common.run.TaskDetails; -import com.netflix.conductor.common.run.Workflow; -import com.netflix.conductor.common.run.WorkflowError; -import com.netflix.conductor.common.run.WorkflowErrorRegistry; +import com.netflix.conductor.common.run.*; import com.netflix.conductor.core.events.queue.Message; import com.netflix.conductor.core.execution.ApplicationException; import com.netflix.conductor.dao.ExecutionDAO; @@ -323,6 +320,17 @@ public Workflow getWorkflow(String workflowId, boolean includeTasks) { return workflow; } + @Override + public WorkflowDetails getWorkflowDetails(String workflowId, boolean includeTasks) { + WorkflowDetails workflow = getWithTransaction(tx -> readWorkflowDetails(tx, workflowId)); + if (workflow != null && includeTasks) { + List tasks = getTasksForWorkflow(workflowId); + tasks.sort(Comparator.comparingLong(Task::getScheduledTime).thenComparingInt(Task::getSeq)); + workflow.setTasks(tasks); + } + return workflow; + } + @Override public List getRunningWorkflowIds(String workflowName) { Preconditions.checkNotNull(workflowName, "workflowName cannot be null"); @@ -781,6 +789,13 @@ private Workflow readWorkflow(Connection tx, String workflowId) { return query(tx, SQL, q -> q.addParameter(workflowId).executeAndFetchFirst(Workflow.class)); } + + private WorkflowDetails readWorkflowDetails(Connection tx, String workflowId) { + String SQL = "SELECT json_data FROM workflow WHERE workflow_id = ?"; + + return query(tx, SQL, q -> q.addParameter(workflowId).executeAndFetchFirst(WorkflowDetails.class)); + } + private void removeWorkflow(Connection tx, String workflowId) { String SQL = "DELETE FROM workflow WHERE workflow_id = ?"; diff --git a/redis-persistence/src/main/java/com/netflix/conductor/dao/dynomite/RedisExecutionDAO.java b/redis-persistence/src/main/java/com/netflix/conductor/dao/dynomite/RedisExecutionDAO.java index 6ebc0f0ce2..3bb646223d 100644 --- a/redis-persistence/src/main/java/com/netflix/conductor/dao/dynomite/RedisExecutionDAO.java +++ b/redis-persistence/src/main/java/com/netflix/conductor/dao/dynomite/RedisExecutionDAO.java @@ -38,10 +38,7 @@ import com.netflix.conductor.common.metadata.tasks.Task.Status; import com.netflix.conductor.common.metadata.tasks.TaskDef; import com.netflix.conductor.common.metadata.tasks.TaskExecLog; -import com.netflix.conductor.common.run.WorkflowError; -import com.netflix.conductor.common.run.WorkflowErrorRegistry; -import com.netflix.conductor.common.run.Workflow; -import com.netflix.conductor.common.run.TaskDetails; +import com.netflix.conductor.common.run.*; import com.netflix.conductor.core.config.Configuration; import com.netflix.conductor.core.events.queue.Message; import com.netflix.conductor.core.execution.ApplicationException; @@ -370,6 +367,11 @@ public Workflow getWorkflow(String workflowId, boolean includeTasks) { return workflow; } + @Override + public WorkflowDetails getWorkflowDetails(String workflowId, boolean includeTasks) { + return null; + } + @Override public List getRunningWorkflowIds(String workflowName) { Preconditions.checkNotNull(workflowName, "workflowName cannot be null");