org.apache.nifi.components.ConfigurableComponent Java Examples

The following examples show how to use org.apache.nifi.components.ConfigurableComponent. 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: HtmlDocumentationWriter.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Add in the documentation information regarding the component whether it accepts an
 * incoming relationship or not.
 *
 * @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 writeInputRequirementInfo(ConfigurableComponent configurableComponent, XMLStreamWriter xmlStreamWriter)
        throws XMLStreamException {
    final InputRequirement inputRequirement = configurableComponent.getClass().getAnnotation(InputRequirement.class);

    if(inputRequirement != null) {
        writeSimpleElement(xmlStreamWriter, "h3", "Input requirement: ");
        switch (inputRequirement.value()) {
            case INPUT_FORBIDDEN:
                xmlStreamWriter.writeCharacters("This component does not allow an incoming relationship.");
                break;
            case INPUT_ALLOWED:
                xmlStreamWriter.writeCharacters("This component allows an incoming relationship.");
                break;
            case INPUT_REQUIRED:
                xmlStreamWriter.writeCharacters("This component requires an incoming relationship.");
                break;
            default:
                xmlStreamWriter.writeCharacters("This component does not have input requirement.");
                break;
        }
    }
}
 
Example #2
Source File: HtmlDocumentationWriter.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public void write(final ConfigurableComponent configurableComponent, final OutputStream streamToWriteTo,
        final boolean includesAdditionalDocumentation) throws IOException {

    try {
        XMLStreamWriter xmlStreamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(
                streamToWriteTo, "UTF-8");
        xmlStreamWriter.writeDTD("<!DOCTYPE html>");
        xmlStreamWriter.writeStartElement("html");
        xmlStreamWriter.writeAttribute("lang", "en");
        writeHead(configurableComponent, xmlStreamWriter);
        writeBody(configurableComponent, xmlStreamWriter, includesAdditionalDocumentation);
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.close();
    } catch (XMLStreamException | FactoryConfigurationError e) {
        throw new IOException("Unable to create XMLOutputStream", e);
    }
}
 
Example #3
Source File: DocGenerator.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * 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 ExtensionManager extensionManager,
                             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(extensionManager, 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));
    }
}
 
Example #4
Source File: BaseScriptedLookupService.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Handles changes to this processor's properties. If changes are made to
 * script- or engine-related properties, the script will be reloaded.
 *
 * @param descriptor of the modified property
 * @param oldValue   non-null property value (previous)
 * @param newValue   the new property value or if null indicates the property
 */
@Override
public void onPropertyModified(final PropertyDescriptor descriptor, final String oldValue, final String newValue) {
    final ComponentLog logger = getLogger();
    final ConfigurableComponent instance = lookupService.get();

    if (ScriptingComponentUtils.SCRIPT_FILE.equals(descriptor)
            || ScriptingComponentUtils.SCRIPT_BODY.equals(descriptor)
            || ScriptingComponentUtils.MODULES.equals(descriptor)
            || scriptingComponentHelper.SCRIPT_ENGINE.equals(descriptor)) {
        scriptNeedsReload.set(true);
        // Need to reset scriptEngine if the value has changed
        if (scriptingComponentHelper.SCRIPT_ENGINE.equals(descriptor)) {
            scriptEngine = null;
        }
    } else if (instance != null) {
        // If the script provides a ConfigurableComponent, call its onPropertyModified() method
        try {
            instance.onPropertyModified(descriptor, oldValue, newValue);
        } catch (final Exception e) {
            final String message = "Unable to invoke onPropertyModified from scripted LookupService: " + e;
            logger.error(message, e);
        }
    }
}
 
Example #5
Source File: DocGenerator.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Generates documentation into the work/docs dir specified by
 * NiFiProperties.
 *
 * @param properties to lookup nifi properties
 */
