fix for delete e2e service 81/20181/1
authorseshukm <seshu.kumar.m@huawei.com>
Mon, 23 Oct 2017 16:01:34 +0000 (21:31 +0530)
committerseshukm <seshu.kumar.m@huawei.com>
Mon, 23 Oct 2017 16:01:34 +0000 (21:31 +0530)
IssueId: SO-258

Change-Id: Ib038f1a40d3a1a8604b3ba1da6b7bc7de33a074e
Signed-off-by: seshukm <seshu.kumar.m@huawei.com>
bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DeleteCustomE2EServiceInstance.groovy
mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstances.java
mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/e2eserviceinstancebeans/E2EServiceInstanceDeleteRequest.java [new file with mode: 0644]
mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstancesTest.java

index 7a047d4..3cd2b28 100644 (file)
@@ -82,72 +82,22 @@ public class DeleteCustomE2EServiceInstance extends AbstractServiceTaskProcessor
                                exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)\r
                        }\r
                \r
-                       //String xmlRequestDetails = vidUtils.getJsonRequestDetailstoXml(siRequest)\r
-                       //execution.setVariable("requestDetails", xmlRequestDetails)\r
-                       \r
-                       //modelInfo\r
-                       String serviceModelInfo = jsonUtil.getJsonValue(siRequest, "requestDetails.modelInfo")\r
-                       if (isBlank(serviceModelInfo)) {\r
-                               msg = "Input serviceModelInfo is null"\r
-                               utils.log("DEBUG", msg, isDebugEnabled)\r
-                       } else\r
-                       {\r
-                               execution.setVariable("serviceModelInfo", serviceModelInfo)\r
-                               //utils.log("DEBUG", "modelInfo" + serviceModelInfo,  isDebugEnabled)\r
-                       }\r
-                       \r
-                       //requestInfo\r
-                       String productFamilyId = jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.productFamilyId")\r
-                       if (isBlank(productFamilyId))\r
-                       {\r
-                               msg = "Input productFamilyId is null"\r
+                        \r
+                       String serviceType = execution.getVariable("serviceType")\r
+                       if (isBlank(serviceType)) {\r
+                               msg = "Input serviceType' is null"\r
                                utils.log("DEBUG", msg, isDebugEnabled)\r
-                               //exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)\r
                        } else {\r
-                               execution.setVariable("productFamilyId", productFamilyId)\r
+                               execution.setVariable("serviceType", serviceType)\r
                        }\r
-                       String source = jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.source")\r
-                       execution.setVariable("source", source)\r
-                       \r
                        //subscriberInfo\r
-                       String globalSubscriberId = jsonUtil.getJsonValue(siRequest, "requestDetails.subscriberInfo.globalSubscriberId")\r
+                       String globalSubscriberId = jsonUtil.getJsonValue(siRequest, "globalSubscriberId")\r
                        if (isBlank(globalSubscriberId)) {\r
                                msg = "Input globalSubscriberId' is null"\r
                                utils.log("DEBUG", msg, isDebugEnabled)\r
                        } else {\r
                                execution.setVariable("globalSubscriberId", globalSubscriberId)\r
                        }\r
-                       \r
-                       //requestParameters\r
-                       String subscriptionServiceType = jsonUtil.getJsonValue(siRequest, "requestDetails.requestParameters.subscriptionServiceType")\r
-                       if (isBlank(subscriptionServiceType)) {\r
-                               msg = "Input subscriptionServiceType is null"\r
-                               utils.log("DEBUG", msg, isDebugEnabled)\r
-                               //exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)\r
-                       } else {\r
-                               execution.setVariable("subscriptionServiceType", subscriptionServiceType)\r
-                       }\r
-                       \r
-                       /*\r
-                        * Extracting User Parameters from incoming Request and converting into a Map\r
-                        */\r
-                       def jsonSlurper = new JsonSlurper()\r
-                       def jsonOutput = new JsonOutput()\r
-\r
-                       Map reqMap = jsonSlurper.parseText(siRequest)\r
-\r
-                       //InputParams\r
-                       def userParams = reqMap.requestDetails?.requestParameters?.userParams\r
-\r
-                       Map<String, String> inputMap = [:]\r
-                       if (userParams) {\r
-                               userParams.each {\r
-                                       userParam -> inputMap.put(userParam.name, userParam.value)\r
-                               }\r
-                       }\r
-                       \r
-                       utils.log("DEBUG", "User Input Parameters map: " + userParams.toString(), isDebugEnabled)\r
-                       execution.setVariable("serviceInputParams", inputMap)\r
 \r
                } catch (BpmnError e) {\r
                        throw e;\r
@@ -164,11 +114,10 @@ public class DeleteCustomE2EServiceInstance extends AbstractServiceTaskProcessor
                utils.log("DEBUG", " *** sendSyncResponse  *** ", isDebugEnabled)\r
 \r
                try {\r
-                       String requestId = execution.getVariable("msoRequestId")\r
-                       String serviceInstanceId = execution.getVariable("serviceInstanceId")\r
-\r
+                       String operationId = execution.getVariable("operationId")\r
+                       \r
                        // RESTResponse (for API Handler (APIH) Reply Task)\r
-                       String syncResponse = """{"requestReferences":{"instanceId":"${serviceInstanceId}","requestId":"${requestId}"}}""".trim()\r
+                       String syncResponse = """{"operationId":"${operationId}"}""".trim()\r
                        utils.log("DEBUG", " sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse, isDebugEnabled)\r
                        sendWorkflowResponse(execution, 202, syncResponse)\r
 \r
index 2f44522..2d1d572 100644 (file)
@@ -45,6 +45,7 @@ import org.openecomp.mso.apihandler.common.ErrorNumbers;
 import org.openecomp.mso.apihandler.common.RequestClient;
 import org.openecomp.mso.apihandler.common.RequestClientFactory;
 import org.openecomp.mso.apihandler.common.ResponseHandler;
+import org.openecomp.mso.apihandlerinfra.e2eserviceinstancebeans.E2EServiceInstanceDeleteRequest;
 import org.openecomp.mso.apihandlerinfra.e2eserviceinstancebeans.E2EServiceInstanceRequest;
 import org.openecomp.mso.apihandlerinfra.e2eserviceinstancebeans.E2EUserParam;
 import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.ModelInfo;
@@ -112,7 +113,130 @@ public class E2EServiceInstances {
 
                instanceIdMap.put("serviceId", serviceId);
 
-               return processE2EserviceInstances(request, Action.deleteInstance, null, version);
+               return deleteE2EserviceInstances(request, Action.deleteInstance, instanceIdMap, version);
+       }
+
+       private Response deleteE2EserviceInstances(String requestJSON, Action action,
+                       HashMap<String, String> instanceIdMap, String version) {
+               
+               String requestId = UUIDChecker.generateUUID(msoLogger);
+               long startTime = System.currentTimeMillis();
+               msoLogger.debug("requestId is: " + requestId);
+               E2EServiceInstanceDeleteRequest e2eDelReq = null;
+
+               MsoRequest msoRequest = new MsoRequest(requestId);
+               
+               ObjectMapper mapper = new ObjectMapper();
+               try {
+                       e2eDelReq = mapper.readValue(requestJSON, E2EServiceInstanceDeleteRequest.class);
+
+               } catch (Exception e) {
+
+                       msoLogger.debug("Mapping of request to JSON object failed : ", e);
+                       Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST,
+                                       MsoException.ServiceException, "Mapping of request to JSON object failed.  " + e.getMessage(),
+                                       ErrorNumbers.SVC_BAD_PARAMETER, null);
+                       msoLogger.error(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "",
+                                       MsoLogger.ErrorCode.SchemaError, requestJSON, e);
+                       msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError,
+                                       "Mapping of request to JSON object failed");
+                       msoLogger.debug("End of the transaction, the final response is: " + (String) response.getEntity());
+                       createOperationStatusRecordForError(action, requestId);
+                       return response;
+               }
+               
+               CatalogDatabase db = null;
+               RecipeLookupResult recipeLookupResult = null;
+               try {
+                       db = CatalogDatabase.getInstance();
+                       recipeLookupResult = getServiceInstanceOrchestrationURI(db, action);
+               } catch (Exception e) {
+                       msoLogger.error(MessageEnum.APIH_DB_ACCESS_EXC, MSO_PROP_APIHANDLER_INFRA, "", "",
+                                       MsoLogger.ErrorCode.AvailabilityError, "Exception while communciate with Catalog DB", e);
+                       msoRequest.setStatus(org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);
+                       Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND,
+                                       MsoException.ServiceException, "No communication to catalog DB " + e.getMessage(),
+                                       ErrorNumbers.SVC_NO_SERVER_RESOURCES, null);
+                       alarmLogger.sendAlarm("MsoDatabaseAccessError", MsoAlarmLogger.CRITICAL,
+                                       Messages.errors.get(ErrorNumbers.NO_COMMUNICATION_TO_CATALOG_DB));
+                       msoRequest.createRequestRecord(Status.FAILED, action);
+                       msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError,
+                                       "Exception while communciate with DB");
+                       msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity());
+                       return response;
+               } finally {
+                       closeCatalogDB(db);
+               }
+               if (recipeLookupResult == null) {
+                       msoLogger.error(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, MSO_PROP_APIHANDLER_INFRA, "", "",
+                                       MsoLogger.ErrorCode.DataError, "No recipe found in DB");
+                       msoRequest.setStatus(org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);
+                       Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND,
+                                       MsoException.ServiceException, "Recipe does not exist in catalog DB",
+                                       ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null);
+                       msoRequest.createRequestRecord(Status.FAILED, action);
+                       msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound,
+                                       "No recipe found in DB");
+                       msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity());
+                       createOperationStatusRecordForError(action, requestId);
+                       return response;
+               }
+
+               
+               RequestClient requestClient = null;
+               HttpResponse response = null;
+
+               long subStartTime = System.currentTimeMillis();
+               //String sirRequestJson = mapReqJsonToSvcInstReq(e2eSir, requestJSON);
+
+               try {
+                       requestClient = RequestClientFactory.getRequestClient(recipeLookupResult.getOrchestrationURI(),
+                                       MsoPropertiesUtils.loadMsoProperties());
+
+                       // Capture audit event
+                       msoLogger.debug("MSO API Handler Posting call to BPEL engine for url: " + requestClient.getUrl());
+            String serviceId = instanceIdMap.get("serviceId");
+            String serviceInstanceType = e2eDelReq.getServiceType();
+                       response = requestClient.post(requestId, false, recipeLookupResult.getRecipeTimeout(), action.name(),
+                                       serviceId, null, null, null, null, serviceInstanceType, null, null, null, requestJSON);
+
+                       msoLogger.recordMetricEvent(subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
+                                       "Successfully received response from BPMN engine", "BPMN", recipeLookupResult.getOrchestrationURI(),
+                                       null);
+               } catch (Exception e) {
+                       msoLogger.recordMetricEvent(subStartTime, MsoLogger.StatusCode.ERROR,
+                                       MsoLogger.ResponseCode.CommunicationError, "Exception while communicate with BPMN engine", "BPMN",
+                                       recipeLookupResult.getOrchestrationURI(), null);
+                       Response resp = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY,
+                                       MsoException.ServiceException, "Failed calling bpmn " + e.getMessage(),
+                                       ErrorNumbers.SVC_NO_SERVER_RESOURCES, null);
+                       alarmLogger.sendAlarm("MsoConfigurationError", MsoAlarmLogger.CRITICAL,
+                                       Messages.errors.get(ErrorNumbers.NO_COMMUNICATION_TO_BPEL));
+                       msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "",
+                                       MsoLogger.ErrorCode.AvailabilityError, "Exception while communicate with BPMN engine");
+                       msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError,
+                                       "Exception while communicate with BPMN engine");
+                       msoLogger.debug("End of the transaction, the final response is: " + (String) resp.getEntity());
+                       createOperationStatusRecordForError(action, requestId);
+                       return resp;
+               }
+
+               if (response == null) {
+                       Response resp = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY,
+                                       MsoException.ServiceException, "bpelResponse is null", ErrorNumbers.SVC_NO_SERVER_RESOURCES, null);
+                       msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "",
+                                       MsoLogger.ErrorCode.BusinessProcesssError, "Null response from BPEL");
+                       msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.InternalError,
+                                       "Null response from BPMN");
+                       msoLogger.debug(END_OF_THE_TRANSACTION + (String) resp.getEntity());
+                       createOperationStatusRecordForError(action, requestId);
+                       return resp;
+               }
+
+               ResponseHandler respHandler = new ResponseHandler(response, requestClient.getType());
+               int bpelStatus = respHandler.getStatus();
+
+               return beplStatusUpdate(requestId, startTime, msoRequest, requestClient, respHandler, bpelStatus);
        }
 
        private Response processE2EserviceInstances(String requestJSON, Action action,
@@ -210,10 +334,11 @@ public class E2EServiceInstances {
                        msoLogger.warn(MessageEnum.APIH_DUPLICATE_FOUND, dupMessage, "", "", MsoLogger.ErrorCode.SchemaError,
                                        "Duplicate request - Subscriber already has a request for this service");
                        
-                       createOperationStatusRecordForError(action, requestId);
+                       
                        msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict,
                                        dupMessage);
                        msoLogger.debug("End of the transaction, the final response is: " + (String) response.getEntity());
+                       createOperationStatusRecordForError(action, requestId);
                        return response;
                }
                
