Changed to unmaintained
[appc.git] / appc-outbound / appc-aai-client / provider / src / main / java / org / onap / appc / aai / client / aai / AaiService.java
index b10abc4..474ead8 100644 (file)
@@ -5,6 +5,9 @@
  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications (C) 2019 Ericsson
+ * Modifications (C) 2019 IBM
  * =============================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -25,10 +28,6 @@ package org.onap.appc.aai.client.aai;
 
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.math.NumberUtils;
 import org.onap.appc.aai.client.AppcAaiClientConstant;
@@ -41,6 +40,11 @@ import org.osgi.framework.BundleContext;
 import org.osgi.framework.FrameworkUtil;
 import org.osgi.framework.ServiceReference;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 public class AaiService {
 
     private static final EELFLogger log = EELFManager.getInstance().getLogger(AaiService.class);
@@ -68,6 +72,7 @@ public class AaiService {
     private static final String ATTR_VNFC_FUNC_CODE = "VNFC-FUNCTION-CODE";
     private static final String ATTR_VSERVER_NAME = "vserver-name";
     private static final String ATTR_VNF_ID = "vnf-id";
+    private static final String ATTR_VF_MODULE_ID = "vf-module-id";
 
     private AAIClient aaiClient;
 
@@ -238,8 +243,8 @@ public class AaiService {
 
     }
 
-    public void insertVnfcs(Map<String, String> params, SvcLogicContext ctx, int vnfcRefLen, int vmCount,
-        String vfModuleIdFromRequest)
+    public void insertVnfcs(Map<String, String> params, SvcLogicContext ctx, int vmCount,
+                            String vfModuleIdFromRequest)
         throws AaiServiceInternalException, SvcLogicException {
         log.info("Received insertVnfcs call with params : " + params);
 
@@ -253,7 +258,7 @@ public class AaiService {
 
             //ConfigScaleOut - Do not process vms that are not associated with vfmodule id if vfmodule id is present
             if (StringUtils.isNotBlank(vfModuleIdFromRequest)) {
-                String vmVfModuleId = ctx.getAttribute(aaiRefKey + "vf-module-id");
+                String vmVfModuleId = ctx.getAttribute(aaiRefKey + ATTR_VF_MODULE_ID);
                 log.info("insertVnfcs():::vfModule for vm is=" + vmVfModuleId);
                 if (StringUtils.isBlank(vmVfModuleId) || !StringUtils
                     .equalsIgnoreCase(vmVfModuleId, vfModuleIdFromRequest)) {
@@ -263,7 +268,6 @@ public class AaiService {
 
             log.info(QUERY_STR_VNFC_NAME + ctx.getAttribute(aaiRefKey + ATTR_VNFC_NAME));
             String vnfcNameAAI = ctx.getAttribute(aaiRefKey + ATTR_VNFC_NAME);
-
             // Get Vnfc_reference data from the table
             String vnfcRefKey = STR_VNFC_REF + vnfcRefIndx + "].";
 
@@ -310,7 +314,7 @@ public class AaiService {
         }
     }
 
-    public List<String> getVnfcData(Map<String, String> params, SvcLogicContext ctx, int vnfcRefLen, int vmCount) {
+    public List<String> getVnfcData(Map<String, String> params, SvcLogicContext ctx, int vmCount) {
 
         String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
         prefix = StringUtils.isNotBlank(prefix) ? (prefix + ".") : "";
@@ -380,7 +384,7 @@ public class AaiService {
         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"));
+            ctx.getAttribute(aaiRefKey + ATTR_VF_MODULE_ID));
 
         return vnfcParams;
     }
@@ -470,7 +474,7 @@ public class AaiService {
           * if all records do not have the same group-notation value, write the new vnfc record to A&AI inventory without a group-notation value and continue to the next VM in the vnfc_reference table.  A 501 intermediate error message should be sent after all new VNFC records have been added to A&AI.
           * If all records match, use the same group-notation value for the new vnfc record as found in the existing vnfc records.
           */
-            groupNotation = getGroupNotationForExistigValue(ctx, prefix, vnfcFuncCode, vmCount);
+            groupNotation = getGroupNotationForExistigValue(ctx, vnfcFuncCode, vmCount);
         }
 
         log.info("RETURNED GROUPNOTATION " + groupNotation);
@@ -499,8 +503,8 @@ public class AaiService {
         return null;
     }
 
-    public String getGroupNotationForExistigValue(SvcLogicContext ctx, String prefix, String vnfcFuncCode,
-        int vmCount) {
+    public String getGroupNotationForExistigValue(SvcLogicContext ctx, String vnfcFuncCode,
+                                                  int vmCount) {
         String vfModuleId = ctx.getAttribute("req-vf-module-id"); //Coming from request-params
         boolean first = true;
         String aaiGroupNotationValue = null;
@@ -508,7 +512,7 @@ public class AaiService {
             String ind = "tmp.vnfInfo.vm[" + i + "].";
             String aaiFuncCode = ctx.getAttribute(ind + "vnfc-function-code");
             String aaiGroupNotation = ctx.getAttribute(ind + "group-notation");
-            String aaiVfModuleId = ctx.getAttribute(ind + "vf-module-id");
+            String aaiVfModuleId = ctx.getAttribute(ind + ATTR_VF_MODULE_ID);
 
             log.info("getGroupNotationForExistigValue()::: vfModuleId=" + vfModuleId + ", aaiFuncCode=" + aaiFuncCode
                 + ", aaiGroupNotation=" + aaiGroupNotation + ",aaiVfMOduleId=" + aaiVfModuleId);
@@ -643,8 +647,10 @@ public class AaiService {
         SvcLogicResource.QueryStatus response =
             aaiClient.query(resourceType, false, null, query, prefix, null, resourceContext);
         log.info("AAIResponse: " + response.toString());
-        if (!SvcLogicResource.QueryStatus.SUCCESS.equals(response)) {
-            throw new AaiServiceInternalException("Error Retrieving " + resourceType + " from A&AI");
+        if (resourceType==null || !resourceType.equals("cloud-region")) {
+            if (!SvcLogicResource.QueryStatus.SUCCESS.equals(response)) {
+                throw new AaiServiceInternalException("Error Retrieving " + resourceType + " from A&AI");
+            }
         }
         return resourceContext;
     }
@@ -730,7 +736,7 @@ public class AaiService {
 
         String vnfId = params.get("vnfId");
         String vfModuleId = params.get("vfModuleId");
-        String resourceKey = "generic-vnf.vnf-id = '" + vnfId +
+        String resourceKey = STR_VNF_ID + vnfId +
             "' AND vf-module.vf-module-id = '" + vfModuleId + "'";
         String queryPrefix = "vfModuleInfo";
         String resourceType = "vf-module";
@@ -774,12 +780,13 @@ public class AaiService {
         cloudOwner = cloudOwner.replaceAll("'", "");
         cloudRegionId = cloudRegionId.replaceAll("'", "");
         log.debug("cloudOwner" +cloudOwner +"," +"cloudRegionId"+ cloudRegionId);
-        String resourceKey = "cloud-region.cloud-owner = '" + cloudOwner +
+        String resourceKey = "depth = '" + 0 + "' AND cloud-region.cloud-owner = '" + cloudOwner +
                 "' AND cloud-region.cloud-region-id = '" + cloudRegionId + "'";
         String queryPrefix ="urlInfo";
         String resourceType = "cloud-region";
         SvcLogicContext urlCtx = readResource(resourceKey, queryPrefix, resourceType);
         log.info("IdentityUrl: "+urlCtx.getAttribute("urlInfo.identity-url"));
+        log.info("Prefix for getIdentityUrl: "+prefix+"cloud-region.identity-url");
         ctx.setAttribute(prefix+"cloud-region.identity-url", urlCtx.getAttribute("urlInfo.identity-url"));
  
     }