Program: 112672
Project: 112672
Buggy source:
/** 
 * - Launch the main process: spark context, kafkaInputDstream and siddhi CEP engine - Filter the incoming messages (kafka) by key in order to separate the different commands - Parse the request contained in the payload - execute related command for each request
 * @param sparkMaster
 * @param zkCluster
 * @param kafkaCluster
 * @param topics
 * @throws Exception
 */
private static void launchStratioStreamingEngine() throws Exception {
  ConfigurationContext cc=new ConfigurationContext();
  String topics=BUS.TOPICS;
  ZKUtils.getZKUtils(cc.getZookeeperHostsQuorum()).createEphemeralZNode(STREAMING.ZK_BASE_PATH + "String_Node_Str" + "String_Node_Str",String.valueOf(System.currentTimeMillis()).getBytes());
  streamingBaseContext=new JavaStreamingContext(cc.getSparkHost(),StreamingEngine.class.getName(),new Duration(cc.getStreamingBatchTime()));
  streamingBaseContext.sparkContext().getConf().setJars(JavaStreamingContext.jarOfClass(StreamingEngine.class));
  KeepPayloadFromMessageFunction keepPayloadFromMessageFunction=new KeepPayloadFromMessageFunction();
  CreateStreamFunction createStreamFunction=new CreateStreamFunction(getSiddhiManager(),cc.getZookeeperHostsQuorum());
  AlterStreamFunction alterStreamFunction=new AlterStreamFunction(getSiddhiManager(),cc.getZookeeperHostsQuorum());
  InsertIntoStreamFunction insertIntoStreamFunction=new InsertIntoStreamFunction(getSiddhiManager(),cc.getZookeeperHostsQuorum());
  AddQueryToStreamFunction addQueryToStreamFunction=new AddQueryToStreamFunction(getSiddhiManager(),cc.getZookeeperHostsQuorum());
  ListenStreamFunction listenStreamFunction=new ListenStreamFunction(getSiddhiManager(),cc.getZookeeperHostsQuorum(),cc.getKafkaHostsQuorum());
  ListStreamsFunction listStreamsFunction=new ListStreamsFunction(getSiddhiManager(),cc.getZookeeperHostsQuorum());
  SaveToCassandraStreamFunction saveToCassandraStreamFunction=new SaveToCassandraStreamFunction(getSiddhiManager(),cc.getZookeeperHostsQuorum(),cc.getCassandraHostsQuorum());
  Map<String,Integer> topicMap=new HashMap<String,Integer>();
  String[] topic_list=topics.split("String_Node_Str");
  HostAndPort kafkaHostAndPort=HostAndPort.fromString(cc.getKafkaHosts().get(0));
  TopicService topicService=new KafkaTopicService(cc.getZookeeperHostsQuorum(),kafkaHostAndPort.getHostText(),kafkaHostAndPort.getPort(),cc.getKafkaConnectionTimeout(),cc.getKafkaSessionTimeout());
  for (  String topic : topic_list) {
    topicService.createTopicIfNotExist(topic,cc.getKafkaReplicationFactor(),cc.getKafkaPartitions());
    Integer partitions=topicService.getNumPartitionsForTopic(topic);
    if (partitions == 0) {
      partitions=cc.getKafkaPartitions();
    }
    topicMap.put(topic,partitions);
  }
  JavaPairDStream<String,String> messages=KafkaUtils.createStream(streamingBaseContext,cc.getZookeeperHostsQuorum(),BUS.STREAMING_GROUP_ID,topicMap);
  messages.cache();
  if (cc.getElasticSearchHost() != null) {
    IndexStreamFunction indexStreamFunction=new IndexStreamFunction(getSiddhiManager(),cc.getZookeeperHostsQuorum(),cc.getElasticSearchHost(),cc.getElasticSearchPort());
    JavaDStream<StratioStreamingMessage> streamToIndexer_requests=messages.filter(new FilterMessagesByOperationFunction(STREAM_OPERATIONS.ACTION.INDEX)).map(keepPayloadFromMessageFunction);
    JavaDStream<StratioStreamingMessage> stopStreamToIndexer_requests=messages.filter(new FilterMessagesByOperationFunction(STREAM_OPERATIONS.ACTION.STOP_INDEX)).map(keepPayloadFromMessageFunction);
    streamToIndexer_requests.foreachRDD(indexStreamFunction);
    stopStreamToIndexer_requests.foreachRDD(indexStreamFunction);
  }
 else {
    logger.warn("String_Node_Str");
  }
  if (cc.getMongoHost() != null) {
    SaveToMongoStreamFunction saveToMongoStreamFunction=new SaveToMongoStreamFunction(getSiddhiManager(),cc.getZookeeperHostsQuorum(),cc.getMongoHost(),cc.getMongoPort(),cc.getMongoUsername(),cc.getMongoPassword());
    JavaDStream<StratioStreamingMessage> saveToMongo_requests=messages.filter(new FilterMessagesByOperationFunction(STREAM_OPERATIONS.ACTION.SAVETO_MONGO)).map(keepPayloadFromMessageFunction);
    JavaDStream<StratioStreamingMessage> stop_saveToMongo_requests=messages.filter(new FilterMessagesByOperationFunction(STREAM_OPERATIONS.ACTION.STOP_SAVETO_MONGO)).map(keepPayloadFromMessageFunction);
    saveToMongo_requests.foreachRDD(saveToMongoStreamFunction);
    stop_saveToMongo_requests.foreach(saveToMongoStreamFunction);
  }
 else {
    logger.warn("String_Node_Str");
  }
  JavaDStream<StratioStreamingMessage> create_requests=messages.filter(new FilterMessagesByOperationFunction(STREAM_OPERATIONS.DEFINITION.CREATE)).map(keepPayloadFromMessageFunction);
  JavaDStream<StratioStreamingMessage> alter_requests=messages.filter(new FilterMessagesByOperationFunction(STREAM_OPERATIONS.DEFINITION.ALTER)).map(keepPayloadFromMessageFunction);
  JavaDStream<StratioStreamingMessage> insert_requests=messages.filter(new FilterMessagesByOperationFunction(STREAM_OPERATIONS.MANIPULATION.INSERT)).map(keepPayloadFromMessageFunction);
  JavaDStream<StratioStreamingMessage> add_query_requests=messages.filter(new FilterMessagesByOperationFunction(STREAM_OPERATIONS.DEFINITION.ADD_QUERY)).map(keepPayloadFromMessageFunction);
  JavaDStream<StratioStreamingMessage> remove_query_requests=messages.filter(new FilterMessagesByOperationFunction(STREAM_OPERATIONS.DEFINITION.REMOVE_QUERY)).map(keepPayloadFromMessageFunction);
  JavaDStream<StratioStreamingMessage> listen_requests=messages.filter(new FilterMessagesByOperationFunction(STREAM_OPERATIONS.ACTION.LISTEN)).map(keepPayloadFromMessageFunction);
  JavaDStream<StratioStreamingMessage> stop_listen_requests=messages.filter(new FilterMessagesByOperationFunction(STREAM_OPERATIONS.ACTION.STOP_LISTEN)).map(keepPayloadFromMessageFunction);
  JavaDStream<StratioStreamingMessage> saveToCassandra_requests=messages.filter(new FilterMessagesByOperationFunction(STREAM_OPERATIONS.ACTION.SAVETO_CASSANDRA)).map(keepPayloadFromMessageFunction);
  JavaDStream<StratioStreamingMessage> stop_saveToCassandra_requests=messages.filter(new FilterMessagesByOperationFunction(STREAM_OPERATIONS.ACTION.STOP_SAVETO_CASSANDRA)).map(keepPayloadFromMessageFunction);
  JavaDStream<StratioStreamingMessage> list_requests=messages.filter(new FilterMessagesByOperationFunction(STREAM_OPERATIONS.MANIPULATION.LIST)).map(keepPayloadFromMessageFunction);
  JavaDStream<StratioStreamingMessage> drop_requests=messages.filter(new FilterMessagesByOperationFunction(STREAM_OPERATIONS.DEFINITION.DROP)).map(keepPayloadFromMessageFunction);
  create_requests.foreachRDD(createStreamFunction);
  alter_requests.foreachRDD(alterStreamFunction);
  insert_requests.foreachRDD(insertIntoStreamFunction);
  add_query_requests.foreachRDD(addQueryToStreamFunction);
  remove_query_requests.foreachRDD(addQueryToStreamFunction);
  listen_requests.foreachRDD(listenStreamFunction);
  stop_listen_requests.foreachRDD(listenStreamFunction);
  saveToCassandra_requests.foreachRDD(saveToCassandraStreamFunction);
  stop_saveToCassandra_requests.foreach(saveToCassandraStreamFunction);
  list_requests.foreachRDD(listStreamsFunction);
  drop_requests.foreachRDD(createStreamFunction);
  if (cc.isAuditEnabled() || cc.isStatsEnabled()) {
    JavaDStream<StratioStreamingMessage> allRequests=create_requests.union(alter_requests).union(insert_requests).union(add_query_requests).union(remove_query_requests).union(listen_requests).union(stop_listen_requests).union(saveToCassandra_requests).union(list_requests).union(drop_requests);
    if (cc.isAuditEnabled()) {
      SaveRequestsToAuditLogFunction saveRequestsToAuditLogFunction=new SaveRequestsToAuditLogFunction(getSiddhiManager(),cc.getZookeeperHostsQuorum(),cc.getKafkaHostsQuorum(),cc.getCassandraHostsQuorum());
      allRequests.window(new Duration(2000),new Duration(6000)).foreachRDD(saveRequestsToAuditLogFunction);
    }
    if (cc.isStatsEnabled()) {
      CollectRequestForStatsFunction collectRequestForStatsFunction=new CollectRequestForStatsFunction(getSiddhiManager(),cc.getZookeeperHostsQuorum(),cc.getKafkaHostsQuorum());
      allRequests.window(new Duration(2000),new Duration(6000)).foreachRDD(collectRequestForStatsFunction);
    }
  }
  StreamPersistence.saveStreamingEngineStatus(getSiddhiManager());
  if (cc.isPrintStreams()) {
    messages.count().foreach(new Function<JavaRDD<Long>,Void>(){
      private static final long serialVersionUID=-2371501158355376325L;
      @Override public Void call(      JavaRDD<Long> arg0) throws Exception {
        StringBuffer sb=new StringBuffer();
        sb.append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append(siddhiManager.getStreamDefinitions().size());
        sb.append("String_Node_Str");
        sb.append(getSiddhiManager().getSiddhiContext().getHazelcastInstance().getMap(STREAMING.STREAM_STATUS_MAP).size());
        sb.append("String_Node_Str");
        for (        StreamDefinition streamMetaData : getSiddhiManager().getStreamDefinitions()) {
          StringBuffer streamDefinition=new StringBuffer();
          streamDefinition.append(streamMetaData.getStreamId());
          for (          Attribute column : streamMetaData.getAttributeList()) {
            streamDefinition.append("String_Node_Str" + column.getName() + "String_Node_Str"+ column.getType());
          }
          if (StreamSharedStatus.getStreamStatus(streamMetaData.getStreamId(),getSiddhiManager()) != null) {
            HashMap<String,QueryDTO> attachedQueries=StreamSharedStatus.getStreamStatus(streamMetaData.getStreamId(),getSiddhiManager()).getAddedQueries();
            streamDefinition.append("String_Node_Str" + attachedQueries.size() + "String_Node_Str");
            for (            String queryId : attachedQueries.keySet()) {
              streamDefinition.append(queryId + "String_Node_Str");
            }
            streamDefinition.append("String_Node_Str" + StreamSharedStatus.getStreamStatus(streamMetaData.getStreamId(),getSiddhiManager()).isUserDefined() + "String_Node_Str");
            streamDefinition.append("String_Node_Str" + StreamSharedStatus.getStreamStatus(streamMetaData.getStreamId(),getSiddhiManager()).isActionEnabled(StreamAction.LISTEN) + "String_Node_Str");
          }
          sb.append("String_Node_Str".concat(streamDefinition.toString()).concat("String_Node_Str"));
        }
        sb.append("String_Node_Str");
        logger.info(sb.toString());
        StreamPersistence.saveStreamingEngineStatus(getSiddhiManager());
        return null;
      }
    }
);
  }
  streamingBaseContext.start();
  logger.info("String_Node_Str",new Date());
  streamingBaseContext.awaitTermination();
}

