com.netflix.conductor.common.metadata.tasks.Task.getOutputData()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(14.2k)|赞(0)|评价(0)|浏览(126)

本文整理了Java中com.netflix.conductor.common.metadata.tasks.Task.getOutputData()方法的一些代码示例,展示了Task.getOutputData()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Task.getOutputData()方法的具体详情如下:
包路径:com.netflix.conductor.common.metadata.tasks.Task
类名称:Task
方法名:getOutputData

Task.getOutputData介绍

暂无

代码示例

代码示例来源:origin: Netflix/conductor

@Override
public void cancel(Workflow workflow, Task task, WorkflowExecutor provider) {
  String workflowId = (String) task.getOutputData().get(SUB_WORKFLOW_ID);
  if(workflowId == null) {
    workflowId = (String) task.getInputData().get(SUB_WORKFLOW_ID);    //Backward compatibility
  }
  
  if(StringUtils.isEmpty(workflowId)) {
    return;
  }
  Workflow subWorkflow = provider.getWorkflow(workflowId, false);
  subWorkflow.setStatus(WorkflowStatus.TERMINATED);
  provider.terminateWorkflow(subWorkflow, "Parent workflow has been terminated with status " + workflow.getStatus(), null);
}

代码示例来源:origin: Netflix/conductor

