Search in sources :

Example 6 with StandardProcessContext

use of org.apache.nifi.processor.StandardProcessContext 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

StandardProcessContext (org.apache.nifi.processor.StandardProcessContext)6 NarCloseable (org.apache.nifi.nar.NarCloseable)3 Callable (java.util.concurrent.Callable)2 Processor (org.apache.nifi.processor.Processor)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 BundleCoordinate (org.apache.nifi.bundle.BundleCoordinate)1 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)1 StateManager (org.apache.nifi.components.state.StateManager)1 StateManagerProvider (org.apache.nifi.components.state.StateManagerProvider)1 Connection (org.apache.nifi.connectable.Connection)1 ProcessorNode (org.apache.nifi.controller.ProcessorNode)1 SchedulingAgentCallback (org.apache.nifi.controller.SchedulingAgentCallback)1 ComponentLifeCycleException (org.apache.nifi.controller.exception.ComponentLifeCycleException)1 ProcessorInstantiationException (org.apache.nifi.controller.exception.ProcessorInstantiationException)1