Exemplo n.º 1
0
    @Override
    public void run() {
      try {
        StopWatch stp2 = new StopWatch();
        stp2.start();
        JSONObject json = new JSONObject();
        job.setStatus("running");
        if (job.progress() == 100.0) {

          finalizeJob(job);
          return;
        }
        Vector<String> ids = new Vector<String>();
        Vector<String> original_names = new Vector<String>();

        String data = job.getNextDataBatch();

        if (data == null || data.equals("")) return;

        String[] lines = data.split("\n");

        if (job.containsId()) {
          for (int i = 0; i < lines.length; i++) {
            if (lines[i].trim().equals("")) continue;
            ids.add(NameUtil.getNameId(lines[i]));
          }
        }

        for (int i = 0; i < lines.length; i++) {
          original_names.add(NameUtil.processName(lines[i], job.containsId()));
        }

        String names = NameUtil.CleanNames(lines, job);

        if (names.equals("")) return;

        if (job.getType() == TnrsJob.NAME_MATCH_JOB) {

          TaxamatchInterface taxa_match = new TaxamatchInterface(tnrsBaseUrl);
          String result = taxa_match.queryTaxamatch(names, job);
          json = (JSONObject) JSONSerializer.toJSON(result);

        } else if (job.getType() == TnrsJob.PARSING_JOB) {

          json = gni_interface.parseNames(names);
        }
        if (job.outstandingNames() == 0) {
          JobHelper.persistJobInfo(baseFolder, job);
        }
        saveResults(job, json, ids, original_names, "");

        job.setStatus("idle");
        stp2.stop();
        log.info("overall :" + stp2.toString());
      } catch (Exception ex) {
        log.error(ExceptionUtils.getFullStackTrace(ex));
        job.setStatus("failed");
        ex.printStackTrace();
      }
    }
Exemplo n.º 2
0
  public void finalizeJob(TnrsJob job) throws Exception {
    synchronized (jobs) {
      jobs.remove(job);
    }

    job.setStatus("complete");

    if (job.email() && !job.getRequest().getEmail().trim().equals("*****@*****.**")) {
      job.setFinishedAt(new Date().toString());
      job_ids.remove(job.getRequest().getId());
      sendNormalCompletionEmail(job);
    }
  }
Exemplo n.º 3
0
  /**
   * This main loop iterates over the submitted jobs and creates the corresponding threads that will
   * carry the execution of each job segment.
   */
  @Override
  public void run() {
    try {
      int jobno = 0;

      while (true) {

        sleep(20);
        synchronized (jobs) {
          if (jobs.size() == 0) {

            continue;
          }
        }

        TnrsJob job = jobs.get(jobno % jobs.size());
        if (job.status().equalsIgnoreCase("idle")) {
          ExecutionThread thread = new ExecutionThread(job);
          threads.add(thread);
          thread.start();
        } else if (job.status().equalsIgnoreCase("stopped")) {
          jobs.remove(job);
          JobHelper.cleanJobData(baseFolder, job);
          jobno = 0;
          continue;
        } else if (job.status().equals("failed")) {
          sendFailedJobEmail(job);
          job.setStatus("error");
        }
        jobno++;

        if (jobs.size() == 200) {

          for (int i = 0; i < threads.size(); i++) {
            threads.elementAt(i).join();
          }
          jobno = 0;
          threads.clear();
        }

        sleep(10);
      }

    } catch (Exception e) {
      log.error(ExceptionUtils.getFullStackTrace(e));
      e.printStackTrace();
    }
  }
Exemplo n.º 4
0
  public TnrsJob submitJob(String jsons) throws Exception {
    JSONObject json = (JSONObject) JSONSerializer.toJSON(jsons);
    boolean emailr = false;

    TnrsJobRequest request =
        new TnrsJobRequest(
            json.getString("email"),
            json.getString("file_name"),
            json.getString("original"),
            emailr);
    TnrsJob job = new TnrsJob(request, new Date().toString(), json.getString("type"));
    job.setSensitivity(Double.parseDouble(json.getString("sensitivity").toLowerCase().trim()));
    job.setTnrs_version(properties.getProperty("org.iplantc.tnrs.version"));
    synchronized (jobs) {
      jobs.add(job);
    }
    job_ids.put(request.getId(), job);
    job.setContainsId(json.getBoolean("has_id"));
    job.setStatus("idle");
    job.getRequest().setId(json.getString("id"));

    return job;
  }