org.apache.nifi.groups.ProcessGroup Java Examples

The following examples show how to use org.apache.nifi.groups.ProcessGroup. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProcessorLifecycleIT.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void validateDisableOperation() throws Exception {
    final FlowManagerAndSystemBundle fcsb = this.buildFlowControllerForTest();
    flowManager = fcsb.getFlowManager();

    ProcessGroup testGroup = flowManager.createProcessGroup(UUID.randomUUID().toString());
    final ProcessorNode testProcNode = flowManager.createProcessor(TestProcessor.class.getName(),
            UUID.randomUUID().toString(), fcsb.getSystemBundle().getBundleDetails().getCoordinate());
    testProcNode.setProperties(properties);
    assertCondition(() -> ScheduledState.STOPPED == testProcNode.getScheduledState());
    assertCondition(() -> ScheduledState.STOPPED == testProcNode.getPhysicalScheduledState());
    // validates idempotency
    for (int i = 0; i < 2; i++) {
        testProcNode.disable();
    }
    assertCondition(() -> ScheduledState.DISABLED == testProcNode.getScheduledState());
    assertCondition(() -> ScheduledState.DISABLED == testProcNode.getPhysicalScheduledState());

    testProcNode.performValidation();
    processScheduler.startProcessor(testProcNode, true);
    assertCondition(() -> ScheduledState.DISABLED == testProcNode.getPhysicalScheduledState());
}
 
Example #2
Source File: ControllerFacade.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the status for the specified remote process group.
 *
 * @param remoteProcessGroupId remote process group id
 * @return the status for the specified remote process group
 */
public RemoteProcessGroupStatus getRemoteProcessGroupStatus(final String remoteProcessGroupId) {
    final ProcessGroup root = getRootGroup();
    final RemoteProcessGroup remoteProcessGroup = root.findRemoteProcessGroup(remoteProcessGroupId);

    // ensure the output port was found
    if (remoteProcessGroup == null) {
        throw new ResourceNotFoundException(String.format("Unable to locate remote process group with id '%s'.", remoteProcessGroupId));
    }

    final String groupId = remoteProcessGroup.getProcessGroup().getIdentifier();
    final ProcessGroupStatus groupStatus = flowController.getEventAccess().getGroupStatus(groupId, NiFiUserUtils.getNiFiUser(), 1);
    if (groupStatus == null) {
        throw new ResourceNotFoundException(String.format("Unable to locate group with id '%s'.", groupId));
    }

    final RemoteProcessGroupStatus status = groupStatus.getRemoteProcessGroupStatus().stream().filter(rpgStatus -> remoteProcessGroupId.equals(rpgStatus.getId())).findFirst().orElse(null);
    if (status == null) {
        throw new ResourceNotFoundException(String.format("Unable to locate remote process group with id '%s'.", remoteProcessGroupId));
    }

    return status;
}
 
Example #3
Source File: TestStandardControllerServiceProvider.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testEnableReferencingComponents() {
    final ProcessGroup procGroup = new MockProcessGroup();
    final FlowController controller = Mockito.mock(FlowController.class);
    Mockito.when(controller.getGroup(Mockito.anyString())).thenReturn(procGroup);

    final StandardProcessScheduler scheduler = createScheduler();
    final StandardControllerServiceProvider provider =
            new StandardControllerServiceProvider(controller, null, null, stateManagerProvider, variableRegistry, NiFiProperties.createBasicNiFiProperties(null, null));
    final ControllerServiceNode serviceNode = provider.createControllerService(ServiceA.class.getName(), "1", false);

    final ProcessorNode procNode = createProcessor(scheduler, provider);
    serviceNode.addReference(procNode);

    // procNode.setScheduledState(ScheduledState.STOPPED);
    provider.unscheduleReferencingComponents(serviceNode);
    assertEquals(ScheduledState.STOPPED, procNode.getScheduledState());

    // procNode.setScheduledState(ScheduledState.RUNNING);
    provider.unscheduleReferencingComponents(serviceNode);
    assertEquals(ScheduledState.STOPPED, procNode.getScheduledState());
}
 
