Search in sources :

Example 6 with ServiceDeploymentInfo

use of io.siddhi.core.stream.ServiceDeploymentInfo in project siddhi by wso2.

the class SingleClientDistributedSink method initTransport.

@Override
public void initTransport(OptionHolder sinkOptionHolder, List<OptionHolder> destinationOptionHolders, Map<String, String> deploymentProperties, List<Map<String, String>> destinationDeploymentProperties, Annotation sinkAnnotation, ConfigReader sinkConfigReader, DistributionStrategy strategy, String type, SiddhiAppContext siddhiAppContext) {
    final String transportType = sinkOptionHolder.validateAndGetStaticValue(SiddhiConstants.ANNOTATION_ELEMENT_TYPE);
    Extension sinkExtension = DefinitionParserHelper.constructExtension(streamDefinition, SiddhiConstants.ANNOTATION_SINK, transportType, sinkAnnotation, SiddhiConstants.NAMESPACE_SINK);
    Set<String> allDynamicOptionKeys = findAllDynamicOptions(destinationOptionHolders);
    destinationOptionHolders.forEach(optionHolder -> {
        optionHolder.merge(sinkOptionHolder);
        allDynamicOptionKeys.forEach(optionKey -> {
            String optionValue = optionHolder.getOrCreateOption(optionKey, null).getValue();
            if (optionValue == null || optionValue.isEmpty()) {
                throw new SiddhiAppValidationException("Destination properties can only contain " + "non-empty static values.");
            }
            Option sinkOption = sinkOptionHolder.getOrAddStaticOption(optionKey, optionValue);
            sinkOption.addVariableValue(optionValue);
            destinationCount++;
        });
    });
    this.sink = (Sink) SiddhiClassLoader.loadExtensionImplementation(sinkExtension, SinkExecutorExtensionHolder.getInstance(siddhiAppContext));
    this.sink.initOnlyTransport(streamDefinition, sinkOptionHolder, sinkConfigReader, type, new SingleClientConnectionCallback(destinationCount, strategy), destinationDeploymentProperties.get(0), siddhiAppContext);
    if (!this.sink.getServiceDeploymentInfoList().isEmpty()) {
        ((ServiceDeploymentInfo) this.sink.getServiceDeploymentInfoList().get(0)).addDeploymentProperties(deploymentProperties);
    }
}
Also used : Extension(io.siddhi.query.api.extension.Extension) SiddhiAppValidationException(io.siddhi.query.api.exception.SiddhiAppValidationException) ServiceDeploymentInfo(io.siddhi.core.stream.ServiceDeploymentInfo)

Example 7 with ServiceDeploymentInfo

use of io.siddhi.core.stream.ServiceDeploymentInfo in project siddhi by wso2.

the class SingleClientDistributedTransportTestCases method singleClientRoundRobin.

