use of org.apache.nifi.registry.flow.diff.ConciseEvolvingDifferenceDescriptor in project nifi by apache.
the class StandardNiFiServiceFacade method getLocalModifications.
@Override
public FlowComparisonEntity getLocalModifications(final String processGroupId) {
final ProcessGroup processGroup = processGroupDAO.getProcessGroup(processGroupId);
final VersionControlInformation versionControlInfo = processGroup.getVersionControlInformation();
if (versionControlInfo == null) {
throw new IllegalStateException("Process Group with ID " + processGroupId + " is not under Version Control");
}
final FlowRegistry flowRegistry = flowRegistryClient.getFlowRegistry(versionControlInfo.getRegistryIdentifier());
if (flowRegistry == null) {
throw new IllegalStateException("Process Group with ID " + processGroupId + " is tracking to a flow in Flow Registry with ID " + versionControlInfo.getRegistryIdentifier() + " but cannot find a Flow Registry with that identifier");
}
final VersionedFlowSnapshot versionedFlowSnapshot;
try {
versionedFlowSnapshot = flowRegistry.getFlowContents(versionControlInfo.getBucketIdentifier(), versionControlInfo.getFlowIdentifier(), versionControlInfo.getVersion(), true, NiFiUserUtils.getNiFiUser());
} catch (final IOException | NiFiRegistryException e) {
throw new NiFiCoreException("Failed to retrieve flow with Flow Registry in order to calculate local differences due to " + e.getMessage(), e);
}
final NiFiRegistryFlowMapper mapper = new NiFiRegistryFlowMapper();
final VersionedProcessGroup localGroup = mapper.mapProcessGroup(processGroup, controllerFacade.getControllerServiceProvider(), flowRegistryClient, true);
final VersionedProcessGroup registryGroup = versionedFlowSnapshot.getFlowContents();
final ComparableDataFlow localFlow = new StandardComparableDataFlow("Local Flow", localGroup);
final ComparableDataFlow registryFlow = new StandardComparableDataFlow("Versioned Flow", registryGroup);
final Set<String> ancestorServiceIds = getAncestorGroupServiceIds(processGroup);
final FlowComparator flowComparator = new StandardFlowComparator(registryFlow, localFlow, ancestorServiceIds, new ConciseEvolvingDifferenceDescriptor());
final FlowComparison flowComparison = flowComparator.compare();
final Set<ComponentDifferenceDTO> differenceDtos = dtoFactory.createComponentDifferenceDtos(flowComparison);
final FlowComparisonEntity entity = new FlowComparisonEntity();
entity.setComponentDifferences(differenceDtos);
return entity;
}
use of org.apache.nifi.registry.flow.diff.ConciseEvolvingDifferenceDescriptor 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();
}
}
Aggregations