org.apache.helix.task.WorkflowContext.getJobState()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(11.1k)|赞(0)|评价(0)|浏览(130)

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

WorkflowContext.getJobState介绍

暂无

代码示例

代码示例来源:origin: apache/incubator-gobblin

  1. WorkflowContext workflowContext = TaskDriver.getWorkflowContext(helixManager, workFlowName);
  2. if (workflowContext != null) {
  3. TaskState jobState = workflowContext.getJobState(TaskUtil.getNamespacedJobName(workFlowName, jobName));
  4. switch (jobState) {
  5. case STOPPED:

代码示例来源:origin: apache/incubator-gobblin

  1. static void waitJobInitialization(
  2. HelixManager helixManager,
  3. String workFlowName,
  4. String jobName,
  5. long timeoutMillis) throws Exception {
  6. WorkflowContext workflowContext = TaskDriver.getWorkflowContext(helixManager, workFlowName);
  7. // If the helix job is deleted from some other thread or a completely external process,
  8. // method waitJobCompletion() needs to differentiate between the cases where
  9. // 1) workflowContext did not get initialized ever, in which case we need to keep waiting, or
  10. // 2) it did get initialized but deleted soon after, in which case we should stop waiting
  11. // To overcome this issue, we wait here till workflowContext gets initialized
  12. long start = System.currentTimeMillis();
  13. while (workflowContext == null || workflowContext.getJobState(TaskUtil.getNamespacedJobName(workFlowName, jobName)) == null) {
  14. if (System.currentTimeMillis() - start > timeoutMillis) {
  15. log.error("Job cannot be initialized within {} milliseconds, considered as an error", timeoutMillis);
  16. throw new JobException("Job cannot be initialized within {} milliseconds, considered as an error");
  17. }
  18. workflowContext = TaskDriver.getWorkflowContext(helixManager, workFlowName);
  19. Thread.sleep(1000);
  20. log.info("Waiting for work flow initialization.");
  21. }
  22. log.info("Work flow {} initialized", workFlowName);
  23. }

代码示例来源:origin: apache/incubator-gobblin

  1. static boolean isJobFinished(String workflowName, String jobName, HelixManager helixManager) {
  2. WorkflowContext workflowContext = TaskDriver.getWorkflowContext(helixManager, workflowName);
  3. if (workflowContext == null) {
  4. // this workflow context doesn't exist, considered as finished.
  5. return true;
  6. }
  7. TaskState jobState = workflowContext.getJobState(TaskUtil.getNamespacedJobName(workflowName, jobName));
  8. switch (jobState) {
  9. case STOPPED:
  10. case FAILED:
  11. case COMPLETED:
  12. case ABORTED:
  13. case TIMED_OUT:
  14. return true;
  15. default:
  16. return false;
  17. }
  18. }

代码示例来源:origin: apache/incubator-pinot

  1. /**
  2. * Get the task state for the given task name.
  3. *
  4. * @param taskName Task name
  5. * @return Task state
  6. */
  7. public synchronized TaskState getTaskState(@Nonnull String taskName) {
  8. String taskType = getTaskType(taskName);
  9. return _taskDriver.getWorkflowContext(getHelixJobQueueName(taskType)).getJobState(getHelixJobName(taskName));
  10. }

代码示例来源:origin: apache/incubator-gobblin

  1. /**
  2. * Deletes the stopped Helix Workflow.
  3. * Caller should stop the Workflow before calling this method.
  4. * @param helixManager helix manager
  5. * @param workFlowName workflow needed to be deleted
  6. * @param jobName helix job name
  7. * @throws InterruptedException
  8. */
  9. private static void deleteStoppedHelixJob(HelixManager helixManager, String workFlowName, String jobName)
  10. throws InterruptedException {
  11. WorkflowContext workflowContext = TaskDriver.getWorkflowContext(helixManager, workFlowName);
  12. while (workflowContext.getJobState(TaskUtil.getNamespacedJobName(workFlowName, jobName)) != STOPPED) {
  13. log.info("Waiting for job {} to stop...", jobName);
  14. workflowContext = TaskDriver.getWorkflowContext(helixManager, workFlowName);
  15. Thread.sleep(1000);
  16. }
  17. // deleting the entire workflow, as one workflow contains only one job
  18. new TaskDriver(helixManager).deleteAndWaitForCompletion(workFlowName, 10000L);
  19. log.info("Workflow deleted.");
  20. }
  21. }

代码示例来源:origin: org.apache.helix/helix-core

  1. public static boolean isJobStarted(String job, WorkflowContext workflowContext) {
  2. TaskState jobState = workflowContext.getJobState(job);
  3. return (jobState != null && jobState != TaskState.NOT_STARTED);
  4. }
  5. }

