예제 #1
0
파일: Clay.java 프로젝트: repshak/BeeQueue
 @Override
 public String toString() {
   return ToStringUtil.toString(this);
 }
예제 #2
0
  public void doLaundryList(Coordiantor coordinator) throws Exception {
    /* if configuration was updated and load all updates
     */
    WorkerData.instance.checkGlobalConfig(coordinator);

    /* Check if host object initialized and if not make sure that
     * host/group exists in db */
    coordinator.ensureHost(WorkerData.instance);

    /* Check CPU & Memory and up update
     * statistics */
    agent.runStatistics();
    coordinator.storeStatistics(WorkerData.instance);

    /* Check all active workers in the same group,
     * calculate next beat time
     * Update status of the workers and beet time
     * on the same machine if necessary.
     */
    coordinator.ensureWorker(WorkerData.instance);

    Map<String, DomainTemplate> activeDomains = Singletons.getGlobalConfig().activeDomains();
    List<BeeQueueDomain> domains = LazyList.morph(BeeQueueDomain.TO_DOMAIN, activeDomains.keySet());
    coordinator.ensureDomains(domains);
    /* Process all messages and create stages, create runs for
     * unblocked stages. Pick runs to execute. Execute.
     */
    coordinator.processEmittedMessages();

    BeeQueueStage readyToRun = coordinator.pickStageToRun();
    if (readyToRun != null) {
      RunHelper runHelper = new RunHelper(readyToRun, WorkerData.instance.worker);
      coordinator.storeRun(runHelper.run);
      runHelper.start();
      coordinator.storeRun(runHelper.run);
      coordinator.updateStage(runHelper.stage);
    }
    /* Run ps. Identify all processes that currently executed.
     * Check all processes that finished on host an update ther stages
     * appropriately
     */
    Map<Long, BeeQueueRun> notFinishedRuns = new LinkedHashMap<Long, BeeQueueRun>();
    for (BeeQueueRun run : coordinator.allCurrentRuns(WorkerData.instance)) {
      File rc = new File(run.dir, "rc.log");
      if (rc.exists()) {
        int returnCode = Integer.parseInt(Files.readAll(rc).trim());
        run.state = returnCode == 0 ? RunState.SUCCESS : RunState.FAILURE;
        coordinator.storeRun(run);
        if (run.state == RunState.SUCCESS) {
          run.stage.newState = StageState.SUCCESS;
        } else {
          run.stage.newState = run.stage.retriesLeft > 0 ? StageState.READY : StageState.FAILURE;
        }
        coordinator.updateStage(run.stage);
      } else {
        notFinishedRuns.put(run.id, run);
      }
    }

    ProcRawData[] ps = agent.runProcessStatistics();
    List<BeeQueueProcess> allActiveProcesses =
        coordinator.allActiveProcessesOnHost(WorkerData.instance.host);
    for (int i = 0; i < ps.length; i++) {
      ProcRawData procRawData = ps[i];
      if (procRawData.env != null && procRawData.env.get(RunHelper.BQ_RUN_ID) != null) {
        BeeQueueProcess process = new BeeQueueProcess();
        process.runId = Long.parseLong((String) procRawData.env.get(RunHelper.BQ_RUN_ID));
        process.pid = "" + procRawData.pid;
        process.ppid = "" + procRawData.state.getPpid();
        process.processName = procRawData.allArgs();
        coordinator.storeProcess(process);
        allActiveProcesses.remove(process);
        BeeQueueRun runThatStillHaveProcesses = notFinishedRuns.remove(process.runId);
        if (runThatStillHaveProcesses != null) {
          runThatStillHaveProcesses.justUpTimeStamp = true;
          coordinator.storeRun(runThatStillHaveProcesses);
        }
      }
    }
    for (BeeQueueProcess process : allActiveProcesses) {
      process.down = true;
      coordinator.storeProcess(process);
    }
    if (notFinishedRuns.size() > 0) {
      ToStringUtil.out("Cannot detect any info about processes:\n", notFinishedRuns);
    }
    coordinator.updateFinishedJobsAndMessages();
  }