Set serviceInstanceId on failed validation 19/111919/1
authorKuleshov, Elena <evn@att.com>
Mon, 31 Aug 2020 19:19:05 +0000 (15:19 -0400)
committerBenjamin, Max (mb388a) <mb388a@att.com>
Mon, 31 Aug 2020 19:19:06 +0000 (15:19 -0400)
Set serviceInstanceId on failed validation requests in the DB.

Issue-ID: SO-3211
Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com>
Change-Id: Ie4232dfd7caa2cc2661ce56b1b14863ac02628fc

mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/E2EServiceInstances.java
mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java
mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java
mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java

index 665fa54..c7692cb 100644 (file)
@@ -396,7 +396,8 @@ public class E2EServiceInstances {
                     ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version);
 
             msoRequest.createErrorRequestRecord(Status.FAILED, requestId,
-                    "Exception while communciate with " + "Catalog DB", action, ModelType.service.name(), requestJSON);
+                    "Exception while communciate with " + "Catalog DB", action, ModelType.service.name(), requestJSON,
+                    null);
             logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
             return response;
         }
@@ -408,7 +409,7 @@ public class E2EServiceInstances {
                     ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null, version);
 
             msoRequest.createErrorRequestRecord(Status.FAILED, requestId, "Recipe does not exist in catalog DB", action,
-                    ModelType.service.name(), requestJSON);
+                    ModelType.service.name(), requestJSON, null);
             logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
             return response;
         }
@@ -484,7 +485,8 @@ public class E2EServiceInstances {
                     ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version);
 
             msoRequest.createErrorRequestRecord(Status.FAILED, requestId,
-                    "Exception while communciate with " + "Catalog DB", action, ModelType.service.name(), requestJSON);
+                    "Exception while communciate with " + "Catalog DB", action, ModelType.service.name(), requestJSON,
+                    null);
             logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
             return response;
         }
@@ -496,7 +498,7 @@ public class E2EServiceInstances {
                     ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null, version);
 
             msoRequest.createErrorRequestRecord(Status.FAILED, requestId, "Recipe does not exist in catalog DB", action,
-                    ModelType.service.name(), requestJSON);
+                    ModelType.service.name(), requestJSON, null);
             logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
             return response;
         }
@@ -715,7 +717,8 @@ public class E2EServiceInstances {
                     ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version);
 
             msoRequest.createErrorRequestRecord(Status.FAILED, requestId,
-                    "No communication to catalog DB " + e.getMessage(), action, ModelType.service.name(), requestJSON);
+                    "No communication to catalog DB " + e.getMessage(), action, ModelType.service.name(), requestJSON,
+                    null);
             logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
             return response;
         }
@@ -727,7 +730,7 @@ public class E2EServiceInstances {
                     MsoException.ServiceException, "Recipe does not exist in catalog DB",
                     ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null, version);
             msoRequest.createErrorRequestRecord(Status.FAILED, requestId, "No recipe found in DB", action,
-                    ModelType.service.name(), requestJSON);
+                    ModelType.service.name(), requestJSON, null);
             logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
             return response;
         }
@@ -948,7 +951,7 @@ public class E2EServiceInstances {
                             ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build();
 
             msoRequest.createErrorRequestRecord(Status.FAILED, requestId, validateException.getMessage(), action,
-                    ModelType.service.name(), requestJSON);
+                    ModelType.service.name(), requestJSON, null);
 
             throw validateException;
         }
index 4ac8b73..bf76cd3 100644 (file)
@@ -451,7 +451,7 @@ public class MsoRequest {
     }
 
     public void createErrorRequestRecord(Status status, String requestId, String errorMessage, Actions action,
-            String requestScope, String requestJSON) {
+            String requestScope, String requestJSON, String serviceInstanceId) {
         try {
             InfraActiveRequests request = new InfraActiveRequests(requestId);
             Timestamp startTimeStamp = new Timestamp(System.currentTimeMillis());
@@ -463,6 +463,9 @@ public class MsoRequest {
             request.setRequestAction(action.toString());
             request.setRequestScope(requestScope);
             request.setRequestBody(requestJSON);
+            if (serviceInstanceId != null) {
+                request.setServiceInstanceId(serviceInstanceId);
+            }
             Timestamp endTimeStamp = new Timestamp(System.currentTimeMillis());
             request.setEndTime(endTimeStamp);
             request.setRequestUrl(MDC.get(LogConstants.HTTP_URL));
index a68309f..87e5a2f 100644 (file)
@@ -326,7 +326,7 @@ public class RequestHandlerUtils extends AbstractRestHandler {
             String requestScope = requestScopeFromUri(requestUri);
 
             msoRequest.createErrorRequestRecord(Status.FAILED, requestId, validateException.getMessage(), action,
-                    requestScope, requestJSON);
+                    requestScope, requestJSON, null);
 
             throw validateException;
         }
index 418ba05..107aa57 100644 (file)
@@ -823,9 +823,16 @@ public class ServiceInstances extends AbstractRestHandler {
 
         sir = requestHandlerUtils.convertJsonToServiceInstanceRequest(requestJSON, action, requestId, requestUri);
         action = handleReplaceInstance(action, sir);
-        requestValidatorListenerRunner.runValidations(requestUri, instanceIdMap, sir, queryParams, action);
 
         String requestScope = requestHandlerUtils.deriveRequestScope(action, sir, requestUri);
+        try {
+            requestValidatorListenerRunner.runValidations(requestUri, instanceIdMap, sir, queryParams, action);
+        } catch (ApiException e) {
+            msoRequest.createErrorRequestRecord(Status.FAILED, requestId, e.getMessage(), action, requestScope,
+                    requestJSON, sir.getServiceInstanceId());
+            throw e;
+        }
+
         InfraActiveRequests currentActiveReq =
                 msoRequest.createRequestObject(sir, action, requestId, Status.IN_PROGRESS, requestJSON, requestScope);
         if (sir.getRequestDetails().getRequestParameters() != null) {