2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * ================================================================================
9 * Modifications (C) 2019 Ericsson
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.appc.aai.client.aai;
28 import com.att.eelf.configuration.EELFLogger;
29 import com.att.eelf.configuration.EELFManager;
30 import org.apache.commons.lang3.StringUtils;
31 import org.apache.commons.lang3.math.NumberUtils;
32 import org.onap.appc.aai.client.AppcAaiClientConstant;
33 import org.onap.ccsdk.sli.adaptors.aai.AAIClient;
34 import org.onap.ccsdk.sli.adaptors.aai.AAIService;
35 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
36 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
37 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
38 import org.osgi.framework.BundleContext;
39 import org.osgi.framework.FrameworkUtil;
40 import org.osgi.framework.ServiceReference;
42 import java.util.ArrayList;
43 import java.util.HashMap;
44 import java.util.List;
47 public class AaiService {
49 private static final EELFLogger log = EELFManager.getInstance().getLogger(AaiService.class);
50 private static final String STR_VNF_ID = "generic-vnf.vnf-id = '";
51 private static final String STR_VNFC_REF = "vnfcReference[";
52 private static final String STR_VNFC_REF_KEY = "VNFCREFKEY ";
53 private static final String STR_AAI_REF_KEY = "AAIREFKEY ";
54 private static final String STR_RELATIONSHIP_LIST = ".relationship-list.relationship[";
55 private static final String STR_VNFC_NAME = "vnfc.vnfc-name = '";
56 private static final String QUERY_STR_VNFC_NAME = "VNFCNAME IN INSERTVNFCS ";
58 private static final String PARAM_GENERIC_VNF = "generic-vnf";
59 private static final String PARAM_VNF_INFO = "vnfInfo";
60 private static final String PARAM_VSERVER = "vserver";
61 private static final String PARAM_VM_INFO = "vmInfo";
62 private static final String PARAM_PROV_STATUS = "prov-status";
63 private static final String PARAM_VAL_NVTPROV = "NVTPROV";
65 private static final String ATTR_VSERVER_ID = "vserver-id";
66 private static final String ATTR_TENANT_ID = "tenant-id";
67 private static final String ATTR_CLOUD_OWNER = "cloud-owner";
68 private static final String ATTR_CLOUD_REGION_ID = "cloud-region-id";
69 private static final String ATTR_VNFC_COUNT = "vm.vnfc-count";
70 private static final String ATTR_VNFC_NAME = "vnfc-name";
71 private static final String ATTR_VNFC_FUNC_CODE = "VNFC-FUNCTION-CODE";
72 private static final String ATTR_VSERVER_NAME = "vserver-name";
73 private static final String ATTR_VNF_ID = "vnf-id";
75 private AAIClient aaiClient;
77 public AaiService(AAIClient aaiClient) {
78 this.aaiClient = aaiClient;
82 BundleContext bctx = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
83 ServiceReference sref = bctx.getServiceReference(AAIService.class);
84 aaiClient = (AAIClient) bctx.getService(sref);
87 public void getGenericVnfInfo(Map<String, String> params, SvcLogicContext ctx)
88 throws AaiServiceInternalException, SvcLogicException {
90 String vnfId = params.get("vnfId");
91 if (StringUtils.isBlank(vnfId)) {
92 throw new AaiServiceInternalException("VnfId is missing");
94 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
95 prefix = StringUtils.isNotBlank(prefix) ? (prefix + ".") : "";
96 String resourceKey = STR_VNF_ID + vnfId + "'";
97 SvcLogicContext vnfCtx = readResource(resourceKey, PARAM_VNF_INFO, PARAM_GENERIC_VNF);
99 ctx.setAttribute(prefix + "vnf.vnf-name", vnfCtx.getAttribute("vnfInfo.vnf-name"));
100 ctx.setAttribute(prefix + "vnf.vnf-type", vnfCtx.getAttribute("vnfInfo.vnf-type"));
101 ctx.setAttribute(prefix + "vnf.prov-status", vnfCtx.getAttribute("vnfInfo.prov-status"));
102 ctx.setAttribute(prefix + "vnf.orchestration-status", vnfCtx.getAttribute("vnfInfo.orchestration-status"));
103 ctx.setAttribute(prefix + "vnf.ipv4-oam-address", vnfCtx.getAttribute("vnfInfo.ipv4-oam-address"));
106 String relLen = vnfCtx.getAttribute("vnfInfo.relationship-list.relationship_length");
107 int relationshipLength = 0;
108 if (relLen != null) {
109 relationshipLength = Integer.parseInt(relLen);
111 log.info("RELLEN " + relationshipLength);
112 for (int i = 0; i < relationshipLength; i++) {
113 String vserverId = getRelationshipValue(i, vnfCtx, PARAM_VSERVER, "vserver.vserver-id", PARAM_VNF_INFO);
114 String tenantId = getRelationshipValue(i, vnfCtx, PARAM_VSERVER, "tenant.tenant-id", PARAM_VNF_INFO);
115 String cloudOwner = getRelationshipValue(i, vnfCtx, PARAM_VSERVER, "cloud-region.cloud-owner",
117 String cloudRegionId =
118 getRelationshipValue(i, vnfCtx, PARAM_VSERVER, "cloud-region.cloud-region-id", PARAM_VNF_INFO);
119 if (vserverId != null) {
120 log.info("VSERVER KEYS " + vserverId + " " + tenantId + " " + cloudOwner + " " + cloudRegionId);
121 String vnfPrefix = prefix + "vm[" + vmCount + "].";
122 ctx.setAttribute(vnfPrefix + ATTR_VSERVER_ID, vserverId);
123 ctx.setAttribute(vnfPrefix + ATTR_TENANT_ID, tenantId);
124 ctx.setAttribute(vnfPrefix + ATTR_CLOUD_OWNER, cloudOwner);
125 ctx.setAttribute(vnfPrefix + ATTR_CLOUD_REGION_ID, cloudRegionId);
129 ctx.setAttribute(prefix + "vm-count", String.valueOf(vmCount));
130 log.info("VMCOUNT FROM VNF INFO " + ctx.getAttribute(prefix + "vm-count"));
133 public void getVMInfo(Map<String, String> params, SvcLogicContext ctx)
134 throws SvcLogicException {
137 log.info("Received getVmInfo call with params : " + params);
138 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
139 prefix = StringUtils.isNotBlank(prefix) ? (prefix + ".") : "";
141 ctx.setAttribute(prefix + ATTR_VNFC_COUNT, String.valueOf(vnfcCount)); // In case no vnfcs are found
143 VServerInfo vServerInfo = new VServerInfo(params);
146 "vserver.vserver-id = '" + vServerInfo.getVserverId() + "' AND tenant.tenant-id = '" + vServerInfo
148 + "' AND cloud-region.cloud-owner = '" + vServerInfo.getCloudOwner()
149 + "' AND cloud-region.cloud-region-id = '"
150 + vServerInfo.getCloudRegionId() + "'";
152 SvcLogicContext vmCtx = readResource(resourceKey, PARAM_VM_INFO, PARAM_VSERVER);
153 ctx.setAttribute(prefix + "vm.prov-status", vmCtx.getAttribute("vmInfo.prov-status"));
154 ctx.setAttribute(prefix + "vm.vserver-name", vmCtx.getAttribute("vmInfo.vserver-name"));
155 ctx.setAttribute(prefix + "vm.vserver-selflink", vmCtx.getAttribute("vmInfo.vserver-selflink"));
157 String relLen = vmCtx.getAttribute("vmInfo.relationship-list.relationship_length");
158 int relationshipLength = 0;
159 if (relLen != null) {
160 relationshipLength = Integer.parseInt(relLen);
162 log.info("RELLEN" + relationshipLength);
163 for (int i = 0; i < relationshipLength; i++) {
164 String vfModuleId = getRelationshipValue(i, vmCtx, "vf-module", "vf-module.vf-module-id",
166 if (vfModuleId != null) {
167 ctx.setAttribute(prefix + "vm.vf-module-id", vfModuleId);
170 String vnfcName = getRelationshipValue(i, vmCtx, "vnfc", "vnfc.vnfc-name", PARAM_VM_INFO);
171 if (vnfcName != null) {
172 ctx.setAttribute(prefix + "vm.vnfc[" + vnfcCount + "].vnfc-name", vnfcName);
176 } // relationshipLength
177 ctx.setAttribute(prefix + ATTR_VNFC_COUNT, String.valueOf(vnfcCount));
178 log.info("VSERVERNAME " + ctx.getAttribute(prefix + "vm.vserver-name") + " HAS NUM VNFCS = "
179 + ctx.getAttribute(prefix + ATTR_VNFC_COUNT));
180 } catch (Exception e) {
181 log.error("An error occurred when fetching Vm info", e);
182 throw new SvcLogicException("Failed to fetch VM info", e);
186 private String getRelationshipValue(int i, SvcLogicContext ctx, String relatedTo, String relationshipKey,
189 if (relatedTo.equals(ctx.getAttribute(prefix + STR_RELATIONSHIP_LIST + i + "].related-to"))) {
190 log.info("RELATEDTO " + relatedTo);
191 int relationshipDataLength = 0;
193 ctx.getAttribute(prefix + STR_RELATIONSHIP_LIST + i + "].relationship-data_length");
194 if (relDataLen != null) {
195 relationshipDataLength = Integer.parseInt(relDataLen);
198 for (int j = 0; j < relationshipDataLength; j++) {
200 String key = ctx.getAttribute(prefix + STR_RELATIONSHIP_LIST + i + "].relationship-data["
201 + j + "].relationship-key");
203 String value = ctx.getAttribute(prefix + STR_RELATIONSHIP_LIST + i + "].relationship-data["
204 + j + "].relationship-value");
206 log.info("GENERIC KEY " + key);
207 log.info("GENERIC VALUE " + value);
209 if (relationshipKey.equals(key)) {
213 } // relationshipDataLength
219 public void getVnfcInfo(Map<String, String> params, SvcLogicContext ctx)
220 throws AaiServiceInternalException, SvcLogicException {
221 log.info("Received getVnfc call with params : " + params);
223 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
224 prefix = StringUtils.isNotBlank(prefix) ? (prefix + ".") : "";
226 String vnfcName = params.get("vnfcName");
227 if (StringUtils.isBlank(vnfcName)) {
228 throw new AaiServiceInternalException("Vnfc Name is missing");
231 String resourceKey = STR_VNFC_NAME + vnfcName + "'";
232 SvcLogicContext vnfcCtx = readResource(resourceKey, "vnfcInfo", "vnfc");
234 // Changes for US 315820 for 1710 vnfc-type renamed to nfc-function,vnfc-function-code renamed to
237 ctx.setAttribute(prefix + "vnfc.vnfc-type", vnfcCtx.getAttribute("vnfcInfo.nfc-function"));
238 ctx.setAttribute(prefix + "vnfc.vnfc-function-code", vnfcCtx.getAttribute("vnfcInfo.nfc-naming-code"));
239 ctx.setAttribute(prefix + "vnfc.group-notation", vnfcCtx.getAttribute("vnfcInfo.group-notation"));
240 ctx.setAttribute(prefix + "vnfc.ipaddress-v4-oam-vip", vnfcCtx.getAttribute("vnfcInfo.ipaddress-v4-oam-vip"));
244 public void insertVnfcs(Map<String, String> params, SvcLogicContext ctx, int vmCount,
245 String vfModuleIdFromRequest)
246 throws AaiServiceInternalException, SvcLogicException {
247 log.info("Received insertVnfcs call with params : " + params);
249 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
251 prefix = StringUtils.isNotBlank(prefix) ? (prefix + ".") : "";
253 log.debug("vnfcRefIndx" + vnfcRefIndx);
254 for (int i = 0; i < vmCount; i++) {
255 String aaiRefKey = prefix + "vm[" + i + "].";
257 //ConfigScaleOut - Do not process vms that are not associated with vfmodule id if vfmodule id is present
258 if (StringUtils.isNotBlank(vfModuleIdFromRequest)) {
259 String vmVfModuleId = ctx.getAttribute(aaiRefKey + "vf-module-id");
260 log.info("insertVnfcs():::vfModule for vm is=" + vmVfModuleId);
261 if (StringUtils.isBlank(vmVfModuleId) || !StringUtils
262 .equalsIgnoreCase(vmVfModuleId, vfModuleIdFromRequest)) {
267 log.info(QUERY_STR_VNFC_NAME + ctx.getAttribute(aaiRefKey + ATTR_VNFC_NAME));
268 String vnfcNameAAI = ctx.getAttribute(aaiRefKey + ATTR_VNFC_NAME);
269 // Get Vnfc_reference data from the table
270 String vnfcRefKey = STR_VNFC_REF + vnfcRefIndx + "].";
272 log.info(STR_VNFC_REF_KEY + vnfcRefKey);
273 log.info(STR_AAI_REF_KEY + aaiRefKey);
275 String groupNotationType = ctx.getAttribute(vnfcRefKey + "GROUP-NOTATION-TYPE");
276 String groupNotationValue = ctx.getAttribute(vnfcRefKey + "GROUP-NOTATION-VALUE");
277 String vnfcType = ctx.getAttribute(vnfcRefKey + "VNFC-TYPE");
278 String vnfcFuncCode = ctx.getAttribute(vnfcRefKey + ATTR_VNFC_FUNC_CODE);
279 String populateIpAddressV4OamVip = ctx.getAttribute(vnfcRefKey + "IPADDRESS-V4-OAM-VIP");
281 // Get vnfc Data to be added
282 String vserverName = ctx.getAttribute(aaiRefKey + ATTR_VSERVER_NAME);
283 String vnfcName = vserverName + vnfcFuncCode + "001";
284 String groupNotation = getGroupNotation(groupNotationType, groupNotationValue, vnfcName, vserverName,
285 prefix, ctx, vnfcType, vnfcFuncCode, vmCount);
287 String ipAddressV4OamVip = null;
288 if ("Y".equals(populateIpAddressV4OamVip)) {
289 ipAddressV4OamVip = ctx.getAttribute("vnf-host-ip-address"); // from input
291 Map<String, String> vnfcParams =
292 populateVnfcParams(ctx, aaiRefKey, ipAddressV4OamVip, groupNotation, vnfcType, vnfcFuncCode);
294 log.info("Vnfc name from AAI: " + vnfcNameAAI);
295 log.info("Vnfc name generated: " + vnfcName);
297 if (StringUtils.isNotBlank(vnfcNameAAI)) {
298 if (vnfcName.equalsIgnoreCase(vnfcNameAAI)) {
299 updateVnfcStatus(vnfcNameAAI, params, prefix);
305 addVnfc(vnfcName, vnfcParams, prefix);
307 // Add VNFC Info to context for current added VNFC
308 ctx.setAttribute(aaiRefKey + ATTR_VNFC_NAME, vnfcName);
309 ctx.setAttribute(aaiRefKey + "vnfc-type", vnfcType);
310 ctx.setAttribute(aaiRefKey + "vnfc-function-code", vnfcFuncCode);
311 ctx.setAttribute(aaiRefKey + "group-notation", groupNotation);
315 public List<String> getVnfcData(Map<String, String> params, SvcLogicContext ctx, int vmCount) {
317 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
318 prefix = StringUtils.isNotBlank(prefix) ? (prefix + ".") : "";
319 List<String> vnfcNames = new ArrayList<>();
320 int vnfcRefIndx = -1;
321 for (int i = 0; i < vmCount; i++) {
322 String aaiRefKey = prefix + "vm[" + i + "].";
323 log.info(QUERY_STR_VNFC_NAME + ctx.getAttribute(aaiRefKey + ATTR_VNFC_NAME));
324 if (ctx.getAttribute(aaiRefKey + ATTR_VNFC_NAME) != null) {
329 String vnfcRefKey = STR_VNFC_REF + vnfcRefIndx + "].";
330 log.info(STR_VNFC_REF_KEY + vnfcRefKey);
331 log.info(STR_AAI_REF_KEY + aaiRefKey);
332 String vnfcFuncCode = ctx.getAttribute(vnfcRefKey + ATTR_VNFC_FUNC_CODE);
334 // Get vnfc Data to be added
335 String vserverName = ctx.getAttribute(aaiRefKey + ATTR_VSERVER_NAME);
336 String vnfcName = vserverName + vnfcFuncCode + "001";
338 vnfcNames.add(vnfcName);
344 private Map<String, String> populateVnfcParams(SvcLogicContext ctx, String aaiRefKey, String ipAddressV4OamVip,
345 String groupNotation, String vnfcType, String vnfcFuncCode) {
347 Map<String, String> vnfcParams = new HashMap<>();
349 // Changes for vnfc-type renamed to nfc-function,vnfc-function-code renamed to
351 vnfcParams.put("nfc-naming-code", vnfcFuncCode);
352 vnfcParams.put("nfc-function", vnfcType);
353 vnfcParams.put("ipaddress-v4-oam-vip", ipAddressV4OamVip);
354 vnfcParams.put(PARAM_PROV_STATUS, PARAM_VAL_NVTPROV);
355 vnfcParams.put("orchestration-status", "CONFIGURED");
356 vnfcParams.put("in-maint", "false");
357 vnfcParams.put("is-closed-loop", "false");
358 vnfcParams.put("group-notation", groupNotation);
359 vnfcParams.put("relationship-list.relationship[0].related-to", PARAM_VSERVER);
360 vnfcParams.put("relationship-list.relationship[0].relationship-data[0].relationship-key", "vserver.vserver-id");
361 vnfcParams.put("relationship-list.relationship[0].relationship-data[0].relationship-value",
362 ctx.getAttribute(aaiRefKey + ATTR_VSERVER_ID));
363 vnfcParams.put("relationship-list.relationship[0].relationship-data[1].relationship-key", "tenant.tenant-id");
364 vnfcParams.put("relationship-list.relationship[0].relationship-data[1].relationship-value",
365 ctx.getAttribute(aaiRefKey + ATTR_TENANT_ID));
366 vnfcParams.put("relationship-list.relationship[0].relationship-data[2].relationship-key",
367 "cloud-region.cloud-owner");
368 vnfcParams.put("relationship-list.relationship[0].relationship-data[2].relationship-value",
369 ctx.getAttribute(aaiRefKey + ATTR_CLOUD_OWNER));
370 vnfcParams.put("relationship-list.relationship[0].relationship-data[3].relationship-key",
371 "cloud-region.cloud-region-id");
372 vnfcParams.put("relationship-list.relationship[0].relationship-data[3].relationship-value",
373 ctx.getAttribute(aaiRefKey + ATTR_CLOUD_REGION_ID));
374 vnfcParams.put("relationship-list.relationship[1].related-to", PARAM_GENERIC_VNF);
375 vnfcParams.put("relationship-list.relationship[1].relationship-data[0].relationship-key", "generic-vnf.vnf-id");
376 vnfcParams.put("relationship-list.relationship[1].relationship-data[0].relationship-value",
377 ctx.getAttribute(ATTR_VNF_ID));
378 vnfcParams.put("relationship-list.relationship[2].related-to", "vf-module");
379 vnfcParams.put("relationship-list.relationship[2].relationship-data[0].relationship-key", "generic-vnf.vnf-id");
380 vnfcParams.put("relationship-list.relationship[2].relationship-data[0].relationship-value",
381 ctx.getAttribute(ATTR_VNF_ID));
382 vnfcParams.put("relationship-list.relationship[2].relationship-data[1].relationship-key",
383 "vf-module.vf-module-id");
384 vnfcParams.put("relationship-list.relationship[2].relationship-data[1].relationship-value",
385 ctx.getAttribute(aaiRefKey + "vf-module-id"));
390 public void addVnfc(String vnfcName, Map<String, String> params, String prefix)
391 throws AaiServiceInternalException, SvcLogicException {
393 log.info("Received addVnfc call with vnfcName : " + vnfcName);
394 log.info("Received addVnfc call with params : " + params);
395 String resourceKey = STR_VNFC_NAME + vnfcName + "'";
396 log.info("Received addVnfc call with resourceKey : " + resourceKey);
398 SvcLogicContext vnfcCtx = new SvcLogicContext();
399 SvcLogicResource.QueryStatus response =
400 aaiClient.save("vnfc", true, false, resourceKey, params, prefix, vnfcCtx);
402 if (SvcLogicResource.QueryStatus.SUCCESS.equals(response)) {
403 log.info("Added VNFC SUCCESSFULLY " + vnfcName);
404 } else if (SvcLogicResource.QueryStatus.FAILURE.equals(response)) {
405 throw new AaiServiceInternalException("VNFC Add failed for vnfc_name " + vnfcName);
409 public String getGroupNotation(String groupNotationType, String groupNotationValue, String vnfcName,
410 String vserverName, String prefix, SvcLogicContext ctx, String vnfcRefVnfcType, String vnfcFuncCode,
413 String groupNotation = null;
415 if ("fixed-value".equals(groupNotationType)) {
416 groupNotation = groupNotationValue;
417 } else if ("first-vnfc-name".equals(groupNotationType)) {
420 * If the group-notation-type value = ?first-vnfc-name?,
421 * then populate the group-notation value with the concatenation of
422 * [vnfc name associated with the first vnfc for the vnfc-type (e.g., *******)]
423 * and [the value in group-notation-value (e.g., pair)].
424 * There may be several vnfc-types associated with the VM?s.
426 /* Vnfc-type should be from refrence data */
428 /* vDBE has 2 VNFCs with same VNFC type . The pair name should be same for both . */
430 * When first VNFC is added details should be added to context so FirstVnfcName doesnt return null second
433 String tmpVnfcName = getFirstVnfcNameForVnfcType(ctx, prefix, vnfcRefVnfcType);
435 log.info("RETURNED FIRSTVNFCNAME" + tmpVnfcName);
436 log.info("CURRENTVNFCNAME" + vnfcName);
437 groupNotation = resolveGroupNotation(groupNotationValue, vnfcName, tmpVnfcName);
438 } else if ("relative-value".equals(groupNotationType)) {
441 * If the group-notation-type = ?relative-value?, then find the group-notation value
442 * from the prior vnfc (where prior means the vnfc with where the last three digits of the
443 * vm-name is one lower than the current one; note that this vnfc may have been previously configured.)
444 * 1. If the group-notation-value = next, then add 1 to the group-notation value from the prior vnfc and use
446 * 2. If the group-notation-value = same, then use the group-notation-value from the prior vnfc record
449 // next and same cant be defined for first VM. if next will not generate grpNotation if Prior is not a
451 String tmpVserverName;
452 if (vserverName != null) {
454 String vmNamePrefix = vserverName.substring(0, vserverName.length() - 3);
455 String lastThreeChars = vserverName.substring(vserverName.length() - 3);
457 if (NumberUtils.isDigits(lastThreeChars)) {
458 int vmNum = Integer.parseInt(lastThreeChars) - 1;
459 String formatted = String.format("%03d", vmNum);
461 log.info("FORMATTED " + formatted);
463 tmpVserverName = vmNamePrefix + formatted;
465 String priorGroupNotation = getGroupNotationForVServer(ctx, prefix, tmpVserverName);
466 groupNotation = resolveGroupNotation(groupNotationValue, priorGroupNotation);
469 } else if ("existing-value".equals(groupNotationType)) {
470 /* This is a new value being added. Find the existing vnfc records in A&AI inventory with the same vnfc-function code as the value in vnfc_reference table.
471 * Verify that the group-notation value is the same for all such records found in inventory.
472 * if all records do not have the same group-notation value, write the new vnfc record to A&AI inventory without a group-notation value and continue to the next VM in the vnfc_reference table. A 501 intermediate error message should be sent after all new VNFC records have been added to A&AI.
473 * If all records match, use the same group-notation value for the new vnfc record as found in the existing vnfc records.
475 groupNotation = getGroupNotationForExistigValue(ctx, vnfcFuncCode, vmCount);
478 log.info("RETURNED GROUPNOTATION " + groupNotation);
479 return groupNotation;
482 private String resolveGroupNotation(String groupNotationValue, String vnfcName, String tmpVnfcName) {
483 if (tmpVnfcName == null) {
484 log.info("CURRENTVNFCNAME" + vnfcName);
485 // No Vnfcs currently exist. Use Current vnfcName
486 return vnfcName + groupNotationValue;
488 return tmpVnfcName + groupNotationValue;
492 private String resolveGroupNotation(String groupNotationValue, String priorGroupNotation) {
493 if ("same".equals(groupNotationValue)) {
494 return priorGroupNotation;
495 } else if ("next".equals(groupNotationValue) && priorGroupNotation != null
496 && NumberUtils.isDigits(priorGroupNotation)) {
498 int nextGrpNotation = Integer.parseInt(priorGroupNotation) + 1;
499 return String.valueOf(nextGrpNotation);
504 public String getGroupNotationForExistigValue(SvcLogicContext ctx, String vnfcFuncCode,
506 String vfModuleId = ctx.getAttribute("req-vf-module-id"); //Coming from request-params
507 boolean first = true;
508 String aaiGroupNotationValue = null;
509 for (int i = 0; i < vmCount; i++) {
510 String ind = "tmp.vnfInfo.vm[" + i + "].";
511 String aaiFuncCode = ctx.getAttribute(ind + "vnfc-function-code");
512 String aaiGroupNotation = ctx.getAttribute(ind + "group-notation");
513 String aaiVfModuleId = ctx.getAttribute(ind + "vf-module-id");
515 log.info("getGroupNotationForExistigValue()::: vfModuleId=" + vfModuleId + ", aaiFuncCode=" + aaiFuncCode
516 + ", aaiGroupNotation=" + aaiGroupNotation + ",aaiVfMOduleId=" + aaiVfModuleId);
518 if (StringUtils.isNotBlank(aaiFuncCode) && aaiFuncCode.equals(vnfcFuncCode) &&
519 (StringUtils.isNotBlank(vfModuleId) && StringUtils.isNotBlank(aaiVfModuleId) && aaiVfModuleId
520 .equals(vfModuleId))) {
521 if (null == aaiGroupNotationValue && first) {
522 if (null == aaiGroupNotation) {//Return if null
525 aaiGroupNotationValue = ctx.getAttribute(ind + "group-notation");
528 if (!StringUtils.equals(aaiGroupNotationValue, ctx.getAttribute(ind + "group-notation"))) {
529 log.info("Values are different, returning null");
536 return aaiGroupNotationValue;
539 public String getGroupNotationForVServer(SvcLogicContext ctx, String prefix, String vserverName) {
541 String vmCountStr = ctx.getAttribute(prefix + "vnf.vm-count");
543 if (vmCountStr == null) {
547 int vmCount = Integer.parseInt(vmCountStr);
548 for (int i = 0; i < vmCount; i++) {
550 String tmpVserver = ctx.getAttribute(prefix + "vm[" + i + "].vserver-name");
552 if (vserverName.equals(tmpVserver)) {
553 return ctx.getAttribute(prefix + "vm[" + i + "].group-notation");
559 public String getFirstVnfcNameForVnfcType(SvcLogicContext ctx, String prefix, String vnfcRefVnfcType) {
561 String vmCountStr = ctx.getAttribute(prefix + "vnf.vm-count");
562 if (vmCountStr == null) {
565 int vmCount = Integer.parseInt(vmCountStr);
566 for (int i = 0; i < vmCount; i++) {
568 String tmpvnfcType = ctx.getAttribute(prefix + "vm[" + i + "].vnfc-type");
570 if (vnfcRefVnfcType.equals(tmpvnfcType)) {
571 return ctx.getAttribute(prefix + "vm[" + i + "].vnfc-name");
577 public void updateVServerStatus(Map<String, String> params, SvcLogicContext ctx, int vmCount)
578 throws AaiServiceInternalException, SvcLogicException {
579 log.info("Received updateVServerStatus call with params : " + params);
581 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
583 prefix = StringUtils.isNotBlank(prefix) ? (prefix + ".") : "";
584 Map<String, String> vServerParams = new HashMap<>();
586 // TODO - Should this just update prov-status or both? What about generic-vnf status? Will that be updated by
589 vServerParams.put(PARAM_PROV_STATUS, PARAM_VAL_NVTPROV);
591 for (int i = 0; i < vmCount; i++) {
592 String aaiRefKey = prefix + "vm[" + i + "].";
594 log.info("VNFCNAME IN UpdateVServer " + ctx.getAttribute(aaiRefKey + ATTR_VNFC_NAME));
596 if (ctx.getAttribute(aaiRefKey + ATTR_VNFC_NAME) != null) {
600 String resourceKey = "vserver.vserver-id = '" + ctx.getAttribute(aaiRefKey + ATTR_VSERVER_ID) + "'"
601 + " AND tenant.tenant-id = '" + ctx.getAttribute(aaiRefKey + ATTR_TENANT_ID) + "'"
602 + " AND cloud-region.cloud-owner = '" + ctx.getAttribute(aaiRefKey + ATTR_CLOUD_OWNER) + "'"
603 + " AND cloud-region.cloud-region-id = '" + ctx.getAttribute(aaiRefKey + ATTR_CLOUD_REGION_ID) + "'";
605 updateResource(PARAM_VSERVER, resourceKey, vServerParams);
609 public void updateVnfStatus(Map<String, String> params, SvcLogicContext ctx)
610 throws AaiServiceInternalException, SvcLogicException {
611 log.info("Received updateVnfStatus call with params : " + params);
613 Map<String, String> vnfParams = new HashMap<>();
615 // TODO - Should this just update prov-status or both? What about generic-vnf status? Will that be updated by
618 vnfParams.put(PARAM_PROV_STATUS, PARAM_VAL_NVTPROV);
620 String resourceKey = STR_VNF_ID + ctx.getAttribute(ATTR_VNF_ID) + "'";
622 updateResource(PARAM_GENERIC_VNF, resourceKey, vnfParams);
625 public void updateResource(String resource, String resourceKey, Map<String, String> params)
626 throws AaiServiceInternalException, SvcLogicException {
628 log.info("Received updateResource call with Key : " + resourceKey);
630 SvcLogicContext ctx = new SvcLogicContext();
631 SvcLogicResource.QueryStatus response = aaiClient.update(resource, resourceKey, params, "tmp.update", ctx);
633 if (SvcLogicResource.QueryStatus.SUCCESS.equals(response)) {
634 log.info("Updated " + resource + " SUCCESSFULLY for " + resourceKey);
636 } else if (SvcLogicResource.QueryStatus.FAILURE.equals(response)) {
637 throw new AaiServiceInternalException(resource + " Update failed for " + resourceKey);
641 public SvcLogicContext readResource(String query, String prefix, String resourceType)
642 throws AaiServiceInternalException, SvcLogicException {
643 SvcLogicContext resourceContext = new SvcLogicContext();
645 SvcLogicResource.QueryStatus response =
646 aaiClient.query(resourceType, false, null, query, prefix, null, resourceContext);
647 log.info("AAIResponse: " + response.toString());
648 if (resourceType==null || !resourceType.equals("cloud-region")) {
649 if (!SvcLogicResource.QueryStatus.SUCCESS.equals(response)) {
650 throw new AaiServiceInternalException("Error Retrieving " + resourceType + " from A&AI");
653 return resourceContext;
656 // Added for Backward Compatibility
657 public void checkAndUpdateVnfc(Map<String, String> params, SvcLogicContext ctx, int vnfcRefLen, int vmCount)
658 throws AaiServiceInternalException, SvcLogicException {
659 log.info("Received checkAndUpdateVnfcStatus call with params : " + params);
661 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
663 prefix = StringUtils.isNotBlank(prefix) ? (prefix + ".") : "";
665 for (int i = 0; i < vmCount; i++) {
666 String aaiRefKey = prefix + "vm[" + i + "].";
668 log.info(QUERY_STR_VNFC_NAME + aaiRefKey + "vnfc-name:" + ctx.getAttribute(aaiRefKey + ATTR_VNFC_NAME));
670 String vnfcNameAai = ctx.getAttribute(aaiRefKey + ATTR_VNFC_NAME);
672 if (StringUtils.isNotBlank(vnfcNameAai)) {
673 // Get Vnfc_reference data
674 for (int vnfcRefIndx = 0; vnfcRefIndx < vnfcRefLen; vnfcRefIndx++) {
676 String vnfcRefKey = STR_VNFC_REF + vnfcRefIndx + "].";
678 log.info(STR_VNFC_REF_KEY + vnfcRefKey);
679 log.info(STR_AAI_REF_KEY + aaiRefKey);
681 String vnfcFuncCode = ctx.getAttribute(vnfcRefKey + ATTR_VNFC_FUNC_CODE);
682 String vserverName = ctx.getAttribute(aaiRefKey + ATTR_VSERVER_NAME);
683 String vnfcNameReference = vserverName + vnfcFuncCode + "001";
684 tryUpdateVnfcStatus(params, prefix, vnfcNameAai, vnfcNameReference);
690 private void tryUpdateVnfcStatus(Map<String, String> params, String prefix, String vnfcNameAai,
691 String vnfcNameReference) throws AaiServiceInternalException, SvcLogicException {
692 if (vnfcNameAai.equals(vnfcNameReference)) {
693 updateVnfcStatus(vnfcNameAai, params, prefix);
697 public void updateVnfcStatus(String vnfcName, Map<String, String> params, String prefix)
698 throws AaiServiceInternalException, SvcLogicException {
700 log.info("Received updateVnfcStatus call with vnfcName : " + vnfcName);
701 log.info("Received updateVnfcStatus call with params : " + params);
703 String resourceKey = STR_VNFC_NAME + vnfcName + "'";
704 log.info("Received updateVnfcStatus call with resourceKey : " + resourceKey);
706 Map<String, String> vnfcParams = new HashMap<>();
707 vnfcParams.put(PARAM_PROV_STATUS, PARAM_VAL_NVTPROV);
708 vnfcParams.put("orchestration-status", "CONFIGURED");
710 log.info("In updateVnfcStatus call with vnfcParams : " + vnfcParams);
712 updateResource("vnfc", resourceKey, vnfcParams);
714 log.info("End of updateVnfcStatus");
717 public void updateVnfStatusWithOAMAddress(Map<String, String> params, SvcLogicContext ctx)
718 throws AaiServiceInternalException, SvcLogicException {
719 log.info("Received updateVnfStatusWithOAMAddress call with params : " + params);
721 String ipAddress = ctx.getAttribute("vnf-host-ip-address");
722 log.debug("Vnf-host-ip-address" + ipAddress);
724 Map<String, String> vnfParams = new HashMap<>();
725 vnfParams.put("ipv4-oam-address", ipAddress);
726 String resourceKey = STR_VNF_ID + ctx.getAttribute(ATTR_VNF_ID) + "'";
727 updateResource(PARAM_GENERIC_VNF, resourceKey, vnfParams);
730 public void getVfModuleInfo(Map<String, String> params, SvcLogicContext vfModuleCtx) throws Exception {
731 log.info("Received getVfModuleInfo call with params : " + params);
732 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
733 prefix = StringUtils.isNotBlank(prefix) ? (prefix + ".") : "";
735 String vnfId = params.get("vnfId");
736 String vfModuleId = params.get("vfModuleId");
737 String resourceKey = STR_VNF_ID + vnfId +
738 "' AND vf-module.vf-module-id = '" + vfModuleId + "'";
739 String queryPrefix = "vfModuleInfo";
740 String resourceType = "vf-module";
741 SvcLogicContext vfmCtx = readResource(resourceKey, queryPrefix, resourceType);
742 String modelInvariantId = vfmCtx.getAttribute("vfModuleInfo.model-invariant-id");
743 log.info("getVfModuleInfo():::modelInvariant=" + modelInvariantId);
744 vfModuleCtx.setAttribute(prefix + "vfModule.model-invariant-id",
745 vfmCtx.getAttribute("vfModuleInfo.model-invariant-id"));
747 .setAttribute(prefix + "vfModule.model-version-id", vfmCtx.getAttribute("vfModuleInfo.model-version-id"));
748 log.info("End - getVfModuleInfo");
751 public void getModelVersionInfo(Map<String, String> modelParams, SvcLogicContext modelCtx) throws Exception {
752 log.info("Received getModelVersionInfo call with params : " + modelParams);
753 String prefix = modelParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
754 prefix = StringUtils.isNotBlank(prefix) ? (prefix + ".") : "";
756 String modelInvariantId = modelParams.get("model-invariant-id");
757 String modelVersionId = modelParams.get("model-version-id");
758 String resourceKey = "model.model-invariant-id = '" + modelInvariantId +
759 "' AND model-ver.model-version-id = '" + modelVersionId + "'";
760 String queryPrefix = "modelInfo";
761 String resourceType = "model-ver";
762 SvcLogicContext vfmCtx = readResource(resourceKey, queryPrefix, resourceType);
763 log.info("getModelVersionInfo():::modelname=" + vfmCtx.getAttribute("modelInfo.model-name"));
764 modelCtx.setAttribute(prefix + "vfModule.model-name", vfmCtx.getAttribute("modelInfo.model-name"));
765 log.info("End - getModelVersionInfo");
769 public void getIdentityUrl(Map<String, String> params, SvcLogicContext ctx) throws Exception{
770 log.info("Recieved getIdentityUrl call with params : "+params);
771 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
772 prefix = StringUtils.isNotBlank(prefix) ? (prefix + ".") : "";
774 String cloudOwner = params.get("cloudOwner");
775 String cloudRegionId = params.get("cloudRegionId");
776 // per comment from git review, we need to sanitize the two parameters
777 // to avoid security issues
778 cloudOwner = cloudOwner.replaceAll("'", "");
779 cloudRegionId = cloudRegionId.replaceAll("'", "");
780 log.debug("cloudOwner" +cloudOwner +"," +"cloudRegionId"+ cloudRegionId);
781 String resourceKey = "depth = '" + 0 + "' AND cloud-region.cloud-owner = '" + cloudOwner +
782 "' AND cloud-region.cloud-region-id = '" + cloudRegionId + "'";
783 String queryPrefix ="urlInfo";
784 String resourceType = "cloud-region";
785 SvcLogicContext urlCtx = readResource(resourceKey, queryPrefix, resourceType);
786 log.info("IdentityUrl: "+urlCtx.getAttribute("urlInfo.identity-url"));
787 log.info("Prefix for getIdentityUrl: "+prefix+"cloud-region.identity-url");
788 ctx.setAttribute(prefix+"cloud-region.identity-url", urlCtx.getAttribute("urlInfo.identity-url"));