Search in sources :

Example 1 with TopologyActions

use of com.hortonworks.streamline.streams.actions.TopologyActions in project streamline by hortonworks.

the class TopologyActionsService method testRunTopology.

public TopologyTestRunHistory testRunTopology(Topology topology, TopologyTestRunCase testCase, Long durationSecs) throws Exception {
    TopologyDag dag = topologyDagBuilder.getDag(topology);
    topology.setTopologyDag(dag);
    ensureValid(dag);
    TopologyActions topologyActions = getTopologyActionsInstance(topology);
    LOG.debug("Running topology {} in test mode", topology);
    return topologyTestRunner.runTest(topologyActions, topology, testCase, durationSecs);
}
Also used : TopologyActions(com.hortonworks.streamline.streams.actions.TopologyActions) TopologyDag(com.hortonworks.streamline.streams.layout.component.TopologyDag)

Example 2 with TopologyActions

use of com.hortonworks.streamline.streams.actions.TopologyActions in project streamline by hortonworks.

the class TopologyStates method invokeKill.

private static void invokeKill(TopologyContext context) throws Exception {
    Topology topology = context.getTopology();
    TopologyActions topologyActions = context.getTopologyActions();
    topologyActions.kill(CatalogToLayoutConverter.getTopologyLayout(topology), context.getAsUser());
    LOG.debug("Killed topology '{}'", topology.getName());
}
Also used : TopologyActions(com.hortonworks.streamline.streams.actions.TopologyActions) Topology(com.hortonworks.streamline.streams.catalog.Topology)

Example 3 with TopologyActions

use of com.hortonworks.streamline.streams.actions.TopologyActions in project streamline by hortonworks.

the class TopologyTestRunnerTest method runTest_withTestCaseId.

@Test
public void runTest_withTestCaseId() throws Exception {
    Topology topology = createSimpleDAGInjectedTestTopology();
    Long topologyId = topology.getId();
    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);
    setTopologyTestRunCaseSinkNotFoundExpectations(topology, testCase);
    setTopologyTestRunHistoryExpectations();
    setSucceedTopologyActionsExpectations();
    long sourceCount = topology.getTopologyDag().getOutputComponents().stream().filter(c -> c instanceof StreamlineSource).count();
    long sinkCount = topology.getTopologyDag().getInputComponents().stream().filter(c -> c instanceof StreamlineSink).count();
    TopologyTestRunHistory resultHistory = topologyTestRunner.runTest(topologyActions, topology, testCase, null);
    waitForTopologyTestRunToFinish(resultHistory);
    assertNotNull(resultHistory);
    assertTrue(resultHistory.getFinished());
    assertTrue(resultHistory.getSuccess());
    new VerificationsInOrder() {

        {
            catalogService.getTopologyTestRunCaseSourceBySourceId(testCaseId, anyLong);
            times = (int) sourceCount;
            catalogService.getTopologyTestRunCaseSinkBySinkId(testCaseId, anyLong);
            times = (int) sinkCount;
            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(isEmptyJson(runHistory.getExpectedOutputRecords()));
            assertTrue(isNotEmptyJson(runHistory.getActualOutputRecords()));
            assertFalse(runHistory.getMatched());
        }
    };
}
Also used : Topology(com.hortonworks.streamline.streams.catalog.Topology) BeforeClass(org.junit.BeforeClass) Expectations(mockit.Expectations) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) TopologyLayout(com.hortonworks.streamline.streams.layout.component.TopologyLayout) TopologyActions(com.hortonworks.streamline.streams.actions.TopologyActions) Edge(com.hortonworks.streamline.streams.layout.component.Edge) TopologyDag(com.hortonworks.streamline.streams.layout.component.TopologyDag) VerificationsInOrder(mockit.VerificationsInOrder) Collectors.toMap(java.util.stream.Collectors.toMap) Files(com.google.common.io.Files) TestRunSource(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSource) Map(java.util.Map) JMockit(mockit.integration.junit4.JMockit) StreamlineSource(com.hortonworks.streamline.streams.layout.component.StreamlineSource) Before(org.junit.Before) Stream(com.hortonworks.streamline.streams.layout.component.Stream) TestRunProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunProcessor) Assert.assertNotNull(org.junit.Assert.assertNotNull) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileWriter(java.io.FileWriter) Assert.assertTrue(org.junit.Assert.assertTrue) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) IOException(java.io.IOException) Delegate(mockit.Delegate) TopologyTestRunCaseSource(com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource) File(java.io.File) TopologyTestRunHistory(com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory) TestRunSink(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSink) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) TopologyTestHelper(com.hortonworks.streamline.streams.actions.utils.TopologyTestHelper) Assert.assertFalse(org.junit.Assert.assertFalse) 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) Injectable(mockit.Injectable) StreamlineSink(com.hortonworks.streamline.streams.layout.component.StreamlineSink) TopologyTestRunCaseSink(com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSink) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) TopologyTestRunCase(com.hortonworks.streamline.streams.catalog.TopologyTestRunCase) StreamlineSource(com.hortonworks.streamline.streams.layout.component.StreamlineSource) StreamlineSink(com.hortonworks.streamline.streams.layout.component.StreamlineSink) 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)

Example 4 with TopologyActions

use of com.hortonworks.streamline.streams.actions.TopologyActions in project streamline by hortonworks.

the class TopologyTestRunnerTest method runTest_topologyActionsTestRunFails.

