summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2019-12-04 13:16:41 +0000
committerGerrit Code Review <gerrit@onap.org>2019-12-04 13:16:41 +0000
commit2a3c5a197236f7ba01b39c8bb51a6b977c964eeb (patch)
tree29bc2b710fe6d0ced2c1f488e03f95784c1a35c6
parent32dab99f3a01cedb20b6af8b85343c61fbd7a6fb (diff)
parentfc2a8c873189ee8d46e5973176777a4dad1e353f (diff)
Merge "DMAAP Listener for ORAN A1 Adapter Policy Mgmt"
-rw-r--r--dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/A1AdapterPolicyDmaapConsumer.java92
-rw-r--r--dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestA1AdapterPolicyDmaapConsumer.java136
-rw-r--r--dmaap-listener/src/test/resources/dmaap-consumer-a1Adapter-policy-1.properties35
3 files changed, 263 insertions, 0 deletions
diff --git a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/A1AdapterPolicyDmaapConsumer.java b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/A1AdapterPolicyDmaapConsumer.java
new file mode 100644
index 00000000..778a77b8
--- /dev/null
+++ b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/A1AdapterPolicyDmaapConsumer.java
@@ -0,0 +1,92 @@
+/*-
+ * ============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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class A1AdapterPolicyDmaapConsumer extends SdncDmaapConsumerImpl {
+
+ private static final Logger LOG = LoggerFactory.getLogger(A1AdapterPolicyDmaapConsumer.class);
+
+ private static final String BODY = "body";
+ private static final String RPC = "rpc-name";
+
+ @Override
+ public void processMsg(String msg) throws InvalidMessageException {
+
+ if (msg == null) {
+ throw new InvalidMessageException("Null A1-ADAPTER-DMAAP message");
+ }
+
+ ObjectMapper oMapper = new ObjectMapper();
+ JsonNode a1AdapterRootNode;
+ try {
+ a1AdapterRootNode = oMapper.readTree(msg);
+ } catch (Exception e) {
+ throw new InvalidMessageException("Cannot parse A1-ADAPTER-DMAAP json input", e);
+ }
+
+ JsonNode bodyNode = a1AdapterRootNode.get(BODY);
+ if(bodyNode == null) {
+ LOG.warn("Missing body in A1-ADAPTER-DMAAP message");
+ return;
+ }
+ String rpcMsgbody;
+ try {
+ ObjectMapper mapper = new ObjectMapper();
+ rpcMsgbody = mapper.writeValueAsString(bodyNode);
+
+ } catch (Exception e) {
+ LOG.error("Unable to parse body in A1-ADAPTER-DMAAP message", e);
+ return;
+ }
+
+ JsonNode rpcNode = a1AdapterRootNode.get(RPC);
+ if(rpcNode == null) {
+ LOG.warn("Missing node in A1-ADAPTER-DMAAP message- " + RPC);
+ return;
+ }
+ String rpc = rpcNode.textValue();
+ String sdncEndpoint = "A1-ADAPTER-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 A1-ADAPTER-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 A1-ADAPTER-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/TestA1AdapterPolicyDmaapConsumer.java b/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestA1AdapterPolicyDmaapConsumer.java
new file mode 100644
index 00000000..8b7044f6
--- /dev/null
+++ b/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestA1AdapterPolicyDmaapConsumer.java
@@ -0,0 +1,136 @@
+/*
+ * 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 TestA1AdapterPolicyDmaapConsumer {
+ private static final String a1AdapterInput = "{\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\": \"getHealthCheck\",\n" +
+ " \"Payload\": {\n" +
+ " \"near-rt-ric-id\": \"near-RT-ric1\",\n" +
+ " \"policy-type-id\": \"20000\",\n" +
+ " \"description\": \"parameters to control policy \",\n" +
+ " \"name\": \"admission_control_policy\",\n" +
+ " \"policy-type\": \"object\"\n" +
+ " }\n" +
+ " },\n" +
+ " \"version\": \"1.0\",\n" +
+ " \"rpc-name\": \"getHealthCheck\",\n" +
+ " \"correlation-id\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459-1\",\n" +
+ " \"type\": \"request\"\n" +
+ " }\n" +
+ "}";
+
+ @Test
+ public void test() throws Exception {
+ Properties props = new Properties();
+
+ A1AdapterPolicyDmaapConsumer consumer = new A1AdapterPolicyDmaapConsumer();
+ InputStream propStr = TestA1AdapterPolicyDmaapConsumer.class.getResourceAsStream("/dmaap-consumer-a1Adapter-policy-1.properties");
+ props.load(propStr);
+ consumer.init(props, "src/test/resources/dmaap-consumer-1.properties");
+ consumer.processMsg(a1AdapterInput);
+ }
+
+ @Test(expected = InvalidMessageException.class)
+ public void testProcessMsgNullMessage() throws Exception {
+ A1AdapterPolicyDmaapConsumer consumer = new A1AdapterPolicyDmaapConsumer();
+ consumer.processMsg(null);
+ }
+
+ @Test
+ public void testProcessMsgMissingBody() throws Exception {
+ String msg = "{\n" +
+ " \"body1\": {\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\": \"getHealthCheck\",\n" +
+ " \"Payload\": {\n" +
+ " \"near-rt-ric-id\": \"near-RT-ric1\",\n" +
+ " \"policy-type-id\": \"20000\",\n" +
+ " \"description\": \"parameters to control policy \",\n" +
+ " \"name\": \"admission_control_policy\",\n" +
+ " \"policy-type\": \"object\"\n" +
+ " }\n" +
+ " },\n" +
+ " \"version\": \"1.0\",\n" +
+ " \"rpc-name\": \"getHealthCheck\",\n" +
+ " \"correlation-id\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459-1\",\n" +
+ " \"type\": \"request\"\n" +
+ " }\n" +
+ "}";
+
+ A1AdapterPolicyDmaapConsumer consumer = new A1AdapterPolicyDmaapConsumer();
+ 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\": \"getHealthCheck\",\n" +
+ " \"Payload\": {\n" +
+ " \"near-rt-ric-id\": \"near-RT-ric1\",\n" +
+ " \"policy-type-id\": \"20000\",\n" +
+ " \"description\": \"parameters to control policy \",\n" +
+ " \"name\": \"admission_control_policy\",\n" +
+ " \"policy-type\": \"object\"\n" +
+ " }\n" +
+ " },\n" +
+ " \"version\": \"1.0\",\n" +
+ " \"rpc-name1\": \"getHealthCheck\",\n" +
+ " \"correlation-id\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459-1\",\n" +
+ " \"type\": \"request\"\n" +
+ " }\n" +
+ "}";
+
+ A1AdapterPolicyDmaapConsumer consumer = new A1AdapterPolicyDmaapConsumer();
+ consumer.processMsg(msg);
+ }
+
+}
diff --git a/dmaap-listener/src/test/resources/dmaap-consumer-a1Adapter-policy-1.properties b/dmaap-listener/src/test/resources/dmaap-consumer-a1Adapter-policy-1.properties
new file mode 100644
index 00000000..edb7c453
--- /dev/null
+++ b/dmaap-listener/src/test/resources/dmaap-consumer-a1Adapter-policy-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=A1-P
+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