代码示例来源:origin: apache/helix

  1. public static boolean isJobStarted(String job, WorkflowContext workflowContext) {
  2. TaskState jobState = workflowContext.getJobState(job);
  3. return (jobState != null && jobState != TaskState.NOT_STARTED);
  4. }

代码示例来源:origin: apache/helix

  1. /**
  2. * Checks if the workflow has been stopped.
  3. * @param ctx Workflow context containing task states
  4. * @param cfg Workflow config containing set of tasks
  5. * @return returns true if all tasks are {@link TaskState#STOPPED}, false otherwise.
  6. */
  7. private static boolean isWorkflowStopped(WorkflowContext ctx, WorkflowConfig cfg) {
  8. for (String job : cfg.getJobDag().getAllNodes()) {
  9. if (ctx.getJobState(job) != TaskState.STOPPED && ctx.getJobState(job) != null) {
  10. return false;
  11. }
  12. }
  13. return true;
  14. }

代码示例来源:origin: org.apache.helix/helix-core

  1. /**
  2. * Checks if the workflow has been stopped.
  3. * @param ctx Workflow context containing task states
  4. * @param cfg Workflow config containing set of tasks
  5. * @return returns true if all tasks are {@link TaskState#STOPPED}, false otherwise.
  6. */
  7. private static boolean isWorkflowStopped(WorkflowContext ctx, WorkflowConfig cfg) {
  8. for (String job : cfg.getJobDag().getAllNodes()) {
  9. if (ctx.getJobState(job) != TaskState.STOPPED && ctx.getJobState(job) != null) {
  10. return false;
  11. }
  12. }
  13. return true;
  14. }

代码示例来源:origin: com.linkedin.gobblin/gobblin-cluster

  1. private void waitForJobCompletion() throws InterruptedException {
  2. while (true) {
  3. WorkflowContext workflowContext = TaskDriver.getWorkflowContext(this.helixManager, this.helixQueueName);
  4. if (workflowContext != null) {
  5. org.apache.helix.task.TaskState helixJobState = workflowContext.getJobState(this.jobResourceName);
  6. if (helixJobState == org.apache.helix.task.TaskState.COMPLETED ||
  7. helixJobState == org.apache.helix.task.TaskState.FAILED ||
  8. helixJobState == org.apache.helix.task.TaskState.STOPPED) {
  9. return;
  10. }
  11. }
  12. Thread.sleep(1000);
  13. }
  14. }

代码示例来源:origin: apache/helix

  1. @Override public boolean verify() throws Exception {
  2. WorkflowContext ctx = driver.getWorkflowContext(workflowName);
  3. return ctx == null || ctx.getJobState(namespacedJobName) == null
  4. || ctx.getJobState(namespacedJobName) == TaskState.NOT_STARTED;
  5. }
  6. }, _default_timeout);

