Search in sources :

Example 76 with ProcessorNode

use of org.apache.nifi.controller.ProcessorNode in project nifi by apache.

the class TestConnectableTask method testIsWorkToDo.

@Test
public void testIsWorkToDo() {
    final ProcessorNode procNode = Mockito.mock(ProcessorNode.class);
    Mockito.when(procNode.hasIncomingConnection()).thenReturn(false);
    final Processor processor = Mockito.mock(Processor.class);
    Mockito.when(procNode.getIdentifier()).thenReturn("123");
    Mockito.when(procNode.getRunnableComponent()).thenReturn(processor);
    final FlowController flowController = Mockito.mock(FlowController.class);
    Mockito.when(flowController.getStateManagerProvider()).thenReturn(Mockito.mock(StateManagerProvider.class));
    final RepositoryContext repoContext = Mockito.mock(RepositoryContext.class);
    Mockito.when(repoContext.getFlowFileEventRepository()).thenReturn(Mockito.mock(FlowFileEventRepository.class));
    final RepositoryContextFactory contextFactory = Mockito.mock(RepositoryContextFactory.class);
    Mockito.when(contextFactory.newProcessContext(Mockito.any(Connectable.class), Mockito.any(AtomicLong.class))).thenReturn(repoContext);
    final LifecycleState scheduleState = new LifecycleState();
    final StringEncryptor encryptor = Mockito.mock(StringEncryptor.class);
    ConnectableTask task = new ConnectableTask(Mockito.mock(SchedulingAgent.class), procNode, flowController, contextFactory, scheduleState, encryptor);
    // There is work to do because there are no incoming connections.
    assertFalse(task.invoke().isYield());
    // Test with only a single connection that is self-looping and empty
    final Connection selfLoopingConnection = Mockito.mock(Connection.class);
    when(selfLoopingConnection.getSource()).thenReturn(procNode);
    when(selfLoopingConnection.getDestination()).thenReturn(procNode);
    when(procNode.hasIncomingConnection()).thenReturn(true);
    when(procNode.getIncomingConnections()).thenReturn(Collections.singletonList(selfLoopingConnection));
    assertFalse(task.invoke().isYield());
    // Test with only a single connection that is self-looping and empty
    final FlowFileQueue flowFileQueue = Mockito.mock(FlowFileQueue.class);
    when(flowFileQueue.isActiveQueueEmpty()).thenReturn(true);
    final FlowFileQueue nonEmptyQueue = Mockito.mock(FlowFileQueue.class);
    when(nonEmptyQueue.isActiveQueueEmpty()).thenReturn(false);
    when(selfLoopingConnection.getFlowFileQueue()).thenReturn(nonEmptyQueue);
    assertFalse(task.invoke().isYield());
    // Test with only a non-looping Connection that has no FlowFiles
    final Connection emptyConnection = Mockito.mock(Connection.class);
    when(emptyConnection.getSource()).thenReturn(Mockito.mock(ProcessorNode.class));
    when(emptyConnection.getDestination()).thenReturn(procNode);
    when(emptyConnection.getFlowFileQueue()).thenReturn(flowFileQueue);
    when(procNode.getIncomingConnections()).thenReturn(Collections.singletonList(emptyConnection));
    // Create a new ConnectableTask because we want to have a different value for the 'hasNonLoopConnection' value, which is calculated in the task's constructor.
    task = new ConnectableTask(Mockito.mock(SchedulingAgent.class), procNode, flowController, contextFactory, scheduleState, encryptor);
    assertTrue(task.invoke().isYield());
    // test when the queue has data
    final Connection nonEmptyConnection = Mockito.mock(Connection.class);
    when(nonEmptyConnection.getSource()).thenReturn(Mockito.mock(ProcessorNode.class));
    when(nonEmptyConnection.getDestination()).thenReturn(procNode);
    when(nonEmptyConnection.getFlowFileQueue()).thenReturn(nonEmptyQueue);
    when(procNode.getIncomingConnections()).thenReturn(Collections.singletonList(nonEmptyConnection));
    assertFalse(task.invoke().isYield());
}
Also used : RepositoryContext(org.apache.nifi.controller.repository.RepositoryContext) Processor(org.apache.nifi.processor.Processor) Connection(org.apache.nifi.connectable.Connection) LifecycleState(org.apache.nifi.controller.scheduling.LifecycleState) FlowFileQueue(org.apache.nifi.controller.queue.FlowFileQueue) AtomicLong(java.util.concurrent.atomic.AtomicLong) ProcessorNode(org.apache.nifi.controller.ProcessorNode) FlowFileEventRepository(org.apache.nifi.controller.repository.FlowFileEventRepository) RepositoryContextFactory(org.apache.nifi.controller.scheduling.RepositoryContextFactory) Connectable(org.apache.nifi.connectable.Connectable) FlowController(org.apache.nifi.controller.FlowController) StringEncryptor(org.apache.nifi.encrypt.StringEncryptor) SchedulingAgent(org.apache.nifi.controller.scheduling.SchedulingAgent) StateManagerProvider(org.apache.nifi.components.state.StateManagerProvider) Test(org.junit.Test)

