Search in sources :

Example 1 with FlowRegistry

use of org.apache.nifi.registry.flow.FlowRegistry 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;
}
Also used : FlowRegistry(org.apache.nifi.registry.flow.FlowRegistry) NiFiRegistryFlowMapper(org.apache.nifi.registry.flow.mapping.NiFiRegistryFlowMapper) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) InstantiatedVersionedProcessGroup(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedProcessGroup) FlowComparison(org.apache.nifi.registry.flow.diff.FlowComparison) IOException(java.io.IOException) ConciseEvolvingDifferenceDescriptor(org.apache.nifi.registry.flow.diff.ConciseEvolvingDifferenceDescriptor) StandardFlowComparator(org.apache.nifi.registry.flow.diff.StandardFlowComparator) StandardComparableDataFlow(org.apache.nifi.registry.flow.diff.StandardComparableDataFlow) ComparableDataFlow(org.apache.nifi.registry.flow.diff.ComparableDataFlow) ComponentDifferenceDTO(org.apache.nifi.web.api.dto.ComponentDifferenceDTO) VersionControlInformation(org.apache.nifi.registry.flow.VersionControlInformation) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ProcessGroup(org.apache.nifi.groups.ProcessGroup) InstantiatedVersionedProcessGroup(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedProcessGroup) VersionedFlowSnapshot(org.apache.nifi.registry.flow.VersionedFlowSnapshot) FlowComparisonEntity(org.apache.nifi.web.api.entity.FlowComparisonEntity) NiFiRegistryException(org.apache.nifi.registry.client.NiFiRegistryException) StandardComparableDataFlow(org.apache.nifi.registry.flow.diff.StandardComparableDataFlow) StandardFlowComparator(org.apache.nifi.registry.flow.diff.StandardFlowComparator) FlowComparator(org.apache.nifi.registry.flow.diff.FlowComparator)

Example 2 with FlowRegistry

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

the class StandardNiFiServiceFacade method deleteRegistryClient.

@Override
public RegistryClientEntity deleteRegistryClient(final Revision revision, final String registryId) {
    final RevisionClaim claim = new StandardRevisionClaim(revision);
    final NiFiUser user = NiFiUserUtils.getNiFiUser();
    final FlowRegistry registry = revisionManager.deleteRevision(claim, user, () -> {
        final FlowRegistry reg = registryDAO.removeFlowRegistry(registryId);
        controllerFacade.save();
        return reg;
    });
    return createRegistryClientEntity(registry);
}
Also used : NiFiUser(org.apache.nifi.authorization.user.NiFiUser) FlowRegistry(org.apache.nifi.registry.flow.FlowRegistry) StandardRevisionClaim(org.apache.nifi.web.revision.StandardRevisionClaim) RevisionClaim(org.apache.nifi.web.revision.RevisionClaim) StandardRevisionClaim(org.apache.nifi.web.revision.StandardRevisionClaim)

Example 3 with FlowRegistry

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

the class FlowRegistryDAO method getFlowVersionsForUser.

@Override
public Set<VersionedFlowSnapshotMetadata> getFlowVersionsForUser(String registryId, String bucketId, String flowId, NiFiUser user) {
    try {
        final FlowRegistry flowRegistry = flowRegistryClient.getFlowRegistry(registryId);
        if (flowRegistry == null) {
            throw new IllegalArgumentException("The specified registry id is unknown to this NiFi.");
        }
        final Set<VersionedFlowSnapshotMetadata> flowVersions = flowRegistry.getFlowVersions(bucketId, flowId, user);
        final Set<VersionedFlowSnapshotMetadata> sortedFlowVersions = new TreeSet<>((f1, f2) -> Integer.compare(f1.getVersion(), f2.getVersion()));
        sortedFlowVersions.addAll(flowVersions);
        return sortedFlowVersions;
    } catch (final IOException | NiFiRegistryException ioe) {
        throw new NiFiCoreException("Unable to obtain listing of versions for bucket with ID " + bucketId + " and flow with ID " + flowId + ": " + ioe, ioe);
    }
}
Also used : NiFiCoreException(org.apache.nifi.web.NiFiCoreException) TreeSet(java.util.TreeSet) FlowRegistry(org.apache.nifi.registry.flow.FlowRegistry) IOException(java.io.IOException) NiFiRegistryException(org.apache.nifi.registry.client.NiFiRegistryException) VersionedFlowSnapshotMetadata(org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata)

