Search in sources :

Example 11 with TopologyTestRunCaseSource

use of com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource in project streamline by hortonworks.

the class StreamCatalogService method getTopologyTestRunCaseSource.

public TopologyTestRunCaseSource getTopologyTestRunCaseSource(Long testcaseId, Long id) {
    TopologyTestRunCaseSource testCaseSource = new TopologyTestRunCaseSource();
    testCaseSource.setId(id);
    TopologyTestRunCaseSource retrieved = dao.get(new StorableKey(TopologyTestRunCaseSource.NAMESPACE, testCaseSource.getPrimaryKey()));
    if (retrieved == null || !retrieved.getTestCaseId().equals(testcaseId)) {
        return null;
    }
    return retrieved;
}
Also used : StorableKey(com.hortonworks.registries.storage.StorableKey) TopologyTestRunCaseSource(com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource)

Example 12 with TopologyTestRunCaseSource

use of com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource in project streamline by hortonworks.

the class StreamCatalogService method removeTopologyDependencies.

private void removeTopologyDependencies(Long topologyId, Long versionId) throws Exception {
    List<QueryParam> topologyIdVersionIdQueryParams = WSUtils.buildTopologyIdAndVersionIdAwareQueryParams(topologyId, versionId, null);
    // remove topology test histories
    Collection<TopologyTestRunHistory> runHistories = listTopologyTestRunHistory(topologyId, versionId);
    runHistories.forEach(history -> removeTopologyTestRunHistory(history.getId()));
    // remove topology test run case
    Collection<TopologyTestRunCase> runCases = listTopologyTestRunCase(topologyIdVersionIdQueryParams);
    for (TopologyTestRunCase runCase : runCases) {
        Collection<TopologyTestRunCaseSource> runCaseSources = listTopologyTestRunCaseSource(runCase.getId());
        Collection<TopologyTestRunCaseSink> runCaseSinks = listTopologyTestRunCaseSink(runCase.getId());
        // remove topology test run case source
        for (TopologyTestRunCaseSource runCaseSource : runCaseSources) {
            removeTopologyTestRunCaseSource(runCaseSource.getId());
        }
        // remove topology test run case sink
        for (TopologyTestRunCaseSink runCaseSink : runCaseSinks) {
            removeTopologyTestRunCaseSink(runCaseSink.getId());
        }
        removeTestRunCase(topologyId, runCase.getId());
    }
    // remove edges
    Collection<TopologyEdge> edges = listTopologyEdges(topologyIdVersionIdQueryParams);
    for (TopologyEdge edge : edges) {
        removeTopologyEdge(topologyId, edge.getId(), versionId);
    }
    // remove rules
    Collection<TopologyRule> topologyRules = listRules(topologyIdVersionIdQueryParams);
    for (TopologyRule topologyRule : topologyRules) {
        removeRule(topologyId, topologyRule.getId(), versionId);
    }
    // remove windowed rules
    Collection<TopologyWindow> topologyWindows = listWindows(topologyIdVersionIdQueryParams);
    for (TopologyWindow topologyWindow : topologyWindows) {
        removeWindow(topologyId, topologyWindow.getId(), versionId);
    }
    // remove branch rules
    Collection<TopologyBranchRule> topologyBranchRules = listBranchRules(topologyIdVersionIdQueryParams);
    for (TopologyBranchRule topologyBranchRule : topologyBranchRules) {
        removeBranchRule(topologyId, topologyBranchRule.getId(), versionId);
    }
    // remove sinks
    Collection<TopologySink> sinks = listTopologySinks(topologyIdVersionIdQueryParams);
    for (TopologySink sink : sinks) {
        removeTopologySink(topologyId, sink.getId(), versionId, false);
    }
    // remove processors
    Collection<TopologyProcessor> processors = listTopologyProcessors(topologyIdVersionIdQueryParams);
    for (TopologyProcessor processor : processors) {
        removeTopologyProcessor(topologyId, processor.getId(), versionId, false);
    }
    // remove sources
    Collection<TopologySource> sources = listTopologySources(topologyIdVersionIdQueryParams);
    for (TopologySource source : sources) {
        removeTopologySource(topologyId, source.getId(), versionId, false);
    }
    // remove output streams
    Collection<TopologyStream> topologyStreams = listStreamInfos(topologyIdVersionIdQueryParams);
    for (TopologyStream topologyStream : topologyStreams) {
        removeStreamInfo(topologyId, topologyStream.getId(), versionId);
    }
    // remove topology editor metadata
    removeTopologyEditorMetadata(topologyId, versionId);
}
Also used : TopologyBranchRule(com.hortonworks.streamline.streams.catalog.TopologyBranchRule) TopologySource(com.hortonworks.streamline.streams.catalog.TopologySource) TopologyTestRunHistory(com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory) TopologyRule(com.hortonworks.streamline.streams.catalog.TopologyRule) BaseTopologyRule(com.hortonworks.streamline.streams.catalog.BaseTopologyRule) TopologyEdge(com.hortonworks.streamline.streams.catalog.TopologyEdge) TopologyTestRunCase(com.hortonworks.streamline.streams.catalog.TopologyTestRunCase) TopologyTestRunCaseSource(com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource) TopologyProcessor(com.hortonworks.streamline.streams.catalog.TopologyProcessor) TopologyWindow(com.hortonworks.streamline.streams.catalog.TopologyWindow) TopologySink(com.hortonworks.streamline.streams.catalog.TopologySink) TopologyStream(com.hortonworks.streamline.streams.catalog.TopologyStream) TopologyTestRunCaseSink(com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSink) QueryParam(com.hortonworks.registries.common.QueryParam) WSUtils.versionIdQueryParam(com.hortonworks.streamline.common.util.WSUtils.versionIdQueryParam) WSUtils.buildEdgesFromQueryParam(com.hortonworks.streamline.common.util.WSUtils.buildEdgesFromQueryParam) WSUtils.currentVersionQueryParam(com.hortonworks.streamline.common.util.WSUtils.currentVersionQueryParam) WSUtils.buildEdgesToQueryParam(com.hortonworks.streamline.common.util.WSUtils.buildEdgesToQueryParam)

