Java源码示例:org.apache.nifi.components.ConfigurableComponent

示例1
/**
 * 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);
            }
        }
    }
}
 
示例2
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);
            }
        }
    }
}
 
示例3
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;
}
 
示例4
/**
 * 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.");
    }
}
 
示例5
/**
 * 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;
        }
    }
}
 
示例6
/**
 * 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();
    }
}
 
示例7
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();
}
 
示例8
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);
        }
    }
}
 
示例9
/**
 * 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;
}
 
示例10
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));
}
 
示例11
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);
            }
        }
    }
}
 
示例12
/**
 * 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)
        );
    }
}
 
示例13
/**
 * 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);
        }
    }
}
 
示例14
/**
 * 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));
    }
}
 
示例15
@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);
    }
}
 
示例16
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());
}
 
示例17
/**
 * 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();
}
 
示例18
@Override
public void teardown(ConfigurableComponent component) {
    ReportingTask reportingTask = (ReportingTask) component;
    try (NarCloseable narCloseable = NarCloseable.withComponentNarLoader(extensionManager, component.getClass(), component.getIdentifier())) {

        final MockConfigurationContext context = new MockConfigurationContext();
        ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnShutdown.class, reportingTask, new MockComponentLogger(), context);
    } finally {
        extensionManager.removeInstanceClassLoader(component.getIdentifier());
    }
}
 
示例19
@Override
public void initialize(ConfigurableComponent component) throws InitializationException {
    ReportingTask reportingTask = (ReportingTask) component;
    ReportingInitializationContext context = new MockReportingInitializationContext();
    try (NarCloseable narCloseable = NarCloseable.withComponentNarLoader(extensionManager, component.getClass(), context.getIdentifier())) {
        reportingTask.initialize(context);
    }
}
 
示例20
@Override
public void teardown(ConfigurableComponent component) {
    try (NarCloseable narCloseable = NarCloseable.withComponentNarLoader(component.getClass(), component.getIdentifier())) {
        ControllerService controllerService = (ControllerService) component;

        final ComponentLog logger = new MockComponentLogger();
        final MockConfigurationContext context = new MockConfigurationContext();
        ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnShutdown.class, controllerService, logger, context);
    } finally {
        ExtensionManager.removeInstanceClassLoaderIfExists(component.getIdentifier());
    }
}
 
示例21
@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);
    }
}
 
示例22
@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.removeInstanceClassLoaderIfExists(component.getIdentifier());
    }
}
 
示例23
@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);
    }
}
 
示例24
@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.removeInstanceClassLoaderIfExists(component.getIdentifier());
    }
}
 
示例25
/**
 * Gets the cached temporary instance of the component for the given type and bundle.
 *
 * @param type type of the component
 * @param bundle the bundle of the component
 * @return the temporary component
 * @throws IllegalStateException if no temporary component exists for the given type and bundle
 */
public ConfigurableComponent getTemporaryComponent(final String type, final BundleDTO bundle) {
    final ExtensionManager extensionManager = getExtensionManager();
    final BundleCoordinate bundleCoordinate = BundleUtils.getBundle(extensionManager, type, bundle);
    final ConfigurableComponent configurableComponent = extensionManager.getTempComponent(type, bundleCoordinate);

    if (configurableComponent == null) {
        throw new IllegalStateException("Unable to obtain temporary component for " + type);
    }

    return configurableComponent;
}
 
示例26
/**
 * 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 Class<? extends ConfigurableComponent> componentClass) {
    if (Processor.class.isAssignableFrom(componentClass)) {
        return new HtmlProcessorDocumentationWriter();
    } else if (ControllerService.class.isAssignableFrom(componentClass)) {
        return new HtmlDocumentationWriter();
    } else if (ReportingTask.class.isAssignableFrom(componentClass)) {
        return new HtmlDocumentationWriter();
    }

    return null;
}
 
示例27
/**
 * 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
 */
private static ConfigurableComponentInitializer getComponentInitializer(
        final Class<? extends ConfigurableComponent> componentClass) {
    if (Processor.class.isAssignableFrom(componentClass)) {
        return new ProcessorInitializer();
    } else if (ControllerService.class.isAssignableFrom(componentClass)) {
        return new ControllerServiceInitializer();
    } else if (ReportingTask.class.isAssignableFrom(componentClass)) {
        return new ReportingTaskingInitializer();
    }

    return null;
}
 
示例28
/**
 * Write the header to be displayed when loaded outside an iframe.
 *
 * @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 writeHeader(ConfigurableComponent configurableComponent, XMLStreamWriter xmlStreamWriter)
        throws XMLStreamException {
    xmlStreamWriter.writeStartElement("h1");
    xmlStreamWriter.writeAttribute("id", "nameHeader");
    // Style will be overwritten on load if needed
    xmlStreamWriter.writeAttribute("style", "display: none;");
    xmlStreamWriter.writeCharacters(getTitle(configurableComponent));
    xmlStreamWriter.writeEndElement();
}
 
示例29
/**
 * Write the description of the Restricted 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 writeRestrictedInfo(ConfigurableComponent configurableComponent, XMLStreamWriter xmlStreamWriter)
        throws XMLStreamException {
    final Restricted restricted = configurableComponent.getClass().getAnnotation(Restricted.class);

    writeSimpleElement(xmlStreamWriter, "h3", "Restricted: ");

    if(restricted != null) {
        final String value = restricted.value();

        if (!StringUtils.isBlank(value)) {
            xmlStreamWriter.writeCharacters(restricted.value());
        }

        final Restriction[] restrictions = restricted.restrictions();
        if (restrictions != null && restrictions.length > 0) {
            xmlStreamWriter.writeStartElement("table");
            xmlStreamWriter.writeAttribute("id", "restrictions");
            xmlStreamWriter.writeStartElement("tr");
            writeSimpleElement(xmlStreamWriter, "th", "Required Permission");
            writeSimpleElement(xmlStreamWriter, "th", "Explanation");
            xmlStreamWriter.writeEndElement();

            for (Restriction restriction : restrictions) {
                xmlStreamWriter.writeStartElement("tr");
                writeSimpleElement(xmlStreamWriter, "td", restriction.requiredPermission().getPermissionLabel());
                writeSimpleElement(xmlStreamWriter, "td", restriction.explanation());
                xmlStreamWriter.writeEndElement();
            }

            xmlStreamWriter.writeEndElement();
        } else {
            xmlStreamWriter.writeCharacters("This component requires access to restricted components regardless of restriction.");
        }
    } else {
        xmlStreamWriter.writeCharacters("This component is not restricted.");
    }
}
 
示例30
/**
 * 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");
    writeDescription(configurableComponent, xmlStreamWriter, hasAdditionalDetails);
    writeTags(configurableComponent, xmlStreamWriter);
    writeProperties(configurableComponent, xmlStreamWriter);
    writeDynamicProperties(configurableComponent, xmlStreamWriter);
    writeAdditionalBodyInfo(configurableComponent, xmlStreamWriter);
    writeStatefulInfo(configurableComponent, xmlStreamWriter);
    writeRestrictedInfo(configurableComponent, xmlStreamWriter);
    writeSeeAlso(configurableComponent, xmlStreamWriter);
    xmlStreamWriter.writeEndElement();
}