This is an automated email from the ASF dual-hosted git repository.

pvillard pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new e81448f98a NIFI-15061 Fixed Logging Context initialization for 
Controller Services
e81448f98a is described below

commit e81448f98a50ba1f79f83596563668e7a29b330d
Author: exceptionfactory <[email protected]>
AuthorDate: Mon Oct 6 10:32:06 2025 -0500

    NIFI-15061 Fixed Logging Context initialization for Controller Services
    
    - Added default constructor for StandardLoggingContext for explicit null 
Grouped Component references
    - Added non-null requirement to StandardLoggingContext constructor to avoid 
unexpected initialization
    
    Signed-off-by: Pierre Villard <[email protected]>
    
    This closes #10394.
---
 .../flowanalysis/AbstractFlowAnalysisRuleNode.java |  2 +-
 .../service/StandardControllerServiceNode.java     | 17 +++++++-----
 .../controller/state/StandardStateManager.java     |  2 +-
 .../manager/StandardStateManagerProvider.java      |  2 +-
 .../nifi/logging/StandardLoggingContext.java       | 16 ++++++++++-
 .../nifi/logging/TestStandardLoggingContext.java   |  2 +-
 .../apache/nifi/controller/ExtensionBuilder.java   | 30 ++++++++++-----------
 .../nifi/controller/StandardReloadComponent.java   | 10 +++----
 .../scheduling/StandardProcessScheduler.java       |  4 +--
 .../controller/tasks/ReportingTaskWrapper.java     |  2 +-
 .../web/dao/impl/StandardFlowAnalysisRuleDAO.java  |  2 +-
 .../web/dao/impl/StandardParameterProviderDAO.java |  2 +-
 .../web/dao/impl/StandardReportingTaskDAO.java     |  2 +-
 .../nifi/stateless/engine/ComponentBuilder.java    | 31 +++++++++++++---------
 .../stateless/engine/StatelessReloadComponent.java | 10 +++----
 .../stateless/engine/StatelessSchedulingAgent.java |  2 +-
 16 files changed, 80 insertions(+), 56 deletions(-)

diff --git 
a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/controller/flowanalysis/AbstractFlowAnalysisRuleNode.java
 
