NiFi CLI - add possibility to set 'Maximum Timer Driven Thread Count' (#7165)

This commit is contained in:
timeabarna 2023-04-18 16:18:44 +02:00 committed by GitHub
parent 946064b1c4
commit 51f7d6d747
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 213 additions and 4 deletions

View File

@ -17,11 +17,12 @@
package org.apache.nifi.toolkit.cli.impl.client.nifi;
import org.apache.nifi.web.api.entity.ClusterEntity;
import org.apache.nifi.web.api.entity.ControllerConfigurationEntity;
import org.apache.nifi.web.api.entity.ControllerServiceEntity;
import org.apache.nifi.web.api.entity.NodeEntity;
import org.apache.nifi.web.api.entity.ParameterProviderEntity;
import org.apache.nifi.web.api.entity.FlowRegistryClientEntity;
import org.apache.nifi.web.api.entity.FlowRegistryClientsEntity;
import org.apache.nifi.web.api.entity.NodeEntity;
import org.apache.nifi.web.api.entity.ParameterProviderEntity;
import org.apache.nifi.web.api.entity.ReportingTaskEntity;
import java.io.IOException;
@ -57,4 +58,8 @@ public interface ControllerClient {
ParameterProviderEntity createParamProvider(ParameterProviderEntity paramProvider) throws NiFiClientException, IOException;
ControllerConfigurationEntity getControllerConfiguration() throws NiFiClientException, IOException;
ControllerConfigurationEntity updateControllerConfiguration(ControllerConfigurationEntity controllerConfiguration) throws NiFiClientException, IOException;
}

View File

@ -21,11 +21,12 @@ import org.apache.nifi.toolkit.cli.impl.client.nifi.ControllerClient;
import org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException;
import org.apache.nifi.toolkit.cli.impl.client.nifi.RequestConfig;
import org.apache.nifi.web.api.entity.ClusterEntity;
import org.apache.nifi.web.api.entity.ControllerConfigurationEntity;
import org.apache.nifi.web.api.entity.ControllerServiceEntity;
import org.apache.nifi.web.api.entity.NodeEntity;
import org.apache.nifi.web.api.entity.ParameterProviderEntity;
import org.apache.nifi.web.api.entity.FlowRegistryClientEntity;
import org.apache.nifi.web.api.entity.FlowRegistryClientsEntity;
import org.apache.nifi.web.api.entity.NodeEntity;
import org.apache.nifi.web.api.entity.ParameterProviderEntity;
import org.apache.nifi.web.api.entity.ReportingTaskEntity;
import javax.ws.rs.client.Entity;
@ -240,4 +241,33 @@ public class JerseyControllerClient extends AbstractJerseyClient implements Cont
);
});
}
@Override
public ControllerConfigurationEntity getControllerConfiguration() throws NiFiClientException, IOException {
return executeAction("Error retrieving controller configuration", () -> {
final WebTarget target = controllerTarget.path("config");
return getRequestBuilder(target).get(ControllerConfigurationEntity.class);
});
}
@Override
public ControllerConfigurationEntity updateControllerConfiguration(ControllerConfigurationEntity controllerConfiguration) throws NiFiClientException, IOException {
if (controllerConfiguration == null || controllerConfiguration.getComponent() == null) {
throw new IllegalArgumentException("Controller configuration must be specified");
}
if (controllerConfiguration.getRevision() == null) {
throw new IllegalArgumentException("Revision must be specified.");
}
return executeAction("Error updating controller configuration", () -> {
final WebTarget target = controllerTarget
.path("config");
return getRequestBuilder(target).put(
Entity.entity(controllerConfiguration, MediaType.APPLICATION_JSON),
ControllerConfigurationEntity.class
);
});
}
}

View File

@ -29,11 +29,13 @@ import org.apache.nifi.toolkit.cli.impl.command.nifi.cs.GetControllerServices;
import org.apache.nifi.toolkit.cli.impl.command.nifi.flow.ClusterSummary;
import org.apache.nifi.toolkit.cli.impl.command.nifi.flow.CreateReportingTask;
import org.apache.nifi.toolkit.cli.impl.command.nifi.flow.CurrentUser;
import org.apache.nifi.toolkit.cli.impl.command.nifi.flow.GetControllerConfiguration;
import org.apache.nifi.toolkit.cli.impl.command.nifi.flow.GetReportingTask;
import org.apache.nifi.toolkit.cli.impl.command.nifi.flow.GetReportingTasks;
import org.apache.nifi.toolkit.cli.impl.command.nifi.flow.GetRootId;
import org.apache.nifi.toolkit.cli.impl.command.nifi.flow.StartReportingTasks;
import org.apache.nifi.toolkit.cli.impl.command.nifi.flow.StopReportingTasks;
import org.apache.nifi.toolkit.cli.impl.command.nifi.flow.UpdateControllerConfiguration;
import org.apache.nifi.toolkit.cli.impl.command.nifi.nodes.ConnectNode;
import org.apache.nifi.toolkit.cli.impl.command.nifi.nodes.DeleteNode;
import org.apache.nifi.toolkit.cli.impl.command.nifi.nodes.DisconnectNode;
@ -180,6 +182,8 @@ public class NiFiCommandGroup extends AbstractCommandGroup {
commands.add(new GetAccessToken());
commands.add(new GetAccessTokenSpnego());
commands.add(new LogoutAccessToken());
commands.add(new GetControllerConfiguration());
commands.add(new UpdateControllerConfiguration());
return new ArrayList<>(commands);
}
}

