diff options
author | Balaji, Ramya (rb111y) <rb111y@att.com> | 2018-02-28 21:01:47 -0500 |
---|---|---|
committer | Balaji, Ramya (rb111y) <rb111y@att.com> | 2018-03-02 13:18:17 -0500 |
commit | 84919d3230ad04b6a78f52e37449ba5d34c9a033 (patch) | |
tree | fff82bd4075ea5728adc43e791ae0313141e597e /appc-config/appc-data-services/provider/src/main | |
parent | 91057d811d2c43013d789ad85dd3ac175c0e98dd (diff) |
ConfigScaleOut flow changes
Code changes and unit test cases
to include template id when
retrieving vnfc reference data and artifacts
from tables. Cleaned up Unit Tests.
Issue-ID: APPC-619,APPC-620
Change-Id: I8db08be19b9fa094a07e5c5597c45327824cfb01
Signed-off-by: Balaji, Ramya (rb111y) <rb111y@att.com>
Diffstat (limited to 'appc-config/appc-data-services/provider/src/main')
2 files changed, 149 insertions, 40 deletions
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 303c974f9..b14eb1c02 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ============================================================================= @@ -42,6 +42,7 @@ public class DGGeneralDBService { private static DGGeneralDBService dgGeneralDBService = null; public static DGGeneralDBService initialise() { + if (dgGeneralDBService == null) { dgGeneralDBService = new DGGeneralDBService(); } @@ -54,6 +55,12 @@ public class DGGeneralDBService { } } + protected DGGeneralDBService(SqlResource svcLogic) { + if (serviceLogic == null) { + serviceLogic = svcLogic; + } + } + public QueryStatus getDeviceProtocolByVnfType(SvcLogicContext ctx, String prefix) throws SvcLogicException { QueryStatus status = null; if (serviceLogic != null && ctx != null) { @@ -117,8 +124,8 @@ public class DGGeneralDBService { + " FROM ASDC_ARTIFACTS a, ASDC_REFERENCE b " + " WHERE a.artifact_name = b.artifact_name " + " AND file_category = '" + fileCategory + "'" + " AND action = $request-action " + " AND vnf_type = $vnf-type ) ; "; - status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); + } return status; } @@ -291,7 +298,7 @@ public class DGGeneralDBService { } - + public QueryStatus getTemplateByArtifactType(SvcLogicContext ctx, String prefix, String fileCategory, String artifactType) throws SvcLogicException { QueryStatus status = null; @@ -307,27 +314,27 @@ public class DGGeneralDBService { } return status; } - - + + public QueryStatus getConfigFilesByVnfVmNCategory(SvcLogicContext ctx, String prefix, String fileCategory, String vnfId, String vmName) throws SvcLogicException { QueryStatus status = null; if (serviceLogic != null && ctx != null) { - + 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 + "'" + " AND vm_name = '" + vmName + "' ) ; "; - - + + status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); } return status; } - - + + public QueryStatus getDownloadConfigTemplateByVnf(SvcLogicContext ctx, String prefix) throws SvcLogicException { QueryStatus status = null; @@ -337,16 +344,16 @@ public class DGGeneralDBService { } return status; } - - - + + + public QueryStatus saveConfigTransactionLog(SvcLogicContext ctx, String prefix) throws SvcLogicException { QueryStatus status = null; if (serviceLogic != null && ctx != null) { - - + + String key = "INSERT INTO CONFIG_TRANSACTION_LOG " + " SET request_id = $request-id , " + " message_type = $log-message-type , " + " message = $log-message ;"; @@ -354,61 +361,61 @@ public class DGGeneralDBService { status = serviceLogic.save("SQL", false, false, key, null, prefix, ctx); - + } return status; } - + public QueryStatus getVnfcReferenceByVnfcTypeNAction(SvcLogicContext ctx, String prefix) throws SvcLogicException { QueryStatus status = null; if (serviceLogic != null && ctx != null) { - + String key = "SELECT * " + " FROM VNFC_REFERENCE " + " WHERE vnf_type = $vnf-type " + " AND vnfc_type = $vnfc-type " + " AND action = $request-action " + " ORDER BY vm_instance, vnfc_instance ; "; - - + + status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); } return status; } - + public QueryStatus getVnfcReferenceByVnfTypeNAction(SvcLogicContext ctx, String prefix) throws SvcLogicException { QueryStatus status = null; if (serviceLogic != null && ctx != null) { - + String key = "SELECT * " + " FROM VNFC_REFERENCE " + " WHERE vnf_type = $vnf-type " + " AND action = $request-action " + " ORDER BY vm_instance, vnfc_instance ; "; - + status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); } return status; } - - + + public QueryStatus getUploadConfigInfo(SvcLogicContext ctx, String prefix) throws SvcLogicException { QueryStatus status = null; if (serviceLogic != null && ctx != null) { - + String key = "SELECT * , UNIX_TIMESTAMP(UPLOAD_DATE) UPLOAD_TIMESTAMP " + " FROM UPLOAD_CONFIG " + " WHERE upload_config_id = " + "( SELECT MAX(upload_config_id) uploadconfigid " + " FROM UPLOAD_CONFIG " + " WHERE vnf_id = $vnf-id AND vm_name = $vm-name ) ; "; - + status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); } return status; @@ -445,4 +452,62 @@ public class DGGeneralDBService { return localContext.getAttribute("artifact-content"); } -}
\ No newline at end of file + public QueryStatus getTemplateWithTemplateModelId(SvcLogicContext ctx, String prefix, String fileCategory, + String templateModelId) throws SvcLogicException { + QueryStatus status = null; + String templatePattern = "'%_"+ templateModelId +"%'"; + if (serviceLogic != null && ctx != null) { + String key = "SELECT artifact_content file_content , asdc_artifacts_id config_file_id " + + " FROM ASDC_ARTIFACTS " + + " WHERE asdc_artifacts_id = ( SELECT MAX(a.asdc_artifacts_id) configfileid " + + " FROM ASDC_ARTIFACTS a, ASDC_REFERENCE b " + " WHERE a.artifact_name = b.artifact_name " + + " AND file_category = '" + fileCategory + "'" + " AND action = $request-action " + + " AND vnf_type = $vnf-type " + " AND vnfc_type = $vnfc-type ) and ASDC_ARTIFACTS.artifact_name like " + + templatePattern + "; "; + log.info("getTemplateWithTemplateModelId()::: with template:::"+ key); + + status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); + } + return status; + } + + public QueryStatus getTemplateByVnfTypeNActionWithTemplateModelId(SvcLogicContext ctx, String prefix, + String fileCategory, String templateModelId) throws SvcLogicException { + QueryStatus status = null; + String templatePattern = "'%_"+ templateModelId +"%'"; + if (serviceLogic != null && ctx != null) { + String key = "SELECT artifact_content file_content , asdc_artifacts_id config_file_id " + + " FROM ASDC_ARTIFACTS " + + " WHERE asdc_artifacts_id = (SELECT MAX(a.asdc_artifacts_id) configfileid " + + " FROM ASDC_ARTIFACTS a, ASDC_REFERENCE b " + " WHERE a.artifact_name = b.artifact_name " + + " AND file_category = '" + fileCategory + "'" + " AND action = $request-action " + + " AND vnf_type = $vnf-type ) and ASDC_ARTIFACTS.artifact_name like " + + templatePattern + "; "; + log.info("getTemplateByVnfTypeNActionWithTemplateModelId()::: with template:::"+ key); + + status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); + } + return status; + + } + + public QueryStatus getVnfcReferenceByVnfTypeNActionWithTemplateModelId(SvcLogicContext ctx, String prefix, + String templateModelId) throws SvcLogicException { + QueryStatus status = null; + if (serviceLogic != null && ctx != null) { + + String key = "SELECT * " + + " FROM VNFC_REFERENCE " + + " WHERE vnf_type = $vnf-type " + + " AND action = $request-action " + + " AND template_id = '" + + templateModelId + "'" + + " ORDER BY vm_instance, vnfc_instance ; "; + + log.info("getVnfcReferenceByVnfTypeNActionWithTemplateModelId()::: with template:::"+ key); + status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); + } + return status; + } + +} 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 c0580b43b..856648210 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ============================================================================= @@ -190,6 +190,7 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin { String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY); String templateName = ctx.getAttribute("template-name"); + String templateModelId = ctx.getAttribute("template-model-id"); QueryStatus status; String responsePrefix1 = ""; @@ -200,22 +201,51 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin { log.info("RESPONSEPREFIX1 : " + responsePrefix1); if (StringUtils.isBlank(templateName)) { + if (StringUtils.isNotBlank(templateModelId)) { + status = db.getTemplateWithTemplateModelId(ctx, responsePrefix, fileCategory,templateModelId); + if (status == QueryStatus.FAILURE) { + throw new QueryException(UNABLE_TO_READ_STR + fileCategory); + } + if (!(status == QueryStatus.NOT_FOUND) ) { + ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, + AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); + log.info("GetTemplate Successful "); + return; + } + } status = db.getTemplate(ctx, responsePrefix, fileCategory); if (status == QueryStatus.FAILURE) { throw new QueryException(UNABLE_TO_READ_STR + fileCategory); } if (status == QueryStatus.NOT_FOUND) { + if (StringUtils.isNotBlank(templateModelId)) { + status = db.getTemplateByVnfTypeNActionWithTemplateModelId(ctx, responsePrefix, fileCategory,templateModelId); + if (status == QueryStatus.FAILURE) { + throw new QueryException(UNABLE_TO_READ_STR + fileCategory); + } + if (!(status == QueryStatus.NOT_FOUND) ) { + ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, + AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); + log.info("GetTemplate Successful "); + return; + } + } + if (status == QueryStatus.NOT_FOUND) { - status = db.getTemplateByVnfTypeNAction(ctx, responsePrefix, fileCategory); - if (status == QueryStatus.FAILURE) { - throw new QueryException(UNABLE_TO_READ_STR + fileCategory); - } + status = db.getTemplateByVnfTypeNAction(ctx, responsePrefix, fileCategory); - if (status == QueryStatus.NOT_FOUND) { - throw new QueryException(UNABLE_TO_READ_STR + fileCategory); + if (status == QueryStatus.FAILURE) { + throw new QueryException(UNABLE_TO_READ_STR + fileCategory); + } + + if (status == QueryStatus.NOT_FOUND) { + throw new QueryException(UNABLE_TO_READ_STR + fileCategory); + } } + + } } else { @@ -629,20 +659,33 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin { log.info("Received getVnfcReference call with params : " + inParams); String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); - QueryStatus status; + String templateModelId = ctx.getAttribute("template-model-id"); + log.info("getVnfcReference():::"+templateModelId); + QueryStatus status = null; try { if (!StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) { + + status = db.getVnfcReferenceByVnfcTypeNAction(ctx, responsePrefix); if (status == QueryStatus.FAILURE) { throw new QueryException("Unable to Read vnfc-reference"); } + } - status = db.getVnfcReferenceByVnfTypeNAction(ctx, responsePrefix); + if (StringUtils.isNotBlank(templateModelId)) { + status = db.getVnfcReferenceByVnfTypeNActionWithTemplateModelId(ctx, responsePrefix,templateModelId); + if (status == QueryStatus.FAILURE) { + throw new QueryException("Unable to Read vnfc-reference with template-model-id"); + } + } + if (StringUtils.isBlank(templateModelId) || (StringUtils.isNotBlank(templateModelId) && (status == QueryStatus.NOT_FOUND))) { + status = db.getVnfcReferenceByVnfTypeNAction(ctx, responsePrefix); - if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) { - throw new QueryException("Unable to Read vnfc reference"); + if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) { + throw new QueryException("Unable to Read vnfc reference"); + } } responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : ""; @@ -794,4 +837,5 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin { } return capabilityCheckNeeded; } -}
\ No newline at end of file + +} |