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

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

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

Task.getWorkflowInstanceId介绍

暂无

代码示例

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

@Override
public List<Task> getPendingTasksByWorkflow(String taskName, String workflowId) {
  List<Task> tasks = new LinkedList<>();
  List<Task> pendingTasks = getPendingTasksForTaskType(taskName);
  pendingTasks.forEach(pendingTask -> {
    if (pendingTask.getWorkflowInstanceId().equals(workflowId)) {
      tasks.add(pendingTask);
    }
  });
  return tasks;
}

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

private void validate(Task task) {
    Preconditions.checkNotNull(task, "task object cannot be null");
    Preconditions.checkNotNull(task.getTaskId(), "Task id cannot be null");
    Preconditions.checkNotNull(task.getWorkflowInstanceId(), "Workflow instance id cannot be null");
    Preconditions.checkNotNull(task.getReferenceTaskName(), "Task reference name cannot be null");
  }
}

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

@VisibleForTesting
void validateTasks(List<Task> tasks) {
  Preconditions.checkNotNull(tasks, "Tasks object cannot be null");
  Preconditions.checkArgument(!tasks.isEmpty(), "Tasks object cannot be empty");
  tasks.forEach(task -> {
    Preconditions.checkNotNull(task, "task object cannot be null");
    Preconditions.checkNotNull(task.getTaskId(), "Task id cannot be null");
    Preconditions.checkNotNull(task.getWorkflowInstanceId(), "Workflow instance id cannot be null");
    Preconditions.checkNotNull(task.getReferenceTaskName(), "Task reference name cannot be null");
  });
  String workflowId = tasks.get(0).getWorkflowInstanceId();
  Optional<Task> optionalTask = tasks.stream()
      .filter(task -> !workflowId.equals(task.getWorkflowInstanceId()))
      .findAny();
  if (optionalTask.isPresent()) {
    throw new ApplicationException(ApplicationException.Code.INTERNAL_ERROR, "Tasks of multiple workflows cannot be created/updated simultaneously");
  }
}

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

/**
   *
   * @param task
   * @throws ApplicationException
   */
  private void validate(Task task) {
    try {
      Preconditions.checkNotNull(task, "task object cannot be null");
      Preconditions.checkNotNull(task.getTaskId(), "Task id cannot be null");
      Preconditions.checkNotNull(task.getWorkflowInstanceId(), "Workflow instance id cannot be null");
      Preconditions.checkNotNull(task.getReferenceTaskName(), "Task reference name cannot be null");
    } catch (NullPointerException npe){
      throw new ApplicationException(Code.INVALID_INPUT, npe.getMessage(), npe);
    }
  }
}

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

/**
 * Sets the update time for the task.
 * Sets the end time for the task (if task is in terminal state and end time is not set).
 * Updates the task in the {@link ExecutionDAO} first, then stores it in the {@link IndexDAO}.
 *
 * @param task the task to be updated in the data store
 * @throws ApplicationException if the dao operations fail
 */
public void updateTask(Task task) {
  try {
    executionDAO.updateTask(task);
    indexDAO.indexTask(task);
  } catch (Exception e) {
    String errorMsg = String.format("Error updating task: %s in workflow: %s", task.getTaskId(), task.getWorkflowInstanceId());
    LOGGER.error(errorMsg, e);
    throw new ApplicationException(ApplicationException.Code.BACKEND_ERROR, errorMsg, e);
  }
}

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

private void removeScheduledTask(Connection connection, Task task, String taskKey) {
  String REMOVE_SCHEDULED_TASK = "DELETE FROM task_scheduled WHERE workflow_id = ? AND task_key = ?";
  execute(connection, REMOVE_SCHEDULED_TASK,
      q -> q.addParameter(task.getWorkflowInstanceId()).addParameter(taskKey).executeDelete());
}

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

@VisibleForTesting
boolean addScheduledTask(Connection connection, Task task, String taskKey) {
  final String INSERT_IGNORE_SCHEDULED_TASK = "INSERT IGNORE INTO task_scheduled (workflow_id, task_key, task_id) VALUES (?, ?, ?)";
  int count = query(connection, INSERT_IGNORE_SCHEDULED_TASK, q -> q.addParameter(task.getWorkflowInstanceId())
      .addParameter(taskKey).addParameter(task.getTaskId()).executeUpdate());
  return count > 0;
}

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

