Java Code Examples for org.apache.nifi.registry.flow.VersionedFlowSnapshot#getSnapshotMetadata()
The following examples show how to use
org.apache.nifi.registry.flow.VersionedFlowSnapshot#getSnapshotMetadata() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BucketFlowResource.java From nifi-registry with Apache License 2.0 | 6 votes |
private static void verifyPathParamsMatchBody(String bucketIdParam, String flowIdParam, VersionedFlowSnapshot flowSnapshot) throws BadRequestException { if (StringUtils.isBlank(bucketIdParam)) { throw new BadRequestException("Bucket id path parameter cannot be blank"); } if (StringUtils.isBlank(flowIdParam)) { throw new BadRequestException("Flow id path parameter cannot be blank"); } if (flowSnapshot == null) { throw new BadRequestException("VersionedFlowSnapshot cannot be null in body"); } final VersionedFlowSnapshotMetadata metadata = flowSnapshot.getSnapshotMetadata(); if (metadata != null && metadata.getBucketIdentifier() != null && !bucketIdParam.equals(metadata.getBucketIdentifier())) { throw new BadRequestException("Bucket id in path param must match bucket id in body"); } if (metadata != null && metadata.getFlowIdentifier() != null && !flowIdParam.equals(metadata.getFlowIdentifier())) { throw new BadRequestException("Flow id in path param must match flow id in body"); } }
Example 2
Source File: BucketFlowResource.java From nifi-registry with Apache License 2.0 | 6 votes |
private static void setSnaphotMetadataIfMissing( @NotNull String bucketIdParam, @NotNull String flowIdParam, @NotNull VersionedFlowSnapshot flowSnapshot) { VersionedFlowSnapshotMetadata metadata = flowSnapshot.getSnapshotMetadata(); if (metadata == null) { metadata = new VersionedFlowSnapshotMetadata(); } if (metadata.getBucketIdentifier() == null) { metadata.setBucketIdentifier(bucketIdParam); } if (metadata.getFlowIdentifier() == null) { metadata.setFlowIdentifier(flowIdParam); } flowSnapshot.setSnapshotMetadata(metadata); }
Example 3
Source File: StandardServiceFacade.java From nifi-registry with Apache License 2.0 | 6 votes |
private void populateLinksAndPermissions(final VersionedFlowSnapshot snapshot) { if (snapshot == null) { return; } if (snapshot.getSnapshotMetadata() != null) { linkService.populateLinks(snapshot.getSnapshotMetadata()); } if (snapshot.getFlow() != null) { linkService.populateLinks(snapshot.getFlow()); } if (snapshot.getBucket() != null) { permissionsService.populateBucketPermissions(snapshot.getBucket()); linkService.populateLinks(snapshot.getBucket()); } }
Example 4
Source File: IntegrationTestUtils.java From nifi-registry with Apache License 2.0 | 6 votes |
public static void assertFlowSnapshotsEqual(VersionedFlowSnapshot expected, VersionedFlowSnapshot actual, boolean checkServerSetFields) { assertNotNull(actual); if (expected.getSnapshotMetadata() != null) { assertFlowSnapshotMetadataEqual(expected.getSnapshotMetadata(), actual.getSnapshotMetadata(), checkServerSetFields); } if (expected.getFlowContents() != null) { assertVersionedProcessGroupsEqual(expected.getFlowContents(), actual.getFlowContents()); } if (checkServerSetFields) { assertFlowsEqual(expected.getFlow(), actual.getFlow(), false); // false because if we are checking a newly created snapshot, the versionsCount won't match assertBucketsEqual(expected.getBucket(), actual.getBucket(), true); } }
Example 5
Source File: StandardServiceFacade.java From nifi-registry with Apache License 2.0 | 5 votes |
private void authorizeBucketAccess(final RequestAction action, final VersionedFlowSnapshot flowSnapshot) { // this should never happen, but if somehow the back-end didn't populate the bucket id let's make sure the flow snapshot isn't returned if (flowSnapshot == null || flowSnapshot.getSnapshotMetadata() == null) { throw new IllegalStateException("Unable to authorize access because bucket identifier is null or blank"); } authorizeBucketAccess(action, flowSnapshot.getSnapshotMetadata().getBucketIdentifier()); }
Example 6
Source File: JerseyFlowSnapshotClient.java From nifi-registry with Apache License 2.0 | 5 votes |
@Override public VersionedFlowSnapshot create(final VersionedFlowSnapshot snapshot) throws NiFiRegistryException, IOException { if (snapshot.getSnapshotMetadata() == null) { throw new IllegalArgumentException("Snapshot Metadata cannot be null"); } final String bucketId = snapshot.getSnapshotMetadata().getBucketIdentifier(); if (StringUtils.isBlank(bucketId)) { throw new IllegalArgumentException("Bucket Identifier cannot be blank"); } final String flowId = snapshot.getSnapshotMetadata().getFlowIdentifier(); if (StringUtils.isBlank(flowId)) { throw new IllegalArgumentException("Flow Identifier cannot be blank"); } return executeAction("Error creating snapshot", () -> { final WebTarget target = bucketFlowSnapshotTarget .resolveTemplate("bucketId", bucketId) .resolveTemplate("flowId", flowId); return getRequestBuilder(target) .post( Entity.entity(snapshot, MediaType.APPLICATION_JSON), VersionedFlowSnapshot.class ); }); }
Example 7
Source File: VersionsResource.java From nifi with Apache License 2.0 | 5 votes |
/** * Perform actual flow update of the specified flow. This is used for the initial flow update and replication updates. */ @Override protected ProcessGroupEntity performUpdateFlow(final String groupId, final Revision revision, final VersionControlInformationEntity requestEntity, final VersionedFlowSnapshot flowSnapshot, final String idGenerationSeed, final boolean verifyNotModified, final boolean updateDescendantVersionedFlows) { logger.info("Updating Process Group with ID {} to version {} of the Versioned Flow", groupId, flowSnapshot.getSnapshotMetadata().getVersion()); // Step 10-11. Update Process Group to the new flow and update variable registry with any Variables that were added or removed final VersionControlInformationDTO requestVci = requestEntity.getVersionControlInformation(); final Bucket bucket = flowSnapshot.getBucket(); final VersionedFlow flow = flowSnapshot.getFlow(); final VersionedFlowSnapshotMetadata metadata = flowSnapshot.getSnapshotMetadata(); final VersionControlInformationDTO versionControlInfo = new VersionControlInformationDTO(); versionControlInfo.setBucketId(metadata.getBucketIdentifier()); versionControlInfo.setBucketName(bucket.getName()); versionControlInfo.setFlowDescription(flow.getDescription()); versionControlInfo.setFlowId(flow.getIdentifier()); versionControlInfo.setFlowName(flow.getName()); versionControlInfo.setGroupId(groupId); versionControlInfo.setRegistryId(requestVci.getRegistryId()); versionControlInfo.setRegistryName(serviceFacade.getFlowRegistryName(requestVci.getRegistryId())); versionControlInfo.setVersion(metadata.getVersion()); versionControlInfo.setState(flowSnapshot.isLatest() ? VersionedFlowState.UP_TO_DATE.name() : VersionedFlowState.STALE.name()); return serviceFacade.updateProcessGroupContents(revision, groupId, versionControlInfo, flowSnapshot, idGenerationSeed, verifyNotModified, false, updateDescendantVersionedFlows); }
Example 8
Source File: TestRegistryService.java From nifi-registry with Apache License 2.0 | 4 votes |
@Test public void testGetSnapshotExists() { final BucketEntity existingBucket = createBucketEntity("b1"); final FlowEntity existingFlow = createFlowEntity(existingBucket.getId()); final FlowSnapshotEntity existingSnapshot = createFlowSnapshotEntity(existingFlow.getId()); existingFlow.setSnapshotCount(10); when(metadataService.getBucketById(existingBucket.getId())) .thenReturn(existingBucket); when(metadataService.getFlowByIdWithSnapshotCounts(existingFlow.getId())) .thenReturn(existingFlow); when(metadataService.getFlowSnapshot(existingFlow.getId(), existingSnapshot.getVersion())) .thenReturn(existingSnapshot); // return a non-null, non-zero-length array so something gets passed to the serializer when(flowPersistenceProvider.getFlowContent( existingBucket.getId(), existingSnapshot.getFlowId(), existingSnapshot.getVersion() )).thenReturn(new byte[10]); final FlowContent flowContent = new FlowContent(); flowContent.setFlowSnapshot(createSnapshot()); when(flowContentSerializer.readDataModelVersion(any(InputStream.class))).thenReturn(3); when(flowContentSerializer.deserializeFlowContent(eq(3), any(InputStream.class))).thenReturn(flowContent); final VersionedFlowSnapshot returnedSnapshot = registryService.getFlowSnapshot( existingBucket.getId(), existingSnapshot.getFlowId(), existingSnapshot.getVersion()); assertNotNull(returnedSnapshot); assertNotNull(returnedSnapshot.getSnapshotMetadata()); final VersionedFlowSnapshotMetadata snapshotMetadata = returnedSnapshot.getSnapshotMetadata(); assertEquals(existingSnapshot.getVersion().intValue(), snapshotMetadata.getVersion()); assertEquals(existingBucket.getId(), snapshotMetadata.getBucketIdentifier()); assertEquals(existingSnapshot.getFlowId(), snapshotMetadata.getFlowIdentifier()); assertEquals(existingSnapshot.getCreated(), new Date(snapshotMetadata.getTimestamp())); assertEquals(existingSnapshot.getCreatedBy(), snapshotMetadata.getAuthor()); assertEquals(existingSnapshot.getComments(), snapshotMetadata.getComments()); final VersionedFlow versionedFlow = returnedSnapshot.getFlow(); assertNotNull(versionedFlow); assertNotNull(versionedFlow.getVersionCount()); assertTrue(versionedFlow.getVersionCount() > 0); final Bucket bucket = returnedSnapshot.getBucket(); assertNotNull(bucket); }
Example 9
Source File: ImportFlowVersion.java From nifi with Apache License 2.0 | 4 votes |
@Override public StringResult doExecute(final NiFiRegistryClient client, final Properties properties) throws ParseException, IOException, NiFiRegistryException { final String flowId = getRequiredArg(properties, CommandOption.FLOW_ID); final String inputFile = getRequiredArg(properties, CommandOption.INPUT_SOURCE); final String contents = getInputSourceContent(inputFile); final FlowClient flowClient = client.getFlowClient(); final FlowSnapshotClient snapshotClient = client.getFlowSnapshotClient(); final ObjectMapper objectMapper = JacksonUtils.getObjectMapper(); final VersionedFlowSnapshot deserializedSnapshot = objectMapper.readValue(contents, VersionedFlowSnapshot.class); if (deserializedSnapshot == null) { throw new IOException("Unable to deserialize flow version from " + inputFile); } final VersionedFlow versionedFlow = flowClient.get(flowId); // determine the latest existing version in the destination system Integer version; try { final VersionedFlowSnapshotMetadata latestMetadata = snapshotClient.getLatestMetadata(flowId); version = latestMetadata.getVersion() + 1; } catch (NiFiRegistryException e) { // when there are no versions it produces a 404 not found version = 1; } // create new metadata using the passed in bucket and flow in the target registry, keep comments final VersionedFlowSnapshotMetadata metadata = new VersionedFlowSnapshotMetadata(); metadata.setBucketIdentifier(versionedFlow.getBucketIdentifier()); metadata.setFlowIdentifier(flowId); metadata.setVersion(version); final VersionedFlowSnapshotMetadata deserializedSnapshotMetadata = deserializedSnapshot.getSnapshotMetadata(); if (deserializedSnapshotMetadata != null) { metadata.setComments(deserializedSnapshotMetadata.getComments()); } // create a new snapshot using the new metadata and the contents from the deserialized snapshot final VersionedFlowSnapshot snapshot = new VersionedFlowSnapshot(); snapshot.setSnapshotMetadata(metadata); snapshot.setFlowContents(deserializedSnapshot.getFlowContents()); snapshot.setExternalControllerServices(deserializedSnapshot.getExternalControllerServices()); snapshot.setParameterContexts(deserializedSnapshot.getParameterContexts()); snapshot.setFlowEncodingVersion(deserializedSnapshot.getFlowEncodingVersion()); final VersionedFlowSnapshot createdSnapshot = snapshotClient.create(snapshot); final VersionedFlowSnapshotMetadata createdMetadata = createdSnapshot.getSnapshotMetadata(); return new StringResult(String.valueOf(createdMetadata.getVersion()), getContext().isInteractive()); }
Example 10
Source File: VersionsResource.java From nifi with Apache License 2.0 | 4 votes |
@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); } else if (isDisconnectedFromCluster()) { verifyDisconnectedNodeModification(requestEntity.isDisconnectedNodeAcknowledged()); } 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); }, (revision, entity) -> { // prepare an entity similar to initial request to pass registry id to performUpdateFlow final VersionControlInformationDTO versionControlInfoDto = new VersionControlInformationDTO(); versionControlInfoDto.setRegistryId(entity.getRegistryId()); final VersionControlInformationEntity versionControlInfo = new VersionControlInformationEntity(); versionControlInfo.setVersionControlInformation(versionControlInfoDto); final ProcessGroupEntity updatedGroup = performUpdateFlow(groupId, revision, versionControlInfo, entity.getVersionedFlowSnapshot(), getIdGenerationSeed().orElse(null), false, entity.getUpdateDescendantVersionedFlows()); final VersionControlInformationDTO updatedVci = updatedGroup.getComponent().getVersionControlInformation(); // response to replication request is a version control entity with revision and versioning info final VersionControlInformationEntity responseEntity = new VersionControlInformationEntity(); responseEntity.setProcessGroupRevision(updatedGroup.getRevision()); responseEntity.setVersionControlInformation(updatedVci); return generateOkResponse(responseEntity).build(); }); }