2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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 * ============LICENSE_END=========================================================
24 package org.onap.appc.aai.client.aai;
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
28 import java.util.ArrayList;
29 import java.util.HashMap;
30 import java.util.List;
32 import org.apache.commons.lang3.StringUtils;
33 import org.apache.commons.lang3.math.NumberUtils;
34 import org.onap.appc.aai.client.AppcAaiClientConstant;
35 import org.onap.ccsdk.sli.adaptors.aai.AAIClient;
36 import org.onap.ccsdk.sli.adaptors.aai.AAIService;
37 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
38 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
39 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
40 import org.osgi.framework.BundleContext;
41 import org.osgi.framework.FrameworkUtil;
42 import org.osgi.framework.ServiceReference;
44 public class AaiService {
46 private static final EELFLogger log = EELFManager.getInstance().getLogger(AaiService.class);
47 private static final String STR_VNF_ID = "generic-vnf.vnf-id = '";
48 private static final String STR_VNFC_REF = "vnfcReference[";
49 private static final String STR_VNFC_REF_KEY = "VNFCREFKEY ";
50 private static final String STR_AAI_REF_KEY = "AAIREFKEY ";
51 private static final String STR_RELATIONSHIP_LIST = ".relationship-list.relationship[";
52 private static final String STR_VNFC_NAME = "vnfc.vnfc-name = '";
53 private static final String QUERY_STR_VNFC_NAME = "VNFCNAME IN INSERTVNFCS ";
55 private static final String PARAM_GENERIC_VNF = "generic-vnf";
56 private static final String PARAM_VNF_INFO = "vnfInfo";
57 private static final String PARAM_VSERVER = "vserver";
58 private static final String PARAM_VM_INFO = "vmInfo";
59 private static final String PARAM_PROV_STATUS = "prov-status";
60 private static final String PARAM_VAL_NVTPROV = "NVTPROV";
62 private static final String ATTR_VSERVER_ID = "vserver-id";
63 private static final String ATTR_TENANT_ID = "tenant-id";
64 private static final String ATTR_CLOUD_OWNER = "cloud-owner";
65 private static final String ATTR_CLOUD_REGION_ID = "cloud-region-id";
66 private static final String ATTR_VNFC_COUNT = "vm.vnfc-count";
67 private static final String ATTR_VNFC_NAME = "vnfc-name";
68 private static final String ATTR_VNFC_FUNC_CODE = "VNFC-FUNCTION-CODE";
69 private static final String ATTR_VSERVER_NAME = "vserver-name";
70 private static final String ATTR_VNF_ID = "vnf-id";
72 private AAIClient aaiClient;
74 public AaiService(AAIClient aaiClient) {
75 this.aaiClient = aaiClient;
79 BundleContext bctx = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
80 ServiceReference sref = bctx.getServiceReference(AAIService.class);
81 aaiClient = (AAIClient) bctx.getService(sref);
84 public void getGenericVnfInfo(Map<String, String> params, SvcLogicContext ctx)
85 throws AaiServiceInternalException, SvcLogicException {
87 String vnfId = params.get("vnfId");
88 if (StringUtils.isBlank(vnfId)) {
89 throw new AaiServiceInternalException("VnfId is missing");
91 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
92 prefix = StringUtils.isNotBlank(prefix) ? (prefix + ".") : "";
93 String resourceKey = STR_VNF_ID + vnfId + "'";
94 SvcLogicContext vnfCtx = readResource(resourceKey, PARAM_VNF_INFO, PARAM_GENERIC_VNF);
96 ctx.setAttribute(prefix + "vnf.vnf-name", vnfCtx.getAttribute("vnfInfo.vnf-name"));
97 ctx.setAttribute(prefix + "vnf.vnf-type", vnfCtx.getAttribute("vnfInfo.vnf-type"));
98 ctx.setAttribute(prefix + "vnf.prov-status", vnfCtx.getAttribute("vnfInfo.prov-status"));
99 ctx.setAttribute(prefix + "vnf.orchestration-status", vnfCtx.getAttribute("vnfInfo.orchestration-status"));
100 ctx.setAttribute(prefix + "vnf.ipv4-oam-address", vnfCtx.getAttribute("vnfInfo.ipv4-oam-address"));
103 String relLen = vnfCtx.getAttribute("vnfInfo.relationship-list.relationship_length");
104 int relationshipLength = 0;
105 if (relLen != null) {
106 relationshipLength = Integer.parseInt(relLen);
108 log.info("RELLEN " + relationshipLength);
109 for (int i = 0; i < relationshipLength; i++) {
110 String vserverId = getRelationshipValue(i, vnfCtx, PARAM_VSERVER, "vserver.vserver-id", PARAM_VNF_INFO);
111 String tenantId = getRelationshipValue(i, vnfCtx, PARAM_VSERVER, "tenant.tenant-id", PARAM_VNF_INFO);
112 String cloudOwner = getRelationshipValue(i, vnfCtx, PARAM_VSERVER, "cloud-region.cloud-owner",
114 String cloudRegionId =
115 getRelationshipValue(i, vnfCtx, PARAM_VSERVER, "cloud-region.cloud-region-id", PARAM_VNF_INFO);
116 if (vserverId != null) {
117 log.info("VSERVER KEYS " + vserverId + " " + tenantId + " " + cloudOwner + " " + cloudRegionId);
118 String vnfPrefix = prefix + "vm[" + vmCount + "].";
119 ctx.setAttribute(vnfPrefix + ATTR_VSERVER_ID, vserverId);
120 ctx.setAttribute(vnfPrefix + ATTR_TENANT_ID, tenantId);
121 ctx.setAttribute(vnfPrefix + ATTR_CLOUD_OWNER, cloudOwner);
122 ctx.setAttribute(vnfPrefix + ATTR_CLOUD_REGION_ID, cloudRegionId);
126 ctx.setAttribute(prefix + "vm-count", String.valueOf(vmCount));
127 log.info("VMCOUNT FROM VNF INFO " + ctx.getAttribute(prefix + "vm-count"));
130 public void getVMInfo(Map<String, String> params, SvcLogicContext ctx)
131 throws SvcLogicException {
134 log.info("Received getVmInfo call with params : " + params);
135 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
136 prefix = StringUtils.isNotBlank(prefix) ? (prefix + ".") : "";
138 ctx.setAttribute(prefix + ATTR_VNFC_COUNT, String.valueOf(vnfcCount)); // In case no vnfcs are found
140 VServerInfo vServerInfo = new VServerInfo(params);
143 "vserver.vserver-id = '" + vServerInfo.getVserverId() + "' AND tenant.tenant-id = '" + vServerInfo
145 + "' AND cloud-region.cloud-owner = '" + vServerInfo.getCloudOwner()
146 + "' AND cloud-region.cloud-region-id = '"
147 + vServerInfo.getCloudRegionId() + "'";
149 SvcLogicContext vmCtx = readResource(resourceKey, PARAM_VM_INFO, PARAM_VSERVER);
150 ctx.setAttribute(prefix + "vm.prov-status", vmCtx.getAttribute("vmInfo.prov-status"));
151 ctx.setAttribute(prefix + "vm.vserver-name", vmCtx.getAttribute("vmInfo.vserver-name"));
153 String relLen = vmCtx.getAttribute("vmInfo.relationship-list.relationship_length");
154 int relationshipLength = 0;
155 if (relLen != null) {
156 relationshipLength = Integer.parseInt(relLen);
158 log.info("RELLEN" + relationshipLength);
159 for (int i = 0; i < relationshipLength; i++) {
160 String vfModuleId = getRelationshipValue(i, vmCtx, "vf-module", "vf-module.vf-module-id",
162 if (vfModuleId != null) {
163 ctx.setAttribute(prefix + "vm.vf-module-id", vfModuleId);
166 String vnfcName = getRelationshipValue(i, vmCtx, "vnfc", "vnfc.vnfc-name", PARAM_VM_INFO);
167 if (vnfcName != null) {
168 ctx.setAttribute(prefix + "vm.vnfc[" + vnfcCount + "].vnfc-name", vnfcName);
172 } // relationshipLength
173 ctx.setAttribute(prefix + ATTR_VNFC_COUNT, String.valueOf(vnfcCount));
174 log.info("VSERVERNAME " + ctx.getAttribute(prefix + "vm.vserver-name") + " HAS NUM VNFCS = "
175 + ctx.getAttribute(prefix + ATTR_VNFC_COUNT));
176 } catch (Exception e) {
177 log.error("An error occurred when fetching Vm info", e);
178 throw new SvcLogicException("Failed to fetch VM info", e);
182 private String getRelationshipValue(int i, SvcLogicContext ctx, String relatedTo, String relationshipKey,
185 if (relatedTo.equals(ctx.getAttribute(prefix + STR_RELATIONSHIP_LIST + i + "].related-to"))) {
186 log.info("RELATEDTO " + relatedTo);
187 int relationshipDataLength = 0;
189 ctx.getAttribute(prefix + STR_RELATIONSHIP_LIST + i + "].relationship-data_length");
190 if (relDataLen != null) {
191 relationshipDataLength = Integer.parseInt(relDataLen);
194 for (int j = 0; j < relationshipDataLength; j++) {
196 String key = ctx.getAttribute(prefix + STR_RELATIONSHIP_LIST + i + "].relationship-data["
197 + j + "].relationship-key");
199 String value = ctx.getAttribute(prefix + STR_RELATIONSHIP_LIST + i + "].relationship-data["
200 + j + "].relationship-value");
202 log.info("GENERIC KEY " + key);
203 log.info("GENERIC VALUE " + value);
205 if (relationshipKey.equals(key)) {
209 } // relationshipDataLength
215 public void getVnfcInfo(Map<String, String> params, SvcLogicContext ctx)
216 throws AaiServiceInternalException, SvcLogicException {
217 log.info("Received getVnfc call with params : " + params);
219 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
220 prefix = StringUtils.isNotBlank(prefix) ? (prefix + ".") : "";
222 String vnfcName = params.get("vnfcName");
223 if (StringUtils.isBlank(vnfcName)) {
224 throw new AaiServiceInternalException("Vnfc Name is missing");
227 String resourceKey = STR_VNFC_NAME + vnfcName + "'";
228 SvcLogicContext vnfcCtx = readResource(resourceKey, "vnfcInfo", "vnfc");
230 // Changes for US 315820 for 1710 vnfc-type renamed to nfc-function,vnfc-function-code renamed to
233 ctx.setAttribute(prefix + "vnfc.vnfc-type", vnfcCtx.getAttribute("vnfcInfo.nfc-function"));
234 ctx.setAttribute(prefix + "vnfc.vnfc-function-code", vnfcCtx.getAttribute("vnfcInfo.nfc-naming-code"));
235 ctx.setAttribute(prefix + "vnfc.group-notation", vnfcCtx.getAttribute("vnfcInfo.group-notation"));
236 ctx.setAttribute(prefix + "vnfc.ipaddress-v4-oam-vip", vnfcCtx.getAttribute("vnfcInfo.ipaddress-v4-oam-vip"));
240 public void insertVnfcs(Map<String, String> params, SvcLogicContext ctx, int vnfcRefLen, int vmCount,
241 String vfModuleIdFromRequest)
242 throws AaiServiceInternalException, SvcLogicException {
243 log.info("Received insertVnfcs call with params : " + params);
245 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
247 prefix = StringUtils.isNotBlank(prefix) ? (prefix + ".") : "";
249 log.debug("vnfcRefIndx" + vnfcRefIndx);
250 for (int i = 0; i < vmCount; i++) {
251 String aaiRefKey = prefix + "vm[" + i + "].";
253 //ConfigScaleOut - Do not process vms that are not associated with vfmodule id if vfmodule id is present
254 if (StringUtils.isNotBlank(vfModuleIdFromRequest)) {
255 String vmVfModuleId = ctx.getAttribute(aaiRefKey + "vf-module-id");
256 log.info("insertVnfcs():::vfModule for vm is=" + vmVfModuleId);
257 if (StringUtils.isBlank(vmVfModuleId) || !StringUtils
258 .equalsIgnoreCase(vmVfModuleId, vfModuleIdFromRequest)) {
263 log.info(QUERY_STR_VNFC_NAME + ctx.getAttribute(aaiRefKey + ATTR_VNFC_NAME));
264 String vnfcNameAAI = ctx.getAttribute(aaiRefKey + ATTR_VNFC_NAME);
266 // Get Vnfc_reference data from the table
267 String vnfcRefKey = STR_VNFC_REF + vnfcRefIndx + "].";
269 log.info(STR_VNFC_REF_KEY + vnfcRefKey);
270 log.info(STR_AAI_REF_KEY + aaiRefKey);
272 String groupNotationType = ctx.getAttribute(vnfcRefKey + "GROUP-NOTATION-TYPE");
273 String groupNotationValue = ctx.getAttribute(vnfcRefKey + "GROUP-NOTATION-VALUE");
274 String vnfcType = ctx.getAttribute(vnfcRefKey + "VNFC-TYPE");
275 String vnfcFuncCode = ctx.getAttribute(vnfcRefKey + ATTR_VNFC_FUNC_CODE);
276 String populateIpAddressV4OamVip = ctx.getAttribute(vnfcRefKey + "IPADDRESS-V4-OAM-VIP");
278 // Get vnfc Data to be added
279 String vserverName = ctx.getAttribute(aaiRefKey + ATTR_VSERVER_NAME);
280 String vnfcName = vserverName + vnfcFuncCode + "001";
281 String groupNotation = getGroupNotation(groupNotationType, groupNotationValue, vnfcName, vserverName,
282 prefix, ctx, vnfcType, vnfcFuncCode, vmCount);
284 String ipAddressV4OamVip = null;
285 if ("Y".equals(populateIpAddressV4OamVip)) {
286 ipAddressV4OamVip = ctx.getAttribute("vnf-host-ip-address"); // from input
288 Map<String, String> vnfcParams =
289 populateVnfcParams(ctx, aaiRefKey, ipAddressV4OamVip, groupNotation, vnfcType, vnfcFuncCode);
291 log.info("Vnfc name from AAI: " + vnfcNameAAI);
292 log.info("Vnfc name generated: " + vnfcName);
294 if (StringUtils.isNotBlank(vnfcNameAAI)) {
295 if (vnfcName.equalsIgnoreCase(vnfcNameAAI)) {
296 updateVnfcStatus(vnfcNameAAI, params, prefix);
302 addVnfc(vnfcName, vnfcParams, prefix);
304 // Add VNFC Info to context for current added VNFC
305 ctx.setAttribute(aaiRefKey + ATTR_VNFC_NAME, vnfcName);
306 ctx.setAttribute(aaiRefKey + "vnfc-type", vnfcType);
307 ctx.setAttribute(aaiRefKey + "vnfc-function-code", vnfcFuncCode);
308 ctx.setAttribute(aaiRefKey + "group-notation", groupNotation);
312 public List<String> getVnfcData(Map<String, String> params, SvcLogicContext ctx, int vnfcRefLen, int vmCount) {
314 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
315 prefix = StringUtils.isNotBlank(prefix) ? (prefix + ".") : "";
316 List<String> vnfcNames = new ArrayList<>();
317 int vnfcRefIndx = -1;
318 for (int i = 0; i < vmCount; i++) {
319 String aaiRefKey = prefix + "vm[" + i + "].";
320 log.info(QUERY_STR_VNFC_NAME + ctx.getAttribute(aaiRefKey + ATTR_VNFC_NAME));
321 if (ctx.getAttribute(aaiRefKey + ATTR_VNFC_NAME) != null) {
326 String vnfcRefKey = STR_VNFC_REF + vnfcRefIndx + "].";
327 log.info(STR_VNFC_REF_KEY + vnfcRefKey);
328 log.info(STR_AAI_REF_KEY + aaiRefKey);
329 String vnfcFuncCode = ctx.getAttribute(vnfcRefKey + ATTR_VNFC_FUNC_CODE);
331 // Get vnfc Data to be added
332 String vserverName = ctx.getAttribute(aaiRefKey + ATTR_VSERVER_NAME);
333 String vnfcName = vserverName + vnfcFuncCode + "001";
335 vnfcNames.add(vnfcName);
341 private Map<String, String> populateVnfcParams(SvcLogicContext ctx, String aaiRefKey, String ipAddressV4OamVip,
342 String groupNotation, String vnfcType, String vnfcFuncCode) {
344 Map<String, String> vnfcParams = new HashMap<>();
346 // Changes for vnfc-type renamed to nfc-function,vnfc-function-code renamed to
348 vnfcParams.put("nfc-naming-code", vnfcFuncCode);
349 vnfcParams.put("nfc-function", vnfcType);
350 vnfcParams.put("ipaddress-v4-oam-vip", ipAddressV4OamVip);
351 vnfcParams.put(PARAM_PROV_STATUS, PARAM_VAL_NVTPROV);
352 vnfcParams.put("orchestration-status", "CONFIGURED");
353 vnfcParams.put("in-maint", "false");
354 vnfcParams.put("is-closed-loop", "false");
355 vnfcParams.put("group-notation", groupNotation);
356 vnfcParams.put("relationship-list.relationship[0].related-to", PARAM_VSERVER);
357 vnfcParams.put("relationship-list.relationship[0].relationship-data[0].relationship-key", "vserver.vserver-id");
358 vnfcParams.put("relationship-list.relationship[0].relationship-data[0].relationship-value",
359 ctx.getAttribute(aaiRefKey + ATTR_VSERVER_ID));
360 vnfcParams.put("relationship-list.relationship[0].relationship-data[1].relationship-key", "tenant.tenant-id");
361 vnfcParams.put("relationship-list.relationship[0].relationship-data[1].relationship-value",
362 ctx.getAttribute(aaiRefKey + ATTR_TENANT_ID));
363 vnfcParams.put("relationship-list.relationship[0].relationship-data[2].relationship-key",
364 "cloud-region.cloud-owner");
365 vnfcParams.put("relationship-list.relationship[0].relationship-data[2].relationship-value",
366 ctx.getAttribute(aaiRefKey + ATTR_CLOUD_OWNER));
367 vnfcParams.put("relationship-list.relationship[0].relationship-data[3].relationship-key",
368 "cloud-region.cloud-region-id");
369 vnfcParams.put("relationship-list.relationship[0].relationship-data[3].relationship-value",
370 ctx.getAttribute(aaiRefKey + ATTR_CLOUD_REGION_ID));
371 vnfcParams.put("relationship-list.relationship[1].related-to", PARAM_GENERIC_VNF);
372 vnfcParams.put("relationship-list.relationship[1].relationship-data[0].relationship-key", "generic-vnf.vnf-id");
373 vnfcParams.put("relationship-list.relationship[1].relationship-data[0].relationship-value",
374 ctx.getAttribute(ATTR_VNF_ID));
375 vnfcParams.put("relationship-list.relationship[2].related-to", "vf-module");
376 vnfcParams.put("relationship-list.relationship[2].relationship-data[0].relationship-key", "generic-vnf.vnf-id");
377 vnfcParams.put("relationship-list.relationship[2].relationship-data[0].relationship-value",
378 ctx.getAttribute(ATTR_VNF_ID));
379 vnfcParams.put("relationship-list.relationship[2].relationship-data[1].relationship-key",
380 "vf-module.vf-module-id");
381 vnfcParams.put("relationship-list.relationship[2].relationship-data[1].relationship-value",
382 ctx.getAttribute(aaiRefKey + "vf-module-id"));
387 public void addVnfc(String vnfcName, Map<String, String> params, String prefix)
388 throws AaiServiceInternalException, SvcLogicException {
390 log.info("Received addVnfc call with vnfcName : " + vnfcName);
391 log.info("Received addVnfc call with params : " + params);
392 String resourceKey = STR_VNFC_NAME + vnfcName + "'";
393 log.info("Received addVnfc call with resourceKey : " + resourceKey);
395 SvcLogicContext vnfcCtx = new SvcLogicContext();
396 SvcLogicResource.QueryStatus response =
397 aaiClient.save("vnfc", true, false, resourceKey, params, prefix, vnfcCtx);
399 if (SvcLogicResource.QueryStatus.SUCCESS.equals(response)) {
400 log.info("Added VNFC SUCCESSFULLY " + vnfcName);
401 } else if (SvcLogicResource.QueryStatus.FAILURE.equals(response)) {
402 throw new AaiServiceInternalException("VNFC Add failed for for vnfc_name " + vnfcName);
406 public String getGroupNotation(String groupNotationType, String groupNotationValue, String vnfcName,
407 String vserverName, String prefix, SvcLogicContext ctx, String vnfcRefVnfcType, String vnfcFuncCode,
410 String groupNotation = null;
412 if ("fixed-value".equals(groupNotationType)) {
413 groupNotation = groupNotationValue;
414 } else if ("first-vnfc-name".equals(groupNotationType)) {
417 * If the group-notation-type value = ?first-vnfc-name?,
418 * then populate the group-notation value with the concatenation of
419 * [vnfc name associated with the first vnfc for the vnfc-type (e.g., *******)]
420 * and [the value in group-notation-value (e.g., pair)].
421 * There may be several vnfc-types associated with the VM?s.
423 /* Vnfc-type should be from refrence data */
425 /* vDBE has 2 VNFCs with same VNFC type . The pair name should be same for both . */
427 * When first VNFC is added details should be added to context so FirstVnfcName doesnt return null second
430 String tmpVnfcName = getFirstVnfcNameForVnfcType(ctx, prefix, vnfcRefVnfcType);
432 log.info("RETURNED FIRSTVNFCNAME" + tmpVnfcName);
433 log.info("CURRENTVNFCNAME" + vnfcName);
434 groupNotation = resolveGroupNotation(groupNotationValue, vnfcName, tmpVnfcName);
435 } else if ("relative-value".equals(groupNotationType)) {
438 * If the group-notation-type = ?relative-value?, then find the group-notation value
439 * from the prior vnfc (where prior means the vnfc with where the last three digits of the
440 * vm-name is one lower than the current one; note that this vnfc may have been previously configured.)
441 * 1. If the group-notation-value = next, then add 1 to the group-notation value from the prior vnfc and use
443 * 2. If the group-notation-value = same, then use the group-notation-value from the prior vnfc record
446 // next and same cant be defined for first VM. if next will not generate grpNotation if Prior is not a
448 String tmpVserverName;
449 if (vserverName != null) {
451 String vmNamePrefix = vserverName.substring(0, vserverName.length() - 3);
452 String lastThreeChars = vserverName.substring(vserverName.length() - 3);
454 if (NumberUtils.isDigits(lastThreeChars)) {
455 int vmNum = Integer.parseInt(lastThreeChars) - 1;
456 String formatted = String.format("%03d", vmNum);
458 log.info("FORMATTED " + formatted);
460 tmpVserverName = vmNamePrefix + formatted;
462 String priorGroupNotation = getGroupNotationForVServer(ctx, prefix, tmpVserverName);
463 groupNotation = resolveGroupNotation(groupNotationValue, priorGroupNotation);
466 } else if ("existing-value".equals(groupNotationType)) {
467 /* 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.
468 * Verify that the group-notation value is the same for all such records found in inventory.
469 * 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.
470 * If all records match, use the same group-notation value for the new vnfc record as found in the existing vnfc records.
472 groupNotation = getGroupNotationForExistigValue(ctx, prefix, vnfcFuncCode, vmCount);
475 log.info("RETURNED GROUPNOTATION " + groupNotation);
476 return groupNotation;
479 private String resolveGroupNotation(String groupNotationValue, String vnfcName, String tmpVnfcName) {
480 if (tmpVnfcName == null) {
481 log.info("CURRENTVNFCNAME" + vnfcName);
482 // No Vnfcs currently exist. Use Current vnfcName
483 return vnfcName + groupNotationValue;
485 return tmpVnfcName + groupNotationValue;
489 private String resolveGroupNotation(String groupNotationValue, String priorGroupNotation) {
490 if ("same".equals(groupNotationValue)) {
491 return priorGroupNotation;
492 } else if ("next".equals(groupNotationValue) && priorGroupNotation != null
493 && NumberUtils.isDigits(priorGroupNotation)) {
495 int nextGrpNotation = Integer.parseInt(priorGroupNotation) + 1;
496 return String.valueOf(nextGrpNotation);
501 public String getGroupNotationForExistigValue(SvcLogicContext ctx, String prefix, String vnfcFuncCode,
503 String vfModuleId = ctx.getAttribute("req-vf-module-id"); //Coming from request-params
504 boolean first = true;
505 String aaiGroupNotationValue = null;
506 for (int i = 0; i < vmCount; i++) {
507 String ind = "tmp.vnfInfo.vm[" + i + "].";
508 String aaiFuncCode = ctx.getAttribute(ind + "vnfc-function-code");
509 String aaiGroupNotation = ctx.getAttribute(ind + "group-notation");
510 String aaiVfModuleId = ctx.getAttribute(ind + "vf-module-id");
512 log.info("getGroupNotationForExistigValue()::: vfModuleId=" + vfModuleId + ", aaiFuncCode=" + aaiFuncCode
513 + ", aaiGroupNotation=" + aaiGroupNotation + ",aaiVfMOduleId=" + aaiVfModuleId);
515 if (StringUtils.isNotBlank(aaiFuncCode) && aaiFuncCode.equals(vnfcFuncCode) &&
516 (StringUtils.isNotBlank(vfModuleId) && StringUtils.isNotBlank(aaiVfModuleId) && aaiVfModuleId
517 .equals(vfModuleId))) {
518 if (null == aaiGroupNotationValue && first) {
519 if (null == aaiGroupNotation) {//Return if null
522 aaiGroupNotationValue = ctx.getAttribute(ind + "group-notation");
525 if (!StringUtils.equals(aaiGroupNotationValue, ctx.getAttribute(ind + "group-notation"))) {
526 log.info("Values are different, returning null");
533 return aaiGroupNotationValue;
536 public String getGroupNotationForVServer(SvcLogicContext ctx, String prefix, String vserverName) {
538 String vmCountStr = ctx.getAttribute(prefix + "vnf.vm-count");
540 if (vmCountStr == null) {
544 int vmCount = Integer.parseInt(vmCountStr);
545 for (int i = 0; i < vmCount; i++) {
547 String tmpVserver = ctx.getAttribute(prefix + "vm[" + i + "].vserver-name");
549 if (vserverName.equals(tmpVserver)) {
550 return ctx.getAttribute(prefix + "vm[" + i + "].group-notation");
556 public String getFirstVnfcNameForVnfcType(SvcLogicContext ctx, String prefix, String vnfcRefVnfcType) {
558 String vmCountStr = ctx.getAttribute(prefix + "vnf.vm-count");
559 if (vmCountStr == null) {
562 int vmCount = Integer.parseInt(vmCountStr);
563 for (int i = 0; i < vmCount; i++) {
565 String tmpvnfcType = ctx.getAttribute(prefix + "vm[" + i + "].vnfc-type");
567 if (vnfcRefVnfcType.equals(tmpvnfcType)) {
568 return ctx.getAttribute(prefix + "vm[" + i + "].vnfc-name");
574 public void updateVServerStatus(Map<String, String> params, SvcLogicContext ctx, int vmCount)
575 throws AaiServiceInternalException, SvcLogicException {
576 log.info("Received updateVServerStatus call with params : " + params);
578 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
580 prefix = StringUtils.isNotBlank(prefix) ? (prefix + ".") : "";
581 Map<String, String> vServerParams = new HashMap<>();
583 // TODO - Should this just update prov-status or both? What about generic-vnf status? Will that be updated by
586 vServerParams.put(PARAM_PROV_STATUS, PARAM_VAL_NVTPROV);
588 for (int i = 0; i < vmCount; i++) {
589 String aaiRefKey = prefix + "vm[" + i + "].";
591 log.info("VNFCNAME IN UpdateVServer " + ctx.getAttribute(aaiRefKey + ATTR_VNFC_NAME));
593 if (ctx.getAttribute(aaiRefKey + ATTR_VNFC_NAME) != null) {
597 String resourceKey = "vserver.vserver-id = '" + ctx.getAttribute(aaiRefKey + ATTR_VSERVER_ID) + "'"
598 + " AND tenant.tenant-id = '" + ctx.getAttribute(aaiRefKey + ATTR_TENANT_ID) + "'"
599 + " AND cloud-region.cloud-owner = '" + ctx.getAttribute(aaiRefKey + ATTR_CLOUD_OWNER) + "'"
600 + " AND cloud-region.cloud-region-id = '" + ctx.getAttribute(aaiRefKey + ATTR_CLOUD_REGION_ID) + "'";
602 updateResource(PARAM_VSERVER, resourceKey, vServerParams);
606 public void updateVnfStatus(Map<String, String> params, SvcLogicContext ctx)
607 throws AaiServiceInternalException, SvcLogicException {
608 log.info("Received updateVnfStatus call with params : " + params);
610 Map<String, String> vnfParams = new HashMap<>();
612 // TODO - Should this just update prov-status or both? What about generic-vnf status? Will that be updated by
615 vnfParams.put(PARAM_PROV_STATUS, PARAM_VAL_NVTPROV);
617 String resourceKey = STR_VNF_ID + ctx.getAttribute(ATTR_VNF_ID) + "'";
619 updateResource(PARAM_GENERIC_VNF, resourceKey, vnfParams);
622 public void updateResource(String resource, String resourceKey, Map<String, String> params)
623 throws AaiServiceInternalException, SvcLogicException {
625 log.info("Received updateResource call with Key : " + resourceKey);
627 SvcLogicContext ctx = new SvcLogicContext();
628 SvcLogicResource.QueryStatus response = aaiClient.update(resource, resourceKey, params, "tmp.update", ctx);
630 if (SvcLogicResource.QueryStatus.SUCCESS.equals(response)) {
631 log.info("Updated " + resource + " SUCCESSFULLY for " + resourceKey);
633 } else if (SvcLogicResource.QueryStatus.FAILURE.equals(response)) {
634 throw new AaiServiceInternalException(resource + " Update failed for " + resourceKey);
638 public SvcLogicContext readResource(String query, String prefix, String resourceType)
639 throws AaiServiceInternalException, SvcLogicException {
640 SvcLogicContext resourceContext = new SvcLogicContext();
642 SvcLogicResource.QueryStatus response =
643 aaiClient.query(resourceType, false, null, query, prefix, null, resourceContext);
644 log.info("AAIResponse: " + response.toString());
645 if (!SvcLogicResource.QueryStatus.SUCCESS.equals(response)) {
646 throw new AaiServiceInternalException("Error Retrieving " + resourceType + " from A&AI");
648 return resourceContext;
651 // Added for Backward Compatibility
652 public void checkAndUpdateVnfc(Map<String, String> params, SvcLogicContext ctx, int vnfcRefLen, int vmCount)
653 throws AaiServiceInternalException, SvcLogicException {
654 log.info("Received checkAndUpdateVnfcStatus call with params : " + params);
656 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
658 prefix = StringUtils.isNotBlank(prefix) ? (prefix + ".") : "";
660 for (int i = 0; i < vmCount; i++) {
661 String aaiRefKey = prefix + "vm[" + i + "].";
663 log.info(QUERY_STR_VNFC_NAME + aaiRefKey + "vnfc-name:" + ctx.getAttribute(aaiRefKey + ATTR_VNFC_NAME));
665 String vnfcNameAai = ctx.getAttribute(aaiRefKey + ATTR_VNFC_NAME);
667 if (StringUtils.isNotBlank(vnfcNameAai)) {
668 // Get Vnfc_reference data
669 for (int vnfcRefIndx = 0; vnfcRefIndx < vnfcRefLen; vnfcRefIndx++) {
671 String vnfcRefKey = STR_VNFC_REF + vnfcRefIndx + "].";
673 log.info(STR_VNFC_REF_KEY + vnfcRefKey);
674 log.info(STR_AAI_REF_KEY + aaiRefKey);
676 String vnfcFuncCode = ctx.getAttribute(vnfcRefKey + ATTR_VNFC_FUNC_CODE);
677 String vserverName = ctx.getAttribute(aaiRefKey + ATTR_VSERVER_NAME);
678 String vnfcNameReference = vserverName + vnfcFuncCode + "001";
679 tryUpdateVnfcStatus(params, prefix, vnfcNameAai, vnfcNameReference);
685 private void tryUpdateVnfcStatus(Map<String, String> params, String prefix, String vnfcNameAai,
686 String vnfcNameReference) throws AaiServiceInternalException, SvcLogicException {
687 if (vnfcNameAai.equals(vnfcNameReference)) {
688 updateVnfcStatus(vnfcNameAai, params, prefix);
692 public void updateVnfcStatus(String vnfcName, Map<String, String> params, String prefix)
693 throws AaiServiceInternalException, SvcLogicException {
695 log.info("Received updateVnfcStatus call with vnfcName : " + vnfcName);
696 log.info("Received updateVnfcStatus call with params : " + params);
698 String resourceKey = STR_VNFC_NAME + vnfcName + "'";
699 log.info("Received updateVnfcStatus call with resourceKey : " + resourceKey);
701 Map<String, String> vnfcParams = new HashMap<>();
702 vnfcParams.put(PARAM_PROV_STATUS, PARAM_VAL_NVTPROV);
703 vnfcParams.put("orchestration-status", "CONFIGURED");
705 log.info("In updateVnfcStatus call with vnfcParams : " + vnfcParams);
707 updateResource("vnfc", resourceKey, vnfcParams);
709 log.info("End of updateVnfcStatus");
712 public void updateVnfStatusWithOAMAddress(Map<String, String> params, SvcLogicContext ctx)
713 throws AaiServiceInternalException, SvcLogicException {
714 log.info("Received updateVnfStatusWithOAMAddress call with params : " + params);
716 String ipAddress = ctx.getAttribute("vnf-host-ip-address");
717 log.debug("Vnf-host-ip-address" + ipAddress);
719 Map<String, String> vnfParams = new HashMap<>();
720 vnfParams.put("ipv4-oam-address", ipAddress);
721 String resourceKey = STR_VNF_ID + ctx.getAttribute(ATTR_VNF_ID) + "'";
722 updateResource(PARAM_GENERIC_VNF, resourceKey, vnfParams);
725 public void getVfModuleInfo(Map<String, String> params, SvcLogicContext vfModuleCtx) throws Exception {
726 log.info("Received getVfModuleInfo call with params : " + params);
727 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
728 prefix = StringUtils.isNotBlank(prefix) ? (prefix + ".") : "";
730 String vnfId = params.get("vnfId");
731 String vfModuleId = params.get("vfModuleId");
732 String resourceKey = "generic-vnf.vnf-id = '" + vnfId +
733 "' AND vf-module.vf-module-id = '" + vfModuleId + "'";
734 String queryPrefix = "vfModuleInfo";
735 String resourceType = "vf-module";
736 SvcLogicContext vfmCtx = readResource(resourceKey, queryPrefix, resourceType);
737 String modelInvariantId = vfmCtx.getAttribute("vfModuleInfo.model-invariant-id");
738 log.info("getVfModuleInfo():::modelInvariant=" + modelInvariantId);
739 vfModuleCtx.setAttribute(prefix + "vfModule.model-invariant-id",
740 vfmCtx.getAttribute("vfModuleInfo.model-invariant-id"));
742 .setAttribute(prefix + "vfModule.model-version-id", vfmCtx.getAttribute("vfModuleInfo.model-version-id"));
743 log.info("End - getVfModuleInfo");
746 public void getModelVersionInfo(Map<String, String> modelParams, SvcLogicContext modelCtx) throws Exception {
747 log.info("Received getModelVersionInfo call with params : " + modelParams);
748 String prefix = modelParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
749 prefix = StringUtils.isNotBlank(prefix) ? (prefix + ".") : "";
751 String modelInvariantId = modelParams.get("model-invariant-id");
752 String modelVersionId = modelParams.get("model-version-id");
753 String resourceKey = "model.model-invariant-id = '" + modelInvariantId +
754 "' AND model-ver.model-version-id = '" + modelVersionId + "'";
755 String queryPrefix = "modelInfo";
756 String resourceType = "model-ver";
757 SvcLogicContext vfmCtx = readResource(resourceKey, queryPrefix, resourceType);
758 log.info("getModelVersionInfo():::modelname=" + vfmCtx.getAttribute("modelInfo.model-name"));
759 modelCtx.setAttribute(prefix + "vfModule.model-name", vfmCtx.getAttribute("modelInfo.model-name"));
760 log.info("End - getModelVersionInfo");