final VersionedProcessGroup copy = new VersionedProcessGroup(); copy.setComments(processGroup.getComments()); copy.setComponentType(processGroup.getComponentType()); copy.setGroupIdentifier(processGroup.getGroupIdentifier()); copy.setIdentifier(processGroup.getIdentifier()); copy.setName(processGroup.getName()); copy.setPosition(processGroup.getPosition()); copy.setVersionedFlowCoordinates(topLevel ? null : processGroup.getVersionedFlowCoordinates()); copy.setConnections(processGroup.getConnections()); copy.setControllerServices(processGroup.getControllerServices()); copy.setFunnels(processGroup.getFunnels()); copy.setInputPorts(processGroup.getInputPorts()); copy.setOutputPorts(processGroup.getOutputPorts()); copy.setProcessors(processGroup.getProcessors()); copy.setRemoteProcessGroups(processGroup.getRemoteProcessGroups()); copy.setVariables(processGroup.getVariables()); copy.setLabels(processGroup.getLabels()); for (final VersionedProcessGroup childGroup : processGroup.getProcessGroups()) { if (childGroup.getVersionedFlowCoordinates() == null) { copyChildren.add(stripContentsFromRemoteDescendantGroups(childGroup, false)); } else { final VersionedProcessGroup childCopy = new VersionedProcessGroup(); childCopy.setComments(childGroup.getComments()); childCopy.setComponentType(childGroup.getComponentType()); childCopy.setGroupIdentifier(childGroup.getGroupIdentifier()); childCopy.setIdentifier(childGroup.getIdentifier()); childCopy.setName(childGroup.getName()); childCopy.setPosition(childGroup.getPosition());
private void findAllProcessGroups(final VersionedProcessGroup group, final Map<String, VersionedProcessGroup> map) { map.put(group.getIdentifier(), group); for (final VersionedProcessGroup child : group.getProcessGroups()) { findAllProcessGroups(child, map); } }
private Set<VersionedConnection> findAllConnections(final VersionedProcessGroup group) { final Set<VersionedConnection> conns = new HashSet<>(); for (final VersionedConnection connection : group.getConnections()) { conns.add(connection); } for (final VersionedProcessGroup childGroup : group.getProcessGroups()) { conns.addAll(findAllConnections(childGroup)); } return conns; }
final VersionedFlowCoordinates coordinates = group.getVersionedFlowCoordinates(); if (coordinates != null) { final String registryUrl = coordinates.getRegistryUrl(); final VersionedProcessGroup contents = snapshot.getFlowContents(); group.setComments(contents.getComments()); group.setConnections(contents.getConnections()); group.setControllerServices(contents.getControllerServices()); group.setFunnels(contents.getFunnels()); group.setInputPorts(contents.getInputPorts()); group.setLabels(contents.getLabels()); group.setOutputPorts(contents.getOutputPorts()); group.setProcessGroups(contents.getProcessGroups()); group.setProcessors(contents.getProcessors()); group.setRemoteProcessGroups(contents.getRemoteProcessGroups()); group.setVariables(contents.getVariables()); coordinates.setLatest(snapshot.isLatest()); for (final VersionedProcessGroup child : group.getProcessGroups()) { populateVersionedContentsRecursively(child, user);
map.put(CommonPropertyKeys.PROCESSORS_KEY, nullToEmpty(versionedProcessGroup.getProcessors()).stream() .map(processorSchemaFunction) .sorted(Comparator.comparing(ProcessorSchema::getName)) map.put(CommonPropertyKeys.CONTROLLER_SERVICES_KEY, nullToEmpty(versionedProcessGroup.getControllerServices()).stream() .map(controllerServiceSchemaFunction) .sorted(Comparator.comparing(ControllerServiceSchema::getName)) map.put(CommonPropertyKeys.CONNECTIONS_KEY, nullToEmpty(versionedProcessGroup.getConnections()).stream() .map(connectionSchemaFunction) .sorted(Comparator.comparing(ConnectionSchema::getName)) map.put(CommonPropertyKeys.FUNNELS_KEY, CollectionUtil.nullToEmpty(versionedProcessGroup.getFunnels()).stream() .map(funnelSchemaFunction) .sorted(Comparator.comparing(FunnelSchema::getId)) map.put(CommonPropertyKeys.REMOTE_PROCESS_GROUPS_KEY, nullToEmpty(versionedProcessGroup.getRemoteProcessGroups()).stream() .map(remoteProcessGroupSchemaFunction) .sorted(Comparator.comparing(RemoteProcessGroupSchema::getName)) map.put(INPUT_PORTS_KEY, nullToEmpty(versionedProcessGroup.getInputPorts()).stream() .map(inputPortSchemaFunction) .sorted(Comparator.comparing(PortSchema::getName)) map.put(OUTPUT_PORTS_KEY, nullToEmpty(versionedProcessGroup.getOutputPorts()).stream() .map(outputPortSchemaFunction) .sorted(Comparator.comparing(PortSchema::getName)) map.put(ProcessGroupSchema.PROCESS_GROUPS_KEY, nullToEmpty(versionedProcessGroup.getProcessGroups()).stream()
group.setComments(proposed.getComments()); group.setName(proposed.getName()); if (updatePosition && proposed.getPosition() != null) { group.setPosition(new Position(proposed.getPosition().getX(), proposed.getPosition().getY())); for (final Map.Entry<String, String> entry : proposed.getVariables().entrySet()) { if (!existingVariableNames.contains(entry.getKey()) && !variablesToSkip.contains(entry.getKey())) { updatedVariableMap.put(entry.getKey(), entry.getValue()); final VersionedFlowCoordinates remoteCoordinates = proposed.getVersionedFlowCoordinates(); if (remoteCoordinates == null) { group.disconnectVersionControl(false); for (final VersionedControllerService proposedService : proposed.getControllerServices()) { ControllerServiceNode service = servicesByVersionedId.get(proposedService.getIdentifier()); if (service == null) { for (final VersionedProcessGroup proposedChildGroup : proposed.getProcessGroups()) { final ProcessGroup childGroup = childGroupsByVersionedId.get(proposedChildGroup.getIdentifier()); final VersionedFlowCoordinates childCoordinates = proposedChildGroup.getVersionedFlowCoordinates(); childGroupsRemoved.remove(proposedChildGroup.getIdentifier()); for (final VersionedFunnel proposedFunnel : proposed.getFunnels()) { final Funnel funnel = funnelsByVersionedId.get(proposedFunnel.getIdentifier()); if (funnel == null) {
private void compare(final VersionedProcessGroup groupA, final VersionedProcessGroup groupB, final Set<FlowDifference> differences, final boolean compareNamePos) { if (compareComponents(groupA, groupB, differences, compareNamePos, compareNamePos, true)) { return; } if (groupA == null) { differences.add(difference(DifferenceType.COMPONENT_ADDED, groupA, groupB, groupA, groupB)); return; } if (groupB == null) { differences.add(difference(DifferenceType.COMPONENT_REMOVED, groupA, groupB, groupA, groupB)); return; } addIfDifferent(differences, DifferenceType.VERSIONED_FLOW_COORDINATES_CHANGED, groupA, groupB, VersionedProcessGroup::getVersionedFlowCoordinates); if (groupA.getVersionedFlowCoordinates() == null && groupB.getVersionedFlowCoordinates() == null) { differences.addAll(compareComponents(groupA.getConnections(), groupB.getConnections(), this::compare)); differences.addAll(compareComponents(groupA.getProcessors(), groupB.getProcessors(), this::compare)); differences.addAll(compareComponents(groupA.getControllerServices(), groupB.getControllerServices(), this::compare)); differences.addAll(compareComponents(groupA.getFunnels(), groupB.getFunnels(), this::compare)); differences.addAll(compareComponents(groupA.getInputPorts(), groupB.getInputPorts(), this::compare)); differences.addAll(compareComponents(groupA.getLabels(), groupB.getLabels(), this::compare)); differences.addAll(compareComponents(groupA.getOutputPorts(), groupB.getOutputPorts(), this::compare)); differences.addAll(compareComponents(groupA.getProcessGroups(), groupB.getProcessGroups(), (a, b, diffs) -> compare(a, b, diffs, true))); differences.addAll(compareComponents(groupA.getRemoteProcessGroups(), groupB.getRemoteProcessGroups(), this::compare)); } }
private static void populateComponentTypes(final VersionedProcessGroup group, final Set<Tuple<String, BundleCoordinate>> componentTypes) { group.getProcessors().stream() .map(versionedProc -> new Tuple<>(versionedProc.getType(), createBundleCoordinate(versionedProc.getBundle()))) .forEach(componentTypes::add); group.getControllerServices().stream() .map(versionedSvc -> new Tuple<>(versionedSvc.getType(), createBundleCoordinate(versionedSvc.getBundle()))) .forEach(componentTypes::add); for (final VersionedProcessGroup childGroup : group.getProcessGroups()) { populateComponentTypes(childGroup, componentTypes); } }
private void findAllProcessors(final VersionedProcessGroup group, final Map<String, VersionedProcessor> map) { for (final VersionedProcessor processor : group.getProcessors()) { map.put(processor.getIdentifier(), processor); } for (final VersionedProcessGroup childGroup : group.getProcessGroups()) { findAllProcessors(childGroup, map); } }
private void findAllControllerServices(final VersionedProcessGroup group, final Map<String, VersionedControllerService> map) { for (final VersionedControllerService service : group.getControllerServices()) { map.put(service.getIdentifier(), service); } for (final VersionedProcessGroup childGroup : group.getProcessGroups()) { findAllControllerServices(childGroup, map); } }
@Override public VersionedFlowSnapshot getFlowContents(final String bucketId, final String flowId, final int version, final boolean fetchRemoteFlows, final NiFiUser user) throws IOException, NiFiRegistryException { final FlowSnapshotClient snapshotClient = getFlowSnapshotClient(user); final VersionedFlowSnapshot flowSnapshot = snapshotClient.get(bucketId, flowId, version); if (fetchRemoteFlows) { final VersionedProcessGroup contents = flowSnapshot.getFlowContents(); for (final VersionedProcessGroup child : contents.getProcessGroups()) { populateVersionedContentsRecursively(child, user); } } return flowSnapshot; }
private void verifyImportProcessGroup(final VersionControlInformationDTO vciDto, final VersionedProcessGroup contents, final ProcessGroup group) { if (group == null) { return; } final VersionControlInformation vci = group.getVersionControlInformation(); if (vci != null) { // Note that we do not compare the Registry ID here because there could be two registry clients // that point to the same server (one could point to localhost while another points to 127.0.0.1, for instance).. if (Objects.equals(vciDto.getBucketId(), vci.getBucketIdentifier()) && Objects.equals(vciDto.getFlowId(), vci.getFlowIdentifier())) { throw new IllegalStateException("Cannot import the specified Versioned Flow into the Process Group because doing so would cause a recursive dataflow. " + "If Process Group A contains Process Group B, then Process Group B is not allowed to contain the flow identified by Process Group A."); } } final Set<VersionedProcessGroup> childGroups = contents.getProcessGroups(); if (childGroups != null) { for (final VersionedProcessGroup childGroup : childGroups) { final VersionedFlowCoordinates childCoordinates = childGroup.getVersionedFlowCoordinates(); if (childCoordinates != null) { final VersionControlInformationDTO childVci = new VersionControlInformationDTO(); childVci.setBucketId(childCoordinates.getBucketId()); childVci.setFlowId(childCoordinates.getFlowId()); verifyImportProcessGroup(childVci, childGroup, group); } } } verifyImportProcessGroup(vciDto, contents, group.getParent()); }
@Override public FlowControllerSchema apply(final VersionedFlowSnapshot versionedFlowSnapshot) { // If the VersionedFlowSnapshot came directly from NiFi Registry without modification, as would be the // case with C2 server, then we should have a non-null VersionedFlow, but if we're using a snapshot that // was export from another tool like the CLI, the flow may be null'd out, so fall back to root group. String name; String description; if (versionedFlowSnapshot.getFlow() == null) { name = versionedFlowSnapshot.getFlowContents().getName(); description = versionedFlowSnapshot.getFlowContents().getComments(); } else { name = versionedFlowSnapshot.getFlow().getName(); description = versionedFlowSnapshot.getFlow().getDescription(); } Map<String, Object> map = new HashMap<>(); map.put(CommonPropertyKeys.NAME_KEY, name); map.put(CommonPropertyKeys.COMMENT_KEY, description); return new FlowControllerSchema(map); } }
.filter(port -> port.getVersionedComponentId().isPresent()) .forEach(port -> removedInputPortsByVersionId.put(port.getVersionedComponentId().get(), port)); flowContents.getInputPorts().stream() .map(VersionedPort::getIdentifier) .forEach(removedInputPortsByVersionId::remove); .filter(port -> port.getVersionedComponentId().isPresent()) .forEach(port -> removedOutputPortsByVersionId.put(port.getVersionedComponentId().get(), port)); flowContents.getOutputPorts().stream() .map(VersionedPort::getIdentifier) .forEach(removedOutputPortsByVersionId::remove);
if (flowSnapshot != null && StringUtils.isNotBlank(flowSnapshot.getFlowContents().getName()) && StringUtils.isBlank(processGroup.getName())) { processGroup.setName(flowSnapshot.getFlowContents().getName()); flowSnapshot.getFlowContents().setPosition(null); entity = serviceFacade.updateProcessGroupContents(newGroupRevision, newGroupId, versionControlInfo, flowSnapshot, getIdGenerationSeed().orElse(null), false, true, true);
final VersionedProcessGroup versionedProcessGroupB = (VersionedProcessGroup) componentB; final VersionedFlowCoordinates coordinatesA = versionedProcessGroupA.getVersionedFlowCoordinates(); final VersionedFlowCoordinates coordinatesB = versionedProcessGroupB.getVersionedFlowCoordinates();
map.put(CommonPropertyKeys.PROCESSORS_KEY, nullToEmpty(versionedProcessGroup.getProcessors()).stream() .map(processorSchemaFunction) .sorted(Comparator.comparing(ProcessorSchema::getName)) map.put(CommonPropertyKeys.CONTROLLER_SERVICES_KEY, nullToEmpty(versionedProcessGroup.getControllerServices()).stream() .map(controllerServiceSchemaFunction) .sorted(Comparator.comparing(ControllerServiceSchema::getName)) map.put(CommonPropertyKeys.CONNECTIONS_KEY, nullToEmpty(versionedProcessGroup.getConnections()).stream() .map(connectionSchemaFunction) .sorted(Comparator.comparing(ConnectionSchema::getName)) map.put(CommonPropertyKeys.FUNNELS_KEY, CollectionUtil.nullToEmpty(versionedProcessGroup.getFunnels()).stream() .map(funnelSchemaFunction) .sorted(Comparator.comparing(FunnelSchema::getId)) map.put(CommonPropertyKeys.REMOTE_PROCESS_GROUPS_KEY, nullToEmpty(versionedProcessGroup.getRemoteProcessGroups()).stream() .map(remoteProcessGroupSchemaFunction) .sorted(Comparator.comparing(RemoteProcessGroupSchema::getName)) map.put(INPUT_PORTS_KEY, nullToEmpty(versionedProcessGroup.getInputPorts()).stream() .map(inputPortSchemaFunction) .sorted(Comparator.comparing(PortSchema::getName)) map.put(OUTPUT_PORTS_KEY, nullToEmpty(versionedProcessGroup.getOutputPorts()).stream() .map(outputPortSchemaFunction) .sorted(Comparator.comparing(PortSchema::getName)) map.put(ProcessGroupSchema.PROCESS_GROUPS_KEY, nullToEmpty(versionedProcessGroup.getProcessGroups()).stream()
if (versionedGroup.getProcessors() != null) { versionedGroup.getProcessors().forEach(processor -> { final BundleCoordinate coordinate = BundleUtils.getCompatibleBundle(extensionManager, processor.getType(), createBundleDto(processor.getBundle())); if (versionedGroup.getControllerServices() != null) { versionedGroup.getControllerServices().forEach(controllerService -> { final BundleCoordinate coordinate = BundleUtils.getCompatibleBundle(extensionManager, controllerService.getType(), createBundleDto(controllerService.getBundle())); if (versionedGroup.getProcessGroups() != null) { versionedGroup.getProcessGroups().forEach(processGroup -> { discoverCompatibleBundles(extensionManager, processGroup); });
private void findAllConnectionIds(final VersionedProcessGroup group, final Set<String> ids) { for (final VersionedConnection connection : group.getConnections()) { ids.add(connection.getIdentifier()); } for (final VersionedProcessGroup childGroup : group.getProcessGroups()) { findAllConnectionIds(childGroup, ids); } }
private void verifyProcessorsInVersionedFlow(final VersionedProcessGroup versionedFlow, final Map<String, Set<BundleCoordinate>> supportedTypes) { if (versionedFlow.getProcessors() != null) { versionedFlow.getProcessors().forEach(processor -> { if (processor.getBundle() == null) { throw new IllegalArgumentException("Processor bundle must be specified."); } if (supportedTypes.containsKey(processor.getType())) { verifyBundleInVersionedFlow(processor.getBundle(), supportedTypes.get(processor.getType())); } else { throw new IllegalStateException("Invalid Processor Type: " + processor.getType()); } }); } if (versionedFlow.getProcessGroups() != null) { versionedFlow.getProcessGroups().forEach(processGroup -> { verifyProcessorsInVersionedFlow(processGroup, supportedTypes); }); } }