Search in sources :

Example 1 with TopologyLayout

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

the class TopologyTestRunner method runTestInBackground.

private Void runTestInBackground(TopologyActions topologyActions, Topology topology, TopologyTestRunHistory history, Map<String, TestRunSource> testRunSourceMap, Map<String, TestRunProcessor> testRunProcessorMap, Map<String, TestRunRulesProcessor> testRunRulesProcessorMap, Map<String, TestRunSink> testRunSinkMap, Map<String, List<Map<String, Object>>> expectedOutputRecordsMap, Optional<Long> durationSecs) throws IOException {
    TopologyLayout topologyLayout = CatalogToLayoutConverter.getTopologyLayout(topology, topology.getTopologyDag());
    try {
        topologyActionsService.setUpClusterArtifacts(topology, topologyActions);
        String mavenArtifacts = topologyActionsService.setUpExtraJars(topology, topologyActions);
        topologyActions.runTest(topologyLayout, history, mavenArtifacts, testRunSourceMap, testRunProcessorMap, testRunRulesProcessorMap, testRunSinkMap, durationSecs);
        history.finishSuccessfully();
        Map<String, List<Map<String, Object>>> actualOutputRecordsMap = parseTestRunOutputFiles(testRunSinkMap);
        history.setActualOutputRecords(objectMapper.writeValueAsString(actualOutputRecordsMap));
        if (expectedOutputRecordsMap != null) {
            boolean matched = equalsOutputRecords(expectedOutputRecordsMap, actualOutputRecordsMap);
            history.setMatched(matched);
        }
    } catch (Throwable e) {
        LOG.warn("Exception thrown while running Topology as test mode. Marking as 'failed'. topology id: {}", topology.getId(), e);
        history.finishWithFailures();
    }
    catalogService.addOrUpdateTopologyTestRunHistory(history.getId(), history);
    return null;
}
Also used : TopologyLayout(com.hortonworks.streamline.streams.layout.component.TopologyLayout) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList)

Example 2 with TopologyLayout

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

the class StormTopologyActionsImpl method deploy.