@Test
public void singleClientRoundRobin() throws InterruptedException {
    log.info("Test inMemorySink And EventMapping With SiddhiQL Dynamic Params");
    InMemoryBroker.Subscriber subscriptionWSO2 = new InMemoryBroker.Subscriber() {

        @Override
        public void onMessage(Object msg) {
            topic1Count.incrementAndGet();
        }

        @Override
        public String getTopic() {
            return "topic1";
        }
    };
    InMemoryBroker.Subscriber subscriptionIBM = new InMemoryBroker.Subscriber() {

        @Override
        public void onMessage(Object msg) {
            topic2Count.incrementAndGet();
        }

        @Override
        public String getTopic() {
            return "topic2";
        }
    };
    // subscribe to "inMemory" broker per topic
    InMemoryBroker.subscribe(subscriptionWSO2);
    InMemoryBroker.subscribe(subscriptionIBM);
    String streams = "" + "@app:name('TestSiddhiApp')" + "define stream FooStream (symbol string, price float, volume long); " + "@sink(type='inMemory', @map(type='passThrough'), " + "   @distribution(strategy='roundRobin', " + "       @destination(topic = 'topic1'), " + "       @destination(topic = 'topic2'))) " + "define stream BarStream (symbol string, price float, volume long); ";
    String query = "" + "from FooStream " + "select * " + "insert into BarStream; ";
    SiddhiManager siddhiManager = new SiddhiManager();
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    List<ServiceDeploymentInfo> serviceDeploymentInfos = siddhiAppRuntime.getSinks().iterator().next().get(0).getServiceDeploymentInfoList();
    Assert.assertEquals(serviceDeploymentInfos.size(), 0);
    InputHandler stockStream = siddhiAppRuntime.getInputHandler("FooStream");
    siddhiAppRuntime.start();
    stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
    stockStream.send(new Object[] { "WSO2", 75.6f, 100L });
    stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
    stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
    stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
    Thread.sleep(100);
    // assert event count
    AssertJUnit.assertEquals("Number of WSO2 events", 3, topic1Count.get());
    AssertJUnit.assertEquals("Number of IBM events", 2, topic2Count.get());
    siddhiAppRuntime.shutdown();
    // unsubscribe from "inMemory" broker per topic
    InMemoryBroker.unsubscribe(subscriptionWSO2);
    InMemoryBroker.unsubscribe(subscriptionIBM);
}
Also used : InputHandler(io.siddhi.core.stream.input.InputHandler) InMemoryBroker(io.siddhi.core.util.transport.InMemoryBroker) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) ServiceDeploymentInfo(io.siddhi.core.stream.ServiceDeploymentInfo) SiddhiManager(io.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 8 with ServiceDeploymentInfo

use of io.siddhi.core.stream.ServiceDeploymentInfo in project siddhi by wso2.

the class SingleClientDistributedTransportTestCases method multiClientRoundRobinWithDep.

@Test
public void multiClientRoundRobinWithDep() throws InterruptedException {
    log.info("Test inMemorySink And EventMapping With SiddhiQL Dynamic Params");
    InMemoryBroker.Subscriber subscriptionWSO2 = new InMemoryBroker.Subscriber() {

        @Override
        public void onMessage(Object msg) {
            topic1Count.incrementAndGet();
        }

        @Override
        public String getTopic() {
            return "topic1";
        }
    };
    InMemoryBroker.Subscriber subscriptionIBM = new InMemoryBroker.Subscriber() {

        @Override
        public void onMessage(Object msg) {
            topic2Count.incrementAndGet();
        }

        @Override
        public String getTopic() {
            return "topic2";
        }
    };
    // subscribe to "inMemory" broker per topic
    InMemoryBroker.subscribe(subscriptionWSO2);
    InMemoryBroker.subscribe(subscriptionIBM);
    String streams = "" + "@app:name('TestSiddhiApp')" + "define stream FooStream (symbol string, price float, volume long); " + "@sink(type='testDepInMemory', dep:foo='bar', @map(type='passThrough'), " + "   @distribution(strategy='roundRobin', " + "       @destination(topic = 'topic1'), " + "       @destination(topic = 'topic2'))) " + "define stream BarStream (symbol string, price float, volume long); ";
    String query = "" + "from FooStream " + "select * " + "insert into BarStream; ";
    SiddhiManager siddhiManager = new SiddhiManager();
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    List<ServiceDeploymentInfo> serviceDeploymentInfos = siddhiAppRuntime.getSinks().iterator().next().get(0).getServiceDeploymentInfoList();
    Assert.assertEquals(serviceDeploymentInfos.size(), 1);
    for (int i = 0; i < serviceDeploymentInfos.size(); i++) {
        ServiceDeploymentInfo serviceDeploymentInfo = serviceDeploymentInfos.get(i);
        Assert.assertNotNull(serviceDeploymentInfo);
        Assert.assertTrue(serviceDeploymentInfo.isSecured());
        Assert.assertTrue(serviceDeploymentInfo.getServiceProtocol() == ServiceDeploymentInfo.ServiceProtocol.TCP);
        Assert.assertTrue(serviceDeploymentInfo.getPort() == 8080);
        Assert.assertTrue(serviceDeploymentInfo.getDeploymentProperties().get("foo").equals("bar"));
    }
    InputHandler stockStream = siddhiAppRuntime.getInputHandler("FooStream");
    siddhiAppRuntime.start();
    stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
    stockStream.send(new Object[] { "WSO2", 75.6f, 100L });
    stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
    stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
    stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
    Thread.sleep(100);
    // assert event count
    AssertJUnit.assertEquals("Number of WSO2 events", 3, topic1Count.get());
    AssertJUnit.assertEquals("Number of IBM events", 2, topic2Count.get());
    siddhiAppRuntime.shutdown();
    // unsubscribe from "inMemory" broker per topic
    InMemoryBroker.unsubscribe(subscriptionWSO2);
    InMemoryBroker.unsubscribe(subscriptionIBM);
}
Also used : InputHandler(io.siddhi.core.stream.input.InputHandler) InMemoryBroker(io.siddhi.core.util.transport.InMemoryBroker) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) ServiceDeploymentInfo(io.siddhi.core.stream.ServiceDeploymentInfo) SiddhiManager(io.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 9 with ServiceDeploymentInfo

use of io.siddhi.core.stream.ServiceDeploymentInfo in project siddhi by wso2.

the class MultiClientDistributedSinkTestCase method multiClientRoundRobin.

@Test
public void multiClientRoundRobin() throws InterruptedException {
    log.info("Test inMemorySink And EventMapping With SiddhiQL Dynamic Params");
    InMemoryBroker.Subscriber subscriptionWSO2 = new InMemoryBroker.Subscriber() {

        @Override
        public void onMessage(Object msg) {
            topic1Count.incrementAndGet();
        }

        @Override
        public String getTopic() {
            return "topic1";
        }
    };
    InMemoryBroker.Subscriber subscriptionIBM = new InMemoryBroker.Subscriber() {

        @Override
        public void onMessage(Object msg) {
            topic2Count.incrementAndGet();
        }

        @Override
        public String getTopic() {
            return "topic2";
        }
    };
    // subscribe to "inMemory" broker per topic
    InMemoryBroker.subscribe(subscriptionWSO2);
    InMemoryBroker.subscribe(subscriptionIBM);
    String streams = "" + "@app:name('TestSiddhiApp')" + "define stream FooStream (symbol string, price float, volume long); " + "@sink(type='testInMemory', @map(type='passThrough'), " + "   @distribution(strategy='roundRobin', " + "       @destination(topic = 'topic1'), " + "       @destination(topic = 'topic2'))) " + "define stream BarStream (symbol string, price float, volume long); ";
    String query = "" + "from FooStream " + "select * " + "insert into BarStream; ";
    SiddhiManager siddhiManager = new SiddhiManager();
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    List<ServiceDeploymentInfo> serviceDeploymentInfos = siddhiAppRuntime.getSinks().iterator().next().get(0).getServiceDeploymentInfoList();
    Assert.assertEquals(serviceDeploymentInfos.size(), 0);
    InputHandler stockStream = siddhiAppRuntime.getInputHandler("FooStream");
    siddhiAppRuntime.start();
    stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
    stockStream.send(new Object[] { "WSO2", 75.6f, 100L });
    stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
    stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
    stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
    Thread.sleep(100);
    // assert event count
    AssertJUnit.assertEquals("Number of WSO2 events", 3, topic1Count.get());
    AssertJUnit.assertEquals("Number of IBM events", 2, topic2Count.get());
    siddhiAppRuntime.shutdown();
    // unsubscribe from "inMemory" broker per topic
    InMemoryBroker.unsubscribe(subscriptionWSO2);
    InMemoryBroker.unsubscribe(subscriptionIBM);
}
Also used : InputHandler(io.siddhi.core.stream.input.InputHandler) InMemoryBroker(io.siddhi.core.util.transport.InMemoryBroker) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) ServiceDeploymentInfo(io.siddhi.core.stream.ServiceDeploymentInfo) SiddhiManager(io.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Aggregations

ServiceDeploymentInfo (io.siddhi.core.stream.ServiceDeploymentInfo)9 SiddhiAppRuntime (io.siddhi.core.SiddhiAppRuntime)7 SiddhiManager (io.siddhi.core.SiddhiManager)7 Test (org.testng.annotations.Test)7 InputHandler (io.siddhi.core.stream.input.InputHandler)5 InMemoryBroker (io.siddhi.core.util.transport.InMemoryBroker)5 Event (io.siddhi.core.event.Event)2 StreamCallback (io.siddhi.core.stream.output.StreamCallback)2 Extension (io.siddhi.query.api.extension.Extension)2 Sink (io.siddhi.core.stream.output.sink.Sink)1 SiddhiAppValidationException (io.siddhi.query.api.exception.SiddhiAppValidationException)1