use of org.onap.so.exceptions.ValidationException in project so by onap.
the class CloudResourcesOrchestration method unlockOrchestrationRequest.
@POST
@Path("/{version: [vV][1]}/{requestId}/unlock")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "Unlock CloudOrchestration requests for a specified requestId")
@Transactional
public Response unlockOrchestrationRequest(String requestJSON, @PathParam("requestId") String requestId, @PathParam("version") String version) throws ApiException {
TenantIsolationRequest msoRequest = new TenantIsolationRequest(requestId);
InfraActiveRequests infraActiveRequest;
CloudOrchestrationRequest cor;
logger.debug("requestId is: {}", requestId);
try {
ObjectMapper mapper = new ObjectMapper();
cor = mapper.readValue(requestJSON, CloudOrchestrationRequest.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;
}
try {
msoRequest.parseOrchestration(cor);
} catch (ValidationException e) {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.SchemaError).build();
ValidateException validateException = new ValidateException.Builder(e.getMessage(), HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build();
throw validateException;
}
try {
infraActiveRequest = requestDbClient.getInfraActiveRequestbyRequestId(requestId);
} catch (Exception e) {
ValidateException validateException = new ValidateException.Builder(e.getMessage(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(e).build();
throw validateException;
}
if (infraActiveRequest == null) {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, ErrorCode.BusinessProcessError).build();
ValidateException validateException = new ValidateException.Builder("Orchestration RequestId " + requestId + " is not found in DB", HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
throw validateException;
} else {
String status = infraActiveRequest.getRequestStatus();
if ("IN_PROGRESS".equalsIgnoreCase(status) || "PENDING".equalsIgnoreCase(status) || "PENDING_MANUAL_TASK".equalsIgnoreCase(status)) {
infraActiveRequest.setRequestStatus("UNLOCKED");
infraActiveRequest.setLastModifiedBy(Constants.MODIFIED_BY_APIHANDLER);
infraActiveRequest.setRequestId(requestId);
requestDbClient.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();
}
use of org.onap.so.exceptions.ValidationException 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.exceptions.ValidationException in project so by onap.
the class TenantIsolationRequest method parse.
void parse(CloudOrchestrationRequest request, HashMap<String, String> instanceIdMap, Action action) throws ValidationException {
this.cor = request;
this.requestInfo = request.getRequestDetails().getRequestInfo();
try {
ObjectMapper mapper = new ObjectMapper();
requestJSON = mapper.writeValueAsString(request.getRequestDetails());
} catch (JsonProcessingException e) {
logger.error("Exception in JSON processing", e);
throw new ValidationException("Parse ServiceInstanceRequest to JSON string", true);
}
String envId = null;
if (instanceIdMap != null) {
envId = instanceIdMap.get("operationalEnvironmentId");
if (envId != null && !UUIDChecker.isValidUUID(envId)) {
throw new ValidationException("operationalEnvironmentId", true);
}
cor.setOperationalEnvironmentId(envId);
}
this.operationalEnvironmentId = envId;
RequestDetails requestDetails = request.getRequestDetails();
RequestParameters requestParameters = requestDetails.getRequestParameters();
requestInfoValidation(action, requestInfo);
requestParamsValidation(action, requestParameters);
relatedInstanceValidation(action, requestDetails, requestParameters);
}
use of org.onap.so.exceptions.ValidationException in project so by onap.
the class CloudConfigurationValidation method validate.
@Override
public ValidationInformation validate(ValidationInformation info) throws ValidationException {
CloudConfiguration cloudConfiguration = info.getSir().getRequestDetails().getCloudConfiguration();
String requestScope = info.getRequestScope();
int reqVersion = info.getReqVersion();
Actions action = info.getAction();
Boolean aLaCarteFlag = info.getALaCarteFlag();
if (!requestScope.equals(ModelType.instanceGroup.toString())) {
if (cloudConfiguration == null && reqVersion >= 5 && (aLaCarteFlag != null && aLaCarteFlag)) {
if ((!requestScope.equalsIgnoreCase(ModelType.service.name()) && !requestScope.equalsIgnoreCase(ModelType.configuration.name())) && (action == Action.createInstance || action == Action.deleteInstance || action == Action.updateInstance)) {
throw new ValidationException("cloudConfiguration");
}
if (requestScope.equalsIgnoreCase(ModelType.configuration.name()) && (action == Action.enablePort || action == Action.disablePort || action == Action.activateInstance || action == Action.deactivateInstance)) {
throw new ValidationException("cloudConfiguration");
}
if (requestScope.equalsIgnoreCase(ModelType.vfModule.name()) && (action == Action.deactivateAndCloudDelete || action == Action.scaleOut)) {
throw new ValidationException("cloudConfiguration");
}
if (requestScope.equals(ModelType.vnf.name()) && action == Action.recreateInstance) {
throw new ValidationException("cloudConfiguration", true);
}
}
}
if (cloudConfiguration == null && ((aLaCarteFlag != null && !aLaCarteFlag) && requestScope.equalsIgnoreCase(ModelType.service.name()) && reqVersion < 5)) {
throw new ValidationException("cloudConfiguration");
}
if (cloudConfiguration != null) {
if (empty(cloudConfiguration.getLcpCloudRegionId())) {
throw new ValidationException("lcpCloudRegionId");
}
if (empty(cloudConfiguration.getTenantId()) && !(requestScope.equalsIgnoreCase(ModelType.configuration.name()))) {
throw new ValidationException("tenantId");
}
}
return info;
}
use of org.onap.so.exceptions.ValidationException in project so by onap.
the class TenantIsolationRequestTest method testParseCloudResourceECOMP.
@Test
public void testParseCloudResourceECOMP() throws Exception {
try {
String requestJSON = new String(Files.readAllBytes(Paths.get("src/test/resources/TenantIsolation/ECOMPOperationEnvironmentCreate.json")));
ObjectMapper mapper = new ObjectMapper();
HashMap<String, String> instanceIdMap = new HashMap<String, String>();
CloudOrchestrationRequest cor = mapper.readValue(requestJSON, CloudOrchestrationRequest.class);
TenantIsolationRequest request = new TenantIsolationRequest("1234");
request.parse(cor, instanceIdMap, Action.create);
assertNotNull(request.getRequestId());
} catch (ValidationException e) {
fail(e.getMessage());
}
}
Aggregations