Example #4
Source File: ProcessGroupAuditor.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Audits the creation of process groups via createProcessGroup().
 *
 * This method only needs to be run 'after returning'. However, in Java 7 the order in which these methods are returned from Class.getDeclaredMethods (even though there is no order guaranteed)
 * seems to differ from Java 6. SpringAOP depends on this ordering to determine advice precedence. By normalizing all advice into Around advice we can alleviate this issue.
 *
 * @param proceedingJoinPoint join point
 * @return group
 * @throws java.lang.Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.ProcessGroupDAO+) && "
        + "execution(org.apache.nifi.groups.ProcessGroup createProcessGroup(String, org.apache.nifi.web.api.dto.ProcessGroupDTO))")
public ProcessGroup createProcessGroupAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    // create the process group
    ProcessGroup processGroup = (ProcessGroup) proceedingJoinPoint.proceed();

    // if no exceptions were thrown, add the process group action...
    // audit process group creation
    final Action action = generateAuditRecord(processGroup, Operation.Add);

    // save the actions
    if (action != null) {
        saveAction(action, logger);
    }

    return processGroup;
}
 
Example #5
Source File: StandardFlowSynchronizer.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
private void addLocalTemplates(final Element processGroupElement, final ProcessGroup processGroup, final FlowEncodingVersion encodingVersion) {
    // Replace the templates with those from the proposed flow
    final List<Element> templateNodeList = getChildrenByTagName(processGroupElement, "template");
    if (templateNodeList != null) {
        for (final Element templateElement : templateNodeList) {
            final TemplateDTO templateDto = TemplateUtils.parseDto(templateElement);
            final Template template = new Template(templateDto);

            // If the Process Group does not have the template, add it.
            if (processGroup.getTemplate(template.getIdentifier()) == null) {
                processGroup.addTemplate(template);
            }
        }
    }

    final List<Element> childGroupElements = getChildrenByTagName(processGroupElement, "processGroup");
    for (final Element childGroupElement : childGroupElements) {
        final String childGroupId = getString(childGroupElement, "id");
        final ProcessGroup childGroup = processGroup.getProcessGroup(childGroupId);
        addLocalTemplates(childGroupElement, childGroup, encodingVersion);
    }
}
 
Example #6
Source File: TestHttpFlowFileServerProtocol.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testUnknownPort() throws Exception {
    final HttpFlowFileServerProtocol serverProtocol = getDefaultHttpFlowFileServerProtocol();
    final Peer peer = getDefaultPeer();
    ((HttpServerCommunicationsSession)peer.getCommunicationsSession())
            .putHandshakeParam(HandshakeProperty.PORT_IDENTIFIER, "port-identifier");

    final ProcessGroup processGroup = mock(ProcessGroup.class);
    doReturn(true).when(processGroup).isRootGroup();

    serverProtocol.setRootProcessGroup(processGroup);
    try {
        serverProtocol.handshake(peer);
        fail();
    } catch (final HandshakeException e) {
        assertEquals(ResponseCode.UNKNOWN_PORT, e.getResponseCode());
    }

    assertFalse(serverProtocol.isHandshakeSuccessful());
}
 
Example #7
Source File: ControllerFacade.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the status for the specified input port.
 *
 * @param portId input port id
 * @return the status for the specified input port
 */
public PortStatus getInputPortStatus(final String portId) {
    final ProcessGroup root = flowController.getGroup(flowController.getRootGroupId());
    final Port port = root.findInputPort(portId);

    // ensure the input port was found
    if (port == null) {
        throw new ResourceNotFoundException(String.format("Unable to locate input port with id '%s'.", portId));
    }

    final String groupId = port.getProcessGroup().getIdentifier();
    final ProcessGroupStatus processGroupStatus = flowController.getGroupStatus(groupId, NiFiUserUtils.getNiFiUser());
    if (processGroupStatus == null) {
        throw new ResourceNotFoundException(String.format("Unable to locate group with id '%s'.", groupId));
    }

    final PortStatus status = processGroupStatus.getInputPortStatus().stream().filter(portStatus -> portId.equals(portStatus.getId())).findFirst().orElse(null);
    if (status == null) {
        throw new ResourceNotFoundException(String.format("Unable to locate input port with id '%s'.", portId));
    }

    return status;
}
 