Example 77 with ProcessorNode

use of org.apache.nifi.controller.ProcessorNode in project nifi by apache.

the class StandardControllerServiceProvider method unscheduleReferencingComponents.

@Override
public Set<ConfiguredComponent> unscheduleReferencingComponents(final ControllerServiceNode serviceNode) {
    // find all of the schedulable components (processors, reporting tasks) that refer to this Controller Service,
    // or a service that references this controller service, etc.
    final List<ProcessorNode> processors = serviceNode.getReferences().findRecursiveReferences(ProcessorNode.class);
    final List<ReportingTaskNode> reportingTasks = serviceNode.getReferences().findRecursiveReferences(ReportingTaskNode.class);
    final Set<ConfiguredComponent> updated = new HashSet<>();
    // verify that  we can stop all components (that are running) before doing anything
    for (final ProcessorNode node : processors) {
        if (node.getScheduledState() == ScheduledState.RUNNING) {
            node.verifyCanStop();
        }
    }
    for (final ReportingTaskNode node : reportingTasks) {
        if (node.getScheduledState() == ScheduledState.RUNNING) {
            node.verifyCanStop();
        }
    }
    // stop all of the components that are running
    for (final ProcessorNode node : processors) {
        if (node.getScheduledState() == ScheduledState.RUNNING) {
            node.getProcessGroup().stopProcessor(node);
            updated.add(node);
        }
    }
    for (final ReportingTaskNode node : reportingTasks) {
        if (node.getScheduledState() == ScheduledState.RUNNING) {
            processScheduler.unschedule(node);
            updated.add(node);
        }
    }
    return updated;
}
Also used : ProcessorNode(org.apache.nifi.controller.ProcessorNode) ReportingTaskNode(org.apache.nifi.controller.ReportingTaskNode) ConfiguredComponent(org.apache.nifi.controller.ConfiguredComponent) HashSet(java.util.HashSet)

Example 78 with ProcessorNode

use of org.apache.nifi.controller.ProcessorNode in project nifi by apache.

the class StandardNiFiServiceFacade method getProcessorPropertyDescriptor.

@Override
public PropertyDescriptorDTO getProcessorPropertyDescriptor(final String id, final String property) {
    final ProcessorNode processor = processorDAO.getProcessor(id);
    PropertyDescriptor descriptor = processor.getPropertyDescriptor(property);
    // return an invalid descriptor if the processor doesn't support this property
    if (descriptor == null) {
        descriptor = new PropertyDescriptor.Builder().name(property).addValidator(Validator.INVALID).dynamic(true).build();
    }
    return dtoFactory.createPropertyDescriptorDto(descriptor, processor.getProcessGroup().getIdentifier());
}
Also used : ProcessorNode(org.apache.nifi.controller.ProcessorNode) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor)

Example 79 with ProcessorNode

use of org.apache.nifi.controller.ProcessorNode in project nifi by apache.

the class StandardNiFiServiceFacade method getProcessorStatus.

@Override
public ProcessorStatusEntity getProcessorStatus(final String id) {
    final ProcessorNode processor = processorDAO.getProcessor(id);
    final PermissionsDTO permissions = dtoFactory.createPermissionsDto(processor);
    final ProcessorStatusDTO dto = dtoFactory.createProcessorStatusDto(controllerFacade.getProcessorStatus(id));
    return entityFactory.createProcessorStatusEntity(dto, permissions);
}
Also used : ProcessorStatusDTO(org.apache.nifi.web.api.dto.status.ProcessorStatusDTO) ProcessorNode(org.apache.nifi.controller.ProcessorNode) PermissionsDTO(org.apache.nifi.web.api.dto.PermissionsDTO)

Example 80 with ProcessorNode

use of org.apache.nifi.controller.ProcessorNode in project nifi by apache.

the class DtoFactory method createProcessGroupStatusDto.

