summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiProvider.java3
-rw-r--r--dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/DmaapListener.java280
-rw-r--r--dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncDmaapConsumer.java234
-rw-r--r--dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncFlatJsonDmaapConsumer.java223
-rw-r--r--dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncOdlConnection.java226
-rw-r--r--ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java11
-rw-r--r--ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java165
-rw-r--r--ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java19
-rw-r--r--ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java26
9 files changed, 574 insertions, 613 deletions
diff --git a/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiProvider.java b/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiProvider.java
index b9c897ec0..cebcb9986 100644
--- a/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiProvider.java
+++ b/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiProvider.java
@@ -157,8 +157,7 @@ public class AsdcApiProvider implements AutoCloseable, ASDCAPIService {
LOG.info("Create Containers succeeded!: ");
} catch (InterruptedException | ExecutionException e) {
- LOG.error("Create Containers Failed: " + e);
- e.printStackTrace();
+ LOG.error("Create Containers Failed: ", e);
}
} else {
LOG.warn("createContainers : cannot find dataBroker to create containers");
diff --git a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/DmaapListener.java b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/DmaapListener.java
index 91afe1d1a..de76e454e 100644
--- a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/DmaapListener.java
+++ b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/DmaapListener.java
@@ -26,140 +26,156 @@ import java.io.FileInputStream;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DmaapListener {
-
- private static final String DMAAP_LISTENER_PROPERTIES = "dmaap-listener.properties";
- private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR";
- private static final Logger LOG = LoggerFactory
- .getLogger(DmaapListener.class);
-
- public static void main(String[] args) {
-
- Properties properties = new Properties();
-
-
- String propFileName = DMAAP_LISTENER_PROPERTIES;
-
- if (args.length > 0) {
- propFileName = args[0];
- }
-
- String propPath = null;
- String propDir = System.getenv(SDNC_CONFIG_DIR);
-
- List<SdncDmaapConsumer> consumers = new LinkedList();
-
- if (propDir == null) {
-
- propDir = "/opt/sdnc/data/properties";
- }
-
- if (!propFileName.startsWith("/")) {
- propPath = propDir + "/" + propFileName;
- }
-
- File propFile = new File(propPath);
-
- if (!propFile.canRead()) {
- LOG.error("Cannot read properties file "+propPath);
- System.exit(1);
- }
-
- try {
- properties.load(new FileInputStream(propFile));
- } catch (Exception e) {
- LOG.error("Caught exception loading properties from "+propPath, e);
- System.exit(1);
- }
-
- String subscriptionStr = properties.getProperty("subscriptions");
-
- boolean threadsRunning = false;
-
- LOG.debug("Dmaap subscriptions : "+subscriptionStr);
-
- if (subscriptionStr != null) {
- String[] subscriptions = subscriptionStr.split(";");
-
- for (int i = 0; i < subscriptions.length; i++) {
- String[] subscription = subscriptions[i].split(":");
- String consumerClassName = subscription[0];
- String propertyPath = subscription[1];
-
- LOG.debug("Handling subscription [" + consumerClassName + "," + propertyPath + "]");
-
- if (propertyPath == null) {
- LOG.error("Invalid subscription (" + subscriptions[i] + ") property file missing");
- continue;
- }
-
- if (!propertyPath.startsWith("/")) {
- propertyPath = propDir + "/" + propertyPath;
- }
-
- Class<?> consumerClass = null;
-
- try {
- consumerClass = Class.forName(consumerClassName);
- } catch (Exception e) {
- LOG.error("Could not find DMaap consumer class " + consumerClassName);
- }
-
- if (consumerClass != null) {
-
- SdncDmaapConsumer consumer = null;
-
- try {
- consumer = (SdncDmaapConsumer) consumerClass.newInstance();
- } catch (Exception e) {
- LOG.error("Could not create consumer from class " + consumerClassName, e);
- }
-
- if (consumer != null) {
- LOG.debug("Initializing consumer " + consumerClassName + "(" + propertyPath + ")");
- consumer.init(properties, propertyPath);
-
- if (consumer.isReady()) {
- Thread consumerThread = new Thread(consumer);
- consumerThread.start();
- consumers.add(consumer);
- threadsRunning = true;
- LOG.info("Started consumer thread (" + consumerClassName + " : " + propertyPath + ")");
- } else {
- LOG.debug("Consumer " + consumerClassName + " is not ready");
- }
- }
-
- }
-
- }
- }
-
- while (threadsRunning) {
-
- threadsRunning = false;
- for (SdncDmaapConsumer consumer : consumers) {
- if (consumer.isRunning()) {
- threadsRunning = true;
- }
- }
-
- if (!threadsRunning) {
- break;
- }
-
- try {
- Thread.sleep(10000);
- } catch (InterruptedException e) {
-
- }
- }
-
- LOG.info("No listener threads running - exitting");
-
- }
+
+ private static final String DMAAP_LISTENER_PROPERTIES = "dmaap-listener.properties";
+ private static final String DMAAP_LISTENER_PROPERTIES_DIR = "/opt/sdnc/data/properties";
+ private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR";
+ private static final Logger LOG = LoggerFactory.getLogger(DmaapListener.class);
+
+ public static void main(String[] args) {
+
+ Properties properties = new Properties();
+ String propFileName = DMAAP_LISTENER_PROPERTIES;
+ String propPath = null;
+ String propDir = System.getenv(SDNC_CONFIG_DIR);
+ List<SdncDmaapConsumer> consumers = new LinkedList<>();
+
+ if (args.length > 0) {
+ propFileName = args[0];
+ }
+
+ if (propDir == null) {
+ propDir = DMAAP_LISTENER_PROPERTIES_DIR;
+ }
+
+ if (!propFileName.startsWith("/")) {
+ propPath = propDir + "/" + propFileName;
+ }
+
+ if (propPath != null) {
+ properties = loadProperties(propPath, properties);
+
+ String subscriptionStr = properties.getProperty("subscriptions");
+
+ boolean threadsRunning = false;
+
+ LOG.debug("Dmaap subscriptions : " + subscriptionStr);
+
+ if (subscriptionStr != null) {
+ threadsRunning = handleSubscriptions(subscriptionStr, propDir, properties, consumers);
+ }
+
+ while (threadsRunning) {
+ threadsRunning = updateThreadState(consumers);
+ if (!threadsRunning) {
+ break;
+ }
+
+ try {
+ Thread.sleep(10000);
+ } catch (InterruptedException e) {
+ LOG.error(e.getLocalizedMessage(), e);
+ }
+ }
+
+ LOG.info("No listener threads running - exiting");
+ }
+ }
+
+ private static boolean updateThreadState(List<SdncDmaapConsumer> consumers) {
+ boolean threadsRunning = false;
+ for (SdncDmaapConsumer consumer : consumers) {
+ if (consumer.isRunning()) {
+ threadsRunning = true;
+ }
+ }
+ return threadsRunning;
+ }
+
+ private static Properties loadProperties(String propPath, Properties properties) {
+ File propFile = new File(propPath);
+
+ if (!propFile.canRead()) {
+ LOG.error("Cannot read properties file " + propPath);
+ System.exit(1);
+ }
+
+ try (FileInputStream in = new FileInputStream(propFile)) {
+ properties.load(in);
+ } catch (Exception e) {
+ LOG.error("Caught exception loading properties from " + propPath, e);
+ System.exit(1);
+ }
+ return properties;
+ }
+
+ private static boolean handleSubscriptions(String subscriptionStr, String propDir, Properties properties,
+ List<SdncDmaapConsumer> consumers) {
+ String[] subscriptions = subscriptionStr.split(";");
+
+ for (String subscription1 : subscriptions) {
+ String[] subscription = subscription1.split(":");
+ String consumerClassName = subscription[0];
+ String propertyPath = subscription[1];
+
+ LOG.debug(String.format("Handling subscription [%s,%s]", consumerClassName, propertyPath));
+
+ if (propertyPath == null) {
+ LOG.error(String.format("Invalid subscription (%s) property file missing", subscription1));
+ continue;
+ }
+
+ if (!propertyPath.startsWith("/")) {
+ propertyPath = propDir + "/" + propertyPath;
+ }
+
+ Class<?> consumerClass = null;
+
+ try {
+ consumerClass = Class.forName(consumerClassName);
+ } catch (Exception e) {
+ LOG.error("Could not find DMaap consumer class {}", consumerClassName, e);
+ }
+
+ if (consumerClass != null) {
+ return handleConsumerClass(consumerClass, consumerClassName, propertyPath,
+ properties, consumers);
+ }
+ }
+ return false;
+ }
+
+ private static boolean handleConsumerClass(Class<?> consumerClass, String consumerClassName, String propertyPath,
+ Properties properties, List<SdncDmaapConsumer> consumers) {
+
+ SdncDmaapConsumer consumer = null;
+
+ try {
+ consumer = (SdncDmaapConsumer) consumerClass.newInstance();
+ } catch (Exception e) {
+ LOG.error("Could not create consumer from class " + consumerClassName, e);
+ }
+
+ if (consumer != null) {
+ LOG.debug(String.format("Initializing consumer %s(%s)", consumerClassName, propertyPath));
+ consumer.init(properties, propertyPath);
+
+ if (consumer.isReady()) {
+ Thread consumerThread = new Thread(consumer);
+ consumerThread.start();
+ consumers.add(consumer);
+
+ LOG.info(String.format("Started consumer thread (%s : %s)", consumerClassName,
+ propertyPath));
+ return true;
+ } else {
+ LOG.debug(String.format("Consumer %s is not ready", consumerClassName));
+ }
+ }
+ return false;
+ }
}
diff --git a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncDmaapConsumer.java b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncDmaapConsumer.java
index c1320d6b4..a0c555303 100644
--- a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncDmaapConsumer.java
+++ b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncDmaapConsumer.java
@@ -21,126 +21,132 @@
package org.onap.ccsdk.sli.northbound.dmaapclient;
+import com.att.nsa.mr.client.MRClientFactory;
+import com.att.nsa.mr.client.MRConsumer;
+import com.att.nsa.mr.client.response.MRConsumerResponse;
import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.att.nsa.mr.client.MRClientFactory;
-import com.att.nsa.mr.client.MRConsumer;
-import com.att.nsa.mr.client.response.MRConsumerResponse;
-
public abstract class SdncDmaapConsumer implements Runnable {
- private static final Logger LOG = LoggerFactory
- .getLogger(SdncDmaapConsumer.class);
-
- private String propertiesPath = "";
- private Properties properties = null;
- MRConsumer consumer = null;
- MRConsumerResponse consumerResponse = null;
- boolean running = false;
- boolean ready = false;
- int fetchPause = 5000; // Default pause between fetchs - 5 seconds
-
- public boolean isReady() {
- return ready;
- }
-
- int timeout = 15000; // Default timeout - 15 seconds
-
- public boolean isRunning() {
- return running;
- }
-
- public SdncDmaapConsumer() {
-
- }
-
- public SdncDmaapConsumer(Properties properties, String propertiesPath) {
- init(properties, propertiesPath);
- }
-
- public String getProperty(String name) {
- return(properties.getProperty(name, ""));
- }
-
- public void init(Properties properties, String propertiesPath) {
-
- this.propertiesPath = propertiesPath;
-
- try {
-
- this.properties = (Properties) properties.clone();
-
- this.properties.load(new FileInputStream(new File(propertiesPath)));
-
- String timeoutStr = properties.getProperty("timeout");
-
- if ((timeoutStr != null) && (timeoutStr.length() > 0)) {
- try {
- timeout = Integer.parseInt(timeoutStr);
- } catch (NumberFormatException e) {
- LOG.error("Non-numeric value specified for timeout ("+timeoutStr+")");
- }
- }
-
- String fetchPauseStr = properties.getProperty("fetchPause");
- if ((fetchPauseStr != null) && (fetchPauseStr.length() > 0)) {
- try {
- fetchPause = Integer.parseInt(fetchPauseStr);
- } catch (NumberFormatException e) {
- LOG.error("Non-numeric valud specified for fetchPause ("+fetchPauseStr+")");
- }
- }
-
- this.consumer = MRClientFactory.createConsumer(propertiesPath);
- ready = true;
- } catch (Exception e) {
- LOG.error("Error initializing DMaaP consumer from file "+propertiesPath, e);
- }
- }
-
-
- @Override
- public void run() {
- if (ready) {
-
- running = true;
-
- while (running) {
-
- try {
- boolean noData = true;
- consumerResponse = consumer.fetchWithReturnConsumerResponse(timeout, -1);
- for (String msg : consumerResponse.getActualMessages()) {
- noData = false;
- LOG.info("Received message from DMaaP:\n"+msg);
- processMsg(msg);
- }
-
- if (noData) {
- if (fetchPause > 0) {
-
- LOG.info("No data received from fetch. Pausing "+fetchPause+" ms before retry");
- Thread.sleep(fetchPause);
- } else {
-
- LOG.info("No data received from fetch. No fetch pause specified - retrying immediately");
- }
- }
- } catch (Exception e) {
- LOG.error("Caught exception reading from DMaaP", e);
- running = false;
- }
-
-
- }
- }
-
- }
-
- abstract public void processMsg(String msg) throws InvalidMessageException;
+ private static final Logger LOG = LoggerFactory
+ .getLogger(SdncDmaapConsumer.class);
+
+ private String propertiesPath = "";
+ private Properties properties = null;
+ private MRConsumer consumer = null;
+ private MRConsumerResponse consumerResponse = null;
+ private boolean running = false;
+ private boolean ready = false;
+ private int fetchPause = 5000; // Default pause between fetch - 5 seconds
+ private int timeout = 15000; // Default timeout - 15 seconds
+
+ public boolean isReady() {
+ return ready;
+ }
+
+
+ public boolean isRunning() {
+ return running;
+ }
+
+ public SdncDmaapConsumer() {
+
+ }
+
+ public SdncDmaapConsumer(Properties properties, String propertiesPath) {
+ init(properties, propertiesPath);
+ }
+
+ public String getProperty(String name) {
+ return (properties.getProperty(name, ""));
+ }
+
+ public void init(Properties properties, String propertiesPath) {
+
+ this.propertiesPath = propertiesPath;
+
+ try (FileInputStream in = new FileInputStream(new File(propertiesPath))) {
+
+ this.properties = (Properties) properties.clone();
+ this.properties.load(in);
+
+ String timeoutStr = properties.getProperty("timeout");
+
+ if ((timeoutStr != null) && (timeoutStr.length() > 0)) {
+ timeout = parseTimeOutValue(timeoutStr);
+ }
+
+ String fetchPauseStr = properties.getProperty("fetchPause");
+ if ((fetchPauseStr != null) && (fetchPauseStr.length() > 0)) {
+ fetchPause = parseFetchPause(fetchPauseStr);
+ }
+
+ this.consumer = MRClientFactory.createConsumer(propertiesPath);
+ ready = true;
+ } catch (Exception e) {
+ LOG.error("Error initializing DMaaP consumer from file " + propertiesPath, e);
+ }
+ }
+
+ private int parseTimeOutValue(String timeoutStr) {
+ try {
+ return Integer.parseInt(timeoutStr);
+ } catch (NumberFormatException e) {
+ LOG.error("Non-numeric value specified for timeout (" + timeoutStr + ")");
+ }
+ return timeout;
+ }
+
+ private int parseFetchPause(String fetchPauseStr) {
+ try {
+ return Integer.parseInt(fetchPauseStr);
+ } catch (NumberFormatException e) {
+ LOG.error("Non-numeric value specified for fetchPause (" + fetchPauseStr + ")");
+ }
+ return fetchPause;
+ }
+
+
+ @Override
+ public void run() {
+ if (ready) {
+
+ running = true;
+
+ while (running) {
+
+ try {
+ boolean noData = true;
+ consumerResponse = consumer.fetchWithReturnConsumerResponse(timeout, -1);
+ for (String msg : consumerResponse.getActualMessages()) {
+ noData = false;
+ LOG.info("Received message from DMaaP:\n" + msg);
+ processMsg(msg);
+ }
+
+ if (noData) {
+ pauseThread();
+ }
+ } catch (Exception e) {
+ LOG.error("Caught exception reading from DMaaP", e);
+ running = false;
+ }
+ }
+ }
+ }
+
+ private void pauseThread() throws InterruptedException {
+ if (fetchPause > 0) {
+ LOG.info(String.format("No data received from fetch. Pausing %d ms before retry", fetchPause));
+ Thread.sleep(fetchPause);
+ } else {
+ LOG.info("No data received from fetch. No fetch pause specified - retrying immediately");
+ }
+ }
+
+ abstract public void processMsg(String msg) throws InvalidMessageException;
}
diff --git a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncFlatJsonDmaapConsumer.java b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncFlatJsonDmaapConsumer.java
index 1754957da..1d499a1e7 100644
--- a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncFlatJsonDmaapConsumer.java
+++ b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncFlatJsonDmaapConsumer.java
@@ -21,175 +21,148 @@
package org.onap.ccsdk.sli.northbound.dmaapclient;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.BufferedReader;
-import java.io.DataOutputStream;
import java.io.File;
import java.io.FileReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.net.Authenticator;
-import java.net.HttpURLConnection;
-import java.net.PasswordAuthentication;
-import java.net.URL;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
-
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.SSLSession;
-
-import org.apache.commons.codec.binary.Base64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-
public class SdncFlatJsonDmaapConsumer extends SdncDmaapConsumer {
- private static final Logger LOG = LoggerFactory
- .getLogger(SdncFlatJsonDmaapConsumer.class);
-
- private static final String DMAAPLISTENERROOT = "DMAAPLISTENERROOT";
- private static final String SDNC_ENDPOINT = "SDNC.endpoint";
-
-
-
- @Override
- public void processMsg(String msg) throws InvalidMessageException {
-
- processMsg(msg, null);
- }
-
- public void processMsg(String msg, String mapDirName) throws InvalidMessageException {
-
- if (msg == null) {
- throw new InvalidMessageException("Null message");
- }
-
- ObjectMapper oMapper = new ObjectMapper();
- JsonNode instarRootNode = null;
- ObjectNode sdncRootNode = null;
-
- String instarMsgName = null;
-
- try {
- instarRootNode = oMapper.readTree(msg);
- } catch (Exception e) {
- throw new InvalidMessageException("Cannot parse json object", e);
- }
-
- Iterator<Map.Entry<String, JsonNode>> instarFields = instarRootNode.fields();
+ private static final Logger LOG = LoggerFactory.getLogger(SdncFlatJsonDmaapConsumer.class);
- while (instarFields.hasNext()) {
- Map.Entry<String, JsonNode> entry = instarFields.next();
+ private static final String DMAAPLISTENERROOT = "DMAAPLISTENERROOT";
+ private static final String SDNC_ENDPOINT = "SDNC.endpoint";
- instarMsgName = entry.getKey();
- instarRootNode = entry.getValue();
- break;
- }
+ @Override
+ public void processMsg(String msg) throws InvalidMessageException {
- Map<String,String> fieldMap = loadMap(instarMsgName, mapDirName);
+ processMsg(msg, null);
+ }
- if (fieldMap == null) {
- throw new InvalidMessageException("Unable to process message - cannot load field mappings");
- }
+ public void processMsg(String msg, String mapDirName) throws InvalidMessageException {
- if (!fieldMap.containsKey(SDNC_ENDPOINT)) {
- throw new InvalidMessageException("No SDNC endpoint known for message "+instarMsgName);
- }
+ if (msg == null) {
+ throw new InvalidMessageException("Null message");
+ }
- String sdncEndpoint = fieldMap.get(SDNC_ENDPOINT);
+ ObjectMapper oMapper = new ObjectMapper();
+ JsonNode instarRootNode;
+ ObjectNode sdncRootNode;
- sdncRootNode = oMapper.createObjectNode();
- ObjectNode inputNode = oMapper.createObjectNode();
+ String instarMsgName = null;
+ try {
+ instarRootNode = oMapper.readTree(msg);
+ } catch (Exception e) {
+ throw new InvalidMessageException("Cannot parse json object", e);
+ }
- for (String fromField : fieldMap.keySet()) {
+ Iterator<Map.Entry<String, JsonNode>> instarFields = instarRootNode.fields();
- if (!SDNC_ENDPOINT.equals(fromField)) {
- JsonNode curNode = instarRootNode.get(fromField);
- if (curNode != null) {
- String fromValue = curNode.textValue();
+ while (instarFields.hasNext()) {
+ Map.Entry<String, JsonNode> entry = instarFields.next();
- inputNode.put(fieldMap.get(fromField), fromValue);
- }
- }
- }
- sdncRootNode.put("input", inputNode);
+ instarMsgName = entry.getKey();
+ instarRootNode = entry.getValue();
+ break;
+ }
- try {
- String rpcMsgbody = oMapper.writeValueAsString(sdncRootNode);
- String odlUrlBase = getProperty("sdnc.odl.url-base");
- String odlUser = getProperty("sdnc.odl.user");
- String odlPassword = getProperty("sdnc.odl.password");
+ Map<String, String> fieldMap = loadMap(instarMsgName, mapDirName);
- if ((odlUrlBase != null) && (odlUrlBase.length() > 0)) {
- SdncOdlConnection conn = SdncOdlConnection.newInstance(odlUrlBase + sdncEndpoint, odlUser, odlPassword);
+ if (fieldMap == null) {
+ throw new InvalidMessageException("Unable to process message - cannot load field mappings");
+ }
- conn.send("POST", "application/json", rpcMsgbody);
- } else {
- LOG.info("POST message body would be:\n"+rpcMsgbody);
- }
- } catch (Exception e) {
+ if (!fieldMap.containsKey(SDNC_ENDPOINT)) {
+ throw new InvalidMessageException("No SDNC endpoint known for message " + instarMsgName);
+ }
- }
+ String sdncEndpoint = fieldMap.get(SDNC_ENDPOINT);
- }
+ sdncRootNode = oMapper.createObjectNode();
+ ObjectNode inputNode = oMapper.createObjectNode();
- private Map<String,String> loadMap(String msgType, String mapDirName) {
- Map<String, String> results = new HashMap<String, String>();
+ for (Map.Entry<String, String> entry : fieldMap.entrySet()) {
+ if (!SDNC_ENDPOINT.equals(entry.getKey())) {
+ JsonNode curNode = instarRootNode.get(entry.getKey());
+ if (curNode != null) {
+ String fromValue = curNode.textValue();
- if (mapDirName == null) {
- String rootdir = System.getenv(DMAAPLISTENERROOT);
+ inputNode.put(entry.getValue(), fromValue);
+ }
+ }
+ }
+ sdncRootNode.put("input", inputNode);
- if ((rootdir == null) || (rootdir.length() == 0)) {
- rootdir = "/opt/app/dmaap-listener";
- }
+ try {
+ String rpcMsgbody = oMapper.writeValueAsString(sdncRootNode);
+ String odlUrlBase = getProperty("sdnc.odl.url-base");
+ String odlUser = getProperty("sdnc.odl.user");
+ String odlPassword = getProperty("sdnc.odl.password");
- mapDirName = rootdir + "/lib";
+ if ((odlUrlBase != null) && (odlUrlBase.length() > 0)) {
+ SdncOdlConnection conn = SdncOdlConnection.newInstance(odlUrlBase + sdncEndpoint, odlUser, odlPassword);
- }
+ conn.send("POST", "application/json", rpcMsgbody);
+ } else {
+ LOG.info("POST message body would be:\n" + rpcMsgbody);
+ }
+ } catch (Exception e) {
+ LOG.error("Unable to process message", e);
+ }
+ }
- String mapFilename = mapDirName + "/" + msgType + ".map";
+ private Map<String, String> loadMap(String msgType, String mapDirName) {
+ Map<String, String> results = new HashMap<>();
- File mapFile = new File(mapFilename);
+ if (mapDirName == null) {
+ String rootdir = System.getenv(DMAAPLISTENERROOT);
- if (!mapFile.canRead()) {
- LOG.error("Cannot read map file ("+mapFilename+")");
- return(null);
- }
+ if ((rootdir == null) || (rootdir.length() == 0)) {
+ rootdir = "/opt/app/dmaap-listener";
+ }
- try (BufferedReader mapReader = new BufferedReader(new FileReader(mapFile))) {
+ mapDirName = rootdir + "/lib";
+ }
- String curLine;
+ String mapFilename = mapDirName + "/" + msgType + ".map";
- while ((curLine = mapReader.readLine()) != null) {
- curLine = curLine.trim();
+ File mapFile = new File(mapFilename);
- if ((curLine.length() > 0) && (!curLine.startsWith("#"))) {
+ if (!mapFile.canRead()) {
+ LOG.error(String.format("Cannot read map file (%s)", mapFilename));
+ return (null);
+ }
- if (curLine.contains("=>")) {
- String[] entry = curLine.split("=>");
- if (entry.length == 2) {
- results.put(entry[0].trim(), entry[1].trim());
- }
- }
- }
- }
- mapReader.close();
- } catch (Exception e) {
- LOG.error("Caught exception reading map "+mapFilename, e);
- return(null);
- }
+ try (BufferedReader mapReader = new BufferedReader(new FileReader(mapFile))) {
- return(results);
- }
+ String curLine;
+ while ((curLine = mapReader.readLine()) != null) {
+ curLine = curLine.trim();
+ if ((curLine.length() > 0) && (!curLine.startsWith("#")) && curLine.contains("=>")) {
+ String[] entry = curLine.split("=>");
+ if (entry.length == 2) {
+ results.put(entry[0].trim(), entry[1].trim());
+ }
+ }
+ }
+ mapReader.close();
+ } catch (Exception e) {
+ LOG.error("Caught exception reading map " + mapFilename, e);
+ return (null);
+ }
+ return (results);
+ }
}
diff --git a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncOdlConnection.java b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncOdlConnection.java
index e31219a23..f88f7bf8c 100644
--- a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncOdlConnection.java
+++ b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncOdlConnection.java
@@ -28,132 +28,124 @@ import java.io.InputStreamReader;
import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.PasswordAuthentication;
-import java.net.ProtocolException;
import java.net.URL;
-
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSession;
-
import org.apache.commons.codec.binary.Base64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SdncOdlConnection {
-
- private static final Logger LOG = LoggerFactory
- .getLogger(SdncOdlConnection.class);
-
- private HttpURLConnection httpConn = null;
-
- private String url = null;
- private String user = null;
- private String password = null;
-
- private class SdncAuthenticator extends Authenticator {
-
- private String user;
- private String passwd;
-
- SdncAuthenticator(String user, String passwd) {
- this.user = user;
- this.passwd = passwd;
- }
- @Override
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(user, passwd.toCharArray());
- }
-
- }
-
- private SdncOdlConnection() {
-
- }
-
- private SdncOdlConnection(String url, String user, String password) {
- this.url = url;
- this.user = user;
- this.password = password;
-
- try {
- URL sdncUrl = new URL(url);
- Authenticator.setDefault(new SdncAuthenticator(user, password));
-
- this.httpConn = (HttpURLConnection) sdncUrl.openConnection();
- } catch (Exception e) {
- LOG.error("Unable to create http connection", e);
- }
- }
-
- public static SdncOdlConnection newInstance(String url, String user, String password) throws IOException
- {
- return (new SdncOdlConnection(url, user, password));
- }
-
-
-
- public String send(String method, String contentType, String msg) throws IOException {
-
- LOG.info("Sending REST " + method + " to " + url);
- LOG.info("Message body:\n" + msg);
- String authStr = user + ":" + password;
- String encodedAuthStr = new String(Base64.encodeBase64(authStr.getBytes()));
-
- httpConn.addRequestProperty("Authentication", "Basic " + encodedAuthStr);
-
- httpConn.setRequestMethod(method);
- httpConn.setRequestProperty("Content-Type", contentType);
- httpConn.setRequestProperty("Accept", contentType);
-
- httpConn.setDoInput(true);
- httpConn.setDoOutput(true);
- httpConn.setUseCaches(false);
-
- if (httpConn instanceof HttpsURLConnection) {
- HostnameVerifier hostnameVerifier = new HostnameVerifier() {
- @Override
- public boolean verify(String hostname, SSLSession session) {
- return true;
- }
- };
- ((HttpsURLConnection) httpConn).setHostnameVerifier(hostnameVerifier);
- }
-
- // Write message
- httpConn.setRequestProperty("Content-Length", "" + msg.length());
- DataOutputStream outStr = new DataOutputStream(httpConn.getOutputStream());
- outStr.write(msg.getBytes());
- outStr.close();
-
- // Read response
- BufferedReader respRdr;
-
- LOG.info("Response: " + httpConn.getResponseCode() + " " + httpConn.getResponseMessage());
-
- if (httpConn.getResponseCode() < 300) {
-
- respRdr = new BufferedReader(new InputStreamReader(httpConn.getInputStream()));
- } else {
- respRdr = new BufferedReader(new InputStreamReader(httpConn.getErrorStream()));
- }
-
- StringBuffer respBuff = new StringBuffer();
-
- String respLn;
-
- while ((respLn = respRdr.readLine()) != null) {
- respBuff.append(respLn + "\n");
- }
- respRdr.close();
-
- String respString = respBuff.toString();
-
- LOG.info("Response body :\n" + respString);
-
- return (respString);
-
- }
-
+ private static final Logger LOG = LoggerFactory
+ .getLogger(SdncOdlConnection.class);
+
+ private HttpURLConnection httpConn = null;
+
+ private String url = null;
+ private String user = null;
+ private String password = null;
+
+ private class SdncAuthenticator extends Authenticator {
+
+ private String user;
+ private String passwd;
+
+ SdncAuthenticator(String user, String passwd) {
+ this.user = user;
+ this.passwd = passwd;
+ }
+
+ @Override
+ protected PasswordAuthentication getPasswordAuthentication() {
+ return new PasswordAuthentication(user, passwd.toCharArray());
+ }
+ }
+
+ private SdncOdlConnection() {
+
+ }
+
+ private SdncOdlConnection(String url, String user, String password) {
+ this.url = url;
+ this.user = user;
+ this.password = password;
+
+ try {
+ URL sdncUrl = new URL(url);
+ Authenticator.setDefault(new SdncAuthenticator(user, password));
+
+ this.httpConn = (HttpURLConnection) sdncUrl.openConnection();
+ } catch (Exception e) {
+ LOG.error("Unable to create http connection", e);
+ }
+ }
+
+ public static SdncOdlConnection newInstance(String url, String user, String password) throws IOException {
+ return new SdncOdlConnection(url, user, password);
+ }
+
+
+ public String send(String method, String contentType, String msg) throws IOException {
+
+ LOG.info(String.format("Sending REST %s to %s", method, url));
+ LOG.info(String.format("Message body:%n%s", msg));
+ String authStr = user + ":" + password;
+ String encodedAuthStr = new String(Base64.encodeBase64(authStr.getBytes()));
+
+ httpConn.addRequestProperty("Authentication", "Basic " + encodedAuthStr);
+
+ httpConn.setRequestMethod(method);
+ httpConn.setRequestProperty("Content-Type", contentType);
+ httpConn.setRequestProperty("Accept", contentType);
+
+ httpConn.setDoInput(true);
+ httpConn.setDoOutput(true);
+ httpConn.setUseCaches(false);
+
+ if (httpConn instanceof HttpsURLConnection) {
+ HostnameVerifier hostnameVerifier = new HostnameVerifier() {
+ @Override
+ public boolean verify(String hostname, SSLSession session) {
+ return true;
+ }
+ };
+ ((HttpsURLConnection) httpConn).setHostnameVerifier(hostnameVerifier);
+ }
+
+ // Write message
+ httpConn.setRequestProperty("Content-Length", Integer.toString(msg.length()));
+ DataOutputStream outStr = new DataOutputStream(httpConn.getOutputStream());
+ outStr.write(msg.getBytes());
+ outStr.close();
+
+ // Read response
+ BufferedReader respRdr;
+
+ LOG.info("Response: " + httpConn.getResponseCode() + " " + httpConn.getResponseMessage());
+
+ if (httpConn.getResponseCode() < 300) {
+
+ respRdr = new BufferedReader(new InputStreamReader(httpConn.getInputStream()));
+ } else {
+ respRdr = new BufferedReader(new InputStreamReader(httpConn.getErrorStream()));
+ }
+
+ StringBuilder respBuff = new StringBuilder();
+
+ String respLn;
+
+ while ((respLn = respRdr.readLine()) != null) {
+ respBuff.append(respLn).append("\n");
+ }
+ respRdr.close();
+
+ String respString = respBuff.toString();
+
+ LOG.info(String.format("Response body :%n%s", respString));
+
+ return respString;
+ }
}
diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java
index dd9437ce9..3605465d4 100644
--- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java
+++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java
@@ -24,7 +24,6 @@ package org.onap.ccsdk.sli.northbound.uebclient;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
-import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@@ -57,7 +56,7 @@ public class SdncArtifactMap {
}
public String getRpcUrl(String base) {
- return(base+rpc);
+ return base+rpc;
}
private SdncArtifactType(String tag, String rpc, String pass) {
@@ -66,14 +65,14 @@ public class SdncArtifactMap {
try {
this.pass = Integer.parseInt(pass);
} catch (Exception e) {
- LOG.error("Invalid pass value for artifact map entry ("+tag+","+rpc+","+pass+")");
+ LOG.error("Invalid pass value for artifact map entry ({} {} {})", tag, rpc, pass, e);
}
}
}
- private Map<String, SdncArtifactType> mapItems = new HashMap<String, SdncArtifactType>();
+ private Map<String, SdncArtifactType> mapItems = new HashMap<>();
private int NumPasses = 1;
@@ -110,9 +109,9 @@ public class SdncArtifactMap {
public SdncArtifactType getMapping(String tag) {
if (mapItems.containsKey(tag)) {
- return(mapItems.get(tag));
+ return mapItems.get(tag);
} else {
- return(null);
+ return null;
}
}
diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java
index e7a42bcb8..0664e8283 100644
--- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java
+++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java
@@ -8,9 +8,9 @@
* 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.
@@ -189,10 +189,9 @@ public class SdncUebCallback implements INotificationCallback {
private static void setJdbcDataSource() throws IOException {
- String propPath = null;
+ String propPath;
String propDir = System.getenv(SDNC_CONFIG_DIR);
if (propDir == null) {
-
propDir = "/opt/sdnc/data/properties";
}
propPath = propDir + "/dblib.properties";
@@ -209,8 +208,8 @@ public class SdncUebCallback implements INotificationCallback {
props.load(new FileInputStream(propFile));
jdbcDataSource = new DBResourceManager(props);
-
- if(((DBResourceManager)jdbcDataSource).isActive()){
+
+ if(jdbcDataSource.isActive()){
LOG.warn( "DBLIB: JDBC DataSource has been initialized.");
} else {
LOG.warn( "DBLIB: JDBC DataSource did not initialize successfully.");
@@ -239,15 +238,6 @@ public class SdncUebCallback implements INotificationCallback {
File incomingDir = null;
File archiveDir = null;
- if (!incomingDir.exists()) {
- incomingDir.mkdirs();
- }
-
-
- if (!archiveDir.exists()) {
- archiveDir.mkdirs();
- }
-
// Process service level artifacts
List<IArtifactInfo> artifactList = data.getServiceArtifacts();
@@ -280,12 +270,14 @@ public class SdncUebCallback implements INotificationCallback {
if (artifactList != null) {
- incomingDir = new File(incomingDirName + "/" + escapeFilename(data.getServiceName()) + "/" + escapeFilename(curResource.getResourceName()));
+ incomingDir = new File(incomingDirName + "/" + escapeFilename(data.getServiceName()) + "/"
+ + escapeFilename(curResource.getResourceName()));
if (!incomingDir.exists()) {
incomingDir.mkdirs();
}
- archiveDir = new File(archiveDirName + "/" + escapeFilename(data.getServiceName()) + "/" + escapeFilename(curResource.getResourceName()));
+ archiveDir = new File(archiveDirName + "/" + escapeFilename(data.getServiceName()) + "/"
+ + escapeFilename(curResource.getResourceName()));
if (!archiveDir.exists()) {
archiveDir.mkdirs();
}
@@ -300,8 +292,6 @@ public class SdncUebCallback implements INotificationCallback {
}
deployDownloadedFiles(incomingDir, archiveDir, data);
-
-
}
@@ -333,7 +323,7 @@ public class SdncUebCallback implements INotificationCallback {
} catch (Exception x) {
// IOException can never be thrown by the iteration.
// In this snippet, it can only be thrown by newDirectoryStream.
- LOG.warn("Cannot process spool file "+ curFileName, x);
+ LOG.warn("Cannot process spool file {}", curFileName, x);
}
// Deploy scheduled deployments
@@ -375,11 +365,11 @@ public class SdncUebCallback implements INotificationCallback {
}
}
- private void handleArtifact(INotificationData data, String svcName, String resourceName, String resourceType, IArtifactInfo artifact, File incomingDir, File archiveDir) {
+ private void handleArtifact(INotificationData data, String svcName, String resourceName, String resourceType,
+ IArtifactInfo artifact, File incomingDir, File archiveDir) {
// Download Artifact
- IDistributionClientDownloadResult downloadResult = client
- .download(artifact);
+ IDistributionClientDownloadResult downloadResult = client.download(artifact);
if (downloadResult == null) {
@@ -412,8 +402,6 @@ public class SdncUebCallback implements INotificationCallback {
if (writeSucceeded && (downloadResult.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS)) {
handleSuccessfulDownload(data, svcName, resourceName, artifact, spoolFile, archiveDir);
-
-
} else {
handleFailedDownload(data, artifact);
}
@@ -495,15 +483,13 @@ public class SdncUebCallback implements INotificationCallback {
try {
- DocumentBuilderFactory dbf = DocumentBuilderFactory
- .newInstance();
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
spoolDoc = db.parse(transformedFile);
} catch (Exception e) {
- LOG.error(
- "Caught exception trying to parse transformed XML file "
- + transformedFile.getAbsolutePath(), e);
+ LOG.error("Caught exception trying to parse transformed XML file {}",
+ transformedFile.getAbsolutePath(), e);
}
} catch (Exception e) {
@@ -514,8 +500,7 @@ public class SdncUebCallback implements INotificationCallback {
if (spoolDoc != null) {
// Analyze file type
- SdncArtifactType artifactType = analyzeFileType(artifactEnum,
- spoolFile, spoolDoc);
+ SdncArtifactType artifactType = analyzeFileType(artifactEnum, spoolFile, spoolDoc);
if (artifactType != null) {
@@ -541,14 +526,14 @@ public class SdncUebCallback implements INotificationCallback {
private void processToscaYaml(INotificationData data, String svcName, String resourceName,
IArtifactInfo artifact, File spoolFile, File archiveDir) {
-
+
// Use ASDC Dist Client 1.1.5 with TOSCA parsing APIs to extract relevant TOSCA model data
-
+
// TOSCA data extraction flow 1707:
// Use ASDC dist-client to get yaml string - not yet available
String model_yaml = null;
LOG.info("Process TOSCA YAML file: "+spoolFile.toString());
-
+
SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance();
ISdcCsarHelper sdcCsarHelper = null;
try {
@@ -573,7 +558,7 @@ public class SdncUebCallback implements INotificationCallback {
LOG.error("Could not insert Tosca YAML data into the SERVICE_MODEL table ", e);
factory.close();
return;
- }
+ }
// Ingest Network (VL) Data - 1707
//List<NodeTemplate> vlNodeTemplatesList = sdcCsarHelper.getServiceNodeTemplatesByType("VL");
@@ -583,7 +568,7 @@ public class SdncUebCallback implements INotificationCallback {
SdncNodeModel nodeModel = new SdncNodeModel (sdcCsarHelper, nodeTemplate);
nodeModel.setServiceUUID(serviceModel.getServiceUUID());
nodeModel.setEcompGeneratedNaming(SdncBaseModel.extractBooleanInputDefaultValue(sdcCsarHelper, SdcPropertyNames.PROPERTY_NAME_SERVICENAMING_DEFAULT_ECOMPGENERATEDNAMING));//service_naming#default#ecomp_generated_naming
-
+
try {
cleanUpExistingToscaData("NETWORK_MODEL", "customization_uuid", nodeModel.getCustomizationUUID());
cleanUpExistingToscaData("VPN_BINDINGS", "network_customization_uuid", nodeModel.getCustomizationUUID());
@@ -595,13 +580,13 @@ public class SdncUebCallback implements INotificationCallback {
LOG.error("Could not insert Tosca YAML data into the NETWORK_MODEL table ", e);
}
}
-
+
// Ingest Allotted Resource Data - 1707
List<NodeTemplate> arNodeTemplatesList = sdcCsarHelper.getAllottedResources();
for (NodeTemplate nodeTemplate : arNodeTemplatesList) {
SdncARModel nodeModel = new SdncARModel (sdcCsarHelper, nodeTemplate);
-
+
try {
cleanUpExistingToscaData("ALLOTTED_RESOURCE_MODEL", "customization_uuid", nodeModel.getCustomizationUUID());
LOG.info("Call insertToscaData for ALLOTTED_RESOURCE_MODEL customizationUUID = " + nodeModel.getCustomizationUUID());
@@ -611,14 +596,14 @@ public class SdncUebCallback implements INotificationCallback {
LOG.error("Could not insert Tosca YAML data into the NETWORK_MODEL table ", e);
}
}
-
+
// Ingest Network (VF) Data - 1707
//List<NodeTemplate> nodeTemplatesList = sdcCsarHelper.getServiceNodeTemplatesByType("VF");
List<NodeTemplate> vfNodeTemplatesList = sdcCsarHelper.getServiceVfList();
for (NodeTemplate nodeTemplate : vfNodeTemplatesList) {
SdncVFModel vfNodeModel = new SdncVFModel (sdcCsarHelper, nodeTemplate);
-
+
try {
cleanUpExistingToscaData("VF_MODEL", "customization_uuid", vfNodeModel.getCustomizationUUID()) ;
LOG.info("Call insertToscaData for VF_MODEL customizationUUID = " + vfNodeModel.getCustomizationUUID());
@@ -626,12 +611,12 @@ public class SdncUebCallback implements INotificationCallback {
} catch (IOException e) {
LOG.error("Could not insert Tosca YAML data into the VF_MODEL table ", e);
}
-
+
// For each VF, insert VF_MODULE_MODEL data
List<Group> vfModules = sdcCsarHelper.getVfModulesByVf(vfNodeModel.getCustomizationUUIDNoQuotes());
for (Group group : vfModules){
SdncVFModuleModel vfModuleModel = new SdncVFModuleModel(sdcCsarHelper, group);
-
+
try {
cleanUpExistingToscaData("VF_MODULE_MODEL", "customization_uuid", vfModuleModel.getCustomizationUUID());
LOG.info("Call insertToscaData for VF_MODULE_MODEL customizationUUID = " + vfModuleModel.getCustomizationUUID());
@@ -639,19 +624,19 @@ public class SdncUebCallback implements INotificationCallback {
} catch (IOException e) {
LOG.error("Could not insert Tosca YAML data into the VF_MODULE_MODEL table ", e);
}
-
+
// For each VF Module, get the VFC list, insert VF_MODULE_TO_VFC_MAPPING data
// List<NodeTemplate> groupMembers = sdcCsarHelper.getMembersOfGroup(group); - old version
- // For each vfcNode (group member) in the groupMembers list, extract vm_type and vm_count.
+ // For each vfcNode (group member) in the groupMembers list, extract vm_type and vm_count.
// Insert vf_module.customizationUUID, vfcNode.customizationUUID and vm_type and vm_count into VF_MODULE_TO_VFC_MAPPING
List<NodeTemplate> groupMembers = sdcCsarHelper.getMembersOfVfModule(nodeTemplate, group); // not yet available
for (NodeTemplate vfcNode : groupMembers){
SdncVFCModel vfcModel = new SdncVFCModel(sdcCsarHelper, vfcNode);
-
+
try {
cleanUpExistingToscaData("VF_MODULE_TO_VFC_MAPPING", "vf_module_customization_uuid", vfModuleModel.getCustomizationUUID());
LOG.info("Call insertToscaData for VF_MODULE_TO_VFC_MAPPING customizationUUID = " + vfModuleModel.getCustomizationUUID());
- insertToscaData("insert into VF_MODULE_TO_VFC_MAPPING (vf_module_customization_uuid, vfc_customization_uuid, vm_type, vm_count) values (" +
+ insertToscaData("insert into VF_MODULE_TO_VFC_MAPPING (vf_module_customization_uuid, vfc_customization_uuid, vm_type, vm_count) values (" +
vfModuleModel.getCustomizationUUID() + ", " + vfcModel.getCustomizationUUID() + ", \"" + vfcModel.getVmType() + "\", \"" + vfcModel.getVmCount() + "\")");
} catch (IOException e) {
LOG.error("Could not insert Tosca YAML data into the VF_MODULE_TO_VFC_MAPPING table ", e);
@@ -660,12 +645,12 @@ public class SdncUebCallback implements INotificationCallback {
}
}
-
+
// For each VF, insert VFC_MODEL data
List<NodeTemplate> vfcNodes = sdcCsarHelper.getVfcListByVf(vfNodeModel.getCustomizationUUIDNoQuotes());
for (NodeTemplate vfcNode : vfcNodes){
SdncVFCModel vfcModel = new SdncVFCModel(sdcCsarHelper, vfcNode);
-
+
try {
cleanUpExistingToscaData("VFC_MODEL", "customization_uuid", vfcModel.getCustomizationUUID());
LOG.info("Call insertToscaData for VFC_MODEL customizationUUID = " + vfcModel.getCustomizationUUID());
@@ -675,35 +660,35 @@ public class SdncUebCallback implements INotificationCallback {
}
}
-
+
// For each VF, insert VF_TO_NETWORK_ROLE_MAPPING data
List<NodeTemplate> cpNodes = sdcCsarHelper.getCpListByVf(vfNodeModel.getCustomizationUUIDNoQuotes());
for (NodeTemplate cpNode : cpNodes){
-
+
// Insert into VF_TO_NETWORK_ROLE_MAPPING vf_customization_uuid and network_role
String cpNetworkRole = sdcCsarHelper.getNodeTemplatePropertyLeafValue(cpNode, "network_role_tag");
-
+
try {
cleanUpExistingToscaData("VF_TO_NETWORK_ROLE_MAPPING", "vf_customization_uuid", vfNodeModel.getCustomizationUUID());
LOG.info("Call insertToscaData for VF_TO_NETWORK_ROLE_MAPPING vfCustomizationUUID = " + vfNodeModel.getCustomizationUUID());
- insertToscaData("insert into VF_TO_NETWORK_ROLE_MAPPING (vf_customization_uuid, network_role) values (" +
+ insertToscaData("insert into VF_TO_NETWORK_ROLE_MAPPING (vf_customization_uuid, network_role) values (" +
vfNodeModel.getCustomizationUUID() + ", \"" + cpNetworkRole + "\")");
} catch (IOException e) {
LOG.error("Could not insert Tosca YAML data into the VF_TO_NETWORK_ROLE_MAPPING table ", e);
}
-
+
// Insert VFC_TO_NETWORK_ROLE_MAPPING data
Map<String, String> mappingParams = new HashMap<String, String>();
//String cpNetworkRoleTag = "\"" + sdcCsarHelper.getNodeTemplatePropertyLeafValue(cpNode, SdcPropertyNames.PROPERTY_NAME_NETWORKROLETAG) + "\"";
// extract network_role, network_role_tag and virtual_binding from this cpNode
SdncBaseModel.addParameter("network_role", SdncBaseModel.extractValue(sdcCsarHelper, cpNode, "network_role"), mappingParams);
SdncBaseModel.addParameter("network_role_tag", SdncBaseModel.extractValue(sdcCsarHelper, cpNode, "network_role_tag"), mappingParams);
- String virtualBinding = "\"" + SdncBaseModel.extractValue(sdcCsarHelper, cpNode, "requirements#virtualBinding") + "\"";
+ String virtualBinding = "\"" + SdncBaseModel.extractValue(sdcCsarHelper, cpNode, "requirements#virtualBinding") + "\"";
// get list of cpNodes and vfcNodes with matching virtualBinding
- List<Pair<NodeTemplate, NodeTemplate>> matchList = sdcCsarHelper.getNodeTemplatePairsByReqName(sdcCsarHelper.getCpListByVf(vfNodeModel.getCustomizationUUIDNoQuotes()), sdcCsarHelper.getVfcListByVf(vfNodeModel.getCustomizationUUIDNoQuotes()), virtualBinding);
+ List<Pair<NodeTemplate, NodeTemplate>> matchList = sdcCsarHelper.getNodeTemplatePairsByReqName(sdcCsarHelper.getCpListByVf(vfNodeModel.getCustomizationUUIDNoQuotes()), sdcCsarHelper.getVfcListByVf(vfNodeModel.getCustomizationUUIDNoQuotes()), virtualBinding);
for (Pair<NodeTemplate, NodeTemplate> match : matchList) { // should be 1 match?
-
+
// extract values from the left "CP" Node
SdncBaseModel.addParameter("ipv4_use_dhcp", SdncBaseModel.extractBooleanValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_DHCPENABLED), mappingParams);
//SdncBaseModel.addParameter("ipv4_ip_version", SdncBaseModel.extractValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_IPVERSION), mappingParams);
@@ -711,14 +696,14 @@ public class SdncUebCallback implements INotificationCallback {
SdncBaseModel.addParameter("ipv6_use_dhcp", SdncBaseModel.extractBooleanValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_DHCPENABLED), mappingParams);
//SdncBaseModel.addParameter("ipv6_ip_version", SdncBaseModel.extractValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_IPVERSION), mappingParams);
SdncBaseModel.addParameter("ipv6_ip_version", "dummy_ipv6_vers", mappingParams);
- //String extcp_subnetpool_id = "\"" + SdncBaseModel.extractValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_SUBNETPOOLID) + "\""; // need path to subnetpoolid
-
+ //String extcp_subnetpool_id = "\"" + SdncBaseModel.extractValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_SUBNETPOOLID) + "\""; // need path to subnetpoolid
+
// extract values from the right "VFC" Node
String vfcCustomizationUuid = "\"" + SdncBaseModel.extractValue(sdcCsarHelper, match.getRight().getMetadata(), "customization_uuid") + "\"";
SdncBaseModel.addParameter("vm_type", SdncBaseModel.extractValue(sdcCsarHelper, match.getRight(), SdcPropertyNames.PROPERTY_NAME_VMTYPE), mappingParams);
SdncBaseModel.addIntParameter("ipv4_count", SdncBaseModel.extractValue(sdcCsarHelper, match.getRight(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_MINSUBNETSCOUNT), mappingParams);
SdncBaseModel.addIntParameter("ipv6_count", SdncBaseModel.extractValue(sdcCsarHelper, match.getRight(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_MINSUBNETSCOUNT), mappingParams);
-
+
try {
cleanUpExistingToscaData("VFC_TO_NETWORK_ROLE_MAPPING", "vfc_customization_uuid", vfcCustomizationUuid);
LOG.info("Call insertToscaData for VFC_TO_NETWORK_ROLE_MAPPING vfcCustomizationUUID = " + vfcCustomizationUuid);
@@ -726,16 +711,16 @@ public class SdncUebCallback implements INotificationCallback {
} catch (IOException e) {
LOG.error("Could not insert Tosca YAML data into the VFC_TO_NETWORK_ROLE_MAPPING table ", e);
}
-
- }
-
- } // CP loop
-
+
+ }
+
+ } // CP loop
+
} // VF loop
-
+
// Close ASDC TOSCA Parser factory - we are done processing this distribution
factory.close();
-
+
if ((artifact != null) && (data != null)) {
LOG.info("Update to SDN-C succeeded");
IDistributionClientResult deploymentStatus;
@@ -743,58 +728,58 @@ public class SdncUebCallback implements INotificationCallback {
client, data, artifact,
DistributionStatusEnum.DEPLOY_OK));
}
-
+
}
-
+
private void cleanUpExistingToscaData(String tableName, String keyName, String keyValue) throws IOException
{
-
+
if (jdbcDataSource == null) {
setJdbcDataSource();
}
try {
int rowCount = 0;
CachedRowSet data = jdbcDataSource.getData("SELECT * from " + tableName + " where " + keyName + " = " + keyValue + ";", null, "");
- while(data.next()) {
- rowCount ++;
+ while(data.next()) {
+ rowCount ++;
}
if (rowCount != 0) {
LOG.info("cleanUpExistingToscaData: " + keyValue);
jdbcDataSource.writeData("DELETE from " + tableName + " where " + keyName + " = " + keyValue + ";", null, null);
}
-
- } catch (SQLException e) {
+
+ } catch (SQLException e) {
LOG.error("Could not clean up existing " + tableName + " for " + keyValue, e);
- }
-
+ }
+
}
-
+
private void cleanUpExistingToscaServiceData(String serviceUUID) throws IOException
{
-
+
if (jdbcDataSource == null) {
setJdbcDataSource();
}
try {
int rowCount = 0;
CachedRowSet data = jdbcDataSource.getData("SELECT * from SERVICE_MODEL where service_uuid = " + serviceUUID + ";", null, "");
- while(data.next()) {
- rowCount ++;
+ while(data.next()) {
+ rowCount ++;
}
if (rowCount != 0) {
LOG.info("cleanUpExistingToscaData: " + serviceUUID);
jdbcDataSource.writeData("DELETE from NETWORK_MODEL where service_uuid = " + serviceUUID + ";", null, null);
jdbcDataSource.writeData("DELETE from SERVICE_MODEL where service_uuid = " + serviceUUID + ";", null, null);
}
-
- } catch (SQLException e) {
+
+ } catch (SQLException e) {
LOG.error("Could not clean up existing NETWORK_MODEL and SERVICE_MODEL for service_UUID " + serviceUUID, e);
- }
-
+ }
+
}
-
+
private void insertToscaData(String toscaDataString) throws IOException
{
LOG.debug("insertToscaData: " + toscaDataString);
@@ -867,11 +852,8 @@ public class SdncUebCallback implements INotificationCallback {
Date now = new Date();
String artifactVersion = sdfDate.format(now);
LOG.debug("Scheduling "+spoolFileName+" version "+artifactVersion+" for deployment");
- String artifactName = spoolFileName;
- if (artifactInfo != null) {
- artifactName = artifactInfo.getArtifactName();
- }
- deployList[type.getPass()].add(new DeployableArtifact(type, svcName, resourceName, artifactName, artifactVersion, spoolFile));
+ deployList[type.getPass()].add(new DeployableArtifact(type, svcName, resourceName, spoolFileName,
+ artifactVersion, spoolFile));
}
} else {
LOG.info("Pass for type "+type.getTag()+" is "+type.getPass()+" which is not <= "+deployList.length);
@@ -1056,8 +1038,7 @@ public class SdncUebCallback implements INotificationCallback {
private File applyXslts(File srcFile) {
- Document doc = null;
-
+ Document doc;
File inFile = srcFile;
File outFile = null;
diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java
index e19646e39..d29890486 100644
--- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java
+++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java
@@ -8,9 +8,9 @@
* 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.
@@ -30,12 +30,10 @@ import org.slf4j.LoggerFactory;
public class SdncUebClient {
- private static final Logger LOG = LoggerFactory
- .getLogger(SdncUebConfiguration.class);
+ private static final Logger LOG = LoggerFactory.getLogger(SdncUebConfiguration.class);
public static void main(String[] args) {
- IDistributionClient client = DistributionClientFactory
- .createDistributionClient();
+ IDistributionClient client = DistributionClientFactory.createDistributionClient();
SdncUebConfiguration config = new SdncUebConfiguration();
@@ -46,17 +44,14 @@ public class SdncUebClient {
LOG.info("Initializing ASDC distribution client");
- IDistributionClientResult result = client.init(
- config, cb);
+ IDistributionClientResult result = client.init(config, cb);
- LOG.info("Initialized ASDC distribution client - results = "
- + result.getDistributionMessageResult());
+ LOG.info("Initialized ASDC distribution client - results = {}", result.getDistributionMessageResult());
if (result.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS) {
LOG.info("Starting client...");
IDistributionClientResult start = client.start();
- LOG.info("Client startup result = "
- + start.getDistributionMessageResult());
+ LOG.info("Client startup result = {}", start.getDistributionMessageResult());
}
diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java
index 3c561118e..4d9c82464 100644
--- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java
+++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java
@@ -8,9 +8,9 @@
* 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.
@@ -91,7 +91,7 @@ public class SdncUebConfiguration implements IConfiguration{
}
public void init() throws IOException {
- String propPath = null;
+ String propPath;
String propDir = System.getenv(SDNC_CONFIG_DIR);
if (propDir == null) {
@@ -132,7 +132,7 @@ public class SdncUebConfiguration implements IConfiguration{
try {
pollingInterval = Integer.parseInt(curval);
} catch (Exception e) {
- LOG.warn("Illegal value for org.onap.ccsdk.sli.northbound.uebclient.polling-interval ("+curval+")");
+ LOG.warn("Illegal value for org.onap.ccsdk.sli.northbound.uebclient.polling-interval ({}) ", curval, e);
}
}
@@ -141,7 +141,7 @@ public class SdncUebConfiguration implements IConfiguration{
try {
pollingTimeout = Integer.parseInt(curval);
} catch (Exception e) {
- LOG.warn("Illegal value for org.onap.ccsdk.sli.northbound.uebclient.polling-timeout ("+curval+")");
+ LOG.warn("Illegal value for org.onap.ccsdk.sli.northbound.uebclient.polling-timeout ({}) ", curval, e);
}
}
@@ -149,18 +149,18 @@ public class SdncUebConfiguration implements IConfiguration{
if ((curval != null) && (curval.length() > 0)) {
String[] artifactTypes = curval.split(",");
- relevantArtifactTypes = new LinkedList<String>();
+ relevantArtifactTypes = new LinkedList<>();
- for (int i = 0 ; i < artifactTypes.length ; i++) {
+ for (String artifactType : artifactTypes) {
try {
- if (ArtifactTypeEnum.valueOf(artifactTypes[i]) != null) {
- relevantArtifactTypes.add(artifactTypes[i]);
+ if (ArtifactTypeEnum.valueOf(artifactType) != null) {
+ relevantArtifactTypes.add(artifactType);
} else {
- LOG.warn("Skipping unrecognized artifact type "+artifactTypes[i]);
+ LOG.warn("Skipping unrecognized artifact type {}", artifactType);
}
} catch (Exception e) {
- LOG.warn("Caught exception validating artifact type "+artifactTypes[i], e);
+ LOG.warn("Caught exception validating artifact type {}", artifactType, e);
}
}
@@ -263,11 +263,11 @@ public class SdncUebConfiguration implements IConfiguration{
}
public int getMaxPasses() {
- return(artifactMap.getNumPasses());
+ return artifactMap.getNumPasses();
}
public SdncArtifactMap.SdncArtifactType getMapping(String tag) {
- return(artifactMap.getMapping(tag));
+ return artifactMap.getMapping(tag);
}
@Override