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);
}
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());
}
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());
}
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();
}
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());
}
Aggregations