use of com.thinkbiganalytics.nifi.rest.model.NifiError in project kylo by Teradata.
the class TemplateCreationHelper method versionProcessGroup.
/**
* Version a ProcessGroup renaming it with the name - {timestamp millis}.
* If {@code removeIfInactive} is true it will not version but just delete it
*
* @param processGroup the group to version
*/
public VersionedProcessGroup versionProcessGroup(ProcessGroupDTO processGroup, String versionIdentifier) {
log.info("Versioning Process Group {} ", processGroup.getName());
VersionedProcessGroup versionedProcessGroup = new VersionedProcessGroup();
versionedProcessGroup.setProcessGroupPriorToVersioning(processGroup);
versionedProcessGroup.setProcessGroupName(processGroup.getName());
List<ProcessorDTO> inputProcessorsPriorToDisabling = restClient.disableAllInputProcessors(processGroup.getId());
versionedProcessGroup.setInputProcessorsPriorToDisabling(inputProcessorsPriorToDisabling);
log.info("Disabled Inputs for {} ", processGroup.getName());
// attempt to stop all processors
try {
restClient.stopInputs(processGroup.getId());
log.info("Stopped Input Ports for {}, ", processGroup.getName());
} catch (Exception e) {
log.error("Error trying to stop Input Ports for {} while creating a new version ", processGroup.getName());
}
// delete input connections
try {
List<ConnectionDTO> deletedConnections = deleteInputPortConnections(processGroup);
versionedProcessGroup.setDeletedInputPortConnections(deletedConnections);
} catch (NifiClientRuntimeException e) {
log.error("Error trying to delete input port connections for Process Group {} while creating a new version. ", processGroup.getName(), e);
getErrors().add(new NifiError(NifiError.SEVERITY.FATAL, "The input port connections to the process group " + processGroup.getName() + " could not be deleted. Please delete them manually " + "in NiFi and try again."));
}
String versionedProcessGroupName = getVersionedProcessGroupName(processGroup.getName(), versionIdentifier);
versionedProcessGroup.setVersionedProcessGroupName(versionedProcessGroupName);
// rename the feedGroup to be name+timestamp
processGroup.setName(versionedProcessGroupName);
restClient.updateProcessGroup(processGroup);
log.info("Renamed ProcessGroup to {}, ", processGroup.getName());
versionedProcessGroup.setVersionedProcessGroup(processGroup);
return versionedProcessGroup;
}
use of com.thinkbiganalytics.nifi.rest.model.NifiError in project kylo by Teradata.
the class TemplateCreationHelper method updateControllerServiceReferences.
/**
* Fix references to the controller services on the processor properties
*
* @param processors processors to inspect
* @param controllerServiceProperties property overrides for controller services
* @return the list of properties that were modified
*/
public List<NifiProperty> updateControllerServiceReferences(List<ProcessorDTO> processors, Map<String, String> controllerServiceProperties, TemplateInstance instance) {
try {
processors = reassignControllerServiceIds(processors, instance);
// merge the snapshotted services with the newly created ones and update respective processors in the newly created flow
final Map<String, ControllerServiceDTO> enabledServices = new HashMap<>();
Map<String, ControllerServiceDTO> allServices = mergedControllerServices;
for (ControllerServiceDTO dto : allServices.values()) {
if (NifiProcessUtil.SERVICE_STATE.ENABLED.name().equals(dto.getState())) {
enabledServices.put(dto.getId(), dto);
enabledServices.put(dto.getName(), dto);
}
}
List<NifiProperty> properties = new ArrayList<>();
Map<String, ProcessGroupDTO> processGroupDTOMap = new HashMap<>();
for (ProcessorDTO dto : processors) {
ProcessGroupDTO groupDTO = processGroupDTOMap.get(dto.getParentGroupId());
if (groupDTO == null) {
// we can create a tmp group dto here as all we need is the id
groupDTO = new ProcessGroupDTO();
groupDTO.setId(dto.getParentGroupId());
groupDTO.setName(dto.getParentGroupId());
processGroupDTOMap.put(dto.getParentGroupId(), groupDTO);
}
properties.addAll(NifiPropertyUtil.getPropertiesForProcessor(groupDTO, dto, restClient.getPropertyDescriptorTransform()));
}
List<NifiProperty> updatedProperties = fixControllerServiceReferences(controllerServiceProperties, enabledServices, allServices, properties);
updatedProperties.forEach(property -> restClient.updateProcessorProperty(property.getProcessGroupId(), property.getProcessorId(), property));
return updatedProperties;
} catch (NifiClientRuntimeException e) {
errors.add(new NifiError(NifiError.SEVERITY.FATAL, "Error trying to identify Controller Services. " + e.getMessage(), NifiProcessGroup.CONTROLLER_SERVICE_CATEGORY));
}
return Collections.emptyList();
}
use of com.thinkbiganalytics.nifi.rest.model.NifiError in project kylo by Teradata.
the class TemplateCreationHelper method cleanupControllerServices.
public void cleanupControllerServices() {
// only keep them if they are the first of their kind
if (snapshotControllerServices != null && !snapshotControllerServices.isEmpty()) {
final Set<String> serviceTypes = new HashSet<>();
for (ControllerServiceDTO dto : snapshotControllerServices) {
serviceTypes.add(dto.getType());
}
List<ControllerServiceDTO> servicesToDelete = Lists.newArrayList(Iterables.filter(newlyCreatedControllerServices, new Predicate<ControllerServiceDTO>() {
@Override
public boolean apply(ControllerServiceDTO controllerServiceDTO) {
return serviceTypes.contains(controllerServiceDTO.getType()) && (controllerServiceDTO.getReferencingComponents() == null || controllerServiceDTO.getReferencingComponents().size() == 0);
}
}));
if (servicesToDelete != null && !servicesToDelete.isEmpty()) {
try {
restClient.deleteControllerServices(servicesToDelete);
} catch (Exception e) {
log.info("error attempting to cleanup controller services while trying to delete Services: " + e.getMessage() + ". It might be wise to login to NIFI and verify there are not extra controller services");
getErrors().add(new NifiError(NifiError.SEVERITY.INFO, "There is an error attempting to remove the controller service :" + e.getMessage()));
}
}
}
}
use of com.thinkbiganalytics.nifi.rest.model.NifiError in project kylo by Teradata.
the class TemplateCreationHelper method fixControllerServiceReferences.
/**
* Enables the controller services for the specified properties or changes the property value to an enabled service.
*
* @param controllerServiceProperties property overrides for controller services
* @param enabledServices map of enabled controller service ids and names to DTOs
* @param allServices map of all controller service ids to DTOs
* @param properties the processor properties to update
* @return the list of properties that were modified
*/
@Nonnull
private List<NifiProperty> fixControllerServiceReferences(@Nullable final Map<String, String> controllerServiceProperties, @Nonnull final Map<String, ControllerServiceDTO> enabledServices, @Nonnull final Map<String, ControllerServiceDTO> allServices, @Nonnull final List<NifiProperty> properties) {
return properties.stream().filter(property -> StringUtils.isNotBlank(property.getPropertyDescriptor().getIdentifiesControllerService())).filter(property -> StringUtils.isNotBlank(property.getValue())).filter(property -> !enabledServices.containsKey(property.getValue())).filter(property -> {
final Optional<ControllerServiceDTO> controllerService = findControllerServiceForProperty(controllerServiceProperties, enabledServices, allServices, property);
if (controllerService.isPresent()) {
if (!controllerService.get().getId().equals(property.getValue())) {
property.setValue(controllerService.get().getId());
return true;
}
} else if (property.getPropertyDescriptor().isRequired()) {
final String message = "Unable to find a valid controller service for the '" + property.getKey() + "' property of the '" + property.getProcessorName() + "' " + "processor.";
errors.add(new NifiError(NifiError.SEVERITY.FATAL, message, NifiProcessGroup.CONTROLLER_SERVICE_CATEGORY));
}
return false;
}).collect(Collectors.toList());
}
use of com.thinkbiganalytics.nifi.rest.model.NifiError in project kylo by Teradata.
the class NifiProcessorValidationUtil method getValidationErrors.
public static List<NifiError> getValidationErrors(ProcessGroupDTO group) {
List<NiFiComponentErrors> processorValidationErrors = getProcessorValidationErrors(group);
List<NifiError> errors = new ArrayList<>();
for (NiFiComponentErrors dto : processorValidationErrors) {
errors.addAll(dto.getValidationErrors());
}
return errors;
}
Aggregations