use of org.onap.so.apihandlerinfra.exceptions.ApiException in project so by onap.
the class ServiceIntentApiHandler 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 E2EServiceInstances method updateE2EserviceInstances.
private Response updateE2EserviceInstances(String requestJSON, Action action, String version) throws ApiException {
String requestId = UUID.randomUUID().toString();
E2EServiceInstanceRequest e2eSir;
String serviceId = instanceIdMap.get(SERVICE_ID);
ObjectMapper mapper = new ObjectMapper();
try {
e2eSir = mapper.readValue(requestJSON, E2EServiceInstanceRequest.class);
} catch (Exception 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);
logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_REQUEST_VALIDATION_ERROR.toString(), MSO_PROP_APIHANDLER_INFRA, ErrorCode.SchemaError.getValue(), requestJSON, e);
logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
return response;
}
ServiceInstancesRequest sir = mapReqJsonToSvcInstReq(e2eSir, requestJSON);
sir.getRequestDetails().getRequestParameters().setaLaCarte(true);
try {
parseRequest(sir, instanceIdMap, action, version, requestJSON, false, requestId);
} catch (Exception 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) {
logger.debug("Logging failed message to the database");
}
logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_REQUEST_VALIDATION_ERROR.toString(), MSO_PROP_APIHANDLER_INFRA, ErrorCode.SchemaError.getValue(), requestJSON, e);
logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
return response;
}
RecipeLookupResult recipeLookupResult;
try {
recipeLookupResult = getServiceInstanceOrchestrationURI(e2eSir.getService().getServiceUuid(), action);
} 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 = e2eSir.getService().getServiceType();
String sirRequestJson = convertToString(sir);
RequestClientParameter postParam = new RequestClientParameter.Builder().setRequestId(requestId).setBaseVfModule(false).setRecipeTimeout(recipeLookupResult.getRecipeTimeout()).setRequestAction(action.name()).setServiceInstanceId(serviceId).setServiceType(serviceInstanceType).setRequestDetails(sirRequestJson).setApiVersion(version).setALaCarte(false).setRecipeParamXsd(recipeLookupResult.getRecipeParamXsd()).build();
return postRequest(recipeLookupResult.getOrchestrationURI(), postParam, version);
}
use of org.onap.so.apihandlerinfra.exceptions.ApiException in project so by onap.
the class E2EServiceInstances method processE2EserviceInstances.
private Response processE2EserviceInstances(String requestJSON, Action action, HashMap<String, String> instanceIdMap, String version) throws ApiException {
String requestId = UUID.randomUUID().toString();
E2EServiceInstanceRequest e2eSir;
MsoRequest msoRequest = new MsoRequest();
ObjectMapper mapper = new ObjectMapper();
try {
e2eSir = mapper.readValue(requestJSON, E2EServiceInstanceRequest.class);
} catch (Exception 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);
logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_REQUEST_VALIDATION_ERROR.toString(), MSO_PROP_APIHANDLER_INFRA, ErrorCode.SchemaError.getValue(), requestJSON, e);
logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
return response;
}
ServiceInstancesRequest sir = mapReqJsonToSvcInstReq(e2eSir, requestJSON);
sir.getRequestDetails().getRequestParameters().setaLaCarte(true);
try {
parseRequest(sir, instanceIdMap, action, version, requestJSON, false, requestId);
} catch (Exception 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) {
logger.debug("Logging failed message to the database");
}
logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_REQUEST_VALIDATION_ERROR.toString(), MSO_PROP_APIHANDLER_INFRA, ErrorCode.SchemaError.getValue(), requestJSON, e);
logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
return response;
}
RecipeLookupResult recipeLookupResult;
try {
recipeLookupResult = getServiceInstanceOrchestrationURI(e2eSir.getService().getServiceUuid(), action);
} 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 = e2eSir.getService().getServiceType();
String serviceId = e2eSir.getService().getServiceId();
String sirRequestJson = convertToString(sir);
RequestClientParameter parameter = new RequestClientParameter.Builder().setRequestId(requestId).setBaseVfModule(false).setRecipeTimeout(recipeLookupResult.getRecipeTimeout()).setRequestAction(action.name()).setServiceInstanceId(serviceId).setServiceType(serviceInstanceType).setRequestDetails(sirRequestJson).setApiVersion(version).setALaCarte(false).setRecipeParamXsd(recipeLookupResult.getRecipeParamXsd()).build();
return postRequest(recipeLookupResult.getOrchestrationURI(), parameter, version);
}
use of org.onap.so.apihandlerinfra.exceptions.ApiException in project so by onap.
the class E2EServiceInstances method compareModelwithTargetVersion.
private Response compareModelwithTargetVersion(String requestJSON, Action action, HashMap<String, String> instanceIdMap, String version) throws ApiException {
String requestId = UUID.randomUUID().toString();
CompareModelsRequest e2eCompareModelReq;
ObjectMapper mapper = new ObjectMapper();
try {
e2eCompareModelReq = mapper.readValue(requestJSON, CompareModelsRequest.class);
} catch (Exception 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);
logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_REQUEST_VALIDATION_ERROR.toString(), MSO_PROP_APIHANDLER_INFRA, ErrorCode.SchemaError.getValue(), requestJSON, e);
logger.debug(END_OF_THE_TRANSACTION + response.getEntity().toString());
return response;
}
return runCompareModelBPMWorkflow(e2eCompareModelReq, requestJSON, requestId, action, version);
}
use of org.onap.so.apihandlerinfra.exceptions.ApiException in project so by onap.
the class InstanceManagement method getInstanceManagementWorkflowRecipe.
private RecipeLookupResult getInstanceManagementWorkflowRecipe(InfraActiveRequests currentActiveReq, String workflowUuid) throws ApiException {
RecipeLookupResult recipeLookupResult;
try {
recipeLookupResult = getCustomWorkflowUri(workflowUuid);
} catch (Exception 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(e.getMessage(), HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build();
requestHandlerUtils.updateStatus(currentActiveReq, Status.FAILED, validateException.getMessage());
throw validateException;
}
if (recipeLookupResult == null) {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.DataError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
RecipeNotFoundException recipeNotFoundExceptionException = new RecipeNotFoundException.Builder("Recipe could not be retrieved from catalog DB.", HttpStatus.SC_NOT_FOUND, ErrorNumbers.SVC_GENERAL_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
requestHandlerUtils.updateStatus(currentActiveReq, Status.FAILED, recipeNotFoundExceptionException.getMessage());
throw recipeNotFoundExceptionException;
}
return recipeLookupResult;
}
Aggregations