diff options
author | Sandeep Shah <sandeeplinux1068@gmail.com> | 2020-03-03 10:10:48 -0600 |
---|---|---|
committer | Sandeep Shah <sandeeplinux1068@gmail.com> | 2020-03-03 10:10:48 -0600 |
commit | 66ce8b86e11159bc833a64685333f7676055e38d (patch) | |
tree | cd9e7d2fcecf8c478f20af41222758b9f74a330d | |
parent | f0594b8f4684ddbb81e490c630e5a968abd2170f (diff) |
DMAAP Listener for ORAN CMNotify VES events
DMAAP listener for VES events originating from ORAN.
Will invoke RPC/DG for updating RuntimeDB
Issue-ID: CCSDK-2133
Signed-off-by: SandeepLinux <Sandeep.Shah@ibm.com>
Change-Id: Ia17a7b2da1c58f5624c1d331aac56ce566d097bf
3 files changed, 287 insertions, 0 deletions
diff --git a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/CMNotifyDmaapConsumer.java b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/CMNotifyDmaapConsumer.java new file mode 100644 index 000000000..e49e77ea8 --- /dev/null +++ b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/CMNotifyDmaapConsumer.java @@ -0,0 +1,112 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : SDN-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * Modifications Copyright © 2019 IBM. + * ================================================================================ + * 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 com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.json.JSONObject; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class CMNotifyDmaapConsumer extends SdncDmaapConsumerImpl { + + private static final Logger LOG = LoggerFactory.getLogger(CMNotifyDmaapConsumer.class); + + private static final String BODY = "body"; + private static final String RPC = "rpc-name"; + private static final String INPUT = "input"; + private static final String PAYLOAD = "Payload"; + + @Override + public void processMsg(String msg) throws InvalidMessageException { + + if (msg == null) { + throw new InvalidMessageException("Null CMNotify-DMAAP message"); + } + + ObjectMapper oMapper = new ObjectMapper(); + JsonNode CMNotifyRootNode; + try { + CMNotifyRootNode = oMapper.readTree(msg); + } catch (Exception e) { + throw new InvalidMessageException("Cannot parse CMNotify-DMAAP json input", e); + } + + JsonNode bodyNode = CMNotifyRootNode.get(BODY); + if(bodyNode == null) { + LOG.warn("Missing body in CMNotify-DMAAP message"); + return; + } + + JsonNode input = bodyNode.get(INPUT); + if(input == null) { + LOG.info("Missing input node."); + return; + } + + JsonNode payloadNode = input.get(PAYLOAD); + if(payloadNode == null) { + LOG.info("Missing payload node."); + return; + } + + JSONObject rpcMsgBodyNode = new JSONObject(); + + rpcMsgBodyNode.put(INPUT,payloadNode); + + String rpcMsgbody; + try { + ObjectMapper mapper = new ObjectMapper(); + rpcMsgbody = mapper.writeValueAsString(rpcMsgBodyNode); + + } catch (Exception e) { + LOG.error("Unable to parse payload in CMNotify-DMAAP message", e); + return; + } + + JsonNode rpcNode = CMNotifyRootNode.get(RPC); + if(rpcNode == null) { + LOG.warn("Missing node in CMNotify-DMAAP message- " + RPC); + return; + } + String rpc = rpcNode.textValue(); + String sdncEndpoint = "CM-NOTIFY-API:" + rpc; + + try { + String odlUrlBase = getProperty("sdnc.odl.url-base"); + String odlUser = getProperty("sdnc.odl.user"); + String odlPassword = getProperty("sdnc.odl.password"); + LOG.info("POST CM-NOTIFY-API Request " + rpcMsgbody); + if ((odlUrlBase != null) && (odlUrlBase.length() > 0)) { + SdncOdlConnection conn = SdncOdlConnection.newInstance(odlUrlBase + "/" + sdncEndpoint, odlUser, odlPassword); + + conn.send("POST", "application/json", rpcMsgbody); + } else { + LOG.warn("Unable to POST CM-NOTIFY-API message. SDNC URL not available. body:\n" + rpcMsgbody); + } + } catch (Exception e) { + LOG.error("Unable to process message", e); + } + } +} diff --git a/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestCMNotifyDmaapConsumer.java b/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestCMNotifyDmaapConsumer.java new file mode 100644 index 000000000..122a6d40b --- /dev/null +++ b/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestCMNotifyDmaapConsumer.java @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2017. Lorem ipsum dolor sit amet, consectetur adipiscing elit. + * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. + * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. + * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. + * Vestibulum commodo. Ut rhoncus gravida arcu. + */ + +package org.onap.ccsdk.sli.northbound.dmaapclient; + +import static org.junit.Assert.assertTrue; + +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; + +import org.apache.commons.io.FileUtils; + +import org.junit.Before; +import org.junit.Test; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + + +public class TestCMNotifyDmaapConsumer { + private static final String cMNotifyInput = "{\n" + + " \"body\": {\n" + + " \"input\": {\n" + + " \"CommonHeader\": {\n" + + " \"TimeStamp\": \"2018-11-30T09:13:37.368Z\",\n" + + " \"APIver\": \"1.0\",\n" + + " \"RequestID\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459\",\n" + + " \"SubRequestID\": \"1\",\n" + + " \"RequestTrack\": {},\n" + + " \"Flags\": {}\n },\n" + + " \"Action\": \"nbrlist-change-notification\",\n" + + " \"Payload\": {\n" + + " \"fap-service-number-of-entries-changed\": 1,\n" + + " \"fap-service\": [{ \"alias\": \n" + + " \"Chn0001\", \"cid\": \"Chn0001\", \"lte-cell-number-of-entries\": 1,\n" + + " \"lte-ran-neighbor-list-in-use-lte-cell-changed\": \n" + + " [{ \"plmnid\": \"ran-1\", \"cid\": \"Chn0002\", \"phy-cell-id\": 4,\n" + + " \"pnf-name\": \"ncserver1\",\n" + + " \"blacklisted\": false }] }] }\n" + + " }\n" + + " },\n" + + " \"version\": \"1.0\",\n" + + " \"rpc-name\": \"nbrlist-change-notification\",\n" + + " \"correlation-id\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459-1\",\n" + + " \"type\": \"request\"\n" + + "}"; + + + @Test + public void test() throws Exception { + Properties props = new Properties(); + + CMNotifyDmaapConsumer consumer = new CMNotifyDmaapConsumer(); + InputStream propStr = TestCMNotifyDmaapConsumer.class.getResourceAsStream("/dmaap-consumer-cMNotify-1.properties"); + props.load(propStr); + consumer.init(props, "src/test/resources/dmaap-consumer-1.properties"); + consumer.processMsg(cMNotifyInput); + } + + @Test(expected = InvalidMessageException.class) + public void testProcessMsgNullMessage() throws Exception { + CMNotifyDmaapConsumer consumer = new CMNotifyDmaapConsumer(); + consumer.processMsg(null); + } + + @Test + public void testProcessMsgMissingBody() throws Exception { + String msg = "{\n" + + " \"bodyTest\": {\n" + + " \"input\": {\n" + + " \"CommonHeader\": {\n" + + " \"TimeStamp\": \"2018-11-30T09:13:37.368Z\",\n" + + " \"APIver\": \"1.0\",\n" + + " \"RequestID\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459\",\n" + + " \"SubRequestID\": \"1\",\n" + + " \"RequestTrack\": {},\n" + + " \"Flags\": {}\n },\n" + + " \"Action\": \"nbrlist-change-notification\",\n" + + " \"Payload\": {\n" + + " \"fap-service-number-of-entries-changed\": 1,\n" + + " \"fap-service\": [{ \"alias\": \n" + + " \"Chn0001\", \"cid\": \"Chn0001\", \"lte-cell-number-of-entries\": 1,\n" + + " \"lte-ran-neighbor-list-in-use-lte-cell-changed\": \n" + + " [{ \"plmnid\": \"ran-1\", \"cid\": \"Chn0002\", \"phy-cell-id\": 4,\n" + + " \"pnf-name\": \"ncserver1\",\n" + + " \"blacklisted\": false }] }] }\n" + + " }\n" + + " },\n" + + " \"version\": \"1.0\",\n" + + " \"rpc-name\": \"nbrlist-change-notification\",\n" + + " \"correlation-id\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459-1\",\n" + + " \"type\": \"request\"\n" + + "}"; + CMNotifyDmaapConsumer consumer = new CMNotifyDmaapConsumer(); + consumer.processMsg(msg); + } + + @Test + public void testProcessMsgInvalidRPC() throws Exception { + String msg = "{\n" + + " \"body\": {\n" + + " \"input\": {\n" + + " \"CommonHeader\": {\n" + + " \"TimeStamp\": \"2018-11-30T09:13:37.368Z\",\n" + + " \"APIver\": \"1.0\",\n" + + " \"RequestID\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459\",\n" + + " \"SubRequestID\": \"1\",\n" + + " \"RequestTrack\": {},\n" + + " \"Flags\": {}\n },\n" + + " \"Action\": \"nbrlist-change-notification\",\n" + + " \"Payload\": {\n" + + " \"fap-service-number-of-entries-changed\": 1,\n" + + " \"fap-service\": [{ \"alias\": \n" + + " \"Chn0001\", \"cid\": \"Chn0001\", \"lte-cell-number-of-entries\": 1,\n" + + " \"lte-ran-neighbor-list-in-use-lte-cell-changed\": \n" + + " [{ \"plmnid\": \"ran-1\", \"cid\": \"Chn0002\", \"phy-cell-id\": 4,\n" + + " \"pnf-name\": \"ncserver1\",\n" + + " \"blacklisted\": false }] }] }\n" + + " }\n" + + " },\n" + + " \"version\": \"1.0\",\n" + + " \"rpc-nameTest\": \"nbrlist-change-notification\",\n" + + " \"correlation-id\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459-1\",\n" + + " \"type\": \"request\"\n" + + "}"; + + CMNotifyDmaapConsumer consumer = new CMNotifyDmaapConsumer(); + consumer.processMsg(msg); + } + +} diff --git a/dmaap-listener/src/test/resources/dmaap-consumer-cMNotify-1.properties b/dmaap-listener/src/test/resources/dmaap-consumer-cMNotify-1.properties new file mode 100644 index 000000000..aae34a26f --- /dev/null +++ b/dmaap-listener/src/test/resources/dmaap-consumer-cMNotify-1.properties @@ -0,0 +1,35 @@ +TransportType=HTTPNOAUTH +Latitude =50.000000 +Longitude =-100.000000 +Version =1.0 +ServiceName =message-router.onap:3904/events +Environment =TEST +Partner = +routeOffer=MR1 +SubContextPath =/ +Protocol =http +MethodType =GET +username =admin +password =admin +contenttype =application/json +authKey=fs20cKwalJ6ry4kX:7Hqm6BDZK47IKxGRkOPFk33qMYs= +authDate=2019-04-09T04:28:40-05:00 +host=message-router.onap:3904 +topic=CM-NOTIFICATION +group=users +id=sdnc1 +timeout=15000 +limit=1000 +filter= +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=15000 +AFT_DME2_ROUNDTRIP_TIMEOUT_MS=240000 +AFT_DME2_EP_READ_TIMEOUT_MS=50000 +sessionstickinessrequired=NO +DME2preferredRouterFilePath=/opt/onap/sdnc/data/properties/dmaap-listener.preferredRoute.txt +sdnc.odl.user=admin +sdnc.odl.password=Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U +sdnc.odl.url-base=http://sdnc.onap:8282/restconf/operations |