use of org.apache.nifi.web.api.dto.PropertyDescriptorDTO in project nifi by apache.
the class PropertyDescriptorDtoMerger method merge.
public static void merge(PropertyDescriptorDTO clientPropertyDescriptor, Map<NodeIdentifier, PropertyDescriptorDTO> dtoMap) {
final Map<Integer, List<AllowableValueEntity>> allowableValueMap = new HashMap<>();
// values are guaranteed to be in order, so map each allowable value for each property descriptor across all node IDs to the index of the value in the descriptor's list of allowable values
for (final Map.Entry<NodeIdentifier, PropertyDescriptorDTO> nodeEntry : dtoMap.entrySet()) {
final PropertyDescriptorDTO nodePropertyDescriptor = nodeEntry.getValue();
final List<AllowableValueEntity> nodePropertyDescriptorAllowableValues = nodePropertyDescriptor.getAllowableValues();
if (nodePropertyDescriptorAllowableValues != null) {
nodePropertyDescriptorAllowableValues.stream().forEach(allowableValueEntity -> {
allowableValueMap.computeIfAbsent(nodePropertyDescriptorAllowableValues.indexOf(allowableValueEntity), propertyDescriptorToAllowableValue -> new ArrayList<>()).add(allowableValueEntity);
});
}
}
// for each AllowableValueEntity in this PropertyDescriptorDTO, get the corresponding AVs previously aggregated and merge them.
final List<AllowableValueEntity> clientPropertyDescriptorAllowableValues = clientPropertyDescriptor.getAllowableValues();
if (clientPropertyDescriptorAllowableValues != null) {
for (AllowableValueEntity clientAllowableValueEntity : clientPropertyDescriptorAllowableValues) {
AllowableValueEntityMerger.merge(clientAllowableValueEntity, allowableValueMap.get(clientPropertyDescriptorAllowableValues.indexOf(clientAllowableValueEntity)));
}
}
}
use of org.apache.nifi.web.api.dto.PropertyDescriptorDTO in project nifi by apache.
the class TemplateUtils method scrubProcessors.
/**
* Scrubs processors prior to saving. This includes removing sensitive properties, validation errors, property descriptors, etc.
*
* @param processors procs
*/
private static void scrubProcessors(final Set<ProcessorDTO> processors) {
// go through each processor
for (final ProcessorDTO processorDTO : processors) {
final ProcessorConfigDTO processorConfig = processorDTO.getConfig();
// ensure that some property configuration have been specified
if (processorConfig != null) {
// if properties have been specified, remove sensitive ones
if (processorConfig.getProperties() != null) {
Map<String, String> processorProperties = processorConfig.getProperties();
// look for sensitive properties and remove them
if (processorConfig.getDescriptors() != null) {
final Collection<PropertyDescriptorDTO> descriptors = processorConfig.getDescriptors().values();
for (PropertyDescriptorDTO descriptor : descriptors) {
if (Boolean.TRUE.equals(descriptor.isSensitive())) {
processorProperties.put(descriptor.getName(), null);
}
scrubPropertyDescriptor(descriptor);
}
}
}
processorConfig.setCustomUiUrl(null);
processorConfig.setDefaultConcurrentTasks(null);
processorConfig.setDefaultSchedulingPeriod(null);
processorConfig.setAutoTerminatedRelationships(null);
}
if (processorDTO.getRelationships() != null) {
for (final RelationshipDTO relationship : processorDTO.getRelationships()) {
relationship.setDescription(null);
}
}
processorDTO.setExtensionMissing(null);
processorDTO.setMultipleVersionsAvailable(null);
processorDTO.setValidationErrors(null);
processorDTO.setInputRequirement(null);
processorDTO.setDescription(null);
processorDTO.setInputRequirement(null);
processorDTO.setPersistsState(null);
processorDTO.setSupportsBatching(null);
processorDTO.setSupportsEventDriven(null);
processorDTO.setSupportsParallelProcessing(null);
}
}
use of org.apache.nifi.web.api.dto.PropertyDescriptorDTO in project nifi by apache.
the class TemplateUtils method scrubControllerServices.
private static void scrubControllerServices(final Set<ControllerServiceDTO> controllerServices) {
for (final ControllerServiceDTO serviceDTO : controllerServices) {
final Map<String, String> properties = serviceDTO.getProperties();
final Map<String, PropertyDescriptorDTO> descriptors = serviceDTO.getDescriptors();
if (properties != null && descriptors != null) {
for (final PropertyDescriptorDTO descriptor : descriptors.values()) {
if (Boolean.TRUE.equals(descriptor.isSensitive())) {
properties.put(descriptor.getName(), null);
}
scrubPropertyDescriptor(descriptor);
}
}
serviceDTO.setControllerServiceApis(null);
serviceDTO.setExtensionMissing(null);
serviceDTO.setMultipleVersionsAvailable(null);
serviceDTO.setCustomUiUrl(null);
serviceDTO.setValidationErrors(null);
}
}
use of org.apache.nifi.web.api.dto.PropertyDescriptorDTO in project kylo by Teradata.
the class TemplateCreationHelperTest method newPropertyDescriptor.
/**
* Creates a new {@link PropertyDescriptorDTO} that identifies the specified controller service.
*
* @param name the name of the property
* @param type the type of controller service
* @param allowableValues the allowable controller service ids
* @return the new property descriptor
*/
@Nonnull
private PropertyDescriptorDTO newPropertyDescriptor(@Nonnull final String name, @Nonnull final String type, @Nonnull final String... allowableValues) {
// Create the list of allowable values
final List<AllowableValueEntity> allowableValueEntities = Stream.of(allowableValues).map(value -> {
final AllowableValueDTO dto = new AllowableValueDTO();
dto.setValue(value);
return dto;
}).map(dto -> {
final AllowableValueEntity entity = new AllowableValueEntity();
entity.setAllowableValue(dto);
return entity;
}).collect(Collectors.toList());
// Create the property descriptor
final PropertyDescriptorDTO property = new PropertyDescriptorDTO();
property.setAllowableValues(allowableValueEntities);
property.setName(name);
property.setIdentifiesControllerService(type);
property.setRequired(true);
return property;
}
use of org.apache.nifi.web.api.dto.PropertyDescriptorDTO in project nifi by apache.
the class ControllerServiceEntityMerger method mergeDtos.
private static void mergeDtos(final ControllerServiceDTO clientDto, final Map<NodeIdentifier, ControllerServiceDTO> dtoMap) {
// if unauthorized for the client dto, simple return
if (clientDto == null) {
return;
}
final Map<String, Set<NodeIdentifier>> validationErrorMap = new HashMap<>();
final Set<ControllerServiceReferencingComponentEntity> referencingComponents = clientDto.getReferencingComponents();
final Map<NodeIdentifier, Set<ControllerServiceReferencingComponentEntity>> nodeReferencingComponentsMap = new HashMap<>();
final Map<String, Map<NodeIdentifier, PropertyDescriptorDTO>> propertyDescriptorMap = new HashMap<>();
String state = null;
for (final Map.Entry<NodeIdentifier, ControllerServiceDTO> nodeEntry : dtoMap.entrySet()) {
final ControllerServiceDTO nodeControllerService = nodeEntry.getValue();
// consider the node controller service if authorized
if (nodeControllerService != null) {
final NodeIdentifier nodeId = nodeEntry.getKey();
if (state == null) {
if (ControllerServiceState.DISABLING.name().equals(nodeControllerService.getState())) {
state = ControllerServiceState.DISABLING.name();
} else if (ControllerServiceState.ENABLING.name().equals(nodeControllerService.getState())) {
state = ControllerServiceState.ENABLING.name();
}
}
nodeReferencingComponentsMap.put(nodeId, nodeControllerService.getReferencingComponents());
// merge the validation errors
ErrorMerger.mergeErrors(validationErrorMap, nodeId, nodeControllerService.getValidationErrors());
// aggregate the property descriptors
final Map<String, PropertyDescriptorDTO> descriptors = nodeControllerService.getDescriptors();
if (descriptors != null) {
descriptors.values().stream().forEach(propertyDescriptor -> {
propertyDescriptorMap.computeIfAbsent(propertyDescriptor.getName(), nodeIdToPropertyDescriptor -> new HashMap<>()).put(nodeId, propertyDescriptor);
});
}
}
}
// merge property descriptors
for (Map<NodeIdentifier, PropertyDescriptorDTO> propertyDescriptorByNodeId : propertyDescriptorMap.values()) {
final Collection<PropertyDescriptorDTO> nodePropertyDescriptors = propertyDescriptorByNodeId.values();
if (!nodePropertyDescriptors.isEmpty()) {
// get the name of the property descriptor and find that descriptor being returned to the client
final PropertyDescriptorDTO propertyDescriptor = nodePropertyDescriptors.iterator().next();
final PropertyDescriptorDTO clientPropertyDescriptor = clientDto.getDescriptors().get(propertyDescriptor.getName());
PropertyDescriptorDtoMerger.merge(clientPropertyDescriptor, propertyDescriptorByNodeId);
}
}
// merge the referencing components
mergeControllerServiceReferences(referencingComponents, nodeReferencingComponentsMap);
// store the 'transition' state is applicable
if (state != null) {
clientDto.setState(state);
}
// set the merged the validation errors
clientDto.setValidationErrors(ErrorMerger.normalizedMergedErrors(validationErrorMap, dtoMap.size()));
}
Aggregations