summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRavi Pendurty <ravi.pendurty@highstreet-technologies.com>2020-10-16 07:34:34 +0200
committerDan Timoney <dtimoney@att.com>2020-10-16 13:05:36 +0000
commitcbf047c16ff2f7373a880eab98f7cb55be5d0f5e (patch)
tree2d60a0fd7449b779a4a0935b76eeb189c7a4aa3c
parent137ab8b058c7d6191ae7ea866481c7cae1774218 (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>
-rw-r--r--sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/service/VESCollectorCfgService.java1
-rw-r--r--sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/service/VESCollectorConfigChangeListener.java27
-rw-r--r--sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/service/VESCollectorService.java3
-rw-r--r--sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/vescollectorconnector/impl/VESCollectorClient.java21
-rw-r--r--sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/vescollectorconnector/impl/config/VESCollectorCfgImpl.java10
-rw-r--r--sdnr/wt/mountpoint-state-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/impl/MountpointStateProviderImpl.java41
-rw-r--r--sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointStateProviderImpl.java4
7 files changed, 104 insertions, 3 deletions
diff --git a/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/service/VESCollectorCfgService.java b/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/service/VESCollectorCfgService.java
index 3bbdfe10a..c274ff91c 100644
--- a/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/service/VESCollectorCfgService.java
+++ b/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/service/VESCollectorCfgService.java
@@ -25,4 +25,5 @@ public interface VESCollectorCfgService {
String getReportingEntityName();
String getEventLogMsgDetail();
+ boolean isVESCollectorEnabled();
}
diff --git a/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/service/VESCollectorConfigChangeListener.java b/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/service/VESCollectorConfigChangeListener.java
new file mode 100644
index 000000000..ac46b1c27
--- /dev/null
+++ b/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/service/VESCollectorConfigChangeListener.java
@@ -0,0 +1,27 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk features
+ * ================================================================================
+ * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
+ * All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ */
+package org.onap.ccsdk.features.sdnr.wt.devicemanager.service;
+
+public interface VESCollectorConfigChangeListener {
+
+ public void notify(VESCollectorCfgService cfg);
+}
diff --git a/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/service/VESCollectorService.java b/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/service/VESCollectorService.java
index d6b965134..287f0f622 100644
--- a/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/service/VESCollectorService.java
+++ b/sdnr/wt/devicemanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/service/VESCollectorService.java
@@ -33,4 +33,7 @@ public interface VESCollectorService extends DeviceManagerService {
VESCollectorCfgService getConfig();
boolean publishVESMessage(String vesMsg);
+ public void registerForChanges(VESCollectorConfigChangeListener o);
+ public void deregister(VESCollectorConfigChangeListener o);
+
}
diff --git a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/vescollectorconnector/impl/VESCollectorClient.java b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/vescollectorconnector/impl/VESCollectorClient.java
index 3b1f71215..70ff86009 100644
--- a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/vescollectorconnector/impl/VESCollectorClient.java
+++ b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/vescollectorconnector/impl/VESCollectorClient.java
@@ -22,13 +22,17 @@
package org.onap.ccsdk.features.sdnr.wt.devicemanager.vescollectorconnector.impl;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Base64;
import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
import org.onap.ccsdk.features.sdnr.wt.common.configuration.filechange.IConfigChangedListener;
import org.onap.ccsdk.features.sdnr.wt.common.http.BaseHTTPClient;
import org.onap.ccsdk.features.sdnr.wt.common.http.BaseHTTPResponse;
+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.devicemanager.vescollectorconnector.impl.config.VESCollectorCfgImpl;
import org.slf4j.Logger;
@@ -40,8 +44,10 @@ public class VESCollectorClient implements VESCollectorService, IConfigChangedLi
private final ConfigurationFileRepresentation cfg;
private BaseHTTPClient httpClient;
private final Map<String, String> headerMap;
+ private List<VESCollectorConfigChangeListener> registeredObjects;
public VESCollectorClient(ConfigurationFileRepresentation config) {
+ registeredObjects = new ArrayList<VESCollectorConfigChangeListener>();
this.vesConfig = new VESCollectorCfgImpl(config);
this.cfg = config;
this.cfg.registerConfigChangedListener(this);
@@ -105,6 +111,21 @@ public class VESCollectorClient implements VESCollectorService, IConfigChangedLi
public void onConfigChanged() {
httpClient.setBaseUrl(getBaseUrl());
setAuthorization(getConfig().getUsername(), getConfig().getPassword());
+ Iterator<VESCollectorConfigChangeListener> it = registeredObjects.iterator();
+ while (it.hasNext()) {
+ VESCollectorConfigChangeListener o = it.next();
+ o.notify(getConfig());
+ }
+ }
+
+ @Override
+ public void registerForChanges(VESCollectorConfigChangeListener o) {
+ registeredObjects.add(o);
+ }
+
+ @Override
+ public void deregister(VESCollectorConfigChangeListener o) {
+ registeredObjects.remove(o);
}
}
diff --git a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/vescollectorconnector/impl/config/VESCollectorCfgImpl.java b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/vescollectorconnector/impl/config/VESCollectorCfgImpl.java
index 1924a6759..c3bddc9b1 100644
--- a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/vescollectorconnector/impl/config/VESCollectorCfgImpl.java
+++ b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/vescollectorconnector/impl/config/VESCollectorCfgImpl.java
@@ -29,6 +29,10 @@ public class VESCollectorCfgImpl implements VESCollectorCfgService, Configuratio
private static final String SECTION_MARKER = "VESCollector";
+ /** set to true if VES Collector is installed and configured */
+ private static final String PROPERTY_KEY_VES_COLLECTOR_ENABLED = "VES_COLLECTOR_ENABLED";
+ private static final boolean DEFAULT_VALUE_VES_COLLECTOR_ENABLED = false;
+
private static final String PROPERTY_KEY_VES_COLLECTOR_IP = "VES_COLLECTOR_IP";
private static final String DEFAULT_VALUE_VES_COLLECTOR_IP = "127.0.0.1";
@@ -76,6 +80,11 @@ public class VESCollectorCfgImpl implements VESCollectorCfgService, Configuratio
return configuration != null ?configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_EVENTLOG_DETAIL) : DEFAULT_VALUE_EVENTLOG_DETAIL;
}
+ @Override
+ public boolean isVESCollectorEnabled() {
+ return configuration.getPropertyBoolean(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_ENABLED);
+ }
+
public boolean getTLSEnabled() {
return configuration.getPropertyBoolean(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_TLS_ENABLED);
}
@@ -102,6 +111,7 @@ public class VESCollectorCfgImpl implements VESCollectorCfgService, Configuratio
@Override
public synchronized void defaults() {
+ configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_ENABLED, DEFAULT_VALUE_VES_COLLECTOR_ENABLED);
configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_TLS_ENABLED, Boolean.FALSE);
configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_USERNAME,
DEFAULT_VALUE_VES_COLLECTOR_USERNAME);
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);