From 02caddbf25efe5b4a917cdeb13a3bb25976ce2a1 Mon Sep 17 00:00:00 2001 From: Yulian Han Date: Fri, 20 Apr 2018 16:14:12 +0800 Subject: updateE2EServiceInstance error staus conflict Change-Id: Idaa55084f5ecb0dd3636c232cebc14fa5f064305 Issue-ID: SO-578 Signed-off-by: Yulian Han --- .../mso/apihandlerinfra/E2EServiceInstances.java | 41 ++++++++++------------ .../apihandlerinfra/E2EServiceInstancesTest.java | 2 +- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstances.java index 8d3a64340d..cb3e8e6a82 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstances.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstances.java @@ -537,6 +537,7 @@ public class E2EServiceInstances { long startTime = System.currentTimeMillis(); msoLogger.debug("requestId is: " + requestId); E2EServiceInstanceRequest e2eSir = null; + String serviceId = instanceIdMap.get("serviceId"); MsoRequest msoRequest = new MsoRequest(requestId); ObjectMapper mapper = new ObjectMapper(); @@ -545,8 +546,6 @@ public class E2EServiceInstances { } catch (Exception e) { - this.createOperationStatusRecordForError(action, requestId); - 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(), @@ -570,7 +569,6 @@ public class E2EServiceInstances { ErrorNumbers.SVC_BAD_PARAMETER, null); if (msoRequest.getRequestId() != null) { msoLogger.debug("Logging failed message to the database"); - this.createOperationStatusRecordForError(action, requestId); } msoLogger.error(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "", MsoLogger.ErrorCode.SchemaError, requestJSON, e); @@ -581,10 +579,10 @@ public class E2EServiceInstances { } //check for the current operation status - Response resp = checkE2ESvcInstStatus(action, requestId, startTime, msoRequest); - if(resp != null && resp.getStatus() != 200) { - return resp; - } +// Response resp = checkE2ESvcInstStatus(action, serviceId, startTime, msoRequest); +// if(resp != null && resp.getStatus() != 200) { +// return resp; +// } CatalogDatabase db = null; RecipeLookupResult recipeLookupResult = null; @@ -604,7 +602,7 @@ public class E2EServiceInstances { 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); @@ -621,13 +619,12 @@ public class E2EServiceInstances { 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; } String serviceInstanceType = e2eSir.getService().getServiceType(); - String serviceId = instanceIdMap.get("serviceId"); RequestClient requestClient = null; HttpResponse response = null; @@ -663,7 +660,7 @@ public class E2EServiceInstances { 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) getBPMNResp.getEntity()); - createOperationStatusRecordForError(action, requestId); + return getBPMNResp; } @@ -675,23 +672,23 @@ public class E2EServiceInstances { msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.InternalError, "Null response from BPMN"); msoLogger.debug(END_OF_THE_TRANSACTION + (String) getBPMNResp.getEntity()); - this.createOperationStatusRecordForError(action, requestId); + return getBPMNResp; } ResponseHandler respHandler = new ResponseHandler(response, requestClient.getType()); int bpelStatus = respHandler.getStatus(); - return beplStatusUpdate(requestId, startTime, msoRequest, requestClient, respHandler, bpelStatus, action, instanceIdMap); + return beplStatusUpdate(serviceId, startTime, msoRequest, requestClient, respHandler, bpelStatus, action, instanceIdMap); } - private Response checkE2ESvcInstStatus(Action action, String requestId, long startTime, MsoRequest msoRequest) { + private Response checkE2ESvcInstStatus(Action action, String serviceId, long startTime, MsoRequest msoRequest) { OperationStatus curStatus = null; // String instanceName = sir.getRequestDetails().getRequestInfo().getInstanceName(); String requestScope = sir.getRequestDetails().getModelInfo().getModelType().name(); try { - if (!(requestId == null && "service".equals(requestScope) && (action == Action.updateInstance))) { - curStatus = chkSvcInstOperStatusbySvcId(requestId); + if (!(serviceId == null && "service".equals(requestScope) && (action == Action.updateInstance))) { + curStatus = chkSvcInstOperStatusbySvcId(serviceId); } } catch (Exception e) { msoLogger.error(MessageEnum.APIH_DUPLICATE_CHECK_EXC, MSO_PROP_APIHANDLER_INFRA, "", "", @@ -707,7 +704,7 @@ public class E2EServiceInstances { } if (curStatus != null && curStatus.getResult() != null && curStatus.getResult().equalsIgnoreCase("processing")) { - String chkMessage = "Error: Locked instance - This " + requestScope + " (" + requestId + ") " + String chkMessage = "Error: Locked instance - This " + requestScope + " (" + serviceId + ") " + "now being worked with a status of " + curStatus.getResult() + ". The latest workflow of instance must be finished or cleaned up."; @@ -719,8 +716,6 @@ public class E2EServiceInstances { msoLogger.debug("End of the transaction, the final response is: " + (String) response.getEntity()); - createOperationStatusRecordForError(action, requestId); - return response; } @@ -1113,7 +1108,7 @@ public class E2EServiceInstances { } } - private Response beplStatusUpdate(String requestId, long startTime, + private Response beplStatusUpdate(String serviceId, long startTime, MsoRequest msoRequest, RequestClient requestClient, ResponseHandler respHandler, int bpelStatus, Action action, HashMap instanceIdMap) { @@ -1129,7 +1124,7 @@ public class E2EServiceInstances { DelE2ESvcResp jo = mapper.readValue( camundaJSONResponseBody, DelE2ESvcResp.class); String operationId = jo.getOperationId(); - this.createOperationStatusRecord("DELETE", requestId, + this.createOperationStatusRecord("DELETE", serviceId, operationId); } catch (Exception ex) { msoLogger.error(MessageEnum.APIH_BPEL_RESPONSE_ERROR, @@ -1359,7 +1354,7 @@ public class E2EServiceInstances { } private void createOperationStatusRecordForError(Action action, - String requestId) throws MsoDatabaseException { + String serviceId) throws MsoDatabaseException { AbstractSessionFactoryManager requestsDbSessionFactoryManager = new RequestsDbSessionFactoryManager(); @@ -1377,7 +1372,7 @@ public class E2EServiceInstances { os.setProgress("100"); os.setReason(""); os.setResult("error"); - os.setServiceId(requestId); + os.setServiceId(serviceId); os.setUserId(""); Timestamp startTimeStamp = new Timestamp(System.currentTimeMillis()); Timestamp endTimeStamp = new Timestamp(System.currentTimeMillis()); diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstancesTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstancesTest.java index d8a6282a8a..45fc89bfc2 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstancesTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstancesTest.java @@ -1001,7 +1001,7 @@ public class E2EServiceInstancesTest { String request = jsonBody; Response resp = instance.updateE2EServiceInstance(request, "v3", "12345"); String respStr = resp.getEntity().toString(); - assertTrue(respStr.contains("SVC2000")); + assertTrue(!respStr.contains("SVC2000")); } @Test -- cgit 1.2.3-korg