Search in sources :

Example 1 with NiFiPropertyDescriptorTransform

use of com.thinkbiganalytics.nifi.rest.model.NiFiPropertyDescriptorTransform in project kylo by Teradata.

the class ConfigurationPropertyReplacer method replaceControllerServiceProperties.

/**
 * This will replace the Map of Properties in the DTO but not persist back to Nifi.  You need to call the rest client to persist the change
 *
 * @param controllerServiceDTO        the controller service
 * @param properties                  the properties to set
 * @param propertyDescriptorTransform transformer
 * @return {@code true} if the properties were updated, {@code false} if not
 */
public static boolean replaceControllerServiceProperties(ControllerServiceDTO controllerServiceDTO, Map<String, String> properties, NiFiPropertyDescriptorTransform propertyDescriptorTransform) {
    Set<String> changedProperties = new HashSet<>();
    if (controllerServiceDTO != null) {
        // check both Nifis Internal Key name as well as the Displayname to match the properties
        CaseInsensitiveMap propertyMap = new CaseInsensitiveMap(properties);
        Map<String, String> controllerServiceProperties = controllerServiceDTO.getProperties();
        controllerServiceProperties.entrySet().stream().filter(entry -> (propertyMap.containsKey(entry.getKey()) || (controllerServiceDTO.getDescriptors().get(entry.getKey()) != null && propertyMap.containsKey(controllerServiceDTO.getDescriptors().get(entry.getKey()).getDisplayName().toLowerCase())))).forEach(entry -> {
            boolean isSensitive = propertyDescriptorTransform.isSensitive(controllerServiceDTO.getDescriptors().get(entry.getKey()));
            String value = (String) propertyMap.get(entry.getKey());
            if (StringUtils.isBlank(value)) {
                value = (String) propertyMap.get(controllerServiceDTO.getDescriptors().get(entry.getKey()).getDisplayName().toLowerCase());
            }
            if (!isSensitive || (isSensitive && StringUtils.isNotBlank(value))) {
                entry.setValue(value);
                changedProperties.add(entry.getKey());
            }
        });
    }
    return !changedProperties.isEmpty();
}
Also used : CaseInsensitiveMap(org.apache.commons.collections.map.CaseInsensitiveMap) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) Set(java.util.Set) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) NiFiPropertyDescriptorTransform(com.thinkbiganalytics.nifi.rest.model.NiFiPropertyDescriptorTransform) HashSet(java.util.HashSet) List(java.util.List) Matcher(java.util.regex.Matcher) Map(java.util.Map) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) CaseInsensitiveMap(org.apache.commons.collections.map.CaseInsensitiveMap) HashSet(java.util.HashSet)

Example 2 with NiFiPropertyDescriptorTransform

use of com.thinkbiganalytics.nifi.rest.model.NiFiPropertyDescriptorTransform in project kylo by Teradata.

the class TemplateCreationHelper method tryToEnableControllerService.

/**
 * Tries to enable the specified controller service.
 *
 * @param controllerService the controller service to enable
 * @param properties        property overrides for the controller service
 * @param enabledServices   map of enabled controller service ids and names to DTOs
 * @param allServices       map of all controller service ids to
 * @return the enabled controller service
 * @throws NifiComponentNotFoundException if the controller service does not exist
 * @throws WebApplicationException        if the controller service cannot be enabled
 */
@Nonnull
private ControllerServiceDTO tryToEnableControllerService(@Nonnull final ControllerServiceDTO controllerService, @Nullable final Map<String, String> properties, @Nonnull final Map<String, ControllerServiceDTO> enabledServices, @Nonnull final Map<String, ControllerServiceDTO> allServices) {
    // Check if already enabled
    if ("ENABLED".equals(controllerService.getState())) {
        return controllerService;
    }
    // Fix controller service references
    final NiFiPropertyDescriptorTransform propertyDescriptorTransform = restClient.getPropertyDescriptorTransform();
    final List<NifiProperty> changedProperties = fixControllerServiceReferences(properties, enabledServices, allServices, NifiPropertyUtil.getPropertiesForService(controllerService, propertyDescriptorTransform));
    if (!changedProperties.isEmpty()) {
        changedProperties.forEach(property -> {
            controllerService.getProperties().put(property.getKey(), property.getValue());
        });
        nifiRestClient.controllerServices().update(controllerService);
    }
    // Enable controller service
    return restClient.enableControllerServiceAndSetProperties(controllerService.getId(), properties);
}
Also used : NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) NiFiPropertyDescriptorTransform(com.thinkbiganalytics.nifi.rest.model.NiFiPropertyDescriptorTransform) Nonnull(javax.annotation.Nonnull)

Aggregations

NiFiPropertyDescriptorTransform (com.thinkbiganalytics.nifi.rest.model.NiFiPropertyDescriptorTransform)2 NifiProperty (com.thinkbiganalytics.nifi.rest.model.NifiProperty)2 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 Nonnull (javax.annotation.Nonnull)1 CaseInsensitiveMap (org.apache.commons.collections.map.CaseInsensitiveMap)1 StringUtils (org.apache.commons.lang3.StringUtils)1 ControllerServiceDTO (org.apache.nifi.web.api.dto.ControllerServiceDTO)1