Search in sources :

Example 76 with ValidationResult

use of org.apache.nifi.components.ValidationResult in project nifi by apache.

the class AbstractConfiguredComponent method getValidationErrors.

public Collection<ValidationResult> getValidationErrors(final Set<String> serviceIdentifiersNotToValidate) {
    final List<ValidationResult> results = new ArrayList<>();
    lock.lock();
    try {
        final ValidationContext validationContext;
        if (serviceIdentifiersNotToValidate == null || serviceIdentifiersNotToValidate.isEmpty()) {
            validationContext = getValidationContext();
        } else {
            validationContext = getValidationContextFactory().newValidationContext(serviceIdentifiersNotToValidate, getProperties(), getAnnotationData(), getProcessGroupIdentifier(), getIdentifier());
        }
        final Collection<ValidationResult> validationResults;
        try (final NarCloseable narCloseable = NarCloseable.withComponentNarLoader(getComponent().getClass(), getComponent().getIdentifier())) {
            validationResults = getComponent().validate(validationContext);
        }
        for (final ValidationResult result : validationResults) {
            if (!result.isValid()) {
                results.add(result);
            }
        }
    } catch (final Throwable t) {
        logger.error("Failed to perform validation of " + this, t);
        results.add(new ValidationResult.Builder().explanation("Failed to run validation due to " + t.toString()).valid(false).build());
    } finally {
        lock.unlock();
    }
    return results;
}
Also used : NarCloseable(org.apache.nifi.nar.NarCloseable) ArrayList(java.util.ArrayList) ValidationResult(org.apache.nifi.components.ValidationResult) ValidationContext(org.apache.nifi.components.ValidationContext)

Example 77 with ValidationResult

use of org.apache.nifi.components.ValidationResult in project nifi by apache.

the class LocalPort method getValidationErrors.

@Override
public Collection<ValidationResult> getValidationErrors() {
    final Collection<ValidationResult> validationErrors = new ArrayList<>();
    if (!isValid()) {
        final ValidationResult error = new ValidationResult.Builder().explanation(String.format("Output connection for port '%s' is not defined.", getName())).subject(String.format("Port '%s'", getName())).valid(false).build();
        validationErrors.add(error);
    }
    return validationErrors;
}
Also used : ArrayList(java.util.ArrayList) ValidationResult(org.apache.nifi.components.ValidationResult)

Example 78 with ValidationResult

use of org.apache.nifi.components.ValidationResult in project nifi-minifi by apache.

the class StatusConfigReporter method handleProcessorRequest.

private static void handleProcessorRequest(String[] sections, ProcessGroupStatus rootGroupStatus, FlowController flowController, List<ProcessorStatusBean> processorStatusBeanList, Map<String, ProcessorStatus> processorStatusMap, Logger logger) throws StatusRequestException {
    if (processorStatusMap == null) {
        processorStatusMap = transformStatusCollection(rootGroupStatus.getProcessorStatus());
    }
    String rootGroupId = flowController.getRootGroupId();
    if (sections[1].equalsIgnoreCase("all")) {
        if (!processorStatusMap.isEmpty()) {
            for (ProcessorStatus processorStatus : processorStatusMap.values()) {
                Collection<ValidationResult> validationResults = flowController.getGroup(rootGroupId).getProcessor(processorStatus.getId()).getValidationErrors();
                processorStatusBeanList.add(parseProcessorStatusRequest(processorStatus, sections[2], flowController, validationResults));
            }
        }
    } else {
        if (processorStatusMap.containsKey(sections[1])) {
            ProcessorStatus processorStatus = processorStatusMap.get(sections[1]);
            Collection<ValidationResult> validationResults = flowController.getGroup(rootGroupId).getProcessor(processorStatus.getId()).getValidationErrors();
            processorStatusBeanList.add(parseProcessorStatusRequest(processorStatus, sections[2], flowController, validationResults));
        } else {
            logger.warn("Status for processor with key " + sections[1] + " was requested but one does not exist");
            throw new StatusRequestException("No processor with key " + sections[1] + " to report status on");
        }
    }
}
Also used : ValidationResult(org.apache.nifi.components.ValidationResult) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus)

