Java Code Examples for org.apache.nifi.groups.ProcessGroup#getParent()

The following examples show how to use org.apache.nifi.groups.ProcessGroup#getParent() . 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: 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 2
Source File: SnippetUtils.java    From nifi with Apache License 2.0 6 votes vote down vote up
private static void verifyNoDuplicateVersionControlInfo(final ProcessGroup group, final Collection<VersionControlInformation> snippetVcis) {
    final VersionControlInformation vci = group.getVersionControlInformation();
    if (vci != null) {
        for (final VersionControlInformation snippetVci : snippetVcis) {
            if (vci.getBucketIdentifier().equals(snippetVci.getBucketIdentifier()) && vci.getFlowIdentifier().equals(snippetVci.getFlowIdentifier())) {
                throw new IllegalArgumentException("Cannot place the given Process Group into the desired destination because the destination group or one of its ancestor groups is "
                    + "under Version Control and one of the selected Process Groups is also under Version Control with the same Flow. A Process Group that is under Version Control "
                    + "cannot contain a child Process Group that points to the same Versioned Flow.");
            }
        }
    }

    final ProcessGroup parent = group.getParent();
    if (parent != null) {
        verifyNoDuplicateVersionControlInfo(parent, snippetVcis);
    }
}
 
Example 3
Source File: SnippetUtils.java    From nifi with Apache License 2.0 6 votes vote down vote up
private static void verifyNoDuplicateVersionControlInfoDtos(final ProcessGroup group, final Collection<VersionControlInformationDTO> snippetVcis) {
    final VersionControlInformation vci = group.getVersionControlInformation();
    if (vci != null) {
        for (final VersionControlInformationDTO snippetVci : snippetVcis) {
            if (vci.getBucketIdentifier().equals(snippetVci.getBucketId()) && vci.getFlowIdentifier().equals(snippetVci.getFlowId())) {
                throw new IllegalArgumentException("Cannot place the given Process Group into the desired destination because the destination group or one of its ancestor groups is "
                    + "under Version Control and one of the selected Process Groups is also under Version Control with the same Flow. A Process Group that is under Version Control "
                    + "cannot contain a child Process Group that points to the same Versioned Flow.");
            }
        }
    }

    final ProcessGroup parent = group.getParent();
    if (parent != null) {
        verifyNoDuplicateVersionControlInfoDtos(parent, snippetVcis);
    }
}
 
Example 4
Source File: AbstractControllerSearchIntegrationTest.java    From nifi with Apache License 2.0 6 votes vote down vote up
private ProcessGroupSetup(final ProcessGroup processGroup) {
    this.processGroup = processGroup;
    processGroups.add(this);

    if (processGroup.getParent() != null) {
        getProcessGroupSetup(processGroup.getParent().getIdentifier()).withChild(processGroup);
    }

    Mockito.when(processGroup.getInputPorts()).thenReturn(inputPorts);
    Mockito.when(processGroup.getOutputPorts()).thenReturn(outputPorts);
    Mockito.when(processGroup.getProcessors()).thenReturn(processors);
    Mockito.when(processGroup.getLabels()).thenReturn(labels);
    Mockito.when(processGroup.getRemoteProcessGroups()).thenReturn(remoteProcessGroups);
    Mockito.when(processGroup.getFunnels()).thenReturn(funnels);
    Mockito.when(processGroup.getConnections()).thenReturn(connections);
    Mockito.when(processGroup.getControllerServices(Mockito.anyBoolean())).thenReturn(controllerServiceNodes);
    Mockito.when(processGroup.getProcessGroups()).thenReturn(children);
}
 
Example 5
Source File: AbstractComponentSearchResultEnricher.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Builds the nearest versioned parent result group for a given user.
 *
 * @param group The containing group
 * @param user The current NiFi user
 * @return Versioned parent group
 */
