org.apache.nifi.web.api.dto.ProcessGroupDTO Java Examples

The following examples show how to use org.apache.nifi.web.api.dto.ProcessGroupDTO. 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: FlowController.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the process group corresponding to the specified DTO. Any field
 * in DTO that is <code>null</code> (with the exception of the required ID)
 * will be ignored.
 *
 * @param dto group
 * @throws ProcessorInstantiationException
 *
 * @throws IllegalStateException if no process group can be found with the
 * ID of DTO or with the ID of the DTO's parentGroupId, if the template ID
 * specified is invalid, or if the DTO's Parent Group ID changes but the
 * parent group has incoming or outgoing connections
 *
 * @throws NullPointerException if the DTO or its ID is null
 */
public void updateProcessGroup(final ProcessGroupDTO dto) throws ProcessorInstantiationException {
    final ProcessGroup group = lookupGroup(requireNonNull(dto).getId());

    final String name = dto.getName();
    final PositionDTO position = dto.getPosition();
    final String comments = dto.getComments();

    if (name != null) {
        group.setName(name);
    }
    if (position != null) {
        group.setPosition(toPosition(position));
    }
    if (comments != null) {
        group.setComments(comments);
    }
}
 
Example #2
Source File: StandardProcessGroupDAO.java    From localization_nifi with Apache License 2.0 6 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();

    if (isNotNull(name)) {
        group.setName(name);
    }
    if (isNotNull(processGroupDTO.getPosition())) {
        group.setPosition(new Position(processGroupDTO.getPosition().getX(), processGroupDTO.getPosition().getY()));
    }
    if (isNotNull(comments)) {
        group.setComments(comments);
    }

    return group;
}
 
Example #3
Source File: StandardProcessGroupDAO.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public ProcessGroup createProcessGroup(String parentGroupId, ProcessGroupDTO processGroup) {
    if (processGroup.getParentGroupId() != null && !flowController.areGroupsSame(processGroup.getParentGroupId(), parentGroupId)) {
        throw new IllegalArgumentException("Cannot specify a different Parent Group ID than the Group to which the Process Group is being added.");
    }

    // get the parent group
    ProcessGroup parentGroup = locateProcessGroup(flowController, parentGroupId);

    // create the process group
    ProcessGroup group = flowController.createProcessGroup(processGroup.getId());
    group.setName(processGroup.getName());
    if (processGroup.getPosition() != null) {
        group.setPosition(new Position(processGroup.getPosition().getX(), processGroup.getPosition().getY()));
    }

    // add the process group
    group.setParent(parentGroup);
    parentGroup.addProcessGroup(group);

    return group;
}
 
Example #4
Source File: TemplateUtils.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Scrubs process groups prior to saving.
 *
 * @param processGroups groups
 */
private static void scrubProcessGroups(final Set<ProcessGroupDTO> processGroups) {
    // go through each process group
    for (final ProcessGroupDTO processGroupDTO : processGroups) {
        processGroupDTO.setActiveRemotePortCount(null);
        processGroupDTO.setDisabledCount(null);
        processGroupDTO.setInactiveRemotePortCount(null);
        processGroupDTO.setLocalInputPortCount(null);
        processGroupDTO.setPublicInputPortCount(null);
        processGroupDTO.setInvalidCount(null);
        processGroupDTO.setLocalOutputPortCount(null);
        processGroupDTO.setPublicOutputPortCount(null);
        processGroupDTO.setRunningCount(null);
        processGroupDTO.setStoppedCount(null);
        processGroupDTO.setUpToDateCount(null);
        processGroupDTO.setLocallyModifiedCount(null);
        processGroupDTO.setStaleCount(null);
        processGroupDTO.setLocallyModifiedAndStaleCount(null);
        processGroupDTO.setSyncFailureCount(null);
        processGroupDTO.setVersionControlInformation(null);
        processGroupDTO.setParameterContext(null);

        scrubSnippet(processGroupDTO.getContents());
    }
}
 
Example #5
Source File: StandardSnippetDAO.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
private void lookupSensitiveProperties(final FlowSnippetDTO snippet) {
    // ensure that contents have been specified
    if (snippet != null) {
        // go through each processor if specified
        if (snippet.getProcessors() != null) {
            lookupSensitiveProcessorProperties(snippet.getProcessors());
        }

        if (snippet.getControllerServices() != null) {
            lookupSensitiveControllerServiceProperties(snippet.getControllerServices());
        }

        // go through each process group if specified
        if (snippet.getProcessGroups() != null) {
            for (final ProcessGroupDTO group : snippet.getProcessGroups()) {
                lookupSensitiveProperties(group.getContents());
            }
        }
    }
}
 
