summaryrefslogtreecommitdiffstats
path: root/appc-inbound/appc-artifact-handler/provider/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'appc-inbound/appc-artifact-handler/provider/src/main')
-rw-r--r--appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/dbservices/DBService.java72
-rw-r--r--appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNode.java53
2 files changed, 110 insertions, 15 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 8e0e71ad0..e1c76ecf8 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
@@ -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
* =============================================================================
@@ -18,7 +18,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
* ============LICENSE_END=========================================================
*/
@@ -155,10 +154,13 @@ public class DBService {
}
public void processSdcReferences(SvcLogicContext context, boolean isUpdate) throws SvcLogicException {
+ processSdcReferences(context, isUpdate, null);
+ }
+
+ public void processSdcReferences(SvcLogicContext context, boolean isUpdate, String modelId) throws SvcLogicException {
String key;
QueryStatus status;
-
- if (isUpdate && context.getAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY)
+ if (isUpdate && context.getAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY)
.equals(SdcArtifactHandlerConstants.CAPABILITY)) {
log.info("Updating capability artifact in ASDC_REFERENCE");
key = UPDATE_QUERY_STR + SdcArtifactHandlerConstants.DB_SDC_REFERENCE + " set ARTIFACT_NAME = $"
@@ -171,6 +173,9 @@ public class DBService {
+ SdcArtifactHandlerConstants.VNFC_TYPE + AND_FILE_CAT_QUERY_STR
+ SdcArtifactHandlerConstants.FILE_CATEGORY + AND_ACTION_QUERY_STR + SdcArtifactHandlerConstants.ACTION
+ AND_VNF_TYPE_QUERY_STR + SdcArtifactHandlerConstants.VNF_TYPE;
+ if (StringUtils.isNotBlank(modelId)) {
+ key += createQueryListForTemplateIds(modelId);
+ }
} else {
if (context.getAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY)
.equals(SdcArtifactHandlerConstants.CAPABILITY)) {
@@ -197,7 +202,11 @@ public class DBService {
}
}
- public boolean isArtifactUpdateRequired(SvcLogicContext context, String db)
+ public boolean isArtifactUpdateRequired(SvcLogicContext context, String db) throws DBException {
+ return isArtifactUpdateRequired( context, db, null);
+ }
+
+ public boolean isArtifactUpdateRequired(SvcLogicContext context, String db, String modelId)
throws DBException {
try {
log.info("Checking if Update required for this data");
@@ -207,6 +216,22 @@ public class DBService {
log.info("VNFC_INSTANCE=" + context.getAttribute(SdcArtifactHandlerConstants.VNFC_INSTANCE));
log.info("VM_INSTANCE=" + context.getAttribute(SdcArtifactHandlerConstants.VM_INSTANCE));
log.info("VNF_TYPE=" + context.getAttribute(SdcArtifactHandlerConstants.VNF_TYPE));
+
+ //Check for templates
+ //if templates are present - there might be multiple records, so validate
+ if( db.equals(SdcArtifactHandlerConstants.DB_SDC_REFERENCE) && StringUtils.isNotBlank(modelId)) {
+ log.info("ModelId is sent!!");
+ String queryPart = createQueryListForTemplateIds(modelId);
+ log.info("Querypart is = "+queryPart);
+ if (isUpdateRequiredForTemplates(queryPart, context, db)) {
+ log.info("Update is Required!!");
+ return true;
+ } else {
+ log.info("Insert is Required!!");
+ return false;
+ }
+ }
+
String whereClause;
QueryStatus status;
whereClause = WHERE_VNF_TYPE_QUERY_STR + SdcArtifactHandlerConstants.VNF_TYPE;
@@ -675,4 +700,41 @@ public class DBService {
+ context.getAttribute(SdcArtifactHandlerConstants.VNF_TYPE), e);
}
}
+
+
+ public boolean isUpdateRequiredForTemplates(String queryPart, SvcLogicContext context, String db) throws DBException {
+ try {
+ log.info("Checking if Update required for this data");
+ log.info("db" + db);
+ log.info("ACTION=" + context.getAttribute(SdcArtifactHandlerConstants.ACTION));
+ log.info("VNF_TYPE=" + context.getAttribute(SdcArtifactHandlerConstants.VNF_TYPE));
+ log.info("");
+ String whereClause;
+ QueryStatus status;
+ whereClause = WHERE_VNF_TYPE_QUERY_STR + SdcArtifactHandlerConstants.VNF_TYPE ;
+ whereClause = resolveWhereClause(context, db, whereClause);
+ whereClause += queryPart;
+ if (validate(db)) {
+ if (!db.equals(SdcArtifactHandlerConstants.DB_DEVICE_AUTHENTICATION)) {
+ String key = "select COUNT(*) from " + db + whereClause;
+ log.info("SELECT String : " + key);
+ status = serviceLogic.query("SQL", false, null, key, null, null, context);
+ checkForFailure(db, status);
+ String count = context.getAttribute("COUNT(*)");
+ log.info("Number of row Returned : " + count + ": " + status + ":");
+ return tryAddCountAttribute(context, count);
+ }
+ }
+ log.info("Problems validating DB and/or Context ");
+ return false;
+
+ } catch (SvcLogicException e) {
+ throw new DBException("An error occurred while checking for artifact update", e);
+ }
+ }
+
+ public String createQueryListForTemplateIds(String modelId) {
+ String queryPart = " AND ARTIFACT_NAME like '%_" + modelId+".%'";
+ return queryPart;
+ }
}
diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNode.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNode.java
index c47650539..349821723 100644
--- a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNode.java
+++ b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNode.java
@@ -18,7 +18,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
* ============LICENSE_END=========================================================
*/
@@ -410,7 +409,12 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin {
try {
if (content.has(ARTIFACT_LIST_PARAM) && content.get(ARTIFACT_LIST_PARAM) instanceof JSONArray) {
JSONArray artifactLists = (JSONArray) content.get(ARTIFACT_LIST_PARAM);
- doProcessArtifactList(dbservice, context, artifactLists);
+ JSONArray templateIdList = null;
+ if (content.has("template-id-list") && null != content.get("template-id-list")
+ && content.get("template-id-list") instanceof JSONArray) {
+ templateIdList = content.getJSONArray("template-id-list");
+ }
+ doProcessArtifactList(dbservice, context, artifactLists, templateIdList);
}
} catch (Exception e) {
log.error("An error occurred when processing artifact list", e);
@@ -418,14 +422,23 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin {
}
}
- private void doProcessArtifactList(DBService dbservice, SvcLogicContext context, JSONArray artifactLists)
+ private void doProcessArtifactList(DBService dbservice, SvcLogicContext context, JSONArray artifactLists,
+ JSONArray templateIdList)
throws SvcLogicException, SQLException, ConfigurationException, DBException {
boolean pdFile = false;
- String suffix = null;
+ int modelInd = 0;
for (int i = 0; i < artifactLists.length(); i++) {
+ String suffix = null;
+ String model = null;
JSONObject artifact = (JSONObject) artifactLists.get(i);
log.info("artifact is " + artifact);
+
+ //Get Model details
+ if (null != templateIdList && i>0 && i%2==0) {
+ modelInd++;
+ }
+
setAttribute(context, artifact::getString, ARTIFACT_NAME);
context.setAttribute(FILE_CATEGORY,
artifact.getString(ARTIFACT_TYPE));
@@ -436,26 +449,46 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin {
suffix = artifact.getString(ARTIFACT_NAME).substring(PD.length());
pdFile = true;
}
- log.info("Artifact-type = " + context.getAttribute(ARTIFACT_TYPE));
- dbservice.processSdcReferences(context, dbservice.isArtifactUpdateRequired(context,
+ log.info("Artifact-type = " + context.getAttribute(FILE_CATEGORY));
+ log.info("Artifact-name = " + context.getAttribute(ARTIFACT_NAME));
+
+ if (null != templateIdList && modelInd < templateIdList.length()) {
+ model = templateIdList.getString(modelInd);
+ log.info("Model is ::: "+model+" ,modelInd = "+modelInd);
+ }
+
+ if (StringUtils.isNotBlank(model)) {
+ dbservice.processSdcReferences(context, dbservice.isArtifactUpdateRequired(context,
+ DB_SDC_REFERENCE, model),model);
+ }
+ else {
+ dbservice.processSdcReferences(context, dbservice.isArtifactUpdateRequired(context,
DB_SDC_REFERENCE));
+ }
cleanArtifactInstanceData(context);
+ //Moving this into the for loop to account for mulitple artifact sets with pds
+ if (pdFile) {
+ log.info("Sending information related to pdfile Artifact");
+ tryUpdateContext(dbservice, context, pdFile, suffix, model);
+ pdFile=false;//set to false afterprocessing yang and Tosca
+ }
}
- tryUpdateContext(dbservice, context, pdFile, suffix);
+
}
- private void tryUpdateContext(DBService dbservice, SvcLogicContext context, boolean pdFile, String suffix)
+ private void tryUpdateContext(DBService dbservice, SvcLogicContext context, boolean pdFile,
+ String suffix, String model)
throws SvcLogicException, SQLException, ConfigurationException, DBException {
if (pdFile) {
context.setAttribute(ARTIFACT_NAME, "Tosca".concat(suffix));
context.setAttribute(FILE_CATEGORY, TOSCA_MODEL);
dbservice.processSdcReferences(context,
- dbservice.isArtifactUpdateRequired(context, DB_SDC_REFERENCE));
+ dbservice.isArtifactUpdateRequired(context, DB_SDC_REFERENCE, model), model);
context.setAttribute(ARTIFACT_NAME, "Yang".concat(suffix));
context.setAttribute(FILE_CATEGORY, PARAMETER_YANG);
dbservice.processSdcReferences(context,
- dbservice.isArtifactUpdateRequired(context, DB_SDC_REFERENCE));
+ dbservice.isArtifactUpdateRequired(context, DB_SDC_REFERENCE, model), model);
}
}