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);
   }
 }
 public Connection getConnection() {
   Connection conn = null;
   /// if (conn == null) {
   try {
     CarbonDataSource carbonDataSource =
         DataSourceManager.getInstance()
             .getDataSourceRepository()
             .getDataSource("SOCIAL_CASSANDRA_DB");
     DataSource dataSource = (DataSource) carbonDataSource.getDSObject();
     conn = dataSource.getConnection();
   } catch (SQLException e) {
     LOG.error("Can't create JDBC connection to Cassandra", e);
   } catch (DataSourceException e) {
     LOG.error("Can't create create data source for Cassandra", e);
   }
   // }
   return conn;
 }
Ejemplo n.º 4
0
 private static Connection createConnection(String dataSourceId)
     throws SQLException, DataServiceFault {
   DataSourceService dataSourceService = DataServicesDSComponent.getDataSourceService();
   CarbonDataSource cds;
   try {
     cds = dataSourceService.getDataSource(dataSourceId);
   } catch (DataSourceException e) {
     throw new DataServiceFault(e, "Error in retrieving data source: " + e.getMessage());
   }
   if (cds == null) {
     throw new DataServiceFault("DataSource '" + dataSourceId + "' is not available.");
   }
   Object ds = cds.getDSObject();
   if (!(ds instanceof DataSource)) {
     throw new DataServiceFault("DataSource '" + dataSourceId + "' is not an RDBMS data source.");
   }
   return ((DataSource) ds).getConnection();
 }
  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;
  }