use of org.apache.nifi.registry.flow.VersionedProcessGroup in project nifi-minifi by apache.
the class NiFiRegConfigSchemaFunction method apply.
@Override
public ConfigSchema apply(final VersionedFlowSnapshot versionedFlowSnapshot) {
Map<String, Object> map = new HashMap<>();
map.put(CommonPropertyKeys.FLOW_CONTROLLER_PROPS_KEY, flowControllerSchemaFunction.apply(versionedFlowSnapshot).toMap());
VersionedProcessGroup versionedProcessGroup = versionedFlowSnapshot.getFlowContents();
addVersionedProcessGroup(map, versionedProcessGroup);
return new ConfigSchema(map);
}
use of org.apache.nifi.registry.flow.VersionedProcessGroup 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));
}
use of org.apache.nifi.registry.flow.VersionedProcessGroup in project nifi-registry by apache.
the class StandardFlowComparator method compare.
@Override
public FlowComparison compare() {
final VersionedProcessGroup groupA = flowA.getContents();
final VersionedProcessGroup groupB = flowB.getContents();
final Set<FlowDifference> differences = compare(groupA, groupB);
return new StandardFlowComparison(flowA, flowB, differences);
}
use of org.apache.nifi.registry.flow.VersionedProcessGroup in project nifi-registry by apache.
the class TestRegistryService method testGetDiffReturnsRemovedComponentChanges.
// -----------------Test Flow Diff Service Method---------------------
@Test
public void testGetDiffReturnsRemovedComponentChanges() {
when(flowPersistenceProvider.getFlowContent(anyString(), anyString(), anyInt())).thenReturn(new byte[10], new byte[10]);
final VersionedProcessGroup pgA = createVersionedProcessGroupA();
final VersionedProcessGroup pgB = createVersionedProcessGroupB();
when(snapshotSerializer.deserialize(any())).thenReturn(pgA, pgB);
final VersionedFlowDifference diff = registryService.getFlowDiff("bucketIdentifier", "flowIdentifier", 1, 2);
assertNotNull(diff);
Optional<ComponentDifferenceGroup> removedComponent = diff.getComponentDifferenceGroups().stream().filter(p -> p.getComponentId().equals("ID-pg1")).findFirst();
assertTrue(removedComponent.isPresent());
assertTrue(removedComponent.get().getDifferences().iterator().next().getDifferenceType().equals("COMPONENT_REMOVED"));
}
use of org.apache.nifi.registry.flow.VersionedProcessGroup in project nifi-registry by apache.
the class TestRegistryService method testGetDiffReturnsChangesInChronologicalOrder.
@Test
public void testGetDiffReturnsChangesInChronologicalOrder() {
when(flowPersistenceProvider.getFlowContent(anyString(), anyString(), anyInt())).thenReturn(new byte[10], new byte[10]);
final VersionedProcessGroup pgA = createVersionedProcessGroupA();
final VersionedProcessGroup pgB = createVersionedProcessGroupB();
when(snapshotSerializer.deserialize(any())).thenReturn(pgA, pgB);
// getFlowDiff orders the changes in ascending order of version number regardless of param order
final VersionedFlowDifference diff = registryService.getFlowDiff("bucketIdentifier", "flowIdentifier", 2, 1);
assertNotNull(diff);
Optional<ComponentDifferenceGroup> nameChangedComponent = diff.getComponentDifferenceGroups().stream().filter(p -> p.getComponentId().equals("ProcessorFirstV1")).findFirst();
assertTrue(nameChangedComponent.isPresent());
ComponentDifference nameChangeDifference = nameChangedComponent.get().getDifferences().stream().filter(d -> d.getDifferenceType().equals("NAME_CHANGED")).findFirst().get();
assertEquals("ProcessorFirstV1", nameChangeDifference.getValueA());
assertEquals("ProcessorFirstV2", nameChangeDifference.getValueB());
}
Aggregations