Updates to config data services bundle 35/27235/2
authorGeorge, Lina (lg941u) <lg941u@att.com>
Wed, 3 Jan 2018 05:35:33 +0000 (00:35 -0500)
committerPatrick Brady <pb071s@att.com>
Wed, 3 Jan 2018 20:12:19 +0000 (20:12 +0000)
Issue-ID: APPC-350
Change-Id: Id5738986a40f8c094c0ce2fc0033d378796733cf
Signed-off-by: George, Lina (lg941u) <lg941u@att.com>
appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/AppcDataServiceConstant.java
appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/db/DGGeneralDBService.java
appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/node/ConfigResourceNode.java
appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/db/TestConfigResourceNode.java

index 9add56b..c26a470 100644 (file)
@@ -42,6 +42,8 @@ public class AppcDataServiceConstant {
     
     public static String INPUT_PARAM_UPLOAD_CONFIG_ID= "uploadConfigId";
     public static String CAPABILITY_VM_LEVEL="vm";
     
     public static String INPUT_PARAM_UPLOAD_CONFIG_ID= "uploadConfigId";
     public static String CAPABILITY_VM_LEVEL="vm";
+    public static String KEY_VSERVER_ID = "vserver-id";
+    public static String KEY_VNFC_FUNCTION_CODE = "vnfc-function-code";
     public enum ACTIONS
     {
        Start, Stop, Restart;
     public enum ACTIONS
     {
        Start, Stop, Restart;
index 87e5506..dbb765f 100644 (file)
@@ -313,9 +313,9 @@ public class DGGeneralDBService {
             
             String key = "SELECT  file_content ,  config_file_id "
                     + " FROM CONFIGFILES "
             
             String key = "SELECT  file_content ,  config_file_id "
                     + " FROM CONFIGFILES "
-                    + " WHERE config_file_id = ( SELECT MAX(config_file_id) configfileid " + " FROM CONFIGFILES " 
-                    + " WHERE file_category = '"    + fileCategory + "'" 
-                    + " AND vnf_id =  '" + vnfId + "'" 
+                    + " WHERE config_file_id = ( SELECT MAX(config_file_id) configfileid " + " FROM CONFIGFILES "
+                    + " WHERE file_category = '"    + fileCategory + "'"
+                    + " AND vnf_id =  '" + vnfId + "'"
                     + " AND vm_name = '" + vmName + "' ) ; ";
             
             
                     + " AND vm_name = '" + vmName + "' ) ; ";
             
             
@@ -366,7 +366,7 @@ public class DGGeneralDBService {
             
             String key = "SELECT  * "
                     + " FROM VNFC_REFERENCE "
             
             String key = "SELECT  * "
                     + " FROM VNFC_REFERENCE "
-                    + " WHERE vnf_type =  $vnf-type " 
+                    + " WHERE vnf_type =  $vnf-type "
                     + " AND vnfc_type = $vnfc-type "
                     + " AND action =  $request-action "
                     + " ORDER BY vm_instance, vnfc_instance ; ";
                     + " AND vnfc_type = $vnfc-type "
                     + " AND action =  $request-action "
                     + " ORDER BY vm_instance, vnfc_instance ; ";
@@ -385,7 +385,7 @@ public class DGGeneralDBService {
             
             String key = "SELECT  * "
                     + " FROM VNFC_REFERENCE "
             
             String key = "SELECT  * "
                     + " FROM VNFC_REFERENCE "
-                    + " WHERE vnf_type =  $vnf-type " 
+                    + " WHERE vnf_type =  $vnf-type "
                     + " AND action =  $request-action   "
                     + " ORDER BY vm_instance, vnfc_instance ; ";
             
                     + " AND action =  $request-action   "
                     + " ORDER BY vm_instance, vnfc_instance ; ";
             
@@ -402,7 +402,7 @@ public class DGGeneralDBService {
             
             String key = "SELECT  * , UNIX_TIMESTAMP(UPLOAD_DATE) UPLOAD_TIMESTAMP "
                     + " FROM UPLOAD_CONFIG "
             
             String key = "SELECT  * , UNIX_TIMESTAMP(UPLOAD_DATE) UPLOAD_TIMESTAMP "
                     + " FROM UPLOAD_CONFIG "
-                    + " WHERE upload_config_id = " + 
+                    + " WHERE upload_config_id = " +
                     "( SELECT MAX(upload_config_id) uploadconfigid " + " FROM UPLOAD_CONFIG "
                     + " WHERE vnf_id =  $vnf-id  AND vm_name = $vm-name ) ; ";
                 
                     "( SELECT MAX(upload_config_id) uploadconfigid " + " FROM UPLOAD_CONFIG "
                     + " WHERE vnf_id =  $vnf-id  AND vm_name = $vm-name ) ; ";
                 
@@ -435,9 +435,8 @@ public class DGGeneralDBService {
                  status = serviceLogic.query("SQL", false, null, queryString1, null, null, localContext);
                  if (status.toString().equals("NOT_FOUND"))
                      return null;
                  status = serviceLogic.query("SQL", false, null, queryString1, null, null, localContext);
                  if (status.toString().equals("NOT_FOUND"))
                      return null;
-
                  if(status.toString().equals("FAILURE"))
                  if(status.toString().equals("FAILURE"))
-                     throw new SvcLogicException("Error - while getting capabilitiesData ");
+                         throw new SvcLogicException("Error - while getting capabilitiesData ");
          }
 
          return localContext.getAttribute("artifact-content");
          }
 
          return localContext.getAttribute("artifact-content");
index abdb3e8..856e93e 100644 (file)
@@ -36,6 +36,7 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicException;
 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
 
 import org.onap.appc.data.services.AppcDataServiceConstant;
 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
 
 import org.onap.appc.data.services.AppcDataServiceConstant;
+import org.onap.appc.data.services.AppcDataServiceConstant.ACTIONS;
 import org.onap.appc.data.services.db.DGGeneralDBService;
 import org.onap.appc.data.services.utils.EscapeUtils;
 
 import org.onap.appc.data.services.db.DGGeneralDBService;
 import org.onap.appc.data.services.utils.EscapeUtils;
 
@@ -102,12 +103,8 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
 
             responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
             DGGeneralDBService db = DGGeneralDBService.initialise();
 
             responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
             DGGeneralDBService db = DGGeneralDBService.initialise();
-            QueryStatus status = db.getDeviceAuthenticationByVnfType(ctx, "device-authentication");
 
 
-            if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
-                throw new Exception("Unable to Read device_authentication");
-
-            status = db.getDeviceProtocolByVnfType(ctx, "tmp.deviceinterfaceprotocol");
+            QueryStatus status = db.getDeviceProtocolByVnfType(ctx, "tmp.deviceinterfaceprotocol");
 
             if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
                 throw new Exception("Unable to Read device_interface_protocol");
 
             if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
                 throw new Exception("Unable to Read device_interface_protocol");
@@ -674,7 +671,7 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
         responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
         String caplevel = inParams.get("caplevel");
         String findCapability = inParams.get("checkCapability");
         responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
         String caplevel = inParams.get("caplevel");
         String findCapability = inParams.get("checkCapability");
-
+        String vServerId=inParams.get("vServerId");
         if (!checkIfCapabilityCheckNeeded(caplevel, findCapability))
         {
             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
         if (!checkIfCapabilityCheckNeeded(caplevel, findCapability))
         {
             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
@@ -688,11 +685,10 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
             log.info("getCapability::returned from DB::+cap");
             if (StringUtils.isBlank(cap)) {
                 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
             log.info("getCapability::returned from DB::+cap");
             if (StringUtils.isBlank(cap)) {
                 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
-                AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
+                        AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
                 log.info("getCapability Successful - No capability blocks found");
                 return;
             }
                 log.info("getCapability Successful - No capability blocks found");
                 return;
             }
-
             ObjectMapper mapper = new ObjectMapper();
             JsonNode caps = mapper.readTree(cap);
             log.info("From DB =   " + caps);
             ObjectMapper mapper = new ObjectMapper();
             JsonNode caps = mapper.readTree(cap);
             log.info("From DB =   " + caps);
@@ -701,13 +697,24 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
             if(caplevel !=null && !caplevel.isEmpty()){
                 JsonNode subCapabilities = capabilities.get(caplevel);
                 log.info("subCapabilities =  " +  caplevel + " : " + subCapabilities);
             if(caplevel !=null && !caplevel.isEmpty()){
                 JsonNode subCapabilities = capabilities.get(caplevel);
                 log.info("subCapabilities =  " +  caplevel + " : " + subCapabilities);
+                if (caplevel.equalsIgnoreCase(AppcDataServiceConstant.CAPABILITY_VM_LEVEL)
+                        && (null == subCapabilities || subCapabilities.isNull() || subCapabilities.size()==0)) {
+                    ctx.setAttribute("capabilities", "None");
+                    ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
+                            AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
+                    log.info("getCapability Successful ");
+                    return;
+                }
                 if(findCapability !=null && !findCapability.isEmpty()){
                 if(findCapability !=null && !findCapability.isEmpty()){
-                    if(subCapabilities != null && subCapabilities.toString().contains(findCapability))
-                        ctx.setAttribute(responsePrefix + "capabilities." + caplevel + "." +  findCapability,
-                                "Supported");
-                    else
-                        ctx.setAttribute(responsePrefix + "capabilities." + caplevel + "." +  findCapability,
-                                "Not-Supported");
+                    if(subCapabilities != null && subCapabilities.toString().contains(findCapability)){
+                        if (caplevel.equalsIgnoreCase(AppcDataServiceConstant.CAPABILITY_VM_LEVEL))
+                            processCapabilitiesForVMLevel(vServerId, ctx, findCapability, subCapabilities);
+                        else
+                            ctx.setAttribute("capabilities" , "Supported");
+                    }
+                    else {
+                        ctx.setAttribute("capabilities" , "Not-Supported");
+                    }
                 }
                 else
                 {
                 }
                 else
                 {
@@ -732,6 +739,46 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
         }
     }
 
         }
     }
 
+    public void processCapabilitiesForVMLevel(String vServerId, SvcLogicContext ctx, String findCapability,
+            JsonNode subCapabilities) throws Exception {
+        log.info("processCapabilitiesForVMLevel():::subCapabilities::" + subCapabilities.toString() + ",vServerId::"
+                + vServerId);
+        if (subCapabilities.size()==0) {
+            ctx.setAttribute("capabilities", "None");
+            log.info("processCapabilitiesForVMLevel :: No VM block found!!");
+            return;
+        }
+        JsonNode vmCaps = null;
+        for (JsonNode cap : subCapabilities) {
+            if (null != cap && null != cap.get(findCapability)
+                    && StringUtils.isNotBlank(cap.get(findCapability).toString())) {
+                vmCaps = cap.get(findCapability);
+                log.info("processCapabilitiesForVMLevel()::vmCaps found" + vmCaps.toString());
+                break;
+            }
+        }
+            
+        if (null == vmCaps || vmCaps.isNull() || vmCaps.size() == 0) {
+            ctx.setAttribute("capabilities", "Not-Supported");
+            log.info("processCapabilitiesForVMLevel :: Found non-empty VM block but Not desired capability!!");
+            return;
+        }
+        
+        String vnfcFunctionCode = getVnfcFunctionCodeForVserver(ctx, vServerId);
+        if (vmCaps != null && vmCaps.toString().contains(vnfcFunctionCode)) 
+            ctx.setAttribute("capabilities", "Supported");
+        else
+            ctx.setAttribute("capabilities", "Not-Supported");
+        log.info("End processCapabilitiesForVMLevel():capabilities is ::"+ctx.getAttribute("capabilities"));
+    }
+
+    private String getVnfcFunctionCodeForVserver(SvcLogicContext ctx, String vServerId) throws Exception {
+        log.debug("getVnfcFunctionCodeForVserver()::vServerId=" + vServerId);
+        String vnfcFunctionCode = ctx.getAttribute("tmp.vnfInfo.vm.vnfc.vnfc-function-code");
+        log.debug("getVnfcFunctionCodeForVserver()::vnfcFunctionCode=" + vnfcFunctionCode);
+        return vnfcFunctionCode;
+    }
+
     public boolean checkIfCapabilityCheckNeeded(String caplevel, String findCapability) {
         boolean capabilityCheckNeeded = true;
         if (!StringUtils.equalsIgnoreCase(caplevel, AppcDataServiceConstant.CAPABILITY_VM_LEVEL)) {
     public boolean checkIfCapabilityCheckNeeded(String caplevel, String findCapability) {
         boolean capabilityCheckNeeded = true;
         if (!StringUtils.equalsIgnoreCase(caplevel, AppcDataServiceConstant.CAPABILITY_VM_LEVEL)) {
@@ -748,4 +795,44 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
     }
 
 
     }
 
 
+
+    /*public void getUploadConfigInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
+
+        log.info("Received getUploadConfigInfo call with params : " + inParams);
+
+        String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
+
+        String uploadConfigId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_UPLOAD_CONFIG_ID);
+        QueryStatus status = null;
+
+        int id = 0;
+        try {
+
+
+            DGGeneralDBService db = DGGeneralDBService.initialise();
+
+            if ( uploadConfigId != null )
+                id = Integer.parseInt(uploadConfigId);
+
+            status = db.getUploadConfigInfo(ctx, responsePrefix,id);
+
+            if ( status == QueryStatus.FAILURE || status == QueryStatus.NOT_FOUND)
+                throw new Exception("Unable to Read upload-config");
+
+
+            responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
+            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
+                    AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
+            log.info("getUploadConfigInfo Successful ");
+        } catch (Exception e) {
+            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
+                    AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
+            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
+            log.error("Failed in getUploadConfigInfo " + e.getMessage());
+
+            throw new SvcLogicException(e.getMessage());
+        }
+    }
+     */
+
 }
 }
index fb44e87..76ddbdc 100644 (file)
@@ -24,6 +24,7 @@
 
 package org.onap.appc.data.services.db;
 
 
 package org.onap.appc.data.services.db;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Map;
 import static org.junit.Assert.assertFalse;
 import java.util.HashMap;
 import java.util.Map;
 import static org.junit.Assert.assertFalse;
@@ -34,6 +35,13 @@ import org.onap.appc.data.services.node.ConfigResourceNode;
 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
 
 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
 
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
 public class TestConfigResourceNode {
 
     @Ignore("Test is taking 60 seconds")
 public class TestConfigResourceNode {
 
     @Ignore("Test is taking 60 seconds")
@@ -158,6 +166,25 @@ public class TestConfigResourceNode {
         node.saveConfigBlock(inParams, ctx);
     }
 
         node.saveConfigBlock(inParams, ctx);
     }
 
+    @Test
+    public void testProcessCapabilitiesForVMLevel ()  throws Exception {
+        //{"capabilities":{"vnfc":[],"vm":[{"ConfigureTest":["SSC","MMSC"]}],"vf-module":[],"vnf":["ConfigModify","HealthCheck"]}}
+        SvcLogicContext ctx = new SvcLogicContext();
+        ConfigResourceNode node = new ConfigResourceNode();
+        String findCapability="Restart";
+        JsonNode subCapabilities = JsonNodeFactory.instance.objectNode();
+        String subCaps= "[{\"Restart\":[\"SSC\",\"MMC\"]},{\"Rebuild\":[\"SSC\"]},{\"Migrate\":[\"SSC\"]},{\"Snapshot\":[\"SSC\"]},{\"Start\":[\"SSC\"]},{\"Stop\":[\"SSC\"]}]";
+        ObjectMapper m = new ObjectMapper();
+        subCapabilities = m.readTree(subCaps);
+        String vServerId="testServer";
+        ctx.setAttribute("tmp.vnfInfo.vm.vnfc.vnfc-function-code", "MMC");
+        ctx.setAttribute("tmp.vnfInfo.vm.vnfc.vnfc-name","testVnfc")    ;
+        node.processCapabilitiesForVMLevel( vServerId,    ctx,
+                 findCapability,  subCapabilities);
+        String result=ctx.getAttribute("capabilities");
+        assertEquals(result,"Supported");
+    }
+
     @Test
     public void testcheckIfCapabilityCheckNeeded ()  throws Exception {
         ConfigResourceNode node = new ConfigResourceNode();
     @Test
     public void testcheckIfCapabilityCheckNeeded ()  throws Exception {
         ConfigResourceNode node = new ConfigResourceNode();