aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2017-04-25 10:56:01 -0400
committerDan Timoney <dtimoney@att.com>2017-04-25 10:56:55 -0400
commit0690dac45a1fd760453859e795453cca59f1451e (patch)
tree19be67f8c6d93d05ccde044240788c30e42d8818
parent518824f28a7b57a0e855a162691e15ca76f2f9f5 (diff)
[SDNGC-5539] Add missing map
Update dmaap-listener to expect map file in /opt/app/dmaap-listener/lib and to deliver map file Change-Id: Ibdc84ce136e70b09765026c0ffd2167eb40dba8e Signed-off-by: Dan Timoney <dtimoney@att.com>
-rw-r--r--dmaap-listener/src/assembly/assemble_zip.xml1
-rw-r--r--dmaap-listener/src/main/java/org/openecomp/sdnc/dmaapclient/SdncFlatJsonDmaapConsumer.java88
2 files changed, 45 insertions, 44 deletions
diff --git a/dmaap-listener/src/assembly/assemble_zip.xml b/dmaap-listener/src/assembly/assemble_zip.xml
index b8c44c77..4874d005 100644
--- a/dmaap-listener/src/assembly/assemble_zip.xml
+++ b/dmaap-listener/src/assembly/assemble_zip.xml
@@ -46,6 +46,7 @@
<outputDirectory>lib</outputDirectory>
<includes>
<include>*.properties</include>
+ <include>*.map</include>
</includes>
</fileSet>
</fileSets>
diff --git a/dmaap-listener/src/main/java/org/openecomp/sdnc/dmaapclient/SdncFlatJsonDmaapConsumer.java b/dmaap-listener/src/main/java/org/openecomp/sdnc/dmaapclient/SdncFlatJsonDmaapConsumer.java
index 1cc5d149..a8186bdd 100644
--- a/dmaap-listener/src/main/java/org/openecomp/sdnc/dmaapclient/SdncFlatJsonDmaapConsumer.java
+++ b/dmaap-listener/src/main/java/org/openecomp/sdnc/dmaapclient/SdncFlatJsonDmaapConsumer.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.
@@ -49,67 +49,67 @@ 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 UEBLISTENERROOT = "UEBLISTENERROOT";
+
+ 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();
-
+
while (instarFields.hasNext()) {
Map.Entry<String, JsonNode> entry = instarFields.next();
-
+
instarMsgName = entry.getKey();
instarRootNode = entry.getValue();
break;
}
Map<String,String> fieldMap = loadMap(instarMsgName, mapDirName);
-
+
if (fieldMap == null) {
throw new InvalidMessageException("Unable to process message - cannot load field mappings");
}
-
+
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();
-
-
+
+
for (String fromField : fieldMap.keySet()) {
-
+
if (!SDNC_ENDPOINT.equals(fromField)) {
JsonNode curNode = instarRootNode.get(fromField);
if (curNode != null) {
@@ -120,60 +120,60 @@ public class SdncFlatJsonDmaapConsumer extends SdncDmaapConsumer {
}
}
sdncRootNode.put("input", inputNode);
-
+
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");
-
+
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) {
-
+
}
-
+
}
private Map<String,String> loadMap(String msgType, String mapDirName) {
Map<String, String> results = new HashMap<String, String>();
-
-
+
+
if (mapDirName == null) {
- String rootdir = System.getenv(UEBLISTENERROOT);
-
+ String rootdir = System.getenv(DMAAPLISTENERROOT);
+
if ((rootdir == null) || (rootdir.length() == 0)) {
- rootdir = "/opt/app/ueb-listener";
+ rootdir = "/opt/app/dmaap-listener";
}
-
+
mapDirName = rootdir + "/lib";
}
-
+
String mapFilename = mapDirName + "/" + msgType + ".map";
-
+
File mapFile = new File(mapFilename);
-
+
if (!mapFile.canRead()) {
LOG.error("Cannot read map file ("+mapFilename+")");
return(null);
}
-
+
try {
BufferedReader mapReader = new BufferedReader(new FileReader(mapFile));
-
+
String curLine = null;
-
+
while ((curLine = mapReader.readLine()) != null) {
curLine = curLine.trim();
-
+
if ((curLine.length() > 0) && (!curLine.startsWith("#"))) {
-
+
if (curLine.contains("=>")) {
String[] entry = curLine.split("=>");
if (entry.length == 2) {
@@ -187,10 +187,10 @@ public class SdncFlatJsonDmaapConsumer extends SdncDmaapConsumer {
LOG.error("Caught exception reading map "+mapFilename, e);
return(null);
}
-
+
return(results);
}
-
-
+
+
}