You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by mc...@apache.org on 2019/09/03 16:56:33 UTC

[nifi] branch master updated: NIFI-6607: Ensure that when creating ParameterContextUpdateRequestDTO that we populate the AffectedComponentEntities with the most up-to-date version of the component

This is an automated email from the ASF dual-hosted git repository.

mcgilman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/master by this push:
     new 4851e00  NIFI-6607: Ensure that when creating ParameterContextUpdateRequestDTO that we populate the AffectedComponentEntities with the most up-to-date version of the component
4851e00 is described below

commit 4851e00f1da758468984c198b8e9f49a006d5f0c
Author: Mark Payne <ma...@hotmail.com>
AuthorDate: Tue Sep 3 12:15:12 2019 -0400

    NIFI-6607: Ensure that when creating ParameterContextUpdateRequestDTO that we populate the AffectedComponentEntities with the most up-to-date version of the component
    
    This closes #3689
---
 .../org/apache/nifi/web/NiFiServiceFacade.java     |  7 ++++
 .../apache/nifi/web/StandardNiFiServiceFacade.java | 40 ++++++++++++++++++++++
 .../nifi/web/api/ParameterContextResource.java     |  5 +--
 3 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiServiceFacade.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiServiceFacade.java
index f62bec2..a349a39 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiServiceFacade.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiServiceFacade.java
@@ -1574,6 +1574,13 @@ public interface NiFiServiceFacade {
     Set<AffectedComponentEntity> getComponentsAffectedByParameterContextUpdate(ParameterContextDTO parameterContextDto);
 
     /**
+     * Returns an up-to-date representation of the component that is referenced by the given affected component
+     * @param affectedComponent the affected component
+     * @return an up-to-date representation of the affected component
+     */
+    AffectedComponentEntity getUpdatedAffectedComponentEntity(AffectedComponentEntity affectedComponent);
+
+    /**
      * Returns a Set representing all Processors that reference any Parameters and that belong to the group with the given ID
      *
      * @param groupId the id of the process group
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java
index 03cdc31..cbc5ec2 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java
@@ -1195,6 +1195,46 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
     }
 
     @Override
+    public AffectedComponentEntity getUpdatedAffectedComponentEntity(final AffectedComponentEntity affectedComponent) {
+        final AffectedComponentDTO dto = affectedComponent.getComponent();
+        if (dto == null) {
+            return affectedComponent;
+        }
+
+        final String groupId = affectedComponent.getProcessGroup().getId();
+        final ProcessGroup processGroup = processGroupDAO.getProcessGroup(groupId);
+
+        final String componentType = dto.getReferenceType();
+        if (AffectedComponentDTO.COMPONENT_TYPE_CONTROLLER_SERVICE.equals(componentType)) {
+            final ControllerServiceNode serviceNode = processGroup.getControllerService(dto.getId());
+            return dtoFactory.createAffectedComponentEntity(serviceNode, revisionManager);
+        } else if (AffectedComponentDTO.COMPONENT_TYPE_PROCESSOR.equals(componentType)) {
+            final ProcessorNode processorNode = processGroup.getProcessor(dto.getId());
+            return dtoFactory.createAffectedComponentEntity(processorNode, revisionManager);
+        } else if (AffectedComponentDTO.COMPONENT_TYPE_INPUT_PORT.equals(componentType)) {
+            final Port inputPort = processGroup.getInputPort(dto.getId());
+            final PortEntity portEntity = createInputPortEntity(inputPort);
+            return dtoFactory.createAffectedComponentEntity(portEntity, AffectedComponentDTO.COMPONENT_TYPE_INPUT_PORT);
+        } else if (AffectedComponentDTO.COMPONENT_TYPE_OUTPUT_PORT.equals(componentType)) {
+            final Port outputPort = processGroup.getOutputPort(dto.getId());
+            final PortEntity portEntity = createOutputPortEntity(outputPort);
+            return dtoFactory.createAffectedComponentEntity(portEntity, AffectedComponentDTO.COMPONENT_TYPE_OUTPUT_PORT);
+        } else if (AffectedComponentDTO.COMPONENT_TYPE_REMOTE_INPUT_PORT.equals(componentType)) {
+            final RemoteGroupPort remoteGroupPort = processGroup.findRemoteGroupPort(dto.getId());
+            final RemoteProcessGroupEntity rpgEntity = createRemoteGroupEntity(remoteGroupPort.getRemoteProcessGroup(), NiFiUserUtils.getNiFiUser());
+            final RemoteProcessGroupPortDTO remotePortDto = dtoFactory.createRemoteProcessGroupPortDto(remoteGroupPort);
+            return dtoFactory.createAffectedComponentEntity(remotePortDto, AffectedComponentDTO.COMPONENT_TYPE_REMOTE_INPUT_PORT, rpgEntity);
+        } else if (AffectedComponentDTO.COMPONENT_TYPE_REMOTE_OUTPUT_PORT.equals(componentType)) {
+            final RemoteGroupPort remoteGroupPort = processGroup.findRemoteGroupPort(dto.getId());
+            final RemoteProcessGroupEntity rpgEntity = createRemoteGroupEntity(remoteGroupPort.getRemoteProcessGroup(), NiFiUserUtils.getNiFiUser());
+            final RemoteProcessGroupPortDTO remotePortDto = dtoFactory.createRemoteProcessGroupPortDto(remoteGroupPort);
+            return dtoFactory.createAffectedComponentEntity(remotePortDto, AffectedComponentDTO.COMPONENT_TYPE_REMOTE_OUTPUT_PORT, rpgEntity);
+        }
+
+        return affectedComponent;
+    }
+
+    @Override
     public Set<AffectedComponentEntity> getComponentsAffectedByParameterContextUpdate(final ParameterContextDTO parameterContextDto) {
         return getComponentsAffectedByParameterContextUpdate(parameterContextDto, true);
     }
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ParameterContextResource.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ParameterContextResource.java
index 63fcad6..5c8fd6a 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ParameterContextResource.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ParameterContextResource.java
@@ -1155,13 +1155,14 @@ public class ParameterContextResource extends ApplicationResource {
         updateRequestDto.setUpdateSteps(updateSteps);
 
         final ParameterContextEntity initialRequest = asyncRequest.getRequest();
+
+        // The AffectedComponentEntity itself does not evaluate equality based on component information. As a result, we want to de-dupe the entities based on their identifiers.
         final Map<String, AffectedComponentEntity> affectedComponents = new HashMap<>();
         for (final ParameterEntity entity : initialRequest.getComponent().getParameters()) {
             for (final AffectedComponentEntity affectedComponentEntity : entity.getParameter().getReferencingComponents()) {
-                affectedComponents.put(affectedComponentEntity.getId(), affectedComponentEntity);
+                affectedComponents.put(affectedComponentEntity.getId(), serviceFacade.getUpdatedAffectedComponentEntity(affectedComponentEntity));
             }
         }
-
         updateRequestDto.setReferencingComponents(new HashSet<>(affectedComponents.values()));
 
         // Populate the Affected Components