c556e9ce99fcc8952b6a8a3d3eebebae5f64ff7f
[appc.git] /
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.instar.interfaceImpl;
26
27 import org.json.JSONArray;
28 import org.json.JSONObject;
29 import org.onap.appc.instar.interfaces.ResponseHandlerInterface;
30 import org.onap.appc.instar.utils.InstarClientConstant;
31 import org.onap.sdnc.config.params.data.ResponseKey;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
33
34 import com.att.eelf.configuration.EELFLogger;
35 import com.att.eelf.configuration.EELFManager;
36
37 public class InstarResponseHandlerImpl implements ResponseHandlerInterface {
38
39     private static final EELFLogger log = EELFManager.getInstance().getLogger(InstarResponseHandlerImpl.class);
40
41     ResponseKey resKey = null;
42     SvcLogicContext ctxt = null;
43
44     public InstarResponseHandlerImpl(ResponseKey filterKeys, SvcLogicContext context) {
45         this.resKey = filterKeys;
46         this.ctxt = context;
47
48     }
49
50     @Override
51     public Object processResponse(String instarResponse, String instarKey) {
52         String fn = " InstarResponseHandlerImpl.processResponse ";
53         log.info(fn + " Instar Response :" + instarResponse);
54
55         JSONObject instarKeyValues;
56
57         log.info("Instar Data in Context : "+ ctxt.getAttribute(InstarClientConstant.INSTAR_KEY_VALUES));
58         if(ctxt.getAttribute(InstarClientConstant.INSTAR_KEY_VALUES) != null){
59             instarKeyValues = new JSONObject(ctxt.getAttribute(InstarClientConstant.INSTAR_KEY_VALUES));
60             log.info("Instar data already exsits :  " + instarKeyValues.toString());
61         }
62         else
63             instarKeyValues = new JSONObject();
64         JSONArray instarResponses = new JSONObject(instarResponse).getJSONArray(InstarClientConstant.INSTAR_RESPONSE_BLOCK_NAME);
65         for (int i = 0; i < instarResponses.length(); i++){
66             JSONObject res = instarResponses.getJSONObject(i);
67             log.info(fn + "Instar Block :" + i + " Values :" +  res.toString());
68             log.info(fn + "Appc Filter Key :"  +  ctxt.getAttribute(InstarClientConstant.VNF_NAME) + resKey.getUniqueKeyValue());
69
70             if(res.getString(InstarClientConstant.FDQN) != null &&
71                     res.getString(InstarClientConstant.FDQN).equalsIgnoreCase(ctxt.getAttribute(InstarClientConstant.VNF_NAME) + resKey.getUniqueKeyValue())) {
72                     if(resKey.getFieldKeyName().equals(InstarClientConstant.V4_ADDRESS)) {
73                         instarKeyValues.put(instarKey, res.getString(InstarClientConstant.INSTAR_V4_ADDRESS));
74                     }
75                     else if (resKey.getFieldKeyName().equals(InstarClientConstant.INSTAR_V4_SUBNET)) {
76                         instarKeyValues.put(instarKey, res.getString(InstarClientConstant.INSTAR_V4_SUBNET) );
77                     }
78                     else if (resKey.getFieldKeyName().equals(InstarClientConstant.INSTAR_V4_DEFAULT_GATEWAY)) {
79                         instarKeyValues.put(instarKey, res.getString(InstarClientConstant.INSTAR_V4_DEFAULT_GATEWAY));
80                     }
81                     else if(resKey.getFieldKeyName().equals(InstarClientConstant.V6_ADDRESS)) {
82                         instarKeyValues.put(instarKey, res.getString(InstarClientConstant.INSTAR_V6_ADDRESS));
83                     }
84                     else if (resKey.getFieldKeyName().equals(InstarClientConstant.INSTAR_V6_SUBNET)) {
85                         instarKeyValues.put(instarKey, res.getString(InstarClientConstant.INSTAR_V6_SUBNET) );
86                     }
87                     else if (resKey.getFieldKeyName().equals(InstarClientConstant.INSTAR_V6_DEFAULT_GATEWAY)) {
88                         instarKeyValues.put(instarKey, res.getString(InstarClientConstant.INSTAR_V6_DEFAULT_GATEWAY));
89                     }
90                     break;
91             }
92         }
93         log.info(fn + "Instar KeyValues  :" + instarKeyValues);
94         ctxt.setAttribute(InstarClientConstant.INSTAR_KEY_VALUES, instarKeyValues.toString());
95
96
97         return instarKeyValues;
98     }
99
100 }