Search in sources :

Example 6 with TopologyDag

use of com.hortonworks.streamline.streams.layout.component.TopologyDag in project streamline by hortonworks.

the class TopologyTestRunnerTest method injectTestTopology.

private void injectTestTopology(Topology topology) {
    StreamlineSource originSource = TopologyTestHelper.createStreamlineSource("1");
    StreamlineProcessor originProcessor = TopologyTestHelper.createStreamlineProcessor("2");
    StreamlineSink originSink = TopologyTestHelper.createStreamlineSink("3");
    TopologyDag topologyDag = new TopologyDag();
    topologyDag.add(originSource);
    topologyDag.add(originProcessor);
    topologyDag.add(originSink);
    topologyDag.addEdge(new Edge("e1", originSource, originProcessor, "default", Stream.Grouping.SHUFFLE));
    topologyDag.addEdge(new Edge("e2", originProcessor, originSink, "default", Stream.Grouping.SHUFFLE));
    topology.setTopologyDag(topologyDag);
}
Also used : StreamlineProcessor(com.hortonworks.streamline.streams.layout.component.StreamlineProcessor) StreamlineSource(com.hortonworks.streamline.streams.layout.component.StreamlineSource) StreamlineSink(com.hortonworks.streamline.streams.layout.component.StreamlineSink) Edge(com.hortonworks.streamline.streams.layout.component.Edge) TopologyDag(com.hortonworks.streamline.streams.layout.component.TopologyDag)

Example 7 with TopologyDag

use of com.hortonworks.streamline.streams.layout.component.TopologyDag in project streamline by hortonworks.

the class StormTopologyActionsImpl method createYamlFile.

private String createYamlFile(TopologyLayout topology, boolean deploy) throws Exception {
    Map<String, Object> yamlMap;
    File f;
    OutputStreamWriter fileWriter = null;
    try {
        f = new File(this.getFilePath(topology));
        if (f.exists()) {
            if (!f.delete()) {
                throw new Exception("Unable to delete old storm " + "artifact for topology id " + topology.getId());
            }
        }
        yamlMap = new LinkedHashMap<>();
        yamlMap.put(StormTopologyLayoutConstants.YAML_KEY_NAME, generateStormTopologyName(topology));
        TopologyDag topologyDag = topology.getTopologyDag();
        LOG.debug("Initial Topology config {}", topology.getConfig());
        StormTopologyFluxGenerator fluxGenerator = new StormTopologyFluxGenerator(topology, conf, getExtraJarsLocation(topology));
        topologyDag.traverse(fluxGenerator);
        for (Map.Entry<String, Map<String, Object>> entry : fluxGenerator.getYamlKeysAndComponents()) {
            addComponentToCollection(yamlMap, entry.getValue(), entry.getKey());
        }
        Config topologyConfig = fluxGenerator.getTopologyConfig();
        putAutoTokenDelegationConfig(topologyConfig, topologyDag);
        registerEventLogger(topologyConfig);
        Map<String, Object> properties = topologyConfig.getProperties();
        if (!deploy) {
            LOG.debug("Disabling topology event logger for test mode...");
            properties.put("topology.eventlogger.executors", 0);
        }
        LOG.debug("Final Topology properties {}", properties);
        addTopologyConfig(yamlMap, properties);
        DumperOptions options = new DumperOptions();
        options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
        options.setSplitLines(false);
        // options.setDefaultScalarStyle(DumperOptions.ScalarStyle.PLAIN);
        Yaml yaml = new Yaml(options);
        fileWriter = new OutputStreamWriter(new FileOutputStream(f), "UTF-8");
        yaml.dump(yamlMap, fileWriter);
        return f.getAbsolutePath();
    } finally {
        if (fileWriter != null) {
            fileWriter.close();
        }
    }
}
Also used : Config(com.hortonworks.streamline.common.Config) ClientConfig(org.glassfish.jersey.client.ClientConfig) StormTopologyFluxGenerator(com.hortonworks.streamline.streams.layout.storm.StormTopologyFluxGenerator) TopologyNotAliveException(com.hortonworks.streamline.streams.exception.TopologyNotAliveException) IOException(java.io.IOException) Yaml(org.yaml.snakeyaml.Yaml) FileOutputStream(java.io.FileOutputStream) DumperOptions(org.yaml.snakeyaml.DumperOptions) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TopologyDag(com.hortonworks.streamline.streams.layout.component.TopologyDag)