Example #8
Source File: BulletinFactory.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
public static Bulletin createBulletin(final Connectable connectable, final String category, final String severity, final String message) {
    final ComponentType type;
    switch (connectable.getConnectableType()) {
        case REMOTE_INPUT_PORT:
        case REMOTE_OUTPUT_PORT:
            type = ComponentType.REMOTE_PROCESS_GROUP;
            break;
        case INPUT_PORT:
            type = ComponentType.INPUT_PORT;
            break;
        case OUTPUT_PORT:
            type = ComponentType.OUTPUT_PORT;
            break;
        case PROCESSOR:
        default:
            type = ComponentType.PROCESSOR;
            break;
    }

    final ProcessGroup group = connectable.getProcessGroup();
    final String groupId = group == null ? null : group.getIdentifier();
    return BulletinFactory.createBulletin(groupId, connectable.getIdentifier(), type, connectable.getName(), category, severity, message);
}
 
Example #9
Source File: TestHttpFlowFileServerProtocol.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testUnauthorized() throws Exception {
    final HttpFlowFileServerProtocol serverProtocol = getDefaultHttpFlowFileServerProtocol();
    final Peer peer = getDefaultPeer();
    ((HttpServerCommunicationsSession)peer.getCommunicationsSession())
            .putHandshakeParam(HandshakeProperty.PORT_IDENTIFIER, "port-identifier");

    final ProcessGroup processGroup = mock(ProcessGroup.class);
    final RootGroupPort port = mock(RootGroupPort.class);
    final PortAuthorizationResult authResult = mock(PortAuthorizationResult.class);
    doReturn(true).when(processGroup).isRootGroup();
    doReturn(port).when(processGroup).getOutputPort("port-identifier");
    doReturn(authResult).when(port).checkUserAuthorization(any(String.class));

    serverProtocol.setRootProcessGroup(processGroup);
    try {
        serverProtocol.handshake(peer);
        fail();
    } catch (final HandshakeException e) {
        assertEquals(ResponseCode.UNAUTHORIZED, e.getResponseCode());
    }

    assertFalse(serverProtocol.isHandshakeSuccessful());
}
 
Example #10
Source File: NiFiRegistryFlowMapperTest.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Test mapping nested process group's parameter contexts
 */
@Test
public void testMapNestedParameterContexts() {
    final ProcessGroup innerInnerProcessGroup =
            prepareProcessGroupWithParameterContext(Collections.emptyList(),
                    true, true);
    final ProcessGroup innerProcessGroup =
            prepareProcessGroupWithParameterContext(Lists.newArrayList(innerInnerProcessGroup),
                    false, true);
    final ProcessGroup processGroup =
            prepareProcessGroupWithParameterContext(Lists.newArrayList(innerProcessGroup),
                    true, true);

    // include nested parameter contexts even though they are version controlled because map descendant indicator is true
    final Map<String, VersionedParameterContext> versionedParameterContexts =
            flowMapper.mapParameterContexts(processGroup, true);

    // verify parameter contexts
    assertEquals(2, versionedParameterContexts.size());

    final String expectedName1 = processGroup.getParameterContext().getName();
    final String expectedName2 = innerInnerProcessGroup.getParameterContext().getName();
    verifyParameterContext(processGroup.getParameterContext(), versionedParameterContexts.get(expectedName1));
    verifyParameterContext(innerInnerProcessGroup.getParameterContext(), versionedParameterContexts.get(expectedName2));
}
 
Example #11
Source File: ControllerFacade.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the status for the specified connection.
 *
 * @param connectionId connection id
 * @return the status for the specified connection
 */
