Search in sources :

Example 1 with Event

use of org.wso2.eventing.Event in project jaggery by wso2.

the class TomcatJaggeryWebappsDeployer method handleZipWebappDeployment.

/**
     * Handle the deployment of a an archive Jaggery app. i.e., a WAR
     *
     * @param webapp                    The WAR Jaggery app file
     * @param webContextParams          ServletContext params for this webapp
     * @param applicationEventListeners Application event listeners
     * @throws CarbonException If a deployment error occurs
     */
@SuppressFBWarnings("PATH_TRAVERSAL_IN")
protected void handleZipWebappDeployment(File webapp, List<WebContextParameter> webContextParams, List<Object> applicationEventListeners) throws CarbonException {
    synchronized (this) {
        String appPath = webapp.getAbsolutePath().substring(0, webapp.getAbsolutePath().indexOf(".zip"));
        try {
            JaggeryDeploymentUtil.unZip(new FileInputStream(webapp), appPath);
            if (!webapp.delete()) {
                throw new CarbonException(appPath + "could not be deleted");
            }
        } catch (FileNotFoundException e) {
            throw new CarbonException(e);
        }
        File unzippedWebapp = new File(appPath);
        handleExplodedWebappDeployment(unzippedWebapp, webContextParams, applicationEventListeners);
    }
}
Also used : CarbonException(org.wso2.carbon.CarbonException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 2 with Event

use of org.wso2.eventing.Event in project jaggery by wso2.

the class TomcatJaggeryWebappsDeployer method handleWebappDeployment.

/**
     * Deployment procedure of Jaggery apps
     *
     * @param webappFile                The Jaggery app file to be deployed
     * @param contextStr                jaggery app context string
     * @param webContextParams          context-params for this Jaggery app
     * @param applicationEventListeners Application event listeners
     * @throws CarbonException If a deployment error occurs
     */
protected void handleWebappDeployment(File webappFile, String contextStr, List<WebContextParameter> webContextParams, List<Object> applicationEventListeners) throws CarbonException {
    String filename = webappFile.getName();
    ArrayList<Object> listeners = new ArrayList<Object>(1);
    // listeners.add(new CarbonServletRequestListener());
    SecurityConstraint securityConstraint = new SecurityConstraint();
    securityConstraint.setAuthConstraint(true);
    SecurityCollection securityCollection = new SecurityCollection();
    securityCollection.setName("ConfigDir");
    securityCollection.setDescription("Jaggery Configuration Dir");
    securityCollection.addPattern("/" + JaggeryCoreConstants.JAGGERY_CONF_FILE);
    securityConstraint.addCollection(securityCollection);
    WebApplicationsHolder webApplicationsHolder = WebAppUtils.getWebappHolder(webappFile.getAbsolutePath(), configurationContext);
    try {
        JSONObject jaggeryConfigObj = readJaggeryConfig(webappFile);
        Tomcat tomcat = DataHolder.getCarbonTomcatService().getTomcat();
        Context context = DataHolder.getCarbonTomcatService().addWebApp(contextStr, webappFile.getAbsolutePath(), new JaggeryDeployerManager.JaggeryConfListener(jaggeryConfigObj, securityConstraint));
        //deploying web app for url mapping inside virtual host
        if (DataHolder.getHotUpdateService() != null) {
            List<String> hostNames = DataHolder.getHotUpdateService().getMappigsPerWebapp(contextStr);
            for (String hostName : hostNames) {
                Host host = DataHolder.getHotUpdateService().addHost(hostName);
                /*                    ApplicationContext.getCurrentApplicationContext().putUrlMappingForApplication(hostName, contextStr);
  */
                Context contextForHost = DataHolder.getCarbonTomcatService().addWebApp(host, "/", webappFile.getAbsolutePath(), new JaggeryDeployerManager.JaggeryConfListener(jaggeryConfigObj, securityConstraint));
                log.info("Deployed JaggeryApp on host: " + contextForHost);
            }
        }
        Manager manager = context.getManager();
        if (isDistributable(context, jaggeryConfigObj)) {
            //Clusterable manager implementation as DeltaManager
            context.setDistributable(true);
            // Using clusterable manager
            CarbonTomcatClusterableSessionManager sessionManager;
            if (manager instanceof CarbonTomcatClusterableSessionManager) {
                sessionManager = (CarbonTomcatClusterableSessionManager) manager;
                sessionManager.setOwnerTenantId(tenantId);
            } else {
                sessionManager = new CarbonTomcatClusterableSessionManager(tenantId);
                context.setManager(sessionManager);
            }
            Object alreadyinsertedSMMap = configurationContext.getProperty(CarbonConstants.TOMCAT_SESSION_MANAGER_MAP);
            if (alreadyinsertedSMMap != null) {
                ((Map<String, CarbonTomcatClusterableSessionManager>) alreadyinsertedSMMap).put(context.getName(), sessionManager);
            } else {
                sessionManagerMap.put(context.getName(), sessionManager);
                configurationContext.setProperty(CarbonConstants.TOMCAT_SESSION_MANAGER_MAP, sessionManagerMap);
            }
        } else {
            if (manager instanceof CarbonTomcatSessionManager) {
                ((CarbonTomcatSessionManager) manager).setOwnerTenantId(tenantId);
            } else if (manager instanceof CarbonTomcatSessionPersistentManager) {
                ((CarbonTomcatSessionPersistentManager) manager).setOwnerTenantId(tenantId);
                log.debug(manager.getInfo() + " enabled Tomcat HTTP Session Persistent mode using " + ((CarbonTomcatSessionPersistentManager) manager).getStore().getInfo());
            } else {
                context.setManager(new CarbonTomcatSessionManager(tenantId));
            }
        }
        context.setReloadable(false);
        JaggeryApplication webapp = new JaggeryApplication(this, context, webappFile);
        webapp.setServletContextParameters(webContextParams);
        webapp.setState("Started");
        webApplicationsHolder.getStartedWebapps().put(filename, webapp);
        webApplicationsHolder.getFaultyWebapps().remove(filename);
        registerApplicationEventListeners(applicationEventListeners, context);
        log.info("Deployed webapp: " + webapp);
    } catch (Throwable e) {
        //catching a Throwable here to avoid web-apps crashing the server during startup
        StandardContext context = new StandardContext();
        context.setName(webappFile.getName());
        context.addParameter(WebappsConstants.FAULTY_WEBAPP, "true");
        JaggeryApplication webapp = new JaggeryApplication(this, context, webappFile);
        webapp.setProperty(WebappsConstants.WEBAPP_FILTER, JaggeryConstants.JAGGERY_WEBAPP_FILTER_PROP);
        String msg = "Error while deploying webapp: " + webapp;
        log.error(msg, e);
        webapp.setFaultReason(new Exception(msg, e));
        webApplicationsHolder.getFaultyWebapps().put(filename, webapp);
        webApplicationsHolder.getStartedWebapps().remove(filename);
        throw new CarbonException(msg, e);
    }
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) Context(org.apache.catalina.Context) StandardContext(org.apache.catalina.core.StandardContext) Tomcat(org.apache.catalina.startup.Tomcat) JaggeryDeployerManager(org.jaggeryjs.jaggery.core.manager.JaggeryDeployerManager) ArrayList(java.util.ArrayList) CarbonException(org.wso2.carbon.CarbonException) Host(org.apache.catalina.Host) CarbonTomcatClusterableSessionManager(org.wso2.carbon.core.session.CarbonTomcatClusterableSessionManager) Manager(org.apache.catalina.Manager) JaggeryDeployerManager(org.jaggeryjs.jaggery.core.manager.JaggeryDeployerManager) SecurityConstraint(org.apache.tomcat.util.descriptor.web.SecurityConstraint) CarbonException(org.wso2.carbon.CarbonException) JSONObject(org.json.simple.JSONObject) CarbonTomcatClusterableSessionManager(org.wso2.carbon.core.session.CarbonTomcatClusterableSessionManager) StandardContext(org.apache.catalina.core.StandardContext) JSONObject(org.json.simple.JSONObject) Map(java.util.Map) SecurityCollection(org.apache.tomcat.util.descriptor.web.SecurityCollection)

Example 3 with Event

use of org.wso2.eventing.Event in project siddhi by wso2.

the class IncrementalExecutor method dispatchEvents.

private void dispatchEvents(Map<String, BaseIncrementalValueStore> baseIncrementalValueGroupByStore) {
    int noOfEvents = baseIncrementalValueGroupByStore.size();
    if (noOfEvents > 0) {
        ComplexEventChunk<StreamEvent> eventChunk = new ComplexEventChunk<>(true);
        for (BaseIncrementalValueStore aBaseIncrementalValueStore : baseIncrementalValueGroupByStore.values()) {
            StreamEvent streamEvent = aBaseIncrementalValueStore.createStreamEvent();
            eventChunk.add(streamEvent);
        }
        LOG.debug("Event dispatched by " + this.duration + " incremental executor: " + eventChunk.toString());
        table.addEvents(eventChunk, noOfEvents);
        if (getNextExecutor() != null) {
            next.execute(eventChunk);
        }
    }
    baseIncrementalValueGroupByStore.clear();
}
Also used : ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 4 with Event

use of org.wso2.eventing.Event in project siddhi by wso2.

the class IncrementalExecutor method dispatchEvent.

private void dispatchEvent(long startTimeOfNewAggregates, BaseIncrementalValueStore aBaseIncrementalValueStore) {
    if (aBaseIncrementalValueStore.isProcessed()) {
        StreamEvent streamEvent = aBaseIncrementalValueStore.createStreamEvent();
        ComplexEventChunk<StreamEvent> eventChunk = new ComplexEventChunk<>(true);
        eventChunk.add(streamEvent);
        LOG.debug("Event dispatched by " + this.duration + " incremental executor: " + eventChunk.toString());
        table.addEvents(eventChunk, 1);
        if (getNextExecutor() != null) {
            next.execute(eventChunk);
        }
    }
    cleanBaseIncrementalValueStore(startTimeOfNewAggregates, aBaseIncrementalValueStore);
}
Also used : ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 5 with Event

use of org.wso2.eventing.Event in project siddhi by wso2.

the class SiddhiDebuggerClient method start.

/**
 * Start the {@link SiddhiDebuggerClient} and configure the breakpoints.
 *
 * @param siddhiApp the Siddhi query
 * @param input         the user input as a whole text
 */
public void start(final String siddhiApp, String input) {
    SiddhiManager siddhiManager = new SiddhiManager();
    info("Deploying the siddhi app");
    final SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    // Add callbacks for all the streams
    final Set<String> streamNames = SiddhiCompiler.parse(siddhiApp).getStreamDefinitionMap().keySet();
    for (String streamName : streamNames) {
        final String stream = streamName;
        siddhiAppRuntime.addCallback(stream, new StreamCallback() {

            @Override
            public void receive(Event[] events) {
                info("@Receive: Stream: " + stream + ", Event: " + Arrays.deepToString(events));
            }
        });
    }
    SiddhiDebugger siddhiDebugger = siddhiAppRuntime.debug();
    final InputFeeder inputFeeder = new InputFeeder(siddhiAppRuntime, input);
    System.out.println("Configure the breakpoints.\nYou can use the following commands:\n - " + ADD_BREAKPOINT + "<query name>:<IN/OUT>\n - " + REMOVE_BREAKPOINT + "<query name>:<IN/OUT>\n - " + START + "\n - " + STOP);
    printNextLine();
    final Scanner scanner = new Scanner(System.in, "UTF-8");
    while (scanner.hasNextLine()) {
        String userInput = scanner.nextLine().trim();
        String command = userInput.toLowerCase();
        if (command.startsWith(ADD_BREAKPOINT)) {
            if (!command.contains(QUERY_DELIMITER)) {
                error("Invalid add query. The query must be " + ADD_BREAKPOINT + "<query " + "name>:<IN/OUT>. Please try again");
                printNextLine();
                continue;
            }
            String[] components = userInput.substring(ADD_BREAKPOINT.length(), userInput.length()).split(QUERY_DELIMITER);
            String queryName = components[0];
            String terminal = components[1].toLowerCase();
            if (IN.equals(terminal)) {
                siddhiDebugger.acquireBreakPoint(queryName, SiddhiDebugger.QueryTerminal.IN);
                info("Added a breakpoint at the IN terminal of " + queryName);
                printNextLine();
            } else if (OUT.equals(terminal)) {
                siddhiDebugger.acquireBreakPoint(queryName, SiddhiDebugger.QueryTerminal.OUT);
                info("Added a breakpoint at the OUT terminal of " + queryName);
                printNextLine();
            } else {
                error("The terminal must be either IN or OUT but found: " + terminal.toUpperCase() + ". Please try again");
                printNextLine();
            }
        } else if (command.startsWith(REMOVE_BREAKPOINT)) {
            if (!command.contains(QUERY_DELIMITER)) {
                error("Invalid add query. The query must be " + REMOVE_BREAKPOINT + "<query " + "name>:<IN/OUT>. Please try again");
                printNextLine();
                continue;
            }
            String[] components = command.substring(ADD_BREAKPOINT.length(), command.length()).split(QUERY_DELIMITER);
            String queryName = components[0];
            String terminal = components[1];
            if (IN.equals(terminal)) {
                siddhiDebugger.releaseBreakPoint(queryName, SiddhiDebugger.QueryTerminal.IN);
                info("Removed the breakpoint at the IN terminal of " + queryName);
                printNextLine();
            } else if (OUT.equals(terminal)) {
                siddhiDebugger.releaseBreakPoint(queryName, SiddhiDebugger.QueryTerminal.OUT);
                info("Removed the breakpoint at the OUT terminal of " + queryName);
                printNextLine();
            } else {
                error("The terminal must be either IN or OUT but found: " + terminal.toUpperCase());
                printNextLine();
            }
        } else if (STOP.equals(command)) {
            inputFeeder.stop();
            siddhiAppRuntime.shutdown();
            break;
        } else if (START.equals(command)) {
            inputFeeder.start();
            info("Siddhi Debugger starts sending input to Siddhi");
            System.out.println("You can use the following commands:\n - " + NEXT + "\n - " + PLAY + "\n - " + STATE + ":<query name>\n - " + STOP);
            break;
        } else {
            error("Invalid command: " + command);
            printNextLine();
        }
    }
    siddhiDebugger.setDebuggerCallback(new SiddhiDebuggerCallback() {

        @Override
        public void debugEvent(ComplexEvent event, String queryName, SiddhiDebugger.QueryTerminal queryTerminal, SiddhiDebugger debugger) {
            info("@Debug: Query: " + queryName + ", Terminal: " + queryTerminal + ", Event: " + event);
            printNextLine();
            while (scanner.hasNextLine()) {
                String command = scanner.nextLine().trim().toLowerCase();
                if (STOP.equals(command)) {
                    debugger.releaseAllBreakPoints();
                    debugger.play();
                    inputFeeder.stop();
                    siddhiAppRuntime.shutdown();
                    break;
                } else if (NEXT.equals(command)) {
                    debugger.next();
                    break;
                } else if (PLAY.equals(command)) {
                    debugger.play();
                    break;
                } else if (command.startsWith(STATE)) {
                    if (!command.contains(QUERY_DELIMITER)) {
                        error("Invalid get state request. The query must be " + STATE + ":<query " + "name>. Please try again");
                        printNextLine();
                        continue;
                    }
                    String[] components = command.split(QUERY_DELIMITER);
                    String requestQueryName = components[1];
                    Map<String, Object> state = debugger.getQueryState(requestQueryName.trim());
                    System.out.println("Query '" + requestQueryName + "' state : ");
                    for (Map.Entry<String, Object> entry : state.entrySet()) {
                        System.out.println("    '" + entry.getKey() + "' : " + entry.getValue());
                    }
                    printNextLine();
                    continue;
                } else {
                    error("Invalid command: " + command);
                    printNextLine();
                }
            }
        }
    });
    inputFeeder.join();
    if (inputFeeder.isRunning()) {
        info("Input feeder has sopped sending all inputs. If you want to stop the execution, use " + "the STOP command");
        printNextLine();
        while (scanner.hasNextLine()) {
            String command = scanner.nextLine().trim().toLowerCase();
            if (STOP.equals(command)) {
                inputFeeder.stop();
                siddhiAppRuntime.shutdown();
                break;
            } else {
                error("Invalid command: " + command);
                printNextLine();
            }
        }
    }
    scanner.close();
    info("Siddhi Debugger is stopped successfully");
}
Also used : Scanner(java.util.Scanner) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) Event(org.wso2.siddhi.core.event.Event) Map(java.util.Map) SiddhiManager(org.wso2.siddhi.core.SiddhiManager)

Aggregations

Test (org.testng.annotations.Test)1150 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)1146 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)1145 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)1119 Event (org.wso2.siddhi.core.event.Event)855 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)587 TestUtil (org.wso2.siddhi.core.TestUtil)300 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)218 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)86 SiddhiApp (org.wso2.siddhi.query.api.SiddhiApp)79 Query (org.wso2.siddhi.query.api.execution.query.Query)79 ArrayList (java.util.ArrayList)68 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)63 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)58 ComplexEventChunk (org.wso2.siddhi.core.event.ComplexEventChunk)38 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)35 GroupedComplexEvent (org.wso2.siddhi.core.event.GroupedComplexEvent)16 InMemoryBroker (org.wso2.siddhi.core.util.transport.InMemoryBroker)16 HashMap (java.util.HashMap)14 CannotRestoreSiddhiAppStateException (org.wso2.siddhi.core.exception.CannotRestoreSiddhiAppStateException)13