Search in sources :

Example 1 with TopologyTestRunHistory

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

the class TopologyTestRunResource method getHistoryOfTestRunTopology.

@GET
@Path("/topologies/{topologyId}/testhistories/{historyId}")
@Timed
public Response getHistoryOfTestRunTopology(@Context UriInfo urlInfo, @PathParam("topologyId") Long topologyId, @PathParam("historyId") Long historyId, @QueryParam("simplify") Boolean simplify, @Context SecurityContext securityContext) throws Exception {
    SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER, Topology.NAMESPACE, topologyId, READ);
    TopologyTestRunHistory history = catalogService.getTopologyTestRunHistory(historyId);
    if (history == null) {
        throw EntityNotFoundException.byId(String.valueOf(historyId));
    }
    if (!history.getTopologyId().equals(topologyId)) {
        throw BadRequestException.message("Test history " + historyId + " is not belong to topology " + topologyId);
    }
    if (BooleanUtils.isTrue(simplify)) {
        return WSUtils.respondEntity(new SimplifiedTopologyTestRunHistory(history), OK);
    } else {
        return WSUtils.respondEntity(history, OK);
    }
}
Also used : TopologyTestRunHistory(com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 2 with TopologyTestRunHistory

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

the class TopologyTestRunResource method testRunTopology.

@POST
@Path("/topologies/{topologyId}/actions/testrun")
@Timed
public Response testRunTopology(@Context UriInfo urlInfo, @PathParam("topologyId") Long topologyId, TopologyTestRunParam topologyTestRunParam, @Context SecurityContext securityContext) throws Exception {
    SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER, Topology.NAMESPACE, topologyId, EXECUTE);
    Topology result = catalogService.getTopology(topologyId);
    if (result != null) {
        Long testCaseId = topologyTestRunParam.getTestCaseId();
        Long durationSecs = topologyTestRunParam.getDurationSecs();
        if (testCaseId == null) {
            throw BadRequestException.missingParameter("testCaseId");
        }
        TopologyTestRunCase testCase = catalogService.getTopologyTestRunCase(topologyId, testCaseId);
        if (testCase == null) {
            throw EntityNotFoundException.byName("topology " + topologyId + " / topology test case " + testCaseId);
        }
        Collection<TopologyTestRunCaseSource> testCaseSources = catalogService.listTopologyTestRunCaseSource(testCaseId);
        if (testCaseSources != null) {
            for (TopologyTestRunCaseSource source : testCaseSources) {
                try {
                    doValidationForTestRunCaseSource(topologyId, testCaseId, source);
                } catch (SchemaValidationFailedException e) {
                    throw handleSchemaValidationFailedException(topologyId, source, e);
                }
            }
        }
        TopologyTestRunHistory history = actionsService.testRunTopology(result, testCase, durationSecs);
        return WSUtils.respondEntity(history, OK);
    }
    throw EntityNotFoundException.byName("topology " + topologyId.toString());
}
Also used : Topology(com.hortonworks.streamline.streams.catalog.Topology) TopologyTestRunCase(com.hortonworks.streamline.streams.catalog.TopologyTestRunCase) TopologyTestRunCaseSource(com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource) TopologyTestRunHistory(com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory) SchemaValidationFailedException(com.hortonworks.streamline.common.exception.SchemaValidationFailedException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed)

Example 3 with TopologyTestRunHistory

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

the class StreamCatalogService method getTopologyTestRunHistory.

public TopologyTestRunHistory getTopologyTestRunHistory(Long id) {
    TopologyTestRunHistory history = new TopologyTestRunHistory();
    history.setId(id);
    return dao.get(new StorableKey(TopologyTestRunHistory.NAMESPACE, history.getPrimaryKey()));
}
Also used : StorableKey(com.hortonworks.registries.storage.StorableKey) TopologyTestRunHistory(com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory)

Example 4 with TopologyTestRunHistory

use of com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory 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 5 with TopologyTestRunHistory

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

the class TopologyTestRunnerTest method runTest_withMismatchedExpectedOutputRecords.

@Test
public void runTest_withMismatchedExpectedOutputRecords() throws Exception {
    Topology topology = createSimpleDAGInjectedTestTopology();
    Long testCaseId = 1L;
    TopologyTestRunCase testCase = new TopologyTestRunCase();
    testCase.setId(testCaseId);
    testCase.setTopologyId(topology.getId());
    testCase.setName("testcase1");
    testCase.setTimestamp(System.currentTimeMillis());
    setTopologyCurrentVersionExpectation(topology);
    setTopologyTestRunCaseExpectations(topology, testCase);
    setTopologyTestRunCaseSinkMismatchedRecordsExpectations(topology, testCase);
    setTopologyTestRunHistoryExpectations();
    setSucceedTopologyActionsExpectations();
    TopologyTestRunHistory resultHistory = topologyTestRunner.runTest(topologyActions, topology, testCase, null);
    assertNotNull(resultHistory);
    waitForTopologyTestRunToFinish(resultHistory);
    new VerificationsInOrder() {

        {
            TopologyTestRunHistory runHistory;
            // some fields are already modified after calling the method, so don't need to capture it
            catalogService.addTopologyTestRunHistory(withInstanceOf(TopologyTestRunHistory.class));
            times = 1;
            catalogService.addOrUpdateTopologyTestRunHistory(anyLong, runHistory = withCapture());
            times = 1;
            assertEquals(topology.getId(), runHistory.getTopologyId());
            assertEquals(topology.getVersionId(), runHistory.getVersionId());
            assertTrue(runHistory.getFinished());
            assertTrue(runHistory.getSuccess());
            assertNotNull(runHistory.getStartTime());
            assertNotNull(runHistory.getFinishTime());
            assertTrue(runHistory.getFinishTime() - runHistory.getStartTime() >= 0);
            assertTrue(isNotEmptyJson(runHistory.getExpectedOutputRecords()));
            assertTrue(isNotEmptyJson(runHistory.getActualOutputRecords()));
            assertFalse(runHistory.getMatched());
        }
    };
}
Also used : Topology(com.hortonworks.streamline.streams.catalog.Topology) TopologyTestRunCase(com.hortonworks.streamline.streams.catalog.TopologyTestRunCase) TopologyTestRunHistory(com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory) VerificationsInOrder(mockit.VerificationsInOrder) Test(org.junit.Test)

Aggregations

TopologyTestRunHistory (com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory)13 Topology (com.hortonworks.streamline.streams.catalog.Topology)8 TopologyTestRunCase (com.hortonworks.streamline.streams.catalog.TopologyTestRunCase)8 TopologyTestRunCaseSource (com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource)6 TopologyTestRunCaseSink (com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSink)5 VerificationsInOrder (mockit.VerificationsInOrder)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 TopologyActions (com.hortonworks.streamline.streams.actions.TopologyActions)4 StreamCatalogService (com.hortonworks.streamline.streams.catalog.service.StreamCatalogService)4 StreamlineProcessor (com.hortonworks.streamline.streams.layout.component.StreamlineProcessor)4 StreamlineSink (com.hortonworks.streamline.streams.layout.component.StreamlineSink)4 StreamlineSource (com.hortonworks.streamline.streams.layout.component.StreamlineSource)4 TopologyLayout (com.hortonworks.streamline.streams.layout.component.TopologyLayout)4 TestRunProcessor (com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunProcessor)4 TestRunRulesProcessor (com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor)4 File (java.io.File)4 Files (com.google.common.io.Files)3 TopologyTestHelper (com.hortonworks.streamline.streams.actions.utils.TopologyTestHelper)3 Edge (com.hortonworks.streamline.streams.layout.component.Edge)3