Search in sources :

Example 1 with org.wso2.carbon.identity.application.common.model.xsd

use of org.wso2.carbon.identity.application.common.model.xsd in project siddhi by wso2.

the class GroupByPerSnapshotOutputRateLimiter method process.

/**
 * Sends the collected unique outputs per group by key upon arrival of timer event from scheduler.
 *
 * @param complexEventChunk Incoming {@link org.wso2.siddhi.core.event.ComplexEventChunk}
 */
@Override
public void process(ComplexEventChunk complexEventChunk) {
    List<ComplexEventChunk<ComplexEvent>> outputEventChunks = new ArrayList<ComplexEventChunk<ComplexEvent>>();
    complexEventChunk.reset();
    synchronized (this) {
        complexEventChunk.reset();
        while (complexEventChunk.hasNext()) {
            ComplexEvent event = complexEventChunk.next();
            if (event.getType() == ComplexEvent.Type.TIMER) {
                tryFlushEvents(outputEventChunks, event);
            } else if (event.getType() == ComplexEvent.Type.CURRENT) {
                complexEventChunk.remove();
                tryFlushEvents(outputEventChunks, event);
                GroupedComplexEvent groupedComplexEvent = ((GroupedComplexEvent) event);
                groupByKeyEvents.put(groupedComplexEvent.getGroupKey(), groupedComplexEvent.getComplexEvent());
            }
        }
    }
    for (ComplexEventChunk eventChunk : outputEventChunks) {
        sendToCallBacks(eventChunk);
    }
}
Also used : GroupedComplexEvent(org.wso2.siddhi.core.event.GroupedComplexEvent) ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) ArrayList(java.util.ArrayList) GroupedComplexEvent(org.wso2.siddhi.core.event.GroupedComplexEvent)

Example 2 with org.wso2.carbon.identity.application.common.model.xsd

use of org.wso2.carbon.identity.application.common.model.xsd in project siddhi by wso2.

the class DefinitionParserHelper method addEventSink.

public static void addEventSink(StreamDefinition streamDefinition, ConcurrentMap<String, List<Sink>> eventSinkMap, SiddhiAppContext siddhiAppContext) {
    for (Annotation sinkAnnotation : streamDefinition.getAnnotations()) {
        if (SiddhiConstants.ANNOTATION_SINK.equalsIgnoreCase(sinkAnnotation.getName())) {
            sinkAnnotation = updateAnnotationRef(sinkAnnotation, SiddhiConstants.NAMESPACE_SINK, siddhiAppContext);
            Annotation mapAnnotation = AnnotationHelper.getAnnotation(SiddhiConstants.ANNOTATION_MAP, sinkAnnotation.getAnnotations());
            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<>();
                String sinkType = sinkAnnotation.getElement(SiddhiConstants.ANNOTATION_ELEMENT_TYPE);
                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);
                }
                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));
                    org.wso2.siddhi.annotation.Extension sinkExt = sink.getClass().getAnnotation(org.wso2.siddhi.annotation.Extension.class);
                    OptionHolder transportOptionHolder = constructOptionHolder(streamDefinition, sinkAnnotation, sinkExt, supportedDynamicOptions);
                    OptionHolder mapOptionHolder = constructOptionHolder(streamDefinition, mapAnnotation, sinkMapper.getClass().getAnnotation(org.wso2.siddhi.annotation.Extension.class), sinkMapper.getSupportedDynamicOptions());
                    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);
                        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));
                        try {
                            distributionStrategy.init(streamDefinition, transportOptionHolder, distributionOptHolder, destinationOptHolders, configReader);
                            ((DistributedTransport) sink).init(streamDefinition, sinkType, transportOptionHolder, sinkConfigReader, sinkMapper, mapType, mapOptionHolder, sinkHandler, payloadElementList, mapperConfigReader, siddhiAppContext, destinationOptHolders, sinkAnnotation, distributionStrategy, supportedDynamicOptions);
                        } catch (Throwable t) {
                            ExceptionUtil.populateQueryContext(t, sinkAnnotation, siddhiAppContext);
                            throw t;
                        }
                    } else {
                        try {
                            sink.init(streamDefinition, sinkType, transportOptionHolder, sinkConfigReader, sinkMapper, mapType, mapOptionHolder, sinkHandler, payloadElementList, mapperConfigReader, siddhiAppContext);
                        } catch (Throwable t) {
                            ExceptionUtil.populateQueryContext(t, sinkAnnotation, siddhiAppContext);
                            throw t;
                        }
                    }
                    if (sinkHandlerManager != null) {
                        sinkHandlerManager.registerSinkHandler(sinkHandler.getElementId(), sinkHandler);
                        siddhiAppContext.getSnapshotService().addSnapshotable(streamDefinition.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);
                    }
                    siddhiAppContext.getSnapshotService().addSnapshotable(sink.getStreamDefinition().getId(), sink);
                    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("Both @sink(type=) and @map(type=) are required.", sinkAnnotation.getQueryContextStartIndex(), sinkAnnotation.getQueryContextEndIndex());
            }
        }
    }
}
Also used : Element(org.wso2.siddhi.query.api.annotation.Element) ArrayList(java.util.ArrayList) OutputGroupDeterminer(org.wso2.siddhi.core.stream.output.sink.OutputGroupDeterminer) SingleClientDistributedSink(org.wso2.siddhi.core.util.transport.SingleClientDistributedSink) MultiClientDistributedSink(org.wso2.siddhi.core.util.transport.MultiClientDistributedSink) SingleClientDistributedSink(org.wso2.siddhi.core.util.transport.SingleClientDistributedSink) Sink(org.wso2.siddhi.core.stream.output.sink.Sink) OptionHolder(org.wso2.siddhi.core.util.transport.OptionHolder) SinkMapper(org.wso2.siddhi.core.stream.output.sink.SinkMapper) SinkHandlerManager(org.wso2.siddhi.core.stream.output.sink.SinkHandlerManager) SinkHandler(org.wso2.siddhi.core.stream.output.sink.SinkHandler) DistributedTransport(org.wso2.siddhi.core.stream.output.sink.distributed.DistributedTransport) DistributionStrategy(org.wso2.siddhi.core.stream.output.sink.distributed.DistributionStrategy) SiddhiAppCreationException(org.wso2.siddhi.core.exception.SiddhiAppCreationException) ConfigReader(org.wso2.siddhi.core.util.config.ConfigReader) Annotation(org.wso2.siddhi.query.api.annotation.Annotation) Extension(org.wso2.siddhi.query.api.extension.Extension) MultiClientDistributedSink(org.wso2.siddhi.core.util.transport.MultiClientDistributedSink)

