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

The following examples show how to use org.apache.nifi.web.api.dto.FlowSnippetDTO. 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: StandardNiFiServiceFacade.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public FlowEntity copySnippet(final String groupId, final String snippetId, final Double originX, final Double originY, final String idGenerationSeed) {
    // create the new snippet
    final FlowSnippetDTO snippet = snippetDAO.copySnippet(groupId, snippetId, originX, originY, idGenerationSeed);

    // save the flow
    controllerFacade.save();

    // drop the snippet
    snippetDAO.dropSnippet(snippetId);

    // post process new flow snippet
    final FlowDTO flowDto = postProcessNewFlowSnippet(groupId, snippet);

    final FlowEntity flowEntity = new FlowEntity();
    flowEntity.setFlow(flowDto);
    return flowEntity;
}
 
Example #2
Source File: StandardFlowSnippet.java    From nifi with Apache License 2.0 6 votes vote down vote up
private void verifyProcessorsInSnippet(final FlowSnippetDTO templateContents, final Map<String, Set<BundleCoordinate>> supportedTypes) {
    if (templateContents.getProcessors() != null) {
        templateContents.getProcessors().forEach(processor -> {
            if (processor.getBundle() == null) {
                throw new IllegalArgumentException("Processor bundle must be specified.");
            }

            if (supportedTypes.containsKey(processor.getType())) {
                verifyBundleInSnippet(processor.getBundle(), supportedTypes.get(processor.getType()));
            } else {
                throw new IllegalStateException("Invalid Processor Type: " + processor.getType());
            }
        });
    }

    if (templateContents.getProcessGroups() != null) {
        templateContents.getProcessGroups().forEach(processGroup -> verifyProcessorsInSnippet(processGroup.getContents(), supportedTypes));
    }
}
 
Example #3
Source File: StandardFlowSnippet.java    From nifi with Apache License 2.0 6 votes vote down vote up
private void verifyControllerServicesInSnippet(final FlowSnippetDTO templateContents, final Map<String, Set<BundleCoordinate>> supportedTypes) {
    if (templateContents.getControllerServices() != null) {
        templateContents.getControllerServices().forEach(controllerService -> {
            if (supportedTypes.containsKey(controllerService.getType())) {
                if (controllerService.getBundle() == null) {
                    throw new IllegalArgumentException("Controller Service bundle must be specified.");
                }

                verifyBundleInSnippet(controllerService.getBundle(), supportedTypes.get(controllerService.getType()));
            } else {
                throw new IllegalStateException("Invalid Controller Service Type: " + controllerService.getType());
            }
        });
    }

    if (templateContents.getProcessGroups() != null) {
        templateContents.getProcessGroups().forEach(processGroup -> verifyControllerServicesInSnippet(processGroup.getContents(), supportedTypes));
    }
}
 
Example #4
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 #5
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 #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: AuthorizeParameterReference.java    From nifi with Apache License 2.0 6 votes vote down vote up
public static void authorizeParameterReferences(final FlowSnippetDTO flowSnippet, final Authorizer authorizer, final Authorizable parameterContextAuthorizable, final NiFiUser user) {
    for (final ProcessorDTO processorDto : flowSnippet.getProcessors()) {
        final ProcessorConfigDTO configDto = processorDto.getConfig();
        if (configDto == null) {
            continue;
        }

        authorizeParameterReferences(configDto.getProperties(), authorizer, parameterContextAuthorizable, user);
    }

    for (final ControllerServiceDTO serviceDto : flowSnippet.getControllerServices()) {
        authorizeParameterReferences(serviceDto.getProperties(), authorizer, parameterContextAuthorizable, user);
    }

    // Note: there is no need to recurse here because when a template/snippet is instantiated, if there are any components in child Process Groups, a new Process Group will be created
    // without any Parameter Context, so there is no need to perform any authorization beyond the top-level group where the instantiation is occurring.
}
 
Example #8
Source File: StandardAuthorizableLookup.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public TemplateContentsAuthorizable getTemplateContents(final FlowSnippetDTO snippet) {
    // templates are immutable so we can pre-compute all encapsulated processors and controller services
    final Set<ComponentAuthorizable> processors = new HashSet<>();
    final Set<ComponentAuthorizable> controllerServices = new HashSet<>();

    // find all processors and controller services
    final ExtensionManager extensionManager = controllerFacade.getExtensionManager();
    createTemporaryProcessorsAndControllerServices(snippet, processors, controllerServices, extensionManager);

    return new TemplateContentsAuthorizable() {
        @Override
        public Set<ComponentAuthorizable> getEncapsulatedProcessors() {
            return processors;
        }

        @Override
        public Set<ComponentAuthorizable> getEncapsulatedControllerServices() {
            return controllerServices;
        }
    };
}
 
