aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/dbservices/DBService.java231
1 files changed, 121 insertions, 110 deletions
diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/dbservices/DBService.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/dbservices/DBService.java
index a337f0989..c3cebb9c4 100644
--- a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/dbservices/DBService.java
+++ b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/dbservices/DBService.java
@@ -33,12 +33,11 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
import org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants;
-
import java.sql.SQLException;
import java.util.HashMap;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.configuration.PropertiesConfiguration;
-import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.ConfigurationException;
public class DBService {
@@ -114,9 +113,9 @@ public class DBService {
+ " RESOURCE_INSTANCE_NAME = $resource-instance-name ," + " RESOURCE_NAME = $resource-name ,"
+ " RESOURCE_VERSION = $resource-version ," + " RESOURCE_TYPE = $resource-type ,"
+ " ARTIFACT_UUID = $artifact-uuid ," + " ARTIFACT_TYPE = $artifact-type ,"
- + " ARTIFACT_VERSION = $artifact-version ," + " ARTIFACT_DESCRIPTION = $artifact-description ,"
- + " INTERNAL_VERSION = " + intversion + "," + " ARTIFACT_NAME = $artifact-name ,"
- + " ARTIFACT_CONTENT = $artifact-contents ";
+ + " ARTIFACT_VERSION = $artifact-version ,"
+ + " ARTIFACT_DESCRIPTION = $artifact-description ," + " INTERNAL_VERSION = " + intversion
+ + "," + " ARTIFACT_NAME = $artifact-name ," + " ARTIFACT_CONTENT = $artifact-contents ";
status = serviceLogic.save("SQL", false, false, key, null, null, ctx);
if (status.toString().equals("FAILURE"))
@@ -155,22 +154,24 @@ public class DBService {
String key = "";
QueryStatus status = null;
- if (isUpdate && context.getAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY).equals(SdcArtifactHandlerConstants.CAPABILITY)) {
+ if (isUpdate && context.getAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY)
+ .equals(SdcArtifactHandlerConstants.CAPABILITY)) {
log.info("Updating capability artifact in ASDC_REFERENCE");
key = "update " + SdcArtifactHandlerConstants.DB_SDC_REFERENCE + " set ARTIFACT_NAME = $"
+ SdcArtifactHandlerConstants.ARTIFACT_NAME + " where " + "FILE_CATEGORY = $"
+ SdcArtifactHandlerConstants.FILE_CATEGORY + " and VNF_TYPE = $"
- + SdcArtifactHandlerConstants.VNF_TYPE ;
+ + SdcArtifactHandlerConstants.VNF_TYPE;
} else if (isUpdate)
key = "update " + SdcArtifactHandlerConstants.DB_SDC_REFERENCE + " set ARTIFACT_NAME = $"
+ SdcArtifactHandlerConstants.ARTIFACT_NAME + " where VNFC_TYPE = $"
+ SdcArtifactHandlerConstants.VNFC_TYPE + " and FILE_CATEGORY = $"
- + SdcArtifactHandlerConstants.FILE_CATEGORY + " and ACTION = $"
- + SdcArtifactHandlerConstants.ACTION + " and VNF_TYPE = $" + SdcArtifactHandlerConstants.VNF_TYPE;
+ + SdcArtifactHandlerConstants.FILE_CATEGORY + " and ACTION = $" + SdcArtifactHandlerConstants.ACTION
+ + " and VNF_TYPE = $" + SdcArtifactHandlerConstants.VNF_TYPE;
else {
- if (context.getAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY).equals(SdcArtifactHandlerConstants.CAPABILITY)) {
- log.info("Inserting new record for capability artifact in ASDC_REFERENCE");
+ if (context.getAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY)
+ .equals(SdcArtifactHandlerConstants.CAPABILITY)) {
+ log.info("Inserting new record for capability artifact in ASDC_REFERENCE");
key = "insert into " + SdcArtifactHandlerConstants.DB_SDC_REFERENCE + " set VNFC_TYPE = null "
+ " , FILE_CATEGORY = $" + SdcArtifactHandlerConstants.FILE_CATEGORY + " , VNF_TYPE = $"
+ SdcArtifactHandlerConstants.VNF_TYPE + " , ACTION = null " + " , ARTIFACT_TYPE = null "
@@ -192,7 +193,8 @@ public class DBService {
}
}
- public boolean isArtifactUpdateRequired(SvcLogicContext context, String db) throws SvcLogicException, SQLException, ConfigurationException {
+ public boolean isArtifactUpdateRequired(SvcLogicContext context, String db)
+ throws SvcLogicException, SQLException, ConfigurationException {
String fn = "DBService.isArtifactUpdateRequired";
log.info("Checking if Update required for this data");
@@ -210,7 +212,7 @@ public class DBService {
if (db != null) {
if (db.equals(SdcArtifactHandlerConstants.DB_SDC_REFERENCE)
&& context.getAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY)
- .equals(SdcArtifactHandlerConstants.CAPABILITY)
+ .equals(SdcArtifactHandlerConstants.CAPABILITY)
&& context.getAttribute(SdcArtifactHandlerConstants.ACTION) == null) {
whereClause = whereClause + " and FILE_CATEGORY = $" + SdcArtifactHandlerConstants.FILE_CATEGORY;
}
@@ -232,15 +234,16 @@ public class DBService {
int vnfc_instance = -1;
if (context.getAttribute(SdcArtifactHandlerConstants.VNFC_INSTANCE) != null)
vnfc_instance = Integer.parseInt(context.getAttribute(SdcArtifactHandlerConstants.VNFC_INSTANCE));
- whereClause = whereClause + " and ACTION = $" + SdcArtifactHandlerConstants.ACTION + " and VNFC_TYPE = $"
- + SdcArtifactHandlerConstants.VNFC_TYPE + " and VNFC_INSTANCE = $"
+ whereClause = whereClause + " and ACTION = $" + SdcArtifactHandlerConstants.ACTION
+ + " and VNFC_TYPE = $" + SdcArtifactHandlerConstants.VNFC_TYPE + " and VNFC_INSTANCE = $"
+ SdcArtifactHandlerConstants.VNFC_INSTANCE + " and VM_INSTANCE = $"
+ SdcArtifactHandlerConstants.VM_INSTANCE;
}
}
- if (!db.equals(SdcArtifactHandlerConstants.DB_DEVICE_AUTHENTICATION) && serviceLogic != null && context != null) {
+ if (!db.equals(SdcArtifactHandlerConstants.DB_DEVICE_AUTHENTICATION) && serviceLogic != null
+ && context != null) {
String key = "select COUNT(*) from " + db + whereClause;
log.info("SELECT String : " + key);
status = serviceLogic.query("SQL", false, null, key, null, null, context);
@@ -255,29 +258,32 @@ public class DBService {
} else
return false;
}
- if (db.equals(SdcArtifactHandlerConstants.DB_DEVICE_AUTHENTICATION) && serviceLogic != null && context != null) {
- log.info("Check for update or insert for properties file");
- String protocol = context.getAttribute(SdcArtifactHandlerConstants.DEVICE_PROTOCOL);
- String action = context.getAttribute(SdcArtifactHandlerConstants.ACTION);
- String vnf_type = context.getAttribute(SdcArtifactHandlerConstants.VNF_TYPE);
- PropertiesConfiguration conf = new PropertiesConfiguration(System.getenv("APPC_CONFIG_DIR")+"/appc_southbound.properties");
- String property ="";
+ if (db.equals(SdcArtifactHandlerConstants.DB_DEVICE_AUTHENTICATION) && serviceLogic != null
+ && context != null) {
+ log.info("Check for update or insert for properties file");
+ String protocol = context.getAttribute(SdcArtifactHandlerConstants.DEVICE_PROTOCOL);
+ String action = context.getAttribute(SdcArtifactHandlerConstants.ACTION);
+ String vnf_type = context.getAttribute(SdcArtifactHandlerConstants.VNF_TYPE);
+ PropertiesConfiguration conf =
+ new PropertiesConfiguration(System.getenv("APPC_CONFIG_DIR") + "/appc_southbound.properties");
+ String property = "";
if (StringUtils.isNotBlank(vnf_type)) {
- if (StringUtils.isNotBlank(protocol)) {
- if (StringUtils.isNotBlank(action)) {
- property = vnf_type + "." + protocol + "." + action;
- }
- }
+ if (StringUtils.isNotBlank(protocol)) {
+ if (StringUtils.isNotBlank(action)) {
+ property = vnf_type + "." + protocol + "." + action;
+ }
+ }
}
- if (conf.subset(property )!=null) {
- if (conf.containsKey(property )) {
- log.info("Key Exists for property"+property +"in southbound.properties file");
- return true;
- }
+ if (conf.subset(property) != null) {
+ if (conf.containsKey(property)) {
+ log.info("Key Exists for property" + property + "in southbound.properties file");
+ return true;
+ }
} else
- log.info("Key Doesnot exists and need to add the key for property"+property +"in southbound.properties file");
- return false;
+ log.info("Key Doesnot exists and need to add the key for property" + property
+ + "in southbound.properties file");
+ return false;
}
return false;
}
@@ -306,63 +312,65 @@ public class DBService {
}
- public void processDeviceAuthentication(SvcLogicContext context, boolean isUpdate) throws SvcLogicException, ConfigurationException {
+ public void processDeviceAuthentication(SvcLogicContext context, boolean isUpdate)
+ throws SvcLogicException, ConfigurationException {
String fn = "DBService.processDeviceAuthentication";
log.info(fn + "Starting DB operation for Device Authentication " + isUpdate);
String protocol = context.getAttribute(SdcArtifactHandlerConstants.DEVICE_PROTOCOL);
- String action = context.getAttribute(SdcArtifactHandlerConstants.ACTION);
- String vnf_type = context.getAttribute(SdcArtifactHandlerConstants.VNF_TYPE);
- String url = context.getAttribute(SdcArtifactHandlerConstants.URL);
- String port = context.getAttribute(SdcArtifactHandlerConstants.PORT_NUMBER);
- String user = context.getAttribute(SdcArtifactHandlerConstants.USER_NAME);
- String property = vnf_type + "." +protocol + "." + action;
- log.info("property :"+property);
- if (StringUtils.isBlank(url)) {
- url = "";
- }
- if (StringUtils.isBlank(port) ) {
- port = "";
- }
- if (StringUtils.isBlank(user)) {
- user = "";
- }
- if (((vnf_type == null) || ("".equals(vnf_type))) && ((action == null) || ("".equals(action)))
- && ((protocol == null) || ("".equals(protocol))))
- throw new SvcLogicException(
- "Error While processing refernce File as few or all of parameters VNF_TYPE,PROTOCOL,ACTION are missing ");
- PropertiesConfiguration conf = new PropertiesConfiguration(System.getenv("APPC_CONFIG_DIR")+"/appc_southbound.properties");
- log.info("is Updating to southbound properties : "+isUpdate);
- if (conf.containsKey(property + "." + "user")) {
- if(user!=null && !user.isEmpty())
- conf.setProperty(property + "." + "user", user);
- } else {
- log.info("is Adding to southbound.properties"+isUpdate);
-
- conf.addProperty(property + "." + "user", user);
- }
+ String action = context.getAttribute(SdcArtifactHandlerConstants.ACTION);
+ String vnf_type = context.getAttribute(SdcArtifactHandlerConstants.VNF_TYPE);
+ String url = context.getAttribute(SdcArtifactHandlerConstants.URL);
+ String port = context.getAttribute(SdcArtifactHandlerConstants.PORT_NUMBER);
+ String user = context.getAttribute(SdcArtifactHandlerConstants.USER_NAME);
+ String property = vnf_type + "." + protocol + "." + action;
+ log.info("property :" + property);
+ if (StringUtils.isBlank(url)) {
+ url = "";
+ }
+ if (StringUtils.isBlank(port)) {
+ port = "";
+ }
+ if (StringUtils.isBlank(user)) {
+ user = "";
+ }
+ if (((vnf_type == null) || ("".equals(vnf_type))) && ((action == null) || ("".equals(action)))
+ && ((protocol == null) || ("".equals(protocol))))
+ throw new SvcLogicException(
+ "Error While processing refernce File as few or all of parameters VNF_TYPE,PROTOCOL,ACTION are missing ");
+ PropertiesConfiguration conf =
+ new PropertiesConfiguration(System.getenv("APPC_CONFIG_DIR") + "/appc_southbound.properties");
+ log.info("is Updating to southbound properties : " + isUpdate);
+ if (conf.containsKey(property + "." + "user")) {
+ if (user != null && !user.isEmpty())
+ conf.setProperty(property + "." + "user", user);
+ } else {
+ log.info("is Adding to southbound.properties" + isUpdate);
+
+ conf.addProperty(property + "." + "user", user);
+ }
- if (conf.containsKey(property + "." + "port")) {
- if (port != null && !port.isEmpty())
- conf.setProperty(property + "." + "port", port);
- } else {
- conf.addProperty(property + "." + "port", port);
- }
- if (conf.containsKey(property + "." + "password")) {
- } else {
- conf.addProperty(property + "." + "password", "");
- }
- if (conf.containsKey(property + "." + "url")) {
- if (url != null && !url.isEmpty())
- conf.setProperty(property + "." + "url", url);
+ if (conf.containsKey(property + "." + "port")) {
+ if (port != null && !port.isEmpty())
+ conf.setProperty(property + "." + "port", port);
+ } else {
+ conf.addProperty(property + "." + "port", port);
+ }
+ if (conf.containsKey(property + "." + "password")) {
+ } else {
+ conf.addProperty(property + "." + "password", "");
+ }
+ if (conf.containsKey(property + "." + "url")) {
+ if (url != null && !url.isEmpty())
+ conf.setProperty(property + "." + "url", url);
- } else {
+ } else {
- conf.addProperty(property + "." + "url", url);
- }
- log.info("About to save to properties file");
- conf.save();
- log.info("saved to properties file");
- }
+ conf.addProperty(property + "." + "url", url);
+ }
+ log.info("About to save to properties file");
+ conf.save();
+ log.info("saved to properties file");
+ }
public void processVnfcReference(SvcLogicContext context, boolean isUpdate) throws SvcLogicException {
String fn = "DBService.processVnfcReference";
@@ -513,7 +521,7 @@ public class DBService {
}
public boolean isProtocolReferenceUpdateRequired(SvcLogicContext context, String vnfType, String protocol,
- String action, String action_level, String template) throws SvcLogicException {
+ String action, String action_level, String template) throws SvcLogicException {
SvcLogicContext localContext = new SvcLogicContext();
String fn = "DBService.isProtocolReferenceUpdateRequired";
log.info(fn + "Starting DB operation for isProtocolReferenceUpdateRequired");
@@ -532,15 +540,16 @@ public class DBService {
}
public void updateProtocolReference(SvcLogicContext context, String vnfType, String protocol, String action,
- String action_level, String template) throws SvcLogicException {
+ String action_level, String template) throws SvcLogicException {
String fn = "DBService.isProtocolReferenceUpdateRequired";
log.info(fn + "Starting DB operation for isProtocolReferenceUpdateRequired");
String key = "";
QueryStatus status = null;
- key = "update PROTOCOL_REFERENCE set UPDATED_DATE=now(), template='" + template + "' where ACTION='" + action
- + "' and ACTION_LEVEL='" + action_level + "' and VNF_TYPE='" + vnfType + "'";
+ key = "update PROTOCOL_REFERENCE set UPDATED_DATE=now(), template='" + template + "', protocol ='" + protocol
+ + "' where ACTION='" + action + "' and ACTION_LEVEL='" + action_level + "' and VNF_TYPE='" + vnfType
+ + "'";
status = serviceLogic.save("SQL", false, false, key, null, null, context);
if (status == QueryStatus.FAILURE) {
log.info("updateProtocolReference:: Error updating protocol reference");
@@ -558,7 +567,7 @@ public class DBService {
String protocol = context.getAttribute(SdcArtifactHandlerConstants.DEVICE_PROTOCOL);
if (StringUtils.isBlank(protocol)) {
log.info(fn + " :: Protocol is Blank!! Returning without querying DB");
- throw new ConfigurationException(fn+":: Protocol is Blank!! Returning without querying DB");
+ throw new ConfigurationException(fn + ":: Protocol is Blank!! Returning without querying DB");
}
key = "select download_config_dg from " + SdcArtifactHandlerConstants.DB_DOWNLOAD_DG_REFERENCE
+ " where protocol = '" + protocol + "'";
@@ -578,23 +587,25 @@ public class DBService {
}
public void cleanUpVnfcReferencesForVnf(SvcLogicContext context) throws SvcLogicException {
- try{
- String key1 = "delete from " + SdcArtifactHandlerConstants.DB_VNFC_REFERENCE
- + " where action = $"+ SdcArtifactHandlerConstants.ACTION + " and vnf_type = $" + SdcArtifactHandlerConstants.VNF_TYPE;
- log.debug("Action : " + context.getAttribute(SdcArtifactHandlerConstants.ACTION));
- log.debug("vnfType: "+ context.getAttribute(SdcArtifactHandlerConstants.VNF_TYPE));
- QueryStatus status = null;
- log.info("cleanUpVnfcReferencesForVnf()::Query:" + key1);
- if (serviceLogic != null && context != null) {
- status = serviceLogic.save("SQL", false, false, key1, null, null, context);
- if (status.toString().equals("FAILURE")) {
- log.debug("Error deleting from VNFC_REFERENCE table");
- throw new SvcLogicException("Error While processing VNFC_REFERENCE table ");
- }
- status = null;
- }
- }catch(Exception e){
- log.debug("Error deleting from VNFC_REFERENCE table : "+context.getAttribute(SdcArtifactHandlerConstants.ACTION) +" and " +context.getAttribute(SdcArtifactHandlerConstants.VNF_TYPE));
- }
- }
+ try {
+ String key1 = "delete from " + SdcArtifactHandlerConstants.DB_VNFC_REFERENCE + " where action = $"
+ + SdcArtifactHandlerConstants.ACTION + " and vnf_type = $" + SdcArtifactHandlerConstants.VNF_TYPE;
+ log.debug("Action : " + context.getAttribute(SdcArtifactHandlerConstants.ACTION));
+ log.debug("vnfType: " + context.getAttribute(SdcArtifactHandlerConstants.VNF_TYPE));
+ QueryStatus status = null;
+ log.info("cleanUpVnfcReferencesForVnf()::Query:" + key1);
+ if (serviceLogic != null && context != null) {
+ status = serviceLogic.save("SQL", false, false, key1, null, null, context);
+ if (status.toString().equals("FAILURE")) {
+ log.debug("Error deleting from VNFC_REFERENCE table");
+ throw new SvcLogicException("Error While processing VNFC_REFERENCE table ");
+ }
+ status = null;
+ }
+ } catch (Exception e) {
+ log.debug("Error deleting from VNFC_REFERENCE table : "
+ + context.getAttribute(SdcArtifactHandlerConstants.ACTION) + " and "
+ + context.getAttribute(SdcArtifactHandlerConstants.VNF_TYPE));
+ }
+ }
}