From fe84190a2fe6c6237db0d24f1e6dda09bb90527b Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Sat, 10 Sep 2016 13:50:26 +0200 Subject: Allow HC user to enable/disable NSH module Because NSH plugin is optional in VPP, it is disabled by default in HC. Change-Id: I6842c68b94144b7ba7e9f6f87a2395e0d692a70c Signed-off-by: Marek Gradzki --- .../io/fd/honeycomb/vppnsh/impl/VppNshModule.java | 43 ++++++++++++++++------ .../fd/honeycomb/vppnsh/impl/cfgattrs/vppnsh.json | 3 -- .../honeycomb-minimal-resources/config/vppnsh.json | 3 ++ 3 files changed, 35 insertions(+), 14 deletions(-) delete mode 100644 nsh/impl/src/main/java/io/fd/honeycomb/vppnsh/impl/cfgattrs/vppnsh.json create mode 100644 nsh/impl/src/main/resources/honeycomb-minimal-resources/config/vppnsh.json diff --git a/nsh/impl/src/main/java/io/fd/honeycomb/vppnsh/impl/VppNshModule.java b/nsh/impl/src/main/java/io/fd/honeycomb/vppnsh/impl/VppNshModule.java index 48f323394..ec1be5bab 100755 --- a/nsh/impl/src/main/java/io/fd/honeycomb/vppnsh/impl/VppNshModule.java +++ b/nsh/impl/src/main/java/io/fd/honeycomb/vppnsh/impl/VppNshModule.java @@ -16,36 +16,41 @@ package io.fd.honeycomb.vppnsh.impl; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; - import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; import com.google.inject.Singleton; import com.google.inject.multibindings.Multibinder; import com.google.inject.name.Names; import io.fd.honeycomb.data.init.DataTreeInitializer; -import io.fd.honeycomb.notification.ManagedNotificationProducer; +import io.fd.honeycomb.translate.read.ReaderFactory; +import io.fd.honeycomb.translate.v3po.util.NamingContext; +import io.fd.honeycomb.translate.write.WriterFactory; import io.fd.honeycomb.vppnsh.impl.cfgattrs.VppNshConfiguration; import io.fd.honeycomb.vppnsh.impl.config.VppNshWriterFactory; -import io.fd.honeycomb.vppnsh.impl.oper.VppNshReaderFactory; import io.fd.honeycomb.vppnsh.impl.init.VppNshInitializer; +import io.fd.honeycomb.vppnsh.impl.oper.VppNshReaderFactory; import io.fd.honeycomb.vppnsh.impl.util.JVppNshProvider; -import io.fd.honeycomb.translate.read.ReaderFactory; -import io.fd.honeycomb.translate.v3po.util.NamingContext; -import io.fd.honeycomb.translate.write.WriterFactory; import net.jmob.guice.conf.core.ConfigurationModule; import org.openvpp.jvpp.nsh.future.FutureJVppNsh; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * This is some glue code necessary for Honeycomb distribution to pick up the plugin classes */ public final class VppNshModule extends AbstractModule { + private static final Logger LOG = LoggerFactory.getLogger(VppNshModule.class); + @Override protected void configure() { - // These are plugin specific config attributes - install(ConfigurationModule.create()); - requestInjection(VppNshConfiguration.class); + // TODO HONEYCOMB-207 workaround: + if (!isEnabled()) { + LOG.info("VppNshModule is disabled. Skipping module configuration."); + return; + } + LOG.info("Configuring VppNsh module"); // Naming contexts bind(NamingContext.class) @@ -63,5 +68,21 @@ public final class VppNshModule extends AbstractModule { Multibinder.newSetBinder(binder(), WriterFactory.class).addBinding().to(VppNshWriterFactory.class); Multibinder.newSetBinder(binder(), ReaderFactory.class).addBinding().to(VppNshReaderFactory.class); Multibinder.newSetBinder(binder(), DataTreeInitializer.class).addBinding().to(VppNshInitializer.class); + LOG.info("NSH module successfully configured"); + } + + private static boolean isEnabled() { + final Injector injector = Guice.createInjector(new AbstractModule() { + @Override + protected void configure() { + // These are plugin specific config attributes + install(ConfigurationModule.create()); + requestInjection(VppNshConfiguration.class); + } + }); + + final VppNshConfiguration cfgAttributes = injector.getInstance(VppNshConfiguration.class); + LOG.debug("Configuration for VppNsh module: {}", cfgAttributes); + return cfgAttributes.isNshEnabled(); } } diff --git a/nsh/impl/src/main/java/io/fd/honeycomb/vppnsh/impl/cfgattrs/vppnsh.json b/nsh/impl/src/main/java/io/fd/honeycomb/vppnsh/impl/cfgattrs/vppnsh.json deleted file mode 100644 index f2fe985b9..000000000 --- a/nsh/impl/src/main/java/io/fd/honeycomb/vppnsh/impl/cfgattrs/vppnsh.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "nsh-enabled" : "false" -} diff --git a/nsh/impl/src/main/resources/honeycomb-minimal-resources/config/vppnsh.json b/nsh/impl/src/main/resources/honeycomb-minimal-resources/config/vppnsh.json new file mode 100644 index 000000000..b03a962f1 --- /dev/null +++ b/nsh/impl/src/main/resources/honeycomb-minimal-resources/config/vppnsh.json @@ -0,0 +1,3 @@ +{ + "nsh-enabled": "false" +} \ No newline at end of file -- cgit 1.2.3-korg