@Override
public void deploy(TopologyLayout topology, String mavenArtifacts, TopologyActionContext ctx, String asUser) throws Exception {
    ctx.setCurrentAction("Adding artifacts to jar");
    Path jarToDeploy = addArtifactsToJar(getArtifactsLocation(topology));
    ctx.setCurrentAction("Creating Storm topology YAML file");
    String fileName = createYamlFileForDeploy(topology);
    ctx.setCurrentAction("Deploying topology via 'storm jar' command");
    List<String> commands = new ArrayList<String>();
    commands.add(stormCliPath);
    commands.add("jar");
    commands.add(jarToDeploy.toString());
    commands.addAll(getExtraJarsArg(topology));
    commands.addAll(getMavenArtifactsRelatedArgs(mavenArtifacts));
    commands.addAll(getNimbusConf());
    commands.addAll(getSecuredClusterConf(asUser));
    commands.add("org.apache.storm.flux.Flux");
    commands.add("--remote");
    commands.add(fileName);
    LOG.info("Deploying Application {}", topology.getName());
    LOG.info(String.join(" ", commands));
    Process process = executeShellProcess(commands);
    ShellProcessResult shellProcessResult = waitProcessFor(process);
    int exitValue = shellProcessResult.exitValue;
    if (exitValue != 0) {
        LOG.error("Topology deploy command failed - exit code: {} / output: {}", exitValue, shellProcessResult.stdout);
        String[] lines = shellProcessResult.stdout.split("\\n");
        String errors = Arrays.stream(lines).filter(line -> line.startsWith("Exception") || line.startsWith("Caused by")).collect(Collectors.joining(", "));
        Pattern pattern = Pattern.compile("Topology with name `(.*)` already exists on cluster");
        Matcher matcher = pattern.matcher(errors);
        if (matcher.find()) {
            throw new TopologyAlreadyExistsOnCluster(matcher.group(1));
        } else {
            throw new Exception("Topology could not be deployed successfully: storm deploy command failed with " + errors);
        }
    }
}
Also used : Path(java.nio.file.Path) HiveSink(com.hortonworks.streamline.streams.layout.component.impl.HiveSink) Arrays(java.util.Arrays) StormTopologyUtil(com.hortonworks.streamline.streams.storm.common.StormTopologyUtil) LoggerFactory(org.slf4j.LoggerFactory) StormJaasCreator(com.hortonworks.streamline.streams.storm.common.StormJaasCreator) StringUtils(org.apache.commons.lang3.StringUtils) TopologyActions(com.hortonworks.streamline.streams.actions.TopologyActions) TopologyDag(com.hortonworks.streamline.streams.layout.component.TopologyDag) Matcher(java.util.regex.Matcher) TestRunSource(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSource) Map(java.util.Map) Path(java.nio.file.Path) Config(com.hortonworks.streamline.common.Config) StormTopologyValidator(com.hortonworks.streamline.streams.layout.storm.StormTopologyValidator) OutputComponent(com.hortonworks.streamline.streams.layout.component.OutputComponent) HdfsSink(com.hortonworks.streamline.streams.layout.component.impl.HdfsSink) TestRunProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunProcessor) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) StormTopologyFluxGenerator(com.hortonworks.streamline.streams.layout.storm.StormTopologyFluxGenerator) TestRunSink(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSink) IOUtils(org.apache.commons.io.IOUtils) StatusImpl(com.hortonworks.streamline.streams.actions.StatusImpl) List(java.util.List) HBaseSink(com.hortonworks.streamline.streams.layout.component.impl.HBaseSink) StormTopologyLayoutConstants(com.hortonworks.streamline.streams.layout.storm.StormTopologyLayoutConstants) HdfsSource(com.hortonworks.streamline.streams.layout.component.impl.HdfsSource) LogLevelLoggerResponse(com.hortonworks.streamline.streams.storm.common.logger.LogLevelLoggerResponse) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) Joiner(com.google.common.base.Joiner) ClientConfig(org.glassfish.jersey.client.ClientConfig) TopologyLayoutConstants(com.hortonworks.streamline.streams.layout.TopologyLayoutConstants) Client(javax.ws.rs.client.Client) HashMap(java.util.HashMap) TopologyLayout(com.hortonworks.streamline.streams.layout.component.TopologyLayout) TopologyAlreadyExistsOnCluster(com.hortonworks.streamline.common.exception.service.exception.request.TopologyAlreadyExistsOnCluster) Yaml(org.yaml.snakeyaml.Yaml) ArrayList(java.util.ArrayList) EnvironmentService(com.hortonworks.streamline.streams.cluster.service.EnvironmentService) TopologyNotAliveException(com.hortonworks.streamline.streams.exception.TopologyNotAliveException) DumperOptions(org.yaml.snakeyaml.DumperOptions) LinkedHashMap(java.util.LinkedHashMap) ClientBuilder(javax.ws.rs.client.ClientBuilder) Lists(com.google.common.collect.Lists) Charset(java.nio.charset.Charset) OutputStreamWriter(java.io.OutputStreamWriter) TopologyActionContext(com.hortonworks.streamline.streams.actions.TopologyActionContext) Logger(org.slf4j.Logger) StormRestAPIClient(com.hortonworks.streamline.streams.storm.common.StormRestAPIClient) LogLevelResponse(com.hortonworks.streamline.streams.storm.common.logger.LogLevelResponse) Files(java.nio.file.Files) StringWriter(java.io.StringWriter) FileOutputStream(java.io.FileOutputStream) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) Constants(com.hortonworks.streamline.streams.cluster.Constants) InputComponent(com.hortonworks.streamline.streams.layout.component.InputComponent) Subject(javax.security.auth.Subject) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) TopologyTestRunHistory(com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory) Collectors.toList(java.util.stream.Collectors.toList) Paths(java.nio.file.Paths) TestRunRulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor) Collections(java.util.Collections) InputStream(java.io.InputStream) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) TopologyNotAliveException(com.hortonworks.streamline.streams.exception.TopologyNotAliveException) IOException(java.io.IOException) TopologyAlreadyExistsOnCluster(com.hortonworks.streamline.common.exception.service.exception.request.TopologyAlreadyExistsOnCluster)

Example 3 with TopologyLayout

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

the class StormTopologyTimeSeriesMetricsImplTest method testGetProcessorComponentStatsWithoutAssigningTimeSeriesQuerier.