Example 13 with TopologyTestRunCaseSource

use of com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource in project streamline by hortonworks.

the class StreamCatalogService method removeTopologyTestRunCaseSource.

public TopologyTestRunCaseSource removeTopologyTestRunCaseSource(Long id) {
    TopologyTestRunCaseSource testcaseSource = new TopologyTestRunCaseSource();
    testcaseSource.setId(id);
    return dao.remove(testcaseSource.getStorableKey());
}
Also used : TopologyTestRunCaseSource(com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource)

Example 14 with TopologyTestRunCaseSource

use of com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource in project streamline by hortonworks.

the class TopologyTestRunnerTest method createTopologyTestRunCaseSource.

private TopologyTestRunCaseSource createTopologyTestRunCaseSource(TopologyTestRunCase testRunCase, StreamlineSource source) {
    TopologyTestRunCaseSource testRunSource = new TopologyTestRunCaseSource();
    testRunSource.setId(Long.valueOf(source.getId()));
    testRunSource.setTestCaseId(testRunCase.getId());
    testRunSource.setSourceId(Long.valueOf(source.getId()));
    try {
        Map<String, String> testRecords = Collections.singletonMap("default", objectMapper.writeValueAsString(TopologyTestHelper.createTestRecords()));
        testRunSource.setRecords(objectMapper.writeValueAsString(testRecords));
    } catch (JsonProcessingException e) {
        throw new RuntimeException("Can't serialize test records map into JSON");
    }
    testRunSource.setOccurrence(1);
    testRunSource.setSleepMsPerIteration(0L);
    testRunSource.setTimestamp(System.currentTimeMillis());
    return testRunSource;
}
Also used : TopologyTestRunCaseSource(com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 15 with TopologyTestRunCaseSource

use of com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource in project streamline by hortonworks.

the class TopologyTestRunner method runTest.

public TopologyTestRunHistory runTest(TopologyActions topologyActions, Topology topology, TopologyTestRunCase testCase, Long durationSecs) throws IOException {
    List<StreamlineSource> sources = topology.getTopologyDag().getOutputComponents().stream().filter(c -> c instanceof StreamlineSource).map(c -> (StreamlineSource) c).collect(toList());
    List<StreamlineSink> sinks = topology.getTopologyDag().getInputComponents().stream().filter(c -> c instanceof StreamlineSink).map(c -> (StreamlineSink) c).collect(toList());
    List<StreamlineProcessor> processors = topology.getTopologyDag().getOutputComponents().stream().filter(c -> c instanceof StreamlineProcessor && !(c instanceof RulesProcessor)).map(c -> (StreamlineProcessor) c).collect(toList());
    List<RulesProcessor> rulesProcessors = topology.getTopologyDag().getOutputComponents().stream().filter(c -> c instanceof RulesProcessor).map(c -> (RulesProcessor) c).collect(toList());
    // load test case sources for all sources
    List<TopologyTestRunCaseSource> testRunCaseSources = sources.stream().map(s -> catalogService.getTopologyTestRunCaseSourceBySourceId(testCase.getId(), Long.valueOf(s.getId()))).collect(toList());
    if (testRunCaseSources.stream().anyMatch(Objects::isNull)) {
        throw new IllegalArgumentException("Not every source register test records.");
    }
    // load test case sources for all sinks
    List<TopologyTestRunCaseSink> testRunCaseSinks = sinks.stream().map(s -> catalogService.getTopologyTestRunCaseSinkBySinkId(testCase.getId(), Long.valueOf(s.getId()))).collect(toList());
    Map<Long, Map<String, List<Map<String, Object>>>> testRecordsForEachSources = readTestRecordsFromTestCaseSources(testRunCaseSources);
    Map<Long, Integer> occurrenceForEachSources = readOccurrenceFromTestCaseSources(testRunCaseSources);
    Map<Long, Long> sleepMsPerRecordsForEachSources = readSleepMsPerIterationFromTestCaseSources(testRunCaseSources);
    Map<String, List<Map<String, Object>>> expectedOutputRecordsMap = readExpectedRecordsFromTestCaseSinks(sinks, testRunCaseSinks);
    String eventLogFilePath = getTopologyTestRunEventLog(topology);
    Map<String, TestRunSource> testRunSourceMap = sources.stream().collect(toMap(s -> s.getName(), s -> {
        TestRunSource testRunSource = new TestRunSource(s.getOutputStreams(), testRecordsForEachSources.get(Long.valueOf(s.getId())), occurrenceForEachSources.get(Long.valueOf(s.getId())), sleepMsPerRecordsForEachSources.get(Long.valueOf(s.getId())), eventLogFilePath);
        testRunSource.setName(s.getName());
        return testRunSource;
    }));
    Map<String, TestRunSink> testRunSinkMap = sinks.stream().collect(toMap(s -> s.getName(), s -> {
        String uuid = UUID.randomUUID().toString();
        TestRunSink testRunSink = new TestRunSink(getTopologyTestRunResult(uuid));
        testRunSink.setName(s.getName());
        return testRunSink;
    }));
    Map<String, TestRunProcessor> testRunProcessorMap = processors.stream().collect(toMap(s -> s.getName(), s -> {
        if (s instanceof JoinProcessor) {
            TestRunProcessor testRunProcessor = new TestRunProcessor(s, true, eventLogFilePath);
            testRunProcessor.setName(s.getName());
            return testRunProcessor;
        } else {
            TestRunProcessor testRunProcessor = new TestRunProcessor(s, false, eventLogFilePath);
            testRunProcessor.setName(s.getName());
            return testRunProcessor;
        }
    }));
    Map<String, TestRunRulesProcessor> testRunRulesProcessorMap = rulesProcessors.stream().collect(toMap(s -> s.getName(), s -> {
        TestRunRulesProcessor testRunRulesProcessor = new TestRunRulesProcessor(s, eventLogFilePath);
        testRunRulesProcessor.setName(s.getName());
        return testRunRulesProcessor;
    }));
    // just create event file before running actual test run process
    createEventLogFile(eventLogFilePath);
    TopologyTestRunHistory history = initializeTopologyTestRunHistory(topology, testCase, expectedOutputRecordsMap, eventLogFilePath);
    catalogService.addTopologyTestRunHistory(history);
    Optional<Long> finalDurationSecs = Optional.ofNullable(durationSecs);
    ParallelStreamUtil.runAsync(() -> runTestInBackground(topologyActions, topology, history, testRunSourceMap, testRunProcessorMap, testRunRulesProcessorMap, testRunSinkMap, expectedOutputRecordsMap, finalDurationSecs), forkJoinPool);
    return history;
}
Also used : Topology(com.hortonworks.streamline.streams.catalog.Topology) StringUtils(org.apache.commons.lang.StringUtils) ParallelStreamUtil(com.hortonworks.streamline.common.util.ParallelStreamUtil) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) TopologyLayout(com.hortonworks.streamline.streams.layout.component.TopologyLayout) TopologyActions(com.hortonworks.streamline.streams.actions.TopologyActions) RulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor) ArrayList(java.util.ArrayList) Collectors.toMap(java.util.stream.Collectors.toMap) TestRunSource(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSource) Map(java.util.Map) StreamlineSource(com.hortonworks.streamline.streams.layout.component.StreamlineSource) TypeReference(com.fasterxml.jackson.core.type.TypeReference) JoinProcessor(com.hortonworks.streamline.streams.layout.component.impl.JoinProcessor) Logger(org.slf4j.Logger) TestRunProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunProcessor) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) CatalogToLayoutConverter(com.hortonworks.streamline.streams.catalog.CatalogToLayoutConverter) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) UUID(java.util.UUID) InputStreamReader(java.io.InputStreamReader) TopologyTestRunCaseSource(com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) Objects(java.util.Objects) TopologyTestRunHistory(com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory) TestRunSink(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSink) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ForkJoinPool(java.util.concurrent.ForkJoinPool) StreamCatalogService(com.hortonworks.streamline.streams.catalog.service.StreamCatalogService) TestRunRulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor) Optional(java.util.Optional) StreamlineProcessor(com.hortonworks.streamline.streams.layout.component.StreamlineProcessor) BufferedReader(java.io.BufferedReader) StreamlineSink(com.hortonworks.streamline.streams.layout.component.StreamlineSink) TopologyTestRunCaseSink(com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSink) TopologyTestRunCase(com.hortonworks.streamline.streams.catalog.TopologyTestRunCase) TestRunProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunProcessor) TestRunSink(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSink) TopologyTestRunHistory(com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) JoinProcessor(com.hortonworks.streamline.streams.layout.component.impl.JoinProcessor) TopologyTestRunCaseSource(com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource) TestRunRulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor) StreamlineSink(com.hortonworks.streamline.streams.layout.component.StreamlineSink) StreamlineProcessor(com.hortonworks.streamline.streams.layout.component.StreamlineProcessor) RulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor) TestRunRulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor) TopologyTestRunCaseSink(com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSink) Objects(java.util.Objects) StreamlineSource(com.hortonworks.streamline.streams.layout.component.StreamlineSource) TestRunSource(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSource) HashMap(java.util.HashMap) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map)