@@ -231,10 +356,11 @@ public class E2EServiceInstances {
                                        ErrorNumbers.SVC_NO_SERVER_RESOURCES, null);
                        alarmLogger.sendAlarm("MsoDatabaseAccessError", MsoAlarmLogger.CRITICAL,
                                        Messages.errors.get(ErrorNumbers.NO_COMMUNICATION_TO_CATALOG_DB));
-                       createOperationStatusRecordForError(action, requestId);
+                       
                        msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError,
                                        "Exception while communciate with DB");
                        msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity());
+                       createOperationStatusRecordForError(action, requestId);
                        return response;
                } finally {
                        closeCatalogDB(db);
@@ -247,11 +373,11 @@ public class E2EServiceInstances {
                        Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND,
                                        MsoException.ServiceException, "Recipe does not exist in catalog DB",
                                        ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null);
-                       createOperationStatusRecordForError(action, requestId);
+               
                        msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound,
                                        "No recipe found in DB");
                        msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity());
-
+                       createOperationStatusRecordForError(action, requestId);
                        return response;
                }
 
@@ -302,12 +428,12 @@ public class E2EServiceInstances {
                                        ErrorNumbers.SVC_NO_SERVER_RESOURCES, null);
                        alarmLogger.sendAlarm("MsoConfigurationError", MsoAlarmLogger.CRITICAL,
                                        Messages.errors.get(ErrorNumbers.NO_COMMUNICATION_TO_BPEL));