@Test
public void runTest_topologyActionsTestRunFails() throws Exception {
    Topology topology = createSimpleDAGInjectedTestTopology();
    Long topologyId = topology.getId();
    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);
    setTopologyTestRunCaseSinkNotFoundExpectations(topology, testCase);
    setTopologyTestRunHistoryExpectations();
    setTopologyActionsThrowingExceptionExpectations();
    long sourceCount = topology.getTopologyDag().getOutputComponents().stream().filter(c -> c instanceof StreamlineSource).count();
    long sinkCount = topology.getTopologyDag().getInputComponents().stream().filter(c -> c instanceof StreamlineSink).count();
    TopologyTestRunHistory resultHistory = topologyTestRunner.runTest(topologyActions, topology, testCase, null);
    assertNotNull(resultHistory);
    waitForTopologyTestRunToFinish(resultHistory);
    new VerificationsInOrder() {

        {
            catalogService.getTopologyTestRunCaseSourceBySourceId(testCaseId, anyLong);
            times = (int) sourceCount;
            catalogService.getTopologyTestRunCaseSinkBySinkId(testCaseId, anyLong);
            times = (int) sinkCount;
            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());
            assertFalse(runHistory.getSuccess());
            assertNotNull(runHistory.getStartTime());
            assertNotNull(runHistory.getFinishTime());
            assertTrue(runHistory.getFinishTime() - runHistory.getStartTime() >= 0);
            assertTrue(isEmptyJson(runHistory.getExpectedOutputRecords()));
            assertNull(runHistory.getActualOutputRecords());
            assertFalse(runHistory.getMatched());
        }
    };
}
Also used : Topology(com.hortonworks.streamline.streams.catalog.Topology) BeforeClass(org.junit.BeforeClass) Expectations(mockit.Expectations) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) TopologyLayout(com.hortonworks.streamline.streams.layout.component.TopologyLayout) TopologyActions(com.hortonworks.streamline.streams.actions.TopologyActions) Edge(com.hortonworks.streamline.streams.layout.component.Edge) TopologyDag(com.hortonworks.streamline.streams.layout.component.TopologyDag) VerificationsInOrder(mockit.VerificationsInOrder) Collectors.toMap(java.util.stream.Collectors.toMap) Files(com.google.common.io.Files) TestRunSource(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSource) Map(java.util.Map) JMockit(mockit.integration.junit4.JMockit) StreamlineSource(com.hortonworks.streamline.streams.layout.component.StreamlineSource) Before(org.junit.Before) Stream(com.hortonworks.streamline.streams.layout.component.Stream) TestRunProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunProcessor) Assert.assertNotNull(org.junit.Assert.assertNotNull) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileWriter(java.io.FileWriter) Assert.assertTrue(org.junit.Assert.assertTrue) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) IOException(java.io.IOException) Delegate(mockit.Delegate) TopologyTestRunCaseSource(com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource) File(java.io.File) TopologyTestRunHistory(com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory) TestRunSink(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSink) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) TopologyTestHelper(com.hortonworks.streamline.streams.actions.utils.TopologyTestHelper) Assert.assertFalse(org.junit.Assert.assertFalse) 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) Injectable(mockit.Injectable) StreamlineSink(com.hortonworks.streamline.streams.layout.component.StreamlineSink) TopologyTestRunCaseSink(com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSink) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) TopologyTestRunCase(com.hortonworks.streamline.streams.catalog.TopologyTestRunCase) StreamlineSource(com.hortonworks.streamline.streams.layout.component.StreamlineSource) StreamlineSink(com.hortonworks.streamline.streams.layout.component.StreamlineSink) 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)

Example 5 with TopologyActions

use of com.hortonworks.streamline.streams.actions.TopologyActions in project streamline by hortonworks.

the class TopologyActionsService method getTopologyActionsInstance.

public TopologyActions getTopologyActionsInstance(Topology ds) {
    Namespace namespace = environmentService.getNamespace(ds.getNamespaceId());
    if (namespace == null) {
        throw new RuntimeException("Corresponding namespace not found: " + ds.getNamespaceId());
    }
    TopologyActions topologyActions = topologyActionsContainer.findInstance(namespace);
    if (topologyActions == null) {
        throw new RuntimeException("Can't find Topology Actions for such namespace " + ds.getNamespaceId());
    }
    return topologyActions;
}
Also used : TopologyActions(com.hortonworks.streamline.streams.actions.TopologyActions) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace)

Aggregations

TopologyActions (com.hortonworks.streamline.streams.actions.TopologyActions)7 Topology (com.hortonworks.streamline.streams.catalog.Topology)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 TopologyTestRunCase (com.hortonworks.streamline.streams.catalog.TopologyTestRunCase)3 TopologyTestRunCaseSink (com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSink)3 TopologyTestRunCaseSource (com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource)3 TopologyTestRunHistory (com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory)3 StreamCatalogService (com.hortonworks.streamline.streams.catalog.service.StreamCatalogService)3 StreamlineProcessor (com.hortonworks.streamline.streams.layout.component.StreamlineProcessor)3 StreamlineSink (com.hortonworks.streamline.streams.layout.component.StreamlineSink)3 StreamlineSource (com.hortonworks.streamline.streams.layout.component.StreamlineSource)3 TopologyDag (com.hortonworks.streamline.streams.layout.component.TopologyDag)3 TopologyLayout (com.hortonworks.streamline.streams.layout.component.TopologyLayout)3 TestRunProcessor (com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunProcessor)3 TestRunRulesProcessor (com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor)3 TestRunSink (com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSink)3 TestRunSource (com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSource)3 File (java.io.File)3 IOException (java.io.IOException)3