Search in sources :

Example 16 with EventReporter

use of org.apache.nifi.events.EventReporter in project nifi by apache.

the class TestHttpClientTransaction method getClientTransaction.

private HttpClientTransaction getClientTransaction(InputStream is, OutputStream os, SiteToSiteRestApiClient apiClient, TransferDirection direction, String transactionUrl) throws IOException {
    PeerDescription description = null;
    String peerUrl = "";
    HttpCommunicationsSession commsSession = new HttpCommunicationsSession();
    ((HttpInput) commsSession.getInput()).setInputStream(is);
    ((HttpOutput) commsSession.getOutput()).setOutputStream(os);
    String clusterUrl = "";
    Peer peer = new Peer(description, commsSession, peerUrl, clusterUrl);
    String portId = "portId";
    boolean useCompression = false;
    int penaltyMillis = 1000;
    EventReporter eventReporter = new EventReporter() {

        @Override
        public void reportEvent(Severity severity, String category, String message) {
            logger.info("Reporting event... severity={}, category={}, message={}", severity, category, message);
        }
    };
    int protocolVersion = 5;
    HttpClientTransaction transaction = new HttpClientTransaction(protocolVersion, peer, direction, useCompression, portId, penaltyMillis, eventReporter);
    transaction.initialize(apiClient, transactionUrl);
    return transaction;
}
Also used : HttpInput(org.apache.nifi.remote.io.http.HttpInput) PeerDescription(org.apache.nifi.remote.PeerDescription) HttpCommunicationsSession(org.apache.nifi.remote.io.http.HttpCommunicationsSession) Peer(org.apache.nifi.remote.Peer) Severity(org.apache.nifi.reporting.Severity) HttpOutput(org.apache.nifi.remote.io.http.HttpOutput) EventReporter(org.apache.nifi.events.EventReporter)

Example 17 with EventReporter

use of org.apache.nifi.events.EventReporter in project nifi by apache.

the class TestSocketClientTransaction method getClientTransaction.

private SocketClientTransaction getClientTransaction(ByteArrayInputStream bis, ByteArrayOutputStream bos, TransferDirection direction) throws IOException {
    PeerDescription description = null;
    String peerUrl = "";
    SocketChannelCommunicationsSession commsSession = mock(SocketChannelCommunicationsSession.class);
    SocketChannelInput socketIn = mock(SocketChannelInput.class);
    SocketChannelOutput socketOut = mock(SocketChannelOutput.class);
    when(commsSession.getInput()).thenReturn(socketIn);
    when(commsSession.getOutput()).thenReturn(socketOut);
    when(socketIn.getInputStream()).thenReturn(bis);
    when(socketOut.getOutputStream()).thenReturn(bos);
    String clusterUrl = "";
    Peer peer = new Peer(description, commsSession, peerUrl, clusterUrl);
    boolean useCompression = false;
    int penaltyMillis = 1000;
    EventReporter eventReporter = null;
    int protocolVersion = 5;
    String destinationId = "destinationId";
    return new SocketClientTransaction(protocolVersion, destinationId, peer, codec, direction, useCompression, penaltyMillis, eventReporter);
}
Also used : PeerDescription(org.apache.nifi.remote.PeerDescription) SocketChannelInput(org.apache.nifi.remote.io.socket.SocketChannelInput) Peer(org.apache.nifi.remote.Peer) SocketChannelOutput(org.apache.nifi.remote.io.socket.SocketChannelOutput) SocketChannelCommunicationsSession(org.apache.nifi.remote.io.socket.SocketChannelCommunicationsSession) EventReporter(org.apache.nifi.events.EventReporter)

Example 18 with EventReporter

use of org.apache.nifi.events.EventReporter in project nifi-minifi by apache.

the class MiNiFiPersistentProvenanceRepositoryTest method printTestName.