Example 8 with TopologyDag

use of com.hortonworks.streamline.streams.layout.component.TopologyDag in project streamline by hortonworks.

the class StormTopologyActionsImpl method runTest.

@Override
public void runTest(TopologyLayout topology, TopologyTestRunHistory testRunHistory, String mavenArtifacts, Map<String, TestRunSource> testRunSourcesForEachSource, Map<String, TestRunProcessor> testRunProcessorsForEachProcessor, Map<String, TestRunRulesProcessor> testRunRulesProcessorsForEachProcessor, Map<String, TestRunSink> testRunSinksForEachSink, Optional<Long> durationSecs) throws Exception {
    TopologyDag originalTopologyDag = topology.getTopologyDag();
    TestTopologyDagCreatingVisitor visitor = new TestTopologyDagCreatingVisitor(originalTopologyDag, testRunSourcesForEachSource, testRunProcessorsForEachProcessor, testRunRulesProcessorsForEachProcessor, testRunSinksForEachSink);
    originalTopologyDag.traverse(visitor);
    TopologyDag testTopologyDag = visitor.getTestTopologyDag();
    TopologyLayout testTopology = copyTopologyLayout(topology, testTopologyDag);
    Path jarToDeploy = addArtifactsToJar(getArtifactsLocation(testTopology));
    String fileName = createYamlFileForTest(testTopology);
    List<String> commands = new ArrayList<String>();
    commands.add(stormCliPath);
    commands.add("jar");
    commands.add(jarToDeploy.toString());
    commands.addAll(getExtraJarsArg(testTopology));
    commands.addAll(getMavenArtifactsRelatedArgs(mavenArtifacts));
    commands.addAll(getNimbusConf());
    commands.addAll(getForceNonSecuredClusterConf());
    commands.addAll(getTempWorkerArtifactArgs());
    commands.add("org.apache.storm.flux.Flux");
    commands.add("--local");
    commands.add("-s");
    if (durationSecs.isPresent()) {
        commands.add(String.valueOf(durationSecs.get() * 1000));
    } else {
        commands.add(String.valueOf(TEST_RUN_TOPOLOGY_DEFAULT_WAIT_MILLIS_FOR_SHUTDOWN));
    }
    commands.add(fileName);
    Process process = executeShellProcess(commands);
    ShellProcessResult shellProcessResult = waitTestRunProcess(process, testRunHistory.getId());
    int exitValue = shellProcessResult.exitValue;
    if (exitValue != 0) {
        LOG.error("Topology deploy command as test mode failed - exit code: {} / output: {}", exitValue, shellProcessResult.stdout);
        throw new Exception("Topology could not be run " + "successfully as test mode: storm deploy command failed");
    }
}
Also used : Path(java.nio.file.Path) TopologyLayout(com.hortonworks.streamline.streams.layout.component.TopologyLayout) ArrayList(java.util.ArrayList) TopologyNotAliveException(com.hortonworks.streamline.streams.exception.TopologyNotAliveException) IOException(java.io.IOException) TopologyDag(com.hortonworks.streamline.streams.layout.component.TopologyDag)

Example 9 with TopologyDag

use of com.hortonworks.streamline.streams.layout.component.TopologyDag in project streamline by hortonworks.

the class TestTopologyDagCreatingVisitorTest method visitProcessor_connectedFromProcessor.