View File

@ -0,0 +1,48 @@
/*
* 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.flow;
import org.apache.commons.cli.MissingOptionException;
import org.apache.nifi.toolkit.cli.api.CommandException;
import org.apache.nifi.toolkit.cli.impl.client.nifi.ControllerClient;
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.command.nifi.AbstractNiFiCommand;
import org.apache.nifi.toolkit.cli.impl.result.nifi.ControllerConfigurationResult;
import org.apache.nifi.web.api.entity.ControllerConfigurationEntity;
import java.io.IOException;
import java.util.Properties;
public class GetControllerConfiguration extends AbstractNiFiCommand<ControllerConfigurationResult> {
public GetControllerConfiguration() {
super("get-controller-configuration", ControllerConfigurationResult.class);
}
@Override
public String getDescription() {
return "Retrieves controller configuration.";
}
@Override
public ControllerConfigurationResult doExecute(final NiFiClient client, final Properties properties) throws NiFiClientException, IOException, MissingOptionException, CommandException {
final ControllerClient controllerClient = client.getControllerClient();
final ControllerConfigurationEntity controllerConfigurationEntity = controllerClient.getControllerConfiguration();
return new ControllerConfigurationResult(getResultType(properties), controllerConfigurationEntity);
}
}

View File

@ -0,0 +1,76 @@
/*
* 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.flow;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.cli.MissingOptionException;
import org.apache.commons.io.IOUtils;
import org.apache.nifi.toolkit.cli.api.CommandException;
import org.apache.nifi.toolkit.cli.api.Context;
import org.apache.nifi.toolkit.cli.impl.client.nifi.ControllerClient;
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.command.CommandOption;
import org.apache.nifi.toolkit.cli.impl.command.nifi.AbstractNiFiCommand;
import org.apache.nifi.toolkit.cli.impl.result.nifi.ControllerConfigurationResult;
import org.apache.nifi.toolkit.cli.impl.util.JacksonUtils;
import org.apache.nifi.web.api.dto.RevisionDTO;
import org.apache.nifi.web.api.entity.ControllerConfigurationEntity;
import java.io.IOException;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.Properties;
public class UpdateControllerConfiguration extends AbstractNiFiCommand<ControllerConfigurationResult> {
public UpdateControllerConfiguration() {
super("update-controller-configuration", ControllerConfigurationResult.class);
}
@Override
public String getDescription() {
return "Updates controller configuration from a local file.";
}
@Override
protected void doInitialize(final Context context) {
addOption(CommandOption.INPUT_SOURCE.createOption());
}
@Override
public ControllerConfigurationResult doExecute(final NiFiClient client, final Properties properties) throws NiFiClientException, IOException, MissingOptionException, CommandException {
final String inputFile = getRequiredArg(properties, CommandOption.INPUT_SOURCE);
final URI uri = Paths.get(inputFile).toAbsolutePath().toUri();
final String contents = IOUtils.toString(uri, StandardCharsets.UTF_8);
final ObjectMapper objectMapper = JacksonUtils.getObjectMapper();
final ControllerConfigurationEntity controllerConfiguration = objectMapper.readValue(contents, ControllerConfigurationEntity.class);
if (controllerConfiguration == null || controllerConfiguration.getComponent() == null) {
throw new IllegalArgumentException("Controller configuration must be specified");
}
final ControllerClient controllerClient = client.getControllerClient();
final RevisionDTO revisionDTO = client.getControllerClient().getControllerConfiguration().getRevision();
controllerConfiguration.setRevision(revisionDTO);
final ControllerConfigurationEntity createdEntity = controllerClient.updateControllerConfiguration(controllerConfiguration);
return new ControllerConfigurationResult(getResultType(properties), createdEntity);
}
}

View File

@ -0,0 +1,46 @@
/*
* 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.result.nifi;
import org.apache.commons.lang3.Validate;
import org.apache.nifi.toolkit.cli.api.ResultType;
import org.apache.nifi.toolkit.cli.impl.result.AbstractWritableResult;
import org.apache.nifi.toolkit.cli.impl.util.JacksonUtils;
import org.apache.nifi.web.api.entity.ControllerConfigurationEntity;
import java.io.IOException;
import java.io.PrintStream;
public class ControllerConfigurationResult extends AbstractWritableResult<ControllerConfigurationEntity> {
private final ControllerConfigurationEntity controllerConfigurationEntity;
public ControllerConfigurationResult(final ResultType resultType, final ControllerConfigurationEntity controllerConfigurationEntity) {
super(resultType);
this.controllerConfigurationEntity = controllerConfigurationEntity;
Validate.notNull(controllerConfigurationEntity);
}
@Override
public ControllerConfigurationEntity getResult() {
return controllerConfigurationEntity;
}
@Override
protected void writeSimpleResult(final PrintStream output) throws IOException {
JacksonUtils.write(getResult(), output);
}
}