Search in sources :

Example 1 with VersionedRemoteGroupPort

use of org.apache.nifi.registry.flow.VersionedRemoteGroupPort in project nifi by apache.

the class TestFlowDifferenceFilters method testFilterAddedRemotePortsWithRemoteInputPortAsComponentA.

@Test
public void testFilterAddedRemotePortsWithRemoteInputPortAsComponentA() {
    VersionedRemoteGroupPort remoteGroupPort = new VersionedRemoteGroupPort();
    remoteGroupPort.setComponentType(ComponentType.REMOTE_INPUT_PORT);
    StandardFlowDifference flowDifference = new StandardFlowDifference(DifferenceType.COMPONENT_ADDED, remoteGroupPort, null, null, null, "");
    // predicate should return false because we don't want to include changes for adding a remote input port
    Assert.assertFalse(FlowDifferenceFilters.FILTER_ADDED_REMOVED_REMOTE_PORTS.test(flowDifference));
}
Also used : StandardFlowDifference(org.apache.nifi.registry.flow.diff.StandardFlowDifference) VersionedRemoteGroupPort(org.apache.nifi.registry.flow.VersionedRemoteGroupPort) Test(org.junit.Test)

Example 2 with VersionedRemoteGroupPort

use of org.apache.nifi.registry.flow.VersionedRemoteGroupPort in project nifi by apache.

the class TestFlowDifferenceFilters method testFilterAddedRemotePortsWithRemoteOutputPort.

@Test
public void testFilterAddedRemotePortsWithRemoteOutputPort() {
    VersionedRemoteGroupPort remoteGroupPort = new VersionedRemoteGroupPort();
    remoteGroupPort.setComponentType(ComponentType.REMOTE_OUTPUT_PORT);
    StandardFlowDifference flowDifference = new StandardFlowDifference(DifferenceType.COMPONENT_ADDED, null, remoteGroupPort, null, null, "");
    // predicate should return false because we don't want to include changes for adding a remote input port
    Assert.assertFalse(FlowDifferenceFilters.FILTER_ADDED_REMOVED_REMOTE_PORTS.test(flowDifference));
}
Also used : StandardFlowDifference(org.apache.nifi.registry.flow.diff.StandardFlowDifference) VersionedRemoteGroupPort(org.apache.nifi.registry.flow.VersionedRemoteGroupPort) Test(org.junit.Test)

Example 3 with VersionedRemoteGroupPort

use of org.apache.nifi.registry.flow.VersionedRemoteGroupPort in project nifi by apache.

the class StandardProcessGroup method updateFlow.