protected SearchResultGroupDTO buildVersionedGroup(final ProcessGroup group, final NiFiUser user) {
    if (group == null) {
        return null;
    }

    ProcessGroup current = group;

    // search for a versioned group by traversing the group tree up to the root
    while (!current.isRootGroup()) {
        if (current.getVersionControlInformation() != null) {
            return buildResultGroup(current, user);
        }

        current = current.getParent();
    }

    // traversed all the way to the root
    return null;
}
 
Example 6
Source File: ControllerFacade.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
private ComponentSearchResultDTO search(final String searchStr, final ProcessGroup group) {
    final List<String> matches = new ArrayList<>();
    final ProcessGroup parent = group.getParent();
    if (parent == null) {
        return null;
    }

    addIfAppropriate(searchStr, group.getIdentifier(), "Id", matches);
    addIfAppropriate(searchStr, group.getName(), "Name", matches);
    addIfAppropriate(searchStr, group.getComments(), "Comments", matches);

    if (matches.isEmpty()) {
        return null;
    }

    final ComponentSearchResultDTO result = new ComponentSearchResultDTO();
    result.setId(group.getIdentifier());
    result.setName(group.getName());
    result.setGroupId(parent.getIdentifier());
    result.setMatches(matches);
    return result;
}
 
Example 7
Source File: DtoFactory.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a FlowBreadcrumbEntity from the specified parent ProcessGroup.
 *
 * @param group group
 * @return dto
 */
private FlowBreadcrumbEntity createBreadcrumbEntity(final ProcessGroup group) {
    if (group == null) {
        return null;
    }

    final FlowBreadcrumbDTO dto = createBreadcrumbDto(group);
    final PermissionsDTO permissions = createPermissionsDto(group);
    final FlowBreadcrumbEntity entity = entityFactory.createFlowBreadcrumbEntity(dto, permissions);

    if (group.getParent() != null) {
        entity.setParentBreadcrumb(createBreadcrumbEntity(group.getParent()));
    }

    return entity;
}
 
Example 8
Source File: StandardProcessGroupDAO.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteProcessGroup(String processGroupId) {
    // get the group
    ProcessGroup group = locateProcessGroup(flowController, processGroupId);
    ProcessGroup parentGroup = group.getParent();

    // ensure this isn't the root group
    if (parentGroup == null) {
        throw new IllegalArgumentException("The Root Group cannot be removed");
    }

    // remove the group
    parentGroup.removeProcessGroup(group);
}
 
Example 9
Source File: StandardOutputPortDAO.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Port createPort(String groupId, PortDTO portDTO) {
    if (isNotNull(portDTO.getParentGroupId()) && !flowController.areGroupsSame(groupId, portDTO.getParentGroupId())) {
        throw new IllegalArgumentException("Cannot specify a different Parent Group ID than the Group to which the OutputPort is being added.");
    }

    // ensure the name has been specified
    if (portDTO.getName() == null) {
        throw new IllegalArgumentException("Port name must be specified.");
    }

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

    // determine if this is the root group
    Port port;
    if (group.getParent() == null) {
        port = flowController.createRemoteOutputPort(portDTO.getId(), portDTO.getName());
    } else {
        port = flowController.createLocalOutputPort(portDTO.getId(), portDTO.getName());
    }

    // ensure we can perform the update before we add the processor to the flow
    verifyUpdate(port, portDTO);

    // configure
    if (portDTO.getPosition() != null) {
        port.setPosition(new Position(portDTO.getPosition().getX(), portDTO.getPosition().getY()));
    }
    port.setComments(portDTO.getComments());

    // add the port
    group.addOutputPort(port);
    return port;
}
 
Example 10
Source File: BulletinFactory.java    From nifi with Apache License 2.0 5 votes vote down vote up
private static String buildGroupPath(ProcessGroup group) {
    if(group == null) {
        return null;
    } else {
        String path = group.getName();
        ProcessGroup parent = group.getParent();
        while(parent != null) {
            path = parent.getName() + " / " + path;
            parent = parent.getParent();
        }
        return path;
    }
}
 
Example 11
Source File: ControllerSearchService.java    From nifi with Apache License 2.0 5 votes vote down vote up
private List<ProcessGroup> getLineage(final ProcessGroup group) {
    final LinkedList<ProcessGroup> result = new LinkedList<>();
    ProcessGroup current = group;

    while (current != null) {
        result.addLast(current);
        current = current.getParent();
    }

    return result;
}
 
