Search in sources :

Example 1 with EventReporter

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

the class TestPersistentProvenanceRepository method testRolloverRetry.

@Test
public void testRolloverRetry() throws IOException, InterruptedException {
    assumeFalse(isWindowsEnvironment());
    final AtomicInteger retryAmount = new AtomicInteger(0);
    final RepositoryConfiguration config = createConfiguration();
    config.setMaxEventFileLife(3, TimeUnit.SECONDS);
    repo = new PersistentProvenanceRepository(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)

Example 2 with EventReporter

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

the class TestNodeClusterCoordinator method testTryAgainIfNoFlowServiceSet.

@Test
public void testTryAgainIfNoFlowServiceSet() {
    final ClusterCoordinationProtocolSenderListener senderListener = Mockito.mock(ClusterCoordinationProtocolSenderListener.class);
    final EventReporter eventReporter = Mockito.mock(EventReporter.class);
    final RevisionManager revisionManager = Mockito.mock(RevisionManager.class);
    Mockito.when(revisionManager.getAllRevisions()).thenReturn(Collections.emptyList());
    final NodeClusterCoordinator coordinator = new NodeClusterCoordinator(senderListener, eventReporter, null, new FirstVoteWinsFlowElection(), null, revisionManager, createProperties(), null) {

        @Override
        void notifyOthersOfNodeStatusChange(NodeConnectionStatus updatedStatus, boolean notifyAllNodes, boolean waitForCoordinator) {
        }
    };
    final NodeIdentifier requestedNodeId = createNodeId(6);
    final ConnectionRequest request = new ConnectionRequest(requestedNodeId, new StandardDataFlow(new byte[0], new byte[0], new byte[0], new HashSet<>()));
    final ConnectionRequestMessage requestMsg = new ConnectionRequestMessage();
    requestMsg.setConnectionRequest(request);
    coordinator.setConnected(true);
    final ProtocolMessage protocolResponse = coordinator.handle(requestMsg);
    assertNotNull(protocolResponse);
    assertTrue(protocolResponse instanceof ConnectionResponseMessage);
    final ConnectionResponse response = ((ConnectionResponseMessage) protocolResponse).getConnectionResponse();
    assertNotNull(response);
    assertEquals(5, response.getTryLaterSeconds());
}
Also used : ConnectionRequestMessage(org.apache.nifi.cluster.protocol.message.ConnectionRequestMessage) RevisionManager(org.apache.nifi.web.revision.RevisionManager) ConnectionResponse(org.apache.nifi.cluster.protocol.ConnectionResponse) ProtocolMessage(org.apache.nifi.cluster.protocol.message.ProtocolMessage) ConnectionRequest(org.apache.nifi.cluster.protocol.ConnectionRequest) StandardDataFlow(org.apache.nifi.cluster.protocol.StandardDataFlow) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) ConnectionResponseMessage(org.apache.nifi.cluster.protocol.message.ConnectionResponseMessage) ClusterCoordinationProtocolSenderListener(org.apache.nifi.cluster.protocol.impl.ClusterCoordinationProtocolSenderListener) EventReporter(org.apache.nifi.events.EventReporter) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with EventReporter

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

the class TestNodeClusterCoordinator method testUnknownNodeAskedToConnectOnAttemptedConnectionComplete.

@Test(timeout = 5000)
public void testUnknownNodeAskedToConnectOnAttemptedConnectionComplete() throws IOException, InterruptedException {
    final ClusterCoordinationProtocolSenderListener senderListener = Mockito.mock(ClusterCoordinationProtocolSenderListener.class);
    final AtomicReference<ReconnectionRequestMessage> requestRef = new AtomicReference<>();
    Mockito.when(senderListener.requestReconnection(Mockito.any(ReconnectionRequestMessage.class))).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            final ReconnectionRequestMessage msg = invocation.getArgumentAt(0, ReconnectionRequestMessage.class);
            requestRef.set(msg);
            return null;
        }
    });
    final EventReporter eventReporter = Mockito.mock(EventReporter.class);
    final RevisionManager revisionManager = Mockito.mock(RevisionManager.class);
    Mockito.when(revisionManager.getAllRevisions()).thenReturn(Collections.emptyList());
    final NodeClusterCoordinator coordinator = new NodeClusterCoordinator(senderListener, eventReporter, null, new FirstVoteWinsFlowElection(), null, revisionManager, createProperties(), null) {

        @Override
        void notifyOthersOfNodeStatusChange(NodeConnectionStatus updatedStatus, boolean notifyAllNodes, boolean waitForCoordinator) {
        }
    };
    final FlowService flowService = Mockito.mock(FlowService.class);
    final StandardDataFlow dataFlow = new StandardDataFlow(new byte[50], new byte[50], new byte[50], new HashSet<>());
    Mockito.when(flowService.createDataFlowFromController()).thenReturn(dataFlow);
    coordinator.setFlowService(flowService);
    coordinator.setConnected(true);
    final NodeIdentifier nodeId = createNodeId(1);
    coordinator.finishNodeConnection(nodeId);
    while (requestRef.get() == null) {
        Thread.sleep(10L);
    }
    final ReconnectionRequestMessage msg = requestRef.get();
    assertEquals(nodeId, msg.getNodeId());
    final StandardDataFlow df = msg.getDataFlow();
    assertNotNull(df);
    assertTrue(Arrays.equals(dataFlow.getFlow(), df.getFlow()));
    assertTrue(Arrays.equals(dataFlow.getSnippets(), df.getSnippets()));
}
Also used : RevisionManager(org.apache.nifi.web.revision.RevisionManager) AtomicReference(java.util.concurrent.atomic.AtomicReference) StandardDataFlow(org.apache.nifi.cluster.protocol.StandardDataFlow) InvocationOnMock(org.mockito.invocation.InvocationOnMock) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) ReconnectionRequestMessage(org.apache.nifi.cluster.protocol.message.ReconnectionRequestMessage) ClusterCoordinationProtocolSenderListener(org.apache.nifi.cluster.protocol.impl.ClusterCoordinationProtocolSenderListener) EventReporter(org.apache.nifi.events.EventReporter) FlowService(org.apache.nifi.services.FlowService) Test(org.junit.Test)