Example 79 with ValidationResult

use of org.apache.nifi.components.ValidationResult in project nifi-minifi by apache.

the class StatusRequestParser method parseControllerServiceStatusRequest.

static ControllerServiceStatus parseControllerServiceStatusRequest(ControllerServiceNode controllerServiceNode, String statusTypes, FlowController flowController, Logger logger) {
    ControllerServiceStatus controllerServiceStatus = new ControllerServiceStatus();
    String id = controllerServiceNode.getIdentifier();
    controllerServiceStatus.setName(id);
    String[] statusSplits = statusTypes.split(",");
    List<Bulletin> bulletinList = flowController.getBulletinRepository().findBulletins(new BulletinQuery.Builder().sourceIdMatches(id).build());
    for (String statusType : statusSplits) {
        switch(statusType.toLowerCase().trim()) {
            case "health":
                ControllerServiceHealth controllerServiceHealth = new ControllerServiceHealth();
                controllerServiceHealth.setState(controllerServiceNode.getState().name());
                controllerServiceHealth.setHasBulletins(!bulletinList.isEmpty());
                Collection<ValidationResult> validationResults = controllerServiceNode.getValidationErrors();
                controllerServiceHealth.setValidationErrorList(transformValidationResults(validationResults));
                controllerServiceStatus.setControllerServiceHealth(controllerServiceHealth);
                break;
            case "bulletins":
                controllerServiceStatus.setBulletinList(transformBulletins(bulletinList));
                break;
        }
    }
    return controllerServiceStatus;
}
Also used : ControllerServiceHealth(org.apache.nifi.minifi.commons.status.controllerservice.ControllerServiceHealth) ControllerServiceStatus(org.apache.nifi.minifi.commons.status.controllerservice.ControllerServiceStatus) Bulletin(org.apache.nifi.reporting.Bulletin) BulletinQuery(org.apache.nifi.reporting.BulletinQuery) ValidationResult(org.apache.nifi.components.ValidationResult)

Example 80 with ValidationResult

use of org.apache.nifi.components.ValidationResult in project nifi-minifi by apache.

the class StatusRequestParser method transformValidationResults.

private static List<ValidationError> transformValidationResults(Collection<ValidationResult> validationResults) {
    List<ValidationError> validationErrorList = new LinkedList<>();
    for (ValidationResult validationResult : validationResults) {
        if (!validationResult.isValid()) {
            ValidationError validationError = new ValidationError();
            validationError.setSubject(validationResult.getSubject());
            validationError.setInput(validationResult.getInput());
            validationError.setReason(validationResult.getExplanation());
            validationErrorList.add(validationError);
        }
    }
    return validationErrorList;
}
Also used : ValidationError(org.apache.nifi.minifi.commons.status.common.ValidationError) ValidationResult(org.apache.nifi.components.ValidationResult) LinkedList(java.util.LinkedList)

Aggregations

ValidationResult (org.apache.nifi.components.ValidationResult)179 Test (org.junit.Test)80 ArrayList (java.util.ArrayList)64 TestRunner (org.apache.nifi.util.TestRunner)46 ValidationContext (org.apache.nifi.components.ValidationContext)37 MockProcessContext (org.apache.nifi.util.MockProcessContext)26 TdchConnectionService (com.thinkbiganalytics.kylo.nifi.teradata.tdch.api.TdchConnectionService)23 Validator (org.apache.nifi.components.Validator)21 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)20 DevTdchConnectionService (com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.controllerservice.DevTdchConnectionService)18 DummyTdchConnectionService (com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.controllerservice.DummyTdchConnectionService)18 HashSet (java.util.HashSet)18 ProcessContext (org.apache.nifi.processor.ProcessContext)15 File (java.io.File)12 HashMap (java.util.HashMap)12 Collection (java.util.Collection)11 SSLContextService (org.apache.nifi.ssl.SSLContextService)11 Map (java.util.Map)10 List (java.util.List)9 ComponentLog (org.apache.nifi.logging.ComponentLog)9