diff --git a/nifi-api/src/main/java/org/apache/nifi/controller/ConfigurationContext.java b/nifi-api/src/main/java/org/apache/nifi/controller/ConfigurationContext.java index e6b3cb2613..c1316b5536 100644 --- a/nifi-api/src/main/java/org/apache/nifi/controller/ConfigurationContext.java +++ b/nifi-api/src/main/java/org/apache/nifi/controller/ConfigurationContext.java @@ -52,4 +52,10 @@ public interface ConfigurationContext extends PropertyContext { * period */ Long getSchedulingPeriod(TimeUnit timeUnit); + + /** + * Returns the component's (ControllerService, ReportingTask, e.g.) name + * @return the String name of this component + */ + String getName(); } diff --git a/nifi-api/src/main/java/org/apache/nifi/reporting/AbstractReportingTask.java b/nifi-api/src/main/java/org/apache/nifi/reporting/AbstractReportingTask.java index 93d23b22f8..339231ae32 100644 --- a/nifi-api/src/main/java/org/apache/nifi/reporting/AbstractReportingTask.java +++ b/nifi-api/src/main/java/org/apache/nifi/reporting/AbstractReportingTask.java @@ -18,7 +18,9 @@ package org.apache.nifi.reporting; import java.util.concurrent.TimeUnit; +import org.apache.nifi.annotation.lifecycle.OnScheduled; import org.apache.nifi.components.AbstractConfigurableComponent; +import org.apache.nifi.controller.ConfigurationContext; import org.apache.nifi.controller.ControllerServiceLookup; import org.apache.nifi.controller.NodeTypeProvider; import org.apache.nifi.logging.ComponentLog; @@ -75,6 +77,15 @@ public abstract class AbstractReportingTask extends AbstractConfigurableComponen return name; } + /** + * Sets various component information using the given context + * @param context the context to use for this reporting task + */ + @OnScheduled + public void setComponentInfo(ConfigurationContext context) { + this.name = context.getName(); + } + /** * @param timeUnit of scheduling period * @return the amount of times that elapses between the moment that this diff --git a/nifi-mock/src/main/java/org/apache/nifi/util/MockConfigurationContext.java b/nifi-mock/src/main/java/org/apache/nifi/util/MockConfigurationContext.java index 91d805e2e8..307f474fd7 100644 --- a/nifi-mock/src/main/java/org/apache/nifi/util/MockConfigurationContext.java +++ b/nifi-mock/src/main/java/org/apache/nifi/util/MockConfigurationContext.java @@ -97,4 +97,9 @@ public class MockConfigurationContext implements ConfigurationContext { public Long getSchedulingPeriod(final TimeUnit timeUnit) { return 0L; } + + @Override + public String getName() { + return null; + } } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardConfigurationContext.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardConfigurationContext.java index c188d75adf..6e8ff6cd56 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardConfigurationContext.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardConfigurationContext.java @@ -100,4 +100,9 @@ public class StandardConfigurationContext implements ConfigurationContext { public Long getSchedulingPeriod(final TimeUnit timeUnit) { return schedulingNanos == null ? null : timeUnit.convert(schedulingNanos, TimeUnit.NANOSECONDS); } + + @Override + public String getName() { + return component.getName(); + } } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-nar-utils/src/main/java/org/apache/nifi/mock/MockConfigurationContext.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-nar-utils/src/main/java/org/apache/nifi/mock/MockConfigurationContext.java index d9a1b37888..4459d14ddf 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-nar-utils/src/main/java/org/apache/nifi/mock/MockConfigurationContext.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-nar-utils/src/main/java/org/apache/nifi/mock/MockConfigurationContext.java @@ -50,4 +50,9 @@ public class MockConfigurationContext implements ConfigurationContext { public Long getSchedulingPeriod(final TimeUnit timeUnit) { return 0L; } + + @Override + public String getName() { + return null; + } }