public ProcessGroupStatusDTO createProcessGroupStatusDto(final ProcessGroup processGroup, final ProcessGroupStatus processGroupStatus) {
    final ProcessGroupStatusDTO processGroupStatusDto = createConciseProcessGroupStatusDto(processGroupStatus);
    final ProcessGroupStatusSnapshotDTO snapshot = processGroupStatusDto.getAggregateSnapshot();
    // processor status
    final Collection<ProcessorStatusSnapshotEntity> processorStatusSnapshotEntities = new ArrayList<>();
    snapshot.setProcessorStatusSnapshots(processorStatusSnapshotEntities);
    final Collection<ProcessorStatus> processorStatusCollection = processGroupStatus.getProcessorStatus();
    if (processorStatusCollection != null) {
        for (final ProcessorStatus processorStatus : processorStatusCollection) {
            final ProcessorStatusDTO processorStatusDto = createProcessorStatusDto(processorStatus);
            final ProcessorNode processor = processGroup.findProcessor(processorStatusDto.getId());
            final PermissionsDTO processorPermissions = createPermissionsDto(processor);
            processorStatusSnapshotEntities.add(entityFactory.createProcessorStatusSnapshotEntity(processorStatusDto.getAggregateSnapshot(), processorPermissions));
        }
    }
    // connection status
    final Collection<ConnectionStatusSnapshotEntity> connectionStatusDtoCollection = new ArrayList<>();
    snapshot.setConnectionStatusSnapshots(connectionStatusDtoCollection);
    final Collection<ConnectionStatus> connectionStatusCollection = processGroupStatus.getConnectionStatus();
    if (connectionStatusCollection != null) {
        for (final ConnectionStatus connectionStatus : connectionStatusCollection) {
            final ConnectionStatusDTO connectionStatusDto = createConnectionStatusDto(connectionStatus);
            final Connection connection = processGroup.findConnection(connectionStatusDto.getId());
            final PermissionsDTO connectionPermissions = createPermissionsDto(connection);
            connectionStatusDtoCollection.add(entityFactory.createConnectionStatusSnapshotEntity(connectionStatusDto.getAggregateSnapshot(), connectionPermissions));
        }
    }
    // local child process groups
    final Collection<ProcessGroupStatusSnapshotEntity> childProcessGroupStatusDtoCollection = new ArrayList<>();
    snapshot.setProcessGroupStatusSnapshots(childProcessGroupStatusDtoCollection);
    final Collection<ProcessGroupStatus> childProcessGroupStatusCollection = processGroupStatus.getProcessGroupStatus();
    if (childProcessGroupStatusCollection != null) {
        for (final ProcessGroupStatus childProcessGroupStatus : childProcessGroupStatusCollection) {
            final ProcessGroupStatusDTO childProcessGroupStatusDto = createProcessGroupStatusDto(processGroup, childProcessGroupStatus);
            final ProcessGroup childProcessGroup = processGroup.findProcessGroup(childProcessGroupStatusDto.getId());
            final PermissionsDTO childProcessGroupPermissions = createPermissionsDto(childProcessGroup);
            childProcessGroupStatusDtoCollection.add(entityFactory.createProcessGroupStatusSnapshotEntity(childProcessGroupStatusDto.getAggregateSnapshot(), childProcessGroupPermissions));
        }
    }
    // remote child process groups
    final Collection<RemoteProcessGroupStatusSnapshotEntity> childRemoteProcessGroupStatusDtoCollection = new ArrayList<>();
    snapshot.setRemoteProcessGroupStatusSnapshots(childRemoteProcessGroupStatusDtoCollection);
    final Collection<RemoteProcessGroupStatus> childRemoteProcessGroupStatusCollection = processGroupStatus.getRemoteProcessGroupStatus();
    if (childRemoteProcessGroupStatusCollection != null) {
        for (final RemoteProcessGroupStatus childRemoteProcessGroupStatus : childRemoteProcessGroupStatusCollection) {
            final RemoteProcessGroupStatusDTO childRemoteProcessGroupStatusDto = createRemoteProcessGroupStatusDto(childRemoteProcessGroupStatus);
            final RemoteProcessGroup remoteProcessGroup = processGroup.findRemoteProcessGroup(childRemoteProcessGroupStatusDto.getId());
            final PermissionsDTO remoteProcessGroupPermissions = createPermissionsDto(remoteProcessGroup);
            childRemoteProcessGroupStatusDtoCollection.add(entityFactory.createRemoteProcessGroupStatusSnapshotEntity(childRemoteProcessGroupStatusDto.getAggregateSnapshot(), remoteProcessGroupPermissions));
        }
    }
    // input ports
    final Collection<PortStatusSnapshotEntity> inputPortStatusDtoCollection = new ArrayList<>();
    snapshot.setInputPortStatusSnapshots(inputPortStatusDtoCollection);
    final Collection<PortStatus> inputPortStatusCollection = processGroupStatus.getInputPortStatus();
    if (inputPortStatusCollection != null) {
        for (final PortStatus portStatus : inputPortStatusCollection) {
            final PortStatusDTO portStatusDto = createPortStatusDto(portStatus);
            final Port inputPort = processGroup.findInputPort(portStatus.getId());
            final PermissionsDTO inputPortPermissions = createPermissionsDto(inputPort);
            inputPortStatusDtoCollection.add(entityFactory.createPortStatusSnapshotEntity(portStatusDto.getAggregateSnapshot(), inputPortPermissions));
        }
    }
    // output ports
    final Collection<PortStatusSnapshotEntity> outputPortStatusDtoCollection = new ArrayList<>();
    snapshot.setOutputPortStatusSnapshots(outputPortStatusDtoCollection);
    final Collection<PortStatus> outputPortStatusCollection = processGroupStatus.getOutputPortStatus();
    if (outputPortStatusCollection != null) {
        for (final PortStatus portStatus : outputPortStatusCollection) {
            final PortStatusDTO portStatusDto = createPortStatusDto(portStatus);
            final Port outputPort = processGroup.findOutputPort(portStatus.getId());
            final PermissionsDTO outputPortPermissions = createPermissionsDto(outputPort);
            outputPortStatusDtoCollection.add(entityFactory.createPortStatusSnapshotEntity(portStatusDto.getAggregateSnapshot(), outputPortPermissions));
        }
    }
    return processGroupStatusDto;
}
Also used : InstantiatedVersionedRemoteGroupPort(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedRemoteGroupPort) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) RootGroupPort(org.apache.nifi.remote.RootGroupPort) Port(org.apache.nifi.connectable.Port) InstantiatedVersionedPort(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedPort) ArrayList(java.util.ArrayList) PortStatusDTO(org.apache.nifi.web.api.dto.status.PortStatusDTO) RemoteProcessGroupStatusSnapshotEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupStatusSnapshotEntity) ProcessGroupStatusSnapshotEntity(org.apache.nifi.web.api.entity.ProcessGroupStatusSnapshotEntity) PortStatusSnapshotEntity(org.apache.nifi.web.api.entity.PortStatusSnapshotEntity) ConnectionStatusSnapshotEntity(org.apache.nifi.web.api.entity.ConnectionStatusSnapshotEntity) ProcessorStatusDTO(org.apache.nifi.web.api.dto.status.ProcessorStatusDTO) ProcessorNode(org.apache.nifi.controller.ProcessorNode) PortStatus(org.apache.nifi.controller.status.PortStatus) ConnectionStatus(org.apache.nifi.controller.status.ConnectionStatus) NodeConnectionStatus(org.apache.nifi.cluster.coordination.node.NodeConnectionStatus) RemoteProcessGroupStatusDTO(org.apache.nifi.web.api.dto.status.RemoteProcessGroupStatusDTO) ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) RemoteProcessGroupStatus(org.apache.nifi.controller.status.RemoteProcessGroupStatus) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) InstantiatedVersionedRemoteProcessGroup(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedRemoteProcessGroup) ProcessGroupStatusDTO(org.apache.nifi.web.api.dto.status.ProcessGroupStatusDTO) RemoteProcessGroupStatusDTO(org.apache.nifi.web.api.dto.status.RemoteProcessGroupStatusDTO) Connection(org.apache.nifi.connectable.Connection) InstantiatedVersionedConnection(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedConnection) RemoteProcessGroupStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.RemoteProcessGroupStatusSnapshotDTO) ProcessGroupStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.ProcessGroupStatusSnapshotDTO) RemoteProcessGroupStatus(org.apache.nifi.controller.status.RemoteProcessGroupStatus) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus) ProcessorStatusSnapshotEntity(org.apache.nifi.web.api.entity.ProcessorStatusSnapshotEntity) ConnectionStatusDTO(org.apache.nifi.web.api.dto.status.ConnectionStatusDTO) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ProcessGroup(org.apache.nifi.groups.ProcessGroup) InstantiatedVersionedProcessGroup(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedProcessGroup) InstantiatedVersionedRemoteProcessGroup(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedRemoteProcessGroup) RemoteProcessGroupStatusSnapshotEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupStatusSnapshotEntity)

Aggregations

ProcessorNode (org.apache.nifi.controller.ProcessorNode)88 ProcessGroup (org.apache.nifi.groups.ProcessGroup)45 Port (org.apache.nifi.connectable.Port)25 ArrayList (java.util.ArrayList)23 Test (org.junit.Test)23 Connection (org.apache.nifi.connectable.Connection)22 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)22 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)22 HashSet (java.util.HashSet)20 Funnel (org.apache.nifi.connectable.Funnel)20 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)20 RootGroupPort (org.apache.nifi.remote.RootGroupPort)20 HashMap (java.util.HashMap)19 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)18 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)17 FlowController (org.apache.nifi.controller.FlowController)17 Map (java.util.Map)16 Connectable (org.apache.nifi.connectable.Connectable)16 ReportingTaskNode (org.apache.nifi.controller.ReportingTaskNode)16 LinkedHashSet (java.util.LinkedHashSet)15