Beispiel #1
0
 private void handleAjaxFlowStatus(Map<String, Object> respMap, int execid) {
   ExecutableFlow flow = flowRunnerManager.getExecutableFlow(execid);
   if (flow == null) {
     respMap.put(STATUS_PARAM, RESPONSE_NOTFOUND);
   } else {
     respMap.put(STATUS_PARAM, flow.getStatus().toString());
     respMap.put(RESPONSE_UPDATETIME, flow.getUpdateTime());
   }
 }
Beispiel #2
0
  private void cancel() {
    synchronized (mainSyncObj) {
      logger.info("Cancel has been called on flow " + execId);
      flowPaused = false;
      flowCancelled = true;

      if (watcher != null) {
        logger.info("Watcher is attached. Stopping watcher.");
        watcher.stopWatcher();
        logger.info("Watcher cancelled status is " + watcher.isWatchCancelled());
      }

      logger.info("Cancelling " + activeJobRunners.size() + " jobs.");
      for (JobRunner runner : activeJobRunners.values()) {
        runner.cancel();
      }

      if (flow.getStatus() != Status.FAILED && flow.getStatus() != Status.FAILED_FINISHING) {
        logger.info("Setting flow status to " + Status.KILLED.toString());
        flow.setStatus(Status.KILLED);
      }
    }
  }
Beispiel #3
0
  /**
   * Main method that executes the jobs.
   *
   * @throws Exception
   */
  private void runFlow() throws Exception {
    logger.info("Starting flows");
    flow.setStatus(Status.RUNNING);
    updateFlow();

    while (!flowFinished) {
      synchronized (mainSyncObj) {
        if (flowPaused) {
          try {
            mainSyncObj.wait(CHECK_WAIT_MS);
          } catch (InterruptedException e) {
          }

          continue;
        } else {
          List<ExecutableNode> jobsReadyToRun = findReadyJobsToRun();

          if (!jobsReadyToRun.isEmpty() && !flowCancelled) {
            for (ExecutableNode node : jobsReadyToRun) {
              long currentTime = System.currentTimeMillis();

              // Queue a job only if it's ready to run.
              if (node.getStatus() == Status.READY) {
                // Collect output props from the job's dependencies.
                Props outputProps = collectOutputProps(node);
                node.setStatus(Status.QUEUED);
                JobRunner runner = createJobRunner(node, outputProps);
                logger.info("Submitting job " + node.getJobId() + " to run.");
                try {
                  executorService.submit(runner);
                  jobRunners.put(node.getJobId(), runner);
                  activeJobRunners.put(node.getJobId(), runner);
                } catch (RejectedExecutionException e) {
                  logger.error(e);
                }
                ;

              } // If killed, then auto complete and KILL
              else if (node.getStatus() == Status.KILLED) {
                logger.info("Killing " + node.getJobId() + " due to prior errors.");
                node.setStartTime(currentTime);
                node.setEndTime(currentTime);
                fireEventListeners(Event.create(this, Type.JOB_FINISHED, node));
              } // If disabled, then we auto skip
              else if (node.getStatus() == Status.DISABLED) {
                logger.info("Skipping disabled job " + node.getJobId() + ".");
                node.setStartTime(currentTime);
                node.setEndTime(currentTime);
                node.setStatus(Status.SKIPPED);
                fireEventListeners(Event.create(this, Type.JOB_FINISHED, node));
              }
            }

            updateFlow();
          } else {
            if (isFlowFinished() || flowCancelled) {
              flowFinished = true;
              break;
            }

            try {
              mainSyncObj.wait(CHECK_WAIT_MS);
            } catch (InterruptedException e) {
            }
          }
        }
      }
    }

    if (flowCancelled) {
      try {
        logger.info("Flow was force cancelled cleaning up.");
        for (JobRunner activeRunner : activeJobRunners.values()) {
          activeRunner.cancel();
        }

        for (ExecutableNode node : flow.getExecutableNodes()) {
          if (Status.isStatusFinished(node.getStatus())) {
            continue;
          } else if (node.getStatus() == Status.DISABLED) {
            node.setStatus(Status.SKIPPED);
          } else {
            node.setStatus(Status.KILLED);
          }
          fireEventListeners(Event.create(this, Type.JOB_FINISHED, node));
        }
      } catch (Exception e) {
        logger.error(e);
      }

      updateFlow();
    }

    logger.info("Finishing up flow. Awaiting Termination");
    executorService.shutdown();

    synchronized (mainSyncObj) {
      switch (flow.getStatus()) {
        case FAILED_FINISHING:
          logger.info("Setting flow status to Failed.");
          flow.setStatus(Status.FAILED);
        case FAILED:
        case KILLED:
          logger.info("Flow is set to " + flow.getStatus().toString());
          break;
        default:
          flow.setStatus(Status.SUCCEEDED);
          logger.info("Flow is set to " + flow.getStatus().toString());
      }
    }
  }