public ConnectionStatus getConnectionStatus(final String connectionId) {
    final ProcessGroup root = flowController.getGroup(flowController.getRootGroupId());
    final Connection connection = root.findConnection(connectionId);

    // ensure the connection was found
    if (connection == null) {
        throw new ResourceNotFoundException(String.format("Unable to locate connection with id '%s'.", connectionId));
    }

    // calculate the process group status
    final String groupId = connection.getProcessGroup().getIdentifier();
    final ProcessGroupStatus processGroupStatus = flowController.getGroupStatus(groupId, NiFiUserUtils.getNiFiUser());
    if (processGroupStatus == null) {
        throw new ResourceNotFoundException(String.format("Unable to locate group with id '%s'.", groupId));
    }

    final ConnectionStatus status = processGroupStatus.getConnectionStatus().stream().filter(connectionStatus -> connectionId.equals(connectionStatus.getId())).findFirst().orElse(null);
    if (status == null) {
        throw new ResourceNotFoundException(String.format("Unable to locate connection with id '%s'.", connectionId));
    }

    return status;
}
 
Example #12
Source File: DtoFactory.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
public ProcessGroupFlowDTO createProcessGroupFlowDto(final ProcessGroup group, final ProcessGroupStatus groupStatus, final RevisionManager revisionManager,
                                                     final Function<ProcessGroup, List<BulletinEntity>> getProcessGroupBulletins) {

    final ProcessGroupFlowDTO dto = new ProcessGroupFlowDTO();
    dto.setId(group.getIdentifier());
    dto.setLastRefreshed(new Date());
    dto.setBreadcrumb(createBreadcrumbEntity(group));
    dto.setFlow(createFlowDto(group, groupStatus, revisionManager, getProcessGroupBulletins));

    final ProcessGroup parent = group.getParent();
    if (parent != null) {
        dto.setParentGroupId(parent.getIdentifier());
    }

    return dto;
}
 
Example #13
Source File: TestProcessorLifecycle.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Will validate the idempotent nature of processor start operation which
 * can be called multiple times without any side-effects.
 */
@Test
public void validateIdempotencyOfProcessorStartOperation() throws Exception {
    fc = this.buildFlowControllerForTest();
    ProcessGroup testGroup = fc.createProcessGroup(UUID.randomUUID().toString());
    this.setControllerRootGroup(fc, testGroup);
    final ProcessorNode testProcNode = fc.createProcessor(TestProcessor.class.getName(), UUID.randomUUID().toString());
    testProcNode.setProperties(properties);
    TestProcessor testProcessor = (TestProcessor) testProcNode.getProcessor();

    // sets the scenario for the processor to run
    this.noop(testProcessor);
    final ProcessScheduler ps = fc.getProcessScheduler();

    ps.startProcessor(testProcNode);
    ps.startProcessor(testProcNode);
    ps.startProcessor(testProcNode);

    Thread.sleep(500);
    assertEquals(1, testProcessor.operationNames.size());
    assertEquals("@OnScheduled", testProcessor.operationNames.get(0));
}
 
Example #14
Source File: StandardLabelDAO.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public Label createLabel(String groupId, LabelDTO labelDTO) {
    if (labelDTO.getParentGroupId() != null && !flowController.areGroupsSame(groupId, labelDTO.getParentGroupId())) {
        throw new IllegalArgumentException("Cannot specify a different Parent Group ID than the Group to which the Label is being added.");
    }

    // get the desired group
    ProcessGroup group = locateProcessGroup(flowController, groupId);

    // create the label
    Label label = flowController.createLabel(labelDTO.getId(), labelDTO.getLabel());
    if (labelDTO.getPosition() != null) {
        label.setPosition(new Position(labelDTO.getPosition().getX(), labelDTO.getPosition().getY()));
    }
    if (labelDTO.getWidth() != null && labelDTO.getHeight() != null) {
        label.setSize(new Size(labelDTO.getWidth(), labelDTO.getHeight()));
    }
    label.setStyle(labelDTO.getStyle());

    // add the label
    group.addLabel(label);
    return label;
}
 
Example #15
Source File: StandardProcessGroupDAO.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public void verifyDeleteFlowRegistry(String registryId) {
    final ProcessGroup rootGroup = flowController.getFlowManager().getRootGroup();

    final VersionControlInformation versionControlInformation = rootGroup.getVersionControlInformation();
    if (versionControlInformation != null && versionControlInformation.getRegistryIdentifier().equals(registryId)) {
        throw new IllegalStateException("The Registry cannot be removed because a Process Group currently under version control is tracking to it.");
    }

    final Set<VersionControlInformation> trackedVersionControlInformation = rootGroup.findAllProcessGroups().stream()
            .map(group -> group.getVersionControlInformation())
            .filter(Objects::nonNull)
            .filter(vci -> vci.getRegistryIdentifier().equals(registryId))
            .collect(Collectors.toSet());

    if (!trackedVersionControlInformation.isEmpty()) {
        throw new IllegalStateException("The Registry cannot be removed because a Process Group currently under version control is tracking to it.");
    }
}
 