Example #9
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 #10
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 #11
Source File: StandardNiFiServiceFacade.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public FlowEntity createTemplateInstance(final String groupId, final Double originX, final Double originY, final String templateId, final String idGenerationSeed) {
    // instantiate the template - there is no need to make another copy of the flow snippet since the actual template
    // was copied and this dto is only used to instantiate it's components (which as already completed)
    final FlowSnippetDTO snippet = templateDAO.instantiateTemplate(groupId, originX, originY, templateId, idGenerationSeed);

    // save the flow
    controllerFacade.save();

    // post process the new flow snippet
    final FlowDTO flowDto = postProcessNewFlowSnippet(groupId, snippet);

    final FlowEntity flowEntity = new FlowEntity();
    flowEntity.setFlow(flowDto);
    return flowEntity;
}
 
Example #12
Source File: TestFlowController.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testInstantiateSnippetWithControllerService() throws ProcessorInstantiationException {
    final String id = UUID.randomUUID().toString();
    final BundleCoordinate coordinate = systemBundle.getBundleDetails().getCoordinate();
    final ControllerServiceNode controllerServiceNode = controller.getFlowManager().createControllerService(ServiceA.class.getName(), id, coordinate, null, true, true);

    // create the controller service dto
    final ControllerServiceDTO csDto = new ControllerServiceDTO();
    csDto.setId(UUID.randomUUID().toString()); // use a different id
    csDto.setParentGroupId(controllerServiceNode.getProcessGroup() == null ? null : controllerServiceNode.getProcessGroup().getIdentifier());
    csDto.setName(controllerServiceNode.getName());
    csDto.setType(controllerServiceNode.getCanonicalClassName());
    csDto.setBundle(new BundleDTO(coordinate.getGroup(), coordinate.getId(), coordinate.getVersion()));
    csDto.setState(controllerServiceNode.getState().name());
    csDto.setAnnotationData(controllerServiceNode.getAnnotationData());
    csDto.setComments(controllerServiceNode.getComments());
    csDto.setPersistsState(controllerServiceNode.getControllerServiceImplementation().getClass().isAnnotationPresent(Stateful.class));
    csDto.setRestricted(controllerServiceNode.isRestricted());
    csDto.setExtensionMissing(controllerServiceNode.isExtensionMissing());
    csDto.setDescriptors(new LinkedHashMap<>());
    csDto.setProperties(new LinkedHashMap<>());

    // create the snippet with the controller service
    final FlowSnippetDTO flowSnippetDTO = new FlowSnippetDTO();
    flowSnippetDTO.setControllerServices(Collections.singleton(csDto));

    // instantiate the snippet
    assertEquals(0, controller.getFlowManager().getRootGroup().getControllerServices(false).size());
    controller.getFlowManager().instantiateSnippet(controller.getFlowManager().getRootGroup(), flowSnippetDTO);
    assertEquals(1, controller.getFlowManager().getRootGroup().getControllerServices(false).size());
}
 
Example #13
Source File: SnippetUtils.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Finds all {@link ProcessGroupDTO}s in the given {@link FlowSnippetDTO}.
 * @param snippet containing the child {@link ProcessGroupDTO}s to be returned
 * @return List of child {@link ProcessGroupDTO}s found in the given {@link FlowSnippetDTO}.
 */
public static List<ProcessGroupDTO> findAllProcessGroups(FlowSnippetDTO snippet) {
    final List<ProcessGroupDTO> allProcessGroups = new ArrayList<>(snippet.getProcessGroups());
    for (final ProcessGroupDTO childGroup : snippet.getProcessGroups()) {
        allProcessGroups.addAll(findAllProcessGroups(childGroup.getContents()));
    }
    return allProcessGroups;
}
 
Example #14
Source File: SnippetUtils.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Scales the placement of individual components of the snippet by the
 * given factorX and factorY. Does not scale components in child process groups.
 *
 * @param snippet snippet
 * @param factorX x location scaling factor
 * @param factorY y location scaling factor
 */
