Search in sources :

Example 16 with ControllerServiceDTO

use of org.apache.nifi.web.api.dto.ControllerServiceDTO in project nifi by apache.

the class StandardControllerServiceDAO method updateControllerService.

@Override
public ControllerServiceNode updateControllerService(final ControllerServiceDTO controllerServiceDTO) {
    // get the controller service
    final ControllerServiceNode controllerService = locateControllerService(controllerServiceDTO.getId());
    // ensure we can perform the update
    verifyUpdate(controllerService, controllerServiceDTO);
    // perform the update
    configureControllerService(controllerService, controllerServiceDTO);
    // attempt to change the underlying controller service if an updated bundle is specified
    // updating the bundle must happen after configuring so that any additional classpath resources are set first
    updateBundle(controllerService, controllerServiceDTO);
    // enable or disable as appropriate
    if (isNotNull(controllerServiceDTO.getState())) {
        final ControllerServiceState purposedControllerServiceState = ControllerServiceState.valueOf(controllerServiceDTO.getState());
        // only attempt an action if it is changing
        if (!purposedControllerServiceState.equals(controllerService.getState())) {
            if (ControllerServiceState.ENABLED.equals(purposedControllerServiceState)) {
                serviceProvider.enableControllerService(controllerService);
            } else if (ControllerServiceState.DISABLED.equals(purposedControllerServiceState)) {
                serviceProvider.disableControllerService(controllerService);
            }
        }
    }
    final ProcessGroup group = controllerService.getProcessGroup();
    if (group != null) {
        group.onComponentModified();
        // For any component that references this Controller Service, find the component's Process Group
        // and notify the Process Group that a component has been modified. This way, we know to re-calculate
        // whether or not the Process Group has local modifications.
        controllerService.getReferences().getReferencingComponents().stream().map(ConfiguredComponent::getProcessGroupIdentifier).filter(id -> !id.equals(group.getIdentifier())).forEach(groupId -> {
            final ProcessGroup descendant = group.findProcessGroup(groupId);
            if (descendant != null) {
                descendant.onComponentModified();
            }
        });
    }
    return controllerService;
}
Also used : ProcessGroup(org.apache.nifi.groups.ProcessGroup) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) URL(java.net.URL) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ConfigurableComponent(org.apache.nifi.components.ConfigurableComponent) BundleDTO(org.apache.nifi.web.api.dto.BundleDTO) ArrayList(java.util.ArrayList) ComponentStateDAO(org.apache.nifi.web.dao.ComponentStateDAO) ControllerServiceDAO(org.apache.nifi.web.dao.ControllerServiceDAO) ROOT_GROUP_ID_ALIAS(org.apache.nifi.controller.FlowController.ROOT_GROUP_ID_ALIAS) Scope(org.apache.nifi.components.state.Scope) Map(java.util.Map) ControllerServiceProvider(org.apache.nifi.controller.service.ControllerServiceProvider) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) ConfiguredComponent(org.apache.nifi.controller.ConfiguredComponent) ControllerServiceInstantiationException(org.apache.nifi.controller.exception.ControllerServiceInstantiationException) Set(java.util.Set) BundleUtils(org.apache.nifi.util.BundleUtils) StateMap(org.apache.nifi.components.state.StateMap) FlowController(org.apache.nifi.controller.FlowController) NiFiCoreException(org.apache.nifi.web.NiFiCoreException) List(java.util.List) ScheduledState(org.apache.nifi.controller.ScheduledState) ControllerServiceState(org.apache.nifi.controller.service.ControllerServiceState) ExtensionManager(org.apache.nifi.nar.ExtensionManager) Collections(java.util.Collections) ValidationException(org.apache.nifi.controller.exception.ValidationException) ControllerServiceState(org.apache.nifi.controller.service.ControllerServiceState) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ConfiguredComponent(org.apache.nifi.controller.ConfiguredComponent) ProcessGroup(org.apache.nifi.groups.ProcessGroup)

Example 17 with ControllerServiceDTO

use of org.apache.nifi.web.api.dto.ControllerServiceDTO in project nifi by apache.

the class SnippetUtils method addControllerServices.

