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.aai.interfaceImpl;
27 import java.util.ArrayList;
28 import java.util.List;
30 import org.apache.commons.lang.StringUtils;
31 import org.json.JSONObject;
32 import org.onap.appc.aai.data.AaiVmInfo;
33 import org.onap.appc.aai.data.AaiVnfInfo;
34 import org.onap.appc.aai.data.AaiVnfcInfo;
35 import org.onap.appc.instar.interfaces.RuleHandlerInterface;
36 import org.onap.appc.aai.utils.AaiClientConstant;
37 import org.onap.sdnc.config.params.data.Parameter;
38 import org.onap.sdnc.config.params.data.ResponseKey;
39 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
41 import com.att.eelf.configuration.EELFLogger;
42 import com.att.eelf.configuration.EELFManager;
44 public class AaiInterfaceRulesHandler implements RuleHandlerInterface {
46 private static final EELFLogger log = EELFManager.getInstance().getLogger(AaiInterfaceRulesHandler.class);
47 private Parameter parameters;
48 private SvcLogicContext context;
49 private AaiVnfInfo vnfInfoData;
51 public AaiInterfaceRulesHandler(Parameter params, SvcLogicContext ctx) {
52 this.parameters = params;
54 this.setVnfInfoData(generateAaiVnfInfoData());
58 public void processRule() throws Exception {
60 String fn = "AaiInterfaceIpAddressHandler.processRule";
61 log.info(fn + "Processing rule :" + parameters.getRuleType());
62 List<ResponseKey> responseKeyList = parameters.getResponseKeys();
63 ResponseKey respKeys = new ResponseKey();
64 if (responseKeyList != null && responseKeyList.size() > 0) {
65 for (ResponseKey filterKeys : responseKeyList) {
66 if (null != filterKeys) {
67 if (StringUtils.isNotBlank(filterKeys.getUniqueKeyName()))
68 respKeys.setUniqueKeyName(filterKeys.getUniqueKeyName());
69 if (StringUtils.isNotBlank(filterKeys.getUniqueKeyValue()))
70 respKeys.setUniqueKeyValue(filterKeys.getUniqueKeyValue());
71 if (StringUtils.isNotBlank(filterKeys.getFieldKeyName()))
72 respKeys.setFieldKeyName(filterKeys.getFieldKeyName());
73 if (StringUtils.isNotBlank(filterKeys.getFilterByField()))
74 respKeys.setFilterByField(filterKeys.getFilterByField());
75 if (StringUtils.isNotBlank(filterKeys.getFilterByValue()))
76 respKeys.setFilterByValue(filterKeys.getFilterByValue());
80 throw new Exception("NO response Keys set for : " + parameters.getRuleType());
82 processKeys(respKeys, parameters.getName());
85 public void processKeys(ResponseKey filterKey, String aaiKey) throws Exception {
87 String fn = "AaiInterfaceRulesHandler.processKeys()::";
88 log.info(fn + "processing for " + aaiKey);
89 String values = new String();
90 JSONObject aaiKeyValues = null;
91 log.info("Aai Data in Context : " + context.getAttribute(AaiClientConstant.AAI_KEY_VALUES));
92 if (context.getAttribute(AaiClientConstant.AAI_KEY_VALUES) != null) {
93 aaiKeyValues = new JSONObject(context.getAttribute(AaiClientConstant.AAI_KEY_VALUES));
94 log.info("Aai data already exsits : " + aaiKeyValues.toString());
96 aaiKeyValues = new JSONObject();
99 if (StringUtils.equalsIgnoreCase(filterKey.getUniqueKeyValue(), "vnf")) {
100 values = getVnfDetailsFromContext(filterKey.getFieldKeyName());
103 if (StringUtils.equalsIgnoreCase(filterKey.getUniqueKeyValue(), "vnfc")) {
104 values = getVnfcDetailsFromContext(filterKey.getFieldKeyName(), filterKey.getFilterByField(),
105 filterKey.getFilterByValue());
107 if (StringUtils.equalsIgnoreCase(filterKey.getUniqueKeyValue(), "vserver")) {
108 values = getVServerDetailsFromContext(filterKey.getFieldKeyName(), filterKey.getFilterByField(),
109 filterKey.getFilterByValue());
111 aaiKeyValues.put(aaiKey, values);
112 context.setAttribute(AaiClientConstant.AAI_KEY_VALUES, aaiKeyValues.toString());
116 private String getVServerDetailsFromContext(String fieldKeyName, String filterByField, String filterByValue) {
117 String fn = "AaiInterfaceRulesHander::getVServerDetailsFromContext():";
119 log.info(fn + "FieldKeyName:" + fieldKeyName + " FilterByName:" + filterByField + " FilterByValue:"
121 if (StringUtils.equalsIgnoreCase(fieldKeyName, "vserver-name")) {
122 if (StringUtils.isNotEmpty(filterByField) && StringUtils.isNotEmpty(filterByField)
123 && StringUtils.isNotEmpty(filterByValue) && StringUtils.isNotEmpty(filterByValue)) {
125 for (AaiVmInfo vm : vnfInfoData.getVmInfo()) {
126 if (StringUtils.equalsIgnoreCase(filterByField, "vm-number") && null != filterByValue) {
127 int vmNumber = Integer.parseInt(filterByValue);
128 if (vmNumber == vmIndex) {
129 if (StringUtils.isBlank(values))
130 values = vm.getVserverName();
132 values = values + "," + vm.getVserverName();
138 for (AaiVmInfo vm : vnfInfoData.getVmInfo()) {
139 if (StringUtils.isBlank(values))
140 values = vm.getVserverName();
142 values = values + "," + vm.getVserverName();
146 log.info(fn + "Returning values:" + values);
151 private String getVnfcDetailsFromContext(String fieldKeyName, String filterByField, String filterByValue) {
152 String fn = "AaiInterfaceRulesHander::getVnfcDetailsFromContext()";
154 log.info(fn + "FieldKeyName:" + fieldKeyName + " FilterByField:" + filterByField + " FilterByValue:"
156 if (StringUtils.equalsIgnoreCase(fieldKeyName, "ipaddress-v4-oam-vip")) {
157 if (StringUtils.isNotEmpty(filterByField) && StringUtils.isNotEmpty(filterByValue)) {
158 for (AaiVmInfo vm : vnfInfoData.getVmInfo()) {
159 for (AaiVnfcInfo vnfcInfo : vm.getVnfcInfo()) {
160 if (StringUtils.equalsIgnoreCase(filterByField, "vnfc-function-code")
161 && StringUtils.equalsIgnoreCase(filterByValue, vnfcInfo.getVnfcFunctionCode()))
162 if (StringUtils.isBlank(values))
163 values = vnfcInfo.getVnfcOamIpAddress();
165 values = values + "," + vnfcInfo.getVnfcOamIpAddress();
170 for (AaiVmInfo vm : vnfInfoData.getVmInfo()) {
171 for (AaiVnfcInfo vnfcInfo : vm.getVnfcInfo()) {
172 if (StringUtils.isBlank(values))
173 values = vnfcInfo.getVnfcOamIpAddress();
175 values = values + "," + vnfcInfo.getVnfcOamIpAddress();
181 if (StringUtils.equalsIgnoreCase(fieldKeyName, "vnfc-name")) {
182 if (StringUtils.isNotBlank(filterByField) && StringUtils.isNotBlank(filterByValue)) {
183 for (AaiVmInfo vm : vnfInfoData.getVmInfo()) {
184 for (AaiVnfcInfo vnfcInfo : vm.getVnfcInfo()) {
185 if (StringUtils.equalsIgnoreCase(filterByField, "vnfc-function-code")
186 && StringUtils.equalsIgnoreCase(filterByValue, vnfcInfo.getVnfcFunctionCode()))
187 if (StringUtils.isBlank(values))
188 values = vnfcInfo.getVnfcName();
190 values = values + "," + vnfcInfo.getVnfcName();
195 for (AaiVmInfo vm : vnfInfoData.getVmInfo()) {
196 for (AaiVnfcInfo vnfcInfo : vm.getVnfcInfo()) {
197 if (StringUtils.isBlank(values))
198 values = vnfcInfo.getVnfcName();
200 values = values + "," + vnfcInfo.getVnfcName();
206 log.info(fn + "Returning values:" + values);
211 private String getVnfDetailsFromContext(String fieldKeyName) {
213 log.info("getVnfDetailsFromContext::" + fieldKeyName);
215 if (StringUtils.equalsIgnoreCase(fieldKeyName, "vnf-name")) {
216 String vnfName = context.getAttribute("tmp.vnfInfo.vnf.vnf-name");
219 if (StringUtils.equalsIgnoreCase(fieldKeyName, "ipv4-oam-ipaddress")) {
220 String ipv4OamAddress = context.getAttribute("tmp.vnfInfo.vnf.ipv4-oam-address");
221 values = ipv4OamAddress;
226 public AaiVnfInfo getVnfInfoData() {
230 public void setVnfInfoData(AaiVnfInfo vnfInfoData) {
231 this.vnfInfoData = vnfInfoData;
234 public AaiVnfInfo generateAaiVnfInfoData() {
236 log.info("AaiInterfaceRulesHandlerImpl:generateAaiVnfInfoData(): Printing variables in context");
237 for (Object key : context.getAttributeKeySet()) {
238 String parmName = (String) key;
239 String parmValue = context.getAttribute(parmName);
240 log.debug("generateAaiVnfInfoData():: " + parmName + "=" + parmValue);
244 String vmcount = context.getAttribute("tmp.vnfInfo.vm-count");
246 if (!StringUtils.isBlank(vmcount))
247 vmCount = Integer.parseInt(vmcount);
248 log.info("generateAaiVnfInfoData::" + "vmCount:" + vmCount);
249 AaiVnfInfo vnfInfo = new AaiVnfInfo();
250 vnfInfo.setVnfName("vnf-name");
251 ArrayList<AaiVmInfo> vmList = new ArrayList<AaiVmInfo>();
253 for (int i = 0; i < vmCount; i++) {
254 AaiVmInfo vm = new AaiVmInfo();
255 String vnfcCountStr = context.getAttribute("tmp.vnfInfo.vm[" + i + "].vnfc-count");
256 int vnfcCount = Integer.parseInt(vnfcCountStr);
257 ArrayList<AaiVnfcInfo> vnfcInfoList = new ArrayList<AaiVnfcInfo>();
258 for (int j = 0; j < vnfcCount; j++) {
259 AaiVnfcInfo vnfcInfo = new AaiVnfcInfo();
260 vnfcInfo.setVnfcName(context.getAttribute("tmp.vnfInfo.vm[" + i + "].vnfc-name"));
261 vnfcInfo.setVnfcFunctionCode(context.getAttribute("tmp.vnfInfo.vm[" + i + "].vnfc-function-code"));
262 vnfcInfo.setVnfcOamIpAddress(
263 context.getAttribute("tmp.vnfInfo.vm[" + i + "].vnfc-ipaddress-v4-oam-vip"));
264 vnfcInfoList.add(vnfcInfo);
266 vm.setVnfcInfo(vnfcInfoList);
267 vm.setVserverId(context.getAttribute("tmp.vnfInfo.vm[" + i + "].vserver-id"));
268 vm.setVserverName(context.getAttribute("tmp.vnfInfo.vm[" + i + "].vserver-name"));
271 vnfInfo.setVmInfo(vmList);