Example #16
Source File: ControllerFacade.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Searches this controller for the specified term.
 *
 * @param searchLiteral search string specified by the user
 * @param activeGroupId the identifier of the currently visited group
 * @return result
 */
public SearchResultsDTO search(final String searchLiteral, final String activeGroupId) {
    final ProcessGroup rootGroup = getRootGroup();
    final ProcessGroup activeGroup = (activeGroupId == null)
            ? rootGroup
            : flowController.getFlowManager().getGroup(activeGroupId);
    final SearchResultsDTO results = new SearchResultsDTO();
    final SearchQuery searchQuery = searchQueryParser.parse(searchLiteral, NiFiUserUtils.getNiFiUser(), rootGroup, activeGroup);

    if (!StringUtils.isEmpty(searchQuery.getTerm())) {
        controllerSearchService.search(searchQuery, results);
        controllerSearchService.searchParameters(searchQuery, results);
    }

    return results;
}
 
Example #17
Source File: StandardSnippetDAO.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public void verifyUpdateSnippetComponent(SnippetDTO snippetDTO) {
    final Snippet snippet = locateSnippet(snippetDTO.getId());

    // if the group is changing move it
    if (snippetDTO.getParentGroupId() != null && !snippet.getParentGroupId().equals(snippetDTO.getParentGroupId())) {
        // get the current process group
        final ProcessGroup processGroup = flowController.getGroup(snippet.getParentGroupId());
        if (processGroup == null) {
            throw new IllegalArgumentException("The specified parent process group could not be found.");
        }

        // get the new process group
        final ProcessGroup newProcessGroup = flowController.getGroup(snippetDTO.getParentGroupId());
        if (newProcessGroup == null) {
            throw new IllegalArgumentException("The new process group could not be found.");
        }

        // perform the verification
        processGroup.verifyCanMove(snippet, newProcessGroup);
    }
}
 
Example #18
Source File: TestStandardRootGroupPort.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
private RootGroupPort createRootGroupPort(NiFiProperties nifiProperties) {
    final BulletinRepository bulletinRepository = mock(BulletinRepository.class);
    final ProcessScheduler processScheduler = null;

    final Authorizer authorizer = mock(Authorizer.class);
    doAnswer(invocation -> {
        final AuthorizationRequest request = invocation.getArgumentAt(0, AuthorizationRequest.class);
        if ("[email protected]".equals(request.getIdentity())) {
            return AuthorizationResult.approved();
        }
        return AuthorizationResult.denied();
    }).when(authorizer).authorize(any(AuthorizationRequest.class));

    final ProcessGroup processGroup = mock(ProcessGroup.class);
    doReturn("process-group-id").when(processGroup).getIdentifier();

    return new StandardRootGroupPort("id", "name", processGroup,
            TransferDirection.SEND, ConnectableType.INPUT_PORT, authorizer, bulletinRepository,
            processScheduler, true, nifiProperties);
}
 
Example #19
Source File: StandardProcessGroupDAO.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public ProcessGroup updateProcessGroupFlow(final String groupId, final VersionedFlowSnapshot proposedSnapshot, final VersionControlInformationDTO versionControlInformation,
                                           final String componentIdSeed, final boolean verifyNotModified, final boolean updateSettings, final boolean updateDescendantVersionedFlows) {

    final ProcessGroup group = locateProcessGroup(flowController, groupId);
    group.updateFlow(proposedSnapshot, componentIdSeed, verifyNotModified, updateSettings, updateDescendantVersionedFlows);
    group.findAllRemoteProcessGroups().forEach(RemoteProcessGroup::initialize);

    // process group being updated may not be versioned
    if (versionControlInformation != null) {
        final StandardVersionControlInformation svci = StandardVersionControlInformation.Builder.fromDto(versionControlInformation)
                .flowSnapshot(proposedSnapshot.getFlowContents())
                .build();
        group.setVersionControlInformation(svci, Collections.emptyMap());
    }

    group.onComponentModified();

    return group;
}
 