/**
 * Finds all Controller Services that are referenced in the given Process Group (and child Process Groups, recursively), and
 * adds them to the given servicesByGroup map
 *
 * @param group the Process Group to start from
 * @param dto the DTO representation of the Process Group
 * @param allServicesReferenced a Set of all Controller Service DTO's that have already been referenced; used to dedupe services
 * @param contentsByGroup a Map of Process Group ID to the Process Group's contents
 * @param highestGroupId the UUID of the 'highest' process group in the snippet
 */
private void addControllerServices(final ProcessGroup group, final ProcessGroupDTO dto, final Set<ControllerServiceDTO> allServicesReferenced, final boolean includeControllerServices, final Set<String> visitedGroupIds, final Map<String, FlowSnippetDTO> contentsByGroup, final String highestGroupId) {
    final FlowSnippetDTO contents = dto.getContents();
    contentsByGroup.put(dto.getId(), contents);
    if (contents == null) {
        return;
    }
    // include this group in the ancestry for this snippet, services only get included if the includeControllerServices
    // flag is set or if the service is defined within this groups hierarchy within the snippet
    visitedGroupIds.add(group.getIdentifier());
    for (final ProcessorNode procNode : group.getProcessors()) {
        // Include all referenced services that are not already included in this snippet.
        getControllerServices(procNode.getProperties()).stream().filter(svc -> allServicesReferenced.add(svc)).filter(svc -> includeControllerServices || visitedGroupIds.contains(svc.getParentGroupId())).forEach(svc -> {
            final String svcGroupId = svc.getParentGroupId();
            final String destinationGroupId = contentsByGroup.containsKey(svcGroupId) ? svcGroupId : highestGroupId;
            svc.setParentGroupId(destinationGroupId);
            final FlowSnippetDTO snippetDto = contentsByGroup.get(destinationGroupId);
            if (snippetDto != null) {
                Set<ControllerServiceDTO> services = snippetDto.getControllerServices();
                if (services == null) {
                    snippetDto.setControllerServices(Collections.singleton(svc));
                } else {
                    services.add(svc);
                    snippetDto.setControllerServices(services);
                }
            }
        });
    }
    // Map child process group ID to the child process group for easy lookup
    final Map<String, ProcessGroupDTO> childGroupMap = contents.getProcessGroups().stream().collect(Collectors.toMap(childGroupDto -> childGroupDto.getId(), childGroupDto -> childGroupDto));
    for (final ProcessGroup childGroup : group.getProcessGroups()) {
        final ProcessGroupDTO childDto = childGroupMap.get(childGroup.getIdentifier());
        if (childDto == null) {
            continue;
        }
        addControllerServices(childGroup, childDto, allServicesReferenced, includeControllerServices, visitedGroupIds, contentsByGroup, highestGroupId);
    }
}
Also used : RemoteProcessGroupContentsDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupContentsDTO) ProcessGroup(org.apache.nifi.groups.ProcessGroup) ProcessorConfigDTO(org.apache.nifi.web.api.dto.ProcessorConfigDTO) ConnectableType(org.apache.nifi.connectable.ConnectableType) LoggerFactory(org.slf4j.LoggerFactory) Port(org.apache.nifi.connectable.Port) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) StringUtils(org.apache.commons.lang3.StringUtils) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) ResourceType(org.apache.nifi.authorization.resource.ResourceType) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) SecureRandom(java.security.SecureRandom) LabelDTO(org.apache.nifi.web.api.dto.LabelDTO) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) PropertyDescriptorDTO(org.apache.nifi.web.api.dto.PropertyDescriptorDTO) TenantEntity(org.apache.nifi.web.api.entity.TenantEntity) Map(java.util.Map) Connection(org.apache.nifi.connectable.Connection) FunnelDTO(org.apache.nifi.web.api.dto.FunnelDTO) ComponentIdGenerator(org.apache.nifi.util.ComponentIdGenerator) Label(org.apache.nifi.controller.label.Label) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) AccessPolicyDAO(org.apache.nifi.web.dao.AccessPolicyDAO) Collection(java.util.Collection) Set(java.util.Set) UUID(java.util.UUID) RemoteProcessGroupPortDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO) Snippet(org.apache.nifi.controller.Snippet) Collectors(java.util.stream.Collectors) ResourceFactory(org.apache.nifi.authorization.resource.ResourceFactory) FlowController(org.apache.nifi.controller.FlowController) StandardCharsets(java.nio.charset.StandardCharsets) PortDTO(org.apache.nifi.web.api.dto.PortDTO) List(java.util.List) ScheduledState(org.apache.nifi.controller.ScheduledState) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) Entry(java.util.Map.Entry) ControllerServiceState(org.apache.nifi.controller.service.ControllerServiceState) DtoFactory(org.apache.nifi.web.api.dto.DtoFactory) Resource(org.apache.nifi.authorization.Resource) FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) ProcessorNode(org.apache.nifi.controller.ProcessorNode) Funnel(org.apache.nifi.connectable.Funnel) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AccessPolicyDTO(org.apache.nifi.web.api.dto.AccessPolicyDTO) LinkedHashSet(java.util.LinkedHashSet) Logger(org.slf4j.Logger) RequestAction(org.apache.nifi.authorization.RequestAction) ComponentDTO(org.apache.nifi.web.api.dto.ComponentDTO) AccessPolicy(org.apache.nifi.authorization.AccessPolicy) Collections(java.util.Collections) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO) FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) ProcessorNode(org.apache.nifi.controller.ProcessorNode) ProcessGroup(org.apache.nifi.groups.ProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)

