From 5fd09f98a9fde773b275c2266f39552cda861713 Mon Sep 17 00:00:00 2001 From: Maros Marsalek Date: Thu, 3 Nov 2016 18:04:26 +0100 Subject: Make persistence optional Change-Id: I9db2d9705abeb27be0fb0c71229386b1943dcaf9 Signed-off-by: Maros Marsalek --- .../infra/distro/cfgattrs/HoneycombConfiguration.java | 11 +++++++++++ .../infra/distro/data/PersistingDataTreeProvider.java | 19 +++++++++++++++++-- .../honeycomb-minimal-resources/config/honeycomb.json | 2 ++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/cfgattrs/HoneycombConfiguration.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/cfgattrs/HoneycombConfiguration.java index 8c09c7b71..cc46f7b8e 100644 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/cfgattrs/HoneycombConfiguration.java +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/cfgattrs/HoneycombConfiguration.java @@ -55,10 +55,21 @@ public class HoneycombConfiguration { return isNetconfTcpEnabled() || isNetconfSshEnabled(); } + public boolean isConfigPersistenceEnabled() { + return persistConfig.isPresent() && Boolean.valueOf(persistConfig.get()); + } + public boolean isContextPersistenceEnabled() { + return persistContext.isPresent() && Boolean.valueOf(persistContext.get()); + } + + @InjectConfig("persist-context") + public Optional persistContext = Optional.of("true"); @InjectConfig("persisted-context-path") public String peristContextPath; @InjectConfig("persisted-context-restoration-type") public String persistedContextRestorationType; + @InjectConfig("persist-config") + public Optional persistConfig = Optional.of("true"); @InjectConfig("persisted-config-path") public String peristConfigPath; @InjectConfig("persisted-config-restoration-type") diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/PersistingDataTreeProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/PersistingDataTreeProvider.java index fb4ebc69d..e7a654c7d 100644 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/PersistingDataTreeProvider.java +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/PersistingDataTreeProvider.java @@ -34,8 +34,10 @@ public abstract class PersistingDataTreeProvider extends ProviderTrait @Inject protected HoneycombConfiguration config; - public PersistingDataTreeAdapter create() { - return new PersistingDataTreeAdapter(getDelegate(), schemaService, Paths.get(getPath())); + public DataTree create() { + return isEnabled() + ? new PersistingDataTreeAdapter(getDelegate(), schemaService, Paths.get(getPath())) + : getDelegate(); } public abstract String getPath(); @@ -44,6 +46,8 @@ public abstract class PersistingDataTreeProvider extends ProviderTrait public abstract DataTree getDelegate(); + protected abstract boolean isEnabled(); + public static final class ConfigPersistingDataTreeProvider extends PersistingDataTreeProvider { @Inject @@ -61,6 +65,11 @@ public abstract class PersistingDataTreeProvider extends ProviderTrait public DataTree getDelegate() { return delegate; } + + @Override + protected boolean isEnabled() { + return config.isConfigPersistenceEnabled(); + } } public static final class ContextPersistingDataTreeProvider extends PersistingDataTreeProvider { @@ -80,5 +89,11 @@ public abstract class PersistingDataTreeProvider extends ProviderTrait public DataTree getDelegate() { return delegate; } + + @Override + protected boolean isEnabled() { + return config.isContextPersistenceEnabled(); + } + } } diff --git a/infra/minimal-distribution/src/main/resources/honeycomb-minimal-resources/config/honeycomb.json b/infra/minimal-distribution/src/main/resources/honeycomb-minimal-resources/config/honeycomb.json index 0c35c5262..1199f85bc 100644 --- a/infra/minimal-distribution/src/main/resources/honeycomb-minimal-resources/config/honeycomb.json +++ b/infra/minimal-distribution/src/main/resources/honeycomb-minimal-resources/config/honeycomb.json @@ -1,6 +1,8 @@ { + "persist-context": "true", "persisted-context-path": "/var/lib/honeycomb/persist/context/data.json", "persisted-context-restoration-type": "Merge", + "persist-config": "true", "persisted-config-path": "/var/lib/honeycomb/persist/config/data.json", "persisted-config-restoration-type": "Merge", -- cgit 1.2.3-korg