Esempio n. 1
0
 public void removeWatcher(Run run, Long userId) throws IOException {
   User user = securityManager.getUserById(userId);
   if (user != null) {
     Run clone = runs.get(run.getId());
     if (clone == null) {
       run.removeWatcher(user);
       push(run);
     } else {
       clone.removeWatcher(user);
     }
   }
 }
 @Override
 public boolean respondsTo(Event event) {
   if (event instanceof RunEvent) {
     RunEvent re = (RunEvent) event;
     Run r = re.getEventObject();
     if (re.getEventType().equals(MisoEventType.RUN_FAILED)
         && r.getStatus() != null
         && r.getStatus().getHealth().equals(HealthType.Failed)) {
       log.info("Run " + r.getAlias() + ": " + re.getEventMessage());
       return true;
     }
   }
   return false;
 }
Esempio n. 3
0
 public void pop(Run run) {
   if (enabled) {
     if (run != null) {
       Run clone = runs.get(run.getId());
       if (clone != null) {
         removeListeners(clone);
         clone = null;
         runs.remove(run.getId());
         log.debug("Dequeued " + run.getId());
       }
     }
   } else {
     log.warn("Alerting system disabled.");
   }
 }
Esempio n. 4
0
 public void updateGroupWatcher(Long userId) throws IOException {
   User user = securityManager.getUserById(userId);
   if (user != null) {
     for (Run r : runs.values()) {
       if (user.getGroups().contains(securityManager.getGroupByName("RunWatchers"))) {
         addWatcher(r, userId);
       } else {
         if (r.getSecurityProfile() != null
             && r.getSecurityProfile().getOwner() != null
             && !r.getSecurityProfile().getOwner().equals(user)) {
           removeWatcher(r, userId);
         }
       }
     }
   }
 }
  @Override
  public void generateResponse(Event event) {
    if (event instanceof RunEvent) {
      RunEvent re = (RunEvent) event;
      Run r = re.getEventObject();

      for (User user : r.getWatchers()) {
        Alert a = new DefaultAlert(user);
        a.setAlertLevel(AlertLevel.CRITICAL);
        a.setAlertTitle("Run Failed: " + r.getAlias());

        StringBuilder at = new StringBuilder();
        at.append(
            "The following Run has been set to FAILED: "
                + r.getAlias()
                + " ("
                + event.getEventMessage()
                + "). Please view Run "
                + r.getId()
                + " in MISO for more information");
        if (event.getEventContext().has("baseURL")) {
          at.append(":\n\n" + event.getEventContext().getString("baseURL") + "/run/" + r.getId());
        }
        a.setAlertText(at.toString());

        for (AlerterService as : alerterServices) {
          try {
            as.raiseAlert(a);
          } catch (AlertingException e) {
            log.error("Cannot raise user-level alert:" + e.getMessage());
            e.printStackTrace();
          }
        }
      }

      if (getSaveSystemAlert()) {
        raiseSystemAlert(event);
      }
    }
  }
Esempio n. 6
0
  @Test
  public void testRuns() {
    try {
      // get row count of experiments in the dataset
      int expected = getDataSet().getTable("Run").getRowCount();

      // get number of experiments from the DAO
      int actual = getRunDAO().count();

      // test data contains 2 experiments, check size of returned list
      TestCase.assertEquals("Wrong number of Run", expected, actual);

      System.out.println("Expected number of Run: " + expected + ", actual: " + actual);

      for (Run d : random(getRunDAO(), actual, 5)) {
        TestCase.assertNotNull(d);
        TestCase.assertNotNull(d.getId());
      }
    } catch (Exception e) {
      e.printStackTrace();
      TestCase.fail();
    }
  }
