/** * Populates the workflow output from external payload storage if the external storage path is specified. * * @param workflow the workflow for which the output is to be populated. */ private void populateWorkflowOutput(Workflow workflow) { if (StringUtils.isNotBlank(workflow.getExternalOutputPayloadStoragePath())) { WorkflowTaskMetrics.incrementExternalPayloadUsedCount(workflow.getWorkflowName(), ExternalPayloadStorage.Operation.READ.name(), ExternalPayloadStorage.PayloadType.WORKFLOW_OUTPUT.name()); workflow.setOutput(downloadFromExternalStorage(ExternalPayloadStorage.PayloadType.WORKFLOW_OUTPUT, workflow.getExternalOutputPayloadStoragePath())); } }
/** * Updates the workflow output. * * @param workflow the workflow instance * @param task if not null, the output of this task will be copied to workflow output if no output parameters are specified in the workflow defintion * if null, the output of the last task in the workflow will be copied to workflow output of no output parameters are specified in the workflow definition */ void updateWorkflowOutput(final Workflow workflow, @Nullable Task task) { List<Task> allTasks = workflow.getTasks(); if (allTasks.isEmpty()) { return; } Task last = Optional.ofNullable(task).orElse(allTasks.get(allTasks.size() - 1)); WorkflowDef workflowDef = workflow.getWorkflowDefinition(); Map<String, Object> output; if (workflowDef.getOutputParameters() != null && !workflowDef.getOutputParameters().isEmpty()) { Workflow workflowInstance = populateWorkflowAndTaskData(workflow); output = parametersUtils.getTaskInput(workflowDef.getOutputParameters(), workflowInstance, null, null); } else if (StringUtils.isNotBlank(last.getExternalOutputPayloadStoragePath())) { output = externalPayloadStorageUtils.downloadPayload(last.getExternalOutputPayloadStoragePath()); Monitors.recordExternalPayloadStorageUsage(last.getTaskDefName(), ExternalPayloadStorage.Operation.READ.toString(), ExternalPayloadStorage.PayloadType.TASK_OUTPUT.toString()); } else { output = last.getOutputData(); } workflow.setOutput(output); externalPayloadStorageUtils.verifyAndUpload(workflow, ExternalPayloadStorage.PayloadType.WORKFLOW_OUTPUT); }
/** * @return a deep copy of the workflow instance * Note: This does not copy the following fields: * <ul> * <li>endTime</li> * <li>taskToDomain</li> * <li>failedReferenceTaskNames</li> * <li>externalInputPayloadStoragePath</li> * <li>externalOutputPayloadStoragePath</li> * </ul> */ public Workflow copy() { Workflow copy = new Workflow(); copy.setInput(input); copy.setOutput(output); copy.setStatus(status); copy.setWorkflowId(workflowId); copy.setParentWorkflowId(parentWorkflowId); copy.setParentWorkflowTaskId(parentWorkflowTaskId); copy.setReRunFromWorkflowId(reRunFromWorkflowId); copy.setCorrelationId(correlationId); copy.setEvent(event); copy.setReasonForIncompletion(reasonForIncompletion); copy.setWorkflowDefinition(workflowDefinition); copy.setTasks(tasks.stream() .map(Task::copy) .collect(Collectors.toList())); return copy; }
@SuppressWarnings("unchecked") @Test public void testUploadWorkflowPayload() throws IOException { AtomicInteger uploadCount = new AtomicInteger(0); InputStream stream = ExternalPayloadStorageUtilsTest.class.getResourceAsStream("/payload.json"); Map<String, Object> payload = objectMapper.readValue(stream, Map.class); when(externalPayloadStorage.getLocation(ExternalPayloadStorage.Operation.WRITE, ExternalPayloadStorage.PayloadType.WORKFLOW_OUTPUT, "")).thenReturn(location); doAnswer(invocation -> { uploadCount.incrementAndGet(); return null; }).when(externalPayloadStorage).upload(anyString(), any(), anyLong()); Workflow workflow = new Workflow(); workflow.setOutput(payload); externalPayloadStorageUtils.verifyAndUpload(workflow, ExternalPayloadStorage.PayloadType.WORKFLOW_OUTPUT); assertNull(workflow.getOutput()); assertEquals(1, uploadCount.get()); assertNotNull(workflow.getExternalOutputPayloadStoragePath()); }
outputMap.put( pair.getKey(), fromProto( pair.getValue() ) ); to.setOutput(outputMap); to.setWorkflowType( from.getWorkflowType() ); to.setVersion( from.getVersion() );
workflow.setStartTime(10L); workflow.setEndTime(100L); workflow.setOutput(Collections.EMPTY_MAP);
workflow.setStartTime(10L); workflow.setEndTime(100L); workflow.setOutput(Collections.EMPTY_MAP);
workflow.setOutput(null); workflow.setExternalOutputPayloadStoragePath(null); executionDAOFacade.updateWorkflow(workflow);
workflow.setOutput(wf.getOutput()); workflow.setExternalOutputPayloadStoragePath(wf.getExternalOutputPayloadStoragePath()); executionDAOFacade.updateWorkflow(workflow);
workflow.setEndTime(100L); workflow.setOutput(Collections.EMPTY_MAP); workflow.setStatus(Workflow.WorkflowStatus.FAILED);
output.put("ouput1", "output 1 value"); output.put("op2", 300); workflow.setOutput(output);
break; case WORKFLOW_OUTPUT: ((Workflow) entity).setOutput(null); ((Workflow) entity).setExternalOutputPayloadStoragePath(uploadHelper(payloadBytes, payloadSize, PayloadType.WORKFLOW_OUTPUT)); Monitors.recordExternalPayloadStorageUsage(((Workflow) entity).getWorkflowType(), ExternalPayloadStorage.Operation.WRITE.toString(), PayloadType.WORKFLOW_OUTPUT.toString());
/** * Populates the workflow output from external payload storage if the external storage path is specified. * * @param workflow the workflow for which the output is to be populated. */ private void populateWorkflowOutput(Workflow workflow) { if (StringUtils.isNotBlank(workflow.getExternalOutputPayloadStoragePath())) { WorkflowTaskMetrics.incrementExternalPayloadUsedCount(workflow.getWorkflowName(), ExternalPayloadStorage.Operation.READ.name(), ExternalPayloadStorage.PayloadType.WORKFLOW_OUTPUT.name()); workflow.setOutput(downloadFromExternalStorage(ExternalPayloadStorage.PayloadType.WORKFLOW_OUTPUT, workflow.getExternalOutputPayloadStoragePath())); } }
/** * Updates the workflow output. * * @param workflow the workflow instance * @param task if not null, the output of this task will be copied to workflow output if no output parameters are specified in the workflow defintion * if null, the output of the last task in the workflow will be copied to workflow output of no output parameters are specified in the workflow definition */ void updateWorkflowOutput(final Workflow workflow, @Nullable Task task) { List<Task> allTasks = workflow.getTasks(); if (allTasks.isEmpty()) { return; } Task last = Optional.ofNullable(task).orElse(allTasks.get(allTasks.size() - 1)); WorkflowDef workflowDef = workflow.getWorkflowDefinition(); Map<String, Object> output; if (workflowDef.getOutputParameters() != null && !workflowDef.getOutputParameters().isEmpty()) { Workflow workflowInstance = populateWorkflowAndTaskData(workflow); output = parametersUtils.getTaskInput(workflowDef.getOutputParameters(), workflowInstance, null, null); } else if (StringUtils.isNotBlank(last.getExternalOutputPayloadStoragePath())) { output = externalPayloadStorageUtils.downloadPayload(last.getExternalOutputPayloadStoragePath()); Monitors.recordExternalPayloadStorageUsage(last.getTaskDefName(), ExternalPayloadStorage.Operation.READ.toString(), ExternalPayloadStorage.PayloadType.TASK_OUTPUT.toString()); } else { output = last.getOutputData(); } workflow.setOutput(output); externalPayloadStorageUtils.verifyAndUpload(workflow, ExternalPayloadStorage.PayloadType.WORKFLOW_OUTPUT); }
/** * @return a deep copy of the workflow instance * Note: This does not copy the following fields: * <ul> * <li>endTime</li> * <li>taskToDomain</li> * <li>failedReferenceTaskNames</li> * <li>externalInputPayloadStoragePath</li> * <li>externalOutputPayloadStoragePath</li> * </ul> */ public Workflow copy() { Workflow copy = new Workflow(); copy.setInput(input); copy.setOutput(output); copy.setStatus(status); copy.setWorkflowId(workflowId); copy.setParentWorkflowId(parentWorkflowId); copy.setParentWorkflowTaskId(parentWorkflowTaskId); copy.setReRunFromWorkflowId(reRunFromWorkflowId); copy.setCorrelationId(correlationId); copy.setEvent(event); copy.setReasonForIncompletion(reasonForIncompletion); copy.setWorkflowDefinition(workflowDefinition); copy.setTasks(tasks.stream() .map(Task::copy) .collect(Collectors.toList())); return copy; }
outputMap.put( pair.getKey(), fromProto( pair.getValue() ) ); to.setOutput(outputMap); to.setWorkflowType( from.getWorkflowType() ); to.setVersion( from.getVersion() );
workflow.setOutput(null); workflow.setExternalOutputPayloadStoragePath(null); executionDAOFacade.updateWorkflow(workflow);
workflow.setOutput(wf.getOutput()); workflow.setExternalOutputPayloadStoragePath(wf.getExternalOutputPayloadStoragePath()); executionDAOFacade.updateWorkflow(workflow);
break; case WORKFLOW_OUTPUT: ((Workflow) entity).setOutput(null); ((Workflow) entity).setExternalOutputPayloadStoragePath(uploadHelper(payloadBytes, payloadSize, PayloadType.WORKFLOW_OUTPUT)); Monitors.recordExternalPayloadStorageUsage(((Workflow) entity).getWorkflowType(), ExternalPayloadStorage.Operation.WRITE.toString(), PayloadType.WORKFLOW_OUTPUT.toString());