b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/controller/flowanalysis/AbstractFlowAnalysisRuleNode.java
index 258752045a..ce995642d3 100644
--- 
a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/controller/flowanalysis/AbstractFlowAnalysisRuleNode.java
+++ 
b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/controller/flowanalysis/AbstractFlowAnalysisRuleNode.java
@@ -283,7 +283,7 @@ public abstract class AbstractFlowAnalysisRuleNode extends 
AbstractComponentNode
         } catch (Exception e) {
             final Throwable cause = e instanceof InvocationTargetException ? 
e.getCause() : e;
 
-            final ComponentLog componentLog = new 
SimpleProcessLogger(getIdentifier(), getFlowAnalysisRule(), new 
StandardLoggingContext(null));
+            final ComponentLog componentLog = new 
SimpleProcessLogger(getIdentifier(), getFlowAnalysisRule(), new 
StandardLoggingContext());
 
             componentLog.error("Failed to invoke {} method", cause);
 
diff --git 
a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceNode.java
 
b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceNode.java
index 0904b85665..1ebd2237c6 100644
--- 
a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceNode.java
+++ 
b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceNode.java
@@ -635,7 +635,8 @@ public class StandardControllerServiceNode extends 
AbstractComponentNode impleme
 
                     enablingAttemptCount.incrementAndGet();
                     if (enablingAttemptCount.get() == 120 || 
enablingAttemptCount.get() % 3600 == 0) {
-                        final ComponentLog componentLog = new 
SimpleProcessLogger(getIdentifier(), StandardControllerServiceNode.this,
+                        final ControllerService controllerService = 
getControllerServiceImplementation();
+                        final ComponentLog componentLog = new 
SimpleProcessLogger(getIdentifier(), controllerService,
                                 new 
StandardLoggingContext(StandardControllerServiceNode.this));
                         componentLog.error("Enabling {} failed: Validation 
Status [{}] Errors {}",
                                 service, validationStatus, 
validationState.getValidationErrors());
@@ -655,9 +656,10 @@ public class StandardControllerServiceNode extends 
AbstractComponentNode impleme
                     return;
                 }
 
+                final ControllerService controllerService = 
getControllerServiceImplementation();
                 try {
-                    try (final NarCloseable ignored = 
NarCloseable.withComponentNarLoader(getExtensionManager(), 
getControllerServiceImplementation().getClass(), getIdentifier())) {
-                        
ReflectionUtils.invokeMethodsWithAnnotation(OnEnabled.class, 
getControllerServiceImplementation(), configContext);
+                    try (final NarCloseable ignored = 
NarCloseable.withComponentNarLoader(getExtensionManager(), 
controllerService.getClass(), getIdentifier())) {
+                        
ReflectionUtils.invokeMethodsWithAnnotation(OnEnabled.class, controllerService, 
configContext);
                     }
 
                     boolean shouldEnable;
@@ -681,7 +683,7 @@ public class StandardControllerServiceNode extends 
AbstractComponentNode impleme
                     }
 
                     final Throwable cause = e instanceof 
InvocationTargetException ? e.getCause() : e;
-                    final ComponentLog componentLog = new 
SimpleProcessLogger(getIdentifier(), StandardControllerServiceNode.this,
+                    final ComponentLog componentLog = new 
SimpleProcessLogger(getIdentifier(), controllerService,
                             new 
StandardLoggingContext(StandardControllerServiceNode.this));
                     componentLog.error("Failed to invoke @OnEnabled method", 
cause);
                     invokeDisable(configContext);
@@ -753,12 +755,13 @@ public class StandardControllerServiceNode extends 
AbstractComponentNode impleme
 
 
     private void invokeDisable(ConfigurationContext configContext) {
-        try (final NarCloseable ignored = 
NarCloseable.withComponentNarLoader(getExtensionManager(), 
getControllerServiceImplementation().getClass(), getIdentifier())) {
-            ReflectionUtils.invokeMethodsWithAnnotation(OnDisabled.class, 
StandardControllerServiceNode.this.getControllerServiceImplementation(), 
configContext);
+        final ControllerService controllerService = 
getControllerServiceImplementation();
+        try (final NarCloseable ignored = 
NarCloseable.withComponentNarLoader(getExtensionManager(), 
controllerService.getClass(), getIdentifier())) {
+            ReflectionUtils.invokeMethodsWithAnnotation(OnDisabled.class, 
controllerService, configContext);
             LOG.debug("Successfully disabled {}", this);
         } catch (Exception e) {
             final Throwable cause = e instanceof InvocationTargetException ? 
e.getCause() : e;
-            final ComponentLog componentLog = new 
SimpleProcessLogger(getIdentifier(), StandardControllerServiceNode.this, new 
StandardLoggingContext(StandardControllerServiceNode.this));
+            final ComponentLog componentLog = new 
SimpleProcessLogger(getIdentifier(), controllerService, new 
StandardLoggingContext(StandardControllerServiceNode.this));
             componentLog.error("Failed to invoke @OnDisabled method due to 
{}", cause);
             LOG.error("Failed to invoke @OnDisabled method of {} due to {}", 
getControllerServiceImplementation(), cause.toString());
         }
diff --git 
a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/controller/state/StandardStateManager.java
 
b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/controller/state/StandardStateManager.java
index 2bd86d3489..c67ee510fd 100644
--- 
a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/controller/state/StandardStateManager.java
+++ 
b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/controller/state/StandardStateManager.java
@@ -61,7 +61,7 @@ public class StandardStateManager implements StateManager {
         final LogRepository repo = 
LogRepositoryFactory.getRepository(componentId);
         final ComponentLog logger = (repo == null) ? null : repo.getLogger();
         if (repo == null || logger == null) {
-            return new SimpleProcessLogger(componentId, this, new 
StandardLoggingContext(null));
+            return new SimpleProcessLogger(componentId, this, new 
StandardLoggingContext());
         }
 
         return logger;
diff --git 
a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/controller/state/manager/StandardStateManagerProvider.java
 
b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/controller/state/manager/StandardStateManagerProvider.java
index c55c761c36..5bc9475248 100644
--- 
a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/controller/state/manager/StandardStateManagerProvider.java
+++ 
b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/controller/state/manager/StandardStateManagerProvider.java
@@ -327,7 +327,7 @@ public class StandardStateManagerProvider implements 
StateManagerProvider {
             propertyMap.put(descriptor, new 
StandardPropertyValue(resourceContext, entry.getValue(), null, 
parameterLookup));
         }
 
-        final ComponentLog logger = new 
SimpleProcessLogger(providerConfig.getId(), provider, new 
StandardLoggingContext(null));
+        final ComponentLog logger = new 
SimpleProcessLogger(providerConfig.getId(), provider, new 
StandardLoggingContext());
         final StateProviderInitializationContext initContext = new 
StandardStateProviderInitializationContext(providerConfig.getId(), propertyMap, 
sslContext, logger);
 
         synchronized (provider) {
diff --git 
a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/logging/StandardLoggingContext.java
 
b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/logging/StandardLoggingContext.java
index 194db11787..a3ccf6a981 100644
--- 
a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/logging/StandardLoggingContext.java
+++ 
b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/logging/StandardLoggingContext.java
@@ -19,6 +19,7 @@ package org.apache.nifi.logging;
 import org.apache.nifi.groups.ProcessGroup;
 
 import java.util.Map;
+import java.util.Objects;
 import java.util.Optional;
 
 public class StandardLoggingContext implements LoggingContext {
@@ -26,8 +27,21 @@ public class StandardLoggingContext implements 
LoggingContext {
 
     private volatile GroupedComponent component;
 
+    /**
+     * Standard Logging Context default constructor for separate component 
initialization
+     *
+     */
+    public StandardLoggingContext() {
+        this.component = null;
+    }
+
+    /**
+     * Standard Logging Context constructor with Grouped Component required
+     *
+     * @param component Grouped Component required
+     */
     public StandardLoggingContext(final GroupedComponent component) {
-        this.component = component;
+        this.component = Objects.requireNonNull(component, "Group Component 
required");
     }
 
     /**
diff --git 
a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/logging/TestStandardLoggingContext.java
 
b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/logging/TestStandardLoggingContext.java
index 81a5571ae0..e6031fadab 100644
--- 
a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/logging/TestStandardLoggingContext.java
+++ 
b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/logging/TestStandardLoggingContext.java
@@ -38,7 +38,7 @@ class TestStandardLoggingContext {
 
     @Test
     void testNullComponent_ShouldReturnOptionalEmpty() {
-        LoggingContext context = new StandardLoggingContext(null);
+        LoggingContext context = new StandardLoggingContext();
 
         assertTrue(context.getLogFileSuffix().isEmpty());
     }
diff --git 
a/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/ExtensionBuilder.java
 
b/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/ExtensionBuilder.java
index 6157486cfd..5cd1729ef5 100644
--- 
a/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/ExtensionBuilder.java
+++ 
b/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/ExtensionBuilder.java
@@ -245,7 +245,7 @@ public class ExtensionBuilder {
        }
 
        boolean creationSuccessful = true;
-       final StandardLoggingContext loggingContext = new 
StandardLoggingContext(null);
+       final StandardLoggingContext loggingContext = new 
StandardLoggingContext();
        LoggableComponent<Processor> loggableComponent;
        try {
            loggableComponent = createLoggableProcessor(loggingContext);
@@ -437,9 +437,9 @@ public class ExtensionBuilder {
        if (stateManagerProvider == null) {
            throw new IllegalStateException("State Manager Provider must be 
specified");
        }
-       final StandardLoggingContext loggingContext = new 
StandardLoggingContext(null);
+
        try {
-           return createControllerServiceNode(loggingContext);
+           return createControllerServiceNode();
        } catch (final Throwable t) {
            logger.error("Could not create Controller Service of type {} from 
{} for ID {} due to: {}; creating \"Ghost\" implementation", type, 
bundleCoordinate, identifier, t.getMessage());
            if (logger.isDebugEnabled()) {
@@ -636,7 +636,7 @@ public class ExtensionBuilder {
        }
    }
 
-   private ControllerServiceNode createControllerServiceNode(final 
StandardLoggingContext loggingContext)
+   private ControllerServiceNode createControllerServiceNode()
        throws ClassNotFoundException, IllegalAccessException, 
InstantiationException, InitializationException, NoSuchMethodException, 
InvocationTargetException {
 
        final ClassLoader ctxClassLoader = 
Thread.currentThread().getContextClassLoader();
@@ -667,7 +667,8 @@ public class ExtensionBuilder {
            }
 
            logger.info("Created Controller Service of type {} with identifier 
{}", type, identifier);
-           final ComponentLog serviceLogger = new 
SimpleProcessLogger(identifier, serviceImpl, new StandardLoggingContext(null));
+           final StandardLoggingContext loggingContext = new 
StandardLoggingContext();
+           final ComponentLog serviceLogger = new 
SimpleProcessLogger(identifier, serviceImpl, loggingContext);
            final TerminationAwareLogger terminationAwareLogger = new 
TerminationAwareLogger(serviceLogger);
 
            final StateManager stateManager = 
stateManagerProvider.getStateManager(identifier, serviceImpl.getClass());
@@ -684,6 +685,7 @@ public class ExtensionBuilder {
            final ControllerServiceNode serviceNode = new 
StandardControllerServiceNode(originalLoggableComponent, 
proxiedLoggableComponent, invocationHandler,
                    identifier, validationContextFactory, serviceProvider, 
reloadComponent, extensionManager, validationTrigger);
            serviceNode.setName(rawClass.getSimpleName());
+           // Set Controller Service Node in Logging Context to populate 
Process Group information
            loggingContext.setComponent(serviceNode);
 
            invocationHandler.setServiceNode(serviceNode);
@@ -767,17 +769,15 @@ public class ExtensionBuilder {
        final ControllerServiceInvocationHandler invocationHandler = new 
StandardControllerServiceInvocationHandler(extensionManager, ghostService);
 
        final ValidationContextFactory validationContextFactory = 
createValidationContextFactory(serviceProvider);
-       final ControllerServiceNode serviceNode = new 
StandardControllerServiceNode(proxiedLoggableComponent, 
proxiedLoggableComponent, invocationHandler, identifier,
+       return new StandardControllerServiceNode(proxiedLoggableComponent, 
proxiedLoggableComponent, invocationHandler, identifier,
                validationContextFactory, serviceProvider, componentType, type, 
reloadComponent, extensionManager, validationTrigger, true);
-
-       return serviceNode;
    }
 
    private LoggableComponent<Processor> createLoggableProcessor(final 
LoggingContext loggingContext) throws ProcessorInstantiationException {
        try {
            final LoggableComponent<Processor> processorComponent;
            if (PythonBundle.isPythonCoordinate(bundleCoordinate)) {
-               processorComponent = createLoggablePythonProcessor();
+               processorComponent = 
createLoggablePythonProcessor(loggingContext);
            } else {
                processorComponent = createLoggableComponent(Processor.class, 
loggingContext);
            }
@@ -800,7 +800,7 @@ public class ExtensionBuilder {
 
    private LoggableComponent<ReportingTask> createLoggableReportingTask() 
throws ReportingTaskInstantiationException {
        try {
-           final LoggableComponent<ReportingTask> taskComponent = 
createLoggableComponent(ReportingTask.class, new StandardLoggingContext(null));
+           final LoggableComponent<ReportingTask> taskComponent = 
createLoggableComponent(ReportingTask.class, new StandardLoggingContext());
 
            final String taskName = 
taskComponent.getComponent().getClass().getSimpleName();
            final ReportingInitializationContext config = new 
StandardReportingInitializationContext(identifier, taskName,
@@ -819,7 +819,7 @@ public class ExtensionBuilder {
 
    private LoggableComponent<FlowAnalysisRule> 
createLoggableFlowAnalysisRule() throws FlowAnalysisRuleInstantiationException {
        try {
-           final LoggableComponent<FlowAnalysisRule> loggableComponent = 
createLoggableComponent(FlowAnalysisRule.class, new 
StandardLoggingContext(null));
+           final LoggableComponent<FlowAnalysisRule> loggableComponent = 
createLoggableComponent(FlowAnalysisRule.class, new StandardLoggingContext());
 
            final FlowAnalysisRuleInitializationContext config = new 
StandardFlowAnalysisInitializationContext(identifier,
                    loggableComponent.getLogger(), serviceProvider, 
kerberosConfig, nodeTypeProvider);
@@ -854,7 +854,7 @@ public class ExtensionBuilder {
 
    private LoggableComponent<FlowRegistryClient> 
createLoggableFlowRegistryClient() throws 
FlowRepositoryClientInstantiationException {
        try {
-           final LoggableComponent<FlowRegistryClient> clientComponent = 
createLoggableComponent(FlowRegistryClient.class, new 
StandardLoggingContext(null));
+           final LoggableComponent<FlowRegistryClient> clientComponent = 
createLoggableComponent(FlowRegistryClient.class, new StandardLoggingContext());
 
            final FlowRegistryClientInitializationContext context = new 
StandardFlowRegistryClientInitializationContext(
                    identifier, clientComponent.getLogger(), systemSslContext);
@@ -870,7 +870,7 @@ public class ExtensionBuilder {
 
    private LoggableComponent<ParameterProvider> 
createLoggableParameterProvider() throws 
ParameterProviderInstantiationException {
        try {
-           final LoggableComponent<ParameterProvider> providerComponent = 
createLoggableComponent(ParameterProvider.class, new 
StandardLoggingContext(null));
+           final LoggableComponent<ParameterProvider> providerComponent = 
createLoggableComponent(ParameterProvider.class, new StandardLoggingContext());
 
            final String taskName = 
providerComponent.getComponent().getClass().getSimpleName();
            final ParameterProviderInitializationContext config = new 
StandardParameterProviderInitializationContext(identifier, taskName,
@@ -887,7 +887,7 @@ public class ExtensionBuilder {
        }
    }
 
-   private LoggableComponent<Processor> createLoggablePythonProcessor() {
+   private LoggableComponent<Processor> createLoggablePythonProcessor(final 
LoggingContext loggingContext) {
        final ClassLoader ctxClassLoader = 
Thread.currentThread().getContextClassLoader();
        try {
            final Bundle bundle = extensionManager.getBundle(bundleCoordinate);
@@ -901,7 +901,7 @@ public class ExtensionBuilder {
 
            final Processor processor = 
pythonBridge.createProcessor(identifier, type, bundleCoordinate.getVersion(), 
true, true);
 
-           final ComponentLog componentLog = new 
SimpleProcessLogger(identifier, processor, new StandardLoggingContext(null));
+           final ComponentLog componentLog = new 
SimpleProcessLogger(identifier, processor, loggingContext);
            final TerminationAwareLogger terminationAwareLogger = new 
TerminationAwareLogger(componentLog);
 
            final ProcessorInitializationContext initContext = new 
StandardProcessorInitializationContext(identifier, terminationAwareLogger,
diff --git 
a/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardReloadComponent.java
 
b/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardReloadComponent.java
index cec3a9ade2..9893acec3e 100644
--- 
a/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardReloadComponent.java
+++ 
b/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardReloadComponent.java
@@ -210,7 +210,7 @@ public class StandardReloadComponent implements 
ReloadComponent {
         final ReportingTaskNode newNode = 
flowController.getFlowManager().createReportingTask(newType, id, 
bundleCoordinate, additionalUrls, true, false, classloaderIsolationKey);
 
         // set the new reporting task into the existing node
-        final ComponentLog componentLogger = new SimpleProcessLogger(id, 
existingNode.getReportingTask(), new StandardLoggingContext(null));
+        final ComponentLog componentLogger = new SimpleProcessLogger(id, 
existingNode.getReportingTask(), new StandardLoggingContext());
         final TerminationAwareLogger terminationAwareLogger = new 
TerminationAwareLogger(componentLogger);
         
LogRepositoryFactory.getRepository(id).setLogger(terminationAwareLogger);
 
@@ -260,7 +260,7 @@ public class StandardReloadComponent implements 
ReloadComponent {
         final FlowAnalysisRuleNode newNode = 
flowController.getFlowManager().createFlowAnalysisRule(newType, id, 
bundleCoordinate, additionalUrls, true, false, classloaderIsolationKey);
 
         // set the new flow analysis rule into the existing node
-        final ComponentLog componentLogger = new SimpleProcessLogger(id, 
existingNode.getFlowAnalysisRule(), new StandardLoggingContext(null));
+        final ComponentLog componentLogger = new SimpleProcessLogger(id, 
existingNode.getFlowAnalysisRule(), new StandardLoggingContext());
         final TerminationAwareLogger terminationAwareLogger = new 
TerminationAwareLogger(componentLogger);
         
LogRepositoryFactory.getRepository(id).setLogger(terminationAwareLogger);
 
@@ -308,7 +308,7 @@ public class StandardReloadComponent implements 
ReloadComponent {
         }
 
         // set the new parameter provider into the existing node
-        final ComponentLog componentLogger = new SimpleProcessLogger(id, 
existingNode.getParameterProvider(), new StandardLoggingContext(null));
+        final ComponentLog componentLogger = new SimpleProcessLogger(id, 
existingNode.getParameterProvider(), new StandardLoggingContext());
         final TerminationAwareLogger terminationAwareLogger = new 
TerminationAwareLogger(componentLogger);
         
LogRepositoryFactory.getRepository(id).setLogger(terminationAwareLogger);
 
@@ -349,8 +349,8 @@ public class StandardReloadComponent implements 
ReloadComponent {
         final FlowRegistryClientNode newNode = 
flowController.getFlowManager().createFlowRegistryClient(newType, id, 
bundleCoordinate, additionalUrls, true, false, null);
         extensionManager.closeURLClassLoader(id, existingInstanceClassLoader);
 
-        // set the new flow registyr client into the existing node
-        final ComponentLog componentLogger = new SimpleProcessLogger(id, 
existingNode.getComponent(), new StandardLoggingContext(null));
+        // set the new flow registry client into the existing node
+        final ComponentLog componentLogger = new SimpleProcessLogger(id, 
existingNode.getComponent(), new StandardLoggingContext());
         final TerminationAwareLogger terminationAwareLogger = new 
TerminationAwareLogger(componentLogger);
         
LogRepositoryFactory.getRepository(id).setLogger(terminationAwareLogger);
 
diff --git 
a/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/scheduling/StandardProcessScheduler.java
 
b/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/scheduling/StandardProcessScheduler.java
index 789ca85a96..10332b1ea0 100644
--- 
a/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/scheduling/StandardProcessScheduler.java
+++ 
b/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/scheduling/StandardProcessScheduler.java
@@ -303,7 +303,7 @@ public final class StandardProcessScheduler implements 
ProcessScheduler {
                     }
                 } catch (final Exception e) {
                     final Throwable cause = e instanceof 
InvocationTargetException ? e.getCause() : e;
-                    final ComponentLog componentLog = new 
SimpleProcessLogger(reportingTask.getIdentifier(), reportingTask, new 
StandardLoggingContext(null));
+                    final ComponentLog componentLog = new 
SimpleProcessLogger(reportingTask.getIdentifier(), reportingTask, new 
StandardLoggingContext());
                     componentLog.error("Failed to invoke @OnScheduled method 
due to {}", cause);
 
                     LOG.error("Failed to invoke the On-Scheduled Lifecycle 
methods of {} due to {}; administratively yielding this "
@@ -354,7 +354,7 @@ public final class StandardProcessScheduler implements 
ProcessScheduler {
                     
ReflectionUtils.invokeMethodsWithAnnotation(OnUnscheduled.class, reportingTask, 
configurationContext);
                 } catch (final Exception e) {
                     final Throwable cause = e instanceof 
InvocationTargetException ? e.getCause() : e;
-                    final ComponentLog componentLog = new 
SimpleProcessLogger(reportingTask.getIdentifier(), reportingTask, new 
StandardLoggingContext(null));
+                    final ComponentLog componentLog = new 
SimpleProcessLogger(reportingTask.getIdentifier(), reportingTask, new 
StandardLoggingContext());
                     componentLog.error("Failed to invoke @OnUnscheduled method 
due to {}", cause);
 
                     LOG.error("Failed to invoke the @OnUnscheduled methods of 
{} due to {}; administratively yielding this ReportingTask and will attempt to 
schedule it again after {}",
diff --git 
a/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/tasks/ReportingTaskWrapper.java
 
b/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/tasks/ReportingTaskWrapper.java
index 6aa93a07ab..f182c51aff 100644
--- 
a/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/tasks/ReportingTaskWrapper.java
+++ 
b/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/tasks/ReportingTaskWrapper.java
@@ -46,7 +46,7 @@ public class ReportingTaskWrapper implements Runnable {
         try (final NarCloseable ignored = 
NarCloseable.withComponentNarLoader(extensionManager, 
taskNode.getReportingTask().getClass(), taskNode.getIdentifier())) {
             
taskNode.getReportingTask().onTrigger(taskNode.getReportingContext());
         } catch (final Throwable t) {
-            final ComponentLog componentLog = new 
SimpleProcessLogger(taskNode.getIdentifier(), taskNode.getReportingTask(), new 
StandardLoggingContext(null));
+            final ComponentLog componentLog = new 
SimpleProcessLogger(taskNode.getIdentifier(), taskNode.getReportingTask(), new 
StandardLoggingContext());
             componentLog.error("Error running task {}", 
taskNode.getReportingTask(), t);
             if (componentLog.isDebugEnabled()) {
                 componentLog.error("", t);
diff --git 
a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardFlowAnalysisRuleDAO.java
 
b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardFlowAnalysisRuleDAO.java
index a4d9ef051b..8a75041ec4 100644
--- 
a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardFlowAnalysisRuleDAO.java
+++ 
b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardFlowAnalysisRuleDAO.java
@@ -281,7 +281,7 @@ public class StandardFlowAnalysisRuleDAO extends 
ComponentDAO implements FlowAna
         final FlowAnalysisRuleNode ruleNode = 
locateFlowAnalysisRule(flowAnalysisRuleId);
 
         final LogRepository logRepository = new NopLogRepository();
-        final ComponentLog configVerificationLog = new 
SimpleProcessLogger(ruleNode.getFlowAnalysisRule(), logRepository, new 
StandardLoggingContext(null));
+        final ComponentLog configVerificationLog = new 
SimpleProcessLogger(ruleNode.getFlowAnalysisRule(), logRepository, new 
StandardLoggingContext());
         final ExtensionManager extensionManager = 
flowController.getExtensionManager();
 
         final ParameterLookup parameterLookup = ParameterLookup.EMPTY;
diff --git 
a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardParameterProviderDAO.java
 
b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardParameterProviderDAO.java
index 958769ab31..1bf0196f37 100644
--- 
a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardParameterProviderDAO.java
+++ 
b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardParameterProviderDAO.java
@@ -238,7 +238,7 @@ public class StandardParameterProviderDAO extends 
ComponentDAO implements Parame
         final ParameterProviderNode parameterProviderNode = 
locateParameterProvider(parameterProviderId);
 
         final LogRepository logRepository = new NopLogRepository();
-        final ComponentLog configVerificationLog = new 
SimpleProcessLogger(parameterProviderNode.getParameterProvider(), 
logRepository, new StandardLoggingContext(null));
+        final ComponentLog configVerificationLog = new 
SimpleProcessLogger(parameterProviderNode.getParameterProvider(), 
logRepository, new StandardLoggingContext());
         final ExtensionManager extensionManager = 
flowController.getExtensionManager();
 
         final ParameterLookup parameterLookup = ParameterLookup.EMPTY;
diff --git 
a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardReportingTaskDAO.java
 
b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardReportingTaskDAO.java
index c57dc456e6..1ff1a8af12 100644
--- 
a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardReportingTaskDAO.java
+++ 
b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardReportingTaskDAO.java
@@ -264,7 +264,7 @@ public class StandardReportingTaskDAO extends ComponentDAO 
implements ReportingT
         final ReportingTaskNode taskNode = 
locateReportingTask(reportingTaskId);
 
         final LogRepository logRepository = new NopLogRepository();
-        final ComponentLog configVerificationLog = new 
SimpleProcessLogger(taskNode.getReportingTask(), logRepository, new 
StandardLoggingContext(null));
+        final ComponentLog configVerificationLog = new 
SimpleProcessLogger(taskNode.getReportingTask(), logRepository, new 
StandardLoggingContext());
         final ExtensionManager extensionManager = 
flowController.getExtensionManager();
 
         final ParameterLookup parameterLookup = ParameterLookup.EMPTY;
diff --git 
a/nifi-stateless/nifi-stateless-bundle/nifi-stateless-engine/src/main/java/org/apache/nifi/stateless/engine/ComponentBuilder.java
 
b/nifi-stateless/nifi-stateless-bundle/nifi-stateless-engine/src/main/java/org/apache/nifi/stateless/engine/ComponentBuilder.java
index 729609f309..4cced115cd 100644
--- 
a/nifi-stateless/nifi-stateless-bundle/nifi-stateless-engine/src/main/java/org/apache/nifi/stateless/engine/ComponentBuilder.java
+++ 
b/nifi-stateless/nifi-stateless-bundle/nifi-stateless-engine/src/main/java/org/apache/nifi/stateless/engine/ComponentBuilder.java
@@ -59,6 +59,7 @@ import 
org.apache.nifi.controller.service.StandardControllerServiceInitializatio
 import 
org.apache.nifi.controller.service.StandardControllerServiceInvocationHandler;
 import org.apache.nifi.controller.service.StandardControllerServiceNode;
 import org.apache.nifi.logging.ComponentLog;
+import org.apache.nifi.logging.LoggingContext;
 import org.apache.nifi.logging.StandardLoggingContext;
 import org.apache.nifi.nar.ExtensionManager;
 import org.apache.nifi.parameter.ParameterProvider;
@@ -128,7 +129,8 @@ public class ComponentBuilder {
     }
 
     public ProcessorNode buildProcessor() throws 
ProcessorInstantiationException {
-        final LoggableComponent<Processor> loggableProcessor = 
createLoggableProcessor();
+        final StandardLoggingContext loggingContext = new 
StandardLoggingContext();
+        final LoggableComponent<Processor> loggableProcessor = 
createLoggableProcessor(loggingContext);
         final ProcessScheduler processScheduler = 
statelessEngine.getProcessScheduler();
         final ControllerServiceProvider controllerServiceProvider = 
statelessEngine.getControllerServiceProvider();
         final ReloadComponent reloadComponent = 
statelessEngine.getReloadComponent();
@@ -138,6 +140,7 @@ public class ComponentBuilder {
 
         final ProcessorNode procNode = new 
StandardProcessorNode(loggableProcessor, identifier, validationContextFactory, 
processScheduler, controllerServiceProvider,
             reloadComponent, extensionManager, validationTrigger);
+        loggingContext.setComponent(procNode);
 
         logger.info("Created Processor of type {} with identifier {}", type, 
identifier);
 
@@ -161,7 +164,7 @@ public class ComponentBuilder {
 
     private LoggableComponent<FlowRegistryClient> 
createLoggableFlowRegistryClient() throws 
FlowRepositoryClientInstantiationException {
         try {
-            final ComponentLog componentLog = new 
SimpleProcessLogger(identifier, 
InMemoryFlowRegistry.class.getDeclaredConstructor().newInstance(), new 
StandardLoggingContext(null));
+            final ComponentLog componentLog = new 
SimpleProcessLogger(identifier, 
InMemoryFlowRegistry.class.getDeclaredConstructor().newInstance(), new 
StandardLoggingContext());
             final TerminationAwareLogger terminationAwareLogger = new 
TerminationAwareLogger(componentLog);
             final InMemoryFlowRegistry registryClient = new 
InMemoryFlowRegistry();
             final LoggableComponent<FlowRegistryClient> nodeComponent = new 
LoggableComponent<>(registryClient, bundleCoordinate, terminationAwareLogger);
@@ -189,7 +192,7 @@ public class ComponentBuilder {
 
     private LoggableComponent<ReportingTask> createLoggableReportingTask() 
throws ReportingTaskInstantiationException {
         try {
-            final LoggableComponent<ReportingTask> taskComponent = 
createLoggableComponent(ReportingTask.class);
+            final LoggableComponent<ReportingTask> taskComponent = 
createLoggableComponent(ReportingTask.class, new StandardLoggingContext());
             final String taskName = 
taskComponent.getComponent().getClass().getSimpleName();
             final NodeTypeProvider nodeTypeProvider = new 
StatelessNodeTypeProvider();
 
@@ -222,7 +225,7 @@ public class ComponentBuilder {
 
     private LoggableComponent<ParameterProvider> 
createLoggableParameterProvider() throws 
ParameterProviderInstantiationException {
         try {
-            final LoggableComponent<ParameterProvider> taskComponent = 
createLoggableComponent(ParameterProvider.class);
+            final LoggableComponent<ParameterProvider> taskComponent = 
createLoggableComponent(ParameterProvider.class, new StandardLoggingContext());
             final String taskName = 
taskComponent.getComponent().getClass().getSimpleName();
             final NodeTypeProvider nodeTypeProvider = new 
StatelessNodeTypeProvider();
 
@@ -280,7 +283,8 @@ public class ComponentBuilder {
             }
 
             logger.info("Created Controller Service of type {} with identifier 
{}", type, identifier);
-            final ComponentLog serviceLogger = new 
SimpleProcessLogger(identifier, serviceImpl, new StandardLoggingContext(null));
+            final StandardLoggingContext loggingContext = new 
StandardLoggingContext();
+            final ComponentLog serviceLogger = new 
SimpleProcessLogger(identifier, serviceImpl, loggingContext);
             final TerminationAwareLogger terminationAwareLogger = new 
TerminationAwareLogger(serviceLogger);
 
             final StateManager stateManager = 
stateManagerProvider.getStateManager(identifier, rawClass);
@@ -295,6 +299,7 @@ public class ComponentBuilder {
             final ControllerServiceNode serviceNode = new 
StandardControllerServiceNode(originalLoggableComponent, 
proxiedLoggableComponent, invocationHandler,
                 identifier, validationContextFactory, serviceProvider, 
reloadComponent, extensionManager, validationTrigger);
             serviceNode.setName(rawClass.getSimpleName());
+            loggingContext.setComponent(serviceNode);
 
             invocationHandler.setServiceNode(serviceNode);
             return serviceNode;
@@ -307,12 +312,12 @@ public class ComponentBuilder {
         }
     }
 
-    private LoggableComponent<Processor> createLoggableProcessor() throws 
ProcessorInstantiationException {
+    private LoggableComponent<Processor> createLoggableProcessor(final 
LoggingContext loggingContext) throws ProcessorInstantiationException {
         try {
-            final LoggableComponent<Processor> processorComponent = 
createLoggableComponent(Processor.class);
-            final ProcessorInitializationContext initiContext = new 
StandardProcessorInitializationContext(identifier, 
processorComponent.getLogger(),
+            final LoggableComponent<Processor> processorComponent = 
createLoggableComponent(Processor.class, loggingContext);
+            final ProcessorInitializationContext initContext = new 
StandardProcessorInitializationContext(identifier, 
processorComponent.getLogger(),
                 statelessEngine.getControllerServiceProvider(), new 
StatelessNodeTypeProvider(), statelessEngine.getKerberosConfig());
-            processorComponent.getComponent().initialize(initiContext);
+            processorComponent.getComponent().initialize(initContext);
 
             return processorComponent;
         } catch (final Exception e) {
@@ -320,8 +325,10 @@ public class ComponentBuilder {
         }
     }
 
-    private <T extends ConfigurableComponent> LoggableComponent<T> 
createLoggableComponent(Class<T> nodeType) throws ClassNotFoundException, 
IllegalAccessException,
-        InstantiationException, NoSuchMethodException, 
InvocationTargetException {
+    private <T extends ConfigurableComponent> LoggableComponent<T> 
createLoggableComponent(
+            final Class<T> nodeType,
+            final LoggingContext loggingContext
+    ) throws ClassNotFoundException, IllegalAccessException, 
InstantiationException, NoSuchMethodException, InvocationTargetException {
 
         final ClassLoader ctxClassLoader = 
Thread.currentThread().getContextClassLoader();
         try {
@@ -345,7 +352,7 @@ public class ComponentBuilder {
             Thread.currentThread().setContextClassLoader(detectedClassLoader);
 
             final Object extensionInstance = 
rawClass.getDeclaredConstructor().newInstance();
-            final ComponentLog componentLog = new 
SimpleProcessLogger(identifier, extensionInstance, new 
StandardLoggingContext(null));
+            final ComponentLog componentLog = new 
SimpleProcessLogger(identifier, extensionInstance, loggingContext);
             final TerminationAwareLogger terminationAwareLogger = new 
TerminationAwareLogger(componentLog);
 
             final T cast = nodeType.cast(extensionInstance);
diff --git 
a/nifi-stateless/nifi-stateless-bundle/nifi-stateless-engine/src/main/java/org/apache/nifi/stateless/engine/StatelessReloadComponent.java
 
b/nifi-stateless/nifi-stateless-bundle/nifi-stateless-engine/src/main/java/org/apache/nifi/stateless/engine/StatelessReloadComponent.java
index 60633a2fd4..8814348811 100644
--- 
a/nifi-stateless/nifi-stateless-bundle/nifi-stateless-engine/src/main/java/org/apache/nifi/stateless/engine/StatelessReloadComponent.java
+++ 
b/nifi-stateless/nifi-stateless-bundle/nifi-stateless-engine/src/main/java/org/apache/nifi/stateless/engine/StatelessReloadComponent.java
@@ -98,7 +98,7 @@ public class StatelessReloadComponent implements 
ReloadComponent {
         }
 
         // set the new processor in the existing node
-        final ComponentLog componentLogger = new SimpleProcessLogger(id, 
newNode.getProcessor(), new StandardLoggingContext(null));
+        final ComponentLog componentLogger = new SimpleProcessLogger(id, 
newNode.getProcessor(), new StandardLoggingContext(newNode));
         final TerminationAwareLogger terminationAwareLogger = new 
TerminationAwareLogger(componentLogger);
         
LogRepositoryFactory.getRepository(id).setLogger(terminationAwareLogger);
 
@@ -157,7 +157,7 @@ public class StatelessReloadComponent implements 
ReloadComponent {
         invocationHandler.setServiceNode(existingNode);
 
         // create LoggableComponents for the proxy and implementation
-        final ComponentLog componentLogger = new SimpleProcessLogger(id, 
newNode.getControllerServiceImplementation(), new StandardLoggingContext(null));
+        final ComponentLog componentLogger = new SimpleProcessLogger(id, 
newNode.getControllerServiceImplementation(), new 
StandardLoggingContext(newNode));
         final TerminationAwareLogger terminationAwareLogger = new 
TerminationAwareLogger(componentLogger);
         
LogRepositoryFactory.getRepository(id).setLogger(terminationAwareLogger);
 
@@ -205,7 +205,7 @@ public class StatelessReloadComponent implements 
ReloadComponent {
         }
 
         // set the new reporting task into the existing node
-        final ComponentLog componentLogger = new SimpleProcessLogger(id, 
existingNode.getReportingTask(), new StandardLoggingContext(null));
+        final ComponentLog componentLogger = new SimpleProcessLogger(id, 
existingNode.getReportingTask(), new StandardLoggingContext());
         final TerminationAwareLogger terminationAwareLogger = new 
TerminationAwareLogger(componentLogger);
         
LogRepositoryFactory.getRepository(id).setLogger(terminationAwareLogger);
 
@@ -250,7 +250,7 @@ public class StatelessReloadComponent implements 
ReloadComponent {
         }
 
         // set the new reporting task into the existing node
-        final ComponentLog componentLogger = new SimpleProcessLogger(id, 
existingNode.getParameterProvider(), new StandardLoggingContext(null));
+        final ComponentLog componentLogger = new SimpleProcessLogger(id, 
existingNode.getParameterProvider(), new StandardLoggingContext());
         final TerminationAwareLogger terminationAwareLogger = new 
TerminationAwareLogger(componentLogger);
         
LogRepositoryFactory.getRepository(id).setLogger(terminationAwareLogger);
 
@@ -288,7 +288,7 @@ public class StatelessReloadComponent implements 
ReloadComponent {
         extensionManager.closeURLClassLoader(id, existingInstanceClassLoader);
 
         // set the new flow registry client into the existing node
-        final ComponentLog componentLogger = new SimpleProcessLogger(id, 
existingNode.getComponent(), new StandardLoggingContext(null));
+        final ComponentLog componentLogger = new SimpleProcessLogger(id, 
existingNode.getComponent(), new StandardLoggingContext());
         final TerminationAwareLogger terminationAwareLogger = new 
TerminationAwareLogger(componentLogger);
         
LogRepositoryFactory.getRepository(id).setLogger(terminationAwareLogger);
 
diff --git 
a/nifi-stateless/nifi-stateless-bundle/nifi-stateless-engine/src/main/java/org/apache/nifi/stateless/engine/StatelessSchedulingAgent.java
 
b/nifi-stateless/nifi-stateless-bundle/nifi-stateless-engine/src/main/java/org/apache/nifi/stateless/engine/StatelessSchedulingAgent.java
index 25c814a7e3..8860a16f29 100644
--- 
a/nifi-stateless/nifi-stateless-bundle/nifi-stateless-engine/src/main/java/org/apache/nifi/stateless/engine/StatelessSchedulingAgent.java
+++ 
b/nifi-stateless/nifi-stateless-bundle/nifi-stateless-engine/src/main/java/org/apache/nifi/stateless/engine/StatelessSchedulingAgent.java
@@ -90,7 +90,7 @@ public class StatelessSchedulingAgent implements 
SchedulingAgent {
             }
 
         } catch (final Throwable t) {
-            final ComponentLog componentLog = new 
SimpleProcessLogger(taskNode.getIdentifier(), taskNode.getReportingTask(), new 
StandardLoggingContext(null));
+            final ComponentLog componentLog = new 
SimpleProcessLogger(taskNode.getIdentifier(), taskNode.getReportingTask(), new 
StandardLoggingContext());
             componentLog.error("Error running task {}", 
taskNode.getReportingTask(), t);
             if (componentLog.isDebugEnabled()) {
                 componentLog.error("", t);


Reply via email to