NIFI-13904 Fixed CLI commands to set/remove parameter context inheritance (#9437)

Signed-off-by: David Handermann <exceptionfactory@apache.org>
This commit is contained in:
Pierre Villard 2024-10-24 21:41:50 +02:00 committed by GitHub
parent d474c831ae
commit d1f4048b06
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 43 additions and 3 deletions

View File

@ -23,11 +23,13 @@ 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.NiFiClient;
import org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException;
import org.apache.nifi.toolkit.cli.impl.client.nifi.ParamContextClient;
import org.apache.nifi.toolkit.cli.impl.client.nifi.ParamProviderClient;
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.ParamProviderResult;
import org.apache.nifi.toolkit.cli.impl.util.JacksonUtils;
import org.apache.nifi.web.api.entity.ParameterContextsEntity;
import org.apache.nifi.web.api.entity.ParameterProviderApplyParametersRequestEntity;
import org.apache.nifi.web.api.entity.ParameterProviderEntity;
import org.apache.nifi.web.api.entity.ParameterProviderParameterApplicationEntity;
@ -81,6 +83,8 @@ public class FetchParams extends AbstractNiFiCommand<ParamProviderResult> {
parameterApplicationEntity = objectMapper.readValue(parameterApplicationJson, ParameterProviderParameterApplicationEntity.class);
}
final ParamProviderClient paramProviderClient = client.getParamProviderClient();
final ParamContextClient paramContextClient = client.getParamContextClient();
final ParameterContextsEntity paramContextEntity = paramContextClient.getParamContexts();
final ParameterProviderEntity existingParameterProvider = paramProviderClient.getParamProvider(paramProviderId);
final ParameterProviderParameterFetchEntity fetchEntity = new ParameterProviderParameterFetchEntity();
@ -92,7 +96,7 @@ public class FetchParams extends AbstractNiFiCommand<ParamProviderResult> {
applyParametersAndWait(paramProviderClient, fetchedParameterProvider, parameterApplicationEntity, sensitiveParamPattern);
}
return new ParamProviderResult(getResultType(properties), fetchedParameterProvider);
return new ParamProviderResult(getResultType(properties), fetchedParameterProvider, paramContextEntity);
}
private void applyParametersAndWait(final ParamProviderClient paramProviderClient, final ParameterProviderEntity fetchedParameterProvider,

View File

@ -21,10 +21,12 @@ 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.NiFiClient;
import org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException;
import org.apache.nifi.toolkit.cli.impl.client.nifi.ParamContextClient;
import org.apache.nifi.toolkit.cli.impl.client.nifi.ParamProviderClient;
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.ParamProviderResult;
import org.apache.nifi.web.api.entity.ParameterContextsEntity;
import org.apache.nifi.web.api.entity.ParameterProviderEntity;
import java.io.IOException;
@ -51,7 +53,9 @@ public class GetParamProvider extends AbstractNiFiCommand<ParamProviderResult> {
throws NiFiClientException, IOException, MissingOptionException, CommandException {
final String paramProviderId = getRequiredArg(properties, CommandOption.PARAM_PROVIDER_ID);
final ParamProviderClient paramProviderClient = client.getParamProviderClient();
final ParamContextClient paramContextClient = client.getParamContextClient();
final ParameterContextsEntity paramContextEntity = paramContextClient.getParamContexts();
final ParameterProviderEntity parameterProvider = paramProviderClient.getParamProvider(paramProviderId);
return new ParamProviderResult(getResultType(properties), parameterProvider);
return new ParamProviderResult(getResultType(properties), parameterProvider, paramContextEntity);
}
}

View File

@ -69,6 +69,14 @@ public class RemoveInheritedParamContexts extends AbstractUpdateParamContextComm
parameterContextDTO.setId(existingParameterContextEntity.getId());
parameterContextDTO.setParameters(existingParameterContextEntity.getComponent().getParameters());
// we need to explicitly set null for the sensitive parameters as we are getting **** for the values
// on the client side. This is the only way for the server side to know that the values are not changed
// during the update parameter context request
parameterContextDTO.getParameters()
.stream()
.filter(t -> t.getParameter().getSensitive().booleanValue())
.forEach(t -> t.getParameter().setValue(null));
final ParameterContextEntity updatedParameterContextEntity = new ParameterContextEntity();
updatedParameterContextEntity.setId(paramContextId);
updatedParameterContextEntity.setComponent(parameterContextDTO);

View File

@ -87,6 +87,14 @@ public class SetInheritedParamContexts extends AbstractUpdateParamContextCommand
parameterContextDTO.setId(existingParameterContextEntity.getId());
parameterContextDTO.setParameters(existingParameterContextEntity.getComponent().getParameters());
// we need to explicitly set null for the sensitive parameters as we are getting **** for the values
// on the client side. This is the only way for the server side to know that the values are not changed
// during the update parameter context request
parameterContextDTO.getParameters()
.stream()
.filter(t -> t.getParameter().getSensitive().booleanValue())
.forEach(t -> t.getParameter().setValue(null));
final ParameterContextEntity updatedParameterContextEntity = new ParameterContextEntity();
updatedParameterContextEntity.setId(paramContextId);
updatedParameterContextEntity.setComponent(parameterContextDTO);

View File

@ -22,6 +22,7 @@ import org.apache.nifi.toolkit.cli.impl.result.writer.DynamicTableWriter;
import org.apache.nifi.toolkit.cli.impl.result.writer.Table;
import org.apache.nifi.toolkit.cli.impl.result.writer.TableWriter;
import org.apache.nifi.web.api.dto.ParameterProviderDTO;
import org.apache.nifi.web.api.entity.ParameterContextsEntity;
import org.apache.nifi.web.api.entity.ParameterGroupConfigurationEntity;
import org.apache.nifi.web.api.entity.ParameterProviderEntity;
@ -35,10 +36,13 @@ import java.util.List;
public class ParamProviderResult extends AbstractWritableResult<ParameterProviderEntity> {
private final ParameterProviderEntity parameterProvider;
private final ParameterContextsEntity parameterContexts;
public ParamProviderResult(final ResultType resultType, final ParameterProviderEntity parameterProvider) {
public ParamProviderResult(final ResultType resultType, final ParameterProviderEntity parameterProvider,
final ParameterContextsEntity paramContextEntity) {
super(resultType);
this.parameterProvider = parameterProvider;
this.parameterContexts = paramContextEntity;
}
@Override
@ -59,6 +63,7 @@ public class ParamProviderResult extends AbstractWritableResult<ParameterProvide
}
final Table fetchedParametersTable = new Table.Builder()
.column("Parameter Group", 20, 60, false)
.column("Parameter Context Id", 36, 36, false)
.column("Parameter Context Name", 20, 60, false)
.column("Fetched Parameter Name", 20, 60, false)
.build();
@ -67,6 +72,7 @@ public class ParamProviderResult extends AbstractWritableResult<ParameterProvide
group.getParameterSensitivities().keySet().stream().sorted()
.forEach(param -> fetchedParametersTable.addRow(new String[] {
group.getGroupName(),
getParameterContextId(group.getParameterContextName()),
group.getParameterContextName(),
param
}));
@ -83,6 +89,16 @@ public class ParamProviderResult extends AbstractWritableResult<ParameterProvide
}
}
private String getParameterContextId(final String name) {
return parameterContexts.getParameterContexts()
.stream()
.filter(t -> t.getComponent().getName().equals(name))
.findFirst()
.get()
.getComponent()
.getId();
}
@Override
public ParameterProviderEntity getResult() {
return parameterProvider;