From 037d2af302cac0300840c341641818b781bb28e9 Mon Sep 17 00:00:00 2001 From: Matt Gilman Date: Mon, 7 Nov 2016 11:58:27 -0500 Subject: [PATCH 1/2] NIFI-2994: - Setting the default position for remote process groups. --- .../java/org/apache/nifi/remote/StandardRemoteProcessGroup.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/remote/StandardRemoteProcessGroup.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/remote/StandardRemoteProcessGroup.java index 1fd4d3277019..855dab754932 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/remote/StandardRemoteProcessGroup.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/remote/StandardRemoteProcessGroup.java @@ -95,7 +95,7 @@ public class StandardRemoteProcessGroup implements RemoteProcessGroup { private final NiFiProperties nifiProperties; private final AtomicReference name = new AtomicReference<>(); - private final AtomicReference position = new AtomicReference<>(); + private final AtomicReference position = new AtomicReference<>(new Position(0D, 0D)); private final AtomicReference comments = new AtomicReference<>(); private final AtomicReference processGroup; private final AtomicBoolean transmitting = new AtomicBoolean(false); From b5f04bb520775565fefa0661957b9a13b7c85d7a Mon Sep 17 00:00:00 2001 From: Matt Gilman Date: Thu, 22 Dec 2016 11:08:47 -0500 Subject: [PATCH 2/2] NIFI-2994: - Adding explicit checks for the x and y coordinate when creating and update components. --- .../nifi/web/api/ConnectionResource.java | 11 +++ .../apache/nifi/web/api/FunnelResource.java | 8 +++ .../nifi/web/api/InputPortResource.java | 8 +++ .../apache/nifi/web/api/LabelResource.java | 8 +++ .../nifi/web/api/OutputPortResource.java | 8 +++ .../nifi/web/api/ProcessGroupResource.java | 67 +++++++++++++++++++ .../nifi/web/api/ProcessorResource.java | 8 +++ .../web/api/RemoteProcessGroupResource.java | 8 +++ 8 files changed, 126 insertions(+) diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ConnectionResource.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ConnectionResource.java index cf6aada37eaa..4527e87b6e72 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ConnectionResource.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ConnectionResource.java @@ -33,6 +33,7 @@ import org.apache.nifi.web.NiFiServiceFacade; import org.apache.nifi.web.Revision; import org.apache.nifi.web.api.dto.ConnectionDTO; +import org.apache.nifi.web.api.dto.PositionDTO; import org.apache.nifi.web.api.entity.ConnectionEntity; import org.apache.nifi.web.api.request.ClientIdParameter; import org.apache.nifi.web.api.request.LongParameter; @@ -51,6 +52,7 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import java.util.List; import java.util.Set; /** @@ -214,6 +216,15 @@ public Response updateConnection( } } + final List proposedBends = requestConnection.getBends(); + if (proposedBends != null) { + for (final PositionDTO proposedBend : proposedBends) { + if (proposedBend.getX() == null || proposedBend.getY() == null) { + throw new IllegalArgumentException("The x and y coordinate of the each bend must be specified."); + } + } + } + if (isReplicateRequest()) { return replicate(HttpMethod.PUT, requestConnectionEntity); } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FunnelResource.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FunnelResource.java index a6747d8a7eaa..dcb35fa66d40 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FunnelResource.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FunnelResource.java @@ -30,6 +30,7 @@ import org.apache.nifi.web.NiFiServiceFacade; import org.apache.nifi.web.Revision; import org.apache.nifi.web.api.dto.FunnelDTO; +import org.apache.nifi.web.api.dto.PositionDTO; import org.apache.nifi.web.api.entity.FunnelEntity; import org.apache.nifi.web.api.request.ClientIdParameter; import org.apache.nifi.web.api.request.LongParameter; @@ -192,6 +193,13 @@ public Response updateFunnel( + "funnel id of the requested resource (%s).", requestFunnelDTO.getId(), id)); } + final PositionDTO proposedPosition = requestFunnelDTO.getPosition(); + if (proposedPosition != null) { + if (proposedPosition.getX() == null || proposedPosition.getY() == null) { + throw new IllegalArgumentException("The x and y coordinate of the proposed position must be specified."); + } + } + if (isReplicateRequest()) { return replicate(HttpMethod.PUT, requestFunnelEntity); } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/InputPortResource.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/InputPortResource.java index a295fc6155a3..65e871ee43e4 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/InputPortResource.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/InputPortResource.java @@ -30,6 +30,7 @@ import org.apache.nifi.web.NiFiServiceFacade; import org.apache.nifi.web.Revision; import org.apache.nifi.web.api.dto.PortDTO; +import org.apache.nifi.web.api.dto.PositionDTO; import org.apache.nifi.web.api.entity.PortEntity; import org.apache.nifi.web.api.request.ClientIdParameter; import org.apache.nifi.web.api.request.LongParameter; @@ -192,6 +193,13 @@ public Response updateInputPort( + "input port id of the requested resource (%s).", requestPortDTO.getId(), id)); } + final PositionDTO proposedPosition = requestPortDTO.getPosition(); + if (proposedPosition != null) { + if (proposedPosition.getX() == null || proposedPosition.getY() == null) { + throw new IllegalArgumentException("The x and y coordinate of the proposed position must be specified."); + } + } + if (isReplicateRequest()) { return replicate(HttpMethod.PUT, requestPortEntity); } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/LabelResource.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/LabelResource.java index 78c728757437..34f62f5a6940 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/LabelResource.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/LabelResource.java @@ -30,6 +30,7 @@ import org.apache.nifi.web.NiFiServiceFacade; import org.apache.nifi.web.Revision; import org.apache.nifi.web.api.dto.LabelDTO; +import org.apache.nifi.web.api.dto.PositionDTO; import org.apache.nifi.web.api.entity.LabelEntity; import org.apache.nifi.web.api.request.ClientIdParameter; import org.apache.nifi.web.api.request.LongParameter; @@ -192,6 +193,13 @@ public Response updateLabel( + "label id of the requested resource (%s).", requestLabelDTO.getId(), id)); } + final PositionDTO proposedPosition = requestLabelDTO.getPosition(); + if (proposedPosition != null) { + if (proposedPosition.getX() == null || proposedPosition.getY() == null) { + throw new IllegalArgumentException("The x and y coordinate of the proposed position must be specified."); + } + } + if (isReplicateRequest()) { return replicate(HttpMethod.PUT, requestLabelEntity); } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/OutputPortResource.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/OutputPortResource.java index 4070415552db..442473ccf0e8 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/OutputPortResource.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/OutputPortResource.java @@ -30,6 +30,7 @@ import org.apache.nifi.web.NiFiServiceFacade; import org.apache.nifi.web.Revision; import org.apache.nifi.web.api.dto.PortDTO; +import org.apache.nifi.web.api.dto.PositionDTO; import org.apache.nifi.web.api.entity.PortEntity; import org.apache.nifi.web.api.request.ClientIdParameter; import org.apache.nifi.web.api.request.LongParameter; @@ -192,6 +193,13 @@ public Response updateOutputPort( + "output port id of the requested resource (%s).", requestPortDTO.getId(), id)); } + final PositionDTO proposedPosition = requestPortDTO.getPosition(); + if (proposedPosition != null) { + if (proposedPosition.getX() == null || proposedPosition.getY() == null) { + throw new IllegalArgumentException("The x and y coordinate of the proposed position must be specified."); + } + } + if (isReplicateRequest()) { return replicate(HttpMethod.PUT, requestPortEntity); } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ProcessGroupResource.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ProcessGroupResource.java index df9b476bed77..4a8f8a927d24 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ProcessGroupResource.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ProcessGroupResource.java @@ -43,6 +43,7 @@ import org.apache.nifi.web.Revision; import org.apache.nifi.web.api.dto.ConnectionDTO; import org.apache.nifi.web.api.dto.ControllerServiceDTO; +import org.apache.nifi.web.api.dto.PositionDTO; import org.apache.nifi.web.api.dto.ProcessGroupDTO; import org.apache.nifi.web.api.dto.ProcessorConfigDTO; import org.apache.nifi.web.api.dto.ProcessorDTO; @@ -101,6 +102,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; @@ -287,6 +289,13 @@ public Response updateProcessGroup( + "not equal the process group id of the requested resource (%s).", requestProcessGroupDTO.getId(), id)); } + final PositionDTO proposedPosition = requestProcessGroupDTO.getPosition(); + if (proposedPosition != null) { + if (proposedPosition.getX() == null || proposedPosition.getY() == null) { + throw new IllegalArgumentException("The x and y coordinate of the proposed position must be specified."); + } + } + if (isReplicateRequest()) { return replicate(HttpMethod.PUT, requestProcessGroupEntity); } @@ -445,6 +454,13 @@ public Response createProcessGroup( throw new IllegalArgumentException("Process group ID cannot be specified."); } + final PositionDTO proposedPosition = requestProcessGroupEntity.getComponent().getPosition(); + if (proposedPosition != null) { + if (proposedPosition.getX() == null || proposedPosition.getY() == null) { + throw new IllegalArgumentException("The x and y coordinate of the proposed position must be specified."); + } + } + if (requestProcessGroupEntity.getComponent().getParentGroupId() != null && !groupId.equals(requestProcessGroupEntity.getComponent().getParentGroupId())) { throw new IllegalArgumentException(String.format("If specified, the parent process group id %s must be the same as specified in the URI %s", requestProcessGroupEntity.getComponent().getParentGroupId(), groupId)); @@ -602,6 +618,13 @@ public Response createProcessor( throw new IllegalArgumentException("The type of processor to create must be specified."); } + final PositionDTO proposedPosition = requestProcessor.getPosition(); + if (proposedPosition != null) { + if (proposedPosition.getX() == null || proposedPosition.getY() == null) { + throw new IllegalArgumentException("The x and y coordinate of the proposed position must be specified."); + } + } + if (requestProcessor.getParentGroupId() != null && !groupId.equals(requestProcessor.getParentGroupId())) { throw new IllegalArgumentException(String.format("If specified, the parent process group id %s must be the same as specified in the URI %s", requestProcessor.getParentGroupId(), groupId)); @@ -760,6 +783,13 @@ public Response createInputPort( throw new IllegalArgumentException("Input port ID cannot be specified."); } + final PositionDTO proposedPosition = requestPortEntity.getComponent().getPosition(); + if (proposedPosition != null) { + if (proposedPosition.getX() == null || proposedPosition.getY() == null) { + throw new IllegalArgumentException("The x and y coordinate of the proposed position must be specified."); + } + } + if (requestPortEntity.getComponent().getParentGroupId() != null && !groupId.equals(requestPortEntity.getComponent().getParentGroupId())) { throw new IllegalArgumentException(String.format("If specified, the parent process group id %s must be the same as specified in the URI %s", requestPortEntity.getComponent().getParentGroupId(), groupId)); @@ -901,6 +931,13 @@ public Response createOutputPort( throw new IllegalArgumentException("Output port ID cannot be specified."); } + final PositionDTO proposedPosition = requestPortEntity.getComponent().getPosition(); + if (proposedPosition != null) { + if (proposedPosition.getX() == null || proposedPosition.getY() == null) { + throw new IllegalArgumentException("The x and y coordinate of the proposed position must be specified."); + } + } + if (requestPortEntity.getComponent().getParentGroupId() != null && !groupId.equals(requestPortEntity.getComponent().getParentGroupId())) { throw new IllegalArgumentException(String.format("If specified, the parent process group id %s must be the same as specified in the URI %s", requestPortEntity.getComponent().getParentGroupId(), groupId)); @@ -1043,6 +1080,13 @@ public Response createFunnel( throw new IllegalArgumentException("Funnel ID cannot be specified."); } + final PositionDTO proposedPosition = requestFunnelEntity.getComponent().getPosition(); + if (proposedPosition != null) { + if (proposedPosition.getX() == null || proposedPosition.getY() == null) { + throw new IllegalArgumentException("The x and y coordinate of the proposed position must be specified."); + } + } + if (requestFunnelEntity.getComponent().getParentGroupId() != null && !groupId.equals(requestFunnelEntity.getComponent().getParentGroupId())) { throw new IllegalArgumentException(String.format("If specified, the parent process group id %s must be the same as specified in the URI %s", requestFunnelEntity.getComponent().getParentGroupId(), groupId)); @@ -1185,6 +1229,13 @@ public Response createLabel( throw new IllegalArgumentException("Label ID cannot be specified."); } + final PositionDTO proposedPosition = requestLabelEntity.getComponent().getPosition(); + if (proposedPosition != null) { + if (proposedPosition.getX() == null || proposedPosition.getY() == null) { + throw new IllegalArgumentException("The x and y coordinate of the proposed position must be specified."); + } + } + if (requestLabelEntity.getComponent().getParentGroupId() != null && !groupId.equals(requestLabelEntity.getComponent().getParentGroupId())) { throw new IllegalArgumentException(String.format("If specified, the parent process group id %s must be the same as specified in the URI %s", requestLabelEntity.getComponent().getParentGroupId(), groupId)); @@ -1334,6 +1385,13 @@ public Response createRemoteProcessGroup( throw new IllegalArgumentException("The URI of the process group must be specified."); } + final PositionDTO proposedPosition = requestRemoteProcessGroupDTO.getPosition(); + if (proposedPosition != null) { + if (proposedPosition.getX() == null || proposedPosition.getY() == null) { + throw new IllegalArgumentException("The x and y coordinate of the proposed position must be specified."); + } + } + if (requestRemoteProcessGroupDTO.getParentGroupId() != null && !groupId.equals(requestRemoteProcessGroupDTO.getParentGroupId())) { throw new IllegalArgumentException(String.format("If specified, the parent process group id %s must be the same as specified in the URI %s", requestRemoteProcessGroupDTO.getParentGroupId(), groupId)); @@ -1493,6 +1551,15 @@ public Response createConnection( throw new IllegalArgumentException("Connection ID cannot be specified."); } + final List proposedBends = requestConnectionEntity.getComponent().getBends(); + if (proposedBends != null) { + for (final PositionDTO proposedBend : proposedBends) { + if (proposedBend.getX() == null || proposedBend.getY() == null) { + throw new IllegalArgumentException("The x and y coordinate of the each bend must be specified."); + } + } + } + if (requestConnectionEntity.getComponent().getParentGroupId() != null && !groupId.equals(requestConnectionEntity.getComponent().getParentGroupId())) { throw new IllegalArgumentException(String.format("If specified, the parent process group id %s must be the same as specified in the URI %s", requestConnectionEntity.getComponent().getParentGroupId(), groupId)); diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ProcessorResource.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ProcessorResource.java index 9bd02d48492e..d17f7ac8ed5d 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ProcessorResource.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ProcessorResource.java @@ -36,6 +36,7 @@ import org.apache.nifi.web.Revision; import org.apache.nifi.web.UiExtensionType; import org.apache.nifi.web.api.dto.ComponentStateDTO; +import org.apache.nifi.web.api.dto.PositionDTO; import org.apache.nifi.web.api.dto.ProcessorConfigDTO; import org.apache.nifi.web.api.dto.ProcessorDTO; import org.apache.nifi.web.api.dto.PropertyDescriptorDTO; @@ -435,6 +436,13 @@ public Response updateProcessor( + "not equal the processor id of the requested resource (%s).", requestProcessorDTO.getId(), id)); } + final PositionDTO proposedPosition = requestProcessorDTO.getPosition(); + if (proposedPosition != null) { + if (proposedPosition.getX() == null || proposedPosition.getY() == null) { + throw new IllegalArgumentException("The x and y coordinate of the proposed position must be specified."); + } + } + if (isReplicateRequest()) { return replicate(HttpMethod.PUT, requestProcessorEntity); } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/RemoteProcessGroupResource.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/RemoteProcessGroupResource.java index 5380d51cd3d5..3aef47efcf7f 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/RemoteProcessGroupResource.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/RemoteProcessGroupResource.java @@ -29,6 +29,7 @@ import org.apache.nifi.authorization.user.NiFiUserUtils; import org.apache.nifi.web.NiFiServiceFacade; import org.apache.nifi.web.Revision; +import org.apache.nifi.web.api.dto.PositionDTO; import org.apache.nifi.web.api.dto.RemoteProcessGroupDTO; import org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO; import org.apache.nifi.web.api.dto.RevisionDTO; @@ -471,6 +472,13 @@ public Response updateRemoteProcessGroup( + "remote process group id of the requested resource (%s).", requestRemoteProcessGroup.getId(), id)); } + final PositionDTO proposedPosition = requestRemoteProcessGroup.getPosition(); + if (proposedPosition != null) { + if (proposedPosition.getX() == null || proposedPosition.getY() == null) { + throw new IllegalArgumentException("The x and y coordinate of the proposed position must be specified."); + } + } + if (isReplicateRequest()) { return replicate(HttpMethod.PUT, requestRemoteProcessGroupEntity); }