Search in sources :

Example 6 with ReportingTask

use of org.apache.nifi.reporting.ReportingTask in project nifi by apache.

the class HtmlDocumentationWriterTest method testReportingTaskWithLogger.

@Test
public void testReportingTaskWithLogger() throws InitializationException, IOException {
    ReportingTask controllerService = new ReportingTaskWithLogger();
    controllerService.initialize(new MockReportingInitializationContext());
    DocumentationWriter writer = new HtmlDocumentationWriter();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    writer.write(controllerService, baos, false);
    String results = new String(baos.toByteArray());
    XmlValidator.assertXmlValid(results);
}
Also used : ReportingTaskWithLogger(org.apache.nifi.documentation.example.ReportingTaskWithLogger) MockReportingInitializationContext(org.apache.nifi.mock.MockReportingInitializationContext) DocumentationWriter(org.apache.nifi.documentation.DocumentationWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FullyDocumentedReportingTask(org.apache.nifi.documentation.example.FullyDocumentedReportingTask) ReportingTask(org.apache.nifi.reporting.ReportingTask) Test(org.junit.Test)

Example 7 with ReportingTask

use of org.apache.nifi.reporting.ReportingTask in project nifi by apache.

the class FlowController method instantiateReportingTask.

private LoggableComponent<ReportingTask> instantiateReportingTask(final String type, final String id, final BundleCoordinate bundleCoordinate, final Set<URL> additionalUrls) throws ReportingTaskInstantiationException {
    final ClassLoader ctxClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        final Bundle reportingTaskBundle = ExtensionManager.getBundle(bundleCoordinate);
        if (reportingTaskBundle == null) {
            throw new IllegalStateException("Unable to find bundle for coordinate " + bundleCoordinate.getCoordinate());
        }
        final ClassLoader detectedClassLoader = ExtensionManager.createInstanceClassLoader(type, id, reportingTaskBundle, additionalUrls);
        final Class<?> rawClass = Class.forName(type, false, detectedClassLoader);
        Thread.currentThread().setContextClassLoader(detectedClassLoader);
        final Class<? extends ReportingTask> reportingTaskClass = rawClass.asSubclass(ReportingTask.class);
        final Object reportingTaskObj = reportingTaskClass.newInstance();
        final ReportingTask reportingTask = reportingTaskClass.cast(reportingTaskObj);
        final ComponentLog componentLog = new SimpleProcessLogger(id, reportingTask);
        final TerminationAwareLogger terminationAwareLogger = new TerminationAwareLogger(componentLog);
        return new LoggableComponent<>(reportingTask, bundleCoordinate, terminationAwareLogger);
    } catch (final Exception e) {
        throw new ReportingTaskInstantiationException(type, e);
    } finally {
        if (ctxClassLoader != null) {
            Thread.currentThread().setContextClassLoader(ctxClassLoader);
        }
    }
}
Also used : Bundle(org.apache.nifi.bundle.Bundle) ComponentLog(org.apache.nifi.logging.ComponentLog) ConfigException(org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException) IOException(java.io.IOException) ProcessorInstantiationException(org.apache.nifi.controller.exception.ProcessorInstantiationException) ComponentLifeCycleException(org.apache.nifi.controller.exception.ComponentLifeCycleException) UnknownServiceAddressException(org.apache.nifi.cluster.protocol.UnknownServiceAddressException) FlowSerializationException(org.apache.nifi.controller.serialization.FlowSerializationException) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException) InitializationException(org.apache.nifi.reporting.InitializationException) ReportingTaskInstantiationException(org.apache.nifi.controller.reporting.ReportingTaskInstantiationException) CommunicationsException(org.apache.nifi.controller.exception.CommunicationsException) FlowSynchronizationException(org.apache.nifi.controller.serialization.FlowSynchronizationException) ControllerServiceInstantiationException(org.apache.nifi.controller.exception.ControllerServiceInstantiationException) ReportingTaskInstantiationException(org.apache.nifi.controller.reporting.ReportingTaskInstantiationException) NarThreadContextClassLoader(org.apache.nifi.nar.NarThreadContextClassLoader) SimpleProcessLogger(org.apache.nifi.processor.SimpleProcessLogger) ReportingTask(org.apache.nifi.reporting.ReportingTask) GhostReportingTask(org.apache.nifi.reporting.GhostReportingTask)

Example 8 with ReportingTask

use of org.apache.nifi.reporting.ReportingTask in project nifi by apache.

the class FlowController method reload.

