Exemplo n.º 1
0
  /**
   * Actually rearrange the exertions in the job according to the sorting
   *
   * @param topXrt
   * @param sortedExertions
   * @throws CycleDetectedException
   * @throws ContextException
   */
  private void reorderJob(Exertion topXrt, List<Mogram> sortedExertions) {
    List<Mogram> sortedSubset = new ArrayList(sortedExertions);
    sortedSubset.retainAll(topXrt.getMograms());

    if (topXrt.getFlowType() != null && topXrt.getFlowType().equals(Strategy.Flow.AUTO)) {
      ((ServiceExertion) topXrt).setFlowType(setFlow(topXrt, sortedSubset));
      logger.info("FLOW for exertion: " + topXrt.getName() + " set to: " + topXrt.getFlowType());
    }
    List<String> exertionsBefore = new ArrayList<String>();
    for (Mogram xrt : topXrt.getMograms()) exertionsBefore.add(xrt.getName());

    List<String> exertionsAfter = new ArrayList<String>();
    for (Mogram xrt : sortedExertions) exertionsAfter.add(xrt.getName());
    if (!topXrt.getMograms().equals(sortedSubset)) {
      logger.info("Order of exertions for " + topXrt.getName() + " will be changed: ");
      logger.info("From: " + exertionsBefore);
      logger.info("To: " + exertionsAfter);
      topXrt.getMograms().removeAll(sortedSubset);
      topXrt.getMograms().addAll(sortedSubset);
    }

    for (Iterator i = topXrt.getMograms().iterator(); i.hasNext(); ) {
      Exertion xrt = (Exertion) i.next();
      if (xrt instanceof Job) {
        reorderJob(xrt, sortedExertions);
      }
    }
  }
Exemplo n.º 2
0
  /** Construct the ExertionSorter */
  public ExertionSorter(Exertion topLevelJob) throws ContextException, SortingException {

    dag = new DAG();
    projectMap = new HashMap();
    contextIdsMap = new HashMap<String, String>();
    revContextIdsMap = new HashMap<String, String>();
    this.topLevelJob = topLevelJob;

    addVertex(this.topLevelJob);

    try {
      getMapping(this.topLevelJob);
      checkParentCycle(this.topLevelJob);

      List sortedProjects = new ArrayList();
      for (Iterator i = TopologicalSorter.sort(dag).iterator(); i.hasNext(); ) {
        String id = (String) i.next();
        sortedProjects.add(projectMap.get(id));
      }

      this.sortedProjects = Collections.unmodifiableList(sortedProjects);
      reorderJob(this.topLevelJob, this.sortedProjects);
    } catch (CycleDetectedException ce) {
      throw new SortingException(ce.getMessage());
    }
  }
Exemplo n.º 3
0
 /**
  * Helper method to build a tree of all exertion IDs in a tree - required by setFlow
  *
  * @param sortedSubXrt
  * @return
  */
 private List<String> addSubExertions(List<Mogram> sortedSubXrt) {
   List<String> sortedSubsetIds = new ArrayList<String>();
   for (Mogram xrt : sortedSubXrt) {
     sortedSubsetIds.add(xrt.getId().toString());
     if (xrt instanceof Job) sortedSubsetIds.addAll(addSubExertions(((Job) xrt).getMograms()));
   }
   return sortedSubsetIds;
 }