b1bf785d551aafab212076af63ed44d2e404529a
[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 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.appc.design.xinterface;
26
27 import java.util.HashMap;
28
29 import org.onap.appc.design.services.util.DesignServiceConstants;
30 import org.onap.appc.instar.dme2client.Dme2Client;
31
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     Dme2Client dme2Client;
41
42     public String parseResponse(String execute, String action) throws Exception {
43         ObjectMapper objectMapper = new ObjectMapper();
44         JsonNode payloadObject = objectMapper.readTree(execute);
45         log.info("payloadObject " + payloadObject);
46
47         //String queryParam = null;
48         String instarResponse = null;
49         HashMap<String, String> payload = null;
50         String ipAddress = null;
51         String mask = null;
52
53         try {
54
55             // check the payload whether its having ipaddr along with subnet
56             ipAddress = payloadObject.get(DesignServiceConstants.INSTAR_V4_ADDRESS) != null
57                     ? payloadObject.get(DesignServiceConstants.INSTAR_V4_ADDRESS).textValue()
58                     : (payloadObject.get(DesignServiceConstants.INSTAR_V6_ADDRESS) !=null)
59                         ?payloadObject.get(DesignServiceConstants.INSTAR_V6_ADDRESS).textValue().toUpperCase()
60                                 :null;
61
62             mask = payloadObject.get(DesignServiceConstants.INSTAR_V4_MASK) != null
63                     ? payloadObject.get(DesignServiceConstants.INSTAR_V4_MASK).textValue()
64                     : (payloadObject.get(DesignServiceConstants.INSTAR_V6_MASK) != null)
65                             ? payloadObject.get(DesignServiceConstants.INSTAR_V6_MASK).textValue().toUpperCase()
66                             : null;
67
68             // TODO -short format
69
70             /*if (mask != null) {
71                 queryParam = ipAddress + "," +mask ;
72                 log.info("Calling Instar with IpAddress "+ ipAddress + " Mask value: "+ mask );
73             } else {
74                 queryParam = "ipAddress "+ipAddress ;
75                 log.info("Calling Instar with IpAddress "+ ipAddress);
76             }*/
77
78             payload = new HashMap<String, String>();
79             payload.put("ipAddress", ipAddress);
80             payload.put("mask", mask);
81             log.info("Calling Instar with IpAddress "+ ipAddress + " Mask value: "+ mask );
82             dme2Client = new Dme2Client("getVnfbyIpadress", "payload", payload);
83
84             instarResponse = dme2Client.send();
85
86             log.debug("Resposne from Instar = " + instarResponse);
87             if (instarResponse == null || instarResponse.length() < 0)
88                 throw new Exception("No Data received from Instar for this action " + action);
89         } catch (Exception e) {
90             e.printStackTrace();
91             throw e;
92         }
93         return instarResponse;
94     }
95 }