2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.aai.client.aai;
27 import java.util.HashMap;
30 import org.apache.commons.lang3.StringUtils;
31 import org.apache.commons.lang3.math.NumberUtils;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
36 import org.onap.appc.aai.client.AppcAaiClientConstant;
37 import com.att.eelf.configuration.EELFLogger;
38 import com.att.eelf.configuration.EELFManager;
39 import org.onap.ccsdk.sli.adaptors.aai.AAIClient;
40 import org.onap.ccsdk.sli.adaptors.aai.AAIService;
41 import org.osgi.framework.BundleContext;
42 import org.osgi.framework.FrameworkUtil;
43 import org.osgi.framework.ServiceReference;
45 public class AaiService {
47 private static final EELFLogger log = EELFManager.getInstance().getLogger(AaiService.class);
48 private AAIClient aaiClient;
51 public AaiService(AAIClient aaiClient) {
52 this.aaiClient = aaiClient;
56 BundleContext bctx = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
57 ServiceReference sref = bctx.getServiceReference(AAIService.class);
58 aaiClient = (AAIClient) bctx.getService(sref);
61 public void getGenericVnfInfo(Map<String, String> params, SvcLogicContext ctx) throws Exception {
64 String vnfId = params.get("vnfId");
65 if(StringUtils.isBlank(vnfId)){
66 throw new Exception("VnfId is missing");
69 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
72 prefix = StringUtils.isNotBlank(prefix) ? (prefix+".") : "";
75 //String resourceKey = "generic-vnf.vnf-id = '" + vnfId + "' AND relationship-key = 'vserver.vserver-id'";
77 String resourceKey = "generic-vnf.vnf-id = '" + vnfId + "'";
79 String resourceType = "generic-vnf";
80 String queryPrefix = "vnfInfo";
81 SvcLogicContext vnfCtx = readResource(resourceKey,queryPrefix,resourceType);
86 ctx.setAttribute(prefix + "vnf.vnf-name", vnfCtx.getAttribute("vnfInfo.vnf-name"));
87 ctx.setAttribute(prefix + "vnf.vnf-type", vnfCtx.getAttribute("vnfInfo.vnf-type"));
88 ctx.setAttribute(prefix + "vnf.prov-status", vnfCtx.getAttribute("vnfInfo.prov-status"));
89 ctx.setAttribute(prefix + "vnf.orchestration-status", vnfCtx.getAttribute("vnfInfo.orchestration-status"));
96 String relLen = vnfCtx.getAttribute("vnfInfo.relationship-list.relationship_length");
97 int relationshipLength = 0;
99 relationshipLength = Integer.parseInt(relLen);
101 log.info("RELLEN " + relationshipLength);
102 for ( int i=0; i < relationshipLength; i++ ) {
104 String vserverId = getRelationshipValue(i, vnfCtx, "vserver", "vserver.vserver-id", "vnfInfo");
105 String tenantId = getRelationshipValue(i, vnfCtx, "vserver", "tenant.tenant-id", "vnfInfo");
106 String cloudOwner = getRelationshipValue(i, vnfCtx, "vserver", "cloud-region.cloud-owner", "vnfInfo");
107 String cloudRegionId = getRelationshipValue(i, vnfCtx, "vserver", "cloud-region.cloud-region-id", "vnfInfo");
109 if ( vserverId != null ) {
111 log.info("VSERVER KEYS " + vserverId + " " + tenantId + " " + cloudOwner + " " + cloudRegionId);
112 String vnfPrefix = prefix + "vm[" + vmCount + "].";
114 ctx.setAttribute(vnfPrefix + "vserver-id", vserverId);
115 ctx.setAttribute(vnfPrefix + "tenant-id", tenantId);
116 ctx.setAttribute(vnfPrefix + "cloud-owner", cloudOwner);
117 ctx.setAttribute(vnfPrefix + "cloud-region-id", cloudRegionId);
125 ctx.setAttribute(prefix + "vm-count", String.valueOf(vmCount));
127 log.info("VMCOUNT FROM VNF INFO " + ctx.getAttribute(prefix + "vm-count"));
136 public void getVMInfo(Map<String, String> params,SvcLogicContext ctx ) throws Exception {
137 log.info("Received getVmInfo call with params : " + params);
139 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
142 prefix = StringUtils.isNotBlank(prefix) ? (prefix+".") : "";
145 ctx.setAttribute(prefix + "vm.vnfc-count", String.valueOf(vnfcCount)); // Incase no vnfcs are found
147 String vserverId = params.get("vserverId");
148 if(StringUtils.isBlank(vserverId)){
149 throw new Exception("VServerId is missing");
152 String tenantId = params.get("tenantId");
153 if(StringUtils.isBlank(tenantId)){
154 throw new Exception("TenantId is missing");
157 String cloudOwner = params.get("cloudOwner");
158 if(StringUtils.isBlank(cloudOwner)){
159 throw new Exception("Cloud Owner is missing");
162 String cloudRegionId = params.get("cloudRegionId");
163 if(StringUtils.isBlank(cloudRegionId)){
164 throw new Exception("Cloud region Id is missing");
169 String resourceKey = "vserver.vserver-id = '" +vserverId + "' AND tenant.tenant-id = '" + tenantId +
170 "' AND cloud-region.cloud-owner = '" +cloudOwner +
171 "' AND cloud-region.cloud-region-id = '" +cloudRegionId + "'";
174 String queryPrefix = "vmInfo";
176 String resourceType = "vserver";
177 SvcLogicContext vmCtx = readResource(resourceKey,queryPrefix,resourceType);
183 ctx.setAttribute(prefix+ "vm.prov-status", vmCtx.getAttribute("vmInfo.prov-status"));
185 ctx.setAttribute(prefix+ "vm.vserver-name", vmCtx.getAttribute("vmInfo.vserver-name"));
189 String relLen = vmCtx.getAttribute("vmInfo.relationship-list.relationship_length");
192 int relationshipLength = 0;
193 if ( relLen != null )
194 relationshipLength = Integer.parseInt(relLen);
196 log.info("RELLEN" + relationshipLength);
197 for ( int i=0; i < relationshipLength; i++ ) {
199 String vfModuleId = getRelationshipValue(i, vmCtx, "vf-module", "vf-module.vf-module-id", "vmInfo");
201 if ( vfModuleId != null )
202 ctx.setAttribute(prefix + "vm.vf-module-id", vfModuleId);
205 String vnfcName = getRelationshipValue(i, vmCtx, "vnfc", "vnfc.vnfc-name", "vmInfo");
207 if ( vnfcName != null ) {
209 ctx.setAttribute(prefix + "vm.vnfc[" + vnfcCount + "].vnfc-name", vnfcName);
216 } //relationshipLength
217 ctx.setAttribute(prefix + "vm.vnfc-count", String.valueOf(vnfcCount));
219 log.info("VSERVERNAME " + ctx.getAttribute(prefix+ "vm.vserver-name") + " HAS NUM VNFCS = " + ctx.getAttribute(prefix+ "vm.vnfc-count"));
225 private String getRelationshipValue(int i, SvcLogicContext ctx, String relatedTo, String relationshipKey, String prefix) throws Exception {
228 if ( relatedTo.equals(ctx.getAttribute(prefix + ".relationship-list.relationship[" + i + "].related-to")) ) {
231 log.info("RELATEDTO " + relatedTo);
232 int relationshipDataLength = 0;
233 String relDataLen = ctx.getAttribute(prefix + ".relationship-list.relationship[" + i + "].relationship-data_length");
235 if ( relDataLen != null )
236 relationshipDataLength = Integer.parseInt(relDataLen);
240 for ( int j =0 ; j < relationshipDataLength ; j++) {
242 String key = ctx.getAttribute(prefix + ".relationship-list.relationship[" + i + "].relationship-data[" + j + "].relationship-key");
244 String value = ctx.getAttribute(prefix + ".relationship-list.relationship[" + i + "].relationship-data[" + j + "].relationship-value");
246 log.info("GENERIC KEY " + key);
247 log.info("GENERIC VALUE " + value);
249 if (relationshipKey.equals(key)) {
254 } // relationshipDataLength
266 public void getVnfcInfo(Map<String, String> params,SvcLogicContext ctx ) throws Exception {
267 log.info("Received getVnfc call with params : " + params);
269 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
270 prefix = StringUtils.isNotBlank(prefix) ? (prefix+".") : "";
272 String vnfcName = params.get("vnfcName");
273 if(StringUtils.isBlank(vnfcName)){
274 throw new Exception("Vnfc Name is missing");
277 String resourceKey = "vnfc.vnfc-name = '" + vnfcName + "'";
279 String queryPrefix = "vnfcInfo";
280 String resourceType = "vnfc";
281 SvcLogicContext vnfcCtx = readResource(resourceKey,queryPrefix,resourceType);
283 // Changes for US 315820 for 1710 vnfc-type renamed to nfc-function,vnfc-function-code renamed to nfc-naming-code
285 /*ctx.setAttribute(prefix+ "vnfc.vnfc-type", vnfcCtx.getAttribute("vnfcInfo.vnfc-type"));
286 ctx.setAttribute(prefix+ "vnfc.vnfc-function-code", vnfcCtx.getAttribute("vnfcInfo.vnfc-function-code"));
287 ctx.setAttribute(prefix+ "vnfc.group-notation", vnfcCtx.getAttribute("vnfcInfo.group-notation"));*/
289 ctx.setAttribute(prefix+ "vnfc.vnfc-type", vnfcCtx.getAttribute("vnfcInfo.nfc-function"));
290 ctx.setAttribute(prefix+ "vnfc.vnfc-function-code", vnfcCtx.getAttribute("vnfcInfo.nfc-naming-code"));
291 ctx.setAttribute(prefix+ "vnfc.group-notation", vnfcCtx.getAttribute("vnfcInfo.group-notation"));
296 public void insertVnfcs(Map<String, String> params,SvcLogicContext ctx, int vnfcRefLen, int vmCount) throws Exception {
297 log.info("Received insertVnfcs call with params : " + params);
299 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
301 prefix = StringUtils.isNotBlank(prefix) ? (prefix+".") : "";
306 for ( int i = 0; i < vmCount ; i++ ) {
307 String aaiRefKey = prefix + "vm[" + i + "].";
309 log.info("VNFCNAME IN INSERTVNFCS " + ctx.getAttribute(aaiRefKey + "vnfc-name"));
310 String numVnfcsStr = ctx.getAttribute(aaiRefKey + "vnfc-count");
313 //if ( numVnfcsStr != null || Integer.parseInt(numVnfcsStr) >= 1 )
316 if ( ctx.getAttribute(aaiRefKey + "vnfc-name") != null )
322 // Get Vnfc_reference data
323 String vnfcRefKey = "vnfcReference[" + vnfcRefIndx + "].";
325 log.info("VNFCREFKEY " + vnfcRefKey);
326 log.info("AAIREFKEY " + aaiRefKey);
328 String vmInstance = ctx.getAttribute(vnfcRefKey+ "VM-INSTANCE");
329 String vnfcInstance = ctx.getAttribute(vnfcRefKey+ "VNFC-INSTANCE");
331 String groupNotationType = ctx.getAttribute(vnfcRefKey+ "GROUP-NOTATION-TYPE");
332 String groupNotationValue = ctx.getAttribute(vnfcRefKey+ "GROUP-NOTATION-VALUE");
334 String vnfcType = ctx.getAttribute(vnfcRefKey+ "VNFC-TYPE");
336 String vnfcFuncCode = ctx.getAttribute(vnfcRefKey+ "VNFC-FUNCTION-CODE");
338 String populateIpAddressV4OamVip = ctx.getAttribute(vnfcRefKey+ "IPADDRESS-V4-OAM-VIP");
341 // Get vnfc Data to be added
342 String vserverName = ctx.getAttribute(aaiRefKey + "vserver-name");
343 String vnfcName = vserverName + vnfcFuncCode + "001";
345 String groupNotation = getGroupNotation(groupNotationType, groupNotationValue, vnfcName, vserverName,prefix, ctx, vnfcType);
348 String ipAddressV4OamVip = null;
349 if ( "Y".equals(populateIpAddressV4OamVip))
350 ipAddressV4OamVip = ctx.getAttribute("vnf-host-ip-address"); // from input
353 Map<String, String> vnfcParams = populateVnfcParams(ctx, aaiRefKey, ipAddressV4OamVip, groupNotation, vnfcType, vnfcFuncCode);
356 addVnfc( vnfcName, vnfcParams, prefix);
358 // Add VNFC Info to context for current added VNFC
359 ctx.setAttribute(aaiRefKey + "vnfc-name", vnfcName);
360 ctx.setAttribute(aaiRefKey + "vnfc-type", vnfcType);
361 ctx.setAttribute(aaiRefKey + "vnfc-function-code", vnfcFuncCode);
362 ctx.setAttribute(aaiRefKey + "group-notation", groupNotation);
371 public Map<String, String> populateVnfcParams(SvcLogicContext ctx, String aaiRefKey,
372 String ipAddressV4OamVip, String groupNotation, String vnfcType, String vnfcFuncCode) throws Exception {
375 Map<String, String> vnfcParams = new HashMap<String, String>();
377 // Changes for US 315820 for 1710 vnfc-type renamed to nfc-function,vnfc-function-code renamed to nfc-naming-code
380 vnfcParams.put("vnfc-function-code", vnfcFuncCode);
381 vnfcParams.put("vnfc-type", vnfcType);
383 vnfcParams.put("nfc-naming-code", vnfcFuncCode);
384 vnfcParams.put("nfc-function", vnfcType);
388 vnfcParams.put("ipaddress-v4-oam-vip", ipAddressV4OamVip);
390 vnfcParams.put("prov-status", "NVTPROV");
391 vnfcParams.put("orchestration-status", "CONFIGURED");
392 vnfcParams.put("in-maint", "false");
393 vnfcParams.put("is-closed-loop", "false");
394 vnfcParams.put("group-notation",groupNotation);
397 vnfcParams.put("relationship-list.relationship[0].related-to","vserver");
398 vnfcParams.put("relationship-list.relationship[0].relationship-data[0].relationship-key","vserver.vserver-id");
399 vnfcParams.put("relationship-list.relationship[0].relationship-data[0].relationship-value",ctx.getAttribute(aaiRefKey + "vserver-id"));
402 vnfcParams.put("relationship-list.relationship[0].relationship-data[1].relationship-key","tenant.tenant-id");
403 vnfcParams.put("relationship-list.relationship[0].relationship-data[1].relationship-value",ctx.getAttribute(aaiRefKey + "tenant-id"));
406 vnfcParams.put("relationship-list.relationship[0].relationship-data[2].relationship-key","cloud-region.cloud-owner");
407 vnfcParams.put("relationship-list.relationship[0].relationship-data[2].relationship-value",ctx.getAttribute(aaiRefKey + "cloud-owner"));
410 vnfcParams.put("relationship-list.relationship[0].relationship-data[3].relationship-key","cloud-region.cloud-region-id");
411 vnfcParams.put("relationship-list.relationship[0].relationship-data[3].relationship-value",ctx.getAttribute(aaiRefKey + "cloud-region-id"));
415 vnfcParams.put("relationship-list.relationship[1].related-to","generic-vnf");
416 vnfcParams.put("relationship-list.relationship[1].relationship-data[0].relationship-key","generic-vnf.vnf-id");
417 vnfcParams.put("relationship-list.relationship[1].relationship-data[0].relationship-value",ctx.getAttribute("vnf-id"));
420 vnfcParams.put("relationship-list.relationship[2].related-to","vf-module");
421 vnfcParams.put("relationship-list.relationship[2].relationship-data[0].relationship-key","generic-vnf.vnf-id");
422 vnfcParams.put("relationship-list.relationship[2].relationship-data[0].relationship-value",ctx.getAttribute("vnf-id"));
425 vnfcParams.put("relationship-list.relationship[2].relationship-data[1].relationship-key","vf-module.vf-module-id");
426 vnfcParams.put("relationship-list.relationship[2].relationship-data[1].relationship-value",ctx.getAttribute(aaiRefKey + "vf-module-id"));
432 public void addVnfc(String vnfcName, Map<String, String> params, String prefix) throws Exception {
434 log.info("Received addVnfc call with vnfcName : " +vnfcName);
435 log.info("Received addVnfc call with params : " + params);
436 String resourceKey = "vnfc.vnfc-name = '" + vnfcName + "'";
438 log.info("Received addVnfc call with resourceKey : " + resourceKey);
441 SvcLogicContext vnfcCtx = new SvcLogicContext();
442 SvcLogicResource.QueryStatus response = aaiClient.save("vnfc", true, false, resourceKey, params, prefix, vnfcCtx) ;
444 if (SvcLogicResource.QueryStatus.SUCCESS.equals(response)) {
445 log.info("Added VNFC SUCCESSFULLY " + vnfcName);
448 else if (SvcLogicResource.QueryStatus.FAILURE.equals(response)) {
449 throw new Exception("VNFC Add failed for for vnfc_name " + vnfcName);
456 public String getGroupNotation(String groupNotationType, String groupNotationValue, String vnfcName,
457 String vserverName, String prefix, SvcLogicContext ctx, String vnfcRefVnfcType) throws Exception {
459 String grpNotation = null;
461 if ( "fixed-value".equals(groupNotationType)) {
462 grpNotation = groupNotationValue;
465 else if ( "first-vnfc-name".equals(groupNotationType) ) {
467 /*If the group-notation-type value = ?first-vnfc-name?,
468 * then populate the group-notation value with the concatenation of
469 * [vnfc name associated with the first vnfc for the vnfc-type (e.g., *******)]
470 * and [the value in group-notation-value (e.g., pair)].
471 * There may be several vnfc-types associated with the VM?s.
473 /* Vnfc-type should be from refrence data */
475 /* vDBE has 2 VNFCs with same VNFC type . The pair name should be same for both . */
476 /* When first VNFC is added details should be added to context so FirstVnfcName doesnt return null second time. */
477 String tmpVnfcName = getFirstVnfcNameForVnfcType(ctx, prefix, vnfcRefVnfcType);
479 log.info("RETURNED FIRSTVNFCNAME" + tmpVnfcName);
480 log.info("CURRENTVNFCNAME" + vnfcName);
481 if ( tmpVnfcName == null ) {
482 log.info("CURRENTVNFCNAME" + vnfcName);
483 // No Vnfcs currently exist. Use Current vnfcName
484 grpNotation = vnfcName + groupNotationValue;
487 grpNotation = tmpVnfcName + groupNotationValue;
491 else if ( "relative-value".equals(groupNotationType) ) {
493 /*If the group-notation-type = ?relative-value?, then find the group-notation value
494 * from the prior vnfc (where prior means the vnfc with where the last three digits of the
495 * vm-name is one lower than the current one; note that this vnfc may have been previously configured.)
496 1. If the group-notation-value = next, then add 1 to the group-notation value from the prior vnfc and use this value
497 2. If the group-notation-value = same, then use the group-notation-value from the prior vnfc record*/
499 // next and same cant be defined for first VM. if next will not generate grpNotation if Prior is not a number
500 String tmpVserverName = null;
501 if ( vserverName != null ) {
503 String vmNamePrefix = vserverName.substring(0,vserverName.length()-3);
505 String lastThreeChars = vserverName.substring(vserverName.length() - 3);
507 if ( NumberUtils.isDigits(lastThreeChars)) {
508 int vmNum = Integer.parseInt(lastThreeChars) - 1;
509 String formatted = String.format("%03d", vmNum);
511 log.info("FORMATTED " + formatted);
513 tmpVserverName = vmNamePrefix + formatted;
516 String priorGroupNotation = getGroupNotationForVServer(ctx, prefix, tmpVserverName);
518 if ( "same".equals(groupNotationValue))
519 grpNotation = priorGroupNotation;
520 else if ( "next".equals(groupNotationValue)) {
521 if ( priorGroupNotation != null && NumberUtils.isDigits(priorGroupNotation)) {
522 int nextGrpNotation = Integer.parseInt(priorGroupNotation) + 1;
523 grpNotation = String.valueOf(nextGrpNotation);
535 log.info("RETURNED GROUPNOTATION " + grpNotation);
539 public String getGroupNotationForVServer(SvcLogicContext ctx, String prefix, String vserverName) throws Exception {
542 String vmCountStr = ctx.getAttribute(prefix+"vnf.vm-count");
544 if ( vmCountStr == null )
547 int vmCount = Integer.valueOf(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");
564 public String getFirstVnfcNameForVnfcType(SvcLogicContext ctx, String prefix, String vnfcRefVnfcType) throws Exception {
568 /*if(StringUtils.isBlank(vnfcRefVnfcType)){
569 throw new Exception("Vnfc Reference : VNFC Type is missing");
573 String vmCountStr = ctx.getAttribute(prefix+"vnf.vm-count");
575 if ( vmCountStr == null )
578 int vmCount = Integer.valueOf(vmCountStr);
579 for ( int i = 0; i < vmCount ; i++ ) {
581 String tmpvnfcType = ctx.getAttribute(prefix+ "vm[" + i + "].vnfc-type");
583 if (vnfcRefVnfcType.equals(tmpvnfcType))
584 return ctx.getAttribute(prefix+ "vm[" + i + "].vnfc-name");
594 public void updateVServerStatus(Map<String, String> params,SvcLogicContext ctx, int vmCount) throws Exception {
595 log.info("Received updateVServerStatus call with params : " + params);
597 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
599 prefix = StringUtils.isNotBlank(prefix) ? (prefix+".") : "";
602 Map<String, String> vServerParams = new HashMap<String, String>();
605 // TODO - Should this just update prov-status or both? What about generic-vnf status? Will that be updated by Dispatcher?
607 vServerParams.put("prov-status", "NVTPROV");
608 //vServerParams.put("orchestration-status", "CONFIGURED");
611 for ( int i = 0; i < vmCount ; i++ ) {
612 String aaiRefKey = prefix + "vm[" + i + "].";
614 log.info("VNFCNAME IN UpdateVServer " + ctx.getAttribute(aaiRefKey + "vnfc-name"));
616 if ( ctx.getAttribute(aaiRefKey + "vnfc-name") != null )
621 String resourceKey = "vserver.vserver-id = '" + ctx.getAttribute(aaiRefKey + "vserver-id") + "'" +
622 " AND tenant.tenant-id = '" + ctx.getAttribute(aaiRefKey + "tenant-id") + "'" +
623 " AND cloud-region.cloud-owner = '" + ctx.getAttribute(aaiRefKey + "cloud-owner") + "'" +
624 " AND cloud-region.cloud-region-id = '" + ctx.getAttribute(aaiRefKey + "cloud-region-id") + "'";
627 updateResource( "vserver", resourceKey, vServerParams);
636 public void updateVnfStatus(Map<String, String> params,SvcLogicContext ctx) throws Exception {
637 log.info("Received updateVnfStatus call with params : " + params);
639 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
641 prefix = StringUtils.isNotBlank(prefix) ? (prefix+".") : "";
644 Map<String, String> vnfParams = new HashMap<String, String>();
647 // TODO - Should this just update prov-status or both? What about generic-vnf status? Will that be updated by Dispatcher?
649 vnfParams.put("prov-status", "NVTPROV");
650 //vnfParams.put("orchestration-status", "CONFIGURED");
653 String resourceKey = "generic-vnf.vnf-id = '" + ctx.getAttribute("vnf-id") + "'";
655 updateResource( "generic-vnf" , resourceKey, vnfParams);
662 public void updateResource( String resource, String resourceKey, Map<String, String> params) throws Exception {
664 log.info("Received updateResource call with Key : " +resourceKey);
667 SvcLogicContext ctx = new SvcLogicContext();
670 SvcLogicResource.QueryStatus response = aaiClient.update(resource, resourceKey , params, "tmp.update", ctx);
674 if (SvcLogicResource.QueryStatus.SUCCESS.equals(response)) {
675 log.info("Updated " + resource + " SUCCESSFULLY for " + resourceKey);
678 else if (SvcLogicResource.QueryStatus.FAILURE.equals(response)) {
679 throw new Exception(resource + " Update failed for " + resourceKey);
684 public SvcLogicContext readResource(String query, String prefix, String resourceType) throws Exception {
685 SvcLogicContext resourceContext = new SvcLogicContext();
687 SvcLogicResource.QueryStatus response = aaiClient.query(resourceType,false,null,query,prefix,null,resourceContext);
688 log.info("AAIResponse: " + response.toString());
689 if(!SvcLogicResource.QueryStatus.SUCCESS.equals(response)){
690 throw new Exception("Error Retrieving " + resourceType + " from A&AI");
693 return resourceContext;
699 //Added 1710 & Backward Compatibility
701 public void checkAndUpdateVnfc(Map<String, String> params,SvcLogicContext ctx, int vnfcRefLen, int vmCount) throws Exception {
702 log.info("Received checkAndUpdateVnfcStatus call with params : " + params);
704 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
706 prefix = StringUtils.isNotBlank(prefix) ? (prefix+".") : "";
708 for ( int i = 0; i < vmCount ; i++ ) {
709 String aaiRefKey = prefix + "vm[" + i + "].";
711 log.info("VNFCNAME IN INSERTVNFCS "+ aaiRefKey+"vnfc-name:" + ctx.getAttribute(aaiRefKey + "vnfc-name"));
713 String numVnfcsStr = ctx.getAttribute(aaiRefKey + "vnfc-count");
714 String vnfcNameAai = ctx.getAttribute(aaiRefKey + "vnfc-name");
716 if (StringUtils.isNotBlank(vnfcNameAai)) {
717 // Get Vnfc_reference data
718 for(int vnfcRefIndx=0;vnfcRefIndx < vnfcRefLen;vnfcRefIndx++ ) {
720 String vnfcRefKey = "vnfcReference[" + vnfcRefIndx + "].";
722 log.info("VNFCREFKEY " + vnfcRefKey);
723 log.info("AAIREFKEY " + aaiRefKey);
725 String vnfcFuncCode = ctx.getAttribute(vnfcRefKey+ "VNFC-FUNCTION-CODE");
726 String vserverName = ctx.getAttribute(aaiRefKey + "vserver-name");
727 String vnfcNameReference = vserverName + vnfcFuncCode + "001";
729 if(vnfcNameAai.equals(vnfcNameReference)) {
731 updateVnfcStatus( vnfcNameAai, params, prefix);
748 public void updateVnfcStatus(String vnfcName, Map<String, String> params, String prefix) throws Exception {
750 log.info("Received updateVnfcStatus call with vnfcName : " +vnfcName);
751 log.info("Received updateVnfcStatus call with params : " + params);
753 String resourceKey = "vnfc.vnfc-name = '" + vnfcName + "'";
754 log.info("Received updateVnfcStatus call with resourceKey : " + resourceKey);
757 Map<String, String> vnfcParams = new HashMap<String, String>();
758 vnfcParams.put("prov-status", "NVTPROV");
759 vnfcParams.put("orchestration-status", "CONFIGURED");
761 log.info("In updateVnfcStatus call with vnfcParams : " + vnfcParams);
763 updateResource( "vnfc" , resourceKey, vnfcParams);
765 log.info("End of updateVnfcStatus");