public static void scaleSnippet(FlowSnippetDTO snippet, double factorX, double factorY) {
    // get the connections
    final Collection<ConnectionDTO> connections = getConnections(snippet);

    // get the components and their positions from the template contents
    final Collection<ComponentDTO> components = getComponents(snippet);

    // only perform the operation if there are components in this snippet
    if (connections.isEmpty() && components.isEmpty()) {
        return;
    }

    // get the component positions from the snippet contents
    final Map<ComponentDTO, PositionDTO> componentPositionLookup = getPositionLookup(components);
    final Map<ConnectionDTO, List<PositionDTO>> connectionPositionLookup = getConnectionPositionLookup(connections);

    // adjust all component positions
    for (final PositionDTO position : componentPositionLookup.values()) {
        position.setX(position.getX() * factorX);
        position.setY(position.getY() * factorY);
    }

    // adjust all connection positions
    for (final List<PositionDTO> bends : connectionPositionLookup.values()) {
        for (final PositionDTO bend : bends) {
            bend.setX(bend.getX() * factorX);
            bend.setY(bend.getY() * factorY);
        }
    }

    // apply the updated positions
    applyUpdatedPositions(componentPositionLookup, connectionPositionLookup);
}
 
Example #15
Source File: StandardFlowManager.java    From nifi with Apache License 2.0 5 votes vote down vote up
public void instantiateSnippet(final ProcessGroup group, final FlowSnippetDTO dto) throws ProcessorInstantiationException {
    requireNonNull(group);
    requireNonNull(dto);

    final FlowSnippet snippet = new StandardFlowSnippet(dto, flowController.getExtensionManager());
    snippet.validate(group);
    snippet.instantiate(this, group);

    group.findAllRemoteProcessGroups().forEach(RemoteProcessGroup::initialize);
}
 
Example #16
Source File: TemplateUtils.java    From nifi with Apache License 2.0 5 votes vote down vote up
private static void scrubSnippet(final FlowSnippetDTO snippet) {
    // ensure that contents have been specified
    if (snippet != null) {
        // go through each processor if specified
        if (snippet.getProcessors() != null) {
            scrubProcessors(snippet.getProcessors());
        }

        // go through each connection if specified
        if (snippet.getConnections() != null) {
            scrubConnections(snippet.getConnections());
        }

        // go through each remote process group if specified
        if (snippet.getRemoteProcessGroups() != null) {
            scrubRemoteProcessGroups(snippet.getRemoteProcessGroups());
        }

        // go through each process group if specified
        if (snippet.getProcessGroups() != null) {
            scrubProcessGroups(snippet.getProcessGroups());
        }

        // go through each controller service if specified
        if (snippet.getControllerServices() != null) {
            scrubControllerServices(snippet.getControllerServices());
        }
    }
}
 
Example #17
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 #18
Source File: SnippetUtils.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Moves the content of the specified snippet around the specified location
 * and scales the placement of individual components of the template by the
 * given factorX and factorY.  Does not scale components in child process groups.
 *
 * @param snippet snippet
 * @param x       x location
 * @param y       y location
 * @param factorX x location scaling factor
 * @param factorY y location scaling factor
 */
public static void moveAndScaleSnippet(FlowSnippetDTO snippet, Double x, Double y, double factorX, double factorY) {
    // ensure the point is specified
    if (x != null && y != null) {
        final PositionDTO origin = new PositionDTO(x, y);

        // get the connections
        final Collection<ConnectionDTO> connections = getConnections(snippet);

        // get the components and their positions from the template contents
        final Collection<ComponentDTO> components = getComponents(snippet);

        // only perform the operation if there are components in this snippet
        if (connections.isEmpty() && components.isEmpty()) {
            return;
        }

        // get the component positions from the snippet contents
        final Map<ComponentDTO, PositionDTO> componentPositionLookup = getPositionLookup(components);
        final Map<ConnectionDTO, List<PositionDTO>> connectionPositionLookup = getConnectionPositionLookup(connections);
        final PositionDTO currentOrigin = getOrigin(componentPositionLookup.values(), connectionPositionLookup.values());

        // adjust all component positions
        for (final PositionDTO position : componentPositionLookup.values()) {
            position.setX(origin.getX() + ((position.getX() - currentOrigin.getX()) * factorX));
            position.setY(origin.getY() + ((position.getY() - currentOrigin.getY()) * factorY));
        }

        // adjust all connection positions
        for (final List<PositionDTO> bends : connectionPositionLookup.values()) {
            for (final PositionDTO bend : bends) {
                bend.setX(origin.getX() + ((bend.getX() - currentOrigin.getX()) * factorX));
                bend.setY(origin.getY() + ((bend.getY() - currentOrigin.getY()) * factorY));
            }
        }

        // apply the updated positions
        applyUpdatedPositions(componentPositionLookup, connectionPositionLookup);
    }
}
 