Example #6
Source File: NiFiClientUtil.java    From nifi with Apache License 2.0 6 votes vote down vote up
private void waitForProcessorsStopped(final ProcessGroupDTO group) throws IOException, NiFiClientException {
    final FlowSnippetDTO groupContents = group.getContents();
    if (groupContents == null) {
        return;
    }

    for (final ProcessorDTO processor : groupContents.getProcessors()) {
        try {
            waitForStoppedProcessor(processor.getId());
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new NiFiClientException("Interrupted while waiting for Processor with ID " + processor.getId() + " to stop");
        }
    }

    for (final ProcessGroupDTO child : groupContents.getProcessGroups()) {
        waitForProcessorsStopped(child);
    }
}
 
Example #7
Source File: FlowResource.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Populates the remaining content of the specified snippet.
 */
private FlowDTO populateRemainingFlowStructure(FlowDTO flowStructure) {
    processorResource.populateRemainingProcessorEntitiesContent(flowStructure.getProcessors());
    connectionResource.populateRemainingConnectionEntitiesContent(flowStructure.getConnections());
    inputPortResource.populateRemainingInputPortEntitiesContent(flowStructure.getInputPorts());
    outputPortResource.populateRemainingOutputPortEntitiesContent(flowStructure.getOutputPorts());
    remoteProcessGroupResource.populateRemainingRemoteProcessGroupEntitiesContent(flowStructure.getRemoteProcessGroups());
    funnelResource.populateRemainingFunnelEntitiesContent(flowStructure.getFunnels());
    labelResource.populateRemainingLabelEntitiesContent(flowStructure.getLabels());
    processGroupResource.populateRemainingProcessGroupEntitiesContent(flowStructure.getProcessGroups());

    // go through each process group child and populate its uri
    for (final ProcessGroupEntity processGroupEntity : flowStructure.getProcessGroups()) {
        final ProcessGroupDTO processGroup = processGroupEntity.getComponent();
        if (processGroup != null) {
            processGroup.setContents(null);
        }
    }

    return flowStructure;
}
 
Example #8
Source File: StandardFlowSynchronizer.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
private static boolean isEmpty(final ProcessGroupDTO dto) {
    if (dto == null) {
        return true;
    }

    final FlowSnippetDTO contents = dto.getContents();
    if (contents == null) {
        return true;
    }

    return CollectionUtils.isEmpty(contents.getProcessors())
            && CollectionUtils.isEmpty(contents.getConnections())
            && CollectionUtils.isEmpty(contents.getFunnels())
            && CollectionUtils.isEmpty(contents.getLabels())
            && CollectionUtils.isEmpty(contents.getOutputPorts())
            && CollectionUtils.isEmpty(contents.getProcessGroups())
            && CollectionUtils.isEmpty(contents.getProcessors())
            && CollectionUtils.isEmpty(contents.getRemoteProcessGroups());
}
 
Example #9
Source File: StandardFlowSynchronizer.java    From nifi with Apache License 2.0 6 votes vote down vote up
private void addVersionControlInfo(final ProcessGroup processGroup, final ProcessGroupDTO processGroupDTO, final FlowController flowController) {
    final VersionControlInformationDTO versionControlInfoDto = processGroupDTO.getVersionControlInformation();
    if (versionControlInfoDto != null) {
        final FlowRegistry flowRegistry = flowController.getFlowRegistryClient().getFlowRegistry(versionControlInfoDto.getRegistryId());
        final String registryName = flowRegistry == null ? versionControlInfoDto.getRegistryId() : flowRegistry.getName();

        versionControlInfoDto.setState(VersionedFlowState.SYNC_FAILURE.name());
        versionControlInfoDto.setStateExplanation("Process Group has not yet been synchronized with the Flow Registry");
        final StandardVersionControlInformation versionControlInformation = StandardVersionControlInformation.Builder.fromDto(versionControlInfoDto)
            .registryName(registryName)
            .build();

        // pass empty map for the version control mapping because the VersionedComponentId has already been set on the components
        processGroup.setVersionControlInformation(versionControlInformation, Collections.emptyMap());
    }
}
 
