diff options
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImpl.java')
-rw-r--r-- | bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImpl.java | 43 |
1 files changed, 37 insertions, 6 deletions
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 bb789607e4..709c5c5758 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 @@ -20,9 +20,14 @@ 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; @@ -34,7 +39,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 { @@ -82,27 +86,54 @@ public class CnfmHttpServiceProviderImpl implements CnfmHttpServiceProvider { } @Override - public void invokeInstantiateAsRequest(InstantiateAsRequest instantiateAsRequest, String asInstanceId) { + public Optional<URI> invokeInstantiateAsRequest(InstantiateAsRequest instantiateAsRequest, String asInstanceId) { try { final String url = cnfmUrlProvider.getInstantiateAsRequestUrl(asInstanceId); final ResponseEntity<AsInstance> response = httpServiceProvider.postHttpRequest(instantiateAsRequest, url, AsInstance.class); - final HttpStatus httpStatus = response.getStatusCode(); if (httpStatus.is2xxSuccessful()) { - if (!response.hasBody()) { - LOGGER.error("Received response without body: {}", response); + 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<AsLcmOpOcc> getInstantiateOperationJobStatus(final String url) { + try { + final ResponseEntity<AsLcmOpOcc> 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; + } + } + } |