@Override
public void reload(final ReportingTaskNode existingNode, final String newType, final BundleCoordinate bundleCoordinate, final Set<URL> additionalUrls) throws ReportingTaskInstantiationException {
    if (existingNode == null) {
        throw new IllegalStateException("Existing ReportingTaskNode cannot be null");
    }
    final String id = existingNode.getReportingTask().getIdentifier();
    // ghost components will have a null logger
    if (existingNode.getLogger() != null) {
        existingNode.getLogger().debug("Reloading component {} to type {} from bundle {}", new Object[] { id, newType, bundleCoordinate });
    }
    // createReportingTask will create a new instance class loader for the same id so
    // save the instance class loader to use it for calling OnRemoved on the existing processor
    final ClassLoader existingInstanceClassLoader = ExtensionManager.getInstanceClassLoader(id);
    // set firstTimeAdded to true so lifecycle annotations get fired, but don't register this node
    // attempt the creation to make sure it works before firing the OnRemoved methods below
    final ReportingTaskNode newNode = createReportingTask(newType, id, bundleCoordinate, additionalUrls, true, false);
    // call OnRemoved for the existing reporting task using the previous instance class loader
    try (final NarCloseable x = NarCloseable.withComponentNarLoader(existingInstanceClassLoader)) {
        ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnRemoved.class, existingNode.getReportingTask(), existingNode.getConfigurationContext());
    } finally {
        ExtensionManager.closeURLClassLoader(id, existingInstanceClassLoader);
    }
    // set the new reporting task into the existing node
    final ComponentLog componentLogger = new SimpleProcessLogger(id, existingNode.getReportingTask());
    final TerminationAwareLogger terminationAwareLogger = new TerminationAwareLogger(componentLogger);
    LogRepositoryFactory.getRepository(id).setLogger(terminationAwareLogger);
    final LoggableComponent<ReportingTask> newReportingTask = new LoggableComponent<>(newNode.getReportingTask(), newNode.getBundleCoordinate(), terminationAwareLogger);
    existingNode.setReportingTask(newReportingTask);
    existingNode.setExtensionMissing(newNode.isExtensionMissing());
    // need to refresh the properties in case we are changing from ghost component to real component
    existingNode.refreshProperties();
}
Also used : NarCloseable(org.apache.nifi.nar.NarCloseable) StandardReportingTaskNode(org.apache.nifi.controller.reporting.StandardReportingTaskNode) NarThreadContextClassLoader(org.apache.nifi.nar.NarThreadContextClassLoader) SimpleProcessLogger(org.apache.nifi.processor.SimpleProcessLogger) ComponentLog(org.apache.nifi.logging.ComponentLog) ReportingTask(org.apache.nifi.reporting.ReportingTask) GhostReportingTask(org.apache.nifi.reporting.GhostReportingTask)

Example 9 with ReportingTask

use of org.apache.nifi.reporting.ReportingTask in project nifi-minifi by apache.

the class ReportingTaskingInitializer method initialize.

@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);
    }
}
Also used : NarCloseable(org.apache.nifi.nar.NarCloseable) ReportingInitializationContext(org.apache.nifi.reporting.ReportingInitializationContext) MockReportingInitializationContext(org.apache.nifi.mock.MockReportingInitializationContext) MockReportingInitializationContext(org.apache.nifi.mock.MockReportingInitializationContext) ReportingTask(org.apache.nifi.reporting.ReportingTask)

Example 10 with ReportingTask

use of org.apache.nifi.reporting.ReportingTask in project nifi-minifi by apache.

the class ReportingTaskingInitializer method teardown.

@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());
    }
}
Also used : NarCloseable(org.apache.nifi.nar.NarCloseable) MockConfigurationContext(org.apache.nifi.mock.MockConfigurationContext) MockComponentLogger(org.apache.nifi.mock.MockComponentLogger) ReportingTask(org.apache.nifi.reporting.ReportingTask)

Aggregations

ReportingTask (org.apache.nifi.reporting.ReportingTask)14 NarCloseable (org.apache.nifi.nar.NarCloseable)8 ComponentLog (org.apache.nifi.logging.ComponentLog)5 ProcessorNode (org.apache.nifi.controller.ProcessorNode)4 SimpleProcessLogger (org.apache.nifi.processor.SimpleProcessLogger)4 ReportingInitializationContext (org.apache.nifi.reporting.ReportingInitializationContext)4 IOException (java.io.IOException)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 Bundle (org.apache.nifi.bundle.Bundle)3 FlowController (org.apache.nifi.controller.FlowController)3 MockReportingInitializationContext (org.apache.nifi.mock.MockReportingInitializationContext)3 Collator (java.text.Collator)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Comparator (java.util.Comparator)2 HashSet (java.util.HashSet)2 List (java.util.List)2