Change code in appc dispatcher for new LCMs in R6
[appc.git] / appc-inbound / appc-design-services / provider / src / main / java / org / onap / appc / design / xinterface / XResponseProcessor.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * ================================================================================
9  * Modifications Copyright (C) 2019 Ericsson
10  * ================================================================================
11  * Modifications Copyright (c) 2019 IBM
12  * ================================================================================
13  * Licensed under the Apache License, Version 2.0 (the "License");
14  * you may not use this file except in compliance with the License.
15  * You may obtain a copy of the License at
16  *
17  *      http://www.apache.org/licenses/LICENSE-2.0
18  *
19  * Unless required by applicable law or agreed to in writing, software
20  * distributed under the License is distributed on an "AS IS" BASIS,
21  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22  * See the License for the specific language governing permissions and
23  * limitations under the License.
24  * ============LICENSE_END=========================================================
25  */
26
27 package org.onap.appc.design.xinterface;
28
29 import java.util.HashMap;
30 import org.onap.appc.design.services.util.DesignServiceConstants;
31 import org.onap.appc.instar.dme2client.Dme2Client;
32 import com.att.eelf.configuration.EELFLogger;
33 import com.att.eelf.configuration.EELFManager;
34 import com.fasterxml.jackson.databind.JsonNode;
35 import com.fasterxml.jackson.databind.ObjectMapper;
36
37 public class XResponseProcessor {
38
39     private final EELFLogger log = EELFManager.getInstance().getLogger(XInterfaceService.class);
40     private static final String EXCEPTION_WHILE_RECEIVING_DATA = "Exception occurred while receiving data";
41     Dme2Client dme2Client;
42
43     public static XResponseProcessor getInstance() {
44         return new XResponseProcessor();
45     }
46
47     public String parseResponse(String execute, String action) throws Exception {
48         ObjectMapper objectMapper = new ObjectMapper();
49         JsonNode payloadObject = objectMapper.readTree(execute);
50         log.info("payloadObject " + payloadObject);
51
52         // String queryParam = null;
53         String instarResponse = null;
54         HashMap<String, String> payload = null;
55         String ipAddress = null;
56         String mask = null;
57
58         try {
59
60             // check the payload whether its having ipaddr along with subnet
61             ipAddress = payloadObject.get(DesignServiceConstants.INSTAR_V4_ADDRESS) != null
62                     ? payloadObject.get(DesignServiceConstants.INSTAR_V4_ADDRESS).textValue()
63                     : (payloadObject.get(DesignServiceConstants.INSTAR_V6_ADDRESS) != null)
64                         ? payloadObject.get(DesignServiceConstants.INSTAR_V6_ADDRESS).textValue().toUpperCase()
65                         : null;
66
67             mask = payloadObject.get(DesignServiceConstants.INSTAR_V4_MASK) != null
68                     ? payloadObject.get(DesignServiceConstants.INSTAR_V4_MASK).textValue()
69
70                     : (payloadObject.get(DesignServiceConstants.INSTAR_V6_MASK) != null)
71                         ? payloadObject.get(DesignServiceConstants.INSTAR_V6_MASK).textValue().toUpperCase()
72                         : null;
73
74             // TODO -short format
75
76             /* if (mask != null) {
77              *     queryParam = ipAddress + "," + mask;
78              *     log.info("Calling Instar with IpAddress " + ipAddress + " Mask value: " + mask);
79              * } else {
80              *     queryParam = "ipAddress " + ipAddress;
81              *     log.info("Calling Instar with IpAddress " + ipAddress);
82              * }
83              */
84
85             payload = new HashMap<String, String>();
86             payload.put("ipAddress", ipAddress);
87             payload.put("mask", mask);
88             log.info("Calling Instar with IpAddress " + ipAddress + " Mask value: " + mask);
89             dme2Client = new Dme2Client("getVnfbyIpadress", "payload", payload);
90
91             instarResponse = dme2Client.send();
92
93             log.debug("Response from Instar = " + instarResponse);
94             if (instarResponse == null || instarResponse.length() < 0)
95                 throw new Exception("No Data received from Instar for this action " + action);
96         } catch (Exception e) {
97             log.error(EXCEPTION_WHILE_RECEIVING_DATA, e);
98             throw e;
99         }
100         return instarResponse;
101     }
102 }