Operator currentOperator = null; Map<String, Product> sourceProducts = new HashMap<>(); for (Node node : graphContext.getGraph().getNodes()) { final NodeContext nodeContext = graphContext.getNodeContext(node); currentOperator = nodeContext.getOperator();
/** * Creates a GraphContext for the given {@code graph} and a {@code logger}. * * @param graph the {@link org.esa.beam.framework.gpf.graph.Graph} to create the context for * @throws GraphException if the graph context could not be created */ public GraphContext(Graph graph, Operator graphOp) throws GraphException { if (graph.getNodeCount() == 0) { throw new GraphException("Empty graph."); } this.graph = graph; this.logger = BeamLogManager.getSystemLogger(); outputNodeContextList = new ArrayList<>(graph.getNodeCount() / 2); nodeContextMap = new HashMap<>(graph.getNodeCount() * 2); for (Node node : graph.getNodes()) { nodeContextMap.put(node, new NodeContext(this, node)); } initNodeContextDeque = new ArrayDeque<>(graph.getNodeCount()); initNodeDependencies(); initOutput(graphOp); }
private void initOutput(Operator graphOp) throws GraphException { for (Node node : getGraph().getNodes()) { NodeContext nodeContext = getNodeContext(node); if (nodeContext.isOutput()) { initNodeContext(nodeContext, graphOp); addOutputNodeContext(nodeContext); } } }
private NodeContext getTargetNodeContext(Graph graph) throws GraphException { GraphContext graphContext = new GraphContext(graph, this); NodeContext targetNodeContext = null; Header header = graph.getHeader(); if (header != null) { HeaderTarget headerTarget = header.getTarget(); Node targetNode = graph.getNode(headerTarget.getNodeId()); for (Node node : graph.getNodes()) { if (node == targetNode) { targetNodeContext = graphContext.getNodeContext(node); break; } } } return targetNodeContext; }
public void testEmptyChain() { Graph graph = new Graph("chain1"); assertEquals("chain1", graph.getId()); assertNotNull(graph.getNodes()); }
public void testOneNodeChain() { Graph graph = new Graph("chain1"); Node node = new Node("node1", "org.esa.beam.framework.gpf.TestOps$Op1Spi"); try { graph.addNode(node); } catch (IllegalArgumentException e) { fail(e.getMessage()); } assertEquals("chain1", graph.getId()); assertNotNull(graph.getNodes()); assertEquals(node, graph.getNode("node1")); }
public void testEmptyChain() throws Exception { Graph chain1 = new Graph("myEmptyChain"); Graph chain2 = doIO(chain1); Node[] nodes = chain2.getNodes(); assertNotNull(nodes); assertEquals(0, nodes.length); assertEquals(chain1.getId(), chain2.getId()); }
private void initNodeDependencies() throws GraphException { Graph graph = getGraph(); for (Node node : graph.getNodes()) { for (NodeSource source : node.getSources()) { String sourceNodeId = source.getSourceNodeId(); Node sourceNode = graph.getNode(sourceNodeId); if (sourceNode == null) { Header header = graph.getHeader(); boolean sourceDefinedInHeader = header != null && isSourceNodeIdInHeader(sourceNodeId, header.getSources()); if (!sourceDefinedInHeader) { throw new GraphException(getMissingSourceMessage(node, source)); } } if (sourceNode != null) { getNodeContext(sourceNode).incrementReferenceCount(); source.setSourceNode(sourceNode); } } } }
public void testRemoveNode() { Graph graph = new Graph("chain1"); Node node = new Node("node1", "org.esa.beam.framework.gpf.TestOps$Op1Spi"); try { graph.addNode(node); } catch (IllegalArgumentException e) { fail(e.getMessage()); } boolean result = graph.removeNode("node1"); assertEquals("chain1", graph.getId()); assertNotNull(graph.getNodes()); assertTrue(result); assertNull(graph.getNode("node1")); }
public void testReadFromXML() throws Exception { String expectedXML = "<graph id=\"myOneNodeGraph\">\n" + " <version>1.0</version>\n" + " <node id=\"node1\">\n" + " <operator>Op1</operator>\n" + " <sources/>\n" + " </node>\n" + "</graph>"; StringReader reader = new StringReader(expectedXML); Graph graph = GraphIO.read(reader); Node[] nodes = graph.getNodes(); assertNotNull(nodes); assertEquals(1, nodes.length); assertNotNull(nodes[0]); assertEquals("myOneNodeGraph", graph.getId()); Node node1 = graph.getNode("node1"); assertNotNull(node1); assertEquals("Op1", node1.getOperatorName()); }
Node[] nodes = graph.getNodes(); assertNotNull(nodes); assertEquals(1, nodes.length);
public void testOneNodeChain() throws Exception { Graph graph1 = new Graph("myOneNodeGraph"); Node node1 = new Node("node1", "Op1"); graph1.addNode(node1); Graph chain2 = doIO(graph1); Node[] nodes = chain2.getNodes(); assertNotNull(nodes); assertEquals(1, nodes.length); assertNotNull(nodes[0]); assertEquals(graph1.getId(), chain2.getId()); Node node1Copy = chain2.getNode("node1"); assertSame(nodes[0], node1Copy); assertEquals("Op1", node1Copy.getOperatorName()); }
public void testTwoNodeChain() throws Exception { Graph graph1 = new Graph("myTwoNodeGraph"); Node node1 = new Node("node1", "Op1"); Node node2 = new Node("node2", "Op2"); node2.addSource(new NodeSource("key1", "node1")); graph1.addNode(node1); graph1.addNode(node2); Graph graph2 = doIO(graph1); assertEquals(graph1.getId(), graph2.getId()); Node[] nodes = graph2.getNodes(); assertNotNull(nodes); assertEquals(2, nodes.length); assertNotNull(nodes[0]); assertNotNull(nodes[1]); Node node1Copy = graph2.getNode("node1"); Node node2Copy = graph2.getNode("node2"); assertSame(nodes[0], node1Copy); assertSame(nodes[1], node2Copy); NodeSource[] sources1 = node1Copy.getSources(); assertNotNull(sources1); assertEquals(0, sources1.length); NodeSource[] sources2 = node2Copy.getSources(); assertNotNull(sources2); assertEquals(1, sources2.length); NodeSource source2 = node2Copy.getSource(0); assertSame(sources2[0], source2); assertEquals("Op1", node1Copy.getOperatorName()); assertEquals("Op2", node2Copy.getOperatorName()); assertEquals("node1", source2.getSourceNodeId()); }
assertEquals("foo", graph.getId()); Node[] nodes = graph.getNodes(); assertNotNull(nodes); assertEquals(3, nodes.length);