private boolean removeTask(Task task) {
  // TODO: calculate shard number based on seq and maxTasksPerShard
  try {
    // get total tasks for this workflow
    WorkflowMetadata workflowMetadata = getWorkflowMetadata(task.getWorkflowInstanceId());
    int totalTasks = workflowMetadata.getTotalTasks();
    // remove from task_lookup table
    removeTaskLookup(task);
    recordCassandraDaoRequests("removeTask", task.getTaskType(), task.getWorkflowType());
    // delete task from workflows table and decrement total tasks by 1
    BatchStatement batchStatement = new BatchStatement();
    batchStatement.add(deleteTaskStatement.bind(UUID.fromString(task.getWorkflowInstanceId()), DEFAULT_SHARD_ID, task.getTaskId()));
    batchStatement.add(updateTotalTasksStatement.bind(totalTasks - 1, UUID.fromString(task.getWorkflowInstanceId()), DEFAULT_SHARD_ID));
    ResultSet resultSet = session.execute(batchStatement);
    return resultSet.wasApplied();
  } catch (Exception e) {
    Monitors.error(CLASS_NAME, "removeTask");
    String errorMsg = String.format("Failed to remove task: %s", task.getTaskId());
    LOGGER.error(errorMsg, e);
    throw new ApplicationException(ApplicationException.Code.BACKEND_ERROR, errorMsg);
  }
}

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

private void addWorkflowToTaskMapping(Connection connection, Task task) {
  String INSERT_WORKFLOW_TO_TASK = "INSERT IGNORE INTO workflow_to_task (workflow_id, task_id) VALUES (?, ?)";
  execute(connection, INSERT_WORKFLOW_TO_TASK,
      q -> q.addParameter(task.getWorkflowInstanceId()).addParameter(task.getTaskId()).executeUpdate());
}

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

@Override
public void updateTask(Task task) {
  try {
    task.setUpdateTime(System.currentTimeMillis());
    if (task.getStatus().isTerminal() && task.getEndTime() == 0) {
      task.setEndTime(System.currentTimeMillis());
    }
    // TODO: calculate the shard number the task belongs to
    String taskPayload = toJson(task);
    recordCassandraDaoRequests("updateTask", task.getTaskType(), task.getWorkflowType());
    recordCassandraDaoPayloadSize("updateTask", taskPayload.length(), task.getTaskType(), task.getWorkflowType());
    session.execute(insertTaskStatement.bind(UUID.fromString(task.getWorkflowInstanceId()), DEFAULT_SHARD_ID, task.getTaskId(), taskPayload));
  } catch (Exception e) {
    Monitors.error(CLASS_NAME, "updateTask");
    String errorMsg = String.format("Error updating task: %s in workflow: %s", task.getTaskId(), task.getWorkflowInstanceId());
    LOGGER.error(errorMsg, e);
    throw new ApplicationException(ApplicationException.Code.BACKEND_ERROR, errorMsg, e);
  }
}

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

private void removeWorkflowToTaskMapping(Connection connection, Task task) {
  String REMOVE_WORKFLOW_TO_TASK = "DELETE FROM workflow_to_task WHERE workflow_id = ? AND task_id = ?";
  execute(connection, REMOVE_WORKFLOW_TO_TASK,
      q -> q.addParameter(task.getWorkflowInstanceId()).addParameter(task.getTaskId()).executeDelete());
}

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

@Override
public List<Task> createTasks(List<Task> tasks) {
  List<Task> tasksCreated = new LinkedList<>();
  for (Task task : tasks) {
    validate(task);
    recordRedisDaoRequests("createTask", task.getTaskType(), task.getWorkflowType());
    String taskKey = task.getReferenceTaskName() + "" + task.getRetryCount();
    Long added = dynoClient.hset(nsKey(SCHEDULED_TASKS, task.getWorkflowInstanceId()), taskKey, task.getTaskId());
    if (added < 1) {
      logger.debug("Task already scheduled, skipping the run " + task.getTaskId() + ", ref=" + task.getReferenceTaskName() + ", key=" + taskKey);
      continue;
    }
    task.setScheduledTime(System.currentTimeMillis());
    correlateTaskToWorkflowInDS(task.getTaskId(), task.getWorkflowInstanceId());
    logger.debug("Scheduled task added to WORKFLOW_TO_TASKS workflowId: {}, taskId: {}, taskType: {} during createTasks",
        task.getWorkflowInstanceId(), task.getTaskId(), task.getTaskType());
    String inProgressTaskKey = nsKey(IN_PROGRESS_TASKS, task.getTaskDefName());
    dynoClient.sadd(inProgressTaskKey, task.getTaskId());
    logger.debug("Scheduled task added to IN_PROGRESS_TASKS with inProgressTaskKey: {}, workflowId: {}, taskId: {}, taskType: {} during createTasks",
        inProgressTaskKey, task.getWorkflowInstanceId(), task.getTaskId(), task.getTaskType());
    updateTask(task);
    tasksCreated.add(task);
  }
  return tasksCreated;
}

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

this.taskDefName = task.getTaskDefName();
this.taskType = task.getTaskType();
this.workflowId = task.getWorkflowInstanceId();
this.workflowType = task.getWorkflowType();
this.correlationId = task.getCorrelationId();

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

