NIFI-6581 Add optional x/y coordinates to CLI pg-import command

Signed-off-by: Pierre Villard <pierre.villard.fr@gmail.com>

This closes #3666.
This commit is contained in:
Bryan Bende 2019-08-22 14:52:21 -04:00 committed by Pierre Villard
parent 5d9bba2f6f
commit d6c645a9e2
No known key found for this signature in database
GPG Key ID: BEE1599F0726E9CD
2 changed files with 30 additions and 5 deletions

View File

@ -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),

View File

@ -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();
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);