diff options
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra')
13 files changed, 277 insertions, 345 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/E2EServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/E2EServiceInstances.java index be1131ed78..84cac6ce5c 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/E2EServiceInstances.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/E2EServiceInstances.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved. * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ * 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 @@ -25,6 +27,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.UUID; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; @@ -69,7 +72,8 @@ import org.onap.so.serviceinstancebeans.RequestInfo; import org.onap.so.serviceinstancebeans.RequestParameters; import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; import org.onap.so.serviceinstancebeans.SubscriberInfo; -import org.onap.so.utils.UUIDChecker; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -85,8 +89,7 @@ import io.swagger.annotations.ApiOperation; public class E2EServiceInstances { private HashMap<String, String> instanceIdMap = new HashMap<>(); - private static final MsoLogger msoLogger = MsoLogger - .getMsoLogger(MsoLogger.Catalog.APIH, E2EServiceInstances.class); + private static final Logger logger = LoggerFactory.getLogger(E2EServiceInstances.class); private static final String MSO_PROP_APIHANDLER_INFRA = "MSO_PROP_APIHANDLER_INFRA"; @@ -190,7 +193,7 @@ public class E2EServiceInstances { @PathParam("version") String version, @PathParam("serviceId") String serviceId) throws ApiException { - msoLogger.debug("------------------scale begin------------------"); + logger.debug("------------------scale begin------------------"); instanceIdMap.put("serviceId", serviceId); return scaleE2EserviceInstances(request, Action.scaleInstance, instanceIdMap, version); } @@ -216,9 +219,8 @@ public class E2EServiceInstances { private Response compareModelwithTargetVersion(String requestJSON, Action action, HashMap<String, String> instanceIdMap, String version) throws ApiException { - String requestId = UUIDChecker.generateUUID(msoLogger); + String requestId = UUID.randomUUID().toString(); long startTime = System.currentTimeMillis(); - msoLogger.debug("requestId is: " + requestId); CompareModelsRequest e2eCompareModelReq; @@ -228,15 +230,13 @@ public class E2EServiceInstances { } catch (Exception e) { - msoLogger.debug("Mapping of request to JSON object failed : ", e); + logger.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, version); - 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 + response.getEntity().toString()); + logger.error("{} {} {} {}", MessageEnum.APIH_REQUEST_VALIDATION_ERROR.toString(), MSO_PROP_APIHANDLER_INFRA, + MsoLogger.ErrorCode.SchemaError.getValue(), requestJSON, e); + logger.debug(END_OF_THE_TRANSACTION + response.getEntity().toString()); return response; } @@ -264,7 +264,7 @@ public class E2EServiceInstances { String bpmnRequest = jjo.toString(); // Capture audit event - msoLogger.debug("MSO API Handler Posting call to BPEL engine for url: " + requestClient.getUrl()); + logger.debug("MSO API Handler Posting call to BPEL engine for url: " + requestClient.getUrl()); String serviceId = instanceIdMap.get("serviceId"); String serviceType = e2eCompareModelReq.getServiceType(); RequestClientParameter postParam = new RequestClientParameter.Builder() @@ -277,32 +277,22 @@ public class E2EServiceInstances { .setRequestDetails(bpmnRequest) .setALaCarte(false).build(); response = requestClient.post(postParam); - - msoLogger.recordMetricEvent(subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, - "Successfully received response from BPMN engine", "BPMN", workflowUrl, null); } catch (Exception e) { - msoLogger.recordMetricEvent(subStartTime, MsoLogger.StatusCode.ERROR, - MsoLogger.ResponseCode.CommunicationError, "Exception while communicate with BPMN engine", "BPMN", - workflowUrl, null); Response resp = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY, MsoException.ServiceException, "Failed calling bpmn " + e.getMessage(), ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version); - msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "", + logger.error("", MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "", MsoLogger.ErrorCode.AvailabilityError, "Exception while communicate with BPMN engine",e); - msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, - "Exception while communicate with BPMN engine"); - msoLogger.debug(END_OF_THE_TRANSACTION + resp.getEntity().toString()); + logger.debug(END_OF_THE_TRANSACTION + resp.getEntity().toString()); return resp; } if (response == null) { Response resp = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY, MsoException.ServiceException, "bpelResponse is null", ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version); - 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 + resp.getEntity().toString()); + logger.error("{} {} {} {}", MessageEnum.APIH_BPEL_COMMUNICATE_ERROR.toString(), MSO_PROP_APIHANDLER_INFRA, + MsoLogger.ErrorCode.BusinessProcesssError.getValue(), "Null response from BPEL"); + logger.debug(END_OF_THE_TRANSACTION + resp.getEntity().toString()); return resp; } @@ -327,24 +317,14 @@ public class E2EServiceInstances { operationStatus = requestsDbClient.getOneByServiceIdAndOperationId(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); + logger.error("{} {} {} {}", MessageEnum.APIH_DB_ACCESS_EXC.toString(), MSO_PROP_APIHANDLER_INFRA, + MsoLogger.ErrorCode.AvailabilityError.getValue(), + "Exception while communciate with Request DB - Infra Request Lookup", e); Response response = msoRequest.buildServiceErrorResponse( HttpStatus.SC_NOT_FOUND, MsoException.ServiceException, e.getMessage(), ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB, null, version); - - msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, - MsoLogger.ResponseCode.DBAccessError, - "Exception while communciate with Request DB"); - msoLogger.debug(END_OF_THE_TRANSACTION - + response.getEntity()); + logger.debug(END_OF_THE_TRANSACTION + response.getEntity()); return response; } @@ -354,15 +334,10 @@ public class E2EServiceInstances { HttpStatus.SC_NO_CONTENT, MsoException.ServiceException, "E2E serviceId " + serviceId + " is not found in DB", ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, null, version); - 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 - + resp.getEntity()); + logger.error("{} {} {} {}", MessageEnum.APIH_BPEL_COMMUNICATE_ERROR.toString(), MSO_PROP_APIHANDLER_INFRA, + MsoLogger.ErrorCode.BusinessProcesssError.getValue(), + "Null response from RequestDB when searching by serviceId"); + logger.debug(END_OF_THE_TRANSACTION + resp.getEntity()); return resp; } @@ -375,9 +350,7 @@ public class E2EServiceInstances { private Response deleteE2EserviceInstances(String requestJSON, Action action, HashMap<String, String> instanceIdMap, String version) throws ApiException { // TODO should be a new one or the same service instance Id - String requestId = UUIDChecker.generateUUID(msoLogger); long startTime = System.currentTimeMillis(); - msoLogger.debug("requestId is: " + requestId); E2EServiceInstanceDeleteRequest e2eDelReq; ObjectMapper mapper = new ObjectMapper(); @@ -387,63 +360,49 @@ public class E2EServiceInstances { } catch (Exception e) { - msoLogger.debug("Mapping of request to JSON object failed : ", e); + logger.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, version); - 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 - + response.getEntity()); + logger.error("{} {} {} {}", MessageEnum.APIH_REQUEST_VALIDATION_ERROR.toString(), MSO_PROP_APIHANDLER_INFRA, + MsoLogger.ErrorCode.SchemaError.getValue(), requestJSON, e); + logger.debug(END_OF_THE_TRANSACTION + response.getEntity()); return response; } + String requestId = UUID.randomUUID().toString(); RecipeLookupResult recipeLookupResult; try { //TODO Get the service template model version uuid from AAI. recipeLookupResult = getServiceInstanceOrchestrationURI(null, action); } catch (Exception e) { - msoLogger.error(MessageEnum.APIH_DB_ACCESS_EXC, - MSO_PROP_APIHANDLER_INFRA, "", "", - MsoLogger.ErrorCode.AvailabilityError, - "Exception while communciate with Catalog DB", e); + logger.error(MessageEnum.APIH_DB_ACCESS_EXC.toString(), MSO_PROP_APIHANDLER_INFRA, + MsoLogger.ErrorCode.AvailabilityError.getValue(), "Exception while communciate with Catalog DB", e); Response response = msoRequest.buildServiceErrorResponse( HttpStatus.SC_NOT_FOUND, MsoException.ServiceException, "No communication to catalog DB " + e.getMessage(), ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version); - msoRequest.createErrorRequestRecord(Status.FAILED, requestId, "Exception while communciate with Catalog DB", action, ModelType.service.name(), requestJSON); - msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, - MsoLogger.ResponseCode.DBAccessError, - "Exception while communciate with DB"); - msoLogger.debug(END_OF_THE_TRANSACTION - + response.getEntity()); + msoRequest.createErrorRequestRecord(Status.FAILED, requestId, "Exception while communciate with " + + "Catalog DB", action, + ModelType.service.name(), requestJSON); + logger.debug(END_OF_THE_TRANSACTION + response.getEntity()); return response; } if (recipeLookupResult == null) { - msoLogger.error(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, - MSO_PROP_APIHANDLER_INFRA, "", "", - MsoLogger.ErrorCode.DataError, "No recipe found in DB"); + logger.error("{} {} {} {}", MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND.toString(), MSO_PROP_APIHANDLER_INFRA, + MsoLogger.ErrorCode.DataError.getValue(), "No recipe found in DB"); Response response = msoRequest.buildServiceErrorResponse( HttpStatus.SC_NOT_FOUND, MsoException.ServiceException, "Recipe does not exist in catalog DB", ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null, version); msoRequest.createErrorRequestRecord(Status.FAILED, requestId,"Recipe does not exist in catalog DB", action, ModelType.service.name(), requestJSON); - - msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, - MsoLogger.ResponseCode.DataNotFound, - "No recipe found in DB"); - msoLogger.debug(END_OF_THE_TRANSACTION - + response.getEntity()); + logger.debug(END_OF_THE_TRANSACTION + response.getEntity()); return response; } @@ -455,14 +414,12 @@ public class E2EServiceInstances { requestClient = requestClientFactory.getRequestClient(recipeLookupResult.getOrchestrationURI()); JSONObject jjo = new JSONObject(requestJSON); - jjo.put("operationId", UUIDChecker.generateUUID(msoLogger)); + jjo.put("operationId", requestId); String bpmnRequest = jjo.toString(); // Capture audit event - msoLogger - .debug("MSO API Handler Posting call to BPEL engine for url: " - + requestClient.getUrl()); + logger.debug("MSO API Handler Posting call to BPEL engine for url: " + requestClient.getUrl()); String serviceId = instanceIdMap.get("serviceId"); String serviceInstanceType = e2eDelReq.getServiceType(); RequestClientParameter clientParam = new RequestClientParameter.Builder() @@ -478,29 +435,14 @@ public class E2EServiceInstances { .setRecipeParamXsd(recipeLookupResult.getRecipeParamXsd()).build(); response = requestClient.post(clientParam); - msoLogger.recordMetricEvent(subStartTime, - MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, - "Successfully received response from BPMN engine", "BPMN", - recipeLookupResult.getOrchestrationURI(), null); } catch (Exception e) { - msoLogger.recordMetricEvent(subStartTime, - MsoLogger.StatusCode.ERROR, - MsoLogger.ResponseCode.CommunicationError, - "Exception while communicate with BPMN engine", "BPMN", - recipeLookupResult.getOrchestrationURI(), null); Response resp = msoRequest.buildServiceErrorResponse( HttpStatus.SC_BAD_GATEWAY, MsoException.ServiceException, "Failed calling bpmn " + e.getMessage(), ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version); - 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: " - + resp.getEntity()); + logger.error("{} {} {} {}", MessageEnum.APIH_BPEL_COMMUNICATE_ERROR.toString(), MSO_PROP_APIHANDLER_INFRA, + MsoLogger.ErrorCode.AvailabilityError.getValue(), "Exception while communicate with BPMN engine"); + logger.debug("End of the transaction, the final response is: " + resp.getEntity()); return resp; } @@ -509,14 +451,9 @@ public class E2EServiceInstances { HttpStatus.SC_BAD_GATEWAY, MsoException.ServiceException, "bpelResponse is null", ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version); - 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 + resp.getEntity()); + logger.error("{} {} {} {}", MessageEnum.APIH_BPEL_COMMUNICATE_ERROR.toString(), MSO_PROP_APIHANDLER_INFRA, + MsoLogger.ErrorCode.BusinessProcesssError.getValue(), "Null response from BPEL"); + logger.debug(END_OF_THE_TRANSACTION + resp.getEntity()); return resp; } @@ -531,9 +468,8 @@ public class E2EServiceInstances { private Response updateE2EserviceInstances(String requestJSON, Action action, HashMap<String, String> instanceIdMap, String version) throws ApiException { - String requestId = UUIDChecker.generateUUID(msoLogger); + String requestId = UUID.randomUUID().toString(); long startTime = System.currentTimeMillis(); - msoLogger.debug("requestId is: " + requestId); E2EServiceInstanceRequest e2eSir; String serviceId = instanceIdMap.get("serviceId"); @@ -543,15 +479,13 @@ public class E2EServiceInstances { } catch (Exception e) { - msoLogger.debug("Mapping of request to JSON object failed : ", e); + logger.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, version); - 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 + response.getEntity()); + logger.error("{} {} {} {}", MessageEnum.APIH_REQUEST_VALIDATION_ERROR.toString(), MSO_PROP_APIHANDLER_INFRA, + MsoLogger.ErrorCode.SchemaError.getValue(), requestJSON, e); + logger.debug(END_OF_THE_TRANSACTION + response.getEntity()); return response; } @@ -560,18 +494,16 @@ public class E2EServiceInstances { try { parseRequest(sir, instanceIdMap, action, version, requestJSON, false, requestId); } catch (Exception e) { - msoLogger.debug("Validation failed: ", e); + logger.debug("Validation failed: ", e); Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST, MsoException.ServiceException, "Error parsing request. " + e.getMessage(), ErrorNumbers.SVC_BAD_PARAMETER, null, version); if (requestId != null) { - msoLogger.debug("Logging failed message to the database"); + logger.debug("Logging failed message to the database"); } - 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 + response.getEntity()); + logger.error("{} {} {} {}", MessageEnum.APIH_REQUEST_VALIDATION_ERROR.toString(), MSO_PROP_APIHANDLER_INFRA, + MsoLogger.ErrorCode.SchemaError.getValue(), requestJSON, e); + logger.debug(END_OF_THE_TRANSACTION + response.getEntity()); return response; } @@ -579,30 +511,24 @@ public class E2EServiceInstances { try { recipeLookupResult = getServiceInstanceOrchestrationURI(e2eSir.getService().getServiceUuid(), 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); + logger.error("{} {} {} {}", MessageEnum.APIH_DB_ACCESS_EXC.toString(), MSO_PROP_APIHANDLER_INFRA, + MsoLogger.ErrorCode.AvailabilityError.getValue(), "Exception while communciate with Catalog DB", e); Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, MsoException.ServiceException, "No communication to catalog DB " + e.getMessage(), ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version); - - - msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError, - "Exception while communciate with DB"); - msoLogger.debug(END_OF_THE_TRANSACTION + response.getEntity()); + + logger.debug(END_OF_THE_TRANSACTION + response.getEntity()); return response; } if (recipeLookupResult == null) { - msoLogger.error(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, MSO_PROP_APIHANDLER_INFRA, "", "", - MsoLogger.ErrorCode.DataError, "No recipe found in DB"); + logger.error("{} {} {} {}", MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND.toString(), MSO_PROP_APIHANDLER_INFRA, + MsoLogger.ErrorCode.DataError.getValue(), "No recipe found in DB"); Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, MsoException.ServiceException, "Recipe does not exist in catalog DB", ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null, version); - - msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, - "No recipe found in DB"); - msoLogger.debug(END_OF_THE_TRANSACTION + response.getEntity()); + logger.debug(END_OF_THE_TRANSACTION + response.getEntity()); return response; } @@ -619,7 +545,7 @@ public class E2EServiceInstances { requestClient = requestClientFactory.getRequestClient(recipeLookupResult.getOrchestrationURI()); // Capture audit event - msoLogger.debug("MSO API Handler Posting call to BPEL engine for url: " + requestClient.getUrl()); + logger.debug("MSO API Handler Posting call to BPEL engine for url: " + requestClient.getUrl()); RequestClientParameter postParam = new RequestClientParameter.Builder() .setRequestId(requestId) .setBaseVfModule(false) @@ -632,24 +558,15 @@ public class E2EServiceInstances { .setALaCarte(false) .setRecipeParamXsd(recipeLookupResult.getRecipeParamXsd()).build(); response = requestClient.post(postParam); - - msoLogger.recordMetricEvent(subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, - "Successfully received response from BPMN engine", "BPMN", recipeLookupResult.getOrchestrationURI(), - null); } catch (Exception e) { - msoLogger.debug("Exception while communicate with BPMN engine", e); - msoLogger.recordMetricEvent(subStartTime, MsoLogger.StatusCode.ERROR, - MsoLogger.ResponseCode.CommunicationError, "Exception while communicate with BPMN engine", "BPMN", - recipeLookupResult.getOrchestrationURI(), null); + logger.debug("Exception while communicate with BPMN engine", e); Response getBPMNResp = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY, MsoException.ServiceException, "Failed calling bpmn " + e.getMessage(), ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version); - 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 + getBPMNResp.getEntity()); + logger.error("{} {} {} {}", MessageEnum.APIH_BPEL_COMMUNICATE_ERROR.toString(), MSO_PROP_APIHANDLER_INFRA, + MsoLogger.ErrorCode.AvailabilityError.getValue(), "Exception while communicate with BPMN engine"); + logger.debug(END_OF_THE_TRANSACTION + getBPMNResp.getEntity()); return getBPMNResp; } @@ -657,11 +574,9 @@ public class E2EServiceInstances { if (response == null) { Response getBPMNResp = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY, MsoException.ServiceException, "bpelResponse is null", ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version); - 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 + getBPMNResp.getEntity()); + logger.error("{} {} {} {}", MessageEnum.APIH_BPEL_COMMUNICATE_ERROR.toString(), MSO_PROP_APIHANDLER_INFRA, + MsoLogger.ErrorCode.BusinessProcesssError.getValue(), "Null response from BPEL"); + logger.debug(END_OF_THE_TRANSACTION + getBPMNResp.getEntity()); return getBPMNResp; } @@ -675,9 +590,8 @@ public class E2EServiceInstances { private Response processE2EserviceInstances(String requestJSON, Action action, HashMap<String, String> instanceIdMap, String version) throws ApiException { - String requestId = UUIDChecker.generateUUID(msoLogger); + String requestId = UUID.randomUUID().toString(); long startTime = System.currentTimeMillis(); - msoLogger.debug("requestId is: " + requestId); E2EServiceInstanceRequest e2eSir; MsoRequest msoRequest = new MsoRequest(); @@ -687,15 +601,13 @@ public class E2EServiceInstances { } catch (Exception e) { - msoLogger.debug("Mapping of request to JSON object failed : ", e); + logger.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, version); - 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 + response.getEntity()); + logger.error("{} {} {} {}", MessageEnum.APIH_REQUEST_VALIDATION_ERROR.toString(), MSO_PROP_APIHANDLER_INFRA, + MsoLogger.ErrorCode.SchemaError.getValue(), requestJSON, e); + logger.debug(END_OF_THE_TRANSACTION + response.getEntity()); return response; } @@ -704,18 +616,16 @@ public class E2EServiceInstances { try { parseRequest(sir, instanceIdMap, action, version, requestJSON, false, requestId); } catch (Exception e) { - msoLogger.debug("Validation failed: ", e); + logger.debug("Validation failed: ", e); Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST, MsoException.ServiceException, "Error parsing request. " + e.getMessage(), ErrorNumbers.SVC_BAD_PARAMETER, null, version); if (requestId != null) { - msoLogger.debug("Logging failed message to the database"); + logger.debug("Logging failed message to the database"); } - 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 + response.getEntity()); + logger.error("{} {} {} {}", MessageEnum.APIH_REQUEST_VALIDATION_ERROR.toString(), MSO_PROP_APIHANDLER_INFRA, + MsoLogger.ErrorCode.SchemaError.getValue(), requestJSON, e); + logger.debug(END_OF_THE_TRANSACTION + response.getEntity()); return response; } @@ -723,28 +633,22 @@ public class E2EServiceInstances { try { recipeLookupResult = getServiceInstanceOrchestrationURI(e2eSir.getService().getServiceUuid(), 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); + logger.error("{} {} {} {}", MessageEnum.APIH_DB_ACCESS_EXC.toString(), MSO_PROP_APIHANDLER_INFRA, + MsoLogger.ErrorCode.AvailabilityError.getValue(), "Exception while communciate with Catalog DB", e); Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, MsoException.ServiceException, "No communication to catalog DB " + e.getMessage(), ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version); - - msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError, - "Exception while communciate with DB"); - msoLogger.debug(END_OF_THE_TRANSACTION + response.getEntity()); + logger.debug(END_OF_THE_TRANSACTION + response.getEntity()); return response; } if (recipeLookupResult == null) { - msoLogger.error(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, MSO_PROP_APIHANDLER_INFRA, "", "", - MsoLogger.ErrorCode.DataError, "No recipe found in DB"); + logger.error("{} {} {} {}", MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND.toString(), MSO_PROP_APIHANDLER_INFRA, + MsoLogger.ErrorCode.DataError.getValue(), "No recipe found in DB"); Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, MsoException.ServiceException, "Recipe does not exist in catalog DB", ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null, version); - - msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, - "No recipe found in DB"); - msoLogger.debug(END_OF_THE_TRANSACTION + response.getEntity()); + logger.debug(END_OF_THE_TRANSACTION + response.getEntity()); return response; } @@ -761,7 +665,7 @@ public class E2EServiceInstances { requestClient = requestClientFactory.getRequestClient(recipeLookupResult.getOrchestrationURI()); // Capture audit event - msoLogger.debug("MSO API Handler Posting call to BPEL engine for url: " + requestClient.getUrl()); + logger.debug("MSO API Handler Posting call to BPEL engine for url: " + requestClient.getUrl()); RequestClientParameter parameter = new RequestClientParameter.Builder() .setRequestId(requestId) .setBaseVfModule(false) @@ -774,34 +678,23 @@ public class E2EServiceInstances { .setALaCarte(false) .setRecipeParamXsd(recipeLookupResult.getRecipeParamXsd()).build(); response = requestClient.post(parameter); - - msoLogger.recordMetricEvent(subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, - "Successfully received response from BPMN engine", "BPMN", recipeLookupResult.getOrchestrationURI(), - null); } catch (Exception e) { - msoLogger.recordMetricEvent(subStartTime, MsoLogger.StatusCode.ERROR, - MsoLogger.ResponseCode.CommunicationError, "Exception while communicate with BPMN engine", "BPMN", - recipeLookupResult.getOrchestrationURI(), null); Response resp = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY, MsoException.ServiceException, "Failed calling bpmn " + e.getMessage(), ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version); - - 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 + resp.getEntity()); + + logger.error("{} {} {} {}", MessageEnum.APIH_BPEL_COMMUNICATE_ERROR.toString(), MSO_PROP_APIHANDLER_INFRA, + MsoLogger.ErrorCode.AvailabilityError.getValue(), "Exception while communicate with BPMN engine"); + logger.debug(END_OF_THE_TRANSACTION + resp.getEntity()); return resp; } if (response == null) { Response resp = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY, MsoException.ServiceException, "bpelResponse is null", ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version); - 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 + resp.getEntity()); + logger.error("{} {} {} {}", MessageEnum.APIH_BPEL_COMMUNICATE_ERROR.toString(), MSO_PROP_APIHANDLER_INFRA, + MsoLogger.ErrorCode.BusinessProcesssError.getValue(), "Null response from BPEL"); + logger.debug(END_OF_THE_TRANSACTION + resp.getEntity()); return resp; } @@ -815,9 +708,8 @@ public class E2EServiceInstances { private Response scaleE2EserviceInstances(String requestJSON, Action action, HashMap<String, String> instanceIdMap, String version) throws ApiException { - String requestId = UUIDChecker.generateUUID(msoLogger); + String requestId = UUID.randomUUID().toString(); long startTime = System.currentTimeMillis(); - msoLogger.debug("requestId is: " + requestId); E2EServiceInstanceScaleRequest e2eScaleReq; ObjectMapper mapper = new ObjectMapper(); @@ -827,22 +719,17 @@ public class E2EServiceInstances { } catch (Exception e) { - msoLogger.debug("Mapping of request to JSON object failed : ", e); + logger.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, version); - 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 - + response.getEntity()); - return response; + logger.error("{} {} {} {}", MessageEnum.APIH_REQUEST_VALIDATION_ERROR.toString(), MSO_PROP_APIHANDLER_INFRA, + MsoLogger.ErrorCode.SchemaError.getValue(), requestJSON, e); + logger.debug(END_OF_THE_TRANSACTION + response.getEntity()); + return response; } RecipeLookupResult recipeLookupResult; @@ -850,40 +737,29 @@ public class E2EServiceInstances { //TODO Get the service template model version uuid from AAI. recipeLookupResult = getServiceInstanceOrchestrationURI(null, action); } catch (Exception e) { - msoLogger.error(MessageEnum.APIH_DB_ACCESS_EXC, - MSO_PROP_APIHANDLER_INFRA, "", "", - MsoLogger.ErrorCode.AvailabilityError, - "Exception while communciate with Catalog DB", e); - - Response response = msoRequest.buildServiceErrorResponse( + logger.error("{} {} {} {}", MessageEnum.APIH_DB_ACCESS_EXC.toString(), MSO_PROP_APIHANDLER_INFRA, + MsoLogger.ErrorCode.AvailabilityError.getValue(), "Exception while communciate with Catalog DB", e); + + Response response = msoRequest.buildServiceErrorResponse( HttpStatus.SC_NOT_FOUND, MsoException.ServiceException, "No communication to catalog DB " + e.getMessage(), ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version); msoRequest.createErrorRequestRecord(Status.FAILED, requestId, "No communication to catalog DB " + e.getMessage(), action, ModelType.service.name(), requestJSON); - msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, - MsoLogger.ResponseCode.DBAccessError, - "Exception while communciate with DB"); - msoLogger.debug(END_OF_THE_TRANSACTION - + response.getEntity()); - return response; + logger.debug(END_OF_THE_TRANSACTION + response.getEntity()); + return response; } if (recipeLookupResult == null) { - msoLogger.error(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, - MSO_PROP_APIHANDLER_INFRA, "", "", - MsoLogger.ErrorCode.DataError, "No recipe found in DB"); - - Response response = msoRequest.buildServiceErrorResponse( + logger.error("{} {} {} {}", MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND.toString(), MSO_PROP_APIHANDLER_INFRA, + MsoLogger.ErrorCode.DataError.getValue(), "No recipe found in DB"); + + Response response = msoRequest.buildServiceErrorResponse( HttpStatus.SC_NOT_FOUND, MsoException.ServiceException, "Recipe does not exist in catalog DB", ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null, version); msoRequest.createErrorRequestRecord(Status.FAILED, requestId, "No recipe found in DB", action, ModelType.service.name(), requestJSON); - msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, - MsoLogger.ResponseCode.DataNotFound, - "No recipe found in DB"); - msoLogger.debug(END_OF_THE_TRANSACTION - + response.getEntity()); - return response; + logger.debug(END_OF_THE_TRANSACTION + response.getEntity()); + return response; } RequestClient requestClient; @@ -894,15 +770,13 @@ public class E2EServiceInstances { requestClient = requestClientFactory.getRequestClient(recipeLookupResult.getOrchestrationURI()); JSONObject jjo = new JSONObject(requestJSON); - jjo.put("operationId", UUIDChecker.generateUUID(msoLogger)); + jjo.put("operationId", requestId); 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"); + logger.debug("MSO API Handler Posting call to BPEL engine for url: " + requestClient.getUrl()); + String serviceId = instanceIdMap.get("serviceId"); String serviceInstanceType = e2eScaleReq.getService().getServiceType(); RequestClientParameter postParam = new RequestClientParameter.Builder() .setRequestId(requestId) @@ -916,32 +790,16 @@ public class E2EServiceInstances { .setALaCarte(false) .setRecipeParamXsd(recipeLookupResult.getRecipeParamXsd()).build(); response = requestClient.post(postParam); - - msoLogger.recordMetricEvent(subStartTime, - MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, - "Successfully received response from BPMN engine", "BPMN", - recipeLookupResult.getOrchestrationURI(), null); - } catch (Exception e) { - msoLogger.recordMetricEvent(subStartTime, - MsoLogger.StatusCode.ERROR, - MsoLogger.ResponseCode.CommunicationError, - "Exception while communicate with BPMN engine", "BPMN", - recipeLookupResult.getOrchestrationURI(), null); + } catch (Exception e) { Response resp = msoRequest.buildServiceErrorResponse( HttpStatus.SC_BAD_GATEWAY, MsoException.ServiceException, "Failed calling bpmn " + e.getMessage(), ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version); - - msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, - MSO_PROP_APIHANDLER_INFRA, "", "", - MsoLogger.ErrorCode.AvailabilityError, - "Exception while communicate with BPMN engine",e); - msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, - MsoLogger.ResponseCode.CommunicationError, - "Exception while communicate with BPMN engine"); - msoLogger.debug(END_OF_THE_TRANSACTION - + resp.getEntity()); - return resp; + + logger.error("{} {} {} {}", MessageEnum.APIH_BPEL_COMMUNICATE_ERROR.toString(), MSO_PROP_APIHANDLER_INFRA, + MsoLogger.ErrorCode.AvailabilityError.getValue(), "Exception while communicate with BPMN engine", e); + logger.debug(END_OF_THE_TRANSACTION + resp.getEntity()); + return resp; } if (response == null) { @@ -949,15 +807,10 @@ public class E2EServiceInstances { HttpStatus.SC_BAD_GATEWAY, MsoException.ServiceException, "bpelResponse is null", ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version); - 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 + resp.getEntity()); - return resp; + logger.error("{} {} {} {}", MessageEnum.APIH_BPEL_COMMUNICATE_ERROR.toString(), MSO_PROP_APIHANDLER_INFRA, + MsoLogger.ErrorCode.BusinessProcesssError.getValue(), "Null response from BPEL"); + logger.debug(END_OF_THE_TRANSACTION + resp.getEntity()); + return resp; } ResponseHandler respHandler = new ResponseHandler(response, @@ -978,11 +831,8 @@ public class E2EServiceInstances { // BPMN accepted the request, the request is in progress if (bpelStatus == HttpStatus.SC_ACCEPTED) { String camundaJSONResponseBody = respHandler.getResponseBody(); - msoLogger.debug("Received from Camunda: " + camundaJSONResponseBody); - msoLogger.recordAuditEvent(startTime, - MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, - "BPMN accepted the request, the request is in progress"); - msoLogger.debug(END_OF_THE_TRANSACTION + camundaJSONResponseBody); + logger.debug("Received from Camunda: " + camundaJSONResponseBody); + logger.debug(END_OF_THE_TRANSACTION + camundaJSONResponseBody); return builder.buildResponse(HttpStatus.SC_ACCEPTED, null, camundaJSONResponseBody, apiVersion); } else { List<String> variables = new ArrayList<>(); @@ -995,17 +845,10 @@ public class E2EServiceInstances { "Request Failed due to BPEL error with HTTP Status= %1 " + '\n' + camundaJSONResponseBody, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, variables, version); - msoLogger.error(MessageEnum.APIH_BPEL_RESPONSE_ERROR, - requestClient.getUrl(), "", "", - MsoLogger.ErrorCode.BusinessProcesssError, - "Response from BPEL engine is failed with HTTP Status=" - + bpelStatus); - msoLogger.recordAuditEvent(startTime, - MsoLogger.StatusCode.ERROR, - MsoLogger.ResponseCode.InternalError, - "Response from BPMN engine is failed"); - msoLogger.debug(END_OF_THE_TRANSACTION - + resp.getEntity()); + logger.error("{} {} {} {}", MessageEnum.APIH_BPEL_RESPONSE_ERROR.toString(), requestClient.getUrl(), + MsoLogger.ErrorCode.BusinessProcesssError.getValue(), + "Response from BPEL engine is failed with HTTP Status=" + bpelStatus); + logger.debug(END_OF_THE_TRANSACTION + resp.getEntity()); return resp; } else { Response resp = msoRequest @@ -1015,16 +858,10 @@ public class E2EServiceInstances { "Request Failed due to BPEL error with HTTP Status= %1", ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, variables, version); - 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, + logger.error("", MessageEnum.APIH_BPEL_RESPONSE_ERROR.toString(), requestClient.getUrl(), + MsoLogger.ErrorCode.BusinessProcesssError.getValue(), "Response from BPEL engine is empty"); - msoLogger.debug(END_OF_THE_TRANSACTION - + resp.getEntity()); + logger.debug(END_OF_THE_TRANSACTION + resp.getEntity()); return resp; } } @@ -1042,12 +879,11 @@ public class E2EServiceInstances { RecipeLookupResult recipeLookupResult = getServiceURI(serviceModelUUID, action); if (recipeLookupResult != null) { - msoLogger.debug("Orchestration URI is: " - + recipeLookupResult.getOrchestrationURI() - + ", recipe Timeout is: " - + Integer.toString(recipeLookupResult.getRecipeTimeout())); + logger.debug( + "Orchestration URI is: " + recipeLookupResult.getOrchestrationURI() + ", recipe Timeout is: " + Integer + .toString(recipeLookupResult.getRecipeTimeout())); } else { - msoLogger.debug("No matching recipe record found"); + logger.debug("No matching recipe record found"); } return recipeLookupResult; } @@ -1204,9 +1040,7 @@ public class E2EServiceInstances { try { returnString = mapper.writeValueAsString(sir); } catch (IOException e) { - msoLogger - .debug("Exception while converting ServiceInstancesRequest object to string", - e); + logger.debug("Exception while converting ServiceInstancesRequest object to string", e); } return returnString; diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/GlobalHealthcheckHandler.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/GlobalHealthcheckHandler.java index b002aa9f54..07c98c19b9 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/GlobalHealthcheckHandler.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/GlobalHealthcheckHandler.java @@ -114,8 +114,6 @@ public class GlobalHealthcheckHandler { HealthcheckResponse rsp = new HealthcheckResponse(); try{ - long startTime = System.currentTimeMillis (); - MsoLogger.setServiceName ("GlobalHealthcheck"); // Generated RequestId String requestId = requestContext.getProperty("requestId").toString(); MsoLogger.setLogContext(requestId, null); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/JerseyConfiguration.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/JerseyConfiguration.java index e6bbc4de4a..182e398461 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/JerseyConfiguration.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/JerseyConfiguration.java @@ -29,6 +29,7 @@ import org.onap.so.apihandler.filters.RequestUriFilter; import org.onap.so.apihandlerinfra.exceptions.ApiExceptionMapper; import org.onap.so.apihandlerinfra.tenantisolation.CloudOrchestration; import org.onap.so.apihandlerinfra.tenantisolation.CloudResourcesOrchestration; +import org.onap.so.apihandlerinfra.tenantisolation.ModelDistributionRequest; import org.onap.so.logging.jaxrs.filter.JaxRsFilterLogging; import org.onap.so.web.exceptions.RuntimeExceptionMapper; import org.springframework.context.annotation.Configuration; @@ -64,6 +65,7 @@ public class JerseyConfiguration extends ResourceConfig { // this registration seems to be needed to get predictable // execution behavior for the above JSON Exception Mappers register(com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider.class); + register(ModelDistributionRequest.class); property(ServletProperties.FILTER_FORWARD_ON_404, true); BeanConfig beanConfig = new BeanConfig(); beanConfig.setVersion("1.0.2"); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java index 411a5e584a..886e0d5133 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java @@ -699,7 +699,6 @@ public class MsoRequest { String vfModuleType = null; String vfModuleModelName = null; ModelInfo modelInfo = sir.getRequestDetails().getModelInfo(); - MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.APIH, MsoRequest.class); RelatedInstanceList[] instanceList = sir.getRequestDetails().getRelatedInstanceList(); String serviceModelName = null; String vnfModelName = null; diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/NodeHealthcheckHandler.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/NodeHealthcheckHandler.java index cb458a7420..351a35826d 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/NodeHealthcheckHandler.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/NodeHealthcheckHandler.java @@ -34,7 +34,6 @@ import javax.ws.rs.core.Response; import org.apache.http.HttpStatus; import org.onap.so.logger.MessageEnum; -import org.onap.so.logger.MsoLogger; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @@ -60,8 +59,6 @@ public class NodeHealthcheckHandler { @ApiOperation(value="Performing node health check",response=Response.class) @Transactional public Response nodeHealthcheck (@Context ContainerRequestContext requestContext) throws UnknownHostException { - long startTime = System.currentTimeMillis (); - MsoLogger.setServiceName ("NodeHealthcheck"); // Generated RequestId String requestId = requestContext.getProperty("requestId").toString(); logger.info("{} {}", MessageEnum.APIH_GENERATED_REQUEST_ID.toString(), requestId); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java index 1f9f5f5fbe..2dab494b07 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java @@ -657,7 +657,7 @@ public class ServiceInstances { public Response deleteInstanceGroups(@PathParam("version") String version, @PathParam("instanceGroupId") String instanceGroupId, @Context ContainerRequestContext requestContext) throws ApiException { String requestId = getRequestId(requestContext); HashMap<String, String> instanceIdMap = new HashMap<>(); - instanceIdMap.put(CommonConstants.INSTANCE_GROUP_ID, instanceGroupId); + instanceIdMap.put(CommonConstants.INSTANCE_GROUP_INSTANCE_ID, instanceGroupId); return deleteInstanceGroups(Action.deleteInstance, instanceIdMap, version, requestId, getRequestUri(requestContext), requestContext); } @@ -670,7 +670,7 @@ public class ServiceInstances { public Response addInstanceGroupMembers(String request, @PathParam("version") String version, @PathParam("instanceGroupId") String instanceGroupId, @Context ContainerRequestContext requestContext) throws ApiException { String requestId = getRequestId(requestContext); HashMap<String, String> instanceIdMap = new HashMap<>(); - instanceIdMap.put(CommonConstants.INSTANCE_GROUP_ID, instanceGroupId); + instanceIdMap.put(CommonConstants.INSTANCE_GROUP_INSTANCE_ID, instanceGroupId); return serviceInstances(request, Action.addMembers, instanceIdMap, version, requestId, getRequestUri(requestContext)); } @@ -683,7 +683,7 @@ public class ServiceInstances { public Response removeInstanceGroupMembers(String request, @PathParam("version") String version, @PathParam("instanceGroupId") String instanceGroupId, @Context ContainerRequestContext requestContext) throws ApiException { String requestId = getRequestId(requestContext); HashMap<String, String> instanceIdMap = new HashMap<>(); - instanceIdMap.put(CommonConstants.INSTANCE_GROUP_ID, instanceGroupId); + instanceIdMap.put(CommonConstants.INSTANCE_GROUP_INSTANCE_ID, instanceGroupId); return serviceInstances(request, Action.removeMembers, instanceIdMap, version, requestId, getRequestUri(requestContext)); } @@ -808,16 +808,13 @@ public class ServiceInstances { } - serviceInstanceId = ""; + serviceInstanceId = setServiceInstanceId(requestScope, sir); String vnfId = ""; String vfModuleId = ""; String volumeGroupId = ""; String networkId = ""; String pnfCorrelationId = ""; String instanceGroupId = null; - if(sir.getServiceInstanceId () != null){ - serviceInstanceId = sir.getServiceInstanceId (); - } if(sir.getVnfInstanceId () != null){ vnfId = sir.getVnfInstanceId (); @@ -884,7 +881,7 @@ public class ServiceInstances { return postBPELRequest(currentActiveReq, requestClientParameter, recipeLookupResult.getOrchestrationURI(), requestScope); } public Response deleteInstanceGroups(Actions action, HashMap<String, String> instanceIdMap, String version, String requestId, String requestUri, ContainerRequestContext requestContext) throws ApiException { - String instanceGroupId = instanceIdMap.get(CommonConstants.INSTANCE_GROUP_ID); + String instanceGroupId = instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID); Boolean aLaCarte = true; long startTime = System.currentTimeMillis (); String apiVersion = version.substring(1); @@ -1117,8 +1114,8 @@ public class ServiceInstances { if(instanceIdMap.get("configurationInstanceId") != null){ currentActiveReq.setConfigurationId(instanceIdMap.get("configurationInstanceId")); } - if(instanceIdMap.get("InstanceGroupInstanceId") != null){ - currentActiveReq.setInstanceGroupId(instanceIdMap.get("InstanceGroupInstanceId")); + if(instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID) != null){ + currentActiveReq.setInstanceGroupId(instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID)); } } } @@ -1249,6 +1246,7 @@ public class ServiceInstances { try { msoRequest.parse(sir, instanceIdMap, action, version, requestJSON, reqVersion, aLaCarte); } catch (Exception e) { + logger.error("failed to parse request", e); ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, MsoLogger.ErrorCode.SchemaError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); ValidateException validateException = new ValidateException.Builder("Error parsing request: " + e.getMessage(), HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e) .errorInfo(errorLoggerInfo).build(); @@ -1969,4 +1967,20 @@ public class ServiceInstances { } return serviceType; } + protected String setServiceInstanceId(String requestScope, ServiceInstancesRequest sir){ + if(sir.getServiceInstanceId () != null){ + return sir.getServiceInstanceId (); + }else if(requestScope.equalsIgnoreCase(ModelType.instanceGroup.toString())){ + RelatedInstanceList[] relatedInstances = sir.getRequestDetails().getRelatedInstanceList(); + if(relatedInstances != null){ + for(RelatedInstanceList relatedInstanceList : relatedInstances){ + RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance(); + if(relatedInstance.getModelInfo().getModelType() == ModelType.service){ + return relatedInstance.getInstanceId(); + } + } + } + } + return null; + } } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudResourcesOrchestration.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudResourcesOrchestration.java index 377b03c4ab..9305b80c13 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudResourcesOrchestration.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudResourcesOrchestration.java @@ -158,7 +158,6 @@ public class CloudResourcesOrchestration { @ApiOperation(value="Get status of an Operational Environment based on filter criteria",response=Response.class) @Transactional public Response getOperationEnvironmentStatusFilter(@Context UriInfo ui, @PathParam("version") String version ) throws ApiException{ - MsoLogger.setServiceName ("getOperationEnvironmentStatusFilter"); MultivaluedMap<String, String> queryParams = ui.getQueryParameters(); List<String> requestIdKey = queryParams.get("requestId"); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/ModelDistributionRequest.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/ModelDistributionRequest.java index ace0fb664c..3ec3ade959 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/ModelDistributionRequest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/ModelDistributionRequest.java @@ -28,7 +28,7 @@ import java.util.List; import javax.inject.Provider; import javax.transaction.Transactional; import javax.ws.rs.Consumes; -import javax.ws.rs.POST; +import javax.ws.rs.PATCH; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; @@ -53,6 +53,7 @@ import org.onap.so.serviceinstancebeans.ServiceException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.core.JsonProcessingException; @@ -61,7 +62,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; - +@Component @Path("/onap/so/infra/modelDistributions") @Api(value="/onap/so/infra/modelDistributions",description="API Requests for Model Distributions") public class ModelDistributionRequest { @@ -70,7 +71,7 @@ public class ModelDistributionRequest { @Autowired private Provider<TenantIsolationRunnable> tenantIsolationRunnable; - @POST + @PATCH @Path("/{version:[vV][1]}/distributions/{distributionId}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/SDCClientHelper.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/SDCClientHelper.java index 9303e12071..31c65e1bd2 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/SDCClientHelper.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/SDCClientHelper.java @@ -82,6 +82,7 @@ public class SDCClientHelper { try { String urlString = this.buildUriBuilder(serviceModelVersionId, operationalEnvironmentId); + logger.debug("Url ASDC Activate request: {}", urlString); String jsonPayload = this.buildJsonWorkloadContext(workloadContext); String basicAuthCred = getBasicAuth(); @@ -157,6 +158,7 @@ public class SDCClientHelper { enhancedAsdcResponseJsonObj.put("statusCode", Integer.toString(statusCode)); enhancedAsdcResponseJsonObj.put("messageId", ""); enhancedAsdcResponseJsonObj.put("message", "Success"); + logger.debug("Url ASDC Activate response: {} {}", "distributionId ", sdcResponseJsonObj.get("distributionId")); } else { // error if (sdcResponseJsonObj.has("requestError") ) { diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/InstanceIdMapValidation.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/InstanceIdMapValidation.java index f1985e9fcf..fad11a5cc6 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/InstanceIdMapValidation.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/InstanceIdMapValidation.java @@ -77,11 +77,11 @@ public class InstanceIdMapValidation implements ValidationRule{ sir.setConfigurationId(instanceIdMap.get("configurationInstanceId")); } - if(instanceIdMap.get(CommonConstants.INSTANCE_GROUP_ID) != null){ - if (!UUIDChecker.isValidUUID (instanceIdMap.get (CommonConstants.INSTANCE_GROUP_ID))) { - throw new ValidationException (CommonConstants.INSTANCE_GROUP_ID, true); + if(instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID) != null){ + if (!UUIDChecker.isValidUUID (instanceIdMap.get (CommonConstants.INSTANCE_GROUP_INSTANCE_ID))) { + throw new ValidationException (CommonConstants.INSTANCE_GROUP_INSTANCE_ID, true); } - sir.setInstanceGroupId(instanceIdMap.get(CommonConstants.INSTANCE_GROUP_ID)); + sir.setInstanceGroupId(instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID)); } } return info; diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/MsoRequestTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/MsoRequestTest.java index 145213fc6c..ee98accfdc 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/MsoRequestTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/MsoRequestTest.java @@ -430,12 +430,12 @@ public class MsoRequestTest extends BaseTest { @Test public void instanceGroupIdHashMapFailureTest() throws JsonParseException, JsonMappingException, IOException, ValidationException{ this.sir = mapper.readValue(inputStream("/SuccessfulValidation/InstanceIdHashMap.json"), ServiceInstancesRequest.class); - this.instanceIdMapTest.put("instanceGroupId", "test"); + this.instanceIdMapTest.put("instanceGroupInstanceId", "test"); this.action = Action.createInstance; thrown.expect(ValidationException.class); this.reqVersion = 7; this.version = "v" + reqVersion; - thrown.expectMessage("No valid instanceGroupId is specified"); + thrown.expectMessage("No valid instanceGroupInstanceId is specified"); this.msoRequest = new MsoRequest(); this.msoRequest.parse(sir, instanceIdMapTest, action, version, originalRequestJSON, reqVersion, false); } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java index 83b5a49e8c..23974ef1fa 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java @@ -31,6 +31,7 @@ import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; @@ -79,8 +80,10 @@ import org.springframework.util.ResourceUtils; import org.springframework.web.util.UriComponentsBuilder; import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.tomakehurst.wiremock.http.Fault; @@ -114,9 +117,12 @@ public class ServiceInstancesTest extends BaseTest{ // set headers headers = new HttpHeaders(); headers.set(ONAPLogConstants.Headers.PARTNER_NAME, "test_name"); - headers.set(ONAPLogConstants.Headers.REQUEST_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d"); - headers.set(MsoLogger.REQUESTOR_ID, "xxxxxx"); - try { // generate one-time port number to avoid RANDOM port number later. + headers.set(MsoLogger.TRANSACTION_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d"); + headers.set(MsoLogger.ONAP_REQUEST_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d"); + headers.set(ONAPLogConstants.MDCs.REQUEST_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d"); + headers.set(MsoLogger.CLIENT_ID, "VID"); + headers.set(MsoLogger.REQUESTOR_ID, "xxxxxx"); + try { // generate one-time port number to avoid RANDOM port number later. initialUrl = new URL(createURLWithPort(Constants.ORCHESTRATION_REQUESTS_PATH)); initialPort = initialUrl.getPort(); } catch (MalformedURLException e) { @@ -391,9 +397,10 @@ public class ServiceInstancesTest extends BaseTest{ } @Test public void activateServiceInstanceNoRecipeALaCarte() throws IOException{ + TestAppender.events.clear(); uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/activate"; HttpHeaders requestIDheaders = new HttpHeaders(); - requestIDheaders.set("X-ECOMP-RequestID", "32807a28-1a14-4b88-b7b3-2950918aa76d"); + requestIDheaders.set(ONAPLogConstants.Headers.REQUEST_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d"); ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceALaCarteTrueNoRecipe.json"), uri, HttpMethod.POST, requestIDheaders); Service defaultService = new Service(); @@ -2368,7 +2375,8 @@ public class ServiceInstancesTest extends BaseTest{ if(logEvent.getLoggerName().equals("org.onap.so.logging.jaxrs.filter.JaxRsFilterLogging") && logEvent.getMarker() != null && logEvent.getMarker().getName().equals("ENTRY")){ Map<String,String> mdc = logEvent.getMDCPropertyMap(); - assertEquals("32807a28-1a14-4b88-b7b3-2950918aa76d", mdc.get(ONAPLogConstants.MDCs.REQUEST_ID)); + assertEquals("32807a28-1a14-4b88-b7b3-2950918aa76d", mdc.get(ONAPLogConstants.MDCs.REQUEST_ID)); + assertEquals("VID",mdc.get(MsoLogger.PARTNERNAME)); } } } @@ -2425,6 +2433,7 @@ public class ServiceInstancesTest extends BaseTest{ public void deleteInstanceGroupNoPartnerNameHeader() throws IOException{ HttpHeaders noPartnerHeaders = new HttpHeaders(); noPartnerHeaders.set(ONAPLogConstants.Headers.REQUEST_ID, "eca3a1b1-43ab-457e-ab1c-367263d148b4"); + noPartnerHeaders.set(MsoLogger.REQUESTOR_ID, "xxxxxx"); uri = servInstanceuri + "/v7/instanceGroups/e05864f0-ab35-47d0-8be4-56fd9619ba3c"; ResponseEntity<String> response = sendRequest(null, uri, HttpMethod.DELETE, noPartnerHeaders); //then @@ -2621,6 +2630,61 @@ public class ServiceInstancesTest extends BaseTest{ assertEquals(serviceType, "networkModelName"); } @Test + public void setServiceInstanceIdInstanceGroupTest() throws JsonParseException, JsonMappingException, IOException{ + String requestScope = "instanceGroup"; + ServiceInstancesRequest sir = mapper.readValue(inputStream("/CreateInstanceGroup.json"), ServiceInstancesRequest.class); + assertEquals("ddcbbf3d-f2c1-4ca0-8852-76a807285efc", servInstances.setServiceInstanceId(requestScope, sir)); + } + @Test + public void setServiceInstanceIdTest(){ + String requestScope = "vnf"; + ServiceInstancesRequest sir = new ServiceInstancesRequest(); + sir.setServiceInstanceId("f0a35706-efc4-4e27-80ea-a995d7a2a40f"); + assertEquals("f0a35706-efc4-4e27-80ea-a995d7a2a40f", servInstances.setServiceInstanceId(requestScope, sir)); + } + @Test + public void setServiceInstanceIdReturnNullTest(){ + String requestScope = "vnf"; + ServiceInstancesRequest sir = new ServiceInstancesRequest(); + assertNull(servInstances.setServiceInstanceId(requestScope, sir)); + } + @Test + public void camundaHistoryCheckTest() throws ContactCamundaException, RequestDbFailureException{ + stubFor(get(("/sobpmnengine/history/process-instance?variables=mso-request-id_eq_f0a35706-efc4-4e27-80ea-a995d7a2a40f")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBodyFile("Camunda/HistoryCheckResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + + InfraActiveRequests duplicateRecord = new InfraActiveRequests(); + duplicateRecord.setRequestId("f0a35706-efc4-4e27-80ea-a995d7a2a40f"); + boolean inProgress = false; + inProgress = servInstances.camundaHistoryCheck(duplicateRecord, null); + assertTrue(inProgress); + } + @Test + public void camundaHistoryCheckNoneFoundTest() throws ContactCamundaException, RequestDbFailureException{ + stubFor(get(("/sobpmnengine/history/process-instance?variables=mso-request-id_eq_f0a35706-efc4-4e27-80ea-a995d7a2a40f")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody("[]").withStatus(org.apache.http.HttpStatus.SC_OK))); + + InfraActiveRequests duplicateRecord = new InfraActiveRequests(); + duplicateRecord.setRequestId("f0a35706-efc4-4e27-80ea-a995d7a2a40f"); + boolean inProgress = false; + inProgress = servInstances.camundaHistoryCheck(duplicateRecord, null); + assertFalse(inProgress); + } + @Test + public void camundaHistoryCheckNotInProgressTest()throws ContactCamundaException, RequestDbFailureException{ + stubFor(get(("/sobpmnengine/history/process-instance?variables=mso-request-id_eq_f0a35706-efc4-4e27-80ea-a995d7a2a40f")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBodyFile("Camunda/HistoryCheckResponseCompleted.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + + InfraActiveRequests duplicateRecord = new InfraActiveRequests(); + duplicateRecord.setRequestId("f0a35706-efc4-4e27-80ea-a995d7a2a40f"); + boolean inProgress = false; + inProgress = servInstances.camundaHistoryCheck(duplicateRecord, null); + assertFalse(inProgress); + } + @Test public void setCamundaHeadersTest()throws ContactCamundaException, RequestDbFailureException{ String encryptedAuth = "015E7ACF706C6BBF85F2079378BDD2896E226E09D13DC2784BA309E27D59AB9FAD3A5E039DF0BB8408"; // user:password String key = "07a7159d3bf51a0e53be7a8f89699be7"; diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/ModelDistributionRequestTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/ModelDistributionRequestTest.java index 9a8f4880f7..4e5cfaba48 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/ModelDistributionRequestTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/ModelDistributionRequestTest.java @@ -24,13 +24,15 @@ import static org.hamcrest.Matchers.hasProperty; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.startsWith; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.contains; import static org.mockito.Mockito.doNothing; +import java.io.IOException; + import javax.inject.Provider; +import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.apache.http.HttpStatus; @@ -38,21 +40,23 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; -import org.mockito.junit.MockitoJUnitRunner; import org.onap.so.apihandler.common.ErrorNumbers; -import org.onap.so.apihandlerinfra.ApiHandlerApplication; import org.onap.so.apihandlerinfra.BaseTest; import org.onap.so.apihandlerinfra.exceptions.ApiException; import org.onap.so.apihandlerinfra.exceptions.ValidateException; import org.onap.so.apihandlerinfra.tenantisolationbeans.Action; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ActiveProfiles; +import org.onap.so.apihandlerinfra.tenantisolationbeans.Distribution; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.web.util.UriComponentsBuilder; +import com.fasterxml.jackson.databind.ObjectMapper; public class ModelDistributionRequestTest extends BaseTest{ @@ -111,4 +115,22 @@ public class ModelDistributionRequestTest extends BaseTest{ assertEquals(200, response.getStatus()); } + @Test + public void testSuccess_PATCH() throws ApiException, IOException{ + String path = "/onap/so/infra/modelDistributions/v1/distributions/ff3514e3-5a33-55df-13ab-12abad84e7fa"; + ObjectMapper mapper = new ObjectMapper(); + Distribution distRequest = mapper.readValue(requestJSON, Distribution.class); + HttpHeaders headers = new HttpHeaders(); + headers.set("Accept", MediaType.APPLICATION_JSON); + headers.set("Content-Type", MediaType.APPLICATION_JSON); + HttpEntity<Distribution> entity = new HttpEntity<Distribution>(distRequest, headers); + + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(path)); + ResponseEntity<String> response = restTemplate.exchange( + builder.toUriString(), + HttpMethod.PATCH, entity, String.class); + assertEquals(200, response.getStatusCodeValue()); + + } + } |