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;
28 import java.util.List;
30 import java.util.ArrayList;
31 import java.util.Collections;
32 import java.util.Comparator;
35 import org.apache.commons.lang3.StringUtils;
36 import org.apache.commons.lang3.math.NumberUtils;
38 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
39 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
41 import org.onap.appc.aai.client.AppcAaiClientConstant;
42 import com.att.eelf.configuration.EELFLogger;
43 import com.att.eelf.configuration.EELFManager;
44 import org.onap.ccsdk.sli.adaptors.aai.AAIClient;
45 import org.onap.ccsdk.sli.adaptors.aai.AAIService;
46 import org.osgi.framework.BundleContext;
47 import org.osgi.framework.FrameworkUtil;
48 import org.osgi.framework.ServiceReference;
50 public class AaiService {
52 private static final EELFLogger log = EELFManager.getInstance().getLogger(AaiService.class);
53 private AAIClient aaiClient;
55 public AaiService(AAIClient aaiClient) {
56 this.aaiClient = aaiClient;
60 BundleContext bctx = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
61 ServiceReference sref = bctx.getServiceReference(AAIService.class);
62 aaiClient = (AAIClient) bctx.getService(sref);
65 public void getGenericVnfInfo(Map<String, String> params, SvcLogicContext ctx) throws Exception {
67 String vnfId = params.get("vnfId");
68 if(StringUtils.isBlank(vnfId)){
69 throw new Exception("VnfId is missing");
71 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
72 prefix = StringUtils.isNotBlank(prefix) ? (prefix+".") : "";
73 //String resourceKey = "generic-vnf.vnf-id = '" + vnfId + "' AND relationship-key = 'vserver.vserver-id'";
74 String resourceKey = "generic-vnf.vnf-id = '" + vnfId + "'";
75 String resourceType = "generic-vnf";
76 String queryPrefix = "vnfInfo";
77 SvcLogicContext vnfCtx = readResource(resourceKey,queryPrefix,resourceType);
79 ctx.setAttribute(prefix + "vnf.vnf-name", vnfCtx.getAttribute("vnfInfo.vnf-name"));
80 ctx.setAttribute(prefix + "vnf.vnf-type", vnfCtx.getAttribute("vnfInfo.vnf-type"));
81 ctx.setAttribute(prefix + "vnf.prov-status", vnfCtx.getAttribute("vnfInfo.prov-status"));
82 ctx.setAttribute(prefix + "vnf.orchestration-status", vnfCtx.getAttribute("vnfInfo.orchestration-status"));
83 ctx.setAttribute(prefix + "vnf.ipv4-oam-address", vnfCtx.getAttribute("vnfInfo.ipv4-oam-address"));
86 String relLen = vnfCtx.getAttribute("vnfInfo.relationship-list.relationship_length");
87 int relationshipLength = 0;
89 relationshipLength = Integer.parseInt(relLen);
90 log.info("RELLEN " + relationshipLength);
91 for ( int i=0; i < relationshipLength; i++ ) {
92 String vserverId = getRelationshipValue(i, vnfCtx, "vserver", "vserver.vserver-id", "vnfInfo");
93 String tenantId = getRelationshipValue(i, vnfCtx, "vserver", "tenant.tenant-id", "vnfInfo");
94 String cloudOwner = getRelationshipValue(i, vnfCtx, "vserver", "cloud-region.cloud-owner", "vnfInfo");
95 String cloudRegionId = getRelationshipValue(i, vnfCtx, "vserver", "cloud-region.cloud-region-id", "vnfInfo");
96 if ( vserverId != null ) {
97 log.info("VSERVER KEYS " + vserverId + " " + tenantId + " " + cloudOwner + " " + cloudRegionId);
98 String vnfPrefix = prefix + "vm[" + vmCount + "].";
99 ctx.setAttribute(vnfPrefix + "vserver-id", vserverId);
100 ctx.setAttribute(vnfPrefix + "tenant-id", tenantId);
101 ctx.setAttribute(vnfPrefix + "cloud-owner", cloudOwner);
102 ctx.setAttribute(vnfPrefix + "cloud-region-id", cloudRegionId);
106 ctx.setAttribute(prefix + "vm-count", String.valueOf(vmCount));
107 log.info("VMCOUNT FROM VNF INFO " + ctx.getAttribute(prefix + "vm-count"));
110 public void getVMInfo(Map<String, String> params,SvcLogicContext ctx )throws Exception {
111 log.info("Received getVmInfo call with params : " + params);
112 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
113 prefix = StringUtils.isNotBlank(prefix) ? (prefix+".") : "";
115 ctx.setAttribute(prefix + "vm.vnfc-count", String.valueOf(vnfcCount)); // Incase no vnfcs are found
116 String vserverId = params.get("vserverId");
117 if(StringUtils.isBlank(vserverId)){
118 throw new Exception("VServerId is missing");
120 String tenantId = params.get("tenantId");
121 if(StringUtils.isBlank(tenantId)){
122 throw new Exception("TenantId is missing");
124 String cloudOwner = params.get("cloudOwner");
125 if(StringUtils.isBlank(cloudOwner)){
126 throw new Exception("Cloud Owner is missing");
128 String cloudRegionId = params.get("cloudRegionId");
129 if(StringUtils.isBlank(cloudRegionId)){
130 throw new Exception("Cloud region Id is missing");
132 String resourceKey = "vserver.vserver-id = '" +vserverId + "' AND tenant.tenant-id = '" + tenantId +
133 "' AND cloud-region.cloud-owner = '" +cloudOwner +
134 "' AND cloud-region.cloud-region-id = '" +cloudRegionId + "'";
135 String queryPrefix = "vmInfo";
136 String resourceType = "vserver";
137 SvcLogicContext vmCtx = readResource(resourceKey,queryPrefix,resourceType);
139 ctx.setAttribute(prefix+ "vm.prov-status", vmCtx.getAttribute("vmInfo.prov-status"));
140 ctx.setAttribute(prefix+ "vm.vserver-name", vmCtx.getAttribute("vmInfo.vserver-name"));
142 String relLen = vmCtx.getAttribute("vmInfo.relationship-list.relationship_length");
143 int relationshipLength = 0;
144 if ( relLen != null )
145 relationshipLength = Integer.parseInt(relLen);
146 log.info("RELLEN" + relationshipLength);
147 for ( int i=0; i < relationshipLength; i++ ) {
148 String vfModuleId = getRelationshipValue(i, vmCtx, "vf-module", "vf-module.vf-module-id", "vmInfo");
149 if ( vfModuleId != null )
150 ctx.setAttribute(prefix + "vm.vf-module-id", vfModuleId);
152 String vnfcName = getRelationshipValue(i, vmCtx, "vnfc", "vnfc.vnfc-name", "vmInfo");
153 if ( vnfcName != null ) {
154 ctx.setAttribute(prefix + "vm.vnfc[" + vnfcCount + "].vnfc-name", vnfcName);
158 } //relationshipLength
159 ctx.setAttribute(prefix + "vm.vnfc-count", String.valueOf(vnfcCount));
160 log.info("VSERVERNAME " + ctx.getAttribute(prefix+ "vm.vserver-name") + " HAS NUM VNFCS = " + ctx.getAttribute(prefix+ "vm.vnfc-count"));
163 private String getRelationshipValue(int i, SvcLogicContext ctx, String relatedTo, String relationshipKey, String prefix) throws Exception {
165 if ( relatedTo.equals(ctx.getAttribute(prefix + ".relationship-list.relationship[" + i + "].related-to")) ) {
166 log.info("RELATEDTO " + relatedTo);
167 int relationshipDataLength = 0;
168 String relDataLen = ctx.getAttribute(prefix + ".relationship-list.relationship[" + i + "].relationship-data_length");
169 if ( relDataLen != null )
170 relationshipDataLength = Integer.parseInt(relDataLen);
172 for ( int j =0 ; j < relationshipDataLength ; j++) {
174 String key = ctx.getAttribute(prefix + ".relationship-list.relationship[" + i + "].relationship-data[" + j + "].relationship-key");
176 String value = ctx.getAttribute(prefix + ".relationship-list.relationship[" + i + "].relationship-data[" + j + "].relationship-value");
178 log.info("GENERIC KEY " + key);
179 log.info("GENERIC VALUE " + value);
181 if (relationshipKey.equals(key)) {
185 } // 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 + "'";
206 String queryPrefix = "vnfcInfo";
207 String resourceType = "vnfc";
208 SvcLogicContext vnfcCtx = readResource(resourceKey,queryPrefix,resourceType);
210 // Changes for US 315820 for 1710 vnfc-type renamed to nfc-function,vnfc-function-code renamed to nfc-naming-code
212 /*ctx.setAttribute(prefix+ "vnfc.vnfc-type", vnfcCtx.getAttribute("vnfcInfo.vnfc-type"));
213 ctx.setAttribute(prefix+ "vnfc.vnfc-function-code", vnfcCtx.getAttribute("vnfcInfo.vnfc-function-code"));
214 ctx.setAttribute(prefix+ "vnfc.group-notation", vnfcCtx.getAttribute("vnfcInfo.group-notation"));*/
216 ctx.setAttribute(prefix+ "vnfc.vnfc-type", vnfcCtx.getAttribute("vnfcInfo.nfc-function"));
217 ctx.setAttribute(prefix+ "vnfc.vnfc-function-code", vnfcCtx.getAttribute("vnfcInfo.nfc-naming-code"));
218 ctx.setAttribute(prefix+ "vnfc.group-notation", vnfcCtx.getAttribute("vnfcInfo.group-notation"));
219 ctx.setAttribute(prefix+ "vnfc.ipaddress-v4-oam-vip", vnfcCtx.getAttribute("vnfcInfo.ipaddress-v4-oam-vip"));
223 public void insertVnfcs(Map<String, String> params,SvcLogicContext ctx, int vnfcRefLen, int vmCount) throws Exception {
224 log.info("Received insertVnfcs call with params : " + params);
226 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
228 prefix = StringUtils.isNotBlank(prefix) ? (prefix +".") : "";
230 log.debug("vnfcRefIndx" +vnfcRefIndx);
231 for ( int i = 0; i < vmCount ; i++ ) {
232 String aaiRefKey = prefix + "vm[" + i + "].";
234 log.info("VNFCNAME IN INSERTVNFCS " + ctx.getAttribute(aaiRefKey + "vnfc-name"));
235 String numVnfcsStr = ctx.getAttribute(aaiRefKey + "vnfc-count");
236 String vnfcNameAAI = ctx.getAttribute(aaiRefKey + "vnfc-name");
237 //if ( numVnfcsStr != null || Integer.parseInt(numVnfcsStr) >= 1 )
239 // Get Vnfc_reference data from the table
240 String vnfcRefKey = "vnfcReference[" + vnfcRefIndx + "].";
242 log.info("VNFCREFKEY " + vnfcRefKey);
243 log.info("AAIREFKEY " + aaiRefKey);
245 String vmInstance = ctx.getAttribute(vnfcRefKey+ "VM-INSTANCE");
246 String vnfcInstance = ctx.getAttribute(vnfcRefKey+ "VNFC-INSTANCE");
248 String groupNotationType = ctx.getAttribute(vnfcRefKey+ "GROUP-NOTATION-TYPE");
249 String groupNotationValue = ctx.getAttribute(vnfcRefKey+ "GROUP-NOTATION-VALUE");
251 String vnfcType = ctx.getAttribute(vnfcRefKey+ "VNFC-TYPE");
253 String vnfcFuncCode = ctx.getAttribute(vnfcRefKey+ "VNFC-FUNCTION-CODE");
255 String populateIpAddressV4OamVip = ctx.getAttribute(vnfcRefKey+ "IPADDRESS-V4-OAM-VIP");
258 // Get vnfc Data to be added
259 String vserverName = ctx.getAttribute(aaiRefKey + "vserver-name");
260 String vnfcName = vserverName + vnfcFuncCode + "001";
262 String groupNotation = getGroupNotation(groupNotationType, groupNotationValue, vnfcName, vserverName,prefix, ctx, vnfcType);
264 String ipAddressV4OamVip = null;
265 if ( "Y".equals(populateIpAddressV4OamVip))
266 ipAddressV4OamVip = ctx.getAttribute("vnf-host-ip-address"); // from input
267 Map<String, String> vnfcParams = populateVnfcParams(ctx, aaiRefKey,
268 ipAddressV4OamVip, groupNotation, vnfcType, vnfcFuncCode);
270 log.info("Vnfc name from AAI: "+ vnfcNameAAI);
271 log.info("Vnfc name generated: " + vnfcName);
273 if (StringUtils.isNotBlank(vnfcNameAAI)) {
275 if (vnfcName.equalsIgnoreCase(vnfcNameAAI)) {
277 updateVnfcStatus(vnfcNameAAI, params, prefix);
285 addVnfc( vnfcName, vnfcParams, prefix);
287 // Add VNFC Info to context for current added VNFC
288 ctx.setAttribute(aaiRefKey + "vnfc-name", vnfcName);
289 ctx.setAttribute(aaiRefKey + "vnfc-type", vnfcType);
290 ctx.setAttribute(aaiRefKey + "vnfc-function-code", vnfcFuncCode);
291 ctx.setAttribute(aaiRefKey + "group-notation", groupNotation);
298 public List<String> getVnfcData(Map<String, String> params,SvcLogicContext ctx, int vnfcRefLen, int vmCount) throws Exception{
300 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
301 prefix = StringUtils.isNotBlank(prefix) ? (prefix +".") : "";
302 List<String> vnfcNames = new ArrayList<String>();
304 for ( int i = 0; i < vmCount ; i++ ) {
305 String aaiRefKey = prefix + "vm[" + i + "].";
306 log.info("VNFCNAME IN INSERTVNFCS " + ctx.getAttribute(aaiRefKey + "vnfc-name"));
307 if ( ctx.getAttribute(aaiRefKey + "vnfc-name") != null )
311 String vnfcRefKey = "vnfcReference[" + vnfcRefIndx + "].";
312 log.info("VNFCREFKEY " + vnfcRefKey);
313 log.info("AAIREFKEY " + aaiRefKey);
314 String groupNotationType = ctx.getAttribute(vnfcRefKey+ "GROUP-NOTATION-TYPE");
315 String groupNotationValue = ctx.getAttribute(vnfcRefKey+ "GROUP-NOTATION-VALUE");
317 String vnfcType = ctx.getAttribute(vnfcRefKey+ "VNFC-TYPE");
319 String vnfcFuncCode = ctx.getAttribute(vnfcRefKey+ "VNFC-FUNCTION-CODE");
321 String populateIpAddressV4OamVip = ctx.getAttribute(vnfcRefKey+ "IPADDRESS-V4-OAM-VIP");
324 // Get vnfc Data to be added
325 String vserverName = ctx.getAttribute(aaiRefKey + "vserver-name");
326 String vnfcName = vserverName + vnfcFuncCode + "001";
328 String groupNotation = getGroupNotation(groupNotationType, groupNotationValue, vnfcName, vserverName,prefix, ctx, vnfcType);
330 String ipAddressV4OamVip = null;
331 if ( "Y".equals(populateIpAddressV4OamVip))
332 ipAddressV4OamVip = ctx.getAttribute("vnf-host-ip-address"); // from input
334 Map<String, String> vnfcParams = populateVnfcParams(ctx, aaiRefKey, ipAddressV4OamVip, groupNotation, vnfcType, vnfcFuncCode);
336 vnfcNames.add(vnfcName);
344 public Map<String, String> populateVnfcParams(SvcLogicContext ctx, String aaiRefKey,
345 String ipAddressV4OamVip, String groupNotation, String vnfcType, String vnfcFuncCode) throws Exception {
347 Map<String, String> vnfcParams = new HashMap<String, String>();
349 // Changes for US 315820 for 1710 vnfc-type renamed to nfc-function,vnfc-function-code renamed to nfc-naming-code
352 vnfcParams.put("vnfc-function-code", vnfcFuncCode);
353 vnfcParams.put("vnfc-type", vnfcType);
355 vnfcParams.put("nfc-naming-code", vnfcFuncCode);
356 vnfcParams.put("nfc-function", vnfcType);
360 vnfcParams.put("ipaddress-v4-oam-vip", ipAddressV4OamVip);
362 vnfcParams.put("prov-status", "NVTPROV");
363 vnfcParams.put("orchestration-status", "CONFIGURED");
364 vnfcParams.put("in-maint", "false");
365 vnfcParams.put("is-closed-loop", "false");
366 vnfcParams.put("group-notation",groupNotation);
369 vnfcParams.put("relationship-list.relationship[0].related-to","vserver");
370 vnfcParams.put("relationship-list.relationship[0].relationship-data[0].relationship-key","vserver.vserver-id");
371 vnfcParams.put("relationship-list.relationship[0].relationship-data[0].relationship-value",ctx.getAttribute(aaiRefKey + "vserver-id"));
374 vnfcParams.put("relationship-list.relationship[0].relationship-data[1].relationship-key","tenant.tenant-id");
375 vnfcParams.put("relationship-list.relationship[0].relationship-data[1].relationship-value",ctx.getAttribute(aaiRefKey + "tenant-id"));
378 vnfcParams.put("relationship-list.relationship[0].relationship-data[2].relationship-key","cloud-region.cloud-owner");
379 vnfcParams.put("relationship-list.relationship[0].relationship-data[2].relationship-value",ctx.getAttribute(aaiRefKey + "cloud-owner"));
382 vnfcParams.put("relationship-list.relationship[0].relationship-data[3].relationship-key","cloud-region.cloud-region-id");
383 vnfcParams.put("relationship-list.relationship[0].relationship-data[3].relationship-value",ctx.getAttribute(aaiRefKey + "cloud-region-id"));
387 vnfcParams.put("relationship-list.relationship[1].related-to","generic-vnf");
388 vnfcParams.put("relationship-list.relationship[1].relationship-data[0].relationship-key","generic-vnf.vnf-id");
389 vnfcParams.put("relationship-list.relationship[1].relationship-data[0].relationship-value",ctx.getAttribute("vnf-id"));
392 vnfcParams.put("relationship-list.relationship[2].related-to","vf-module");
393 vnfcParams.put("relationship-list.relationship[2].relationship-data[0].relationship-key","generic-vnf.vnf-id");
394 vnfcParams.put("relationship-list.relationship[2].relationship-data[0].relationship-value",ctx.getAttribute("vnf-id"));
397 vnfcParams.put("relationship-list.relationship[2].relationship-data[1].relationship-key","vf-module.vf-module-id");
398 vnfcParams.put("relationship-list.relationship[2].relationship-data[1].relationship-value",ctx.getAttribute(aaiRefKey + "vf-module-id"));
404 public void addVnfc(String vnfcName, Map<String, String> params, String prefix) throws Exception {
406 log.info("Received addVnfc call with vnfcName : " +vnfcName);
407 log.info("Received addVnfc call with params : " + params);
408 String resourceKey = "vnfc.vnfc-name = '" + vnfcName + "'";
410 log.info("Received addVnfc call with resourceKey : " + resourceKey);
413 SvcLogicContext vnfcCtx = new SvcLogicContext();
414 SvcLogicResource.QueryStatus response = aaiClient.save("vnfc", true, false, resourceKey, params, prefix, vnfcCtx) ;
416 if (SvcLogicResource.QueryStatus.SUCCESS.equals(response)) {
417 log.info("Added VNFC SUCCESSFULLY " + vnfcName);
420 else if (SvcLogicResource.QueryStatus.FAILURE.equals(response)) {
421 throw new Exception("VNFC Add failed for for vnfc_name " + vnfcName);
428 public String getGroupNotation(String groupNotationType, String groupNotationValue, String vnfcName,
429 String vserverName, String prefix, SvcLogicContext ctx, String vnfcRefVnfcType) throws Exception {
431 String grpNotation = null;
433 if ( "fixed-value".equals(groupNotationType)) {
434 grpNotation = groupNotationValue;
437 else if ( "first-vnfc-name".equals(groupNotationType) ) {
439 /*If the group-notation-type value = ?first-vnfc-name?,
440 * then populate the group-notation value with the concatenation of
441 * [vnfc name associated with the first vnfc for the vnfc-type (e.g., *******)]
442 * and [the value in group-notation-value (e.g., pair)].
443 * There may be several vnfc-types associated with the VM?s.
445 /* Vnfc-type should be from refrence data */
447 /* vDBE has 2 VNFCs with same VNFC type . The pair name should be same for both . */
448 /* When first VNFC is added details should be added to context so FirstVnfcName doesnt return null second time. */
449 String tmpVnfcName = getFirstVnfcNameForVnfcType(ctx, prefix, vnfcRefVnfcType);
451 log.info("RETURNED FIRSTVNFCNAME" + tmpVnfcName);
452 log.info("CURRENTVNFCNAME" + vnfcName);
453 if ( tmpVnfcName == null ) {
454 log.info("CURRENTVNFCNAME" + vnfcName);
455 // No Vnfcs currently exist. Use Current vnfcName
456 grpNotation = vnfcName + groupNotationValue;
459 grpNotation = tmpVnfcName + groupNotationValue;
463 else if ( "relative-value".equals(groupNotationType) ) {
465 /*If the group-notation-type = ?relative-value?, then find the group-notation value
466 * from the prior vnfc (where prior means the vnfc with where the last three digits of the
467 * vm-name is one lower than the current one; note that this vnfc may have been previously configured.)
468 1. If the group-notation-value = next, then add 1 to the group-notation value from the prior vnfc and use this value
469 2. If the group-notation-value = same, then use the group-notation-value from the prior vnfc record*/
471 // next and same cant be defined for first VM. if next will not generate grpNotation if Prior is not a number
472 String tmpVserverName = null;
473 if ( vserverName != null ) {
475 String vmNamePrefix = vserverName.substring(0,vserverName.length()-3);
477 String lastThreeChars = vserverName.substring(vserverName.length() - 3);
479 if ( NumberUtils.isDigits(lastThreeChars)) {
480 int vmNum = Integer.parseInt(lastThreeChars) - 1;
481 String formatted = String.format("%03d", vmNum);
483 log.info("FORMATTED " + formatted);
485 tmpVserverName = vmNamePrefix + formatted;
488 String priorGroupNotation = getGroupNotationForVServer(ctx, prefix, tmpVserverName);
490 if ( "same".equals(groupNotationValue))
491 grpNotation = priorGroupNotation;
492 else if ( "next".equals(groupNotationValue)) {
493 if ( priorGroupNotation != null && NumberUtils.isDigits(priorGroupNotation)) {
494 int nextGrpNotation = Integer.parseInt(priorGroupNotation) + 1;
495 grpNotation = String.valueOf(nextGrpNotation);
507 log.info("RETURNED GROUPNOTATION " + grpNotation);
511 public String getGroupNotationForVServer(SvcLogicContext ctx, String prefix, String vserverName) throws Exception {
514 String vmCountStr = ctx.getAttribute(prefix+"vnf.vm-count");
516 if ( vmCountStr == null )
519 int vmCount = Integer.valueOf(vmCountStr);
520 for ( int i = 0; i < vmCount ; i++ ) {
522 String tmpVserver = ctx.getAttribute(prefix+ "vm[" + i + "].vserver-name");
524 if (vserverName.equals(tmpVserver))
525 return ctx.getAttribute(prefix+ "vm[" + i + "].group-notation");
536 public String getFirstVnfcNameForVnfcType(SvcLogicContext ctx, String prefix, String vnfcRefVnfcType) throws Exception {
540 /*if(StringUtils.isBlank(vnfcRefVnfcType)){
541 throw new Exception("Vnfc Reference : VNFC Type is missing");
545 String vmCountStr = ctx.getAttribute(prefix+"vnf.vm-count");
547 if ( vmCountStr == null )
550 int vmCount = Integer.valueOf(vmCountStr);
551 for ( int i = 0; i < vmCount ; i++ ) {
553 String tmpvnfcType = ctx.getAttribute(prefix+ "vm[" + i + "].vnfc-type");
555 if (vnfcRefVnfcType.equals(tmpvnfcType))
556 return ctx.getAttribute(prefix+ "vm[" + i + "].vnfc-name");
566 public void updateVServerStatus(Map<String, String> params,SvcLogicContext ctx, int vmCount) throws Exception {
567 log.info("Received updateVServerStatus call with params : " + params);
569 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
571 prefix = StringUtils.isNotBlank(prefix) ? (prefix+".") : "";
574 Map<String, String> vServerParams = new HashMap<String, String>();
577 // TODO - Should this just update prov-status or both? What about generic-vnf status? Will that be updated by Dispatcher?
579 vServerParams.put("prov-status", "NVTPROV");
580 //vServerParams.put("orchestration-status", "CONFIGURED");
583 for ( int i = 0; i < vmCount ; i++ ) {
584 String aaiRefKey = prefix + "vm[" + i + "].";
586 log.info("VNFCNAME IN UpdateVServer " + ctx.getAttribute(aaiRefKey + "vnfc-name"));
588 if ( ctx.getAttribute(aaiRefKey + "vnfc-name") != null )
593 String resourceKey = "vserver.vserver-id = '" + ctx.getAttribute(aaiRefKey + "vserver-id") + "'" +
594 " AND tenant.tenant-id = '" + ctx.getAttribute(aaiRefKey + "tenant-id") + "'" +
595 " AND cloud-region.cloud-owner = '" + ctx.getAttribute(aaiRefKey + "cloud-owner") + "'" +
596 " AND cloud-region.cloud-region-id = '" + ctx.getAttribute(aaiRefKey + "cloud-region-id") + "'";
599 updateResource( "vserver", resourceKey, vServerParams);
608 public void updateVnfStatus(Map<String, String> params,SvcLogicContext ctx) throws Exception {
609 log.info("Received updateVnfStatus call with params : " + params);
611 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
613 prefix = StringUtils.isNotBlank(prefix) ? (prefix+".") : "";
616 Map<String, String> vnfParams = new HashMap<String, String>();
619 // TODO - Should this just update prov-status or both? What about generic-vnf status? Will that be updated by Dispatcher?
621 vnfParams.put("prov-status", "NVTPROV");
622 //vnfParams.put("orchestration-status", "CONFIGURED");
625 String resourceKey = "generic-vnf.vnf-id = '" + ctx.getAttribute("vnf-id") + "'";
627 updateResource( "generic-vnf" , resourceKey, vnfParams);
634 public void updateResource( String resource, String resourceKey, Map<String, String> params) throws Exception {
636 log.info("Received updateResource call with Key : " +resourceKey);
639 SvcLogicContext ctx = new SvcLogicContext();
642 SvcLogicResource.QueryStatus response = aaiClient.update(resource, resourceKey , params, "tmp.update", ctx);
646 if (SvcLogicResource.QueryStatus.SUCCESS.equals(response)) {
647 log.info("Updated " + resource + " SUCCESSFULLY for " + resourceKey);
650 else if (SvcLogicResource.QueryStatus.FAILURE.equals(response)) {
651 throw new Exception(resource + " Update failed for " + resourceKey);
656 public SvcLogicContext readResource(String query, String prefix, String resourceType) throws Exception {
657 SvcLogicContext resourceContext = new SvcLogicContext();
659 SvcLogicResource.QueryStatus response = aaiClient.query(resourceType,false,null,query,prefix,null,resourceContext);
660 log.info("AAIResponse: " + response.toString());
661 if(!SvcLogicResource.QueryStatus.SUCCESS.equals(response)){
662 throw new Exception("Error Retrieving " + resourceType + " from A&AI");
665 return resourceContext;
671 //Added 1710 & Backward Compatibility
673 public void checkAndUpdateVnfc(Map<String, String> params,SvcLogicContext ctx, int vnfcRefLen, int vmCount) throws Exception {
674 log.info("Received checkAndUpdateVnfcStatus call with params : " + params);
676 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
678 prefix = StringUtils.isNotBlank(prefix) ? (prefix+".") : "";
680 for ( int i = 0; i < vmCount ; i++ ) {
681 String aaiRefKey = prefix + "vm[" + i + "].";
683 log.info("VNFCNAME IN INSERTVNFCS "+ aaiRefKey+"vnfc-name:" + ctx.getAttribute(aaiRefKey + "vnfc-name"));
685 String numVnfcsStr = ctx.getAttribute(aaiRefKey + "vnfc-count");
686 String vnfcNameAai = ctx.getAttribute(aaiRefKey + "vnfc-name");
688 if (StringUtils.isNotBlank(vnfcNameAai)) {
689 // Get Vnfc_reference data
690 for(int vnfcRefIndx=0;vnfcRefIndx < vnfcRefLen;vnfcRefIndx++ ) {
692 String vnfcRefKey = "vnfcReference[" + vnfcRefIndx + "].";
694 log.info("VNFCREFKEY " + vnfcRefKey);
695 log.info("AAIREFKEY " + aaiRefKey);
697 String vnfcFuncCode = ctx.getAttribute(vnfcRefKey+ "VNFC-FUNCTION-CODE");
698 String vserverName = ctx.getAttribute(aaiRefKey + "vserver-name");
699 String vnfcNameReference = vserverName + vnfcFuncCode + "001";
701 if(vnfcNameAai.equals(vnfcNameReference)) {
703 updateVnfcStatus( vnfcNameAai, params, prefix);
720 public void updateVnfcStatus(String vnfcName, Map<String, String> params, String prefix) throws Exception {
722 log.info("Received updateVnfcStatus call with vnfcName : " +vnfcName);
723 log.info("Received updateVnfcStatus call with params : " + params);
725 String resourceKey = "vnfc.vnfc-name = '" + vnfcName + "'";
726 log.info("Received updateVnfcStatus call with resourceKey : " + resourceKey);
729 Map<String, String> vnfcParams = new HashMap<String, String>();
730 vnfcParams.put("prov-status", "NVTPROV");
731 vnfcParams.put("orchestration-status", "CONFIGURED");
733 log.info("In updateVnfcStatus call with vnfcParams : " + vnfcParams);
735 updateResource( "vnfc" , resourceKey, vnfcParams);
737 log.info("End of updateVnfcStatus");
741 public void updateVnfStatusWithOAMAddress(Map<String, String> params, SvcLogicContext ctx) throws Exception {
742 log.info("Received updateVnfStatusWithOAMAddress call with params : " + params);
744 String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
745 String ipAddress = ctx.getAttribute("vnf-host-ip-address");
746 log.debug("Vnf-host-ip-address" + ipAddress);
748 prefix = StringUtils.isNotBlank(prefix) ? (prefix+".") : "";
750 Map<String, String> vnfParams = new HashMap<String, String>();
752 vnfParams.put("ipv4-oam-address", ipAddress);
754 String resourceKey = "generic-vnf.vnf-id = '" + ctx.getAttribute("vnf-id") + "'";
756 updateResource( "generic-vnf" , resourceKey, vnfParams);