@Before
public void printTestName() {
    reportedEvents.clear();
    eventReporter = new EventReporter() {

        private static final long serialVersionUID = 1L;

        @Override
        public void reportEvent(Severity severity, String category, String message) {
            reportedEvents.add(new ReportedEvent(severity, category, message));
            System.out.println(severity + " : " + category + " : " + message);
        }
    };
}
Also used : Severity(org.apache.nifi.reporting.Severity) EventReporter(org.apache.nifi.events.EventReporter) Before(org.junit.Before)

Example 19 with EventReporter

use of org.apache.nifi.events.EventReporter in project nifi-minifi by apache.

the class MiNiFiPersistentProvenanceRepositoryTest method testRolloverRetry.

@Test
public void testRolloverRetry() throws IOException, InterruptedException {
    final AtomicInteger retryAmount = new AtomicInteger(0);
    final RepositoryConfiguration config = createConfiguration();
    config.setMaxEventFileLife(3, TimeUnit.SECONDS);
    repo = new MiNiFiPersistentProvenanceRepository(config, DEFAULT_ROLLOVER_MILLIS) {

        @Override
        File mergeJournals(List<File> journalFiles, File suggestedMergeFile, EventReporter eventReporter) throws IOException {
            retryAmount.incrementAndGet();
            return super.mergeJournals(journalFiles, suggestedMergeFile, eventReporter);
        }

        // Indicate that there are no files available.
        @Override
        protected List<File> filterUnavailableFiles(List<File> journalFiles) {
            return Collections.emptyList();
        }

        @Override
        protected long getRolloverRetryMillis() {
            // retry quickly.
            return 10L;
        }
    };
    repo.initialize(getEventReporter(), null, null, IdentifierLookup.EMPTY);
    final Map<String, String> attributes = new HashMap<>();
    final ProvenanceEventBuilder builder = new StandardProvenanceEventRecord.Builder();
    builder.setEventTime(System.currentTimeMillis());
    builder.setEventType(ProvenanceEventType.RECEIVE);
    builder.setTransitUri("nifi://unit-test");
    attributes.put("uuid", "12345678-0000-0000-0000-012345678912");
    builder.fromFlowFile(createFlowFile(3L, 3000L, attributes));
    builder.setComponentId("1234");
    builder.setComponentType("dummy processor");
    final ProvenanceEventRecord record = builder.build();
    final ExecutorService exec = Executors.newFixedThreadPool(10);
    for (int i = 0; i < 10000; i++) {
        exec.submit(new Runnable() {

            @Override
            public void run() {
                repo.registerEvent(record);
            }
        });
    }
    exec.shutdown();
    exec.awaitTermination(10, TimeUnit.SECONDS);
    repo.waitForRollover();
    assertEquals(5, retryAmount.get());
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(java.util.concurrent.ExecutorService) List(java.util.List) ArrayList(java.util.ArrayList) TestUtil.createFlowFile(org.apache.nifi.provenance.TestUtil.createFlowFile) FlowFile(org.apache.nifi.flowfile.FlowFile) File(java.io.File) EventReporter(org.apache.nifi.events.EventReporter) Test(org.junit.Test)

Aggregations

EventReporter (org.apache.nifi.events.EventReporter)19 Severity (org.apache.nifi.reporting.Severity)6 IOException (java.io.IOException)5 ClusterCoordinationProtocolSenderListener (org.apache.nifi.cluster.protocol.impl.ClusterCoordinationProtocolSenderListener)5 ArrayList (java.util.ArrayList)4 RevisionManager (org.apache.nifi.web.revision.RevisionManager)4 File (java.io.File)3 List (java.util.List)3 Before (org.junit.Before)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 ExecutorService (java.util.concurrent.ExecutorService)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Authorizer (org.apache.nifi.authorization.Authorizer)2 NodeClusterCoordinator (org.apache.nifi.cluster.coordination.node.NodeClusterCoordinator)2 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)2 StandardDataFlow (org.apache.nifi.cluster.protocol.StandardDataFlow)2 RecordReaders (org.apache.nifi.provenance.serialization.RecordReaders)2 EventFileManager (org.apache.nifi.provenance.store.EventFileManager)2