Search in sources :

Example 1 with NifiError

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;
}
Also used : NifiError(com.thinkbiganalytics.nifi.rest.model.NifiError) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) VersionedProcessGroup(com.thinkbiganalytics.nifi.rest.model.VersionedProcessGroup) NifiClientRuntimeException(com.thinkbiganalytics.nifi.rest.client.NifiClientRuntimeException) NifiClientRuntimeException(com.thinkbiganalytics.nifi.rest.client.NifiClientRuntimeException) NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 2 with NifiError

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();
}
Also used : ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) HashMap(java.util.HashMap) NifiError(com.thinkbiganalytics.nifi.rest.model.NifiError) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) ArrayList(java.util.ArrayList) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) NifiClientRuntimeException(com.thinkbiganalytics.nifi.rest.client.NifiClientRuntimeException)

Example 3 with NifiError

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()));
            }
        }
    }
}
Also used : ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) NifiError(com.thinkbiganalytics.nifi.rest.model.NifiError) NifiClientRuntimeException(com.thinkbiganalytics.nifi.rest.client.NifiClientRuntimeException) NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) WebApplicationException(javax.ws.rs.WebApplicationException) HashSet(java.util.HashSet) Predicate(com.google.common.base.Predicate)

Example 4 with NifiError

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());
}
Also used : Iterables(com.google.common.collect.Iterables) VersionedProcessGroup(com.thinkbiganalytics.nifi.rest.model.VersionedProcessGroup) ProcessorConfigDTO(org.apache.nifi.web.api.dto.ProcessorConfigDTO) NifiError(com.thinkbiganalytics.nifi.rest.model.NifiError) LoggerFactory(org.slf4j.LoggerFactory) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) NifiProcessUtil(com.thinkbiganalytics.nifi.rest.support.NifiProcessUtil) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) NiFiPropertyDescriptorTransform(com.thinkbiganalytics.nifi.rest.model.NiFiPropertyDescriptorTransform) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) NifiClientRuntimeException(com.thinkbiganalytics.nifi.rest.client.NifiClientRuntimeException) NiFiAllowableValue(com.thinkbiganalytics.nifi.rest.model.NiFiAllowableValue) Lists(com.google.common.collect.Lists) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) NifiConnectionUtil(com.thinkbiganalytics.nifi.rest.support.NifiConnectionUtil) NiFiObjectCache(com.thinkbiganalytics.nifi.rest.NiFiObjectCache) NifiPropertyUtil(com.thinkbiganalytics.nifi.rest.support.NifiPropertyUtil) Map(java.util.Map) NiFiRestClient(com.thinkbiganalytics.nifi.rest.client.NiFiRestClient) NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) Nonnull(javax.annotation.Nonnull) NifiConstants(com.thinkbiganalytics.nifi.rest.support.NifiConstants) Nullable(javax.annotation.Nullable) NifiTemplateNameUtil(com.thinkbiganalytics.nifi.rest.support.NifiTemplateNameUtil) Logger(org.slf4j.Logger) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) Set(java.util.Set) ComparisonChain(com.google.common.collect.ComparisonChain) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) List(java.util.List) Predicate(com.google.common.base.Predicate) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) Optional(java.util.Optional) WebApplicationException(javax.ws.rs.WebApplicationException) Comparator(java.util.Comparator) Collections(java.util.Collections) LegacyNifiRestClient(com.thinkbiganalytics.nifi.rest.client.LegacyNifiRestClient) NifiProcessGroup(com.thinkbiganalytics.nifi.rest.model.NifiProcessGroup) FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) Optional(java.util.Optional) NifiError(com.thinkbiganalytics.nifi.rest.model.NifiError) Nonnull(javax.annotation.Nonnull)

Example 5 with NifiError

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;
}
Also used : NifiError(com.thinkbiganalytics.nifi.rest.model.NifiError) ArrayList(java.util.ArrayList) NiFiComponentErrors(com.thinkbiganalytics.nifi.rest.model.NiFiComponentErrors)

Aggregations

NifiError (com.thinkbiganalytics.nifi.rest.model.NifiError)7 NifiClientRuntimeException (com.thinkbiganalytics.nifi.rest.client.NifiClientRuntimeException)5 ProcessorDTO (org.apache.nifi.web.api.dto.ProcessorDTO)5 NifiProperty (com.thinkbiganalytics.nifi.rest.model.NifiProperty)4 ArrayList (java.util.ArrayList)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 ProcessGroupDTO (org.apache.nifi.web.api.dto.ProcessGroupDTO)4 NifiComponentNotFoundException (com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException)3 NifiProcessGroup (com.thinkbiganalytics.nifi.rest.model.NifiProcessGroup)3 VersionedProcessGroup (com.thinkbiganalytics.nifi.rest.model.VersionedProcessGroup)3 ConnectionDTO (org.apache.nifi.web.api.dto.ConnectionDTO)3 ControllerServiceDTO (org.apache.nifi.web.api.dto.ControllerServiceDTO)3 FlowSnippetDTO (org.apache.nifi.web.api.dto.FlowSnippetDTO)3 Predicate (com.google.common.base.Predicate)2 AlignProcessGroupComponents (com.thinkbiganalytics.nifi.rest.client.layout.AlignProcessGroupComponents)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 TemplateDTO (org.apache.nifi.web.api.dto.TemplateDTO)2 Stopwatch (com.google.common.base.Stopwatch)1 ComparisonChain (com.google.common.collect.ComparisonChain)1