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 0ab1fbccc8 NIFI-10934 Added uniqueness check for Registry Client 
creation
0ab1fbccc8 is described below

commit 0ab1fbccc84c007df5d4ddd7b57af894d6def065
Author: Bence Simon <bsi...@apache.org>
AuthorDate: Fri Dec 2 16:48:22 2022 +0100

    NIFI-10934 Added uniqueness check for Registry Client creation
    
    This closes #6750
    
    Signed-off-by: David Handermann <exceptionfact...@apache.org>
    Co-authored-by: Chris Sampson 
<12159006+chrissamo...@users.noreply.github.com>
---
 .../org/apache/nifi/web/api/ControllerResource.java    | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ControllerResource.java
 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ControllerResource.java
index adb7991716..94b3e07d8a 100644
--- 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ControllerResource.java
+++ 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ControllerResource.java
@@ -37,9 +37,9 @@ import org.apache.nifi.web.api.dto.BulletinDTO;
 import org.apache.nifi.web.api.dto.ClusterDTO;
 import org.apache.nifi.web.api.dto.ControllerServiceDTO;
 import org.apache.nifi.web.api.dto.DocumentedTypeDTO;
+import org.apache.nifi.web.api.dto.FlowRegistryClientDTO;
 import org.apache.nifi.web.api.dto.NodeDTO;
 import org.apache.nifi.web.api.dto.ParameterProviderDTO;
-import org.apache.nifi.web.api.dto.FlowRegistryClientDTO;
 import org.apache.nifi.web.api.dto.PropertyDescriptorDTO;
 import org.apache.nifi.web.api.dto.ReportingTaskDTO;
 import org.apache.nifi.web.api.entity.BulletinEntity;
@@ -48,12 +48,12 @@ import 
org.apache.nifi.web.api.entity.ComponentHistoryEntity;
 import org.apache.nifi.web.api.entity.ControllerConfigurationEntity;
 import org.apache.nifi.web.api.entity.ControllerServiceEntity;
 import org.apache.nifi.web.api.entity.Entity;
+import org.apache.nifi.web.api.entity.FlowRegistryClientEntity;
 import org.apache.nifi.web.api.entity.FlowRegistryClientTypesEntity;
+import org.apache.nifi.web.api.entity.FlowRegistryClientsEntity;
 import org.apache.nifi.web.api.entity.HistoryEntity;
 import org.apache.nifi.web.api.entity.NodeEntity;
 import org.apache.nifi.web.api.entity.ParameterProviderEntity;
-import org.apache.nifi.web.api.entity.FlowRegistryClientEntity;
-import org.apache.nifi.web.api.entity.FlowRegistryClientsEntity;
 import org.apache.nifi.web.api.entity.PropertyDescriptorEntity;
 import org.apache.nifi.web.api.entity.ReportingTaskEntity;
 import org.apache.nifi.web.api.request.ClientIdParameter;
@@ -494,22 +494,26 @@ public class ControllerResource extends 
ApplicationResource {
         preprocessObsoleteRequest(requestFlowRegistryClientEntity);
 
         if (requestFlowRegistryClientEntity == null || 
requestFlowRegistryClientEntity.getComponent() == null) {
-            throw new IllegalArgumentException("Flow registry client details 
must be specified.");
+            throw new IllegalArgumentException("Flow Registry client details 
must be specified.");
         }
 
         if (requestFlowRegistryClientEntity.getRevision() == null
                 || (requestFlowRegistryClientEntity.getRevision().getVersion() 
== null
                 || requestFlowRegistryClientEntity.getRevision().getVersion() 
!= 0)) {
-            throw new IllegalArgumentException("A revision of 0 must be 
specified when creating a new Registry.");
+            throw new IllegalArgumentException("A revision of 0 must be 
specified when creating a new Flow Registry.");
         }
 
         final FlowRegistryClientDTO requestRegistryClient = 
requestFlowRegistryClientEntity.getComponent();
         if (requestRegistryClient.getId() != null) {
-            throw new IllegalArgumentException("Registry ID cannot be 
specified.");
+            throw new IllegalArgumentException("Flow Registry ID cannot be 
specified.");
         }
 
         if (StringUtils.isBlank(requestRegistryClient.getName())) {
-            throw new IllegalArgumentException("Registry name must be 
specified.");
+            throw new IllegalArgumentException("Flow Registry name must be 
specified.");
+        }
+
+        if (serviceFacade.getRegistryClients().stream().anyMatch(rce -> 
requestRegistryClient.getName().equals(rce.getComponent().getName()))) {
+            throw new IllegalArgumentException("A Flow Registry already exists 
with the name " + requestRegistryClient.getName());
         }
 
         if (isReplicateRequest()) {

Reply via email to