use of org.apache.nifi.nar.NarCloseable in project nifi by apache.
the class AbstractConfiguredComponent method validate.
@Override
public Collection<ValidationResult> validate(final ValidationContext context) {
try (final NarCloseable narCloseable = NarCloseable.withComponentNarLoader(getComponent().getClass(), getComponent().getIdentifier())) {
final Collection<ValidationResult> validationResults = getComponent().validate(context);
// validate selected controller services implement the API required by the processor
final List<PropertyDescriptor> supportedDescriptors = getComponent().getPropertyDescriptors();
if (null != supportedDescriptors) {
for (final PropertyDescriptor descriptor : supportedDescriptors) {
if (descriptor.getControllerServiceDefinition() == null) {
// skip properties that aren't for a controller service
continue;
}
final String controllerServiceId = context.getProperty(descriptor).getValue();
if (controllerServiceId == null) {
// if the property value is null we should already have a validation error
continue;
}
final ControllerServiceNode controllerServiceNode = getControllerServiceProvider().getControllerServiceNode(controllerServiceId);
if (controllerServiceNode == null) {
// if the node was null we should already have a validation error
continue;
}
final Class<? extends ControllerService> controllerServiceApiClass = descriptor.getControllerServiceDefinition();
final ClassLoader controllerServiceApiClassLoader = controllerServiceApiClass.getClassLoader();
final Consumer<String> addValidationError = explanation -> validationResults.add(new ValidationResult.Builder().input(controllerServiceId).subject(descriptor.getDisplayName()).valid(false).explanation(explanation).build());
final Bundle controllerServiceApiBundle = ExtensionManager.getBundle(controllerServiceApiClassLoader);
if (controllerServiceApiBundle == null) {
addValidationError.accept(String.format("Unable to find bundle for ControllerService API class %s.", controllerServiceApiClass.getCanonicalName()));
continue;
}
final BundleCoordinate controllerServiceApiCoordinate = controllerServiceApiBundle.getBundleDetails().getCoordinate();
final Bundle controllerServiceBundle = ExtensionManager.getBundle(controllerServiceNode.getBundleCoordinate());
if (controllerServiceBundle == null) {
addValidationError.accept(String.format("Unable to find bundle for coordinate %s.", controllerServiceNode.getBundleCoordinate()));
continue;
}
final BundleCoordinate controllerServiceCoordinate = controllerServiceBundle.getBundleDetails().getCoordinate();
final boolean matchesApi = matchesApi(controllerServiceBundle, controllerServiceApiCoordinate);
if (!matchesApi) {
final String controllerServiceType = controllerServiceNode.getComponentType();
final String controllerServiceApiType = controllerServiceApiClass.getSimpleName();
final String explanation = new StringBuilder().append(controllerServiceType).append(" - ").append(controllerServiceCoordinate.getVersion()).append(" from ").append(controllerServiceCoordinate.getGroup()).append(" - ").append(controllerServiceCoordinate.getId()).append(" is not compatible with ").append(controllerServiceApiType).append(" - ").append(controllerServiceApiCoordinate.getVersion()).append(" from ").append(controllerServiceApiCoordinate.getGroup()).append(" - ").append(controllerServiceApiCoordinate.getId()).toString();
addValidationError.accept(explanation);
}
}
}
return validationResults;
}
}
use of org.apache.nifi.nar.NarCloseable in project nifi-minifi by apache.
the class ProcessorInitializer method initialize.
@Override
public void initialize(ConfigurableComponent component) {
Processor processor = (Processor) component;
ProcessorInitializationContext initializationContext = new MockProcessorInitializationContext();
try (NarCloseable narCloseable = NarCloseable.withComponentNarLoader(component.getClass(), initializationContext.getIdentifier())) {
processor.initialize(initializationContext);
}
}
use of org.apache.nifi.nar.NarCloseable in project nifi-minifi by apache.
the class ControllerServiceInitializer method initialize.
@Override
public void initialize(ConfigurableComponent component) throws InitializationException {
ControllerService controllerService = (ControllerService) component;
ControllerServiceInitializationContext context = new MockControllerServiceInitializationContext();
try (NarCloseable narCloseable = NarCloseable.withComponentNarLoader(component.getClass(), context.getIdentifier())) {
controllerService.initialize(context);
}
}
Aggregations