This is an automated email from the ASF dual-hosted git repository.
exceptionfactory pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/main by this push:
new 56a65a5877 NIFI-11947 Support preserving created timestamp for Flow
Snapshots
56a65a5877 is described below
commit 56a65a587764f00ee15f91db6eb0040c5a6e2f32
Author: Ravinarayan Singh <[email protected]>
AuthorDate: Mon Aug 14 18:06:56 2023 -0700
NIFI-11947 Support preserving created timestamp for Flow Snapshots
This closes #7610
Signed-off-by: David Handermann <[email protected]>
---
.../nifi/registry/service/RegistryService.java | 2 +-
.../nifi/registry/service/TestRegistryService.java | 36 ++++++++++++++++++++++
.../nifi/registry/web/api/BucketFlowResource.java | 3 ++
3 files changed, 40 insertions(+), 1 deletion(-)
diff --git
a/nifi-registry/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/RegistryService.java
b/nifi-registry/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/RegistryService.java
index a7582447e0..04d3f8642a 100644
---
a/nifi-registry/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/RegistryService.java
+++
b/nifi-registry/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/RegistryService.java
@@ -544,7 +544,7 @@ public class RegistryService {
}
// validation will ensure that the metadata and contents are not null
- if (flowSnapshot.getSnapshotMetadata() != null) {
+ if (flowSnapshot.getSnapshotMetadata() != null &&
flowSnapshot.getSnapshotMetadata().getTimestamp() <= 0) {
flowSnapshot.getSnapshotMetadata().setTimestamp(System.currentTimeMillis());
}
diff --git
a/nifi-registry/nifi-registry-core/nifi-registry-framework/src/test/java/org/apache/nifi/registry/service/TestRegistryService.java
b/nifi-registry/nifi-registry-core/nifi-registry-framework/src/test/java/org/apache/nifi/registry/service/TestRegistryService.java
index f2da65ff27..1964687b38 100644
---
a/nifi-registry/nifi-registry-core/nifi-registry-framework/src/test/java/org/apache/nifi/registry/service/TestRegistryService.java
+++
b/nifi-registry/nifi-registry-core/nifi-registry-framework/src/test/java/org/apache/nifi/registry/service/TestRegistryService.java
@@ -799,6 +799,42 @@ public class TestRegistryService {
assertThrows(IllegalStateException.class, () ->
registryService.createFlowSnapshot(snapshot));
}
+ @Test
+ public void testCreateSnapshotWhenPreserveSourcePropertiesTrue() {
+ final long timestamp = System.currentTimeMillis();
+ final VersionedFlowSnapshot snapshot = createSnapshot();
+ snapshot.getSnapshotMetadata().setTimestamp(timestamp);
+ final BucketEntity existingBucket = new BucketEntity();
+ existingBucket.setId("b1");
+ existingBucket.setName("My Bucket");
+ existingBucket.setDescription("This is my bucket");
+ existingBucket.setCreated(new Date());
+
+
when(metadataService.getBucketById(existingBucket.getId())).thenReturn(existingBucket);
+
+ // return a flow with the existing snapshot when getFlowById is called
+ final FlowEntity existingFlow = new FlowEntity();
+ existingFlow.setId("flow1");
+ existingFlow.setName("My Flow");
+ existingFlow.setDescription("This is my flow.");
+ existingFlow.setCreated(new Date());
+ existingFlow.setModified(new Date());
+ existingFlow.setBucketId(existingBucket.getId());
+
+
when(metadataService.getFlowById(existingFlow.getId())).thenReturn(existingFlow);
+
when(metadataService.getFlowByIdWithSnapshotCounts(existingFlow.getId())).thenReturn(existingFlow);
+
+ final VersionedFlowSnapshot createdSnapshot =
registryService.createFlowSnapshot(snapshot);
+ assertNotNull(createdSnapshot);
+ assertNotNull(createdSnapshot.getSnapshotMetadata());
+ assertNotNull(createdSnapshot.getFlow());
+ assertNotNull(createdSnapshot.getBucket());
+
assertEquals(timestamp,createdSnapshot.getSnapshotMetadata().getTimestamp());
+ verify(flowContentSerializer,
times(1)).serializeFlowContent(any(FlowContent.class), any(OutputStream.class));
+ verify(flowPersistenceProvider, times(1)).saveFlowContent(any(),
any());
+ verify(metadataService,
times(1)).createFlowSnapshot(any(FlowSnapshotEntity.class));
+
+ }
@Test
public void testCreateSnapshotVersionNotNextVersion() {
final VersionedFlowSnapshot snapshot = createSnapshot();
diff --git
a/nifi-registry/nifi-registry-core/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/BucketFlowResource.java
b/nifi-registry/nifi-registry-core/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/BucketFlowResource.java
index a1b270b28b..1b4d302aae 100644
---
a/nifi-registry/nifi-registry-core/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/BucketFlowResource.java
+++
b/nifi-registry/nifi-registry-core/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/BucketFlowResource.java
@@ -294,6 +294,9 @@ public class BucketFlowResource extends ApplicationResource
{
if
(StringUtils.isBlank(snapshot.getSnapshotMetadata().getAuthor())) {
throw new BadRequestException("Author must not be blank");
}
+ if (snapshot.getSnapshotMetadata().getTimestamp() <= 0) {
+ throw new BadRequestException("Invalid timestamp");
+ }
} else {
final String userIdentity = NiFiUserUtils.getNiFiUserIdentity();
snapshot.getSnapshotMetadata().setAuthor(userIdentity);