Search in sources :

Example 1 with FileHeader

use of org.apache.nifi.processors.evtx.parser.FileHeader in project nifi by apache.

the class ParseEvtx method processRecordGranularity.

protected void processRecordGranularity(ProcessSession session, ComponentLog componentLog, FlowFile flowFile, String basename, InputStream in) throws IOException {
    FileHeader fileHeader = fileHeaderFactory.create(in, componentLog);
    while (fileHeader.hasNext()) {
        try {
            ChunkHeader chunkHeader = fileHeader.next();
            while (chunkHeader.hasNext()) {
                FlowFile updated = session.create(flowFile);
                AtomicReference<Exception> exceptionReference = new AtomicReference<>(null);
                try {
                    Record record = chunkHeader.next();
                    updated = session.write(updated, out -> {
                        try (RootNodeHandler rootNodeHandler = rootNodeHandlerFactory.create(out)) {
                            try {
                                rootNodeHandler.handle(record.getRootNode());
                            } catch (IOException e) {
                                exceptionReference.set(e);
                            }
                        } catch (IOException e) {
                            exceptionReference.set(e);
                        }
                    });
                    resultProcessor.process(session, componentLog, updated, exceptionReference.get(), getName(basename, chunkHeader.getChunkNumber(), record.getRecordNum(), XML_EXTENSION));
                } catch (Exception e) {
                    exceptionReference.set(e);
                    session.remove(updated);
                }
                if (exceptionReference.get() != null) {
                    malformedChunkHandler.handle(flowFile, session, getName(basename, chunkHeader.getChunkNumber(), null, EVTX_EXTENSION), chunkHeader.getBinaryReader().getBytes());
                }
            }
        } catch (MalformedChunkException e) {
            malformedChunkHandler.handle(flowFile, session, getName(basename, e.getChunkNum(), null, EVTX_EXTENSION), e.getBadChunk());
        }
    }
}
Also used : Arrays(java.util.Arrays) CapabilityDescription(org.apache.nifi.annotation.documentation.CapabilityDescription) FileHeaderFactory(org.apache.nifi.processors.evtx.parser.FileHeaderFactory) FileHeader(org.apache.nifi.processors.evtx.parser.FileHeader) EventDriven(org.apache.nifi.annotation.behavior.EventDriven) ComponentLog(org.apache.nifi.logging.ComponentLog) SideEffectFree(org.apache.nifi.annotation.behavior.SideEffectFree) AtomicReference(java.util.concurrent.atomic.AtomicReference) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) ProcessException(org.apache.nifi.processor.exception.ProcessException) HashSet(java.util.HashSet) WritesAttributes(org.apache.nifi.annotation.behavior.WritesAttributes) Relationship(org.apache.nifi.processor.Relationship) Requirement(org.apache.nifi.annotation.behavior.InputRequirement.Requirement) ReadsAttributes(org.apache.nifi.annotation.behavior.ReadsAttributes) Record(org.apache.nifi.processors.evtx.parser.Record) ChunkHeader(org.apache.nifi.processors.evtx.parser.ChunkHeader) OutputStream(java.io.OutputStream) MalformedChunkException(org.apache.nifi.processors.evtx.parser.MalformedChunkException) FlowFile(org.apache.nifi.flowfile.FlowFile) ProcessContext(org.apache.nifi.processor.ProcessContext) Set(java.util.Set) ProcessSession(org.apache.nifi.processor.ProcessSession) IOException(java.io.IOException) WritesAttribute(org.apache.nifi.annotation.behavior.WritesAttribute) InputRequirement(org.apache.nifi.annotation.behavior.InputRequirement) List(java.util.List) SupportsBatching(org.apache.nifi.annotation.behavior.SupportsBatching) AbstractProcessor(org.apache.nifi.processor.AbstractProcessor) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Tags(org.apache.nifi.annotation.documentation.Tags) CoreAttributes(org.apache.nifi.flowfile.attributes.CoreAttributes) Collections(java.util.Collections) ReadsAttribute(org.apache.nifi.annotation.behavior.ReadsAttribute) InputStream(java.io.InputStream) FlowFile(org.apache.nifi.flowfile.FlowFile) ChunkHeader(org.apache.nifi.processors.evtx.parser.ChunkHeader) AtomicReference(java.util.concurrent.atomic.AtomicReference) Record(org.apache.nifi.processors.evtx.parser.Record) IOException(java.io.IOException) MalformedChunkException(org.apache.nifi.processors.evtx.parser.MalformedChunkException) FileHeader(org.apache.nifi.processors.evtx.parser.FileHeader) ProcessException(org.apache.nifi.processor.exception.ProcessException) MalformedChunkException(org.apache.nifi.processors.evtx.parser.MalformedChunkException) IOException(java.io.IOException)

Example 2 with FileHeader

use of org.apache.nifi.processors.evtx.parser.FileHeader in project nifi by apache.

the class ParseEvtx method processChunkGranularity.

