Skip to content

Commit

Permalink
NIFI-13904 Fixed CLI commands to set/remove parameter context inherit…
Browse files Browse the repository at this point in the history
…ance (#9437)

Signed-off-by: David Handermann <exceptionfactory@apache.org>
  • Loading branch information
pvillard31 authored Oct 24, 2024
1 parent d474c83 commit d1f4048
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
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;
Expand Down Expand Up @@ -81,6 +83,8 @@ public ParamProviderResult doExecute(final NiFiClient client, final Properties p
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();
Expand All @@ -92,7 +96,7 @@ public ParamProviderResult doExecute(final NiFiClient client, final Properties p
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
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;
Expand All @@ -51,7 +53,9 @@ public ParamProviderResult doExecute(final NiFiClient client, final Properties p
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ public VoidResult doExecute(final NiFiClient client, final Properties properties
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ public VoidResult doExecute(final NiFiClient client, final Properties properties
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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;

Expand All @@ -35,10 +36,13 @@
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
Expand All @@ -59,6 +63,7 @@ protected void writeSimpleResult(final PrintStream output) throws IOException {
}
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();
Expand All @@ -67,6 +72,7 @@ protected void writeSimpleResult(final PrintStream output) throws IOException {
group.getParameterSensitivities().keySet().stream().sorted()
.forEach(param -> fetchedParametersTable.addRow(new String[] {
group.getGroupName(),
getParameterContextId(group.getParameterContextName()),
group.getParameterContextName(),
param
}));
Expand All @@ -83,6 +89,16 @@ protected void writeSimpleResult(final PrintStream output) throws IOException {
}
}

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;
Expand Down

0 comments on commit d1f4048

Please sign in to comment.