Example 4 with EventReporter

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

the class FlowController method createConnection.

/**
 * Creates a connection between two Connectable objects.
 *
 * @param id required ID of the connection
 * @param name the name of the connection, or <code>null</code> to leave the
 * connection unnamed
 * @param source required source
 * @param destination required destination
 * @param relationshipNames required collection of relationship names
 * @return
 *
 * @throws NullPointerException if the ID, source, destination, or set of
 * relationships is null.
 * @throws IllegalArgumentException if <code>relationships</code> is an
 * empty collection
 */
public Connection createConnection(final String id, final String name, final Connectable source, final Connectable destination, final Collection<String> relationshipNames) {
    final StandardConnection.Builder builder = new StandardConnection.Builder(processScheduler);
    final List<Relationship> relationships = new ArrayList<>();
    for (final String relationshipName : requireNonNull(relationshipNames)) {
        relationships.add(new Relationship.Builder().name(relationshipName).build());
    }
    // Create and initialize a FlowFileSwapManager for this connection
    final FlowFileSwapManager swapManager = createSwapManager(nifiProperties);
    final EventReporter eventReporter = createEventReporter(getBulletinRepository());
    try (final NarCloseable narCloseable = NarCloseable.withNarLoader()) {
        final SwapManagerInitializationContext initializationContext = new SwapManagerInitializationContext() {

            @Override
            public ResourceClaimManager getResourceClaimManager() {
                return resourceClaimManager;
            }

            @Override
            public FlowFileRepository getFlowFileRepository() {
                return flowFileRepository;
            }

            @Override
            public EventReporter getEventReporter() {
                return eventReporter;
            }
        };
        swapManager.initialize(initializationContext);
    }
    return builder.id(requireNonNull(id).intern()).name(name == null ? null : name.intern()).relationships(relationships).source(requireNonNull(source)).destination(destination).swapManager(swapManager).queueSwapThreshold(nifiProperties.getQueueSwapThreshold()).eventReporter(eventReporter).resourceClaimManager(resourceClaimManager).flowFileRepository(flowFileRepository).provenanceRepository(provenanceRepository).build();
}
Also used : NarCloseable(org.apache.nifi.nar.NarCloseable) Relationship(org.apache.nifi.processor.Relationship) ArrayList(java.util.ArrayList) FlowFileSwapManager(org.apache.nifi.controller.repository.FlowFileSwapManager) StandardConnection(org.apache.nifi.connectable.StandardConnection) SwapManagerInitializationContext(org.apache.nifi.controller.repository.SwapManagerInitializationContext) EventReporter(org.apache.nifi.events.EventReporter)

Example 5 with EventReporter

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

the class TestFileSystemSwapManager method createSwapManager.

private FileSystemSwapManager createSwapManager() {
    final FileSystemSwapManager swapManager = new FileSystemSwapManager();
    final ResourceClaimManager resourceClaimManager = new NopResourceClaimManager();
    final FlowFileRepository flowfileRepo = Mockito.mock(FlowFileRepository.class);
    swapManager.initialize(new SwapManagerInitializationContext() {

        @Override
        public ResourceClaimManager getResourceClaimManager() {
            return resourceClaimManager;
        }

        @Override
        public FlowFileRepository getFlowFileRepository() {
            return flowfileRepo;
        }

        @Override
        public EventReporter getEventReporter() {
            return EventReporter.NO_OP;
        }
    });
    return swapManager;
}
Also used : FlowFileRepository(org.apache.nifi.controller.repository.FlowFileRepository) ResourceClaimManager(org.apache.nifi.controller.repository.claim.ResourceClaimManager) SwapManagerInitializationContext(org.apache.nifi.controller.repository.SwapManagerInitializationContext) EventReporter(org.apache.nifi.events.EventReporter)

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