2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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
17 * http://www.apache.org/licenses/LICENSE-2.0
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.
25 * ============LICENSE_END=========================================================
28 package org.onap.appc.design.xinterface;
30 import java.util.HashMap;
31 import org.onap.appc.design.services.util.DesignServiceConstants;
32 import org.onap.appc.instar.dme2client.Dme2Client;
33 import com.att.eelf.configuration.EELFLogger;
34 import com.att.eelf.configuration.EELFManager;
35 import com.fasterxml.jackson.databind.JsonNode;
36 import com.fasterxml.jackson.databind.ObjectMapper;
38 public class XResponseProcessor {
40 private final EELFLogger log = EELFManager.getInstance().getLogger(XInterfaceService.class);
41 private static final String EXCEPTION_WHILE_RECEIVING_DATA = "Exception occured while receiving data";
42 Dme2Client dme2Client;
44 public static XResponseProcessor getInstance() {
45 return new XResponseProcessor();
48 public String parseResponse(String execute, String action) throws Exception {
49 ObjectMapper objectMapper = new ObjectMapper();
50 JsonNode payloadObject = objectMapper.readTree(execute);
51 log.info("payloadObject " + payloadObject);
53 // String queryParam = null;
54 String instarResponse = null;
55 HashMap<String, String> payload = null;
56 String ipAddress = null;
61 // check the payload whether its having ipaddr along with subnet
62 ipAddress = payloadObject.get(DesignServiceConstants.INSTAR_V4_ADDRESS) != null
63 ? payloadObject.get(DesignServiceConstants.INSTAR_V4_ADDRESS).textValue()
64 : (payloadObject.get(DesignServiceConstants.INSTAR_V6_ADDRESS) != null)
65 ? payloadObject.get(DesignServiceConstants.INSTAR_V6_ADDRESS).textValue()
69 mask = payloadObject.get(DesignServiceConstants.INSTAR_V4_MASK) != null
70 ? payloadObject.get(DesignServiceConstants.INSTAR_V4_MASK).textValue()
71 : (payloadObject.get(DesignServiceConstants.INSTAR_V6_MASK) != null)
72 ? payloadObject.get(DesignServiceConstants.INSTAR_V6_MASK).textValue().toUpperCase()
78 * if (mask != null) { queryParam = ipAddress + "," +mask ;
79 * log.info("Calling Instar with IpAddress "+ ipAddress + " Mask value: "+ mask ); } else {
80 * queryParam = "ipAddress "+ipAddress ; log.info("Calling Instar with IpAddress "+
84 payload = new HashMap<String, String>();
85 payload.put("ipAddress", ipAddress);
86 payload.put("mask", mask);
87 log.info("Calling Instar with IpAddress " + ipAddress + " Mask value: " + mask);
88 dme2Client = new Dme2Client("getVnfbyIpadress", "payload", payload);
90 instarResponse = dme2Client.send();
92 log.debug("Resposne from Instar = " + instarResponse);
93 if (instarResponse == null || instarResponse.length() < 0)
94 throw new Exception("No Data received from Instar for this action " + action);
95 } catch (Exception e) {
96 log.error(EXCEPTION_WHILE_RECEIVING_DATA, e);
99 return instarResponse;