private SiddhiManager createMockSiddhiManager( String[] inputStreamDefinitions, String executionPlan) throws SiddhiParserException { SiddhiConfiguration siddhiConfig = new SiddhiConfiguration(); siddhiConfig.setSiddhiExtensions(SiddhiExtensionLoader.loadSiddhiExtensions()); SiddhiManager siddhiManager = new SiddhiManager(siddhiConfig); try { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); if (tenantId > -1) { DataSourceManager.getInstance().initTenant(tenantId); } List<CarbonDataSource> dataSources = EventProcessorValueHolder.getDataSourceService().getAllDataSources(); for (CarbonDataSource cds : dataSources) { try { if (cds.getDSObject() instanceof DataSource) { siddhiManager .getSiddhiContext() .addDataSource(cds.getDSMInfo().getName(), (DataSource) cds.getDSObject()); } } catch (Exception e) { log.error("Unable to add the datasource" + cds.getDSMInfo().getName(), e); } } } catch (DataSourceException e) { log.error("Unable to access the datasource service", e); } for (String streamDefinition : inputStreamDefinitions) { if (streamDefinition.trim().length() > 0) { siddhiManager.defineStream(streamDefinition); } } siddhiManager.addExecutionPlan(executionPlan); return siddhiManager; }
public static void loadDataSourceConfiguration(SiddhiManager siddhiManager) { try { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); if (tenantId > -1) { DataSourceManager.getInstance().initTenant(tenantId); } List<CarbonDataSource> dataSources = EventProcessorValueHolder.getDataSourceService().getAllDataSources(); for (CarbonDataSource cds : dataSources) { try { if (cds.getDSObject() instanceof DataSource) { siddhiManager.setDataSource(cds.getDSMInfo().getName(), (DataSource) cds.getDSObject()); } } catch (Exception e) { log.error("Unable to add the datasource" + cds.getDSMInfo().getName(), e); } } } catch (DataSourceException e) { log.error("Unable to populate the data sources in Siddhi engine.", e); } }
private SiddhiManager getSiddhiManagerFor( ExecutionPlanConfiguration executionPlanConfiguration, SiddhiConfiguration siddhiConfig, Map<String, InputHandler> inputHandlerMap) throws ExecutionPlanConfigurationException { SiddhiManager siddhiManager = new SiddhiManager(siddhiConfig); try { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); if (tenantId > -1) { DataSourceManager.getInstance().initTenant(tenantId); } List<CarbonDataSource> dataSources = EventProcessorValueHolder.getDataSourceService().getAllDataSources(); for (CarbonDataSource cds : dataSources) { try { if (cds.getDSObject() instanceof DataSource) { siddhiManager .getSiddhiContext() .addDataSource(cds.getDSMInfo().getName(), (DataSource) cds.getDSObject()); } } catch (Exception e) { log.error("Unable to add the datasource" + cds.getDSMInfo().getName(), e); } } } catch (DataSourceException e) { log.error("Unable to populate the data sources in Siddhi engine.", e); } int persistenceTimeInterval = 0; try { persistenceTimeInterval = Integer.parseInt( executionPlanConfiguration .getSiddhiConfigurationProperties() .get(EventProcessorConstants.SIDDHI_SNAPSHOT_INTERVAL)); } catch (NumberFormatException e) { log.error("Unable to parse snapshot time interval.", e); } if (persistenceTimeInterval > 0) { if (null == EventProcessorValueHolder.getPersistenceStore()) { if (EventProcessorValueHolder.getClusterInformation() == null) { try { String adminPassword = EventProcessorValueHolder.getUserRealm().getRealmConfiguration().getAdminPassword(); String adminUserName = EventProcessorValueHolder.getUserRealm().getRealmConfiguration().getAdminUserName(); ClusterInformation clusterInformation = new ClusterInformation(adminUserName, adminPassword); clusterInformation.setClusterName(CassandraPersistenceStore.CLUSTER_NAME); EventProcessorValueHolder.setClusterInformation(clusterInformation); } catch (UserStoreException e) { log.error("Unable to get realm configuration.", e); } } if (CassandraConnectionValidator.getInstance() .checkCassandraConnection( EventProcessorValueHolder.getClusterInformation().getUsername(), EventProcessorValueHolder.getClusterInformation().getPassword())) { Cluster cluster = EventProcessorValueHolder.getDataAccessService() .getCluster(EventProcessorValueHolder.getClusterInformation()); CassandraPersistenceStore casandraPersistenceStore = new CassandraPersistenceStore(cluster); EventProcessorValueHolder.setPersistenceStore(casandraPersistenceStore); } else { throw new ExecutionPlanConfigurationException( "Cannot connect to Cassandra. To run with embedded Cassandra enabled, start the server with command: ./wso2server.sh -Ddisable.cassandra.server.startup=false"); } } siddhiManager.setPersistStore(EventProcessorValueHolder.getPersistenceStore()); } return siddhiManager; }