/** * Return true if this composite <code>Job</code> is a tree. * * @param visited a set of visited exertions * @return true if this <code>Job</code> composite is a tree * @see sorcer.service.Exertion#isTree() */ public boolean isTree(Set visited) { visited.add(this); Iterator i = exertions.iterator(); while (i.hasNext()) { ServiceExertion e = (ServiceExertion) i.next(); if (visited.contains(e) || !e.isTree(visited)) { return false; } } return true; }
/* (non-Javadoc) * @see sorcer.service.Exertion#addExertion(sorcer.service.Exertion) */ @Override public Exertion addExertion(Exertion ex) throws ExertionException { exertions.add(ex); ((ServiceExertion) ex).setIndex(exertions.indexOf(ex)); try { controlContext.registerExertion(ex); } catch (ContextException e) { throw new ExertionException(e); } ((ServiceExertion) ex).setParentId(getId()); return this; }
/** * 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); } } }
@Override public Context linkControlContext(Context context, String path) { Exertion ext; for (int i = 0; i < size(); i++) { ext = exertions.get(i); try { ((ServiceExertion) ext).linkControlContext(context, path + CPS + ext.getName()); } catch (ContextException e) { e.printStackTrace(); } } return context; }
@Override public ServiceExertion substitute(Arg... entries) throws EvaluationException { try { if (entries != null) { for (Arg e : entries) { if (e instanceof Entry) if (((Entry) e).path().indexOf(name) >= 0) putJobValue(((Entry) e).path(), ((Entry) e).value()); else super.putValue(((Entry) e).path(), ((Entry) e).value()); } } } catch (ContextException ex) { ex.printStackTrace(); throw new EvaluationException(ex); } return this; }
public void reset(int state) { for (Exertion e : exertions) ((ServiceExertion) e).reset(state); this.setStatus(state); }
public Object putValue(String path, Object value) throws ContextException { if (path.indexOf(name) >= 0) putJobValue(path, value); else super.putValue(path, value); return value; }
public List<Exertion> getExertions(List<Exertion> exs) { for (Exertion e : exertions) ((ServiceExertion) e).getExertions(exs); exs.add(this); return exs; }