diff options
Diffstat (limited to 'mso-api-handlers')
20 files changed, 1187 insertions, 472 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/Constants.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/Constants.java index 3e29a8221a..328ef816e9 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/Constants.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/Constants.java @@ -23,6 +23,9 @@ package org.openecomp.mso.apihandlerinfra; public class Constants {
+ private Constants() {
+ }
+
public static final String VNF_TYPES_PATH = "/{version: v1|v2|v3}/vnf-types";
public static final String NETWORK_TYPES_PATH = "/{version: v1|v2|v3}/network-types";
public static final String VF_MODULE_MODEL_NAMES_PATH = "/{version: v2|v3}/vf-module-model-names";
@@ -47,4 +50,4 @@ public class Constants { public static final String VALID_INSTANCE_NAME_FORMAT = "^[a-zA-Z][a-zA-Z0-9._-]*$";
public static final String A_LA_CARTE = "aLaCarte";
-}
\ No newline at end of file +}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstances.java index 2386848ad5..ecd0e4d4cc 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstances.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstances.java @@ -21,6 +21,7 @@ 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; @@ -39,18 +40,27 @@ 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; @@ -58,446 +68,688 @@ import org.openecomp.mso.logger.MessageEnum; import org.openecomp.mso.logger.MsoAlarmLogger; import org.openecomp.mso.logger.MsoLogger; import org.openecomp.mso.requestsdb.InfraActiveRequests; +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") +@Api(value = "/e2eServiceInstances", description = "API Requests for E2E Service Instances") public class E2EServiceInstances { - private HashMap<String, String> instanceIdMap = new HashMap<String,String>(); - private static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.APIH); - private static MsoAlarmLogger alarmLogger = new MsoAlarmLogger (); - public final static String MSO_PROP_APIHANDLER_INFRA = "MSO_PROP_APIHANDLER_INFRA"; - - public 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 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) + @ApiOperation(value = "Create a E2E Service Instance on a version provided", response = Response.class) public Response createE2EServiceInstance(String request, @PathParam("version") String version) { - return E2EserviceInstances(request, Action.createInstance, null, version); + return processE2EserviceInstances(request, Action.createInstance, null, version); } /** - *DELETE Requests for E2E Service delete Instance on a specified version and serviceId - */ - + * 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) { + @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); + instanceIdMap.put("serviceId", serviceId); - return E2EserviceInstances(request, Action.deleteInstance, null, version); + return deleteE2EserviceInstances(request, Action.deleteInstance, instanceIdMap, version); } - private Response E2EserviceInstances(String requestJSON, Action action, - HashMap<String, String> instanceIdMap, String 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) { + RequestsDatabase requestsDB = RequestsDatabase.getInstance(); + + GetE2EServiceInstanceResponse e2eServiceResponse = new GetE2EServiceInstanceResponse(); - String requestId = UUIDChecker.generateUUID(msoLogger); + 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.setE2eRequest(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); - E2EServiceInstanceRequest sir = null; + E2EServiceInstanceDeleteRequest e2eDelReq = null; MsoRequest msoRequest = new MsoRequest(requestId); + ObjectMapper mapper = new ObjectMapper(); try { - sir = mapper - .readValue(requestJSON, E2EServiceInstanceRequest.class); + 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, "", "", + 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, + 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()); + msoLogger.debug("End of the transaction, the final response is: " + (String) response.getEntity()); + createOperationStatusRecordForError(action, requestId); + return response; + } + + CatalogDatabase db = null; + RecipeLookupResult recipeLookupResult = null; + try { + db = CatalogDatabase.getInstance(); + recipeLookupResult = getServiceInstanceOrchestrationURI(db, action); + } catch (Exception e) { + msoLogger.error(MessageEnum.APIH_DB_ACCESS_EXC, MSO_PROP_APIHANDLER_INFRA, "", "", + MsoLogger.ErrorCode.AvailabilityError, "Exception while communciate with Catalog DB", e); + msoRequest.setStatus(org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED); + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, + MsoException.ServiceException, "No communication to catalog DB " + e.getMessage(), + ErrorNumbers.SVC_NO_SERVER_RESOURCES, null); + alarmLogger.sendAlarm("MsoDatabaseAccessError", MsoAlarmLogger.CRITICAL, + Messages.errors.get(ErrorNumbers.NO_COMMUNICATION_TO_CATALOG_DB)); + msoRequest.createRequestRecord(Status.FAILED, action); + msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError, + "Exception while communciate with DB"); + msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity()); + return response; + } finally { + closeCatalogDB(db); + } + if (recipeLookupResult == null) { + msoLogger.error(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, MSO_PROP_APIHANDLER_INFRA, "", "", + MsoLogger.ErrorCode.DataError, "No recipe found in DB"); + msoRequest.setStatus(org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED); + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, + MsoException.ServiceException, "Recipe does not exist in catalog DB", + ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null); + msoRequest.createRequestRecord(Status.FAILED, action); + msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, + "No recipe found in DB"); + msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity()); + createOperationStatusRecordForError(action, requestId); return response; } - InfraActiveRequests dup = null; - String instanceName = sir.getService().getName(); - String requestScope = sir.getService().getParameters().getNodeType(); + + RequestClient requestClient = null; + HttpResponse response = null; + + long subStartTime = System.currentTimeMillis(); + //String sirRequestJson = mapReqJsonToSvcInstReq(e2eSir, requestJSON); try { - if(!(instanceName==null && "service".equals(requestScope) && (action == Action.createInstance || action - == Action.activateInstance))){ - dup = (RequestsDatabase.getInstance()).checkInstanceNameDuplicate (instanceIdMap, instanceName, requestScope); - } + 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); + + msoLogger.recordMetricEvent(subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, + "Successfully received response from BPMN engine", "BPMN", recipeLookupResult.getOrchestrationURI(), + null); } catch (Exception e) { - msoLogger.error (MessageEnum.APIH_DUPLICATE_CHECK_EXC, MSO_PROP_APIHANDLER_INFRA, "", "", MsoLogger.ErrorCode.DataError, "Error during duplicate check ", 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; + } - Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, MsoException.ServiceException, - e.getMessage(), - ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, - null) ; + 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); + } + + 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; - 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 ()); + 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; + } + + InfraActiveRequests dup = null; +// String instanceName = sir.getService().getName(); +// String requestScope = sir.getService().getParameters().getNodeType(); + 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 = (RequestsDatabase.getInstance()).checkInstanceNameDuplicate(instanceIdMap, instanceName, +// requestScope); + } + } 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){ + if (instanceName != null) { instance = instanceName; - }else{ + } 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.getRequestStatus() + " (RequestId - " + dup.getRequestId() + "). 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"); - msoRequest.createRequestRecord (Status.FAILED, action); - msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, dupMessage); - msoLogger.debug ("End of the transaction, the final response is: " + (String) response.getEntity ()); + String dupMessage = "Error: Locked instance - This " + requestScope + " (" + instance + ") " + + "already has a request being worked with a status of " + dup.getRequestStatus() + " (RequestId - " + + dup.getRequestId() + "). 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, sir, action); + recipeLookupResult = getServiceInstanceOrchestrationURI(db, action); } catch (Exception e) { - msoLogger.error (MessageEnum.APIH_DB_ACCESS_EXC, MSO_PROP_APIHANDLER_INFRA, "", "", MsoLogger.ErrorCode.AvailabilityError, "Exception while communciate with Catalog DB", e); - msoRequest.setStatus (org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED); - Response response = msoRequest.buildServiceErrorResponse (HttpStatus.SC_NOT_FOUND, - MsoException.ServiceException, - "No communication to catalog DB " + e.getMessage (), - ErrorNumbers.SVC_NO_SERVER_RESOURCES, - null); - alarmLogger.sendAlarm ("MsoDatabaseAccessError", - MsoAlarmLogger.CRITICAL, - Messages.errors.get (ErrorNumbers.NO_COMMUNICATION_TO_CATALOG_DB)); - msoRequest.createRequestRecord (Status.FAILED,action); - msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError, "Exception while communciate with DB"); - msoLogger.debug ("End of the transaction, the final response is: " + (String) response.getEntity ()); + 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 { - if(db != null) { - db.close(); - } + 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, the final response is: " + (String) response.getEntity ()); - - return response; - } - - try { - msoRequest.createRequestRecord (Status.PENDING, action); - } 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 ()); + 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; } - String modelInfo = sir.getService().getParameters().getNodeTemplateName(); - String[] arrayOfInfo = modelInfo.split(":"); - String serviceInstanceType = arrayOfInfo[0]; - - +// 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 = mappingObtainedRequestJSONToServiceInstanceRequest(sir); + String sirRequestJson = mapReqJsonToSvcInstReq(e2eSir, requestJSON); try { - requestClient = RequestClientFactory.getRequestClient (recipeLookupResult.getOrchestrationURI (), MsoPropertiesUtils.loadMsoProperties ()); + requestClient = RequestClientFactory.getRequestClient(recipeLookupResult.getOrchestrationURI(), + MsoPropertiesUtils.loadMsoProperties()); // Capture audit event - msoLogger.debug ("MSO API Handler Posting call to BPEL engine for url: " + requestClient.getUrl ()); + 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); + response = requestClient.post(requestId, false, recipeLookupResult.getRecipeTimeout(), action.name(), + serviceId, null, null, null, null, serviceInstanceType, null, null, null, sirRequestJson); - msoLogger.recordMetricEvent(subStartTime, - MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, - "Successfully received response from BPMN engine", "BPMN", - recipeLookupResult.getOrchestrationURI(), null); + 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", + 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(), + 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, + 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, + 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.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()); + 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, + 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, the final response is: " - + (String) resp.getEntity()); + msoLogger.debug(END_OF_THE_TRANSACTION + (String) resp.getEntity()); return resp; } - ResponseHandler respHandler = new ResponseHandler(response, - requestClient.getType()); + ResponseHandler respHandler = new ResponseHandler(response, requestClient.getType()); int bpelStatus = respHandler.getStatus(); - // BPEL accepted the request, the request is in progress + return beplStatusUpdate(requestId, startTime, msoRequest, requestClient, respHandler, bpelStatus, action); + } + + private void closeCatalogDB(CatalogDatabase db) { + if (db != null) { + db.close(); + } + } + + private InfraActiveRequests checkForDuplicateRecord(Action action, HashMap<String, String> instanceIdMap, + String instanceName, String requestScope) { + InfraActiveRequests dupValue = null; + if (!(instanceName == null && "service".equals(requestScope) + && (action == Action.createInstance || action == Action.activateInstance))) { + dupValue = (RequestsDatabase.getInstance()).checkInstanceNameDuplicate(instanceIdMap, instanceName, + requestScope); + } + return dupValue; + } + + private Response duplicateRecordFound(Action action, HashMap<String, String> instanceIdMap, long startTime, + MsoRequest msoRequest, InfraActiveRequests dup, String instanceName, String requestScope) { + 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.getRequestStatus() + " (RequestId - " + + dup.getRequestId() + "). 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"); + msoRequest.createRequestRecord(Status.FAILED, action); + msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, dupMessage); + msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity()); + return response; + } + + private Response beplStatusUpdate(String requestId, long startTime, MsoRequest msoRequest, + RequestClient requestClient, ResponseHandler respHandler, int bpelStatus, Action action) { + // BPMN accepted the request, the request is in progress if (bpelStatus == HttpStatus.SC_ACCEPTED) { String camundaJSONResponseBody = respHandler.getResponseBody(); - msoLogger - .debug("Received from Camunda: " + camundaJSONResponseBody); - (RequestsDatabase.getInstance()).updateInfraStatus(requestId, - Status.IN_PROGRESS.toString(), - Constants.PROGRESS_REQUEST_IN_PROGRESS, - Constants.MODIFIED_BY_APIHANDLER); - - msoLogger.recordAuditEvent(startTime, - MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, + 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, the final response is: " - + (String) camundaJSONResponseBody); - return Response.status(HttpStatus.SC_ACCEPTED) - .entity(camundaJSONResponseBody).build(); + msoLogger.debug(END_OF_THE_TRANSACTION + camundaJSONResponseBody); + return Response.status(HttpStatus.SC_ACCEPTED).entity(camundaJSONResponseBody).build(); } else { - List<String> variables = new ArrayList<String>(); + 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(), "", "", + 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 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, the final response is: " - + (String) resp.getEntity()); + 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 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.recordAuditEvent(startTime, - MsoLogger.StatusCode.ERROR, - MsoLogger.ResponseCode.InternalError, - "Response from BPEL engine is empty"); - msoLogger - .debug("End of the transaction, the final response is: " - + (String) resp.getEntity()); + msoLogger.debug(END_OF_THE_TRANSACTION + (String) resp.getEntity()); return resp; } } } - private RecipeLookupResult getServiceInstanceOrchestrationURI( - CatalogDatabase db, E2EServiceInstanceRequest sir, Action action) { - - RecipeLookupResult recipeLookupResult = null; + /** + * Getting recipes from catalogDb + * + * @param db + * @param action + * @return + */ + private RecipeLookupResult getServiceInstanceOrchestrationURI(CatalogDatabase db, Action action) { - recipeLookupResult = getServiceURI(db, sir, action); + RecipeLookupResult recipeLookupResult = getServiceURI(db, action); if (recipeLookupResult != null) { - msoLogger.debug ("Orchestration URI is: " + recipeLookupResult.getOrchestrationURI() + ", recipe Timeout is: " + Integer.toString(recipeLookupResult.getRecipeTimeout ())); - } - else { + msoLogger.debug("Orchestration URI is: " + recipeLookupResult.getOrchestrationURI() + + ", recipe Timeout is: " + Integer.toString(recipeLookupResult.getRecipeTimeout())); + } else { msoLogger.debug("No matching recipe record found"); } return recipeLookupResult; } - private RecipeLookupResult getServiceURI(CatalogDatabase db, - E2EServiceInstanceRequest sir, Action action) { + /** + * Getting recipes from catalogDb + * + * @param db + * @param action + * @return + */ + private RecipeLookupResult getServiceURI(CatalogDatabase db, Action action) { String defaultServiceModelName = "UUI_DEFAULT"; - Service serviceRecord = null; - ServiceRecipe recipe = null; - - serviceRecord = db.getServiceByModelName(defaultServiceModelName); - recipe = db.getServiceRecipeByModelUUID(serviceRecord.getModelUUID(), action.name()); + Service serviceRecord = db.getServiceByModelName(defaultServiceModelName); + ServiceRecipe recipe = db.getServiceRecipeByModelUUID(serviceRecord.getModelUUID(), action.name()); if (recipe == null) { return null; } - return new RecipeLookupResult(recipe.getOrchestrationUri(), - recipe.getRecipeTimeout()); + return new RecipeLookupResult(recipe.getOrchestrationUri(), recipe.getRecipeTimeout()); } - private String mappingObtainedRequestJSONToServiceInstanceRequest(E2EServiceInstanceRequest e2eSir){ + /** + * Converting E2EServiceInstanceRequest to ServiceInstanceRequest and + * passing it to camunda engine. + * + * @param e2eSir + * @return + */ + private String mapReqJsonToSvcInstReq(E2EServiceInstanceRequest e2eSir, String requestJSON) { - ServiceInstancesRequest sir = new ServiceInstancesRequest(); + sir = new ServiceInstancesRequest(); String returnString = null; RequestDetails requestDetails = new RequestDetails(); ModelInfo modelInfo = new ModelInfo(); - - //ModelInvariantId + + // ModelInvariantId modelInfo.setModelInvariantId(e2eSir.getService().getServiceDefId()); - - //modelNameVersionId + + // modelNameVersionId modelInfo.setModelNameVersionId(e2eSir.getService().getTemplateId()); - - String modelInfoValue = e2eSir.getService().getParameters().getNodeTemplateName(); - String[] arrayOfInfo = modelInfoValue.split(":"); - String modelName = arrayOfInfo[0]; - String modelVersion = arrayOfInfo[1]; - - //modelName + +// 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 + + // modelVersion modelInfo.setModelVersion(modelVersion); - - //modelType - //if(ModelType.service.equals(e2eSir.getService().getParameters().getNodeType())){ - modelInfo.setModelType(ModelType.service); - //} - - //setting modelInfo to requestDetails + + // modelType + modelInfo.setModelType(ModelType.service); + + // setting modelInfo to requestDetails requestDetails.setModelInfo(modelInfo); - + SubscriberInfo subscriberInfo = new SubscriberInfo(); - //globalsubscriberId + // globalsubscriberId subscriberInfo.setGlobalSubscriberId(e2eSir.getService().getParameters().getGlobalSubscriberId()); - //subscriberName + // subscriberName subscriberInfo.setSubscriberName(e2eSir.getService().getParameters().getSubscriberName()); - - //setting subscriberInfo to requestDetails + + // setting subscriberInfo to requestDetails requestDetails.setSubscriberInfo(subscriberInfo); - + RequestInfo requestInfo = new RequestInfo(); - - //instanceName + + // instanceName requestInfo.setInstanceName(e2eSir.getService().getName()); - //source + // source requestInfo.setSource("UUI"); - //suppressRollback + // suppressRollback requestInfo.setSuppressRollback(true); - //setting requestInfo to requestDetails + // setting requestInfo to requestDetails requestDetails.setRequestInfo(requestInfo); - + RequestParameters requestParameters = new RequestParameters(); - - //subscriptionServiceType + + // subscriptionServiceType requestParameters.setSubscriptionServiceType("MOG"); - //Userparams + // Userparams List<E2EUserParam> userParams; - userParams = e2eSir.getService().getParameters().getRequestParameters().getUserParams(); + //userParams = e2eSir.getService().getParameters().getRequestParameters().getUserParams(); List<Map<String, String>> userParamList = new ArrayList<>(); - Map<String,String> userParamMap= new HashMap<>(); - for(E2EUserParam userp: userParams){ - userParamMap.put(userp.getName(), userp.getValue()); - userParamList.add(userParamMap); - } - + 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 + + // setting requestParameters to requestDetails requestDetails.setRequestParameters(requestParameters); - + sir.setRequestDetails(requestDetails); - //converting to string + // converting to string ObjectMapper mapper = new ObjectMapper(); try { returnString = mapper.writeValueAsString(sir); @@ -507,4 +759,73 @@ public class E2EServiceInstances { return returnString; } + + + private void createOperationStatusRecordForError(Action action, String requestId) { + + 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(""); + os.setFinishedAt(new Timestamp(System.currentTimeMillis())); + os.setOperateAt(new Timestamp(System.currentTimeMillis())); + + 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); + } finally { + if (null != session) { + session.close(); + } + } + } + private void createOperationStatusRecord(String actionNm, String serviceId, String operationId) { + + 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(""); + os.setFinishedAt(new Timestamp(System.currentTimeMillis())); + os.setOperateAt(new Timestamp(System.currentTimeMillis())); + + 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); + } finally { + if (null != session) { + session.close(); + } + } + } }
\ No newline at end of file diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/Messages.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/Messages.java index 91bf2df48c..746493c194 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/Messages.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/Messages.java @@ -28,7 +28,7 @@ import org.openecomp.mso.apihandler.common.ErrorNumbers; public class Messages { - public static final Map<String,String> errors = new HashMap<>(); + protected static final Map<String,String> errors = new HashMap<>(); static { errors.put(ErrorNumbers.REQUEST_FAILED_SCHEMA_VALIDATION + "_service", "Service request FAILED schema validation. %s"); errors.put(ErrorNumbers.REQUEST_FAILED_SCHEMA_VALIDATION + "_feature", "Feature request FAILED schema validation. %s"); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/OrchestrationRequests.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/OrchestrationRequests.java index fb507a69cf..2f32e80dc1 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/OrchestrationRequests.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/OrchestrationRequests.java @@ -54,6 +54,7 @@ import org.openecomp.mso.logger.MessageEnum; import org.openecomp.mso.logger.MsoAlarmLogger; import org.openecomp.mso.logger.MsoLogger; import org.openecomp.mso.requestsdb.InfraActiveRequests; +import org.openecomp.mso.requestsdb.OperationStatus; import org.openecomp.mso.requestsdb.RequestsDatabase; import com.wordnik.swagger.annotations.Api; @@ -133,60 +134,7 @@ public class OrchestrationRequests { return Response.status(200).entity(orchestrationResponse).build(); } - @GET - @Path("e2eServiceInstances/{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) { - - GetE2EServiceInstanceResponse e2eServiceResponse = new GetE2EServiceInstanceResponse(); - - MsoRequest msoRequest = new MsoRequest(serviceId); - - long startTime = System.currentTimeMillis(); - - InfraActiveRequests requestDB = null; - - try { - requestDB = requestsDB.getRequestFromInfraActive(serviceId); - - } 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 (requestDB == 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; - - } - - E2ERequest e2erequest = mapInfraActiveRequestToE2ERequest(requestDB); - - e2eServiceResponse.setE2eRequest(e2erequest); - - return Response.status(200).entity(e2eServiceResponse).build(); - } + @GET @Path("orchestrationRequests/{version:[vV][2-5]}") @@ -243,7 +191,7 @@ public class OrchestrationRequests { } @POST - @Path("/{version: [vV][3-5]}/{requestId}/unlock") + @Path("orchestrationRequests/{version: [vV][3-5]}/{requestId}/unlock") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "Unlock Orchestrated Requests for a given requestId", response = Response.class) @@ -438,29 +386,4 @@ public class OrchestrationRequests { return request; } - private E2ERequest mapInfraActiveRequestToE2ERequest(InfraActiveRequests requestDB) { - - E2ERequest e2erequest = new E2ERequest(); - - e2erequest.setOperationId(requestDB.getRequestId()); - // e2erequest.setRequestScope(requestDB.getRequestScope()); - e2erequest.setOperation(requestDB.getRequestAction()); - e2erequest.setResult(requestDB.getRequestStatus()); - e2erequest.setReason(requestDB.getStatusMessage()); - e2erequest.setUserId(requestDB.getRequestorId()); - e2erequest.setOperationContent(requestDB.getStatusMessage()); - e2erequest.setProgress(requestDB.getProgress()); - - String startTimeStamp = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(requestDB.getStartTime()) - + " GMT"; - e2erequest.setOperateAt(startTimeStamp); - - if (requestDB.getEndTime() != null) { - String endTimeStamp = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(requestDB.getEndTime()) - + " GMT"; - e2erequest.setFinishedAt(endTimeStamp); - } - - return e2erequest; - } }
\ No newline at end of file diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/TasksHandler.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/TasksHandler.java index 1e8bea0c55..92e3e5b078 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/TasksHandler.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/TasksHandler.java @@ -86,7 +86,7 @@ public class TasksHandler { // Prepare the query string to /task interface TaskVariables tv = new TaskVariables(); - List<TaskVariableValue> tvvList = new ArrayList<TaskVariableValue>(); + List<TaskVariableValue> tvvList = new ArrayList<>(); if (originalRequestId != null) { TaskVariableValue tvv = new TaskVariableValue(); @@ -168,7 +168,7 @@ public class TasksHandler { return resp; } TasksGetResponse trr = new TasksGetResponse(); - List<TaskList> taskList = new ArrayList<TaskList>(); + List<TaskList> taskList = new ArrayList<>(); ResponseHandler respHandler = new ResponseHandler (response, requestClient.getType ()); int bpelStatus = respHandler.getStatus (); @@ -250,7 +250,6 @@ public class TasksHandler { msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successful"); responseBack = Response.status (HttpStatus.SC_ACCEPTED).entity (jsonResponse).build (); - // msoLogger.debug ("End of the transaction, the final response is: " + (String) response.getEntity ()); return responseBack; } @@ -261,9 +260,9 @@ public class TasksHandler { // Makes a GET call to Camunda to get variables for this task private TaskList getTaskInfo(String taskId) throws Exception { - TaskList taskList = null; + TaskList taskList; String getRequestUrl = requestUrl + taskId + "/variables"; - HttpResponse getResponse = null; + HttpResponse getResponse; long subStartTime = System.currentTimeMillis(); RequestClient requestClient = RequestClientFactory.getRequestClient (getRequestUrl, MsoPropertiesUtils.loadMsoProperties ()); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/e2eserviceinstancebeans/DelE2ESvcResp.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/e2eserviceinstancebeans/DelE2ESvcResp.java new file mode 100644 index 0000000000..c05b0977ba --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/e2eserviceinstancebeans/DelE2ESvcResp.java @@ -0,0 +1,37 @@ +/*- + * ============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.e2eserviceinstancebeans; + +import org.codehaus.jackson.map.annotate.JsonSerialize; + +@JsonSerialize(include = JsonSerialize.Inclusion.NON_DEFAULT) +public class DelE2ESvcResp { + + private String operationId; + + public String getOperationId() { + return operationId; + } + + public void setOperationId(String operationId) { + this.operationId = operationId; + } +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/e2eserviceinstancebeans/E2EParameters.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/e2eserviceinstancebeans/E2EParameters.java index 0e2067e448..bcad1f33cc 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/e2eserviceinstancebeans/E2EParameters.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/e2eserviceinstancebeans/E2EParameters.java @@ -21,6 +21,7 @@ package org.openecomp.mso.apihandlerinfra.e2eserviceinstancebeans; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.codehaus.jackson.annotate.JsonIgnore; @@ -30,52 +31,55 @@ import org.codehaus.jackson.annotate.JsonProperty; @JsonIgnoreProperties({ "additionalProperties" }) public class E2EParameters { - @JsonProperty("domainHost") - private String domainHost; - - @JsonProperty("nodeTemplateName") - private String nodeTemplateName; - - @JsonProperty("nodeType") - private String nodeType; - @JsonProperty("globalSubscriberId") private String globalSubscriberId; @JsonProperty("subscriberName") private String subscriberName; + + @JsonProperty("serviceType") + private String serviceType; + + @JsonProperty("templateName") + private String templateName; + - @JsonProperty("requestParameters") - private E2ERequestParameters requestParameters; + @JsonProperty("resources") + private List<ResourceRequest> resources; @JsonIgnore private Map<String, Object> additionalProperties = new HashMap<>(); - public String getDomainHost() { - return domainHost; - } - - public void setDomainHost(String domainHost) { - this.domainHost = domainHost; - } - - public String getNodeTemplateName() { - return nodeTemplateName; - } - - public void setNodeTemplateName(String nodeTemplateName) { - this.nodeTemplateName = nodeTemplateName; - } - - public String getNodeType() { - return nodeType; - } - - public void setNodeType(String nodeType) { - this.nodeType = nodeType; - } - - public String getGlobalSubscriberId() { + + /** + * @return Returns the serviceType. + */ + public String getServiceType() { + return serviceType; + } + + /** + * @param serviceType The serviceType to set. + */ + public void setServiceType(String serviceType) { + this.serviceType = serviceType; + } + + /** + * @return Returns the templateName. + */ + public String getTemplateName() { + return templateName; + } + + /** + * @param templateName The templateName to set. + */ + public void setTemplateName(String templateName) { + this.templateName = templateName; + } + + public String getGlobalSubscriberId() { return globalSubscriberId; } @@ -91,14 +95,6 @@ public class E2EParameters { this.subscriberName = subscriberName; } - public E2ERequestParameters getRequestParameters() { - return requestParameters; - } - - public void setRequestParameters(E2ERequestParameters requestParameters) { - this.requestParameters = requestParameters; - } - public Map<String, Object> getAdditionalProperties() { return additionalProperties; } @@ -106,5 +102,19 @@ public class E2EParameters { public void setAdditionalProperties(Map<String, Object> additionalProperties) { this.additionalProperties = additionalProperties; } + + /** + * @return Returns the resources. + */ + public List<ResourceRequest> getResources() { + return resources; + } + + /** + * @param resources The resources to set. + */ + public void setResources(List<ResourceRequest> resources) { + this.resources = resources; + } } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/e2eserviceinstancebeans/E2EServiceInstanceDeleteRequest.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/e2eserviceinstancebeans/E2EServiceInstanceDeleteRequest.java new file mode 100644 index 0000000000..157ee72535 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/e2eserviceinstancebeans/E2EServiceInstanceDeleteRequest.java @@ -0,0 +1,46 @@ +/*-
+ * ============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.e2eserviceinstancebeans;
+
+
+public class E2EServiceInstanceDeleteRequest {
+
+ private String globalSubscriberId;
+
+ private String serviceType;
+
+ public String getGlobalSubscriberId() {
+ return globalSubscriberId;
+ }
+
+ public void setGlobalSubscriberId(String globalSubscriberId) {
+ this.globalSubscriberId = globalSubscriberId;
+ }
+
+ public String getServiceType() {
+ return serviceType;
+ }
+
+ public void setServiceType(String serviceType) {
+ this.serviceType = serviceType;
+ }
+
+}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/e2eserviceinstancebeans/GetE2EServiceInstanceResponse.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/e2eserviceinstancebeans/GetE2EServiceInstanceResponse.java index 8145afca6d..4c749b7e58 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/e2eserviceinstancebeans/GetE2EServiceInstanceResponse.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/e2eserviceinstancebeans/GetE2EServiceInstanceResponse.java @@ -22,18 +22,19 @@ package org.openecomp.mso.apihandlerinfra.e2eserviceinstancebeans;
import org.codehaus.jackson.map.annotate.JsonSerialize;
+import org.openecomp.mso.requestsdb.OperationStatus;
@JsonSerialize(include=JsonSerialize.Inclusion.NON_DEFAULT)
public class GetE2EServiceInstanceResponse {
- protected E2ERequest e2eRequest;
+ protected OperationStatus e2eRequest;
- public E2ERequest getE2eRequest() {
+ public OperationStatus getE2eRequest() {
return e2eRequest;
}
- public void setE2eRequest(E2ERequest e2eRequest) {
- this.e2eRequest = e2eRequest;
+ public void setE2eRequest(OperationStatus requestDB) {
+ this.e2eRequest = requestDB;
}
}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/e2eserviceinstancebeans/LocationConstraint.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/e2eserviceinstancebeans/LocationConstraint.java new file mode 100644 index 0000000000..c4c0c534ac --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/e2eserviceinstancebeans/LocationConstraint.java @@ -0,0 +1,72 @@ +/*- + * ============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.e2eserviceinstancebeans; + +/** + * <br> + * <p> + * </p> + * + * @author + * @version ONAP Amsterdam Release 2017-9-6 + */ +public class LocationConstraint { + + /** + * vnf profile id + */ + private String vnfProfileId; + + /** + * location constraints: vimId + */ + private VimLocation locationConstraints; + + /** + * @return Returns the vnfProfileId. + */ + public String getVnfProfileId() { + return vnfProfileId; + } + + /** + * @param vnfProfileId The vnfProfileId to set. + */ + public void setVnfProfileId(String vnfProfileId) { + this.vnfProfileId = vnfProfileId; + } + + + /** + * @return Returns the locationConstraints. + */ + public VimLocation getLocationConstraints() { + return locationConstraints; + } + + + /** + * @param locationConstraints The locationConstraints to set. + */ + public void setLocationConstraints(VimLocation locationConstraints) { + this.locationConstraints = locationConstraints; + } + +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/e2eserviceinstancebeans/E2ERequestParameters.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/e2eserviceinstancebeans/NsParameters.java index ae8fe808f2..6121e47f83 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/e2eserviceinstancebeans/E2ERequestParameters.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/e2eserviceinstancebeans/NsParameters.java @@ -7,9 +7,9 @@ * 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. @@ -17,49 +17,52 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.mso.apihandlerinfra.e2eserviceinstancebeans; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.codehaus.jackson.annotate.JsonIgnore; -import org.codehaus.jackson.annotate.JsonProperty; - -public class E2ERequestParameters { - - @JsonProperty("subscriptionServiceType") - private String subscriptionServiceType; - - @JsonProperty("userParams") - private List<E2EUserParam> userParams = null; - - @JsonIgnore - private Map<String, Object> additionalProperties = new HashMap<>(); - - public String getSubscriptionServiceType() { - return subscriptionServiceType; - } - - public void setSubscriptionServiceType(String subscriptionServiceType) { - this.subscriptionServiceType = subscriptionServiceType; - } +/** + * <br> + * <p> + * </p> + * + * @author + * @version ONAP Amsterdam Release 2017-9-6 + */ +public class NsParameters { - public List<E2EUserParam> getUserParams() { - return userParams; - } + private List<LocationConstraint> locationConstraints; - public void setUserParams(List<E2EUserParam> userParams) { - this.userParams = userParams; - } + private Map<String, Object> additionalParamForNs = new HashMap<String,Object>(); + /** + * @return Returns the locationConstraints. + */ + public List<LocationConstraint> getLocationConstraints() { + return locationConstraints; + } - public Map<String, Object> getAdditionalProperties() { - return additionalProperties; - } + /** + * @param locationConstraints The locationConstraints to set. + */ + public void setLocationConstraints(List<LocationConstraint> locationConstraints) { + this.locationConstraints = locationConstraints; + } - public void setAdditionalProperties(Map<String, Object> additionalProperties) { - this.additionalProperties = additionalProperties; - } + + /** + * @return Returns the additionalParamForNs. + */ + public Map<String, Object> getAdditionalParamForNs() { + return additionalParamForNs; + } + + /** + * @param additionalParamForNs The additionalParamForNs to set. + */ + public void setAdditionalParamForNs(Map<String, Object> additionalParamForNs) { + this.additionalParamForNs = additionalParamForNs; + } } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/e2eserviceinstancebeans/ResourceRequest.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/e2eserviceinstancebeans/ResourceRequest.java new file mode 100644 index 0000000000..5db3c3f73d --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/e2eserviceinstancebeans/ResourceRequest.java @@ -0,0 +1,110 @@ +/*- + * ============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.e2eserviceinstancebeans; + +import java.util.HashMap; +import java.util.Map; + +import org.codehaus.jackson.annotate.JsonIgnore; +import org.codehaus.jackson.annotate.JsonProperty; + +public class ResourceRequest { + + @JsonProperty("resourceName") + private String resourceName; + + @JsonProperty("resourceDefId") + private String resourceDefId; + + @JsonProperty("resourceId") + private String resourceId; + + @JsonProperty("nsParameters") + private NsParameters nsParameters = null; + + @JsonIgnore + private Map<String, Object> additionalProperties = new HashMap<>(); + + /** + * @return Returns the resourceName. + */ + public String getResourceName() { + return resourceName; + } + + /** + * @param resourceName The resourceName to set. + */ + public void setResourceName(String resourceName) { + this.resourceName = resourceName; + } + + /** + * @return Returns the resourceDefId. + */ + public String getResourceDefId() { + return resourceDefId; + } + + /** + * @param resourceDefId The resourceDefId to set. + */ + public void setResourceDefId(String resourceDefId) { + this.resourceDefId = resourceDefId; + } + + /** + * @return Returns the resourceId. + */ + public String getResourceId() { + return resourceId; + } + + /** + * @param resourceId The resourceId to set. + */ + public void setResourceId(String resourceId) { + this.resourceId = resourceId; + } + + /** + * @return Returns the nsParameters. + */ + public NsParameters getNsParameters() { + return nsParameters; + } + + /** + * @param nsParameters The nsParameters to set. + */ + public void setNsParameters(NsParameters nsParameters) { + this.nsParameters = nsParameters; + } + + public Map<String, Object> getAdditionalProperties() { + return additionalProperties; + } + + public void setAdditionalProperties(Map<String, Object> additionalProperties) { + this.additionalProperties = additionalProperties; + } + +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/e2eserviceinstancebeans/VimLocation.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/e2eserviceinstancebeans/VimLocation.java new file mode 100644 index 0000000000..3a72f03157 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/e2eserviceinstancebeans/VimLocation.java @@ -0,0 +1,50 @@ +/*-
+ * ============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.e2eserviceinstancebeans;
+
+/**
+ *
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version ONAP Amsterdam Release 2017-10-18
+ */
+public class VimLocation {
+ private String vimId;
+
+
+ /**
+ * @return Returns the vimId.
+ */
+ public String getVimId() {
+ return vimId;
+ }
+
+
+ /**
+ * @param vimId The vimId to set.
+ */
+ public void setVimId(String vimId) {
+ this.vimId = vimId;
+ }
+
+}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstancesTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstancesTest.java index 98a2a11800..eef597e931 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstancesTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstancesTest.java @@ -34,9 +34,13 @@ import org.apache.http.HttpResponse; import org.apache.http.ProtocolVersion;
import org.apache.http.entity.BasicHttpEntity;
import org.apache.http.message.BasicHttpResponse;
+import org.hibernate.HibernateException;
+import org.hibernate.Session;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Order;
+import org.hibernate.internal.SessionFactoryImpl;
import org.junit.Test;
+import org.mockito.Mockito;
import org.openecomp.mso.apihandler.common.CamundaClient;
import org.openecomp.mso.apihandler.common.RequestClient;
import org.openecomp.mso.apihandler.common.RequestClientFactory;
@@ -111,10 +115,10 @@ public class E2EServiceInstancesTest { };
E2EServiceInstances instance = new E2EServiceInstances();
- String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"modelInvariantId value from SDC?\",\"templateId\":\"modelVersionId value from SDC??\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"NEED THIS UUI - AAI\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}";
+ String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"templateId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"parameters\":{\"globalSubscriberId\":\"123457\", \"subscriberName\":\"Customer1\",\"serviceType\":\"voLTE\",\"templateName\":\"voLTE Service:1.0\",\"resources\":[{\"resourceName\":\"MOG\",\"resourceDefId\":\"MOG\",\"resourceId\":\"MOG\",\"nsParameters\":{\"locationConstraints\":[{\"vnfProfileId\":\"zte-vBAS-1.0\",\"locationConstraints\":{\"vimId\":\"4050083f-465f-4838-af1e-47a545222ad0\"}},{\"vnfProfileId\":\"zte-vMME-1.0\",\"locationConstraints\":{\"vimId\":\"4050083f-465f-4838-af1e-47a545222ad0\"}}],\"additionalParamForNs\":{}}}]}}}";
Response resp = instance.createE2EServiceInstance(request, "v3");
String respStr = resp.getEntity().toString();
- assertTrue(respStr.indexOf("Exception while creating record in DB null") != -1);
+ assertTrue(respStr.indexOf("success") != -1);
}
@Test
@@ -175,10 +179,10 @@ public class E2EServiceInstancesTest { };
E2EServiceInstances instance = new E2EServiceInstances();
- String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"modelInvariantId value from SDC?\",\"templateId\":\"modelVersionId value from SDC??\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"NEED THIS UUI - AAI\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}";
+ String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"templateId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"parameters\":{\"globalSubscriberId\":\"123457\", \"subscriberName\":\"Customer1\",\"serviceType\":\"voLTE\",\"templateName\":\"voLTE Service:1.0\",\"resources\":[{\"resourceName\":\"MOG\",\"resourceDefId\":\"MOG\",\"resourceId\":\"MOG\",\"nsParameters\":{\"locationConstraints\":[{\"vnfProfileId\":\"zte-vBAS-1.0\",\"locationConstraints\":{\"vimId\":\"4050083f-465f-4838-af1e-47a545222ad0\"}},{\"vnfProfileId\":\"zte-vMME-1.0\",\"locationConstraints\":{\"vimId\":\"4050083f-465f-4838-af1e-47a545222ad0\"}}],\"additionalParamForNs\":{}}}]}}}";
Response resp = instance.createE2EServiceInstance(request, "v3");
String respStr = resp.getEntity().toString();
- assertTrue(respStr.indexOf("Exception while creating record in DB null") != -1);
+ assertTrue(respStr.indexOf("SVC2000") != -1);
}
@Test
@@ -239,10 +243,10 @@ public class E2EServiceInstancesTest { };
E2EServiceInstances instance = new E2EServiceInstances();
- String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"modelInvariantId value from SDC?\",\"templateId\":\"modelVersionId value from SDC??\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"NEED THIS UUI - AAI\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}";
+ String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"templateId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"parameters\":{\"globalSubscriberId\":\"123457\", \"subscriberName\":\"Customer1\",\"serviceType\":\"voLTE\",\"templateName\":\"voLTE Service:1.0\",\"resources\":[{\"resourceName\":\"MOG\",\"resourceDefId\":\"MOG\",\"resourceId\":\"MOG\",\"nsParameters\":{\"locationConstraints\":[{\"vnfProfileId\":\"zte-vBAS-1.0\",\"locationConstraints\":{\"vimId\":\"4050083f-465f-4838-af1e-47a545222ad0\"}},{\"vnfProfileId\":\"zte-vMME-1.0\",\"locationConstraints\":{\"vimId\":\"4050083f-465f-4838-af1e-47a545222ad0\"}}],\"additionalParamForNs\":{}}}]}}}";
Response resp = instance.createE2EServiceInstance(request, "v3");
String respStr = resp.getEntity().toString();
- assertTrue(respStr.indexOf("Exception while creating record in DB null") != -1);
+ assertTrue(respStr.indexOf("SVC2000") != -1);
}
@Test
@@ -291,10 +295,10 @@ public class E2EServiceInstancesTest { };
E2EServiceInstances instance = new E2EServiceInstances();
- String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"modelInvariantId value from SDC?\",\"templateId\":\"modelVersionId value from SDC??\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"NEED THIS UUI - AAI\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}";
+ String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"templateId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"parameters\":{\"globalSubscriberId\":\"123457\", \"subscriberName\":\"Customer1\",\"serviceType\":\"voLTE\",\"templateName\":\"voLTE Service:1.0\",\"resources\":[{\"resourceName\":\"MOG\",\"resourceDefId\":\"MOG\",\"resourceId\":\"MOG\",\"nsParameters\":{\"locationConstraints\":[{\"vnfProfileId\":\"zte-vBAS-1.0\",\"locationConstraints\":{\"vimId\":\"4050083f-465f-4838-af1e-47a545222ad0\"}},{\"vnfProfileId\":\"zte-vMME-1.0\",\"locationConstraints\":{\"vimId\":\"4050083f-465f-4838-af1e-47a545222ad0\"}}],\"additionalParamForNs\":{}}}]}}}";
Response resp = instance.createE2EServiceInstance(request, "v3");
String respStr = resp.getEntity().toString();
- assertTrue(respStr.indexOf("Exception while creating record in DB null") != -1);
+ assertTrue(respStr.indexOf("SVC1000") != -1);
}
@Test
@@ -340,10 +344,10 @@ public class E2EServiceInstancesTest { };
E2EServiceInstances instance = new E2EServiceInstances();
- String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"modelInvariantId value from SDC?\",\"templateId\":\"modelVersionId value from SDC??\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"NEED THIS UUI - AAI\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}";
+ String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"templateId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"parameters\":{\"globalSubscriberId\":\"123457\", \"subscriberName\":\"Customer1\",\"serviceType\":\"voLTE\",\"templateName\":\"voLTE Service:1.0\",\"resources\":[{\"resourceName\":\"MOG\",\"resourceDefId\":\"MOG\",\"resourceId\":\"MOG\",\"nsParameters\":{\"locationConstraints\":[{\"vnfProfileId\":\"zte-vBAS-1.0\",\"locationConstraints\":{\"vimId\":\"4050083f-465f-4838-af1e-47a545222ad0\"}},{\"vnfProfileId\":\"zte-vMME-1.0\",\"locationConstraints\":{\"vimId\":\"4050083f-465f-4838-af1e-47a545222ad0\"}}],\"additionalParamForNs\":{}}}]}}}";
Response resp = instance.createE2EServiceInstance(request, "v3");
String respStr = resp.getEntity().toString();
- assertTrue(respStr.indexOf("Exception while creating record in DB null") != -1);
+ assertTrue(respStr.indexOf("SVC1000") != -1);
}
@Test
@@ -370,10 +374,10 @@ public class E2EServiceInstancesTest { }
};
E2EServiceInstances instance = new E2EServiceInstances();
- String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"modelInvariantId value from SDC?\",\"templateId\":\"modelVersionId value from SDC??\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"NEED THIS UUI - AAI\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}";
+ String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"templateId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"parameters\":{\"globalSubscriberId\":\"123457\", \"subscriberName\":\"Customer1\",\"serviceType\":\"voLTE\",\"templateName\":\"voLTE Service:1.0\",\"resources\":[{\"resourceName\":\"MOG\",\"resourceDefId\":\"MOG\",\"resourceId\":\"MOG\",\"nsParameters\":{\"locationConstraints\":[{\"vnfProfileId\":\"zte-vBAS-1.0\",\"locationConstraints\":{\"vimId\":\"4050083f-465f-4838-af1e-47a545222ad0\"}},{\"vnfProfileId\":\"zte-vMME-1.0\",\"locationConstraints\":{\"vimId\":\"4050083f-465f-4838-af1e-47a545222ad0\"}}],\"additionalParamForNs\":{}}}]}}}";
Response resp = instance.createE2EServiceInstance(request, "v3");
String respStr = resp.getEntity().toString();
- assertTrue(respStr.indexOf("Exception while creating record in DB null") != -1);
+ assertTrue(respStr.indexOf("SVC1000") != -1);
}
@Test
@@ -401,7 +405,7 @@ public class E2EServiceInstancesTest { }
};
E2EServiceInstances instance = new E2EServiceInstances();
- String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"modelInvariantId value from SDC?\",\"templateId\":\"modelVersionId value from SDC??\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"NEED THIS UUI - AAI\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}";
+ String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"templateId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}";
Response resp = instance.createE2EServiceInstance(request, "v3");
String respStr = resp.getEntity().toString();
//assertTrue(respStr.indexOf("Recipe could not be retrieved from catalog DB ") !=-1);
@@ -422,10 +426,10 @@ public class E2EServiceInstancesTest { }
};
E2EServiceInstances instance = new E2EServiceInstances();
- String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"modelInvariantId value from SDC?\",\"templateId\":\"modelVersionId value from SDC??\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"NEED THIS UUI - AAI\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}";
+ String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"templateId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"parameters\":{\"globalSubscriberId\":\"123457\", \"subscriberName\":\"Customer1\",\"serviceType\":\"voLTE\",\"templateName\":\"voLTE Service:1.0\",\"resources\":[{\"resourceName\":\"MOG\",\"resourceDefId\":\"MOG\",\"resourceId\":\"MOG\",\"nsParameters\":{\"locationConstraints\":[{\"vnfProfileId\":\"zte-vBAS-1.0\",\"locationConstraints\":{\"vimId\":\"4050083f-465f-4838-af1e-47a545222ad0\"}},{\"vnfProfileId\":\"zte-vMME-1.0\",\"locationConstraints\":{\"vimId\":\"4050083f-465f-4838-af1e-47a545222ad0\"}}],\"additionalParamForNs\":{}}}]}}}";
Response resp = instance.createE2EServiceInstance(request, "v3");
String respStr = resp.getEntity().toString();
- assertTrue(respStr.indexOf("The existing request must finish or be cleaned up before proceeding.") != -1);
+ assertTrue(respStr.indexOf("SVC1000") != -1);
}
@Test
@@ -437,7 +441,7 @@ public class E2EServiceInstancesTest { }
};
E2EServiceInstances instance = new E2EServiceInstances();
- String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"modelInvariantId value from SDC?\",\"templateId\":\"modelVersionId value from SDC??\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"NEED THIS UUI - AAI\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}";
+ String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"templateId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}";
Response resp = instance.createE2EServiceInstance(request, "v3");
String respStr = resp.getEntity().toString();
//assertTrue(respStr.indexOf("Recipe could not be retrieved from catalog DB ") != -1);
@@ -447,10 +451,10 @@ public class E2EServiceInstancesTest { @Test
public void createE2EServiceInstanceTestDBQueryFail(){
E2EServiceInstances instance = new E2EServiceInstances();
- String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"modelInvariantId value from SDC?\",\"templateId\":\"modelVersionId value from SDC??\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"NEED THIS UUI - AAI\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}";
+ String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"templateId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"parameters\":{\"globalSubscriberId\":\"123457\", \"subscriberName\":\"Customer1\",\"serviceType\":\"voLTE\",\"templateName\":\"voLTE Service:1.0\",\"resources\":[{\"resourceName\":\"MOG\",\"resourceDefId\":\"MOG\",\"resourceId\":\"MOG\",\"nsParameters\":{\"locationConstraints\":[{\"vnfProfileId\":\"zte-vBAS-1.0\",\"locationConstraints\":{\"vimId\":\"4050083f-465f-4838-af1e-47a545222ad0\"}},{\"vnfProfileId\":\"zte-vMME-1.0\",\"locationConstraints\":{\"vimId\":\"4050083f-465f-4838-af1e-47a545222ad0\"}}],\"additionalParamForNs\":{}}}]}}}";
Response resp = instance.createE2EServiceInstance(request, "v3");
String respStr = resp.getEntity().toString();
- assertTrue(respStr.indexOf("SVC2000") != -1);
+ assertTrue(respStr.indexOf("SVC1000") != -1);
}
@Test
@@ -465,9 +469,9 @@ public class E2EServiceInstancesTest { @Test
public void deleteE2EServiceInstanceTestNormal(){
E2EServiceInstances instance = new E2EServiceInstances();
- String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"modelInvariantId value from SDC?\",\"templateId\":\"modelVersionId value from SDC??\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"NEED THIS UUI - AAI\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}";
+ String request = "{\"globalSubscriberId\":\"299392392\",\"serviceType\":\"VoLTE\"}";
Response resp = instance.deleteE2EServiceInstance(request, "v3", "12345678");
String respStr = resp.getEntity().toString();
- assertTrue(respStr.indexOf("SVC2000") != -1);
+ assertTrue(respStr.indexOf("SVC1000") != -1);
}
}
diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/OperationStatus.java b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/OperationStatus.java index 010b79d38d..ddf6b44cc2 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/OperationStatus.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/OperationStatus.java @@ -19,6 +19,7 @@ */
package org.openecomp.mso.requestsdb;
+import java.io.Serializable;
import java.sql.Timestamp;
/**
@@ -30,12 +31,19 @@ import java.sql.Timestamp; * @author
* @version ONAP Amsterdam Release 2017-08-28
*/
-public class OperationStatus {
+public class OperationStatus implements Serializable{
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
private String serviceId;
private String operationId;
+ private String serviceName;
+
private String operation;
private String userId;
@@ -152,4 +160,69 @@ public class OperationStatus { this.finishedAt = finishedAt;
}
+
+
+ /**
+ * @return Returns the serviceName.
+ */
+ public String getServiceName() {
+ return serviceName;
+ }
+
+
+
+ /**
+ * @param serviceName The serviceName to set.
+ */
+ public void setServiceName(String serviceName) {
+ this.serviceName = serviceName;
+ }
+
+
+ /**
+ * <br>
+ *
+ * @return
+ * @since ONAP Amsterdam Release
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((operationId == null) ? 0 : operationId.hashCode());
+ result = prime * result + ((serviceId == null) ? 0 : serviceId.hashCode());
+ return result;
+ }
+
+
+ /**
+ * <br>
+ *
+ * @param obj
+ * @return
+ * @since ONAP Amsterdam Release
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if(this == obj)
+ return true;
+ if(obj == null)
+ return false;
+ if(getClass() != obj.getClass())
+ return false;
+ OperationStatus other = (OperationStatus)obj;
+ if(operationId == null) {
+ if(other.operationId != null)
+ return false;
+ } else if(!operationId.equals(other.operationId))
+ return false;
+ if(serviceId == null) {
+ if(other.serviceId != null)
+ return false;
+ } else if(!serviceId.equals(other.serviceId))
+ return false;
+ return true;
+ }
+
+
}
diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/RequestsDatabase.java b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/RequestsDatabase.java index b426c39176..c6f0cea993 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/RequestsDatabase.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/RequestsDatabase.java @@ -647,7 +647,7 @@ public class RequestsDatabase { + operStatus.getResourceTemplateUUID()); try { String hql = - "FROM ResourceOperationStatus WHERE SERVICE_ID = :service_id and OPERATION_ID = :operation_id and RESOURCE_TEMPLATE_UUID = : res_uuid"; + "FROM ResourceOperationStatus WHERE SERVICE_ID = :service_id and OPERATION_ID = :operation_id and RESOURCE_TEMPLATE_UUID = :res_uuid"; Query query = session.createQuery(hql); query.setParameter("service_id", operStatus.getServiceId()); query.setParameter("operation_id", operStatus.getOperationId()); diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/ResourceOperationStatus.java b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/ResourceOperationStatus.java index 298eb9cf4b..2e91397d14 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/ResourceOperationStatus.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/ResourceOperationStatus.java @@ -19,6 +19,8 @@ */
package org.openecomp.mso.requestsdb;
+import java.io.Serializable;
+
/**
* The Resource operation status
* <br>
@@ -28,7 +30,12 @@ package org.openecomp.mso.requestsdb; * @author
* @version ONAP Amsterdam Release 2017-08-28
*/
-public class ResourceOperationStatus {
+public class ResourceOperationStatus implements Serializable{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
private String serviceId;
@@ -161,6 +168,55 @@ public class ResourceOperationStatus { public void setOperType(String operType) {
this.operType = operType;
}
-
+
+ /**
+ * <br>
+ *
+ * @return
+ * @since ONAP Amsterdam Release
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((operationId == null) ? 0 : operationId.hashCode());
+ result = prime * result + ((resourceTemplateUUID == null) ? 0 : resourceTemplateUUID.hashCode());
+ result = prime * result + ((serviceId == null) ? 0 : serviceId.hashCode());
+ return result;
+ }
+
+ /**
+ * <br>
+ *
+ * @param obj
+ * @return
+ * @since ONAP Amsterdam Release
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if(this == obj)
+ return true;
+ if(obj == null)
+ return false;
+ if(getClass() != obj.getClass())
+ return false;
+ ResourceOperationStatus other = (ResourceOperationStatus)obj;
+ if(operationId == null) {
+ if(other.operationId != null)
+ return false;
+ } else if(!operationId.equals(other.operationId))
+ return false;
+ if(resourceTemplateUUID == null) {
+ if(other.resourceTemplateUUID != null)
+ return false;
+ } else if(!resourceTemplateUUID.equals(other.resourceTemplateUUID))
+ return false;
+ if(serviceId == null) {
+ if(other.serviceId != null)
+ return false;
+ } else if(!serviceId.equals(other.serviceId))
+ return false;
+ return true;
+ }
}
diff --git a/mso-api-handlers/mso-requests-db/src/main/resources/OperationStatus.hbm.xml b/mso-api-handlers/mso-requests-db/src/main/resources/OperationStatus.hbm.xml index f00c2da408..a433ab5a8b 100644 --- a/mso-api-handlers/mso-requests-db/src/main/resources/OperationStatus.hbm.xml +++ b/mso-api-handlers/mso-requests-db/src/main/resources/OperationStatus.hbm.xml @@ -28,8 +28,11 @@ <meta attribute="class-description"> This class describes a operation status </meta> - <id name="serviceId" type="string" column="SERVICE_ID"/> - <id name="operationId" column="OPERATION_ID" type="string" length="256"/> + <composite-id> + <key-property name="serviceId" type="string" column="SERVICE_ID"/> + <key-property name="operationId" column="OPERATION_ID" type="string" length="256"/> + </composite-id> + <property name="serviceName" column="SERVICE_NAME" type="string" length="256"/> <property name="operation" column="OPERATION_TYPE" type="string" length="256"/> <property name="userId" column="USER_ID" type="string" length="256"/> <property name="result" column="RESULT" type="string" length="256"/> @@ -39,6 +42,6 @@ <property name="operateAt" type="timestamp" generated="insert" insert="false" update="false" not-null="true"> <column name="OPERATE_AT" default="CURRENT_TIMESTAMP"/> </property> - <property name="finishedAt" column="FINISHED_AT" type="timestamp" generated="update" insert="false" update="false"/> + <property name="finishedAt" column="FINISHED_AT" type="timestamp" generated="always" insert="false" update="false"/> </class> </hibernate-mapping> diff --git a/mso-api-handlers/mso-requests-db/src/main/resources/ResourceOperationStatus.hbm.xml b/mso-api-handlers/mso-requests-db/src/main/resources/ResourceOperationStatus.hbm.xml index 87e23980d6..22d147402d 100644 --- a/mso-api-handlers/mso-requests-db/src/main/resources/ResourceOperationStatus.hbm.xml +++ b/mso-api-handlers/mso-requests-db/src/main/resources/ResourceOperationStatus.hbm.xml @@ -28,9 +28,11 @@ <meta attribute="class-description"> This class describes a progress status </meta> - <id name="serviceId" type="string" column="SERVICE_ID"/> - <id name="operationId" column="OPERATION_ID" type="string" length="256"/> - <id name="resourceTemplateUUID" type="string" column="RESOURCE_TEMPLATE_UUID"/> + <composite-id> + <key-property name="serviceId" type="string" column="SERVICE_ID"/> + <key-property name="operationId" type="string" column="OPERATION_ID" length="256"/> + <key-property name="resourceTemplateUUID" type="string" column="RESOURCE_TEMPLATE_UUID"/> + </composite-id> <property name="operType" column="OPER_TYPE" type="string" length="256"/> <property name="resourceInstanceID" column="RESOURCE_INSTANCE_ID" type="string" length="256"/> <property name="jobId" column="JOB_ID" type="string" length="256"/> diff --git a/mso-api-handlers/mso-requests-db/src/main/resources/hibernate-requests-core-mysql.cfg.xml b/mso-api-handlers/mso-requests-db/src/main/resources/hibernate-requests-core-mysql.cfg.xml index 531b77196c..edf8333016 100644 --- a/mso-api-handlers/mso-requests-db/src/main/resources/hibernate-requests-core-mysql.cfg.xml +++ b/mso-api-handlers/mso-requests-db/src/main/resources/hibernate-requests-core-mysql.cfg.xml @@ -33,5 +33,7 @@ <mapping resource="InfraActiveRequests.hbm.xml"></mapping> <mapping resource="SiteStatus.hbm.xml"></mapping> + <mapping resource="OperationStatus.hbm.xml"></mapping> + <mapping resource="ResourceOperationStatus.hbm.xml"></mapping> </session-factory> </hibernate-configuration> |