Search in sources :

Example 81 with ProcessorNode

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

the class DtoFactory method createAffectedComponentDto.

public AffectedComponentDTO createAffectedComponentDto(final ConfiguredComponent component) {
    final AffectedComponentDTO dto = new AffectedComponentDTO();
    dto.setId(component.getIdentifier());
    dto.setName(component.getName());
    dto.setProcessGroupId(component.getProcessGroupIdentifier());
    if (component instanceof ProcessorNode) {
        final ProcessorNode node = ((ProcessorNode) component);
        dto.setState(node.getScheduledState().name());
        dto.setActiveThreadCount(node.getActiveThreadCount());
        dto.setReferenceType(AffectedComponentDTO.COMPONENT_TYPE_PROCESSOR);
    } else if (component instanceof ControllerServiceNode) {
        final ControllerServiceNode node = ((ControllerServiceNode) component);
        dto.setState(node.getState().name());
        dto.setReferenceType(AffectedComponentDTO.COMPONENT_TYPE_CONTROLLER_SERVICE);
    }
    final Collection<ValidationResult> validationErrors = component.getValidationErrors();
    if (validationErrors != null && !validationErrors.isEmpty()) {
        final List<String> errors = new ArrayList<>();
        for (final ValidationResult validationResult : validationErrors) {
            errors.add(validationResult.toString());
        }
        dto.setValidationErrors(errors);
    }
    return dto;
}
Also used : ProcessorNode(org.apache.nifi.controller.ProcessorNode) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ArrayList(java.util.ArrayList) ValidationResult(org.apache.nifi.components.ValidationResult)

Example 82 with ProcessorNode

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

the class ControllerSearchServiceTest method setupMockedProcessor.

/**
 * Mocks Processor including isAuthorized() and its name & id.
 *
 * @param processorName          Desired processor name
 * @param containingProcessGroup The process group
 * @param authorizedToRead       Can the processor data be read?
 * @param variableRegistry       The variable registry
 */
private static void setupMockedProcessor(final String processorName, final ProcessGroup containingProcessGroup, boolean authorizedToRead, final MutableVariableRegistry variableRegistry) {
    final String processorId = processorName + "Id";
    final Processor processor1 = mock(Processor.class);
    final ProcessorNode processorNode1 = mock(StandardProcessorNode.class);
    Mockito.doReturn(authorizedToRead).when(processorNode1).isAuthorized(any(Authorizer.class), eq(RequestAction.READ), any(NiFiUser.class));
    Mockito.doReturn(variableRegistry).when(processorNode1).getVariableRegistry();
    Mockito.doReturn(processor1).when(processorNode1).getProcessor();
    // set processor node's attributes
    Mockito.doReturn(processorId).when(processorNode1).getIdentifier();
    // not actually searching based on versioned component id
    Mockito.doReturn(Optional.ofNullable(null)).when(processorNode1).getVersionedComponentId();
    Mockito.doReturn(processorName).when(processorNode1).getName();
    // assign processor node to its PG
    Mockito.doReturn(new HashSet<ProcessorNode>() {

        {
            add(processorNode1);
        }
    }).when(containingProcessGroup).getProcessors();
}
Also used : Processor(org.apache.nifi.processor.Processor) StandardProcessorNode(org.apache.nifi.controller.StandardProcessorNode) ProcessorNode(org.apache.nifi.controller.ProcessorNode) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) Authorizer(org.apache.nifi.authorization.Authorizer)

Example 83 with ProcessorNode

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

the class StandardProcessorDAO method clearState.

@Override
public void clearState(String processorId) {
    final ProcessorNode processor = locateProcessor(processorId);
    componentStateDAO.clearState(processor);
}
Also used : ProcessorNode(org.apache.nifi.controller.ProcessorNode)

Example 84 with ProcessorNode

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

the class StandardProcessorDAO method verifyTerminate.

@Override
public void verifyTerminate(final String processorId) {
    final ProcessorNode processor = locateProcessor(processorId);
    processor.verifyCanTerminate();
}
Also used : ProcessorNode(org.apache.nifi.controller.ProcessorNode)

Example 85 with ProcessorNode

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

the class StandardProcessorDAO method updateProcessor.

@Override
public ProcessorNode updateProcessor(ProcessorDTO processorDTO) {
    ProcessorNode processor = locateProcessor(processorDTO.getId());
    ProcessGroup parentGroup = processor.getProcessGroup();
    // ensure we can perform the update
    verifyUpdate(processor, processorDTO);
    // configure the processor
    configureProcessor(processor, processorDTO);
    parentGroup.onComponentModified();
    // attempt to change the underlying processor if an updated bundle is specified
    // updating the bundle must happen after configuring so that any additional classpath resources are set first
    updateBundle(processor, processorDTO);
    // see if an update is necessary
    if (isNotNull(processorDTO.getState())) {
        final ScheduledState purposedScheduledState = ScheduledState.valueOf(processorDTO.getState());
        // only attempt an action if it is changing
        if (!purposedScheduledState.equals(processor.getScheduledState())) {
            try {
                // perform the appropriate action
                switch(purposedScheduledState) {
                    case RUNNING:
                        parentGroup.startProcessor(processor, true);
                        break;
                    case STOPPED:
                        switch(processor.getScheduledState()) {
                            case RUNNING:
                                parentGroup.stopProcessor(processor);
                                break;
                            case DISABLED:
                                parentGroup.enableProcessor(processor);
                                break;
                        }
                        break;
                    case DISABLED:
                        parentGroup.disableProcessor(processor);
                        break;
                }
            } catch (IllegalStateException | ComponentLifeCycleException ise) {
                throw new NiFiCoreException(ise.getMessage(), ise);
            } catch (RejectedExecutionException ree) {
                throw new NiFiCoreException("Unable to schedule all tasks for the specified processor.", ree);
            } catch (NullPointerException npe) {
                throw new NiFiCoreException("Unable to update processor run state.", npe);
            } catch (Exception e) {
                throw new NiFiCoreException("Unable to update processor run state: " + e, e);
            }
        }
    }
    return processor;
}
Also used : NiFiCoreException(org.apache.nifi.web.NiFiCoreException) ProcessorNode(org.apache.nifi.controller.ProcessorNode) ScheduledState(org.apache.nifi.controller.ScheduledState) ProcessGroup(org.apache.nifi.groups.ProcessGroup) ComponentLifeCycleException(org.apache.nifi.controller.exception.ComponentLifeCycleException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ProcessorInstantiationException(org.apache.nifi.controller.exception.ProcessorInstantiationException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException) ParseException(java.text.ParseException) ComponentLifeCycleException(org.apache.nifi.controller.exception.ComponentLifeCycleException) NiFiCoreException(org.apache.nifi.web.NiFiCoreException) ValidationException(org.apache.nifi.controller.exception.ValidationException)

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