代码示例来源:origin: org.apache.helix/helix-core

  1. /**
  2. * Count the number of jobs in a workflow that are not in final state.
  3. * @param workflowCfg
  4. * @param workflowCtx
  5. * @return
  6. */
  7. public static int getInCompleteJobCount(WorkflowConfig workflowCfg, WorkflowContext workflowCtx) {
  8. int inCompleteCount = 0;
  9. for (String jobName : workflowCfg.getJobDag().getAllNodes()) {
  10. TaskState jobState = workflowCtx.getJobState(jobName);
  11. if (jobState == TaskState.IN_PROGRESS || jobState == TaskState.STOPPED) {
  12. ++inCompleteCount;
  13. }
  14. }
  15. return inCompleteCount;
  16. }

代码示例来源:origin: apache/helix

  1. /**
  2. * Count the number of jobs in a workflow that are not in final state.
  3. * @param workflowCfg
  4. * @param workflowCtx
  5. * @return
  6. */
  7. public static int getInCompleteJobCount(WorkflowConfig workflowCfg, WorkflowContext workflowCtx) {
  8. int inCompleteCount = 0;
  9. for (String jobName : workflowCfg.getJobDag().getAllNodes()) {
  10. TaskState jobState = workflowCtx.getJobState(jobName);
  11. if (jobState == TaskState.IN_PROGRESS || jobState == TaskState.STOPPED
  12. || jobState == TaskState.STOPPING) {
  13. ++inCompleteCount;
  14. }
  15. }
  16. return inCompleteCount;
  17. }

代码示例来源:origin: org.apache.gobblin/gobblin-cluster

  1. /**
  2. * Deletes the stopped Helix Workflow.
  3. * Caller should stop the Workflow before calling this method.
  4. * @param helixManager helix manager
  5. * @param workFlowName workflow needed to be deleted
  6. * @param jobName helix job name
  7. * @throws InterruptedException
  8. */
  9. private static void deleteStoppedHelixJob(HelixManager helixManager, String workFlowName, String jobName)
  10. throws InterruptedException {
  11. WorkflowContext workflowContext = TaskDriver.getWorkflowContext(helixManager, workFlowName);
  12. while (workflowContext.getJobState(TaskUtil.getNamespacedJobName(workFlowName, jobName)) != STOPPED) {
  13. log.info("Waiting for job {} to stop...", jobName);
  14. workflowContext = TaskDriver.getWorkflowContext(helixManager, workFlowName);
  15. Thread.sleep(1000);
  16. }
  17. // deleting the entire workflow, as one workflow contains only one job
  18. new TaskDriver(helixManager).deleteAndWaitForCompletion(workFlowName, 10000L);
  19. log.info("Workflow deleted.");
  20. }
  21. }

代码示例来源:origin: org.apache.helix/helix-core

  1. /**
  2. * Checks if the workflow has completed.
  3. * @param ctx Workflow context containing job states
  4. * @param cfg Workflow config containing set of jobs
  5. * @return returns true if all tasks are {@link TaskState#COMPLETED}, false otherwise.
  6. */
  7. private static boolean isWorkflowComplete(WorkflowContext ctx, WorkflowConfig cfg) {
  8. if (!cfg.isTerminable()) {
  9. return false;
  10. }
  11. for (String job : cfg.getJobDag().getAllNodes()) {
  12. if (ctx.getJobState(job) != TaskState.COMPLETED) {
  13. return false;
  14. }
  15. }
  16. return true;
  17. }

代码示例来源:origin: apache/helix

  1. /**
  2. * Checks if the workflow has completed.
  3. * @param ctx Workflow context containing job states
  4. * @param cfg Workflow config containing set of jobs
  5. * @return returns true if all tasks are {@link TaskState#COMPLETED}, false otherwise.
  6. */
  7. private static boolean isWorkflowComplete(WorkflowContext ctx, WorkflowConfig cfg) {
  8. if (!cfg.isTerminable()) {
  9. return false;
  10. }
  11. for (String job : cfg.getJobDag().getAllNodes()) {
  12. if (ctx.getJobState(job) != TaskState.COMPLETED) {
  13. return false;
  14. }
  15. }
  16. return true;
  17. }

