NIFI-4816: Allow name to be updated for ReportingTasks

This closes #2452

Signed-off-by: Scott Aslan <scottyaslan@gmail.com>
This commit is contained in:
Matthew Burgess 2018-02-06 16:33:56 -05:00 committed by Scott Aslan
parent 54b1659704
commit b4b970b876
5 changed files with 32 additions and 0 deletions

View File

@ -52,4 +52,10 @@ public interface ConfigurationContext extends PropertyContext {
* period * period
*/ */
Long getSchedulingPeriod(TimeUnit timeUnit); Long getSchedulingPeriod(TimeUnit timeUnit);
/**
* Returns the component's (ControllerService, ReportingTask, e.g.) name
* @return the String name of this component
*/
String getName();
} }

View File

@ -18,7 +18,9 @@ package org.apache.nifi.reporting;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.apache.nifi.annotation.lifecycle.OnScheduled;
import org.apache.nifi.components.AbstractConfigurableComponent; import org.apache.nifi.components.AbstractConfigurableComponent;
import org.apache.nifi.controller.ConfigurationContext;
import org.apache.nifi.controller.ControllerServiceLookup; import org.apache.nifi.controller.ControllerServiceLookup;
import org.apache.nifi.controller.NodeTypeProvider; import org.apache.nifi.controller.NodeTypeProvider;
import org.apache.nifi.logging.ComponentLog; import org.apache.nifi.logging.ComponentLog;
@ -75,6 +77,15 @@ public abstract class AbstractReportingTask extends AbstractConfigurableComponen
return name; 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 * @param timeUnit of scheduling period
* @return the amount of times that elapses between the moment that this * @return the amount of times that elapses between the moment that this

View File

@ -97,4 +97,9 @@ public class MockConfigurationContext implements ConfigurationContext {
public Long getSchedulingPeriod(final TimeUnit timeUnit) { public Long getSchedulingPeriod(final TimeUnit timeUnit) {
return 0L; return 0L;
} }
@Override
public String getName() {
return null;
}
} }

View File

@ -100,4 +100,9 @@ public class StandardConfigurationContext implements ConfigurationContext {
public Long getSchedulingPeriod(final TimeUnit timeUnit) { public Long getSchedulingPeriod(final TimeUnit timeUnit) {
return schedulingNanos == null ? null : timeUnit.convert(schedulingNanos, TimeUnit.NANOSECONDS); return schedulingNanos == null ? null : timeUnit.convert(schedulingNanos, TimeUnit.NANOSECONDS);
} }
@Override
public String getName() {
return component.getName();
}
} }

View File

@ -50,4 +50,9 @@ public class MockConfigurationContext implements ConfigurationContext {
public Long getSchedulingPeriod(final TimeUnit timeUnit) { public Long getSchedulingPeriod(final TimeUnit timeUnit) {
return 0L; return 0L;
} }
@Override
public String getName() {
return null;
}
} }