Search in sources :

Example 6 with PropertyDescriptorDTO

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)));
        }
    }
}
Also used : List(java.util.List) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) PropertyDescriptorDTO(org.apache.nifi.web.api.dto.PropertyDescriptorDTO) AllowableValueEntity(org.apache.nifi.web.api.entity.AllowableValueEntity) Map(java.util.Map) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) AllowableValueEntity(org.apache.nifi.web.api.entity.AllowableValueEntity) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) PropertyDescriptorDTO(org.apache.nifi.web.api.dto.PropertyDescriptorDTO)

Example 7 with PropertyDescriptorDTO

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

Example 8 with PropertyDescriptorDTO

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

Example 9 with PropertyDescriptorDTO

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;
}
Also used : AllowableValueEntity(org.apache.nifi.web.api.entity.AllowableValueEntity) ProcessorConfigDTO(org.apache.nifi.web.api.dto.ProcessorConfigDTO) ProcessGroupStatusDTO(org.apache.nifi.web.api.dto.status.ProcessGroupStatusDTO) NiFiPropertyDescriptor(com.thinkbiganalytics.nifi.rest.model.NiFiPropertyDescriptor) AllowableValueDTO(org.apache.nifi.web.api.dto.AllowableValueDTO) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) NiFiPropertyDescriptorTransform(com.thinkbiganalytics.nifi.rest.model.NiFiPropertyDescriptorTransform) ArrayList(java.util.ArrayList) NiFiAllowableValue(com.thinkbiganalytics.nifi.rest.model.NiFiAllowableValue) PropertyDescriptorDTO(org.apache.nifi.web.api.dto.PropertyDescriptorDTO) NiFiRestClient(com.thinkbiganalytics.nifi.rest.client.NiFiRestClient) NiFiControllerServicesRestClient(com.thinkbiganalytics.nifi.rest.client.NiFiControllerServicesRestClient) Nonnull(javax.annotation.Nonnull) ImmutableSet(com.google.common.collect.ImmutableSet) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) Assert(org.junit.Assert) Collections(java.util.Collections) LegacyNifiRestClient(com.thinkbiganalytics.nifi.rest.client.LegacyNifiRestClient) AllowableValueDTO(org.apache.nifi.web.api.dto.AllowableValueDTO) AllowableValueEntity(org.apache.nifi.web.api.entity.AllowableValueEntity) PropertyDescriptorDTO(org.apache.nifi.web.api.dto.PropertyDescriptorDTO) Nonnull(javax.annotation.Nonnull)

Example 10 with PropertyDescriptorDTO

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()));
}
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) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) 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)

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