public static void generate(final NiFiProperties properties) {
    @SuppressWarnings("rawtypes")
    final Set<Class> extensionClasses = new HashSet<>();
    extensionClasses.addAll(ExtensionManager.getExtensions(Processor.class));
    extensionClasses.addAll(ExtensionManager.getExtensions(ControllerService.class));
    extensionClasses.addAll(ExtensionManager.getExtensions(ReportingTask.class));

    final File explodedNiFiDocsDir = properties.getComponentDocumentationWorkingDirectory();

    logger.debug("Generating documentation for: " + extensionClasses.size() + " components in: "
            + explodedNiFiDocsDir);

    for (final Class<?> extensionClass : extensionClasses) {
        if (ConfigurableComponent.class.isAssignableFrom(extensionClass)) {
            final Class<? extends ConfigurableComponent> componentClass = extensionClass.asSubclass(ConfigurableComponent.class);
            try {
                logger.debug("Documenting: " + componentClass);
                document(explodedNiFiDocsDir, componentClass);
            } catch (Exception e) {
                logger.warn("Unable to document: " + componentClass, e);
            }
        }
    }
}
 
Example #6
Source File: FingerprintFactory.java    From nifi with Apache License 2.0 6 votes vote down vote up
private void addReportingTaskFingerprint(final StringBuilder builder, final ReportingTaskDTO dto) {
    builder.append(dto.getId());
    builder.append(dto.getType());
    builder.append(dto.getName());

    addBundleFingerprint(builder, dto.getBundle());

    builder.append(dto.getComments());
    builder.append(dto.getSchedulingPeriod());
    builder.append(dto.getSchedulingStrategy());
    builder.append(dto.getAnnotationData());

    // get the temp instance of the ReportingTask so that we know the default property values
    final BundleCoordinate coordinate = getCoordinate(dto.getType(), dto.getBundle());
    final ConfigurableComponent configurableComponent = extensionManager.getTempComponent(dto.getType(), coordinate);
    if (configurableComponent == null) {
        logger.warn("Unable to get ReportingTask of type {}; its default properties will be fingerprinted instead of being ignored.", dto.getType());
    }

    addPropertiesFingerprint(builder, configurableComponent, dto.getProperties());
}
 
Example #7
Source File: StandardControllerServiceDAO.java    From nifi with Apache License 2.0 6 votes vote down vote up
private void updateBundle(final ControllerServiceNode controllerService, final ControllerServiceDTO controllerServiceDTO) {
    final BundleDTO bundleDTO = controllerServiceDTO.getBundle();
    if (bundleDTO != null) {
        final ExtensionManager extensionManager = serviceProvider.getExtensionManager();
        final BundleCoordinate incomingCoordinate = BundleUtils.getBundle(extensionManager, controllerService.getCanonicalClassName(), bundleDTO);
        final BundleCoordinate existingCoordinate = controllerService.getBundleCoordinate();
        if (!existingCoordinate.getCoordinate().equals(incomingCoordinate.getCoordinate())) {
            try {
                // we need to use the property descriptors from the temp component here in case we are changing from a ghost component to a real component
                final ConfigurableComponent tempComponent = extensionManager.getTempComponent(controllerService.getCanonicalClassName(), incomingCoordinate);
                final Set<URL> additionalUrls = controllerService.getAdditionalClasspathResources(tempComponent.getPropertyDescriptors());
                flowController.getReloadComponent().reload(controllerService, controllerService.getCanonicalClassName(), incomingCoordinate, additionalUrls);
            } catch (ControllerServiceInstantiationException e) {
                throw new NiFiCoreException(String.format("Unable to update controller service %s from %s to %s due to: %s",
                        controllerServiceDTO.getId(), controllerService.getBundleCoordinate().getCoordinate(), incomingCoordinate.getCoordinate(), e.getMessage()), e);
            }
        }
    }
}
 
Example #8
Source File: FlowUpdateResource.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Authorize read/write permissions for the given user on every component of the given flow in support of flow update.
 *
 * @param lookup        A lookup instance to use for retrieving components for authorization purposes
 * @param user          the user to authorize
 * @param groupId       the id of the process group being evaluated
 * @param flowSnapshot  the new flow contents to examine for restricted components
 */