-                       createOperationStatusRecordForError(action, requestId);
                        msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "",
                                        MsoLogger.ErrorCode.AvailabilityError, "Exception while communicate with BPMN engine");
                        msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError,
                                        "Exception while communicate with BPMN engine");
                        msoLogger.debug("End of the transaction, the final response is: " + (String) resp.getEntity());
+                       createOperationStatusRecordForError(action, requestId);
                        return resp;
                }
 
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/e2eserviceinstancebeans/E2EServiceInstanceDeleteRequest.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/e2eserviceinstancebeans/E2EServiceInstanceDeleteRequest.java
new file mode 100644 (file)
index 0000000..157ee72
--- /dev/null
@@ -0,0 +1,46 @@
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * ONAP - SO\r
+ * ================================================================================\r
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
+package org.openecomp.mso.apihandlerinfra.e2eserviceinstancebeans;\r
+\r
+\r
+public class E2EServiceInstanceDeleteRequest {\r
+\r
+       private String globalSubscriberId;\r
+       \r
+       private String serviceType;\r
+\r
+       public String getGlobalSubscriberId() {\r
+               return globalSubscriberId;\r
+       }\r
+\r
+       public void setGlobalSubscriberId(String globalSubscriberId) {\r
+               this.globalSubscriberId = globalSubscriberId;\r
+       }\r
+\r
+       public String getServiceType() {\r
+               return serviceType;\r
+       }\r
+\r
+       public void setServiceType(String serviceType) {\r
+               this.serviceType = serviceType;\r
+       }\r
+       \r
+}\r
index 0e966da..eef597e 100644 (file)
@@ -469,7 +469,7 @@ public class E2EServiceInstancesTest {
        @Test\r
        public void deleteE2EServiceInstanceTestNormal(){\r
                E2EServiceInstances instance = new E2EServiceInstances();\r
-               String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"templateId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"parameters\":{\"globalSubscriberId\":\"123457\", \"subscriberName\":\"Customer1\",\"serviceType\":\"voLTE\",\"templateName\":\"voLTE Service:1.0\",\"resources\":[{\"resourceName\":\"MOG\",\"resourceDefId\":\"MOG\",\"resourceId\":\"MOG\",\"nsParameters\":{\"locationConstraints\":[{\"vnfProfileId\":\"zte-vBAS-1.0\",\"locationConstraints\":{\"vimId\":\"4050083f-465f-4838-af1e-47a545222ad0\"}},{\"vnfProfileId\":\"zte-vMME-1.0\",\"locationConstraints\":{\"vimId\":\"4050083f-465f-4838-af1e-47a545222ad0\"}}],\"additionalParamForNs\":{}}}]}}}";\r
+               String request = "{\"globalSubscriberId\":\"299392392\",\"serviceType\":\"VoLTE\"}";\r
                Response resp = instance.deleteE2EServiceInstance(request, "v3", "12345678");\r
                String respStr = resp.getEntity().toString();\r
                assertTrue(respStr.indexOf("SVC1000") != -1);\r