Example 12
Source File: StandardInputPortDAO.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Port createPort(String groupId, PortDTO portDTO) {
    if (isNotNull(portDTO.getParentGroupId()) && !flowController.getFlowManager().areGroupsSame(groupId, portDTO.getParentGroupId())) {
        throw new IllegalArgumentException("Cannot specify a different Parent Group ID than the Group to which the InputPort is being added.");
    }

    // ensure the name has been specified
    if (portDTO.getName() == null) {
        throw new IllegalArgumentException("Port name must be specified.");
    }

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

    // determine if this is the root group
    Port port;
    if (group.getParent() == null || Boolean.TRUE.equals(portDTO.getAllowRemoteAccess())) {
        port = flowController.getFlowManager().createPublicInputPort(portDTO.getId(), portDTO.getName());
    } else {
        port = flowController.getFlowManager().createLocalInputPort(portDTO.getId(), portDTO.getName());
    }

    // Unique public port check among all groups.
    if (port instanceof PublicPort) {
        verifyPublicPortUniqueness(port.getIdentifier(), port.getName());
    }

    // ensure we can perform the update before we add the port to the flow
    verifyUpdate(port, portDTO);

    // configure
    if (portDTO.getPosition() != null) {
        port.setPosition(new Position(portDTO.getPosition().getX(), portDTO.getPosition().getY()));
    }
    port.setComments(portDTO.getComments());

    // add the port
    group.addInputPort(port);
    return port;
}
 
Example 13
Source File: StandardProcessGroupDAO.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteProcessGroup(String processGroupId) {
    // get the group
    ProcessGroup group = locateProcessGroup(flowController, processGroupId);
    ProcessGroup parentGroup = group.getParent();

    // ensure this isn't the root group
    if (parentGroup == null) {
        throw new IllegalArgumentException("The Root Group cannot be removed");
    }

    // remove the group
    parentGroup.removeProcessGroup(group);
}
 
Example 14
Source File: StandardOutputPortDAO.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Port createPort(String groupId, PortDTO portDTO) {
    if (isNotNull(portDTO.getParentGroupId()) && !flowController.getFlowManager().areGroupsSame(groupId, portDTO.getParentGroupId())) {
        throw new IllegalArgumentException("Cannot specify a different Parent Group ID than the Group to which the OutputPort is being added.");
    }

    // ensure the name has been specified
    if (portDTO.getName() == null) {
        throw new IllegalArgumentException("Port name must be specified.");
    }

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

    // determine if this is the root group
    Port port;
    if (group.getParent() == null || Boolean.TRUE.equals(portDTO.getAllowRemoteAccess())) {
        port = flowController.getFlowManager().createPublicOutputPort(portDTO.getId(), portDTO.getName());
    } else {
        port = flowController.getFlowManager().createLocalOutputPort(portDTO.getId(), portDTO.getName());
    }

    // Unique public port check among all groups.
    if (port instanceof PublicPort) {
        verifyPublicPortUniqueness(port.getIdentifier(), port.getName());
    }

    // ensure we can perform the update before we add the port to the flow
    verifyUpdate(port, portDTO);

    // configure
    if (portDTO.getPosition() != null) {
        port.setPosition(new Position(portDTO.getPosition().getX(), portDTO.getPosition().getY()));
    }
    port.setComments(portDTO.getComments());

    // add the port
    group.addOutputPort(port);
    return port;
}
 