Example 3 with org.wso2.carbon.identity.application.common.model.xsd

use of org.wso2.carbon.identity.application.common.model.xsd in project siddhi by wso2.

the class StatisticsTestCase method statisticsTest1.

@Test
public void statisticsTest1() throws InterruptedException {
    log.info("statistics test 1");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:statistics(reporter = 'console', interval = '2' )" + " " + "define stream cseEventStream (symbol string, price float, volume int);" + "define stream cseEventStream2 (symbol string, price float, volume int);" + "" + "@info(name = 'query1') " + "from cseEventStream[70 > price] " + "select * " + "insert into outputStream ;" + "" + "@info(name = 'query2') " + "from cseEventStream[volume > 90] " + "select * " + "insert into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            eventArrived = true;
            for (Event event : events) {
                count++;
                AssertJUnit.assertTrue("IBM".equals(event.getData(0)) || "WSO2".equals(event.getData(0)));
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);
    PrintStream old = System.out;
    System.setOut(ps);
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "WSO2", 55.6f, 100 });
    inputHandler.send(new Object[] { "IBM", 75.6f, 100 });
    Thread.sleep(3010);
    siddhiAppRuntime.shutdown();
    AssertJUnit.assertTrue(eventArrived);
    AssertJUnit.assertEquals(3, count);
    System.out.flush();
    String output = baos.toString();
    AssertJUnit.assertTrue(output.contains("Gauges"));
    AssertJUnit.assertTrue(output.contains("org.wso2.siddhi." + SiddhiConstants.METRIC_INFIX_SIDDHI_APPS));
    AssertJUnit.assertTrue(output.contains("query1.memory"));
    AssertJUnit.assertTrue(output.contains("Meters"));
    AssertJUnit.assertTrue(output.contains(SiddhiConstants.METRIC_INFIX_SIDDHI + SiddhiConstants.METRIC_DELIMITER + SiddhiConstants.METRIC_INFIX_STREAMS + SiddhiConstants.METRIC_DELIMITER + "cseEventStream"));
    AssertJUnit.assertTrue(output.contains("Timers"));
    AssertJUnit.assertTrue(output.contains("query1.latency"));
    log.info(output);
    System.setOut(old);
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) PrintStream(java.io.PrintStream) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Example 4 with org.wso2.carbon.identity.application.common.model.xsd

use of org.wso2.carbon.identity.application.common.model.xsd in project siddhi by wso2.

the class StatisticsTestCase method statisticsTest6.

