NIFI-7578 nifi-toolkit CLI Process Group Create command

- Remove unused imports
- Fix checkstyle errors

This closes #4358.
This commit is contained in:
Javi Roman 2020-06-24 18:45:37 +02:00 committed by Bryan Bende
parent c2f46c44ca
commit c221e4934d
No known key found for this signature in database
GPG Key ID: A0DDA9ED50711C39
2 changed files with 79 additions and 0 deletions

View File

@ -61,6 +61,7 @@ import org.apache.nifi.toolkit.cli.impl.command.nifi.pg.PGSetVar;
import org.apache.nifi.toolkit.cli.impl.command.nifi.pg.PGStart;
import org.apache.nifi.toolkit.cli.impl.command.nifi.pg.PGStatus;
import org.apache.nifi.toolkit.cli.impl.command.nifi.pg.PGStop;
import org.apache.nifi.toolkit.cli.impl.command.nifi.pg.PGCreate;
import org.apache.nifi.toolkit.cli.impl.command.nifi.policies.GetAccessPolicy;
import org.apache.nifi.toolkit.cli.impl.command.nifi.policies.UpdateAccessPolicy;
import org.apache.nifi.toolkit.cli.impl.command.nifi.registry.CreateRegistryClient;
@ -110,6 +111,7 @@ public class NiFiCommandGroup extends AbstractCommandGroup {
commands.add(new PGImport());
commands.add(new PGStart());
commands.add(new PGStop());
commands.add(new PGCreate());
commands.add(new PGGetVars());
commands.add(new PGSetVar());
commands.add(new PGGetVersion());

View File

@ -0,0 +1,77 @@
/*
* 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.FlowClient;
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.dto.ProcessGroupDTO;
import org.apache.nifi.web.api.entity.ProcessGroupEntity;
import java.io.IOException;
import java.util.Properties;
/**
* Command to create process-groups childs of the root process group.
*/
public class PGCreate extends AbstractNiFiCommand<StringResult> {
public PGCreate() {
super("pg-create", StringResult.class);
}
@Override
public String getDescription() {
return "Creates a process group child of the root group.";
}
@Override
protected void doInitialize(Context context) {
addOption(CommandOption.PG_NAME.createOption());
}
@Override
public StringResult doExecute(final NiFiClient client, final Properties properties)
throws NiFiClientException, IOException, MissingOptionException {
final String processGroupName = getRequiredArg(properties, CommandOption.PG_NAME);
final FlowClient flowClient = client.getFlowClient();
final ProcessGroupClient pgClient = client.getProcessGroupClient();
final String rootPgId = flowClient.getRootGroupId();
final ProcessGroupDTO processGroupDTO = new ProcessGroupDTO();
processGroupDTO.setParentGroupId(rootPgId);
processGroupDTO.setName(processGroupName);
final ProcessGroupEntity pgEntity = new ProcessGroupEntity();
pgEntity.setComponent(processGroupDTO);
pgEntity.setRevision(getInitialRevisionDTO());
final ProcessGroupEntity createdEntity = pgClient.createProcessGroup(
rootPgId, pgEntity);
return new StringResult(createdEntity.getId(), getContext().isInteractive());
}
}