Esempio n. 7
0
 public void push(Run run) {
   if (enabled) {
     if (run != null) {
       Run clone = cloner.deepClone(run);
       if (clone != null) {
         applyListeners(clone);
         if (runs.containsKey(run.getId())) {
           if (clone.getStatus() != null) {
             log.debug(
                 "Not replacing " + clone.getId() + ": " + clone.getStatus().getHealth().name());
           }
         } else {
           runs.put(run.getId(), clone);
           if (clone.getStatus() != null) {
             log.debug("Queued " + clone.getId() + ": " + clone.getStatus().getHealth().name());
           }
         }
       }
     }
   } else {
     log.warn("Alerting system disabled.");
   }
 }
Esempio n. 8
0
  @Deprecated
  public JSONObject previewExperiment(HttpSession session, JSONObject json) {
    String experimentId = (String) json.get("experimentId");

    try {
      Experiment e = requestManager.getExperimentById(Long.parseLong(experimentId));
      Collection<Run> runs = requestManager.listRunsByExperimentId(e.getExperimentId());

      session.setAttribute("experiment", e);

      StringBuilder rb = new StringBuilder();
      for (Run r : runs) {
        rb.append("<li><a href='/miso/run/")
            .append(r.getRunId())
            .append("'>")
            .append(r.getName())
            .append("</a></li>");
      }

      StringBuilder sb = new StringBuilder();
      if (e.getPool() != null) {
        if (e.getPlatform().getPlatformType().equals(PlatformType.ILLUMINA)) {
          for (Object dil : e.getPool().getDilutions()) {
            Sample s = ((LibraryDilution) dil).getLibrary().getSample();
            sb.append("<li><a href='/miso/sample/")
                .append(s.getSampleId())
                .append("'>")
                .append(s.getName())
                .append("</a></li>");
          }
        } else {
          for (Object dil : e.getPool().getDilutions()) {
            Sample s =
                ((emPCRDilution) dil).getEmPCR().getLibraryDilution().getLibrary().getSample();
            sb.append("<li><a href='/miso/sample/")
                .append(s.getSampleId())
                .append("'>")
                .append(s.getName())
                .append("</a></li>");
          }
        }
      }

      StringBuilder b = new StringBuilder();
      b.append(
          "<div onclick=\"Effect.toggle('preview"
              + experimentId
              + "','blind'); return false;\">"
              + "<img src=\"/styles/images/moreinfo.png\" class=\"previewimage\"/></div>");
      b.append("<br/><div id=\"preview" + experimentId + "\" class='exppreview'>");
      b.append("Title: <b>").append(e.getTitle()).append("</b><br/>");
      b.append("Description: <b>").append(e.getDescription()).append("</b><br/>");
      b.append("Samples: <ul class=\"bullets\">").append(sb.toString()).append("</ul>");
      b.append("Runs: <ul class=\"bullets\">").append(rb.toString()).append("</ul>");
      b.append("</div>");
      return JSONUtils.SimpleJSONResponse(b.toString());

    } catch (IOException e) {
      log.debug("Failed", e);
      return JSONUtils.SimpleJSONError("Failed");
    }
  }
Esempio n. 9
0
 public void removeListeners(Run run) {
   run.removeListener(getRunListener());
 }
Esempio n. 10
0
 public void applyListeners(Run run) {
   run.addListener(getRunListener());
 }
Esempio n. 11
0
  private void update(Run r) throws IOException {
    if (enabled) {
      Run clone = runs.get(r.getId());
      if (clone == null) {
        log.debug("Update: no clone - pushing");
        // new run - add all RunWatchers!
        for (User u : securityManager.listUsersByGroupName("RunWatchers")) {
          r.addWatcher(u);
        }
        push(r);
      } else {
        log.debug("Update: got clone of " + clone.getId());
        if (r.getStatus() != null) {
          clone.setStatus(r.getStatus());
        }

        // run QC added
        if (r.getRunQCs().size() > clone.getRunQCs().size()) {
          Set<RunQC> clonedQCs = new HashSet<RunQC>(clone.getRunQCs());
          for (RunQC qc : r.getRunQCs()) {
            if (!clonedQCs.contains(qc)) {
              try {
                clone.addQc(cloner.deepClone(qc));
              } catch (MalformedRunQcException e) {
                throw new IOException(e);
              }
            }
          }
        }

        pop(clone);
        push(r);
      }
    }
  }
