use of io.siddhi.core.exception.SiddhiAppCreationException in project siddhi by wso2.
the class DefinitionParserHelper method addEventSink.
public static void addEventSink(StreamDefinition streamDefinition, StreamJunction streamJunction, ConcurrentMap<String, List<Sink>> eventSinkMap, SiddhiAppContext siddhiAppContext) {
for (Annotation sinkAnnotation : streamDefinition.getAnnotations()) {
if (SiddhiConstants.ANNOTATION_SINK.equalsIgnoreCase(sinkAnnotation.getName())) {
try {
sinkAnnotation = updateAnnotationRef(sinkAnnotation, SiddhiConstants.NAMESPACE_SINK, siddhiAppContext);
Annotation mapAnnotation = AnnotationHelper.getAnnotation(SiddhiConstants.ANNOTATION_MAP, sinkAnnotation.getAnnotations());
String sinkType = sinkAnnotation.getElement(SiddhiConstants.ANNOTATION_ELEMENT_TYPE);
if (sinkType == null) {
throw new SiddhiAppCreationException("Attribute 'type' does not exist for annotation '" + sinkAnnotation + "'", sinkAnnotation, siddhiAppContext);
}
if (mapAnnotation == null) {
mapAnnotation = Annotation.annotation(SiddhiConstants.ANNOTATION_MAP).element(SiddhiConstants.ANNOTATION_ELEMENT_TYPE, "passThrough");
}
Annotation distributionAnnotation = AnnotationHelper.getAnnotation(SiddhiConstants.ANNOTATION_DISTRIBUTION, sinkAnnotation.getAnnotations());
if (mapAnnotation != null) {
String[] supportedDynamicOptions = null;
List<OptionHolder> destinationOptHolders = new ArrayList<>();
List<Map<String, String>> destinationDeploymentProperties = new ArrayList<>();
Extension sinkExtension = constructExtension(streamDefinition, SiddhiConstants.ANNOTATION_SINK, sinkType, sinkAnnotation, SiddhiConstants.NAMESPACE_SINK);
ConfigReader sinkConfigReader = siddhiAppContext.getSiddhiContext().getConfigManager().generateConfigReader(sinkExtension.getNamespace(), sinkExtension.getName());
final boolean isDistributedTransport = (distributionAnnotation != null);
boolean isMultiClient = false;
if (isDistributedTransport) {
Sink sink = createSink(sinkExtension, siddhiAppContext);
isMultiClient = isMultiClientDistributedTransport(sink, streamDefinition, distributionAnnotation, siddhiAppContext);
supportedDynamicOptions = sink.getSupportedDynamicOptions();
destinationOptHolders = createDestinationOptionHolders(distributionAnnotation, streamDefinition, sink, siddhiAppContext);
destinationDeploymentProperties = createDestinationDeploymentProperties(distributionAnnotation, sink);
}
final String mapType = mapAnnotation.getElement(SiddhiConstants.ANNOTATION_ELEMENT_TYPE);
if (mapType != null) {
Sink sink;
if (isDistributedTransport) {
sink = (isMultiClient) ? new MultiClientDistributedSink() : new SingleClientDistributedSink();
} else {
sink = createSink(sinkExtension, siddhiAppContext);
}
if (supportedDynamicOptions == null) {
supportedDynamicOptions = sink.getSupportedDynamicOptions();
}
// load output mapper extension
Extension mapperExtension = constructExtension(streamDefinition, SiddhiConstants.ANNOTATION_MAP, mapType, sinkAnnotation, SiddhiConstants.NAMESPACE_SINK_MAPPER);
ConfigReader mapperConfigReader = siddhiAppContext.getSiddhiContext().getConfigManager().generateConfigReader(sinkExtension.getNamespace(), sinkExtension.getName());
SinkMapper sinkMapper = (SinkMapper) SiddhiClassLoader.loadExtensionImplementation(mapperExtension, SinkMapperExecutorExtensionHolder.getInstance(siddhiAppContext));
io.siddhi.annotation.Extension sinkExt = sink.getClass().getAnnotation(io.siddhi.annotation.Extension.class);
OptionHolder transportOptionHolder = constructOptionHolder(streamDefinition, sinkAnnotation, sinkExt, supportedDynamicOptions, true);
Map<String, String> deploymentProperties = createDeploymentProperties(sinkAnnotation, sinkExt);
OptionHolder mapOptionHolder = constructOptionHolder(streamDefinition, mapAnnotation, sinkMapper.getClass().getAnnotation(io.siddhi.annotation.Extension.class), sinkMapper.getSupportedDynamicOptions(), false);
List<Element> payloadElementList = getPayload(mapAnnotation);
OptionHolder distributionOptHolder = null;
SinkHandlerManager sinkHandlerManager = siddhiAppContext.getSiddhiContext().getSinkHandlerManager();
SinkHandler sinkHandler = null;
if (sinkHandlerManager != null) {
sinkHandler = sinkHandlerManager.generateSinkHandler();
}
if (isDistributedTransport) {
distributionOptHolder = constructOptionHolder(streamDefinition, distributionAnnotation, sinkExt, supportedDynamicOptions, true);
String strategyType = distributionOptHolder.validateAndGetStaticValue(SiddhiConstants.DISTRIBUTION_STRATEGY_KEY);
Extension strategyExtension = constructExtension(streamDefinition, SiddhiConstants.ANNOTATION_SINK, strategyType, sinkAnnotation, SiddhiConstants.NAMESPACE_DISTRIBUTION_STRATEGY);
ConfigReader configReader = siddhiAppContext.getSiddhiContext().getConfigManager().generateConfigReader(strategyExtension.getNamespace(), strategyExtension.getName());
DistributionStrategy distributionStrategy = (DistributionStrategy) SiddhiClassLoader.loadExtensionImplementation(strategyExtension, DistributionStrategyExtensionHolder.getInstance(siddhiAppContext));
distributionStrategy.init(streamDefinition, transportOptionHolder, distributionOptHolder, destinationOptHolders, configReader);
((DistributedTransport) sink).init(streamDefinition, sinkType, transportOptionHolder, sinkConfigReader, sinkMapper, mapType, mapOptionHolder, sinkHandler, payloadElementList, mapperConfigReader, streamJunction, siddhiAppContext, destinationOptHolders, sinkAnnotation, distributionStrategy, supportedDynamicOptions, deploymentProperties, destinationDeploymentProperties);
} else {
sink.init(streamDefinition, sinkType, transportOptionHolder, sinkConfigReader, sinkMapper, mapType, mapOptionHolder, sinkHandler, payloadElementList, mapperConfigReader, deploymentProperties, streamJunction, siddhiAppContext);
}
if (sinkHandlerManager != null) {
sinkHandlerManager.registerSinkHandler(sinkHandler.getId(), sinkHandler);
}
validateSinkMapperCompatibility(streamDefinition, sinkType, mapType, sink, sinkMapper, sinkAnnotation);
// Setting the output group determiner
OutputGroupDeterminer groupDeterminer = constructOutputGroupDeterminer(transportOptionHolder, distributionOptHolder, streamDefinition, destinationOptHolders.size());
if (groupDeterminer != null) {
sink.getMapper().setGroupDeterminer(groupDeterminer);
}
List<Sink> eventSinks = eventSinkMap.get(streamDefinition.getId());
if (eventSinks == null) {
eventSinks = new ArrayList<>();
eventSinks.add(sink);
eventSinkMap.put(streamDefinition.getId(), eventSinks);
} else {
eventSinks.add(sink);
}
} else {
throw new SiddhiAppCreationException("Attribute 'type' does not exist for annotation '" + mapAnnotation + "'", mapAnnotation, siddhiAppContext);
}
} else {
throw new SiddhiAppCreationException("Both @sink(type=) and @map(type=) are required.", sinkAnnotation.getQueryContextStartIndex(), sinkAnnotation.getQueryContextEndIndex());
}
} catch (Throwable t) {
ExceptionUtil.populateQueryContext(t, sinkAnnotation, siddhiAppContext);
throw t;
}
}
}
}
use of io.siddhi.core.exception.SiddhiAppCreationException in project siddhi by wso2.
the class DefinitionParserHelper method constructOptionHolder.
private static OptionHolder constructOptionHolder(StreamDefinition streamDefinition, Annotation annotation, io.siddhi.annotation.Extension extension, String[] supportedDynamicOptions, boolean supportDeploymentOptions) {
List<String> supportedDynamicOptionList = new ArrayList<>();
if (supportedDynamicOptions != null) {
supportedDynamicOptionList = Arrays.asList(supportedDynamicOptions);
}
Map<String, String> options = new HashMap<>();
Map<String, String> dynamicOptions = new HashMap<>();
for (Element element : annotation.getElements()) {
if (element.getKey().startsWith("dep:")) {
if (!supportDeploymentOptions) {
throw new SiddhiAppCreationException("DeploymentOption is not supported by '" + extension.namespace() + ":" + extension.name() + "', but a deployment property '" + element.getKey() + "' is configured", annotation.getQueryContextStartIndex(), annotation.getQueryContextEndIndex());
}
}
if (Pattern.matches("(.*?)\\{\\{.*?\\}\\}(.*?)", element.getValue())) {
if (supportedDynamicOptionList.contains(element.getKey())) {
dynamicOptions.put(element.getKey(), element.getValue());
} else {
throw new SiddhiAppCreationException("'" + element.getKey() + "' is not a supported " + "DynamicOption " + "for the Extension '" + extension.namespace() + ":" + extension.name() + "', it only supports following as its DynamicOptions: " + supportedDynamicOptionList, annotation.getQueryContextStartIndex(), annotation.getQueryContextEndIndex());
}
} else {
options.put(element.getKey(), element.getValue());
}
}
return new OptionHolder(streamDefinition, options, dynamicOptions, extension);
}
use of io.siddhi.core.exception.SiddhiAppCreationException in project siddhi by wso2.
the class TemplateBuilder method assignTemplateArrayAttributePositions.
private void assignTemplateArrayAttributePositions(String[] splitTemplateArray, StreamDefinition streamDefinition) {
this.positionArray = new int[splitTemplateArray.length / 2];
int positionCount = 0;
for (int i = 0; i < splitTemplateArray.length; i++) {
if (i % 2 != 0) {
try {
positionArray[positionCount++] = Integer.parseInt(splitTemplateArray[i]);
} catch (NumberFormatException e) {
throw new SiddhiAppCreationException(String.format("Invalid mapping configuration provided in " + "%s. Mapping parameter should be surrounded only with '{{' and '}}'.", streamDefinition));
}
}
}
}
use of io.siddhi.core.exception.SiddhiAppCreationException in project siddhi by wso2.
the class AttributeStreamFunction method init.
@Override
protected StateFactory init(AbstractDefinition inputDefinition, ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, boolean outputExpectsExpiredEvents, SiddhiQueryContext siddhiQueryContext) {
if (attributeExpressionExecutors.length != 1) {
throw new SiddhiAppCreationException("Only one attribute is expected but found " + attributeExpressionExecutors.length);
}
if (!(attributeExpressionExecutors[0] instanceof ConstantExpressionExecutor)) {
throw new SiddhiAppCreationException("Attribute is expected to be constant, but its not!");
}
newAttributes = new ArrayList<>();
newAttributes.add(new Attribute(((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue().toString(), inputDefinition.getAttributeList().get(0).getType()));
return null;
}
use of io.siddhi.core.exception.SiddhiAppCreationException in project siddhi by wso2.
the class SessionWindowTestCase method testSessionWindow10.
@Test(description = "This test checks whether the allowedLatency parameter value is greater" + " than the session gap value", expectedExceptions = SiddhiAppCreationException.class)
public void testSessionWindow10() {
log.info("SessionWindow Test10: Testing session window " + "with providing greater allowedLatency value than session gap value");
SiddhiManager siddhiManager = new SiddhiManager();
SiddhiAppRuntime siddhiAppRuntime = null;
String purchaseEventStream = "" + "define stream purchaseEventStream (user string, item_number int, price float, quantity int);";
String query = "" + "@info(name = 'query0') " + "from purchaseEventStream#window.session(5 sec, 6 sec) " + "select * " + "insert all events into outputStream ;";
try {
siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(purchaseEventStream + query);
} catch (SiddhiAppCreationException e) {
AssertJUnit.assertEquals("There is no parameterOverload for 'session' that matches attribute types " + "'<LONG, LONG>'. Supported parameter overloads are (<INT|LONG|TIME> session.gap), " + "(<INT|LONG|TIME> session.gap, <STRING> session.key), (<INT|LONG|TIME> session.gap, " + "<STRING> session.key, <INT|LONG|TIME> allowed.latency).", e.getCause().getMessage());
throw e;
} finally {
if (siddhiAppRuntime != null) {
siddhiAppRuntime.shutdown();
}
}
}
Aggregations