Search in sources :

Example 16 with SimpleProcessLogger

use of org.apache.nifi.processor.SimpleProcessLogger in project nifi by apache.

the class FlowController method reload.

@Override
public void reload(final ProcessorNode existingNode, final String newType, final BundleCoordinate bundleCoordinate, final Set<URL> additionalUrls) throws ProcessorInstantiationException {
    if (existingNode == null) {
        throw new IllegalStateException("Existing ProcessorNode cannot be null");
    }
    final String id = existingNode.getProcessor().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 });
    }
    // createProcessor 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);
    // create a new node with firstTimeAdded as true so lifecycle methods get fired
    // attempt the creation to make sure it works before firing the OnRemoved methods below
    final ProcessorNode newNode = createProcessor(newType, id, bundleCoordinate, additionalUrls, true, false);
    // call OnRemoved for the existing processor using the previous instance class loader
    try (final NarCloseable x = NarCloseable.withComponentNarLoader(existingInstanceClassLoader)) {
        final StateManager stateManager = getStateManagerProvider().getStateManager(id);
        final StandardProcessContext processContext = new StandardProcessContext(existingNode, controllerServiceProvider, encryptor, stateManager, () -> false);
        ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnRemoved.class, existingNode.getProcessor(), processContext);
    } finally {
        ExtensionManager.closeURLClassLoader(id, existingInstanceClassLoader);
    }
    // set the new processor in the existing node
    final ComponentLog componentLogger = new SimpleProcessLogger(id, newNode.getProcessor());
    final TerminationAwareLogger terminationAwareLogger = new TerminationAwareLogger(componentLogger);
    LogRepositoryFactory.getRepository(id).setLogger(terminationAwareLogger);
    final LoggableComponent<Processor> newProcessor = new LoggableComponent<>(newNode.getProcessor(), newNode.getBundleCoordinate(), terminationAwareLogger);
    existingNode.setProcessor(newProcessor);
    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) GhostProcessor(org.apache.nifi.processor.GhostProcessor) Processor(org.apache.nifi.processor.Processor) ComponentLog(org.apache.nifi.logging.ComponentLog) StateManager(org.apache.nifi.components.state.StateManager) NarThreadContextClassLoader(org.apache.nifi.nar.NarThreadContextClassLoader) StandardProcessContext(org.apache.nifi.processor.StandardProcessContext) SimpleProcessLogger(org.apache.nifi.processor.SimpleProcessLogger)

Aggregations

ComponentLog (org.apache.nifi.logging.ComponentLog)16 SimpleProcessLogger (org.apache.nifi.processor.SimpleProcessLogger)16 NarCloseable (org.apache.nifi.nar.NarCloseable)9 ProcessorInstantiationException (org.apache.nifi.controller.exception.ProcessorInstantiationException)5 NarThreadContextClassLoader (org.apache.nifi.nar.NarThreadContextClassLoader)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 ControllerServiceInstantiationException (org.apache.nifi.controller.exception.ControllerServiceInstantiationException)4 Processor (org.apache.nifi.processor.Processor)4 ReportingTask (org.apache.nifi.reporting.ReportingTask)4 IOException (java.io.IOException)3 Bundle (org.apache.nifi.bundle.Bundle)3 CompletableFuture (java.util.concurrent.CompletableFuture)2 OnStopped (org.apache.nifi.annotation.lifecycle.OnStopped)2 OnUnscheduled (org.apache.nifi.annotation.lifecycle.OnUnscheduled)2 ConfigurationContext (org.apache.nifi.controller.ConfigurationContext)2 ComponentLifeCycleException (org.apache.nifi.controller.exception.ComponentLifeCycleException)2 ReportingTaskInstantiationException (org.apache.nifi.controller.reporting.ReportingTaskInstantiationException)2 GhostReportingTask (org.apache.nifi.reporting.GhostReportingTask)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1