use of org.apache.nifi.registry.diff.ComponentDifferenceGroup 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.diff.ComponentDifferenceGroup 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());
}
use of org.apache.nifi.registry.diff.ComponentDifferenceGroup in project nifi-registry by apache.
the class DataModelMapper method map.
public static ComponentDifferenceGroup map(VersionedComponent versionedComponent) {
ComponentDifferenceGroup grouping = new ComponentDifferenceGroup();
grouping.setComponentId(versionedComponent.getIdentifier());
grouping.setComponentName(versionedComponent.getName());
grouping.setProcessGroupId(versionedComponent.getGroupIdentifier());
grouping.setComponentType(versionedComponent.getComponentType().getTypeName());
return grouping;
}
use of org.apache.nifi.registry.diff.ComponentDifferenceGroup in project nifi-registry by apache.
the class RegistryService method getFlowDiff.
/**
* Returns the differences between two specified versions of a flow.
*
* @param bucketIdentifier the id of the bucket the flow exists in
* @param flowIdentifier the flow to be examined
* @param versionA the first version of the comparison
* @param versionB the second version of the comparison
* @return The differences between two specified versions, grouped by component.
*/
public VersionedFlowDifference getFlowDiff(final String bucketIdentifier, final String flowIdentifier, final Integer versionA, final Integer versionB) {
if (StringUtils.isBlank(bucketIdentifier)) {
throw new IllegalArgumentException("Bucket identifier cannot be null or blank");
}
if (StringUtils.isBlank(flowIdentifier)) {
throw new IllegalArgumentException("Flow identifier cannot be null or blank");
}
if (versionA == null || versionB == null) {
throw new IllegalArgumentException("Version cannot be null or blank");
}
// older version is always the lower, regardless of the order supplied
final Integer older = Math.min(versionA, versionB);
final Integer newer = Math.max(versionA, versionB);
readLock.lock();
try {
// Get the content for both versions of the flow
final byte[] serializedSnapshotA = flowPersistenceProvider.getFlowContent(bucketIdentifier, flowIdentifier, older);
if (serializedSnapshotA == null || serializedSnapshotA.length == 0) {
throw new IllegalStateException("No serialized content found for snapshot with flow identifier " + flowIdentifier + " and version " + older);
}
final byte[] serializedSnapshotB = flowPersistenceProvider.getFlowContent(bucketIdentifier, flowIdentifier, newer);
if (serializedSnapshotB == null || serializedSnapshotB.length == 0) {
throw new IllegalStateException("No serialized content found for snapshot with flow identifier " + flowIdentifier + " and version " + newer);
}
// deserialize the contents
final InputStream inputA = new ByteArrayInputStream(serializedSnapshotA);
final VersionedProcessGroup flowContentsA = processGroupSerializer.deserialize(inputA);
final InputStream inputB = new ByteArrayInputStream(serializedSnapshotB);
final VersionedProcessGroup flowContentsB = processGroupSerializer.deserialize(inputB);
final ComparableDataFlow comparableFlowA = new StandardComparableDataFlow(String.format("Version %d", older), flowContentsA);
final ComparableDataFlow comparableFlowB = new StandardComparableDataFlow(String.format("Version %d", newer), flowContentsB);
// Compare the two versions of the flow
final FlowComparator flowComparator = new StandardFlowComparator(comparableFlowA, comparableFlowB, null, new ConciseEvolvingDifferenceDescriptor());
final FlowComparison flowComparison = flowComparator.compare();
VersionedFlowDifference result = new VersionedFlowDifference();
result.setBucketId(bucketIdentifier);
result.setFlowId(flowIdentifier);
result.setVersionA(older);
result.setVersionB(newer);
Set<ComponentDifferenceGroup> differenceGroups = getStringComponentDifferenceGroupMap(flowComparison.getDifferences());
result.setComponentDifferenceGroups(differenceGroups);
return result;
} finally {
readLock.unlock();
}
}
use of org.apache.nifi.registry.diff.ComponentDifferenceGroup in project nifi-registry by apache.
the class RegistryService method getStringComponentDifferenceGroupMap.
/**
* Group the differences in the comparison by component
* @param flowDifferences The differences to group together by component
* @return A set of componentDifferenceGroups where each entry contains a set of differences specific to that group
*/
private Set<ComponentDifferenceGroup> getStringComponentDifferenceGroupMap(Set<FlowDifference> flowDifferences) {
Map<String, ComponentDifferenceGroup> differenceGroups = new HashMap<>();
for (FlowDifference diff : flowDifferences) {
ComponentDifferenceGroup group;
// A component may only exist on only one version for new/removed components
VersionedComponent component = ObjectUtils.firstNonNull(diff.getComponentA(), diff.getComponentB());
if (differenceGroups.containsKey(component.getIdentifier())) {
group = differenceGroups.get(component.getIdentifier());
} else {
group = DataModelMapper.map(component);
differenceGroups.put(component.getIdentifier(), group);
}
group.getDifferences().add(DataModelMapper.map(diff));
}
return differenceGroups.values().stream().collect(Collectors.toSet());
}
Aggregations