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; }
/** * Executes the graph using a new default {@link GraphContext}. * * @param graph the {@link Graph} * @param pm a progress monitor. Can be used to signal progress. * * @throws GraphException if any error occurs during execution * @see GraphProcessor#executeGraph(GraphContext, com.bc.ceres.core.ProgressMonitor) */ public void executeGraph(Graph graph, ProgressMonitor pm) throws GraphException { GraphContext graphContext; try { pm.beginTask("Executing processing graph", 100); graphContext = new GraphContext(graph); executeGraph(graphContext, SubProgressMonitor.create(pm, 90)); graphContext.dispose(); } finally { pm.done(); } }
try { Graph graph = GraphIO.read(new FileReader(file)); graphContext = new GraphContext(graph); Product[] outputProducts = graphContext.getOutputProducts(); if (outputProducts.length != 1) { getLogger().warning("Filtered out graph '" + file + "'"); graphContext.dispose();
private void initOutput(Operator graphOp) throws GraphException { for (Node node : getGraph().getNodes()) { NodeContext nodeContext = getNodeContext(node); if (nodeContext.isOutput()) { initNodeContext(nodeContext, graphOp); addOutputNodeContext(nodeContext); } } }
@Override public void graphProcessingStopped(GraphContext graphContext) { VelocityContext velocityContext = metadataResourceEngine.getVelocityContext(); velocityContext.put("graph", graphContext.getGraph()); Product[] outputProducts = graphContext.getOutputProducts(); if (outputProducts.length >= 1) { velocityContext.put("targetProduct", outputProducts[0]); Operator currentOperator = null; Map<String, Product> sourceProducts = new HashMap<>(); for (Node node : graphContext.getGraph().getNodes()) { final NodeContext nodeContext = graphContext.getNodeContext(node); currentOperator = nodeContext.getOperator(); if (currentOperator instanceof ReadOp) {
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 testTargetProductCreation() throws GraphException { Graph graph = new Graph("chain1"); Node node1 = new Node("node1", "Op1"); graph.addNode(node1); GraphContext graphContext = new GraphContext(graph); Product[] outputProducts = graphContext.getOutputProducts(); assertNotNull(outputProducts); assertEquals(1, outputProducts.length); assertNotNull(outputProducts[0]); }
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); } } } }
private void initNodeContext(final NodeContext nodeContext, Operator graphOp) throws GraphException { if (nodeContext.isInitialized()) { return; } for (NodeSource source : nodeContext.getNode().getSources()) { NodeContext sourceNodeContext = getNodeContext(source.getSourceNode()); Product sourceProduct = null; if (sourceNodeContext != null) { initNodeContext(sourceNodeContext, graphOp); sourceProduct = sourceNodeContext.getTargetProduct(); } else { if (graphOp != null) { sourceProduct = graphOp.getSourceProduct(source.getSourceNodeId()); } } if (sourceProduct == null) { throw new GraphException(getMissingSourceMessage(nodeContext.getNode(), source)); } nodeContext.addSourceProduct(source.getName(), sourceProduct); } Node node = nodeContext.getNode(); DomElement configuration = node.getConfiguration(); OperatorConfiguration opConfiguration = this.createOperatorConfiguration(configuration, new HashMap<String, Object>()); nodeContext.setOperatorConfiguration(opConfiguration); nodeContext.initTargetProduct(); getInitNodeContextDeque().addFirst(nodeContext); }
String referenceNodeId = referenceParts[0]; String propertyName = referenceParts[1]; Node node = getGraph().getNode(referenceNodeId); NodeContext referredNodeContext = getNodeContext(node); Operator operator = referredNodeContext.getOperator(); OperatorConfiguration.PropertyReference propertyReference = new OperatorConfiguration.PropertyReference(parameterName, propertyName, operator);
NodeContext[] outputNodeContexts = graphContext.getOutputNodeContexts(); Map<Dimension, List<NodeContext>> tileDimMap = buildTileDimensionMap(outputNodeContexts); if (pm.isCanceled()) { return graphContext.getOutputProducts(); return graphContext.getOutputProducts();
public void graphProcessingStopped(GraphContext graphContext) { ralla("graph [" + graphContext.getGraph().getId() + "] stopped"); }
/** * Disposes this {@code GraphContext}. */ public void dispose() { Deque<NodeContext> initNodeContextDeque = getInitNodeContextDeque(); while (!initNodeContextDeque.isEmpty()) { NodeContext nodeContext = initNodeContextDeque.pop(); nodeContext.dispose(); } }
private void initOperator() throws GraphException { final OperatorSpiRegistry spiRegistry = GPF.getDefaultInstance().getOperatorSpiRegistry(); OperatorSpi operatorSpi = spiRegistry.getOperatorSpi(node.getOperatorName()); if (operatorSpi == null) { throw new GraphException("SPI not found for operator '" + node.getOperatorName() + "'"); } try { this.operator = operatorSpi.createOperator(); this.operator.setLogger(graphContext.getLogger()); // this.operator.setConfiguration(node.getConfiguration()); } catch (OperatorException e) { throw new GraphException("Failed to create instance of operator '" + node.getOperatorName() + "'", e); } }
public void testOptionalAndWrongProductIsNotGiven() throws GraphException { Graph graph = new Graph("graph"); Node wrongBandsNode = new Node("WrongBands", wrongBandsOpSpi.getOperatorAlias()); Node consumerNode = new Node("OptionalConsumer", optionalConsumerOpSpi.getOperatorAlias()); graph.addNode(wrongBandsNode); graph.addNode(consumerNode); new GraphContext(graph); }
public void testThreeOpsExecutionOrder() throws Exception { VerbousTileCache.setVerbous(false); Graph graph = new Graph("graph"); Node node1 = new Node("node1", "Op1"); Node node2 = new Node("node2", "Op2"); Node node3 = new Node("node3", "Op3"); node2.addSource(new NodeSource("input", "node1")); node3.addSource(new NodeSource("input1", "node1")); node3.addSource(new NodeSource("input2", "node2")); graph.addNode(node1); graph.addNode(node2); graph.addNode(node3); GraphProcessor processor = new GraphProcessor(); GraphContext graphContext = new GraphContext(graph); Product chainOut = graphContext.getOutputProducts()[0]; assertNotNull(chainOut); assertEquals("Op3Name", chainOut.getName()); processor.executeGraph(graphContext, ProgressMonitor.NULL); // - Op3 requires the two bands of Op2 // - Op2 computes all bands // --> Op2 should only be called once assertEquals("Op1;Op2;Op3;", TestOps.getCalls()); TestOps.clearCalls(); VerbousTileCache.setVerbous(false); }
public void graphProcessingStarted(GraphContext graphContext) { ralla("graph [" + graphContext.getGraph().getId() + "] started"); }
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()); }
GraphContext graphContext = new GraphContext(graph); Product[] targetProducts = processor.executeGraph(graphContext, ProgressMonitor.NULL); assertEquals("N2", targetProducts[0].getName()); graphContext.dispose();
public void testNotInitialzedInputResultsInException() { Graph graph = new Graph("graph"); Node goodNode = new Node("Good", goodOpSpi.getOperatorAlias()); Node consumerNode = new Node("Consumer", consumerOpSpi.getOperatorAlias()); graph.addNode(goodNode); graph.addNode(consumerNode); try { new GraphContext(graph); fail("GraphException expected, because input1 is not initialized"); } catch (GraphException ge) { } }