Add sync response task 57/12957/1
authorc00149107 <chenchuanyu@huawei.com>
Mon, 18 Sep 2017 03:45:40 +0000 (11:45 +0800)
committerc00149107 <chenchuanyu@huawei.com>
Mon, 18 Sep 2017 03:45:40 +0000 (11:45 +0800)
Add sync response task for e2e service flow

Change-Id: I3b17e0103fb3e7cb4ba41d076bc6014acc1d295c
Issue-ID:SO-57
Signed-off-by: c00149107 <chenchuanyu@huawei.com>
bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/CreateGenericE2EServiceInstance.groovy

index ab96c0b..3302210 100644 (file)
@@ -50,6 +50,13 @@ public class CreateGenericE2EServiceInstance extends AbstractServiceTaskProcesso
 \r
     VidUtils vidUtils = new VidUtils()\r
 \r
+    /**\r
+     * Pre Process the BPMN Flow Request\r
+     * Inclouds:\r
+     * Deal with the parameters\r
+     * generate the service instance id\r
+     * generate the operation id\r
+     */\r
     public void preProcessRequest (Execution execution) {\r
           def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
        String msg = ""\r
@@ -70,10 +77,19 @@ public class CreateGenericE2EServiceInstance extends AbstractServiceTaskProcesso
            utils.log("DEBUG", "Generated new Service Instance:" + serviceInstanceId, isDebugEnabled)\r
            serviceInstanceId = UriUtils.encode(serviceInstanceId,"UTF-8")\r
            execution.setVariable("serviceInstanceId", serviceInstanceId)\r
-\r
+           \r
+           String operationId = execution.getVariable("operationId")\r
+           if (isBlank(operationId)) {\r
+               operationId = UUID.randomUUID().toString()\r
+           }\r
+           utils.log("DEBUG", "Generated new Service Instance Operation:" + operationId, isDebugEnabled)\r
+           serviceInstanceId = UriUtils.encode(operationId,"UTF-8")\r
+           execution.setVariable("operationId", operationId)\r
            //subscriberInfo, TBD , there is no globalSubscriberId in R1 for E2E Service.\r
            //requestInfo TBD , there is no requestDetails for R1 E2E service\r
 \r
+           //TBD need to insert operationInfo to RequestDb\r
+           \r
            //set service Instance Name\r
            execution.setVariable("serviceInstanceName", jsonUtil.getJsonValue(siRequest, "service.name"))\r
            execution.setVariable("serviceDescription", jsonUtil.getJsonValue(siRequest, "service.description"))\r
@@ -101,7 +117,30 @@ public class CreateGenericE2EServiceInstance extends AbstractServiceTaskProcesso
        utils.log("DEBUG"," ***** Exit preProcessRequest *****",  isDebugEnabled)\r
        }\r
 \r
+    /**\r
+     * send the sync response\r
+     * the response incloudes the instance id and the operation id\r
+     */\r
     public void sendSyncResponse(Execution execution) {\r
+        def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+        utils.log("DEBUG", " *** sendSyncResponse *** ", isDebugEnabled)\r
+\r
+        try {\r
+            String requestId = execution.getVariable("msoRequestId")\r
+            String serviceInstanceId = execution.getVariable("serviceInstanceId")\r
+            String operationId = execution.getVariable("operationId")\r
+            // RESTResponse for API Handler (APIH) Reply Task\r
+            String createServiceRestResponse = """{"service":{"serviceId":"${serviceInstanceId}","operationId":"${operationId}"}}""".trim()\r
+            utils.log("DEBUG", " sendSyncResponse to APIH:" + "\n" + createServiceRestResponse, isDebugEnabled)\r
+            sendWorkflowResponse(execution, 202, createServiceRestResponse)\r
+            execution.setVariable("sentSyncResponse", true)\r
+\r
+        } catch (Exception ex) {\r
+            String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()\r
+            utils.log("DEBUG", msg, isDebugEnabled)\r
+            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
+        }\r
+        utils.log("DEBUG"," ***** Exit sendSyncResopnse *****",  isDebugEnabled)\r
     }\r
 \r
     public void preCreateRequest(Execution execution) {\r