use of org.apache.nifi.web.api.dto.PropertyDescriptorDTO in project kylo by Teradata.
the class NifiPropertyUtil method getPropertiesForProcessor.
/**
* Return a list of properties on a gi en processor
*
* @param processGroup the processors group
* @param processor the processor
* @param propertyDescriptorTransform the transform utility
* @return the list of properties on the processor
*/
public static List<NifiProperty> getPropertiesForProcessor(ProcessGroupDTO processGroup, ProcessorDTO processor, NiFiPropertyDescriptorTransform propertyDescriptorTransform) {
List<NifiProperty> properties = new ArrayList<>();
for (Map.Entry<String, String> entry : processor.getConfig().getProperties().entrySet()) {
PropertyDescriptorDTO descriptorDTO = processor.getConfig().getDescriptors().get(entry.getKey());
if (descriptorDTO != null) {
final NiFiPropertyDescriptor propertyDescriptor = propertyDescriptorTransform.toNiFiPropertyDescriptor(processor.getConfig().getDescriptors().get(entry.getKey()));
final NifiProperty property = new NifiProperty(processor.getParentGroupId(), processor.getId(), entry.getKey(), entry.getValue(), propertyDescriptor);
property.setProcessGroupName(processGroup.getName());
property.setProcessorName(processor.getName());
property.setProcessorType(processor.getType());
properties.add(property);
}
}
return properties;
}
use of org.apache.nifi.web.api.dto.PropertyDescriptorDTO in project nifi by apache.
the class ProcessorResource method getPropertyDescriptor.
/**
* Returns the descriptor for the specified property.
*
* @param id The id of the processor
* @param propertyName The property
* @return a propertyDescriptorEntity
* @throws InterruptedException if interrupted
*/
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}/descriptors")
@ApiOperation(value = "Gets the descriptor for a processor property", response = PropertyDescriptorEntity.class, authorizations = { @Authorization(value = "Read - /processors/{uuid}") })
@ApiResponses(value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 404, message = "The specified resource could not be found."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") })
public Response getPropertyDescriptor(@ApiParam(value = "If the client id is not specified, new one will be generated. This value (whether specified or generated) is included in the response.", required = false) @QueryParam(CLIENT_ID) @DefaultValue(StringUtils.EMPTY) final ClientIdParameter clientId, @ApiParam(value = "The processor id.", required = true) @PathParam("id") final String id, @ApiParam(value = "The property name.", required = true) @QueryParam("propertyName") final String propertyName) throws InterruptedException {
// ensure the property name is specified
if (propertyName == null) {
throw new IllegalArgumentException("The property name must be specified.");
}
if (isReplicateRequest()) {
return replicate(HttpMethod.GET);
}
// authorize access
serviceFacade.authorizeAccess(lookup -> {
final Authorizable processor = lookup.getProcessor(id).getAuthorizable();
processor.authorize(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser());
});
// get the property descriptor
final PropertyDescriptorDTO descriptor = serviceFacade.getProcessorPropertyDescriptor(id, propertyName);
// generate the response entity
final PropertyDescriptorEntity entity = new PropertyDescriptorEntity();
entity.setPropertyDescriptor(descriptor);
// generate the response
return generateOkResponse(entity).build();
}
use of org.apache.nifi.web.api.dto.PropertyDescriptorDTO in project nifi by apache.
the class SnippetUtils method updateControllerServiceIdentifiers.
private void updateControllerServiceIdentifiers(final ProcessorConfigDTO configDto, final Map<String, String> serviceIdMap) {
if (configDto == null) {
return;
}
final Map<String, String> properties = configDto.getProperties();
final Map<String, PropertyDescriptorDTO> descriptors = configDto.getDescriptors();
if (properties != null && descriptors != null) {
for (final PropertyDescriptorDTO descriptor : descriptors.values()) {
if (descriptor.getIdentifiesControllerService() != null) {
final String currentServiceId = properties.get(descriptor.getName());
if (currentServiceId == null) {
continue;
}
// the serviceIdMap will be empty
if (serviceIdMap.containsKey(currentServiceId)) {
final String newServiceId = serviceIdMap.get(currentServiceId);
properties.put(descriptor.getName(), newServiceId);
}
}
}
}
}
use of org.apache.nifi.web.api.dto.PropertyDescriptorDTO in project nifi by apache.
the class ControllerServiceEntityMerger method mergeControllerServiceReferencingComponent.
private static void mergeControllerServiceReferencingComponent(ControllerServiceReferencingComponentEntity clientEntity, Map<NodeIdentifier, ControllerServiceReferencingComponentEntity> nodeEntities) {
final Map<String, Map<NodeIdentifier, PropertyDescriptorDTO>> propertyDescriptorMap = new HashMap<>();
final Map<NodeIdentifier, Set<ControllerServiceReferencingComponentEntity>> nodeReferencingComponentsMap = new HashMap<>();
// aggregate the property descriptors
for (Map.Entry<NodeIdentifier, ControllerServiceReferencingComponentEntity> entry : nodeEntities.entrySet()) {
final NodeIdentifier nodeIdentifier = entry.getKey();
final ControllerServiceReferencingComponentEntity nodeEntity = entry.getValue();
nodeEntity.getComponent().getDescriptors().values().stream().forEach(propertyDescriptor -> {
propertyDescriptorMap.computeIfAbsent(propertyDescriptor.getName(), nodeIdToPropertyDescriptor -> new HashMap<>()).put(nodeIdentifier, propertyDescriptor);
});
nodeReferencingComponentsMap.put(nodeIdentifier, nodeEntity.getComponent().getReferencingComponents());
}
// 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 = clientEntity.getComponent().getDescriptors().get(propertyDescriptor.getName());
PropertyDescriptorDtoMerger.merge(clientPropertyDescriptor, propertyDescriptorByNodeId);
}
}
final Set<ControllerServiceReferencingComponentEntity> referencingComponents = clientEntity.getComponent().getReferencingComponents();
mergeControllerServiceReferences(referencingComponents, nodeReferencingComponentsMap);
}
use of org.apache.nifi.web.api.dto.PropertyDescriptorDTO in project nifi by apache.
the class ProcessorEntityMerger method mergeDtos.
private static void mergeDtos(final ProcessorDTO clientDto, final Map<NodeIdentifier, ProcessorDTO> dtoMap) {
// if unauthorized for the client dto, simple return
if (clientDto == null) {
return;
}
final Map<String, Set<NodeIdentifier>> validationErrorMap = new HashMap<>();
final Map<String, Map<NodeIdentifier, PropertyDescriptorDTO>> propertyDescriptorMap = new HashMap<>();
for (final Map.Entry<NodeIdentifier, ProcessorDTO> nodeEntry : dtoMap.entrySet()) {
final ProcessorDTO nodeProcessor = nodeEntry.getValue();
// merge the validation errors and aggregate the property descriptors, if authorized
if (nodeProcessor != null) {
final NodeIdentifier nodeId = nodeEntry.getKey();
// merge the validation errors
ErrorMerger.mergeErrors(validationErrorMap, nodeId, nodeProcessor.getValidationErrors());
// aggregate the property descriptors
nodeProcessor.getConfig().getDescriptors().values().stream().forEach(propertyDescriptor -> {
propertyDescriptorMap.computeIfAbsent(propertyDescriptor.getName(), nodeIdToPropertyDescriptor -> new HashMap<>()).put(nodeId, propertyDescriptor);
});
// if any node does not support multiple versions (null or false), make it unavailable
if (clientDto.getMultipleVersionsAvailable() == null || !Boolean.TRUE.equals(nodeProcessor.getMultipleVersionsAvailable())) {
clientDto.setMultipleVersionsAvailable(Boolean.FALSE);
}
}
}
// 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.getConfig().getDescriptors().get(propertyDescriptor.getName());
PropertyDescriptorDtoMerger.merge(clientPropertyDescriptor, propertyDescriptorByNodeId);
}
}
// set the merged the validation errors
clientDto.setValidationErrors(ErrorMerger.normalizedMergedErrors(validationErrorMap, dtoMap.size()));
}
Aggregations