Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot shutdown and start a same Siddhi app runtime #1616

Open
niveathika opened this issue Jan 17, 2020 · 1 comment · Fixed by siddhi-io/distribution#851
Open

Cannot shutdown and start a same Siddhi app runtime #1616

niveathika opened this issue Jan 17, 2020 · 1 comment · Fixed by siddhi-io/distribution#851

Comments

@niveathika
Copy link
Member

niveathika commented Jan 17, 2020

Description:
$subject, due to clearing of all input handlers during the shutdown, https://github.com/siddhi-io/siddhi/blob/master/modules/siddhi-core/src/main/java/io/siddhi/core/stream/input/InputManager.java#L84

Here, the input handlers between source mappers and stream junction are cleared leading to log being printed as siddhi app runtime is not running,

[pool-4-thread-1] ERROR io.siddhi.extension.map.xml.sourcemapper.XmlSourceMapper  - Exception occurred when converting XML message to Siddhi Event
java.lang.InterruptedException: Siddhi app 'TestSiddhiApp' is not running, cannot send events
	at io.siddhi.core.stream.input.InputHandler.send(InputHandler.java:93)
	at io.siddhi.core.stream.input.source.PassThroughSourceHandler.sendEvents(PassThroughSourceHandler.java:40)
	at io.siddhi.core.stream.input.source.InputEventHandler.sendEvents(InputEventHandler.java:111)
	at io.siddhi.extension.map.xml.sourcemapper.XmlSourceMapper.mapAndProcess(XmlSourceMapper.java:254)
	at io.siddhi.core.stream.input.source.SourceMapper.onEvent(SourceMapper.java:152)
	at io.siddhi.core.stream.input.source.SourceMapper.onEvent(SourceMapper.java:118)
	at io.siddhi.extension.io.http.source.HttpWorkerThread.run(HttpWorkerThread.java:62)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

Affected Siddhi Version:
5.1.12

Steps to reproduce:
Modified Siddhi-io-http testcase

 @Test
    public void testHTTPStopAndStart() throws Exception {
        logger.info(" Creating test for publishing events without URL.");
        URI baseURI = URI.create(String.format("http://%s:%d", "0.0.0.0", 8280));
        List<String> receivedEventNameList = new ArrayList<>(2);
        PersistenceStore persistenceStore = new InMemoryPersistenceStore();
        SiddhiManager siddhiManager = new SiddhiManager();
        siddhiManager.setPersistenceStore(persistenceStore);
        siddhiManager.setExtension("xml-input-mapper", XmlSourceMapper.class);
        String inStreamDefinition = "@App:name('TestSiddhiApp')" +
                "@source(type='http', @map(type='xml') )" +
                "define stream inputStream (name string, age int, country string);";
        String query = ("@info(name = 'query') "
                + "from inputStream "
                + "select *  "
                + "insert into outputStream;"
        );
        SiddhiAppRuntime siddhiAppRuntime = siddhiManager
                .createSiddhiAppRuntime(inStreamDefinition + query);

        siddhiAppRuntime.addCallback("query", new QueryCallback() {
            @Override
            public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
                EventPrinter.print(timeStamp, inEvents, removeEvents);
                for (Event event : inEvents) {
                    eventCount.incrementAndGet();
                    receivedEventNameList.add(event.getData(0).toString());
                }
            }
        });
        siddhiAppRuntime.start();
        // publishing events
        List<String> expected = new ArrayList<>(2);
        expected.add("John");
        expected.add("Mike");
        String event1 = "<events>"
                + "<event>"
                + "<name>John</name>"
                + "<age>100</age>"
                + "<country>AUS</country>"
                + "</event>"
                + "</events>";
        String event2 = "<events>"
                + "<event>"
                + "<name>Mike</name>"
                + "<age>20</age>"
                + "<country>USA</country>"
                + "</event>"
                + "</events>";
        HttpTestUtil.httpPublishEventDefault(event1, baseURI);
        HttpTestUtil.httpPublishEventDefault(event2, baseURI);
        SiddhiTestHelper.waitForEvents(waitTime, 2, eventCount, timeout);
        Assert.assertEquals(receivedEventNameList.toString(), expected.toString());
        siddhiAppRuntime.shutdown();

        eventCount.set(0);
        receivedEventNameList.clear();

        siddhiAppRuntime.start();
        HttpTestUtil.httpPublishEventDefault(event1, baseURI);
        SiddhiTestHelper.waitForEvents(waitTime, 1, eventCount, timeout);
        Assert.assertEquals(receivedEventNameList.toString(), expected.toString());
        siddhiAppRuntime.shutdown();

    }

Related Issues:
siddhi-io/distribution#826
siddhi-io/siddhi-io-http#161

@salvalcantara
Copy link
Contributor

salvalcantara commented Jan 22, 2020

@niveathika Is this something affecting only Siddhi-io-http or would be the same in general for any siddhi application runtime? Also, on a related note, what would be the recommended way to restart an application runtime when using Siddhi as a java library? For my use case, I have a runtime that detects multiple patterns. On the first detection of any of them I want to restart the whole runtime to start again from scratch. Seems from the replies in #1614 that it is not possible to do that from the siddhi application itself so I am planning to "reset" the runtime from the "outside". I guess that it would be a matter of calling shutdown followed by start on the runtime object, since it seems there is no such thing as a restart method. Maybe @mohanvive can help on this. Ideally, it should be possible to clear the associated state for a runtime without having to recreate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants