use of org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo 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.logging.ErrorLoggerInfo 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.logging.ErrorLoggerInfo 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);
}
use of org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo in project so by onap.
the class TasksHandler method getTaskInfo.
// Makes a GET call to Camunda to get variables for this task
private TaskList getTaskInfo(String taskId) throws ApiException {
TaskList taskList;
String getRequestUrl = UriBuilder.fromUri(requestUrl).path(taskId).path("variables").build().toString();
ResponseEntity<String> getResponse;
getResponse = camundaClient.get(getRequestUrl);
responseHandler.acceptedResponse(getResponse);
String respBody = getResponse.getBody();
if (respBody != null) {
taskList = buildTaskList(taskId, respBody);
} else {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, ErrorCode.AvailabilityError).build();
throw new BPMNFailureException.Builder(String.valueOf(HttpStatus.SC_BAD_GATEWAY), HttpStatus.SC_BAD_GATEWAY, ErrorNumbers.SVC_NO_SERVER_RESOURCES).errorInfo(errorLoggerInfo).build();
}
return taskList;
}
use of org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo in project so by onap.
the class TasksHandler method queryFilters.
@Path("/{version:[vV]1}")
@GET
@Operation(description = "Finds Manual Tasks", responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
@Transactional
public Response queryFilters(@QueryParam("taskId") String taskId, @QueryParam("originalRequestId") String originalRequestId, @QueryParam("subscriptionServiceType") String subscriptionServiceType, @QueryParam("nfRole") String nfRole, @QueryParam("buildingBlockName") String buildingBlockName, @QueryParam("originalRequestDate") String originalRequestDate, @QueryParam("originalRequestorId") String originalRequestorId, @PathParam("version") String version) throws ApiException {
String apiVersion = version.substring(1);
// Prepare the query string to /task interface
TaskVariables tv = new TaskVariables();
List<TaskVariableValue> tvvList = new ArrayList<>();
if (originalRequestId != null) {
TaskVariableValue tvv = new TaskVariableValue();
tvv.setName("originalRequestId");
tvv.setValue(originalRequestId);
tvv.setOperator("eq");
tvvList.add(tvv);
}
if (subscriptionServiceType != null) {
TaskVariableValue tvv = new TaskVariableValue();
tvv.setName("subscriptionServiceType");
tvv.setValue(subscriptionServiceType);
tvv.setOperator("eq");
tvvList.add(tvv);
}
if (nfRole != null) {
TaskVariableValue tvv = new TaskVariableValue();
tvv.setName("nfRole");
tvv.setValue(nfRole);
tvv.setOperator("eq");
tvvList.add(tvv);
}
if (buildingBlockName != null) {
TaskVariableValue tvv = new TaskVariableValue();
tvv.setName("buildingBlockName");
tvv.setValue(buildingBlockName);
tvv.setOperator("eq");
tvvList.add(tvv);
}
if (originalRequestDate != null) {
TaskVariableValue tvv = new TaskVariableValue();
tvv.setName("originalRequestDate");
tvv.setValue(originalRequestDate);
tvv.setOperator("eq");
tvvList.add(tvv);
}
if (originalRequestorId != null) {
TaskVariableValue tvv = new TaskVariableValue();
tvv.setName("originalRequestorId");
tvv.setValue(originalRequestorId);
tvv.setOperator("eq");
tvvList.add(tvv);
}
tv.setTaskVariables(tvvList);
ResponseEntity<String> response = null;
String camundaJsonReq = null;
try {
ObjectMapper mapper = new ObjectMapper();
camundaJsonReq = mapper.writeValueAsString(tv);
} catch (JsonProcessingException e) {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.SchemaError).build();
throw 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();
}
response = camundaClient.post(camundaJsonReq, requestUrl);
TasksGetResponse trr = new TasksGetResponse();
List<TaskList> taskList = new ArrayList<>();
int bpelStatus = responseHandler.setStatus(response.getStatusCodeValue());
String respBody = response.getBody();
responseHandler.acceptedOrNoContentResponse(response);
if (null != respBody) {
JSONArray data = new JSONArray(respBody);
for (int i = 0; i < data.length(); i++) {
JSONObject taskEntry = data.getJSONObject(i);
String id = taskEntry.getString("id");
if (taskId != null && !taskId.equals(id)) {
continue;
}
// Get variables info for each task ID
TaskList taskListEntry = null;
taskListEntry = getTaskInfo(id);
taskList.add(taskListEntry);
}
trr.setTaskList(taskList);
} else {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_RESPONSE_ERROR, ErrorCode.BusinessProcessError).build();
throw new BPMNFailureException.Builder(String.valueOf(bpelStatus), bpelStatus, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
}
String jsonResponse = null;
try {
ObjectMapper mapper = new ObjectMapper();
jsonResponse = mapper.writeValueAsString(trr);
} catch (JsonProcessingException e) {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.SchemaError).build();
throw 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();
}
return builder.buildResponse(HttpStatus.SC_ACCEPTED, "", jsonResponse, apiVersion);
}
Aggregations