Search in sources :

Example 1 with RestProcessingException

use of org.onap.so.rest.exceptions.RestProcessingException in project so by onap.

the class VnfmAdapterServiceProviderImpl method invokeCreateInstantiationRequest.

@Override
public Optional<CreateVnfResponse> invokeCreateInstantiationRequest(final String vnfId, final CreateVnfRequest request) {
    try {
        final String url = urlProvider.getCreateInstantiateUrl(vnfId);
        final ResponseEntity<CreateVnfResponse> response = httpServiceProvider.postHttpRequest(request, url, CreateVnfResponse.class);
        final HttpStatus httpStatus = response.getStatusCode();
        if (!(httpStatus.equals(HttpStatus.ACCEPTED)) && !(httpStatus.equals(HttpStatus.OK))) {
            LOGGER.error("Unable to invoke HTTP POST using URL: {}, Response Code: {}", url, httpStatus.value());
            return Optional.absent();
        }
        if (!response.hasBody()) {
            LOGGER.error(RECEIVED_RESPONSE_WITHOUT_BODY, response);
            return Optional.absent();
        }
        final CreateVnfResponse createVnfResponse = response.getBody();
        if (createVnfResponse.getJobId() == null || createVnfResponse.getJobId().isEmpty()) {
            LOGGER.error("Received invalid instantiation response: {}", response);
            return Optional.absent();
        }
        return Optional.of(createVnfResponse);
    } catch (final RestProcessingException | InvalidRestRequestException | HttpResouceNotFoundException httpInvocationException) {
        LOGGER.error("Unexpected error while processing create and instantiation request", httpInvocationException);
        return Optional.absent();
    }
}
Also used : CreateVnfResponse(org.onap.so.adapters.etsisol003adapter.lcm.v1.model.CreateVnfResponse) HttpStatus(org.springframework.http.HttpStatus) InvalidRestRequestException(org.onap.so.rest.exceptions.InvalidRestRequestException) HttpResouceNotFoundException(org.onap.so.rest.exceptions.HttpResouceNotFoundException) RestProcessingException(org.onap.so.rest.exceptions.RestProcessingException)

Example 2 with RestProcessingException

use of org.onap.so.rest.exceptions.RestProcessingException in project so by onap.

the class VnfmAdapterServiceProviderImpl method invokeDeleteRequest.

@Override
public Optional<DeleteVnfResponse> invokeDeleteRequest(final String vnfId) {
    try {
        final String url = urlProvider.getDeleteUrl(vnfId);
        LOGGER.debug("Will send request to vnfm adapter using url: {}", url);
        final ResponseEntity<DeleteVnfResponse> response = httpServiceProvider.deleteHttpRequest(url, DeleteVnfResponse.class);
        LOGGER.debug("Response received: ", response);
        final HttpStatus httpStatus = response.getStatusCode();
        if (!(httpStatus.equals(HttpStatus.ACCEPTED)) && !(httpStatus.equals(HttpStatus.OK))) {
            LOGGER.error("Unable to invoke HTTP DELETE using URL: {}, Response Code: {}", url, httpStatus.value());
            return Optional.absent();
        }
        if (!response.hasBody()) {
            LOGGER.error(RECEIVED_RESPONSE_WITHOUT_BODY, response);
            return Optional.absent();
        }
        final DeleteVnfResponse deleteVnfResponse = response.getBody();
        if (deleteVnfResponse.getJobId() == null || deleteVnfResponse.getJobId().isEmpty()) {
            LOGGER.error("Received invalid delete response: {}", response);
            return Optional.absent();
        }
        return Optional.of(deleteVnfResponse);
    } catch (final RestProcessingException | InvalidRestRequestException httpInvocationException) {
        LOGGER.error("Unexpected error while processing delete request", httpInvocationException);
        return Optional.absent();
    }
}
Also used : HttpStatus(org.springframework.http.HttpStatus) InvalidRestRequestException(org.onap.so.rest.exceptions.InvalidRestRequestException) RestProcessingException(org.onap.so.rest.exceptions.RestProcessingException) DeleteVnfResponse(org.onap.so.adapters.etsisol003adapter.lcm.v1.model.DeleteVnfResponse)

Example 3 with RestProcessingException

use of org.onap.so.rest.exceptions.RestProcessingException in project so by onap.

the class VnfmAdapterServiceProviderImpl method getInstantiateOperationJobStatus.

@Override
public Optional<QueryJobResponse> getInstantiateOperationJobStatus(final String jobId) {
    try {
        final String url = urlProvider.getJobStatusUrl(jobId);
        final ResponseEntity<QueryJobResponse> response = httpServiceProvider.getHttpResponse(url, QueryJobResponse.class);
        final HttpStatus httpStatus = response.getStatusCode();
        if (!(httpStatus.equals(HttpStatus.ACCEPTED)) && !(httpStatus.equals(HttpStatus.OK))) {
            LOGGER.error("Unable to invoke HTTP GET using URL: {}, Response Code: ", url, httpStatus.value());
            return Optional.absent();
        }
        if (!response.hasBody()) {
            LOGGER.error(RECEIVED_RESPONSE_WITHOUT_BODY, response);
            return Optional.absent();
        }
        return Optional.of(response.getBody());
    } catch (final RestProcessingException | InvalidRestRequestException | HttpResouceNotFoundException httpInvocationException) {
        LOGGER.error("Unexpected error while processing job request", httpInvocationException);
        throw httpInvocationException;
    }
}
Also used : QueryJobResponse(org.onap.so.adapters.etsisol003adapter.lcm.v1.model.QueryJobResponse) HttpStatus(org.springframework.http.HttpStatus) InvalidRestRequestException(org.onap.so.rest.exceptions.InvalidRestRequestException) HttpResouceNotFoundException(org.onap.so.rest.exceptions.HttpResouceNotFoundException) RestProcessingException(org.onap.so.rest.exceptions.RestProcessingException)

Aggregations

InvalidRestRequestException (org.onap.so.rest.exceptions.InvalidRestRequestException)3 RestProcessingException (org.onap.so.rest.exceptions.RestProcessingException)3 HttpStatus (org.springframework.http.HttpStatus)3 HttpResouceNotFoundException (org.onap.so.rest.exceptions.HttpResouceNotFoundException)2 CreateVnfResponse (org.onap.so.adapters.etsisol003adapter.lcm.v1.model.CreateVnfResponse)1 DeleteVnfResponse (org.onap.so.adapters.etsisol003adapter.lcm.v1.model.DeleteVnfResponse)1 QueryJobResponse (org.onap.so.adapters.etsisol003adapter.lcm.v1.model.QueryJobResponse)1