Example 4 with FlowRegistry

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

the class FlowRegistryDAO method getBucketsForUser.

@Override
public Set<Bucket> getBucketsForUser(final String registryId, final NiFiUser user) {
    try {
        final FlowRegistry flowRegistry = flowRegistryClient.getFlowRegistry(registryId);
        if (flowRegistry == null) {
            throw new IllegalArgumentException("The specified registry id is unknown to this NiFi.");
        }
        final Set<Bucket> buckets = flowRegistry.getBuckets(user);
        final Set<Bucket> sortedBuckets = new TreeSet<>((b1, b2) -> b1.getName().compareTo(b2.getName()));
        sortedBuckets.addAll(buckets);
        return sortedBuckets;
    } catch (final IOException | NiFiRegistryException ioe) {
        throw new NiFiCoreException("Unable to obtain listing of buckets: " + ioe, ioe);
    }
}
Also used : NiFiCoreException(org.apache.nifi.web.NiFiCoreException) Bucket(org.apache.nifi.registry.bucket.Bucket) TreeSet(java.util.TreeSet) FlowRegistry(org.apache.nifi.registry.flow.FlowRegistry) IOException(java.io.IOException) NiFiRegistryException(org.apache.nifi.registry.client.NiFiRegistryException)

Example 5 with FlowRegistry

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

the class StandardProcessGroupDAO method updateVersionControlInformation.

@Override
public ProcessGroup updateVersionControlInformation(final VersionControlInformationDTO versionControlInformation, final Map<String, String> versionedComponentMapping) {
    final String groupId = versionControlInformation.getGroupId();
    final ProcessGroup group = locateProcessGroup(flowController, groupId);
    final String registryId = versionControlInformation.getRegistryId();
    final FlowRegistry flowRegistry = flowController.getFlowRegistryClient().getFlowRegistry(registryId);
    final String registryName = flowRegistry == null ? registryId : flowRegistry.getName();
    final NiFiRegistryFlowMapper mapper = new NiFiRegistryFlowMapper();
    final VersionedProcessGroup flowSnapshot = mapper.mapProcessGroup(group, flowController, flowController.getFlowRegistryClient(), false);
    final StandardVersionControlInformation vci = StandardVersionControlInformation.Builder.fromDto(versionControlInformation).registryName(registryName).flowSnapshot(flowSnapshot).build();
    group.setVersionControlInformation(vci, versionedComponentMapping);
    group.onComponentModified();
    return group;
}
Also used : StandardVersionControlInformation(org.apache.nifi.registry.flow.StandardVersionControlInformation) FlowRegistry(org.apache.nifi.registry.flow.FlowRegistry) NiFiRegistryFlowMapper(org.apache.nifi.registry.flow.mapping.NiFiRegistryFlowMapper) ProcessGroup(org.apache.nifi.groups.ProcessGroup) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup)

Aggregations

FlowRegistry (org.apache.nifi.registry.flow.FlowRegistry)16 IOException (java.io.IOException)8 NiFiRegistryException (org.apache.nifi.registry.client.NiFiRegistryException)7 StandardVersionControlInformation (org.apache.nifi.registry.flow.StandardVersionControlInformation)5 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)5 VersionControlInformation (org.apache.nifi.registry.flow.VersionControlInformation)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 TreeSet (java.util.TreeSet)3 BundleCoordinate (org.apache.nifi.bundle.BundleCoordinate)3 Port (org.apache.nifi.connectable.Port)3 ProcessGroup (org.apache.nifi.groups.ProcessGroup)3 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)3 VersionedFlowSnapshot (org.apache.nifi.registry.flow.VersionedFlowSnapshot)3 NiFiRegistryFlowMapper (org.apache.nifi.registry.flow.mapping.NiFiRegistryFlowMapper)3 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)3 LinkedHashSet (java.util.LinkedHashSet)2 NiFiUser (org.apache.nifi.authorization.user.NiFiUser)2 Connectable (org.apache.nifi.connectable.Connectable)2