Search in sources :

Example 6 with TopologyRule

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

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

the class RuleParserTest method testParseAgg.

@Test
public void testParseAgg() throws Exception {
    final UDF stddevp = new UDF();
    stddevp.setClassName("foo.class.name");
    stddevp.setDescription("stddev p");
    stddevp.setId(100L);
    stddevp.setJarStoragePath("jarstoragepath");
    stddevp.setName("stddevp");
    stddevp.setType(Udf.Type.AGGREGATE);
    new Expectations() {

        {
            mockCatalogService.listStreamInfos(withAny(new ArrayList<QueryParam>()));
            result = mockTopologyStream;
            mockCatalogService.listUDFs();
            result = Collections.singleton(stddevp);
            mockTopologyStream.getStreamId();
            result = "teststream";
            mockTopologyStream.getFields();
            result = Arrays.asList(Schema.Field.of("temperature", Schema.Type.LONG), Schema.Field.of("humidity", Schema.Type.LONG));
        }
    };
    TopologyRule topologyRule = new TopologyRule();
    topologyRule.setId(1L);
    topologyRule.setName("Test");
    topologyRule.setDescription("test rule");
    topologyRule.setTopologyId(1L);
    topologyRule.setVersionId(1L);
    topologyRule.setSql("select stddevp(temperature) from teststream");
    RuleParser ruleParser = new RuleParser(mockCatalogService, topologyRule.getSql(), topologyRule.getTopologyId(), topologyRule.getVersionId());
    ruleParser.parse();
    LOG.info("Projection: [{}]", ruleParser.getProjection());
    assertEquals(1, ruleParser.getStreams().size());
    assertEquals(new Stream("teststream", Arrays.asList(Schema.Field.of("temperature", Schema.Type.LONG), Schema.Field.of("humidity", Schema.Type.LONG))), ruleParser.getStreams().get(0));
    assertNull(ruleParser.getGroupBy());
    assertNull(ruleParser.getHaving());
}
Also used : Expectations(mockit.Expectations) UDF(com.hortonworks.streamline.streams.catalog.UDF) ArrayList(java.util.ArrayList) TopologyStream(com.hortonworks.streamline.streams.catalog.TopologyStream) Stream(com.hortonworks.streamline.streams.layout.component.Stream) TopologyRule(com.hortonworks.streamline.streams.catalog.TopologyRule) Test(org.junit.Test)

Example 8 with TopologyRule

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

the class RuleParserTest method testParseSimple.

@Test
public void testParseSimple() throws Exception {
    new Expectations() {

        {
            mockCatalogService.listStreamInfos(withAny(new ArrayList<QueryParam>()));
            result = mockTopologyStream;
            mockTopologyStream.getStreamId();
            result = "teststream";
            mockTopologyStream.getFields();
            result = Arrays.asList(Schema.Field.of("temperature", Schema.Type.LONG), Schema.Field.of("humidity", Schema.Type.LONG));
        }
    };
    TopologyRule topologyRule = new TopologyRule();
    topologyRule.setId(1L);
    topologyRule.setName("Test");
    topologyRule.setDescription("test rule");
    topologyRule.setTopologyId(1L);
    topologyRule.setVersionId(1L);
    topologyRule.setSql("select temperature as temp from teststream where humidity > 80");
    RuleParser ruleParser = new RuleParser(mockCatalogService, topologyRule.getSql(), topologyRule.getTopologyId(), topologyRule.getVersionId());
    ruleParser.parse();
    assertEquals(new Condition(new BinaryExpression(Operator.GREATER_THAN, new FieldExpression(Schema.Field.of("humidity", Schema.Type.LONG)), new Literal("80"))), ruleParser.getCondition());
    assertEquals(new Projection(Arrays.asList(new AsExpression(new FieldExpression(Schema.Field.of("temperature", Schema.Type.LONG)), "TEMP"))), ruleParser.getProjection());
    assertEquals(1, ruleParser.getStreams().size());
    assertEquals(new Stream("teststream", Arrays.asList(Schema.Field.of("temperature", Schema.Type.LONG), Schema.Field.of("humidity", Schema.Type.LONG))), ruleParser.getStreams().get(0));
    assertNull(ruleParser.getGroupBy());
    assertNull(ruleParser.getHaving());
    assertTrue(ruleParser.getCondition().getExpression() instanceof BinaryExpression);
    assertTrue(((BinaryExpression) ruleParser.getCondition().getExpression()).getSecond() instanceof Literal);
    Literal literal = ((Literal) ((BinaryExpression) ruleParser.getCondition().getExpression()).getSecond());
    assertEquals("80", literal.getValue());
}
Also used : Expectations(mockit.Expectations) Condition(com.hortonworks.streamline.streams.layout.component.rule.expression.Condition) BinaryExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.BinaryExpression) Literal(com.hortonworks.streamline.streams.layout.component.rule.expression.Literal) ArrayList(java.util.ArrayList) Projection(com.hortonworks.streamline.streams.layout.component.rule.expression.Projection) TopologyStream(com.hortonworks.streamline.streams.catalog.TopologyStream) Stream(com.hortonworks.streamline.streams.layout.component.Stream) TopologyRule(com.hortonworks.streamline.streams.catalog.TopologyRule) AsExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.AsExpression) FieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.FieldExpression) Test(org.junit.Test)

Example 9 with TopologyRule

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

the class TopologyExportVisitor method createRuleHandlerMap.