Fixed version (ground truth):
/** 
 * - Launch the main process: spark context, kafkaInputDstream and siddhi CEP engine - Filter the incoming messages (kafka) by key in order to separate the different commands - Parse the request contained in the payload - execute related command for each request
 * @param sparkMaster
 * @param zkCluster
 * @param kafkaCluster
 * @param topics
 * @throws Exception
 */
private static void launchStratioStreamingEngine() throws Exception {
  ConfigurationContext cc=new ConfigurationContext();
  String topics=BUS.TOPICS;
  ZKUtils.getZKUtils(cc.getZookeeperHostsQuorum()).createEphemeralZNode(STREAMING.ZK_BASE_PATH + "String_Node_Str" + "String_Node_Str",String.valueOf(System.currentTimeMillis()).getBytes());
  streamingBaseContext=new JavaStreamingContext(cc.getSparkHost(),StreamingEngine.class.getName(),new Duration(cc.getStreamingBatchTime()));
  streamingBaseContext.sparkContext().getConf().setJars(JavaStreamingContext.jarOfClass(StreamingEngine.class));
  KeepPayloadFromMessageFunction keepPayloadFromMessageFunction=new KeepPayloadFromMessageFunction();
  CreateStreamFunction createStreamFunction=new CreateStreamFunction(getSiddhiManager(),cc.getZookeeperHostsQuorum());
  AlterStreamFunction alterStreamFunction=new AlterStreamFunction(getSiddhiManager(),cc.getZookeeperHostsQuorum());
  InsertIntoStreamFunction insertIntoStreamFunction=new InsertIntoStreamFunction(getSiddhiManager(),cc.getZookeeperHostsQuorum());
  AddQueryToStreamFunction addQueryToStreamFunction=new AddQueryToStreamFunction(getSiddhiManager(),cc.getZookeeperHostsQuorum());
  ListenStreamFunction listenStreamFunction=new ListenStreamFunction(getSiddhiManager(),cc.getZookeeperHostsQuorum(),cc.getKafkaHostsQuorum());
  ListStreamsFunction listStreamsFunction=new ListStreamsFunction(getSiddhiManager(),cc.getZookeeperHostsQuorum());
  SaveToCassandraStreamFunction saveToCassandraStreamFunction=new SaveToCassandraStreamFunction(getSiddhiManager(),cc.getZookeeperHostsQuorum(),cc.getCassandraHostsQuorum());
  Map<String,Integer> topicMap=new HashMap<String,Integer>();
  String[] topicList=topics.split("String_Node_Str");
  HostAndPort kafkaHostAndPort=HostAndPort.fromString(cc.getKafkaHosts().get(0));
  TopicService topicService=new KafkaTopicService(cc.getZookeeperHostsQuorum(),kafkaHostAndPort.getHostText(),kafkaHostAndPort.getPort(),cc.getKafkaConnectionTimeout(),cc.getKafkaSessionTimeout());
  for (  String topic : topicList) {
    topicService.createTopicIfNotExist(topic,cc.getKafkaReplicationFactor(),cc.getKafkaPartitions());
    Integer partitions=topicService.getNumPartitionsForTopic(topic);
    if (partitions == 0) {
      partitions=cc.getKafkaPartitions();
    }
    topicMap.put(topic,partitions);
  }
  JavaPairDStream<String,String> messages=KafkaUtils.createStream(streamingBaseContext,cc.getZookeeperHostsQuorum(),BUS.STREAMING_GROUP_ID,topicMap);
  messages.cache();
  if (cc.getElasticSearchHost() != null) {
    IndexStreamFunction indexStreamFunction=new IndexStreamFunction(getSiddhiManager(),cc.getZookeeperHostsQuorum(),cc.getElasticSearchHost(),cc.getElasticSearchPort());
    JavaDStream<StratioStreamingMessage> streamToIndexerRequests=messages.filter(new FilterMessagesByOperationFunction(STREAM_OPERATIONS.ACTION.INDEX)).map(keepPayloadFromMessageFunction);
    JavaDStream<StratioStreamingMessage> stopStreamToIndexerRequests=messages.filter(new FilterMessagesByOperationFunction(STREAM_OPERATIONS.ACTION.STOP_INDEX)).map(keepPayloadFromMessageFunction);
    streamToIndexerRequests.foreachRDD(indexStreamFunction);
    stopStreamToIndexerRequests.foreachRDD(indexStreamFunction);
  }
 else {
    logger.warn("String_Node_Str");
  }
  if (cc.getMongoHost() != null) {
    SaveToMongoStreamFunction saveToMongoStreamFunction=new SaveToMongoStreamFunction(getSiddhiManager(),cc.getZookeeperHostsQuorum(),cc.getMongoHost(),cc.getMongoPort(),cc.getMongoUsername(),cc.getMongoPassword());
    JavaDStream<StratioStreamingMessage> saveToMongoRequests=messages.filter(new FilterMessagesByOperationFunction(STREAM_OPERATIONS.ACTION.SAVETO_MONGO)).map(keepPayloadFromMessageFunction);
    JavaDStream<StratioStreamingMessage> stopSaveToMongoRequests=messages.filter(new FilterMessagesByOperationFunction(STREAM_OPERATIONS.ACTION.STOP_SAVETO_MONGO)).map(keepPayloadFromMessageFunction);
    saveToMongoRequests.foreachRDD(saveToMongoStreamFunction);
    stopSaveToMongoRequests.foreach(saveToMongoStreamFunction);
  }
 else {
    logger.warn("String_Node_Str");
  }
  JavaDStream<StratioStreamingMessage> createRequests=messages.filter(new FilterMessagesByOperationFunction(STREAM_OPERATIONS.DEFINITION.CREATE)).map(keepPayloadFromMessageFunction);
  JavaDStream<StratioStreamingMessage> alterRequests=messages.filter(new FilterMessagesByOperationFunction(STREAM_OPERATIONS.DEFINITION.ALTER)).map(keepPayloadFromMessageFunction);
  JavaDStream<StratioStreamingMessage> insertRequests=messages.filter(new FilterMessagesByOperationFunction(STREAM_OPERATIONS.MANIPULATION.INSERT)).map(keepPayloadFromMessageFunction);
  JavaDStream<StratioStreamingMessage> addQueryRequests=messages.filter(new FilterMessagesByOperationFunction(STREAM_OPERATIONS.DEFINITION.ADD_QUERY)).map(keepPayloadFromMessageFunction);
  JavaDStream<StratioStreamingMessage> removeQueryRequests=messages.filter(new FilterMessagesByOperationFunction(STREAM_OPERATIONS.DEFINITION.REMOVE_QUERY)).map(keepPayloadFromMessageFunction);
  JavaDStream<StratioStreamingMessage> listenRequests=messages.filter(new FilterMessagesByOperationFunction(STREAM_OPERATIONS.ACTION.LISTEN)).map(keepPayloadFromMessageFunction);
  JavaDStream<StratioStreamingMessage> stopListenRequests=messages.filter(new FilterMessagesByOperationFunction(STREAM_OPERATIONS.ACTION.STOP_LISTEN)).map(keepPayloadFromMessageFunction);
  JavaDStream<StratioStreamingMessage> saveToCassandraRequests=messages.filter(new FilterMessagesByOperationFunction(STREAM_OPERATIONS.ACTION.SAVETO_CASSANDRA)).map(keepPayloadFromMessageFunction);
  JavaDStream<StratioStreamingMessage> stopSaveToCassandraRequests=messages.filter(new FilterMessagesByOperationFunction(STREAM_OPERATIONS.ACTION.STOP_SAVETO_CASSANDRA)).map(keepPayloadFromMessageFunction);
  JavaDStream<StratioStreamingMessage> listRequests=messages.filter(new FilterMessagesByOperationFunction(STREAM_OPERATIONS.MANIPULATION.LIST)).map(keepPayloadFromMessageFunction);
  JavaDStream<StratioStreamingMessage> dropRequests=messages.filter(new FilterMessagesByOperationFunction(STREAM_OPERATIONS.DEFINITION.DROP)).map(keepPayloadFromMessageFunction);
  createRequests.foreachRDD(createStreamFunction);
  alterRequests.foreachRDD(alterStreamFunction);
  insertRequests.foreachRDD(insertIntoStreamFunction);
  addQueryRequests.foreachRDD(addQueryToStreamFunction);
  removeQueryRequests.foreachRDD(addQueryToStreamFunction);
  listenRequests.foreachRDD(listenStreamFunction);
  stopListenRequests.foreachRDD(listenStreamFunction);
  saveToCassandraRequests.foreachRDD(saveToCassandraStreamFunction);
  stopSaveToCassandraRequests.foreach(saveToCassandraStreamFunction);
  listRequests.foreachRDD(listStreamsFunction);
  dropRequests.foreachRDD(createStreamFunction);
  if (cc.isAuditEnabled() || cc.isStatsEnabled()) {
    JavaDStream<StratioStreamingMessage> allRequests=createRequests.union(alterRequests).union(insertRequests).union(addQueryRequests).union(removeQueryRequests).union(listenRequests).union(stopListenRequests).union(saveToCassandraRequests).union(listRequests).union(dropRequests);
    if (cc.isAuditEnabled()) {
      SaveRequestsToAuditLogFunction saveRequestsToAuditLogFunction=new SaveRequestsToAuditLogFunction(getSiddhiManager(),cc.getZookeeperHostsQuorum(),cc.getKafkaHostsQuorum(),cc.getCassandraHostsQuorum());
      allRequests.window(new Duration(2000),new Duration(6000)).foreachRDD(saveRequestsToAuditLogFunction);
    }
    if (cc.isStatsEnabled()) {
      CollectRequestForStatsFunction collectRequestForStatsFunction=new CollectRequestForStatsFunction(getSiddhiManager(),cc.getZookeeperHostsQuorum(),cc.getKafkaHostsQuorum());
      allRequests.window(new Duration(2000),new Duration(6000)).foreachRDD(collectRequestForStatsFunction);
    }
  }
  StreamPersistence.saveStreamingEngineStatus(getSiddhiManager());
  if (cc.isPrintStreams()) {
    messages.count().foreach(new Function<JavaRDD<Long>,Void>(){
      private static final long serialVersionUID=-2371501158355376325L;
      @Override public Void call(      JavaRDD<Long> arg0) throws Exception {
        StringBuffer sb=new StringBuffer();
        sb.append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append(siddhiManager.getStreamDefinitions().size());
        sb.append("String_Node_Str");
        sb.append(getSiddhiManager().getSiddhiContext().getHazelcastInstance().getMap(STREAMING.STREAM_STATUS_MAP).size());
        sb.append("String_Node_Str");
        for (        StreamDefinition streamMetaData : getSiddhiManager().getStreamDefinitions()) {
          StringBuffer streamDefinition=new StringBuffer();
          streamDefinition.append(streamMetaData.getStreamId());
          for (          Attribute column : streamMetaData.getAttributeList()) {
            streamDefinition.append("String_Node_Str" + column.getName() + "String_Node_Str"+ column.getType());
          }
          if (StreamSharedStatus.getStreamStatus(streamMetaData.getStreamId(),getSiddhiManager()) != null) {
            HashMap<String,QueryDTO> attachedQueries=StreamSharedStatus.getStreamStatus(streamMetaData.getStreamId(),getSiddhiManager()).getAddedQueries();
            streamDefinition.append("String_Node_Str" + attachedQueries.size() + "String_Node_Str");
            for (            String queryId : attachedQueries.keySet()) {
              streamDefinition.append(queryId + "String_Node_Str");
            }
            streamDefinition.append("String_Node_Str" + StreamSharedStatus.getStreamStatus(streamMetaData.getStreamId(),getSiddhiManager()).isUserDefined() + "String_Node_Str");
            streamDefinition.append("String_Node_Str" + StreamSharedStatus.getStreamStatus(streamMetaData.getStreamId(),getSiddhiManager()).isActionEnabled(StreamAction.LISTEN) + "String_Node_Str");
          }
          sb.append("String_Node_Str".concat(streamDefinition.toString()).concat("String_Node_Str"));
        }
        sb.append("String_Node_Str");
        logger.info(sb.toString());
        StreamPersistence.saveStreamingEngineStatus(getSiddhiManager());
        return null;
      }
    }
);
  }
  streamingBaseContext.start();
  logger.info("String_Node_Str",new Date());
  streamingBaseContext.awaitTermination();
}