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