private static String getMissingSourceMessage(Node node, NodeSource source) { return MessageFormat.format("Missing source ''{0}'' in node ''{1}''", source.getSourceNodeId(), node.getId()); } }
@Override public void marshal(Object object, HierarchicalStreamWriter hierarchicalStreamWriter, MarshallingContext marshallingContext) { SourceList sourceList = (SourceList) object; NodeSource[] sources = sourceList.getSources(); for (NodeSource source : sources) { hierarchicalStreamWriter.startNode(source.getName()); hierarchicalStreamWriter.addAttribute("refid", source.getSourceNodeId()); hierarchicalStreamWriter.endNode(); } }
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); }
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 testGraph(String[] args, int expectedNodeCount, String expectedLog, Map<String, String> expectedSourceNodeIdFilePathMap, String expectedTargetNodeId, String expectedTargetFilepath, String expectedTargetFormat) throws Exception { clTool.run(args); assertEquals(expectedLog, context.logString); Graph executedGraph = context.executedGraph; assertNotNull(executedGraph); assertEquals(expectedNodeCount, executedGraph.getNodeCount()); for (Map.Entry<String, String> entry : expectedSourceNodeIdFilePathMap.entrySet()) { String expectedSourceFilePath = entry.getValue(); if (expectedSourceFilePath != null) { final String key = entry.getKey(); Node generatedReaderNode1 = executedGraph.getNode(key); assertNotNull("Source ID not found: " + key, generatedReaderNode1); assertEquals(expectedSourceFilePath, generatedReaderNode1.getConfiguration().getChild("file").getValue()); } } Node generatedWriterNode = executedGraph.getNode(expectedTargetNodeId); assertNotNull(generatedWriterNode); assertEquals("node1", generatedWriterNode.getSource(0).getSourceNodeId()); DomElement parameters = generatedWriterNode.getConfiguration(); assertNotNull(parameters); assertNotNull(expectedTargetFilepath, parameters.getChild("file").getValue()); assertNotNull(expectedTargetFormat, parameters.getChild("formatName").getValue()); }
assertEquals(expectedSourceNodeId1, node1.getSource(0).getSourceNodeId()); assertEquals(expectedThreshold, node1.getConfiguration().getChild("threshold").getValue()); assertEquals("node1", node2.getSource(0).getSourceNodeId()); assertEquals(expectedSourceNodeId2, node2.getSource(1).getSourceNodeId()); assertEquals(expectedExpression, node2.getConfiguration().getChild("expression").getValue()); assertEquals("node2", generatedWriterNode.getSource(0).getSourceNodeId());
assertNotNull(sources2); assertEquals(1, sources2.length); assertEquals("grunt", sources2[0].getSourceNodeId()); assertEquals("grunt", sources3[0].getSourceNodeId()); assertEquals("baz", sources3[1].getSourceNodeId());
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()); }