Example 18 with ControllerServiceDTO

use of org.apache.nifi.web.api.dto.ControllerServiceDTO in project nifi by apache.

the class StandardFlowSynchronizer method isEmpty.

public static boolean isEmpty(final DataFlow dataFlow) {
    if (dataFlow == null || dataFlow.getFlow() == null || dataFlow.getFlow().length == 0) {
        return true;
    }
    final Document document = parseFlowBytes(dataFlow.getFlow());
    final Element rootElement = document.getDocumentElement();
    final Element rootGroupElement = (Element) rootElement.getElementsByTagName("rootGroup").item(0);
    final FlowEncodingVersion encodingVersion = FlowEncodingVersion.parse(rootGroupElement);
    final ProcessGroupDTO rootGroupDto = FlowFromDOMFactory.getProcessGroup(null, rootGroupElement, null, encodingVersion);
    final NodeList reportingTasks = rootElement.getElementsByTagName("reportingTask");
    final ReportingTaskDTO reportingTaskDTO = reportingTasks.getLength() == 0 ? null : FlowFromDOMFactory.getReportingTask((Element) reportingTasks.item(0), null);
    final NodeList controllerServices = rootElement.getElementsByTagName("controllerService");
    final ControllerServiceDTO controllerServiceDTO = controllerServices.getLength() == 0 ? null : FlowFromDOMFactory.getControllerService((Element) controllerServices.item(0), null);
    return isEmpty(rootGroupDto) && isEmpty(reportingTaskDTO) && isEmpty(controllerServiceDTO);
}
Also used : ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) FlowEncodingVersion(org.apache.nifi.controller.serialization.FlowEncodingVersion) ReportingTaskDTO(org.apache.nifi.web.api.dto.ReportingTaskDTO) Document(org.w3c.dom.Document)

Example 19 with ControllerServiceDTO

use of org.apache.nifi.web.api.dto.ControllerServiceDTO in project nifi by apache.

the class StandardFlowSynchronizer method updateProcessGroup.

