Java Code Examples for org.apache.nifi.components.ConfigurableComponent#getPropertyDescriptors()

The following examples show how to use org.apache.nifi.components.ConfigurableComponent#getPropertyDescriptors() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExtensionManager.java    From nifi-minifi with Apache License 2.0 6 votes vote down vote up
private static boolean checkControllerServiceReferenceEligibility(final ConfigurableComponent component, final ClassLoader classLoader) {
    // if the extension does not require instance classloading, its eligible
    final boolean requiresInstanceClassLoading = component.getClass().isAnnotationPresent(RequiresInstanceClassLoading.class);

    final Set<Class> cobundledApis = new HashSet<>();
    try (final NarCloseable closeable = NarCloseable.withComponentNarLoader(component.getClass().getClassLoader())) {
        final List<PropertyDescriptor> descriptors = component.getPropertyDescriptors();
        if (descriptors != null && !descriptors.isEmpty()) {
            for (final PropertyDescriptor descriptor : descriptors) {
                final Class<? extends ControllerService> serviceApi = descriptor.getControllerServiceDefinition();
                if (serviceApi != null && classLoader.equals(serviceApi.getClassLoader())) {
                    cobundledApis.add(serviceApi);
                }
            }
        }
    }

    if (!cobundledApis.isEmpty()) {
        logger.warn(String.format(
                "Component %s is bundled with its referenced Controller Service APIs %s. The service APIs should not be bundled with component implementations that reference it.",
                component.getClass().getName(), StringUtils.join(cobundledApis.stream().map(cls -> cls.getName()).collect(Collectors.toSet()), ", ")));
    }

    // the component is eligible when it does not require instance classloading or when the supporting APIs are bundled in a parent NAR
    return requiresInstanceClassLoading == false || cobundledApis.isEmpty();
}
 
Example 2
Source File: ExtensionManager.java    From nifi-minifi with Apache License 2.0 6 votes vote down vote up
/**
 * Find the bundle coordinates for any service APIs that are referenced by this component and not part of the same bundle.
 *
 * @param component the component being instantiated
 */
protected static Set<BundleCoordinate> findReachableApiBundles(final ConfigurableComponent component) {
    final Set<BundleCoordinate> reachableApiBundles = new HashSet<>();

    try (final NarCloseable closeable = NarCloseable.withComponentNarLoader(component.getClass().getClassLoader())) {
        final List<PropertyDescriptor> descriptors = component.getPropertyDescriptors();
        if (descriptors != null && !descriptors.isEmpty()) {
            for (final PropertyDescriptor descriptor : descriptors) {
                final Class<? extends ControllerService> serviceApi = descriptor.getControllerServiceDefinition();
                if (serviceApi != null && !component.getClass().getClassLoader().equals(serviceApi.getClassLoader())) {
                    final Bundle apiBundle = classLoaderBundleLookup.get(serviceApi.getClassLoader());
                    reachableApiBundles.add(apiBundle.getBundleDetails().getCoordinate());
                }
            }
        }
    }

    return reachableApiBundles;
}
 
Example 3
Source File: StandardExtensionDiscoveringManager.java    From nifi with Apache License 2.0 6 votes vote down vote up
private static boolean checkControllerServiceReferenceEligibility(final ConfigurableComponent component, final ClassLoader classLoader) {
    // if the extension does not require instance classloading, its eligible
    final boolean requiresInstanceClassLoading = component.getClass().isAnnotationPresent(RequiresInstanceClassLoading.class);

    final Set<Class> cobundledApis = new HashSet<>();
    try (final NarCloseable closeable = NarCloseable.withComponentNarLoader(component.getClass().getClassLoader())) {
        final List<PropertyDescriptor> descriptors = component.getPropertyDescriptors();
        if (descriptors != null && !descriptors.isEmpty()) {
            for (final PropertyDescriptor descriptor : descriptors) {
                final Class<? extends ControllerService> serviceApi = descriptor.getControllerServiceDefinition();
                if (serviceApi != null && classLoader.equals(serviceApi.getClassLoader())) {
                    cobundledApis.add(serviceApi);
                }
            }
        }
    }

    if (!cobundledApis.isEmpty()) {
        logger.warn(String.format(
                "Component %s is bundled with its referenced Controller Service APIs %s. The service APIs should not be bundled with component implementations that reference it.",
                component.getClass().getName(), StringUtils.join(cobundledApis.stream().map(Class::getName).collect(Collectors.toSet()), ", ")));
    }

    // the component is eligible when it does not require instance classloading or when the supporting APIs are bundled in a parent NAR
    return requiresInstanceClassLoading == false || cobundledApis.isEmpty();
}
 
Example 4
Source File: StandardExtensionDiscoveringManager.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Find the bundle coordinates for any service APIs that are referenced by this component and not part of the same bundle.
 *
 * @param component the component being instantiated
 */
