2 * ============LICENSE_START=======================================================
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
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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.instar.interfaceImpl;
27 import com.att.eelf.configuration.EELFLogger;
28 import com.att.eelf.configuration.EELFManager;
29 import org.json.JSONArray;
30 import org.json.JSONObject;
31 import org.onap.appc.instar.interfaces.ResponseHandlerInterface;
32 import org.onap.appc.instar.utils.InstarClientConstant;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
34 import org.onap.sdnc.config.params.data.ResponseKey;
36 public class InstarResponseHandlerImpl implements ResponseHandlerInterface {
38 private static final EELFLogger log = EELFManager.getInstance().getLogger(InstarResponseHandlerImpl.class);
40 ResponseKey resKey = null;
41 SvcLogicContext ctxt = null;
43 public InstarResponseHandlerImpl(ResponseKey filterKeys, SvcLogicContext context) {
44 this.resKey = filterKeys;
50 public Object processResponse(String instarResponse, String instarKey) {
51 String fn = " InstarResponseHandlerImpl.processResponse ";
52 log.info(fn + " Instar Response :" + instarResponse);
54 JSONObject instarKeyValues;
56 log.info("Instar Data in Context : " + ctxt.getAttribute(InstarClientConstant.INSTAR_KEY_VALUES));
57 if (ctxt.getAttribute(InstarClientConstant.INSTAR_KEY_VALUES) != null) {
58 instarKeyValues = new JSONObject(ctxt.getAttribute(InstarClientConstant.INSTAR_KEY_VALUES));
59 log.info("Instar data already exsits : " + instarKeyValues.toString());
61 instarKeyValues = new JSONObject();
63 JSONArray instarResponses = new JSONObject(instarResponse)
64 .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
69 .getUniqueKeyValue());
71 if (res.getString(InstarClientConstant.FDQN) != null &&
72 res.getString(InstarClientConstant.FDQN)
73 .equalsIgnoreCase(ctxt.getAttribute(InstarClientConstant.VNF_NAME) + resKey.getUniqueKeyValue())) {
74 if (resKey.getFieldKeyName().equals(InstarClientConstant.V4_ADDRESS)) {
75 instarKeyValues.put(instarKey, res.getString(InstarClientConstant.INSTAR_V4_ADDRESS));
76 } else if (resKey.getFieldKeyName().equals(InstarClientConstant.INSTAR_V4_SUBNET)) {
77 instarKeyValues.put(instarKey, res.getString(InstarClientConstant.INSTAR_V4_SUBNET));
78 } else if (resKey.getFieldKeyName().equals(InstarClientConstant.INSTAR_V4_DEFAULT_GATEWAY)) {
79 instarKeyValues.put(instarKey, res.getString(InstarClientConstant.INSTAR_V4_DEFAULT_GATEWAY));
80 } else if (resKey.getFieldKeyName().equals(InstarClientConstant.V6_ADDRESS)) {
81 instarKeyValues.put(instarKey, res.getString(InstarClientConstant.INSTAR_V6_ADDRESS));
82 } else if (resKey.getFieldKeyName().equals(InstarClientConstant.INSTAR_V6_SUBNET)) {
83 instarKeyValues.put(instarKey, res.getString(InstarClientConstant.INSTAR_V6_SUBNET));
84 } else if (resKey.getFieldKeyName().equals(InstarClientConstant.INSTAR_V6_DEFAULT_GATEWAY)) {
85 instarKeyValues.put(instarKey, res.getString(InstarClientConstant.INSTAR_V6_DEFAULT_GATEWAY));
90 log.info(fn + "Instar KeyValues :" + instarKeyValues);
91 ctxt.setAttribute(InstarClientConstant.INSTAR_KEY_VALUES, instarKeyValues.toString());
93 return instarKeyValues;