Esempio n. 12
0
  @RequestMapping(value = "project/{projectId}", method = RequestMethod.GET)
  public @ResponseBody String jsonRestProject(@PathVariable Long projectId, ModelMap model)
      throws IOException {
    StringBuilder sb = new StringBuilder();

    Project p = requestManager.getProjectById(projectId);
    sb.append("'id':'" + projectId + "'");
    sb.append(",");
    sb.append("'name':'" + p.getName() + "'");
    sb.append(",");
    sb.append("'alias':'" + p.getAlias() + "'");
    sb.append(",");
    sb.append("'progress':'" + p.getProgress().name() + "'");
    sb.append(",");
    sb.append("'description':'" + p.getDescription() + "'");
    sb.append(",");

    sb.append("'overviews':[");
    if (p.getOverviews().size() > 0) {
      int oi = 0;
      for (ProjectOverview overview : p.getOverviews()) {
        oi++;
        sb.append("{");
        sb.append("'allSampleQcPassed':" + overview.getAllSampleQcPassed());
        sb.append(",");
        sb.append("'libraryPreparationComplete':" + overview.getLibraryPreparationComplete());
        sb.append(",");
        sb.append("'allLibrariesQcPassed':" + overview.getAllLibrariesQcPassed());
        sb.append(",");
        sb.append("'allPoolsConstructed':" + overview.getAllPoolsConstructed());
        sb.append(",");
        sb.append("'allRunsCompleted':" + overview.getAllRunsCompleted());
        sb.append(",");
        sb.append("'primaryAnalysisCompleted':" + overview.getPrimaryAnalysisCompleted());
        sb.append("}");
        if (oi < p.getOverviews().size()) {
          sb.append(",");
        }
      }
    }
    sb.append("]");
    sb.append(",");

    sb.append("'samples':[");
    Collection<Sample> samples = requestManager.listAllSamplesByProjectId(projectId);
    if (samples.size() > 0) {
      int si = 0;
      for (Sample sample : samples) {
        si++;
        String sampleQubit = "not available";
        if (requestManager.listAllSampleQCsBySampleId(sample.getId()).size() > 0) {
          ArrayList<SampleQC> sampleQcList =
              new ArrayList(requestManager.listAllSampleQCsBySampleId(sample.getId()));
          SampleQC lastQc = sampleQcList.get(sampleQcList.size() - 1);
          sampleQubit = (lastQc.getResults() != null ? lastQc.getResults().toString() : "");
        }
        sb.append("{");
        sb.append("'alias':'" + sample.getAlias() + "'");
        sb.append(",");
        sb.append(
            "'qcPassed':'"
                + (sample.getQcPassed() != null ? sample.getQcPassed().toString() : "")
                + "'");
        sb.append(",");

        sb.append(
            "'receivedDate':'"
                + (sample.getReceivedDate() != null
                    ? LimsUtils.getDateAsString(sample.getReceivedDate())
                    : "not available")
                + "'");
        sb.append(",");
        sb.append(
            "'sampleType':'"
                + (sample.getSampleType() != null ? sample.getSampleType() : "")
                + "'");
        sb.append(",");
        sb.append("'sampleQubit':'" + sampleQubit + "'");
        sb.append("}");

        if (si < samples.size()) {
          sb.append(",");
        }
      }
    }
    sb.append("]");
    sb.append(",");

    sb.append("'runs':[");
    Collection<Run> runs = requestManager.listAllRunsByProjectId(projectId);
    if (runs.size() > 0) {
      int ri = 0;
      for (Run run : runs) {
        ri++;
        if (!run.getStatus().getHealth().getKey().equals("Failed")) {
          ArrayList<String> runSamples = new ArrayList();
          Collection<SequencerPartitionContainer<SequencerPoolPartition>> spcs =
              requestManager.listSequencerPartitionContainersByRunId(run.getId());
          if (spcs.size() > 0) {
            for (SequencerPartitionContainer<SequencerPoolPartition> spc : spcs) {

              if (spc.getPartitions().size() > 0) {
                for (SequencerPoolPartition spp : spc.getPartitions()) {
                  if (spp.getPool() != null) {
                    if (spp.getPool().getDilutions().size() > 0) {
                      for (Dilution dilution : spp.getPool().getDilutions()) {
                        Sample sample = dilution.getLibrary().getSample();
                        if (sample.getProject().equals(p)) {
                          runSamples.add(sample.getAlias());
                        }
                      }
                    }
                  }
                }
              }
            }
          }

          sb.append("{");
          sb.append("'name':'" + run.getName() + "'");
          sb.append(",");
          sb.append(
              "'status':'"
                  + (run.getStatus() != null && run.getStatus().getHealth() != null
                      ? run.getStatus().getHealth().getKey()
                      : "")
                  + "'");
          sb.append(",");
          sb.append(
              "'startDate':'"
                  + (run.getStatus() != null && run.getStatus().getStartDate() != null
                      ? run.getStatus().getStartDate().toString()
                      : "")
                  + "'");
          sb.append(",");
          sb.append(
              "'completionDate':'"
                  + (run.getStatus() != null && run.getStatus().getCompletionDate() != null
                      ? run.getStatus().getCompletionDate().toString()
                      : "")
                  + "'");
          sb.append(",");
          sb.append(
              "'platformType':'"
                  + (run.getPlatformType() != null ? run.getPlatformType().getKey() : "")
                  + "'");
          sb.append(",");
          sb.append("'samples':[");
          if (runSamples.size() > 0) {
            int rsi = 0;
            for (String alias : runSamples) {
              rsi++;
              sb.append("{'sampleAlias':'" + alias + "'}");
              if (rsi < runSamples.size()) {
                sb.append(",");
              }
            }
          }
          sb.append("]");
          sb.append("}");
          if (ri < runs.size()) {
            sb.append(",");
          }
        }
      }
    }
    sb.append("]");

    return "{" + sb.toString() + "}";
  }
  private Map<String, Run> processRunJSON(
      HealthType ht, JSONArray runs, RequestManager requestManager) {
    Map<String, Run> updatedRuns = new HashMap<String, Run>();
    List<Run> runsToSave = new ArrayList<Run>();
    // 2011-01-25 15:37:27.093
    DateFormat logDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
    DateFormat simpleLogDateFormat = new SimpleDateFormat("yyyyMMdd");
    Pattern simpleDateRegex = Pattern.compile("[0-9]{8}");

    StringBuilder sb = new StringBuilder();

    for (JSONObject run : (Iterable<JSONObject>) runs) {
      String runName = run.getString("runName");
      sb.append("Processing " + runName + "\n");
      log.debug("Processing " + runName);

      if (run.has("status")) {
        String xml = run.getString("status");
        Status is = new SolidStatus(xml);
        is.setHealth(ht);
        is.setRunName(runName);

        Run r = null;
        Matcher m = p.matcher(runName);
        if (m.matches()) {
          try {
            r = requestManager.getRunByAlias(runName);
          } catch (IOException ioe) {
            log.warn(
                "Cannot find run by this alias. This usually means the run hasn't been previously imported. If attemptRunPopulation is false, processing will not take place for this run!");
          }
        }

        try {
          if (attemptRunPopulation) {
            if (r == null) {
              log.debug("Saving new run and status: " + is.getRunName());
              r = new SolidRun(xml);
              r.getStatus().setHealth(ht);
              if (run.has("fullPath")) {
                r.setFilePath(run.getString("fullPath"));
              }

              SequencerReference sr = null;
              if (run.has("sequencerName")) {
                sr = requestManager.getSequencerReferenceByName(run.getString("sequencerName"));
                r.getStatus().setInstrumentName(run.getString("sequencerName"));
                r.setSequencerReference(sr);
              }
              if (r.getSequencerReference() == null) {
                sr = requestManager.getSequencerReferenceByName(m.group(1));
                r.getStatus().setInstrumentName(m.group(1));
                r.setSequencerReference(sr);
              }
              if (r.getSequencerReference() == null) {
                sr = requestManager.getSequencerReferenceByName(r.getStatus().getInstrumentName());
                r.setSequencerReference(sr);
              }

              if (r.getSequencerReference() != null) {
                if (run.has("startDate")) {
                  try {
                    log.debug("Updating start date:" + run.getString("startDate"));

                    Matcher m2 = simpleDateRegex.matcher(run.getString("startDate"));
                    if (m2.matches()) {
                      r.getStatus()
                          .setStartDate(simpleLogDateFormat.parse(run.getString("startDate")));
                    } else {
                      r.getStatus().setStartDate(logDateFormat.parse(run.getString("startDate")));
                    }
                  } catch (ParseException e) {
                    log.error(e.getMessage());
                    e.printStackTrace();
                  }
                }

                if (run.has("completionDate")) {
                  try {
                    if (run.get("completionDate") != null
                        && !run.getString("completionDate").equals("null")) {
                      log.debug("Updating completion date:" + run.getString("completionDate"));
                      r.getStatus()
                          .setCompletionDate(logDateFormat.parse(run.getString("completionDate")));
                    } else {
                      r.getStatus().setCompletionDate(null);
                    }
                  } catch (ParseException e) {
                    log.error(e.getMessage());
                    e.printStackTrace();
                  }
                }
              }
            } else {
              log.debug("Updating existing run and status: " + is.getRunName());

              r.setAlias(runName);
              r.setPlatformType(PlatformType.SOLID);

              if (r.getSequencerReference() == null) {
                SequencerReference sr = null;
                if (run.has("sequencerName")) {
                  sr = requestManager.getSequencerReferenceByName(run.getString("sequencerName"));
                  r.getStatus().setInstrumentName(run.getString("sequencerName"));
                  r.setSequencerReference(sr);
                }
                if (r.getSequencerReference() == null) {
                  sr = requestManager.getSequencerReferenceByName(m.group(1));
                  r.getStatus().setInstrumentName(m.group(1));
                  r.setSequencerReference(sr);
                }
                if (r.getSequencerReference() == null) {
                  sr =
                      requestManager.getSequencerReferenceByName(r.getStatus().getInstrumentName());
                  r.setSequencerReference(sr);
                }
              }
              if (r.getSequencerReference() != null) {
                if (run.has("startDate")) {
                  try {
                    log.debug("Updating start date:" + run.getString("startDate"));

                    Matcher m2 = simpleDateRegex.matcher(run.getString("startDate"));
                    if (m2.matches()) {
                      r.getStatus()
                          .setStartDate(simpleLogDateFormat.parse(run.getString("startDate")));
                    } else {
                      r.getStatus().setStartDate(logDateFormat.parse(run.getString("startDate")));
                    }
                  } catch (ParseException e) {
                    log.error(e.getMessage());
                    e.printStackTrace();
                  }
                }

                if (run.has("completionDate")) {
                  try {
                    if (run.get("completionDate") != null
                        && !run.getString("completionDate").equals("null")) {
                      log.debug("Updating completion date:" + run.getString("completionDate"));
                      r.getStatus()
                          .setCompletionDate(logDateFormat.parse(run.getString("completionDate")));
                    } else {
                      r.getStatus().setCompletionDate(null);
                    }
                  } catch (ParseException e) {
                    log.error(e.getMessage());
                    e.printStackTrace();
                  }
                }

                // update path if changed
                if (run.has("fullPath")
                    && !"".equals(run.getString("fullPath"))
                    && r.getFilePath() != null
                    && !"".equals(r.getFilePath())) {
                  if (!run.getString("fullPath").equals(r.getFilePath())) {
                    log.debug(
                        "Updating run file path:"
                            + r.getFilePath()
                            + " -> "
                            + run.getString("fullPath"));
                    r.setFilePath(run.getString("fullPath"));
                  }
                }

                // update status if run isn't completed or failed
                if (!r.getStatus().getHealth().equals(HealthType.Completed)
                    && !r.getStatus().getHealth().equals(HealthType.Failed)) {
                  log.debug(
                      "Saving previously saved status: "
                          + is.getRunName()
                          + " ("
                          + r.getStatus().getHealth().getKey()
                          + " -> "
                          + is.getHealth().getKey()
                          + ")");
                  r.setStatus(is);
                }
              }
            }

            if (r.getSequencerReference() != null) {
              List<SequencerPartitionContainer<SequencerPoolPartition>> fs =
                  ((SolidRun) r).getSequencerPartitionContainers();
              if (fs.isEmpty()) {
                if (run.has("containerId") && !"".equals(run.getString("containerId"))) {
                  Collection<SequencerPartitionContainer<SequencerPoolPartition>> pfs =
                      requestManager.listSequencerPartitionContainersByBarcode(
                          run.getString("containerId"));
                  if (!pfs.isEmpty()) {
                    if (pfs.size() == 1) {
                      SequencerPartitionContainer lf =
                          new ArrayList<SequencerPartitionContainer<SequencerPoolPartition>>(pfs)
                              .get(0);
                      if (lf.getSecurityProfile() != null && r.getSecurityProfile() == null) {
                        r.setSecurityProfile(lf.getSecurityProfile());
                      }
                      if (lf.getPlatform() == null
                          && r.getSequencerReference().getPlatform() != null) {
                        lf.setPlatform(r.getSequencerReference().getPlatform());
                      }
                      //                      else {
                      //                        lf.setPlatformType(PlatformType.SOLID);
                      //                      }
                      ((RunImpl) r).addSequencerPartitionContainer(lf);
                    }
                  } else {
                    log.debug("No containers linked to run " + r.getId() + ": creating...");
                    SequencerPartitionContainer f = new SequencerPartitionContainerImpl();
                    f.setSecurityProfile(r.getSecurityProfile());
                    f.initEmptyPartitions();
                    f.setIdentificationBarcode(run.getString("containerNum"));
                    if (f.getPlatform() == null
                        && r.getSequencerReference().getPlatform() != null) {
                      f.setPlatform(r.getSequencerReference().getPlatform());
                    }
                    //                    else {
                    //                      f.setPlatformType(PlatformType.SOLID);
                    //                    }
                    // f.setPaired(r.getPairedEnd());
                    ((RunImpl) r).addSequencerPartitionContainer(f);
                  }
                }
              } else {
                SequencerPartitionContainer f = fs.iterator().next();
                log.debug("Got container " + f.getId());

                if (f.getSecurityProfile() == null) {
                  f.setSecurityProfile(r.getSecurityProfile());
                }

                if (f.getPlatform() == null && r.getSequencerReference().getPlatform() != null) {
                  f.setPlatform(r.getSequencerReference().getPlatform());
                }
                //                else {
                //                  f.setPlatformType(PlatformType.SOLID);
                //                }

                if (run.has("containerId") && !"".equals(run.getString("containerId"))) {
                  f.setIdentificationBarcode(run.getString("containerId"));
                }

                long flowId = requestManager.saveSequencerPartitionContainer(f);
                f.setId(flowId);
              }

              updatedRuns.put(r.getAlias(), r);
              runsToSave.add(r);
            }
          }
        } catch (IOException e) {
          log.error(e.getMessage());
          e.printStackTrace();
        }
      }
    }

    try {
      if (runsToSave.size() > 0) {
        int[] saved = requestManager.saveRuns(runsToSave);
        log.info("Batch saved " + saved.length + " / " + runs.size() + " runs");
      }
    } catch (IOException e) {
      log.error("Couldn't save run batch: " + e.getMessage());
      e.printStackTrace();
    }

    return updatedRuns;
  }