Search in sources :

Example 1 with PropertyDescriptorDTO

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;
}
Also used : ArrayList(java.util.ArrayList) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) HashMap(java.util.HashMap) Map(java.util.Map) NiFiPropertyDescriptor(com.thinkbiganalytics.nifi.rest.model.NiFiPropertyDescriptor) PropertyDescriptorDTO(org.apache.nifi.web.api.dto.PropertyDescriptorDTO)

Example 2 with PropertyDescriptorDTO

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();
}
Also used : ComponentAuthorizable(org.apache.nifi.authorization.ComponentAuthorizable) Authorizable(org.apache.nifi.authorization.resource.Authorizable) PropertyDescriptorEntity(org.apache.nifi.web.api.entity.PropertyDescriptorEntity) PropertyDescriptorDTO(org.apache.nifi.web.api.dto.PropertyDescriptorDTO) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with PropertyDescriptorDTO

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);
                }
            }
        }
    }
}
Also used : PropertyDescriptorDTO(org.apache.nifi.web.api.dto.PropertyDescriptorDTO)

Example 4 with PropertyDescriptorDTO

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);
}
Also used : PermissionsDTO(org.apache.nifi.web.api.dto.PermissionsDTO) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) PropertyDescriptorDTO(org.apache.nifi.web.api.dto.PropertyDescriptorDTO) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) ControllerServiceReferencingComponentDTO(org.apache.nifi.web.api.dto.ControllerServiceReferencingComponentDTO) ControllerServiceReferencingComponentEntity(org.apache.nifi.web.api.entity.ControllerServiceReferencingComponentEntity) Collection(java.util.Collection) Map(java.util.Map) ControllerServiceState(org.apache.nifi.controller.service.ControllerServiceState) ControllerServiceEntity(org.apache.nifi.web.api.entity.ControllerServiceEntity) Set(java.util.Set) HashMap(java.util.HashMap) Set(java.util.Set) HashMap(java.util.HashMap) ControllerServiceReferencingComponentEntity(org.apache.nifi.web.api.entity.ControllerServiceReferencingComponentEntity) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) Map(java.util.Map) HashMap(java.util.HashMap) PropertyDescriptorDTO(org.apache.nifi.web.api.dto.PropertyDescriptorDTO)

Example 5 with PropertyDescriptorDTO

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()));
}
Also used : NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) PropertyDescriptorDTO(org.apache.nifi.web.api.dto.PropertyDescriptorDTO) ProcessorStatusDTO(org.apache.nifi.web.api.dto.status.ProcessorStatusDTO) Collection(java.util.Collection) Map(java.util.Map) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) Set(java.util.Set) HashMap(java.util.HashMap) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) Set(java.util.Set) HashMap(java.util.HashMap) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) Map(java.util.Map) HashMap(java.util.HashMap) PropertyDescriptorDTO(org.apache.nifi.web.api.dto.PropertyDescriptorDTO)

Aggregations

PropertyDescriptorDTO (org.apache.nifi.web.api.dto.PropertyDescriptorDTO)14 HashMap (java.util.HashMap)8 Map (java.util.Map)6 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)5 ControllerServiceDTO (org.apache.nifi.web.api.dto.ControllerServiceDTO)5 Collection (java.util.Collection)4 Set (java.util.Set)4 ProcessorDTO (org.apache.nifi.web.api.dto.ProcessorDTO)4 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 ArrayList (java.util.ArrayList)3 Consumes (javax.ws.rs.Consumes)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 ComponentAuthorizable (org.apache.nifi.authorization.ComponentAuthorizable)3 Authorizable (org.apache.nifi.authorization.resource.Authorizable)3 PropertyDescriptorEntity (org.apache.nifi.web.api.entity.PropertyDescriptorEntity)3 NiFiPropertyDescriptor (com.thinkbiganalytics.nifi.rest.model.NiFiPropertyDescriptor)2 NifiProperty (com.thinkbiganalytics.nifi.rest.model.NifiProperty)2