Search in sources :

Example 21 with EventBatch

use of org.apache.hadoop.hdfs.inotify.EventBatch in project nifi by apache.

the class TestGetHDFSEvents method onTriggerShouldOnlyProcessEventsWithSpecificPath.

@Test
public void onTriggerShouldOnlyProcessEventsWithSpecificPath() throws Exception {
    Event[] events = getEvents();
    EventBatch eventBatch = mock(EventBatch.class);
    when(eventBatch.getEvents()).thenReturn(events);
    when(inotifyEventInputStream.poll(1000000L, TimeUnit.MICROSECONDS)).thenReturn(eventBatch);
    when(hdfsAdmin.getInotifyEventStream()).thenReturn(inotifyEventInputStream);
    when(eventBatch.getTxid()).thenReturn(100L);
    GetHDFSEvents processor = new TestableGetHDFSEvents(kerberosProperties, hdfsAdmin);
    TestRunner runner = TestRunners.newTestRunner(processor);
    runner.setProperty(GetHDFSEvents.HDFS_PATH_TO_WATCH, "/some/path/create(/)?");
    runner.run();
    List<MockFlowFile> successfulFlowFiles = runner.getFlowFilesForRelationship(GetHDFSEvents.REL_SUCCESS);
    assertEquals(1, successfulFlowFiles.size());
    verify(eventBatch).getTxid();
    assertEquals("100", runner.getProcessContext().getStateManager().getState(Scope.CLUSTER).get("last.tx.id"));
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) TestRunner(org.apache.nifi.util.TestRunner) Event(org.apache.hadoop.hdfs.inotify.Event) EventBatch(org.apache.hadoop.hdfs.inotify.EventBatch) Test(org.junit.Test)

Example 22 with EventBatch

use of org.apache.hadoop.hdfs.inotify.EventBatch in project SSM by Intel-bigdata.

the class InotifyFetchAndApplyTask method run.

@Override
public void run() {
    LOG.trace("InotifyFetchAndApplyTask run at " + new Date());
    try {
        EventBatch eventBatch = inotifyEventInputStream.poll();
        while (eventBatch != null) {
            applier.apply(eventBatch.getEvents());
            lastId.getAndSet(eventBatch.getTxid());
            metaStore.updateAndInsertIfNotExist(new SystemInfo(SmartConstants.SMART_HDFS_LAST_INOTIFY_TXID, String.valueOf(lastId.get())));
            eventBatch = inotifyEventInputStream.poll();
        }
    } catch (Throwable t) {
        LOG.error("Inotify Apply Events error", t);
    }
}
Also used : SystemInfo(org.smartdata.model.SystemInfo) EventBatch(org.apache.hadoop.hdfs.inotify.EventBatch) Date(java.util.Date)

Aggregations

EventBatch (org.apache.hadoop.hdfs.inotify.EventBatch)22 Event (org.apache.hadoop.hdfs.inotify.Event)13 Test (org.junit.Test)12 IOException (java.io.IOException)6 Configuration (org.apache.hadoop.conf.Configuration)5 MockFlowFile (org.apache.nifi.util.MockFlowFile)5 TestRunner (org.apache.nifi.util.TestRunner)5 MissingEventsException (org.apache.hadoop.hdfs.inotify.MissingEventsException)4 MiniQJMHACluster (org.apache.hadoop.hdfs.qjournal.MiniQJMHACluster)4 ArrayList (java.util.ArrayList)3 DFSInotifyEventInputStream (org.apache.hadoop.hdfs.DFSInotifyEventInputStream)3 OutputStream (java.io.OutputStream)2 FsPermission (org.apache.hadoop.fs.permission.FsPermission)2 TraceScope (org.apache.htrace.core.TraceScope)2 AlluxioURI (alluxio.AlluxioURI)1 Constants (alluxio.Constants)1 SyncInfo (alluxio.SyncInfo)1 ConcurrentHashSet (alluxio.collections.ConcurrentHashSet)1 PropertyKey (alluxio.conf.PropertyKey)1 InvalidPathException (alluxio.exception.InvalidPathException)1