private ProcessGroup updateProcessGroup(final FlowController controller, final ProcessGroup parentGroup, final Element processGroupElement, final StringEncryptor encryptor, final FlowEncodingVersion encodingVersion) throws ProcessorInstantiationException {
    // get the parent group ID
    final String parentId = (parentGroup == null) ? null : parentGroup.getIdentifier();
    // get the process group
    final ProcessGroupDTO processGroupDto = FlowFromDOMFactory.getProcessGroup(parentId, processGroupElement, encryptor, encodingVersion);
    // update the process group
    if (parentId == null) {
        /*
             * Labels are not included in the "inherit flow" algorithm, so we cannot
             * blindly update them because they may not exist in the current flow.
             * Therefore, we first remove all labels, and then let the updating
             * process add labels defined in the new flow.
             */
        final ProcessGroup root = controller.getGroup(controller.getRootGroupId());
        for (final Label label : root.findAllLabels()) {
            label.getProcessGroup().removeLabel(label);
        }
    }
    // update the process group
    controller.updateProcessGroup(processGroupDto);
    // get the real process group and ID
    final ProcessGroup processGroup = controller.getGroup(processGroupDto.getId());
    // determine the scheduled state of all of the Controller Service
    final List<Element> controllerServiceNodeList = getChildrenByTagName(processGroupElement, "controllerService");
    final Set<ControllerServiceNode> toDisable = new HashSet<>();
    final Set<ControllerServiceNode> toEnable = new HashSet<>();
    for (final Element serviceElement : controllerServiceNodeList) {
        final ControllerServiceDTO dto = FlowFromDOMFactory.getControllerService(serviceElement, encryptor);
        final ControllerServiceNode serviceNode = processGroup.getControllerService(dto.getId());
        // Check if the controller service is in the correct state. We consider it the correct state if
        // we are in a transitional state and heading in the right direction or already in the correct state.
        // E.g., it is the correct state if it should be 'DISABLED' and it is either DISABLED or DISABLING.
        final ControllerServiceState serviceState = getFinalTransitionState(serviceNode.getState());
        final ControllerServiceState clusterState = getFinalTransitionState(ControllerServiceState.valueOf(dto.getState()));
        if (serviceState != clusterState) {
            switch(clusterState) {
                case DISABLED:
                    toDisable.add(serviceNode);
                    break;
                case ENABLED:
                    toEnable.add(serviceNode);
                    break;
            }
        }
    }
    controller.disableControllerServicesAsync(toDisable);
    controller.enableControllerServices(toEnable);
    // processors & ports cannot be updated - they must be the same. Except for the scheduled state.
    final List<Element> processorNodeList = getChildrenByTagName(processGroupElement, "processor");
    for (final Element processorElement : processorNodeList) {
        final ProcessorDTO dto = FlowFromDOMFactory.getProcessor(processorElement, encryptor);
        final ProcessorNode procNode = processGroup.getProcessor(dto.getId());
        updateNonFingerprintedProcessorSettings(procNode, dto);
        if (!procNode.getScheduledState().name().equals(dto.getState())) {
            try {
                switch(ScheduledState.valueOf(dto.getState())) {
                    case DISABLED:
                        // switch processor do disabled. This means we have to stop it (if it's already stopped, this method does nothing),
                        // and then we have to disable it.
                        controller.stopProcessor(procNode.getProcessGroupIdentifier(), procNode.getIdentifier());
                        procNode.getProcessGroup().disableProcessor(procNode);
                        break;
                    case RUNNING:
                        // we want to run now. Make sure processor is not disabled and then start it.
                        procNode.getProcessGroup().enableProcessor(procNode);
                        controller.startProcessor(procNode.getProcessGroupIdentifier(), procNode.getIdentifier(), false);
                        break;
                    case STOPPED:
                        if (procNode.getScheduledState() == ScheduledState.DISABLED) {
                            procNode.getProcessGroup().enableProcessor(procNode);
                        } else if (procNode.getScheduledState() == ScheduledState.RUNNING) {
                            controller.stopProcessor(procNode.getProcessGroupIdentifier(), procNode.getIdentifier());
                        }
                        break;
                }
            } catch (final IllegalStateException ise) {
                logger.error("Failed to change Scheduled State of {} from {} to {} due to {}", procNode, procNode.getScheduledState().name(), dto.getState(), ise.toString());
                logger.error("", ise);
                // create bulletin for the Processor Node
                controller.getBulletinRepository().addBulletin(BulletinFactory.createBulletin(procNode, "Node Reconnection", Severity.ERROR.name(), "Failed to change Scheduled State of " + procNode + " from " + procNode.getScheduledState().name() + " to " + dto.getState() + " due to " + ise.toString()));
                // create bulletin at Controller level.
                controller.getBulletinRepository().addBulletin(BulletinFactory.createBulletin("Node Reconnection", Severity.ERROR.name(), "Failed to change Scheduled State of " + procNode + " from " + procNode.getScheduledState().name() + " to " + dto.getState() + " due to " + ise.toString()));
            }
        }
    }
    final List<Element> inputPortList = getChildrenByTagName(processGroupElement, "inputPort");
    for (final Element portElement : inputPortList) {
        final PortDTO dto = FlowFromDOMFactory.getPort(portElement);
        final Port port = processGroup.getInputPort(dto.getId());
        if (!port.getScheduledState().name().equals(dto.getState())) {
            switch(ScheduledState.valueOf(dto.getState())) {
                case DISABLED:
                    // switch processor do disabled. This means we have to stop it (if it's already stopped, this method does nothing),
                    // and then we have to disable it.
                    controller.stopConnectable(port);
                    port.getProcessGroup().disableInputPort(port);
                    break;
                case RUNNING:
                    // we want to run now. Make sure processor is not disabled and then start it.
                    port.getProcessGroup().enableInputPort(port);
                    controller.startConnectable(port);
                    break;
                case STOPPED:
                    if (port.getScheduledState() == ScheduledState.DISABLED) {
                        port.getProcessGroup().enableInputPort(port);
                    } else if (port.getScheduledState() == ScheduledState.RUNNING) {
                        controller.stopConnectable(port);
                    }
                    break;
            }
        }
    }
    final List<Element> outputPortList = getChildrenByTagName(processGroupElement, "outputPort");
    for (final Element portElement : outputPortList) {
        final PortDTO dto = FlowFromDOMFactory.getPort(portElement);
        final Port port = processGroup.getOutputPort(dto.getId());
        if (!port.getScheduledState().name().equals(dto.getState())) {
            switch(ScheduledState.valueOf(dto.getState())) {
                case DISABLED:
                    // switch processor do disabled. This means we have to stop it (if it's already stopped, this method does nothing),
                    // and then we have to disable it.
                    controller.stopConnectable(port);
                    port.getProcessGroup().disableOutputPort(port);
                    break;
                case RUNNING:
                    // we want to run now. Make sure processor is not disabled and then start it.
                    port.getProcessGroup().enableOutputPort(port);
                    controller.startConnectable(port);
                    break;
                case STOPPED:
                    if (port.getScheduledState() == ScheduledState.DISABLED) {
                        port.getProcessGroup().enableOutputPort(port);
                    } else if (port.getScheduledState() == ScheduledState.RUNNING) {
                        controller.stopConnectable(port);
                    }
                    break;
            }
        }
    }
    // Update scheduled state of Remote Group Ports
    final List<Element> remoteProcessGroupList = getChildrenByTagName(processGroupElement, "remoteProcessGroup");
    for (final Element remoteGroupElement : remoteProcessGroupList) {
        final RemoteProcessGroupDTO remoteGroupDto = FlowFromDOMFactory.getRemoteProcessGroup(remoteGroupElement, encryptor);
        final RemoteProcessGroup rpg = processGroup.getRemoteProcessGroup(remoteGroupDto.getId());
        // input ports
        final List<Element> inputPortElements = getChildrenByTagName(remoteGroupElement, "inputPort");
        for (final Element inputPortElement : inputPortElements) {
            final RemoteProcessGroupPortDescriptor portDescriptor = FlowFromDOMFactory.getRemoteProcessGroupPort(inputPortElement);
            final String inputPortId = portDescriptor.getId();
            final RemoteGroupPort inputPort = rpg.getInputPort(inputPortId);
            if (inputPort == null) {
                continue;
            }
            if (portDescriptor.isTransmitting()) {
                if (inputPort.getScheduledState() != ScheduledState.RUNNING && inputPort.getScheduledState() != ScheduledState.STARTING) {
                    rpg.startTransmitting(inputPort);
                }
            } else if (inputPort.getScheduledState() != ScheduledState.STOPPED && inputPort.getScheduledState() != ScheduledState.STOPPING) {
                rpg.stopTransmitting(inputPort);
            }
        }
        // output ports
        final List<Element> outputPortElements = getChildrenByTagName(remoteGroupElement, "outputPort");
        for (final Element outputPortElement : outputPortElements) {
            final RemoteProcessGroupPortDescriptor portDescriptor = FlowFromDOMFactory.getRemoteProcessGroupPort(outputPortElement);
            final String outputPortId = portDescriptor.getId();
            final RemoteGroupPort outputPort = rpg.getOutputPort(outputPortId);
            if (outputPort == null) {
                continue;
            }
            if (portDescriptor.isTransmitting()) {
                if (outputPort.getScheduledState() != ScheduledState.RUNNING && outputPort.getScheduledState() != ScheduledState.STARTING) {
                    rpg.startTransmitting(outputPort);
                }
            } else if (outputPort.getScheduledState() != ScheduledState.STOPPED && outputPort.getScheduledState() != ScheduledState.STOPPING) {
                rpg.stopTransmitting(outputPort);
            }
        }
    }
    // add labels
    final List<Element> labelNodeList = getChildrenByTagName(processGroupElement, "label");
    for (final Element labelElement : labelNodeList) {
        final LabelDTO labelDTO = FlowFromDOMFactory.getLabel(labelElement);
        final Label label = controller.createLabel(labelDTO.getId(), labelDTO.getLabel());
        label.setStyle(labelDTO.getStyle());
        label.setPosition(new Position(labelDTO.getPosition().getX(), labelDTO.getPosition().getY()));
        label.setVersionedComponentId(labelDTO.getVersionedComponentId());
        if (labelDTO.getWidth() != null && labelDTO.getHeight() != null) {
            label.setSize(new Size(labelDTO.getWidth(), labelDTO.getHeight()));
        }
        processGroup.addLabel(label);
    }
    // update nested process groups (recursively)
    final List<Element> nestedProcessGroupNodeList = getChildrenByTagName(processGroupElement, "processGroup");
    for (final Element nestedProcessGroupElement : nestedProcessGroupNodeList) {
        updateProcessGroup(controller, processGroup, nestedProcessGroupElement, encryptor, encodingVersion);
    }
    // update connections
    final List<Element> connectionNodeList = getChildrenByTagName(processGroupElement, "connection");
    for (final Element connectionElement : connectionNodeList) {
        final ConnectionDTO dto = FlowFromDOMFactory.getConnection(connectionElement);
        final Connection connection = processGroup.getConnection(dto.getId());
        connection.setName(dto.getName());
        connection.setProcessGroup(processGroup);
        if (dto.getLabelIndex() != null) {
            connection.setLabelIndex(dto.getLabelIndex());
        }
        if (dto.getzIndex() != null) {
            connection.setZIndex(dto.getzIndex());
        }
        final List<Position> bendPoints = new ArrayList<>();
        for (final PositionDTO bend : dto.getBends()) {
            bendPoints.add(new Position(bend.getX(), bend.getY()));
        }
        connection.setBendPoints(bendPoints);
        List<FlowFilePrioritizer> newPrioritizers = null;
        final List<String> prioritizers = dto.getPrioritizers();
        if (prioritizers != null) {
            final List<String> newPrioritizersClasses = new ArrayList<>(prioritizers);
            newPrioritizers = new ArrayList<>();
            for (final String className : newPrioritizersClasses) {
                try {
                    newPrioritizers.add(controller.createPrioritizer(className));
                } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException e) {
                    throw new IllegalArgumentException("Unable to set prioritizer " + className + ": " + e);
                }
            }
        }
        if (newPrioritizers != null) {
            connection.getFlowFileQueue().setPriorities(newPrioritizers);
        }
        if (dto.getBackPressureObjectThreshold() != null) {
            connection.getFlowFileQueue().setBackPressureObjectThreshold(dto.getBackPressureObjectThreshold());
        }
        if (dto.getBackPressureDataSizeThreshold() != null && !dto.getBackPressureDataSizeThreshold().trim().isEmpty()) {
            connection.getFlowFileQueue().setBackPressureDataSizeThreshold(dto.getBackPressureDataSizeThreshold());
        }
        if (dto.getFlowFileExpiration() != null) {
            connection.getFlowFileQueue().setFlowFileExpiration(dto.getFlowFileExpiration());
        }
    }
    // Replace the templates with those from the proposed flow
    final List<Element> templateNodeList = getChildrenByTagName(processGroupElement, "template");
    for (final Element templateElement : templateNodeList) {
        final TemplateDTO templateDto = TemplateUtils.parseDto(templateElement);
        final Template template = new Template(templateDto);
        // This just makes sure that they do.
        if (processGroup.getTemplate(template.getIdentifier()) != null) {
            processGroup.removeTemplate(template);
        }
        processGroup.addTemplate(template);
    }
    return processGroup;
}
Also used : ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) ControllerServiceState(org.apache.nifi.controller.service.ControllerServiceState) Size(org.apache.nifi.connectable.Size) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) Element(org.w3c.dom.Element) RootGroupPort(org.apache.nifi.remote.RootGroupPort) Port(org.apache.nifi.connectable.Port) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) Label(org.apache.nifi.controller.label.Label) ArrayList(java.util.ArrayList) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) FlowFilePrioritizer(org.apache.nifi.flowfile.FlowFilePrioritizer) HashSet(java.util.HashSet) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) Position(org.apache.nifi.connectable.Position) PortDTO(org.apache.nifi.web.api.dto.PortDTO) Connection(org.apache.nifi.connectable.Connection) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) RemoteProcessGroupPortDescriptor(org.apache.nifi.groups.RemoteProcessGroupPortDescriptor) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ProcessGroup(org.apache.nifi.groups.ProcessGroup) LabelDTO(org.apache.nifi.web.api.dto.LabelDTO) ProcessorInstantiationException(org.apache.nifi.controller.exception.ProcessorInstantiationException) ReportingTaskInstantiationException(org.apache.nifi.controller.reporting.ReportingTaskInstantiationException)