@Override
public void updateFlow(final VersionedFlowSnapshot proposedSnapshot, final String componentIdSeed, final boolean verifyNotDirty, final boolean updateSettings, final boolean updateDescendantVersionedFlows) {
    writeLock.lock();
    try {
        verifyCanUpdate(proposedSnapshot, true, verifyNotDirty);
        final NiFiRegistryFlowMapper mapper = new NiFiRegistryFlowMapper();
        final VersionedProcessGroup versionedGroup = mapper.mapProcessGroup(this, controllerServiceProvider, flowController.getFlowRegistryClient(), true);
        final ComparableDataFlow localFlow = new StandardComparableDataFlow("Local Flow", versionedGroup);
        final ComparableDataFlow remoteFlow = new StandardComparableDataFlow("Remote Flow", proposedSnapshot.getFlowContents());
        final FlowComparator flowComparator = new StandardFlowComparator(remoteFlow, localFlow, getAncestorGroupServiceIds(), new StaticDifferenceDescriptor());
        final FlowComparison flowComparison = flowComparator.compare();
        final Set<String> updatedVersionedComponentIds = new HashSet<>();
        for (final FlowDifference diff : flowComparison.getDifferences()) {
            // Ignore these as local differences for now because we can't do anything with it
            if (diff.getDifferenceType() == DifferenceType.BUNDLE_CHANGED) {
                continue;
            }
            // and if so compare our VersionedControllerService to the existing service.
            if (diff.getDifferenceType() == DifferenceType.COMPONENT_ADDED) {
                final VersionedComponent component = diff.getComponentA() == null ? diff.getComponentB() : diff.getComponentA();
                if (ComponentType.CONTROLLER_SERVICE == component.getComponentType()) {
                    final ControllerServiceNode serviceNode = getVersionedControllerService(this, component.getIdentifier());
                    if (serviceNode != null) {
                        final VersionedControllerService versionedService = mapper.mapControllerService(serviceNode, controllerServiceProvider);
                        final Set<FlowDifference> differences = flowComparator.compareControllerServices(versionedService, (VersionedControllerService) component);
                        if (!differences.isEmpty()) {
                            updatedVersionedComponentIds.add(component.getIdentifier());
                        }
                        continue;
                    }
                }
            }
            final VersionedComponent component = diff.getComponentA() == null ? diff.getComponentB() : diff.getComponentA();
            updatedVersionedComponentIds.add(component.getIdentifier());
            if (component.getComponentType() == ComponentType.REMOTE_INPUT_PORT || component.getComponentType() == ComponentType.REMOTE_OUTPUT_PORT) {
                final String remoteGroupId = ((VersionedRemoteGroupPort) component).getRemoteGroupId();
                updatedVersionedComponentIds.add(remoteGroupId);
            }
        }
        if (LOG.isInfoEnabled()) {
            final String differencesByLine = flowComparison.getDifferences().stream().map(FlowDifference::toString).collect(Collectors.joining("\n"));
            LOG.info("Updating {} to {}; there are {} differences to take into account:\n{}", this, proposedSnapshot, flowComparison.getDifferences().size(), differencesByLine);
        }
        final Set<String> knownVariables = getKnownVariableNames();
        final StandardVersionControlInformation originalVci = this.versionControlInfo.get();
        try {
            updateProcessGroup(this, proposedSnapshot.getFlowContents(), componentIdSeed, updatedVersionedComponentIds, false, updateSettings, updateDescendantVersionedFlows, knownVariables);
        } catch (final Throwable t) {
            // As a result, it is safe to use the get() and then the set() methods of the AtomicReference without introducing the 'check-then-modify' problem.
            if (this.versionControlInfo.get() == null) {
                this.versionControlInfo.set(originalVci);
            }
            throw t;
        }
    } catch (final ProcessorInstantiationException pie) {
        throw new IllegalStateException("Failed to update flow", pie);
    } finally {
        writeLock.unlock();
    }
}
Also used : StandardVersionControlInformation(org.apache.nifi.registry.flow.StandardVersionControlInformation) NiFiRegistryFlowMapper(org.apache.nifi.registry.flow.mapping.NiFiRegistryFlowMapper) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) FlowComparison(org.apache.nifi.registry.flow.diff.FlowComparison) VersionedRemoteGroupPort(org.apache.nifi.registry.flow.VersionedRemoteGroupPort) VersionedControllerService(org.apache.nifi.registry.flow.VersionedControllerService) StandardFlowComparator(org.apache.nifi.registry.flow.diff.StandardFlowComparator) StaticDifferenceDescriptor(org.apache.nifi.registry.flow.diff.StaticDifferenceDescriptor) StandardComparableDataFlow(org.apache.nifi.registry.flow.diff.StandardComparableDataFlow) ComparableDataFlow(org.apache.nifi.registry.flow.diff.ComparableDataFlow) VersionedComponent(org.apache.nifi.registry.flow.VersionedComponent) FlowDifference(org.apache.nifi.registry.flow.diff.FlowDifference) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ProcessorInstantiationException(org.apache.nifi.controller.exception.ProcessorInstantiationException) StandardComparableDataFlow(org.apache.nifi.registry.flow.diff.StandardComparableDataFlow) FlowComparator(org.apache.nifi.registry.flow.diff.FlowComparator) StandardFlowComparator(org.apache.nifi.registry.flow.diff.StandardFlowComparator) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Example 4 with VersionedRemoteGroupPort

