add update action for e2e svcinst 53/34253/1
authorYulian Han <elaine.hanyulian@huawei.com>
Tue, 6 Mar 2018 07:46:24 +0000 (15:46 +0800)
committerYulian Han <elaine.hanyulian@huawei.com>
Tue, 6 Mar 2018 10:19:36 +0000 (18:19 +0800)
Issue-ID: SO-419
Change-Id: Ibef5e8e617dcfb1d4f9b4087f20d6058a47bd741
Signed-off-by: Yulian Han <elaine.hanyulian@huawei.com>
mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstances.java

index 0914516..c51c61e 100644 (file)
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.mso.apihandlerinfra;
-
-import java.io.IOException;
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-
-import org.apache.http.HttpResponse;
-import org.apache.http.HttpStatus;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.hibernate.Session;
-import org.json.JSONObject;
-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.Messages;
-import org.openecomp.mso.apihandlerinfra.MsoException;
-import org.openecomp.mso.apihandlerinfra.MsoRequest;
-import org.openecomp.mso.apihandlerinfra.e2eserviceinstancebeans.DelE2ESvcResp;
-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.e2eserviceinstancebeans.GetE2EServiceInstanceResponse;
-import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.ModelInfo;
-import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.RequestDetails;
-import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.RequestInfo;
-import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.RequestParameters;
-import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.ServiceInstancesRequest;
-import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.SubscriberInfo;
-import org.openecomp.mso.db.AbstractSessionFactoryManager;
-import org.openecomp.mso.db.catalog.CatalogDatabase;
-import org.openecomp.mso.db.catalog.beans.Service;
-import org.openecomp.mso.db.catalog.beans.ServiceRecipe;
-import org.openecomp.mso.logger.MessageEnum;
-import org.openecomp.mso.logger.MsoAlarmLogger;
-import org.openecomp.mso.logger.MsoLogger;
-import org.openecomp.mso.properties.MsoDatabaseException;
-import org.openecomp.mso.requestsdb.OperationStatus;
-import org.openecomp.mso.requestsdb.RequestsDatabase;
-import org.openecomp.mso.requestsdb.RequestsDbSessionFactoryManager;
-import org.openecomp.mso.utils.UUIDChecker;
-
-import com.wordnik.swagger.annotations.Api;
-import com.wordnik.swagger.annotations.ApiOperation;
-
-@Path("/e2eServiceInstances")
-@Api(value = "/e2eServiceInstances", description = "API Requests for E2E Service Instances")
-public class E2EServiceInstances {
-
-       private HashMap<String, String> instanceIdMap = new HashMap<>();
-       private static MsoLogger msoLogger = MsoLogger
-                       .getMsoLogger(MsoLogger.Catalog.APIH);
-       private static MsoAlarmLogger alarmLogger = new MsoAlarmLogger();
-       public static final String MSO_PROP_APIHANDLER_INFRA = "MSO_PROP_APIHANDLER_INFRA";
-       private ServiceInstancesRequest sir = null;
-
-       public static final String END_OF_THE_TRANSACTION = "End of the transaction, the final response is: ";
-       public static final String EXCEPTION_CREATING_DB_RECORD = "Exception while creating record in DB";
-       public static final String EXCEPTION_COMMUNICATE_BPMN_ENGINE = "Exception while communicate with BPMN engine";
-
-       /**
-        * POST Requests for E2E Service create Instance on a version provided
-        */
-
-       @POST
-       @Path("/{version:[vV][3-5]}")
-       @Consumes(MediaType.APPLICATION_JSON)
-       @Produces(MediaType.APPLICATION_JSON)
-       @ApiOperation(value = "Create a E2E Service Instance on a version provided", response = Response.class)
-       public Response createE2EServiceInstance(String request,
-                       @PathParam("version") String version) {
-
-               return processE2EserviceInstances(request, Action.createInstance, null,
-                               version);
-       }
-
-       /**
-        * DELETE Requests for E2E Service delete Instance on a specified version
-        * and serviceId
-        */
-
-       @DELETE
-       @Path("/{version:[vV][3-5]}/{serviceId}")
-       @Consumes(MediaType.APPLICATION_JSON)
-       @Produces(MediaType.APPLICATION_JSON)
-       @ApiOperation(value = "Delete E2E Service Instance on a specified version and serviceId", response = Response.class)
-       public Response deleteE2EServiceInstance(String request,
-                       @PathParam("version") String version,
-                       @PathParam("serviceId") String serviceId) {
-
-               instanceIdMap.put("serviceId", serviceId);
-
-               return deleteE2EserviceInstances(request, Action.deleteInstance,
-                               instanceIdMap, version);
-       }
-
-       @GET
-       @Path("/{version:[vV][3-5]}/{serviceId}/operations/{operationId}")
-       @ApiOperation(value = "Find e2eServiceInstances Requests for a given serviceId and operationId", response = Response.class)
-       @Produces(MediaType.APPLICATION_JSON)
-       public Response getE2EServiceInstances(
-                       @PathParam("serviceId") String serviceId,
-                       @PathParam("version") String version,
-                       @PathParam("operationId") String operationId) {
-               return getE2EServiceInstances(serviceId, operationId);
-       }
-
-       private Response getE2EServiceInstances(String serviceId, String operationId) {
-               RequestsDatabase requestsDB = RequestsDatabase.getInstance();
-
-               GetE2EServiceInstanceResponse e2eServiceResponse = new GetE2EServiceInstanceResponse();
-
-               MsoRequest msoRequest = new MsoRequest(serviceId);
-
-               long startTime = System.currentTimeMillis();
-
-               OperationStatus operationStatus = null;
-
-               try {
-                       operationStatus = requestsDB.getOperationStatus(serviceId,
-                                       operationId);
-
-               } catch (Exception e) {
-                       msoLogger
-                                       .error(MessageEnum.APIH_DB_ACCESS_EXC,
-                                                       MSO_PROP_APIHANDLER_INFRA,
-                                                       "",
-                                                       "",
-                                                       MsoLogger.ErrorCode.AvailabilityError,
-                                                       "Exception while communciate with Request DB - Infra Request Lookup",
-                                                       e);
-                       msoRequest
-                                       .setStatus(org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);
-                       Response response = msoRequest.buildServiceErrorResponse(
-                                       HttpStatus.SC_NOT_FOUND, MsoException.ServiceException,
-                                       e.getMessage(),
-                                       ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB, null);
-                       alarmLogger.sendAlarm("MsoDatabaseAccessError",
-                                       MsoAlarmLogger.CRITICAL, Messages.errors
-                                                       .get(ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB));
-                       msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR,
-                                       MsoLogger.ResponseCode.DBAccessError,
-                                       "Exception while communciate with Request DB");
-                       msoLogger.debug("End of the transaction, the final response is: "
-                                       + (String) response.getEntity());
-                       return response;
-
-               }
-
-               if (operationStatus == null) {
-                       Response resp = msoRequest.buildServiceErrorResponse(
-                                       HttpStatus.SC_NO_CONTENT, MsoException.ServiceException,
-                                       "E2E serviceId " + serviceId + " is not found in DB",
-                                       ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, null);
-                       msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR,
-                                       MSO_PROP_APIHANDLER_INFRA, "", "",
-                                       MsoLogger.ErrorCode.BusinessProcesssError,
-                                       "Null response from RequestDB when searching by serviceId");
-                       msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR,
-                                       MsoLogger.ResponseCode.DataNotFound,
-                                       "Null response from RequestDB when searching by serviceId");
-                       msoLogger.debug("End of the transaction, the final response is: "
-                                       + (String) resp.getEntity());
-                       return resp;
-
-               }
-
-               e2eServiceResponse.setOperationStatus(operationStatus);
-
-               return Response.status(200).entity(e2eServiceResponse).build();
-       }
-
-       private Response deleteE2EserviceInstances(String requestJSON,
-                       Action action, HashMap<String, String> instanceIdMap, String version) {
-               // TODO should be a new one or the same service instance Id
-               String requestId = instanceIdMap.get("serviceId");
-               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();
-                       //TODO  Get the service template model version uuid from AAI.
-                       recipeLookupResult = getServiceInstanceOrchestrationURI(db, null, 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());
-
-                       JSONObject jjo = new JSONObject(requestJSON);
-                       jjo.put("operationId", UUIDChecker.generateUUID(msoLogger));
-
-                       String bpmnRequest = jjo.toString();
-
-                       // 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, bpmnRequest, recipeLookupResult.getRecipeParamXsd());
-
-                       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, action, instanceIdMap);
-       }
-
-       private Response processE2EserviceInstances(String requestJSON, Action action,
-                       HashMap<String, String> instanceIdMap, String version) {
-
-               String requestId = UUIDChecker.generateUUID(msoLogger);
-               long startTime = System.currentTimeMillis();
-               msoLogger.debug("requestId is: " + requestId);
-               E2EServiceInstanceRequest e2eSir = null;
-
-               MsoRequest msoRequest = new MsoRequest(requestId);
-               ObjectMapper mapper = new ObjectMapper();
-               try {
-                       e2eSir = mapper.readValue(requestJSON, E2EServiceInstanceRequest.class);
-
-               } catch (Exception e) {
-          //TODO update the service name
-          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(),
-                                       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());
-                       return response;
-               }
-
-               mapReqJsonToSvcInstReq(e2eSir, requestJSON);
-               sir.getRequestDetails().getRequestParameters().setaLaCarte(true);
-               try {
-                       msoRequest.parse(sir, instanceIdMap, action, version);
-               } catch (Exception e) {
-                       msoLogger.debug("Validation failed: ", e);
-                       Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST,
-                                       MsoException.ServiceException, "Error parsing request.  " + e.getMessage(),
-                                       ErrorNumbers.SVC_BAD_PARAMETER, null);
-                       if (msoRequest.getRequestId() != null) {
-                               msoLogger.debug("Logging failed message to the database");
-                               //TODO update the service name
-                         this.createOperationStatusRecordForError(action, requestId);
-                       }
-                       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,
-                                       "Validation of the input request failed");
-                       msoLogger.debug("End of the transaction, the final response is: " + (String) response.getEntity());
-                       return response;
-               }
-               
-               OperationStatus dup = null;
-               String instanceName = sir.getRequestDetails().getRequestInfo().getInstanceName();
-               String requestScope = sir.getRequestDetails().getModelInfo().getModelType().name();
-               try {
-                       if (!(instanceName == null && "service".equals(requestScope)
-                                       && (action == Action.createInstance || action == Action.activateInstance))) {
-                         //TODO : Need to check for the duplicate record from the operation status,
-                         //TODO : commenting this check for unblocking current testing for now...  induces dead code...
-                               dup = chkDuplicateServiceNameInOperStatus( instanceName);
-                       }
-               } catch (Exception e) {
-                       msoLogger.error(MessageEnum.APIH_DUPLICATE_CHECK_EXC, MSO_PROP_APIHANDLER_INFRA, "", "",
-                                       MsoLogger.ErrorCode.DataError, "Error during duplicate check ", e);
-
-                       Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR,
-                                       MsoException.ServiceException, e.getMessage(), ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, null);
-
-                       msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError,
-                                       "Error during duplicate check");
-                       msoLogger.debug("End of the transaction, the final response is: " + (String) response.getEntity());
-                       return response;
-               }
-
-               if (dup != null) {
-                       // Found the duplicate record. Return the appropriate error.
-                       String instance = null;
-                       if (instanceName != null) {
-                               instance = instanceName;
-                       } else {
-                               instance = instanceIdMap.get(requestScope + "InstanceId");
-                       }
-                       String dupMessage = "Error: Locked instance - This " + requestScope + " (" + instance + ") "
-                                       + "already has a request being worked with a status of " + dup.getProgress() + " (ServiceId - "
-                                       + dup.getServiceId() + "). The existing request must finish or be cleaned up before proceeding.";
-
-                       Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_CONFLICT,
-                                       MsoException.ServiceException, dupMessage, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, null);
-
-                       msoLogger.warn(MessageEnum.APIH_DUPLICATE_FOUND, dupMessage, "", "", MsoLogger.ErrorCode.SchemaError,
-                                       "Duplicate request - Subscriber already has a request for this service");
-                       
-                       
-                       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;
-               }
-               
-               CatalogDatabase db = null;
-               RecipeLookupResult recipeLookupResult = null;
-               try {
-                       db = CatalogDatabase.getInstance();
-                       recipeLookupResult = getServiceInstanceOrchestrationURI(db, e2eSir.getService().getTemplateId(), 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));
-                       
-                       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);
-               }
-
-               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);
-               
-                       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;
-               }
-//             try {
-//                     msoRequest.createRequestRecord(Status.PENDING, action);
-//                     //createOperationStatusRecord(action, requestId);
-//             } catch (Exception e) {
-//                     msoLogger.error(MessageEnum.APIH_DB_ACCESS_EXC_REASON, "Exception while creating record in DB", "", "",
-//                                     MsoLogger.ErrorCode.SchemaError, "Exception while creating record in DB", e);
-//                     msoRequest.setStatus(org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);
-//                     Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR,
-//                                     MsoException.ServiceException, "Exception while creating record in DB " + e.getMessage(),
-//                                     ErrorNumbers.SVC_BAD_PARAMETER, null);
-//                     msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError,
-//                                     "Exception while creating record in DB");
-//                     msoLogger.debug("End of the transaction, the final response is: " + (String) response.getEntity());
-//                     return response;
-//             }
-
-               String serviceInstanceType = e2eSir.getService().getParameters().getServiceType();
-
-               String serviceId = "";
-               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());
-
-                       response = requestClient.post(requestId, false, recipeLookupResult.getRecipeTimeout(), action.name(),
-                                       serviceId, null, null, null, null, serviceInstanceType, null, null, null, sirRequestJson, recipeLookupResult.getRecipeParamXsd());
-
-                       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());
-                       return resp;
-               }
-
-               ResponseHandler respHandler = new ResponseHandler(response, requestClient.getType());
-               int bpelStatus = respHandler.getStatus();
-
-               return beplStatusUpdate(requestId, startTime, msoRequest, requestClient, respHandler, bpelStatus, action, instanceIdMap);
-       }
-
-       private void closeCatalogDB(CatalogDatabase db) {
-               if (db != null) {
-                       db.close();
-               }
-       }
-
-       private Response beplStatusUpdate(String requestId, long startTime,
-                       MsoRequest msoRequest, RequestClient requestClient,
-                       ResponseHandler respHandler, int bpelStatus, Action action,
-                       HashMap<String, String> instanceIdMap) {
-               // BPMN accepted the request, the request is in progress
-               if (bpelStatus == HttpStatus.SC_ACCEPTED) {
-                       String camundaJSONResponseBody = respHandler.getResponseBody();
-                       msoLogger
-                                       .debug("Received from Camunda: " + camundaJSONResponseBody);
-
-                       // currently only for delete case we update the status here
-                       if (action == Action.deleteInstance) {
-                               ObjectMapper mapper = new ObjectMapper();
-                               try {
-                                       DelE2ESvcResp jo = mapper.readValue(
-                                                       camundaJSONResponseBody, DelE2ESvcResp.class);
-                                       String operationId = jo.getOperationId();
-                               this.createOperationStatusRecord("DELETE", requestId,
-                                                               operationId);
-                               } catch (Exception ex) {
-                                       msoLogger.error(MessageEnum.APIH_BPEL_RESPONSE_ERROR,
-                                                       requestClient.getUrl(), "", "",
-                                                       MsoLogger.ErrorCode.BusinessProcesssError,
-                                                       "Response from BPEL engine is failed with HTTP Status="
-                                                                       + bpelStatus);
-                               }
-                       }
-                       msoLogger.recordAuditEvent(startTime,
-                                       MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
-                                       "BPMN accepted the request, the request is in progress");
-                       msoLogger.debug(END_OF_THE_TRANSACTION + camundaJSONResponseBody);
-                       return Response.status(HttpStatus.SC_ACCEPTED)
-                                       .entity(camundaJSONResponseBody).build();
-               } else {
-                       List<String> variables = new ArrayList<>();
-                       variables.add(bpelStatus + "");
-                       String camundaJSONResponseBody = respHandler.getResponseBody();
-                       if (camundaJSONResponseBody != null
-                                       && !camundaJSONResponseBody.isEmpty()) {
-                               Response resp = msoRequest.buildServiceErrorResponse(
-                                               bpelStatus, MsoException.ServiceException,
-                                               "Request Failed due to BPEL error with HTTP Status= %1 "
-                                                               + '\n' + camundaJSONResponseBody,
-                                               ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, variables);
-                               msoLogger.error(MessageEnum.APIH_BPEL_RESPONSE_ERROR,
-                                               requestClient.getUrl(), "", "",
-                                               MsoLogger.ErrorCode.BusinessProcesssError,
-                                               "Response from BPEL engine is failed with HTTP Status="
-                                                               + bpelStatus);
-                               msoLogger.recordAuditEvent(startTime,
-                                               MsoLogger.StatusCode.ERROR,
-                                               MsoLogger.ResponseCode.InternalError,
-                                               "Response from BPMN engine is failed");
-                               msoLogger.debug(END_OF_THE_TRANSACTION
-                                               + (String) resp.getEntity());
-                               return resp;
-                       } else {
-                               Response resp = msoRequest
-                                               .buildServiceErrorResponse(
-                                                               bpelStatus,
-                                                               MsoException.ServiceException,
-                                                               "Request Failed due to BPEL error with HTTP Status= %1",
-                                                               ErrorNumbers.SVC_DETAILED_SERVICE_ERROR,
-                                                               variables);
-                               msoLogger.error(MessageEnum.APIH_BPEL_RESPONSE_ERROR,
-                                               requestClient.getUrl(), "", "",
-                                               MsoLogger.ErrorCode.BusinessProcesssError,
-                                               "Response from BPEL engine is empty");
-                               msoLogger.recordAuditEvent(startTime,
-                                               MsoLogger.StatusCode.ERROR,
-                                               MsoLogger.ResponseCode.InternalError,
-                                               "Response from BPEL engine is empty");
-                               msoLogger.debug(END_OF_THE_TRANSACTION
-                                               + (String) resp.getEntity());
-                               return resp;
-                       }
-               }
-       }
-
-       /**
-        * Getting recipes from catalogDb
-        * 
-        * @param db the catalog db
-        * @param serviceModelUUID the service model version uuid
-        * @param action the action for the service
-        * @return the service recipe result
-        */
-       private RecipeLookupResult getServiceInstanceOrchestrationURI(
-                       CatalogDatabase db, String serviceModelUUID, Action action) {
-
-               RecipeLookupResult recipeLookupResult = getServiceURI(db, serviceModelUUID, action);
-
-               if (recipeLookupResult != null) {
-                       msoLogger.debug("Orchestration URI is: "
-                                       + recipeLookupResult.getOrchestrationURI()
-                                       + ", recipe Timeout is: "
-                                       + Integer.toString(recipeLookupResult.getRecipeTimeout()));
-               } else {
-                       msoLogger.debug("No matching recipe record found");
-               }
-               return recipeLookupResult;
-       }
-
-       /**
-        * Getting recipes from catalogDb
-        * If Service recipe is not set, use default recipe, if set , use special recipe.
-        * @param db the catalog db
-        * @param serviceModelUUID the service version uuid
-        * @param action the action of the service.
-        * @return the service recipe result.
-        */
-       private RecipeLookupResult getServiceURI(CatalogDatabase db, String serviceModelUUID, Action action) {
-
-               String defaultServiceModelName = "UUI_DEFAULT";
-
-               Service defaultServiceRecord = db
-                               .getServiceByModelName(defaultServiceModelName);
-               ServiceRecipe defaultRecipe = db.getServiceRecipeByModelUUID(
-                       defaultServiceRecord.getModelUUID(), action.name());
-               //set recipe as default generic recipe
-               ServiceRecipe recipe = defaultRecipe;
-               //check the service special recipe 
-               if(null != serviceModelUUID && ! serviceModelUUID.isEmpty()){
-                     ServiceRecipe serviceSpecialRecipe = db.getServiceRecipeByModelUUID(
-                             serviceModelUUID, action.name());
-                     if(null != serviceSpecialRecipe){
-                         //set service special recipe.
-                         recipe = serviceSpecialRecipe;
-                     }
-               }       
-               
-               if (recipe == null) {
-                       return null;
-               }
-               return new RecipeLookupResult(recipe.getOrchestrationUri(),
-                               recipe.getRecipeTimeout(), recipe.getServiceParamXSD());
-
-       }
-
-       /**
-        * Converting E2EServiceInstanceRequest to ServiceInstanceRequest and
-        * passing it to camunda engine.
-        * 
-        * @param e2eSir
-        * @return
-        */
-       private String mapReqJsonToSvcInstReq(E2EServiceInstanceRequest e2eSir,
-                       String requestJSON) {
-
-               sir = new ServiceInstancesRequest();
-
-               String returnString = null;
-               RequestDetails requestDetails = new RequestDetails();
-               ModelInfo modelInfo = new ModelInfo();
-
-               // ModelInvariantId
-               modelInfo.setModelInvariantId(e2eSir.getService().getServiceDefId());
-
-               // modelNameVersionId
-               modelInfo.setModelNameVersionId(e2eSir.getService().getTemplateId());
-
-               // String modelInfoValue =
-               // e2eSir.getService().getParameters().getNodeTemplateName();
-               // String[] arrayOfInfo = modelInfoValue.split(":");
-               // String modelName = arrayOfInfo[0];
-               // String modelVersion = arrayOfInfo[1];
-
-               // TODO: To ensure, if we dont get the values from the UUI
-               String modelName = "voLTE";
-               String modelVersion = "1.0";
-               // modelName
-               modelInfo.setModelName(modelName);
-
-               // modelVersion
-               modelInfo.setModelVersion(modelVersion);
-
-               // modelType
-               modelInfo.setModelType(ModelType.service);
-
-               // setting modelInfo to requestDetails
-               requestDetails.setModelInfo(modelInfo);
-
-               SubscriberInfo subscriberInfo = new SubscriberInfo();
-
-               // globalsubscriberId
-               subscriberInfo.setGlobalSubscriberId(e2eSir.getService()
-                               .getParameters().getGlobalSubscriberId());
-
-               // subscriberName
-               subscriberInfo.setSubscriberName(e2eSir.getService().getParameters()
-                               .getSubscriberName());
-
-               // setting subscriberInfo to requestDetails
-               requestDetails.setSubscriberInfo(subscriberInfo);
-
-               RequestInfo requestInfo = new RequestInfo();
-
-               // instanceName
-               requestInfo.setInstanceName(e2eSir.getService().getName());
-
-               // source
-               requestInfo.setSource("UUI");
-
-               // suppressRollback
-               requestInfo.setSuppressRollback(true);
-
-               // setting requestInfo to requestDetails
-               requestDetails.setRequestInfo(requestInfo);
-
-               RequestParameters requestParameters = new RequestParameters();
-
-               // subscriptionServiceType
-               requestParameters.setSubscriptionServiceType("MOG");
-
-               // Userparams
-               List<E2EUserParam> userParams;
-               // userParams =
-               // e2eSir.getService().getParameters().getRequestParameters().getUserParams();
-               List<Map<String, String>> userParamList = new ArrayList<>();
-               Map<String, String> userParamMap = new HashMap<>();
-               // complete json request updated in the camunda
-               userParamMap.put("UUIRequest", requestJSON);
-               userParamMap.put("ServiceInstanceName", e2eSir.getService().getName());
-
-               // Map<String, String> userParamMap3 = null;
-               // for (E2EUserParam userp : userParams) {
-               // userParamMap.put(userp.getName(), userp.getValue());
-               //
-               // }
-               userParamList.add(userParamMap);
-               requestParameters.setUserParams(userParamList);
-
-               // setting requestParameters to requestDetails
-               requestDetails.setRequestParameters(requestParameters);
-
-               sir.setRequestDetails(requestDetails);
-
-               // converting to string
-               ObjectMapper mapper = new ObjectMapper();
-               try {
-                       returnString = mapper.writeValueAsString(sir);
-               } catch (IOException e) {
-                       msoLogger
-                                       .debug("Exception while converting ServiceInstancesRequest object to string",
-                                                       e);
-               }
-
-               return returnString;
-       }
-
-       private void createOperationStatusRecordForError(Action action,
-                       String requestId) throws MsoDatabaseException {
-
-               AbstractSessionFactoryManager requestsDbSessionFactoryManager = new RequestsDbSessionFactoryManager();
-
-               Session session = null;
-               try {
-
-                       session = requestsDbSessionFactoryManager.getSessionFactory()
-                                       .openSession();
-                       session.beginTransaction();
-
-                       OperationStatus os = new OperationStatus();
-                       os.setOperation(action.name());
-                       os.setOperationContent("");
-                       os.setOperationId("");
-                       os.setProgress("100");
-                       os.setReason("");
-                       os.setResult("error");
-                       os.setServiceId(requestId);
-                       os.setUserId("");
-                       Timestamp startTimeStamp = new Timestamp(System.currentTimeMillis());
-                       Timestamp endTimeStamp = new Timestamp(System.currentTimeMillis());
-                       os.setFinishedAt(endTimeStamp);
-                       os.setOperateAt(startTimeStamp);
-
-                       session.save(os);
-                       session.getTransaction().commit();
-
-               } catch (Exception e) {
-                       msoLogger.error(MessageEnum.APIH_DB_INSERT_EXC, "", "",
-                                       MsoLogger.ErrorCode.DataError,
-                                       "Exception when creation record request in Operation", e);
-                       throw new MsoDatabaseException(
-                                       "Data did inserted in Operatus Status Table for failure", e);
-               } finally {
-                       if (null != session) {
-                               session.close();
-                       }
-               }
-       }
-
-       private void createOperationStatusRecord(String actionNm, String serviceId,
-                       String operationId) throws MsoDatabaseException {
-
-               AbstractSessionFactoryManager requestsDbSessionFactoryManager = new RequestsDbSessionFactoryManager();
-
-               Session session = null;
-               try {
-
-                       session = requestsDbSessionFactoryManager.getSessionFactory()
-                                       .openSession();
-                       session.beginTransaction();
-
-                       OperationStatus os = new OperationStatus();
-                       os.setOperation(actionNm);
-                       os.setOperationContent("");
-                       os.setOperationId(operationId);
-                       os.setProgress("0");
-                       os.setReason("");
-                       os.setResult("processing");
-                       os.setServiceId(serviceId);
-                       // TODO : to be updated...
-                       os.setUserId("");
-                       Timestamp startTimeStamp = new Timestamp(System.currentTimeMillis());
-                       Timestamp endTimeStamp = new Timestamp(System.currentTimeMillis());
-                       os.setFinishedAt(endTimeStamp);
-                       os.setOperateAt(startTimeStamp);
-
-                       session.save(os);
-                       session.getTransaction().commit();
-
-               } catch (Exception e) {
-                       msoLogger.error(MessageEnum.APIH_DB_INSERT_EXC, "", "",
-                                       MsoLogger.ErrorCode.DataError,
-                                       "Exception when creation record request in Operation", e);
-                       throw new MsoDatabaseException(
-                                       "Data did inserted in Operatus Status Table", e);
-               } finally {
-                       if (null != session) {
-                               session.close();
-                       }
-               }
-       }
-
-       private OperationStatus chkDuplicateServiceInOperStatus(String serviceId) {
-               OperationStatus dupServiceName = (RequestsDatabase.getInstance())
-                               .getOperationStatusByServiceId(serviceId);
-
-               return dupServiceName;
-       }
-
-       private OperationStatus chkDuplicateServiceNameInOperStatus(
-                       String serviceName) {
-               OperationStatus dupServiceName = (RequestsDatabase.getInstance())
-                               .getOperationStatusByServiceName(serviceName);
-
-               return dupServiceName;
-       }
+/*-\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;\r
+\r
+import java.io.IOException;\r
+import java.sql.Timestamp;\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+\r
+import javax.ws.rs.Consumes;\r
+import javax.ws.rs.DELETE;\r
+import javax.ws.rs.GET;\r
+import javax.ws.rs.POST;\r
+import javax.ws.rs.PUT;\r
+import javax.ws.rs.Path;\r
+import javax.ws.rs.PathParam;\r
+import javax.ws.rs.Produces;\r
+import javax.ws.rs.core.MediaType;\r
+import javax.ws.rs.core.Response;\r
+\r
+import org.apache.http.HttpResponse;\r
+import org.apache.http.HttpStatus;\r
+import org.codehaus.jackson.map.ObjectMapper;\r
+import org.hibernate.Session;\r
+import org.json.JSONObject;\r
+import org.openecomp.mso.apihandler.common.ErrorNumbers;\r
+import org.openecomp.mso.apihandler.common.RequestClient;\r
+import org.openecomp.mso.apihandler.common.RequestClientFactory;\r
+import org.openecomp.mso.apihandler.common.ResponseHandler;\r
+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.DelE2ESvcResp;\r
+import org.openecomp.mso.apihandlerinfra.e2eserviceinstancebeans.E2EServiceInstanceDeleteRequest;\r
+import org.openecomp.mso.apihandlerinfra.e2eserviceinstancebeans.E2EServiceInstanceRequest;\r
+import org.openecomp.mso.apihandlerinfra.e2eserviceinstancebeans.E2EUserParam;\r
+import org.openecomp.mso.apihandlerinfra.e2eserviceinstancebeans.GetE2EServiceInstanceResponse;\r
+import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.ModelInfo;\r
+import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.RequestDetails;\r
+import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.RequestInfo;\r
+import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.RequestParameters;\r
+import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.ServiceInstancesRequest;\r
+import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.SubscriberInfo;\r
+import org.openecomp.mso.db.AbstractSessionFactoryManager;\r
+import org.openecomp.mso.db.catalog.CatalogDatabase;\r
+import org.openecomp.mso.db.catalog.beans.Service;\r
+import org.openecomp.mso.db.catalog.beans.ServiceRecipe;\r
+import org.openecomp.mso.logger.MessageEnum;\r
+import org.openecomp.mso.logger.MsoAlarmLogger;\r
+import org.openecomp.mso.logger.MsoLogger;\r
+import org.openecomp.mso.properties.MsoDatabaseException;\r
+import org.openecomp.mso.requestsdb.OperationStatus;\r
+import org.openecomp.mso.requestsdb.RequestsDatabase;\r
+import org.openecomp.mso.requestsdb.RequestsDbSessionFactoryManager;\r
+import org.openecomp.mso.utils.UUIDChecker;\r
+\r
+import com.wordnik.swagger.annotations.Api;\r
+import com.wordnik.swagger.annotations.ApiOperation;\r
+\r
+@Path("/e2eServiceInstances")\r
+@Api(value = "/e2eServiceInstances", description = "API Requests for E2E Service Instances")\r
+public class E2EServiceInstances {\r
+\r
+       private HashMap<String, String> instanceIdMap = new HashMap<>();\r
+       private static MsoLogger msoLogger = MsoLogger\r
+                       .getMsoLogger(MsoLogger.Catalog.APIH);\r
+       private static MsoAlarmLogger alarmLogger = new MsoAlarmLogger();\r
+       public static final String MSO_PROP_APIHANDLER_INFRA = "MSO_PROP_APIHANDLER_INFRA";\r
+       private ServiceInstancesRequest sir = null;\r
+\r
+       public static final String END_OF_THE_TRANSACTION = "End of the transaction, the final response is: ";\r
+       public static final String EXCEPTION_CREATING_DB_RECORD = "Exception while creating record in DB";\r
+       public static final String EXCEPTION_COMMUNICATE_BPMN_ENGINE = "Exception while communicate with BPMN engine";\r
+\r
+       /**\r
+        * POST Requests for E2E Service create Instance on a version provided\r
+        */\r
+\r
+       @POST\r
+       @Path("/{version:[vV][3-5]}")\r
+       @Consumes(MediaType.APPLICATION_JSON)\r
+       @Produces(MediaType.APPLICATION_JSON)\r
+       @ApiOperation(value = "Create an E2E Service Instance on a version provided", response = Response.class)\r
+       public Response createE2EServiceInstance(String request,\r
+                       @PathParam("version") String version) {\r
+\r
+               return processE2EserviceInstances(request, Action.createInstance, null,\r
+                               version);\r
+       }\r
+       \r
+       /**\r
+        * PUT Requests for E2E Service update Instance on a version provided\r
+        */\r
+\r
+       @PUT\r
+       @Path("/{version:[vV][3-5]}/{serviceId}")\r
+       @Consumes(MediaType.APPLICATION_JSON)\r
+       @Produces(MediaType.APPLICATION_JSON)\r
+       @ApiOperation(value = "Update an E2E Service Instance on a version provided and serviceId", response = Response.class)\r
+       public Response updateE2EServiceInstance(String request,\r
+                       @PathParam("version") String version,\r
+                       @PathParam("serviceId") String serviceId) {\r
+               \r
+               instanceIdMap.put("serviceId", serviceId);\r
+\r
+               return updateE2EserviceInstances(request, Action.updateInstance, instanceIdMap,\r
+                               version);\r
+       }\r
+\r
+       /**\r
+        * DELETE Requests for E2E Service delete Instance on a specified version\r
+        * and serviceId\r
+        */\r
+\r
+       @DELETE\r
+       @Path("/{version:[vV][3-5]}/{serviceId}")\r
+       @Consumes(MediaType.APPLICATION_JSON)\r
+       @Produces(MediaType.APPLICATION_JSON)\r
+       @ApiOperation(value = "Delete E2E Service Instance on a specified version and serviceId", response = Response.class)\r
+       public Response deleteE2EServiceInstance(String request,\r
+                       @PathParam("version") String version,\r
+                       @PathParam("serviceId") String serviceId) {\r
+\r
+               instanceIdMap.put("serviceId", serviceId);\r
+\r
+               return deleteE2EserviceInstances(request, Action.deleteInstance,\r
+                               instanceIdMap, version);\r
+       }\r
+\r
+       @GET\r
+       @Path("/{version:[vV][3-5]}/{serviceId}/operations/{operationId}")\r
+       @ApiOperation(value = "Find e2eServiceInstances Requests for a given serviceId and operationId", response = Response.class)\r
+       @Produces(MediaType.APPLICATION_JSON)\r
+       public Response getE2EServiceInstances(\r
+                       @PathParam("serviceId") String serviceId,\r
+                       @PathParam("version") String version,\r
+                       @PathParam("operationId") String operationId) {\r
+               return getE2EServiceInstances(serviceId, operationId);\r
+       }\r
+\r
+       private Response getE2EServiceInstances(String serviceId, String operationId) {\r
+               RequestsDatabase requestsDB = RequestsDatabase.getInstance();\r
+\r
+               GetE2EServiceInstanceResponse e2eServiceResponse = new GetE2EServiceInstanceResponse();\r
+\r
+               MsoRequest msoRequest = new MsoRequest(serviceId);\r
+\r
+               long startTime = System.currentTimeMillis();\r
+\r
+               OperationStatus operationStatus = null;\r
+\r
+               try {\r
+                       operationStatus = requestsDB.getOperationStatus(serviceId,\r
+                                       operationId);\r
+\r
+               } catch (Exception e) {\r
+                       msoLogger\r
+                                       .error(MessageEnum.APIH_DB_ACCESS_EXC,\r
+                                                       MSO_PROP_APIHANDLER_INFRA,\r
+                                                       "",\r
+                                                       "",\r
+                                                       MsoLogger.ErrorCode.AvailabilityError,\r
+                                                       "Exception while communciate with Request DB - Infra Request Lookup",\r
+                                                       e);\r
+                       msoRequest\r
+                                       .setStatus(org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);\r
+                       Response response = msoRequest.buildServiceErrorResponse(\r
+                                       HttpStatus.SC_NOT_FOUND, MsoException.ServiceException,\r
+                                       e.getMessage(),\r
+                                       ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB, null);\r
+                       alarmLogger.sendAlarm("MsoDatabaseAccessError",\r
+                                       MsoAlarmLogger.CRITICAL, Messages.errors\r
+                                                       .get(ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB));\r
+                       msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR,\r
+                                       MsoLogger.ResponseCode.DBAccessError,\r
+                                       "Exception while communciate with Request DB");\r
+                       msoLogger.debug("End of the transaction, the final response is: "\r
+                                       + (String) response.getEntity());\r
+                       return response;\r
+\r
+               }\r
+\r
+               if (operationStatus == null) {\r
+                       Response resp = msoRequest.buildServiceErrorResponse(\r
+                                       HttpStatus.SC_NO_CONTENT, MsoException.ServiceException,\r
+                                       "E2E serviceId " + serviceId + " is not found in DB",\r
+                                       ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, null);\r
+                       msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR,\r
+                                       MSO_PROP_APIHANDLER_INFRA, "", "",\r
+                                       MsoLogger.ErrorCode.BusinessProcesssError,\r
+                                       "Null response from RequestDB when searching by serviceId");\r
+                       msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR,\r
+                                       MsoLogger.ResponseCode.DataNotFound,\r
+                                       "Null response from RequestDB when searching by serviceId");\r
+                       msoLogger.debug("End of the transaction, the final response is: "\r
+                                       + (String) resp.getEntity());\r
+                       return resp;\r
+\r
+               }\r
+\r
+               e2eServiceResponse.setOperationStatus(operationStatus);\r
+\r
+               return Response.status(200).entity(e2eServiceResponse).build();\r
+       }\r
+\r
+       private Response deleteE2EserviceInstances(String requestJSON,\r
+                       Action action, HashMap<String, String> instanceIdMap, String version) {\r
+               // TODO should be a new one or the same service instance Id\r
+               String requestId = instanceIdMap.get("serviceId");\r
+               long startTime = System.currentTimeMillis();\r
+               msoLogger.debug("requestId is: " + requestId);\r
+               E2EServiceInstanceDeleteRequest e2eDelReq = null;\r
+\r
+               MsoRequest msoRequest = new MsoRequest(requestId);\r
+\r
+               ObjectMapper mapper = new ObjectMapper();\r
+               try {\r
+                       e2eDelReq = mapper.readValue(requestJSON,\r
+                                       E2EServiceInstanceDeleteRequest.class);\r
+\r
+               } catch (Exception e) {\r
+\r
+                       msoLogger.debug("Mapping of request to JSON object failed : ", e);\r
+                       Response response = msoRequest.buildServiceErrorResponse(\r
+                                       HttpStatus.SC_BAD_REQUEST,\r
+                                       MsoException.ServiceException,\r
+                                       "Mapping of request to JSON object failed.  "\r
+                                                       + e.getMessage(), ErrorNumbers.SVC_BAD_PARAMETER,\r
+                                       null);\r
+                       msoLogger.error(MessageEnum.APIH_REQUEST_VALIDATION_ERROR,\r
+                                       MSO_PROP_APIHANDLER_INFRA, "", "",\r
+                                       MsoLogger.ErrorCode.SchemaError, requestJSON, e);\r
+                       msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR,\r
+                                       MsoLogger.ResponseCode.SchemaError,\r
+                                       "Mapping of request to JSON object failed");\r
+                       msoLogger.debug("End of the transaction, the final response is: "\r
+                                       + (String) response.getEntity());\r
+                       createOperationStatusRecordForError(action, requestId);\r
+                       return response;\r
+               }\r
+\r
+               CatalogDatabase db = null;\r
+               RecipeLookupResult recipeLookupResult = null;\r
+               try {\r
+                       db = CatalogDatabase.getInstance();\r
+                       //TODO  Get the service template model version uuid from AAI.\r
+                       recipeLookupResult = getServiceInstanceOrchestrationURI(db, null, action);\r
+               } catch (Exception e) {\r
+                       msoLogger.error(MessageEnum.APIH_DB_ACCESS_EXC,\r
+                                       MSO_PROP_APIHANDLER_INFRA, "", "",\r
+                                       MsoLogger.ErrorCode.AvailabilityError,\r
+                                       "Exception while communciate with Catalog DB", e);\r
+                       msoRequest\r
+                                       .setStatus(org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);\r
+                       Response response = msoRequest.buildServiceErrorResponse(\r
+                                       HttpStatus.SC_NOT_FOUND, MsoException.ServiceException,\r
+                                       "No communication to catalog DB " + e.getMessage(),\r
+                                       ErrorNumbers.SVC_NO_SERVER_RESOURCES, null);\r
+                       alarmLogger.sendAlarm("MsoDatabaseAccessError",\r
+                                       MsoAlarmLogger.CRITICAL, Messages.errors\r
+                                                       .get(ErrorNumbers.NO_COMMUNICATION_TO_CATALOG_DB));\r
+                       msoRequest.createRequestRecord(Status.FAILED, action);\r
+                       msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR,\r
+                                       MsoLogger.ResponseCode.DBAccessError,\r
+                                       "Exception while communciate with DB");\r
+                       msoLogger.debug(END_OF_THE_TRANSACTION\r
+                                       + (String) response.getEntity());\r
+                       return response;\r
+               } finally {\r
+                       closeCatalogDB(db);\r
+               }\r
+               if (recipeLookupResult == null) {\r
+                       msoLogger.error(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND,\r
+                                       MSO_PROP_APIHANDLER_INFRA, "", "",\r
+                                       MsoLogger.ErrorCode.DataError, "No recipe found in DB");\r
+                       msoRequest\r
+                                       .setStatus(org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);\r
+                       Response response = msoRequest.buildServiceErrorResponse(\r
+                                       HttpStatus.SC_NOT_FOUND, MsoException.ServiceException,\r
+                                       "Recipe does not exist in catalog DB",\r
+                                       ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null);\r
+                       msoRequest.createRequestRecord(Status.FAILED, action);\r
+                       msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR,\r
+                                       MsoLogger.ResponseCode.DataNotFound,\r
+                                       "No recipe found in DB");\r
+                       msoLogger.debug(END_OF_THE_TRANSACTION\r
+                                       + (String) response.getEntity());\r
+                       createOperationStatusRecordForError(action, requestId);\r
+                       return response;\r
+               }\r
+\r
+               RequestClient requestClient = null;\r
+               HttpResponse response = null;\r
+\r
+               long subStartTime = System.currentTimeMillis();\r
+               // String sirRequestJson = mapReqJsonToSvcInstReq(e2eSir, requestJSON);\r
+\r
+               try {\r
+                       requestClient = RequestClientFactory.getRequestClient(\r
+                                       recipeLookupResult.getOrchestrationURI(),\r
+                                       MsoPropertiesUtils.loadMsoProperties());\r
+\r
+                       JSONObject jjo = new JSONObject(requestJSON);\r
+                       jjo.put("operationId", UUIDChecker.generateUUID(msoLogger));\r
+\r
+                       String bpmnRequest = jjo.toString();\r
+\r
+                       // Capture audit event\r
+                       msoLogger\r
+                                       .debug("MSO API Handler Posting call to BPEL engine for url: "\r
+                                                       + requestClient.getUrl());\r
+                       String serviceId = instanceIdMap.get("serviceId");\r
+                       String serviceInstanceType = e2eDelReq.getServiceType();\r
+                       response = requestClient.post(requestId, false,\r
+                                       recipeLookupResult.getRecipeTimeout(), action.name(),\r
+                                       serviceId, null, null, null, null, serviceInstanceType,\r
+                                       null, null, null, bpmnRequest, recipeLookupResult.getRecipeParamXsd());\r
+\r
+                       msoLogger.recordMetricEvent(subStartTime,\r
+                                       MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,\r
+                                       "Successfully received response from BPMN engine", "BPMN",\r
+                                       recipeLookupResult.getOrchestrationURI(), null);\r
+               } catch (Exception e) {\r
+                       msoLogger.recordMetricEvent(subStartTime,\r
+                                       MsoLogger.StatusCode.ERROR,\r
+                                       MsoLogger.ResponseCode.CommunicationError,\r
+                                       "Exception while communicate with BPMN engine", "BPMN",\r
+                                       recipeLookupResult.getOrchestrationURI(), null);\r
+                       Response resp = msoRequest.buildServiceErrorResponse(\r
+                                       HttpStatus.SC_BAD_GATEWAY, MsoException.ServiceException,\r
+                                       "Failed calling bpmn " + e.getMessage(),\r
+                                       ErrorNumbers.SVC_NO_SERVER_RESOURCES, null);\r
+                       alarmLogger.sendAlarm("MsoConfigurationError",\r
+                                       MsoAlarmLogger.CRITICAL,\r
+                                       Messages.errors.get(ErrorNumbers.NO_COMMUNICATION_TO_BPEL));\r
+                       msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR,\r
+                                       MSO_PROP_APIHANDLER_INFRA, "", "",\r
+                                       MsoLogger.ErrorCode.AvailabilityError,\r
+                                       "Exception while communicate with BPMN engine");\r
+                       msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR,\r
+                                       MsoLogger.ResponseCode.CommunicationError,\r
+                                       "Exception while communicate with BPMN engine");\r
+                       msoLogger.debug("End of the transaction, the final response is: "\r
+                                       + (String) resp.getEntity());\r
+                       createOperationStatusRecordForError(action, requestId);\r
+                       return resp;\r
+               }\r
+\r
+               if (response == null) {\r
+                       Response resp = msoRequest.buildServiceErrorResponse(\r
+                                       HttpStatus.SC_BAD_GATEWAY, MsoException.ServiceException,\r
+                                       "bpelResponse is null",\r
+                                       ErrorNumbers.SVC_NO_SERVER_RESOURCES, null);\r
+                       msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR,\r
+                                       MSO_PROP_APIHANDLER_INFRA, "", "",\r
+                                       MsoLogger.ErrorCode.BusinessProcesssError,\r
+                                       "Null response from BPEL");\r
+                       msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR,\r
+                                       MsoLogger.ResponseCode.InternalError,\r
+                                       "Null response from BPMN");\r
+                       msoLogger.debug(END_OF_THE_TRANSACTION + (String) resp.getEntity());\r
+                       createOperationStatusRecordForError(action, requestId);\r
+                       return resp;\r
+               }\r
+\r
+               ResponseHandler respHandler = new ResponseHandler(response,\r
+                               requestClient.getType());\r
+               int bpelStatus = respHandler.getStatus();\r
+\r
+               return beplStatusUpdate(requestId, startTime, msoRequest,\r
+                               requestClient, respHandler, bpelStatus, action, instanceIdMap);\r
+       }\r
+\r
+       private Response updateE2EserviceInstances(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
+               E2EServiceInstanceRequest e2eSir = null;\r
+\r
+               MsoRequest msoRequest = new MsoRequest(requestId);\r
+               ObjectMapper mapper = new ObjectMapper();\r
+               try {\r
+                       e2eSir = mapper.readValue(requestJSON, E2EServiceInstanceRequest.class);\r
+\r
+               } catch (Exception e) {\r
+          \r
+          this.createOperationStatusRecordForError(action, requestId);\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: " + (String) response.getEntity());\r
+                       return response;\r
+               }\r
+\r
+               mapReqJsonToSvcInstReq(e2eSir, requestJSON);\r
+               sir.getRequestDetails().getRequestParameters().setaLaCarte(true);\r
+               try {\r
+                       msoRequest.parse(sir, instanceIdMap, action, version);\r
+               } catch (Exception e) {\r
+                       msoLogger.debug("Validation failed: ", e);\r
+                       Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST,\r
+                                       MsoException.ServiceException, "Error parsing request.  " + e.getMessage(),\r
+                                       ErrorNumbers.SVC_BAD_PARAMETER, null);\r
+                       if (msoRequest.getRequestId() != null) {\r
+                               msoLogger.debug("Logging failed message to the database");\r
+                               this.createOperationStatusRecordForError(action, requestId);\r
+                       }\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
+                                       "Validation of the input request failed");\r
+                       msoLogger.debug("End of the transaction, the final response is: " + (String) response.getEntity());\r
+                       return response;\r
+               }\r
+               \r
+               //check for the current operation status\r
+               Response resp = checkE2ESvcInstStatus(action, requestId, startTime, msoRequest);\r
+               if(resp != null && resp.getStatus() != 200) {\r
+                       return resp;\r
+               }\r
+               \r
+               CatalogDatabase db = null;\r
+               RecipeLookupResult recipeLookupResult = null;\r
+               try {\r
+                       db = CatalogDatabase.getInstance();\r
+                       recipeLookupResult = getServiceInstanceOrchestrationURI(db, e2eSir.getService().getTemplateId(), action);\r
+               } catch (Exception e) {\r
+                       msoLogger.error(MessageEnum.APIH_DB_ACCESS_EXC, MSO_PROP_APIHANDLER_INFRA, "", "",\r
+                                       MsoLogger.ErrorCode.AvailabilityError, "Exception while communciate with Catalog DB", e);\r
+                       msoRequest.setStatus(org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);\r
+                       Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND,\r
+                                       MsoException.ServiceException, "No communication to catalog DB " + e.getMessage(),\r
+                                       ErrorNumbers.SVC_NO_SERVER_RESOURCES, null);\r
+                       alarmLogger.sendAlarm("MsoDatabaseAccessError", MsoAlarmLogger.CRITICAL,\r
+                                       Messages.errors.get(ErrorNumbers.NO_COMMUNICATION_TO_CATALOG_DB));\r
+                       \r
+                       msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError,\r
+                                       "Exception while communciate with DB");\r
+                       msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity());\r
+                       createOperationStatusRecordForError(action, requestId);\r
+                       return response;\r
+               } finally {\r
+                       closeCatalogDB(db);\r
+               }\r
+\r
+               if (recipeLookupResult == null) {\r
+                       msoLogger.error(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, MSO_PROP_APIHANDLER_INFRA, "", "",\r
+                                       MsoLogger.ErrorCode.DataError, "No recipe found in DB");\r
+                       msoRequest.setStatus(org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);\r
+                       Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND,\r
+                                       MsoException.ServiceException, "Recipe does not exist in catalog DB",\r
+                                       ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null);\r
+               \r
+                       msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound,\r
+                                       "No recipe found in DB");\r
+                       msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity());\r
+                       createOperationStatusRecordForError(action, requestId);\r
+                       return response;\r
+               }\r
+\r
+               String serviceInstanceType = e2eSir.getService().getParameters().getServiceType();\r
+\r
+               String serviceId = "";\r
+               RequestClient requestClient = null;\r
+               HttpResponse response = null;\r
+\r
+               long subStartTime = System.currentTimeMillis();\r
+               String sirRequestJson = mapReqJsonToSvcInstReq(e2eSir, requestJSON);\r
+\r
+               try {\r
+                       requestClient = RequestClientFactory.getRequestClient(recipeLookupResult.getOrchestrationURI(),\r
+                                       MsoPropertiesUtils.loadMsoProperties());\r
+\r
+                       // Capture audit event\r
+                       msoLogger.debug("MSO API Handler Posting call to BPEL engine for url: " + requestClient.getUrl());\r
+\r
+                       response = requestClient.post(requestId, false, recipeLookupResult.getRecipeTimeout(), action.name(),\r
+                                       serviceId, null, null, null, null, serviceInstanceType, null, null, null, sirRequestJson, recipeLookupResult.getRecipeParamXsd());\r
+\r
+                       msoLogger.recordMetricEvent(subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,\r
+                                       "Successfully received response from BPMN engine", "BPMN", recipeLookupResult.getOrchestrationURI(),\r
+                                       null);\r
+               } catch (Exception e) {\r
+                       msoLogger.recordMetricEvent(subStartTime, MsoLogger.StatusCode.ERROR,\r
+                                       MsoLogger.ResponseCode.CommunicationError, "Exception while communicate with BPMN engine", "BPMN",\r
+                                       recipeLookupResult.getOrchestrationURI(), null);\r
+                       Response getBPMNResp = 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: " + (String) getBPMNResp.getEntity());\r
+                       createOperationStatusRecordForError(action, requestId);\r
+                       return getBPMNResp;\r
+               }\r
+\r
+               if (response == null) {\r
+                       Response getBPMNResp = 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 + (String) getBPMNResp.getEntity());\r
+                       return getBPMNResp;\r
+               }\r
+\r
+               ResponseHandler respHandler = new ResponseHandler(response, requestClient.getType());\r
+               int bpelStatus = respHandler.getStatus();\r
+\r
+               return beplStatusUpdate(requestId, startTime, msoRequest, requestClient, respHandler, bpelStatus, action, instanceIdMap);\r
+       }\r
+\r
+       private Response checkE2ESvcInstStatus(Action action, String requestId, long startTime, MsoRequest msoRequest) {\r
+               OperationStatus curStatus = null;\r
+//             String instanceName = sir.getRequestDetails().getRequestInfo().getInstanceName();\r
+               String requestScope = sir.getRequestDetails().getModelInfo().getModelType().name();\r
+               try {\r
+                       if (!(requestId == null && "service".equals(requestScope) && (action == Action.updateInstance))) {                          \r
+                               curStatus = chkSvcInstOperStatusbySvcId(requestId);\r
+                       }\r
+               } catch (Exception e) {\r
+                       msoLogger.error(MessageEnum.APIH_DUPLICATE_CHECK_EXC, MSO_PROP_APIHANDLER_INFRA, "", "",\r
+                                       MsoLogger.ErrorCode.DataError, "Error during current operation status check ", e);\r
+\r
+                       Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR,\r
+                                       MsoException.ServiceException, e.getMessage(), ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, null);\r
+\r
+                       msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError,\r
+                                       "Error during current operation status check");\r
+                       msoLogger.debug("End of the transaction, the final response is: " + (String) response.getEntity());\r
+                       return response;\r
+               }\r
+\r
+               if (curStatus != null && !curStatus.getProgress().equals("100")) {\r
+                       String chkMessage = "Error: Locked instance - This " + requestScope + " (" + requestId + ") "\r
+                                       + "now being worked with a status of " + curStatus.getProgress() + " (ServiceName - "\r
+                                       + curStatus.getServiceName()\r
+                                       + "). The existing request must finish or be cleaned up before proceeding.";\r
+\r
+                       Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_CONFLICT,\r
+                                       MsoException.ServiceException, chkMessage, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, null);\r
+\r
+                       msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict,\r
+                                       chkMessage);\r
+\r
+                       msoLogger.debug("End of the transaction, the final response is: " + (String) response.getEntity());\r
+\r
+                       createOperationStatusRecordForError(action, requestId);\r
+\r
+                       return response;\r
+               }\r
+               \r
+               return Response.status(200).entity(null).build();\r
+       }\r
+       \r
+       private Response processE2EserviceInstances(String requestJSON, Action action,\r
+                       HashMap<String, String> instanceIdMap, String version) {\r
+\r
+               String requestId = UUIDChecker.generateUUID(msoLogger);\r
+               long startTime = System.currentTimeMillis();\r
+               msoLogger.debug("requestId is: " + requestId);\r
+               E2EServiceInstanceRequest e2eSir = null;\r
+\r
+               MsoRequest msoRequest = new MsoRequest(requestId);\r
+               ObjectMapper mapper = new ObjectMapper();\r
+               try {\r
+                       e2eSir = mapper.readValue(requestJSON, E2EServiceInstanceRequest.class);\r
+\r
+               } catch (Exception e) {\r
+          //TODO update the service name\r
+          this.createOperationStatusRecordForError(action, requestId);\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: " + (String) response.getEntity());\r
+                       return response;\r
+               }\r
+\r
+               mapReqJsonToSvcInstReq(e2eSir, requestJSON);\r
+               sir.getRequestDetails().getRequestParameters().setaLaCarte(true);\r
+               try {\r
+                       msoRequest.parse(sir, instanceIdMap, action, version);\r
+               } catch (Exception e) {\r
+                       msoLogger.debug("Validation failed: ", e);\r
+                       Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST,\r
+                                       MsoException.ServiceException, "Error parsing request.  " + e.getMessage(),\r
+                                       ErrorNumbers.SVC_BAD_PARAMETER, null);\r
+                       if (msoRequest.getRequestId() != null) {\r
+                               msoLogger.debug("Logging failed message to the database");\r
+                               //TODO update the service name\r
+                         this.createOperationStatusRecordForError(action, requestId);\r
+                       }\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
+                                       "Validation of the input request failed");\r
+                       msoLogger.debug("End of the transaction, the final response is: " + (String) response.getEntity());\r
+                       return response;\r
+               }\r
+               \r
+               OperationStatus dup = null;\r
+               String instanceName = sir.getRequestDetails().getRequestInfo().getInstanceName();\r
+               String requestScope = sir.getRequestDetails().getModelInfo().getModelType().name();\r
+               try {\r
+                       if (!(instanceName == null && "service".equals(requestScope)\r
+                                       && (action == Action.createInstance || action == Action.activateInstance))) {\r
+                         //TODO : Need to check for the duplicate record from the operation status,\r
+                         //TODO : commenting this check for unblocking current testing for now...  induces dead code...\r
+                               dup = chkDuplicateServiceNameInOperStatus( instanceName);\r
+                       }\r
+               } catch (Exception e) {\r
+                       msoLogger.error(MessageEnum.APIH_DUPLICATE_CHECK_EXC, MSO_PROP_APIHANDLER_INFRA, "", "",\r
+                                       MsoLogger.ErrorCode.DataError, "Error during duplicate check ", e);\r
+\r
+                       Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR,\r
+                                       MsoException.ServiceException, e.getMessage(), ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, null);\r
+\r
+                       msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError,\r
+                                       "Error during duplicate check");\r
+                       msoLogger.debug("End of the transaction, the final response is: " + (String) response.getEntity());\r
+                       return response;\r
+               }\r
+\r
+               if (dup != null) {\r
+                       // Found the duplicate record. Return the appropriate error.\r
+                       String instance = null;\r
+                       if (instanceName != null) {\r
+                               instance = instanceName;\r
+                       } else {\r
+                               instance = instanceIdMap.get(requestScope + "InstanceId");\r
+                       }\r
+                       String dupMessage = "Error: Locked instance - This " + requestScope + " (" + instance + ") "\r
+                                       + "already has a request being worked with a status of " + dup.getProgress() + " (ServiceId - "\r
+                                       + dup.getServiceId() + "). The existing request must finish or be cleaned up before proceeding.";\r
+\r
+                       Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_CONFLICT,\r
+                                       MsoException.ServiceException, dupMessage, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, null);\r
+\r
+                       msoLogger.warn(MessageEnum.APIH_DUPLICATE_FOUND, dupMessage, "", "", MsoLogger.ErrorCode.SchemaError,\r
+                                       "Duplicate request - Subscriber already has a request for this service");\r
+                       \r
+                       \r
+                       msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict,\r
+                                       dupMessage);\r
+                       msoLogger.debug("End of the transaction, the final response is: " + (String) response.getEntity());\r
+                       createOperationStatusRecordForError(action, requestId);\r
+                       return response;\r
+               }\r
+               \r
+               CatalogDatabase db = null;\r
+               RecipeLookupResult recipeLookupResult = null;\r
+               try {\r
+                       db = CatalogDatabase.getInstance();\r
+                       recipeLookupResult = getServiceInstanceOrchestrationURI(db, e2eSir.getService().getTemplateId(), action);\r
+               } catch (Exception e) {\r
+                       msoLogger.error(MessageEnum.APIH_DB_ACCESS_EXC, MSO_PROP_APIHANDLER_INFRA, "", "",\r
+                                       MsoLogger.ErrorCode.AvailabilityError, "Exception while communciate with Catalog DB", e);\r
+                       msoRequest.setStatus(org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);\r
+                       Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND,\r
+                                       MsoException.ServiceException, "No communication to catalog DB " + e.getMessage(),\r
+                                       ErrorNumbers.SVC_NO_SERVER_RESOURCES, null);\r
+                       alarmLogger.sendAlarm("MsoDatabaseAccessError", MsoAlarmLogger.CRITICAL,\r
+                                       Messages.errors.get(ErrorNumbers.NO_COMMUNICATION_TO_CATALOG_DB));\r
+                       \r
+                       msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError,\r
+                                       "Exception while communciate with DB");\r
+                       msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity());\r
+                       createOperationStatusRecordForError(action, requestId);\r
+                       return response;\r
+               } finally {\r
+                       closeCatalogDB(db);\r
+               }\r
+\r
+               if (recipeLookupResult == null) {\r
+                       msoLogger.error(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, MSO_PROP_APIHANDLER_INFRA, "", "",\r
+                                       MsoLogger.ErrorCode.DataError, "No recipe found in DB");\r
+                       msoRequest.setStatus(org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);\r
+                       Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND,\r
+                                       MsoException.ServiceException, "Recipe does not exist in catalog DB",\r
+                                       ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null);\r
+               \r
+                       msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound,\r
+                                       "No recipe found in DB");\r
+                       msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity());\r
+                       createOperationStatusRecordForError(action, requestId);\r
+                       return response;\r
+               }\r
+//             try {\r
+//                     msoRequest.createRequestRecord(Status.PENDING, action);\r
+//                     //createOperationStatusRecord(action, requestId);\r
+//             } catch (Exception e) {\r
+//                     msoLogger.error(MessageEnum.APIH_DB_ACCESS_EXC_REASON, "Exception while creating record in DB", "", "",\r
+//                                     MsoLogger.ErrorCode.SchemaError, "Exception while creating record in DB", e);\r
+//                     msoRequest.setStatus(org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);\r
+//                     Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR,\r
+//                                     MsoException.ServiceException, "Exception while creating record in DB " + e.getMessage(),\r
+//                                     ErrorNumbers.SVC_BAD_PARAMETER, null);\r
+//                     msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError,\r
+//                                     "Exception while creating record in DB");\r
+//                     msoLogger.debug("End of the transaction, the final response is: " + (String) response.getEntity());\r
+//                     return response;\r
+//             }\r
+\r
+               String serviceInstanceType = e2eSir.getService().getParameters().getServiceType();\r
+\r
+               String serviceId = "";\r
+               RequestClient requestClient = null;\r
+               HttpResponse response = null;\r
+\r
+               long subStartTime = System.currentTimeMillis();\r
+               String sirRequestJson = mapReqJsonToSvcInstReq(e2eSir, requestJSON);\r
+\r
+               try {\r
+                       requestClient = RequestClientFactory.getRequestClient(recipeLookupResult.getOrchestrationURI(),\r
+                                       MsoPropertiesUtils.loadMsoProperties());\r
+\r
+                       // Capture audit event\r
+                       msoLogger.debug("MSO API Handler Posting call to BPEL engine for url: " + requestClient.getUrl());\r
+\r
+                       response = requestClient.post(requestId, false, recipeLookupResult.getRecipeTimeout(), action.name(),\r
+                                       serviceId, null, null, null, null, serviceInstanceType, null, null, null, sirRequestJson, recipeLookupResult.getRecipeParamXsd());\r
+\r
+                       msoLogger.recordMetricEvent(subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,\r
+                                       "Successfully received response from BPMN engine", "BPMN", recipeLookupResult.getOrchestrationURI(),\r
+                                       null);\r
+               } catch (Exception e) {\r
+                       msoLogger.recordMetricEvent(subStartTime, MsoLogger.StatusCode.ERROR,\r
+                                       MsoLogger.ResponseCode.CommunicationError, "Exception while communicate with BPMN engine", "BPMN",\r
+                                       recipeLookupResult.getOrchestrationURI(), 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: " + (String) resp.getEntity());\r
+                       createOperationStatusRecordForError(action, requestId);\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 + (String) resp.getEntity());\r
+                       return resp;\r
+               }\r
+\r
+               ResponseHandler respHandler = new ResponseHandler(response, requestClient.getType());\r
+               int bpelStatus = respHandler.getStatus();\r
+\r
+               return beplStatusUpdate(requestId, startTime, msoRequest, requestClient, respHandler, bpelStatus, action, instanceIdMap);\r
+       }\r
+\r
+       private void closeCatalogDB(CatalogDatabase db) {\r
+               if (db != null) {\r
+                       db.close();\r
+               }\r
+       }\r
+\r
+       private Response beplStatusUpdate(String requestId, long startTime,\r
+                       MsoRequest msoRequest, RequestClient requestClient,\r
+                       ResponseHandler respHandler, int bpelStatus, Action action,\r
+                       HashMap<String, String> instanceIdMap) {\r
+               // 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
+\r
+                       // currently only for delete case we update the status here\r
+                       if (action == Action.deleteInstance) {\r
+                               ObjectMapper mapper = new ObjectMapper();\r
+                               try {\r
+                                       DelE2ESvcResp jo = mapper.readValue(\r
+                                                       camundaJSONResponseBody, DelE2ESvcResp.class);\r
+                                       String operationId = jo.getOperationId();\r
+                               this.createOperationStatusRecord("DELETE", requestId,\r
+                                                               operationId);\r
+                               } catch (Exception ex) {\r
+                                       msoLogger.error(MessageEnum.APIH_BPEL_RESPONSE_ERROR,\r
+                                                       requestClient.getUrl(), "", "",\r
+                                                       MsoLogger.ErrorCode.BusinessProcesssError,\r
+                                                       "Response from BPEL engine is failed with HTTP Status="\r
+                                                                       + bpelStatus);\r
+                               }\r
+                       }\r
+                       msoLogger.recordAuditEvent(startTime,\r
+                                       MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,\r
+                                       "BPMN accepted the request, the request is in progress");\r
+                       msoLogger.debug(END_OF_THE_TRANSACTION + camundaJSONResponseBody);\r
+                       return Response.status(HttpStatus.SC_ACCEPTED)\r
+                                       .entity(camundaJSONResponseBody).build();\r
+               } else {\r
+                       List<String> variables = new ArrayList<>();\r
+                       variables.add(bpelStatus + "");\r
+                       String camundaJSONResponseBody = respHandler.getResponseBody();\r
+                       if (camundaJSONResponseBody != null\r
+                                       && !camundaJSONResponseBody.isEmpty()) {\r
+                               Response resp = msoRequest.buildServiceErrorResponse(\r
+                                               bpelStatus, MsoException.ServiceException,\r
+                                               "Request Failed due to BPEL error with HTTP Status= %1 "\r
+                                                               + '\n' + camundaJSONResponseBody,\r
+                                               ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, variables);\r
+                               msoLogger.error(MessageEnum.APIH_BPEL_RESPONSE_ERROR,\r
+                                               requestClient.getUrl(), "", "",\r
+                                               MsoLogger.ErrorCode.BusinessProcesssError,\r
+                                               "Response from BPEL engine is failed with HTTP Status="\r
+                                                               + bpelStatus);\r
+                               msoLogger.recordAuditEvent(startTime,\r
+                                               MsoLogger.StatusCode.ERROR,\r
+                                               MsoLogger.ResponseCode.InternalError,\r
+                                               "Response from BPMN engine is failed");\r
+                               msoLogger.debug(END_OF_THE_TRANSACTION\r
+                                               + (String) resp.getEntity());\r
+                               return resp;\r
+                       } else {\r
+                               Response resp = msoRequest\r
+                                               .buildServiceErrorResponse(\r
+                                                               bpelStatus,\r
+                                                               MsoException.ServiceException,\r
+                                                               "Request Failed due to BPEL error with HTTP Status= %1",\r
+                                                               ErrorNumbers.SVC_DETAILED_SERVICE_ERROR,\r
+                                                               variables);\r
+                               msoLogger.error(MessageEnum.APIH_BPEL_RESPONSE_ERROR,\r
+                                               requestClient.getUrl(), "", "",\r
+                                               MsoLogger.ErrorCode.BusinessProcesssError,\r
+                                               "Response from BPEL engine is empty");\r
+                               msoLogger.recordAuditEvent(startTime,\r
+                                               MsoLogger.StatusCode.ERROR,\r
+                                               MsoLogger.ResponseCode.InternalError,\r
+                                               "Response from BPEL engine is empty");\r
+                               msoLogger.debug(END_OF_THE_TRANSACTION\r
+                                               + (String) resp.getEntity());\r
+                               return resp;\r
+                       }\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Getting recipes from catalogDb\r
+        * \r
+        * @param db the catalog db\r
+        * @param serviceModelUUID the service model version uuid\r
+        * @param action the action for the service\r
+        * @return the service recipe result\r
+        */\r
+       private RecipeLookupResult getServiceInstanceOrchestrationURI(\r
+                       CatalogDatabase db, String serviceModelUUID, Action action) {\r
+\r
+               RecipeLookupResult recipeLookupResult = getServiceURI(db, serviceModelUUID, action);\r
+\r
+               if (recipeLookupResult != null) {\r
+                       msoLogger.debug("Orchestration URI is: "\r
+                                       + recipeLookupResult.getOrchestrationURI()\r
+                                       + ", recipe Timeout is: "\r
+                                       + Integer.toString(recipeLookupResult.getRecipeTimeout()));\r
+               } else {\r
+                       msoLogger.debug("No matching recipe record found");\r
+               }\r
+               return recipeLookupResult;\r
+       }\r
+\r
+       /**\r
+        * Getting recipes from catalogDb\r
+        * If Service recipe is not set, use default recipe, if set , use special recipe.\r
+        * @param db the catalog db\r
+        * @param serviceModelUUID the service version uuid\r
+        * @param action the action of the service.\r
+        * @return the service recipe result.\r
+        */\r
+       private RecipeLookupResult getServiceURI(CatalogDatabase db, String serviceModelUUID, Action action) {\r
+\r
+               String defaultServiceModelName = "UUI_DEFAULT";\r
+\r
+               Service defaultServiceRecord = db\r
+                               .getServiceByModelName(defaultServiceModelName);\r
+               ServiceRecipe defaultRecipe = db.getServiceRecipeByModelUUID(\r
+                       defaultServiceRecord.getModelUUID(), action.name());\r
+               //set recipe as default generic recipe\r
+               ServiceRecipe recipe = defaultRecipe;\r
+               //check the service special recipe \r
+               if(null != serviceModelUUID && ! serviceModelUUID.isEmpty()){\r
+                     ServiceRecipe serviceSpecialRecipe = db.getServiceRecipeByModelUUID(\r
+                             serviceModelUUID, action.name());\r
+                     if(null != serviceSpecialRecipe){\r
+                         //set service special recipe.\r
+                         recipe = serviceSpecialRecipe;\r
+                     }\r
+               }       \r
+               \r
+               if (recipe == null) {\r
+                       return null;\r
+               }\r
+               return new RecipeLookupResult(recipe.getOrchestrationUri(),\r
+                               recipe.getRecipeTimeout(), recipe.getServiceParamXSD());\r
+\r
+       }\r
+\r
+       /**\r
+        * Converting E2EServiceInstanceRequest to ServiceInstanceRequest and\r
+        * passing it to camunda engine.\r
+        * \r
+        * @param e2eSir\r
+        * @return\r
+        */\r
+       private String mapReqJsonToSvcInstReq(E2EServiceInstanceRequest e2eSir,\r
+                       String requestJSON) {\r
+\r
+               sir = new ServiceInstancesRequest();\r
+\r
+               String returnString = null;\r
+               RequestDetails requestDetails = new RequestDetails();\r
+               ModelInfo modelInfo = new ModelInfo();\r
+\r
+               // ModelInvariantId\r
+               modelInfo.setModelInvariantId(e2eSir.getService().getServiceDefId());\r
+\r
+               // modelNameVersionId\r
+               modelInfo.setModelNameVersionId(e2eSir.getService().getTemplateId());\r
+\r
+               // String modelInfoValue =\r
+               // e2eSir.getService().getParameters().getNodeTemplateName();\r
+               // String[] arrayOfInfo = modelInfoValue.split(":");\r
+               // String modelName = arrayOfInfo[0];\r
+               // String modelVersion = arrayOfInfo[1];\r
+\r
+               // TODO: To ensure, if we dont get the values from the UUI\r
+               String modelName = "voLTE";\r
+               String modelVersion = "1.0";\r
+               // modelName\r
+               modelInfo.setModelName(modelName);\r
+\r
+               // modelVersion\r
+               modelInfo.setModelVersion(modelVersion);\r
+\r
+               // modelType\r
+               modelInfo.setModelType(ModelType.service);\r
+\r
+               // setting modelInfo to requestDetails\r
+               requestDetails.setModelInfo(modelInfo);\r
+\r
+               SubscriberInfo subscriberInfo = new SubscriberInfo();\r
+\r
+               // globalsubscriberId\r
+               subscriberInfo.setGlobalSubscriberId(e2eSir.getService()\r
+                               .getParameters().getGlobalSubscriberId());\r
+\r
+               // subscriberName\r
+               subscriberInfo.setSubscriberName(e2eSir.getService().getParameters()\r
+                               .getSubscriberName());\r
+\r
+               // setting subscriberInfo to requestDetails\r
+               requestDetails.setSubscriberInfo(subscriberInfo);\r
+\r
+               RequestInfo requestInfo = new RequestInfo();\r
+\r
+               // instanceName\r
+               requestInfo.setInstanceName(e2eSir.getService().getName());\r
+\r
+               // source\r
+               requestInfo.setSource("UUI");\r
+\r
+               // suppressRollback\r
+               requestInfo.setSuppressRollback(true);\r
+\r
+               // setting requestInfo to requestDetails\r
+               requestDetails.setRequestInfo(requestInfo);\r
+\r
+               RequestParameters requestParameters = new RequestParameters();\r
+\r
+               // subscriptionServiceType\r
+               requestParameters.setSubscriptionServiceType("MOG");\r
+\r
+               // Userparams\r
+               List<E2EUserParam> userParams;\r
+               // userParams =\r
+               // e2eSir.getService().getParameters().getRequestParameters().getUserParams();\r
+               List<Map<String, String>> userParamList = new ArrayList<>();\r
+               Map<String, String> userParamMap = new HashMap<>();\r
+               // complete json request updated in the camunda\r
+               userParamMap.put("UUIRequest", requestJSON);\r
+               userParamMap.put("ServiceInstanceName", e2eSir.getService().getName());\r
+\r
+               // Map<String, String> userParamMap3 = null;\r
+               // for (E2EUserParam userp : userParams) {\r
+               // userParamMap.put(userp.getName(), userp.getValue());\r
+               //\r
+               // }\r
+               userParamList.add(userParamMap);\r
+               requestParameters.setUserParams(userParamList);\r
+\r
+               // setting requestParameters to requestDetails\r
+               requestDetails.setRequestParameters(requestParameters);\r
+\r
+               sir.setRequestDetails(requestDetails);\r
+\r
+               // converting to string\r
+               ObjectMapper mapper = new ObjectMapper();\r
+               try {\r
+                       returnString = mapper.writeValueAsString(sir);\r
+               } catch (IOException e) {\r
+                       msoLogger\r
+                                       .debug("Exception while converting ServiceInstancesRequest object to string",\r
+                                                       e);\r
+               }\r
+\r
+               return returnString;\r
+       }\r
+\r
+       private void createOperationStatusRecordForError(Action action,\r
+                       String requestId) throws MsoDatabaseException {\r
+\r
+               AbstractSessionFactoryManager requestsDbSessionFactoryManager = new RequestsDbSessionFactoryManager();\r
+\r
+               Session session = null;\r
+               try {\r
+\r
+                       session = requestsDbSessionFactoryManager.getSessionFactory()\r
+                                       .openSession();\r
+                       session.beginTransaction();\r
+\r
+                       OperationStatus os = new OperationStatus();\r
+                       os.setOperation(action.name());\r
+                       os.setOperationContent("");\r
+                       os.setOperationId("");\r
+                       os.setProgress("100");\r
+                       os.setReason("");\r
+                       os.setResult("error");\r
+                       os.setServiceId(requestId);\r
+                       os.setUserId("");\r
+                       Timestamp startTimeStamp = new Timestamp(System.currentTimeMillis());\r
+                       Timestamp endTimeStamp = new Timestamp(System.currentTimeMillis());\r
+                       os.setFinishedAt(endTimeStamp);\r
+                       os.setOperateAt(startTimeStamp);\r
+\r
+                       session.save(os);\r
+                       session.getTransaction().commit();\r
+\r
+               } catch (Exception e) {\r
+                       msoLogger.error(MessageEnum.APIH_DB_INSERT_EXC, "", "",\r
+                                       MsoLogger.ErrorCode.DataError,\r
+                                       "Exception when creation record request in Operation", e);\r
+                       throw new MsoDatabaseException(\r
+                                       "Data did inserted in Operatus Status Table for failure", e);\r
+               } finally {\r
+                       if (null != session) {\r
+                               session.close();\r
+                       }\r
+               }\r
+       }\r
+\r
+       private void createOperationStatusRecord(String actionNm, String serviceId,\r
+                       String operationId) throws MsoDatabaseException {\r
+\r
+               AbstractSessionFactoryManager requestsDbSessionFactoryManager = new RequestsDbSessionFactoryManager();\r
+\r
+               Session session = null;\r
+               try {\r
+\r
+                       session = requestsDbSessionFactoryManager.getSessionFactory()\r
+                                       .openSession();\r
+                       session.beginTransaction();\r
+\r
+                       OperationStatus os = new OperationStatus();\r
+                       os.setOperation(actionNm);\r
+                       os.setOperationContent("");\r
+                       os.setOperationId(operationId);\r
+                       os.setProgress("0");\r
+                       os.setReason("");\r
+                       os.setResult("processing");\r
+                       os.setServiceId(serviceId);\r
+                       // TODO : to be updated...\r
+                       os.setUserId("");\r
+                       Timestamp startTimeStamp = new Timestamp(System.currentTimeMillis());\r
+                       Timestamp endTimeStamp = new Timestamp(System.currentTimeMillis());\r
+                       os.setFinishedAt(endTimeStamp);\r
+                       os.setOperateAt(startTimeStamp);\r
+\r
+                       session.save(os);\r
+                       session.getTransaction().commit();\r
+\r
+               } catch (Exception e) {\r
+                       msoLogger.error(MessageEnum.APIH_DB_INSERT_EXC, "", "",\r
+                                       MsoLogger.ErrorCode.DataError,\r
+                                       "Exception when creation record request in Operation", e);\r
+                       throw new MsoDatabaseException(\r
+                                       "Data did inserted in Operatus Status Table", e);\r
+               } finally {\r
+                       if (null != session) {\r
+                               session.close();\r
+                       }\r
+               }\r
+       }\r
+\r
+       private OperationStatus chkSvcInstOperStatusbySvcId(String serviceId) {\r
+               OperationStatus svcInstanceOperStatus = (RequestsDatabase.getInstance())\r
+                               .getOperationStatusByServiceId(serviceId);\r
+\r
+               return svcInstanceOperStatus;\r
+       }\r
+\r
+       private OperationStatus chkDuplicateServiceNameInOperStatus(\r
+                       String serviceName) {\r
+               OperationStatus dupServiceName = (RequestsDatabase.getInstance())\r
+                               .getOperationStatusByServiceName(serviceName);\r
+\r
+               return dupServiceName;\r
+       }\r
 }
\ No newline at end of file