From e65aad8fe61a806540d13a91e06bfdf22c51bf2f Mon Sep 17 00:00:00 2001 From: Matt Gilman Date: Mon, 7 Nov 2016 11:58:27 -0500 Subject: [PATCH] NIFI-2994: - Setting the default position for remote process groups. Signed-off-by: Yolanda M. Davis This closes #1303 --- .../remote/StandardRemoteProcessGroup.java | 2 +- .../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 +++ 9 files changed, 127 insertions(+), 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 1fd4d32770..855dab7549 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); 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 cf6aada37e..4527e87b6e 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.connectable.ConnectableType; 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.QueryParam; 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 class ConnectionResource extends ApplicationResource { } } + 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 a6747d8a7e..dcb35fa66d 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.authorization.user.NiFiUserUtils; 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 class FunnelResource extends ApplicationResource { + "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 a295fc6155..65e871ee43 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.authorization.user.NiFiUserUtils; 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 class InputPortResource extends ApplicationResource { + "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 78c7287574..34f62f5a69 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.authorization.user.NiFiUserUtils; 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 class LabelResource extends ApplicationResource { + "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 4070415552..442473ccf0 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.authorization.user.NiFiUserUtils; 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 class OutputPortResource extends ApplicationResource { + "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 df9b476bed..4a8f8a927d 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.ResourceNotFoundException; 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.io.InputStream; 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 class ProcessGroupResource extends ApplicationResource { + "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 class ProcessGroupResource extends ApplicationResource { 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 class ProcessGroupResource extends ApplicationResource { 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 class ProcessGroupResource extends ApplicationResource { 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 class ProcessGroupResource extends ApplicationResource { 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 class ProcessGroupResource extends ApplicationResource { 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 class ProcessGroupResource extends ApplicationResource { 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 class ProcessGroupResource extends ApplicationResource { 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 class ProcessGroupResource extends ApplicationResource { 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 9bd02d4849..d17f7ac8ed 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.NiFiServiceFacade; 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 class ProcessorResource extends ApplicationResource { + "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 5380d51cd3..3aef47efcf 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.resource.Authorizable; 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 class RemoteProcessGroupResource extends ApplicationResource { + "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); }