Search in sources :

Example 26 with VersionedFlow

use of org.apache.nifi.registry.flow.VersionedFlow in project nifi-registry by apache.

the class TestLinkService method setup.

@Before
public void setup() {
    linkService = new LinkService();
    // setup buckets
    final Bucket bucket1 = new Bucket();
    bucket1.setIdentifier("b1");
    bucket1.setName("Bucket 1");
    final Bucket bucket2 = new Bucket();
    bucket2.setIdentifier("b2");
    bucket2.setName("Bucket 2");
    buckets = new ArrayList<>();
    buckets.add(bucket1);
    buckets.add(bucket2);
    // setup flows
    final VersionedFlow flow1 = new VersionedFlow();
    flow1.setIdentifier("f1");
    flow1.setName("Flow 1");
    flow1.setBucketIdentifier(bucket1.getIdentifier());
    final VersionedFlow flow2 = new VersionedFlow();
    flow2.setIdentifier("f2");
    flow2.setName("Flow 2");
    flow2.setBucketIdentifier(bucket1.getIdentifier());
    flows = new ArrayList<>();
    flows.add(flow1);
    flows.add(flow2);
    // setup snapshots
    final VersionedFlowSnapshotMetadata snapshotMetadata1 = new VersionedFlowSnapshotMetadata();
    snapshotMetadata1.setFlowIdentifier(flow1.getIdentifier());
    snapshotMetadata1.setVersion(1);
    snapshotMetadata1.setBucketIdentifier(bucket1.getIdentifier());
    final VersionedFlowSnapshotMetadata snapshotMetadata2 = new VersionedFlowSnapshotMetadata();
    snapshotMetadata2.setFlowIdentifier(flow1.getIdentifier());
    snapshotMetadata2.setVersion(2);
    snapshotMetadata2.setBucketIdentifier(bucket1.getIdentifier());
    snapshots = new ArrayList<>();
    snapshots.add(snapshotMetadata1);
    snapshots.add(snapshotMetadata2);
    // setup items
    items = new ArrayList<>();
    items.add(flow1);
    items.add(flow2);
}
Also used : Bucket(org.apache.nifi.registry.bucket.Bucket) VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) VersionedFlowSnapshotMetadata(org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata) Before(org.junit.Before)

Example 27 with VersionedFlow

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

the class DeleteBucket method doExecute.

@Override
public OkResult doExecute(final NiFiRegistryClient client, final Properties properties) throws IOException, NiFiRegistryException, ParseException {
    final String bucketId = getRequiredArg(properties, CommandOption.BUCKET_ID);
    final boolean forceDelete = properties.containsKey(CommandOption.FORCE.getLongName());
    final FlowClient flowClient = client.getFlowClient();
    final List<VersionedFlow> flowsInBucket = flowClient.getByBucket(bucketId);
    if (flowsInBucket != null && flowsInBucket.size() > 0 && !forceDelete) {
        throw new NiFiRegistryException("Bucket is not empty, use --" + CommandOption.FORCE.getLongName() + " to delete");
    } else {
        final BucketClient bucketClient = client.getBucketClient();
        bucketClient.delete(bucketId);
        return new OkResult(getContext().isInteractive());
    }
}
Also used : BucketClient(org.apache.nifi.registry.client.BucketClient) OkResult(org.apache.nifi.toolkit.cli.impl.result.OkResult) VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) FlowClient(org.apache.nifi.registry.client.FlowClient) NiFiRegistryException(org.apache.nifi.registry.client.NiFiRegistryException)

Example 28 with VersionedFlow

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

the class VersionedFlowsResult method createReferenceResolver.