protected void authorizeFlowUpdate(final AuthorizableLookup lookup, final NiFiUser user, final String groupId,
                                   final VersionedFlowSnapshot flowSnapshot) {
    // Step 2: Verify READ and WRITE permissions for user, for every component.
    final ProcessGroupAuthorizable groupAuthorizable = lookup.getProcessGroup(groupId);
    authorizeProcessGroup(groupAuthorizable, authorizer, lookup, RequestAction.READ, true,
            false, true, true, true);
    authorizeProcessGroup(groupAuthorizable, authorizer, lookup, RequestAction.WRITE, true,
            false, true, true, false);

    final VersionedProcessGroup groupContents = flowSnapshot.getFlowContents();
    final Set<ConfigurableComponent> restrictedComponents = FlowRegistryUtils.getRestrictedComponents(groupContents, serviceFacade);
    restrictedComponents.forEach(restrictedComponent -> {
        final ComponentAuthorizable restrictedComponentAuthorizable = lookup.getConfigurableComponent(restrictedComponent);
        authorizeRestrictions(authorizer, restrictedComponentAuthorizable);
    });

    final Map<String, VersionedParameterContext> parameterContexts = flowSnapshot.getParameterContexts();
    if (parameterContexts != null) {
        parameterContexts.values().forEach(
                context -> AuthorizeParameterReference.authorizeParameterContextAddition(context, serviceFacade, authorizer, lookup, user)
        );
    }
}
 
Example #9
Source File: FlowRegistryUtils.java    From nifi with Apache License 2.0 6 votes vote down vote up
public static Set<ConfigurableComponent> getRestrictedComponents(final VersionedProcessGroup group, final NiFiServiceFacade serviceFacade) {
    final Set<ConfigurableComponent> restrictedComponents = new HashSet<>();

    final Set<Tuple<String, BundleCoordinate>> componentTypes = new HashSet<>();
    populateComponentTypes(group, componentTypes);

    for (final Tuple<String, BundleCoordinate> tuple : componentTypes) {
        final ConfigurableComponent component = serviceFacade.getTempComponent(tuple.getKey(), tuple.getValue());
        if (component == null) {
            throw new NiFiCoreException("Could not create an instance of component " + tuple.getKey() + " using bundle coordinates " + tuple.getValue());
        }

        final boolean isRestricted = component.getClass().isAnnotationPresent(Restricted.class);
        if (isRestricted) {
            restrictedComponents.add(component);
        }
    }

    return restrictedComponents;
}
 
Example #10
Source File: HtmlDocumentationWriter.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Write the description of the Stateful annotation if provided in 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 writeStatefulInfo(ConfigurableComponent configurableComponent, XMLStreamWriter xmlStreamWriter)
        throws XMLStreamException {
    final Stateful stateful = configurableComponent.getClass().getAnnotation(Stateful.class);

    writeSimpleElement(xmlStreamWriter, "h3", "State management: ");

    if(stateful != null) {
        xmlStreamWriter.writeStartElement("table");
        xmlStreamWriter.writeAttribute("id", "stateful");
        xmlStreamWriter.writeStartElement("tr");
        writeSimpleElement(xmlStreamWriter, "th", "Scope");
        writeSimpleElement(xmlStreamWriter, "th", "Description");
        xmlStreamWriter.writeEndElement();

        xmlStreamWriter.writeStartElement("tr");
        writeSimpleElement(xmlStreamWriter, "td", join(stateful.scopes(), ", "));
        writeSimpleElement(xmlStreamWriter, "td", stateful.description());
        xmlStreamWriter.writeEndElement();

        xmlStreamWriter.writeEndElement();
    } else {
        xmlStreamWriter.writeCharacters("This component does not store state.");
    }
}
 
Example #11
Source File: HtmlDocumentationWriter.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Writes the body section of the documentation, this consists of the
 * component description, the tags, and the PropertyDescriptors.
 *
 * @param configurableComponent the component to describe
 * @param xmlStreamWriter the stream writer
 * @param hasAdditionalDetails whether there are additional details present
 * or not
 * @throws XMLStreamException thrown if there was a problem writing to the
 * XML stream
 */
