Пример #1
0
    @Override
    public void handle(HttpExchange arg0) throws IOException {

      try {
        JSONObject request =
            (JSONObject) JSONSerializer.toJSON(IOUtils.toString(arg0.getRequestBody()));
        String email = request.getString("email");
        String key = request.getString("key");

        for (int i = 0; i < jobs.size(); i++) {
          TnrsJob job = jobs.get(i);
          if (job.getRequest().getId().equals(key) && job.getRequest().getEmail().equals(email)) {
            JSONObject json = (JSONObject) JSONSerializer.toJSON(job.toJsonString());
            json.put("status", "incomplete");
            json.put("progress", job.progress());

            HandlerHelper.writeResponseRequest(arg0, 200, json.toString(), "application/json");
            return;
          }
        }
        if (JobHelper.jobFileExists(baseFolder, email, key)) {
          TnrsJob job = JobHelper.readJobInfo(baseFolder, email, key);

          HandlerHelper.writeResponseRequest(arg0, 200, job.toJsonString(), "application/json");
        } else {
          HandlerHelper.writeResponseRequest(
              arg0, 500, "No such job exists o it might have expired", "text/plain");
        }

      } catch (Exception ex) {
        log.error(ExceptionUtils.getFullStackTrace(ex));
        throw new IOException(ex);
      }
    }
Пример #2
0
  private void sendNormalCompletionEmail(TnrsJob job) throws Exception {

    EmailAttachment attachment = new EmailAttachment();
    attachment.setPath(JobHelper.createJobInfoFile(job));
    attachment.setDisposition(EmailAttachment.ATTACHMENT);
    attachment.setDescription("Job information");
    attachment.setName(job.getRequest().getFilename() + " " + job.getRequest().getId() + ".txt");
    MultiPartEmail response = new MultiPartEmail();
    response.setHostName(properties.getProperty("org.iplantc.tnrs.mail.host"));
    response.setSmtpPort(Integer.parseInt(properties.getProperty("org.iplantc.tnrs.mail.port")));
    response.setFrom("*****@*****.**");
    response.setSubject("TNRS Job completion");
    response.setMsg(
        "Your TNRS "
            + job.getTypeString()
            + " job for the file "
            + job.getRequest().getOriginalFilename()
            + " completed on "
            + dateFormat.format(new Date())
            + ".Details describing the settings applied for this job are attached to this email. You may wish to retain this for your records. \n\n Your results will be available for 7 days, after which they will be deleted from our system. 	\n\n"
            + "To view your results, go to the TNRS website at http://tnrs.iplantcollaborative.org, select the \"Retrieve results\" tab, and enter your email address and the following submission key:\n\n"
            + job.getRequest().getId()
            + "\n\n"
            + "Please contact us at [email protected] if you have any difficulty retrieving your results.\n"
            + "\n"
            + "Thank you,\n"
            + "iPlant Collaborative");
    response.addTo(job.getRequest().getEmail());
    response.attach(attachment);
    response.send();
  }
Пример #3
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();
      }
    }
 /**
  * Checks if the map scale is valid
  *
  * @return <code>true</code> if map scale is valid; <code>false</code> otherwise.
  */
 protected boolean validateMapScales() {
   return JobHelper.isRequestScalesInRange(
       this.session.getMapScales(),
       (int) this.session.getLocation().getZoom(),
       layer,
       session.getLocation().getSrs());
 }
Пример #5
0
    @Override
    public void handle(HttpExchange arg0) throws IOException {
      try {
        JSONObject json =
            (JSONObject) JSONSerializer.toJSON(IOUtils.toString(arg0.getRequestBody()));

        JSONObject result = new JSONObject();

        String email = json.getString("email");
        String key = json.getString("key");

        for (int i = 0; i < jobs.size(); i++) {

          TnrsJob job = jobs.get(i);

          if (job.getRequest().getEmail().equals(email) && job.getRequest().getId().equals(key)) {
            if (job.status().equals("failed") || job.status().equals("error")) {
              result.put("type", "failed");
            } else {
              result.put("type", "incomplete");
              double progress = job.progress();
              if (job.progress() == 100.0) {
                progress = 99.0;
              }
              result.put("progress", progress);
            }
            HandlerHelper.writeResponseRequest(arg0, 200, result.toString(), "application/json");

            return;
          }
        }

        String filename = baseFolder + email.replace("@", "-").replace(".", "-") + "/result" + key;

        File results = new File(filename);

        if (!results.exists()) {
          result.put("type", "non-existent");
        } else {
          result.put("type", "complete");
          TnrsJob job = JobHelper.readJobInfo(baseFolder, email, key);

          result.put("job_type", job.getTypeString());
        }

        HandlerHelper.writeResponseRequest(arg0, 200, result.toString(), "application/json");

        return;
      } catch (Exception ex) {
        log.error(ExceptionUtils.getFullStackTrace(ex));
        throw new IOException(ex);
      }
    }
Пример #6
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();
    }
  }
Пример #7
0
    @Override
    public void handle(HttpExchange arg0) throws IOException {
      try {

        JSONObject json =
            (JSONObject) JSONSerializer.toJSON(IOUtils.toString(arg0.getRequestBody()));

        String email = json.getString("email");
        String key = json.getString("key");
        String session_id = json.getString("session_id");

        TnrsJob job = JobHelper.readJobInfo(baseFolder, email, key);

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

          ParsingResultsFile results = new ParsingResultsFile(job, baseFolder);
          results.createFileForDownload(properties.getProperty("org.iplantc.folder.tmp"));

        } else {

          MatchingResultsFile results = new MatchingResultsFile(job, baseFolder, session_id, false);

          results.createFileForDownload(
              properties.getProperty("org.iplantc.tnrs.folder.tmp"), json);

          results.close();
        }

        String url = servicesUrl + "getcsv?id=" + key;

        HandlerHelper.writeResponseRequest(arg0, 200, url, null);
      } catch (Exception ex) {
        log.error(ExceptionUtils.getFullStackTrace(ex));
        ex.printStackTrace();
      }
    }
 void waitTillJobHasFinished() {
   jobHelper.waitTillJobHasFinished();
 }