Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
import org.apache.nifi.toolkit.cli.impl.command.nifi.pg.PGImport;
import org.apache.nifi.toolkit.cli.impl.command.nifi.pg.PGList;
import org.apache.nifi.toolkit.cli.impl.command.nifi.pg.PGListProcessors;
import org.apache.nifi.toolkit.cli.impl.command.nifi.pg.PGRename;
import org.apache.nifi.toolkit.cli.impl.command.nifi.pg.PGReplace;
import org.apache.nifi.toolkit.cli.impl.command.nifi.pg.PGSetParamContext;
import org.apache.nifi.toolkit.cli.impl.command.nifi.pg.PGStart;
Expand Down Expand Up @@ -178,6 +179,7 @@ protected List<Command> createCommands() {
commands.add(new PGGetParamContext());
commands.add(new PGSetParamContext());
commands.add(new PGReplace());
commands.add(new PGRename());
commands.add(new PGExport());
commands.add(new PGEmptyQueues());
commands.add(new PGDelete());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@ public String getDescription() {
+ "If only one registry client 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.";
+ "with existing process groups. If a process group name is specified, the imported process group will be "
+ "renamed with the specified name.";
}

@Override
protected void doInitialize(Context context) {
addOption(CommandOption.PG_ID.createOption());
addOption(CommandOption.PG_NAME.createOption());
addOption(CommandOption.INPUT_SOURCE.createOption());
addOption(CommandOption.REGISTRY_CLIENT_ID.createOption());
addOption(CommandOption.BUCKET_ID.createOption());
Expand Down Expand Up @@ -218,6 +220,12 @@ public StringResult doExecute(final NiFiClient client, final Properties properti
createdEntity = pgClient.upload(parentPgId, input, pgName, posDto.getX(), posDto.getY());
}

final String pgName = getArg(properties, CommandOption.PG_NAME);
if (StringUtils.isNotBlank(pgName)) {
final PGRename pgRename = new PGRename();
pgRename.rename(pgName, pgClient, createdEntity);
}

return new StringResult(createdEntity.getId(), getContext().isInteractive());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* 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.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.toolkit.client.NiFiClient;
import org.apache.nifi.toolkit.client.NiFiClientException;
import org.apache.nifi.toolkit.client.ProcessGroupClient;
import org.apache.nifi.web.api.entity.ProcessGroupEntity;
import org.apache.nifi.web.api.entity.ProcessGroupRecursivity;

import java.io.IOException;
import java.util.Properties;

/**
* Command to rename a process group.
*/
public class PGRename extends AbstractNiFiCommand<StringResult> {

public PGRename() {
super("pg-rename", StringResult.class);
}

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

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

@Override
public StringResult doExecute(final NiFiClient client, final Properties properties)
throws NiFiClientException, IOException, MissingOptionException {

final String pgId = getRequiredArg(properties, CommandOption.PG_ID);
final String pgName = getRequiredArg(properties, CommandOption.PG_NAME);

final ProcessGroupClient pgClient = client.getProcessGroupClient();
final ProcessGroupEntity pgEntity = pgClient.getProcessGroup(pgId);
if (pgEntity == null) {
throw new NiFiClientException("Process group with id " + pgId + " not found.");
}

rename(pgName, pgClient, pgEntity);

return new StringResult(pgId, isInteractive());
}

protected void rename(final String pgName, final ProcessGroupClient pgClient, final ProcessGroupEntity pgEntity) throws NiFiClientException, IOException {
pgEntity.setProcessGroupUpdateStrategy(ProcessGroupRecursivity.DIRECT_CHILDREN.name());
pgEntity.getComponent().setContents(null);
pgEntity.getComponent().setVersionControlInformation(null);
pgEntity.getComponent().setName(pgName);

pgClient.updateProcessGroup(pgEntity);
}
}