代码示例来源:origin: apache/helix

  1. public void refreshJobsStatus(TaskDriver driver) {
  2. for (Map.Entry<String, JobMonitor> jobMonitor : _perTypeJobMonitorMap.entrySet()) {
  3. jobMonitor.getValue().resetJobGauge();
  4. }
  5. for (String workflow : driver.getWorkflows().keySet()) {
  6. if (workflow.isEmpty()) {
  7. continue;
  8. }
  9. WorkflowConfig workflowConfig = driver.getWorkflowConfig(workflow);
  10. if (workflowConfig == null) {
  11. continue;
  12. }
  13. Set<String> allJobs = workflowConfig.getJobDag().getAllNodes();
  14. WorkflowContext workflowContext = driver.getWorkflowContext(workflow);
  15. for (String job : allJobs) {
  16. TaskState currentState = workflowContext == null ? TaskState.NOT_STARTED : workflowContext.getJobState(job);
  17. updateJobGauges(workflowConfig.getJobTypes() == null ? null : workflowConfig.getJobTypes().get(job),
  18. currentState);
  19. }
  20. }
  21. }

代码示例来源:origin: org.apache.helix/helix-core

  1. /**
  2. * Checks if the workflow has been stopped.
  3. * @param ctx Workflow context containing task states
  4. * @param cfg Workflow config containing set of tasks
  5. * @return returns true if all tasks are {@link TaskState#STOPPED}, false otherwise.
  6. */
  7. protected boolean isWorkflowStopped(WorkflowContext ctx, WorkflowConfig cfg) {
  8. for (String job : cfg.getJobDag().getAllNodes()) {
  9. TaskState jobState = ctx.getJobState(job);
  10. if (jobState != null
  11. && (jobState.equals(TaskState.IN_PROGRESS) || jobState.equals(TaskState.STOPPING))) {
  12. return false;
  13. }
  14. }
  15. return true;
  16. }

代码示例来源:origin: apache/helix

  1. /**
  2. * Checks if the workflow has been stopped.
  3. * @param ctx Workflow context containing task states
  4. * @param cfg Workflow config containing set of tasks
  5. * @return returns true if all tasks are {@link TaskState#STOPPED}, false otherwise.
  6. */
  7. protected boolean isWorkflowStopped(WorkflowContext ctx, WorkflowConfig cfg) {
  8. for (String job : cfg.getJobDag().getAllNodes()) {
  9. TaskState jobState = ctx.getJobState(job);
  10. if (jobState != null
  11. && (jobState.equals(TaskState.IN_PROGRESS) || jobState.equals(TaskState.STOPPING))) {
  12. return false;
  13. }
  14. }
  15. return true;
  16. }

代码示例来源:origin: org.apache.helix/helix-core

  1. public void refreshJobsStatus(TaskDriver driver) {
  2. for (JobMonitor jobMonitor : _perTypeJobMonitorMap.values()) {
  3. jobMonitor.resetJobGauge();
  4. }
  5. for (String workflow : driver.getWorkflows().keySet()) {
  6. if (workflow.isEmpty()) {
  7. continue;
  8. }
  9. WorkflowConfig workflowConfig = driver.getWorkflowConfig(workflow);
  10. if (workflowConfig == null) {
  11. continue;
  12. }
  13. Set<String> allJobs = workflowConfig.getJobDag().getAllNodes();
  14. WorkflowContext workflowContext = driver.getWorkflowContext(workflow);
  15. for (String job : allJobs) {
  16. TaskState currentState = workflowContext == null ? TaskState.NOT_STARTED : workflowContext.getJobState(job);
  17. updateJobGauges(workflowConfig.getJobTypes() == null ? null : workflowConfig.getJobTypes().get(job),
  18. currentState);
  19. }
  20. }
  21. }

相关文章