Example #20
Source File: ControllerFacade.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the status history for the specified remote process group.
 *
 * @param remoteProcessGroupId remote process group id
 * @return status history
 */
public StatusHistoryDTO getRemoteProcessGroupStatusHistory(final String remoteProcessGroupId) {
    final ProcessGroup root = getRootGroup();
    final RemoteProcessGroup remoteProcessGroup = root.findRemoteProcessGroup(remoteProcessGroupId);

    // ensure the output port was found
    if (remoteProcessGroup == null) {
        throw new ResourceNotFoundException(String.format("Unable to locate remote process group with id '%s'.", remoteProcessGroupId));
    }

    final StatusHistoryDTO statusHistory = flowController.getRemoteProcessGroupStatusHistory(remoteProcessGroupId);

    // if not authorized
    if (!remoteProcessGroup.isAuthorized(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser())) {
        statusHistory.getComponentDetails().put(ComponentStatusRepository.COMPONENT_DETAIL_NAME, remoteProcessGroupId);
        statusHistory.getComponentDetails().remove(ComponentStatusRepository.COMPONENT_DETAIL_URI);
    }

    return statusHistory;
}
 
Example #21
Source File: StandardProcessGroupDAO.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public void scheduleComponents(final String groupId, final ScheduledState state, final Set<String> componentIds) {
    final ProcessGroup group = locateProcessGroup(flowController, groupId);

    for (final String componentId : componentIds) {
        final Connectable connectable = group.findLocalConnectable(componentId);
        if (ScheduledState.RUNNING.equals(state)) {
            if (ConnectableType.PROCESSOR.equals(connectable.getConnectableType())) {
                connectable.getProcessGroup().startProcessor((ProcessorNode) connectable);
            } else if (ConnectableType.INPUT_PORT.equals(connectable.getConnectableType())) {
                connectable.getProcessGroup().startInputPort((Port) connectable);
            } else if (ConnectableType.OUTPUT_PORT.equals(connectable.getConnectableType())) {
                connectable.getProcessGroup().startOutputPort((Port) connectable);
            }
        } else {
            if (ConnectableType.PROCESSOR.equals(connectable.getConnectableType())) {
                connectable.getProcessGroup().stopProcessor((ProcessorNode) connectable);
            } else if (ConnectableType.INPUT_PORT.equals(connectable.getConnectableType())) {
                connectable.getProcessGroup().stopInputPort((Port) connectable);
            } else if (ConnectableType.OUTPUT_PORT.equals(connectable.getConnectableType())) {
                connectable.getProcessGroup().stopOutputPort((Port) connectable);
            }
        }
    }
}
 
Example #22
Source File: AbstractPort.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
public AbstractPort(final String id, final String name, final ProcessGroup processGroup, final ConnectableType type, final ProcessScheduler scheduler) {
    this.id = requireNonNull(id);
    this.name = new AtomicReference<>(requireNonNull(name));
    position = new AtomicReference<>(new Position(0D, 0D));
    outgoingConnections = new HashSet<>();
    incomingConnections = new ArrayList<>();
    comments = new AtomicReference<>();
    lossTolerant = new AtomicBoolean(false);
    concurrentTaskCount = new AtomicInteger(1);
    processScheduler = scheduler;

    final List<Relationship> relationshipList = new ArrayList<>();
    relationshipList.add(PORT_RELATIONSHIP);
    relationships = Collections.unmodifiableList(relationshipList);
    this.processGroup = new AtomicReference<>(processGroup);
    this.type = type;
    penalizationPeriod = new AtomicReference<>("30 sec");
    yieldPeriod = new AtomicReference<>("1 sec");
    yieldExpiration = new AtomicLong(0L);
    schedulingPeriod = new AtomicReference<>("0 millis");
    schedulingNanos = new AtomicLong(MINIMUM_SCHEDULING_NANOS);
    scheduledState = new AtomicReference<>(ScheduledState.STOPPED);
}
 