Example #10
Source File: StandardFlowSynchronizer.java    From nifi with Apache License 2.0 6 votes vote down vote up
private static boolean isEmpty(final ProcessGroupDTO dto) {
    if (dto == null) {
        return true;
    }

    final FlowSnippetDTO contents = dto.getContents();
    if (contents == null) {
        return true;
    }

    final String parameterContextId = dto.getParameterContext() == null ? null : dto.getParameterContext().getId();

    return CollectionUtils.isEmpty(contents.getProcessors())
            && CollectionUtils.isEmpty(contents.getConnections())
            && CollectionUtils.isEmpty(contents.getFunnels())
            && CollectionUtils.isEmpty(contents.getLabels())
            && CollectionUtils.isEmpty(contents.getInputPorts())
            && CollectionUtils.isEmpty(contents.getOutputPorts())
            && CollectionUtils.isEmpty(contents.getProcessGroups())
            && CollectionUtils.isEmpty(contents.getRemoteProcessGroups())
            && parameterContextId == null;
}
 
Example #11
Source File: TemplateUtils.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Scrubs process groups prior to saving.
 *
 * @param processGroups groups
 */
private static void scrubProcessGroups(final Set<ProcessGroupDTO> processGroups) {
    // go through each process group
    for (final ProcessGroupDTO processGroupDTO : processGroups) {
        processGroupDTO.setActiveRemotePortCount(null);
        processGroupDTO.setDisabledCount(null);
        processGroupDTO.setInactiveRemotePortCount(null);
        processGroupDTO.setInputPortCount(null);
        processGroupDTO.setInvalidCount(null);
        processGroupDTO.setOutputPortCount(null);
        processGroupDTO.setRunningCount(null);
        processGroupDTO.setStoppedCount(null);

        scrubSnippet(processGroupDTO.getContents());
    }
}
 
Example #12
Source File: StandardSnippetDAO.java    From nifi with Apache License 2.0 6 votes vote down vote up
private void lookupSensitiveProperties(final FlowSnippetDTO snippet) {
    // ensure that contents have been specified
    if (snippet != null) {
        // go through each processor if specified
        if (snippet.getProcessors() != null) {
            lookupSensitiveProcessorProperties(snippet.getProcessors());
        }

        if (snippet.getControllerServices() != null) {
            lookupSensitiveControllerServiceProperties(snippet.getControllerServices());
        }

        // go through each process group if specified
        if (snippet.getProcessGroups() != null) {
            for (final ProcessGroupDTO group : snippet.getProcessGroups()) {
                lookupSensitiveProperties(group.getContents());
            }
        }
    }
}
 
Example #13
Source File: PGGetParamContext.java    From nifi with Apache License 2.0 6 votes vote down vote up
private String getParamContextId(final ProcessGroupDTO processGroup) {
    if (processGroup == null) {
        return "";
    }

    final ParameterContextReferenceEntity parameterContextReference = processGroup.getParameterContext();
    if (parameterContextReference == null) {
        return "";
    }

    final String paramContextId = parameterContextReference.getId();
    if (StringUtils.isBlank(paramContextId)) {
        return "";
    }

    return paramContextId;
}
 
Example #14
Source File: PGSetParamContext.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public VoidResult doExecute(final NiFiClient client, final Properties properties)
        throws NiFiClientException, IOException, MissingOptionException, CommandException {

    final String pgId = getRequiredArg(properties, CommandOption.PG_ID);
    final String paramContextId = getRequiredArg(properties, CommandOption.PARAM_CONTEXT_ID);

    final ProcessGroupClient pgClient = client.getProcessGroupClient();
    final ProcessGroupEntity pgEntity = pgClient.getProcessGroup(pgId);

    final ParameterContextReferenceEntity parameterContextReference = new ParameterContextReferenceEntity();
    parameterContextReference.setId(paramContextId);

    final ProcessGroupDTO updatedDTO = new ProcessGroupDTO();
    updatedDTO.setId(pgId);
    updatedDTO.setParameterContext(parameterContextReference);

    final ProcessGroupEntity updatedEntity = new ProcessGroupEntity();
    updatedEntity.setId(pgId);
    updatedEntity.setComponent(updatedDTO);
    updatedEntity.setRevision(pgEntity.getRevision());

    pgClient.updateProcessGroup(updatedEntity);
    return VoidResult.getInstance();
}
 