Example 20 with ControllerServiceDTO

use of org.apache.nifi.web.api.dto.ControllerServiceDTO in project nifi by apache.

the class TemplateUtils method scrubControllerServices.

private static void scrubControllerServices(final Set<ControllerServiceDTO> controllerServices) {
    for (final ControllerServiceDTO serviceDTO : controllerServices) {
        final Map<String, String> properties = serviceDTO.getProperties();
        final Map<String, PropertyDescriptorDTO> descriptors = serviceDTO.getDescriptors();
        if (properties != null && descriptors != null) {
            for (final PropertyDescriptorDTO descriptor : descriptors.values()) {
                if (Boolean.TRUE.equals(descriptor.isSensitive())) {
                    properties.put(descriptor.getName(), null);
                }
                scrubPropertyDescriptor(descriptor);
            }
        }
        serviceDTO.setControllerServiceApis(null);
        serviceDTO.setExtensionMissing(null);
        serviceDTO.setMultipleVersionsAvailable(null);
        serviceDTO.setCustomUiUrl(null);
        serviceDTO.setValidationErrors(null);
    }
}
Also used : ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) PropertyDescriptorDTO(org.apache.nifi.web.api.dto.PropertyDescriptorDTO)

Aggregations

ControllerServiceDTO (org.apache.nifi.web.api.dto.ControllerServiceDTO)60 HashSet (java.util.HashSet)20 ArrayList (java.util.ArrayList)19 HashMap (java.util.HashMap)19 Map (java.util.Map)18 ProcessorDTO (org.apache.nifi.web.api.dto.ProcessorDTO)17 List (java.util.List)16 Set (java.util.Set)16 ProcessGroupDTO (org.apache.nifi.web.api.dto.ProcessGroupDTO)15 Collectors (java.util.stream.Collectors)14 FlowSnippetDTO (org.apache.nifi.web.api.dto.FlowSnippetDTO)14 Collections (java.util.Collections)13 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)13 ConnectionDTO (org.apache.nifi.web.api.dto.ConnectionDTO)13 ProcessorConfigDTO (org.apache.nifi.web.api.dto.ProcessorConfigDTO)13 Logger (org.slf4j.Logger)13 LoggerFactory (org.slf4j.LoggerFactory)13 Optional (java.util.Optional)12 Nonnull (javax.annotation.Nonnull)11 NifiProperty (com.thinkbiganalytics.nifi.rest.model.NifiProperty)10