protected void processChunkGranularity(ProcessSession session, ComponentLog componentLog, FlowFile flowFile, String basename, InputStream in) throws IOException {
    FileHeader fileHeader = fileHeaderFactory.create(in, componentLog);
    while (fileHeader.hasNext()) {
        try {
            ChunkHeader chunkHeader = fileHeader.next();
            FlowFile updated = session.create(flowFile);
            AtomicReference<Exception> exceptionReference = new AtomicReference<>(null);
            updated = session.write(updated, out -> {
                try (RootNodeHandler rootNodeHandler = rootNodeHandlerFactory.create(out)) {
                    while (chunkHeader.hasNext()) {
                        try {
                            rootNodeHandler.handle(chunkHeader.next().getRootNode());
                        } catch (IOException e) {
                            exceptionReference.set(e);
                            break;
                        }
                    }
                } catch (IOException e) {
                    exceptionReference.set(e);
                }
            });
            Exception exception = exceptionReference.get();
            resultProcessor.process(session, componentLog, updated, exception, getName(basename, chunkHeader.getChunkNumber(), null, XML_EXTENSION));
            if (exception != null) {
                malformedChunkHandler.handle(flowFile, session, getName(basename, chunkHeader.getChunkNumber(), null, EVTX_EXTENSION), chunkHeader.getBinaryReader().getBytes());
            }
        } catch (MalformedChunkException e) {
            malformedChunkHandler.handle(flowFile, session, getName(basename, e.getChunkNum(), null, EVTX_EXTENSION), e.getBadChunk());
        }
    }
}
Also used : Arrays(java.util.Arrays) CapabilityDescription(org.apache.nifi.annotation.documentation.CapabilityDescription) FileHeaderFactory(org.apache.nifi.processors.evtx.parser.FileHeaderFactory) FileHeader(org.apache.nifi.processors.evtx.parser.FileHeader) EventDriven(org.apache.nifi.annotation.behavior.EventDriven) ComponentLog(org.apache.nifi.logging.ComponentLog) SideEffectFree(org.apache.nifi.annotation.behavior.SideEffectFree) AtomicReference(java.util.concurrent.atomic.AtomicReference) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) ProcessException(org.apache.nifi.processor.exception.ProcessException) HashSet(java.util.HashSet) WritesAttributes(org.apache.nifi.annotation.behavior.WritesAttributes) Relationship(org.apache.nifi.processor.Relationship) Requirement(org.apache.nifi.annotation.behavior.InputRequirement.Requirement) ReadsAttributes(org.apache.nifi.annotation.behavior.ReadsAttributes) Record(org.apache.nifi.processors.evtx.parser.Record) ChunkHeader(org.apache.nifi.processors.evtx.parser.ChunkHeader) OutputStream(java.io.OutputStream) MalformedChunkException(org.apache.nifi.processors.evtx.parser.MalformedChunkException) FlowFile(org.apache.nifi.flowfile.FlowFile) ProcessContext(org.apache.nifi.processor.ProcessContext) Set(java.util.Set) ProcessSession(org.apache.nifi.processor.ProcessSession) IOException(java.io.IOException) WritesAttribute(org.apache.nifi.annotation.behavior.WritesAttribute) InputRequirement(org.apache.nifi.annotation.behavior.InputRequirement) List(java.util.List) SupportsBatching(org.apache.nifi.annotation.behavior.SupportsBatching) AbstractProcessor(org.apache.nifi.processor.AbstractProcessor) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Tags(org.apache.nifi.annotation.documentation.Tags) CoreAttributes(org.apache.nifi.flowfile.attributes.CoreAttributes) Collections(java.util.Collections) ReadsAttribute(org.apache.nifi.annotation.behavior.ReadsAttribute) InputStream(java.io.InputStream) FlowFile(org.apache.nifi.flowfile.FlowFile) ChunkHeader(org.apache.nifi.processors.evtx.parser.ChunkHeader) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) MalformedChunkException(org.apache.nifi.processors.evtx.parser.MalformedChunkException) FileHeader(org.apache.nifi.processors.evtx.parser.FileHeader) ProcessException(org.apache.nifi.processor.exception.ProcessException) MalformedChunkException(org.apache.nifi.processors.evtx.parser.MalformedChunkException) IOException(java.io.IOException)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 EventDriven (org.apache.nifi.annotation.behavior.EventDriven)2 InputRequirement (org.apache.nifi.annotation.behavior.InputRequirement)2 Requirement (org.apache.nifi.annotation.behavior.InputRequirement.Requirement)2 ReadsAttribute (org.apache.nifi.annotation.behavior.ReadsAttribute)2 ReadsAttributes (org.apache.nifi.annotation.behavior.ReadsAttributes)2 SideEffectFree (org.apache.nifi.annotation.behavior.SideEffectFree)2 SupportsBatching (org.apache.nifi.annotation.behavior.SupportsBatching)2 WritesAttribute (org.apache.nifi.annotation.behavior.WritesAttribute)2 WritesAttributes (org.apache.nifi.annotation.behavior.WritesAttributes)2 CapabilityDescription (org.apache.nifi.annotation.documentation.CapabilityDescription)2