mirror of https://github.com/apache/nifi.git
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:
parent
0eebf6b14e
commit
e0d6b49cd5
|
@ -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;
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue