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 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.appc.design.xinterface;
28 import java.util.HashMap;
29 import org.onap.appc.design.services.util.DesignServiceConstants;
30 import org.onap.appc.instar.dme2client.Dme2Client;
31 import com.att.eelf.configuration.EELFLogger;
32 import com.att.eelf.configuration.EELFManager;
33 import com.fasterxml.jackson.databind.JsonNode;
34 import com.fasterxml.jackson.databind.ObjectMapper;
36 public class XResponseProcessor {
38 private final EELFLogger log = EELFManager.getInstance().getLogger(XInterfaceService.class);
39 Dme2Client dme2Client;
41 public static XResponseProcessor getInstance() {
42 return new XResponseProcessor();
45 public String parseResponse(String execute, String action) throws Exception {
46 ObjectMapper objectMapper = new ObjectMapper();
47 JsonNode payloadObject = objectMapper.readTree(execute);
48 log.info("payloadObject " + payloadObject);
50 // String queryParam = null;
51 String instarResponse = null;
52 HashMap<String, String> payload = null;
53 String ipAddress = null;
58 // check the payload whether its having ipaddr along with subnet
59 ipAddress = payloadObject.get(DesignServiceConstants.INSTAR_V4_ADDRESS) != null
60 ? payloadObject.get(DesignServiceConstants.INSTAR_V4_ADDRESS).textValue()
61 : (payloadObject.get(DesignServiceConstants.INSTAR_V6_ADDRESS) != null)
62 ? payloadObject.get(DesignServiceConstants.INSTAR_V6_ADDRESS).textValue()
66 mask = payloadObject.get(DesignServiceConstants.INSTAR_V4_MASK) != null
67 ? payloadObject.get(DesignServiceConstants.INSTAR_V4_MASK).textValue()
68 : (payloadObject.get(DesignServiceConstants.INSTAR_V6_MASK) != null)
69 ? payloadObject.get(DesignServiceConstants.INSTAR_V6_MASK).textValue().toUpperCase()
75 * if (mask != null) { queryParam = ipAddress + "," +mask ;
76 * log.info("Calling Instar with IpAddress "+ ipAddress + " Mask value: "+ mask ); } else {
77 * queryParam = "ipAddress "+ipAddress ; log.info("Calling Instar with IpAddress "+
81 payload = new HashMap<String, String>();
82 payload.put("ipAddress", ipAddress);
83 payload.put("mask", mask);
84 log.info("Calling Instar with IpAddress " + ipAddress + " Mask value: " + mask);
85 dme2Client = new Dme2Client("getVnfbyIpadress", "payload", payload);
87 instarResponse = dme2Client.send();
89 log.debug("Resposne from Instar = " + instarResponse);
90 if (instarResponse == null || instarResponse.length() < 0)
91 throw new Exception("No Data received from Instar for this action " + action);
92 } catch (Exception e) {
96 return instarResponse;