1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
|
/*-
* ============LICENSE_START=======================================================
* ONAP : APPC
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
* ============LICENSE_END=========================================================
*/
package org.onap.appc.aai.interfaceImpl;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.json.JSONObject;
import org.onap.appc.aai.data.AaiVmInfo;
import org.onap.appc.aai.data.AaiVnfInfo;
import org.onap.appc.aai.data.AaiVnfcInfo;
import org.onap.appc.instar.interfaces.RuleHandlerInterface;
import org.onap.appc.aai.utils.AaiClientConstant;
import org.onap.sdnc.config.params.data.Parameter;
import org.onap.sdnc.config.params.data.ResponseKey;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
public class AaiInterfaceRulesHandler implements RuleHandlerInterface {
private static final EELFLogger log = EELFManager.getInstance().getLogger(AaiInterfaceRulesHandler.class);
private Parameter parameters;
private SvcLogicContext context;
private AaiVnfInfo vnfInfoData;
public AaiInterfaceRulesHandler(Parameter params, SvcLogicContext ctx) {
this.parameters = params;
this.context = ctx;
this.setVnfInfoData(generateAaiVnfInfoData());
}
@Override
public void processRule() throws IllegalStateException {
String fn = "AaiInterfaceIpAddressHandler.processRule";
log.info(fn + "Processing rule :" + parameters.getRuleType());
List<ResponseKey> responseKeyList = parameters.getResponseKeys();
ResponseKey respKeys = new ResponseKey();
if (responseKeyList == null || responseKeyList.isEmpty()) {
throw new IllegalStateException("NO response Keys set for : " + parameters.getRuleType());
}
for (ResponseKey filterKeys : responseKeyList) {
if (null == filterKeys)
continue;
if (StringUtils.isNotBlank(filterKeys.getUniqueKeyName()))
respKeys.setUniqueKeyName(filterKeys.getUniqueKeyName());
if (StringUtils.isNotBlank(filterKeys.getUniqueKeyValue()))
respKeys.setUniqueKeyValue(filterKeys.getUniqueKeyValue());
if (StringUtils.isNotBlank(filterKeys.getFieldKeyName()))
respKeys.setFieldKeyName(filterKeys.getFieldKeyName());
if (StringUtils.isNotBlank(filterKeys.getFilterByField()))
respKeys.setFilterByField(filterKeys.getFilterByField());
if (StringUtils.isNotBlank(filterKeys.getFilterByValue()))
respKeys.setFilterByValue(filterKeys.getFilterByValue());
}
processKeys(respKeys, parameters.getName());
}
public void processKeys(ResponseKey filterKey, String aaiKey) {
String fn = "AaiInterfaceRulesHandler.processKeys()::";
log.info(fn + "processing for " + aaiKey);
String values = new String();
JSONObject aaiKeyValues = null;
log.info("Aai Data in Context : " + context.getAttribute(AaiClientConstant.AAI_KEY_VALUES));
if (context.getAttribute(AaiClientConstant.AAI_KEY_VALUES) != null) {
aaiKeyValues = new JSONObject(context.getAttribute(AaiClientConstant.AAI_KEY_VALUES));
log.info("Aai data already exsits : " + aaiKeyValues.toString());
} else {
aaiKeyValues = new JSONObject();
}
if (StringUtils.equalsIgnoreCase(filterKey.getUniqueKeyValue(), "vnf")) {
values = getVnfDetailsFromContext(filterKey.getFieldKeyName());
}
if (StringUtils.equalsIgnoreCase(filterKey.getUniqueKeyValue(), "vnfc")) {
values = getVnfcDetailsFromContext(filterKey.getFieldKeyName(), filterKey.getFilterByField(),
filterKey.getFilterByValue());
}
if (StringUtils.equalsIgnoreCase(filterKey.getUniqueKeyValue(), "vserver")) {
values = getVServerDetailsFromContext(filterKey.getFieldKeyName(), filterKey.getFilterByField(),
filterKey.getFilterByValue());
}
aaiKeyValues.put(aaiKey, values);
context.setAttribute(AaiClientConstant.AAI_KEY_VALUES, aaiKeyValues.toString());
return;
}
private String getVServerDetailsFromContext(String fieldKeyName, String filterByField, String filterByValue) {
String fn = "AaiInterfaceRulesHander::getVServerDetailsFromContext():";
String values = "";
log.info(fn + "FieldKeyName:" + fieldKeyName + " FilterByName:" + filterByField + " FilterByValue:"
+ filterByValue);
if (!StringUtils.equalsIgnoreCase(fieldKeyName, "vserver-name")) {
log.info(fn + "Returning values:" + values);
return values;
}
if (StringUtils.isNotEmpty(filterByField)
&& StringUtils.isNotEmpty(filterByValue) ) {
int vmIndex = -1;
for (AaiVmInfo vm : vnfInfoData.getVmInfo()) {
vmIndex++;
if (!StringUtils.equalsIgnoreCase(filterByField, "vm-number"))
continue;
int vmNumber = Integer.parseInt(filterByValue);
if (vmNumber != vmIndex)
continue;
if (StringUtils.isBlank(values))
values = vm.getVserverName();
else
values = values + "," + vm.getVserverName();
}
} else {
for (AaiVmInfo vm : vnfInfoData.getVmInfo()) {
if (StringUtils.isBlank(values))
values = vm.getVserverName();
else
values = values + "," + vm.getVserverName();
}
}
log.info(fn + "Returning values:" + values);
return values;
}
//split from getVnfcDetailsFromContext
private String add2ValuesIpaddressV4OamVipNotEmpty(String values, String filterByField, String filterByValue )
{
for (AaiVmInfo vm : vnfInfoData.getVmInfo()) {
for (AaiVnfcInfo vnfcInfo : vm.getVnfcInfo()) {
if (!StringUtils.equalsIgnoreCase(filterByField, "vnfc-function-code")
|| !StringUtils.equalsIgnoreCase(filterByValue, vnfcInfo.getVnfcFunctionCode()))
continue;
if (StringUtils.isBlank(values))
values = vnfcInfo.getVnfcOamIpAddress();
else
values = values + "," + vnfcInfo.getVnfcOamIpAddress();
}
}
return values;
}
//split from getVnfcDetailsFromContext
private String add2ValuesIpaddressV4OamVipEmpty(String values, String filterByField, String filterByValue )
{
for (AaiVmInfo vm : vnfInfoData.getVmInfo()) {
for (AaiVnfcInfo vnfcInfo : vm.getVnfcInfo()) {
if (StringUtils.isBlank(values))
values = vnfcInfo.getVnfcOamIpAddress();
else
values = values + "," + vnfcInfo.getVnfcOamIpAddress();
}
}
return values;
}
//split from getVnfcDetailsFromContext
private String add2ValuesVnfcNameNotEmpty(String values, String filterByField, String filterByValue )
{
for (AaiVmInfo vm : vnfInfoData.getVmInfo()) {
for (AaiVnfcInfo vnfcInfo : vm.getVnfcInfo()) {
if (!StringUtils.equalsIgnoreCase(filterByField, "vnfc-function-code")
|| !StringUtils.equalsIgnoreCase(filterByValue, vnfcInfo.getVnfcFunctionCode()))
continue;
if (StringUtils.isBlank(values))
values = vnfcInfo.getVnfcName();
else
values = values + "," + vnfcInfo.getVnfcName();
}
}
return values;
}
//split from getVnfcDetailsFromContext
private String add2ValuesVnfcNameEmpty(String values, String filterByField, String filterByValue )
{
for (AaiVmInfo vm : vnfInfoData.getVmInfo()) {
for (AaiVnfcInfo vnfcInfo : vm.getVnfcInfo()) {
if (StringUtils.isBlank(values))
values = vnfcInfo.getVnfcName();
else
values = values + "," + vnfcInfo.getVnfcName();
}
}
return values;
}
private String getVnfcDetailsFromContext(String fieldKeyName, String filterByField, String filterByValue) {
String fn = "AaiInterfaceRulesHander::getVnfcDetailsFromContext()";
String values = "";
log.info(fn + "FieldKeyName:" + fieldKeyName + " FilterByField:" + filterByField + " FilterByValue:"
+ filterByValue);
if (StringUtils.equalsIgnoreCase(fieldKeyName, "ipaddress-v4-oam-vip")) {
if (StringUtils.isNotEmpty(filterByField) && StringUtils.isNotEmpty(filterByValue)) {
values = add2ValuesIpaddressV4OamVipNotEmpty(values, filterByField, filterByValue);
} else {
values = add2ValuesIpaddressV4OamVipEmpty(values, filterByField, filterByValue);
}
}
if (StringUtils.equalsIgnoreCase(fieldKeyName, "vnfc-name")) {
if (StringUtils.isNotBlank(filterByField) && StringUtils.isNotBlank(filterByValue)) {
values = add2ValuesVnfcNameNotEmpty(values, filterByField, filterByValue);
} else {
values = add2ValuesVnfcNameEmpty(values, filterByField, filterByValue);
}
}
log.info(fn + "Returning values:" + values);
return values;
}
private String getVnfDetailsFromContext(String fieldKeyName) {
log.info("getVnfDetailsFromContext::" + fieldKeyName);
String values = "";
if (StringUtils.equalsIgnoreCase(fieldKeyName, "vnf-name")) {
String vnfName = context.getAttribute("tmp.vnfInfo.vnf.vnf-name");
values = vnfName;
}
if (StringUtils.equalsIgnoreCase(fieldKeyName, "ipv4-oam-ipaddress")) {
String ipv4OamAddress = context.getAttribute("tmp.vnfInfo.vnf.ipv4-oam-address");
values = ipv4OamAddress;
}
return values;
}
public AaiVnfInfo getVnfInfoData() {
return vnfInfoData;
}
public void setVnfInfoData(AaiVnfInfo vnfInfoData) {
this.vnfInfoData = vnfInfoData;
}
public AaiVnfInfo generateAaiVnfInfoData() {
log.info("AaiInterfaceRulesHandlerImpl:generateAaiVnfInfoData(): Printing variables in context");
for (Object key : context.getAttributeKeySet()) {
String parmName = (String) key;
String parmValue = context.getAttribute(parmName);
log.debug("generateAaiVnfInfoData():: " + parmName + "=" + parmValue);
}
String vmcount = context.getAttribute("tmp.vnfInfo.vm-count");
int vmCount = 0;
if (!StringUtils.isBlank(vmcount))
vmCount = Integer.parseInt(vmcount);
log.info("generateAaiVnfInfoData::" + "vmCount:" + vmCount);
AaiVnfInfo vnfInfo = new AaiVnfInfo();
vnfInfo.setVnfName("vnf-name");
ArrayList<AaiVmInfo> vmList = new ArrayList<AaiVmInfo>();
for (int i = 0; i < vmCount; i++) {
AaiVmInfo vm = new AaiVmInfo();
String vnfcCountStr = context.getAttribute("tmp.vnfInfo.vm[" + i + "].vnfc-count");
int vnfcCount = Integer.parseInt(vnfcCountStr);
ArrayList<AaiVnfcInfo> vnfcInfoList = new ArrayList<AaiVnfcInfo>();
for (int j = 0; j < vnfcCount; j++) {
AaiVnfcInfo vnfcInfo = new AaiVnfcInfo();
vnfcInfo.setVnfcName(context.getAttribute("tmp.vnfInfo.vm[" + i + "].vnfc-name"));
vnfcInfo.setVnfcFunctionCode(context.getAttribute("tmp.vnfInfo.vm[" + i + "].vnfc-function-code"));
vnfcInfo.setVnfcOamIpAddress(
context.getAttribute("tmp.vnfInfo.vm[" + i + "].vnfc-ipaddress-v4-oam-vip"));
vnfcInfoList.add(vnfcInfo);
}
vm.setVnfcInfo(vnfcInfoList);
vm.setVserverId(context.getAttribute("tmp.vnfInfo.vm[" + i + "].vserver-id"));
vm.setVserverName(context.getAttribute("tmp.vnfInfo.vm[" + i + "].vserver-name"));
vmList.add(vm);
}
vnfInfo.setVmInfo(vmList);
return vnfInfo;
}
}
|