use of org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo in project so by onap.
the class InstanceManagement method processCustomWorkflowRequest.
private Response processCustomWorkflowRequest(final String requestJSON, final Actions action, final Map<String, String> instanceIdMap, final String version, final String requestId, final ContainerRequestContext requestContext, final boolean aLaCarte) throws ApiException {
String pnfName = null;
String vnfType = null;
String workflowUuid = null;
String vnfInstanceId = null;
String svcInstanceId = null;
final String apiVersion = version.substring(1);
if (instanceIdMap != null && !instanceIdMap.isEmpty()) {
pnfName = instanceIdMap.get("pnfName");
workflowUuid = instanceIdMap.get("workflowUuid");
vnfInstanceId = instanceIdMap.get("vnfInstanceId");
svcInstanceId = instanceIdMap.get("serviceInstanceId");
}
final String requestUri = requestHandlerUtils.getRequestUri(requestContext, URI_PREFIX);
final ServiceInstancesRequest svcInsReq = requestHandlerUtils.convertJsonToServiceInstanceRequest(requestJSON, action, requestId, requestUri);
final String requestScope = requestHandlerUtils.deriveRequestScope(action, svcInsReq, requestUri);
InfraActiveRequests currentActiveReq = msoRequest.createRequestObject(svcInsReq, action, requestId, Status.IN_PROGRESS, requestJSON, requestScope);
try {
requestHandlerUtils.validateHeaders(requestContext);
} catch (ValidationException e) {
LOG.error("Exception occurred", e);
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_VALIDATION_ERROR, ErrorCode.SchemaError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
ValidateException validateException = new ValidateException.Builder(e.getMessage(), HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build();
requestHandlerUtils.updateStatus(currentActiveReq, Status.FAILED, validateException.getMessage());
throw validateException;
}
requestHandlerUtils.parseRequest(svcInsReq, instanceIdMap, action, version, requestJSON, aLaCarte, requestId, currentActiveReq);
requestHandlerUtils.setInstanceId(currentActiveReq, requestScope, null, instanceIdMap);
if (requestScope.equalsIgnoreCase(ModelType.vnf.name())) {
vnfType = msoRequest.getVnfType(svcInsReq, requestScope);
currentActiveReq.setVnfType(vnfType);
}
checkDuplicateAndBuildError(action, instanceIdMap, requestScope, currentActiveReq);
final RecipeLookupResult recipeLookupResult = getInstanceManagementWorkflowRecipe(currentActiveReq, workflowUuid);
currentActiveReq = setWorkflowNameAndOperationName(currentActiveReq, workflowUuid);
saveCurrentActiveRequest(currentActiveReq);
RequestClientParameter requestClientParameter;
try {
requestClientParameter = new RequestClientParameter.Builder().setRequestId(requestId).setRecipeTimeout(recipeLookupResult.getRecipeTimeout()).setRequestAction(action.toString()).setServiceInstanceId(svcInstanceId).setVnfId(vnfInstanceId).setVnfType(vnfType).setPnfCorrelationId(pnfName).setApiVersion(apiVersion).setRequestDetails(requestHandlerUtils.mapJSONtoMSOStyle(requestJSON, null, aLaCarte, action)).setALaCarte(aLaCarte).setRequestUri(requestUri).build();
} catch (IOException e) {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_RESPONSE_ERROR, ErrorCode.SchemaError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
throw new ValidateException.Builder("Unable to generate RequestClientParamter object" + e.getMessage(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo).build();
}
return requestHandlerUtils.postBPELRequest(currentActiveReq, requestClientParameter, recipeLookupResult.getOrchestrationURI(), requestScope);
}
use of org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo in project so by onap.
the class ManualTasks method completeTask.
@POST
@Path("/{version:[vV]1}/{taskId}/complete")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "Complete specified task", responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
@Transactional
public Response completeTask(String request, @PathParam("version") String version, @PathParam("taskId") String taskId, @Context ContainerRequestContext requestContext) throws ApiException {
String requestId = requestContext.getProperty("requestId").toString();
logger.info(LoggingAnchor.TWO, MessageEnum.APIH_GENERATED_REQUEST_ID.toString(), requestId);
logger.debug("requestId is: {}", requestId);
TasksRequest taskRequest = null;
String apiVersion = version.substring(1);
try {
ObjectMapper mapper = new ObjectMapper();
taskRequest = mapper.readValue(request, TasksRequest.class);
if (taskRequest.getRequestDetails() == null) {
throw new ValidationException("requestDetails");
}
if (taskRequest.getRequestDetails().getRequestInfo() == null) {
throw new ValidationException("requestInfo");
}
if (empty(taskRequest.getRequestDetails().getRequestInfo().getSource())) {
throw new ValidationException("source");
}
if (empty(taskRequest.getRequestDetails().getRequestInfo().getRequestorId())) {
throw new ValidationException("requestorId");
}
} catch (IOException e) {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.SchemaError).build();
ValidateException validateException = new ValidateException.Builder("Mapping of request to JSON object failed: " + e.getMessage(), HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build();
throw validateException;
} catch (ValidationException e) {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.SchemaError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
ValidateException validateException = new ValidateException.Builder("Mapping of request to JSON Object failed. " + e.getMessage(), HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo).build();
throw validateException;
}
// Transform the request to Camunda-style Complete request
Variables variablesForComplete = new Variables();
Value sourceValue = new Value();
sourceValue.setValue(taskRequest.getRequestDetails().getRequestInfo().getSource());
Value responseValue = new Value();
responseValue.setValue(taskRequest.getRequestDetails().getRequestInfo().getResponseValue().name());
Value requestorIdValue = new Value();
requestorIdValue.setValue(taskRequest.getRequestDetails().getRequestInfo().getRequestorId());
variablesForComplete.setSource(sourceValue);
variablesForComplete.setResponseValue(responseValue);
variablesForComplete.setRequestorId(requestorIdValue);
String camundaJsonReq;
try {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
camundaJsonReq = mapper.writeValueAsString(variablesForComplete);
} catch (JsonProcessingException e) {
logger.error("Mapping of JSON object to Camunda request failed");
ValidateException validateException = new ValidateException.Builder("Mapping of JSON object to Camunda request failed", HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_GENERAL_SERVICE_ERROR).build();
throw validateException;
}
String requestUrl = taskUri + "/" + taskId + "/complete";
ResponseEntity<String> response = camundaClient.post(camundaJsonReq, requestUrl);
int bpelStatus = responseHandler.setStatus(response.getStatusCodeValue());
responseHandler.acceptedOrNoContentResponse(response);
logger.debug("Received good response from Camunda");
TaskRequestReference trr = new TaskRequestReference();
trr.setTaskId(taskId);
String completeResp = null;
try {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
completeResp = mapper.writeValueAsString(trr);
} catch (JsonProcessingException e) {
logger.error("Unable to map response from Camunda");
ValidateException validateException = new ValidateException.Builder("Request Failed due to bad response format", bpelStatus, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).build();
throw validateException;
}
logger.debug("Response to the caller: {}", completeResp);
logger.debug("End of the transaction, the final response is: {}", completeResp);
return builder.buildResponse(HttpStatus.SC_ACCEPTED, requestId, completeResp, apiVersion);
}
use of org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo in project so by onap.
the class Onap3gppServiceInstances method processServiceInstanceRequest.
/**
* Process allocate service request and send request to corresponding workflow
*
* @param request
* @param action
* @param version
* @return
* @throws ApiException
*/
private Response processServiceInstanceRequest(Allocate3gppService request, Action action, String version, String requestId, HashMap<String, String> instanceIdMap, String requestUri) throws ApiException {
String defaultServiceModelName = "COMMON_SS_DEFAULT";
String requestScope = ModelType.service.name();
String apiVersion = version.substring(1);
String serviceRequestJson = toString.apply(request);
if (serviceRequestJson != null) {
InfraActiveRequests currentActiveReq = createRequestObject(request, action, requestId, Status.IN_PROGRESS, requestScope, serviceRequestJson);
String instanceName = request.getName();
requestHandlerUtils.checkForDuplicateRequests(action, instanceIdMap, requestScope, currentActiveReq, instanceName);
try {
requestsDbClient.save(currentActiveReq);
} catch (Exception e) {
logger.error("Exception occurred", e);
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.DataError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
throw new RequestDbFailureException.Builder(SAVE_TO_DB, e.toString(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(e).errorInfo(errorLoggerInfo).build();
}
RecipeLookupResult recipeLookupResult;
try {
recipeLookupResult = getServiceInstanceOrchestrationURI(request.getModelUuid(), action, defaultServiceModelName);
} catch (Exception e) {
logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ACCESS_EXC.toString(), MSO_PROP_APIHANDLER_INFRA, 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);
logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
return response;
}
if (recipeLookupResult == null) {
logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND.toString(), MSO_PROP_APIHANDLER_INFRA, 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);
logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
return response;
}
String serviceInstanceType = request.getSubscriptionServiceType();
RequestClientParameter parameter;
try {
parameter = new RequestClientParameter.Builder().setRequestId(requestId).setBaseVfModule(false).setRecipeTimeout(recipeLookupResult.getRecipeTimeout()).setRequestAction(action.name()).setServiceInstanceId(null).setServiceType(serviceInstanceType).setRequestDetails(serviceRequestJson).setApiVersion(version).setALaCarte(false).setRecipeParamXsd(recipeLookupResult.getRecipeParamXsd()).setApiVersion(apiVersion).build();
} catch (Exception e) {
logger.error("Exception occurred", e);
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_RESPONSE_ERROR, ErrorCode.SchemaError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
throw new ValidateException.Builder("Unable to generate RequestClientParamter object" + e.getMessage(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo).build();
}
return postBPELRequest(currentActiveReq, parameter, recipeLookupResult.getOrchestrationURI(), requestScope);
} else {
Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, MsoException.ServiceException, "JsonProcessingException occurred - serviceRequestJson is null", ErrorNumbers.SVC_BAD_PARAMETER, null, version);
return response;
}
}
use of org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo in project so by onap.
the class OrchestrationRequests method infraActiveRequestLookup.
protected InfraActiveRequests infraActiveRequestLookup(String requestId) throws ApiException {
InfraActiveRequests infraActiveRequest = null;
try {
infraActiveRequest = requestsDbClient.getInfraActiveRequestbyRequestId(requestId);
} catch (Exception e) {
logger.error("Exception occurred while communicating with RequestDb during InfraActiveRequest lookup ", e);
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.AvailabilityError).build();
ValidateException validateException = new ValidateException.Builder("Exception occurred while communicating with RequestDb during InfraActiveRequest lookup", HttpStatus.SC_NOT_FOUND, ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB).cause(e).errorInfo(errorLoggerInfo).build();
throw validateException;
}
if (infraActiveRequest == null) {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, ErrorCode.BusinessProcessError).build();
ValidateException validateException = new ValidateException.Builder("Null response from RequestDB when searching by RequestId " + requestId, HttpStatus.SC_NOT_FOUND, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
throw validateException;
}
return infraActiveRequest;
}
use of org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo in project so by onap.
the class OrchestrationRequests method unlockOrchestrationRequest.
@POST
@Path("/{version: [vV][4-7]}/{requestId}/unlock")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "Unlock Orchestrated Requests for a given requestId", responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
@Transactional
public Response unlockOrchestrationRequest(String requestJSON, @PathParam("requestId") String requestId, @PathParam("version") String version) throws ApiException {
logger.debug("requestId is: {}", requestId);
ServiceInstancesRequest sir;
try {
ObjectMapper mapper = new ObjectMapper();
sir = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
} catch (IOException e) {
logger.error("Exception occurred", e);
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.SchemaError).build();
ValidateException validateException = new ValidateException.Builder("Mapping of request to JSON object failed : " + e.getMessage(), HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build();
throw validateException;
}
try {
msoRequest.parseOrchestration(sir);
} catch (Exception e) {
logger.error("Exception occurred", e);
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.SchemaError).build();
ValidateException validateException = new ValidateException.Builder("Error parsing request: " + e.getMessage(), HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build();
throw validateException;
}
InfraActiveRequests infraActiveRequest = infraActiveRequestLookup(requestId);
String status = infraActiveRequest.getRequestStatus();
if (Status.IN_PROGRESS.toString().equalsIgnoreCase(status) || Status.PENDING.toString().equalsIgnoreCase(status) || Status.PENDING_MANUAL_TASK.toString().equalsIgnoreCase(status)) {
infraActiveRequest.setRequestStatus(Status.UNLOCKED.toString());
infraActiveRequest.setLastModifiedBy(Constants.MODIFIED_BY_APIHANDLER);
infraActiveRequest.setRequestId(requestId);
requestsDbClient.save(infraActiveRequest);
} else {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, ErrorCode.DataError).build();
ValidateException validateException = new ValidateException.Builder("Orchestration RequestId " + requestId + " has a status of " + status + " and can not be unlocked", HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
throw validateException;
}
return Response.status(HttpStatus.SC_NO_CONTENT).entity("").build();
}
Aggregations