Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NIFI-13868: add pg-delete command to Nifi Toolkit #9387

Open
wants to merge 3 commits into
base: support/nifi-1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions nifi-docs/src/main/asciidoc/toolkit-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,6 @@ FlowEntity copySnippet(String processGroupId, CopySnippetRequestEntity copySnipp
throws NiFiClientException, IOException;

FlowComparisonEntity getLocalModifications(String processGroupId) throws NiFiClientException, IOException;

void deleteProcessGroup(ProcessGroupEntity entity) throws NiFiClientException, IOException;
exceptionfactory marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -356,4 +356,18 @@ public FlowComparisonEntity getLocalModifications(final String processGroupId) t
});
}

@Override
public void deleteProcessGroup(ProcessGroupEntity entity) throws NiFiClientException, IOException {
if (entity == null) {
throw new IllegalArgumentException("Process group entity cannot be null");
}
executeAction("Error deleting process group", () -> {
final WebTarget target = processGroupsTarget
.path("{id}")
.queryParam("version", entity.getRevision().getVersion())
.resolveTemplate("id", entity.getId());
getRequestBuilder(target).delete();
return null;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
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;
Expand Down Expand Up @@ -150,6 +151,7 @@ protected List<Command> createCommands() {
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());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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.VoidResult;
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<VoidResult> {

public PGDelete() {
super("pg-delete", VoidResult.class);
}

@Override
public String getDescription() {
return "Deletes the given process group.";
}

@Override
protected void doInitialize(final Context context) {
addOption(CommandOption.PG_ID.createOption());
}

@Override
public VoidResult 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) {
grishick marked this conversation as resolved.
Show resolved Hide resolved
throw new NiFiClientException("Process group with id " + pgId + " not found.");
}
pgClient.deleteProcessGroup(pgEntity);

return new VoidResult();
}
}