private Map<String, RulesHandler> createRuleHandlerMap() {
    ImmutableMap.Builder<String, RulesHandler> rulesHandlerBuilder = ImmutableMap.builder();
    RulesHandler rulesHandler = new RulesHandler() {

        @Override
        public void handle(Rule rule) throws Exception {
            TopologyRule topologyRule = streamCatalogService.getRule(topologyId, rule.getId());
            topologyData.addRule(topologyRule);
        }
    };
    rulesHandlerBuilder.put(ComponentTypes.RULE, rulesHandler);
    rulesHandlerBuilder.put(ComponentTypes.PROJECTION, rulesHandler);
    rulesHandlerBuilder.put(ComponentTypes.BRANCH, new RulesHandler() {

        @Override
        public void handle(Rule rule) throws Exception {
            TopologyBranchRule topologyBranchRule = streamCatalogService.getBranchRule(topologyId, rule.getId());
            topologyData.addBranch(topologyBranchRule);
        }
    });
    rulesHandlerBuilder.put(ComponentTypes.WINDOW, new RulesHandler() {

        @Override
        public void handle(Rule rule) throws Exception {
            TopologyWindow topologyWindow = streamCatalogService.getWindow(topologyId, rule.getId());
            topologyData.addWindow(topologyWindow);
        }
    });
    return rulesHandlerBuilder.build();
}
Also used : TopologyWindow(com.hortonworks.streamline.streams.catalog.TopologyWindow) TopologyBranchRule(com.hortonworks.streamline.streams.catalog.TopologyBranchRule) Rule(com.hortonworks.streamline.streams.layout.component.rule.Rule) TopologyBranchRule(com.hortonworks.streamline.streams.catalog.TopologyBranchRule) TopologyRule(com.hortonworks.streamline.streams.catalog.TopologyRule) TopologyRule(com.hortonworks.streamline.streams.catalog.TopologyRule) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 10 with TopologyRule

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

the class RuleParserTest method testParseComplex1.

@Test
public void testParseComplex1() throws Exception {
    final UDF myFunc = new UDF();
    myFunc.setClassName("foo.class.name");
    myFunc.setDescription("My function");
    myFunc.setId(Math.abs(new Random().nextLong()));
    myFunc.setJarStoragePath("/udfstorage/");
    myFunc.setName("UPPER");
    myFunc.setType(Udf.Type.FUNCTION);
    new Expectations() {

        {
            mockCatalogService.listStreamInfos(withAny(new ArrayList<QueryParam>()));
            result = mockTopologyStream;
            mockCatalogService.listUDFs();
            result = Collections.singleton(myFunc);
            mockTopologyStream.getStreamId();
            result = "teststream";
            mockTopologyStream.getFields();
            result = Arrays.asList(Schema.Field.of("temperature", Schema.Type.LONG), Schema.Field.of("humidity", Schema.Type.LONG), Schema.Field.of("city", Schema.Type.STRING));
        }
    };
    TopologyRule topologyRule = new TopologyRule();
    topologyRule.setId(1L);
    topologyRule.setName("Test");
    topologyRule.setDescription("test rule");
    topologyRule.setTopologyId(1L);
    topologyRule.setVersionId(1L);
    topologyRule.setSql("select temperature, humidity, city from teststream where temperature + humidity > 100 OR UPPER(city) = 'SFO'");
    RuleParser ruleParser = new RuleParser(mockCatalogService, topologyRule.getSql(), topologyRule.getTopologyId(), topologyRule.getVersionId());
    ruleParser.parse();
    LOG.info("Projection: [{}]", ruleParser.getProjection());
    assertNotNull(ruleParser.getProjection());
    assertNotNull(ruleParser.getCondition());
    assertEquals(1, ruleParser.getStreams().size());
    assertNull(ruleParser.getGroupBy());
    assertNull(ruleParser.getHaving());
}
Also used : Expectations(mockit.Expectations) Random(java.util.Random) UDF(com.hortonworks.streamline.streams.catalog.UDF) ArrayList(java.util.ArrayList) TopologyRule(com.hortonworks.streamline.streams.catalog.TopologyRule) Test(org.junit.Test)

Aggregations

TopologyRule (com.hortonworks.streamline.streams.catalog.TopologyRule)18 ArrayList (java.util.ArrayList)7 BaseTopologyRule (com.hortonworks.streamline.streams.catalog.BaseTopologyRule)6 TopologyStream (com.hortonworks.streamline.streams.catalog.TopologyStream)6 Expectations (mockit.Expectations)6 Test (org.junit.Test)6 Timed (com.codahale.metrics.annotation.Timed)5 TopologyBranchRule (com.hortonworks.streamline.streams.catalog.TopologyBranchRule)5 Stream (com.hortonworks.streamline.streams.layout.component.Stream)5 TopologyWindow (com.hortonworks.streamline.streams.catalog.TopologyWindow)4 UDF (com.hortonworks.streamline.streams.catalog.UDF)4 Path (javax.ws.rs.Path)4 QueryParam (com.hortonworks.registries.common.QueryParam)3 StorableKey (com.hortonworks.registries.storage.StorableKey)3 Rule (com.hortonworks.streamline.streams.layout.component.rule.Rule)3 BinaryExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.BinaryExpression)3 Literal (com.hortonworks.streamline.streams.layout.component.rule.expression.Literal)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 WSUtils.buildEdgesFromQueryParam (com.hortonworks.streamline.common.util.WSUtils.buildEdgesFromQueryParam)2 WSUtils.buildEdgesToQueryParam (com.hortonworks.streamline.common.util.WSUtils.buildEdgesToQueryParam)2