use of org.onap.so.apihandlerinfra.exceptions.ValidateException in project so by onap.
the class CloudResourcesOrchestration method mapInfraActiveRequestToRequest.
private Request mapInfraActiveRequestToRequest(InfraActiveRequests iar) throws ApiException {
Request request = new Request();
request.setRequestId(iar.getRequestId());
request.setRequestScope(iar.getRequestScope());
request.setRequestType(iar.getRequestAction());
InstanceReferences ir = new InstanceReferences();
if (iar.getOperationalEnvId() != null)
ir.setOperationalEnvironmentId(iar.getOperationalEnvId());
if (iar.getOperationalEnvName() != null)
ir.setOperationalEnvName(iar.getOperationalEnvName());
if (iar.getRequestorId() != null)
ir.setRequestorId(iar.getRequestorId());
request.setInstanceReferences(ir);
String requestBody = iar.getRequestBody();
RequestDetails requestDetails = null;
if (requestBody != null) {
try {
ObjectMapper mapper = new ObjectMapper();
requestDetails = mapper.readValue(requestBody, RequestDetails.class);
} 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;
}
}
request.setRequestDetails(requestDetails);
String startTimeStamp = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(iar.getStartTime()) + " GMT";
request.setStartTime(startTimeStamp);
RequestStatus status = new RequestStatus();
if (iar.getStatusMessage() != null) {
status.setStatusMessage(iar.getStatusMessage());
}
if (iar.getEndTime() != null) {
String endTimeStamp = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(iar.getEndTime()) + " GMT";
status.setTimeStamp(endTimeStamp);
}
if (iar.getRequestStatus() != null) {
status.setRequestState(iar.getRequestStatus());
}
if (iar.getProgress() != null) {
status.setPercentProgress(iar.getProgress().toString());
}
request.setRequestStatus(status);
return request;
}
use of org.onap.so.apihandlerinfra.exceptions.ValidateException in project so by onap.
the class CloudResourcesOrchestration method getOperationEnvironmentStatusFilter.
@GET
@Path("/{version:[vV][1]}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "Get status of an Operational Environment based on filter criteria", responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
@Transactional
public Response getOperationEnvironmentStatusFilter(@Context UriInfo ui, @PathParam("version") String version) throws ApiException {
MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
List<String> requestIdKey = queryParams.get("requestId");
String apiVersion = version.substring(1);
if (queryParams.size() == 1 && requestIdKey != null) {
String requestId = requestIdKey.get(0);
CloudOrchestrationResponse cloudOrchestrationGetResponse = new CloudOrchestrationResponse();
InfraActiveRequests requestDB;
try {
requestDB = requestDbClient.getInfraActiveRequestbyRequestId(requestId);
} catch (Exception e) {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.AvailabilityError).build();
ValidateException validateException = new ValidateException.Builder(e.getMessage(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(e).errorInfo(errorLoggerInfo).build();
throw validateException;
}
if (requestDB == null) {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, ErrorCode.BusinessProcessError).build();
ValidateException validateException = new ValidateException.Builder("Orchestration RequestId " + requestId + " is not found in DB", HttpStatus.SC_NO_CONTENT, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
throw validateException;
}
Request request = mapInfraActiveRequestToRequest(requestDB);
cloudOrchestrationGetResponse.setRequest(request);
return builder.buildResponse(HttpStatus.SC_OK, requestId, cloudOrchestrationGetResponse, apiVersion);
} else {
TenantIsolationRequest tenantIsolationRequest = new TenantIsolationRequest();
List<InfraActiveRequests> activeRequests;
CloudOrchestrationRequestList orchestrationList;
Map<String, String> orchestrationMap;
try {
orchestrationMap = tenantIsolationRequest.getOrchestrationFilters(queryParams);
} catch (ValidationException ex) {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.BusinessProcessError).build();
ValidateException validateException = new ValidateException.Builder(ex.getMessage(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_GENERAL_SERVICE_ERROR).cause(ex).errorInfo(errorLoggerInfo).build();
throw validateException;
}
activeRequests = requestDbClient.getCloudOrchestrationFiltersFromInfraActive(orchestrationMap);
orchestrationList = new CloudOrchestrationRequestList();
List<CloudOrchestrationResponse> requestLists = new ArrayList<>();
for (InfraActiveRequests infraActive : activeRequests) {
Request request = mapInfraActiveRequestToRequest(infraActive);
CloudOrchestrationResponse requestList = new CloudOrchestrationResponse();
requestList.setRequest(request);
requestLists.add(requestList);
}
orchestrationList.setRequestList(requestLists);
return builder.buildResponse(HttpStatus.SC_OK, null, orchestrationList, apiVersion);
}
}
use of org.onap.so.apihandlerinfra.exceptions.ValidateException in project so by onap.
the class ModelDistributionRequest method buildServiceErrorResponse.
private Response buildServiceErrorResponse(int httpResponseCode, MsoException exceptionType, String text, String messageId, List<String> variables) throws ApiException {
RequestError re = new RequestError();
ServiceException se = new ServiceException();
se.setMessageId(messageId);
se.setText(text);
if (variables != null) {
for (String variable : variables) {
se.getVariables().add(variable);
}
}
re.setServiceException(se);
String requestErrorStr;
try {
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(Include.NON_DEFAULT);
requestErrorStr = mapper.writeValueAsString(re);
} catch (JsonProcessingException e) {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_VALIDATION_ERROR, ErrorCode.DataError).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;
}
return Response.status(httpResponseCode).entity(requestErrorStr).build();
}
use of org.onap.so.apihandlerinfra.exceptions.ValidateException in project so by onap.
the class DeactivateVnfOperationalEnvironment method execute.
public void execute(String requestId, CloudOrchestrationRequest request) throws ApiException {
String operationalEnvironmentId = request.getOperationalEnvironmentId();
OperationalEnvironment aaiOpEnv = getAAIOperationalEnvironment(operationalEnvironmentId);
if (aaiOpEnv != null) {
String operationalEnvironmentStatus = aaiOpEnv.getOperationalEnvironmentStatus();
if (StringUtils.isBlank(operationalEnvironmentStatus)) {
String error = "OperationalEnvironmentStatus is null on OperationalEnvironmentId: " + operationalEnvironmentId;
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.DataError).build();
throw new ValidateException.Builder(error, HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
}
if (operationalEnvironmentStatus.equalsIgnoreCase("ACTIVE")) {
aaiOpEnv.setOperationalEnvironmentStatus("INACTIVE");
aaiHelper.updateAaiOperationalEnvironment(operationalEnvironmentId, aaiOpEnv);
} else if (!operationalEnvironmentStatus.equalsIgnoreCase("INACTIVE")) {
String error = "Invalid OperationalEnvironmentStatus on OperationalEnvironmentId: " + operationalEnvironmentId;
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.DataError).build();
ValidateException validateException = new ValidateException.Builder(error, HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
requestDb.updateInfraFailureCompletion(error, requestId, operationalEnvironmentId);
throw validateException;
}
requestDb.updateInfraSuccessCompletion("SUCCESSFULLY Deactivated OperationalEnvironment", requestId, operationalEnvironmentId);
}
}
Aggregations