diff options
author | Ravi Pendurty <ravi.pendurty@highstreet-technologies.com> | 2020-10-16 07:34:34 +0200 |
---|---|---|
committer | Ravi Pendurty <ravi.pendurty@highstreet-technologies.com> | 2020-10-16 07:35:02 +0200 |
commit | 84592e17c68253e101085307b6d8717a2fc2adbf (patch) | |
tree | c9adafa185e612730fed95701c3a618be659518e /sdnr/wt/mountpoint-state-provider | |
parent | a09598cb10c7a713d00d0876a102121e60261ba6 (diff) |
Enable and Disable writing mountpoint state changes to VES Collector
Enable and Disable writing mountpoint state changes to VES Collector
Issue-ID: SDNC-1382
Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com>
Change-Id: I92113b9d05a509f74dfdb9af44daa5431cfa40d0
Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/mountpoint-state-provider')
2 files changed, 42 insertions, 3 deletions
diff --git a/sdnr/wt/mountpoint-state-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/impl/MountpointStateProviderImpl.java b/sdnr/wt/mountpoint-state-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/impl/MountpointStateProviderImpl.java index 6838bc3b2..e00b656f2 100644 --- a/sdnr/wt/mountpoint-state-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/impl/MountpointStateProviderImpl.java +++ b/sdnr/wt/mountpoint-state-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/impl/MountpointStateProviderImpl.java @@ -25,11 +25,14 @@ package org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.impl; import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NetconfNetworkElementService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorCfgService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorConfigChangeListener; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService; import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNodeStateService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class MountpointStateProviderImpl implements AutoCloseable { +public class MountpointStateProviderImpl implements VESCollectorConfigChangeListener, AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(MountpointStateProviderImpl.class); private static final String APPLICATION_NAME = "mountpoint-state-provider"; @@ -40,6 +43,8 @@ public class MountpointStateProviderImpl implements AutoCloseable { private MountpointNodeConnectListenerImpl nodeConnectListener; private MountpointNodeStateListenerImpl nodeStateListener; private MountpointStatePublisher mountpointStatePublisher; + private VESCollectorService vesCollectorService; + private boolean vesCollectorEnabledCV = false; //Current value public MountpointStateProviderImpl() { LOG.info("Creating provider class for {}", APPLICATION_NAME); @@ -60,8 +65,13 @@ public class MountpointStateProviderImpl implements AutoCloseable { nodeConnectListener = new MountpointNodeConnectListenerImpl(netconfNodeStateService); nodeStateListener = new MountpointNodeStateListenerImpl(netconfNodeStateService); + vesCollectorService = netconfNetworkElementService.getServiceProvider().getVESCollectorService(); + vesCollectorService.registerForChanges(this); + boolean vesCollectorEnabled = vesCollectorService.getConfig().isVESCollectorEnabled(); - startPublishing(); + if (vesCollectorEnabled) { + startPublishing(); + } } /** @@ -74,7 +84,8 @@ public class MountpointStateProviderImpl implements AutoCloseable { } public void startPublishing() { - mountpointStatePublisher = new MountpointStatePublisher(netconfNetworkElementService.getServiceProvider().getVESCollectorService()); + mountpointStatePublisher = new MountpointStatePublisher( + netconfNetworkElementService.getServiceProvider().getVESCollectorService()); Thread t = new Thread(mountpointStatePublisher); t.start(); @@ -82,10 +93,16 @@ public class MountpointStateProviderImpl implements AutoCloseable { nodeStateListener.start(mountpointStatePublisher); } + public void stopPublishing() throws Exception { + mountpointStatePublisher.stop(); + close(nodeConnectListener, nodeStateListener); + } + @Override public void close() throws Exception { LOG.info("{} closing ...", this.getClass().getName()); mountpointStatePublisher.stop(); + vesCollectorService.deregister(this); close(nodeConnectListener, nodeStateListener); LOG.info("{} closing done", APPLICATION_NAME); } @@ -103,4 +120,22 @@ public class MountpointStateProviderImpl implements AutoCloseable { } } } + + @Override + public void notify(VESCollectorCfgService cfg) { + boolean vesCollectorEnabledPV = cfg.isVESCollectorEnabled(); // Pending value a.k.a new value + if (vesCollectorEnabledPV != vesCollectorEnabledCV) { + vesCollectorEnabledCV = vesCollectorEnabledPV; + if (vesCollectorEnabledPV) { + startPublishing(); + } else { + try { + stopPublishing(); + } catch (Exception e) { + LOG.debug("{}", e); + } + } + } + } + } diff --git a/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointStateProviderImpl.java b/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointStateProviderImpl.java index 4e4ac3064..709d92140 100644 --- a/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointStateProviderImpl.java +++ b/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointStateProviderImpl.java @@ -30,6 +30,7 @@ import java.io.IOException; import org.junit.Test; import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider; import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NetconfNetworkElementService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorCfgService; import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService; import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.impl.MountpointStateProviderImpl; import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNodeStateService; @@ -46,10 +47,13 @@ public class TestMountpointStateProviderImpl { NetconfNodeStateService netconfNodeStateService = mock(NetconfNodeStateService.class); DeviceManagerServiceProvider serviceProvider = mock(DeviceManagerServiceProvider.class); VESCollectorService vesCollectorService = mock(VESCollectorService.class); + VESCollectorCfgService vesCollectorCfgService = mock(VESCollectorCfgService.class); NetconfNetworkElementService netconfNetworkElementService = mock(NetconfNetworkElementService.class); when(netconfNetworkElementService.getServiceProvider()).thenReturn(serviceProvider); when(serviceProvider.getVESCollectorService()).thenReturn(vesCollectorService); + when(vesCollectorService.getConfig()).thenReturn(vesCollectorCfgService); + when(vesCollectorCfgService.isVESCollectorEnabled()).thenReturn(true); mountpointStateProvider = new MountpointStateProviderImpl(); mountpointStateProvider.setNetconfNetworkElementService(netconfNetworkElementService); |