Search in sources :

Example 21 with ComponentLog

use of org.apache.nifi.logging.ComponentLog in project nifi by apache.

the class ParseEvtxTest method testGetBasenameExtension.

@Test
public void testGetBasenameExtension() {
    String basename = "basename.wrongextension";
    FlowFile flowFile = mock(FlowFile.class);
    ComponentLog componentLog = mock(ComponentLog.class);
    when(flowFile.getAttribute(CoreAttributes.FILENAME.key())).thenReturn(basename);
    assertEquals(basename, parseEvtx.getBasename(flowFile, componentLog));
    verify(componentLog).warn(anyString(), isA(Object[].class));
}
Also used : FlowFile(org.apache.nifi.flowfile.FlowFile) MockFlowFile(org.apache.nifi.util.MockFlowFile) Mockito.anyString(org.mockito.Mockito.anyString) ComponentLog(org.apache.nifi.logging.ComponentLog) Test(org.junit.Test)

Example 22 with ComponentLog

use of org.apache.nifi.logging.ComponentLog in project nifi by apache.

the class ResultProcessorTest method testProcessResultFileSuccess.

@Test
public void testProcessResultFileSuccess() {
    ProcessSession processSession = mock(ProcessSession.class);
    ComponentLog componentLog = mock(ComponentLog.class);
    FlowFile flowFile = mock(FlowFile.class);
    Exception exception = null;
    String name = "basename";
    when(processSession.putAttribute(eq(flowFile), anyString(), anyString())).thenReturn(flowFile);
    resultProcessor.process(processSession, componentLog, flowFile, exception, name);
    verify(processSession).putAttribute(flowFile, CoreAttributes.FILENAME.key(), name);
    verify(processSession).putAttribute(flowFile, CoreAttributes.MIME_TYPE.key(), MediaType.APPLICATION_XML_UTF_8.toString());
    verify(processSession).transfer(flowFile, successRelationship);
    verifyNoMoreInteractions(componentLog);
}
Also used : ProcessSession(org.apache.nifi.processor.ProcessSession) FlowFile(org.apache.nifi.flowfile.FlowFile) Matchers.anyString(org.mockito.Matchers.anyString) ComponentLog(org.apache.nifi.logging.ComponentLog) Test(org.junit.Test)

Example 23 with ComponentLog

use of org.apache.nifi.logging.ComponentLog in project nifi by apache.

the class TestKerberosProperties method testValidatePrincipalAndKeytab.

@Test
public void testValidatePrincipalAndKeytab() {
    final ComponentLog log = Mockito.mock(ComponentLog.class);
    final Configuration config = new Configuration();
    // no security enabled in config so doesn't matter what principal and keytab are
    List<ValidationResult> results = KerberosProperties.validatePrincipalAndKeytab("test", config, null, null, log);
    Assert.assertEquals(0, results.size());
    results = KerberosProperties.validatePrincipalAndKeytab("test", config, "principal", null, log);
    Assert.assertEquals(0, results.size());
    results = KerberosProperties.validatePrincipalAndKeytab("test", config, "principal", "keytab", log);
    Assert.assertEquals(0, results.size());
    // change the config to have kerberos turned on
    config.set("hadoop.security.authentication", "kerberos");
    config.set("hadoop.security.authorization", "true");
    results = KerberosProperties.validatePrincipalAndKeytab("test", config, null, null, log);
    Assert.assertEquals(2, results.size());
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) ValidationResult(org.apache.nifi.components.ValidationResult) ComponentLog(org.apache.nifi.logging.ComponentLog) Test(org.junit.Test)

Example 24 with ComponentLog

use of org.apache.nifi.logging.ComponentLog in project nifi by apache.

the class BinFiles method processBins.

