Search in sources :

Example 16 with VersionedFlowSnapshot

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

the class TestRegistryService method testCreateFirstSnapshot.

@Test
public void testCreateFirstSnapshot() {
    final VersionedFlowSnapshot snapshot = createSnapshot();
    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());
    verify(snapshotSerializer, times(1)).serialize(eq(snapshot.getFlowContents()), any(OutputStream.class));
    verify(flowPersistenceProvider, times(1)).saveFlowContent(any(), any());
    verify(metadataService, times(1)).createFlowSnapshot(any(FlowSnapshotEntity.class));
}
Also used : BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) FlowSnapshotEntity(org.apache.nifi.registry.db.entity.FlowSnapshotEntity) OutputStream(java.io.OutputStream) VersionedFlowSnapshot(org.apache.nifi.registry.flow.VersionedFlowSnapshot) Date(java.util.Date) FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity) Test(org.junit.Test)

Example 17 with VersionedFlowSnapshot

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

the class TestRegistryService method testCreateSnapshotNullFlowContents.

@Test(expected = ConstraintViolationException.class)
public void testCreateSnapshotNullFlowContents() {
    final VersionedFlowSnapshot snapshot = createSnapshot();
    snapshot.setFlowContents(null);
    registryService.createFlowSnapshot(snapshot);
}
Also used : VersionedFlowSnapshot(org.apache.nifi.registry.flow.VersionedFlowSnapshot) Test(org.junit.Test)

Example 18 with VersionedFlowSnapshot

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

the class TestRegistryService method testCreateSnapshotFlowDoesNotExist.

@Test(expected = ResourceNotFoundException.class)
public void testCreateSnapshotFlowDoesNotExist() {
    final VersionedFlowSnapshot snapshot = createSnapshot();
    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);
    when(metadataService.getFlowById(snapshot.getSnapshotMetadata().getFlowIdentifier())).thenReturn(null);
    registryService.createFlowSnapshot(snapshot);
}
Also used : BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) VersionedFlowSnapshot(org.apache.nifi.registry.flow.VersionedFlowSnapshot) Date(java.util.Date) Test(org.junit.Test)

Example 19 with VersionedFlowSnapshot

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

the class TestRegistryService method createSnapshot.

// ---------------------- Test VersionedFlowSnapshot methods ---------------------------------------------
private VersionedFlowSnapshot createSnapshot() {
    final VersionedFlowSnapshotMetadata snapshotMetadata = new VersionedFlowSnapshotMetadata();
    snapshotMetadata.setFlowIdentifier("flow1");
    snapshotMetadata.setVersion(1);
    snapshotMetadata.setComments("This is the first snapshot");
    snapshotMetadata.setBucketIdentifier("b1");
    snapshotMetadata.setAuthor("user1");
    final VersionedProcessGroup processGroup = new VersionedProcessGroup();
    processGroup.setIdentifier("pg1");
    processGroup.setName("My Process Group");
    final VersionedFlowSnapshot snapshot = new VersionedFlowSnapshot();
    snapshot.setSnapshotMetadata(snapshotMetadata);
    snapshot.setFlowContents(processGroup);
    return snapshot;
}
Also used : VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) VersionedFlowSnapshot(org.apache.nifi.registry.flow.VersionedFlowSnapshot) VersionedFlowSnapshotMetadata(org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata)

Example 20 with VersionedFlowSnapshot

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

the class FlowsIT method testCreateFlowVersionGetFlowVersion.