@Test
public void visitProcessor_connectedFromProcessor() throws Exception {
    StreamlineProcessor originProcessor = TopologyTestHelper.createStreamlineProcessor("1");
    StreamlineProcessor originProcessor2 = TopologyTestHelper.createStreamlineProcessor("2");
    TopologyDag originTopologyDag = new TopologyDag();
    originTopologyDag.add(originProcessor);
    originTopologyDag.add(originProcessor2);
    originTopologyDag.addEdge(new Edge("e1", originProcessor, originProcessor2, "default", Stream.Grouping.SHUFFLE));
    TestRunProcessor testProcessor = createTestRunProcessor(originProcessor);
    TestRunProcessor testProcessor2 = createTestRunProcessor(originProcessor2);
    Map<String, TestRunProcessor> processorMap = new HashMap<>();
    processorMap.put(originProcessor.getName(), testProcessor);
    processorMap.put(originProcessor2.getName(), testProcessor2);
    TestTopologyDagCreatingVisitor visitor = new TestTopologyDagCreatingVisitor(originTopologyDag, Collections.emptyMap(), processorMap, Collections.emptyMap(), Collections.emptyMap());
    visitor.visit(originProcessor);
    visitor.visit(originProcessor2);
    TopologyDag testTopologyDag = visitor.getTestTopologyDag();
    List<OutputComponent> testProcessors = testTopologyDag.getOutputComponents().stream().filter(o -> (o instanceof TestRunProcessor)).collect(toList());
    Optional<OutputComponent> testRunProcessorOptional = testProcessors.stream().filter(o -> o.getName().equals(originProcessor.getName())).findAny();
    Optional<OutputComponent> testRunProcessor2Optional = testProcessors.stream().filter(o -> o.getName().equals(originProcessor2.getName())).findAny();
    assertTrue(testRunProcessorOptional.isPresent());
    assertTrue(testRunProcessor2Optional.isPresent());
    TestRunProcessor testRunProcessor = (TestRunProcessor) testRunProcessorOptional.get();
    TestRunProcessor testRunProcessor2 = (TestRunProcessor) testRunProcessor2Optional.get();
    assertEquals(1, testTopologyDag.getEdgesFrom(testRunProcessor).size());
    assertEquals(1, testTopologyDag.getEdgesTo(testRunProcessor2).size());
    assertTrue(testTopologyDag.getEdgesFrom(testRunProcessor).get(0) == testTopologyDag.getEdgesTo(testRunProcessor2).get(0));
}
Also used : OutputComponent(com.hortonworks.streamline.streams.layout.component.OutputComponent) Stream(com.hortonworks.streamline.streams.layout.component.Stream) TestRunProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunProcessor) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) HashMap(java.util.HashMap) InputComponent(com.hortonworks.streamline.streams.layout.component.InputComponent) RulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor) Edge(com.hortonworks.streamline.streams.layout.component.Edge) TopologyDag(com.hortonworks.streamline.streams.layout.component.TopologyDag) TestRunSink(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSink) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) TopologyTestHelper(com.hortonworks.streamline.streams.actions.utils.TopologyTestHelper) TestRunSource(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSource) Map(java.util.Map) TestRunRulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor) Optional(java.util.Optional) StreamlineProcessor(com.hortonworks.streamline.streams.layout.component.StreamlineProcessor) StreamlineSource(com.hortonworks.streamline.streams.layout.component.StreamlineSource) Assert.fail(org.junit.Assert.fail) StreamlineSink(com.hortonworks.streamline.streams.layout.component.StreamlineSink) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) StreamlineProcessor(com.hortonworks.streamline.streams.layout.component.StreamlineProcessor) TestRunProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunProcessor) OutputComponent(com.hortonworks.streamline.streams.layout.component.OutputComponent) HashMap(java.util.HashMap) Edge(com.hortonworks.streamline.streams.layout.component.Edge) TopologyDag(com.hortonworks.streamline.streams.layout.component.TopologyDag) Test(org.junit.Test)