Example #23
Source File: StandardFunnelDAO.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public Funnel createFunnel(String groupId, FunnelDTO funnelDTO) {
    if (funnelDTO.getParentGroupId() != null && !flowController.getFlowManager().areGroupsSame(groupId, funnelDTO.getParentGroupId())) {
        throw new IllegalArgumentException("Cannot specify a different Parent Group ID than the Group to which the Funnel is being added.");
    }

    // get the desired group
    ProcessGroup group = locateProcessGroup(flowController, groupId);

    // create the funnel
    Funnel funnel = flowController.getFlowManager().createFunnel(funnelDTO.getId());
    if (funnelDTO.getPosition() != null) {
        funnel.setPosition(new Position(funnelDTO.getPosition().getX(), funnelDTO.getPosition().getY()));
    }

    // add the funnel
    group.addFunnel(funnel);
    group.startFunnel(funnel);
    return funnel;
}
 
Example #24
Source File: RelationshipAuditor.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Determines the type of component the specified connectable is.
 */
private Component determineConnectableType(Connectable connectable) {
    String sourceId = connectable.getIdentifier();
    Component componentType = Component.Controller;
    if (connectable instanceof ProcessorNode) {
        componentType = Component.Processor;
    } else if (connectable instanceof RemoteGroupPort) {
        final RemoteGroupPort remoteGroupPort = (RemoteGroupPort) connectable;
        if (TransferDirection.RECEIVE.equals(remoteGroupPort.getTransferDirection())) {
            if (remoteGroupPort.getRemoteProcessGroup() == null) {
                componentType = Component.InputPort;
            } else {
                componentType = Component.OutputPort;
            }
        } else {
            if (remoteGroupPort.getRemoteProcessGroup() == null) {
                componentType = Component.OutputPort;
            } else {
                componentType = Component.InputPort;
            }
        }
    } else if (connectable instanceof Port) {
        ProcessGroup processGroup = connectable.getProcessGroup();
        if (processGroup.getInputPort(sourceId) != null) {
            componentType = Component.InputPort;
        } else if (processGroup.getOutputPort(sourceId) != null) {
            componentType = Component.OutputPort;
        }
    } else if (connectable instanceof Funnel) {
        componentType = Component.Funnel;
    }
    return componentType;
}
 
Example #25
Source File: PositionScaler.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Scales the positions of all {@link Position}s in the given {@link ProcessGroup} by
 * the provided factor.  This method replaces all {@link Position}s in each {@link Positionable}
 * in the {@link ProcessGroup} with a new scaled {@link Position}.
 *
 * @param processGroup containing the {@link Positionable}s to be scaled
 * @param factorX      used to scale a {@link Positionable}'s X-coordinate position
 * @param factorY      used to scale a {@link Positionable}'s Y-coordinate position
 */
public static void scale(ProcessGroup processGroup, double factorX, double factorY) {
    processGroup.findAllPositionables().stream().forEach(p -> scale(p, factorX, factorY));
    Map<Connection, List<Position>> bendPointsByConnection =
            processGroup.findAllConnections().stream().collect(Collectors.toMap(connection -> connection, Connection::getBendPoints));
    bendPointsByConnection.entrySet().stream()
            .forEach(connectionListEntry -> connectionListEntry.getKey().setBendPoints(connectionListEntry.getValue().stream()
                    .map(p -> scalePosition(p, factorX, factorY)).collect(Collectors.toList())));

}
 
Example #26
Source File: ControllerFacade.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the output ports on the root group.
 *
 * @return output ports
 */
public Set<RootGroupPort> getOutputPorts() {
    final Set<RootGroupPort> outputPorts = new HashSet<>();
    ProcessGroup rootGroup = flowController.getGroup(flowController.getRootGroupId());
    for (final Port port : rootGroup.getOutputPorts()) {
        if (port instanceof RootGroupPort) {
            outputPorts.add((RootGroupPort) port);
        }
    }
    return outputPorts;
}
 