protected Set<BundleCoordinate> findReachableApiBundles(final ConfigurableComponent component) {
    final Set<BundleCoordinate> reachableApiBundles = new HashSet<>();

    try (final NarCloseable closeable = NarCloseable.withComponentNarLoader(component.getClass().getClassLoader())) {
        final List<PropertyDescriptor> descriptors = component.getPropertyDescriptors();
        if (descriptors != null && !descriptors.isEmpty()) {
            for (final PropertyDescriptor descriptor : descriptors) {
                final Class<? extends ControllerService> serviceApi = descriptor.getControllerServiceDefinition();
                if (serviceApi != null && !component.getClass().getClassLoader().equals(serviceApi.getClassLoader())) {
                    final Bundle apiBundle = classLoaderBundleLookup.get(serviceApi.getClassLoader());
                    reachableApiBundles.add(apiBundle.getBundleDetails().getCoordinate());
                }
            }
        }
    }

    return reachableApiBundles;
}
 
Example 5
Source File: HtmlDocumentationWriter.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Indicates whether or not the component contains at least one sensitive property.
 *
 * @param component the component to interogate
 * @return whether or not the component contains at least one sensitive property.
 */
private boolean containsSensitiveProperties(final ConfigurableComponent component) {
    for (PropertyDescriptor descriptor : component.getPropertyDescriptors()) {
        if (descriptor.isSensitive()) {
            return true;
        }
    }
    return false;
}
 
Example 6
Source File: HtmlDocumentationWriter.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Indicates whether or not the component contains at least one property that supports Expression Language.
 *
 * @param component the component to interogate
 * @return whether or not the component contains at least one sensitive property.
 */
private boolean containsExpressionLanguage(final ConfigurableComponent component) {
    for (PropertyDescriptor descriptor : component.getPropertyDescriptors()) {
        if (descriptor.isExpressionLanguageSupported()) {
            return true;
        }
    }
    return false;
}
 
Example 7
Source File: HtmlDocumentationWriter.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Indicates whether or not the component contains at least one sensitive property.
 *
 * @param component the component to interogate
 * @return whether or not the component contains at least one sensitive property.
 */
private boolean containsSensitiveProperties(final ConfigurableComponent component) {
    for (PropertyDescriptor descriptor : component.getPropertyDescriptors()) {
        if (descriptor.isSensitive()) {
            return true;
        }
    }
    return false;
}
 
Example 8
Source File: HtmlDocumentationWriter.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Indicates whether or not the component contains at least one property that supports Expression Language.
 *
 * @param component the component to interrogate
 * @return whether or not the component contains at least one sensitive property.
 */
private boolean containsExpressionLanguage(final ConfigurableComponent component) {
    for (PropertyDescriptor descriptor : component.getPropertyDescriptors()) {
        if (descriptor.isExpressionLanguageSupported()) {
            return true;
        }
    }
    return false;
}
 
Example 9
Source File: HtmlDocumentationWriter.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Writes the PropertyDescriptors out as a table.
 *
 * @param configurableComponent the component to describe
 * @param xmlStreamWriter the stream writer
 * @throws XMLStreamException thrown if there was a problem writing to the
 * XML Stream
 */
