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);
}
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());
}
}
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();
}
};
}
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();
});
}
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);
}
}
Aggregations