Search in sources :

Example 6 with ConfigurableComponent

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

the class FingerprintFactory method addFlowFileProcessorFingerprint.

private StringBuilder addFlowFileProcessorFingerprint(final StringBuilder builder, final Element processorElem) throws FingerprintException {
    // id
    appendFirstValue(builder, DomUtils.getChildNodesByTagName(processorElem, "id"));
    appendFirstValue(builder, DomUtils.getChildNodesByTagName(processorElem, "versionedComponentId"));
    // class
    final NodeList childNodes = DomUtils.getChildNodesByTagName(processorElem, "class");
    final String className = childNodes.item(0).getTextContent();
    appendFirstValue(builder, childNodes);
    // annotation data
    appendFirstValue(builder, DomUtils.getChildNodesByTagName(processorElem, "annotationData"));
    // get the bundle details if possible
    final BundleDTO bundle = FlowFromDOMFactory.getBundle(DomUtils.getChild(processorElem, "bundle"));
    addBundleFingerprint(builder, bundle);
    // max concurrent tasks
    appendFirstValue(builder, DomUtils.getChildNodesByTagName(processorElem, "maxConcurrentTasks"));
    // scheduling period
    appendFirstValue(builder, DomUtils.getChildNodesByTagName(processorElem, "schedulingPeriod"));
    // penalization period
    appendFirstValue(builder, DomUtils.getChildNodesByTagName(processorElem, "penalizationPeriod"));
    // yield period
    appendFirstValue(builder, DomUtils.getChildNodesByTagName(processorElem, "yieldPeriod"));
    // bulletin level
    appendFirstValue(builder, DomUtils.getChildNodesByTagName(processorElem, "bulletinLevel"));
    // loss tolerant
    appendFirstValue(builder, DomUtils.getChildNodesByTagName(processorElem, "lossTolerant"));
    // scheduling strategy
    appendFirstValue(builder, DomUtils.getChildNodesByTagName(processorElem, "schedulingStrategy"));
    // execution node
    appendFirstValue(builder, DomUtils.getChildNodesByTagName(processorElem, "executionNode"));
    // run duration nanos
    appendFirstValue(builder, DomUtils.getChildNodesByTagName(processorElem, "runDurationNanos"));
    // get the temp instance of the Processor so that we know the default property values
    final BundleCoordinate coordinate = getCoordinate(className, bundle);
    final ConfigurableComponent configurableComponent = ExtensionManager.getTempComponent(className, coordinate);
    if (configurableComponent == null) {
        logger.warn("Unable to get Processor of type {}; its default properties will be fingerprinted instead of being ignored.", className);
    }
    // properties
    final NodeList propertyElems = DomUtils.getChildNodesByTagName(processorElem, "property");
    final List<Element> sortedPropertyElems = sortElements(propertyElems, getProcessorPropertiesComparator());
    for (final Element propertyElem : sortedPropertyElems) {
        final String propName = DomUtils.getChildElementsByTagName(propertyElem, "name").get(0).getTextContent();
        String propValue = getFirstValue(DomUtils.getChildNodesByTagName(propertyElem, "value"), null);
        addPropertyFingerprint(builder, configurableComponent, propName, propValue);
    }
    final NodeList autoTerminateElems = DomUtils.getChildNodesByTagName(processorElem, "autoTerminatedRelationship");
    final List<Element> sortedAutoTerminateElems = sortElements(autoTerminateElems, getElementTextComparator());
    for (final Element autoTerminateElem : sortedAutoTerminateElems) {
        builder.append(autoTerminateElem.getTextContent());
    }
    return builder;
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) ConfigurableComponent(org.apache.nifi.components.ConfigurableComponent) BundleDTO(org.apache.nifi.web.api.dto.BundleDTO) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate)

Example 7 with ConfigurableComponent

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

the class DocGenerator method document.

/**
 * Generates the documentation for a particular configurable component. Will
 * check to see if an "additionalDetails.html" file exists and will link
 * that from the generated documentation.
 *
 * @param componentDocsDir the component documentation directory
 * @param componentClass the class to document
 * @throws InstantiationException ie
 * @throws IllegalAccessException iae
 * @throws IOException ioe
 * @throws InitializationException ie
 */
