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();
}
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);
}
Aggregations