Example #15
Source File: PGCreate.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public StringResult doExecute(final NiFiClient client, final Properties properties)
        throws NiFiClientException, IOException, MissingOptionException {

    final String processGroupName = getRequiredArg(properties, CommandOption.PG_NAME);

    final FlowClient flowClient = client.getFlowClient();
    final ProcessGroupClient pgClient = client.getProcessGroupClient();
    final String rootPgId = flowClient.getRootGroupId();

    final ProcessGroupDTO processGroupDTO = new ProcessGroupDTO();
    processGroupDTO.setParentGroupId(rootPgId);
    processGroupDTO.setName(processGroupName);

    final ProcessGroupEntity pgEntity = new ProcessGroupEntity();
    pgEntity.setComponent(processGroupDTO);
    pgEntity.setRevision(getInitialRevisionDTO());

    final ProcessGroupEntity createdEntity = pgClient.createProcessGroup(
            rootPgId, pgEntity);

    return new StringResult(createdEntity.getId(), getContext().isInteractive());
}
 
Example #16
Source File: PGList.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public ProcessGroupsResult doExecute(final NiFiClient client, final Properties properties)
        throws NiFiClientException, IOException {

    final FlowClient flowClient = client.getFlowClient();

    // get the optional id of the parent PG, otherwise fallback to the root group
    String parentPgId = getArg(properties, CommandOption.PG_ID);
    if (StringUtils.isBlank(parentPgId)) {
        parentPgId = flowClient.getRootGroupId();
    }

    final ProcessGroupFlowEntity processGroupFlowEntity = flowClient.getProcessGroup(parentPgId);
    final ProcessGroupFlowDTO processGroupFlowDTO = processGroupFlowEntity.getProcessGroupFlow();
    final FlowDTO flowDTO = processGroupFlowDTO.getFlow();

    final List<ProcessGroupDTO> processGroups = new ArrayList<>();
    if (flowDTO.getProcessGroups() != null) {
        flowDTO.getProcessGroups().stream().map(pge -> pge.getComponent()).forEach(dto -> processGroups.add(dto));
    }

    return new ProcessGroupsResult(getResultType(properties), processGroups);
}
 
Example #17
Source File: FlowResource.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Populates the remaining content of the specified snippet.
 */
private FlowDTO populateRemainingFlowStructure(FlowDTO flowStructure) {
    processorResource.populateRemainingProcessorEntitiesContent(flowStructure.getProcessors());
    connectionResource.populateRemainingConnectionEntitiesContent(flowStructure.getConnections());
    inputPortResource.populateRemainingInputPortEntitiesContent(flowStructure.getInputPorts());
    outputPortResource.populateRemainingOutputPortEntitiesContent(flowStructure.getOutputPorts());
    remoteProcessGroupResource.populateRemainingRemoteProcessGroupEntitiesContent(flowStructure.getRemoteProcessGroups());
    funnelResource.populateRemainingFunnelEntitiesContent(flowStructure.getFunnels());
    labelResource.populateRemainingLabelEntitiesContent(flowStructure.getLabels());
    processGroupResource.populateRemainingProcessGroupEntitiesContent(flowStructure.getProcessGroups());

    // go through each process group child and populate its uri
    for (final ProcessGroupEntity processGroupEntity : flowStructure.getProcessGroups()) {
        final ProcessGroupDTO processGroup = processGroupEntity.getComponent();
        if (processGroup != null) {
            processGroup.setContents(null);
        }
    }

    return flowStructure;
}
 
Example #18
Source File: ProcessGroupEntityMerger.java    From nifi with Apache License 2.0 6 votes vote down vote up
private void mergeVersionControlInformation(ProcessGroupEntity targetGroup, ProcessGroupEntity toMerge) {
    final ProcessGroupDTO targetGroupDto = targetGroup.getComponent();
    final ProcessGroupDTO toMergeGroupDto = toMerge.getComponent();
    if (targetGroupDto == null || toMergeGroupDto == null) {
        return;
    }

    final VersionControlInformationDTO targetVersionControl = targetGroupDto.getVersionControlInformation();
    final VersionControlInformationDTO toMergeVersionControl = toMergeGroupDto.getVersionControlInformation();

    if (targetVersionControl == null) {
        targetGroupDto.setVersionControlInformation(toMergeGroupDto.getVersionControlInformation());
    } else if (toMergeVersionControl != null) {
        VersionControlInformationEntityMerger.updateFlowState(targetVersionControl, toMergeVersionControl);
    }
}
 