protected void writeProperties(final ConfigurableComponent configurableComponent,
        final XMLStreamWriter xmlStreamWriter) throws XMLStreamException {

    final List<PropertyDescriptor> properties = configurableComponent.getPropertyDescriptors();
    writeSimpleElement(xmlStreamWriter, "h3", "Properties: ");

    if (properties.size() > 0) {
        final boolean containsExpressionLanguage = containsExpressionLanguage(configurableComponent);
        final boolean containsSensitiveProperties = containsSensitiveProperties(configurableComponent);
        xmlStreamWriter.writeStartElement("p");
        xmlStreamWriter.writeCharacters("In the list below, the names of required properties appear in ");
        writeSimpleElement(xmlStreamWriter, "strong", "bold");
        xmlStreamWriter.writeCharacters(". Any other properties (not in bold) are considered optional. " +
                "The table also indicates any default values");
        if (containsExpressionLanguage) {
            if (!containsSensitiveProperties) {
                xmlStreamWriter.writeCharacters(", and ");
            } else {
                xmlStreamWriter.writeCharacters(", ");
            }
            xmlStreamWriter.writeCharacters("whether a property supports the ");
            writeLink(xmlStreamWriter, "NiFi Expression Language", "../../html/expression-language-guide.html");
        }
        if (containsSensitiveProperties) {
            xmlStreamWriter.writeCharacters(", and whether a property is considered " + "\"sensitive\", meaning that its value will be encrypted. Before entering a "
                    + "value in a sensitive property, ensure that the ");

            writeSimpleElement(xmlStreamWriter, "strong", "nifi.properties");
            xmlStreamWriter.writeCharacters(" file has " + "an entry for the property ");
            writeSimpleElement(xmlStreamWriter, "strong", "nifi.sensitive.props.key");
        }
        xmlStreamWriter.writeCharacters(".");
        xmlStreamWriter.writeEndElement();

        xmlStreamWriter.writeStartElement("table");
        xmlStreamWriter.writeAttribute("id", "properties");

        // write the header row
        xmlStreamWriter.writeStartElement("tr");
        writeSimpleElement(xmlStreamWriter, "th", "Name");
        writeSimpleElement(xmlStreamWriter, "th", "Default Value");
        writeSimpleElement(xmlStreamWriter, "th", "Allowable Values");
        writeSimpleElement(xmlStreamWriter, "th", "Description");
        xmlStreamWriter.writeEndElement();

        // write the individual properties
        for (PropertyDescriptor property : properties) {
            xmlStreamWriter.writeStartElement("tr");
            xmlStreamWriter.writeStartElement("td");
            xmlStreamWriter.writeAttribute("id", "name");
            if (property.isRequired()) {
                writeSimpleElement(xmlStreamWriter, "strong", property.getDisplayName());
            } else {
                xmlStreamWriter.writeCharacters(property.getDisplayName());
            }

            xmlStreamWriter.writeEndElement();
            writeSimpleElement(xmlStreamWriter, "td", property.getDefaultValue(), false, "default-value");
            xmlStreamWriter.writeStartElement("td");
            xmlStreamWriter.writeAttribute("id", "allowable-values");
            writeValidValues(xmlStreamWriter, property);
            xmlStreamWriter.writeEndElement();
            xmlStreamWriter.writeStartElement("td");
            xmlStreamWriter.writeAttribute("id", "description");
            if (property.getDescription() != null && property.getDescription().trim().length() > 0) {
                xmlStreamWriter.writeCharacters(property.getDescription());
            } else {
                xmlStreamWriter.writeCharacters("No Description Provided.");
            }

            if (property.isSensitive()) {
                xmlStreamWriter.writeEmptyElement("br");
                writeSimpleElement(xmlStreamWriter, "strong", "Sensitive Property: true");
            }

            if (property.isExpressionLanguageSupported()) {
                xmlStreamWriter.writeEmptyElement("br");
                writeSimpleElement(xmlStreamWriter, "strong", "Supports Expression Language: true");
            }
            xmlStreamWriter.writeEndElement();

            xmlStreamWriter.writeEndElement();
        }

        // TODO support dynamic properties...
        xmlStreamWriter.writeEndElement();

    } else {
        writeSimpleElement(xmlStreamWriter, "p", "This component has no required or optional properties.");
    }
}
 
Example 10
Source File: BaseScriptedLookupService.java    From nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a list of property descriptors supported by this processor. The
 * list always includes properties such as script engine name, script file
 * name, script body name, script arguments, and an external module path. If
 * the scripted processor also defines supported properties, those are added
 * to the list as well.
 *
 * @return a List of PropertyDescriptor objects supported by this processor
 */
@Override
protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {

    synchronized (scriptingComponentHelper.isInitialized) {
        if (!scriptingComponentHelper.isInitialized.get()) {
            scriptingComponentHelper.createResources();
        }
    }
    List<PropertyDescriptor> supportedPropertyDescriptors = new ArrayList<>();
    List<PropertyDescriptor> _temp = new ArrayList<>();
    _temp.addAll(scriptingComponentHelper.getDescriptors());
    _temp.remove(scriptingComponentHelper.SCRIPT_ENGINE);

    PropertyDescriptor.Builder jythonLessEngineProp = new PropertyDescriptor
            .Builder().fromPropertyDescriptor(scriptingComponentHelper.SCRIPT_ENGINE);
    List<AllowableValue> filtered = scriptingComponentHelper.getScriptEngineAllowableValues()
            .stream().filter(allowableValue -> !allowableValue.getValue().contains("ython"))
            .collect(Collectors.toList());
    jythonLessEngineProp.allowableValues(filtered.toArray(new AllowableValue[filtered.size()]));

    supportedPropertyDescriptors.add(jythonLessEngineProp.build());
    supportedPropertyDescriptors.addAll(_temp);

    final ConfigurableComponent instance = lookupService.get();
    if (instance != null) {
        try {
            final List<PropertyDescriptor> instanceDescriptors = instance.getPropertyDescriptors();
            if (instanceDescriptors != null) {
                supportedPropertyDescriptors.addAll(instanceDescriptors);
            }
        } catch (final Throwable t) {
            final ComponentLog logger = getLogger();
            final String message = "Unable to get property descriptors from Processor: " + t;

            logger.error(message);
            if (logger.isDebugEnabled()) {
                logger.error(message, t);
            }
        }
    }

    return Collections.unmodifiableList(supportedPropertyDescriptors);
}