private static void document(final File componentDocsDir, final Class<? extends ConfigurableComponent> componentClass, final BundleCoordinate bundleCoordinate) throws InstantiationException, IllegalAccessException, IOException, InitializationException {
    // use temp components from ExtensionManager which should always be populated before doc generation
    final String classType = componentClass.getCanonicalName();
    final ConfigurableComponent component = ExtensionManager.getTempComponent(classType, bundleCoordinate);
    final DocumentationWriter writer = getDocumentWriter(componentClass);
    final File baseDocumentationFile = new File(componentDocsDir, "index.html");
    if (baseDocumentationFile.exists()) {
        logger.warn(baseDocumentationFile + " already exists, overwriting!");
    }
    try (final OutputStream output = new BufferedOutputStream(new FileOutputStream(baseDocumentationFile))) {
        writer.write(component, output, hasAdditionalInfo(componentDocsDir));
    }
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileOutputStream(java.io.FileOutputStream) HtmlDocumentationWriter(org.apache.nifi.documentation.html.HtmlDocumentationWriter) HtmlProcessorDocumentationWriter(org.apache.nifi.documentation.html.HtmlProcessorDocumentationWriter) ConfigurableComponent(org.apache.nifi.components.ConfigurableComponent) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 8 with ConfigurableComponent

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

the class HtmlDocumentationWriter method writeSeeAlso.

/**
 * Writes the list of components that may be linked from this component.
 *
 * @param configurableComponent the component to describe
 * @param xmlStreamWriter the stream writer to use
 * @throws XMLStreamException thrown if there was a problem writing the XML
 */
private void writeSeeAlso(ConfigurableComponent configurableComponent, XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
    final SeeAlso seeAlso = configurableComponent.getClass().getAnnotation(SeeAlso.class);
    if (seeAlso != null) {
        writeSimpleElement(xmlStreamWriter, "h3", "See Also:");
        xmlStreamWriter.writeStartElement("p");
        Class<? extends ConfigurableComponent>[] componentNames = seeAlso.value();
        String[] classNames = seeAlso.classNames();
        if (componentNames.length > 0 || classNames.length > 0) {
            // Write alternatives
            iterateAndLinkComponents(xmlStreamWriter, componentNames, classNames, ", ", configurableComponent.getClass().getSimpleName());
        } else {
            xmlStreamWriter.writeCharacters("No tags provided.");
        }
        xmlStreamWriter.writeEndElement();
    }
}
Also used : SeeAlso(org.apache.nifi.annotation.documentation.SeeAlso) ConfigurableComponent(org.apache.nifi.components.ConfigurableComponent)

Example 9 with ConfigurableComponent

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

the class HtmlDocumentationWriter method writeDeprecationWarning.

/**
 * Writes a warning about the deprecation of a component.
 *
 * @param configurableComponent the component to describe
 * @param xmlStreamWriter the stream writer
 * @throws XMLStreamException thrown if there was a problem writing to the
 * XML stream
 */
private void writeDeprecationWarning(final ConfigurableComponent configurableComponent, final XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
    final DeprecationNotice deprecationNotice = configurableComponent.getClass().getAnnotation(DeprecationNotice.class);
    if (deprecationNotice != null) {
        xmlStreamWriter.writeStartElement("h2");
        xmlStreamWriter.writeCharacters("Deprecation notice: ");
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeStartElement("p");
        xmlStreamWriter.writeCharacters("");
        if (!StringUtils.isEmpty(deprecationNotice.reason())) {
            xmlStreamWriter.writeCharacters(deprecationNotice.reason());
        } else {
            // Write a default note
            xmlStreamWriter.writeCharacters("Please be aware this processor is deprecated and may be removed in " + "the near future.");
        }
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeStartElement("p");
        xmlStreamWriter.writeCharacters("Please consider using one the following alternatives: ");
        Class<? extends ConfigurableComponent>[] componentNames = deprecationNotice.alternatives();
        String[] classNames = deprecationNotice.classNames();
        if (componentNames.length > 0 || classNames.length > 0) {
            // Write alternatives
            iterateAndLinkComponents(xmlStreamWriter, componentNames, classNames, ",", configurableComponent.getClass().getSimpleName());
        } else {
            xmlStreamWriter.writeCharacters("No alternative components suggested.");
        }
        xmlStreamWriter.writeEndElement();
    }
}
Also used : DeprecationNotice(org.apache.nifi.annotation.documentation.DeprecationNotice) ConfigurableComponent(org.apache.nifi.components.ConfigurableComponent)

Example 10 with ConfigurableComponent

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

the class ExtensionManager method loadExtensions.

/**
 * Loads extensions from the specified bundle.
 *
 * @param bundle from which to load extensions
 */
@SuppressWarnings("unchecked")
private static void loadExtensions(final Bundle bundle) {
    for (final Map.Entry<Class, Set<Class>> entry : definitionMap.entrySet()) {
        final boolean isControllerService = ControllerService.class.equals(entry.getKey());
        final boolean isProcessor = Processor.class.equals(entry.getKey());
        final boolean isReportingTask = ReportingTask.class.equals(entry.getKey());
        final ServiceLoader<?> serviceLoader = ServiceLoader.load(entry.getKey(), bundle.getClassLoader());
        for (final Object o : serviceLoader) {
            // create a cache of temp ConfigurableComponent instances, the initialize here has to happen before the checks below
            if ((isControllerService || isProcessor || isReportingTask) && o instanceof ConfigurableComponent) {
                final ConfigurableComponent configurableComponent = (ConfigurableComponent) o;
                initializeTempComponent(configurableComponent);
                final String cacheKey = getClassBundleKey(o.getClass().getCanonicalName(), bundle.getBundleDetails().getCoordinate());
                tempComponentLookup.put(cacheKey, (ConfigurableComponent) o);
            }
            // only consider extensions discovered directly in this bundle
            boolean registerExtension = bundle.getClassLoader().equals(o.getClass().getClassLoader());
            if (registerExtension) {
                final Class extensionType = o.getClass();
                if (isControllerService && !checkControllerServiceEligibility(extensionType)) {
                    registerExtension = false;
                    logger.error(String.format("Skipping Controller Service %s because it is bundled with its supporting APIs and requires instance class loading.", extensionType.getName()));
                }
                final boolean canReferenceControllerService = (isControllerService || isProcessor || isReportingTask) && o instanceof ConfigurableComponent;
                if (canReferenceControllerService && !checkControllerServiceReferenceEligibility((ConfigurableComponent) o, bundle.getClassLoader())) {
                    registerExtension = false;
                    logger.error(String.format("Skipping component %s because it is bundled with its referenced Controller Service APIs and requires instance class loading.", extensionType.getName()));
                }
                if (registerExtension) {
                    registerServiceClass(o.getClass(), classNameBundleLookup, bundle, entry.getValue());
                }
            }
        }
        classLoaderBundleLookup.put(bundle.getClassLoader(), bundle);
    }
}
Also used : HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) ConfigurableComponent(org.apache.nifi.components.ConfigurableComponent) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

ConfigurableComponent (org.apache.nifi.components.ConfigurableComponent)20 BundleCoordinate (org.apache.nifi.bundle.BundleCoordinate)9 LinkedHashSet (java.util.LinkedHashSet)6 URL (java.net.URL)5 HashSet (java.util.HashSet)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Set (java.util.Set)4 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 IOException (java.io.IOException)3 Consumes (javax.ws.rs.Consumes)3 POST (javax.ws.rs.POST)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 AccessDeniedException (org.apache.nifi.authorization.AccessDeniedException)3 NiFiCoreException (org.apache.nifi.web.NiFiCoreException)3 BundleDTO (org.apache.nifi.web.api.dto.BundleDTO)3 Api (io.swagger.annotations.Api)2 ApiParam (io.swagger.annotations.ApiParam)2