add compareModelofE2EServiceInstance process 37/37737/2
authorYulian Han <elaine.hanyulian@huawei.com>
Fri, 23 Mar 2018 01:45:53 +0000 (09:45 +0800)
committerYulian Han <elaine.hanyulian@huawei.com>
Fri, 23 Mar 2018 01:45:53 +0000 (09:45 +0800)
Change-Id: Idaa55084f5ecb0dd3636c232cebc14fa5f0641e6
Issue-ID: SO-419
Signed-off-by: Yulian Han <elaine.hanyulian@huawei.com>
mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/Action.java
mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstances.java

index 86cacb9..8c99d06 100644 (file)
@@ -36,5 +36,6 @@ public enum Action {
        addRelationships,
        removeRelationships,
        inPlaceSoftwareUpdate,
-       applyUpdatedConfig
+       applyUpdatedConfig,
+       compareModel
 }
index c27e827..6d6227a 100644 (file)
@@ -50,6 +50,7 @@ import org.openecomp.mso.apihandler.common.ResponseHandler;
 import org.openecomp.mso.apihandlerinfra.Messages;\r
 import org.openecomp.mso.apihandlerinfra.MsoException;\r
 import org.openecomp.mso.apihandlerinfra.MsoRequest;\r
+import org.openecomp.mso.apihandlerinfra.e2eserviceinstancebeans.CompareModelsRequest;\r
 import org.openecomp.mso.apihandlerinfra.e2eserviceinstancebeans.DelE2ESvcResp;\r
 import org.openecomp.mso.apihandlerinfra.e2eserviceinstancebeans.E2EServiceInstanceDeleteRequest;\r
 import org.openecomp.mso.apihandlerinfra.e2eserviceinstancebeans.E2EServiceInstanceRequest;\r
@@ -158,6 +159,125 @@ public class E2EServiceInstances {
                        @PathParam("operationId") String operationId) {\r
                return getE2EServiceInstances(serviceId, operationId);\r
        }\r