Example 15
Source File: StandardInputPortDAO.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Port createPort(String groupId, PortDTO portDTO) {
    if (isNotNull(portDTO.getParentGroupId()) && !flowController.areGroupsSame(groupId, portDTO.getParentGroupId())) {
        throw new IllegalArgumentException("Cannot specify a different Parent Group ID than the Group to which the InputPort is being added.");
    }

    // ensure the name has been specified
    if (portDTO.getName() == null) {
        throw new IllegalArgumentException("Port name must be specified.");
    }

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

    // determine if this is the root group
    Port port;
    if (group.getParent() == null) {
        port = flowController.createRemoteInputPort(portDTO.getId(), portDTO.getName());
    } else {
        port = flowController.createLocalInputPort(portDTO.getId(), portDTO.getName());
    }

    // ensure we can perform the update before we add the processor to the flow
    verifyUpdate(port, portDTO);

    // configure
    if (portDTO.getPosition() != null) {
        port.setPosition(new Position(portDTO.getPosition().getX(), portDTO.getPosition().getY()));
    }
    port.setComments(portDTO.getComments());

    // add the port
    group.addInputPort(port);
    return port;
}
 
Example 16
Source File: DtoFactory.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a ProcessGroupDTO from the specified ProcessGroup.
 *
 * @param group group
 * @return dto
 */
private ProcessGroupDTO createConciseProcessGroupDto(final ProcessGroup group) {
    if (group == null) {
        return null;
    }

    final ProcessGroupDTO dto = new ProcessGroupDTO();
    dto.setId(group.getIdentifier());
    dto.setPosition(createPositionDto(group.getPosition()));
    dto.setComments(group.getComments());
    dto.setName(group.getName());

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

    final ProcessGroupCounts counts = group.getCounts();
    dto.setRunningCount(counts.getRunningCount());
    dto.setStoppedCount(counts.getStoppedCount());
    dto.setInvalidCount(counts.getInvalidCount());
    dto.setDisabledCount(counts.getDisabledCount());
    dto.setInputPortCount(counts.getInputPortCount());
    dto.setOutputPortCount(counts.getOutputPortCount());
    dto.setActiveRemotePortCount(counts.getActiveRemotePortCount());
    dto.setInactiveRemotePortCount(counts.getInactiveRemotePortCount());

    return dto;
}
 
Example 17
Source File: StandardProcessGroupDAO.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
public ProcessGroup updateProcessGroup(ProcessGroupDTO processGroupDTO) {
    final ProcessGroup group = locateProcessGroup(flowController, processGroupDTO.getId());

    final String name = processGroupDTO.getName();
    final String comments = processGroupDTO.getComments();
    final String concurrencyName = processGroupDTO.getFlowfileConcurrency();
    final FlowFileConcurrency flowFileConcurrency = concurrencyName == null ? null : FlowFileConcurrency.valueOf(concurrencyName);

    final String outboundPolicyName = processGroupDTO.getFlowfileOutboundPolicy();
    final FlowFileOutboundPolicy flowFileOutboundPolicy = outboundPolicyName == null ? null : FlowFileOutboundPolicy.valueOf(outboundPolicyName);

    final ParameterContextReferenceEntity parameterContextReference = processGroupDTO.getParameterContext();
    if (parameterContextReference != null) {
        final String parameterContextId = parameterContextReference.getId();
        if (parameterContextId == null) {
            group.setParameterContext(null);
        } else {
            final ParameterContext parameterContext = flowController.getFlowManager().getParameterContextManager().getParameterContext(parameterContextId);
            if (parameterContext == null) {
                throw new IllegalStateException("Cannot set Process Group's Parameter Context because no Parameter Context exists with ID " + parameterContextId);
            }

            group.setParameterContext(parameterContext);
        }
    }

    if (isNotNull(name)) {
        group.setName(name);
    }
    if (isNotNull(processGroupDTO.getPosition())) {
        group.setPosition(new Position(processGroupDTO.getPosition().getX(), processGroupDTO.getPosition().getY()));
        final ProcessGroup parent = group.getParent();
        if (parent != null) {
            parent.onComponentModified();
        }
    }
    if (isNotNull(comments)) {
        group.setComments(comments);
    }
    if (flowFileConcurrency != null) {
        group.setFlowFileConcurrency(flowFileConcurrency);
    }
    if (flowFileOutboundPolicy != null) {
        group.setFlowFileOutboundPolicy(flowFileOutboundPolicy);
    }
    group.onComponentModified();
    return group;
}