diff options
Diffstat (limited to 'appc-config/appc-data-services/provider/src/main')
3 files changed, 110 insertions, 22 deletions
diff --git a/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/AppcDataServiceConstant.java b/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/AppcDataServiceConstant.java index 9add56b5e..c26a47096 100644 --- a/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/AppcDataServiceConstant.java +++ b/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/AppcDataServiceConstant.java @@ -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 KEY_VSERVER_ID = "vserver-id"; + public static String KEY_VNFC_FUNCTION_CODE = "vnfc-function-code"; public enum ACTIONS { Start, Stop, Restart; diff --git a/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/db/DGGeneralDBService.java b/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/db/DGGeneralDBService.java index 87e5506a2..dbb765f61 100644 --- a/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/db/DGGeneralDBService.java +++ b/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/db/DGGeneralDBService.java @@ -313,9 +313,9 @@ public class DGGeneralDBService { 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 + "' ) ; "; @@ -366,7 +366,7 @@ public class DGGeneralDBService { 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 ; "; @@ -385,7 +385,7 @@ public class DGGeneralDBService { 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 ; "; @@ -402,7 +402,7 @@ public class DGGeneralDBService { 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 ) ; "; @@ -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; - if(status.toString().equals("FAILURE")) - throw new SvcLogicException("Error - while getting capabilitiesData "); + throw new SvcLogicException("Error - while getting capabilitiesData "); } return localContext.getAttribute("artifact-content"); diff --git a/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/node/ConfigResourceNode.java b/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/node/ConfigResourceNode.java index abdb3e85b..856e93e18 100644 --- a/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/node/ConfigResourceNode.java +++ b/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/node/ConfigResourceNode.java @@ -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.appc.data.services.AppcDataServiceConstant.ACTIONS; 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(); - 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"); @@ -674,7 +671,7 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin { 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, @@ -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, - AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); + AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); log.info("getCapability Successful - No capability blocks found"); return; } - 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.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(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 { @@ -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)) { @@ -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()); + } + } + */ + } |