2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ============LICENSE_END=========================================================
24 package org.onap.appc.instar.interfaceImpl;
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
28 import org.json.JSONArray;
29 import org.json.JSONObject;
30 import org.onap.appc.instar.interfaces.ResponseHandlerInterface;
31 import org.onap.appc.instar.utils.InstarClientConstant;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
33 import org.onap.sdnc.config.params.data.ResponseKey;
35 public class InstarResponseHandlerImpl implements ResponseHandlerInterface {
37 private static final EELFLogger log = EELFManager.getInstance().getLogger(InstarResponseHandlerImpl.class);
39 private ResponseKey resKey = null;
40 private SvcLogicContext ctxt = null;
42 public InstarResponseHandlerImpl(ResponseKey filterKeys, SvcLogicContext context) {
43 this.resKey = filterKeys;
48 public Object processResponse(String instarResponse, String instarKey) {
49 String fn = " InstarResponseHandlerImpl.processResponse ";
50 log.info(fn + " Instar Response :" + instarResponse);
52 JSONObject instarKeyValues;
54 log.info("Instar Data in Context : " + ctxt.getAttribute(InstarClientConstant.INSTAR_KEY_VALUES));
55 if (ctxt.getAttribute(InstarClientConstant.INSTAR_KEY_VALUES) != null) {
56 instarKeyValues = new JSONObject(ctxt.getAttribute(InstarClientConstant.INSTAR_KEY_VALUES));
57 log.info("Instar data already exsits : " + instarKeyValues.toString());
59 instarKeyValues = new JSONObject();
61 JSONArray instarResponses = new JSONObject(instarResponse)
62 .getJSONArray(InstarClientConstant.INSTAR_RESPONSE_BLOCK_NAME);
63 for (int i = 0; i < instarResponses.length(); i++) {
64 JSONObject res = instarResponses.getJSONObject(i);
65 log.info(fn + "Instar Block :" + i + " Values :" + res.toString());
66 log.info(fn + "Appc Filter Key :" + ctxt.getAttribute(InstarClientConstant.VNF_NAME) + resKey
67 .getUniqueKeyValue());
69 if (hasValidFdqn(res)) {
70 switch (resKey.getFieldKeyName()) {
71 case InstarClientConstant.V4_ADDRESS:
72 instarKeyValues.put(instarKey, res.getString(InstarClientConstant.INSTAR_V4_ADDRESS));
74 case InstarClientConstant.INSTAR_V4_SUBNET:
75 instarKeyValues.put(instarKey, res.getString(InstarClientConstant.INSTAR_V4_SUBNET));
77 case InstarClientConstant.INSTAR_V4_DEFAULT_GATEWAY:
78 instarKeyValues.put(instarKey, res.getString(InstarClientConstant.INSTAR_V4_DEFAULT_GATEWAY));
80 case InstarClientConstant.V6_ADDRESS:
81 instarKeyValues.put(instarKey, res.getString(InstarClientConstant.INSTAR_V6_ADDRESS));
83 case InstarClientConstant.INSTAR_V6_SUBNET:
84 instarKeyValues.put(instarKey, res.getString(InstarClientConstant.INSTAR_V6_SUBNET));
86 case InstarClientConstant.INSTAR_V6_DEFAULT_GATEWAY:
87 instarKeyValues.put(instarKey, res.getString(InstarClientConstant.INSTAR_V6_DEFAULT_GATEWAY));
95 log.info(fn + "Instar KeyValues :" + instarKeyValues);
96 ctxt.setAttribute(InstarClientConstant.INSTAR_KEY_VALUES, instarKeyValues.toString());
98 return instarKeyValues;
101 private boolean hasValidFdqn(JSONObject res) {
102 return res.getString(InstarClientConstant.FDQN) != null &&
103 res.getString(InstarClientConstant.FDQN)
104 .equalsIgnoreCase(ctxt.getAttribute(InstarClientConstant.VNF_NAME) + resKey.getUniqueKeyValue());