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 IllegalStateException {
60 String fn = "AaiInterfaceIpAddressHandler.processRule";
61 log.info(fn + "Processing rule :" + parameters.getRuleType());
62 List<ResponseKey> responseKeyList = parameters.getResponseKeys();
63 ResponseKey respKeys = new ResponseKey();
65 if (responseKeyList == null || responseKeyList.isEmpty()) {
66 throw new IllegalStateException("NO response Keys set for : " + parameters.getRuleType());
69 for (ResponseKey filterKeys : responseKeyList) {
71 if (null == filterKeys)
74 if (StringUtils.isNotBlank(filterKeys.getUniqueKeyName()))
75 respKeys.setUniqueKeyName(filterKeys.getUniqueKeyName());
76 if (StringUtils.isNotBlank(filterKeys.getUniqueKeyValue()))
77 respKeys.setUniqueKeyValue(filterKeys.getUniqueKeyValue());
78 if (StringUtils.isNotBlank(filterKeys.getFieldKeyName()))
79 respKeys.setFieldKeyName(filterKeys.getFieldKeyName());
80 if (StringUtils.isNotBlank(filterKeys.getFilterByField()))
81 respKeys.setFilterByField(filterKeys.getFilterByField());
82 if (StringUtils.isNotBlank(filterKeys.getFilterByValue()))
83 respKeys.setFilterByValue(filterKeys.getFilterByValue());
86 processKeys(respKeys, parameters.getName());
89 public void processKeys(ResponseKey filterKey, String aaiKey) {
91 String fn = "AaiInterfaceRulesHandler.processKeys()::";
92 log.info(fn + "processing for " + aaiKey);
93 String values = new String();
94 JSONObject aaiKeyValues = null;
95 log.info("Aai Data in Context : " + context.getAttribute(AaiClientConstant.AAI_KEY_VALUES));
96 if (context.getAttribute(AaiClientConstant.AAI_KEY_VALUES) != null) {
97 aaiKeyValues = new JSONObject(context.getAttribute(AaiClientConstant.AAI_KEY_VALUES));
98 log.info("Aai data already exsits : " + aaiKeyValues.toString());
100 aaiKeyValues = new JSONObject();
103 if (StringUtils.equalsIgnoreCase(filterKey.getUniqueKeyValue(), "vnf")) {
104 values = getVnfDetailsFromContext(filterKey.getFieldKeyName());
107 if (StringUtils.equalsIgnoreCase(filterKey.getUniqueKeyValue(), "vnfc")) {
108 values = getVnfcDetailsFromContext(filterKey.getFieldKeyName(), filterKey.getFilterByField(),
109 filterKey.getFilterByValue());
111 if (StringUtils.equalsIgnoreCase(filterKey.getUniqueKeyValue(), "vserver")) {
112 values = getVServerDetailsFromContext(filterKey.getFieldKeyName(), filterKey.getFilterByField(),
113 filterKey.getFilterByValue());
115 aaiKeyValues.put(aaiKey, values);
116 context.setAttribute(AaiClientConstant.AAI_KEY_VALUES, aaiKeyValues.toString());
120 private String getVServerDetailsFromContext(String fieldKeyName, String filterByField, String filterByValue) {
121 String fn = "AaiInterfaceRulesHander::getVServerDetailsFromContext():";
123 log.info(fn + "FieldKeyName:" + fieldKeyName + " FilterByName:" + filterByField + " FilterByValue:"
126 if (!StringUtils.equalsIgnoreCase(fieldKeyName, "vserver-name")) {
127 log.info(fn + "Returning values:" + values);
131 if (StringUtils.isNotEmpty(filterByField)
132 && StringUtils.isNotEmpty(filterByValue) ) {
134 for (AaiVmInfo vm : vnfInfoData.getVmInfo()) {
137 if (!StringUtils.equalsIgnoreCase(filterByField, "vm-number"))
140 int vmNumber = Integer.parseInt(filterByValue);
141 if (vmNumber != vmIndex)
144 if (StringUtils.isBlank(values))
145 values = vm.getVserverName();
147 values = values + "," + vm.getVserverName();
150 for (AaiVmInfo vm : vnfInfoData.getVmInfo()) {
151 if (StringUtils.isBlank(values))
152 values = vm.getVserverName();
154 values = values + "," + vm.getVserverName();
158 log.info(fn + "Returning values:" + values);
163 //split from getVnfcDetailsFromContext
164 private String add2ValuesIpaddressV4OamVipNotEmpty(String values, String filterByField, String filterByValue )
166 for (AaiVmInfo vm : vnfInfoData.getVmInfo()) {
167 for (AaiVnfcInfo vnfcInfo : vm.getVnfcInfo()) {
168 if (!StringUtils.equalsIgnoreCase(filterByField, "vnfc-function-code")
169 || !StringUtils.equalsIgnoreCase(filterByValue, vnfcInfo.getVnfcFunctionCode()))
172 if (StringUtils.isBlank(values))
173 values = vnfcInfo.getVnfcOamIpAddress();
175 values = values + "," + vnfcInfo.getVnfcOamIpAddress();
183 //split from getVnfcDetailsFromContext
184 private String add2ValuesIpaddressV4OamVipEmpty(String values, String filterByField, String filterByValue )
186 for (AaiVmInfo vm : vnfInfoData.getVmInfo()) {
187 for (AaiVnfcInfo vnfcInfo : vm.getVnfcInfo()) {
188 if (StringUtils.isBlank(values))
189 values = vnfcInfo.getVnfcOamIpAddress();
191 values = values + "," + vnfcInfo.getVnfcOamIpAddress();
198 //split from getVnfcDetailsFromContext
199 private String add2ValuesVnfcNameNotEmpty(String values, String filterByField, String filterByValue )
201 for (AaiVmInfo vm : vnfInfoData.getVmInfo()) {
202 for (AaiVnfcInfo vnfcInfo : vm.getVnfcInfo()) {
203 if (!StringUtils.equalsIgnoreCase(filterByField, "vnfc-function-code")
204 || !StringUtils.equalsIgnoreCase(filterByValue, vnfcInfo.getVnfcFunctionCode()))
207 if (StringUtils.isBlank(values))
208 values = vnfcInfo.getVnfcName();
210 values = values + "," + vnfcInfo.getVnfcName();
218 //split from getVnfcDetailsFromContext
219 private String add2ValuesVnfcNameEmpty(String values, String filterByField, String filterByValue )
221 for (AaiVmInfo vm : vnfInfoData.getVmInfo()) {
222 for (AaiVnfcInfo vnfcInfo : vm.getVnfcInfo()) {
223 if (StringUtils.isBlank(values))
224 values = vnfcInfo.getVnfcName();
226 values = values + "," + vnfcInfo.getVnfcName();
233 private String getVnfcDetailsFromContext(String fieldKeyName, String filterByField, String filterByValue) {
234 String fn = "AaiInterfaceRulesHander::getVnfcDetailsFromContext()";
236 log.info(fn + "FieldKeyName:" + fieldKeyName + " FilterByField:" + filterByField + " FilterByValue:"
238 if (StringUtils.equalsIgnoreCase(fieldKeyName, "ipaddress-v4-oam-vip")) {
239 if (StringUtils.isNotEmpty(filterByField) && StringUtils.isNotEmpty(filterByValue)) {
240 values = add2ValuesIpaddressV4OamVipNotEmpty(values, filterByField, filterByValue);
242 values = add2ValuesIpaddressV4OamVipEmpty(values, filterByField, filterByValue);
245 if (StringUtils.equalsIgnoreCase(fieldKeyName, "vnfc-name")) {
246 if (StringUtils.isNotBlank(filterByField) && StringUtils.isNotBlank(filterByValue)) {
247 values = add2ValuesVnfcNameNotEmpty(values, filterByField, filterByValue);
249 values = add2ValuesVnfcNameEmpty(values, filterByField, filterByValue);
252 log.info(fn + "Returning values:" + values);
257 private String getVnfDetailsFromContext(String fieldKeyName) {
259 log.info("getVnfDetailsFromContext::" + fieldKeyName);
261 if (StringUtils.equalsIgnoreCase(fieldKeyName, "vnf-name")) {
262 String vnfName = context.getAttribute("tmp.vnfInfo.vnf.vnf-name");
265 if (StringUtils.equalsIgnoreCase(fieldKeyName, "ipv4-oam-ipaddress")) {
266 String ipv4OamAddress = context.getAttribute("tmp.vnfInfo.vnf.ipv4-oam-address");
267 values = ipv4OamAddress;
272 public AaiVnfInfo getVnfInfoData() {
276 public void setVnfInfoData(AaiVnfInfo vnfInfoData) {
277 this.vnfInfoData = vnfInfoData;
280 public AaiVnfInfo generateAaiVnfInfoData() {
282 log.info("AaiInterfaceRulesHandlerImpl:generateAaiVnfInfoData(): Printing variables in context");
283 for (Object key : context.getAttributeKeySet()) {
284 String parmName = (String) key;
285 String parmValue = context.getAttribute(parmName);
286 log.debug("generateAaiVnfInfoData():: " + parmName + "=" + parmValue);
290 String vmcount = context.getAttribute("tmp.vnfInfo.vm-count");
292 if (!StringUtils.isBlank(vmcount))
293 vmCount = Integer.parseInt(vmcount);
294 log.info("generateAaiVnfInfoData::" + "vmCount:" + vmCount);
295 AaiVnfInfo vnfInfo = new AaiVnfInfo();
296 vnfInfo.setVnfName("vnf-name");
297 ArrayList<AaiVmInfo> vmList = new ArrayList<AaiVmInfo>();
299 for (int i = 0; i < vmCount; i++) {
300 AaiVmInfo vm = new AaiVmInfo();
301 String vnfcCountStr = context.getAttribute("tmp.vnfInfo.vm[" + i + "].vnfc-count");
302 int vnfcCount = Integer.parseInt(vnfcCountStr);
303 ArrayList<AaiVnfcInfo> vnfcInfoList = new ArrayList<AaiVnfcInfo>();
304 for (int j = 0; j < vnfcCount; j++) {
305 AaiVnfcInfo vnfcInfo = new AaiVnfcInfo();
306 vnfcInfo.setVnfcName(context.getAttribute("tmp.vnfInfo.vm[" + i + "].vnfc-name"));
307 vnfcInfo.setVnfcFunctionCode(context.getAttribute("tmp.vnfInfo.vm[" + i + "].vnfc-function-code"));
308 vnfcInfo.setVnfcOamIpAddress(
309 context.getAttribute("tmp.vnfInfo.vm[" + i + "].vnfc-ipaddress-v4-oam-vip"));
310 vnfcInfoList.add(vnfcInfo);
312 vm.setVnfcInfo(vnfcInfoList);
313 vm.setVserverId(context.getAttribute("tmp.vnfInfo.vm[" + i + "].vserver-id"));
314 vm.setVserverName(context.getAttribute("tmp.vnfInfo.vm[" + i + "].vserver-name"));
317 vnfInfo.setVmInfo(vmList);