@Test
public void testCreateFlowVersionGetFlowVersion() throws Exception {
    // Given: an empty Bucket "3" (see FlowsIT.sql) with a newly created flow
    long testStartTime = System.currentTimeMillis();
    final String bucketId = "2";
    final VersionedFlow flow = new VersionedFlow();
    flow.setBucketIdentifier(bucketId);
    flow.setName("Test Flow for creating snapshots");
    flow.setDescription("This is a randomly named flow created by an integration test for the purpose of holding snapshots.");
    final VersionedFlow createdFlow = client.target(createURL("buckets/{bucketId}/flows")).resolveTemplate("bucketId", bucketId).request().post(Entity.entity(flow, MediaType.APPLICATION_JSON), VersionedFlow.class);
    final String flowId = createdFlow.getIdentifier();
    // When: an initial flow snapshot is created *without* a version
    final VersionedFlowSnapshotMetadata flowSnapshotMetadata = new VersionedFlowSnapshotMetadata();
    flowSnapshotMetadata.setBucketIdentifier("2");
    flowSnapshotMetadata.setFlowIdentifier(flowId);
    flowSnapshotMetadata.setComments("This is snapshot 1, created by an integration test.");
    final VersionedFlowSnapshot flowSnapshot = new VersionedFlowSnapshot();
    flowSnapshot.setSnapshotMetadata(flowSnapshotMetadata);
    // an empty root process group
    flowSnapshot.setFlowContents(new VersionedProcessGroup());
    WebTarget clientRequestTarget = client.target(createURL("buckets/{bucketId}/flows/{flowId}/versions")).resolveTemplate("bucketId", bucketId).resolveTemplate("flowId", flowId);
    final Response response = clientRequestTarget.request().post(Entity.entity(flowSnapshot, MediaType.APPLICATION_JSON), Response.class);
    // Then: an error is returned because version != 1
    assertEquals(400, response.getStatus());
    // But When: an initial flow snapshot is created with version == 1
    flowSnapshot.getSnapshotMetadata().setVersion(1);
    final VersionedFlowSnapshot createdFlowSnapshot = clientRequestTarget.request().post(Entity.entity(flowSnapshot, MediaType.APPLICATION_JSON), VersionedFlowSnapshot.class);
    // Then: the server returns the created flow snapshot, with server-set fields populated correctly :)
    assertFlowSnapshotsEqual(flowSnapshot, createdFlowSnapshot, false);
    // both server and client in same JVM, so there shouldn't be skew
    assertTrue(createdFlowSnapshot.getSnapshotMetadata().getTimestamp() - testStartTime > 0L);
    assertEquals("anonymous", createdFlowSnapshot.getSnapshotMetadata().getAuthor());
    assertNotNull(createdFlowSnapshot.getSnapshotMetadata().getLink());
    assertNotNull(createdFlowSnapshot.getSnapshotMetadata().getLink().getUri());
    assertNotNull(createdFlowSnapshot.getFlow());
    assertEquals(1, createdFlowSnapshot.getFlow().getVersionCount());
    assertNotNull(createdFlowSnapshot.getBucket());
    // And when .../flows/{id}/versions is queried, then the newly created flow snapshot is returned in the list
    final VersionedFlowSnapshotMetadata[] versionedFlowSnapshots = clientRequestTarget.request().get(VersionedFlowSnapshotMetadata[].class);
    assertNotNull(versionedFlowSnapshots);
    assertEquals(1, versionedFlowSnapshots.length);
    assertFlowSnapshotMetadataEqual(createdFlowSnapshot.getSnapshotMetadata(), versionedFlowSnapshots[0], true);
    // And when the link URI is queried, then the newly created flow snapshot is returned
    final VersionedFlowSnapshot flowSnapshotByLink = client.target(createURL(versionedFlowSnapshots[0].getLink().getUri().toString())).request().get(VersionedFlowSnapshot.class);
    assertFlowSnapshotsEqual(createdFlowSnapshot, flowSnapshotByLink, true);
    assertNotNull(flowSnapshotByLink.getFlow());
    assertNotNull(flowSnapshotByLink.getBucket());
    // And when the bucket is queried by .../versions/{v}, then the newly created flow snapshot is returned
    final VersionedFlowSnapshot flowSnapshotByVersionNumber = clientRequestTarget.path("/1").request().get(VersionedFlowSnapshot.class);
    assertFlowSnapshotsEqual(createdFlowSnapshot, flowSnapshotByVersionNumber, true);
    assertNotNull(flowSnapshotByVersionNumber.getFlow());
    assertNotNull(flowSnapshotByVersionNumber.getBucket());
    // And when the latest URI is queried, then the newly created flow snapshot is returned
    final VersionedFlowSnapshot flowSnapshotByLatest = clientRequestTarget.path("/latest").request().get(VersionedFlowSnapshot.class);
    assertFlowSnapshotsEqual(createdFlowSnapshot, flowSnapshotByLatest, true);
    assertNotNull(flowSnapshotByLatest.getFlow());
    assertNotNull(flowSnapshotByLatest.getBucket());
}
Also used : Response(javax.ws.rs.core.Response) VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) VersionedFlowSnapshot(org.apache.nifi.registry.flow.VersionedFlowSnapshot) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) WebTarget(javax.ws.rs.client.WebTarget) VersionedFlowSnapshotMetadata(org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata) Test(org.junit.Test)

Aggregations

VersionedFlowSnapshot (org.apache.nifi.registry.flow.VersionedFlowSnapshot)38 VersionedFlowSnapshotMetadata (org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata)18 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)16 VersionedFlow (org.apache.nifi.registry.flow.VersionedFlow)15 Bucket (org.apache.nifi.registry.bucket.Bucket)12 IOException (java.io.IOException)11 Date (java.util.Date)11 Test (org.junit.Test)11 ApiOperation (io.swagger.annotations.ApiOperation)8 ApiResponses (io.swagger.annotations.ApiResponses)8 Consumes (javax.ws.rs.Consumes)8 Path (javax.ws.rs.Path)8 Produces (javax.ws.rs.Produces)8 Authorizable (org.apache.nifi.authorization.resource.Authorizable)8 VersionedFlowState (org.apache.nifi.registry.flow.VersionedFlowState)8 RevisionDTO (org.apache.nifi.web.api.dto.RevisionDTO)8 VersionControlInformationDTO (org.apache.nifi.web.api.dto.VersionControlInformationDTO)8 HashMap (java.util.HashMap)7 NiFiRegistryException (org.apache.nifi.registry.client.NiFiRegistryException)7 Collections (java.util.Collections)6