Example #19
Source File: ProcessGroupEntityMerger.java    From nifi with Apache License 2.0 6 votes vote down vote up
private static void mergeDtos(final ProcessGroupDTO clientDto, final Map<NodeIdentifier, ProcessGroupDTO> dtoMap) {
    // if unauthorized for the client dto, simple return
    if (clientDto == null) {
        return;
    }

    // get the parameter context if configured
    final ParameterContextReferenceEntity clientParameterContextEntity = clientDto.getParameterContext();

    // if this process group is bound to a parameter context, merge the permissions from the other nodes
    if (clientParameterContextEntity != null) {
        for (Map.Entry<NodeIdentifier, ProcessGroupDTO> entry : dtoMap.entrySet()) {
            final ProcessGroupDTO dto = entry.getValue();
            final ParameterContextReferenceEntity parameterContextReferenceEntity = dto.getParameterContext();

            PermissionsDtoMerger.mergePermissions(clientParameterContextEntity.getPermissions(), parameterContextReferenceEntity.getPermissions());
        }
    }
}
 
Example #20
Source File: ProcessGroupEntityMerger.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public void merge(ProcessGroupEntity clientEntity, Map<NodeIdentifier, ProcessGroupEntity> entityMap) {
    ComponentEntityMerger.super.merge(clientEntity, entityMap);

    final Map<NodeIdentifier, ProcessGroupDTO> dtoMap = new HashMap<>();
    for (Map.Entry<NodeIdentifier, ProcessGroupEntity> entry : entityMap.entrySet()) {
        final ProcessGroupEntity entity = entry.getValue();
        if (entity != clientEntity) {
            mergeStatus(clientEntity.getStatus(), clientEntity.getPermissions().getCanRead(), entry.getValue().getStatus(), entry.getValue().getPermissions().getCanRead(), entry.getKey());
            mergeVersionControlInformation(clientEntity, entity);
        }

        dtoMap.put(entry.getKey(), entity.getComponent());
    }

    mergeDtos(clientEntity.getComponent(), dtoMap);
}
 
Example #21
Source File: NiFiClientUtil.java    From nifi with Apache License 2.0 5 votes vote down vote up
public ProcessGroupEntity createProcessGroup(final String name, final String parentGroupId) throws NiFiClientException, IOException {
    final ProcessGroupDTO component = new ProcessGroupDTO();
    component.setName(name);
    component.setParentGroupId(parentGroupId);

    final ProcessGroupEntity childGroupEntity = new ProcessGroupEntity();
    childGroupEntity.setRevision(createNewRevision());
    childGroupEntity.setComponent(component);

    final ProcessGroupEntity childGroup = nifiClient.getProcessGroupClient().createProcessGroup(parentGroupId, childGroupEntity);
    return childGroup;
}
 
Example #22
Source File: TemplateUtils.java    From nifi with Apache License 2.0 5 votes vote down vote up
private static void escapeParameterReferences(final FlowSnippetDTO flowSnippetDTO) {
    flowSnippetDTO.getProcessors().forEach(TemplateUtils::escapeParameterReferences);
    flowSnippetDTO.getControllerServices().forEach(TemplateUtils::escapeParameterReferences);

    for (final ProcessGroupDTO groupDto : flowSnippetDTO.getProcessGroups()) {
        escapeParameterReferences(groupDto.getContents());
    }
}
 
Example #23
Source File: StandardProcessGroupDAO.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void verifyUpdate(final ProcessGroupDTO processGroup) {
    final ParameterContextReferenceEntity parameterContextReference = processGroup.getParameterContext();
    if (parameterContextReference == null) {
        return;
    }

    final ParameterContext parameterContext = locateParameterContext(parameterContextReference.getId());
    final ProcessGroup group = locateProcessGroup(flowController, processGroup.getId());
    group.verifyCanSetParameterContext(parameterContext);
}
 