Example #19
Source File: SnippetUtils.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Gets all components, but not connections, that are part of the specified template.
 *
 * @param contents snippet
 * @return component dtos
 */
private static Collection<ComponentDTO> getComponents(FlowSnippetDTO contents) {
    final Collection<ComponentDTO> components = new HashSet<>();

    // add all components
    if (contents.getInputPorts() != null) {
        components.addAll(contents.getInputPorts());
    }
    if (contents.getLabels() != null) {
        components.addAll(contents.getLabels());
    }
    if (contents.getOutputPorts() != null) {
        components.addAll(contents.getOutputPorts());
    }
    if (contents.getProcessGroups() != null) {
        components.addAll(contents.getProcessGroups());
    }
    if (contents.getProcessors() != null) {
        components.addAll(contents.getProcessors());
    }
    if (contents.getFunnels() != null) {
        components.addAll(contents.getFunnels());
    }
    if (contents.getRemoteProcessGroups() != null) {
        components.addAll(contents.getRemoteProcessGroups());
    }

    return components;
}
 
Example #20
Source File: SnippetUtils.java    From nifi with Apache License 2.0 5 votes vote down vote up
public static void verifyNoVersionControlConflicts(final FlowSnippetDTO snippetContents, final ProcessGroup destination) {
    final List<VersionControlInformationDTO> vcis = new ArrayList<>();
    for (final ProcessGroupDTO childGroup : snippetContents.getProcessGroups()) {
        findAllVersionControlInfo(childGroup, vcis);
    }

    verifyNoDuplicateVersionControlInfoDtos(destination, vcis);
}
 
Example #21
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 #22
Source File: TestFlowController.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testInstantiateSnippetWhenControllerServiceMissingBundle() throws ProcessorInstantiationException {
    final String id = UUID.randomUUID().toString();
    final BundleCoordinate coordinate = systemBundle.getBundleDetails().getCoordinate();
    final ControllerServiceNode controllerServiceNode = controller.getFlowManager().createControllerService(ServiceA.class.getName(), id, coordinate, null, true, true);

    // create the controller service dto
    final ControllerServiceDTO csDto = new ControllerServiceDTO();
    csDto.setId(UUID.randomUUID().toString()); // use a different id
    csDto.setParentGroupId(controllerServiceNode.getProcessGroup() == null ? null : controllerServiceNode.getProcessGroup().getIdentifier());
    csDto.setName(controllerServiceNode.getName());
    csDto.setType(controllerServiceNode.getCanonicalClassName());
    csDto.setBundle(null); // missing bundle
    csDto.setState(controllerServiceNode.getState().name());
    csDto.setAnnotationData(controllerServiceNode.getAnnotationData());
    csDto.setComments(controllerServiceNode.getComments());
    csDto.setPersistsState(controllerServiceNode.getControllerServiceImplementation().getClass().isAnnotationPresent(Stateful.class));
    csDto.setRestricted(controllerServiceNode.isRestricted());
    csDto.setExtensionMissing(controllerServiceNode.isExtensionMissing());
    csDto.setDescriptors(new LinkedHashMap<>());
    csDto.setProperties(new LinkedHashMap<>());

    // create the snippet with the controller service
    final FlowSnippetDTO flowSnippetDTO = new FlowSnippetDTO();
    flowSnippetDTO.setControllerServices(Collections.singleton(csDto));

    // instantiate the snippet
    assertEquals(0, controller.getFlowManager().getRootGroup().getControllerServices(false).size());
    controller.getFlowManager().instantiateSnippet(controller.getFlowManager().getRootGroup(), flowSnippetDTO);
}
 
Example #23
Source File: SnippetAuditor.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Audits copy/paste.
 *
 * @param proceedingJoinPoint join point
 * @return dto
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.SnippetDAO+) && "
        + "execution(org.apache.nifi.web.api.dto.FlowSnippetDTO copySnippet(java.lang.String, java.lang.String, java.lang.Double, java.lang.Double, java.lang.String))")
public FlowSnippetDTO copySnippetAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    // perform the underlying operation
    FlowSnippetDTO snippet = (FlowSnippetDTO) proceedingJoinPoint.proceed();
    auditSnippet(snippet);
    return snippet;
}
 
