public synchronized int getIterationDepth(Map<String, Integer> inputDepths) throws IterationTypeMismatchException { int temp = 0; for (IterationStrategyNode child : getChildren()) { temp += child.getIterationDepth(inputDepths); } return temp; }
/** * Implements IterationStrategyNode */ public final synchronized void setParent(IterationStrategyNode newParent) { if (newParent != null) { this.parent = newParent; if (newParent.getChildren().contains(this) == false) { newParent.getChildren().add(newParent.getChildCount(), this); } } else { if (this.parent != null) { // Remove from the current parent if (this.parent.getChildren().contains(this)) { this.parent.getChildren().remove(this); } } this.parent = null; } }
/** * Push the specified completion event to the parent node */ protected final void pushCompletion(Completion completion) { if (parent != null) { parent.receiveCompletion(parent.getIndex(this), completion); } }
/** * Push the specified job up to the parent node in the iteration strategy. */ protected final void pushJob(Job job) { if (parent != null) { int index = parent.getIndex(this); if (index < 0) { throw new WorkflowStructureException( "Parent doesn't have this node in its child list!"); } parent.receiveJob(parent.getIndex(this), job); } }
@Test public void implicitStrategy() throws Exception { Dataflow translated = WorkflowModelTranslator .doTranslation(iterateImplicit); Processor proc = null; for (Processor candidate : translated.getProcessors()) { if (candidate.getLocalName().equals("iterate")) { proc = candidate; break; } } assertNotNull("Can't find processor", proc); IterationStrategy itStrat = proc.getIterationStrategy().getStrategies() .get(0); assertEquals("Iteration should have 1 child", 1, itStrat .getTerminalNode().getChildCount()); IterationStrategyNode first = itStrat.getTerminalNode().getChildAt(0); assertTrue("Implicit strategy should be cross product ", first instanceof CrossProduct); assertEquals("Should have 3 children", 3, first.getChildCount()); NamedInputPortNode node0 = (NamedInputPortNode) first.getChildAt(0); NamedInputPortNode node1 = (NamedInputPortNode) first.getChildAt(1); NamedInputPortNode node2 = (NamedInputPortNode) first.getChildAt(2); // Should be reverse order assertEquals("in2", node0.getPortName()); assertEquals("in1", node1.getPortName()); assertEquals("in0", node2.getPortName()); }
@Test public void moveNodeToDifferentParent() { crossProduct1.setParent(root); crossProduct1.insert(input1); crossProduct1.insert(dotProduct1); dotProduct1.insert(input2); dotProduct1.insert(crossProduct2); // Check tree assertEquals(crossProduct2, root.getChildAt(0).getChildAt(1) .getChildAt(1)); assertEquals(Arrays.asList(input2, crossProduct2), dotProduct1 .getChildren()); crossProduct1.insert(crossProduct2, 1); assertEquals(Arrays.asList(input1, crossProduct2, dotProduct1), crossProduct1.getChildren()); assertEquals(crossProduct1, crossProduct2.getParent()); // Should no longer be in dotProduct1 assertEquals(Arrays.asList(input2), dotProduct1.getChildren()); }
/** * Implements IterationStrategyNode */ public final synchronized void setParent(MutableTreeNode newParent) { if (newParent != null && !(newParent instanceof IterationStrategyNode)) { throw new IllegalArgumentException( "Parent not a IterationStrategyNode instance: " + newParent); } if (newParent != null && !newParent.getAllowsChildren()) { throw new IllegalStateException( "New parent does not allow children"); } if (newParent == this) { throw new IllegalArgumentException("Can't be it's own parent"); } removeFromParent(); parent = (IterationStrategyNode) newParent; if (parent != null) { if (!parent.getChildren().contains(this)) { parent.insert(this); } } }
public void removeFromParent() { if (parent != null) { IterationStrategyNode oldParent = parent; parent = null; oldParent.remove(this); } }
/** * Push the specified job up to the parent node in the iteration strategy. */ protected final void pushJob(Job job) { if (parent != null) { int index = parent.getIndex(this); if (index < 0) { throw new WorkflowStructureException( "Parent doesn't have this node in its child list!"); } parent.receiveJob(parent.getIndex(this), job); } }
@Test public void dotProduct() throws Exception { Dataflow translated = WorkflowModelTranslator.doTranslation(iterateDot); Processor proc = null; for (Processor candidate : translated.getProcessors()) { if (candidate.getLocalName().equals("iterate")) { proc = candidate; break; } } assertNotNull("Can't find processor", proc); IterationStrategy itStrat = proc.getIterationStrategy().getStrategies() .get(0); assertEquals("Iteration should have 1 child", 1, itStrat .getTerminalNode().getChildCount()); IterationStrategyNode first = itStrat.getTerminalNode().getChildAt(0); assertTrue("Implicit strategy should be dot product ", first instanceof DotProduct); assertEquals("Should have 3 children", 3, first.getChildCount()); NamedInputPortNode node0 = (NamedInputPortNode) first.getChildAt(0); NamedInputPortNode node1 = (NamedInputPortNode) first.getChildAt(1); NamedInputPortNode node2 = (NamedInputPortNode) first.getChildAt(2); // Should be reverse order assertEquals("in2", node0.getPortName()); assertEquals("in1", node1.getPortName()); assertEquals("in0", node2.getPortName()); }
@Test public void moveNodeToDifferentParent() { crossProduct1.setParent(root); crossProduct1.insert(input1); crossProduct1.insert(dotProduct1); dotProduct1.insert(input2); dotProduct1.insert(crossProduct2); // Check tree assertEquals(crossProduct2, root.getChildAt(0).getChildAt(1) .getChildAt(1)); assertEquals(Arrays.asList(input2, crossProduct2), dotProduct1 .getChildren()); crossProduct1.insert(crossProduct2, 1); assertEquals(Arrays.asList(input1, crossProduct2, dotProduct1), crossProduct1.getChildren()); assertEquals(crossProduct1, crossProduct2.getParent()); // Should no longer be in dotProduct1 assertEquals(Arrays.asList(input2), dotProduct1.getChildren()); }
/** * Implements IterationStrategyNode */ public final synchronized void setParent(MutableTreeNode newParent) { if (newParent != null && !(newParent instanceof IterationStrategyNode)) { throw new IllegalArgumentException( "Parent not a IterationStrategyNode instance: " + newParent); } if (newParent != null && !newParent.getAllowsChildren()) { throw new IllegalStateException( "New parent does not allow children"); } if (newParent == this) { throw new IllegalArgumentException("Can't be it's own parent"); } removeFromParent(); parent = (IterationStrategyNode) newParent; if (parent != null) { if (!parent.getChildren().contains(this)) { parent.insert(this); } } }
public void removeFromParent() { if (parent != null) { IterationStrategyNode oldParent = parent; parent = null; oldParent.remove(this); } }
public synchronized int getIterationDepth(Map<String, Integer> inputDepths) throws IterationTypeMismatchException { int temp = 0; for (IterationStrategyNode child : getChildren()) { temp += child.getIterationDepth(inputDepths); } return temp; }
/** * Push the specified completion event to the parent node */ protected final void pushCompletion(Completion completion) { if (parent != null) { parent.receiveCompletion(parent.getIndex(this), completion); } }
/** * Push the specified job up to the parent node in the iteration strategy. */ protected final void pushJob(Job job) { if (parent != null) { int index = parent.getIndex(this); if (index < 0) { throw new WorkflowStructureException( "Parent doesn't have this node in its child list!"); } parent.receiveJob(parent.getIndex(this), job); } }
@Test public void crossProduct() throws Exception { Dataflow translated = WorkflowModelTranslator .doTranslation(iterateCross); Processor proc = null; for (Processor candidate : translated.getProcessors()) { if (candidate.getLocalName().equals("iterate")) { proc = candidate; break; } } assertNotNull("Can't find processor", proc); IterationStrategy itStrat = proc.getIterationStrategy().getStrategies() .get(0); assertEquals("Iteration should have 1 child", 1, itStrat .getTerminalNode().getChildCount()); IterationStrategyNode first = itStrat.getTerminalNode().getChildAt(0); assertTrue("Implicit strategy should be cross product ", first instanceof CrossProduct); assertEquals("Should have 3 children", 3, first.getChildCount()); NamedInputPortNode node0 = (NamedInputPortNode) first.getChildAt(0); NamedInputPortNode node1 = (NamedInputPortNode) first.getChildAt(1); NamedInputPortNode node2 = (NamedInputPortNode) first.getChildAt(2); // Should be reverse order assertEquals("in2", node0.getPortName()); assertEquals("in1", node1.getPortName()); assertEquals("in0", node2.getPortName()); }
assertEquals(1, ((CrossProduct) terminal.getChildAt(0)) .getChildCount()); assertTrue(terminal.getChildAt(0).getChildAt(0) instanceof NamedInputPortNode); assertEquals("input_1", ((NamedInputPortNode) terminal .getChildAt(0).getChildAt(0)).getPortName()); } else if (processor.getLocalName().equals("processor_b")) { AbstractIterationStrategyNode terminal = (AbstractIterationStrategyNode) iterationStrategies assertEquals(2, ((CrossProduct) terminal.getChildAt(0)) .getChildCount()); assertTrue(terminal.getChildAt(0).getChildAt(0) instanceof NamedInputPortNode); assertTrue(terminal.getChildAt(0).getChildAt(1) instanceof NamedInputPortNode); assertEquals("input_2", ((NamedInputPortNode) terminal .getChildAt(0).getChildAt(0)).getPortName()); assertEquals("input_3", ((NamedInputPortNode) terminal .getChildAt(0).getChildAt(1)).getPortName());
public int getIterationDepth(Map<String, Integer> inputDepths) throws IterationTypeMismatchException { // Check that all input depths are the same int depth = getChildren().get(0).getIterationDepth(inputDepths); for (IterationStrategyNode childNode : getChildren()) { if (childNode.getIterationDepth(inputDepths) != depth) { throw new IterationTypeMismatchException( "Mismatched input types for dot product node"); } } return depth; }
/** * Push the specified completion event to the parent node */ protected final void pushCompletion(Completion completion) { if (parent != null) { parent.receiveCompletion(parent.getIndex(this), completion); } }