@Override
public void start(Workflow workflow, Task task, WorkflowExecutor executor) {
  Map<String, Object> taskInput = task.getInputData();
  Map<String, Object> taskOutput = task.getOutputData();

代码示例来源:origin: Netflix/conductor

@SuppressWarnings("unchecked")
@Override
public void start(Workflow workflow, Task task, WorkflowExecutor provider) {
  Map<String, Object> input = task.getInputData();
  String name = input.get("subWorkflowName").toString();
  int version = (int) input.get("subWorkflowVersion");
  Map<String, Object> wfInput = (Map<String, Object>) input.get("workflowInput");
  if (wfInput == null || wfInput.isEmpty()) {
    wfInput = input;
  }
  String correlationId = workflow.getCorrelationId();
  
  try {
    String subWorkflowId = provider.startWorkflow(name, version, wfInput, null, correlationId, workflow.getWorkflowId(), task.getTaskId(), null, workflow.getTaskToDomain());
    task.getOutputData().put(SUB_WORKFLOW_ID, subWorkflowId);
    task.getInputData().put(SUB_WORKFLOW_ID, subWorkflowId);
    task.setStatus(Status.IN_PROGRESS);
  } catch (Exception e) {
    task.setStatus(Status.FAILED);
    task.setReasonForIncompletion(e.getMessage());
    logger.error(e.getMessage(), e);
  }
}

代码示例来源:origin: Netflix/conductor

@Override
public boolean execute(Workflow workflow, Task task, WorkflowExecutor provider) {
  String workflowId = (String) task.getOutputData().get(SUB_WORKFLOW_ID);
  if (workflowId == null) {
    workflowId = (String) task.getInputData().get(SUB_WORKFLOW_ID);    //Backward compatibility
  }
  
  if(StringUtils.isEmpty(workflowId)) {
    return false;
  }
  
  Workflow subWorkflow = provider.getWorkflow(workflowId, false);
  WorkflowStatus subWorkflowStatus = subWorkflow.getStatus();
  if(!subWorkflowStatus.isTerminal()){
    return false;
  }
  task.getOutputData().putAll(subWorkflow.getOutput());
  if (subWorkflowStatus.isSuccessful()) {
    task.setStatus(Status.COMPLETED);
  } else {
    task.setReasonForIncompletion(subWorkflow.getReasonForIncompletion());
    task.setStatus(Status.FAILED);
  }
  return true;
}

代码示例来源:origin: Netflix/conductor

if (task.getOutputData() != null) {
  this.output = task.getOutputData().toString();

代码示例来源:origin: Netflix/conductor

@Override
public void start(Workflow workflow, Task task, WorkflowExecutor provider) {
  Map<String, Object> payload = new HashMap<>(task.getInputData());
  payload.put("workflowInstanceId", workflow.getWorkflowId());
  payload.put("workflowType", workflow.getWorkflowName());
  payload.put("workflowVersion", workflow.getWorkflowVersion());
  payload.put("correlationId", workflow.getCorrelationId());
  String payloadJson;
  try {
    payloadJson = objectMapper.writeValueAsString(payload);
  } catch (JsonProcessingException e) {
    String msg = String.format("Error serializing JSON payload for task: %s, workflow: %s", task.getTaskId(), workflow.getWorkflowId());
    throw new ApplicationException(INTERNAL_ERROR, msg);
  }
  Message message = new Message(task.getTaskId(), payloadJson, task.getTaskId());
  ObservableQueue queue = getQueue(workflow, task);
  if(queue != null) {
    queue.publish(Collections.singletonList(message));
    task.getOutputData().putAll(payload);
    task.setStatus(Status.COMPLETED);
  } else {
    task.setReasonForIncompletion("No queue found to publish.");
    task.setStatus(Status.FAILED);
  }
}

代码示例来源:origin: Netflix/conductor

/**
 * 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);
}

代码示例来源:origin: Netflix/conductor

task.getOutputData().put("location", "http://location");
task.setStatus(Task.Status.COMPLETED);
task2.getOutputData().put("refId", "abcddef_1234_7890_aaffcc");
task2.setStatus(Task.Status.SCHEDULED);

代码示例来源:origin: Netflix/conductor

@Test
public void testGetTaskInputV1() {
  Map<String, Object> ip = new HashMap<>();
  ip.put("workflowInputParam", "workflow.input.requestId");
  ip.put("taskOutputParam", "task2.output.location");
  WorkflowDef def = new WorkflowDef();
  def.setSchemaVersion(1);
  Workflow workflow = new Workflow();
  workflow.setWorkflowDefinition(def);
  workflow.getInput().put("requestId", "request id 001");
  Task task = new Task();
  task.setReferenceTaskName("task2");
  task.getOutputData().put("location", "http://location");
  task.getOutputData().put("isPersonActive", true);
  workflow.getTasks().add(task);
  Map<String, Object> taskInput = parametersUtils.getTaskInput(ip, workflow, null, null);
  assertNotNull(taskInput);
  assertTrue(taskInput.containsKey("workflowInputParam"));
  assertTrue(taskInput.containsKey("taskOutputParam"));
  assertEquals("request id 001", taskInput.get("workflowInputParam"));
  assertEquals("http://location", taskInput.get("taskOutputParam"));
}

代码示例来源:origin: Netflix/conductor

public TaskResult(Task task) {
  this.workflowInstanceId = task.getWorkflowInstanceId();
  this.taskId = task.getTaskId();
  this.reasonForIncompletion = task.getReasonForIncompletion();
  this.callbackAfterSeconds = task.getCallbackAfterSeconds();
  this.status = Status.valueOf(task.getStatus().name());
  this.workerId = task.getWorkerId();
  this.outputData = task.getOutputData();
  this.externalOutputPayloadStoragePath = task.getExternalOutputPayloadStoragePath();
}

代码示例来源:origin: Netflix/conductor

@Test
public void testOAuth() {
  Task task = new Task();
  Input input = new Input();
  input.setUri("http://localhost:7009/oauth");
  input.setMethod("POST");
  input.setOauthConsumerKey("someKey");
  input.setOauthConsumerSecret("someSecret");
  task.getInputData().put(HttpTask.REQUEST_PARAMETER_NAME, input);
  httpTask.start(workflow, task, workflowExecutor);
  Map<String, Object> response = (Map<String, Object>) task.getOutputData().get("response");
  Map<String, String> body = (Map<String, String>) response.get("body");
  assertEquals("someKey", body.get("oauth_consumer_key"));
  assertTrue("Should have OAuth nonce", body.containsKey("oauth_nonce"));
  assertTrue("Should have OAuth signature", body.containsKey("oauth_signature"));
  assertTrue("Should have OAuth signature method", body.containsKey("oauth_signature_method"));
  assertTrue("Should have OAuth oauth_timestamp", body.containsKey("oauth_timestamp"));
  assertTrue("Should have OAuth oauth_version", body.containsKey("oauth_version"));
  assertEquals("Task output: " + task.getOutputData(), Status.COMPLETED, task.getStatus());
}

代码示例来源:origin: Netflix/conductor

@Test
public void testPost() {
  Task task = new Task();
  Input input = new Input();
  input.setUri("http://localhost:7009/post");
  Map<String, Object> body = new HashMap<>();
  body.put("input_key1", "value1");
  body.put("input_key2", 45.3d);
  input.setBody(body);
  input.setMethod("POST");
  task.getInputData().put(HttpTask.REQUEST_PARAMETER_NAME, input);
  httpTask.start(workflow, task, workflowExecutor);
  assertEquals(task.getReasonForIncompletion(), Task.Status.COMPLETED, task.getStatus());
  Map<String, Object> hr = (Map<String, Object>) task.getOutputData().get("response");
  Object response = hr.get("body");
  assertEquals(Task.Status.COMPLETED, task.getStatus());
  assertTrue("response is: " + response, response instanceof Map);
  Map<String, Object> map = (Map<String, Object>) response;
  Set<String> inputKeys = body.keySet();
  Set<String> responseKeys = map.keySet();
  inputKeys.containsAll(responseKeys);
  responseKeys.containsAll(inputKeys);
}

代码示例来源:origin: Netflix/conductor

@Test
public void testTextGET() {
  Task task = new Task();
  Input input = new Input();
  input.setUri("http://localhost:7009/text");
  input.setMethod("GET");
  task.getInputData().put(HttpTask.REQUEST_PARAMETER_NAME, input);
  httpTask.start(workflow, task, workflowExecutor);
  Map<String, Object> hr = (Map<String, Object>) task.getOutputData().get("response");
  Object response = hr.get("body");
  assertEquals(Task.Status.COMPLETED, task.getStatus());
  assertEquals(TEXT_RESPONSE, response);
}

代码示例来源:origin: Netflix/conductor

@Test
  public void testFailTaskWithOutputPayload() {
    Task task = new Task();
    task.setOutputData(new HashMap<>());

    expectedException.expect(TerminateWorkflowException.class);
    externalPayloadStorageUtils.failTask(task, ExternalPayloadStorage.PayloadType.TASK_OUTPUT, "error");
    assertNotNull(task);
    assertNull(task.getOutputData());
  }
}

代码示例来源:origin: Netflix/conductor

@Test
public void testJsonGET() throws JsonProcessingException {
  Task task = new Task();
  Input input = new Input();
  input.setUri("http://localhost:7009/json");
  input.setMethod("GET");
  task.getInputData().put(HttpTask.REQUEST_PARAMETER_NAME, input);
  httpTask.start(workflow, task, workflowExecutor);
  Map<String, Object> hr = (Map<String, Object>) task.getOutputData().get("response");
  Object response = hr.get("body");
  assertEquals(Task.Status.COMPLETED, task.getStatus());
  assertTrue(response instanceof Map);
  Map<String, Object> map = (Map<String, Object>) response;
  assertEquals(JSON_RESPONSE, objectMapper.writeValueAsString(map));
}

代码示例来源:origin: Netflix/conductor

@Test
public void testNumberGET() {
  Task task = new Task();
  Input input = new Input();
  input.setUri("http://localhost:7009/numeric");
  input.setMethod("GET");
  task.getInputData().put(HttpTask.REQUEST_PARAMETER_NAME, input);
  httpTask.start(workflow, task, workflowExecutor);
  Map<String, Object> hr = (Map<String, Object>) task.getOutputData().get("response");
  Object response = hr.get("body");
  assertEquals(Task.Status.COMPLETED, task.getStatus());
  assertEquals(NUM_RESPONSE, response);
  assertTrue(response instanceof Number);
}

代码示例来源:origin: Netflix/conductor

@Test
public void testPostNoContent() {
  Task task = new Task();
  Input input = new Input();
  input.setUri("http://localhost:7009/post2");
  Map<String, Object> body = new HashMap<>();
  body.put("input_key1", "value1");
  body.put("input_key2", 45.3d);
  input.setBody(body);
  input.setMethod("POST");
  task.getInputData().put(HttpTask.REQUEST_PARAMETER_NAME, input);
  httpTask.start(workflow, task, workflowExecutor);
  assertEquals(task.getReasonForIncompletion(), Task.Status.COMPLETED, task.getStatus());
  Map<String, Object> hr = (Map<String, Object>) task.getOutputData().get("response");
  Object response = hr.get("body");
  assertEquals(Task.Status.COMPLETED, task.getStatus());
  assertNull("response is: " + response, response);
}

代码示例来源:origin: Netflix/conductor

@Override
  public int hashCode() {
    return Objects.hash(getTaskType(), getStatus(), getInputData(), getReferenceTaskName(), getRetryCount(), getSeq(), getCorrelationId(), getPollCount(), getTaskDefName(), getScheduledTime(), getStartTime(), getEndTime(), getUpdateTime(), getStartDelayInSeconds(), getRetriedTaskId(), isRetried(), isExecuted(), isCallbackFromWorker(), getResponseTimeoutSeconds(), getWorkflowInstanceId(), getWorkflowType(), getTaskId(), getReasonForIncompletion(), getCallbackAfterSeconds(), getWorkerId(), getOutputData(), getWorkflowTask(), getDomain(), getInputMessage(), getOutputMessage(), getRateLimitPerFrequency(), getRateLimitFrequencyInSeconds(), getExternalInputPayloadStoragePath(), getExternalOutputPayloadStoragePath());
  }
}

代码示例来源:origin: Netflix/conductor

@Test
public void testFailure() {
  Task task = new Task();
  Input input = new Input();
  input.setUri("http://localhost:7009/failure");
  input.setMethod("GET");
  task.getInputData().put(HttpTask.REQUEST_PARAMETER_NAME, input);
  httpTask.start(workflow, task, workflowExecutor);
  assertEquals("Task output: " + task.getOutputData(), Task.Status.FAILED, task.getStatus());
  assertEquals(ERROR_RESPONSE, task.getReasonForIncompletion());
  task.setStatus(Status.SCHEDULED);
  task.getInputData().remove(HttpTask.REQUEST_PARAMETER_NAME);
  httpTask.start(workflow, task, workflowExecutor);
  assertEquals(Task.Status.FAILED, task.getStatus());
  assertEquals(HttpTask.MISSING_REQUEST, task.getReasonForIncompletion());
}

代码示例来源:origin: Netflix/conductor

assertEquals("testWorkflow:some_arbitary_queue", queue.getURI());
assertEquals("conductor", queue.getType());
assertEquals("conductor:testWorkflow:some_arbitary_queue", task.getOutputData().get("event_produced"));

相关文章

Task类方法