Example #24
Source File: StandardProcessGroupDAO.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public ProcessGroup createProcessGroup(String parentGroupId, ProcessGroupDTO processGroup) {
    final FlowManager flowManager = flowController.getFlowManager();
    if (processGroup.getParentGroupId() != null && !flowManager.areGroupsSame(processGroup.getParentGroupId(), parentGroupId)) {
        throw new IllegalArgumentException("Cannot specify a different Parent Group ID than the Group to which the Process Group is being added.");
    }

    // get the parent group
    ProcessGroup parentGroup = locateProcessGroup(flowController, parentGroupId);

    // create the process group
    ProcessGroup group = flowManager.createProcessGroup(processGroup.getId());
    if (processGroup.getName() != null) {
        group.setName(processGroup.getName());
    }
    if (processGroup.getPosition() != null) {
        group.setPosition(new Position(processGroup.getPosition().getX(), processGroup.getPosition().getY()));
    }

    final ParameterContextReferenceEntity parameterContextReference = processGroup.getParameterContext();
    if (parameterContextReference != null && parameterContextReference.getId() != null) {
        final ParameterContext parameterContext = flowController.getFlowManager().getParameterContextManager().getParameterContext(parameterContextReference.getId());
        group.setParameterContext(parameterContext);
    }

    // add the process group
    group.setParent(parentGroup);
    parentGroup.addProcessGroup(group);

    return group;
}
 
Example #25
Source File: StandardTemplateDAO.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public FlowSnippetDTO instantiateTemplate(String groupId, Double originX, Double originY, String encodingVersion,
                                          FlowSnippetDTO requestSnippet, String idGenerationSeed) {

    ProcessGroup group = locateProcessGroup(flowController, groupId);

    try {
        // copy the template which pre-processes all ids
        FlowSnippetDTO snippet = snippetUtils.copy(requestSnippet, group, idGenerationSeed, false);

        // calculate scaling factors based on the template encoding version attempt to parse the encoding version.
        // get the major version, or 0 if no version could be parsed
        final FlowEncodingVersion templateEncodingVersion = FlowEncodingVersion.parse(encodingVersion);
        int templateEncodingMajorVersion = templateEncodingVersion != null ? templateEncodingVersion.getMajorVersion() : 0;

        // based on the major version < 1, use the default scaling factors.  Otherwise, don't scale (use factor of 1.0)
        double factorX = templateEncodingMajorVersion < 1 ? FlowController.DEFAULT_POSITION_SCALE_FACTOR_X : 1.0;
        double factorY = templateEncodingMajorVersion < 1 ? FlowController.DEFAULT_POSITION_SCALE_FACTOR_Y : 1.0;

        // reposition and scale the template contents
        org.apache.nifi.util.SnippetUtils.moveAndScaleSnippet(snippet, originX, originY, factorX, factorY);

        // find all the child process groups in each process group in the top level of this snippet
        final List<ProcessGroupDTO> childProcessGroups  = org.apache.nifi.util.SnippetUtils.findAllProcessGroups(snippet);
        // scale (but don't reposition) child process groups
        childProcessGroups.forEach(processGroup -> org.apache.nifi.util.SnippetUtils.scaleSnippet(processGroup.getContents(), factorX, factorY));

        // instantiate the template into this group
        flowController.getFlowManager().instantiateSnippet(group, snippet);

        return snippet;
    } catch (ProcessorInstantiationException pie) {
        throw new NiFiCoreException(String.format("Unable to instantiate template because processor type '%s' is unknown to this NiFi.",
                StringUtils.substringAfterLast(pie.getMessage(), ".")));
    }
}
 
Example #26
Source File: SnippetUtils.java    From nifi with Apache License 2.0 5 votes vote down vote up
private static void findAllVersionControlInfo(final ProcessGroupDTO dto, final List<VersionControlInformationDTO> found) {
    final VersionControlInformationDTO vci = dto.getVersionControlInformation();
    if (vci != null) {
        found.add(vci);
    }

    final FlowSnippetDTO contents = dto.getContents();
    if (contents != null) {
        for (final ProcessGroupDTO child : contents.getProcessGroups()) {
            findAllVersionControlInfo(child, found);
        }
    }
}
 
Example #27
Source File: StandardFlowServiceTest.java    From nifi with Apache License 2.0 5 votes vote down vote up
private void assertEquals(ProcessGroupDTO expected, ProcessGroupDTO actual) {
    if (expected == null && actual == null) {
        return;
    }

    Assert.assertEquals(expected.getComments(), actual.getComments());
    assertEquals(expected.getContents(), actual.getContents());
}
 
