NIFI-3510: Added logging for when controller services are enabled/disabled

Signed-off-by: Pierre Villard <pierre.villard.fr@gmail.com>

This closes #2151.
This commit is contained in:
m-hogue 2017-09-12 16:30:02 -04:00 committed by Pierre Villard
parent e01d59a462
commit 91383264d8
1 changed files with 6 additions and 2 deletions

View File

@ -399,6 +399,7 @@ public class StandardControllerServiceNode extends AbstractConfiguredComponent i
this.active.set(true);
}
final StandardControllerServiceNode service = this;
final ConfigurationContext configContext = new StandardConfigurationContext(this, this.serviceProvider, null, getVariableRegistry());
scheduler.execute(new Runnable() {
@Override
@ -408,17 +409,19 @@ public class StandardControllerServiceNode extends AbstractConfiguredComponent i
ReflectionUtils.invokeMethodsWithAnnotation(OnEnabled.class, getControllerServiceImplementation(), configContext);
}
boolean shouldEnable = false;
boolean shouldEnable;
synchronized (active) {
shouldEnable = active.get() && stateTransition.enable();
}
if (!shouldEnable) {
LOG.debug("Disabling service " + this + " after it has been enabled due to disable action being initiated.");
LOG.debug("Disabling service {} after it has been enabled due to disable action being initiated.", service);
// Can only happen if user initiated DISABLE operation before service finished enabling. It's state will be
// set to DISABLING (see disable() operation)
invokeDisable(configContext);
stateTransition.disable();
} else {
LOG.debug("Successfully enabled {}", service);
}
} catch (Exception e) {
future.completeExceptionally(e);
@ -499,6 +502,7 @@ public class StandardControllerServiceNode extends AbstractConfiguredComponent i
private void invokeDisable(ConfigurationContext configContext) {
try (final NarCloseable nc = NarCloseable.withComponentNarLoader(getControllerServiceImplementation().getClass(), getIdentifier())) {
ReflectionUtils.invokeMethodsWithAnnotation(OnDisabled.class, StandardControllerServiceNode.this.getControllerServiceImplementation(), 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);