NIFI-11850 - CLI - add keep existing parameter context flag

This closes #7520

Signed-off-by: David Handermann <exceptionfactory@apache.org>
This commit is contained in:
Pierre Villard 2023-07-24 17:26:26 +02:00 committed by exceptionfactory
parent 0eebf6b14e
commit e0d6b49cd5
No known key found for this signature in database
GPG Key ID: 29B6A52D2AAE8DBA
4 changed files with 22 additions and 1 deletions

View File

@ -38,6 +38,9 @@ public interface ProcessGroupClient {
ProcessGroupEntity createProcessGroup(String parentGroupdId, ProcessGroupEntity entity)
throws NiFiClientException, IOException;
ProcessGroupEntity createProcessGroup(String parentGroupdId, ProcessGroupEntity entity, boolean keepExisting)
throws NiFiClientException, IOException;
ProcessGroupEntity getProcessGroup(String processGroupId) throws NiFiClientException, IOException;
ProcessGroupEntity updateProcessGroup(ProcessGroupEntity entity) throws NiFiClientException, IOException;

View File

@ -58,6 +58,12 @@ public class JerseyProcessGroupClient extends AbstractJerseyClient implements Pr
@Override
public ProcessGroupEntity createProcessGroup(final String parentGroupdId, final ProcessGroupEntity entity)
throws NiFiClientException, IOException {
return createProcessGroup(parentGroupdId, entity, true);
}
@Override
public ProcessGroupEntity createProcessGroup(final String parentGroupdId, final ProcessGroupEntity entity, boolean keepExisting)
throws NiFiClientException, IOException {
if (StringUtils.isBlank(parentGroupdId)) {
throw new IllegalArgumentException("Parent process group id cannot be null or blank");
@ -70,6 +76,7 @@ public class JerseyProcessGroupClient extends AbstractJerseyClient implements Pr
return executeAction("Error creating process group", () -> {
final WebTarget target = processGroupsTarget
.path("{id}/process-groups")
.queryParam("parameterContextHandlingStrategy", keepExisting ? "KEEP_EXISTING" : "REPLACE")
.resolveTemplate("id", parentGroupdId);
return getRequestBuilder(target).post(

View File

@ -83,6 +83,8 @@ public enum CommandOption {
PG_NAME("pgn", "processGroupName", "The name of a process group", true),
PG_VAR_NAME("var", "varName", "The name of a variable", true),
PG_VAR_VALUE("val", "varValue", "The value of a variable", true),
KEEP_EXISTING_PARAMETER_CONTEXT("kepc", "keep-existing-parameter-context", "If false, only directly associated Parameter Contexts will be copied, "
+ "inherited Contexts with no direct assignment to a Process Group are ignored", true),
POS_X("px", "posX", "The x coordinate of a position", true),
POS_Y("py", "posY", "The y coordinate of a position", true),

View File

@ -65,6 +65,7 @@ public class PGImport extends AbstractNiFiCommand<StringResult> {
addOption(CommandOption.FLOW_VERSION.createOption());
addOption(CommandOption.POS_X.createOption());
addOption(CommandOption.POS_Y.createOption());
addOption(CommandOption.KEEP_EXISTING_PARAMETER_CONTEXT.createOption());
}
@Override
@ -78,6 +79,8 @@ public class PGImport extends AbstractNiFiCommand<StringResult> {
final String posXStr = getArg(properties, CommandOption.POS_X);
final String posYStr = getArg(properties, CommandOption.POS_Y);
String keepExistingPC = getArg(properties, CommandOption.KEEP_EXISTING_PARAMETER_CONTEXT);
final boolean posXExists = StringUtils.isNotBlank(posXStr);
final boolean posYExists = StringUtils.isNotBlank(posYStr);
@ -89,6 +92,12 @@ public class PGImport extends AbstractNiFiCommand<StringResult> {
throw new IllegalArgumentException("Missing X position - Please specify both X and Y, or specify neither");
}
if(StringUtils.isNotBlank(keepExistingPC) && !(keepExistingPC.equals("true") || keepExistingPC.equals("false"))) {
throw new IllegalArgumentException("Keep Existing Parameter Context must be either true or false");
} else if (StringUtils.isBlank(keepExistingPC)) {
keepExistingPC = "true";
}
// 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);
@ -140,7 +149,7 @@ public class PGImport extends AbstractNiFiCommand<StringResult> {
pgEntity.setRevision(getInitialRevisionDTO());
final ProcessGroupClient pgClient = client.getProcessGroupClient();
final ProcessGroupEntity createdEntity = pgClient.createProcessGroup(parentPgId, pgEntity);
final ProcessGroupEntity createdEntity = pgClient.createProcessGroup(parentPgId, pgEntity, Boolean.parseBoolean(keepExistingPC));
return new StringResult(createdEntity.getId(), getContext().isInteractive());
}