Example #28
Source File: JoinClusterWithDifferentFlow.java    From nifi with Apache License 2.0 5 votes vote down vote up
private void verifyFlowContentsOnDisk(final File backupFile) throws IOException, SAXException, ParserConfigurationException {
    // Read the flow and make sure that the backup looks the same as the original. We don't just do a byte comparison because the compression may result in different
    // gzipped bytes and because if the two flows do differ, we want to have the String representation so that we can compare to see how they are different.
    final String flowXml = readFlow(backupFile);
    final String expectedFlow = readFlow(new File("src/test/resources/flows/mismatched-flows/flow2.xml.gz"));

    assertEquals(expectedFlow, flowXml);

    // Verify some of the values that were persisted to disk
    final File confDir = backupFile.getParentFile();
    final String loadedFlow = readFlow(new File(confDir, "flow.xml.gz"));

    final DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    final Document document = documentBuilder.parse(new InputSource(new StringReader(loadedFlow)));
    final Element rootElement = (Element) document.getElementsByTagName("flowController").item(0);
    final FlowEncodingVersion encodingVersion = FlowEncodingVersion.parse(rootElement);

    final NiFiInstance node2 = getNiFiInstance().getNodeInstance(2);
    final StringEncryptor encryptor = createEncryptorFromProperties(node2.getProperties());
    final Element rootGroupElement = (Element) rootElement.getElementsByTagName("rootGroup").item(0);

    final ProcessGroupDTO groupDto = FlowFromDOMFactory.getProcessGroup(null, rootGroupElement, encryptor, encodingVersion);
    final Set<ProcessGroupDTO> childGroupDtos = groupDto.getContents().getProcessGroups();
    assertEquals(1, childGroupDtos.size());

    final ProcessGroupDTO childGroup = childGroupDtos.iterator().next();
    assertFalse(childGroup.getId().endsWith("00"));
    final FlowSnippetDTO childContents = childGroup.getContents();

    final Set<ProcessorDTO> childProcessors = childContents.getProcessors();
    assertEquals(1, childProcessors.size());

    final ProcessorDTO procDto = childProcessors.iterator().next();
    assertFalse(procDto.getId().endsWith("00"));
    assertFalse(procDto.getName().endsWith("00"));
}
 
Example #29
Source File: StandardNiFiServiceFacade.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public ProcessGroupEntity updateProcessGroup(final Revision revision, final ProcessGroupDTO processGroupDTO) {
    final ProcessGroup processGroupNode = processGroupDAO.getProcessGroup(processGroupDTO.getId());
    final RevisionUpdate<ProcessGroupDTO> snapshot = updateComponent(revision,
            processGroupNode,
            () -> processGroupDAO.updateProcessGroup(processGroupDTO),
            processGroup -> dtoFactory.createProcessGroupDto(processGroup));

    final PermissionsDTO permissions = dtoFactory.createPermissionsDto(processGroupNode);
    final RevisionDTO updatedRevision = dtoFactory.createRevisionDTO(snapshot.getLastModification());
    final ProcessGroupStatusDTO status = dtoFactory.createConciseProcessGroupStatusDto(controllerFacade.getProcessGroupStatus(processGroupNode.getIdentifier()));
    final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(processGroupNode.getIdentifier()));
    final List<BulletinEntity> bulletinEntities = bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissions.getCanRead())).collect(Collectors.toList());
    return entityFactory.createProcessGroupEntity(snapshot.getComponent(), updatedRevision, permissions, status, bulletinEntities);
}
 
Example #30
Source File: SnippetUtils.java    From nifi with Apache License 2.0 5 votes vote down vote up
private void updateControllerServiceIdentifiers(final FlowSnippetDTO snippet, final Map<String, String> serviceIdMap) {
    final Set<ProcessorDTO> processors = snippet.getProcessors();
    if (processors != null) {
        for (final ProcessorDTO processor : processors) {
            updateControllerServiceIdentifiers(processor.getConfig(), serviceIdMap);
        }
    }

    for (final ProcessGroupDTO processGroupDto : snippet.getProcessGroups()) {
        updateControllerServiceIdentifiers(processGroupDto.getContents(), serviceIdMap);
    }
}