Search in sources :

Example 1 with NiFiRegistryException

use of org.apache.nifi.registry.client.NiFiRegistryException 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 NiFiRegistryException

use of org.apache.nifi.registry.client.NiFiRegistryException in project nifi by apache.

the class StandardNiFiServiceFacade method registerFlowWithFlowRegistry.

@Override
public VersionControlComponentMappingEntity registerFlowWithFlowRegistry(final String groupId, final StartVersionControlRequestEntity requestEntity) {
    final ProcessGroup processGroup = processGroupDAO.getProcessGroup(groupId);
    final VersionControlInformation currentVci = processGroup.getVersionControlInformation();
    final int expectedVersion = currentVci == null ? 1 : currentVci.getVersion() + 1;
    // Create a VersionedProcessGroup snapshot of the flow as it is currently.
    final InstantiatedVersionedProcessGroup versionedProcessGroup = createFlowSnapshot(groupId);
    final VersionedFlowDTO versionedFlowDto = requestEntity.getVersionedFlow();
    final String flowId = versionedFlowDto.getFlowId() == null ? UUID.randomUUID().toString() : versionedFlowDto.getFlowId();
    final VersionedFlow versionedFlow = new VersionedFlow();
    versionedFlow.setBucketIdentifier(versionedFlowDto.getBucketId());
    versionedFlow.setCreatedTimestamp(System.currentTimeMillis());
    versionedFlow.setDescription(versionedFlowDto.getDescription());
    versionedFlow.setModifiedTimestamp(versionedFlow.getCreatedTimestamp());
    versionedFlow.setName(versionedFlowDto.getFlowName());
    versionedFlow.setIdentifier(flowId);
    // Add the Versioned Flow and first snapshot to the Flow Registry
    final String registryId = requestEntity.getVersionedFlow().getRegistryId();
    final VersionedFlowSnapshot registeredSnapshot;
    final VersionedFlow registeredFlow;
    String action = "create the flow";
    try {
        // first, create the flow in the registry, if necessary
        if (versionedFlowDto.getFlowId() == null) {
            registeredFlow = registerVersionedFlow(registryId, versionedFlow);
        } else {
            registeredFlow = getVersionedFlow(registryId, versionedFlowDto.getBucketId(), versionedFlowDto.getFlowId());
        }
        action = "add the local flow to the Flow Registry as the first Snapshot";
        // add first snapshot to the flow in the registry
        registeredSnapshot = registerVersionedFlowSnapshot(registryId, registeredFlow, versionedProcessGroup, versionedFlowDto.getComments(), expectedVersion);
    } catch (final NiFiRegistryException e) {
        throw new IllegalArgumentException(e.getLocalizedMessage());
    } catch (final IOException ioe) {
        throw new IllegalStateException("Failed to communicate with Flow Registry when attempting to " + action);
    }
    final Bucket bucket = registeredSnapshot.getBucket();
    final VersionedFlow flow = registeredSnapshot.getFlow();
    // Update the Process Group with the new VersionControlInformation. (Send this to all nodes).
    final VersionControlInformationDTO vci = new VersionControlInformationDTO();
    vci.setBucketId(bucket.getIdentifier());
    vci.setBucketName(bucket.getName());
    vci.setFlowId(flow.getIdentifier());
    vci.setFlowName(flow.getName());
    vci.setFlowDescription(flow.getDescription());
    vci.setGroupId(groupId);
    vci.setRegistryId(registryId);
    vci.setRegistryName(getFlowRegistryName(registryId));
    vci.setVersion(registeredSnapshot.getSnapshotMetadata().getVersion());
    vci.setState(VersionedFlowState.UP_TO_DATE.name());
    final Map<String, String> mapping = dtoFactory.createVersionControlComponentMappingDto(versionedProcessGroup);
    final Revision groupRevision = revisionManager.getRevision(groupId);
    final RevisionDTO groupRevisionDto = dtoFactory.createRevisionDTO(groupRevision);
    final VersionControlComponentMappingEntity entity = new VersionControlComponentMappingEntity();
    entity.setVersionControlInformation(vci);
    entity.setProcessGroupRevision(groupRevisionDto);
    entity.setVersionControlComponentMapping(mapping);
    return entity;
}
Also used : VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) InstantiatedVersionedProcessGroup(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedProcessGroup) IOException(java.io.IOException) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) VersionControlInformationDTO(org.apache.nifi.web.api.dto.VersionControlInformationDTO) VersionControlInformation(org.apache.nifi.registry.flow.VersionControlInformation) VersionedFlowDTO(org.apache.nifi.web.api.dto.VersionedFlowDTO) Bucket(org.apache.nifi.registry.bucket.Bucket) 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) NiFiRegistryException(org.apache.nifi.registry.client.NiFiRegistryException) VersionControlComponentMappingEntity(org.apache.nifi.web.api.entity.VersionControlComponentMappingEntity)

