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

The following examples show how to use org.apache.nifi.groups.ProcessGroup#onComponentModified() . 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: StandardProcessGroupDAO.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public ProcessGroup updateVersionControlInformation(final VersionControlInformationDTO versionControlInformation, final Map<String, String> versionedComponentMapping) {
    final String groupId = versionControlInformation.getGroupId();
    final ProcessGroup group = locateProcessGroup(flowController, groupId);

    final String registryId = versionControlInformation.getRegistryId();
    final FlowRegistry flowRegistry = flowController.getFlowRegistryClient().getFlowRegistry(registryId);
    final String registryName = flowRegistry == null ? registryId : flowRegistry.getName();

    final NiFiRegistryFlowMapper mapper = new NiFiRegistryFlowMapper(flowController.getExtensionManager());
    final VersionedProcessGroup flowSnapshot = mapper.mapProcessGroup(group, flowController.getControllerServiceProvider(), flowController.getFlowRegistryClient(), false);

    final StandardVersionControlInformation vci = StandardVersionControlInformation.Builder.fromDto(versionControlInformation)
        .registryName(registryName)
        .flowSnapshot(flowSnapshot)
        .build();

    group.setVersionControlInformation(vci, versionedComponentMapping);
    group.onComponentModified();

    return group;
}
 
Example 2
Source File: StandardProcessGroupDAO.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public ProcessGroup updateProcessGroupFlow(final String groupId, final VersionedFlowSnapshot proposedSnapshot, final VersionControlInformationDTO versionControlInformation,
                                           final String componentIdSeed, final boolean verifyNotModified, final boolean updateSettings, final boolean updateDescendantVersionedFlows) {

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

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

    group.onComponentModified();

    return group;
}
 
Example 3
Source File: StandardProcessGroupDAO.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public ProcessGroup updateVariableRegistry(final VariableRegistryDTO variableRegistry) {
    final ProcessGroup group = locateProcessGroup(flowController, variableRegistry.getProcessGroupId());
    if (group == null) {
        throw new ResourceNotFoundException("Could not find Process Group with ID " + variableRegistry.getProcessGroupId());
    }

    final Map<String, String> variableMap = new HashMap<>();
    variableRegistry.getVariables().stream() // have to use forEach here instead of using Collectors.toMap because value may be null
        .map(VariableEntity::getVariable)
        .forEach(var -> variableMap.put(var.getName(), var.getValue()));

    group.setVariables(variableMap);
    group.onComponentModified();
    return group;
}
 
Example 4
Source File: StandardProcessGroupDAO.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public ProcessGroup disconnectVersionControl(final String groupId) {
    final ProcessGroup group = locateProcessGroup(flowController, groupId);
    group.disconnectVersionControl(true);
    group.onComponentModified();
    return group;
}
 
Example 5
Source File: StandardControllerServiceDAO.java    From nifi with Apache License 2.0 4 votes vote down vote up
@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(ComponentNode::getProcessGroupIdentifier)
            .filter(id -> !id.equals(group.getIdentifier()))
            .forEach(groupId -> {
                final ProcessGroup descendant = group.findProcessGroup(groupId);
                if (descendant != null) {
                    descendant.onComponentModified();
                }
            });
    }

    return controllerService;
}
 
