aboutsummaryrefslogtreecommitdiffstats
path: root/appc-inbound/appc-design-services/provider
diff options
context:
space:
mode:
Diffstat (limited to 'appc-inbound/appc-design-services/provider')
-rw-r--r--appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DbResponseProcessor.java10
-rw-r--r--appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DesignDBService.java103
-rw-r--r--appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/RequestValidator.java18
-rw-r--r--appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/DesignServiceConstants.java3
-rw-r--r--appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDesignDBServices.java7
5 files changed, 123 insertions, 18 deletions
diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DbResponseProcessor.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DbResponseProcessor.java
index 229e61cb3..5e5f78a53 100644
--- a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DbResponseProcessor.java
+++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DbResponseProcessor.java
@@ -66,9 +66,15 @@ public class DbResponseProcessor {
case DesignServiceConstants.SETINCART:
response= getsetStatusResponse(dbresposne);
break;
- default:
+ case DesignServiceConstants.UPLOADADMINARTIFACT:
+ response= getsetStatusResponse(dbresposne);
+ break;
+ case DesignServiceConstants.CHECKVNF:
+ response= getStatusResponse(dbresposne);
+ break;
+ default:
log.error("Action " + action + " Not Supported by response Parser");
- throw new Exception(" Action " + action + " not found while processing request ");
+ throw new Exception(" Action " + action + " not found while processing request ");
}
return response;
diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DesignDBService.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DesignDBService.java
index af9dfc9ec..4e6375b91 100644
--- a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DesignDBService.java
+++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DesignDBService.java
@@ -33,6 +33,8 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
+
+import org.json.JSONObject;
import org.onap.appc.design.data.ArtifactInfo;
import org.onap.appc.design.data.DesignInfo;
import org.onap.appc.design.data.DesignResponse;
@@ -41,6 +43,7 @@ import org.onap.appc.design.services.util.ArtifactHandlerClient;
import org.onap.appc.design.services.util.DesignServiceConstants;
import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource;
import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
+import org.apache.commons.lang.StringUtils;
public class DesignDBService {
@@ -109,6 +112,12 @@ public class DesignDBService {
case DesignServiceConstants.SETPROTOCOLREFERENCE:
response = setProtocolReference(payload, requestID);
break;
+ case DesignServiceConstants.UPLOADADMINARTIFACT:
+ response = uploadAdminArtifact(payload, requestID);
+ break;
+ case DesignServiceConstants.CHECKVNF:
+ response = checkVNF(payload, requestID);
+ break;
default:
throw new DBException(" Action " + action + " not found while processing request ");
@@ -116,6 +125,77 @@ public class DesignDBService {
return response;
}
+ private String checkVNF(String payload, String requestId) throws Exception {
+
+ log.info("Got into Check VNF Request with payload: " + payload);
+ if (StringUtils.isBlank(payload))
+ throw new DBException("Payload in CheckVNF request is null or Blank");
+ if (StringUtils.isBlank(requestId))
+ throw new DBException("requestId in CheckVNF request is null or Blank");
+ ObjectMapper objectMapper = new ObjectMapper();
+ JsonNode payloadObject = objectMapper.readTree(payload);
+ String vnfType = payloadObject.get("vnf-type").textValue();
+ log.info("Check VNF Request with VNF TYPE: " + vnfType);
+ ArrayList<String> argList = new ArrayList<>();
+ argList.add(vnfType);
+ String queryString = "SELECT DT_ACTION_STATUS_ID,USER FROM sdnctl.DT_ACTION_STATUS WHERE VNF_TYPE = ? ORDER BY DT_ACTION_STATUS_ID DESC LIMIT 1 ; ";
+ log.info(QUERY_STR + queryString);
+ ResultSet data = dbservice.getDBData(queryString, argList);
+ int rowCount = 0;
+ String user = null;
+ String dtActionStatusId = null;
+ while (data.next()) {
+ rowCount++;
+ user = data.getString("USER");
+ dtActionStatusId = data.getString("DT_ACTION_STATUS_ID");
+ }
+ log.debug("DT_ACTION_STATUS_ID-> " + dtActionStatusId + " user-> " + user);
+ JSONObject jObject = new JSONObject();
+ if (rowCount == 0) {
+ log.debug("vnf-type does not present in APPC DB, row Count:" + rowCount);
+ jObject.put("result", "No");
+ } else {
+ log.debug("vnf-type present in APPC DB, row Count:" + rowCount);
+ jObject.put("result", "Yes");
+ jObject.put("user", user);
+ }
+ log.info("Check VNF result: " + jObject.toString());
+
+ return jObject.toString();
+
+ }
+
+ private String uploadAdminArtifact(String payload, String requestId) throws Exception {
+
+ ObjectMapper objectMapper = new ObjectMapper();
+ objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
+ JsonNode payloadObject = objectMapper.readTree(payload);
+ log.info("Got upload Admin Aritfact with requestId : " + requestId + " & Payload" + payloadObject.asText());
+
+ if (StringUtils.isBlank(requestId)) {
+ throw new DBException("Request-id is missing in the uploadAdminArtifact payload . ");
+ }
+
+ ArtifactHandlerClient ac = new ArtifactHandlerClient();
+ String requestString = ac.createArtifactData(payload, requestId);
+ ac.execute(requestString, "POST");
+
+ int sdcArtifactId = getSDCArtifactIDbyRequestID(requestId);
+ if (sdcArtifactId == 0)
+ throw new DBException(
+ "Error occured while validating/Saving the artifact to SDC_ARTIFACTS or getting SDC_ARTIFACTS_ID .");
+ JsonNode json = payloadObject.get(DesignServiceConstants.USER_ID);
+ if (json == null || json.asText().trim().isEmpty()) {
+ log.info("UserId in Admin Aritfact is null or blank, User Id : " + json.asText());
+ throw new DBException("User Id is null or blank");
+ }
+
+ int sdcReferenceId = 0;
+ createArtifactTrackingRecord(payload, requestId, sdcArtifactId, sdcReferenceId);
+
+ return SUCCESS_JSON;
+ }
+
private String getAppcTimestampUTC( String requestID) throws Exception
{
log.info("Starting getAppcTimestampUTC: requestID:" + requestID );
@@ -389,7 +469,7 @@ public class DesignDBService {
ArrayList<String> argList = new ArrayList<>();
argList.add("TLSUUID" + requestID);
String queryString = " SELECT ASDC_ARTIFACTS_ID FROM ASDC_ARTIFACTS where SERVICE_UUID = ? ";
- log.info(QUERY_STR + queryString);
+ log.info(QUERY_STR + queryString+ " & UUID or" + "TLSUUID :" + requestID);
ResultSet data = dbservice.getDBData(queryString, argList);
while (data.next()) {
artifactId = data.getInt("ASDC_ARTIFACTS_ID");
@@ -408,26 +488,33 @@ public class DesignDBService {
try {
ObjectMapper objectMapper = new ObjectMapper();
JsonNode payloadObject = objectMapper.readTree(payload);
+ String artifactName = payloadObject.get("artifact-name").textValue();
ArrayList<String> argList = new ArrayList<>();
- argList.add(payloadObject.get("artifact-name").textValue());
+ argList.add(artifactName);
argList.add(payloadObject.get("artifact-type").textValue());
- String queryString = "SELECT INTERNAL_VERSION, ARTIFACT_CONTENT FROM ASDC_ARTIFACTS where " +
- " ARTIFACT_NAME = ? AND ARTIFACT_TYPE = ? ";
-
+ String queryString = "SELECT INTERNAL_VERSION, ARTIFACT_CONTENT FROM ASDC_ARTIFACTS where "
+ + " ARTIFACT_NAME = ? AND ARTIFACT_TYPE = ? ";
log.info(QUERY_STR + queryString);
ResultSet data = dbservice.getDBData(queryString, argList);
String artifactContent = null;
+ int rowCount = 0;
int hightestVerion = -1;
while (data.next()) {
+ rowCount++;
int version = data.getInt("INTERNAL_VERSION");
if (hightestVerion < version) {
artifactContent = data.getString("ARTIFACT_CONTENT");
+ hightestVerion = version;
}
}
+ log.debug("No of rows: " + rowCount + " highest Inetrnal Version" + hightestVerion);
+ if (rowCount == 0) {
+ throw new DBException("Sorry !!!APPC DB doesn't have any artifact Named : " + artifactName);
+ }
if (artifactContent == null || artifactContent.isEmpty()) {
- throw new DBException(
- "Sorry !!! I dont have any artifact Named : " + payloadObject.get("artifact-name").textValue());
+ throw new DBException("Sorry !!! Artifact Content is stored blank in APPC DB for " + artifactName
+ + " and Internal version " + hightestVerion);
}
DesignResponse designResponse = new DesignResponse();
List<ArtifactInfo> artifactInfoList = new ArrayList<>();
@@ -437,7 +524,7 @@ public class DesignDBService {
designResponse.setArtifactInfo(artifactInfoList);
ObjectMapper mapper = new ObjectMapper();
String jsonString = mapper.writeValueAsString(designResponse);
- log.info(INFO_STR + jsonString);
+ log.debug("End of getArtifact:" + INFO_STR + jsonString);
return jsonString;
} catch (Exception e) {
log.error(DB_OPERATION_ERROR, e);
diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/RequestValidator.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/RequestValidator.java
index 5278cc7b3..f98aae46f 100644
--- a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/RequestValidator.java
+++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/RequestValidator.java
@@ -48,6 +48,8 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
+import org.onap.appc.design.services.util.DesignServiceConstants;
+
public class RequestValidator {
private static final EELFLogger log = EELFManager.getInstance().getLogger(RequestValidator.class);
@@ -82,16 +84,28 @@ public class RequestValidator {
case UPLOADARTIFACT:
errorString = resolveUploadArtifactErrorString(payloadObject);
break;
+ case DesignServiceConstants.UPLOADADMINARTIFACT:
+ errorString = resolveUploadArtifactErrorString(payloadObject);
+ break;
case SETPROTOCOLREFERENCE:
case SETINCART:
errorString = resolveErrorString(payloadObject);
break;
+ case DesignServiceConstants.CHECKVNF:
+ errorString = resolveCheckVNFErrorString(payloadObject);
+ break;
default:
throw new RequestValidationException(" Action " + action + " not found while processing request ");
}
checkForErrorString(errorString);
}
+ private static String resolveCheckVNFErrorString(JsonNode payloadObject) {
+ if (nullOrEmpty(payloadObject, VNF_TYPE))
+ return VNF_TYPE;
+ return null;
+ }
+
private static void checkForErrorString(String errorString) throws RequestValidationException {
if (errorString != null) {
throw new RequestValidationException(" Missing input parameter :-" + errorString + " -:");
@@ -174,8 +188,8 @@ public class RequestValidator {
}
private static boolean nullOrEmpty(JsonNode payloadObject, String param) {
- return payloadObject.get(param) == null || payloadObject
- .get(param).textValue().isEmpty();
+ JsonNode payload = payloadObject.get(param);
+ return payload == null || payload.textValue().trim().isEmpty();
}
}
diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/DesignServiceConstants.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/DesignServiceConstants.java
index 7bc8f40eb..ccd5bf8d0 100644
--- a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/DesignServiceConstants.java
+++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/DesignServiceConstants.java
@@ -90,6 +90,7 @@ public class DesignServiceConstants {
public static final String ARTIFACT_TYPE = "artifact-type";
public static final String STATUS = "status";
public static final String UPLOADARTIFACT = "uploadArtifact";
+ public static final String UPLOADADMINARTIFACT = "uploadAdminArtifact";
public static final String REQUETS_ID = "request-id";
public static final String REQUEST_ACTION = "request-action";
public static final String SOURCE = "source";
@@ -107,7 +108,7 @@ public class DesignServiceConstants {
public static final String INSTAR_V6_ADDRESS = "v6IPAddress";
public static final String INSTAR_V4_MASK = "v4Subnet";
public static final String INSTAR_V6_MASK = "v6Subnet";
-
+ public static final String CHECKVNF = "checkVNF";
private DesignServiceConstants() {
}
diff --git a/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDesignDBServices.java b/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDesignDBServices.java
index 127ca4c2c..b8972a48b 100644
--- a/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDesignDBServices.java
+++ b/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDesignDBServices.java
@@ -198,8 +198,5 @@ public class TestDesignDBServices {
DesignDBService design = DesignDBService.initialise();
String result = Whitebox.invokeMethod(design, "getAppcTimestampUTC",requestId);
assertTrue(result.endsWith("Z"));
- }
-
-
-
-}
+ }
+ }