You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by pv...@apache.org on 2019/11/13 09:29:14 UTC
[nifi] branch master updated: NIFI-6581 Add optional x/y
coordinates to CLI pg-import command
This is an automated email from the ASF dual-hosted git repository.
pvillard 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 d6c645a NIFI-6581 Add optional x/y coordinates to CLI pg-import command
d6c645a is described below
commit d6c645a9e23e119c335598339ee1ecf979fbce2e
Author: Bryan Bende <bb...@apache.org>
AuthorDate: Thu Aug 22 14:52:21 2019 -0400
NIFI-6581 Add optional x/y coordinates to CLI pg-import command
Signed-off-by: Pierre Villard <pi...@gmail.com>
This closes #3666.
---
.../toolkit/cli/impl/command/CommandOption.java | 3 ++
.../toolkit/cli/impl/command/nifi/pg/PGImport.java | 32 ++++++++++++++++++----
2 files changed, 30 insertions(+), 5 deletions(-)
diff --git a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/CommandOption.java b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/CommandOption.java
index 79d77a0..623d555 100644
--- a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/CommandOption.java
+++ b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/CommandOption.java
@@ -82,6 +82,9 @@ public enum CommandOption {
PG_VAR_NAME("var", "varName", "The name of a variable", true),
PG_VAR_VALUE("val", "varValue", "The value of a variable", true),
+ POS_X("px", "posX", "The x coordinate of a position", true),
+ POS_Y("py", "posY", "The y coordinate of a position", true),
+
// NiFi - Controller Services
CS_ID("cs", "controllerServiceId", "The id of a controller service", true),
diff --git a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/nifi/pg/PGImport.java b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/nifi/pg/PGImport.java
index b17fba1..8baf120 100644
--- a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/nifi/pg/PGImport.java
+++ b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/nifi/pg/PGImport.java
@@ -51,7 +51,9 @@ public class PGImport extends AbstractNiFiCommand<StringResult> {
public String getDescription() {
return "Creates a new process group by importing a versioned flow from a registry. If no process group id is " +
"specified, then the created process group will be placed in the root group. If only one registry client " +
- "exists in NiFi, then it does not need to be specified and will be automatically selected.";
+ "exists in NiFi, then it does not need to be specified and will be automatically selected. The x and y " +
+ "coordinates for the position of the imported process group may be optionally specified. If left blank, " +
+ "the position will automatically be selected to avoid overlapping with existing process groups.";
}
@Override
@@ -61,6 +63,8 @@ public class PGImport extends AbstractNiFiCommand<StringResult> {
addOption(CommandOption.BUCKET_ID.createOption());
addOption(CommandOption.FLOW_ID.createOption());
addOption(CommandOption.FLOW_VERSION.createOption());
+ addOption(CommandOption.POS_X.createOption());
+ addOption(CommandOption.POS_Y.createOption());
}
@Override
@@ -71,6 +75,20 @@ public class PGImport extends AbstractNiFiCommand<StringResult> {
final String flowId = getRequiredArg(properties, CommandOption.FLOW_ID);
final Integer flowVersion = getRequiredIntArg(properties, CommandOption.FLOW_VERSION);
+ final String posXStr = getArg(properties, CommandOption.POS_X);
+ final String posYStr = getArg(properties, CommandOption.POS_Y);
+
+ final boolean posXExists = StringUtils.isNotBlank(posXStr);
+ final boolean posYExists = StringUtils.isNotBlank(posYStr);
+
+ if ((posXExists && !posYExists)) {
+ throw new IllegalArgumentException("Missing Y position - Please specify both X and Y, or specify neither");
+ }
+
+ if ((posYExists && !posXExists)) {
+ throw new IllegalArgumentException("Missing X position - Please specify both X and Y, or specify neither");
+ }
+
// if a registry client is specified use it, otherwise see if there is only one available and use that,
// if more than one is available then throw an exception because we don't know which one to use
String registryId = getArg(properties, CommandOption.REGISTRY_CLIENT_ID);
@@ -103,11 +121,15 @@ public class PGImport extends AbstractNiFiCommand<StringResult> {
versionControlInfo.setFlowId(flowId);
versionControlInfo.setVersion(flowVersion);
- final ProcessGroupBox pgBox = client.getFlowClient().getSuggestedProcessGroupCoordinates(parentPgId);
-
final PositionDTO posDto = new PositionDTO();
- posDto.setX(Integer.valueOf(pgBox.getX()).doubleValue());
- posDto.setY(Integer.valueOf(pgBox.getY()).doubleValue());
+ if (posXExists && posYExists) {
+ posDto.setX(Double.parseDouble(posXStr));
+ posDto.setY(Double.parseDouble(posYStr));
+ } else {
+ final ProcessGroupBox pgBox = client.getFlowClient().getSuggestedProcessGroupCoordinates(parentPgId);
+ posDto.setX(Integer.valueOf(pgBox.getX()).doubleValue());
+ posDto.setY(Integer.valueOf(pgBox.getY()).doubleValue());
+ }
final ProcessGroupDTO pgDto = new ProcessGroupDTO();
pgDto.setVersionControlInformation(versionControlInfo);