private void writeBody(final ConfigurableComponent configurableComponent,
        final XMLStreamWriter xmlStreamWriter, final boolean hasAdditionalDetails)
        throws XMLStreamException {
    xmlStreamWriter.writeStartElement("body");
    writeHeader(configurableComponent, xmlStreamWriter);
    writeDeprecationWarning(configurableComponent, xmlStreamWriter);
    writeDescription(configurableComponent, xmlStreamWriter, hasAdditionalDetails);
    writeTags(configurableComponent, xmlStreamWriter);
    writeProperties(configurableComponent, xmlStreamWriter);
    writeDynamicProperties(configurableComponent, xmlStreamWriter);
    writeAdditionalBodyInfo(configurableComponent, xmlStreamWriter);
    writeStatefulInfo(configurableComponent, xmlStreamWriter);
    writeRestrictedInfo(configurableComponent, xmlStreamWriter);
    writeInputRequirementInfo(configurableComponent, xmlStreamWriter);
    writeSystemResourceConsiderationInfo(configurableComponent, xmlStreamWriter);
    writeSeeAlso(configurableComponent, xmlStreamWriter);
    xmlStreamWriter.writeEndElement();
}
 
Example #12
Source File: HtmlDocumentationWriter.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
    }
}
 
Example #13
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 #14
Source File: ExtensionBuilder.java    From nifi with Apache License 2.0 6 votes vote down vote up
private <T extends ConfigurableComponent> LoggableComponent<T> createLoggableComponent(Class<T> nodeType) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
    final ClassLoader ctxClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        final Bundle bundle = extensionManager.getBundle(bundleCoordinate);
        if (bundle == null) {
            throw new IllegalStateException("Unable to find bundle for coordinate " + bundleCoordinate.getCoordinate());
        }

        final ClassLoader detectedClassLoader = extensionManager.createInstanceClassLoader(type, identifier, bundle, classpathUrls == null ? Collections.emptySet() : classpathUrls);
        final Class<?> rawClass = Class.forName(type, true, detectedClassLoader);
        Thread.currentThread().setContextClassLoader(detectedClassLoader);

        final Object extensionInstance = rawClass.newInstance();
        final ComponentLog componentLog = new SimpleProcessLogger(identifier, extensionInstance);
        final TerminationAwareLogger terminationAwareLogger = new TerminationAwareLogger(componentLog);

        final T cast = nodeType.cast(extensionInstance);
        return new LoggableComponent<>(cast, bundleCoordinate, terminationAwareLogger);
    } finally {
        if (ctxClassLoader != null) {
            Thread.currentThread().setContextClassLoader(ctxClassLoader);
        }
    }
}
 
Example #15
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 #16
Source File: AbstractDocumentationWriter.java    From nifi with Apache License 2.0 6 votes vote down vote up
protected void writeBody(final ConfigurableComponent component, Map<String,ServiceAPI> propertyServices) throws IOException {
    writeExtensionName(component.getClass().getName());
    writeExtensionType(getExtensionType(component));
    writeDeprecationNotice(component.getClass().getAnnotation(DeprecationNotice.class));
    writeDescription(getDescription(component));
    writeTags(getTags(component));
    writeProperties(component.getPropertyDescriptors(), propertyServices);
    writeDynamicProperties(getDynamicProperties(component));

    if (component instanceof Processor) {
        final Processor processor = (Processor) component;

        writeRelationships(processor.getRelationships());
        writeDynamicRelationship(getDynamicRelationship(processor));
        writeReadsAttributes(getReadsAttributes(processor));
        writeWritesAttributes(getWritesAttributes(processor));
    }

    writeStatefulInfo(component.getClass().getAnnotation(Stateful.class));
    writeRestrictedInfo(component.getClass().getAnnotation(Restricted.class));
    writeInputRequirementInfo(getInputRequirement(component));
    writeSystemResourceConsiderationInfo(getSystemResourceConsiderations(component));
    writeSeeAlso(component.getClass().getAnnotation(SeeAlso.class));
}
 
