mirror of https://github.com/apache/nifi.git
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:
parent
d474c831ae
commit
d1f4048b06
|
@ -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.api.Context;
|
||||||
import org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClient;
|
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.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.client.nifi.ParamProviderClient;
|
||||||
import org.apache.nifi.toolkit.cli.impl.command.CommandOption;
|
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.command.nifi.AbstractNiFiCommand;
|
||||||
import org.apache.nifi.toolkit.cli.impl.result.nifi.ParamProviderResult;
|
import org.apache.nifi.toolkit.cli.impl.result.nifi.ParamProviderResult;
|
||||||
import org.apache.nifi.toolkit.cli.impl.util.JacksonUtils;
|
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.ParameterProviderApplyParametersRequestEntity;
|
||||||
import org.apache.nifi.web.api.entity.ParameterProviderEntity;
|
import org.apache.nifi.web.api.entity.ParameterProviderEntity;
|
||||||
import org.apache.nifi.web.api.entity.ParameterProviderParameterApplicationEntity;
|
import org.apache.nifi.web.api.entity.ParameterProviderParameterApplicationEntity;
|
||||||
|
@ -81,6 +83,8 @@ public class FetchParams extends AbstractNiFiCommand<ParamProviderResult> {
|
||||||
parameterApplicationEntity = objectMapper.readValue(parameterApplicationJson, ParameterProviderParameterApplicationEntity.class);
|
parameterApplicationEntity = objectMapper.readValue(parameterApplicationJson, ParameterProviderParameterApplicationEntity.class);
|
||||||
}
|
}
|
||||||
final ParamProviderClient paramProviderClient = client.getParamProviderClient();
|
final ParamProviderClient paramProviderClient = client.getParamProviderClient();
|
||||||
|
final ParamContextClient paramContextClient = client.getParamContextClient();
|
||||||
|
final ParameterContextsEntity paramContextEntity = paramContextClient.getParamContexts();
|
||||||
final ParameterProviderEntity existingParameterProvider = paramProviderClient.getParamProvider(paramProviderId);
|
final ParameterProviderEntity existingParameterProvider = paramProviderClient.getParamProvider(paramProviderId);
|
||||||
|
|
||||||
final ParameterProviderParameterFetchEntity fetchEntity = new ParameterProviderParameterFetchEntity();
|
final ParameterProviderParameterFetchEntity fetchEntity = new ParameterProviderParameterFetchEntity();
|
||||||
|
@ -92,7 +96,7 @@ public class FetchParams extends AbstractNiFiCommand<ParamProviderResult> {
|
||||||
applyParametersAndWait(paramProviderClient, fetchedParameterProvider, parameterApplicationEntity, sensitiveParamPattern);
|
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,
|
private void applyParametersAndWait(final ParamProviderClient paramProviderClient, final ParameterProviderEntity fetchedParameterProvider,
|
||||||
|
|
|
@ -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.api.Context;
|
||||||
import org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClient;
|
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.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.client.nifi.ParamProviderClient;
|
||||||
import org.apache.nifi.toolkit.cli.impl.command.CommandOption;
|
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.command.nifi.AbstractNiFiCommand;
|
||||||
import org.apache.nifi.toolkit.cli.impl.result.nifi.ParamProviderResult;
|
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 org.apache.nifi.web.api.entity.ParameterProviderEntity;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -51,7 +53,9 @@ public class GetParamProvider extends AbstractNiFiCommand<ParamProviderResult> {
|
||||||
throws NiFiClientException, IOException, MissingOptionException, CommandException {
|
throws NiFiClientException, IOException, MissingOptionException, CommandException {
|
||||||
final String paramProviderId = getRequiredArg(properties, CommandOption.PARAM_PROVIDER_ID);
|
final String paramProviderId = getRequiredArg(properties, CommandOption.PARAM_PROVIDER_ID);
|
||||||
final ParamProviderClient paramProviderClient = client.getParamProviderClient();
|
final ParamProviderClient paramProviderClient = client.getParamProviderClient();
|
||||||
|
final ParamContextClient paramContextClient = client.getParamContextClient();
|
||||||
|
final ParameterContextsEntity paramContextEntity = paramContextClient.getParamContexts();
|
||||||
final ParameterProviderEntity parameterProvider = paramProviderClient.getParamProvider(paramProviderId);
|
final ParameterProviderEntity parameterProvider = paramProviderClient.getParamProvider(paramProviderId);
|
||||||
return new ParamProviderResult(getResultType(properties), parameterProvider);
|
return new ParamProviderResult(getResultType(properties), parameterProvider, paramContextEntity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,14 @@ public class RemoveInheritedParamContexts extends AbstractUpdateParamContextComm
|
||||||
parameterContextDTO.setId(existingParameterContextEntity.getId());
|
parameterContextDTO.setId(existingParameterContextEntity.getId());
|
||||||
parameterContextDTO.setParameters(existingParameterContextEntity.getComponent().getParameters());
|
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();
|
final ParameterContextEntity updatedParameterContextEntity = new ParameterContextEntity();
|
||||||
updatedParameterContextEntity.setId(paramContextId);
|
updatedParameterContextEntity.setId(paramContextId);
|
||||||
updatedParameterContextEntity.setComponent(parameterContextDTO);
|
updatedParameterContextEntity.setComponent(parameterContextDTO);
|
||||||
|
|
|
@ -87,6 +87,14 @@ public class SetInheritedParamContexts extends AbstractUpdateParamContextCommand
|
||||||
parameterContextDTO.setId(existingParameterContextEntity.getId());
|
parameterContextDTO.setId(existingParameterContextEntity.getId());
|
||||||
parameterContextDTO.setParameters(existingParameterContextEntity.getComponent().getParameters());
|
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();
|
final ParameterContextEntity updatedParameterContextEntity = new ParameterContextEntity();
|
||||||
updatedParameterContextEntity.setId(paramContextId);
|
updatedParameterContextEntity.setId(paramContextId);
|
||||||
updatedParameterContextEntity.setComponent(parameterContextDTO);
|
updatedParameterContextEntity.setComponent(parameterContextDTO);
|
||||||
|
|
|
@ -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.Table;
|
||||||
import org.apache.nifi.toolkit.cli.impl.result.writer.TableWriter;
|
import org.apache.nifi.toolkit.cli.impl.result.writer.TableWriter;
|
||||||
import org.apache.nifi.web.api.dto.ParameterProviderDTO;
|
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.ParameterGroupConfigurationEntity;
|
||||||
import org.apache.nifi.web.api.entity.ParameterProviderEntity;
|
import org.apache.nifi.web.api.entity.ParameterProviderEntity;
|
||||||
|
|
||||||
|
@ -35,10 +36,13 @@ import java.util.List;
|
||||||
public class ParamProviderResult extends AbstractWritableResult<ParameterProviderEntity> {
|
public class ParamProviderResult extends AbstractWritableResult<ParameterProviderEntity> {
|
||||||
|
|
||||||
private final ParameterProviderEntity parameterProvider;
|
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);
|
super(resultType);
|
||||||
this.parameterProvider = parameterProvider;
|
this.parameterProvider = parameterProvider;
|
||||||
|
this.parameterContexts = paramContextEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -59,6 +63,7 @@ public class ParamProviderResult extends AbstractWritableResult<ParameterProvide
|
||||||
}
|
}
|
||||||
final Table fetchedParametersTable = new Table.Builder()
|
final Table fetchedParametersTable = new Table.Builder()
|
||||||
.column("Parameter Group", 20, 60, false)
|
.column("Parameter Group", 20, 60, false)
|
||||||
|
.column("Parameter Context Id", 36, 36, false)
|
||||||
.column("Parameter Context Name", 20, 60, false)
|
.column("Parameter Context Name", 20, 60, false)
|
||||||
.column("Fetched Parameter Name", 20, 60, false)
|
.column("Fetched Parameter Name", 20, 60, false)
|
||||||
.build();
|
.build();
|
||||||
|
@ -67,6 +72,7 @@ public class ParamProviderResult extends AbstractWritableResult<ParameterProvide
|
||||||
group.getParameterSensitivities().keySet().stream().sorted()
|
group.getParameterSensitivities().keySet().stream().sorted()
|
||||||
.forEach(param -> fetchedParametersTable.addRow(new String[] {
|
.forEach(param -> fetchedParametersTable.addRow(new String[] {
|
||||||
group.getGroupName(),
|
group.getGroupName(),
|
||||||
|
getParameterContextId(group.getParameterContextName()),
|
||||||
group.getParameterContextName(),
|
group.getParameterContextName(),
|
||||||
param
|
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
|
@Override
|
||||||
public ParameterProviderEntity getResult() {
|
public ParameterProviderEntity getResult() {
|
||||||
return parameterProvider;
|
return parameterProvider;
|
||||||
|
|
Loading…
Reference in New Issue