public int requeuePendingTasks(String taskType) {
  int count = 0;
  List<Task> tasks = getPendingTasksForTaskType(taskType);
  for (Task pending : tasks) {
    if (SystemTaskType.is(pending.getTaskType())) {
      continue;
    }
    if (pending.getStatus().isTerminal()) {
      continue;
    }
    logger.info("Requeuing Task: workflowId=" + pending.getWorkflowInstanceId() + ", taskType=" + pending.getTaskType() + ", taskId=" + pending.getTaskId());
    boolean pushed = requeue(pending);
    if (pushed) {
      count++;
    }
  }
  return count;
}

代码示例来源: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

@VisibleForTesting
void checkForTimeout(TaskDef taskDef, Task task) {
  if (taskDef == null) {
    LOGGER.warn("missing task type " + task.getTaskDefName() + ", workflowId=" + task.getWorkflowInstanceId());
    return;
  }
  if (task.getStatus().isTerminal() || taskDef.getTimeoutSeconds() <= 0 || !task.getStatus().equals(IN_PROGRESS)) {
    return;
  }
  long timeout = 1000L * taskDef.getTimeoutSeconds();
  long now = System.currentTimeMillis();
  long elapsedTime = now - (task.getStartTime() + ((long) task.getStartDelayInSeconds() * 1000L));
  if (elapsedTime < timeout) {
    return;
  }
  String reason = "Task timed out after " + elapsedTime + " millisecond.  Timeout configured as " + timeout;
  Monitors.recordTaskTimeout(task.getTaskDefName());
  switch (taskDef.getTimeoutPolicy()) {
    case ALERT_ONLY:
      return;
    case RETRY:
      task.setStatus(TIMED_OUT);
      task.setReasonForIncompletion(reason);
      return;
    case TIME_OUT_WF:
      task.setStatus(TIMED_OUT);
      task.setReasonForIncompletion(reason);
      throw new TerminateWorkflowException(reason, WorkflowStatus.TIMED_OUT, task);
  }
}

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

@Override
public boolean removeTask(String taskId) {
  Task task = getTask(taskId);
  if(task == null) {
    logger.warn("No such task found by id {}", taskId);
    return false;
  }
  String taskKey = task.getReferenceTaskName() + "" + task.getRetryCount();
  dynoClient.hdel(nsKey(SCHEDULED_TASKS, task.getWorkflowInstanceId()), taskKey);
  dynoClient.srem(nsKey(IN_PROGRESS_TASKS, task.getTaskDefName()), task.getTaskId());
  dynoClient.srem(nsKey(WORKFLOW_TO_TASKS, task.getWorkflowInstanceId()), task.getTaskId());
  dynoClient.srem(nsKey(TASKS_IN_PROGRESS_STATUS, task.getTaskDefName()), task.getTaskId());
  dynoClient.del(nsKey(TASK, task.getTaskId()));
  dynoClient.zrem(nsKey(TASK_LIMIT_BUCKET, task.getTaskDefName()), task.getTaskId());
  recordRedisDaoRequests("removeTask", task.getTaskType(), task.getWorkflowType());
  return true;
}

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

private void addTaskInProgress(Connection connection, Task task) {
  String EXISTS_IN_PROGRESS_TASK = "SELECT EXISTS(SELECT 1 FROM task_in_progress WHERE task_def_name = ? AND task_id = ?)";
  boolean exist = query(connection, EXISTS_IN_PROGRESS_TASK,
      q -> q.addParameter(task.getTaskDefName()).addParameter(task.getTaskId()).exists());
  if (!exist) {
    String INSERT_IN_PROGRESS_TASK = "INSERT INTO task_in_progress (task_def_name, task_id, workflow_id) VALUES (?, ?, ?)";
    execute(connection, INSERT_IN_PROGRESS_TASK, q -> q.addParameter(task.getTaskDefName())
        .addParameter(task.getTaskId()).addParameter(task.getWorkflowInstanceId()).executeUpdate());
  }
}

代码示例来源: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
@SuppressWarnings("unchecked")
public void testCorrelateTaskToWorkflowInDS() {
  String workflowId = "workflowId";
  String taskId = "taskId1";
  String taskDefName = "task1";
  TaskDef def = new TaskDef();
  def.setName("task1");
  def.setConcurrentExecLimit(1);
  Task task = new Task();
  task.setTaskId(taskId);
  task.setWorkflowInstanceId(workflowId);
  task.setReferenceTaskName("ref_name");
  task.setTaskDefName(taskDefName);
  task.setTaskType(taskDefName);
  task.setStatus(Status.IN_PROGRESS);
  List<Task> tasks = executionDAO.createTasks(Collections.singletonList(task));
  assertNotNull(tasks);
  assertEquals(1, tasks.size());
  executionDAO.correlateTaskToWorkflowInDS(taskId, workflowId);
  tasks = executionDAO.getTasksForWorkflow(workflowId);
  assertNotNull(tasks);
  assertEquals(workflowId, tasks.get(0).getWorkflowInstanceId());
  assertEquals(taskId, tasks.get(0).getTaskId());
}

相关文章

微信公众号

最新文章

更多

Task类方法