@Test
public void testGetProcessorComponentStatsWithoutAssigningTimeSeriesQuerier() throws Exception {
    stormTopologyTimeSeriesMetrics.setTimeSeriesQuerier(null);
    final TopologyLayout topology = getTopologyLayoutForTest();
    final long from = 1L;
    final long to = 3L;
    final Map<String, Map<Long, Double>> expectedMisc = new HashMap<>();
    expectedMisc.put(StormMappedMetric.ackedRecords.name(), Collections.emptyMap());
    expectedMisc.put(StormMappedMetric.executeTime.name(), Collections.emptyMap());
    TopologyTimeSeriesMetrics.TimeSeriesComponentMetric actual = stormTopologyTimeSeriesMetrics.getComponentStats(topology, processor, from, to, null);
    assertEquals(Collections.emptyMap(), actual.getInputRecords());
    assertEquals(Collections.emptyMap(), actual.getOutputRecords());
    assertEquals(Collections.emptyMap(), actual.getFailedRecords());
    assertEquals(Collections.emptyMap(), actual.getRecordsInWaitQueue());
    assertEquals(Collections.emptyMap(), actual.getProcessedTime());
    assertEquals(expectedMisc, actual.getMisc());
}
Also used : TopologyLayout(com.hortonworks.streamline.streams.layout.component.TopologyLayout) HashMap(java.util.HashMap) TopologyTimeSeriesMetrics(com.hortonworks.streamline.streams.metrics.topology.TopologyTimeSeriesMetrics) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 4 with TopologyLayout

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

the class StormTopologyTimeSeriesMetricsImplTest method getProcessorComponentStats.

@Test
public void getProcessorComponentStats() throws Exception {
    final TopologyLayout topology = getTopologyLayoutForTest();
    final long from = 1L;
    final long to = 3L;
    final TopologyTimeSeriesMetrics.TimeSeriesComponentMetric expectedMetric = setupExpectionToBoltComponent(processor, from, to);
    TopologyTimeSeriesMetrics.TimeSeriesComponentMetric actual = stormTopologyTimeSeriesMetrics.getComponentStats(topology, processor, from, to, null);
    assertEquals(expectedMetric, actual);
}
Also used : TopologyLayout(com.hortonworks.streamline.streams.layout.component.TopologyLayout) TopologyTimeSeriesMetrics(com.hortonworks.streamline.streams.metrics.topology.TopologyTimeSeriesMetrics) Test(org.junit.Test)

Example 5 with TopologyLayout

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

the class StormTopologyTimeSeriesMetricsImplTest method getSourceComponentStats.

@Test
public void getSourceComponentStats() throws Exception {
    final TopologyLayout topology = getTopologyLayoutForTest();
    final long from = 1L;
    final long to = 3L;
    final TopologyTimeSeriesMetrics.TimeSeriesComponentMetric expectedMetric = setupExpectionToSpoutComponent(source, from, to);
    TopologyTimeSeriesMetrics.TimeSeriesComponentMetric actual = stormTopologyTimeSeriesMetrics.getComponentStats(topology, source, from, to, null);
    assertEquals(expectedMetric, actual);
}
Also used : TopologyLayout(com.hortonworks.streamline.streams.layout.component.TopologyLayout) TopologyTimeSeriesMetrics(com.hortonworks.streamline.streams.metrics.topology.TopologyTimeSeriesMetrics) Test(org.junit.Test)

Aggregations

TopologyLayout (com.hortonworks.streamline.streams.layout.component.TopologyLayout)10 Test (org.junit.Test)7 TopologyTimeSeriesMetrics (com.hortonworks.streamline.streams.metrics.topology.TopologyTimeSeriesMetrics)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 TopologyDag (com.hortonworks.streamline.streams.layout.component.TopologyDag)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 TopologyActions (com.hortonworks.streamline.streams.actions.TopologyActions)2 TopologyTestRunHistory (com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory)2 TopologyNotAliveException (com.hortonworks.streamline.streams.exception.TopologyNotAliveException)2 TestRunProcessor (com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunProcessor)2 TestRunRulesProcessor (com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor)2 TestRunSink (com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSink)2 TestRunSource (com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSource)2 File (java.io.File)2 IOException (java.io.IOException)2 Collectors.toList (java.util.stream.Collectors.toList)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1