@Override
public ReferenceResolver createReferenceResolver(final Context context) {
    final Map<Integer, VersionedFlow> backRefs = new HashMap<>();
    final AtomicInteger position = new AtomicInteger(0);
    versionedFlows.forEach(f -> backRefs.put(position.incrementAndGet(), f));
    return new ReferenceResolver() {

        @Override
        public ResolvedReference resolve(final CommandOption option, final Integer position) {
            final VersionedFlow versionedFlow = backRefs.get(position);
            if (versionedFlow != null) {
                if (option != null && option == CommandOption.BUCKET_ID) {
                    return new ResolvedReference(option, position, versionedFlow.getBucketName(), versionedFlow.getBucketIdentifier());
                } else {
                    return new ResolvedReference(option, position, versionedFlow.getName(), versionedFlow.getIdentifier());
                }
            } else {
                return null;
            }
        }

        @Override
        public boolean isEmpty() {
            return backRefs.isEmpty();
        }
    };
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ResolvedReference(org.apache.nifi.toolkit.cli.api.ResolvedReference) CommandOption(org.apache.nifi.toolkit.cli.impl.command.CommandOption) HashMap(java.util.HashMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) ReferenceResolver(org.apache.nifi.toolkit.cli.api.ReferenceResolver)

Example 29 with VersionedFlow

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

the class VersionsResource method updateFlowVersion.

@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("process-groups/{id}")
@ApiOperation(value = "Update the version of a Process Group with the given ID", response = VersionControlInformationEntity.class, notes = "For a Process Group that is already under Version Control, this will update the version of the flow to a different version. This endpoint expects " + "that the given snapshot will not modify any Processor that is currently running or any Controller Service that is enabled. " + NON_GUARANTEED_ENDPOINT, authorizations = { @Authorization(value = "Read - /process-groups/{uuid}"), @Authorization(value = "Write - /process-groups/{uuid}") })
@ApiResponses(value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 404, message = "The specified resource could not be found."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") })
public Response updateFlowVersion(@ApiParam("The process group id.") @PathParam("id") final String groupId, @ApiParam(value = "The controller service configuration details.", required = true) final VersionedFlowSnapshotEntity requestEntity) {
    // Verify the request
    final RevisionDTO revisionDto = requestEntity.getProcessGroupRevision();
    if (revisionDto == null) {
        throw new IllegalArgumentException("Process Group Revision must be specified.");
    }
    final VersionedFlowSnapshot requestFlowSnapshot = requestEntity.getVersionedFlowSnapshot();
    if (requestFlowSnapshot == null) {
        throw new IllegalArgumentException("Versioned Flow Snapshot must be supplied.");
    }
    final VersionedFlowSnapshotMetadata requestSnapshotMetadata = requestFlowSnapshot.getSnapshotMetadata();
    if (requestSnapshotMetadata == null) {
        throw new IllegalArgumentException("Snapshot Metadata must be supplied.");
    }
    if (requestSnapshotMetadata.getBucketIdentifier() == null) {
        throw new IllegalArgumentException("The Bucket ID must be supplied.");
    }
    if (requestSnapshotMetadata.getFlowIdentifier() == null) {
        throw new IllegalArgumentException("The Flow ID must be supplied.");
    }
    // Perform the request
    if (isReplicateRequest()) {
        return replicate(HttpMethod.PUT, requestEntity);
    }
    final Revision requestRevision = getRevision(requestEntity.getProcessGroupRevision(), groupId);
    return withWriteLock(serviceFacade, requestEntity, requestRevision, lookup -> {
        final ProcessGroupAuthorizable groupAuthorizable = lookup.getProcessGroup(groupId);
        final Authorizable processGroup = groupAuthorizable.getAuthorizable();
        processGroup.authorize(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser());
        processGroup.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
    }, () -> {
        // We do not enforce that the Process Group is 'not dirty' because at this point,
        // the client has explicitly indicated the dataflow that the Process Group should
        // provide and provided the Revision to ensure that they have the most up-to-date
        // view of the Process Group.
        serviceFacade.verifyCanUpdate(groupId, requestFlowSnapshot, true, false);
    }, (rev, entity) -> {
        final VersionedFlowSnapshot flowSnapshot = entity.getVersionedFlowSnapshot();
        final VersionedFlowSnapshotMetadata snapshotMetadata = flowSnapshot.getSnapshotMetadata();
        final Bucket bucket = flowSnapshot.getBucket();
        final VersionedFlow flow = flowSnapshot.getFlow();
        // Update the Process Group to match the proposed flow snapshot
        final VersionControlInformationDTO versionControlInfoDto = new VersionControlInformationDTO();
        versionControlInfoDto.setBucketId(snapshotMetadata.getBucketIdentifier());
        versionControlInfoDto.setBucketName(bucket.getName());
        versionControlInfoDto.setFlowId(snapshotMetadata.getFlowIdentifier());
        versionControlInfoDto.setFlowName(flow.getName());
        versionControlInfoDto.setFlowDescription(flow.getDescription());
        versionControlInfoDto.setGroupId(groupId);
        versionControlInfoDto.setVersion(snapshotMetadata.getVersion());
        versionControlInfoDto.setRegistryId(entity.getRegistryId());
        versionControlInfoDto.setRegistryName(serviceFacade.getFlowRegistryName(entity.getRegistryId()));
        final VersionedFlowState flowState = snapshotMetadata.getVersion() == flow.getVersionCount() ? VersionedFlowState.UP_TO_DATE : VersionedFlowState.STALE;
        versionControlInfoDto.setState(flowState.name());
        final NiFiUser user = NiFiUserUtils.getNiFiUser();
        final ProcessGroupEntity updatedGroup = serviceFacade.updateProcessGroupContents(user, rev, groupId, versionControlInfoDto, flowSnapshot, getIdGenerationSeed().orElse(null), false, true, entity.getUpdateDescendantVersionedFlows());
        final VersionControlInformationDTO updatedVci = updatedGroup.getComponent().getVersionControlInformation();
        final VersionControlInformationEntity responseEntity = new VersionControlInformationEntity();
        responseEntity.setProcessGroupRevision(updatedGroup.getRevision());
        responseEntity.setVersionControlInformation(updatedVci);
        return generateOkResponse(responseEntity).build();
    });
}
Also used : ProcessGroupEntity(org.apache.nifi.web.api.entity.ProcessGroupEntity) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) VersionedFlowSnapshotMetadata(org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata) VersionControlInformationDTO(org.apache.nifi.web.api.dto.VersionControlInformationDTO) ProcessGroupAuthorizable(org.apache.nifi.authorization.ProcessGroupAuthorizable) VersionControlInformationEntity(org.apache.nifi.web.api.entity.VersionControlInformationEntity) Revision(org.apache.nifi.web.Revision) Bucket(org.apache.nifi.registry.bucket.Bucket) VersionedFlowSnapshot(org.apache.nifi.registry.flow.VersionedFlowSnapshot) VersionedFlowState(org.apache.nifi.registry.flow.VersionedFlowState) ComponentAuthorizable(org.apache.nifi.authorization.ComponentAuthorizable) Authorizable(org.apache.nifi.authorization.resource.Authorizable) ProcessGroupAuthorizable(org.apache.nifi.authorization.ProcessGroupAuthorizable) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 30 with VersionedFlow

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

the class FlowRegistryDAO method getFlowsForUser.

@Override
public Set<VersionedFlow> getFlowsForUser(String registryId, String bucketId, 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<VersionedFlow> flows = flowRegistry.getFlows(bucketId, user);
        final Set<VersionedFlow> sortedFlows = new TreeSet<>((f1, f2) -> f1.getName().compareTo(f2.getName()));
        sortedFlows.addAll(flows);
        return sortedFlows;
    } catch (final IOException | NiFiRegistryException ioe) {
        throw new NiFiCoreException("Unable to obtain listing of flows for bucket with ID " + bucketId + ": " + ioe, ioe);
    }
}
Also used : NiFiCoreException(org.apache.nifi.web.NiFiCoreException) TreeSet(java.util.TreeSet) FlowRegistry(org.apache.nifi.registry.flow.FlowRegistry) VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) IOException(java.io.IOException) NiFiRegistryException(org.apache.nifi.registry.client.NiFiRegistryException)

Aggregations

VersionedFlow (org.apache.nifi.registry.flow.VersionedFlow)46 Test (org.junit.Test)19 Bucket (org.apache.nifi.registry.bucket.Bucket)12 BucketEntity (org.apache.nifi.registry.db.entity.BucketEntity)11 FlowEntity (org.apache.nifi.registry.db.entity.FlowEntity)11 VersionedFlowSnapshot (org.apache.nifi.registry.flow.VersionedFlowSnapshot)11 VersionedFlowSnapshotMetadata (org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata)10 Date (java.util.Date)9 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)8 ApiOperation (io.swagger.annotations.ApiOperation)7 ApiResponses (io.swagger.annotations.ApiResponses)7 Consumes (javax.ws.rs.Consumes)7 Produces (javax.ws.rs.Produces)7 ArrayList (java.util.ArrayList)6 Path (javax.ws.rs.Path)6 IOException (java.io.IOException)5 FlowClient (org.apache.nifi.registry.client.FlowClient)5 NiFiRegistryException (org.apache.nifi.registry.client.NiFiRegistryException)5 TreeSet (java.util.TreeSet)3 Response (javax.ws.rs.core.Response)3