summaryrefslogtreecommitdiffstats
path: root/so-cnf-adapter-application/src
diff options
context:
space:
mode:
authorGrzegorz Wielgosinski <g.wielgosins@samsung.com>2021-08-20 12:27:50 +0200
committerGrzegorz Wielgosinski <g.wielgosins@samsung.com>2021-08-23 15:44:29 +0200
commit0112178680266620628c4dd92c8d611c6aa0b19e (patch)
tree74799ccfe754ea2735f62932838564feb66e5353 /so-cnf-adapter-application/src
parentaf65cfcdcb097d4060dceba9731f326d063556a8 (diff)
Expose delete instance AAI API
Issue-ID: SO-3690 Signed-off-by: Grzegorz Wielgosinski <g.wielgosins@samsung.com> Change-Id: If11540cf3419fb0f40af6951eb50b249d1c6faf4
Diffstat (limited to 'so-cnf-adapter-application/src')
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/instantiation/AaiRequest.java (renamed from so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/instantiation/AaiUpdateRequest.java)4
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/rest/CnfAdapterRest.java28
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiIdGeneratorService.java8
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiService.java43
4 files changed, 61 insertions, 22 deletions
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/instantiation/AaiUpdateRequest.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/instantiation/AaiRequest.java
index c1dc41f..0665d9a 100644
--- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/instantiation/AaiUpdateRequest.java
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/instantiation/AaiRequest.java
@@ -6,7 +6,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(value = "true")
-public class AaiUpdateRequest {
+public class AaiRequest {
@JsonProperty("instanceId")
private String instanceId;
@@ -61,7 +61,7 @@ public class AaiUpdateRequest {
@Override
public String toString() {
- return "AaiUpdateRequest{" +
+ return "AaiRequest{" +
"instanceId='" + instanceId + '\'' +
", cloudRegion='" + cloudRegion + '\'' +
", cloudOwner='" + cloudOwner + '\'' +
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/rest/CnfAdapterRest.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/rest/CnfAdapterRest.java
index 82025ef..488b384 100644
--- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/rest/CnfAdapterRest.java
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/rest/CnfAdapterRest.java
@@ -51,7 +51,7 @@ import org.onap.so.adapters.cnf.model.ResourceBundleEntity;
import org.onap.so.adapters.cnf.model.Tag;
import org.onap.so.adapters.cnf.model.aai.AaiCallbackResponse;
import org.onap.so.adapters.cnf.model.healthcheck.HealthCheckResponse;
-import org.onap.so.adapters.cnf.model.instantiation.AaiUpdateRequest;
+import org.onap.so.adapters.cnf.model.instantiation.AaiRequest;
import org.onap.so.adapters.cnf.model.statuscheck.StatusCheckResponse;
import org.onap.so.adapters.cnf.service.CnfAdapterService;
import org.onap.so.adapters.cnf.service.aai.AaiService;
@@ -127,16 +127,36 @@ public class CnfAdapterRest {
@ResponseBody
@RequestMapping(value = {"/api/cnf-adapter/v1/aai-update/"}, method = RequestMethod.POST,
produces = "application/json")
- public DeferredResult<ResponseEntity> aaiUpdate(@RequestBody AaiUpdateRequest aaiUpdateRequest) {
+ public DeferredResult<ResponseEntity> aaiUpdate(@RequestBody AaiRequest aaiRequest) {
logger.info("aai-update called.");
DeferredResult<ResponseEntity> response = new DeferredResult<>();
ForkJoinPool.commonPool().submit(() -> {
logger.info("Processing aai update");
-// aaiService.aaiUpdate(aaiUpdateRequest);
+// aaiService.aaiUpdate(aaiRequest);
AaiCallbackResponse mockCallbackResponse = new AaiCallbackResponse();
mockCallbackResponse.setCompletionStatus(AaiCallbackResponse.CompletionStatus.COMPLETED);
- callbackClient.sendPostCallback(aaiUpdateRequest.getCallbackUrl(), mockCallbackResponse);
+ callbackClient.sendPostCallback(aaiRequest.getCallbackUrl(), mockCallbackResponse);
+ return response;
+ });
+
+ response.setResult(ResponseEntity.accepted().build());
+ return response;
+ }
+
+ @ResponseBody
+ @RequestMapping(value = {"/api/cnf-adapter/v1/aai-delete/"}, method = RequestMethod.POST,
+ produces = "application/json")
+ public DeferredResult<ResponseEntity> aaiDelete(@RequestBody AaiRequest aaiRequest) {
+ logger.info("aai-delete called.");
+ DeferredResult<ResponseEntity> response = new DeferredResult<>();
+
+ ForkJoinPool.commonPool().submit(() -> {
+ logger.info("Processing aai delete");
+// aaiService.aaiDelete(aaiRequest);
+ AaiCallbackResponse mockCallbackResponse = new AaiCallbackResponse();
+ mockCallbackResponse.setCompletionStatus(AaiCallbackResponse.CompletionStatus.COMPLETED);
+ callbackClient.sendPostCallback(aaiRequest.getCallbackUrl(), mockCallbackResponse);
return response;
});
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiIdGeneratorService.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiIdGeneratorService.java
index 383a753..2e79b35 100644
--- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiIdGeneratorService.java
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiIdGeneratorService.java
@@ -1,7 +1,7 @@
package org.onap.so.adapters.cnf.service.aai;
import com.google.common.hash.Hashing;
-import org.onap.so.adapters.cnf.model.instantiation.AaiUpdateRequest;
+import org.onap.so.adapters.cnf.model.instantiation.AaiRequest;
import org.onap.so.adapters.cnf.model.statuscheck.K8sRbInstanceGvk;
import org.onap.so.adapters.cnf.model.statuscheck.K8sRbInstanceResourceStatus;
import org.springframework.stereotype.Service;
@@ -11,11 +11,11 @@ import java.nio.charset.StandardCharsets;
@Service
class AaiIdGeneratorService {
- String generateId(K8sRbInstanceResourceStatus resourceStatus, AaiUpdateRequest aaiUpdateRequest) {
+ String generateId(K8sRbInstanceResourceStatus resourceStatus, AaiRequest aaiRequest) {
K8sRbInstanceGvk gvk = resourceStatus.getGvk();
String originalString = resourceStatus.getName() + gvk.getKind() + gvk.getGroup() + gvk.getVersion() +
- aaiUpdateRequest.getInstanceId() + aaiUpdateRequest.getCloudOwner() +
- aaiUpdateRequest.getCloudRegion() + aaiUpdateRequest.getTenantId();
+ aaiRequest.getInstanceId() + aaiRequest.getCloudOwner() +
+ aaiRequest.getCloudRegion() + aaiRequest.getTenantId();
return Hashing.sha256()
.hashString(originalString, StandardCharsets.UTF_8)
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiService.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiService.java
index bf9e64b..effecce 100644
--- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiService.java
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiService.java
@@ -1,13 +1,12 @@
package org.onap.so.adapters.cnf.service.aai;
-import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import org.onap.aaiclient.client.aai.AAIResourcesClient;
import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri;
import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory;
import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder;
import org.onap.so.adapters.cnf.client.MulticloudClient;
-import org.onap.so.adapters.cnf.model.instantiation.AaiUpdateRequest;
+import org.onap.so.adapters.cnf.model.instantiation.AaiRequest;
import org.onap.so.adapters.cnf.model.statuscheck.K8sRbInstanceGvk;
import org.onap.so.adapters.cnf.model.statuscheck.K8sRbInstanceResourceStatus;
import org.onap.so.adapters.cnf.model.statuscheck.K8sRbInstanceStatus;
@@ -31,22 +30,42 @@ public class AaiService {
this.aaiIdGeneratorService = aaiIdGeneratorService;
}
- public void aaiUpdate(AaiUpdateRequest aaiUpdateRequest) throws BadResponseException {
- String instanceId = aaiUpdateRequest.getInstanceId();
+ public void aaiUpdate(AaiRequest aaiRequest) throws BadResponseException {
+ String instanceId = aaiRequest.getInstanceId();
K8sRbInstanceStatus instanceStatus = multicloudClient.getInstanceStatus(instanceId);
List<K8sRbInstanceResourceStatus> resourcesStatus = instanceStatus.getResourcesStatus();
List<ParseResult> parsedStatus = resourcesStatus.stream()
- .map(status -> parse(status, aaiUpdateRequest))
+ .map(status -> parse(status, aaiRequest))
.collect(Collectors.toList());
- parsedStatus.forEach(status -> sendPostRequestToAai(status, aaiUpdateRequest));
+ parsedStatus.forEach(status -> sendUpdateRequestToAai(status, aaiRequest));
}
- private void sendPostRequestToAai(ParseResult parseResult, AaiUpdateRequest aaiUpdateRequest) {
+ public void aaiDelete(AaiRequest aaiRequest) throws BadResponseException {
+ String instanceId = aaiRequest.getInstanceId();
+ K8sRbInstanceStatus instanceStatus = multicloudClient.getInstanceStatus(instanceId);
+
+ List<K8sRbInstanceResourceStatus> resourcesStatus = instanceStatus.getResourcesStatus();
+ List<ParseResult> parsedStatus = resourcesStatus.stream()
+ .map(status -> parse(status, aaiRequest))
+ .collect(Collectors.toList());
+
+ parsedStatus.forEach(status -> sendDeleteRequestToAai(aaiRequest));
+ }
+
+ private void sendDeleteRequestToAai(AaiRequest aaiRequest) {
+ AAIResourceUri aaiUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure()
+ .cloudRegion(aaiRequest.getCloudOwner(), aaiRequest.getCloudRegion())
+ .tenant(aaiRequest.getTenantId())
+ .build());
+ getAaiClient().delete(aaiUri);
+ }
+
+ private void sendUpdateRequestToAai(ParseResult parseResult, AaiRequest aaiRequest) {
AAIResourceUri aaiUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure()
- .cloudRegion(aaiUpdateRequest.getCloudOwner(), aaiUpdateRequest.getCloudRegion())
- .tenant(aaiUpdateRequest.getTenantId())
+ .cloudRegion(aaiRequest.getCloudOwner(), aaiRequest.getCloudRegion())
+ .tenant(aaiRequest.getTenantId())
.build());
String payload = gson.toJson(parseResult);
getAaiClient().create(aaiUri, payload);
@@ -59,11 +78,11 @@ public class AaiService {
return aaiClient;
}
- private ParseResult parse(K8sRbInstanceResourceStatus status, AaiUpdateRequest aaiUpdateRequest) {
+ private ParseResult parse(K8sRbInstanceResourceStatus status, AaiRequest aaiRequest) {
ParseResult result = new ParseResult();
K8sRbInstanceGvk gvk = status.getGvk();
K8sStatusMetadata metadata = status.getStatus().getK8sStatusMetadata();
- String id = aaiIdGeneratorService.generateId(status, aaiUpdateRequest);
+ String id = aaiIdGeneratorService.generateId(status, aaiRequest);
result.setId(id);
result.setName(status.getName());
result.setGroup(gvk.getGroup());
@@ -76,7 +95,7 @@ public class AaiService {
labels.add(value);
});
result.setLabels(labels);
- result.setK8sResourceSelfLink(String.format("http://so-cnf-adapter:8090/api/cnf-adapter/v1/instance/%s/query", aaiUpdateRequest.getInstanceId()));
+ result.setK8sResourceSelfLink(String.format("http://so-cnf-adapter:8090/api/cnf-adapter/v1/instance/%s/query", aaiRequest.getInstanceId()));
return result;
}