private int processBins(final ProcessContext context) {
    final ComponentLog logger = getLogger();
    int processedBins = 0;
    Bin bin;
    while ((bin = readyBins.poll()) != null) {
        boolean binAlreadyCommitted;
        try {
            binAlreadyCommitted = this.processBin(bin, context);
        } catch (final ProcessException e) {
            logger.error("Failed to process bundle of {} files due to {}", new Object[] { bin.getContents().size(), e });
            final ProcessSession binSession = bin.getSession();
            for (final FlowFile flowFile : bin.getContents()) {
                binSession.transfer(flowFile, REL_FAILURE);
            }
            binSession.commit();
            continue;
        } catch (final Exception e) {
            logger.error("Failed to process bundle of {} files due to {}; rolling back sessions", new Object[] { bin.getContents().size(), e });
            bin.getSession().rollback();
            continue;
        }
        // If this bin's session has been committed, move on.
        if (!binAlreadyCommitted) {
            final ProcessSession binSession = bin.getSession();
            binSession.transfer(bin.getContents(), REL_ORIGINAL);
            binSession.commit();
        }
        processedBins++;
    }
    return processedBins;
}
Also used : ProcessSession(org.apache.nifi.processor.ProcessSession) FlowFile(org.apache.nifi.flowfile.FlowFile) ProcessException(org.apache.nifi.processor.exception.ProcessException) ComponentLog(org.apache.nifi.logging.ComponentLog) ProcessException(org.apache.nifi.processor.exception.ProcessException) IOException(java.io.IOException)

Example 25 with ComponentLog

use of org.apache.nifi.logging.ComponentLog in project nifi by apache.

the class ExtractImageMetadata method onTrigger.

@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
    FlowFile flowfile = session.get();
    if (flowfile == null) {
        return;
    }
    final ComponentLog logger = this.getLogger();
    final AtomicReference<Metadata> value = new AtomicReference<>(null);
    final Integer max = context.getProperty(MAX_NUMBER_OF_ATTRIBUTES).asInteger();
    try {
        session.read(flowfile, new InputStreamCallback() {

            @Override
            public void process(InputStream in) throws IOException {
                try {
                    Metadata imageMetadata = ImageMetadataReader.readMetadata(in);
                    value.set(imageMetadata);
                } catch (ImageProcessingException ex) {
                    throw new ProcessException(ex);
                }
            }
        });
        Metadata metadata = value.get();
        Map<String, String> results = getTags(max, metadata);
        // Write the results to an attribute
        if (!results.isEmpty()) {
            flowfile = session.putAllAttributes(flowfile, results);
        }
        session.transfer(flowfile, SUCCESS);
    } catch (ProcessException e) {
        logger.error("Failed to extract image metadata from {} due to {}", new Object[] { flowfile, e });
        session.transfer(flowfile, FAILURE);
    }
}
Also used : FlowFile(org.apache.nifi.flowfile.FlowFile) ImageProcessingException(com.drew.imaging.ImageProcessingException) InputStream(java.io.InputStream) Metadata(com.drew.metadata.Metadata) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) ComponentLog(org.apache.nifi.logging.ComponentLog) ProcessException(org.apache.nifi.processor.exception.ProcessException) InputStreamCallback(org.apache.nifi.processor.io.InputStreamCallback)

Aggregations

ComponentLog (org.apache.nifi.logging.ComponentLog)211 FlowFile (org.apache.nifi.flowfile.FlowFile)111 ProcessException (org.apache.nifi.processor.exception.ProcessException)95 IOException (java.io.IOException)94 HashMap (java.util.HashMap)51 Map (java.util.Map)47 InputStream (java.io.InputStream)46 ArrayList (java.util.ArrayList)44 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)40 HashSet (java.util.HashSet)33 ProcessSession (org.apache.nifi.processor.ProcessSession)32 List (java.util.List)28 ProcessContext (org.apache.nifi.processor.ProcessContext)28 Relationship (org.apache.nifi.processor.Relationship)28 StopWatch (org.apache.nifi.util.StopWatch)28 OutputStream (java.io.OutputStream)27 InputStreamCallback (org.apache.nifi.processor.io.InputStreamCallback)27 Set (java.util.Set)23 Collections (java.util.Collections)21 AtomicReference (java.util.concurrent.atomic.AtomicReference)21