Example 3 with NiFiRegistryException

use of org.apache.nifi.registry.client.NiFiRegistryException 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 NiFiRegistryException

use of org.apache.nifi.registry.client.NiFiRegistryException 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 NiFiRegistryException

use of org.apache.nifi.registry.client.NiFiRegistryException in project nifi by apache.

the class AbstractNiFiRegistryCommand method getVersions.

protected List<Integer> getVersions(final NiFiRegistryClient client, final String bucketId, final String flowId) throws NiFiRegistryException, IOException {
    final FlowSnapshotClient srcSnapshotClient = client.getFlowSnapshotClient();
    final List<VersionedFlowSnapshotMetadata> srcVersionMetadata = srcSnapshotClient.getSnapshotMetadata(bucketId, flowId);
    return srcVersionMetadata.stream().map(s -> s.getVersion()).collect(Collectors.toList());
}
Also used : Properties(java.util.Properties) AbstractPropertyCommand(org.apache.nifi.toolkit.cli.impl.command.AbstractPropertyCommand) SessionVariable(org.apache.nifi.toolkit.cli.impl.session.SessionVariable) IOException(java.io.IOException) CommandException(org.apache.nifi.toolkit.cli.api.CommandException) FileInputStream(java.io.FileInputStream) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) BucketItem(org.apache.nifi.registry.bucket.BucketItem) NiFiRegistryClient(org.apache.nifi.registry.client.NiFiRegistryClient) VersionedFlowSnapshotMetadata(org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata) List(java.util.List) NiFiRegistryException(org.apache.nifi.registry.client.NiFiRegistryException) Result(org.apache.nifi.toolkit.cli.api.Result) ParseException(org.apache.commons.cli.ParseException) FlowSnapshotClient(org.apache.nifi.registry.client.FlowSnapshotClient) ClientFactory(org.apache.nifi.toolkit.cli.api.ClientFactory) Optional(java.util.Optional) InputStream(java.io.InputStream) FlowSnapshotClient(org.apache.nifi.registry.client.FlowSnapshotClient) VersionedFlowSnapshotMetadata(org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata)

Aggregations

NiFiRegistryException (org.apache.nifi.registry.client.NiFiRegistryException)14 IOException (java.io.IOException)10 VersionedFlowSnapshot (org.apache.nifi.registry.flow.VersionedFlowSnapshot)7 FlowRegistry (org.apache.nifi.registry.flow.FlowRegistry)6 VersionedFlowSnapshotMetadata (org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata)6 VersionedFlow (org.apache.nifi.registry.flow.VersionedFlow)5 Bucket (org.apache.nifi.registry.bucket.Bucket)4 FlowSnapshotClient (org.apache.nifi.registry.client.FlowSnapshotClient)4 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)4 TreeSet (java.util.TreeSet)3 BucketClient (org.apache.nifi.registry.client.BucketClient)3 FlowClient (org.apache.nifi.registry.client.FlowClient)3 NiFiCoreException (org.apache.nifi.web.NiFiCoreException)3 ProcessGroup (org.apache.nifi.groups.ProcessGroup)2 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)2 BucketItem (org.apache.nifi.registry.bucket.BucketItem)2 NiFiRegistryClient (org.apache.nifi.registry.client.NiFiRegistryClient)2 VersionControlInformation (org.apache.nifi.registry.flow.VersionControlInformation)2 InstantiatedVersionedProcessGroup (org.apache.nifi.registry.flow.mapping.InstantiatedVersionedProcessGroup)2 OkResult (org.apache.nifi.toolkit.cli.impl.result.OkResult)2