Example #24
Source File: SnippetUtils.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Gets all connections that are part of the specified template.
 *
 * @param contents snippet content
 * @return connection dtos
 */
private static Collection<ConnectionDTO> getConnections(FlowSnippetDTO contents) {
    final Collection<ConnectionDTO> connections = new HashSet<>();
    if (contents.getConnections() != null) {
        connections.addAll(contents.getConnections());
    }
    return connections;
}
 
Example #25
Source File: StandardTemplateDAO.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void verifyCanInstantiate(final String groupId, final FlowSnippetDTO snippetDTO) {
    final ProcessGroup processGroup = flowController.getFlowManager().getGroup(groupId);
    if (processGroup == null) {
        throw new ResourceNotFoundException("Could not find Process Group with ID " + groupId);
    }

    verifyComponentTypes(snippetDTO);
    verifyParameterReferences(snippetDTO, processGroup.getParameterContext());
}
 
Example #26
Source File: InstantiateTemplateRequestEntity.java    From nifi with Apache License 2.0 5 votes vote down vote up
@ApiModelProperty(
        value = "A flow snippet of the template contents. If not specified, this is automatically "
                + "populated by the node receiving the user request. These details need to be replicated "
                + "throughout the cluster to ensure consistency."
)
public FlowSnippetDTO getSnippet() {
    return snippet;
}
 
Example #27
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 #28
Source File: SnippetUtils.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Attempts to roll back and in the specified snippet.
 *
 * @param snippet snippet
 */
public void rollbackClonedPolicies(final FlowSnippetDTO snippet) {
    if (!accessPolicyDAO.supportsConfigurableAuthorizer()) {
        return;
    }

    snippet.getControllerServices().forEach(controllerServiceDTO -> {
        rollbackClonedPolicy(ResourceFactory.getComponentResource(ResourceType.ControllerService, controllerServiceDTO.getId(), controllerServiceDTO.getName()));
    });
    snippet.getFunnels().forEach(funnelDTO -> {
        rollbackClonedPolicy(ResourceFactory.getComponentResource(ResourceType.Funnel, funnelDTO.getId(), funnelDTO.getId()));
    });
    snippet.getInputPorts().forEach(inputPortDTO -> {
        rollbackClonedPolicy(ResourceFactory.getComponentResource(ResourceType.InputPort, inputPortDTO.getId(), inputPortDTO.getName()));
    });
    snippet.getLabels().forEach(labelDTO -> {
        rollbackClonedPolicy(ResourceFactory.getComponentResource(ResourceType.Label, labelDTO.getId(), labelDTO.getLabel()));
    });
    snippet.getOutputPorts().forEach(outputPortDTO -> {
        rollbackClonedPolicy(ResourceFactory.getComponentResource(ResourceType.OutputPort, outputPortDTO.getId(), outputPortDTO.getName()));
    });
    snippet.getProcessors().forEach(processorDTO -> {
        rollbackClonedPolicy(ResourceFactory.getComponentResource(ResourceType.Processor, processorDTO.getId(), processorDTO.getName()));
    });
    snippet.getRemoteProcessGroups().forEach(remoteProcessGroupDTO -> {
        rollbackClonedPolicy(ResourceFactory.getComponentResource(ResourceType.RemoteProcessGroup, remoteProcessGroupDTO.getId(), remoteProcessGroupDTO.getName()));
    });
    snippet.getProcessGroups().forEach(processGroupDTO -> {
        rollbackClonedPolicy(ResourceFactory.getComponentResource(ResourceType.ProcessGroup, processGroupDTO.getId(), processGroupDTO.getName()));

        // consider all descendant components
        if (processGroupDTO.getContents() != null) {
            rollbackClonedPolicies(processGroupDTO.getContents());
        }
    });
}
 
Example #29
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);
    }
}
 
Example #30
Source File: SnippetAuditor.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Audits the instantiation of a template.
 *
 * @param proceedingJoinPoint join point
 * @return dto
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.TemplateDAO+) && "
        + "execution(org.apache.nifi.web.api.dto.FlowSnippetDTO instantiateTemplate("
        + "java.lang.String, java.lang.Double, java.lang.Double, java.lang.String, org.apache.nifi.web.api.dto.FlowSnippetDTO, java.lang.String))")
public FlowSnippetDTO instantiateTemplateAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    // perform the underlying operation
    FlowSnippetDTO snippet = (FlowSnippetDTO) proceedingJoinPoint.proceed();
    auditSnippet(snippet);
    return snippet;
}