Code & Workflow Enhancements for CNF - Upgrade
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / client / adapter / cnf / CnfAdapterClient.java
index 6765999..82c0e49 100644 (file)
@@ -27,6 +27,8 @@ import javax.ws.rs.core.UriBuilder;
 import org.apache.http.HttpStatus;
 import org.onap.so.client.adapter.cnf.entities.InstanceRequest;
 import org.onap.so.client.adapter.cnf.entities.InstanceResponse;
+import org.onap.so.client.adapter.cnf.entities.UpgradeInstanceResponse;
+import org.onap.so.client.adapter.cnf.entities.UpgradeInstanceRequest;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -61,7 +63,7 @@ public class CnfAdapterClient {
         try {
             // String uri = env.getRequiredProperty("mso.cnf.adapter.endpoint"); //TODO: This needs to be added as well
             // for configuration
-            String uri = "http://cnf-adapter:8090"; // TODO: What is the correct uri?
+            String uri = "http://so-cnf-adapter:8090";
             String endpoint = UriBuilder.fromUri(uri).path(INSTANCE_CREATE_PATH).build().toString();
             HttpEntity<?> entity = getHttpEntity(request);
             ResponseEntity<InstanceResponse> result =
@@ -76,12 +78,31 @@ public class CnfAdapterClient {
         }
     }
 
+
+    @Retryable(value = {HttpServerErrorException.class}, maxAttempts = 3, backoff = @Backoff(delay = 3000))
+    public void deleteVfModule(String heatStackId) throws CnfAdapterClientException {
+        try {
+            // String uri = env.getRequiredProperty("mso.cnf.adapter.endpoint"); //TODO: This needs to be added as well
+            // for configuration
+            String uri = "http://so-cnf-adapter:8090";
+            String endpoint = UriBuilder.fromUri(uri).path(INSTANCE_CREATE_PATH + "/" + heatStackId).build().toString();
+            HttpEntity<?> entity = new HttpEntity<>(getHttpHeaders());
+            restTemplate.exchange(endpoint, HttpMethod.DELETE, entity, String.class);
+        } catch (HttpClientErrorException e) {
+            logger.error("Error Calling CNF Adapter, e");
+            if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) {
+                throw new EntityNotFoundException(e.getResponseBodyAsString());
+            }
+            throw e;
+        }
+    }
+
     @Retryable(value = {HttpServerErrorException.class}, maxAttempts = 3, backoff = @Backoff(delay = 3000))
     public InstanceResponse healthcheck() throws CnfAdapterClientException {
         try {
             // String uri = env.getRequiredProperty("mso.cnf.adapter.endpoint"); //TODO: This needs to be added as well
             // for configuration
-            String uri = "http://cnf-adapter:8090"; // TODO: What is the correct uri?
+            String uri = "http://so-cnf-adapter:8090";
             String endpoint = UriBuilder.fromUri(uri).path("/api/cnf-adapter/v1/healthcheck").build().toString();
             HttpEntity<?> entity = new HttpEntity<>(getHttpHeaders());
             ResponseEntity<InstanceResponse> result =
@@ -96,6 +117,26 @@ public class CnfAdapterClient {
         }
     }
 
+    @Retryable(value = {HttpServerErrorException.class}, maxAttempts = 3, backoff = @Backoff(delay = 3000))
+    public UpgradeInstanceResponse upgradeVfModule(UpgradeInstanceRequest request, String heatStackId)
+            throws CnfAdapterClientException {
+        try {
+            String uri = "http://so-cnf-adapter:8090";
+            String endpoint = UriBuilder.fromUri(uri).path(INSTANCE_CREATE_PATH + "/" + heatStackId + "/upgrade")
+                    .build().toString();
+            HttpEntity<?> entity = getHttpEntity(request);
+            ResponseEntity<UpgradeInstanceResponse> result =
+                    restTemplate.exchange(endpoint, HttpMethod.POST, entity, UpgradeInstanceResponse.class);
+            return result.getBody();
+        } catch (HttpClientErrorException e) {
+            logger.error("Error Calling CNF Adapter, e");
+            if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) {
+                throw new EntityNotFoundException(e.getResponseBodyAsString());
+            }
+            throw e;
+        }
+    }
+
     protected HttpHeaders getHttpHeaders() {
         HttpHeaders headers = new HttpHeaders();
         List<MediaType> acceptableMediaTypes = new ArrayList<>();
@@ -116,4 +157,8 @@ public class CnfAdapterClient {
         return new HttpEntity<>(request, headers);
     }
 
+    protected HttpEntity<?> getHttpEntity(UpgradeInstanceRequest request) {
+        HttpHeaders headers = getHttpHeaders();
+        return new HttpEntity<>(request, headers);
+    }
 }