Example #17
Source File: StandardReportingTaskDAO.java    From nifi with Apache License 2.0 6 votes vote down vote up
private void updateBundle(ReportingTaskNode reportingTask, ReportingTaskDTO reportingTaskDTO) {
    final BundleDTO bundleDTO = reportingTaskDTO.getBundle();
    if (bundleDTO != null) {
        final ExtensionManager extensionManager = reportingTaskProvider.getExtensionManager();
        final BundleCoordinate incomingCoordinate = BundleUtils.getBundle(extensionManager, reportingTask.getCanonicalClassName(), bundleDTO);
        final BundleCoordinate existingCoordinate = reportingTask.getBundleCoordinate();
        if (!existingCoordinate.getCoordinate().equals(incomingCoordinate.getCoordinate())) {
            try {
                // we need to use the property descriptors from the temp component here in case we are changing from a ghost component to a real component
                final ConfigurableComponent tempComponent = extensionManager.getTempComponent(reportingTask.getCanonicalClassName(), incomingCoordinate);
                final Set<URL> additionalUrls = reportingTask.getAdditionalClasspathResources(tempComponent.getPropertyDescriptors());
                reloadComponent.reload(reportingTask, reportingTask.getCanonicalClassName(), incomingCoordinate, additionalUrls);
            } catch (ReportingTaskInstantiationException e) {
                throw new NiFiCoreException(String.format("Unable to update reporting task %s from %s to %s due to: %s",
                        reportingTaskDTO.getId(), reportingTask.getBundleCoordinate().getCoordinate(), incomingCoordinate.getCoordinate(), e.getMessage()), e);
            }
        }
    }
}
 
Example #18
Source File: HtmlDocumentationWriter.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Writes a description of the configurable component.
 *
 * @param configurableComponent the component to describe
 * @param xmlStreamWriter the stream writer
 * @param hasAdditionalDetails whether there are additional details
 * available as 'additionalDetails.html'
 * @throws XMLStreamException thrown if there was a problem writing to the
 * XML stream
 */
protected void writeDescription(final ConfigurableComponent configurableComponent,
        final XMLStreamWriter xmlStreamWriter, final boolean hasAdditionalDetails)
        throws XMLStreamException {
    writeSimpleElement(xmlStreamWriter, "h2", "Description: ");
    writeSimpleElement(xmlStreamWriter, "p", getDescription(configurableComponent));
    if (hasAdditionalDetails) {
        xmlStreamWriter.writeStartElement("p");

        writeLink(xmlStreamWriter, "Additional Details...", ADDITIONAL_DETAILS_HTML);

        xmlStreamWriter.writeEndElement();
    }
}
 
Example #19
Source File: ProcessorInitializer.java    From nifi-minifi with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example #20
Source File: ProcessorInitializer.java    From nifi-minifi with Apache License 2.0 5 votes vote down vote up
@Override
public void teardown(ConfigurableComponent component) {
    Processor processor = (Processor) component;
    try (NarCloseable narCloseable = NarCloseable.withComponentNarLoader(component.getClass(), component.getIdentifier())) {

        final ComponentLog logger = new MockComponentLogger();
        final MockProcessContext context = new MockProcessContext();
        ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnShutdown.class, processor, logger, context);
    } finally {
        ExtensionManager.removeInstanceClassLoader(component.getIdentifier());
    }
}
 
Example #21
Source File: ReportingTaskingInitializer.java    From nifi-minifi with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(ConfigurableComponent component) throws InitializationException {
    ReportingTask reportingTask = (ReportingTask) component;
    ReportingInitializationContext context = new MockReportingInitializationContext();
    try (NarCloseable narCloseable = NarCloseable.withComponentNarLoader(component.getClass(), context.getIdentifier())) {
        reportingTask.initialize(context);
    }
}
 
Example #22
Source File: AbstractDocumentationWriter.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(final ConfigurableComponent component) {
    try {
        if (component instanceof Processor) {
            initialize((Processor) component);
        } else if (component instanceof ControllerService) {
            initialize((ControllerService) component);
        } else if (component instanceof ReportingTask) {
            initialize((ReportingTask) component);
        }
    } catch (final InitializationException ie) {
        throw new RuntimeException("Failed to initialize " + component, ie);
    }
}
 
Example #23
Source File: ReportingTaskingInitializer.java    From nifi-minifi with Apache License 2.0 5 votes vote down vote up
@Override
public void teardown(ConfigurableComponent component) {
    ReportingTask reportingTask = (ReportingTask) component;
    try (NarCloseable narCloseable = NarCloseable.withComponentNarLoader(component.getClass(), component.getIdentifier())) {

        final MockConfigurationContext context = new MockConfigurationContext();
        ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnShutdown.class, reportingTask, new MockComponentLogger(), context);
    } finally {
        ExtensionManager.removeInstanceClassLoader(component.getIdentifier());
    }
}
 
