2 * ============LICENSE_START=======================================================
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
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.
24 * ============LICENSE_END=========================================================
27 package org.onap.appc.design.xinterface;
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;
37 public class XResponseProcessor {
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;
43 public static XResponseProcessor getInstance() {
44 return new XResponseProcessor();
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);
52 // String queryParam = null;
53 String instarResponse = null;
54 HashMap<String, String> payload = null;
55 String ipAddress = null;
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()
67 mask = payloadObject.get(DesignServiceConstants.INSTAR_V4_MASK) != null
68 ? payloadObject.get(DesignServiceConstants.INSTAR_V4_MASK).textValue()
70 : (payloadObject.get(DesignServiceConstants.INSTAR_V6_MASK) != null)
71 ? payloadObject.get(DesignServiceConstants.INSTAR_V6_MASK).textValue().toUpperCase()
76 /* if (mask != null) {
77 * queryParam = ipAddress + "," + mask;
78 * log.info("Calling Instar with IpAddress " + ipAddress + " Mask value: " + mask);
80 * queryParam = "ipAddress " + ipAddress;
81 * log.info("Calling Instar with IpAddress " + ipAddress);
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);
91 instarResponse = dme2Client.send();
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);
100 return instarResponse;