Aggregations

TopologyTestRunCaseSource (com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource)15 Path (javax.ws.rs.Path)7 TopologyTestRunCase (com.hortonworks.streamline.streams.catalog.TopologyTestRunCase)5 QueryParam (com.hortonworks.registries.common.QueryParam)4 WSUtils.buildEdgesFromQueryParam (com.hortonworks.streamline.common.util.WSUtils.buildEdgesFromQueryParam)4 WSUtils.buildEdgesToQueryParam (com.hortonworks.streamline.common.util.WSUtils.buildEdgesToQueryParam)4 WSUtils.currentVersionQueryParam (com.hortonworks.streamline.common.util.WSUtils.currentVersionQueryParam)4 WSUtils.versionIdQueryParam (com.hortonworks.streamline.common.util.WSUtils.versionIdQueryParam)4 TopologySource (com.hortonworks.streamline.streams.catalog.TopologySource)4 TopologyTestRunCaseSink (com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSink)4 TopologyTestRunHistory (com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory)3 POST (javax.ws.rs.POST)3 Timed (com.codahale.metrics.annotation.Timed)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 SchemaValidationFailedException (com.hortonworks.streamline.common.exception.SchemaValidationFailedException)2 BaseTopologyRule (com.hortonworks.streamline.streams.catalog.BaseTopologyRule)2 Topology (com.hortonworks.streamline.streams.catalog.Topology)2 TopologyBranchRule (com.hortonworks.streamline.streams.catalog.TopologyBranchRule)2 TopologyEdge (com.hortonworks.streamline.streams.catalog.TopologyEdge)2 TopologyProcessor (com.hortonworks.streamline.streams.catalog.TopologyProcessor)2