Example #24
Source File: ExtensionManager.java    From nifi-minifi with Apache License 2.0 5 votes vote down vote up
private static void initializeTempComponent(final ConfigurableComponent configurableComponent) {
    ConfigurableComponentInitializer initializer = null;
    try {
        initializer = ConfigurableComponentInitializerFactory.createComponentInitializer(configurableComponent.getClass());
        initializer.initialize(configurableComponent);
    } catch (final InitializationException e) {
        logger.warn(String.format("Unable to initialize component %s due to %s", configurableComponent.getClass().getName(), e.getMessage()));
    }
}
 
Example #25
Source File: DocGenerator.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the DocumentationWriter for the type of component. Currently
 * Processor, ControllerService, and ReportingTask are supported.
 *
 * @param componentClass the class that requires a DocumentationWriter
 * @return a DocumentationWriter capable of generating documentation for
 * that specific type of class
 */
private static DocumentationWriter getDocumentWriter(final ExtensionManager extensionManager,
                                                              final Class<? extends ConfigurableComponent> componentClass) {
    if (Processor.class.isAssignableFrom(componentClass)) {
        return new HtmlProcessorDocumentationWriter(extensionManager);
    } else if (ControllerService.class.isAssignableFrom(componentClass)) {
        return new HtmlDocumentationWriter(extensionManager);
    } else if (ReportingTask.class.isAssignableFrom(componentClass)) {
        return new HtmlDocumentationWriter(extensionManager);
    }

    return null;
}
 
Example #26
Source File: HtmlDocumentationWriter.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a description of the ConfigurableComponent using the
 * CapabilityDescription annotation.
 *
 * @param configurableComponent the component to describe
 * @return a description of the configurableComponent
 */
protected String getDescription(final ConfigurableComponent configurableComponent) {
    final CapabilityDescription capabilityDescription = configurableComponent.getClass().getAnnotation(
            CapabilityDescription.class);

    final String description;
    if (capabilityDescription != null) {
        description = capabilityDescription.value();
    } else {
        description = "No description provided.";
    }

    return description;
}
 
Example #27
Source File: ConfigurableComponentInitializerFactory.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a ConfigurableComponentInitializer for the type of component.
 * Currently Processor, ControllerService and ReportingTask are supported.
 *
 * @param componentClass the class that requires a ConfigurableComponentInitializer
 * @return a ConfigurableComponentInitializer capable of initializing that specific type of class
 */
public static ConfigurableComponentInitializer createComponentInitializer(
        final ExtensionManager extensionManager, final Class<? extends ConfigurableComponent> componentClass) {
    if (Processor.class.isAssignableFrom(componentClass)) {
        return new ProcessorInitializer(extensionManager);
    } else if (ControllerService.class.isAssignableFrom(componentClass)) {
        return new ControllerServiceInitializer(extensionManager);
    } else if (ReportingTask.class.isAssignableFrom(componentClass)) {
        return new ReportingTaskingInitializer(extensionManager);
    }

    return null;
}
 
Example #28
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 #29
Source File: AbstractDocumentationWriter.java    From nifi with Apache License 2.0 5 votes vote down vote up
protected List<String> getTags(final ConfigurableComponent component) {
    final Tags tags = component.getClass().getAnnotation(Tags.class);
    if (tags == null) {
        return Collections.emptyList();
    }

    final String[] tagValues = tags.value();
    return tagValues == null ? Collections.emptyList() : Arrays.asList(tagValues);
}
 
Example #30
Source File: StandardAuthorizableLookup.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public ComponentAuthorizable getConfigurableComponent(ConfigurableComponent configurableComponent) {
    try {
        return new ConfigurableComponentAuthorizable(configurableComponent, controllerFacade.getExtensionManager());
    } catch (final Exception e) {
        throw new AccessDeniedException("Unable to create component to verify if it references any Controller Services.");
    }
}