@Test
public void statisticsTest6() throws InterruptedException {
    log.info("statistics test 1");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:statistics(reporter = 'console', interval = '2', include='*query2.*,*cseEventStream2*' )" + " " + "define stream cseEventStream (symbol string, price float, volume int);" + "define stream cseEventStream2 (symbol string, price float, volume int);" + "" + "@info(name = 'query1') " + "from cseEventStream[70 > price] " + "select * " + "insert into outputStream ;" + "" + "@info(name = 'query2') " + "from cseEventStream[volume > 90] " + "select * " + "insert into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            eventArrived = true;
            for (Event event : events) {
                count++;
                AssertJUnit.assertTrue("IBM".equals(event.getData(0)) || "WSO2".equals(event.getData(0)));
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);
    PrintStream old = System.out;
    System.setOut(ps);
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "WSO2", 55.6f, 100 });
    inputHandler.send(new Object[] { "IBM", 75.6f, 100 });
    Thread.sleep(3010);
    siddhiAppRuntime.shutdown();
    AssertJUnit.assertTrue(eventArrived);
    AssertJUnit.assertEquals(3, count);
    System.out.flush();
    String output = baos.toString();
    AssertJUnit.assertTrue(output.contains("Gauges"));
    AssertJUnit.assertTrue(output.contains("org.wso2.siddhi." + SiddhiConstants.METRIC_INFIX_SIDDHI_APPS));
    AssertJUnit.assertFalse(output.contains("query1.memory"));
    AssertJUnit.assertTrue(output.contains("cseEventStream2.throughput"));
    AssertJUnit.assertTrue(output.contains("Meters"));
    AssertJUnit.assertTrue(output.contains(SiddhiConstants.METRIC_INFIX_SIDDHI + SiddhiConstants.METRIC_DELIMITER + SiddhiConstants.METRIC_INFIX_STREAMS + SiddhiConstants.METRIC_DELIMITER + "cseEventStream"));
    AssertJUnit.assertTrue(output.contains("Timers"));
    AssertJUnit.assertFalse(output.contains("query1.latency"));
    AssertJUnit.assertTrue(output.contains("query2.memory"));
    log.info(output);
    System.setOut(old);
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) PrintStream(java.io.PrintStream) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Example 5 with org.wso2.carbon.identity.application.common.model.xsd

use of org.wso2.carbon.identity.application.common.model.xsd in project product-apim by wso2.

the class APIMgtBaseIntegrationIT method init.

@BeforeClass
public void init() throws AMIntegrationTestException {
    TokenInfo tokenInfo = TestUtil.getToken("admin", "admin");
    apiPublisherClient = new ApiClient(TestUtil.OAUTH2_SECURITY).setBasePath("https://" + TestUtil.getIpAddressOfContainer() + ":9443/api/am/publisher/v1.0");
    apiPublisherClient.setAccessToken(tokenInfo.getToken(), tokenInfo.getExpiryTime());
    apiStoreClient = new org.wso2.carbon.apimgt.rest.integration.tests.store.ApiClient(TestUtil.OAUTH2_SECURITY).setBasePath("https://" + TestUtil.getIpAddressOfContainer() + ":9443/api/am/store/v1.0");
    apiStoreClient.setAccessToken(tokenInfo.getToken(), tokenInfo.getExpiryTime());
    apiAdminClient = new org.wso2.carbon.apimgt.rest.integration.tests.admin.ApiClient(TestUtil.OAUTH2_SECURITY).setBasePath("https://" + TestUtil.getIpAddressOfContainer() + ":9443/api/am/admin/v1.0");
    apiAdminClient.setAccessToken(tokenInfo.getToken(), tokenInfo.getExpiryTime());
}
Also used : TokenInfo(org.wso2.carbon.apimgt.rest.integration.tests.util.TokenInfo) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

UserStoreException (org.wso2.carbon.user.api.UserStoreException)140 ArrayList (java.util.ArrayList)137 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)121 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)103 HashMap (java.util.HashMap)95 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)79 Resource (org.wso2.carbon.registry.core.Resource)78 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)63 IOException (java.io.IOException)60 RealmService (org.wso2.carbon.user.core.service.RealmService)59 Registry (org.wso2.carbon.registry.core.Registry)56 Test (org.junit.Test)55 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)43 APIProductResource (org.wso2.carbon.apimgt.api.model.APIProductResource)40 GovernanceException (org.wso2.carbon.governance.api.exception.GovernanceException)39 Map (java.util.Map)38 UserStoreException (org.wso2.carbon.user.core.UserStoreException)37 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)35 XMLStreamException (javax.xml.stream.XMLStreamException)34 OMElement (org.apache.axiom.om.OMElement)32