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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.aai.client.aai;
27 import java.util.ArrayList;
28 import java.util.HashMap;
29 import java.util.List;
31 import org.apache.commons.lang3.StringUtils;
32 import org.apache.commons.lang3.math.NumberUtils;
33 import org.onap.appc.aai.client.AppcAaiClientConstant;
34 import org.onap.ccsdk.sli.adaptors.aai.AAIClient;
35 import org.onap.ccsdk.sli.adaptors.aai.AAIService;
36 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
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;
41 import com.att.eelf.configuration.EELFLogger;
42 import com.att.eelf.configuration.EELFManager;
44 public class AaiService {
46 private static final EELFLogger log = EELFManager.getInstance().getLogger(AaiService.class);
47 private AAIClient aaiClient;
49 public AaiService(AAIClient aaiClient) {
50 this.aaiClient = aaiClient;
54 BundleContext bctx = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
55 ServiceReference sref = bctx.getServiceReference(AAIService.class);
56 aaiClient = (AAIClient) bctx.getService(sref);
59 public void getGenericVnfInfo(Map<String, String> params, SvcLogicContext ctx) throws Exception {
61 String vnfId = params.get("vnfId");
62 if (StringUtils.isBlank(vnfId)) {
63 throw new Exception("VnfId is missing");
65 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
66 prefix = StringUtils.isNotBlank(prefix) ? (prefix + ".") : "";
67 String resourceKey = "generic-vnf.vnf-id = '" + vnfId + "'";
68 String resourceType = "generic-vnf";
69 String queryPrefix = "vnfInfo";
70 SvcLogicContext vnfCtx = readResource(resourceKey, queryPrefix, resourceType);
72 ctx.setAttribute(prefix + "vnf.vnf-name", vnfCtx.getAttribute("vnfInfo.vnf-name"));
73 ctx.setAttribute(prefix + "vnf.vnf-type", vnfCtx.getAttribute("vnfInfo.vnf-type"));
74 ctx.setAttribute(prefix + "vnf.prov-status", vnfCtx.getAttribute("vnfInfo.prov-status"));
75 ctx.setAttribute(prefix + "vnf.orchestration-status", vnfCtx.getAttribute("vnfInfo.orchestration-status"));
76 ctx.setAttribute(prefix + "vnf.ipv4-oam-address", vnfCtx.getAttribute("vnfInfo.ipv4-oam-address"));
79 String relLen = vnfCtx.getAttribute("vnfInfo.relationship-list.relationship_length");
80 int relationshipLength = 0;
82 relationshipLength = Integer.parseInt(relLen);
84 log.info("RELLEN " + relationshipLength);
85 for (int i = 0; i < relationshipLength; i++) {
86 String vserverId = getRelationshipValue(i, vnfCtx, "vserver", "vserver.vserver-id", "vnfInfo");
87 String tenantId = getRelationshipValue(i, vnfCtx, "vserver", "tenant.tenant-id", "vnfInfo");
88 String cloudOwner = getRelationshipValue(i, vnfCtx, "vserver", "cloud-region.cloud-owner", "vnfInfo");
89 String cloudRegionId =
90 getRelationshipValue(i, vnfCtx, "vserver", "cloud-region.cloud-region-id", "vnfInfo");
91 if (vserverId != null) {
92 log.info("VSERVER KEYS " + vserverId + " " + tenantId + " " + cloudOwner + " " + cloudRegionId);
93 String vnfPrefix = prefix + "vm[" + vmCount + "].";
94 ctx.setAttribute(vnfPrefix + "vserver-id", vserverId);
95 ctx.setAttribute(vnfPrefix + "tenant-id", tenantId);
96 ctx.setAttribute(vnfPrefix + "cloud-owner", cloudOwner);
97 ctx.setAttribute(vnfPrefix + "cloud-region-id", cloudRegionId);
101 ctx.setAttribute(prefix + "vm-count", String.valueOf(vmCount));
102 log.info("VMCOUNT FROM VNF INFO " + ctx.getAttribute(prefix + "vm-count"));
105 public void getVMInfo(Map<String, String> params, SvcLogicContext ctx) throws Exception {
106 log.info("Received getVmInfo call with params : " + params);
107 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
108 prefix = StringUtils.isNotBlank(prefix) ? (prefix + ".") : "";
110 ctx.setAttribute(prefix + "vm.vnfc-count", String.valueOf(vnfcCount)); // Incase no vnfcs are found
111 String vserverId = params.get("vserverId");
112 if (StringUtils.isBlank(vserverId)) {
113 throw new Exception("VServerId is missing");
115 String tenantId = params.get("tenantId");
116 if (StringUtils.isBlank(tenantId)) {
117 throw new Exception("TenantId is missing");
119 String cloudOwner = params.get("cloudOwner");
120 if (StringUtils.isBlank(cloudOwner)) {
121 throw new Exception("Cloud Owner is missing");
123 String cloudRegionId = params.get("cloudRegionId");
124 if (StringUtils.isBlank(cloudRegionId)) {
125 throw new Exception("Cloud region Id is missing");
127 String resourceKey = "vserver.vserver-id = '" + vserverId + "' AND tenant.tenant-id = '" + tenantId
128 + "' AND cloud-region.cloud-owner = '" + cloudOwner + "' AND cloud-region.cloud-region-id = '"
129 + cloudRegionId + "'";
130 String queryPrefix = "vmInfo";
131 String resourceType = "vserver";
132 SvcLogicContext vmCtx = readResource(resourceKey, queryPrefix, resourceType);
134 ctx.setAttribute(prefix + "vm.prov-status", vmCtx.getAttribute("vmInfo.prov-status"));
135 ctx.setAttribute(prefix + "vm.vserver-name", vmCtx.getAttribute("vmInfo.vserver-name"));
137 String relLen = vmCtx.getAttribute("vmInfo.relationship-list.relationship_length");
138 int relationshipLength = 0;
139 if (relLen != null) {
140 relationshipLength = Integer.parseInt(relLen);
142 log.info("RELLEN" + relationshipLength);
143 for (int i = 0; i < relationshipLength; i++) {
144 String vfModuleId = getRelationshipValue(i, vmCtx, "vf-module", "vf-module.vf-module-id", "vmInfo");
145 if (vfModuleId != null)
146 ctx.setAttribute(prefix + "vm.vf-module-id", vfModuleId);
148 String vnfcName = getRelationshipValue(i, vmCtx, "vnfc", "vnfc.vnfc-name", "vmInfo");
149 if (vnfcName != null) {
150 ctx.setAttribute(prefix + "vm.vnfc[" + vnfcCount + "].vnfc-name", vnfcName);
154 } // relationshipLength
155 ctx.setAttribute(prefix + "vm.vnfc-count", String.valueOf(vnfcCount));
156 log.info("VSERVERNAME " + ctx.getAttribute(prefix + "vm.vserver-name") + " HAS NUM VNFCS = "
157 + ctx.getAttribute(prefix + "vm.vnfc-count"));
160 private String getRelationshipValue(int i, SvcLogicContext ctx, String relatedTo, String relationshipKey,
161 String prefix) throws Exception {
163 if (relatedTo.equals(ctx.getAttribute(prefix + ".relationship-list.relationship[" + i + "].related-to"))) {
164 log.info("RELATEDTO " + relatedTo);
165 int relationshipDataLength = 0;
167 ctx.getAttribute(prefix + ".relationship-list.relationship[" + i + "].relationship-data_length");
168 if (relDataLen != null) {
169 relationshipDataLength = Integer.parseInt(relDataLen);
172 for (int j = 0; j < relationshipDataLength; j++) {
174 String key = ctx.getAttribute(prefix + ".relationship-list.relationship[" + i + "].relationship-data["
175 + j + "].relationship-key");
177 String value = ctx.getAttribute(prefix + ".relationship-list.relationship[" + i + "].relationship-data["
178 + j + "].relationship-value");
180 log.info("GENERIC KEY " + key);
181 log.info("GENERIC VALUE " + value);
183 if (relationshipKey.equals(key)) {
187 } // relationshipDataLength
193 public void getVnfcInfo(Map<String, String> params, SvcLogicContext ctx) throws Exception {
194 log.info("Received getVnfc call with params : " + params);
196 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
197 prefix = StringUtils.isNotBlank(prefix) ? (prefix + ".") : "";
199 String vnfcName = params.get("vnfcName");
200 if (StringUtils.isBlank(vnfcName)) {
201 throw new Exception("Vnfc Name is missing");
204 String resourceKey = "vnfc.vnfc-name = '" + vnfcName + "'";
205 String queryPrefix = "vnfcInfo";
206 String resourceType = "vnfc";
207 SvcLogicContext vnfcCtx = readResource(resourceKey, queryPrefix, resourceType);
209 // Changes for US 315820 for 1710 vnfc-type renamed to nfc-function,vnfc-function-code renamed to
212 ctx.setAttribute(prefix + "vnfc.vnfc-type", vnfcCtx.getAttribute("vnfcInfo.nfc-function"));
213 ctx.setAttribute(prefix + "vnfc.vnfc-function-code", vnfcCtx.getAttribute("vnfcInfo.nfc-naming-code"));
214 ctx.setAttribute(prefix + "vnfc.group-notation", vnfcCtx.getAttribute("vnfcInfo.group-notation"));
215 ctx.setAttribute(prefix + "vnfc.ipaddress-v4-oam-vip", vnfcCtx.getAttribute("vnfcInfo.ipaddress-v4-oam-vip"));
219 public void insertVnfcs(Map<String, String> params, SvcLogicContext ctx, int vnfcRefLen, int vmCount)
221 log.info("Received insertVnfcs call with params : " + params);
223 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
225 prefix = StringUtils.isNotBlank(prefix) ? (prefix + ".") : "";
227 log.debug("vnfcRefIndx" + vnfcRefIndx);
228 for (int i = 0; i < vmCount; i++) {
229 String aaiRefKey = prefix + "vm[" + i + "].";
231 log.info("VNFCNAME IN INSERTVNFCS " + ctx.getAttribute(aaiRefKey + "vnfc-name"));
232 String vnfcNameAAI = ctx.getAttribute(aaiRefKey + "vnfc-name");
234 // Get Vnfc_reference data from the table
235 String vnfcRefKey = "vnfcReference[" + vnfcRefIndx + "].";
237 log.info("VNFCREFKEY " + vnfcRefKey);
238 log.info("AAIREFKEY " + aaiRefKey);
240 String groupNotationType = ctx.getAttribute(vnfcRefKey + "GROUP-NOTATION-TYPE");
241 String groupNotationValue = ctx.getAttribute(vnfcRefKey + "GROUP-NOTATION-VALUE");
242 String vnfcType = ctx.getAttribute(vnfcRefKey + "VNFC-TYPE");
243 String vnfcFuncCode = ctx.getAttribute(vnfcRefKey + "VNFC-FUNCTION-CODE");
244 String populateIpAddressV4OamVip = ctx.getAttribute(vnfcRefKey + "IPADDRESS-V4-OAM-VIP");
246 // Get vnfc Data to be added
247 String vserverName = ctx.getAttribute(aaiRefKey + "vserver-name");
248 String vnfcName = vserverName + vnfcFuncCode + "001";
249 String groupNotation = getGroupNotation(groupNotationType, groupNotationValue, vnfcName, vserverName,
250 prefix, ctx, vnfcType, vnfcFuncCode, vmCount);
252 String ipAddressV4OamVip = null;
253 if ("Y".equals(populateIpAddressV4OamVip)) {
254 ipAddressV4OamVip = ctx.getAttribute("vnf-host-ip-address"); // from input
256 Map<String, String> vnfcParams =
257 populateVnfcParams(ctx, aaiRefKey, ipAddressV4OamVip, groupNotation, vnfcType, vnfcFuncCode);
259 log.info("Vnfc name from AAI: " + vnfcNameAAI);
260 log.info("Vnfc name generated: " + vnfcName);
262 if (StringUtils.isNotBlank(vnfcNameAAI)) {
263 if (vnfcName.equalsIgnoreCase(vnfcNameAAI)) {
264 updateVnfcStatus(vnfcNameAAI, params, prefix);
270 addVnfc(vnfcName, vnfcParams, prefix);
272 // Add VNFC Info to context for current added VNFC
273 ctx.setAttribute(aaiRefKey + "vnfc-name", vnfcName);
274 ctx.setAttribute(aaiRefKey + "vnfc-type", vnfcType);
275 ctx.setAttribute(aaiRefKey + "vnfc-function-code", vnfcFuncCode);
276 ctx.setAttribute(aaiRefKey + "group-notation", groupNotation);
280 public List<String> getVnfcData(Map<String, String> params, SvcLogicContext ctx, int vnfcRefLen, int vmCount)
283 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
284 prefix = StringUtils.isNotBlank(prefix) ? (prefix + ".") : "";
285 List<String> vnfcNames = new ArrayList<String>();
286 int vnfcRefIndx = -1;
287 for (int i = 0; i < vmCount; i++) {
288 String aaiRefKey = prefix + "vm[" + i + "].";
289 log.info("VNFCNAME IN INSERTVNFCS " + ctx.getAttribute(aaiRefKey + "vnfc-name"));
290 if (ctx.getAttribute(aaiRefKey + "vnfc-name") != null) {
295 String vnfcRefKey = "vnfcReference[" + vnfcRefIndx + "].";
296 log.info("VNFCREFKEY " + vnfcRefKey);
297 log.info("AAIREFKEY " + aaiRefKey);
298 String vnfcFuncCode = ctx.getAttribute(vnfcRefKey + "VNFC-FUNCTION-CODE");
300 // Get vnfc Data to be added
301 String vserverName = ctx.getAttribute(aaiRefKey + "vserver-name");
302 String vnfcName = vserverName + vnfcFuncCode + "001";
305 vnfcNames.add(vnfcName);
311 private Map<String, String> populateVnfcParams(SvcLogicContext ctx, String aaiRefKey, String ipAddressV4OamVip,
312 String groupNotation, String vnfcType, String vnfcFuncCode) throws Exception {
314 Map<String, String> vnfcParams = new HashMap<String, String>();
316 // Changes for vnfc-type renamed to nfc-function,vnfc-function-code renamed to
318 vnfcParams.put("nfc-naming-code", vnfcFuncCode);
319 vnfcParams.put("nfc-function", vnfcType);
320 vnfcParams.put("ipaddress-v4-oam-vip", ipAddressV4OamVip);
321 vnfcParams.put("prov-status", "NVTPROV");
322 vnfcParams.put("orchestration-status", "CONFIGURED");
323 vnfcParams.put("in-maint", "false");
324 vnfcParams.put("is-closed-loop", "false");
325 vnfcParams.put("group-notation", groupNotation);
326 vnfcParams.put("relationship-list.relationship[0].related-to", "vserver");
327 vnfcParams.put("relationship-list.relationship[0].relationship-data[0].relationship-key", "vserver.vserver-id");
328 vnfcParams.put("relationship-list.relationship[0].relationship-data[0].relationship-value",
329 ctx.getAttribute(aaiRefKey + "vserver-id"));
330 vnfcParams.put("relationship-list.relationship[0].relationship-data[1].relationship-key", "tenant.tenant-id");
331 vnfcParams.put("relationship-list.relationship[0].relationship-data[1].relationship-value",
332 ctx.getAttribute(aaiRefKey + "tenant-id"));
333 vnfcParams.put("relationship-list.relationship[0].relationship-data[2].relationship-key",
334 "cloud-region.cloud-owner");
335 vnfcParams.put("relationship-list.relationship[0].relationship-data[2].relationship-value",
336 ctx.getAttribute(aaiRefKey + "cloud-owner"));
337 vnfcParams.put("relationship-list.relationship[0].relationship-data[3].relationship-key",
338 "cloud-region.cloud-region-id");
339 vnfcParams.put("relationship-list.relationship[0].relationship-data[3].relationship-value",
340 ctx.getAttribute(aaiRefKey + "cloud-region-id"));
341 vnfcParams.put("relationship-list.relationship[1].related-to", "generic-vnf");
342 vnfcParams.put("relationship-list.relationship[1].relationship-data[0].relationship-key", "generic-vnf.vnf-id");
343 vnfcParams.put("relationship-list.relationship[1].relationship-data[0].relationship-value",
344 ctx.getAttribute("vnf-id"));
345 vnfcParams.put("relationship-list.relationship[2].related-to", "vf-module");
346 vnfcParams.put("relationship-list.relationship[2].relationship-data[0].relationship-key", "generic-vnf.vnf-id");
347 vnfcParams.put("relationship-list.relationship[2].relationship-data[0].relationship-value",
348 ctx.getAttribute("vnf-id"));
349 vnfcParams.put("relationship-list.relationship[2].relationship-data[1].relationship-key",
350 "vf-module.vf-module-id");
351 vnfcParams.put("relationship-list.relationship[2].relationship-data[1].relationship-value",
352 ctx.getAttribute(aaiRefKey + "vf-module-id"));
357 public void addVnfc(String vnfcName, Map<String, String> params, String prefix) throws Exception {
358 log.info("Received addVnfc call with vnfcName : " + vnfcName);
359 log.info("Received addVnfc call with params : " + params);
360 String resourceKey = "vnfc.vnfc-name = '" + vnfcName + "'";
361 log.info("Received addVnfc call with resourceKey : " + resourceKey);
363 SvcLogicContext vnfcCtx = new SvcLogicContext();
364 SvcLogicResource.QueryStatus response =
365 aaiClient.save("vnfc", true, false, resourceKey, params, prefix, vnfcCtx);
367 if (SvcLogicResource.QueryStatus.SUCCESS.equals(response)) {
368 log.info("Added VNFC SUCCESSFULLY " + vnfcName);
369 } else if (SvcLogicResource.QueryStatus.FAILURE.equals(response)) {
370 throw new Exception("VNFC Add failed for for vnfc_name " + vnfcName);
374 public String getGroupNotation(String groupNotationType, String groupNotationValue, String vnfcName,
375 String vserverName, String prefix, SvcLogicContext ctx, String vnfcRefVnfcType, String vnfcFuncCode, int vmCount) throws Exception {
377 String grpNotation = null;
379 if ("fixed-value".equals(groupNotationType)) {
380 grpNotation = groupNotationValue;
381 } else if ("first-vnfc-name".equals(groupNotationType)) {
384 * If the group-notation-type value = ?first-vnfc-name?,
385 * then populate the group-notation value with the concatenation of
386 * [vnfc name associated with the first vnfc for the vnfc-type (e.g., *******)]
387 * and [the value in group-notation-value (e.g., pair)].
388 * There may be several vnfc-types associated with the VM?s.
390 /* Vnfc-type should be from refrence data */
392 /* vDBE has 2 VNFCs with same VNFC type . The pair name should be same for both . */
394 * When first VNFC is added details should be added to context so FirstVnfcName doesnt return null second
397 String tmpVnfcName = getFirstVnfcNameForVnfcType(ctx, prefix, vnfcRefVnfcType);
399 log.info("RETURNED FIRSTVNFCNAME" + tmpVnfcName);
400 log.info("CURRENTVNFCNAME" + vnfcName);
401 if (tmpVnfcName == null) {
402 log.info("CURRENTVNFCNAME" + vnfcName);
403 // No Vnfcs currently exist. Use Current vnfcName
404 grpNotation = vnfcName + groupNotationValue;
406 grpNotation = tmpVnfcName + groupNotationValue;
408 } else if ("relative-value".equals(groupNotationType)) {
411 * If the group-notation-type = ?relative-value?, then find the group-notation value
412 * from the prior vnfc (where prior means the vnfc with where the last three digits of the
413 * vm-name is one lower than the current one; note that this vnfc may have been previously configured.)
414 * 1. If the group-notation-value = next, then add 1 to the group-notation value from the prior vnfc and use
416 * 2. If the group-notation-value = same, then use the group-notation-value from the prior vnfc record
419 // next and same cant be defined for first VM. if next will not generate grpNotation if Prior is not a
421 String tmpVserverName = null;
422 if (vserverName != null) {
424 String vmNamePrefix = vserverName.substring(0, vserverName.length() - 3);
426 String lastThreeChars = vserverName.substring(vserverName.length() - 3);
428 if (NumberUtils.isDigits(lastThreeChars)) {
429 int vmNum = Integer.parseInt(lastThreeChars) - 1;
430 String formatted = String.format("%03d", vmNum);
432 log.info("FORMATTED " + formatted);
434 tmpVserverName = vmNamePrefix + formatted;
436 String priorGroupNotation = getGroupNotationForVServer(ctx, prefix, tmpVserverName);
438 if ("same".equals(groupNotationValue)) {
439 grpNotation = priorGroupNotation;
440 } else if ("next".equals(groupNotationValue)) {
441 if (priorGroupNotation != null && NumberUtils.isDigits(priorGroupNotation)) {
442 int nextGrpNotation = Integer.parseInt(priorGroupNotation) + 1;
443 grpNotation = String.valueOf(nextGrpNotation);
449 else if ("existing-value".equals(groupNotationType)) {
450 /* 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.
451 * Verify that the group-notation value is the same for all such records found in inventory.
452 * 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.
453 If all records match, use the same group-notation value for the new vnfc record as found in the existing vnfc records.
455 grpNotation = getGroupNotationForExistigValue(ctx, prefix, vnfcFuncCode, vmCount);
458 log.info("RETURNED GROUPNOTATION " + grpNotation);
462 public String getGroupNotationForExistigValue(SvcLogicContext ctx, String prefix, String vnfcFuncCode, int vmCount) {
463 String vfModuleId = ctx.getAttribute("req-vf-module-id"); //Coming from request-params
465 String aaiGroupNotationValue=null;
466 for (int i=0;i<vmCount;i++ )
468 String ind = "tmp.vnfInfo.vm["+i+"].";
469 String aaiFuncCode = ctx.getAttribute(ind+"vnfc-function-code");
470 String aaiGroupNotation = ctx.getAttribute(ind+"group-notation");
471 String aaiVfModuleId = ctx.getAttribute(ind+"vf-module-id");
473 log.info("getGroupNotationForExistigValue()::: vfModuleId="+vfModuleId+", aaiFuncCode="+aaiFuncCode
474 +", aaiGroupNotation="+aaiGroupNotation+",aaiVfMOduleId="+aaiVfModuleId);
476 if (StringUtils.isNotBlank(aaiFuncCode) && aaiFuncCode.equals(vnfcFuncCode) &&
477 (StringUtils.isNotBlank(vfModuleId) && StringUtils.isNotBlank(aaiVfModuleId) && aaiVfModuleId.equals(vfModuleId))) {
478 if (null==aaiGroupNotationValue && first) {
479 if (null == aaiGroupNotation) {//Return if null
482 aaiGroupNotationValue = ctx.getAttribute(ind+"group-notation");
486 if (!StringUtils.equals(aaiGroupNotationValue, ctx.getAttribute(ind+"group-notation"))) {
487 log.info("Values are different, returning null");
494 return aaiGroupNotationValue;
497 public String getGroupNotationForVServer(SvcLogicContext ctx, String prefix, String vserverName) {
499 String vmCountStr = ctx.getAttribute(prefix + "vnf.vm-count");
501 if (vmCountStr == null) {
505 int vmCount = Integer.valueOf(vmCountStr);
506 for (int i = 0; i < vmCount; i++) {
508 String tmpVserver = ctx.getAttribute(prefix + "vm[" + i + "].vserver-name");
510 if (vserverName.equals(tmpVserver)) {
511 return ctx.getAttribute(prefix + "vm[" + i + "].group-notation");
518 public String getFirstVnfcNameForVnfcType(SvcLogicContext ctx, String prefix, String vnfcRefVnfcType) {
520 String vmCountStr = ctx.getAttribute(prefix + "vnf.vm-count");
522 if (vmCountStr == null) {
526 int vmCount = Integer.valueOf(vmCountStr);
527 for (int i = 0; i < vmCount; i++) {
529 String tmpvnfcType = ctx.getAttribute(prefix + "vm[" + i + "].vnfc-type");
531 if (vnfcRefVnfcType.equals(tmpvnfcType)) {
532 return ctx.getAttribute(prefix + "vm[" + i + "].vnfc-name");
538 public void updateVServerStatus(Map<String, String> params, SvcLogicContext ctx, int vmCount) throws Exception {
539 log.info("Received updateVServerStatus call with params : " + params);
541 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
543 prefix = StringUtils.isNotBlank(prefix) ? (prefix + ".") : "";
544 Map<String, String> vServerParams = new HashMap<String, String>();
546 // TODO - Should this just update prov-status or both? What about generic-vnf status? Will that be updated by
549 vServerParams.put("prov-status", "NVTPROV");
551 for (int i = 0; i < vmCount; i++) {
552 String aaiRefKey = prefix + "vm[" + i + "].";
554 log.info("VNFCNAME IN UpdateVServer " + ctx.getAttribute(aaiRefKey + "vnfc-name"));
556 if (ctx.getAttribute(aaiRefKey + "vnfc-name") != null) {
560 String resourceKey = "vserver.vserver-id = '" + ctx.getAttribute(aaiRefKey + "vserver-id") + "'"
561 + " AND tenant.tenant-id = '" + ctx.getAttribute(aaiRefKey + "tenant-id") + "'"
562 + " AND cloud-region.cloud-owner = '" + ctx.getAttribute(aaiRefKey + "cloud-owner") + "'"
563 + " AND cloud-region.cloud-region-id = '" + ctx.getAttribute(aaiRefKey + "cloud-region-id") + "'";
565 updateResource("vserver", resourceKey, vServerParams);
569 public void updateVnfStatus(Map<String, String> params, SvcLogicContext ctx) throws Exception {
570 log.info("Received updateVnfStatus call with params : " + params);
572 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
574 prefix = StringUtils.isNotBlank(prefix) ? (prefix + ".") : "";
576 Map<String, String> vnfParams = new HashMap<String, String>();
578 // TODO - Should this just update prov-status or both? What about generic-vnf status? Will that be updated by
581 vnfParams.put("prov-status", "NVTPROV");
583 String resourceKey = "generic-vnf.vnf-id = '" + ctx.getAttribute("vnf-id") + "'";
585 updateResource("generic-vnf", resourceKey, vnfParams);
588 public void updateResource(String resource, String resourceKey, Map<String, String> params) throws Exception {
590 log.info("Received updateResource call with Key : " + resourceKey);
592 SvcLogicContext ctx = new SvcLogicContext();
593 SvcLogicResource.QueryStatus response = aaiClient.update(resource, resourceKey, params, "tmp.update", ctx);
595 if (SvcLogicResource.QueryStatus.SUCCESS.equals(response)) {
596 log.info("Updated " + resource + " SUCCESSFULLY for " + resourceKey);
598 } else if (SvcLogicResource.QueryStatus.FAILURE.equals(response)) {
599 throw new Exception(resource + " Update failed for " + resourceKey);
603 public SvcLogicContext readResource(String query, String prefix, String resourceType) throws Exception {
604 SvcLogicContext resourceContext = new SvcLogicContext();
606 SvcLogicResource.QueryStatus response =
607 aaiClient.query(resourceType, false, null, query, prefix, null, resourceContext);
608 log.info("AAIResponse: " + response.toString());
609 if (!SvcLogicResource.QueryStatus.SUCCESS.equals(response)) {
610 throw new Exception("Error Retrieving " + resourceType + " from A&AI");
613 return resourceContext;
616 // Added for Backward Compatibility
618 public void checkAndUpdateVnfc(Map<String, String> params, SvcLogicContext ctx, int vnfcRefLen, int vmCount)
620 log.info("Received checkAndUpdateVnfcStatus call with params : " + params);
622 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
624 prefix = StringUtils.isNotBlank(prefix) ? (prefix + ".") : "";
626 for (int i = 0; i < vmCount; i++) {
627 String aaiRefKey = prefix + "vm[" + i + "].";
629 log.info("VNFCNAME IN INSERTVNFCS " + aaiRefKey + "vnfc-name:" + ctx.getAttribute(aaiRefKey + "vnfc-name"));
631 String vnfcNameAai = ctx.getAttribute(aaiRefKey + "vnfc-name");
633 if (StringUtils.isNotBlank(vnfcNameAai)) {
634 // Get Vnfc_reference data
635 for (int vnfcRefIndx = 0; vnfcRefIndx < vnfcRefLen; vnfcRefIndx++) {
637 String vnfcRefKey = "vnfcReference[" + vnfcRefIndx + "].";
639 log.info("VNFCREFKEY " + vnfcRefKey);
640 log.info("AAIREFKEY " + aaiRefKey);
642 String vnfcFuncCode = ctx.getAttribute(vnfcRefKey + "VNFC-FUNCTION-CODE");
643 String vserverName = ctx.getAttribute(aaiRefKey + "vserver-name");
644 String vnfcNameReference = vserverName + vnfcFuncCode + "001";
646 if (vnfcNameAai.equals(vnfcNameReference)) {
647 updateVnfcStatus(vnfcNameAai, params, prefix);
654 public void updateVnfcStatus(String vnfcName, Map<String, String> params, String prefix) throws Exception {
656 log.info("Received updateVnfcStatus call with vnfcName : " + vnfcName);
657 log.info("Received updateVnfcStatus call with params : " + params);
659 String resourceKey = "vnfc.vnfc-name = '" + vnfcName + "'";
660 log.info("Received updateVnfcStatus call with resourceKey : " + resourceKey);
662 Map<String, String> vnfcParams = new HashMap<String, String>();
663 vnfcParams.put("prov-status", "NVTPROV");
664 vnfcParams.put("orchestration-status", "CONFIGURED");
666 log.info("In updateVnfcStatus call with vnfcParams : " + vnfcParams);
668 updateResource("vnfc", resourceKey, vnfcParams);
670 log.info("End of updateVnfcStatus");
673 public void updateVnfStatusWithOAMAddress(Map<String, String> params, SvcLogicContext ctx) throws Exception {
674 log.info("Received updateVnfStatusWithOAMAddress call with params : " + params);
676 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
677 String ipAddress = ctx.getAttribute("vnf-host-ip-address");
678 log.debug("Vnf-host-ip-address" + ipAddress);
680 prefix = StringUtils.isNotBlank(prefix) ? (prefix + ".") : "";
682 Map<String, String> vnfParams = new HashMap<String, String>();
684 vnfParams.put("ipv4-oam-address", ipAddress);
686 String resourceKey = "generic-vnf.vnf-id = '" + ctx.getAttribute("vnf-id") + "'";
688 updateResource("generic-vnf", resourceKey, vnfParams);
691 public void getVfModuleInfo(Map<String, String> params, SvcLogicContext vfModuleCtx) throws Exception {
692 log.info("Received getVfModuleInfo call with params : " + params);
693 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
694 prefix = StringUtils.isNotBlank(prefix) ? (prefix + ".") : "";
696 String vnfId = params.get("vnfId");
697 String vfModuleId = params.get("vfModuleId");
698 String resourceKey = "generic-vnf.vnf-id = '" + vnfId +
699 "' AND vf-module.vf-module-id = '" + vfModuleId + "'";
700 String queryPrefix = "vfModuleInfo";
701 String resourceType = "vf-module";
702 SvcLogicContext vfmCtx = readResource(resourceKey, queryPrefix, resourceType);
703 String modelInvariantId=vfmCtx.getAttribute("vfModuleInfo.model-invariant-id");
704 log.info("getVfModuleInfo():::modelInvariant="+modelInvariantId);
705 vfModuleCtx.setAttribute(prefix+"vfModule.model-invariant-id", vfmCtx.getAttribute("vfModuleInfo.model-invariant-id"));
706 vfModuleCtx.setAttribute(prefix+"vfModule.model-version-id", vfmCtx.getAttribute("vfModuleInfo.model-version-id"));
707 log.info("End - getVfModuleInfo");
710 public void getModelVersionInfo(Map<String, String> modelParams, SvcLogicContext modelCtx) throws Exception {
711 log.info("Received getModelVersionInfo call with params : " + modelParams);
712 String prefix = modelParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
713 prefix = StringUtils.isNotBlank(prefix) ? (prefix + ".") : "";
715 String modelInvariantId = modelParams.get("model-invariant-id");
716 String modelVersionId = modelParams.get("model-version-id");
717 String resourceKey = "model.model-invariant-id = '" + modelInvariantId +
718 "' AND model-ver.model-version-id = '" + modelVersionId + "'";
719 String queryPrefix = "modelInfo";
720 String resourceType = "model-ver";
721 SvcLogicContext vfmCtx = readResource(resourceKey, queryPrefix, resourceType);
722 log.info("getModelVersionInfo():::modelname="+vfmCtx.getAttribute("modelInfo.model-name"));
723 modelCtx.setAttribute(prefix+"vfModule.model-name", vfmCtx.getAttribute("modelInfo.model-name"));
724 log.info("End - getModelVersionInfo");