Search in sources :

Example 1 with ParserRunnerImpl

use of org.apache.metron.parsers.ParserRunnerImpl in project metron by apache.

the class StellarParserRunner method doParse.

private List<JSONObject> doParse(List<String> messages) {
    // initialize
    HashSet<String> sensorTypes = new HashSet<>();
    sensorTypes.add(sensorType);
    ParserRunnerImpl runner = new ParserRunnerImpl(sensorTypes);
    runner.init(() -> parserConfigurations, context);
    // parse each message
    List<ParserRunnerResults<JSONObject>> results = messages.stream().map(str -> str.getBytes(StandardCharsets.UTF_8)).map(bytes -> DEFAULT.get(emptyMap(), bytes, false, emptyMap())).map(msg -> runner.execute(sensorType, msg, parserConfigurations)).collect(Collectors.toList());
    // aggregate both successes and errors into a list that can be returned
    List<JSONObject> successes = results.stream().flatMap(result -> result.getMessages().stream()).collect(Collectors.toList());
    successCount += successes.size();
    List<JSONObject> errors = results.stream().flatMap(result -> result.getErrors().stream()).map(err -> err.getJSONObject()).collect(Collectors.toList());
    errorCount += errors.size();
    // return a list of both successes and errors
    successes.addAll(errors);
    return successes;
}
Also used : Collections.emptyMap(java.util.Collections.emptyMap) ParserConfigurations(org.apache.metron.common.configuration.ParserConfigurations) ParserRunnerResults(org.apache.metron.parsers.ParserRunnerResults) DEFAULT(org.apache.metron.common.message.metadata.RawMessageStrategies.DEFAULT) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) ParserRunnerImpl(org.apache.metron.parsers.ParserRunnerImpl) HashSet(java.util.HashSet) List(java.util.List) JSONObject(org.json.simple.JSONObject) SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig) Map(java.util.Map) Context(org.apache.metron.stellar.dsl.Context) JSONObject(org.json.simple.JSONObject) ParserRunnerImpl(org.apache.metron.parsers.ParserRunnerImpl) ParserRunnerResults(org.apache.metron.parsers.ParserRunnerResults) HashSet(java.util.HashSet)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 IOException (java.io.IOException)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Collections.emptyMap (java.util.Collections.emptyMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 ParserConfigurations (org.apache.metron.common.configuration.ParserConfigurations)1 SensorParserConfig (org.apache.metron.common.configuration.SensorParserConfig)1 DEFAULT (org.apache.metron.common.message.metadata.RawMessageStrategies.DEFAULT)1 ParserRunnerImpl (org.apache.metron.parsers.ParserRunnerImpl)1 ParserRunnerResults (org.apache.metron.parsers.ParserRunnerResults)1 Context (org.apache.metron.stellar.dsl.Context)1 JSONObject (org.json.simple.JSONObject)1