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")); }
/** * 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 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; }
private Graph createTestGraph(String opName) { Graph graph = new Graph("graph"); Node input1Node = new Node("input1", "InputOp"); Node input2Node = new Node("input2", "InputOp"); Node input3Node = new Node("input3", "InputOp"); Node outputNode = new Node("output", opName); graph.addNode(input1Node); graph.addNode(input2Node); graph.addNode(input3Node); graph.addNode(outputNode); return graph; }
@Test public void testIt() throws Exception { InputStream stream = BinningInGraphTest.class.getResourceAsStream("BinningInGraphTest.xml"); Graph graph = GraphIO.read(new InputStreamReader(stream)); Assert.assertNotNull(graph); Assert.assertEquals(1, graph.getNodeCount()); Assert.assertEquals("subsetNodeId", graph.getNode(0).getId()); Assert.assertEquals("subsetNodeId", graph.getNode(0).getId()); } }
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()); }
Graph graph = GraphIO.read(reader); Header header = graph.getHeader(); assertNotNull(header); assertEquals("node1", header.getTarget().getNodeId()); 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 lastNode = graph.getNode(graph.getNodeCount() - 1); SortedMap<String, String> sourceFilePathsMap = commandLineArgs.getSourceFilePathMap(); String sourceFilePath = entry.getValue(); String sourceNodeId = sourceNodeIdMap.get(sourceId); if (graph.getNode(sourceNodeId) == null) { sourceNode.setConfiguration(configuration); graph.addNode(sourceNode); targetNode.setConfiguration(configuration); graph.addNode(targetNode);
/** * Removes the {@link Node} with the given {@code id} from this graph if present. * * @param id the id of the {@link Node} to be removed * @return {@code true} if the graph contains a {@link Node} with the given {@code id}. Else {@code false}. */ public boolean removeNode(String id) { return nodeList.remove(getNode(id)); }
public void testSpiCreation() throws GraphException { Graph graph = new Graph("chain1"); Node node1 = new Node("node1", "Op1"); graph.addNode(node1); GraphContext graphContext = new GraphContext(graph); NodeContext nodeContext = graphContext.getNodeContext(node1); assertEquals("Op1", graph.getNode("node1").getOperatorName()); assertEquals("org.esa.beam.framework.gpf.TestOps$Op1", nodeContext.getOperator().getClass().getName()); }
public Spi(Graph graph) { super(GraphOp.class, graph.getId()); this.graph = graph; } }
public void testWriteToXMLWithApplicationData() throws Exception { Graph graph1 = new Graph("myOneNodeGraph"); Node node1 = new Node("node1", "Op1"); graph1.addNode(node1); font.setValue("big"); xpp3Dom.addChild(font); graph1.setAppData("foo", xpp3Dom); colour.setValue("red"); xpp3Dom2.addChild(colour); graph1.setAppData("baz", xpp3Dom2);
public void testApplicationData() throws Exception { Graph graph = new Graph("chain1"); assertNull(graph.getApplicationData("foo")); XppDom xpp3Dom1 = new XppDom(""); XppDom font = new XppDom("font"); font.setValue("big"); xpp3Dom1.addChild(font); graph.setAppData("foo", xpp3Dom1); assertSame(xpp3Dom1, graph.getApplicationData("foo")); XppDom xpp3Dom2 = new XppDom(""); XppDom font2 = new XppDom("font"); font2.setValue("small"); xpp3Dom2.addChild(font2); graph.setAppData("foo", xpp3Dom2); assertSame(xpp3Dom2, graph.getApplicationData("foo")); }
Operator currentOperator = null; Map<String, Product> sourceProducts = new HashMap<>(); for (Node node : graphContext.getGraph().getNodes()) { final NodeContext nodeContext = graphContext.getNodeContext(node); currentOperator = nodeContext.getOperator();
private void setOperatorParameters(Graph graph, OperatorContext operatorContext) { // todo - implement me, this code here is not adequate - we need the graph's header in order to get the GraphOp's parameters Map<String, Object> parameters = operatorContext.getParameterMap(); if (parameters == null) { parameters = new HashMap<String, Object>(); } List<HeaderParameter> parameters1 = graph.getHeader().getParameters(); for (HeaderParameter headerParameter : parameters1) { //TODO use them, convert them..... } fillMapFromConfiguration(parameters); operatorContext.setParameterMap(parameters); }
/** * Deserializes a {@link Graph} from a XML Reader using a mapping * for the substitution of template variables inside the XML-based * {@link Graph} definition. * * @param reader the XML reader * @param variables a mapping from template variable names to their string values. * @return the deserialized <code>graph</code> * @throws GraphException if an error occurs during reading */ public static Graph read(Reader reader, Map<String, String> variables) throws GraphException { XStream xStream = initXstream(); Reader inputReader = reader; if (variables != null) { addSourceProductsVariable(variables); inputReader = new TemplateReader(reader, variables); } // todo - throw exception if a given variable does not exist in the graph definition or if variables are not set. Graph graph = (Graph) xStream.fromXML(inputReader); if (graph.getVersion() == null) { throw new GraphException("No version is specified in the graph XML."); } else if (!Graph.CURRENT_VERSION.equals(graph.getVersion())) { throw new GraphException("Wrong version given in the graph XML. " + "Given version: " + graph.getVersion() + " Current version: " + Graph.CURRENT_VERSION); } return graph; }
public void testEmptyChain() { Graph graph = new Graph("test-graph"); try { new GraphContext(graph); fail("GraphException expected due to empty graph"); } catch (GraphException e) { // ok } }
public void testReadFromXMLWithAppData() 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" + " <applicationData id=\"foo\">\n" + " <font>Big</font>\n" + " <colour>red</colour>\n" + " </applicationData>\n" + " <applicationData id=\"bar\">\n" + " <textmode>true</textmode>\n" + " </applicationData>\n" + "</graph>"; StringReader reader = new StringReader(expectedXML); Graph graph = GraphIO.read(reader); XppDom fooData = graph.getApplicationData("foo"); assertNotNull(fooData); assertEquals(2, fooData.getChildCount()); assertEquals("Big", fooData.getChild("font").getValue()); assertEquals("red", fooData.getChild("colour").getValue()); XppDom barData = graph.getApplicationData("bar"); assertNotNull(barData); assertEquals(1, barData.getChildCount()); assertEquals("true", barData.getChild("textmode").getValue()); }
public void testAddExistingNode() { Graph graph = new Graph("chain1"); Node node1 = new Node("node1", "org.esa.beam.framework.gpf.TestOps$Op1Spi"); Node node2 = new Node("node1", "org.esa.beam.framework.gpf.TestOps$Op2Spi"); try { graph.addNode(node1); graph.addNode(node2); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException e) { // expected } }