use of org.onap.so.apihandlerinfra.exceptions.ApiException in project so by onap.
the class RequestHandlerUtils method postBPELRequest.
public Response postBPELRequest(InfraActiveRequests currentActiveReq, RequestClientParameter requestClientParameter, String orchestrationUri, String requestScope) throws ApiException {
ObjectMapper mapper = new ObjectMapper();
ResponseEntity<String> response = postRequest(currentActiveReq, requestClientParameter, orchestrationUri);
ServiceInstancesResponse jsonResponse = null;
int bpelStatus = responseHandler.setStatus(response.getStatusCodeValue());
try {
responseHandler.acceptedResponse(response);
CamundaResponse camundaResponse = responseHandler.getCamundaResponse(response);
String responseBody = camundaResponse.getResponse();
if ("Success".equalsIgnoreCase(camundaResponse.getMessage())) {
jsonResponse = mapper.readValue(responseBody, ServiceInstancesResponse.class);
jsonResponse.getRequestReferences().setRequestId(requestClientParameter.getRequestId());
Optional<URL> selfLinkUrl = buildSelfLinkUrl(currentActiveReq.getRequestUrl(), requestClientParameter.getRequestId());
if (selfLinkUrl.isPresent()) {
jsonResponse.getRequestReferences().setRequestSelfLink(selfLinkUrl.get());
} else {
jsonResponse.getRequestReferences().setRequestSelfLink(null);
}
} else {
BPMNFailureException bpmnException = new BPMNFailureException.Builder(String.valueOf(bpelStatus) + responseBody, bpelStatus, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).build();
updateStatus(currentActiveReq, Status.FAILED, bpmnException.getMessage());
throw bpmnException;
}
} catch (ApiException e) {
updateStatus(currentActiveReq, Status.FAILED, e.getMessage());
throw e;
} catch (IOException e) {
logger.error("Exception caught mapping Camunda JSON response to object: ", e);
updateStatus(currentActiveReq, Status.FAILED, e.getMessage());
throw new ValidateException.Builder("Exception caught mapping Camunda JSON response to object", HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).build();
}
return builder.buildResponse(HttpStatus.SC_ACCEPTED, requestClientParameter.getRequestId(), jsonResponse, requestClientParameter.getApiVersion());
}
use of org.onap.so.apihandlerinfra.exceptions.ApiException in project so by onap.
the class Onap3gppServiceInstances method deleteServiceInstances.
/**
* process delete service instance request and call corresponding workflow
*
* @param request
* @param action
* @param version
* @return
* @throws ApiException
*/
private Response deleteServiceInstances(DeAllocate3gppService 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);
requestHandlerUtils.checkForDuplicateRequests(action, instanceIdMap, requestScope, currentActiveReq, null);
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(null, 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();
String serviceInstanceId = request.getServiceInstanceID();
RequestClientParameter parameter;
try {
parameter = new RequestClientParameter.Builder().setRequestId(requestId).setBaseVfModule(false).setRecipeTimeout(recipeLookupResult.getRecipeTimeout()).setRequestAction(action.name()).setServiceInstanceId(serviceInstanceId).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 ServiceInstances method configurationRecipeLookup.
private Response configurationRecipeLookup(String requestJSON, Action action, HashMap<String, String> instanceIdMap, String version, String requestId, String requestUri) throws ApiException {
String serviceInstanceId;
Boolean aLaCarte = null;
String apiVersion = version.substring(1);
ServiceInstancesRequest sir;
sir = requestHandlerUtils.convertJsonToServiceInstanceRequest(requestJSON, action, requestId, requestUri);
String requestScope = requestHandlerUtils.deriveRequestScope(action, sir, requestUri);
InfraActiveRequests currentActiveReq = msoRequest.createRequestObject(sir, action, requestId, Status.IN_PROGRESS, requestJSON, requestScope);
if (sir.getRequestDetails().getRequestParameters() != null) {
aLaCarte = sir.getRequestDetails().getRequestParameters().getALaCarte();
}
requestHandlerUtils.parseRequest(sir, instanceIdMap, action, version, requestJSON, aLaCarte, requestId, currentActiveReq);
requestHandlerUtils.setInstanceId(currentActiveReq, requestScope, null, instanceIdMap);
String instanceName = sir.getRequestDetails().getRequestInfo().getInstanceName();
requestHandlerUtils.checkForDuplicateRequests(action, instanceIdMap, requestScope, currentActiveReq, instanceName);
ServiceInstancesResponse serviceResponse = new ServiceInstancesResponse();
RequestReferences referencesResponse = new RequestReferences();
referencesResponse.setRequestId(requestId);
serviceResponse.setRequestReferences(referencesResponse);
String orchestrationUri = env.getProperty(CommonConstants.ALACARTE_ORCHESTRATION);
String timeOut = env.getProperty(CommonConstants.ALACARTE_RECIPE_TIMEOUT);
if (StringUtils.isBlank(orchestrationUri) || StringUtils.isBlank(timeOut)) {
String error = StringUtils.isBlank(orchestrationUri) ? "ALaCarte Orchestration URI not found in properties" : "ALaCarte Recipe Timeout not found in properties";
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, ErrorCode.DataError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
ValidateException validateException = new ValidateException.Builder(error, HttpStatus.SC_NOT_FOUND, ErrorNumbers.SVC_GENERAL_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
requestHandlerUtils.updateStatus(currentActiveReq, Status.FAILED, validateException.getMessage());
throw validateException;
}
serviceInstanceId = "";
String configurationId = "";
String pnfCorrelationId = "";
if (sir.getServiceInstanceId() != null) {
serviceInstanceId = sir.getServiceInstanceId();
}
if (sir.getConfigurationId() != null) {
configurationId = sir.getConfigurationId();
}
pnfCorrelationId = getPnfCorrelationId(sir);
try {
infraActiveRequestsClient.save(currentActiveReq);
} catch (Exception 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();
}
if (!requestScope.equalsIgnoreCase(ModelType.service.name())) {
aLaCarte = true;
} else if (aLaCarte == null) {
aLaCarte = false;
}
RequestClientParameter requestClientParameter = null;
try {
requestClientParameter = new RequestClientParameter.Builder().setRequestId(requestId).setBaseVfModule(false).setRecipeTimeout(Integer.parseInt(timeOut)).setRequestAction(action.toString()).setServiceInstanceId(serviceInstanceId).setPnfCorrelationId(pnfCorrelationId).setConfigurationId(configurationId).setRequestDetails(requestHandlerUtils.mapJSONtoMSOStyle(requestJSON, sir, aLaCarte, action)).setApiVersion(apiVersion).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, orchestrationUri, requestScope);
}
use of org.onap.so.apihandlerinfra.exceptions.ApiException in project so by onap.
the class ServiceInstances method serviceInstances.
public Response serviceInstances(String requestJSON, Actions action, HashMap<String, String> instanceIdMap, String version, String requestId, String requestUri, HashMap<String, String> queryParams) throws ApiException {
String serviceInstanceId;
Boolean aLaCarte = null;
ServiceInstancesRequest sir;
String apiVersion = version.substring(1);
sir = requestHandlerUtils.convertJsonToServiceInstanceRequest(requestJSON, action, requestId, requestUri);
action = handleReplaceInstance(action, sir);
String requestScope = requestHandlerUtils.deriveRequestScope(action, sir, requestUri);
try {
requestValidatorListenerRunner.runValidations(requestUri, instanceIdMap, sir, queryParams, action);
} catch (ApiException e) {
msoRequest.createErrorRequestRecord(Status.FAILED, requestId, e.getMessage(), action, requestScope, requestJSON, requestHandlerUtils.getServiceInstanceIdForValidationError(sir, instanceIdMap, requestScope).orElse(null), sir);
throw e;
}
InfraActiveRequests currentActiveReq = msoRequest.createRequestObject(sir, action, requestId, Status.IN_PROGRESS, requestJSON, requestScope);
if (sir.getRequestDetails().getRequestParameters() != null) {
aLaCarte = sir.getRequestDetails().getRequestParameters().getALaCarte();
}
requestHandlerUtils.parseRequest(sir, instanceIdMap, action, version, requestJSON, aLaCarte, requestId, currentActiveReq);
if ((action == Action.replaceInstance || action == Action.replaceInstanceRetainAssignments) && (requestScope.equals(ModelType.vnf.toString()) || requestScope.equals(ModelType.vfModule.toString())) && sir.getRequestDetails().getCloudConfiguration() == null) {
CloudConfiguration cloudConfiguration = getCloudConfigurationOnReplace(requestScope, instanceIdMap, currentActiveReq);
sir.getRequestDetails().setCloudConfiguration(cloudConfiguration);
setCloudConfigurationCurrentActiveRequest(cloudConfiguration, currentActiveReq);
}
requestHandlerUtils.setInstanceId(currentActiveReq, requestScope, null, instanceIdMap);
String instanceName = null;
if (sir.getRequestDetails().getRequestInfo() != null) {
instanceName = sir.getRequestDetails().getRequestInfo().getInstanceName();
}
boolean alaCarteFlag = msoRequest.getAlacarteFlag(sir);
String vnfType = msoRequest.getVnfType(sir, requestScope);
String networkType = msoRequest.getNetworkType(sir, requestScope);
String sdcServiceModelVersion = msoRequest.getSDCServiceModelVersion(sir);
String vfModuleType = msoRequest.getVfModuleType(sir, requestScope);
if (requestScope.equalsIgnoreCase(ModelType.vnf.name()) && vnfType != null) {
currentActiveReq.setVnfType(vnfType);
} else if (requestScope.equalsIgnoreCase(ModelType.network.name()) && networkType != null) {
currentActiveReq.setNetworkType(networkType);
}
requestHandlerUtils.checkForDuplicateRequests(action, instanceIdMap, requestScope, currentActiveReq, instanceName);
ServiceInstancesResponse serviceResponse = new ServiceInstancesResponse();
RequestReferences referencesResponse = new RequestReferences();
referencesResponse.setRequestId(requestId);
serviceResponse.setRequestReferences(referencesResponse);
RecipeLookupResult recipeLookupResult = requestHandlerUtils.getServiceInstanceOrchestrationURI(sir, action, alaCarteFlag, currentActiveReq);
String serviceInstanceType = requestHandlerUtils.getServiceType(requestScope, sir, alaCarteFlag);
ModelInfo modelInfo = sir.getRequestDetails().getModelInfo();
ModelType modelType = requestHandlerUtils.getModelType(action, modelInfo);
Boolean isBaseVfModule = false;
if (modelType.equals(ModelType.vfModule)) {
isBaseVfModule = requestHandlerUtils.getIsBaseVfModule(modelInfo, action, vnfType, sdcServiceModelVersion, currentActiveReq);
}
serviceInstanceId = requestHandlerUtils.setServiceInstanceId(requestScope, sir);
String vnfId = "";
String vfModuleId = "";
String volumeGroupId = "";
String networkId = "";
String pnfCorrelationId = "";
String instanceGroupId = null;
if (sir.getVnfInstanceId() != null) {
vnfId = sir.getVnfInstanceId();
}
if (sir.getVfModuleInstanceId() != null) {
vfModuleId = sir.getVfModuleInstanceId();
}
if (sir.getVolumeGroupInstanceId() != null) {
volumeGroupId = sir.getVolumeGroupInstanceId();
}
if (sir.getNetworkInstanceId() != null) {
networkId = sir.getNetworkInstanceId();
}
if (sir.getInstanceGroupId() != null) {
instanceGroupId = sir.getInstanceGroupId();
}
pnfCorrelationId = getPnfCorrelationId(sir);
try {
infraActiveRequestsClient.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();
}
if (!requestScope.equalsIgnoreCase(ModelType.service.name()) && action != Action.recreateInstance && !requestScope.equalsIgnoreCase(ModelType.vnf.name())) {
aLaCarte = true;
} else if (aLaCarte == null) {
aLaCarte = false;
}
RequestClientParameter requestClientParameter;
try {
requestClientParameter = new RequestClientParameter.Builder().setRequestId(requestId).setBaseVfModule(isBaseVfModule).setRecipeTimeout(recipeLookupResult.getRecipeTimeout()).setRequestAction(action.toString()).setServiceInstanceId(serviceInstanceId).setPnfCorrelationId(pnfCorrelationId).setVnfId(vnfId).setVfModuleId(vfModuleId).setVolumeGroupId(volumeGroupId).setNetworkId(networkId).setServiceType(serviceInstanceType).setVnfType(vnfType).setVfModuleType(vfModuleType).setNetworkType(networkType).setRequestDetails(requestHandlerUtils.mapJSONtoMSOStyle(requestJSON, sir, aLaCarte, action)).setApiVersion(apiVersion).setALaCarte(aLaCarte).setRequestUri(requestUri).setInstanceGroupId(instanceGroupId).build();
} catch (IOException 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 requestHandlerUtils.postBPELRequest(currentActiveReq, requestClientParameter, recipeLookupResult.getOrchestrationURI(), requestScope);
}
use of org.onap.so.apihandlerinfra.exceptions.ApiException in project so by onap.
the class ServiceInstances method deleteInstanceGroups.
/**
* This method deletes the Instance Groups.
*
* This method will check whether the request is not duplicate in requestdb. if its not then will save as a new
* request. And will send a POST request to BEPL client to delete the Insatnce Groups.
*
* @param action
* @param instanceIdMap
* @param version
* @param requestId
* @param requestUri
* @param requestContext
* @return
* @throws ApiException
*/
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_INSTANCE_ID);
Boolean aLaCarte = true;
String apiVersion = version.substring(1);
ServiceInstancesRequest sir = new ServiceInstancesRequest();
sir.setInstanceGroupId(instanceGroupId);
String requestScope = ModelType.instanceGroup.toString();
InfraActiveRequests currentActiveReq = msoRequest.createRequestObject(sir, action, requestId, Status.IN_PROGRESS, null, requestScope);
requestHandlerUtils.setInstanceId(currentActiveReq, requestScope, null, instanceIdMap);
try {
requestHandlerUtils.validateHeaders(requestContext);
} catch (ValidationException e) {
logger.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.checkForDuplicateRequests(action, instanceIdMap, requestScope, currentActiveReq, null);
ServiceInstancesResponse serviceResponse = new ServiceInstancesResponse();
RequestReferences referencesResponse = new RequestReferences();
referencesResponse.setRequestId(requestId);
serviceResponse.setRequestReferences(referencesResponse);
Boolean isBaseVfModule = false;
RecipeLookupResult recipeLookupResult = new RecipeLookupResult("/mso/async/services/WorkflowActionBB", 180);
try {
infraActiveRequestsClient.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();
}
RequestClientParameter requestClientParameter = new RequestClientParameter.Builder().setRequestId(requestId).setBaseVfModule(isBaseVfModule).setRecipeTimeout(recipeLookupResult.getRecipeTimeout()).setRequestAction(action.toString()).setApiVersion(apiVersion).setALaCarte(aLaCarte).setRequestUri(requestUri).setInstanceGroupId(instanceGroupId).build();
return requestHandlerUtils.postBPELRequest(currentActiveReq, requestClientParameter, recipeLookupResult.getOrchestrationURI(), requestScope);
}
Aggregations