Search in sources :

Example 31 with ApiException

use of org.onap.so.apihandlerinfra.exceptions.ApiException in project so by onap.

the class ActivateVnfStatusOperationalEnvironmentTest method checkOrUpdateOverallStatusTest_Error.

@Test
public void checkOrUpdateOverallStatusTest_Error() throws JsonProcessingException {
    OperationalEnvServiceModelStatus serviceModelDb = new OperationalEnvServiceModelStatus();
    serviceModelDb.setRequestId(requestIdOrig);
    serviceModelDb.setServiceModelVersionId(serviceModelVersionId);
    serviceModelDb.setWorkloadContext(workloadContext);
    serviceModelDb.setRecoveryAction(recoveryActionRetry);
    serviceModelDb.setOperationalEnvId(operationalEnvironmentId);
    serviceModelDb.setRetryCount(retryCountZero);
    serviceModelDb.setServiceModelVersionDistrStatus(statusError);
    serviceModelDb.setVnfOperationalEnvId(vnfOperationalEnvironmentId);
    wireMockServer.stubFor(get(urlPathEqualTo("/operationalEnvServiceModelStatus/search/findOneByOperationalEnvIdAndServiceModelVersionIdAndRequestId")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBody(mapper.writeValueAsString(serviceModelDb)).withStatus(HttpStatus.SC_OK)));
    InfraActiveRequests iar = new InfraActiveRequests();
    iar.setRequestId(requestIdOrig);
    iar.setRequestStatus("PENDING");
    wireMockServer.stubFor(get(urlPathEqualTo("/infraActiveRequests/" + requestIdOrig)).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBody(mapper.writeValueAsString(iar)).withStatus(HttpStatus.SC_OK)));
    try {
        activateVnfStatus.checkOrUpdateOverallStatus(operationalEnvironmentId, requestIdOrig);
    } catch (ApiException e) {
        assertThat(e.getMessage(), startsWith("Overall Activation process is a Failure. "));
        assertEquals(e.getHttpResponseCode(), HttpStatus.SC_BAD_REQUEST);
        assertEquals(e.getMessageID(), ErrorNumbers.SVC_DETAILED_SERVICE_ERROR);
    }
}
Also used : OperationalEnvServiceModelStatus(org.onap.so.db.request.beans.OperationalEnvServiceModelStatus) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) BaseTest(org.onap.so.apihandlerinfra.BaseTest) Test(org.junit.Test)

Example 32 with ApiException

use of org.onap.so.apihandlerinfra.exceptions.ApiException in project so by onap.

the class CreateVnfOperationalEnvironment method execute.

public void execute(String requestId, CloudOrchestrationRequest request) throws ApiException {
    try {
        setRequest(request);
        ObjectMapper objectMapper = new ObjectMapper();
        AAIResultWrapper aaiResultWrapper = aaiHelper.getAaiOperationalEnvironment(getEcompManagingEnvironmentId());
        if (aaiResultWrapper.isEmpty()) {
            throw new NotFoundException(getEcompManagingEnvironmentId() + " not found in A&AI");
        }
        OperationalEnvironment aaiEnv = aaiResultWrapper.asBean(OperationalEnvironment.class).get();
        // Find ECOMP environments in GRM
        logger.debug(" Start of GRM findRunningServicesAsString");
        String searchKey = getSearchKey(aaiEnv);
        String tenantContext = getTenantContext().toUpperCase();
        String jsonResponse = getGrmClient().findRunningServicesAsString(searchKey, 1, tenantContext);
        ServiceEndPointList sel = objectMapper.readValue(jsonResponse, ServiceEndPointList.class);
        if (sel.getServiceEndPointList().size() == 0) {
            throw new TenantIsolationException("GRM did not find any matches for " + searchKey + " in " + tenantContext);
        }
        // Replicate end-point for VNF Operating environment in GRM
        List<ServiceEndPointRequest> serviceEndpointRequestList = buildEndPointRequestList(sel);
        int ctr = 0;
        int total = serviceEndpointRequestList.size();
        for (ServiceEndPointRequest requestList : serviceEndpointRequestList) {
            logger.debug("Creating endpoint " + ++ctr + " of " + total + ": " + requestList.getServiceEndPoint().getName());
            getGrmClient().addServiceEndPoint(requestList);
        }
        // Create VNF operating in A&AI
        aaiHelper.createOperationalEnvironment(aaiClientObjectBuilder.buildAAIOperationalEnvironment("INACTIVE", request));
        aaiHelper.createRelationship(request.getOperationalEnvironmentId(), getEcompManagingEnvironmentId());
        // Update request database
        requestDb.updateInfraSuccessCompletion("SUCCESSFULLY created VNF operational environment", requestId, request.getOperationalEnvironmentId());
    } catch (Exception e) {
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.DataError).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;
    }
}
Also used : ServiceEndPointList(org.onap.so.client.grm.beans.ServiceEndPointList) ServiceEndPointRequest(org.onap.so.client.grm.beans.ServiceEndPointRequest) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) AAIClientObjectBuilder(org.onap.so.apihandlerinfra.tenantisolation.helpers.AAIClientObjectBuilder) NotFoundException(javax.ws.rs.NotFoundException) ServiceEndPoint(org.onap.so.client.grm.beans.ServiceEndPoint) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) TenantIsolationException(org.onap.so.apihandlerinfra.tenantisolation.exceptions.TenantIsolationException) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) NotFoundException(javax.ws.rs.NotFoundException) OperationalEnvironment(org.onap.aai.domain.yang.OperationalEnvironment) ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TenantIsolationException(org.onap.so.apihandlerinfra.tenantisolation.exceptions.TenantIsolationException) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper)

Example 33 with ApiException

use of org.onap.so.apihandlerinfra.exceptions.ApiException 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 34 with ApiException

use of org.onap.so.apihandlerinfra.exceptions.ApiException 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)

Aggregations

ApiException (org.onap.so.apihandlerinfra.exceptions.ApiException)34 ValidateException (org.onap.so.apihandlerinfra.exceptions.ValidateException)28 IOException (java.io.IOException)23 ErrorLoggerInfo (org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo)18 InfraActiveRequests (org.onap.so.db.request.beans.InfraActiveRequests)18 BPMNFailureException (org.onap.so.apihandlerinfra.exceptions.BPMNFailureException)16 CamundaResponse (org.onap.so.apihandler.camundabeans.CamundaResponse)15 RequestClientParameter (org.onap.so.apihandler.common.RequestClientParameter)14 ResponseBuilder (org.onap.so.apihandler.common.ResponseBuilder)14 Response (javax.ws.rs.core.Response)13 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)12 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)12 RequestDbFailureException (org.onap.so.apihandlerinfra.exceptions.RequestDbFailureException)10 ValidationException (org.onap.so.exceptions.ValidationException)10 ServiceInstancesRequest (org.onap.so.serviceinstancebeans.ServiceInstancesRequest)8 JSONObject (org.json.JSONObject)7 GetE2EServiceInstanceResponse (org.onap.so.apihandlerinfra.e2eserviceinstancebeans.GetE2EServiceInstanceResponse)7 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)6 Operation (io.swagger.v3.oas.annotations.Operation)4 Transactional (javax.transaction.Transactional)4