Search in sources :

Example 31 with ValidationException

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();
}
Also used : ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) ValidationException(org.onap.so.exceptions.ValidationException) ResponseBuilder(org.onap.so.apihandler.common.ResponseBuilder) IOException(java.io.IOException) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) IOException(java.io.IOException) ValidationException(org.onap.so.exceptions.ValidationException) ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Operation(io.swagger.v3.oas.annotations.Operation) Transactional(javax.transaction.Transactional)

Example 32 with ValidationException

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);
    }
}
Also used : ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) ValidationException(org.onap.so.exceptions.ValidationException) ResponseBuilder(org.onap.so.apihandler.common.ResponseBuilder) Request(org.onap.so.apihandlerinfra.tenantisolationbeans.Request) ArrayList(java.util.ArrayList) CloudOrchestrationResponse(org.onap.so.apihandlerinfra.tenantisolationbeans.CloudOrchestrationResponse) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) IOException(java.io.IOException) ValidationException(org.onap.so.exceptions.ValidationException) ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) CloudOrchestrationRequestList(org.onap.so.apihandlerinfra.tenantisolationbeans.CloudOrchestrationRequestList) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation) Transactional(javax.transaction.Transactional)

Example 33 with ValidationException

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);
}
Also used : ValidationException(org.onap.so.exceptions.ValidationException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RequestDetails(org.onap.so.apihandlerinfra.tenantisolationbeans.RequestDetails) RequestParameters(org.onap.so.apihandlerinfra.tenantisolationbeans.RequestParameters)

Example 34 with ValidationException

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;
}
Also used : ValidationException(org.onap.so.exceptions.ValidationException) CloudConfiguration(org.onap.so.serviceinstancebeans.CloudConfiguration) Actions(org.onap.so.apihandlerinfra.Actions)

Example 35 with ValidationException

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());
    }
}
Also used : ValidationException(org.onap.so.exceptions.ValidationException) HashMap(java.util.HashMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BaseTest(org.onap.so.apihandlerinfra.BaseTest) Test(org.junit.Test)

Aggregations

ValidationException (org.onap.so.exceptions.ValidationException)35 Actions (org.onap.so.apihandlerinfra.Actions)10 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)9 ErrorLoggerInfo (org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo)9 IOException (java.io.IOException)8 ValidateException (org.onap.so.apihandlerinfra.exceptions.ValidateException)8 HashMap (java.util.HashMap)6 InfraActiveRequests (org.onap.so.db.request.beans.InfraActiveRequests)6 ServiceInstancesRequest (org.onap.so.serviceinstancebeans.ServiceInstancesRequest)6 Operation (io.swagger.v3.oas.annotations.Operation)5 Transactional (javax.transaction.Transactional)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 ResponseBuilder (org.onap.so.apihandler.common.ResponseBuilder)5 ModelInfo (org.onap.so.serviceinstancebeans.ModelInfo)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 Consumes (javax.ws.rs.Consumes)4 Test (org.junit.Test)4 BaseTest (org.onap.so.apihandlerinfra.BaseTest)4 RequestInfo (org.onap.so.serviceinstancebeans.RequestInfo)4