use of org.apache.nifi.registry.flow.VersionedRemoteGroupPort in project nifi-minifi by apache.

the class VersionedProcessGroupEnricher method enrich.

public void enrich(final VersionedProcessGroup versionedProcessGroup) {
    List<VersionedProcessGroup> allVersionedProcessGroups = getAllVersionedProcessGroups(versionedProcessGroup);
    Set<VersionedRemoteProcessGroup> remoteProcessGroups = getAll(allVersionedProcessGroups, VersionedProcessGroup::getRemoteProcessGroups).collect(Collectors.toSet());
    Map<String, String> connectableNameMap = getAll(allVersionedProcessGroups, VersionedProcessGroup::getProcessors).collect(Collectors.toMap(VersionedComponent::getIdentifier, VersionedComponent::getName));
    Map<String, String> rpgIdToTargetIdMap = new HashMap<>();
    for (VersionedRemoteProcessGroup remoteProcessGroup : remoteProcessGroups) {
        final Set<VersionedRemoteGroupPort> rpgInputPorts = nullToEmpty(remoteProcessGroup.getInputPorts());
        final Set<VersionedRemoteGroupPort> rpgOutputPorts = nullToEmpty(remoteProcessGroup.getOutputPorts());
        // Map all port DTOs to their respective targetIds
        rpgIdToTargetIdMap.putAll(Stream.concat(rpgInputPorts.stream(), rpgOutputPorts.stream()).collect(Collectors.toMap(VersionedRemoteGroupPort::getIdentifier, VersionedRemoteGroupPort::getTargetId)));
        addConnectables(connectableNameMap, rpgInputPorts, VersionedRemoteGroupPort::getIdentifier, VersionedRemoteGroupPort::getIdentifier);
        addConnectables(connectableNameMap, rpgOutputPorts, VersionedRemoteGroupPort::getIdentifier, VersionedRemoteGroupPort::getIdentifier);
    }
    addConnectables(connectableNameMap, getAll(allVersionedProcessGroups, VersionedProcessGroup::getInputPorts).collect(Collectors.toList()), VersionedPort::getIdentifier, VersionedPort::getName);
    addConnectables(connectableNameMap, getAll(allVersionedProcessGroups, VersionedProcessGroup::getOutputPorts).collect(Collectors.toList()), VersionedPort::getIdentifier, VersionedPort::getName);
    final Set<VersionedConnection> connections = getAll(allVersionedProcessGroups, VersionedProcessGroup::getConnections).collect(Collectors.toSet());
    // Enrich connection endpoints using known names and overriding with targetIds for remote ports
    for (VersionedConnection connection : connections) {
        setName(connectableNameMap, connection.getSource(), rpgIdToTargetIdMap);
        setName(connectableNameMap, connection.getDestination(), rpgIdToTargetIdMap);
    }
    // Override any ids that are for Remote Ports to use their target Ids where available
    connections.stream().flatMap(connectionDTO -> Stream.of(connectionDTO.getSource(), connectionDTO.getDestination())).filter(connectable -> (connectable.getType() == ConnectableComponentType.REMOTE_OUTPUT_PORT || connectable.getType() == ConnectableComponentType.REMOTE_INPUT_PORT)).forEach(connectable -> connectable.setId(Optional.ofNullable(rpgIdToTargetIdMap.get(connectable.getId())).orElse(connectable.getId())));
    // Establish unique names for connections
    for (VersionedConnection connection : connections) {
        if (StringUtil.isNullOrEmpty(connection.getName())) {
            StringBuilder name = new StringBuilder();
            ConnectableComponent connectionSource = connection.getSource();
            name.append(determineValueForConnectable(connectionSource, rpgIdToTargetIdMap));
            name.append("/");
            if (connection.getSelectedRelationships() != null && connection.getSelectedRelationships().size() > 0) {
                name.append(connection.getSelectedRelationships().iterator().next());
            }
            name.append("/");
            ConnectableComponent connectionDestination = connection.getDestination();
            name.append(determineValueForConnectable(connectionDestination, rpgIdToTargetIdMap));
            connection.setName(name.toString());
        }
    }
    nullToEmpty(versionedProcessGroup.getProcessGroups()).stream().forEach(pg -> enrich(pg));
}
Also used : ConnectableComponent(org.apache.nifi.registry.flow.ConnectableComponent) Collection(java.util.Collection) Set(java.util.Set) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) VersionedRemoteGroupPort(org.apache.nifi.registry.flow.VersionedRemoteGroupPort) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) StringUtil(org.apache.nifi.minifi.commons.schema.common.StringUtil) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) Map(java.util.Map) VersionedPort(org.apache.nifi.registry.flow.VersionedPort) VersionedRemoteProcessGroup(org.apache.nifi.registry.flow.VersionedRemoteProcessGroup) Optional(java.util.Optional) CollectionUtil.nullToEmpty(org.apache.nifi.minifi.commons.schema.common.CollectionUtil.nullToEmpty) VersionedComponent(org.apache.nifi.registry.flow.VersionedComponent) VersionedConnection(org.apache.nifi.registry.flow.VersionedConnection) ConnectableComponentType(org.apache.nifi.registry.flow.ConnectableComponentType) HashMap(java.util.HashMap) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) VersionedRemoteGroupPort(org.apache.nifi.registry.flow.VersionedRemoteGroupPort) VersionedPort(org.apache.nifi.registry.flow.VersionedPort) ConnectableComponent(org.apache.nifi.registry.flow.ConnectableComponent) VersionedRemoteProcessGroup(org.apache.nifi.registry.flow.VersionedRemoteProcessGroup) VersionedConnection(org.apache.nifi.registry.flow.VersionedConnection)

