From efb10e2b1dad0a3419e543e08130ef490765417d Mon Sep 17 00:00:00 2001 From: Bryan Bende Date: Mon, 4 Dec 2017 15:49:27 -0500 Subject: [PATCH] NIFIREG-42 Adding IT test for NiFi Registry client and upgrading to Spring Boot 2.0.0.M7 so we can use Jersey 2.26 --- nifi-registry-client/pom.xml | 42 +-- .../impl/TestJerseyNiFiRegistryClient.java | 315 ---------------- .../registry/client/impl/TestUserClient.java | 58 --- nifi-registry-framework/pom.xml | 10 + .../nifi/registry/db/DatabaseKeyService.java | 2 +- .../registry/db/DatabaseMetadataService.java | 14 +- .../registry/db/DatabaseKeyServiceSpec.groovy | 3 +- .../repository/TestBucketItemRepository.java | 8 +- .../db/repository/TestBucketRepository.java | 18 +- .../db/repository/TestFlowRepository.java | 12 +- .../TestFlowSnapshotRepository.java | 14 +- .../db/repository/TestKeyRepository.java | 10 +- nifi-registry-web-api/pom.xml | 27 +- .../registry/NiFiRegistryApiApplication.java | 2 +- .../nifi/registry/web/api/AccessResource.java | 5 +- .../registry/web/api/BucketFlowResource.java | 2 +- .../web/mapper/NiFiRegistryJsonProvider.java | 2 +- .../kerberos/KerberosSpnegoFactory.java | 4 +- .../KerberosSpnegoIdentityProvider.java | 9 +- .../NiFiRegistryTestApiApplication.java | 2 +- .../SecureLdapTestApiApplication.java | 2 +- .../registry/web/api/IntegrationTestBase.java | 50 ++- .../web/api/SecureNiFiRegistryClientIT.java | 163 ++++++++ .../api/UnsecuredNiFiRegistryClientIT.java | 349 ++++++++++++++++++ pom.xml | 71 ++-- 25 files changed, 667 insertions(+), 527 deletions(-) delete mode 100644 nifi-registry-client/src/test/java/org/apache/nifi/registry/client/impl/TestJerseyNiFiRegistryClient.java delete mode 100644 nifi-registry-client/src/test/java/org/apache/nifi/registry/client/impl/TestUserClient.java create mode 100644 nifi-registry-web-api/src/test/java/org/apache/nifi/registry/web/api/SecureNiFiRegistryClientIT.java create mode 100644 nifi-registry-web-api/src/test/java/org/apache/nifi/registry/web/api/UnsecuredNiFiRegistryClientIT.java diff --git a/nifi-registry-client/pom.xml b/nifi-registry-client/pom.xml index 660599504..70d279087 100644 --- a/nifi-registry-client/pom.xml +++ b/nifi-registry-client/pom.xml @@ -21,44 +21,6 @@ nifi-registry-client jar - - - 2.26 - 2.1 - - - - - - javax.ws.rs - javax.ws.rs-api - ${jax.rs.api.version} - - - org.glassfish.jersey.core - jersey-client - ${jersey.version} - - - org.glassfish.jersey.media - jersey-media-json-jackson - ${jersey.version} - - - org.glassfish.jersey.inject - jersey-hk2 - ${jersey.version} - - - org.glassfish.jersey.core - jersey-common - ${jersey.version} - - - - org.apache.nifi.registry @@ -73,18 +35,22 @@ org.glassfish.jersey.core jersey-client + ${jersey.version} org.glassfish.jersey.media jersey-media-json-jackson + ${jersey.version} org.glassfish.jersey.inject jersey-hk2 + ${jersey.version} org.glassfish.jersey.core jersey-common + ${jersey.version} org.slf4j diff --git a/nifi-registry-client/src/test/java/org/apache/nifi/registry/client/impl/TestJerseyNiFiRegistryClient.java b/nifi-registry-client/src/test/java/org/apache/nifi/registry/client/impl/TestJerseyNiFiRegistryClient.java deleted file mode 100644 index bfdfb3370..000000000 --- a/nifi-registry-client/src/test/java/org/apache/nifi/registry/client/impl/TestJerseyNiFiRegistryClient.java +++ /dev/null @@ -1,315 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.registry.client.impl; - -import org.apache.nifi.registry.bucket.Bucket; -import org.apache.nifi.registry.bucket.BucketItem; -import org.apache.nifi.registry.client.BucketClient; -import org.apache.nifi.registry.client.FlowClient; -import org.apache.nifi.registry.client.FlowSnapshotClient; -import org.apache.nifi.registry.client.ItemsClient; -import org.apache.nifi.registry.client.NiFiRegistryClient; -import org.apache.nifi.registry.client.NiFiRegistryClientConfig; -import org.apache.nifi.registry.client.NiFiRegistryException; -import org.apache.nifi.registry.field.Fields; -import org.apache.nifi.registry.flow.VersionedFlow; -import org.apache.nifi.registry.flow.VersionedFlowSnapshot; -import org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata; -import org.apache.nifi.registry.flow.VersionedProcessGroup; -import org.apache.nifi.registry.flow.VersionedProcessor; -import org.apache.nifi.registry.params.SortOrder; -import org.apache.nifi.registry.params.SortParameter; -import org.junit.Assert; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class TestJerseyNiFiRegistryClient { - - public static final Logger LOGGER = LoggerFactory.getLogger(TestJerseyNiFiRegistryClient.class); - - public static void main(String[] args) { - final NiFiRegistryClientConfig config = new NiFiRegistryClientConfig.Builder() - .baseUrl("http://localhost:8080") - .build(); - - final NiFiRegistryClient client = new JerseyNiFiRegistryClient.Builder() - .config(config) - .build(); - - final BucketClient bucketClient = client.getBucketClient(); - - try { - // ---------------------- TEST BUCKETS --------------------------// - - // create buckets - final int numBuckets = 10; - final List createdBuckets = new ArrayList<>(); - - for (int i=0; i < numBuckets; i++) { - final Bucket createdBucket = createBucket(bucketClient, i); - System.out.println("Created bucket # " + i + " with id " + createdBucket.getIdentifier()); - createdBuckets.add(createdBucket); - } - - // get each bucket - for (final Bucket bucket : createdBuckets) { - final Bucket retrievedBucket = bucketClient.get(bucket.getIdentifier()); - Assert.assertNotNull(retrievedBucket); - System.out.println("Retrieved bucket " + retrievedBucket.getIdentifier()); - } - - //final Bucket nonExistentBucket = bucketClient.get("does-not-exist"); - //Assert.assertNull(nonExistentBucket); - - // get bucket fields - final Fields bucketFields = bucketClient.getFields(); - Assert.assertNotNull(bucketFields); - System.out.println("Retrieved bucket fields, size = " + bucketFields.getFields().size()); - Assert.assertTrue(bucketFields.getFields().size() > 0); - - // get all buckets - final List allBuckets = bucketClient.getAll(); - System.out.println("Retrieved buckets, size = " + allBuckets.size()); - Assert.assertEquals(numBuckets, allBuckets.size()); - allBuckets.stream().forEach(b -> System.out.println("Retrieve bucket " + b.getIdentifier())); - - // get all buckets with sorting - final SortParameter sortParam = new SortParameter("created", SortOrder.ASC); - final List allBucketsSorted = bucketClient.getAll(Arrays.asList(sortParam)); - System.out.println("Retrieved sorted buckets, size = " + allBucketsSorted.size()); - Assert.assertEquals(numBuckets, allBucketsSorted.size()); - allBucketsSorted.stream().forEach(b -> System.out.println("Retrieve bucket " + b.getIdentifier())); - - // update each bucket - for (final Bucket bucket : createdBuckets) { - final Bucket bucketUpdate = new Bucket(); - bucketUpdate.setIdentifier(bucket.getIdentifier()); - bucketUpdate.setDescription(bucket.getDescription() + " UPDATE"); - - final Bucket updatedBucket = bucketClient.update(bucketUpdate); - Assert.assertNotNull(updatedBucket); - System.out.println("Updated bucket " + updatedBucket.getIdentifier()); - } - - // ---------------------- TEST FLOWS --------------------------// - - final FlowClient flowClient = client.getFlowClient(); - - // create flows - final Bucket flowsBucket = createdBuckets.get(0); - - final VersionedFlow flow1 = createFlow(flowClient, flowsBucket, 1); - System.out.println("Created flow # 1 with id " + flow1.getIdentifier()); - - final VersionedFlow flow2 = createFlow(flowClient, flowsBucket, 2); - System.out.println("Created flow # 2 with id " + flow2.getIdentifier()); - - // get flow - final VersionedFlow retrievedFlow1 = flowClient.get(flowsBucket.getIdentifier(), flow1.getIdentifier()); - Assert.assertNotNull(retrievedFlow1); - System.out.println("Retrieved flow # 1 with id " + retrievedFlow1.getIdentifier()); - - final VersionedFlow retrievedFlow2 = flowClient.get(flowsBucket.getIdentifier(), flow2.getIdentifier()); - Assert.assertNotNull(retrievedFlow2); - System.out.println("Retrieved flow # 2 with id " + retrievedFlow2.getIdentifier()); - - // update flows - final VersionedFlow flow1Update = new VersionedFlow(); - flow1Update.setIdentifier(flow1.getIdentifier()); - flow1Update.setName(flow1.getName() + " UPDATED"); - - final VersionedFlow updatedFlow1 = flowClient.update(flowsBucket.getIdentifier(), flow1Update); - Assert.assertNotNull(updatedFlow1); - System.out.println("Updated flow # 1 with id " + updatedFlow1.getIdentifier()); - - // get flow fields - final Fields flowFields = flowClient.getFields(); - Assert.assertNotNull(flowFields); - System.out.println("Retrieved flow fields, size = " + flowFields.getFields().size()); - Assert.assertTrue(flowFields.getFields().size() > 0); - - // get flows in bucket - final List flowsInBucket = flowClient.getByBucket(flowsBucket.getIdentifier()); - Assert.assertNotNull(flowsInBucket); - Assert.assertEquals(2, flowsInBucket.size()); - flowsInBucket.stream().forEach(f -> System.out.println("Flow in bucket, flow id " + f.getIdentifier())); - - // get flows in bucket with sorting - final SortParameter flowsSortParam = new SortParameter("created", SortOrder.ASC); - final List flowsInBucketSorted = flowClient.getByBucket(flowsBucket.getIdentifier(), Arrays.asList(flowsSortParam)); - Assert.assertNotNull(flowsInBucketSorted); - Assert.assertEquals(2, flowsInBucketSorted.size()); - - // ---------------------- TEST SNAPSHOTS --------------------------// - - final FlowSnapshotClient snapshotClient = client.getFlowSnapshotClient(); - - // create snapshots - final VersionedFlow snapshotFlow = flow1; - - final VersionedFlowSnapshot snapshot1 = createSnapshot(snapshotClient, snapshotFlow, 1); - System.out.println("Created snapshot # 1 with version " + snapshot1.getSnapshotMetadata().getVersion()); - - final VersionedFlowSnapshot snapshot2 = createSnapshot(snapshotClient, snapshotFlow, 2); - System.out.println("Created snapshot # 2 with version " + snapshot2.getSnapshotMetadata().getVersion()); - - // get snapshot - final VersionedFlowSnapshot retrievedSnapshot1 = snapshotClient.get(snapshotFlow.getBucketIdentifier(), snapshotFlow.getIdentifier(), 1); - Assert.assertNotNull(retrievedSnapshot1); - Assert.assertFalse(retrievedSnapshot1.isLatest()); - System.out.println("Retrieved snapshot # 1 with version " + retrievedSnapshot1.getSnapshotMetadata().getVersion()); - - final VersionedFlowSnapshot retrievedSnapshot2 = snapshotClient.get(snapshotFlow.getBucketIdentifier(), snapshotFlow.getIdentifier(), 2); - Assert.assertNotNull(retrievedSnapshot2); - Assert.assertTrue(retrievedSnapshot2.isLatest()); - System.out.println("Retrieved snapshot # 2 with version " + retrievedSnapshot2.getSnapshotMetadata().getVersion()); - - // get latest - final VersionedFlowSnapshot retrievedSnapshotLatest = snapshotClient.getLatest(snapshotFlow.getBucketIdentifier(), snapshotFlow.getIdentifier()); - Assert.assertNotNull(retrievedSnapshotLatest); - Assert.assertEquals(snapshot2.getSnapshotMetadata().getVersion(), retrievedSnapshotLatest.getSnapshotMetadata().getVersion()); - Assert.assertTrue(retrievedSnapshotLatest.isLatest()); - System.out.println("Retrieved latest snapshot with version " + retrievedSnapshotLatest.getSnapshotMetadata().getVersion()); - - // get metadata - final List retrievedMetadata = snapshotClient.getSnapshotMetadata(snapshotFlow.getBucketIdentifier(), snapshotFlow.getIdentifier()); - Assert.assertNotNull(retrievedMetadata); - Assert.assertEquals(2, retrievedMetadata.size()); - retrievedMetadata.stream().forEach(s -> System.out.println("Retrieved snapshot metadata " + s.getVersion())); - - // ---------------------- TEST ITEMS --------------------------// - - final ItemsClient itemsClient = client.getItemsClient(); - - // get fields - final Fields itemFields = itemsClient.getFields(); - Assert.assertNotNull(itemFields.getFields()); - Assert.assertTrue(itemFields.getFields().size() > 0); - - // get all items - final List allItems = itemsClient.getAll(); - Assert.assertEquals(2, allItems.size()); - allItems.stream().forEach(i -> System.out.println("All items, item " + i.getIdentifier())); - - // get all items with sorting - final SortParameter itemsSortParam = new SortParameter("created", SortOrder.ASC); - final List allItemsSorted = itemsClient.getAll(Arrays.asList(itemsSortParam)); - Assert.assertEquals(2, allItemsSorted.size()); - - // get items for bucket - final List bucketItems = itemsClient.getByBucket(flowsBucket.getIdentifier()); - Assert.assertEquals(2, bucketItems.size()); - bucketItems.stream().forEach(i -> System.out.println("Items in bucket, item " + i.getIdentifier())); - - // get items for bucket with sorting - final List bucketItemsSorted = itemsClient.getByBucket(flowsBucket.getIdentifier(), Arrays.asList(itemsSortParam)); - Assert.assertEquals(2, bucketItemsSorted.size()); - - // ---------------------- DELETE DATA --------------------------// - - final VersionedFlow deletedFlow1 = flowClient.delete(flowsBucket.getIdentifier(), flow1.getIdentifier()); - Assert.assertNotNull(deletedFlow1); - System.out.println("Deleted flow " + deletedFlow1.getIdentifier()); - - final VersionedFlow deletedFlow2 = flowClient.delete(flowsBucket.getIdentifier(), flow2.getIdentifier()); - Assert.assertNotNull(deletedFlow2); - System.out.println("Deleted flow " + deletedFlow2.getIdentifier()); - - // delete each bucket - for (final Bucket bucket : createdBuckets) { - final Bucket deletedBucket = bucketClient.delete(bucket.getIdentifier()); - Assert.assertNotNull(deletedBucket); - System.out.println("Deleted bucket " + deletedBucket.getIdentifier()); - } - Assert.assertEquals(0, bucketClient.getAll().size()); - - System.out.println("!!! SUCCESS !!!"); - - } catch (Exception e) { - LOGGER.error(e.getMessage(), e); - } finally { - try { - client.close(); - } catch (Exception e) { - - } - } - } - - private static Bucket createBucket(BucketClient bucketClient, int num) throws IOException, NiFiRegistryException { - final Bucket bucket = new Bucket(); - bucket.setName("Bucket #" + num); - bucket.setDescription("This is bucket #" + num); - return bucketClient.create(bucket); - } - - private static VersionedFlow createFlow(FlowClient client, Bucket bucket, int num) throws IOException, NiFiRegistryException { - final VersionedFlow versionedFlow = new VersionedFlow(); - versionedFlow.setName(bucket.getName() + " Flow #" + num); - versionedFlow.setDescription("This is " + bucket.getName() + " flow #" + num); - versionedFlow.setBucketIdentifier(bucket.getIdentifier()); - return client.create(versionedFlow); - } - - private static VersionedFlowSnapshot createSnapshot(FlowSnapshotClient client, VersionedFlow flow, int num) throws IOException, NiFiRegistryException { - final VersionedFlowSnapshotMetadata snapshotMetadata = new VersionedFlowSnapshotMetadata(); - snapshotMetadata.setBucketIdentifier(flow.getBucketIdentifier()); - snapshotMetadata.setFlowIdentifier(flow.getIdentifier()); - snapshotMetadata.setVersion(num); - snapshotMetadata.setComments("This is snapshot #" + num); - - final VersionedProcessGroup rootProcessGroup = new VersionedProcessGroup(); - rootProcessGroup.setIdentifier("root-pg"); - rootProcessGroup.setName("Root Process Group"); - - final VersionedProcessGroup subProcessGroup = new VersionedProcessGroup(); - subProcessGroup.setIdentifier("sub-pg"); - subProcessGroup.setName("Sub Process Group"); - rootProcessGroup.getProcessGroups().add(subProcessGroup); - - final Map processorProperties = new HashMap<>(); - processorProperties.put("Prop 1", "Val 1"); - processorProperties.put("Prop 2", "Val 2"); - - final VersionedProcessor processor1 = new VersionedProcessor(); - processor1.setIdentifier("p1"); - processor1.setName("Processor 1"); - processor1.setProperties(processorProperties); - - final VersionedProcessor processor2 = new VersionedProcessor(); - processor2.setIdentifier("p2"); - processor2.setName("Processor 2"); - processor2.setProperties(processorProperties); - - subProcessGroup.getProcessors().add(processor1); - subProcessGroup.getProcessors().add(processor2); - - final VersionedFlowSnapshot snapshot = new VersionedFlowSnapshot(); - snapshot.setSnapshotMetadata(snapshotMetadata); - snapshot.setFlowContents(rootProcessGroup); - - return client.create(snapshot); - } - -} diff --git a/nifi-registry-client/src/test/java/org/apache/nifi/registry/client/impl/TestUserClient.java b/nifi-registry-client/src/test/java/org/apache/nifi/registry/client/impl/TestUserClient.java deleted file mode 100644 index 1184e56e6..000000000 --- a/nifi-registry-client/src/test/java/org/apache/nifi/registry/client/impl/TestUserClient.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.registry.client.impl; - -import org.apache.nifi.registry.client.NiFiRegistryClient; -import org.apache.nifi.registry.client.NiFiRegistryClientConfig; -import org.apache.nifi.registry.client.UserClient; -import org.apache.nifi.registry.model.authorization.AccessStatus; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class TestUserClient { - - public static final Logger LOGGER = LoggerFactory.getLogger(TestUserClient.class); - - public static void main(String[] args) { - final NiFiRegistryClientConfig config = new NiFiRegistryClientConfig.Builder() - .baseUrl("http://localhost:8080") - .build(); - - final NiFiRegistryClient client = new JerseyNiFiRegistryClient.Builder() - .config(config) - .build(); - - final UserClient userClient = client.getUserClient(); - - try { - final AccessStatus status = userClient.getAccessStatus(); - System.out.println("Identity: " + status.getIdentity()); - System.out.println("Status: " + status.getStatus()); - System.out.println("Message: " + status.getMessage()); - - } catch (Exception e) { - LOGGER.error(e.getMessage(), e); - } finally { - try { - client.close(); - } catch (Exception e) { - - } - } - } - -} diff --git a/nifi-registry-framework/pom.xml b/nifi-registry-framework/pom.xml index e4bc46224..28870b51b 100644 --- a/nifi-registry-framework/pom.xml +++ b/nifi-registry-framework/pom.xml @@ -263,6 +263,16 @@ flyway-spring-test ${flyway.version} test + + + org.springframework + spring-context + + + org.springframework + spring-jdbc + + org.mockito diff --git a/nifi-registry-framework/src/main/java/org/apache/nifi/registry/db/DatabaseKeyService.java b/nifi-registry-framework/src/main/java/org/apache/nifi/registry/db/DatabaseKeyService.java index eb552518f..d0697b3ae 100644 --- a/nifi-registry-framework/src/main/java/org/apache/nifi/registry/db/DatabaseKeyService.java +++ b/nifi-registry-framework/src/main/java/org/apache/nifi/registry/db/DatabaseKeyService.java @@ -55,7 +55,7 @@ public Key getKey(String id) { Key key = null; readLock.lock(); try { - KeyEntity keyEntity = keyRepository.findOne(id); + KeyEntity keyEntity = keyRepository.findById(id).orElse(null); if (keyEntity != null) { key = DataModelMapper.map(keyEntity); } else { diff --git a/nifi-registry-framework/src/main/java/org/apache/nifi/registry/db/DatabaseMetadataService.java b/nifi-registry-framework/src/main/java/org/apache/nifi/registry/db/DatabaseMetadataService.java index 02be4456a..3f0373a55 100644 --- a/nifi-registry-framework/src/main/java/org/apache/nifi/registry/db/DatabaseMetadataService.java +++ b/nifi-registry-framework/src/main/java/org/apache/nifi/registry/db/DatabaseMetadataService.java @@ -106,7 +106,7 @@ public BucketEntity createBucket(final BucketEntity bucket) { @Override public BucketEntity getBucketById(final String bucketIdentifier) { - return bucketRepository.findOne(bucketIdentifier); + return bucketRepository.findById(bucketIdentifier).orElse(null); } @Override @@ -282,7 +282,7 @@ public FlowEntity createFlow(final FlowEntity flow) { @Override public FlowEntity getFlowById(final String bucketIdentifier, final String flowIdentifier) { - FlowEntity flow = flowRepository.findOne(flowIdentifier); + FlowEntity flow = flowRepository.findById(flowIdentifier).orElse(null); if (flow == null || flow.getBucket() == null || !bucketIdentifier.equals(flow.getBucket().getId())) { return null; @@ -293,7 +293,7 @@ public FlowEntity getFlowById(final String bucketIdentifier, final String flowId @Override public FlowEntity getFlowByIdWithSnapshotCounts(final String bucketIdentifier, final String flowIdentifier) { - FlowEntity flow = flowRepository.findOne(flowIdentifier); + FlowEntity flow = flowRepository.findById(flowIdentifier).orElse(null); if (flow == null || flow.getBucket() == null || !bucketIdentifier.equals(flow.getBucket().getId())) { return null; @@ -362,7 +362,7 @@ public FlowSnapshotEntity createFlowSnapshot(final FlowSnapshotEntity flowSnapsh @Override public FlowSnapshotEntity getFlowSnapshot(final String bucketIdentifier, final String flowIdentifier, final Integer version) { final FlowSnapshotEntityKey key = new FlowSnapshotEntityKey(flowIdentifier, version); - FlowSnapshotEntity flowSnapshot = flowSnapshotRepository.findOne(key); + FlowSnapshotEntity flowSnapshot = flowSnapshotRepository.findById(key).orElse(null); if (flowSnapshot == null || flowSnapshot.getFlow() == null @@ -403,9 +403,9 @@ public Set getFlowFields() { private Pageable getPageRequest(final QueryParameters parameters) { final Sort sort = getSort(parameters); if (sort == null) { - return new PageRequest(parameters.getPageNum(), parameters.getNumRows()); + return PageRequest.of(parameters.getPageNum(), parameters.getNumRows()); } else { - return new PageRequest(parameters.getPageNum(), parameters.getNumRows(), sort); + return PageRequest.of(parameters.getPageNum(), parameters.getNumRows(), sort); } } @@ -427,7 +427,7 @@ private Sort getSort(final QueryParameters parameters) { if (orders.isEmpty()) { return null; } else { - return new Sort(orders); + return Sort.by(orders); } } diff --git a/nifi-registry-framework/src/test/groovy/org/apache/nifi/registry/db/DatabaseKeyServiceSpec.groovy b/nifi-registry-framework/src/test/groovy/org/apache/nifi/registry/db/DatabaseKeyServiceSpec.groovy index c3cea6a61..3695ead27 100644 --- a/nifi-registry-framework/src/test/groovy/org/apache/nifi/registry/db/DatabaseKeyServiceSpec.groovy +++ b/nifi-registry-framework/src/test/groovy/org/apache/nifi/registry/db/DatabaseKeyServiceSpec.groovy @@ -34,7 +34,8 @@ class DatabaseKeyServiceSpec extends Specification { def "get key"() { given: "a record exists for id=key1" - keyRepository.findOne("key1") >> new KeyEntity([id: "key1", tenantIdentity: "user1", keyValue: "keyValue1"]) + keyRepository.findById("key1") >> Optional.of(new KeyEntity([id: "key1", tenantIdentity: "user1", keyValue: "keyValue1"])) + keyRepository.findById("key2") >> Optional.empty() when: "getKey is called with an existing id" Key existingKey = keyService.getKey("key1") diff --git a/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestBucketItemRepository.java b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestBucketItemRepository.java index c7fd7af59..c024d7631 100644 --- a/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestBucketItemRepository.java +++ b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestBucketItemRepository.java @@ -39,7 +39,7 @@ public class TestBucketItemRepository extends DatabaseBaseTest { @Test public void testFindByBucket() { - final BucketEntity bucket = bucketRepository.findOne("1"); + final BucketEntity bucket = bucketRepository.findById("1").orElse(null); assertNotNull(bucket); final List entities = bucketItemRepository.findByBucket(bucket); @@ -49,10 +49,10 @@ public void testFindByBucket() { @Test public void testFindByBucketPageable() { - final BucketEntity bucket = bucketRepository.findOne("1"); + final BucketEntity bucket = bucketRepository.findById("1").orElse(null); assertNotNull(bucket); - final List entities = bucketItemRepository.findByBucket(bucket, new PageRequest(0, 2, new Sort(Sort.Direction.ASC, "id"))); + final List entities = bucketItemRepository.findByBucket(bucket, PageRequest.of(0, 2, new Sort(Sort.Direction.ASC, "id"))); assertNotNull(entities); assertEquals(2, entities.size()); assertEquals("1", entities.get(0).getId()); @@ -61,7 +61,7 @@ public void testFindByBucketPageable() { @Test public void testFindByBucketSort() { - final BucketEntity bucket = bucketRepository.findOne("1"); + final BucketEntity bucket = bucketRepository.findById("1").orElse(null); assertNotNull(bucket); final List entities = bucketItemRepository.findByBucket(bucket, new Sort(Sort.Direction.DESC, "id")); diff --git a/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestBucketRepository.java b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestBucketRepository.java index f431180a3..7c1d74f8c 100644 --- a/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestBucketRepository.java +++ b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestBucketRepository.java @@ -61,7 +61,7 @@ public void testCreate() { public void testUpdate() { final String id = "1"; - final BucketEntity existingBucket = bucketRepository.findOne(id); + final BucketEntity existingBucket = bucketRepository.findById(id).orElse(null); assertNotNull(existingBucket); final String updatedDescription = existingBucket.getDescription() + " UPDATED"; @@ -69,7 +69,7 @@ public void testUpdate() { bucketRepository.save(existingBucket); - final BucketEntity updatedBucket = bucketRepository.findOne(id); + final BucketEntity updatedBucket = bucketRepository.findById(id).orElse(null); assertNotNull(updatedBucket); assertEquals(updatedDescription, updatedBucket.getDescription()); @@ -81,12 +81,12 @@ public void testUpdate() { public void testDelete() { final String id = "6"; - final BucketEntity existingBucket = bucketRepository.findOne(id); + final BucketEntity existingBucket = bucketRepository.findById(id).orElse(null); assertNotNull(existingBucket); bucketRepository.delete(existingBucket); - final BucketEntity updatedBucket = bucketRepository.findOne(id); + final BucketEntity updatedBucket = bucketRepository.findById(id).orElse(null); assertNull(updatedBucket); } @@ -94,7 +94,7 @@ public void testDelete() { public void testOneToManyWithBucketItems() { final String id = "1"; - final BucketEntity existingBucket = bucketRepository.findOne(id); + final BucketEntity existingBucket = bucketRepository.findById(id).orElse(null); assertNotNull(existingBucket); final Set items = existingBucket.getItems(); @@ -122,7 +122,7 @@ public void testFindAllWithPaging() { int pageSize = 2; // query for first page - Pageable pageable = new PageRequest(pageIndex, pageSize, sort); + Pageable pageable = PageRequest.of(pageIndex, pageSize, sort); Page page = bucketRepository.findAll(pageable); assertNotNull(page); @@ -139,7 +139,7 @@ public void testFindAllWithPaging() { // query for second page pageIndex++; - pageable = new PageRequest(pageIndex, pageSize, sort); + pageable = PageRequest.of(pageIndex, pageSize, sort); buckets = bucketRepository.findAll(pageable); assertNotNull(buckets); @@ -150,7 +150,7 @@ public void testFindAllWithPaging() { // query for third page pageIndex++; - pageable = new PageRequest(pageIndex, pageSize, sort); + pageable = PageRequest.of(pageIndex, pageSize, sort); buckets = bucketRepository.findAll(pageable); assertNotNull(buckets); @@ -161,7 +161,7 @@ public void testFindAllWithPaging() { // query for fourth page pageIndex++; - pageable = new PageRequest(pageIndex, pageSize, sort); + pageable = PageRequest.of(pageIndex, pageSize, sort); buckets = bucketRepository.findAll(pageable); assertNotNull(buckets); diff --git a/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestFlowRepository.java b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestFlowRepository.java index dbffb7aaa..5646966bf 100644 --- a/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestFlowRepository.java +++ b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestFlowRepository.java @@ -44,7 +44,7 @@ public class TestFlowRepository extends DatabaseBaseTest { public void testCreateFlow() { final String bucketId = "1"; - final BucketEntity existingBucket = bucketRepository.findOne(bucketId); + final BucketEntity existingBucket = bucketRepository.findById(bucketId).orElse(null); assertNotNull(existingBucket); assertNotNull(existingBucket.getItems()); assertEquals(2, existingBucket.getItems().size()); @@ -71,7 +71,7 @@ public void testCreateFlow() { public void testUpdateFlow() { final String flowId = "1"; - final FlowEntity flow = flowRepository.findOne(flowId); + final FlowEntity flow = flowRepository.findById(flowId).orElse(null); assertNotNull(flow); assertEquals(flowId, flow.getId()); @@ -80,7 +80,7 @@ public void testUpdateFlow() { flowRepository.save(flow); - final FlowEntity updatedFlow = flowRepository.findOne(flowId); + final FlowEntity updatedFlow = flowRepository.findById(flowId).orElse(null); assertEquals(flow.getName(), updatedFlow.getName()); assertEquals(flow.getDescription(), updatedFlow.getDescription()); assertEquals(flow.getCreated(), updatedFlow.getCreated()); @@ -92,12 +92,12 @@ public void testUpdateFlow() { public void testDeleteFlow() { final String flowId = "1"; - final FlowEntity flow = flowRepository.findOne(flowId); + final FlowEntity flow = flowRepository.findById(flowId).orElse(null); assertNotNull(flow); flowRepository.delete(flow); - final FlowEntity deletedFlow = flowRepository.findOne(flowId); + final FlowEntity deletedFlow = flowRepository.findById(flowId).orElse(null); assertNull(deletedFlow); } @@ -105,7 +105,7 @@ public void testDeleteFlow() { public void testOneToManyWithFlowSnapshots() { final String flowId = "1"; - final FlowEntity flow = flowRepository.findOne(flowId); + final FlowEntity flow = flowRepository.findById(flowId).orElse(null); assertNotNull(flow); assertNotNull(flow.getSnapshots()); assertEquals(3, flow.getSnapshots().size()); diff --git a/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestFlowSnapshotRepository.java b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestFlowSnapshotRepository.java index d2d598520..2dc74b9b7 100644 --- a/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestFlowSnapshotRepository.java +++ b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestFlowSnapshotRepository.java @@ -57,7 +57,7 @@ public void testCreateFlowSnapshot() { flowSnapshotRepository.save(flowSnapshot); - final FlowSnapshotEntity createdFlowSnapshot = flowSnapshotRepository.findOne(key); + final FlowSnapshotEntity createdFlowSnapshot = flowSnapshotRepository.findById(key).orElse(null); assertNotNull(createdFlowSnapshot); } @@ -67,7 +67,7 @@ public void testFindById() { key.setFlowId("1"); key.setVersion(1); - final FlowSnapshotEntity flowSnapshot = flowSnapshotRepository.findOne(key); + final FlowSnapshotEntity flowSnapshot = flowSnapshotRepository.findById(key).orElse(null); assertNotNull(flowSnapshot); assertEquals(key, flowSnapshot.getId()); assertNotNull(flowSnapshot.getFlow()); @@ -80,12 +80,12 @@ public void testDeleteFlowSnapshot() { key.setFlowId("1"); key.setVersion(1); - final FlowSnapshotEntity flowSnapshot = flowSnapshotRepository.findOne(key); + final FlowSnapshotEntity flowSnapshot = flowSnapshotRepository.findById(key).orElse(null); assertNotNull(flowSnapshot); flowSnapshotRepository.delete(flowSnapshot); - final FlowSnapshotEntity deletedFlowSnapshot = flowSnapshotRepository.findOne(key); + final FlowSnapshotEntity deletedFlowSnapshot = flowSnapshotRepository.findById(key).orElse(null); assertNull(deletedFlowSnapshot); } @@ -95,7 +95,7 @@ public void testDeleteBucketCascadesToSnapshots() { key.setFlowId("1"); key.setVersion(1); - final FlowSnapshotEntity flowSnapshot = flowSnapshotRepository.findOne(key); + final FlowSnapshotEntity flowSnapshot = flowSnapshotRepository.findById(key).orElse(null); assertNotNull(flowSnapshot); final FlowEntity flow = flowSnapshot.getFlow(); @@ -106,8 +106,8 @@ public void testDeleteBucketCascadesToSnapshots() { bucketRepository.delete(bucket); - assertNull(flowRepository.findOne(flow.getId())); - assertNull(flowSnapshotRepository.findOne(key)); + assertNull(flowRepository.findById(flow.getId()).orElse(null)); + assertNull(flowSnapshotRepository.findById(key).orElse(null)); } @Test diff --git a/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestKeyRepository.java b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestKeyRepository.java index 567b0be17..6bc4fefac 100644 --- a/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestKeyRepository.java +++ b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestKeyRepository.java @@ -51,7 +51,7 @@ public void testCreate() { public void testUpdate() { final String prepopulatedKeyId = "1"; // see test-setup.sql - final KeyEntity existingKey = keyRepository.findOne(prepopulatedKeyId); + final KeyEntity existingKey = keyRepository.findById(prepopulatedKeyId).orElse(null); assertNotNull(existingKey); final String updatedKeyValue = existingKey.getKeyValue() + " UPDATED"; @@ -59,7 +59,7 @@ public void testUpdate() { keyRepository.save(existingKey); - final KeyEntity updatedKey = keyRepository.findOne(prepopulatedKeyId); + final KeyEntity updatedKey = keyRepository.findById(prepopulatedKeyId).orElse(null); assertNotNull(updatedKey); assertEquals(updatedKeyValue, updatedKey.getKeyValue()); } @@ -69,12 +69,12 @@ public void testUpdate() { public void testDelete() { final String id = "1"; - final KeyEntity existingKey = keyRepository.findOne("1"); + final KeyEntity existingKey = keyRepository.findById("1").orElse(null); assertNotNull(existingKey); keyRepository.delete(existingKey); - final KeyEntity deletedKey = keyRepository.findOne("1"); + final KeyEntity deletedKey = keyRepository.findById("1").orElse(null); assertNull(deletedKey); } @@ -99,7 +99,7 @@ public void testDeleteByTenantIdentity() { KeyEntity deletedKey = keyRepository.findOneByTenantIdentity(prepopulatedKeyTenantIdentity); assertNull(deletedKey); - deletedKey = keyRepository.findOne("1"); + deletedKey = keyRepository.findById("1").orElse(null); assertNull(deletedKey); } diff --git a/nifi-registry-web-api/pom.xml b/nifi-registry-web-api/pom.xml index 8b53496e3..48c561559 100644 --- a/nifi-registry-web-api/pom.xml +++ b/nifi-registry-web-api/pom.xml @@ -108,10 +108,17 @@ spring-boot-starter-jersey ${spring.boot.version} + org.springframework.boot spring-boot-starter-actuator ${spring.boot.version} + + + io.micrometer + micrometer-core + + org.springframework.security.kerberos @@ -172,26 +179,6 @@ javax.servlet-api provided - - org.glassfish.jersey.core - jersey-server - - - org.glassfish.jersey.containers - jersey-container-servlet - - - org.glassfish.jersey.core - jersey-client - - - org.glassfish.jersey.media - jersey-media-json-jackson - - - org.glassfish.jersey.ext - jersey-bean-validation - io.swagger swagger-annotations diff --git a/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/NiFiRegistryApiApplication.java b/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/NiFiRegistryApiApplication.java index 19adaed91..ad6c1db0a 100644 --- a/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/NiFiRegistryApiApplication.java +++ b/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/NiFiRegistryApiApplication.java @@ -19,7 +19,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.web.support.SpringBootServletInitializer; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import java.util.Properties; diff --git a/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/AccessResource.java b/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/AccessResource.java index 5cd1ccda5..02bc3db86 100644 --- a/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/AccessResource.java +++ b/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/AccessResource.java @@ -41,6 +41,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.lang.Nullable; import org.springframework.stereotype.Component; import javax.servlet.http.HttpServletRequest; @@ -80,8 +81,8 @@ public AccessResource( NiFiRegistryProperties properties, JwtService jwtService, X509IdentityProvider x509IdentityProvider, - KerberosSpnegoIdentityProvider kerberosSpnegoIdentityProvider, - IdentityProvider identityProvider) { + @Nullable KerberosSpnegoIdentityProvider kerberosSpnegoIdentityProvider, + @Nullable IdentityProvider identityProvider) { this.properties = properties; this.jwtService = jwtService; this.x509IdentityProvider = x509IdentityProvider; diff --git a/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/BucketFlowResource.java b/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/BucketFlowResource.java index eac4e9cd5..c8a88440e 100644 --- a/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/BucketFlowResource.java +++ b/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/BucketFlowResource.java @@ -330,7 +330,7 @@ public Response getLatestFlowVersion( throw new ResourceNotFoundException("Not flow versions found for flow with id " + flowId); } - final VersionedFlowSnapshotMetadata lastSnapshotMetadata = snapshots.last(); + final VersionedFlowSnapshotMetadata lastSnapshotMetadata = snapshots.first(); final VersionedFlowSnapshot lastSnapshot = registryService.getFlowSnapshot(bucketId, flowId, lastSnapshotMetadata.getVersion()); populateLinks(lastSnapshot); diff --git a/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/mapper/NiFiRegistryJsonProvider.java b/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/mapper/NiFiRegistryJsonProvider.java index 3d2e4a172..a2174ba31 100644 --- a/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/mapper/NiFiRegistryJsonProvider.java +++ b/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/mapper/NiFiRegistryJsonProvider.java @@ -19,8 +19,8 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider; import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector; +import org.glassfish.jersey.jackson.internal.jackson.jaxrs.json.JacksonJaxbJsonProvider; import org.springframework.stereotype.Component; import javax.ws.rs.Produces; diff --git a/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/security/authentication/kerberos/KerberosSpnegoFactory.java b/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/security/authentication/kerberos/KerberosSpnegoFactory.java index 66d369dbc..16211ed27 100644 --- a/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/security/authentication/kerberos/KerberosSpnegoFactory.java +++ b/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/security/authentication/kerberos/KerberosSpnegoFactory.java @@ -47,8 +47,8 @@ public KerberosSpnegoIdentityProvider kerberosSpnegoIdentityProvider() throws Ex return kerberosSpnegoIdentityProvider; } - @Bean - public KerberosServiceAuthenticationProvider kerberosServiceAuthenticationProvider() throws Exception { + + private KerberosServiceAuthenticationProvider kerberosServiceAuthenticationProvider() throws Exception { if (kerberosServiceAuthenticationProvider == null && properties.isKerberosSpnegoSupportEnabled()) { diff --git a/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/security/authentication/kerberos/KerberosSpnegoIdentityProvider.java b/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/security/authentication/kerberos/KerberosSpnegoIdentityProvider.java index 70027928a..e611b53c6 100644 --- a/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/security/authentication/kerberos/KerberosSpnegoIdentityProvider.java +++ b/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/security/authentication/kerberos/KerberosSpnegoIdentityProvider.java @@ -31,6 +31,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.lang.Nullable; import org.springframework.security.authentication.AuthenticationDetailsSource; import org.springframework.security.core.Authentication; import org.springframework.security.core.AuthenticationException; @@ -73,7 +74,9 @@ public AuthType getAuthType() { private AuthenticationDetailsSource authenticationDetailsSource; @Autowired - public KerberosSpnegoIdentityProvider(KerberosServiceAuthenticationProvider kerberosServiceAuthenticationProvider, NiFiRegistryProperties properties) { + public KerberosSpnegoIdentityProvider( + @Nullable KerberosServiceAuthenticationProvider kerberosServiceAuthenticationProvider, + NiFiRegistryProperties properties) { this.kerberosServiceAuthenticationProvider = kerberosServiceAuthenticationProvider; authenticationDetailsSource = new WebAuthenticationDetailsSource(); @@ -129,6 +132,10 @@ public AuthenticationResponse authenticate(AuthenticationRequest authenticationR return null; } + if (kerberosServiceAuthenticationProvider == null) { + throw new IdentityAccessException("The Kerberos authentication provider is not initialized."); + } + try { KerberosServiceRequestToken kerberosServiceRequestToken = new KerberosServiceRequestToken(kerberosTicket); kerberosServiceRequestToken.setDetails(authenticationRequest.getDetails()); diff --git a/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/NiFiRegistryTestApiApplication.java b/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/NiFiRegistryTestApiApplication.java index e55fb210d..04514dd97 100644 --- a/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/NiFiRegistryTestApiApplication.java +++ b/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/NiFiRegistryTestApiApplication.java @@ -18,7 +18,7 @@ import org.apache.nifi.registry.db.DataSourceFactory; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.web.support.SpringBootServletInitializer; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.FilterType; diff --git a/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/SecureLdapTestApiApplication.java b/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/SecureLdapTestApiApplication.java index fea83493e..74d0730ff 100644 --- a/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/SecureLdapTestApiApplication.java +++ b/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/SecureLdapTestApiApplication.java @@ -19,7 +19,7 @@ import org.apache.nifi.registry.db.DataSourceFactory; import org.apache.nifi.registry.security.authorization.AuthorizerFactory; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.web.support.SpringBootServletInitializer; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.FilterType; diff --git a/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/web/api/IntegrationTestBase.java b/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/web/api/IntegrationTestBase.java index e1d396e90..9f3d4397a 100644 --- a/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/web/api/IntegrationTestBase.java +++ b/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/web/api/IntegrationTestBase.java @@ -19,16 +19,16 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider; import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector; import org.apache.nifi.registry.client.NiFiRegistryClientConfig; import org.apache.nifi.registry.properties.NiFiRegistryProperties; import org.glassfish.jersey.client.ClientConfig; +import org.glassfish.jersey.jackson.internal.jackson.jaxrs.json.JacksonJaxbJsonProvider; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.context.embedded.LocalServerPort; -import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.context.annotation.Bean; import javax.annotation.PostConstruct; @@ -46,7 +46,7 @@ */ public abstract class IntegrationTestBase { - private static final String CONTEXT_PATH = "/nifi-registry-api-test"; + private static final String CONTEXT_PATH = "/nifi-registry-api"; @TestConfiguration public static class TestConfigurationClass { @@ -62,8 +62,8 @@ public static class TestConfigurationClass { private NiFiRegistryProperties testProperties; @Bean - public JettyEmbeddedServletContainerFactory jettyEmbeddedServletContainerFactory() { - JettyEmbeddedServletContainerFactory jettyContainerFactory = new JettyEmbeddedServletContainerFactory(); + public JettyServletWebServerFactory jettyEmbeddedServletContainerFactory() { + JettyServletWebServerFactory jettyContainerFactory = new JettyServletWebServerFactory(); jettyContainerFactory.setContextPath(CONTEXT_PATH); return jettyContainerFactory; } @@ -125,11 +125,7 @@ String createURL(String relativeResourcePath) { throw new IllegalArgumentException("Resource path cannot be null"); } - final boolean isSecure = this.properties.getSslPort() != null; - final String protocolSchema = isSecure ? "https" : "http"; - - final StringBuilder baseUriBuilder = new StringBuilder() - .append(protocolSchema).append("://localhost:").append(port).append(CONTEXT_PATH); + final StringBuilder baseUriBuilder = new StringBuilder(createBaseURL()).append(CONTEXT_PATH); if (!relativeResourcePath.startsWith("/")) { baseUriBuilder.append('/'); @@ -139,6 +135,38 @@ String createURL(String relativeResourcePath) { return baseUriBuilder.toString(); } + /** + * Sub-classes can utilize this method to obtain the base-url for a client. + * + * @return a string containing the base url which includes the scheme, host, and port + */ + String createBaseURL() { + final boolean isSecure = this.properties.getSslPort() != null; + final String protocolSchema = isSecure ? "https" : "http"; + + final StringBuilder baseUriBuilder = new StringBuilder() + .append(protocolSchema).append("://localhost:").append(port); + + return baseUriBuilder.toString(); + } + + NiFiRegistryClientConfig createClientConfig(String baseUrl) { + final NiFiRegistryClientConfig.Builder builder = new NiFiRegistryClientConfig.Builder(); + builder.baseUrl(baseUrl); + + if (this.clientConfig != null) { + if (this.clientConfig.getSslContext() != null) { + builder.sslContext(this.clientConfig.getSslContext()); + } + + if (this.clientConfig.getHostnameVerifier() != null) { + builder.hostnameVerifier(this.clientConfig.getHostnameVerifier()); + } + } + + return builder.build(); + } + /** * A helper method for loading NiFiRegistryProperties by reading *.properties files from disk. * diff --git a/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/web/api/SecureNiFiRegistryClientIT.java b/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/web/api/SecureNiFiRegistryClientIT.java new file mode 100644 index 000000000..45c32c0d4 --- /dev/null +++ b/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/web/api/SecureNiFiRegistryClientIT.java @@ -0,0 +1,163 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.registry.web.api; + +import org.apache.nifi.registry.NiFiRegistryTestApiApplication; +import org.apache.nifi.registry.bucket.Bucket; +import org.apache.nifi.registry.client.BucketClient; +import org.apache.nifi.registry.client.FlowClient; +import org.apache.nifi.registry.client.FlowSnapshotClient; +import org.apache.nifi.registry.client.NiFiRegistryClient; +import org.apache.nifi.registry.client.NiFiRegistryClientConfig; +import org.apache.nifi.registry.client.NiFiRegistryException; +import org.apache.nifi.registry.client.UserClient; +import org.apache.nifi.registry.client.impl.JerseyNiFiRegistryClient; +import org.apache.nifi.registry.flow.VersionedFlow; +import org.apache.nifi.registry.flow.VersionedFlowSnapshot; +import org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata; +import org.apache.nifi.registry.flow.VersionedProcessGroup; +import org.apache.nifi.registry.model.authorization.AccessStatus; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Import; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.junit4.SpringRunner; + +import java.io.IOException; +import java.util.List; + +@RunWith(SpringRunner.class) +@SpringBootTest( + classes = NiFiRegistryTestApiApplication.class, + webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + properties = "spring.profiles.include=ITSecureFile") +@Import(SecureITClientConfiguration.class) +@Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:db/clearDB.sql") +public class SecureNiFiRegistryClientIT extends IntegrationTestBase { + + static final Logger LOGGER = LoggerFactory.getLogger(SecureNiFiRegistryClientIT.class); + + private NiFiRegistryClient client; + + @Before + public void setup() { + final String baseUrl = createBaseURL(); + LOGGER.info("Using base url = " + baseUrl); + + final NiFiRegistryClientConfig clientConfig = createClientConfig(baseUrl); + Assert.assertNotNull(clientConfig); + + final NiFiRegistryClient client = new JerseyNiFiRegistryClient.Builder() + .config(clientConfig) + .build(); + Assert.assertNotNull(client); + this.client = client; + } + + @After + public void teardown() { + try { + client.close(); + } catch (Exception e) { + + } + } + + @Test + public void testGetAccessStatus() throws IOException, NiFiRegistryException { + final UserClient userClient = client.getUserClient(); + final AccessStatus status = userClient.getAccessStatus(); + Assert.assertEquals("CN=user1, OU=nifi", status.getIdentity()); + Assert.assertEquals("ACTIVE", status.getStatus()); + } + + @Test + public void testCrudOperations() throws IOException, NiFiRegistryException { + final Bucket bucket = new Bucket(); + bucket.setName("Bucket 1"); + bucket.setDescription("This is bucket 1"); + + final BucketClient bucketClient = client.getBucketClient(); + final Bucket createdBucket = bucketClient.create(bucket); + Assert.assertNotNull(createdBucket); + Assert.assertNotNull(createdBucket.getIdentifier()); + + final List buckets = bucketClient.getAll(); + Assert.assertEquals(1, buckets.size()); + + final VersionedFlow flow = new VersionedFlow(); + flow.setBucketIdentifier(createdBucket.getIdentifier()); + flow.setName("Flow 1"); + + final FlowClient flowClient = client.getFlowClient(); + final VersionedFlow createdFlow = flowClient.create(flow); + Assert.assertNotNull(createdFlow); + Assert.assertNotNull(createdFlow.getIdentifier()); + + final VersionedFlowSnapshotMetadata snapshotMetadata = new VersionedFlowSnapshotMetadata(); + snapshotMetadata.setBucketIdentifier(createdFlow.getBucketIdentifier()); + snapshotMetadata.setFlowIdentifier(createdFlow.getIdentifier()); + snapshotMetadata.setVersion(1); + snapshotMetadata.setComments("This is snapshot #1"); + + final VersionedProcessGroup rootProcessGroup = new VersionedProcessGroup(); + rootProcessGroup.setIdentifier("root-pg"); + rootProcessGroup.setName("Root Process Group"); + + final VersionedFlowSnapshot snapshot = new VersionedFlowSnapshot(); + snapshot.setSnapshotMetadata(snapshotMetadata); + snapshot.setFlowContents(rootProcessGroup); + + final FlowSnapshotClient snapshotClient = client.getFlowSnapshotClient(); + final VersionedFlowSnapshot createdSnapshot = snapshotClient.create(snapshot); + Assert.assertNotNull(createdSnapshot); + Assert.assertEquals("CN=user1, OU=nifi", createdSnapshot.getSnapshotMetadata().getAuthor()); + } + + @Test + public void testGetAccessStatusWithProxiedEntity() throws IOException, NiFiRegistryException { + final String proxiedEntity = "user2"; + final UserClient userClient = client.getUserClient(proxiedEntity); + final AccessStatus status = userClient.getAccessStatus(); + Assert.assertEquals("user2", status.getIdentity()); + Assert.assertEquals("ACTIVE", status.getStatus()); + } + + @Test + public void testCreatedBucketWithProxiedEntity() throws IOException, NiFiRegistryException { + final String proxiedEntity = "user2"; + final BucketClient bucketClient = client.getBucketClient(proxiedEntity); + + final Bucket bucket = new Bucket(); + bucket.setName("Bucket 1"); + bucket.setDescription("This is bucket 1"); + + try { + bucketClient.create(bucket); + Assert.fail("Shouldn't have been able to create a bucket"); + } catch (Exception e) { + + } + } + +} diff --git a/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/web/api/UnsecuredNiFiRegistryClientIT.java b/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/web/api/UnsecuredNiFiRegistryClientIT.java new file mode 100644 index 000000000..e43bbdd26 --- /dev/null +++ b/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/web/api/UnsecuredNiFiRegistryClientIT.java @@ -0,0 +1,349 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.registry.web.api; + +import org.apache.nifi.registry.bucket.Bucket; +import org.apache.nifi.registry.bucket.BucketItem; +import org.apache.nifi.registry.client.BucketClient; +import org.apache.nifi.registry.client.FlowClient; +import org.apache.nifi.registry.client.FlowSnapshotClient; +import org.apache.nifi.registry.client.ItemsClient; +import org.apache.nifi.registry.client.NiFiRegistryClient; +import org.apache.nifi.registry.client.NiFiRegistryClientConfig; +import org.apache.nifi.registry.client.NiFiRegistryException; +import org.apache.nifi.registry.client.UserClient; +import org.apache.nifi.registry.client.impl.JerseyNiFiRegistryClient; +import org.apache.nifi.registry.field.Fields; +import org.apache.nifi.registry.flow.VersionedFlow; +import org.apache.nifi.registry.flow.VersionedFlowSnapshot; +import org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata; +import org.apache.nifi.registry.flow.VersionedProcessGroup; +import org.apache.nifi.registry.flow.VersionedProcessor; +import org.apache.nifi.registry.model.authorization.AccessStatus; +import org.apache.nifi.registry.params.SortOrder; +import org.apache.nifi.registry.params.SortParameter; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Test all basic functionality of JerseyNiFiRegistryClient. + */ +public class UnsecuredNiFiRegistryClientIT extends UnsecuredITBase { + + static final Logger LOGGER = LoggerFactory.getLogger(UnsecuredNiFiRegistryClientIT.class); + + private NiFiRegistryClient client; + + @Before + public void setup() { + final String baseUrl = createBaseURL(); + LOGGER.info("Using base url = " + baseUrl); + + final NiFiRegistryClientConfig clientConfig = new NiFiRegistryClientConfig.Builder() + .baseUrl(baseUrl) + .build(); + + Assert.assertNotNull(clientConfig); + + final NiFiRegistryClient client = new JerseyNiFiRegistryClient.Builder() + .config(clientConfig) + .build(); + + Assert.assertNotNull(client); + this.client = client; + } + + @After + public void teardown() { + try { + client.close(); + } catch (Exception e) { + + } + } + + @Test + public void testUserClient() { + final UserClient userClient = client.getUserClient(); + try { + final AccessStatus status = userClient.getAccessStatus(); + Assert.fail("Should have thrown a 409"); + } catch (Exception e) { + } + } + + @Test + public void testNiFiRegistryClient() throws IOException, NiFiRegistryException { + // ---------------------- TEST BUCKETS --------------------------// + + final BucketClient bucketClient = client.getBucketClient(); + + // create buckets + final int numBuckets = 10; + final List createdBuckets = new ArrayList<>(); + + for (int i=0; i < numBuckets; i++) { + final Bucket createdBucket = createBucket(bucketClient, i); + LOGGER.info("Created bucket # " + i + " with id " + createdBucket.getIdentifier()); + createdBuckets.add(createdBucket); + } + + // get each bucket + for (final Bucket bucket : createdBuckets) { + final Bucket retrievedBucket = bucketClient.get(bucket.getIdentifier()); + Assert.assertNotNull(retrievedBucket); + LOGGER.info("Retrieved bucket " + retrievedBucket.getIdentifier()); + } + + //final Bucket nonExistentBucket = bucketClient.get("does-not-exist"); + //Assert.assertNull(nonExistentBucket); + + // get bucket fields + final Fields bucketFields = bucketClient.getFields(); + Assert.assertNotNull(bucketFields); + LOGGER.info("Retrieved bucket fields, size = " + bucketFields.getFields().size()); + Assert.assertTrue(bucketFields.getFields().size() > 0); + + // get all buckets + final List allBuckets = bucketClient.getAll(); + LOGGER.info("Retrieved buckets, size = " + allBuckets.size()); + Assert.assertEquals(numBuckets, allBuckets.size()); + allBuckets.stream().forEach(b -> System.out.println("Retrieve bucket " + b.getIdentifier())); + + // get all buckets with sorting + final SortParameter sortParam = new SortParameter("created", SortOrder.ASC); + final List allBucketsSorted = bucketClient.getAll(Arrays.asList(sortParam)); + LOGGER.info("Retrieved sorted buckets, size = " + allBucketsSorted.size()); + Assert.assertEquals(numBuckets, allBucketsSorted.size()); + allBucketsSorted.stream().forEach(b -> System.out.println("Retrieve bucket " + b.getIdentifier())); + + // update each bucket + for (final Bucket bucket : createdBuckets) { + final Bucket bucketUpdate = new Bucket(); + bucketUpdate.setIdentifier(bucket.getIdentifier()); + bucketUpdate.setDescription(bucket.getDescription() + " UPDATE"); + + final Bucket updatedBucket = bucketClient.update(bucketUpdate); + Assert.assertNotNull(updatedBucket); + LOGGER.info("Updated bucket " + updatedBucket.getIdentifier()); + } + + // ---------------------- TEST FLOWS --------------------------// + + final FlowClient flowClient = client.getFlowClient(); + + // create flows + final Bucket flowsBucket = createdBuckets.get(0); + + final VersionedFlow flow1 = createFlow(flowClient, flowsBucket, 1); + LOGGER.info("Created flow # 1 with id " + flow1.getIdentifier()); + + final VersionedFlow flow2 = createFlow(flowClient, flowsBucket, 2); + LOGGER.info("Created flow # 2 with id " + flow2.getIdentifier()); + + // get flow + final VersionedFlow retrievedFlow1 = flowClient.get(flowsBucket.getIdentifier(), flow1.getIdentifier()); + Assert.assertNotNull(retrievedFlow1); + LOGGER.info("Retrieved flow # 1 with id " + retrievedFlow1.getIdentifier()); + + final VersionedFlow retrievedFlow2 = flowClient.get(flowsBucket.getIdentifier(), flow2.getIdentifier()); + Assert.assertNotNull(retrievedFlow2); + LOGGER.info("Retrieved flow # 2 with id " + retrievedFlow2.getIdentifier()); + + // update flows + final VersionedFlow flow1Update = new VersionedFlow(); + flow1Update.setIdentifier(flow1.getIdentifier()); + flow1Update.setName(flow1.getName() + " UPDATED"); + + final VersionedFlow updatedFlow1 = flowClient.update(flowsBucket.getIdentifier(), flow1Update); + Assert.assertNotNull(updatedFlow1); + LOGGER.info("Updated flow # 1 with id " + updatedFlow1.getIdentifier()); + + // get flow fields + final Fields flowFields = flowClient.getFields(); + Assert.assertNotNull(flowFields); + LOGGER.info("Retrieved flow fields, size = " + flowFields.getFields().size()); + Assert.assertTrue(flowFields.getFields().size() > 0); + + // get flows in bucket + final List flowsInBucket = flowClient.getByBucket(flowsBucket.getIdentifier()); + Assert.assertNotNull(flowsInBucket); + Assert.assertEquals(2, flowsInBucket.size()); + flowsInBucket.stream().forEach(f -> LOGGER.info("Flow in bucket, flow id " + f.getIdentifier())); + + // get flows in bucket with sorting + final SortParameter flowsSortParam = new SortParameter("created", SortOrder.ASC); + final List flowsInBucketSorted = flowClient.getByBucket(flowsBucket.getIdentifier(), Arrays.asList(flowsSortParam)); + Assert.assertNotNull(flowsInBucketSorted); + Assert.assertEquals(2, flowsInBucketSorted.size()); + + // ---------------------- TEST SNAPSHOTS --------------------------// + + final FlowSnapshotClient snapshotClient = client.getFlowSnapshotClient(); + + // create snapshots + final VersionedFlow snapshotFlow = flow1; + + final VersionedFlowSnapshot snapshot1 = createSnapshot(snapshotClient, snapshotFlow, 1); + LOGGER.info("Created snapshot # 1 with version " + snapshot1.getSnapshotMetadata().getVersion()); + + final VersionedFlowSnapshot snapshot2 = createSnapshot(snapshotClient, snapshotFlow, 2); + LOGGER.info("Created snapshot # 2 with version " + snapshot2.getSnapshotMetadata().getVersion()); + + // get snapshot + final VersionedFlowSnapshot retrievedSnapshot1 = snapshotClient.get(snapshotFlow.getBucketIdentifier(), snapshotFlow.getIdentifier(), 1); + Assert.assertNotNull(retrievedSnapshot1); + Assert.assertFalse(retrievedSnapshot1.isLatest()); + LOGGER.info("Retrieved snapshot # 1 with version " + retrievedSnapshot1.getSnapshotMetadata().getVersion()); + + final VersionedFlowSnapshot retrievedSnapshot2 = snapshotClient.get(snapshotFlow.getBucketIdentifier(), snapshotFlow.getIdentifier(), 2); + Assert.assertNotNull(retrievedSnapshot2); + Assert.assertTrue(retrievedSnapshot2.isLatest()); + LOGGER.info("Retrieved snapshot # 2 with version " + retrievedSnapshot2.getSnapshotMetadata().getVersion()); + + // get latest + final VersionedFlowSnapshot retrievedSnapshotLatest = snapshotClient.getLatest(snapshotFlow.getBucketIdentifier(), snapshotFlow.getIdentifier()); + Assert.assertNotNull(retrievedSnapshotLatest); + Assert.assertEquals(snapshot2.getSnapshotMetadata().getVersion(), retrievedSnapshotLatest.getSnapshotMetadata().getVersion()); + Assert.assertTrue(retrievedSnapshotLatest.isLatest()); + LOGGER.info("Retrieved latest snapshot with version " + retrievedSnapshotLatest.getSnapshotMetadata().getVersion()); + + // get metadata + final List retrievedMetadata = snapshotClient.getSnapshotMetadata(snapshotFlow.getBucketIdentifier(), snapshotFlow.getIdentifier()); + Assert.assertNotNull(retrievedMetadata); + Assert.assertEquals(2, retrievedMetadata.size()); + Assert.assertEquals(2, retrievedMetadata.get(0).getVersion()); + Assert.assertEquals(1, retrievedMetadata.get(1).getVersion()); + retrievedMetadata.stream().forEach(s -> LOGGER.info("Retrieved snapshot metadata " + s.getVersion())); + + // ---------------------- TEST ITEMS --------------------------// + + final ItemsClient itemsClient = client.getItemsClient(); + + // get fields + final Fields itemFields = itemsClient.getFields(); + Assert.assertNotNull(itemFields.getFields()); + Assert.assertTrue(itemFields.getFields().size() > 0); + + // get all items + final List allItems = itemsClient.getAll(); + Assert.assertEquals(2, allItems.size()); + allItems.stream().forEach(i -> LOGGER.info("All items, item " + i.getIdentifier())); + + // get all items with sorting + final SortParameter itemsSortParam = new SortParameter("created", SortOrder.ASC); + final List allItemsSorted = itemsClient.getAll(Arrays.asList(itemsSortParam)); + Assert.assertEquals(2, allItemsSorted.size()); + + // get items for bucket + final List bucketItems = itemsClient.getByBucket(flowsBucket.getIdentifier()); + Assert.assertEquals(2, bucketItems.size()); + bucketItems.stream().forEach(i -> LOGGER.info("Items in bucket, item " + i.getIdentifier())); + + // get items for bucket with sorting + final List bucketItemsSorted = itemsClient.getByBucket(flowsBucket.getIdentifier(), Arrays.asList(itemsSortParam)); + Assert.assertEquals(2, bucketItemsSorted.size()); + + // ---------------------- DELETE DATA --------------------------// + + final VersionedFlow deletedFlow1 = flowClient.delete(flowsBucket.getIdentifier(), flow1.getIdentifier()); + Assert.assertNotNull(deletedFlow1); + LOGGER.info("Deleted flow " + deletedFlow1.getIdentifier()); + + final VersionedFlow deletedFlow2 = flowClient.delete(flowsBucket.getIdentifier(), flow2.getIdentifier()); + Assert.assertNotNull(deletedFlow2); + LOGGER.info("Deleted flow " + deletedFlow2.getIdentifier()); + + // delete each bucket + for (final Bucket bucket : createdBuckets) { + final Bucket deletedBucket = bucketClient.delete(bucket.getIdentifier()); + Assert.assertNotNull(deletedBucket); + LOGGER.info("Deleted bucket " + deletedBucket.getIdentifier()); + } + Assert.assertEquals(0, bucketClient.getAll().size()); + + LOGGER.info("!!! SUCCESS !!!"); + + } + + private static Bucket createBucket(BucketClient bucketClient, int num) throws IOException, NiFiRegistryException { + final Bucket bucket = new Bucket(); + bucket.setName("Bucket #" + num); + bucket.setDescription("This is bucket #" + num); + return bucketClient.create(bucket); + } + + private static VersionedFlow createFlow(FlowClient client, Bucket bucket, int num) throws IOException, NiFiRegistryException { + final VersionedFlow versionedFlow = new VersionedFlow(); + versionedFlow.setName(bucket.getName() + " Flow #" + num); + versionedFlow.setDescription("This is " + bucket.getName() + " flow #" + num); + versionedFlow.setBucketIdentifier(bucket.getIdentifier()); + return client.create(versionedFlow); + } + + private static VersionedFlowSnapshot createSnapshot(FlowSnapshotClient client, VersionedFlow flow, int num) throws IOException, NiFiRegistryException { + final VersionedFlowSnapshotMetadata snapshotMetadata = new VersionedFlowSnapshotMetadata(); + snapshotMetadata.setBucketIdentifier(flow.getBucketIdentifier()); + snapshotMetadata.setFlowIdentifier(flow.getIdentifier()); + snapshotMetadata.setVersion(num); + snapshotMetadata.setComments("This is snapshot #" + num); + + final VersionedProcessGroup rootProcessGroup = new VersionedProcessGroup(); + rootProcessGroup.setIdentifier("root-pg"); + rootProcessGroup.setName("Root Process Group"); + + final VersionedProcessGroup subProcessGroup = new VersionedProcessGroup(); + subProcessGroup.setIdentifier("sub-pg"); + subProcessGroup.setName("Sub Process Group"); + rootProcessGroup.getProcessGroups().add(subProcessGroup); + + final Map processorProperties = new HashMap<>(); + processorProperties.put("Prop 1", "Val 1"); + processorProperties.put("Prop 2", "Val 2"); + + final VersionedProcessor processor1 = new VersionedProcessor(); + processor1.setIdentifier("p1"); + processor1.setName("Processor 1"); + processor1.setProperties(processorProperties); + + final VersionedProcessor processor2 = new VersionedProcessor(); + processor2.setIdentifier("p2"); + processor2.setName("Processor 2"); + processor2.setProperties(processorProperties); + + subProcessGroup.getProcessors().add(processor1); + subProcessGroup.getProcessors().add(processor2); + + final VersionedFlowSnapshot snapshot = new VersionedFlowSnapshot(); + snapshot.setSnapshotMetadata(snapshotMetadata); + snapshot.setFlowContents(rootProcessGroup); + + return client.create(snapshot); + } + +} diff --git a/pom.xml b/pom.xml index f216bcce8..d0d3a6a8a 100644 --- a/pom.xml +++ b/pom.xml @@ -107,10 +107,11 @@ 2017 1.7.12 9.4.3.v20170317 - 2.0.1 - 2.25.1 - 1.5.7.RELEASE - 4.2.3.RELEASE + 2.1 + 2.26 + 2.9.2 + 2.0.0.M7 + 5.0.0.RELEASE 4.2.0 @@ -149,6 +150,16 @@ true + + spring-milestones + http://repo.spring.io/milestone + + false + + + true + + @@ -234,37 +245,6 @@ javax.ws.rs-api ${jax.rs.api.version} - - org.glassfish.jersey.core - jersey-server - ${jersey.version} - - - org.glassfish.jersey.containers - jersey-container-servlet - ${jersey.version} - - - org.glassfish.jersey.core - jersey-client - ${jersey.version} - - - org.glassfish.jersey.media - jersey-media-json-jackson - ${jersey.version} - - - org.glassfish.jersey.ext - jersey-bean-validation - ${jersey.version} - - - org.glassfish.web - javax.el - - - javax.validation validation-api @@ -280,6 +260,27 @@ javax.el 3.0.1-b08 + + + com.fasterxml.jackson.core + jackson-annotations + ${jackson.version} + + + com.fasterxml.jackson.module + jackson-module-jaxb-annotations + ${jackson.version} + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + + + com.fasterxml.jackson.core + jackson-core + ${jackson.version} + org.apache.commons commons-lang3