Release version 1.1.0 of sli/northbound
[ccsdk/sli/northbound.git] / dmaap-listener / src / main / java / org / onap / ccsdk / sli / northbound / dmaapclient / OofPciPocDmaapConsumers.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.ccsdk.sli.northbound.dmaapclient;
23
24 import java.io.BufferedReader;
25 import java.io.File;
26 import java.io.FileReader;
27 import java.io.IOException;
28 import java.io.StringWriter;
29 import java.io.Writer;
30 import java.time.Instant;
31 import java.util.HashMap;
32 import java.util.Map;
33 import java.util.Properties;
34 import org.apache.velocity.VelocityContext;
35 import org.apache.velocity.app.VelocityEngine;
36 import org.json.JSONArray;
37 import org.json.JSONObject;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40 import com.fasterxml.jackson.databind.JsonNode;
41 import com.fasterxml.jackson.databind.ObjectMapper;
42
43 public class OofPciPocDmaapConsumers extends SdncDmaapConsumerImpl {
44
45     private static final Logger LOG = LoggerFactory.getLogger(OofPciPocDmaapConsumers.class);
46     private static final String SDNC_ENDPOINT = "SDNC.endpoint";
47     private static final String TEMPLATE = "SDNC.template";
48     private static final String DMAAPLISTENERROOT = "DMAAPLISTENERROOT";
49     private static final String UTF_8 = "UTF-8";
50
51     private static final String PARAMETER_NAME = "parameter-name";
52     private static final String STRING_VALUE = "string-value";
53     private static final String PHYSICAL_CELL_ID_INPUT_FAP_SERVICE = "configuration-phy-cell-id-input.fap-service";
54     private static final String EVENT_HEADER = "event-header";
55         private static final String ACTION = "Action";
56         private static final String CONFIGURATIONS = "Configurations";
57         private static final String MODIFY_CONFIG = "ModifyConfig";
58         private static final String DATA = "data";
59         private static final String FAP_SERVICE = "FAPService";
60
61         private static final String PAYLOAD = "Payload";
62         private static final String PCI_CHANGES_MAP_FILE_NAME = "pci-changes-from-policy-to-sdnr";
63         private static final String SLI_PARAMETERS = "sli_parameters";
64         private static final String RPC_NAME = "rpc-name";
65         private static final String BODY = "body";
66         private static final String INPUT = "input";
67   private static final String COMMON_HEADER = "CommonHeader";
68   private static final String TIME_STAMP = "TimeStamp";
69   private static final String REQUEST_ID = "RequestID";
70   private static final String SUB_REQUEST_ID = "SubRequestID";
71
72   private static final String TIME_STAMP_FOR_SLI = "timeStamp";
73   private static final String REQUEST_ID_FOR_SLI = "requestID";
74   private static final String SUB_REQUEST_ID_FOR_SLI = "subRequestID";
75
76   private static final String CONFIGURATION_PHY_CELL_ID_INPUT = "configuration-phy-cell-id-input.";
77
78         private static final String EMPTY = "";
79         private static final String ESCAPE_SEQUENCE_QUOTES = "\"";
80
81     private static final String GENERIC_NEIGHBOR_CONFIGURATION_INPUT = "generic-neighbor-configuration-input.";
82     private static final String GENERIC_NEIGHBOR_CONFIGURATION_INPUT_NEIGHBOR_LIST_IN_USE = GENERIC_NEIGHBOR_CONFIGURATION_INPUT.concat("neighbor-list-in-use");
83         private static final String MODIFY_CONFIG_ANR = "ModifyConfigANR";
84         private static final String ANR_CHANGES_MAP_FILE_NAME = "anr-changes-from-policy-to-sdnr";
85
86     private String rootDir;
87
88     protected VelocityEngine velocityEngine;
89
90     public OofPciPocDmaapConsumers() {
91         velocityEngine = new VelocityEngine();
92         Properties props = new Properties();
93         rootDir = System.getenv(DMAAPLISTENERROOT);
94
95         if ((rootDir == null) || (rootDir.length() == 0)) {
96           rootDir = "/opt/onap/sdnc/dmaap-listener/lib/";
97         }
98         else {
99             rootDir = rootDir + "/lib/";
100         }
101
102         props.put("file.resource.loader.path", rootDir);
103         velocityEngine.init(props);
104     }
105
106     /*
107      * for testing purposes
108      */
109     OofPciPocDmaapConsumers(Properties props) {
110         velocityEngine = new VelocityEngine();
111         velocityEngine.init(props);
112     }
113
114     protected String publish(String templatePath, String jsonString, JsonNode configurationsOrDataNode, boolean invokePciChangesPublish, boolean invokeAnrChangesPublish) throws IOException, InvalidMessageException
115     {
116         if (invokePciChangesPublish){
117             return publishPciChangesFromPolicyToSDNR(templatePath, configurationsOrDataNode, jsonString);
118         } else if (invokeAnrChangesPublish){
119             return publishANRChangesFromPolicyToSDNR(templatePath, configurationsOrDataNode, jsonString);
120         } else {
121             return publishFullMessage(templatePath, jsonString);
122         }
123     }
124
125     private String publishFullMessage(String templatePath, String jsonString) throws IOException
126     {
127         JSONObject jsonObj = new JSONObject(jsonString);
128         VelocityContext context = new VelocityContext();
129         for(Object key : jsonObj.keySet())
130         {
131             context.put((String)key, jsonObj.get((String)key));
132         }
133
134         String id = jsonObj.getJSONObject(EVENT_HEADER).get("id").toString();
135         context.put("req_id", id);
136
137         context.put("curr_time", Instant.now());
138
139         ObjectMapper oMapper = new ObjectMapper();
140
141         String rpcMsgbody = oMapper.writeValueAsString(jsonString);
142         context.put("full_message", rpcMsgbody);
143
144         Writer writer = new StringWriter();
145         velocityEngine.mergeTemplate(templatePath, UTF_8, context, writer);
146         writer.flush();
147
148         return writer.toString();
149     }
150
151     private String publishANRChangesFromPolicyToSDNR(String templatePath, JsonNode dataNode, String msg) throws IOException, InvalidMessageException
152     {
153         VelocityContext context = new VelocityContext();
154
155         String RPC_NAME_KEY_IN_VT = "rpc_name";
156         String RPC_NAME_VALUE_IN_VT = "generic-neighbor-configuration";
157
158         String CELL_CONFIG = "CellConfig";
159         String ALIAS_LABEL = "alias";
160         String LTE = "LTE";
161         String RAN = "RAN";
162         String LTE_CELL = "LTECell";
163         String NEIGHBOR_LIST_IN_USE = "NeighborListInUse";
164
165         JSONObject numberOfEntries = new JSONObject();
166         JSONObject alias = new JSONObject();
167         JSONArray sliParametersArray = new JSONArray();
168
169         ObjectMapper oMapper = new ObjectMapper();
170
171         JsonNode dmaapMessageRootNode;
172         try {
173                 dmaapMessageRootNode = oMapper.readTree(msg);
174         } catch (Exception e) {
175             throw new InvalidMessageException("Cannot parse json object", e);
176         }
177
178         JsonNode commonHeader = dmaapMessageRootNode.get(BODY).get(INPUT).get(COMMON_HEADER);
179
180         JsonNode timeStamp = commonHeader.get(TIME_STAMP);
181
182         JsonNode requestID = commonHeader.get(REQUEST_ID);
183
184         JsonNode subRequestID = commonHeader.get(SUB_REQUEST_ID);
185
186         sliParametersArray.put(new JSONObject().put(PARAMETER_NAME, GENERIC_NEIGHBOR_CONFIGURATION_INPUT+TIME_STAMP_FOR_SLI).put(STRING_VALUE,timeStamp));
187
188         sliParametersArray.put(new JSONObject().put(PARAMETER_NAME, GENERIC_NEIGHBOR_CONFIGURATION_INPUT+REQUEST_ID_FOR_SLI).put(STRING_VALUE,requestID));
189
190         sliParametersArray.put(new JSONObject().put(PARAMETER_NAME, GENERIC_NEIGHBOR_CONFIGURATION_INPUT+SUB_REQUEST_ID_FOR_SLI).put(STRING_VALUE,subRequestID));
191
192         String aliasValue =  dataNode.get(DATA).get(FAP_SERVICE).get(ALIAS_LABEL).textValue();
193
194         JsonNode nbrListInUse = dataNode.get(DATA).get(FAP_SERVICE).get(CELL_CONFIG).get(LTE).get(RAN).get(NEIGHBOR_LIST_IN_USE).get(LTE_CELL);
195
196         int entryCount = 0;
197
198         if(nbrListInUse.isArray()) {
199                 for(JsonNode lteCell:nbrListInUse) {
200                         sliParametersArray.put(new JSONObject().put(PARAMETER_NAME, GENERIC_NEIGHBOR_CONFIGURATION_INPUT_NEIGHBOR_LIST_IN_USE+"["+entryCount+"]."+"plmnid")
201                                 .put(STRING_VALUE, lteCell.get("PLMNID").toString().replace(ESCAPE_SEQUENCE_QUOTES, EMPTY)));
202                         sliParametersArray.put(new JSONObject().put(PARAMETER_NAME, GENERIC_NEIGHBOR_CONFIGURATION_INPUT_NEIGHBOR_LIST_IN_USE+"["+entryCount+"]."+"cid")
203                                 .put(STRING_VALUE, lteCell.get("CID").toString().replace(ESCAPE_SEQUENCE_QUOTES, EMPTY)));
204                         sliParametersArray.put(new JSONObject().put(PARAMETER_NAME, GENERIC_NEIGHBOR_CONFIGURATION_INPUT_NEIGHBOR_LIST_IN_USE+"["+entryCount+"]."+"phy-cell-id")
205                                 .put(STRING_VALUE, lteCell.get("PhyCellID").toString().replace(ESCAPE_SEQUENCE_QUOTES, EMPTY)));
206                         sliParametersArray.put(new JSONObject().put(PARAMETER_NAME, GENERIC_NEIGHBOR_CONFIGURATION_INPUT_NEIGHBOR_LIST_IN_USE+"["+entryCount+"]."+"pnf-name")
207                                 .put(STRING_VALUE, lteCell.get("PNFName").toString().replace(ESCAPE_SEQUENCE_QUOTES, EMPTY)));
208                         sliParametersArray.put(new JSONObject().put(PARAMETER_NAME, GENERIC_NEIGHBOR_CONFIGURATION_INPUT_NEIGHBOR_LIST_IN_USE+"["+entryCount+"]."+"blacklisted")
209                                 .put(STRING_VALUE, lteCell.get("Blacklisted").toString().replace(ESCAPE_SEQUENCE_QUOTES, EMPTY)));
210
211                         entryCount++;
212                 }
213
214                 alias.put(PARAMETER_NAME, GENERIC_NEIGHBOR_CONFIGURATION_INPUT+ALIAS_LABEL);
215             alias.put(STRING_VALUE, aliasValue);
216
217             numberOfEntries.put(PARAMETER_NAME, GENERIC_NEIGHBOR_CONFIGURATION_INPUT+"lte-cell-number-of-entries");
218             numberOfEntries.put(STRING_VALUE, entryCount);
219
220             sliParametersArray.put(alias);
221             sliParametersArray.put(numberOfEntries);
222
223             context.put(SLI_PARAMETERS, sliParametersArray);
224
225             context.put(RPC_NAME_KEY_IN_VT, RPC_NAME_VALUE_IN_VT);
226
227             Writer writer = new StringWriter();
228             velocityEngine.mergeTemplate(templatePath, UTF_8, context, writer);
229             writer.flush();
230
231             return writer.toString();
232
233         }else {
234                 throw new InvalidMessageException("nbrListInUse is not of Type Array. Could not read neighbor list elements");
235         }
236
237     }
238
239     private String publishPciChangesFromPolicyToSDNR(String templatePath, JsonNode configurationsJsonNode, String msg) throws IOException, InvalidMessageException
240     {
241         String RPC_NAME_KEY_IN_VT = "rpc_name";
242         String RPC_NAME_VALUE_IN_VT = "configuration-phy-cell-id";
243         String ALIAS = "alias";
244         String X0005b9Lte = "X0005b9Lte";
245
246         VelocityContext context = new VelocityContext();
247
248         JSONObject numberOfEntries = new JSONObject();
249         JSONArray sliParametersArray = new JSONArray();
250
251         JsonNode configurations = configurationsJsonNode.get(CONFIGURATIONS);
252
253         ObjectMapper oMapper = new ObjectMapper();
254
255         JsonNode dmaapMessageRootNode;
256         try {
257                 dmaapMessageRootNode = oMapper.readTree(msg);
258         } catch (Exception e) {
259             throw new InvalidMessageException("Cannot parse json object", e);
260         }
261
262         JsonNode commonHeader = dmaapMessageRootNode.get(BODY).get(INPUT).get(COMMON_HEADER);
263
264         JsonNode timeStamp = commonHeader.get(TIME_STAMP);
265
266         JsonNode requestID = commonHeader.get(REQUEST_ID);
267
268         JsonNode subRequestID = commonHeader.get(SUB_REQUEST_ID);
269
270         sliParametersArray.put(new JSONObject().put(PARAMETER_NAME, CONFIGURATION_PHY_CELL_ID_INPUT+TIME_STAMP_FOR_SLI).put(STRING_VALUE,timeStamp));
271
272         sliParametersArray.put(new JSONObject().put(PARAMETER_NAME, CONFIGURATION_PHY_CELL_ID_INPUT+REQUEST_ID_FOR_SLI).put(STRING_VALUE,requestID));
273
274         sliParametersArray.put(new JSONObject().put(PARAMETER_NAME, CONFIGURATION_PHY_CELL_ID_INPUT+SUB_REQUEST_ID_FOR_SLI).put(STRING_VALUE,subRequestID));
275
276         int entryCount = 0;
277
278         if(configurations.isArray()) {
279                 for(JsonNode dataNode:configurations) {
280                         sliParametersArray.put(new JSONObject().put(PARAMETER_NAME, PHYSICAL_CELL_ID_INPUT_FAP_SERVICE+"["+entryCount+"]."+ALIAS)
281                                 .put(STRING_VALUE, dataNode.get(DATA).get(FAP_SERVICE).get(ALIAS).toString().replace(ESCAPE_SEQUENCE_QUOTES, EMPTY)));
282                         sliParametersArray.put(new JSONObject().put(PARAMETER_NAME, PHYSICAL_CELL_ID_INPUT_FAP_SERVICE+"["+entryCount+"]."+"cid")
283                                 .put(STRING_VALUE, dataNode.get(DATA).get(FAP_SERVICE).get("CellConfig").get("LTE").get("RAN").get("Common").get("CellIdentity").toString().replace(ESCAPE_SEQUENCE_QUOTES, EMPTY)));
284                         sliParametersArray.put(new JSONObject().put(PARAMETER_NAME, PHYSICAL_CELL_ID_INPUT_FAP_SERVICE+"["+entryCount+"]."+"phy-cell-id-in-use")
285                                 .put(STRING_VALUE, dataNode.get(DATA).get(FAP_SERVICE).get(X0005b9Lte).get("phyCellIdInUse").toString().replace(ESCAPE_SEQUENCE_QUOTES, EMPTY)));
286                         sliParametersArray.put(new JSONObject().put(PARAMETER_NAME, PHYSICAL_CELL_ID_INPUT_FAP_SERVICE+"["+entryCount+"]."+"pnf-name")
287                                 .put(STRING_VALUE, dataNode.get(DATA).get(FAP_SERVICE).get(X0005b9Lte).get("pnfName").toString().replace(ESCAPE_SEQUENCE_QUOTES, EMPTY)));
288                         entryCount++;
289                 }
290
291             numberOfEntries.put(PARAMETER_NAME, PHYSICAL_CELL_ID_INPUT_FAP_SERVICE+"-number-of-entries");
292             numberOfEntries.put(STRING_VALUE, entryCount);
293
294             sliParametersArray.put(numberOfEntries);
295
296             context.put(SLI_PARAMETERS, sliParametersArray);
297
298             context.put(RPC_NAME_KEY_IN_VT, RPC_NAME_VALUE_IN_VT);
299
300             Writer writer = new StringWriter();
301             velocityEngine.mergeTemplate(templatePath, UTF_8, context, writer);
302             writer.flush();
303
304             return writer.toString();
305
306         }else {
307                 throw new InvalidMessageException("Configurations is not of Type Array. Could not read configuration changes");
308         }
309
310     }
311
312     @Override
313     public void processMsg(String msg) throws InvalidMessageException {
314
315         if (msg == null) {
316             throw new InvalidMessageException("Null message");
317         }
318
319         ObjectMapper oMapper = new ObjectMapper();
320         JsonNode dmaapMessageRootNode;
321         try {
322                 dmaapMessageRootNode = oMapper.readTree(msg);
323         } catch (Exception e) {
324             throw new InvalidMessageException("Cannot parse json object", e);
325         }
326
327
328         JsonNode rpcnameNode = dmaapMessageRootNode.get(RPC_NAME);
329         if(rpcnameNode == null) {
330                  LOG.info("Unable to identify the respective consumer to invoke. Please verify the dmaap message..");
331                  return;
332         }
333
334         String rpcname = rpcnameNode.textValue();
335
336         if(!MODIFY_CONFIG.toLowerCase().equals(rpcname) && !MODIFY_CONFIG_ANR.toLowerCase().equals(rpcname)) {
337             LOG.info("Unknown rpc name {}", rpcname);
338             return;
339         }
340
341         if(MODIFY_CONFIG.toLowerCase().equals(rpcname)) {
342                 invokePCIChangesConsumer(dmaapMessageRootNode, oMapper, msg);
343             return;
344         }
345
346         if(MODIFY_CONFIG_ANR.toLowerCase().equals(rpcname)) {
347                 invokeANRChangesConsumer(dmaapMessageRootNode, oMapper, msg);
348             return;
349         }
350
351     }
352
353     private void invokeANRChangesConsumer(JsonNode dmaapMessageRootNode, ObjectMapper oMapper,
354                         String msg) throws InvalidMessageException {
355         JsonNode body = dmaapMessageRootNode.get(BODY);
356         if(body == null) {
357                  LOG.info("Missing body node.");
358                  return;
359         }
360
361         JsonNode input = body.get(INPUT);
362         if(input == null) {
363                  LOG.info("Missing input node.");
364                  return;
365         }
366
367         JsonNode action = input.get(ACTION);
368         if(action == null) {
369                  LOG.info("Missing action node.");
370                  return;
371         }
372
373         if(!MODIFY_CONFIG_ANR.equals(action.textValue())) {
374             LOG.info("Unknown Action {}", action);
375             return;
376         }
377
378         JsonNode payload = input.get(PAYLOAD);
379         if(payload == null) {
380             LOG.info("Missing payload node.");
381             return;
382         }
383
384         String payloadText = payload.asText();
385
386         if(!payloadText.contains(CONFIGURATIONS)) {
387          LOG.info("Missing configurations node.");
388          return;
389        }
390
391        JsonNode configurationsJsonNode;
392             try {
393                 configurationsJsonNode = oMapper.readTree(payloadText);
394             } catch (Exception e) {
395                 throw new InvalidMessageException("Cannot parse payload value", e);
396             }
397
398         String mapFilename = rootDir + ANR_CHANGES_MAP_FILE_NAME + ".map";
399         Map<String, String> fieldMap = loadMap(mapFilename);
400         if (fieldMap == null) {
401             return;
402         }
403
404         if (!fieldMap.containsKey(SDNC_ENDPOINT)) {
405             return;
406         }
407         String sdncEndpoint = fieldMap.get(SDNC_ENDPOINT);
408
409         if (!fieldMap.containsKey(TEMPLATE)) {
410             throw new InvalidMessageException("No SDNC template known for message ");
411         }
412         String templateName = fieldMap.get(TEMPLATE);
413
414         JsonNode configurations = configurationsJsonNode.get(CONFIGURATIONS);
415
416         if(configurations.isArray()) {
417                 for(JsonNode dataNode:configurations) {
418                 if(dataNode.get(DATA).get(FAP_SERVICE) == null) {
419                     LOG.info("Could not make a rpc call. Missing fapService node for dataNode element::", dataNode.textValue());
420                 }else {
421                         buildAndInvokeANRChangesRPC(sdncEndpoint, templateName,msg, dataNode);
422                 }
423                 }
424         }else {
425                 throw new InvalidMessageException("Configurations is not of Type Array. Could not read configuration changes");
426         }
427         }
428
429         private void invokePCIChangesConsumer(JsonNode dmaapMessageRootNode, ObjectMapper oMapper,
430                         String msg) throws InvalidMessageException {
431                 JsonNode body = dmaapMessageRootNode.get(BODY);
432         if(body == null) {
433                  LOG.info("Missing body node.");
434                  return;
435         }
436
437         JsonNode input = body.get(INPUT);
438         if(input == null) {
439                  LOG.info("Missing input node.");
440                  return;
441         }
442
443         JsonNode action = input.get(ACTION);
444         if(action == null) {
445                  LOG.info("Missing action node.");
446                  return;
447         }
448
449
450         if(!MODIFY_CONFIG.equals(action.textValue())) {
451             LOG.info("Unknown Action {}", action);
452             return;
453         }
454
455         JsonNode payload = input.get(PAYLOAD);
456         if(payload == null) {
457             LOG.info("Missing payload node.");
458             return;
459         }
460
461         String configurations = payload.asText();
462
463         if(!configurations.contains(CONFIGURATIONS)) {
464          LOG.info("Missing configurations node.");
465          return;
466        }
467
468        JsonNode configurationsJsonNode;
469             try {
470                 configurationsJsonNode = oMapper.readTree(configurations);
471             } catch (Exception e) {
472                 throw new InvalidMessageException("Cannot parse payload value", e);
473             }
474
475         String mapFilename = rootDir + PCI_CHANGES_MAP_FILE_NAME + ".map";
476         Map<String, String> fieldMap = loadMap(mapFilename);
477         if (fieldMap == null) {
478             return;
479         }
480
481         if (!fieldMap.containsKey(SDNC_ENDPOINT)) {
482             return;
483         }
484         String sdncEndpoint = fieldMap.get(SDNC_ENDPOINT);
485
486         if (!fieldMap.containsKey(TEMPLATE)) {
487             throw new InvalidMessageException("No SDNC template known for message ");
488         }
489         String templateName = fieldMap.get(TEMPLATE);
490
491         buildAndInvokePCIChangesRPC(sdncEndpoint, templateName, msg, configurationsJsonNode);
492         }
493
494         private void buildAndInvokePCIChangesRPC(String sdncEndpoint, String templateName, String msg, JsonNode configurationsOrDataNode) {
495                 try {
496             String rpcMsgbody = publish(templateName, msg, configurationsOrDataNode, true, false);
497             String odlUrlBase = getProperty("sdnc.odl.url-base");
498             String odlUser = getProperty("sdnc.odl.user");
499             String odlPassword = getProperty("sdnc.odl.password");
500
501             if ((odlUrlBase != null) && (odlUrlBase.length() > 0)) {
502                 SdncOdlConnection conn = SdncOdlConnection.newInstance(odlUrlBase + "/" + sdncEndpoint, odlUser, odlPassword);
503
504                 conn.send("POST", "application/json", rpcMsgbody);
505             } else {
506                 LOG.info("POST message body would be:\n" + rpcMsgbody);
507             }
508         } catch (Exception e) {
509             LOG.error("Unable to process message", e);
510         }
511         }
512
513         private void buildAndInvokeANRChangesRPC(String sdncEndpoint, String templateName, String msg, JsonNode configurationsOrDataNode) {
514                 try {
515             String rpcMsgbody = publish(templateName, msg, configurationsOrDataNode, false, true);
516             String odlUrlBase = getProperty("sdnc.odl.url-base");
517             String odlUser = getProperty("sdnc.odl.user");
518             String odlPassword = getProperty("sdnc.odl.password");
519
520             if ((odlUrlBase != null) && (odlUrlBase.length() > 0)) {
521                 SdncOdlConnection conn = SdncOdlConnection.newInstance(odlUrlBase + "/" + sdncEndpoint, odlUser, odlPassword);
522
523                 conn.send("POST", "application/json", rpcMsgbody);
524             } else {
525                 LOG.info("POST message body would be:\n" + rpcMsgbody);
526             }
527         } catch (Exception e) {
528             LOG.error("Unable to process message", e);
529         }
530         }
531
532         private Map<String, String> loadMap(String mapFilename) {
533         File mapFile = new File(mapFilename);
534
535         if (!mapFile.canRead()) {
536             LOG.error(String.format("Cannot read map file (%s)", mapFilename));
537             return null;
538         }
539
540         Map<String, String> results = new HashMap<>();
541         try (BufferedReader mapReader = new BufferedReader(new FileReader(mapFile))) {
542
543             String curLine;
544
545             while ((curLine = mapReader.readLine()) != null) {
546                 curLine = curLine.trim();
547
548                 if ((curLine.length() > 0) && (!curLine.startsWith("#")) && curLine.contains("=>")) {
549                     String[] entry = curLine.split("=>");
550                     if (entry.length == 2) {
551                         results.put(entry[0].trim(), entry[1].trim());
552                     }
553                 }
554             }
555             mapReader.close();
556         } catch (Exception e) {
557             LOG.error("Caught exception reading map " + mapFilename, e);
558             return null;
559         }
560
561         return results;
562     }
563
564 }