use of org.onap.so.apihandlerinfra.exceptions.ApiException 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.exceptions.ApiException in project so by onap.
the class Onap3gppServiceInstances method postBPELRequest.
private Response postBPELRequest(InfraActiveRequests currentActiveReq, RequestClientParameter parameter, String orchestrationURI, String requestScope) throws ApiException {
ResponseEntity<String> response = requestHandlerUtils.postRequest(currentActiveReq, parameter, orchestrationURI);
logger.debug("BPEL response : " + response);
int bpelStatus = responseHandler.setStatus(response.getStatusCodeValue());
String jsonResponse;
try {
responseHandler.acceptedResponse(response);
CamundaResponse camundaResponse = responseHandler.getCamundaResponse(response);
String responseBody = camundaResponse.getResponse();
if ("Success".equalsIgnoreCase(camundaResponse.getMessage())) {
jsonResponse = responseBody;
} else {
BPMNFailureException bpmnException = new BPMNFailureException.Builder(String.valueOf(bpelStatus) + responseBody, bpelStatus, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).build();
requestHandlerUtils.updateStatus(currentActiveReq, Status.FAILED, bpmnException.getMessage());
throw bpmnException;
}
} catch (ApiException e) {
requestHandlerUtils.updateStatus(currentActiveReq, Status.FAILED, e.getMessage());
throw e;
}
return builder.buildResponse(HttpStatus.SC_ACCEPTED, parameter.getRequestId(), jsonResponse, parameter.getApiVersion());
}
use of org.onap.so.apihandlerinfra.exceptions.ApiException in project so by onap.
the class Onap3gppServiceInstances method getSubnetCapabilities.
private Response getSubnetCapabilities(List<SubnetTypes> subnetTypes, String version) throws ApiException {
ObjectMapper oMapper = new ObjectMapper();
String inputFileString = "";
Map<String, Object> subnetCapability = new HashMap<>();
BufferedReader br = null;
try {
logger.debug("Reading SubnetCapability file");
br = new BufferedReader(new FileReader(new File(subnetCapabilityConfigFile)));
StringBuilder sb = new StringBuilder();
String line = br.readLine();
while (line != null) {
sb.append(line);
sb.append("\n");
line = br.readLine();
}
inputFileString = sb.toString();
subnetCapability = oMapper.readValue(inputFileString, Map.class);
} catch (Exception e) {
logger.debug("Exception while reading subnet capability value from json", e);
}
Map<String, Object> responseMap = new HashMap<>();
for (SubnetTypes value : subnetTypes) {
if (subnetCapability.containsKey(value.toString())) {
responseMap.put(value.toString(), subnetCapability.get(value.toString()));
}
}
String response = null;
try {
response = oMapper.writeValueAsString(responseMap);
} catch (JsonProcessingException e) {
logger.debug("Exception while converting subnet capability object to String {}", e);
}
return builder.buildResponse(HttpStatus.SC_OK, null, response, version);
}
use of org.onap.so.apihandlerinfra.exceptions.ApiException 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.exceptions.ApiException 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