Example 10 with TopologyDag

use of com.hortonworks.streamline.streams.layout.component.TopologyDag in project streamline by hortonworks.

the class TestTopologyDagCreatingVisitorTest method visitSource.

@Test
public void visitSource() throws Exception {
    StreamlineSource originSource = TopologyTestHelper.createStreamlineSource("1");
    TopologyDag originTopologyDag = new TopologyDag();
    originTopologyDag.add(originSource);
    TestRunSource testSource = createTestRunSource(originSource);
    TestTopologyDagCreatingVisitor visitor = new TestTopologyDagCreatingVisitor(originTopologyDag, Collections.singletonMap(originSource.getName(), testSource), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap());
    visitor.visit(originSource);
    TopologyDag testTopologyDag = visitor.getTestTopologyDag();
    List<OutputComponent> testSources = testTopologyDag.getOutputComponents().stream().filter(o -> (o instanceof TestRunSource && o.getName().equals(originSource.getName()))).collect(toList());
    assertEquals(1, testSources.size());
    TestRunSource testRunSource = (TestRunSource) testSources.get(0);
    assertEquals(originSource.getId(), testRunSource.getId());
    assertEquals(testSource.getTestRecordsForEachStream(), testRunSource.getTestRecordsForEachStream());
}
Also used : OutputComponent(com.hortonworks.streamline.streams.layout.component.OutputComponent) Stream(com.hortonworks.streamline.streams.layout.component.Stream) TestRunProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunProcessor) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) HashMap(java.util.HashMap) InputComponent(com.hortonworks.streamline.streams.layout.component.InputComponent) RulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor) Edge(com.hortonworks.streamline.streams.layout.component.Edge) TopologyDag(com.hortonworks.streamline.streams.layout.component.TopologyDag) TestRunSink(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSink) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) TopologyTestHelper(com.hortonworks.streamline.streams.actions.utils.TopologyTestHelper) TestRunSource(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSource) Map(java.util.Map) TestRunRulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor) Optional(java.util.Optional) StreamlineProcessor(com.hortonworks.streamline.streams.layout.component.StreamlineProcessor) StreamlineSource(com.hortonworks.streamline.streams.layout.component.StreamlineSource) Assert.fail(org.junit.Assert.fail) StreamlineSink(com.hortonworks.streamline.streams.layout.component.StreamlineSink) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) OutputComponent(com.hortonworks.streamline.streams.layout.component.OutputComponent) StreamlineSource(com.hortonworks.streamline.streams.layout.component.StreamlineSource) TestRunSource(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSource) TopologyDag(com.hortonworks.streamline.streams.layout.component.TopologyDag) Test(org.junit.Test)

Aggregations

TopologyDag (com.hortonworks.streamline.streams.layout.component.TopologyDag)15 StreamlineSink (com.hortonworks.streamline.streams.layout.component.StreamlineSink)9 StreamlineSource (com.hortonworks.streamline.streams.layout.component.StreamlineSource)9 Test (org.junit.Test)9 Edge (com.hortonworks.streamline.streams.layout.component.Edge)8 StreamlineProcessor (com.hortonworks.streamline.streams.layout.component.StreamlineProcessor)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8 TopologyTestHelper (com.hortonworks.streamline.streams.actions.utils.TopologyTestHelper)7 InputComponent (com.hortonworks.streamline.streams.layout.component.InputComponent)7 OutputComponent (com.hortonworks.streamline.streams.layout.component.OutputComponent)7 Stream (com.hortonworks.streamline.streams.layout.component.Stream)7 RulesProcessor (com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor)7 TestRunProcessor (com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunProcessor)7 TestRunRulesProcessor (com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor)7 TestRunSink (com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSink)7 TestRunSource (com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSource)7 Collections (java.util.Collections)7 List (java.util.List)7 Optional (java.util.Optional)7