summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorshashikanth.vh <shashikanth.vh@huawei.com>2018-07-19 15:11:17 +0530
committerShashikanth VH <shashikanth.vh@huawei.com>2018-07-20 06:27:05 +0000
commitbe74be10e66d9a5d127c6280f802ef173dbf17de (patch)
tree5163e2c10b72a4d701cb7e77d86655ec0943f8f1
parent16ecee44bc14dcb0a128cfdabf0ae8b17f1db057 (diff)
Added dmaap consumer for esr-thirdparty AAI events
Modified SdncAaiDmaapConsumer.java to handle AAI EVENT for esr-thirdparty-sdnc and template Change-Id: I8aaa2e649a722d8d51f0b3329c94541396fde96b Issue-ID: CCSDK-389 Signed-off-by: shashikanth.vh <shashikanth.vh@huawei.com>
-rw-r--r--dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncAaiDmaapConsumer.java154
-rw-r--r--dmaap-listener/src/main/resources/esr-thirdparty-sdnc.map5
-rw-r--r--dmaap-listener/src/main/resources/template-esr-thirdparty-sdnc.vt100
-rw-r--r--dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestSdncEsrDmaapReceiver.java140
-rw-r--r--dmaap-listener/src/test/resources/dmaap-consumer-esrsysteminfo.properties34
-rwxr-xr-xdmaap-listener/src/test/resources/dmaap-listener.properties2
6 files changed, 391 insertions, 44 deletions
diff --git a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncAaiDmaapConsumer.java b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncAaiDmaapConsumer.java
index 2c4de7104..be2e36c1a 100644
--- a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncAaiDmaapConsumer.java
+++ b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncAaiDmaapConsumer.java
@@ -3,14 +3,14 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights
- * reserved.
+ * 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.
@@ -33,6 +33,7 @@ import java.util.Map;
import java.util.Properties;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
+import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -46,66 +47,133 @@ public class SdncAaiDmaapConsumer extends SdncDmaapConsumerImpl {
private static final String TEMPLATE = "SDNC.template";
private static final String DMAAPLISTENERROOT = "DMAAPLISTENERROOT";
+ private static final String ESR_SYSTEM_INFO = "esr-system-info";
+ private static final String RELATIONSHIP_LIST = "relationship-list";
+ private static final String ESR_SYSTEM_INFO_LIST = "esr-system-info-list";
private static final String AAI_EVENT = "AAI-EVENT";
-
+
private static final String EVENT_TYPE = "event-type";
+ private static final String ENTITY = "entity";
private static final String ENTITY_TYPE = "entity-type";
private static final String EVENT_HEADER = "event-header";
-
+
private String rootDir;
protected VelocityEngine velocityEngine;
-
+
public SdncAaiDmaapConsumer() {
velocityEngine = new VelocityEngine();
- Properties props = new Properties();
+ Properties props = new Properties();
rootDir = System.getenv(DMAAPLISTENERROOT);
if ((rootDir == null) || (rootDir.length() == 0)) {
- rootDir = "/opt/app/dmaap-listener/lib/";
+ rootDir = "/opt/app/dmaap-listener/lib/";
}
else {
- rootDir = rootDir + "/lib/";
+ rootDir = rootDir + "/lib/";
}
-
- props.put("file.resource.loader.path", rootDir);
+
+ props.put("file.resource.loader.path", rootDir);
velocityEngine.init(props);
}
-
+
/*
* for testing purposes
*/
SdncAaiDmaapConsumer(Properties props) {
- velocityEngine = new VelocityEngine();
+ velocityEngine = new VelocityEngine();
velocityEngine.init(props);
}
-
+
protected String publish(String templatePath, String jsonString) throws IOException
- {
- JSONObject jsonObj = new JSONObject(jsonString);
- VelocityContext context = new VelocityContext();
- for(Object key : jsonObj.keySet())
- {
- context.put((String)key, jsonObj.get((String)key));
- }
-
- String id = jsonObj.getJSONObject(EVENT_HEADER).get("id").toString();
- context.put("req_id", id);
-
- context.put("curr_time", Instant.now());
-
- ObjectMapper oMapper = new ObjectMapper();
-
- String rpcMsgbody = oMapper.writeValueAsString(jsonString);
- context.put("full_message", rpcMsgbody);
-
- Writer writer = new StringWriter();
- velocityEngine.mergeTemplate(templatePath, "UTF-8", context, writer);
- writer.flush();
-
- return writer.toString();
+ {
+ if (templatePath.contains("esr-thirdparty-sdnc")){
+ return publishEsrThirdPartySdnc(templatePath, jsonString);
+ } else {
+ return publishFullMessage(templatePath, jsonString);
+ }
+ }
+
+ private String publishFullMessage(String templatePath, String jsonString) throws IOException
+ {
+ JSONObject jsonObj = new JSONObject(jsonString);
+ VelocityContext context = new VelocityContext();
+ for(Object key : jsonObj.keySet())
+ {
+ context.put((String)key, jsonObj.get((String)key));
+ }
+
+ String id = jsonObj.getJSONObject(EVENT_HEADER).get("id").toString();
+ context.put("req_id", id);
+
+ context.put("curr_time", Instant.now());
+
+ ObjectMapper oMapper = new ObjectMapper();
+
+ String rpcMsgbody = oMapper.writeValueAsString(jsonString);
+ context.put("full_message", rpcMsgbody);
+
+ Writer writer = new StringWriter();
+ velocityEngine.mergeTemplate(templatePath, "UTF-8", context, writer);
+ writer.flush();
+
+ return writer.toString();
+ }
+
+ private String publishEsrThirdPartySdnc(String templatePath, String jsonString) throws IOException
+ {
+ JSONObject jsonObj = new JSONObject(jsonString);
+ VelocityContext context = new VelocityContext();
+
+ JSONObject eventHeader = jsonObj.getJSONObject(EVENT_HEADER);
+ for(Object key : eventHeader.keySet())
+ {
+ if (!key.equals("action")) {
+ context.put(((String)key).replaceAll("-", ""), eventHeader.get((String)key));
+ } else {
+ String action = (String) eventHeader.get((String) key);
+ context.put((String)key, action.substring(0,1).toUpperCase()
+ + action.substring(1).toLowerCase());
+ }
+ }
+
+ JSONObject entityObj = jsonObj.getJSONObject(ENTITY);
+ for(Object key : entityObj.keySet())
+ {
+ switch((String)key)
+ {
+ case ESR_SYSTEM_INFO_LIST :
+ JSONArray esrSystemInfo = entityObj.getJSONObject((String)key)
+ .getJSONArray(ESR_SYSTEM_INFO);
+
+ for (int i = 0; i < esrSystemInfo.length(); i++) {
+ JSONObject objects = esrSystemInfo.getJSONObject(i);
+
+ for (Object name : objects.keySet()) {
+ context.put(((String)name).replaceAll("-", ""),
+ objects.get((String)name).toString());
+ }
+ }
+ break;
+
+ case RELATIONSHIP_LIST :
+ //convertion not required for relationship
+ break;
+
+ default :
+ context.put(((String)key).replaceAll("-", ""),
+ entityObj.get((String)key).toString());
+ break;
+ }
+ }
+
+ Writer writer = new StringWriter();
+ velocityEngine.mergeTemplate(templatePath, "UTF-8", context, writer);
+ writer.flush();
+
+ return writer.toString();
}
-
+
@Override
public void processMsg(String msg) throws InvalidMessageException {
@@ -171,14 +239,14 @@ public class SdncAaiDmaapConsumer extends SdncDmaapConsumerImpl {
}
}
- private Map<String, String> loadMap(String mapFilename) {
- File mapFile = new File(mapFilename);
+ private Map<String, String> loadMap(String mapFilename) {
+ File mapFile = new File(mapFilename);
if (!mapFile.canRead()) {
LOG.error(String.format("Cannot read map file (%s)", mapFilename));
return null;
}
-
+
Map<String, String> results = new HashMap<>();
try (BufferedReader mapReader = new BufferedReader(new FileReader(mapFile))) {
@@ -199,8 +267,8 @@ public class SdncAaiDmaapConsumer extends SdncDmaapConsumerImpl {
LOG.error("Caught exception reading map " + mapFilename, e);
return null;
}
-
+
return results;
- }
+ }
}
diff --git a/dmaap-listener/src/main/resources/esr-thirdparty-sdnc.map b/dmaap-listener/src/main/resources/esr-thirdparty-sdnc.map
new file mode 100644
index 000000000..603645ebe
--- /dev/null
+++ b/dmaap-listener/src/main/resources/esr-thirdparty-sdnc.map
@@ -0,0 +1,5 @@
+# SDN-C URL
+SDNC.endpoint => DataChange:data-change-notification
+
+# Field mapping
+SDNC.template => template-esr-thirdparty-sdnc.vt
diff --git a/dmaap-listener/src/main/resources/template-esr-thirdparty-sdnc.vt b/dmaap-listener/src/main/resources/template-esr-thirdparty-sdnc.vt
new file mode 100644
index 000000000..225fce026
--- /dev/null
+++ b/dmaap-listener/src/main/resources/template-esr-thirdparty-sdnc.vt
@@ -0,0 +1,100 @@
+{
+ "DataChange:input": {
+ "DataChange:aai-node-type": "$entitytype",
+ "DataChange:selflink": "$entitylink",
+ "DataChange:aai-event-id": "$id",
+ "DataChange:aai-event-trigger": "$action",
+ "DataChange:key-data": [{
+ "DataChange:key-name": "thirdparty-sdnc-id",
+ "DataChange:key-value": "$thirdpartysdncid"
+ },
+ {
+ "DataChange:key-name": "resource-version",
+ "DataChange:key-value": "$resourceversion"
+ },
+ {
+ "DataChange:key-name": "location",
+ "DataChange:key-value": "$location"
+ },
+ {
+ "DataChange:key-name": "product-name",
+ "DataChange:key-value": "$productname"
+ },
+ {
+ "DataChange:key-name": "esr-system-info-id",
+ "DataChange:key-value": "$esrsysteminfoid"
+ },
+ {
+ "DataChange:key-name": "system-type",
+ "DataChange:key-value": "$systemtype"
+ },
+ {
+ "DataChange:key-name": "service-url",
+ "DataChange:key-value": "$serviceurl"
+ },
+ {
+ "DataChange:key-name": "ssl-cacert",
+ "DataChange:key-value": "$sslcacert"
+ },
+ {
+ "DataChange:key-name": "type",
+ "DataChange:key-value": "$type"
+ },
+ {
+ "DataChange:key-name": "ssl-insecure",
+ "DataChange:key-value": "$sslinsecure"
+ },
+ {
+ "DataChange:key-name": "system-status",
+ "DataChange:key-value": "$systemstatus"
+ },
+ {
+ "DataChange:key-name": "version",
+ "DataChange:key-value": "$version"
+ },
+ {
+ "DataChange:key-name": "passive",
+ "DataChange:key-value": "$passive"
+ },
+ {
+ "DataChange:key-name": "password",
+ "DataChange:key-value": "$password"
+ },
+ {
+ "DataChange:key-name": "protocol",
+ "DataChange:key-value": "$protocol"
+ },
+ {
+ "DataChange:key-name": "ip-address",
+ "DataChange:key-value": "$ipaddress"
+ },
+ {
+ "DataChange:key-name": "cloud-domain",
+ "DataChange:key-value": "$clouddomain"
+ },
+ {
+ "DataChange:key-name": "user-name",
+ "DataChange:key-value": "$username"
+ },
+ {
+ "DataChange:key-name": "system-name",
+ "DataChange:key-value": "$systemname"
+ },
+ {
+ "DataChange:key-name": "port",
+ "DataChange:key-value": "$port"
+ },
+ {
+ "DataChange:key-name": "vendor",
+ "DataChange:key-value": "$vendor"
+ },
+ {
+ "DataChange:key-name": "remote-path",
+ "DataChange:key-value": "$remotepath"
+ },
+ {
+ "DataChange:key-name": "default-tenant",
+ "DataChange:key-value": "$defaulttenant"
+ }]
+ }
+}
diff --git a/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestSdncEsrDmaapReceiver.java b/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestSdncEsrDmaapReceiver.java
new file mode 100644
index 000000000..623c96426
--- /dev/null
+++ b/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestSdncEsrDmaapReceiver.java
@@ -0,0 +1,140 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - CCSDK
+ * ================================================================================
+ * Copyright (C) 2018 Huawei Technologies Co., Ltd. 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.sli.northbound.dmaapclient;
+
+import org.apache.commons.io.FileUtils;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.util.Map;
+import java.util.Properties;
+
+public class TestSdncEsrDmaapReceiver {
+ static String aaiInput = "{\"cambria.partition\":\"AAI\",\n" +
+ " \"event-header\":\n" +
+ " {\n" +
+ " \"severity\":\"NORMAL\",\n" +
+ " \"entity-type\":\"esr-thirdparty-sdnc\",\n" +
+ " \"top-entity-type\":\"esr-thirdparty-sdnc\",\n" +
+ " \"entity-link\":\"aai/v11/external-system/esr-thirdparty-sdnc-list/esr-thirdparty-sdnc/IP-WAN-Controller-1\",\n" +
+ " \"event-type\":\"AAI-EVENT\",\n" +
+ " \"domain\":\"dev\",\n" +
+ " \"action\":\"UPDATE\",\n" +
+ " \"sequence-number\":\"0\",\n" +
+ " \"id\":\"bf4df797-759a-4684-a63c-393b7d40ed55\",\n" +
+ " \"source-name\":\"postman\",\n" +
+ " \"version\":\"v11\",\n" +
+ " \"timestamp\":\"20180104-09:57:58:721\"\n" +
+ " },\n" +
+ " \"entity\":\n" +
+ " {\n" +
+ " \"thirdparty-sdnc-id\":\"IP-WAN-Controller-1\",\n" +
+ " \"relationship-list\":\n" +
+ " {\n" +
+ " \"relationship\":\n" +
+ " [\n" +
+ " {\n" +
+ " \"related-to\":\"pnf\",\n" +
+ " \"relationship-data\":\n" +
+ " [\n" +
+ " {\n" +
+ " \"relationship-value\":\"a8098c1a-f86e-11da-bd1a-00112444be1e\",\n" +
+ " \"relationship-key\":\"pnf.pnf-name\"\n" +
+ " }\n" +
+ " ],\n" +
+ " \"related-link\":\"aai/v11/network/pnfs/pnf/a8098c1a-f86e-11da-bd1a-00112444be1e\"\n" +
+ " }\n" +
+ " ]\n" +
+ " },\n" +
+ " \"resource-version\":\"1515059878654\",\n" +
+ " \"location\":\"Core\",\n" +
+ " \"product-name\":\"AC-WAN\",\n" +
+ " \"esr-system-info-list\":\n" +
+ " {\"esr-system-info\":\n" +
+ " [\n" +
+ " {\n" +
+ " \"esr-system-info-id\":\"IP-WAN-Controller-ESR-1\",\n" +
+ " \"system-type\":\"example-system-type-val-12078\",\n" +
+ " \"service-url\":\"https://182.2.61.24:18002\",\n" +
+ " \"ssl-cacert\":\"example-ssl-cacert-val-20589\",\n" +
+ " \"type\":\"WAN\",\n" +
+ " \"ssl-insecure\":true,\n" +
+ " \"system-status\":\"example-system-status-val-23435\",\n" +
+ " \"version\":\"V3R1\",\n" +
+ " \"passive\":true,\n" +
+ " \"password\":\"Admin@12345\",\n" +
+ " \"protocol\":\"RESTCONF\",\n" +
+ " \"ip-address\":\"182.2.61.24\",\n" +
+ " \"cloud-domain\":\"example-cloud-domain-val-76077\",\n" +
+ " \"user-name\":\"admin\",\n" +
+ " \"system-name\":\"IP-WAN-Controller\",\n" +
+ " \"port\":\"18002\",\n" +
+ " \"vendor\":\"IP-WAN\",\n" +
+ " \"resource-version\":\"1515059878666\",\n" +
+ " \"remote-path\":\"example-remotepath-val-5833\",\n" +
+ " \"default-tenant\":\"example-default-tenant-val-71148\"\n" +
+ " }\n" +
+ " ]\n" +
+ " }\n" +
+ " }\n" +
+ " }";
+
+ @Test
+ public void testProcessMsgInvalidEventType() throws Exception {
+ String DMAAPLISTENERROOT = "DMAAPLISTENERROOT";
+ File directory = new File("lib");
+
+ if (! directory.exists()){
+ directory.mkdir();
+ }
+
+ File source = new File("src/main/resources");
+ File dest = new File("lib/");
+ try {
+ FileUtils.copyDirectory(source, dest);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ try {
+ Map<String, String> env = System.getenv();
+ Class<?> cl = env.getClass();
+ Field field = cl.getDeclaredField("m");
+ field.setAccessible(true);
+ Map<String, String> writableEnv = (Map<String, String>) field.get(env);
+ writableEnv.put(DMAAPLISTENERROOT, ".");
+ } catch (Exception e) {
+ throw new IllegalStateException("Failed to set environment variable", e);
+ }
+ Properties props = new Properties();
+ InputStream propStr = TestSdncEsrDmaapReceiver.class.getResourceAsStream("/dmaap-consumer-esrsysteminfo.properties");
+
+ props.load(propStr);
+
+ SdncAaiDmaapConsumer consumer = new SdncAaiDmaapConsumer();
+
+ consumer.init(props, "src/test/resources/dmaap-consumer-esrsysteminfo.properties");
+ consumer.processMsg(aaiInput);
+ }
+}
diff --git a/dmaap-listener/src/test/resources/dmaap-consumer-esrsysteminfo.properties b/dmaap-listener/src/test/resources/dmaap-consumer-esrsysteminfo.properties
new file mode 100644
index 000000000..9f5cfe71f
--- /dev/null
+++ b/dmaap-listener/src/test/resources/dmaap-consumer-esrsysteminfo.properties
@@ -0,0 +1,34 @@
+TransportType=DME2
+Latitude =47.778998
+Longitude =-122.182883
+Version =1.0
+ServiceName =dmaap-v1.dev.dmaap.dt.saat.acsi.att.com/events
+Environment =TEST
+Partner =
+SubContextPath =/
+Protocol =https
+MethodType =GET
+username =test
+password =test
+contenttype =application/json
+authKey=ABC123
+authDate=2016-05-10T13:13:50-0700
+host=localhost:3904
+topic=AAI-EVENT
+group=pserver
+id=1
+timeout=20000
+limit=10000
+filter={"class":"Equals","field":"event-header.entity-type","value":"pserver"}
+AFT_DME2_EXCHANGE_REQUEST_HANDLERS=com.att.nsa.test.PreferredRouteRequestHandler
+AFT_DME2_EXCHANGE_REPLY_HANDLERS=com.att.nsa.test.PreferredRouteReplyHandler
+AFT_DME2_REQ_TRACE_ON=true
+AFT_ENVIRONMENT=AFTUAT
+AFT_DME2_EP_CONN_TIMEOUT=55000
+AFT_DME2_ROUNDTRIP_TIMEOUT_MS=240000
+AFT_DME2_EP_READ_TIMEOUT_MS=50000
+sessionstickinessrequired=NO
+DME2preferredRouterFilePath=src/test/resources/dmaap-listener.preferredRoute.txt
+sdnc.odl.user=admin
+sdnc.odl.password=admin
+sdnc.odl.url-base=http://localhost:8181/restconf/operations \ No newline at end of file
diff --git a/dmaap-listener/src/test/resources/dmaap-listener.properties b/dmaap-listener/src/test/resources/dmaap-listener.properties
index ed180e515..defef0b43 100755
--- a/dmaap-listener/src/test/resources/dmaap-listener.properties
+++ b/dmaap-listener/src/test/resources/dmaap-listener.properties
@@ -1 +1 @@
-subscriptions=org.onap.ccsdk.sli.northbound.dmaapclient.DummyDmaapConsumer:dmaap-consumer-1.properties \ No newline at end of file
+subscriptions=org.onap.ccsdk.sli.northbound.dmaapclient.DummyDmaapConsumer:dmaap-consumer-1.properties;org.onap.ccsdk.sli.northbound.dmaapclient.SdncAaiDmaapConsumer:dmaap-consumer-esrsysteminfo.properties \ No newline at end of file