aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImpl.java
diff options
context:
space:
mode:
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.java52
1 files changed, 51 insertions, 1 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 709c5c5758..ed0bc3937b 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
@@ -23,11 +23,11 @@ import static org.onap.so.bpmn.infrastructure.adapter.cnfm.tasks.CnfmHttpService
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.cnfm.lcm.model.TerminateAsRequest;
import org.onap.so.rest.exceptions.HttpResouceNotFoundException;
import org.onap.so.rest.exceptions.InvalidRestRequestException;
import org.onap.so.rest.exceptions.RestProcessingException;
@@ -136,4 +136,54 @@ public class CnfmHttpServiceProviderImpl implements CnfmHttpServiceProvider {
}
}
+ @Override
+ public Optional<Boolean> invokeDeleteAsRequest(String asInstanceId) {
+ try {
+
+ final String url = cnfmUrlProvider.getDeleteAsRequestUrl(asInstanceId);
+ LOGGER.debug("Will send request to CNFM by uisng the url: {}", url);
+
+ ResponseEntity<Void> response = httpServiceProvider.deleteHttpRequest(url, Void.class);
+ final HttpStatus httpStatus = response.getStatusCode();
+ if (!(httpStatus.is2xxSuccessful())) {
+ LOGGER.error("Unable to invoke HTTP DELETE using URL: {}, Response Code: {}", url, httpStatus.value());
+ return Optional.empty();
+ }
+ return Optional.of(Boolean.TRUE);
+ } catch (final RestProcessingException | InvalidRestRequestException
+ | HttpResouceNotFoundException httpInvocationException) {
+ LOGGER.error("Unexpected error while processing delete request", httpInvocationException);
+ return Optional.empty();
+ }
+ }
+
+ @Override
+ public Optional<URI> invokeTerminateAsRequest(String asInstanceId, TerminateAsRequest terminateAsRequest) {
+ try {
+
+ final String url = cnfmUrlProvider.getTerminateAsRequestUrl(asInstanceId);
+ LOGGER.debug("Will send request to CNFM to terminate by uisng the url: {}", url);
+
+ ResponseEntity<Void> response = httpServiceProvider.postHttpRequest(terminateAsRequest, url, Void.class);
+ final HttpStatus httpStatus = response.getStatusCode();
+ if (httpStatus.is2xxSuccessful()) {
+ URI statusUri = response.getHeaders().getLocation();
+ if (statusUri == null) {
+ LOGGER.error("Received response without status URL while terminating of instance with ID: {}",
+ asInstanceId);
+ return Optional.empty();
+ }
+ return Optional.of(statusUri);
+ }
+ LOGGER.error("Unable to invoke HTTP DELETE while terminating by using URL: {}, Response Code: {}", url,
+ httpStatus.value());
+ return Optional.empty();
+
+ } catch (final RestProcessingException | InvalidRestRequestException
+ | HttpResouceNotFoundException httpInvocationException) {
+ LOGGER.error("Unexpected error while processing terminate request", httpInvocationException);
+ return Optional.empty();
+ }
+ }
+
}