X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=bpmn%2Fso-bpmn-tasks%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fso%2Fbpmn%2Finfrastructure%2Fadapter%2Fcnfm%2Ftasks%2FCnfmHttpServiceProviderImpl.java;h=1035f4314e5f76f5aa2afb80b528fee3da02ca1b;hb=fa660d2d8a9b2b6f3190bf5c3c26dcf4fa15c146;hp=3f78896b5d0391297a7e866f3bb271c944682a76;hpb=1a6b1ef83417efbbb8ec7cfe204c105e49e7e1f2;p=so.git diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImpl.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImpl.java index 3f78896b5d..1035f4314e 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImpl.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImpl.java @@ -17,13 +17,15 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ - package org.onap.so.bpmn.infrastructure.adapter.cnfm.tasks; import static org.onap.so.bpmn.infrastructure.adapter.cnfm.tasks.CnfmHttpServiceConfiguration.CNFM_HTTP_REST_SERVICE_PROVIDER_BEAN; +import java.net.URI; import java.util.Optional; import org.onap.so.cnfm.lcm.model.AsInstance; +import org.onap.so.cnfm.lcm.model.AsLcmOpOcc; import org.onap.so.cnfm.lcm.model.CreateAsRequest; +import org.onap.so.cnfm.lcm.model.InstantiateAsRequest; import org.onap.so.rest.exceptions.HttpResouceNotFoundException; import org.onap.so.rest.exceptions.InvalidRestRequestException; import org.onap.so.rest.exceptions.RestProcessingException; @@ -35,7 +37,6 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; -import org.onap.so.cnfm.lcm.model.InstantiateAsRequest; @Service public class CnfmHttpServiceProviderImpl implements CnfmHttpServiceProvider { @@ -83,24 +84,54 @@ public class CnfmHttpServiceProviderImpl implements CnfmHttpServiceProvider { } @Override - public void invokeInstantiateAsRequest(InstantiateAsRequest instantiateAsRequest, String asInstanceId) { + public Optional invokeInstantiateAsRequest(InstantiateAsRequest instantiateAsRequest, String asInstanceId) { try { final String url = cnfmUrlProvider.getInstantiateAsRequestUrl(asInstanceId); final ResponseEntity response = httpServiceProvider.postHttpRequest(instantiateAsRequest, url, AsInstance.class); - final HttpStatus httpStatus = response.getStatusCode(); - if (httpStatus.is2xxSuccessful() && !(response.hasBody())) { - LOGGER.error("Response received without body: {}", response); + if (httpStatus.is2xxSuccessful()) { + URI statusUri = response.getHeaders().getLocation(); + if (statusUri == null) { + LOGGER.error("Received response without status URL for instance ID: {}", asInstanceId); + return Optional.empty(); + } + return Optional.of(statusUri); } LOGGER.error("Unable to invoke HTTP POST using URL: {}, Response Code: {}", url, httpStatus.value()); + return Optional.empty(); } catch (final RestProcessingException | InvalidRestRequestException | HttpResouceNotFoundException httpInvocationException) { LOGGER.error("Unexpected error while processing instantiation request", httpInvocationException); + return Optional.empty(); } } + @Override + public Optional getInstantiateOperationJobStatus(final String url) { + try { + final ResponseEntity response = httpServiceProvider.getHttpResponse(url, AsLcmOpOcc.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.empty(); + } + + if (!response.hasBody()) { + LOGGER.error("CNFM status response recieved without body: {}", response); + return Optional.empty(); + } + return Optional.of(response.getBody()); + } catch (final RestProcessingException | InvalidRestRequestException + | HttpResouceNotFoundException httpInvocationException) { + LOGGER.error("Unexpected error while processing job request", httpInvocationException); + throw httpInvocationException; + } + } + }