Search in sources :

Example 11 with Grok

use of io.thekraken.grok.api.Grok in project incubator-gobblin by apache.

the class GrokToJsonConverter method init.

@Override
public Converter<String, JsonArray, String, JsonObject> init(WorkUnitState workUnit) {
    super.init(workUnit);
    String pattern = workUnit.getProp(GROK_PATTERN);
    String patternsFile = workUnit.getProp(BASE_PATTERNS_FILE);
    this.nullStringRegexes = DatasetFilterUtils.getPatternsFromStrings(workUnit.getPropAsList(NULLSTRING_REGEXES, ""));
    InputStreamReader grokPatterns;
    try {
        if (patternsFile == null) {
            grokPatterns = new InputStreamReader(getClass().getResourceAsStream("/grok/grok-base-patterns"), "UTF8");
        } else {
            grokPatterns = new InputStreamReader(new FileInputStream(patternsFile), "UTF8");
        }
        grok = new Grok();
        grok.addPatternFromReader(grokPatterns);
        grok.compile(pattern);
    } catch (GrokException | FileNotFoundException | UnsupportedEncodingException e) {
        throw new RuntimeException("Error initializing GROK: " + e);
    }
    return this;
}
Also used : InputStreamReader(java.io.InputStreamReader) Grok(io.thekraken.grok.api.Grok) GrokException(io.thekraken.grok.api.exception.GrokException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) FileInputStream(java.io.FileInputStream)

Aggregations

Grok (io.thekraken.grok.api.Grok)11 FileInputStream (java.io.FileInputStream)9 InputStream (java.io.InputStream)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 Test (org.junit.Test)8 File (java.io.File)4 Record (org.apache.nifi.serialization.record.Record)4 RecordSchema (org.apache.nifi.serialization.record.RecordSchema)3 InputStreamReader (java.io.InputStreamReader)2 GrokException (io.thekraken.grok.api.exception.GrokException)1 FileNotFoundException (java.io.FileNotFoundException)1 Reader (java.io.Reader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 OnEnabled (org.apache.nifi.annotation.lifecycle.OnEnabled)1 OnScheduled (org.apache.nifi.annotation.lifecycle.OnScheduled)1 RecordReader (org.apache.nifi.serialization.RecordReader)1