-
- } // relationshipDataLength
-
-
- } // if related-To
-
-
- return null;
-
-
- }
-
-
- public void getVnfcInfo(Map<String, String> params,SvcLogicContext ctx ) throws Exception {
- log.info("Received getVnfc call with params : " + params);
-
- String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
- prefix = StringUtils.isNotBlank(prefix) ? (prefix+".") : "";
-
- String vnfcName = params.get("vnfcName");
- if(StringUtils.isBlank(vnfcName)){
- throw new Exception("Vnfc Name is missing");
- }
-
- String resourceKey = "vnfc.vnfc-name = '" + vnfcName + "'";
-
- String queryPrefix = "vnfcInfo";
- String resourceType = "vnfc";
- SvcLogicContext vnfcCtx = readResource(resourceKey,queryPrefix,resourceType);
-
- // Changes for US 315820 for 1710 vnfc-type renamed to nfc-function,vnfc-function-code renamed to nfc-naming-code
-
- /*ctx.setAttribute(prefix+ "vnfc.vnfc-type", vnfcCtx.getAttribute("vnfcInfo.vnfc-type"));
- ctx.setAttribute(prefix+ "vnfc.vnfc-function-code", vnfcCtx.getAttribute("vnfcInfo.vnfc-function-code"));
- ctx.setAttribute(prefix+ "vnfc.group-notation", vnfcCtx.getAttribute("vnfcInfo.group-notation"));*/
-
- ctx.setAttribute(prefix+ "vnfc.vnfc-type", vnfcCtx.getAttribute("vnfcInfo.nfc-function"));
- ctx.setAttribute(prefix+ "vnfc.vnfc-function-code", vnfcCtx.getAttribute("vnfcInfo.nfc-naming-code"));
- ctx.setAttribute(prefix+ "vnfc.group-notation", vnfcCtx.getAttribute("vnfcInfo.group-notation"));
-
-
- }
-
- public void insertVnfcs(Map<String, String> params,SvcLogicContext ctx, int vnfcRefLen, int vmCount) throws Exception {
- log.info("Received insertVnfcs call with params : " + params);
-
- String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
-
- prefix = StringUtils.isNotBlank(prefix) ? (prefix+".") : "";
-
-
-
- int vnfcRefIndx =-1;
- for ( int i = 0; i < vmCount ; i++ ) {
- String aaiRefKey = prefix + "vm[" + i + "].";
-
- log.info("VNFCNAME IN INSERTVNFCS " + ctx.getAttribute(aaiRefKey + "vnfc-name"));
- String numVnfcsStr = ctx.getAttribute(aaiRefKey + "vnfc-count");
-
-
- //if ( numVnfcsStr != null || Integer.parseInt(numVnfcsStr) >= 1 )
-
-
- if ( ctx.getAttribute(aaiRefKey + "vnfc-name") != null )
- continue;
- else
- vnfcRefIndx++;
-
-
- // Get Vnfc_reference data
- String vnfcRefKey = "vnfcReference[" + vnfcRefIndx + "].";
-
- log.info("VNFCREFKEY " + vnfcRefKey);
- log.info("AAIREFKEY " + aaiRefKey);
-
- String vmInstance = ctx.getAttribute(vnfcRefKey+ "VM-INSTANCE");
- String vnfcInstance = ctx.getAttribute(vnfcRefKey+ "VNFC-INSTANCE");
-
- String groupNotationType = ctx.getAttribute(vnfcRefKey+ "GROUP-NOTATION-TYPE");
- String groupNotationValue = ctx.getAttribute(vnfcRefKey+ "GROUP-NOTATION-VALUE");
-
- String vnfcType = ctx.getAttribute(vnfcRefKey+ "VNFC-TYPE");
-
- String vnfcFuncCode = ctx.getAttribute(vnfcRefKey+ "VNFC-FUNCTION-CODE");
-
- String populateIpAddressV4OamVip = ctx.getAttribute(vnfcRefKey+ "IPADDRESS-V4-OAM-VIP");
-
-
- // Get vnfc Data to be added
- String vserverName = ctx.getAttribute(aaiRefKey + "vserver-name");
- String vnfcName = vserverName + vnfcFuncCode + "001";
-
- String groupNotation = getGroupNotation(groupNotationType, groupNotationValue, vnfcName, vserverName,prefix, ctx, vnfcType);
-
-
- String ipAddressV4OamVip = null;
- if ( "Y".equals(populateIpAddressV4OamVip))
- ipAddressV4OamVip = ctx.getAttribute("vnf-host-ip-address"); // from input
-
-
- Map<String, String> vnfcParams = populateVnfcParams(ctx, aaiRefKey, ipAddressV4OamVip, groupNotation, vnfcType, vnfcFuncCode);
-
-
- addVnfc( vnfcName, vnfcParams, prefix);
-
- // Add VNFC Info to context for current added VNFC
- ctx.setAttribute(aaiRefKey + "vnfc-name", vnfcName);
- ctx.setAttribute(aaiRefKey + "vnfc-type", vnfcType);
- ctx.setAttribute(aaiRefKey + "vnfc-function-code", vnfcFuncCode);
- ctx.setAttribute(aaiRefKey + "group-notation", groupNotation);
-
- }
-
-
- }
-
-
-
- public Map<String, String> populateVnfcParams(SvcLogicContext ctx, String aaiRefKey,
- String ipAddressV4OamVip, String groupNotation, String vnfcType, String vnfcFuncCode) throws Exception {
-
-
- Map<String, String> vnfcParams = new HashMap<String, String>();
-
- // Changes for US 315820 for 1710 vnfc-type renamed to nfc-function,vnfc-function-code renamed to nfc-naming-code
-
- /*
- vnfcParams.put("vnfc-function-code", vnfcFuncCode);
- vnfcParams.put("vnfc-type", vnfcType);
- */
- vnfcParams.put("nfc-naming-code", vnfcFuncCode);
- vnfcParams.put("nfc-function", vnfcType);
-
- //
-
- vnfcParams.put("ipaddress-v4-oam-vip", ipAddressV4OamVip);
-
- vnfcParams.put("prov-status", "NVTPROV");
- vnfcParams.put("orchestration-status", "CONFIGURED");
- vnfcParams.put("in-maint", "false");
- vnfcParams.put("is-closed-loop", "false");
- vnfcParams.put("group-notation",groupNotation);
-
-
- vnfcParams.put("relationship-list.relationship[0].related-to","vserver");
- vnfcParams.put("relationship-list.relationship[0].relationship-data[0].relationship-key","vserver.vserver-id");
- vnfcParams.put("relationship-list.relationship[0].relationship-data[0].relationship-value",ctx.getAttribute(aaiRefKey + "vserver-id"));
-
-
- vnfcParams.put("relationship-list.relationship[0].relationship-data[1].relationship-key","tenant.tenant-id");
- vnfcParams.put("relationship-list.relationship[0].relationship-data[1].relationship-value",ctx.getAttribute(aaiRefKey + "tenant-id"));
-
-
- vnfcParams.put("relationship-list.relationship[0].relationship-data[2].relationship-key","cloud-region.cloud-owner");
- vnfcParams.put("relationship-list.relationship[0].relationship-data[2].relationship-value",ctx.getAttribute(aaiRefKey + "cloud-owner"));
-
-
- vnfcParams.put("relationship-list.relationship[0].relationship-data[3].relationship-key","cloud-region.cloud-region-id");
- vnfcParams.put("relationship-list.relationship[0].relationship-data[3].relationship-value",ctx.getAttribute(aaiRefKey + "cloud-region-id"));
-
-
-
- vnfcParams.put("relationship-list.relationship[1].related-to","generic-vnf");
- vnfcParams.put("relationship-list.relationship[1].relationship-data[0].relationship-key","generic-vnf.vnf-id");
- vnfcParams.put("relationship-list.relationship[1].relationship-data[0].relationship-value",ctx.getAttribute("vnf-id"));
-
-
- vnfcParams.put("relationship-list.relationship[2].related-to","vf-module");
- vnfcParams.put("relationship-list.relationship[2].relationship-data[0].relationship-key","generic-vnf.vnf-id");
- vnfcParams.put("relationship-list.relationship[2].relationship-data[0].relationship-value",ctx.getAttribute("vnf-id"));
-
-
- vnfcParams.put("relationship-list.relationship[2].relationship-data[1].relationship-key","vf-module.vf-module-id");
- vnfcParams.put("relationship-list.relationship[2].relationship-data[1].relationship-value",ctx.getAttribute(aaiRefKey + "vf-module-id"));
-
-
- return vnfcParams;
- }
-
- public void addVnfc(String vnfcName, Map<String, String> params, String prefix) throws Exception {
-
- log.info("Received addVnfc call with vnfcName : " +vnfcName);
- log.info("Received addVnfc call with params : " + params);
- String resourceKey = "vnfc.vnfc-name = '" + vnfcName + "'";
-
- log.info("Received addVnfc call with resourceKey : " + resourceKey);
-
-
- SvcLogicContext vnfcCtx = new SvcLogicContext();
- SvcLogicResource.QueryStatus response = aaiClient.save("vnfc", true, false, resourceKey, params, prefix, vnfcCtx) ;
-
- if (SvcLogicResource.QueryStatus.SUCCESS.equals(response)) {
- log.info("Added VNFC SUCCESSFULLY " + vnfcName);
-
- }
- else if (SvcLogicResource.QueryStatus.FAILURE.equals(response)) {
- throw new Exception("VNFC Add failed for for vnfc_name " + vnfcName);
-
- }
-
-
- }
-
- public String getGroupNotation(String groupNotationType, String groupNotationValue, String vnfcName,
- String vserverName, String prefix, SvcLogicContext ctx, String vnfcRefVnfcType) throws Exception {
-
- String grpNotation = null;
-
- if ( "fixed-value".equals(groupNotationType)) {
- grpNotation = groupNotationValue;
-
- }
- else if ( "first-vnfc-name".equals(groupNotationType) ) {
-
- /*If the group-notation-type value = ?first-vnfc-name?,
- * then populate the group-notation value with the concatenation of
- * [vnfc name associated with the first vnfc for the vnfc-type (e.g., *******)]
- * and [the value in group-notation-value (e.g., pair)].
- * There may be several vnfc-types associated with the VM?s.
- */
- /* Vnfc-type should be from refrence data */
-
- /* vDBE has 2 VNFCs with same VNFC type . The pair name should be same for both . */
- /* When first VNFC is added details should be added to context so FirstVnfcName doesnt return null second time. */
- String tmpVnfcName = getFirstVnfcNameForVnfcType(ctx, prefix, vnfcRefVnfcType);
-
- log.info("RETURNED FIRSTVNFCNAME" + tmpVnfcName);
- log.info("CURRENTVNFCNAME" + vnfcName);
- if ( tmpVnfcName == null ) {
- log.info("CURRENTVNFCNAME" + vnfcName);
- // No Vnfcs currently exist. Use Current vnfcName
- grpNotation = vnfcName + groupNotationValue;
- }
- else
- grpNotation = tmpVnfcName + groupNotationValue;
-
-
- }
- else if ( "relative-value".equals(groupNotationType) ) {
-
- /*If the group-notation-type = ?relative-value?, then find the group-notation value
- * from the prior vnfc (where prior means the vnfc with where the last three digits of the
- * vm-name is one lower than the current one; note that this vnfc may have been previously configured.)
- 1. If the group-notation-value = next, then add 1 to the group-notation value from the prior vnfc and use this value
- 2. If the group-notation-value = same, then use the group-notation-value from the prior vnfc record*/
-
- // next and same cant be defined for first VM. if next will not generate grpNotation if Prior is not a number
- String tmpVserverName = null;
- if ( vserverName != null ) {
-
- String vmNamePrefix = vserverName.substring(0,vserverName.length()-3);
-
- String lastThreeChars = vserverName.substring(vserverName.length() - 3);
-
- if ( NumberUtils.isDigits(lastThreeChars)) {
- int vmNum = Integer.parseInt(lastThreeChars) - 1;
- String formatted = String.format("%03d", vmNum);
-
- log.info("FORMATTED " + formatted);
-
- tmpVserverName = vmNamePrefix + formatted;
-
-
- String priorGroupNotation = getGroupNotationForVServer(ctx, prefix, tmpVserverName);
-
- if ( "same".equals(groupNotationValue))
- grpNotation = priorGroupNotation;
- else if ( "next".equals(groupNotationValue)) {
- if ( priorGroupNotation != null && NumberUtils.isDigits(priorGroupNotation)) {
- int nextGrpNotation = Integer.parseInt(priorGroupNotation) + 1;
- grpNotation = String.valueOf(nextGrpNotation);
- }
- }
- }
-
- }
-
-
-
- }
-
-
- log.info("RETURNED GROUPNOTATION " + grpNotation);
- return grpNotation;
- }
-
- public String getGroupNotationForVServer(SvcLogicContext ctx, String prefix, String vserverName) throws Exception {
-
-
- String vmCountStr = ctx.getAttribute(prefix+"vnf.vm-count");
-
- if ( vmCountStr == null )
- return null;
-
- int vmCount = Integer.valueOf(vmCountStr);
- for ( int i = 0; i < vmCount ; i++ ) {
-
- String tmpVserver = ctx.getAttribute(prefix+ "vm[" + i + "].vserver-name");
-
- if (vserverName.equals(tmpVserver))
- return ctx.getAttribute(prefix+ "vm[" + i + "].group-notation");
-
- } // vmCount
-
- return null;
-
- }
-
-
-
-
- public String getFirstVnfcNameForVnfcType(SvcLogicContext ctx, String prefix, String vnfcRefVnfcType) throws Exception {
-
-
-
- /*if(StringUtils.isBlank(vnfcRefVnfcType)){
- throw new Exception("Vnfc Reference : VNFC Type is missing");
- }*/
-
-
- String vmCountStr = ctx.getAttribute(prefix+"vnf.vm-count");
-
- if ( vmCountStr == null )
- return null;
-
- int vmCount = Integer.valueOf(vmCountStr);
- for ( int i = 0; i < vmCount ; i++ ) {
-
- String tmpvnfcType = ctx.getAttribute(prefix+ "vm[" + i + "].vnfc-type");
-
- if (vnfcRefVnfcType.equals(tmpvnfcType))
- return ctx.getAttribute(prefix+ "vm[" + i + "].vnfc-name");
-
- } // vmCount
-
-
-
- return null;
-
- }
-
- public void updateVServerStatus(Map<String, String> params,SvcLogicContext ctx, int vmCount) throws Exception {
- log.info("Received updateVServerStatus call with params : " + params);
-
- String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
-
- prefix = StringUtils.isNotBlank(prefix) ? (prefix+".") : "";
-
-
- Map<String, String> vServerParams = new HashMap<String, String>();
-
-
- // TODO - Should this just update prov-status or both? What about generic-vnf status? Will that be updated by Dispatcher?
-
- vServerParams.put("prov-status", "NVTPROV");
- //vServerParams.put("orchestration-status", "CONFIGURED");
-
-
- for ( int i = 0; i < vmCount ; i++ ) {
- String aaiRefKey = prefix + "vm[" + i + "].";
-
- log.info("VNFCNAME IN UpdateVServer " + ctx.getAttribute(aaiRefKey + "vnfc-name"));
-
- if ( ctx.getAttribute(aaiRefKey + "vnfc-name") != null )
- continue;
-
-
-
- String resourceKey = "vserver.vserver-id = '" + ctx.getAttribute(aaiRefKey + "vserver-id") + "'" +
- " AND tenant.tenant-id = '" + ctx.getAttribute(aaiRefKey + "tenant-id") + "'" +
- " AND cloud-region.cloud-owner = '" + ctx.getAttribute(aaiRefKey + "cloud-owner") + "'" +
- " AND cloud-region.cloud-region-id = '" + ctx.getAttribute(aaiRefKey + "cloud-region-id") + "'";
-
-
- updateResource( "vserver", resourceKey, vServerParams);
-
- }
-
-
- }
-
-
-
- public void updateVnfStatus(Map<String, String> params,SvcLogicContext ctx) throws Exception {
- log.info("Received updateVnfStatus call with params : " + params);
-
- String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
-
- prefix = StringUtils.isNotBlank(prefix) ? (prefix+".") : "";
-
-
- Map<String, String> vnfParams = new HashMap<String, String>();
-
-
- // TODO - Should this just update prov-status or both? What about generic-vnf status? Will that be updated by Dispatcher?
-
- vnfParams.put("prov-status", "NVTPROV");
- //vnfParams.put("orchestration-status", "CONFIGURED");
-
-
- String resourceKey = "generic-vnf.vnf-id = '" + ctx.getAttribute("vnf-id") + "'";
-
- updateResource( "generic-vnf" , resourceKey, vnfParams);
-
-
-
-
- }
-
- public void updateResource( String resource, String resourceKey, Map<String, String> params) throws Exception {
-
- log.info("Received updateResource call with Key : " +resourceKey);
-
-
- SvcLogicContext ctx = new SvcLogicContext();
-
-
- SvcLogicResource.QueryStatus response = aaiClient.update(resource, resourceKey , params, "tmp.update", ctx);
-
-
-
- if (SvcLogicResource.QueryStatus.SUCCESS.equals(response)) {
- log.info("Updated " + resource + " SUCCESSFULLY for " + resourceKey);
-
- }
- else if (SvcLogicResource.QueryStatus.FAILURE.equals(response)) {
- throw new Exception(resource + " Update failed for " + resourceKey);
-
- }
- }
-
- public SvcLogicContext readResource(String query, String prefix, String resourceType) throws Exception {
+
+ } // relationshipDataLength
+
+ } // if related-To
+
+ return null;
+
+ }
+
+ public void getVnfcInfo(Map<String, String> params,SvcLogicContext ctx ) throws Exception {
+ log.info("Received getVnfc call with params : " + params);
+
+ String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
+ prefix = StringUtils.isNotBlank(prefix) ? (prefix+".") : "";
+
+ String vnfcName = params.get("vnfcName");
+ if(StringUtils.isBlank(vnfcName)){
+ throw new Exception("Vnfc Name is missing");
+ }
+
+ String resourceKey = "vnfc.vnfc-name = '" + vnfcName + "'";
+
+ String queryPrefix = "vnfcInfo";
+ String resourceType = "vnfc";
+ SvcLogicContext vnfcCtx = readResource(resourceKey,queryPrefix,resourceType);
+
+ // Changes for US 315820 for 1710 vnfc-type renamed to nfc-function,vnfc-function-code renamed to nfc-naming-code
+
+ /*ctx.setAttribute(prefix+ "vnfc.vnfc-type", vnfcCtx.getAttribute("vnfcInfo.vnfc-type"));
+ ctx.setAttribute(prefix+ "vnfc.vnfc-function-code", vnfcCtx.getAttribute("vnfcInfo.vnfc-function-code"));
+ ctx.setAttribute(prefix+ "vnfc.group-notation", vnfcCtx.getAttribute("vnfcInfo.group-notation"));*/
+
+ ctx.setAttribute(prefix+ "vnfc.vnfc-type", vnfcCtx.getAttribute("vnfcInfo.nfc-function"));
+ ctx.setAttribute(prefix+ "vnfc.vnfc-function-code", vnfcCtx.getAttribute("vnfcInfo.nfc-naming-code"));
+ ctx.setAttribute(prefix+ "vnfc.group-notation", vnfcCtx.getAttribute("vnfcInfo.group-notation"));
+ ctx.setAttribute(prefix+ "vnfc.ipaddress-v4-oam-vip", vnfcCtx.getAttribute("vnfcInfo.ipaddress-v4-oam-vip"));
+
+ }
+
+ public void insertVnfcs(Map<String, String> params,SvcLogicContext ctx, int vnfcRefLen, int vmCount) throws Exception {
+ log.info("Received insertVnfcs call with params : " + params);
+
+ String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
+
+ prefix = StringUtils.isNotBlank(prefix) ? (prefix +".") : "";
+ int vnfcRefIndx = 0;
+ log.debug("vnfcRefIndx" +vnfcRefIndx);
+ for ( int i = 0; i < vmCount ; i++ ) {
+ String aaiRefKey = prefix + "vm[" + i + "].";
+
+ log.info("VNFCNAME IN INSERTVNFCS " + ctx.getAttribute(aaiRefKey + "vnfc-name"));
+ String numVnfcsStr = ctx.getAttribute(aaiRefKey + "vnfc-count");
+ String vnfcNameAAI = ctx.getAttribute(aaiRefKey + "vnfc-name");
+ //if ( numVnfcsStr != null || Integer.parseInt(numVnfcsStr) >= 1 )
+
+ // Get Vnfc_reference data from the table
+ String vnfcRefKey = "vnfcReference[" + vnfcRefIndx + "].";
+
+ log.info("VNFCREFKEY " + vnfcRefKey);
+ log.info("AAIREFKEY " + aaiRefKey);
+
+ String vmInstance = ctx.getAttribute(vnfcRefKey+ "VM-INSTANCE");
+ String vnfcInstance = ctx.getAttribute(vnfcRefKey+ "VNFC-INSTANCE");
+
+ String groupNotationType = ctx.getAttribute(vnfcRefKey+ "GROUP-NOTATION-TYPE");
+ String groupNotationValue = ctx.getAttribute(vnfcRefKey+ "GROUP-NOTATION-VALUE");
+
+ String vnfcType = ctx.getAttribute(vnfcRefKey+ "VNFC-TYPE");
+
+ String vnfcFuncCode = ctx.getAttribute(vnfcRefKey+ "VNFC-FUNCTION-CODE");
+
+ String populateIpAddressV4OamVip = ctx.getAttribute(vnfcRefKey+ "IPADDRESS-V4-OAM-VIP");
+
+
+ // Get vnfc Data to be added
+ String vserverName = ctx.getAttribute(aaiRefKey + "vserver-name");
+ String vnfcName = vserverName + vnfcFuncCode + "001";
+
+ String groupNotation = getGroupNotation(groupNotationType, groupNotationValue, vnfcName, vserverName,prefix, ctx, vnfcType);
+
+ String ipAddressV4OamVip = null;
+ if ( "Y".equals(populateIpAddressV4OamVip))
+ ipAddressV4OamVip = ctx.getAttribute("vnf-host-ip-address"); // from input
+ Map<String, String> vnfcParams = populateVnfcParams(ctx, aaiRefKey,
+ ipAddressV4OamVip, groupNotation, vnfcType, vnfcFuncCode);
+
+ log.info("Vnfc name from AAI: "+ vnfcNameAAI);
+ log.info("Vnfc name generated: " + vnfcName);
+
+ if (StringUtils.isNotBlank(vnfcNameAAI)) {
+
+ if (vnfcName.equalsIgnoreCase(vnfcNameAAI)) {
+
+ updateVnfcStatus(vnfcNameAAI, params, prefix);
+ vnfcRefIndx++;
+ continue;
+
+ } else
+ continue;
+ }
+ vnfcRefIndx++;
+ addVnfc( vnfcName, vnfcParams, prefix);
+
+ // Add VNFC Info to context for current added VNFC
+ ctx.setAttribute(aaiRefKey + "vnfc-name", vnfcName);
+ ctx.setAttribute(aaiRefKey + "vnfc-type", vnfcType);
+ ctx.setAttribute(aaiRefKey + "vnfc-function-code", vnfcFuncCode);
+ ctx.setAttribute(aaiRefKey + "group-notation", groupNotation);
+
+ }
+
+ }
+
+
+ public List<String> getVnfcData(Map<String, String> params,SvcLogicContext ctx, int vnfcRefLen, int vmCount) throws Exception{
+
+ String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
+ prefix = StringUtils.isNotBlank(prefix) ? (prefix +".") : "";
+ List<String> vnfcNames = new ArrayList<String>();
+ int vnfcRefIndx =-1;
+ for ( int i = 0; i < vmCount ; i++ ) {
+ String aaiRefKey = prefix + "vm[" + i + "].";
+ log.info("VNFCNAME IN INSERTVNFCS " + ctx.getAttribute(aaiRefKey + "vnfc-name"));
+ if ( ctx.getAttribute(aaiRefKey + "vnfc-name") != null )
+ continue;
+ else
+ vnfcRefIndx++;
+ String vnfcRefKey = "vnfcReference[" + vnfcRefIndx + "].";
+ log.info("VNFCREFKEY " + vnfcRefKey);
+ log.info("AAIREFKEY " + aaiRefKey);
+ String groupNotationType = ctx.getAttribute(vnfcRefKey+ "GROUP-NOTATION-TYPE");
+ String groupNotationValue = ctx.getAttribute(vnfcRefKey+ "GROUP-NOTATION-VALUE");
+
+ String vnfcType = ctx.getAttribute(vnfcRefKey+ "VNFC-TYPE");
+
+ String vnfcFuncCode = ctx.getAttribute(vnfcRefKey+ "VNFC-FUNCTION-CODE");
+
+ String populateIpAddressV4OamVip = ctx.getAttribute(vnfcRefKey+ "IPADDRESS-V4-OAM-VIP");
+
+
+ // Get vnfc Data to be added
+ String vserverName = ctx.getAttribute(aaiRefKey + "vserver-name");
+ String vnfcName = vserverName + vnfcFuncCode + "001";
+
+ String groupNotation = getGroupNotation(groupNotationType, groupNotationValue, vnfcName, vserverName,prefix, ctx, vnfcType);
+
+ String ipAddressV4OamVip = null;
+ if ( "Y".equals(populateIpAddressV4OamVip))
+ ipAddressV4OamVip = ctx.getAttribute("vnf-host-ip-address"); // from input
+
+ Map<String, String> vnfcParams = populateVnfcParams(ctx, aaiRefKey, ipAddressV4OamVip, groupNotation, vnfcType, vnfcFuncCode);
+
+ vnfcNames.add(vnfcName);
+
+ }
+
+ return vnfcNames;
+
+ }
+
+ public Map<String, String> populateVnfcParams(SvcLogicContext ctx, String aaiRefKey,
+ String ipAddressV4OamVip, String groupNotation, String vnfcType, String vnfcFuncCode) throws Exception {
+
+ Map<String, String> vnfcParams = new HashMap<String, String>();
+
+ // Changes for US 315820 for 1710 vnfc-type renamed to nfc-function,vnfc-function-code renamed to nfc-naming-code
+
+ /*
+ vnfcParams.put("vnfc-function-code", vnfcFuncCode);
+ vnfcParams.put("vnfc-type", vnfcType);
+ */
+ vnfcParams.put("nfc-naming-code", vnfcFuncCode);
+ vnfcParams.put("nfc-function", vnfcType);
+
+ //
+
+ vnfcParams.put("ipaddress-v4-oam-vip", ipAddressV4OamVip);
+
+ vnfcParams.put("prov-status", "NVTPROV");
+ vnfcParams.put("orchestration-status", "CONFIGURED");
+ vnfcParams.put("in-maint", "false");
+ vnfcParams.put("is-closed-loop", "false");
+ vnfcParams.put("group-notation",groupNotation);
+
+
+ vnfcParams.put("relationship-list.relationship[0].related-to","vserver");
+ vnfcParams.put("relationship-list.relationship[0].relationship-data[0].relationship-key","vserver.vserver-id");
+ vnfcParams.put("relationship-list.relationship[0].relationship-data[0].relationship-value",ctx.getAttribute(aaiRefKey + "vserver-id"));
+
+
+ vnfcParams.put("relationship-list.relationship[0].relationship-data[1].relationship-key","tenant.tenant-id");
+ vnfcParams.put("relationship-list.relationship[0].relationship-data[1].relationship-value",ctx.getAttribute(aaiRefKey + "tenant-id"));
+
+
+ vnfcParams.put("relationship-list.relationship[0].relationship-data[2].relationship-key","cloud-region.cloud-owner");
+ vnfcParams.put("relationship-list.relationship[0].relationship-data[2].relationship-value",ctx.getAttribute(aaiRefKey + "cloud-owner"));
+
+
+ vnfcParams.put("relationship-list.relationship[0].relationship-data[3].relationship-key","cloud-region.cloud-region-id");
+ vnfcParams.put("relationship-list.relationship[0].relationship-data[3].relationship-value",ctx.getAttribute(aaiRefKey + "cloud-region-id"));
+
+
+
+ vnfcParams.put("relationship-list.relationship[1].related-to","generic-vnf");
+ vnfcParams.put("relationship-list.relationship[1].relationship-data[0].relationship-key","generic-vnf.vnf-id");
+ vnfcParams.put("relationship-list.relationship[1].relationship-data[0].relationship-value",ctx.getAttribute("vnf-id"));
+
+
+ vnfcParams.put("relationship-list.relationship[2].related-to","vf-module");
+ vnfcParams.put("relationship-list.relationship[2].relationship-data[0].relationship-key","generic-vnf.vnf-id");
+ vnfcParams.put("relationship-list.relationship[2].relationship-data[0].relationship-value",ctx.getAttribute("vnf-id"));
+
+
+ vnfcParams.put("relationship-list.relationship[2].relationship-data[1].relationship-key","vf-module.vf-module-id");
+ vnfcParams.put("relationship-list.relationship[2].relationship-data[1].relationship-value",ctx.getAttribute(aaiRefKey + "vf-module-id"));
+
+
+ return vnfcParams;
+ }
+
+ public void addVnfc(String vnfcName, Map<String, String> params, String prefix) throws Exception {
+
+ log.info("Received addVnfc call with vnfcName : " +vnfcName);
+ log.info("Received addVnfc call with params : " + params);
+ String resourceKey = "vnfc.vnfc-name = '" + vnfcName + "'";
+
+ log.info("Received addVnfc call with resourceKey : " + resourceKey);
+
+
+ SvcLogicContext vnfcCtx = new SvcLogicContext();
+ SvcLogicResource.QueryStatus response = aaiClient.save("vnfc", true, false, resourceKey, params, prefix, vnfcCtx) ;
+
+ if (SvcLogicResource.QueryStatus.SUCCESS.equals(response)) {
+ log.info("Added VNFC SUCCESSFULLY " + vnfcName);
+
+ }
+ else if (SvcLogicResource.QueryStatus.FAILURE.equals(response)) {
+ throw new Exception("VNFC Add failed for for vnfc_name " + vnfcName);
+
+ }
+
+
+ }
+
+ public String getGroupNotation(String groupNotationType, String groupNotationValue, String vnfcName,
+ String vserverName, String prefix, SvcLogicContext ctx, String vnfcRefVnfcType) throws Exception {
+
+ String grpNotation = null;
+
+ if ( "fixed-value".equals(groupNotationType)) {
+ grpNotation = groupNotationValue;
+
+ }
+ else if ( "first-vnfc-name".equals(groupNotationType) ) {
+
+ /*If the group-notation-type value = ?first-vnfc-name?,
+ * then populate the group-notation value with the concatenation of
+ * [vnfc name associated with the first vnfc for the vnfc-type (e.g., *******)]
+ * and [the value in group-notation-value (e.g., pair)].
+ * There may be several vnfc-types associated with the VM?s.
+ */
+ /* Vnfc-type should be from refrence data */
+
+ /* vDBE has 2 VNFCs with same VNFC type . The pair name should be same for both . */
+ /* When first VNFC is added details should be added to context so FirstVnfcName doesnt return null second time. */
+ String tmpVnfcName = getFirstVnfcNameForVnfcType(ctx, prefix, vnfcRefVnfcType);
+
+ log.info("RETURNED FIRSTVNFCNAME" + tmpVnfcName);
+ log.info("CURRENTVNFCNAME" + vnfcName);
+ if ( tmpVnfcName == null ) {
+ log.info("CURRENTVNFCNAME" + vnfcName);
+ // No Vnfcs currently exist. Use Current vnfcName
+ grpNotation = vnfcName + groupNotationValue;
+ }
+ else
+ grpNotation = tmpVnfcName + groupNotationValue;
+
+
+ }
+ else if ( "relative-value".equals(groupNotationType) ) {
+
+ /*If the group-notation-type = ?relative-value?, then find the group-notation value
+ * from the prior vnfc (where prior means the vnfc with where the last three digits of the
+ * vm-name is one lower than the current one; note that this vnfc may have been previously configured.)
+ 1. If the group-notation-value = next, then add 1 to the group-notation value from the prior vnfc and use this value
+ 2. If the group-notation-value = same, then use the group-notation-value from the prior vnfc record*/
+
+ // next and same cant be defined for first VM. if next will not generate grpNotation if Prior is not a number
+ String tmpVserverName = null;
+ if ( vserverName != null ) {
+
+ String vmNamePrefix = vserverName.substring(0,vserverName.length()-3);
+
+ String lastThreeChars = vserverName.substring(vserverName.length() - 3);
+
+ if ( NumberUtils.isDigits(lastThreeChars)) {
+ int vmNum = Integer.parseInt(lastThreeChars) - 1;
+ String formatted = String.format("%03d", vmNum);
+
+ log.info("FORMATTED " + formatted);
+
+ tmpVserverName = vmNamePrefix + formatted;
+
+
+ String priorGroupNotation = getGroupNotationForVServer(ctx, prefix, tmpVserverName);
+
+ if ( "same".equals(groupNotationValue))
+ grpNotation = priorGroupNotation;
+ else if ( "next".equals(groupNotationValue)) {
+ if ( priorGroupNotation != null && NumberUtils.isDigits(priorGroupNotation)) {
+ int nextGrpNotation = Integer.parseInt(priorGroupNotation) + 1;
+ grpNotation = String.valueOf(nextGrpNotation);
+ }
+ }
+ }
+
+ }
+
+
+
+ }
+
+
+ log.info("RETURNED GROUPNOTATION " + grpNotation);
+ return grpNotation;
+ }
+
+ public String getGroupNotationForVServer(SvcLogicContext ctx, String prefix, String vserverName) throws Exception {
+
+
+ String vmCountStr = ctx.getAttribute(prefix+"vnf.vm-count");
+
+ if ( vmCountStr == null )
+ return null;
+
+ int vmCount = Integer.valueOf(vmCountStr);
+ for ( int i = 0; i < vmCount ; i++ ) {
+
+ String tmpVserver = ctx.getAttribute(prefix+ "vm[" + i + "].vserver-name");
+
+ if (vserverName.equals(tmpVserver))
+ return ctx.getAttribute(prefix+ "vm[" + i + "].group-notation");
+
+ } // vmCount
+
+ return null;
+
+ }
+
+
+
+
+ public String getFirstVnfcNameForVnfcType(SvcLogicContext ctx, String prefix, String vnfcRefVnfcType) throws Exception {
+
+
+
+ /*if(StringUtils.isBlank(vnfcRefVnfcType)){
+ throw new Exception("Vnfc Reference : VNFC Type is missing");
+ }*/
+
+
+ String vmCountStr = ctx.getAttribute(prefix+"vnf.vm-count");
+
+ if ( vmCountStr == null )
+ return null;
+
+ int vmCount = Integer.valueOf(vmCountStr);
+ for ( int i = 0; i < vmCount ; i++ ) {
+
+ String tmpvnfcType = ctx.getAttribute(prefix+ "vm[" + i + "].vnfc-type");
+
+ if (vnfcRefVnfcType.equals(tmpvnfcType))
+ return ctx.getAttribute(prefix+ "vm[" + i + "].vnfc-name");
+
+ } // vmCount
+
+
+
+ return null;
+
+ }
+
+ public void updateVServerStatus(Map<String, String> params,SvcLogicContext ctx, int vmCount) throws Exception {
+ log.info("Received updateVServerStatus call with params : " + params);
+
+ String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
+
+ prefix = StringUtils.isNotBlank(prefix) ? (prefix+".") : "";
+
+
+ Map<String, String> vServerParams = new HashMap<String, String>();
+
+
+ // TODO - Should this just update prov-status or both? What about generic-vnf status? Will that be updated by Dispatcher?
+
+ vServerParams.put("prov-status", "NVTPROV");
+ //vServerParams.put("orchestration-status", "CONFIGURED");
+
+
+ for ( int i = 0; i < vmCount ; i++ ) {
+ String aaiRefKey = prefix + "vm[" + i + "].";
+
+ log.info("VNFCNAME IN UpdateVServer " + ctx.getAttribute(aaiRefKey + "vnfc-name"));
+
+ if ( ctx.getAttribute(aaiRefKey + "vnfc-name") != null )
+ continue;
+
+
+
+ String resourceKey = "vserver.vserver-id = '" + ctx.getAttribute(aaiRefKey + "vserver-id") + "'" +
+ " AND tenant.tenant-id = '" + ctx.getAttribute(aaiRefKey + "tenant-id") + "'" +
+ " AND cloud-region.cloud-owner = '" + ctx.getAttribute(aaiRefKey + "cloud-owner") + "'" +
+ " AND cloud-region.cloud-region-id = '" + ctx.getAttribute(aaiRefKey + "cloud-region-id") + "'";
+
+
+ updateResource( "vserver", resourceKey, vServerParams);
+
+ }
+
+
+ }
+
+
+
+ public void updateVnfStatus(Map<String, String> params,SvcLogicContext ctx) throws Exception {
+ log.info("Received updateVnfStatus call with params : " + params);
+
+ String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
+
+ prefix = StringUtils.isNotBlank(prefix) ? (prefix+".") : "";
+
+
+ Map<String, String> vnfParams = new HashMap<String, String>();
+
+
+ // TODO - Should this just update prov-status or both? What about generic-vnf status? Will that be updated by Dispatcher?
+
+ vnfParams.put("prov-status", "NVTPROV");
+ //vnfParams.put("orchestration-status", "CONFIGURED");
+
+
+ String resourceKey = "generic-vnf.vnf-id = '" + ctx.getAttribute("vnf-id") + "'";
+
+ updateResource( "generic-vnf" , resourceKey, vnfParams);
+
+
+
+
+ }
+
+ public void updateResource( String resource, String resourceKey, Map<String, String> params) throws Exception {
+
+ log.info("Received updateResource call with Key : " +resourceKey);
+
+
+ SvcLogicContext ctx = new SvcLogicContext();
+
+
+ SvcLogicResource.QueryStatus response = aaiClient.update(resource, resourceKey , params, "tmp.update", ctx);
+
+
+
+ if (SvcLogicResource.QueryStatus.SUCCESS.equals(response)) {
+ log.info("Updated " + resource + " SUCCESSFULLY for " + resourceKey);
+
+ }
+ else if (SvcLogicResource.QueryStatus.FAILURE.equals(response)) {
+ throw new Exception(resource + " Update failed for " + resourceKey);
+
+ }
+ }
+
+ public SvcLogicContext readResource(String query, String prefix, String resourceType) throws Exception {