Example #1
0
  @CliCommand(value = "columns", help = "list all streams querys into engine")
  public String listQuerys(
      @CliOption(
              key = {"stream"},
              help = "The stream name",
              mandatory = true,
              optionContext = "stream")
          final String streamName) {
    // XXX create new renderer to render this table
    try {

      List<ColumnNameTypeValue> columnsValues = ssaw.api().columnsFromStream(streamName);

      List<String> columns = Arrays.asList("Column", "Type");
      List<Map<String, Object>> data = new ArrayList<>();

      for (ColumnNameTypeValue columnValue : columnsValues) {
        Map<String, Object> row = new HashMap<>();
        row.put("Column", columnValue.getColumn());
        row.put("Type", columnValue.getType());

        data.add(row);
      }

      return TableRenderer.renderMapDataAsTable(data, columns);
    } catch (StratioStreamingException e) {
      throw new StreamingShellException(e);
    }
  }
  public int enlargeStream(
      String streamName, List<ColumnNameTypeValue> columns, Boolean raiseException)
      throws ServiceException {
    int addedColumns = 0;
    StreamDefinition streamMetaData = siddhiManager.getStreamDefinition(streamName);
    for (ColumnNameTypeValue columnNameTypeValue : columns) {
      if (!SiddhiUtils.columnAlreadyExistsInStream(
          columnNameTypeValue.getColumn(), streamMetaData)) {
        addedColumns++;
        // JPFM -- Updating the columns in streamStatusDao
        streamStatusDao.addColumn(streamName, columnNameTypeValue);
        streamMetaData.attribute(
            columnNameTypeValue.getColumn(), getSiddhiType(columnNameTypeValue.getType()));
      } else {
        if (raiseException) {
          throw new ServiceException(
              String.format(
                  "Alter stream error, Column %s already " + "exists.",
                  columnNameTypeValue.getColumn()));
        }
      }
    }

    return addedColumns;
  }
 public void createInternalStream(String streamName, List<ColumnNameTypeValue> columns) {
   StreamDefinition newStream = QueryFactory.createStreamDefinition().name(streamName);
   for (ColumnNameTypeValue column : columns) {
     newStream.attribute(column.getColumn(), getSiddhiType(column.getType()));
   }
   siddhiManager.defineStream(newStream);
   streamStatusDao.createInferredStream(streamName, columns);
 }
  @Override
  public void process(Iterable<StratioStreamingMessage> messages) throws Exception {

    Integer partitionSize = maxBatchSize;

    if (partitionSize <= 0) {
      partitionSize = Iterables.size(messages);
    }

    Iterable<List<StratioStreamingMessage>> partitionIterables =
        Iterables.partition(messages, partitionSize);

    try {

      for (List<StratioStreamingMessage> messageList : partitionIterables) {

        Map<String, Collection<SolrInputDocument>> elemntsToInsert =
            new HashMap<String, Collection<SolrInputDocument>>();
        int count = 0;
        for (StratioStreamingMessage stratioStreamingMessage : messageList) {
          count += 1;
          SolrInputDocument document = new SolrInputDocument();
          document.addField("stratio_decision_id", System.nanoTime() + "-" + count);
          for (ColumnNameTypeValue column : stratioStreamingMessage.getColumns()) {
            document.addField(column.getColumn(), column.getValue());
          }
          checkCore(stratioStreamingMessage);
          Collection<SolrInputDocument> collection =
              elemntsToInsert.get(stratioStreamingMessage.getStreamName());
          if (collection == null) {
            collection = new HashSet<>();
          }
          collection.add(document);
          elemntsToInsert.put(stratioStreamingMessage.getStreamName(), collection);
        }
        while (retryStrategy.shouldRetry()) {
          try {
            for (Map.Entry<String, Collection<SolrInputDocument>> elem :
                elemntsToInsert.entrySet()) {
              getSolrclient(elem.getKey()).add(elem.getValue());
            }
            break;
          } catch (SolrException e) {
            try {
              log.error("Solr cloud status not yet properly initialized, retrying");
              retryStrategy.errorOccured();
            } catch (RuntimeException ex) {
              log.error("Error while initializing Solr Cloud core ", ex.getMessage());
            }
          }
        }
        flushClients();
      }
    } catch (Exception ex) {
      log.error("Error in Solr: " + ex.getMessage());
    }
  }