aboutsummaryrefslogtreecommitdiffstats
path: root/appc-config/appc-data-services/provider/src/main
diff options
context:
space:
mode:
authorkurczews <krzysztof.kurczewski@nokia.com>2018-01-30 10:32:23 +0100
committerPatrick Brady <pb071s@att.com>2018-01-31 20:21:13 +0000
commit4a12f557c13ee03831bf4aa5c3a02eb482998eba (patch)
tree39d55fe76f74bd93cdd57e170686ecb47d54c9a3 /appc-config/appc-data-services/provider/src/main
parent818c1290483623a633c14233fa9f672f0ce17e97 (diff)
Add coverage for ConfigResourceNode
Change-Id: Ida31164383c01340d47b85d59034882c9206b9a2 Issue-ID: APPC-441 Signed-off-by: kurczews <krzysztof.kurczewski@nokia.com>
Diffstat (limited to 'appc-config/appc-data-services/provider/src/main')
-rw-r--r--appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/node/ConfigResourceNode.java111
1 files changed, 35 insertions, 76 deletions
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 e22567336..8b9b8ddfa 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
@@ -23,6 +23,10 @@
*/
package org.onap.appc.data.services.node;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -35,49 +39,65 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
public class ConfigResourceNode implements SvcLogicJavaPlugin {
+ static final String DEVICE_CONF_PREFIX = "configfilereference-deviceconfig";
+ static final String DEVICE_CONF_FILE_TYPE = "device_configuration";
+
+ static final String SUCCESS_PREFIX = "configfilereference-success";
+ static final String SUCCESS_FILE_TYPE = "configuration_success";
+
+ static final String FAILURE_PREFIX = "configfilereference-failure";
+ static final String FAILURE_FILE_TYPE = "configuration_error";
+
+ static final String LOG_PREFIX = "configfilereference-log";
+ static final String LOG_FILE_TYPE = "log";
+
private static final EELFLogger log = EELFManager.getInstance().getLogger(ConfigResourceNode.class);
+ private final DGGeneralDBService db;
+
+ /**
+ * Constructor which provide default DB service
+ */
+ public ConfigResourceNode() {
+ db = DGGeneralDBService.initialise();
+ }
+
+ /**
+ * Constructor which allow to provide custom DB service, prefer to use no-arg constructor
+ */
+ public ConfigResourceNode(DGGeneralDBService dbService) {
+ db = dbService;
+ }
public void getConfigFileReference(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
log.info("Received getConfigFiles call with params : " + inParams);
-
String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
try {
-
responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
- DGGeneralDBService db = DGGeneralDBService.initialise();
- QueryStatus status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-deviceconfig",
- "device_configuration");
+ QueryStatus status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, DEVICE_CONF_PREFIX, DEVICE_CONF_FILE_TYPE);
if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
throw new Exception("Unable to Read ConfigFileReference:device-configuration");
- status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-success",
- "configuration_success");
+ status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, SUCCESS_PREFIX, SUCCESS_FILE_TYPE);
if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
throw new Exception("Unable to Read ConfigFileReference:configuration_success");
- status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-failure",
- "configuration_error");
+ status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, FAILURE_PREFIX, FAILURE_FILE_TYPE);
if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
throw new Exception("Unable to Read ConfigFileReference:configuration_error");
- status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-log", "log");
+ status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, LOG_PREFIX, LOG_FILE_TYPE);
if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
throw new Exception("Unable to Read ConfigFileReference:configuration_log");
-
ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
log.info("GetConfigFileReference Successful ");
@@ -94,14 +114,10 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
public void getCommonConfigInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
log.info("Received getDeviceInfo call with params : " + inParams);
-
String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
try {
-
responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
- DGGeneralDBService db = DGGeneralDBService.initialise();
-
QueryStatus status = db.getDeviceProtocolByVnfType(ctx, "tmp.deviceinterfaceprotocol");
if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
@@ -118,8 +134,6 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
throw new Exception("Unable to Read configure_action_dg");
}
-
-
ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
log.info("getCommonConfigInfo Successful ");
@@ -139,7 +153,6 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
log.info("Received getTemplate call with params : " + inParams);
-
String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY);
String templateName = ctx.getAttribute("template-name");
@@ -152,13 +165,10 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
log.info("RESPONSEPREFIX : " + responsePrefix);
log.info("RESPONSEPREFIX1 : " + responsePrefix1);
- DGGeneralDBService db = DGGeneralDBService.initialise();
-
if (StringUtils.isBlank(templateName)) {
// if ( !StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
-
status = db.getTemplate(ctx, responsePrefix, fileCategory);
if (status == QueryStatus.FAILURE)
throw new Exception("Unable to Read " + fileCategory);
@@ -188,7 +198,6 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
throw new Exception("Unable to Read " + fileCategory + " template");
}
-
ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
log.info("GetTemplate Successful ");
@@ -211,7 +220,6 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
try {
responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
- DGGeneralDBService db = DGGeneralDBService.initialise();
QueryStatus status = db.saveConfigFiles(ctx, "tmp.configFiles");
if (status == QueryStatus.FAILURE)
@@ -249,7 +257,6 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
try {
responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
- DGGeneralDBService db = DGGeneralDBService.initialise();
ctx.setAttribute("tmp.escaped.devicerunningconfig",
EscapeUtils.escapeSql(ctx.getAttribute("device-running-config")));
@@ -292,7 +299,6 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
try {
responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
- DGGeneralDBService db = DGGeneralDBService.initialise();
QueryStatus status = db.savePrepareRelationship(ctx, "tmp.preparerel", fileId, sdcArtifactInd);
if (status == QueryStatus.FAILURE)
@@ -318,10 +324,8 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
try {
-
responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
ctx.setAttribute("tmp.convertconfig.escapeData", EscapeUtils.escapeSql(ctx.getAttribute("configuration")));
- DGGeneralDBService db = DGGeneralDBService.initialise();
if (StringUtils.isBlank(ctx.getAttribute("configuration-params"))) {
saveDeviceConfiguration(inParams, ctx, "Request", ctx.getAttribute("tmp.convertconfig.escapeData"),
@@ -358,9 +362,7 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
try {
-
responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
- DGGeneralDBService db = DGGeneralDBService.initialise();
if (StringUtils.isBlank(ctx.getAttribute("configuration-params"))) {
@@ -397,11 +399,8 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
}
}
-
-
public void saveStyleSheetConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
-
log.info("Received saveStyleSheet call with params : " + inParams);
String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
@@ -414,7 +413,6 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
saveDeviceConfiguration(inParams, ctx, "StyleSheet", ctx.getAttribute("tmp.convertconfig.escapeData"),
ctx.getAttribute("tmp.merge.mergedData"));
-
ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
log.info("saveStyleSheet Successful ");
@@ -428,10 +426,8 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
}
}
-
public void getSmmChainKeyFiles(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
-
log.info("Received saveStyleSheet call with params : " + inParams);
String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
@@ -441,32 +437,24 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
try {
-
responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
- DGGeneralDBService db = DGGeneralDBService.initialise();
-
-
status = db.getTemplateByArtifactType(ctx, "smm", "smm", siteLocation);
if (status == QueryStatus.FAILURE)
throw new Exception("Unable to Read smm file");
-
status = db.getTemplateByArtifactType(ctx, "intermediate-ca-chain", "intermediate_ca_chain", siteLocation);
if (status == QueryStatus.FAILURE)
throw new Exception("Unable to Read intermediate_ca_chain file");
-
-
status = db.getTemplateByArtifactType(ctx, "server-certificate-and-key", "server_certificate_and_key",
siteLocation);
if (status == QueryStatus.FAILURE)
throw new Exception("Unable to Read server_certificate_and_key file");
-
ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
log.info("saveStyleSheet Successful ");
@@ -480,7 +468,6 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
}
}
-
public void saveDeviceConfiguration(Map<String, String> inParams, SvcLogicContext ctx, String dataSource,
String fileContent, String deviceConfig) throws SvcLogicException {
ctx.setAttribute("data-source", dataSource);
@@ -505,7 +492,6 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
saveConfigFiles(inParams, ctx);
}
-
public void getConfigFilesByVnfVmNCategory(Map<String, String> inParams, SvcLogicContext ctx)
throws SvcLogicException {
@@ -516,16 +502,11 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
String vnfId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VNF_ID);
String vmName = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VM_NAME);
try {
-
-
- DGGeneralDBService db = DGGeneralDBService.initialise();
-
QueryStatus status = db.getConfigFilesByVnfVmNCategory(ctx, responsePrefix, fileCategory, vnfId, vmName);
if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
throw new Exception("Unable to get " + ctx.getAttribute("fileCategory") + " from configfiles");
-
responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
@@ -541,7 +522,6 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
}
}
-
public void getDownloadConfigTemplateByVnf(Map<String, String> inParams, SvcLogicContext ctx)
throws SvcLogicException {
@@ -549,14 +529,11 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
try {
- DGGeneralDBService db = DGGeneralDBService.initialise();
-
QueryStatus status = db.getDownloadConfigTemplateByVnf(ctx, responsePrefix);
if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
throw new Exception("Unable to get download config template.");
-
responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
@@ -572,11 +549,8 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
}
}
-
public void saveConfigTransactionLog(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
-
-
String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
String messageType = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE_TYPE);
@@ -585,17 +559,13 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
try {
SvcLogicContext logctx = new SvcLogicContext();
-
String escapedMessage = EscapeUtils.escapeSql(message);
-
logctx.setAttribute("request-id", ctx.getAttribute("request-id"));
logctx.setAttribute("log-message-type", messageType);
logctx.setAttribute("log-message", escapedMessage);
-
responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
- DGGeneralDBService db = DGGeneralDBService.initialise();
QueryStatus status = db.saveConfigTransactionLog(logctx, responsePrefix);
logctx.setAttribute("log-message", null);
@@ -603,33 +573,23 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
if (status == QueryStatus.FAILURE)
throw new Exception("Unable to insert into config_transaction_log");
-
} catch (Exception e) {
ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
-
throw new SvcLogicException(e.getMessage());
}
}
-
-
public void getVnfcReference(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
log.info("Received getVnfcReference call with params : " + inParams);
String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
-
-
QueryStatus status = null;
try {
-
-
- DGGeneralDBService db = DGGeneralDBService.initialise();
-
if (!StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
status = db.getVnfcReferenceByVnfcTypeNAction(ctx, responsePrefix);
@@ -672,7 +632,6 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
return;
}
try {
- DGGeneralDBService db = DGGeneralDBService.initialise();
String cap = db.getCapability(ctx, inParams.get("vnf-type"));
log.info("getCapability::returned from DB::+cap");
if (StringUtils.isBlank(cap)) {