Example 5 with VersionedRemoteGroupPort

use of org.apache.nifi.registry.flow.VersionedRemoteGroupPort in project nifi by apache.

the class NiFiRegistryFlowMapper method mapRemotePort.

public VersionedRemoteGroupPort mapRemotePort(final RemoteGroupPort remotePort, final ComponentType componentType) {
    final VersionedRemoteGroupPort port = new InstantiatedVersionedRemoteGroupPort(remotePort.getIdentifier(), remotePort.getRemoteProcessGroup().getIdentifier());
    port.setIdentifier(getId(remotePort.getVersionedComponentId(), remotePort.getIdentifier()));
    port.setGroupIdentifier(getGroupId(remotePort.getRemoteProcessGroup().getIdentifier()));
    port.setComments(remotePort.getComments());
    port.setConcurrentlySchedulableTaskCount(remotePort.getMaxConcurrentTasks());
    port.setRemoteGroupId(getGroupId(remotePort.getRemoteProcessGroup().getIdentifier()));
    port.setName(remotePort.getName());
    port.setUseCompression(remotePort.isUseCompression());
    port.setBatchSize(mapBatchSettings(remotePort));
    port.setTargetId(remotePort.getTargetIdentifier());
    port.setComponentType(componentType);
    return port;
}
Also used : VersionedRemoteGroupPort(org.apache.nifi.registry.flow.VersionedRemoteGroupPort)

Aggregations

VersionedRemoteGroupPort (org.apache.nifi.registry.flow.VersionedRemoteGroupPort)6 StandardFlowDifference (org.apache.nifi.registry.flow.diff.StandardFlowDifference)3 Test (org.junit.Test)3 VersionedComponent (org.apache.nifi.registry.flow.VersionedComponent)2 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 StringUtils (org.apache.commons.lang3.StringUtils)1 ProcessorInstantiationException (org.apache.nifi.controller.exception.ProcessorInstantiationException)1