This is an automated email from the ASF dual-hosted git repository.
exceptionfactory pushed a commit to branch support/nifi-1.x
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/support/nifi-1.x by this push:
new 83ab53671e NIFI-13868 Added pg-delete command to NiFi Toolkit CLI
(#9387)
83ab53671e is described below
commit 83ab53671e94917d1194531c61a2c93a529fae1a
Author: Greg Solovyev <[email protected]>
AuthorDate: Mon Oct 28 13:34:45 2024 -0700
NIFI-13868 Added pg-delete command to NiFi Toolkit CLI (#9387)
Signed-off-by: David Handermann <[email protected]>
---
nifi-docs/src/main/asciidoc/toolkit-guide.adoc | 19 ++++---
.../cli/impl/client/nifi/ProcessGroupClient.java | 2 +
.../client/nifi/impl/JerseyProcessGroupClient.java | 13 +++++
.../cli/impl/command/nifi/NiFiCommandGroup.java | 2 +
.../toolkit/cli/impl/command/nifi/pg/PGDelete.java | 65 ++++++++++++++++++++++
5 files changed, 92 insertions(+), 9 deletions(-)
diff --git a/nifi-docs/src/main/asciidoc/toolkit-guide.adoc
b/nifi-docs/src/main/asciidoc/toolkit-guide.adoc
index 1354d06d66..c447d6c74e 100644
--- a/nifi-docs/src/main/asciidoc/toolkit-guide.adoc
+++ b/nifi-docs/src/main/asciidoc/toolkit-guide.adoc
@@ -100,6 +100,7 @@ The following are available commands:
nifi pg-get-param-context
nifi pg-set-param-context
nifi pg-replace
+ nifi pg-delete
nifi get-services
nifi get-service
nifi create-service
@@ -309,15 +310,15 @@ Typing "nifi " and then a tab will show the sub-commands
for NiFi:
create-reg-client get-nodes merge-param-context
pg-start
create-reporting-task get-param-context offload-node
pg-status
create-service get-policy pg-change-version
pg-stop
- create-user get-reg-client-id pg-create-service
set-param
- create-user-group get-reporting-task pg-disable-services
start-reporting-tasks
- current-user get-reporting-tasks pg-enable-services
stop-reporting-tasks
- delete-node get-root-id pg-get-all-versions
update-policy
- delete-param get-service pg-get-param-context
update-reg-client
- delete-param-context get-services pg-get-services
update-user-group
- disable-services import-param-context pg-get-vars
upload-template
- disconnect-node list-param-contexts pg-get-version
delete-reporting-task
- download-template list-reg-clients pg-import
+ create-user get-reg-client-id pg-create-service
pg-delete
+ create-user-group get-reporting-task pg-disable-services
set-param
+ current-user get-reporting-tasks pg-enable-services
start-reporting-tasks
+ delete-node get-root-id pg-get-all-versions
stop-reporting-tasks
+ delete-param get-service pg-get-param-context
update-policy
+ delete-param-context get-services pg-get-services
update-reg-client
+ disable-services import-param-context pg-get-vars
update-user-group
+ disconnect-node list-param-contexts pg-get-version
upload-template
+ download-template list-reg-clients pg-import
delete-reporting-task
Arguments that represent a path to a file, such as `-p` or when setting a
properties file in the session, will auto-complete the path being typed:
diff --git
a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/client/nifi/ProcessGroupClient.java
b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/client/nifi/ProcessGroupClient.java
index 6c49e92ae8..072275ac92 100644
---
a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/client/nifi/ProcessGroupClient.java
+++
b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/client/nifi/ProcessGroupClient.java
@@ -75,4 +75,6 @@ public interface ProcessGroupClient {
throws NiFiClientException, IOException;
FlowComparisonEntity getLocalModifications(String processGroupId) throws
NiFiClientException, IOException;
+
+ ProcessGroupEntity deleteProcessGroup(ProcessGroupEntity entity) throws
NiFiClientException, IOException;
}
diff --git
a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/client/nifi/impl/JerseyProcessGroupClient.java
b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/client/nifi/impl/JerseyProcessGroupClient.java
index 2f204e22fa..b0d2590535 100644
---
a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/client/nifi/impl/JerseyProcessGroupClient.java
+++
b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/client/nifi/impl/JerseyProcessGroupClient.java
@@ -356,4 +356,17 @@ public class JerseyProcessGroupClient extends
AbstractJerseyClient implements Pr
});
}
+ @Override
+ public ProcessGroupEntity deleteProcessGroup(ProcessGroupEntity entity)
throws NiFiClientException, IOException {
+ if (entity == null) {
+ throw new IllegalArgumentException("Process group entity cannot be
null");
+ }
+ return executeAction("Error deleting process group", () -> {
+ final WebTarget target = processGroupsTarget
+ .path("{id}")
+ .queryParam("version", entity.getRevision().getVersion())
+ .resolveTemplate("id", entity.getId());
+ return getRequestBuilder(target).delete(ProcessGroupEntity.class);
+ });
+ }
}
diff --git
a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/nifi/NiFiCommandGroup.java
b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/nifi/NiFiCommandGroup.java
index 12f02380a3..db9e8cce49 100644
---
a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/nifi/NiFiCommandGroup.java
+++
b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/nifi/NiFiCommandGroup.java
@@ -66,6 +66,7 @@ import
org.apache.nifi.toolkit.cli.impl.command.nifi.pg.PGChangeVersion;
import org.apache.nifi.toolkit.cli.impl.command.nifi.pg.PGConnect;
import org.apache.nifi.toolkit.cli.impl.command.nifi.pg.PGCreate;
import
org.apache.nifi.toolkit.cli.impl.command.nifi.pg.PGCreateControllerService;
+import org.apache.nifi.toolkit.cli.impl.command.nifi.pg.PGDelete;
import
org.apache.nifi.toolkit.cli.impl.command.nifi.pg.PGDisableControllerServices;
import
org.apache.nifi.toolkit.cli.impl.command.nifi.pg.PGEnableControllerServices;
import org.apache.nifi.toolkit.cli.impl.command.nifi.pg.PGGetAllVersions;
@@ -150,6 +151,7 @@ public class NiFiCommandGroup extends AbstractCommandGroup {
commands.add(new PGGetParamContext());
commands.add(new PGSetParamContext());
commands.add(new PGReplace());
+ commands.add(new PGDelete());
commands.add(new GetControllerServices());
commands.add(new GetControllerService());
commands.add(new CreateControllerService());
diff --git
a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/nifi/pg/PGDelete.java
b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/nifi/pg/PGDelete.java
new file mode 100644
index 0000000000..787ecc537b
--- /dev/null
+++
b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/nifi/pg/PGDelete.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.toolkit.cli.impl.command.nifi.pg;
+
+import org.apache.commons.cli.MissingOptionException;
+import org.apache.nifi.toolkit.cli.api.Context;
+import org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClient;
+import org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException;
+import org.apache.nifi.toolkit.cli.impl.client.nifi.ProcessGroupClient;
+import org.apache.nifi.toolkit.cli.impl.command.CommandOption;
+import org.apache.nifi.toolkit.cli.impl.command.nifi.AbstractNiFiCommand;
+import org.apache.nifi.toolkit.cli.impl.result.StringResult;
+import org.apache.nifi.web.api.entity.ProcessGroupEntity;
+
+import java.io.IOException;
+import java.util.Properties;
+
+/**
+ * Command to delete a process group.
+ */
+public class PGDelete extends AbstractNiFiCommand<StringResult> {
+
+ public PGDelete() {
+ super("pg-delete", StringResult.class);
+ }
+
+ @Override
+ public String getDescription() {
+ return "Deletes the given process group. Deleting a process group
requires, stopping all Processors, disabling all Controller Services, and
emptying all Queues.";
+ }
+
+ @Override
+ protected void doInitialize(final Context context) {
+ addOption(CommandOption.PG_ID.createOption());
+ }
+
+ @Override
+ public StringResult doExecute(final NiFiClient client, final Properties
properties)
+ throws NiFiClientException, IOException, MissingOptionException {
+
+ final String pgId = getRequiredArg(properties, CommandOption.PG_ID);
+
+ final ProcessGroupClient pgClient = client.getProcessGroupClient();
+ final ProcessGroupEntity pgEntity = pgClient.getProcessGroup(pgId);
+ if (pgEntity == null) {
+ throw new NiFiClientException("Process group with id " + pgId + "
not found.");
+ }
+ pgClient.deleteProcessGroup(pgEntity);
+ return new StringResult(pgId, isInteractive());
+ }
+}
\ No newline at end of file