Example 6
Source File: AbstractPortDAO.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
public Port updatePort(PortDTO portDTO) {
    final Port port = locatePort(portDTO.getId());
    final ProcessGroup processGroup = port.getProcessGroup();

    // ensure we can do this update
    verifyUpdate(port, portDTO);

    // handle state transition
    if (isNotNull(portDTO.getState())) {
        final ScheduledState proposedScheduledState = ScheduledState.valueOf(portDTO.getState());

        // only attempt an action if it is changing
        if (!proposedScheduledState.equals(port.getScheduledState())) {
            try {
                handleStateTransition(port, proposedScheduledState);
            } catch (IllegalStateException ise) {
                throw new NiFiCoreException(ise.getMessage(), ise);
            }
        }
    }

    if (port instanceof PublicPort) {
        final PublicPort publicPort = (PublicPort) port;
        if (isNotNull(portDTO.getGroupAccessControl())) {
            publicPort.setGroupAccessControl(portDTO.getGroupAccessControl());
        }
        if (isNotNull(portDTO.getUserAccessControl())) {
            publicPort.setUserAccessControl(portDTO.getUserAccessControl());
        }
    }

    // update the port
    final String name = portDTO.getName();
    final String comments = portDTO.getComments();
    final Integer concurrentTasks = portDTO.getConcurrentlySchedulableTaskCount();
    if (isNotNull(portDTO.getPosition())) {
        port.setPosition(new Position(portDTO.getPosition().getX(), portDTO.getPosition().getY()));
    }
    if (isNotNull(name)) {
        port.setName(name);
    }
    if (isNotNull(comments)) {
        port.setComments(comments);
    }
    if (isNotNull(concurrentTasks)) {
        port.setMaxConcurrentTasks(concurrentTasks);
    }

    processGroup.onComponentModified();
    return port;
}
 
Example 7
Source File: StandardProcessorDAO.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
public ProcessorNode updateProcessor(ProcessorDTO processorDTO) {
    ProcessorNode processor = locateProcessor(processorDTO.getId());
    ProcessGroup parentGroup = processor.getProcessGroup();

    // ensure we can perform the update
    verifyUpdate(processor, processorDTO);

    // configure the processor
    configureProcessor(processor, processorDTO);
    parentGroup.onComponentModified();

    // attempt to change the underlying processor if an updated bundle is specified
    // updating the bundle must happen after configuring so that any additional classpath resources are set first
    updateBundle(processor, processorDTO);

    // see if an update is necessary
    if (isNotNull(processorDTO.getState())) {
        final ScheduledState purposedScheduledState = ScheduledState.valueOf(processorDTO.getState());

        // only attempt an action if it is changing
        if (!purposedScheduledState.equals(processor.getScheduledState())) {
            try {
                // perform the appropriate action
                switch (purposedScheduledState) {
                    case RUNNING:
                        parentGroup.startProcessor(processor, true);
                        break;
                    case STOPPED:
                        switch (processor.getScheduledState()) {
                            case RUNNING:
                                parentGroup.stopProcessor(processor);
                                break;
                            case DISABLED:
                                parentGroup.enableProcessor(processor);
                                break;
                        }
                        break;
                    case DISABLED:
                        parentGroup.disableProcessor(processor);
                        break;
                }
            } catch (IllegalStateException | ComponentLifeCycleException ise) {
                throw new NiFiCoreException(ise.getMessage(), ise);
            } catch (RejectedExecutionException ree) {
                throw new NiFiCoreException("Unable to schedule all tasks for the specified processor.", ree);
            } catch (NullPointerException npe) {
                throw new NiFiCoreException("Unable to update processor run state.", npe);
            } catch (Exception e) {
                throw new NiFiCoreException("Unable to update processor run state: " + e, e);
            }
        }
    }

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

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

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

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

            group.setParameterContext(parameterContext);
        }
    }

    if (isNotNull(name)) {
        group.setName(name);
    }
    if (isNotNull(processGroupDTO.getPosition())) {
        group.setPosition(new Position(processGroupDTO.getPosition().getX(), processGroupDTO.getPosition().getY()));
        final ProcessGroup parent = group.getParent();
        if (parent != null) {
            parent.onComponentModified();
        }
    }
    if (isNotNull(comments)) {
        group.setComments(comments);
    }
    if (flowFileConcurrency != null) {
        group.setFlowFileConcurrency(flowFileConcurrency);
    }
    if (flowFileOutboundPolicy != null) {
        group.setFlowFileOutboundPolicy(flowFileOutboundPolicy);
    }
    group.onComponentModified();
    return group;
}
 
Example 9
Source File: StandardRemoteProcessGroupDAO.java    From nifi with Apache License 2.0 4 votes vote down vote up
private RemoteProcessGroup updateRemoteProcessGroup(RemoteProcessGroup remoteProcessGroup, RemoteProcessGroupDTO remoteProcessGroupDTO) {
    // verify the update request
    verifyUpdate(remoteProcessGroup, remoteProcessGroupDTO);

    // configure the remote process group
    final String targetUris = remoteProcessGroupDTO.getTargetUris();
    final String name = remoteProcessGroupDTO.getName();
    final String comments = remoteProcessGroupDTO.getComments();
    final String communicationsTimeout = remoteProcessGroupDTO.getCommunicationsTimeout();
    final String yieldDuration = remoteProcessGroupDTO.getYieldDuration();
    final String proxyHost = remoteProcessGroupDTO.getProxyHost();
    final Integer proxyPort = remoteProcessGroupDTO.getProxyPort();
    final String proxyUser = remoteProcessGroupDTO.getProxyUser();
    final String proxyPassword = remoteProcessGroupDTO.getProxyPassword();

    final String transportProtocol = remoteProcessGroupDTO.getTransportProtocol();
    final String localNetworkInterface = remoteProcessGroupDTO.getLocalNetworkInterface();

    if (isNotNull(targetUris)) {
        remoteProcessGroup.setTargetUris(targetUris);
    }
    if (isNotNull(name)) {
        remoteProcessGroup.setName(name);
    }
    if (isNotNull(comments)) {
        remoteProcessGroup.setComments(comments);
    }
    if (isNotNull(communicationsTimeout)) {
        remoteProcessGroup.setCommunicationsTimeout(communicationsTimeout);
    }
    if (isNotNull(yieldDuration)) {
        remoteProcessGroup.setYieldDuration(yieldDuration);
    }
    if (isNotNull(remoteProcessGroupDTO.getPosition())) {
        remoteProcessGroup.setPosition(new Position(remoteProcessGroupDTO.getPosition().getX(), remoteProcessGroupDTO.getPosition().getY()));
    }
    if (isNotNull(transportProtocol)) {
        remoteProcessGroup.setTransportProtocol(SiteToSiteTransportProtocol.valueOf(transportProtocol.toUpperCase()));
        // No null check because these proxy settings have to be clear if not specified.
        // But when user Enable/Disable transmission, only isTransmitting is sent.
        // To prevent clearing these values in that case, set these only if transportProtocol is sent,
        // assuming UI sends transportProtocol always for update.
        remoteProcessGroup.setProxyHost(proxyHost);
        remoteProcessGroup.setProxyPort(proxyPort);
        remoteProcessGroup.setProxyUser(proxyUser);
        // Keep using current password when null or "********" was sent.
        // Passing other values updates the password,
        // specify empty String to clear password.
        if (isNotNull(proxyPassword) && !DtoFactory.SENSITIVE_VALUE_MASK.equals(proxyPassword)) {
            remoteProcessGroup.setProxyPassword(proxyPassword);
        }
    }
    if (localNetworkInterface != null) {
        if (StringUtils.isBlank(localNetworkInterface)) {
            remoteProcessGroup.setNetworkInterface(null);
        } else {
            remoteProcessGroup.setNetworkInterface(localNetworkInterface);
        }
    }

    final Boolean isTransmitting = remoteProcessGroupDTO.isTransmitting();
    if (isNotNull(isTransmitting)) {
        // start or stop as necessary
        if (!remoteProcessGroup.isTransmitting() && isTransmitting) {
            remoteProcessGroup.startTransmitting();
        } else if (remoteProcessGroup.isTransmitting() && !isTransmitting) {
            remoteProcessGroup.stopTransmitting();
        }
    }

    final ProcessGroup group = remoteProcessGroup.getProcessGroup();
    if (group != null) {
        group.onComponentModified();
    }
    return remoteProcessGroup;
}