+       \r
+       /**\r
+        * GET Requests for Comparing model of service instance with target version\r
+        */\r
+       \r
+       @GET\r
+       @Path("/{version:[vV][3-5]}/{serviceId}/modeldifferences")\r
+       @Consumes(MediaType.APPLICATION_JSON)\r
+       @Produces(MediaType.APPLICATION_JSON)\r
+       @ApiOperation(value = "Find added and deleted resources of target model for the e2eserviceInstance on a given serviceId ", response = Response.class)\r
+       public Response compareModelwithTargetVersion(String request,\r
+                       @PathParam("serviceId") String serviceId,\r
+                       @PathParam("version") String version) {\r
+               \r
+               instanceIdMap.put("serviceId", serviceId);\r
+               \r
+               return compareModelwithTargetVersion(request, Action.compareModel, instanceIdMap, version);\r
+       }       \r
+\r
+       private Response compareModelwithTargetVersion(String requestJSON, Action action,\r
+                       HashMap<String, String> instanceIdMap, String version) {\r
+\r
+               String requestId = instanceIdMap.get("serviceId");\r
+               long startTime = System.currentTimeMillis();\r
+               msoLogger.debug("requestId is: " + requestId);\r
+\r
+               CompareModelsRequest e2eCompareModelReq = null;\r
+\r
+               MsoRequest msoRequest = new MsoRequest(requestId);\r
+\r
+               ObjectMapper mapper = new ObjectMapper();\r
+               try {\r
+                       e2eCompareModelReq = mapper.readValue(requestJSON, CompareModelsRequest.class);\r
+\r
+               } catch (Exception e) {\r
+\r
+                       msoLogger.debug("Mapping of request to JSON object failed : ", e);\r
+                       Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST,\r
+                                       MsoException.ServiceException, "Mapping of request to JSON object failed.  " + e.getMessage(),\r
+                                       ErrorNumbers.SVC_BAD_PARAMETER, null);\r
+                       msoLogger.error(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "",\r
+                                       MsoLogger.ErrorCode.SchemaError, requestJSON, e);\r
+                       msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError,\r
+                                       "Mapping of request to JSON object failed");\r
+                       msoLogger.debug("End of the transaction, the final response is: " + response.getEntity().toString());\r
+\r
+                       return response;\r
+               }\r
+\r
+               Response returnResp = runCompareModelBPMWorkflow(e2eCompareModelReq, msoRequest, requestJSON, requestId,\r
+                               startTime, action);\r
+\r
+               return returnResp;\r
+\r
+       }\r
+\r
+       private Response runCompareModelBPMWorkflow(CompareModelsRequest e2eCompareModelReq, MsoRequest msoRequest,\r
+                       String requestJSON, String requestId, long startTime, Action action) {\r
+               \r
+               // Define RecipeLookupResult info here instead of query DB for efficiency\r
+               String workflowUrl = "/mso/async/services/CompareModelofE2EServiceInstance";\r
+               int recipeTimeout = 180;\r
+\r
+               RequestClient requestClient = null;\r
+               HttpResponse response = null;\r
+\r
+               long subStartTime = System.currentTimeMillis();\r
+\r
+               try {\r
+                       requestClient = RequestClientFactory.getRequestClient(workflowUrl, MsoPropertiesUtils.loadMsoProperties());\r
+\r
+                       JSONObject jjo = new JSONObject(requestJSON);\r
+                       String bpmnRequest = jjo.toString();\r
+\r
+                       // Capture audit event\r
+                       msoLogger.debug("MSO API Handler Posting call to BPEL engine for url: " + requestClient.getUrl());\r
+                       String serviceId = instanceIdMap.get("serviceId");\r
+                       String serviceType = e2eCompareModelReq.getServiceType();\r
+                       response = requestClient.post(requestId, false, recipeTimeout, action.name(), serviceId, null, null, null,\r
+                                       null, null, serviceType, null, null, null, bpmnRequest, null);\r
+\r
+                       msoLogger.recordMetricEvent(subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,\r
+                                       "Successfully received response from BPMN engine", "BPMN", workflowUrl, null);\r
+               } catch (Exception e) {\r
+                       msoLogger.recordMetricEvent(subStartTime, MsoLogger.StatusCode.ERROR,\r
+                                       MsoLogger.ResponseCode.CommunicationError, "Exception while communicate with BPMN engine", "BPMN",\r
+                                       workflowUrl, null);\r
+                       Response resp = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY,\r
+                                       MsoException.ServiceException, "Failed calling bpmn " + e.getMessage(),\r
+                                       ErrorNumbers.SVC_NO_SERVER_RESOURCES, null);\r
+                       alarmLogger.sendAlarm("MsoConfigurationError", MsoAlarmLogger.CRITICAL,\r
+                                       Messages.errors.get(ErrorNumbers.NO_COMMUNICATION_TO_BPEL));\r
+                       msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "",\r
+                                       MsoLogger.ErrorCode.AvailabilityError, "Exception while communicate with BPMN engine");\r
+                       msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError,\r
+                                       "Exception while communicate with BPMN engine");\r
+                       msoLogger.debug("End of the transaction, the final response is: " + resp.getEntity().toString());\r
+                       return resp;\r
+               }\r
+\r
+               if (response == null) {\r
+                       Response resp = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY,\r
+                                       MsoException.ServiceException, "bpelResponse is null", ErrorNumbers.SVC_NO_SERVER_RESOURCES, null);\r
+                       msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "",\r
+                                       MsoLogger.ErrorCode.BusinessProcesssError, "Null response from BPEL");\r
+                       msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.InternalError,\r
+                                       "Null response from BPMN");\r
+                       msoLogger.debug(END_OF_THE_TRANSACTION + resp.getEntity().toString());\r
+                       return resp;\r
+               }\r
+\r
+               ResponseHandler respHandler = new ResponseHandler(response, requestClient.getType());\r
+               int bpelStatus = respHandler.getStatus();\r
+               // String responseBody = respHandler.getResponseBody();\r
+               // CompareModelsResult modelDiffResponse = new CompareModelsResult();\r
+\r
+               return beplStatusUpdate(requestId, startTime, msoRequest, requestClient, respHandler, bpelStatus, action,\r
+                               instanceIdMap);\r
+       }\r
 \r
        private Response getE2EServiceInstances(String serviceId, String operationId) {\r
                RequestsDatabase requestsDB = RequestsDatabase.getInstance();\r
@@ -814,8 +934,7 @@ public class E2EServiceInstances {
                // BPMN accepted the request, the request is in progress\r
                if (bpelStatus == HttpStatus.SC_ACCEPTED) {\r
                        String camundaJSONResponseBody = respHandler.getResponseBody();\r
-                       msoLogger\r
-                                       .debug("Received from Camunda: " + camundaJSONResponseBody);\r
+                       msoLogger.debug("Received from Camunda: " + camundaJSONResponseBody);\r
 \r
                        // currently only for delete case we update the status here\r
                        if (action == Action.deleteInstance) {\r
@@ -834,6 +953,7 @@ public class E2EServiceInstances {
                                                                        + bpelStatus);\r
                                }\r
                        }\r
+                       \r
                        msoLogger.recordAuditEvent(startTime,\r
                                        MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,\r
                                        "BPMN accepted the request, the request is in progress");\r