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.openecomp.appc.aai.client.aai;
27 import java.util.ArrayList;
28 import java.util.Collections;
29 import java.util.Comparator;
30 import java.util.HashMap;
34 import org.apache.commons.lang3.StringUtils;
35 import org.apache.commons.lang3.math.NumberUtils;
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.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
42 import org.openecomp.appc.aai.client.AppcAaiClientConstant;
43 import com.att.eelf.configuration.EELFLogger;
44 import com.att.eelf.configuration.EELFManager;
45 import org.onap.ccsdk.sli.adaptors.aai.AAIClient;
46 import org.onap.ccsdk.sli.adaptors.aai.AAIService;
47 import org.osgi.framework.BundleContext;
48 import org.osgi.framework.FrameworkUtil;
49 import org.osgi.framework.ServiceReference;
51 public class AaiService {
53 private static final EELFLogger log = EELFManager.getInstance().getLogger(AaiService.class);
54 private AAIClient aaiClient;
57 public AaiService(AAIClient aaiClient) {
58 this.aaiClient = aaiClient;
62 BundleContext bctx = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
63 ServiceReference sref = bctx.getServiceReference(AAIService.class);
64 aaiClient = (AAIClient) bctx.getService(sref);
67 public void getGenericVnfInfo(Map<String, String> params, SvcLogicContext ctx) throws Exception {
70 String vnfId = params.get("vnfId");
71 if(StringUtils.isBlank(vnfId)){
72 throw new Exception("VnfId is missing");
75 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
78 prefix = StringUtils.isNotBlank(prefix) ? (prefix+".") : "";
81 //String resourceKey = "generic-vnf.vnf-id = '" + vnfId + "' AND relationship-key = 'vserver.vserver-id'";
83 String resourceKey = "generic-vnf.vnf-id = '" + vnfId + "'";
85 String resourceType = "generic-vnf";
86 String queryPrefix = "vnfInfo";
87 SvcLogicContext vnfCtx = readResource(resourceKey,queryPrefix,resourceType);
92 ctx.setAttribute(prefix + "vnf.vnf-name", vnfCtx.getAttribute("vnfInfo.vnf-name"));
93 ctx.setAttribute(prefix + "vnf.vnf-type", vnfCtx.getAttribute("vnfInfo.vnf-type"));
94 ctx.setAttribute(prefix + "vnf.prov-status", vnfCtx.getAttribute("vnfInfo.prov-status"));
95 ctx.setAttribute(prefix + "vnf.orchestration-status", vnfCtx.getAttribute("vnfInfo.orchestration-status"));
102 String relLen = vnfCtx.getAttribute("vnfInfo.relationship-list.relationship_length");
103 int relationshipLength = 0;
104 if ( relLen != null )
105 relationshipLength = Integer.parseInt(relLen);
107 log.info("RELLEN " + relationshipLength);
108 for ( int i=0; i < relationshipLength; i++ ) {
110 String vserverId = getRelationshipValue(i, vnfCtx, "vserver", "vserver.vserver-id", "vnfInfo");
111 String tenantId = getRelationshipValue(i, vnfCtx, "vserver", "tenant.tenant-id", "vnfInfo");
112 String cloudOwner = getRelationshipValue(i, vnfCtx, "vserver", "cloud-region.cloud-owner", "vnfInfo");
113 String cloudRegionId = getRelationshipValue(i, vnfCtx, "vserver", "cloud-region.cloud-region-id", "vnfInfo");
115 if ( vserverId != null ) {
117 log.info("VSERVER KEYS " + vserverId + " " + tenantId + " " + cloudOwner + " " + cloudRegionId);
118 String vnfPrefix = prefix + "vm[" + vmCount + "].";
120 ctx.setAttribute(vnfPrefix + "vserver-id", vserverId);
121 ctx.setAttribute(vnfPrefix + "tenant-id", tenantId);
122 ctx.setAttribute(vnfPrefix + "cloud-owner", cloudOwner);
123 ctx.setAttribute(vnfPrefix + "cloud-region-id", cloudRegionId);
131 ctx.setAttribute(prefix + "vm-count", String.valueOf(vmCount));
133 log.info("VMCOUNT FROM VNF INFO " + ctx.getAttribute(prefix + "vm-count"));
142 public void getVMInfo(Map<String, String> params,SvcLogicContext ctx ) throws Exception {
143 log.info("Received getVmInfo call with params : " + params);
145 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
148 prefix = StringUtils.isNotBlank(prefix) ? (prefix+".") : "";
151 ctx.setAttribute(prefix + "vm.vnfc-count", String.valueOf(vnfcCount)); // Incase no vnfcs are found
153 String vserverId = params.get("vserverId");
154 if(StringUtils.isBlank(vserverId)){
155 throw new Exception("VServerId is missing");
158 String tenantId = params.get("tenantId");
159 if(StringUtils.isBlank(tenantId)){
160 throw new Exception("TenantId is missing");
163 String cloudOwner = params.get("cloudOwner");
164 if(StringUtils.isBlank(cloudOwner)){
165 throw new Exception("Cloud Owner is missing");
168 String cloudRegionId = params.get("cloudRegionId");
169 if(StringUtils.isBlank(cloudRegionId)){
170 throw new Exception("Cloud region Id is missing");
175 String resourceKey = "vserver.vserver-id = '" +vserverId + "' AND tenant.tenant-id = '" + tenantId +
176 "' AND cloud-region.cloud-owner = '" +cloudOwner +
177 "' AND cloud-region.cloud-region-id = '" +cloudRegionId + "'";
180 String queryPrefix = "vmInfo";
182 String resourceType = "vserver";
183 SvcLogicContext vmCtx = readResource(resourceKey,queryPrefix,resourceType);
189 ctx.setAttribute(prefix+ "vm.prov-status", vmCtx.getAttribute("vmInfo.prov-status"));
191 ctx.setAttribute(prefix+ "vm.vserver-name", vmCtx.getAttribute("vmInfo.vserver-name"));
195 String relLen = vmCtx.getAttribute("vmInfo.relationship-list.relationship_length");
198 int relationshipLength = 0;
199 if ( relLen != null )
200 relationshipLength = Integer.parseInt(relLen);
202 log.info("RELLEN" + relationshipLength);
203 for ( int i=0; i < relationshipLength; i++ ) {
205 String vfModuleId = getRelationshipValue(i, vmCtx, "vf-module", "vf-module.vf-module-id", "vmInfo");
207 if ( vfModuleId != null )
208 ctx.setAttribute(prefix + "vm.vf-module-id", vfModuleId);
211 String vnfcName = getRelationshipValue(i, vmCtx, "vnfc", "vnfc.vnfc-name", "vmInfo");
213 if ( vnfcName != null ) {
215 ctx.setAttribute(prefix + "vm.vnfc[" + vnfcCount + "].vnfc-name", vnfcName);
222 } //relationshipLength
223 ctx.setAttribute(prefix + "vm.vnfc-count", String.valueOf(vnfcCount));
225 log.info("VSERVERNAME " + ctx.getAttribute(prefix+ "vm.vserver-name") + " HAS NUM VNFCS = " + ctx.getAttribute(prefix+ "vm.vnfc-count"));
231 private String getRelationshipValue(int i, SvcLogicContext ctx, String relatedTo, String relationshipKey, String prefix) throws Exception {
234 if ( relatedTo.equals(ctx.getAttribute(prefix + ".relationship-list.relationship[" + i + "].related-to")) ) {
237 log.info("RELATEDTO " + relatedTo);
238 int relationshipDataLength = 0;
239 String relDataLen = ctx.getAttribute(prefix + ".relationship-list.relationship[" + i + "].relationship-data_length");
241 if ( relDataLen != null )
242 relationshipDataLength = Integer.parseInt(relDataLen);
246 for ( int j =0 ; j < relationshipDataLength ; j++) {
248 String key = ctx.getAttribute(prefix + ".relationship-list.relationship[" + i + "].relationship-data[" + j + "].relationship-key");
250 String value = ctx.getAttribute(prefix + ".relationship-list.relationship[" + i + "].relationship-data[" + j + "].relationship-value");
252 log.info("GENERIC KEY " + key);
253 log.info("GENERIC VALUE " + value);
255 if (relationshipKey.equals(key)) {
260 } // relationshipDataLength
272 public void getVnfcInfo(Map<String, String> params,SvcLogicContext ctx ) throws Exception {
273 log.info("Received getVnfc call with params : " + params);
275 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
276 prefix = StringUtils.isNotBlank(prefix) ? (prefix+".") : "";
278 String vnfcName = params.get("vnfcName");
279 if(StringUtils.isBlank(vnfcName)){
280 throw new Exception("Vnfc Name is missing");
283 String resourceKey = "vnfc.vnfc-name = '" + vnfcName + "'";
285 String queryPrefix = "vnfcInfo";
286 String resourceType = "vnfc";
287 SvcLogicContext vnfcCtx = readResource(resourceKey,queryPrefix,resourceType);
289 // Changes for US 315820 for 1710 vnfc-type renamed to nfc-function,vnfc-function-code renamed to nfc-naming-code
291 /*ctx.setAttribute(prefix+ "vnfc.vnfc-type", vnfcCtx.getAttribute("vnfcInfo.vnfc-type"));
292 ctx.setAttribute(prefix+ "vnfc.vnfc-function-code", vnfcCtx.getAttribute("vnfcInfo.vnfc-function-code"));
293 ctx.setAttribute(prefix+ "vnfc.group-notation", vnfcCtx.getAttribute("vnfcInfo.group-notation"));*/
295 ctx.setAttribute(prefix+ "vnfc.vnfc-type", vnfcCtx.getAttribute("vnfcInfo.nfc-function"));
296 ctx.setAttribute(prefix+ "vnfc.vnfc-function-code", vnfcCtx.getAttribute("vnfcInfo.nfc-naming-code"));
297 ctx.setAttribute(prefix+ "vnfc.group-notation", vnfcCtx.getAttribute("vnfcInfo.group-notation"));
302 public void insertVnfcs(Map<String, String> params,SvcLogicContext ctx, int vnfcRefLen, int vmCount) throws Exception {
303 log.info("Received insertVnfcs call with params : " + params);
305 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
307 prefix = StringUtils.isNotBlank(prefix) ? (prefix+".") : "";
312 for ( int i = 0; i < vmCount ; i++ ) {
313 String aaiRefKey = prefix + "vm[" + i + "].";
315 log.info("VNFCNAME IN INSERTVNFCS " + ctx.getAttribute(aaiRefKey + "vnfc-name"));
316 String numVnfcsStr = ctx.getAttribute(aaiRefKey + "vnfc-count");
319 //if ( numVnfcsStr != null || Integer.parseInt(numVnfcsStr) >= 1 )
322 if ( ctx.getAttribute(aaiRefKey + "vnfc-name") != null )
328 // Get Vnfc_reference data
329 String vnfcRefKey = "vnfcReference[" + vnfcRefIndx + "].";
331 log.info("VNFCREFKEY " + vnfcRefKey);
332 log.info("AAIREFKEY " + aaiRefKey);
334 String vmInstance = ctx.getAttribute(vnfcRefKey+ "VM-INSTANCE");
335 String vnfcInstance = ctx.getAttribute(vnfcRefKey+ "VNFC-INSTANCE");
337 String groupNotationType = ctx.getAttribute(vnfcRefKey+ "GROUP-NOTATION-TYPE");
338 String groupNotationValue = ctx.getAttribute(vnfcRefKey+ "GROUP-NOTATION-VALUE");
340 String vnfcType = ctx.getAttribute(vnfcRefKey+ "VNFC-TYPE");
342 String vnfcFuncCode = ctx.getAttribute(vnfcRefKey+ "VNFC-FUNCTION-CODE");
344 String populateIpAddressV4OamVip = ctx.getAttribute(vnfcRefKey+ "IPADDRESS-V4-OAM-VIP");
347 // Get vnfc Data to be added
348 String vserverName = ctx.getAttribute(aaiRefKey + "vserver-name");
349 String vnfcName = vserverName + vnfcFuncCode + "001";
351 String groupNotation = getGroupNotation(groupNotationType, groupNotationValue, vnfcName, vserverName,prefix, ctx, vnfcType);
354 String ipAddressV4OamVip = null;
355 if ( "Y".equals(populateIpAddressV4OamVip))
356 ipAddressV4OamVip = ctx.getAttribute("vnf-host-ip-address"); // from input
359 Map<String, String> vnfcParams = populateVnfcParams(ctx, aaiRefKey, ipAddressV4OamVip, groupNotation, vnfcType, vnfcFuncCode);
362 addVnfc( vnfcName, vnfcParams, prefix);
364 // Add VNFC Info to context for current added VNFC
365 ctx.setAttribute(aaiRefKey + "vnfc-name", vnfcName);
366 ctx.setAttribute(aaiRefKey + "vnfc-type", vnfcType);
367 ctx.setAttribute(aaiRefKey + "vnfc-function-code", vnfcFuncCode);
368 ctx.setAttribute(aaiRefKey + "group-notation", groupNotation);
377 public Map<String, String> populateVnfcParams(SvcLogicContext ctx, String aaiRefKey,
378 String ipAddressV4OamVip, String groupNotation, String vnfcType, String vnfcFuncCode) throws Exception {
381 Map<String, String> vnfcParams = new HashMap<String, String>();
383 // Changes for US 315820 for 1710 vnfc-type renamed to nfc-function,vnfc-function-code renamed to nfc-naming-code
386 vnfcParams.put("vnfc-function-code", vnfcFuncCode);
387 vnfcParams.put("vnfc-type", vnfcType);
389 vnfcParams.put("nfc-naming-code", vnfcFuncCode);
390 vnfcParams.put("nfc-function", vnfcType);
394 vnfcParams.put("ipaddress-v4-oam-vip", ipAddressV4OamVip);
396 vnfcParams.put("prov-status", "NVTPROV");
397 vnfcParams.put("orchestration-status", "CONFIGURED");
398 vnfcParams.put("in-maint", "false");
399 vnfcParams.put("is-closed-loop", "false");
400 vnfcParams.put("group-notation",groupNotation);
403 vnfcParams.put("relationship-list.relationship[0].related-to","vserver");
404 vnfcParams.put("relationship-list.relationship[0].relationship-data[0].relationship-key","vserver.vserver-id");
405 vnfcParams.put("relationship-list.relationship[0].relationship-data[0].relationship-value",ctx.getAttribute(aaiRefKey + "vserver-id"));
408 vnfcParams.put("relationship-list.relationship[0].relationship-data[1].relationship-key","tenant.tenant-id");
409 vnfcParams.put("relationship-list.relationship[0].relationship-data[1].relationship-value",ctx.getAttribute(aaiRefKey + "tenant-id"));
412 vnfcParams.put("relationship-list.relationship[0].relationship-data[2].relationship-key","cloud-region.cloud-owner");
413 vnfcParams.put("relationship-list.relationship[0].relationship-data[2].relationship-value",ctx.getAttribute(aaiRefKey + "cloud-owner"));
416 vnfcParams.put("relationship-list.relationship[0].relationship-data[3].relationship-key","cloud-region.cloud-region-id");
417 vnfcParams.put("relationship-list.relationship[0].relationship-data[3].relationship-value",ctx.getAttribute(aaiRefKey + "cloud-region-id"));
421 vnfcParams.put("relationship-list.relationship[1].related-to","generic-vnf");
422 vnfcParams.put("relationship-list.relationship[1].relationship-data[0].relationship-key","generic-vnf.vnf-id");
423 vnfcParams.put("relationship-list.relationship[1].relationship-data[0].relationship-value",ctx.getAttribute("vnf-id"));
426 vnfcParams.put("relationship-list.relationship[2].related-to","vf-module");
427 vnfcParams.put("relationship-list.relationship[2].relationship-data[0].relationship-key","generic-vnf.vnf-id");
428 vnfcParams.put("relationship-list.relationship[2].relationship-data[0].relationship-value",ctx.getAttribute("vnf-id"));
431 vnfcParams.put("relationship-list.relationship[2].relationship-data[1].relationship-key","vf-module.vf-module-id");
432 vnfcParams.put("relationship-list.relationship[2].relationship-data[1].relationship-value",ctx.getAttribute(aaiRefKey + "vf-module-id"));
438 public void addVnfc(String vnfcName, Map<String, String> params, String prefix) throws Exception {
440 log.info("Received addVnfc call with vnfcName : " +vnfcName);
441 log.info("Received addVnfc call with params : " + params);
442 String resourceKey = "vnfc.vnfc-name = '" + vnfcName + "'";
444 log.info("Received addVnfc call with resourceKey : " + resourceKey);
447 SvcLogicContext vnfcCtx = new SvcLogicContext();
448 SvcLogicResource.QueryStatus response = aaiClient.save("vnfc", true, false, resourceKey, params, prefix, vnfcCtx) ;
450 if (SvcLogicResource.QueryStatus.SUCCESS.equals(response)) {
451 log.info("Added VNFC SUCCESSFULLY " + vnfcName);
454 else if (SvcLogicResource.QueryStatus.FAILURE.equals(response)) {
455 throw new Exception("VNFC Add failed for for vnfc_name " + vnfcName);
462 public String getGroupNotation(String groupNotationType, String groupNotationValue, String vnfcName,
463 String vserverName, String prefix, SvcLogicContext ctx, String vnfcRefVnfcType) throws Exception {
465 String grpNotation = null;
467 if ( "fixed-value".equals(groupNotationType)) {
468 grpNotation = groupNotationValue;
471 else if ( "first-vnfc-name".equals(groupNotationType) ) {
473 /*If the group-notation-type value = ?first-vnfc-name?,
474 * then populate the group-notation value with the concatenation of
475 * [vnfc name associated with the first vnfc for the vnfc-type (e.g., *******)]
476 * and [the value in group-notation-value (e.g., pair)].
477 * There may be several vnfc-types associated with the VM?s.
479 /* Vnfc-type should be from refrence data */
481 /* vDBE has 2 VNFCs with same VNFC type . The pair name should be same for both . */
482 /* When first VNFC is added details should be added to context so FirstVnfcName doesnt return null second time. */
483 String tmpVnfcName = getFirstVnfcNameForVnfcType(ctx, prefix, vnfcRefVnfcType);
485 log.info("RETURNED FIRSTVNFCNAME" + tmpVnfcName);
486 log.info("CURRENTVNFCNAME" + vnfcName);
487 if ( tmpVnfcName == null ) {
488 log.info("CURRENTVNFCNAME" + vnfcName);
489 // No Vnfcs currently exist. Use Current vnfcName
490 grpNotation = vnfcName + groupNotationValue;
493 grpNotation = tmpVnfcName + groupNotationValue;
497 else if ( "relative-value".equals(groupNotationType) ) {
499 /*If the group-notation-type = ?relative-value?, then find the group-notation value
500 * from the prior vnfc (where prior means the vnfc with where the last three digits of the
501 * vm-name is one lower than the current one; note that this vnfc may have been previously configured.)
502 1. If the group-notation-value = next, then add 1 to the group-notation value from the prior vnfc and use this value
503 2. If the group-notation-value = same, then use the group-notation-value from the prior vnfc record*/
505 // next and same cant be defined for first VM. if next will not generate grpNotation if Prior is not a number
506 String tmpVserverName = null;
507 if ( vserverName != null ) {
509 String vmNamePrefix = vserverName.substring(0,vserverName.length()-3);
511 String lastThreeChars = vserverName.substring(vserverName.length() - 3);
513 if ( NumberUtils.isDigits(lastThreeChars)) {
514 int vmNum = Integer.parseInt(lastThreeChars) - 1;
515 String formatted = String.format("%03d", vmNum);
517 log.info("FORMATTED " + formatted);
519 tmpVserverName = vmNamePrefix + formatted;
522 String priorGroupNotation = getGroupNotationForVServer(ctx, prefix, tmpVserverName);
524 if ( "same".equals(groupNotationValue))
525 grpNotation = priorGroupNotation;
526 else if ( "next".equals(groupNotationValue)) {
527 if ( priorGroupNotation != null && NumberUtils.isDigits(priorGroupNotation)) {
528 int nextGrpNotation = Integer.parseInt(priorGroupNotation) + 1;
529 grpNotation = String.valueOf(nextGrpNotation);
541 log.info("RETURNED GROUPNOTATION " + grpNotation);
545 public String getGroupNotationForVServer(SvcLogicContext ctx, String prefix, String vserverName) throws Exception {
548 String vmCountStr = ctx.getAttribute(prefix+"vnf.vm-count");
550 if ( vmCountStr == null )
553 int vmCount = Integer.valueOf(vmCountStr);
554 for ( int i = 0; i < vmCount ; i++ ) {
556 String tmpVserver = ctx.getAttribute(prefix+ "vm[" + i + "].vserver-name");
558 if (vserverName.equals(tmpVserver))
559 return ctx.getAttribute(prefix+ "vm[" + i + "].group-notation");
570 public String getFirstVnfcNameForVnfcType(SvcLogicContext ctx, String prefix, String vnfcRefVnfcType) throws Exception {
574 /*if(StringUtils.isBlank(vnfcRefVnfcType)){
575 throw new Exception("Vnfc Reference : VNFC Type is missing");
579 String vmCountStr = ctx.getAttribute(prefix+"vnf.vm-count");
581 if ( vmCountStr == null )
584 int vmCount = Integer.valueOf(vmCountStr);
585 for ( int i = 0; i < vmCount ; i++ ) {
587 String tmpvnfcType = ctx.getAttribute(prefix+ "vm[" + i + "].vnfc-type");
589 if (vnfcRefVnfcType.equals(tmpvnfcType))
590 return ctx.getAttribute(prefix+ "vm[" + i + "].vnfc-name");
600 public void updateVServerStatus(Map<String, String> params,SvcLogicContext ctx, int vmCount) throws Exception {
601 log.info("Received updateVServerStatus call with params : " + params);
603 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
605 prefix = StringUtils.isNotBlank(prefix) ? (prefix+".") : "";
608 Map<String, String> vServerParams = new HashMap<String, String>();
611 // TODO - Should this just update prov-status or both? What about generic-vnf status? Will that be updated by Dispatcher?
613 vServerParams.put("prov-status", "NVTPROV");
614 //vServerParams.put("orchestration-status", "CONFIGURED");
617 for ( int i = 0; i < vmCount ; i++ ) {
618 String aaiRefKey = prefix + "vm[" + i + "].";
620 log.info("VNFCNAME IN UpdateVServer " + ctx.getAttribute(aaiRefKey + "vnfc-name"));
622 if ( ctx.getAttribute(aaiRefKey + "vnfc-name") != null )
627 String resourceKey = "vserver.vserver-id = '" + ctx.getAttribute(aaiRefKey + "vserver-id") + "'" +
628 " AND tenant.tenant-id = '" + ctx.getAttribute(aaiRefKey + "tenant-id") + "'" +
629 " AND cloud-region.cloud-owner = '" + ctx.getAttribute(aaiRefKey + "cloud-owner") + "'" +
630 " AND cloud-region.cloud-region-id = '" + ctx.getAttribute(aaiRefKey + "cloud-region-id") + "'";
633 updateResource( "vserver", resourceKey, vServerParams);
642 public void updateVnfStatus(Map<String, String> params,SvcLogicContext ctx) throws Exception {
643 log.info("Received updateVnfStatus call with params : " + params);
645 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
647 prefix = StringUtils.isNotBlank(prefix) ? (prefix+".") : "";
650 Map<String, String> vnfParams = new HashMap<String, String>();
653 // TODO - Should this just update prov-status or both? What about generic-vnf status? Will that be updated by Dispatcher?
655 vnfParams.put("prov-status", "NVTPROV");
656 //vnfParams.put("orchestration-status", "CONFIGURED");
659 String resourceKey = "generic-vnf.vnf-id = '" + ctx.getAttribute("vnf-id") + "'";
661 updateResource( "generic-vnf" , resourceKey, vnfParams);
668 public void updateResource( String resource, String resourceKey, Map<String, String> params) throws Exception {
670 log.info("Received updateResource call with Key : " +resourceKey);
673 SvcLogicContext ctx = new SvcLogicContext();
676 SvcLogicResource.QueryStatus response = aaiClient.update(resource, resourceKey , params, "tmp.update", ctx);
680 if (SvcLogicResource.QueryStatus.SUCCESS.equals(response)) {
681 log.info("Updated " + resource + " SUCCESSFULLY for " + resourceKey);
684 else if (SvcLogicResource.QueryStatus.FAILURE.equals(response)) {
685 throw new Exception(resource + " Update failed for " + resourceKey);
690 public SvcLogicContext readResource(String query, String prefix, String resourceType) throws Exception {
691 SvcLogicContext resourceContext = new SvcLogicContext();
693 SvcLogicResource.QueryStatus response = aaiClient.query(resourceType,false,null,query,prefix,null,resourceContext);
694 log.info("AAIResponse: " + response.toString());
695 if(!SvcLogicResource.QueryStatus.SUCCESS.equals(response)){
696 throw new Exception("Error Retrieving " + resourceType + " from A&AI");
699 return resourceContext;
705 //Added 1710 & Backward Compatibility
707 public void checkAndUpdateVnfc(Map<String, String> params,SvcLogicContext ctx, int vnfcRefLen, int vmCount) throws Exception {
708 log.info("Received checkAndUpdateVnfcStatus call with params : " + params);
710 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
712 prefix = StringUtils.isNotBlank(prefix) ? (prefix+".") : "";
714 for ( int i = 0; i < vmCount ; i++ ) {
715 String aaiRefKey = prefix + "vm[" + i + "].";
717 log.info("VNFCNAME IN INSERTVNFCS "+ aaiRefKey+"vnfc-name:" + ctx.getAttribute(aaiRefKey + "vnfc-name"));
719 String numVnfcsStr = ctx.getAttribute(aaiRefKey + "vnfc-count");
720 String vnfcNameAai = ctx.getAttribute(aaiRefKey + "vnfc-name");
722 if (StringUtils.isNotBlank(vnfcNameAai)) {
723 // Get Vnfc_reference data
724 for(int vnfcRefIndx=0;vnfcRefIndx < vnfcRefLen;vnfcRefIndx++ ) {
726 String vnfcRefKey = "vnfcReference[" + vnfcRefIndx + "].";
728 log.info("VNFCREFKEY " + vnfcRefKey);
729 log.info("AAIREFKEY " + aaiRefKey);
731 String vnfcFuncCode = ctx.getAttribute(vnfcRefKey+ "VNFC-FUNCTION-CODE");
732 String vserverName = ctx.getAttribute(aaiRefKey + "vserver-name");
733 String vnfcNameReference = vserverName + vnfcFuncCode + "001";
735 if(vnfcNameAai.equals(vnfcNameReference)) {
737 updateVnfcStatus( vnfcNameAai, params, prefix);
754 public void updateVnfcStatus(String vnfcName, Map<String, String> params, String prefix) throws Exception {
756 log.info("Received updateVnfcStatus call with vnfcName : " +vnfcName);
757 log.info("Received updateVnfcStatus call with params : " + params);
759 String resourceKey = "vnfc.vnfc-name = '" + vnfcName + "'";
760 log.info("Received updateVnfcStatus call with resourceKey : " + resourceKey);
763 Map<String, String> vnfcParams = new HashMap<String, String>();
764 vnfcParams.put("prov-status", "NVTPROV");
765 vnfcParams.put("orchestration-status", "CONFIGURED");
767 log.info("In updateVnfcStatus call with vnfcParams : " + vnfcParams);
769 updateResource( "vnfc" , resourceKey, vnfcParams);
771 log.info("End of updateVnfcStatus");