summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/mountpoint-registrar/provider/src/main/java
diff options
context:
space:
mode:
authorhighstreetherbert <herbert.eiselt@highstreet-technologies.com>2020-07-15 19:23:07 +0200
committerhighstreetherbert <herbert.eiselt@highstreet-technologies.com>2020-07-16 13:06:25 +0200
commit3d93b15a297c0c661100c665aa5379bf4fedff7d (patch)
tree7f3d0b20ac34d85ca98936c4998f40ddf2de322e /sdnr/wt/mountpoint-registrar/provider/src/main/java
parent002ad417b90882524276d1b9cfe377c6f6293a4c (diff)
SDN-R Sodium compliant mountpoint-registrar
Adapted tests Issue-ID: CCSDK-2568 Signed-off-by: highstreetherbert <herbert.eiselt@highstreet-technologies.com> Change-Id: Iab79976a60a77f84bdaa1f191b58333a9b114149 Signed-off-by: highstreetherbert <herbert.eiselt@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/mountpoint-registrar/provider/src/main/java')
-rw-r--r--sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPFaultVESMsgConsumer.java19
-rw-r--r--sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPPNFRegVESMsgConsumer.java18
-rw-r--r--sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPVESMsgConsumerMain.java60
-rw-r--r--sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/GeneralConfig.java12
-rw-r--r--sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/MountpointRegistrarImpl.java13
5 files changed, 58 insertions, 64 deletions
diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPFaultVESMsgConsumer.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPFaultVESMsgConsumer.java
index 4e6cc996d..b0227da6f 100644
--- a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPFaultVESMsgConsumer.java
+++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPFaultVESMsgConsumer.java
@@ -18,15 +18,12 @@
package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
-
import java.io.IOException;
-
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SeverityType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class DMaaPFaultVESMsgConsumer extends DMaaPVESMsgConsumerImpl {
@@ -36,6 +33,12 @@ public class DMaaPFaultVESMsgConsumer extends DMaaPVESMsgConsumerImpl {
private static final String DEFAULT_SDNRUSER = "admin";
private static final String DEFAULT_SDNRPASSWD = "admin";
+ private final GeneralConfig generalConfig;
+
+ public DMaaPFaultVESMsgConsumer(GeneralConfig generalConfig) {
+ this.generalConfig = generalConfig;
+ }
+
@Override
public void processMsg(String msg) throws Exception {
String faultNodeId;
@@ -89,15 +92,15 @@ public class DMaaPFaultVESMsgConsumer extends DMaaPVESMsgConsumerImpl {
}
public String getBaseUrl() {
- return GeneralConfig.getBaseUrl();
+ return generalConfig.getBaseUrl();
}
public String getSDNRUser() {
- return GeneralConfig.getSDNRUser() != null ? GeneralConfig.getSDNRUser() : DEFAULT_SDNRUSER;
+ return generalConfig.getSDNRUser() != null ? generalConfig.getSDNRUser() : DEFAULT_SDNRUSER;
}
public String getSDNRPasswd() {
- return GeneralConfig.getSDNRPasswd() != null ? GeneralConfig.getSDNRPasswd() : DEFAULT_SDNRPASSWD;
+ return generalConfig.getSDNRPasswd() != null ? generalConfig.getSDNRPasswd() : DEFAULT_SDNRPASSWD;
}
public FaultNotificationClient getFaultNotificationClient(String baseUrl) {
diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPPNFRegVESMsgConsumer.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPPNFRegVESMsgConsumer.java
index ed9f583a5..c412a7a91 100644
--- a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPPNFRegVESMsgConsumer.java
+++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPPNFRegVESMsgConsumer.java
@@ -18,14 +18,12 @@
package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
public class DMaaPPNFRegVESMsgConsumer extends DMaaPVESMsgConsumerImpl {
private static final Logger LOG = LoggerFactory.getLogger(DMaaPPNFRegVESMsgConsumer.class);
@@ -36,6 +34,12 @@ public class DMaaPPNFRegVESMsgConsumer extends DMaaPVESMsgConsumerImpl {
private static final String DEFAULT_SDNRUSER = "admin";
private static final String DEFAULT_SDNRPASSWD = "admin";
+ private final GeneralConfig generalConfig;
+
+ public DMaaPPNFRegVESMsgConsumer(GeneralConfig generalConfig) {
+ this.generalConfig = generalConfig;
+ }
+
@Override
public void processMsg(String msg) {
LOG.debug("Message from DMaaP topic is - {} ", msg);
@@ -105,15 +109,15 @@ public class DMaaPPNFRegVESMsgConsumer extends DMaaPVESMsgConsumerImpl {
}
public String getBaseUrl() {
- return GeneralConfig.getBaseUrl();
+ return generalConfig.getBaseUrl();
}
public String getSDNRUser() {
- return GeneralConfig.getSDNRUser() != null ? GeneralConfig.getSDNRUser() : DEFAULT_SDNRUSER;
+ return generalConfig.getSDNRUser() != null ? generalConfig.getSDNRUser() : DEFAULT_SDNRUSER;
}
public String getSDNRPasswd() {
- return GeneralConfig.getSDNRPasswd() != null ? GeneralConfig.getSDNRPasswd() : DEFAULT_SDNRPASSWD;
+ return generalConfig.getSDNRPasswd() != null ? generalConfig.getSDNRPasswd() : DEFAULT_SDNRPASSWD;
}
public PNFMountPointClient getPNFMountPointClient(String baseUrl) {
diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPVESMsgConsumerMain.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPVESMsgConsumerMain.java
index 7b851aa5c..97dd79577 100644
--- a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPVESMsgConsumerMain.java
+++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPVESMsgConsumerMain.java
@@ -22,7 +22,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
-
import org.onap.ccsdk.features.sdnr.wt.common.configuration.Configuration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -30,14 +29,18 @@ import org.slf4j.LoggerFactory;
public class DMaaPVESMsgConsumerMain implements Runnable {
private static final Logger LOG = LoggerFactory.getLogger(DMaaPVESMsgConsumerMain.class);
-
+ private static final String pnfRegClass =
+ "org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPPNFRegVESMsgConsumer";
+ private static final String faultClass =
+ "org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPFaultVESMsgConsumer";
boolean threadsRunning = false;
- static List<DMaaPVESMsgConsumer> consumers = new LinkedList<>();
- public GeneralConfig config;
+ List<DMaaPVESMsgConsumer> consumers = new LinkedList<>();
public PNFRegistrationConfig pnfRegistrationConfig;
public FaultConfig faultConfig;
+ public GeneralConfig generalConfig;
- public DMaaPVESMsgConsumerMain(Map<String, Configuration> configMap) {
+ public DMaaPVESMsgConsumerMain(Map<String, Configuration> configMap, GeneralConfig generalConfig) {
+ this.generalConfig = generalConfig;
configMap.forEach((k, v) -> initialize(k, v));
}
@@ -77,6 +80,7 @@ public class DMaaPVESMsgConsumerMain implements Runnable {
pnfRegistrationConfig.getClientReadTimeout());
consumerProperties.put(PNFRegistrationConfig.PROPERTY_KEY_CONSUMER_CLIENT_CONNECTTIMEOUT,
pnfRegistrationConfig.getClientConnectTimeout());
+ threadsRunning = createConsumer("pnfRegistration", consumerProperties);
} else if (domain.equalsIgnoreCase("fault")) {
this.faultConfig = (FaultConfig) domainConfig;
consumerClass = faultConfig.getConsumerClass();
@@ -97,16 +101,11 @@ public class DMaaPVESMsgConsumerMain implements Runnable {
faultConfig.getClientReadTimeout());
consumerProperties.put(FaultConfig.PROPERTY_KEY_CONSUMER_CLIENT_CONNECTTIMEOUT,
faultConfig.getClientConnectTimeout());
+ threadsRunning = createConsumer("fault", consumerProperties);
}
-
- if (consumerClass != null) {
- LOG.info("Calling createConsumer : {}", consumerClass);
- threadsRunning = createConsumer(consumerClass, consumerProperties);
- }
-
}
- private static boolean updateThreadState(List<DMaaPVESMsgConsumer> consumers) {
+ private boolean updateThreadState(List<DMaaPVESMsgConsumer> consumers) {
boolean threadsRunning = false;
for (DMaaPVESMsgConsumer consumer : consumers) {
if (consumer.isRunning()) {
@@ -116,35 +115,21 @@ public class DMaaPVESMsgConsumerMain implements Runnable {
return threadsRunning;
}
- static boolean createConsumer(String consumerClassName, Properties properties) {
- Class<?> consumerClass = null;
+ public boolean createConsumer(String consumerType, Properties properties) {
+ DMaaPVESMsgConsumerImpl consumer = null;
- try {
- consumerClass = Class.forName(consumerClassName);
- } catch (Exception e) {
- LOG.error("Could not find DMaap VES Message consumer class {}", consumerClassName, e);
- }
+ if (consumerType.equalsIgnoreCase("pnfRegistration"))
+ consumer = new DMaaPPNFRegVESMsgConsumer(generalConfig);
+ else if (consumerType.equalsIgnoreCase("fault"))
+ consumer = new DMaaPFaultVESMsgConsumer(generalConfig);
- if (consumerClass != null) {
- LOG.debug("Calling handleConsumerClass");
- handleConsumerClass(consumerClass, consumerClassName, properties, consumers);
- }
+ handleConsumer(consumer, properties, consumers);
return !consumers.isEmpty();
}
- private static boolean handleConsumerClass(Class<?> consumerClass, String consumerClassName, Properties properties,
+ private boolean handleConsumer(DMaaPVESMsgConsumer consumer, Properties properties,
List<DMaaPVESMsgConsumer> consumers) {
- DMaaPVESMsgConsumer consumer = null;
-
- try {
- consumer = (DMaaPVESMsgConsumer) consumerClass.newInstance();
- LOG.debug("Successfully created an instance of consumerClass : {}", consumerClassName);
- } catch (Exception e) {
- LOG.error("Could not create consumer from class {}", consumerClassName, e);
- }
-
if (consumer != null) {
- LOG.info("Initializing consumer {}({})", consumerClassName, properties);
consumer.init(properties);
if (consumer.isReady()) {
@@ -152,15 +137,16 @@ public class DMaaPVESMsgConsumerMain implements Runnable {
consumerThread.start();
consumers.add(consumer);
- LOG.info("Started consumer thread ({} : {})", consumerClassName, properties);
+ LOG.info("Started consumer thread ({} : {})", consumer.getClass().getSimpleName(), properties);
return true;
} else {
- LOG.debug("Consumer {} is not ready", consumerClassName);
+ LOG.debug("Consumer {} is not ready", consumer.getClass().getSimpleName());
}
}
return false;
}
+ @Override
public void run() {
while (threadsRunning) {
threadsRunning = updateThreadState(consumers);
@@ -178,7 +164,7 @@ public class DMaaPVESMsgConsumerMain implements Runnable {
LOG.info("No listener threads running - exiting");
}
- public static List<DMaaPVESMsgConsumer> getConsumers() {
+ public List<DMaaPVESMsgConsumer> getConsumers() {
return consumers;
}
diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/GeneralConfig.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/GeneralConfig.java
index e8269ccda..f0d4323c4 100644
--- a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/GeneralConfig.java
+++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/GeneralConfig.java
@@ -44,11 +44,11 @@ public class GeneralConfig implements Configuration {
private static final String DEFAULT_VALUE_BASEURL = "http://localhost:8181";
- private static ConfigurationFileRepresentation configuration;
+ private ConfigurationFileRepresentation configuration;
public GeneralConfig(ConfigurationFileRepresentation configuration) {
- GeneralConfig.configuration = configuration;
- GeneralConfig.configuration.addSection(SECTION_MARKER);
+ this.configuration = configuration;
+ configuration.addSection(SECTION_MARKER);
defaults();
}
@@ -57,15 +57,15 @@ public class GeneralConfig implements Configuration {
return enabled;
}
- public static String getBaseUrl() {
+ public String getBaseUrl() {
return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_BASEURL);
}
- public static String getSDNRUser() {
+ public String getSDNRUser() {
return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_USER);
}
- public static String getSDNRPasswd() {
+ public String getSDNRPasswd() {
return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_USERPASSWD);
}
diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/MountpointRegistrarImpl.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/MountpointRegistrarImpl.java
index 12a992216..94b15a54c 100644
--- a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/MountpointRegistrarImpl.java
+++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/MountpointRegistrarImpl.java
@@ -21,11 +21,9 @@ package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-
import org.onap.ccsdk.features.sdnr.wt.common.configuration.Configuration;
import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
import org.onap.ccsdk.features.sdnr.wt.common.configuration.filechange.IConfigChangedListener;
-import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -40,6 +38,7 @@ public class MountpointRegistrarImpl implements AutoCloseable, IConfigChangedLis
private GeneralConfig generalConfig;
private boolean dmaapEnabled = false;
private Map<String, Configuration> configMap = new HashMap<>();
+ private DMaaPVESMsgConsumerMain dmaapConsumerMain = null;
// Blueprint 1
public MountpointRegistrarImpl() {
@@ -63,7 +62,8 @@ public class MountpointRegistrarImpl implements AutoCloseable, IConfigChangedLis
dmaapEnabled = generalConfig.getEnabled();
if (dmaapEnabled) { // start dmaap consumer thread only if dmaapEnabled=true
LOG.info("DMaaP seems to be enabled, starting consumer(s)");
- dmaapVESMsgConsumerMain = new Thread(new DMaaPVESMsgConsumerMain(configMap));
+ dmaapConsumerMain = new DMaaPVESMsgConsumerMain(configMap, generalConfig);
+ dmaapVESMsgConsumerMain = new Thread(dmaapConsumerMain);
dmaapVESMsgConsumerMain.start();
} else {
LOG.info("DMaaP seems to be disabled, not starting any consumer(s)");
@@ -72,7 +72,7 @@ public class MountpointRegistrarImpl implements AutoCloseable, IConfigChangedLis
/**
* Reflect status for Unit Tests
- *
+ *
* @return Text with status
*/
public String isInitializationOk() {
@@ -85,11 +85,12 @@ public class MountpointRegistrarImpl implements AutoCloseable, IConfigChangedLis
boolean dmaapEnabledNewVal = generalConfig.getEnabled();
if (!dmaapEnabled && dmaapEnabledNewVal) { // Dmaap disabled earlier (or during bundle startup) but enabled later, start Consumer(s)
LOG.info("DMaaP is enabled, starting consumer(s)");
- dmaapVESMsgConsumerMain = new Thread(new DMaaPVESMsgConsumerMain(configMap));
+ dmaapConsumerMain = new DMaaPVESMsgConsumerMain(configMap, generalConfig);
+ dmaapVESMsgConsumerMain = new Thread(dmaapConsumerMain);
dmaapVESMsgConsumerMain.start();
} else if (dmaapEnabled && !dmaapEnabledNewVal) { // Dmaap enabled earlier (or during bundle startup) but disabled later, stop consumer(s)
LOG.info("DMaaP is disabled, stopping consumer(s)");
- List<DMaaPVESMsgConsumer> consumers = DMaaPVESMsgConsumerMain.getConsumers();
+ List<DMaaPVESMsgConsumer> consumers = dmaapConsumerMain.getConsumers();
for (DMaaPVESMsgConsumer consumer : consumers) {
// stop all consumers
consumer.stopConsumer();