Example #27
Source File: StandardFlowSynchronizer.java    From nifi with Apache License 2.0 5 votes vote down vote up
private void addLabels(final Element processGroupElement, final ProcessGroup processGroup, final FlowController controller) {
    final List<Element> labelNodeList = getChildrenByTagName(processGroupElement, "label");
    for (final Element labelElement : labelNodeList) {
        final LabelDTO labelDTO = FlowFromDOMFactory.getLabel(labelElement);
        final Label label = controller.getFlowManager().createLabel(labelDTO.getId(), labelDTO.getLabel());
        label.setVersionedComponentId(labelDTO.getVersionedComponentId());
        label.setStyle(labelDTO.getStyle());

        label.setPosition(toPosition(labelDTO.getPosition()));
        label.setSize(new Size(labelDTO.getWidth(), labelDTO.getHeight()));
        processGroup.addLabel(label);
    }
}
 
Example #28
Source File: NiFiRegistryFlowMapper.java    From nifi with Apache License 2.0 5 votes vote down vote up
private InstantiatedVersionedProcessGroup mapGroup(final ProcessGroup group, final ControllerServiceProvider serviceProvider,
                                                   final BiFunction<ProcessGroup, VersionedProcessGroup, Boolean> applyVersionControlInfo) {
    final Set<String> allIncludedGroupsIds = group.findAllProcessGroups().stream()
            .map(ProcessGroup::getIdentifier)
            .collect(Collectors.toSet());
    allIncludedGroupsIds.add(group.getIdentifier());

    final Map<String, ExternalControllerServiceReference> externalControllerServiceReferences = new HashMap<>();
    final InstantiatedVersionedProcessGroup versionedGroup =
            mapGroup(group, serviceProvider, applyVersionControlInfo, true, allIncludedGroupsIds, externalControllerServiceReferences);

    populateReferencedAncestorVariables(group, versionedGroup);

    return versionedGroup;
}
 
Example #29
Source File: ComponentCountTask.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public DiagnosticsDumpElement captureDump(final boolean verbose) {
    final List<String> details = new ArrayList<>();

    final ProcessGroup processGroup = flowController.getFlowManager().getRootGroup();
    details.add("Processors:");
    countProcessors(processGroup.findAllProcessors(), details);

    details.add("\n\nController Services:");
    countControllerServices(processGroup.findAllControllerServices(), details);

    return new StandardDiagnosticsDumpElement("Component Counts", details);
}
 
Example #30
Source File: TestProcessorLifecycle.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Validates that processor can be stopped before start sequence finished.
 */
@Test
public void validateProcessorUnscheduledAndStoppedWhenStopIsCalledBeforeProcessorFullyStarted() throws Exception {
    fc = this.buildFlowControllerForTest();
    ProcessGroup testGroup = fc.createProcessGroup(UUID.randomUUID().toString());
    this.setControllerRootGroup(fc, testGroup);
    ProcessorNode testProcNode = fc.createProcessor(TestProcessor.class.getName(), UUID.randomUUID().toString());
    testProcNode.setProperties(properties);
    TestProcessor testProcessor = (TestProcessor) testProcNode.getProcessor();

    // sets the scenario for the processor to run
    int delay = 2000;
    this.longRunningOnSchedule(testProcessor, delay);
    ProcessScheduler ps = fc.getProcessScheduler();

    ps.startProcessor(testProcNode);
    Thread.sleep(1000);
    assertTrue(testProcNode.getPhysicalScheduledState() == ScheduledState.STARTING);
    assertTrue(testProcNode.getScheduledState() == ScheduledState.RUNNING);

    ps.stopProcessor(testProcNode);
    Thread.sleep(100);
    assertTrue(testProcNode.getPhysicalScheduledState() == ScheduledState.STOPPING);
    assertTrue(testProcNode.getScheduledState() == ScheduledState.STOPPED);
    Thread.sleep(1000);
    assertTrue(testProcNode.getScheduledState() == ScheduledState.STOPPED);

    assertEquals(2, testProcessor.operationNames.size());
    assertEquals("@OnScheduled", testProcessor.operationNames.get(0));
    assertEquals("@OnUnscheduled", testProcessor.operationNames.get(1));
}