summaryrefslogtreecommitdiffstats
path: root/so-cnf-adapter-application/src/main/java/org/onap
diff options
context:
space:
mode:
authorGrzegorz Wielgosinski <g.wielgosins@samsung.com>2021-08-13 13:07:34 +0200
committerGrzegorz Wielgosinski <g.wielgosins@samsung.com>2021-08-23 15:41:40 +0200
commitaf65cfcdcb097d4060dceba9731f326d063556a8 (patch)
tree7acda9f9ed9b8cf677e775ba5c898c8e46b5fabc /so-cnf-adapter-application/src/main/java/org/onap
parentf38fe1e195c4fc56646050a206724ea3c5c5aff6 (diff)
Expose create instance AAI API
Issue-ID: SO-3690 Signed-off-by: Grzegorz Wielgosinski <g.wielgosins@samsung.com> Change-Id: Ifcae8e8ac36a6d837e951d39116835f3eb9111e0
Diffstat (limited to 'so-cnf-adapter-application/src/main/java/org/onap')
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/aai/AaiCallbackResponse.java44
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/instantiation/AaiUpdateRequest.java72
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/K8sRbInstanceResourceStatus.java6
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/K8sStatus.java26
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/K8sStatusMetadata.java40
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/rest/CnfAdapterRest.java136
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiIdGeneratorService.java25
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiService.java157
8 files changed, 448 insertions, 58 deletions
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/aai/AaiCallbackResponse.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/aai/AaiCallbackResponse.java
new file mode 100644
index 0000000..65e79ac
--- /dev/null
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/aai/AaiCallbackResponse.java
@@ -0,0 +1,44 @@
+package org.onap.so.adapters.cnf.model.aai;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonIgnoreProperties(value = "true")
+public class AaiCallbackResponse {
+
+ @JsonProperty("status")
+ private CompletionStatus completionStatus;
+
+ @JsonProperty("statusMessage")
+ private String message;
+
+ public CompletionStatus getCompletionStatus() {
+ return completionStatus;
+ }
+
+ public void setCompletionStatus(CompletionStatus completionStatus) {
+ this.completionStatus = completionStatus;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ @Override
+ public String toString() {
+ return "AaiCallbackResponse{" +
+ "completionStatus=" + completionStatus +
+ ", message='" + message + '\'' +
+ '}';
+ }
+
+ public enum CompletionStatus {
+ COMPLETED, FAILED
+ }
+}
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/AaiUpdateRequest.java
new file mode 100644
index 0000000..c1dc41f
--- /dev/null
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/instantiation/AaiUpdateRequest.java
@@ -0,0 +1,72 @@
+package org.onap.so.adapters.cnf.model.instantiation;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonIgnoreProperties(value = "true")
+public class AaiUpdateRequest {
+
+ @JsonProperty("instanceId")
+ private String instanceId;
+ @JsonProperty("cloudRegion")
+ private String cloudRegion;
+ @JsonProperty("cloudOwner")
+ private String cloudOwner;
+ @JsonProperty("tenantId")
+ private String tenantId;
+ @JsonProperty("callbackUrl")
+ private String callbackUrl;
+
+ public String getInstanceId() {
+ return instanceId;
+ }
+
+ public void setInstanceId(String instanceId) {
+ this.instanceId = instanceId;
+ }
+
+ public String getCloudRegion() {
+ return cloudRegion;
+ }
+
+ public void setCloudRegion(String cloudRegion) {
+ this.cloudRegion = cloudRegion;
+ }
+
+ public String getCloudOwner() {
+ return cloudOwner;
+ }
+
+ public void setCloudOwner(String cloudOwner) {
+ this.cloudOwner = cloudOwner;
+ }
+
+ public String getTenantId() {
+ return tenantId;
+ }
+
+ public void setTenantId(String tenantId) {
+ this.tenantId = tenantId;
+ }
+
+ public String getCallbackUrl() {
+ return callbackUrl;
+ }
+
+ public void setCallbackUrl(String callbackUrl) {
+ this.callbackUrl = callbackUrl;
+ }
+
+ @Override
+ public String toString() {
+ return "AaiUpdateRequest{" +
+ "instanceId='" + instanceId + '\'' +
+ ", cloudRegion='" + cloudRegion + '\'' +
+ ", cloudOwner='" + cloudOwner + '\'' +
+ ", tenantId='" + tenantId + '\'' +
+ ", callbackUrl='" + callbackUrl + '\'' +
+ '}';
+ }
+}
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/K8sRbInstanceResourceStatus.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/K8sRbInstanceResourceStatus.java
index 27a3c39..fe11b03 100644
--- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/K8sRbInstanceResourceStatus.java
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/K8sRbInstanceResourceStatus.java
@@ -18,7 +18,7 @@ public class K8sRbInstanceResourceStatus {
private K8sRbInstanceGvk gvk;
@JsonProperty("status")
- private Map<String, Object> status;
+ private K8sStatus status;
public String getName() {
return name;
@@ -36,11 +36,11 @@ public class K8sRbInstanceResourceStatus {
this.gvk = gvk;
}
- public Map<String, Object> getStatus() {
+ public K8sStatus getStatus() {
return status;
}
- public void setStatus(Map<String, Object> status) {
+ public void setStatus(K8sStatus status) {
this.status = status;
}
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/K8sStatus.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/K8sStatus.java
new file mode 100644
index 0000000..5fe4e30
--- /dev/null
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/K8sStatus.java
@@ -0,0 +1,26 @@
+package org.onap.so.adapters.cnf.model.statuscheck;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+@JsonIgnoreProperties
+public class K8sStatus {
+
+ @JsonProperty("metadata")
+ private K8sStatusMetadata k8sStatusMetadata;
+
+ public K8sStatusMetadata getK8sStatusMetadata() {
+ return k8sStatusMetadata;
+ }
+
+ public void setK8sStatusMetadata(K8sStatusMetadata k8sStatusMetadata) {
+ this.k8sStatusMetadata = k8sStatusMetadata;
+ }
+
+ @Override
+ public String toString() {
+ return "K8sStatus{" +
+ "k8sStatusMetadata=" + k8sStatusMetadata +
+ '}';
+ }
+}
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/K8sStatusMetadata.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/K8sStatusMetadata.java
new file mode 100644
index 0000000..a69f7e7
--- /dev/null
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/K8sStatusMetadata.java
@@ -0,0 +1,40 @@
+package org.onap.so.adapters.cnf.model.statuscheck;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.Map;
+
+@JsonIgnoreProperties
+public class K8sStatusMetadata {
+
+ @JsonProperty("metadata")
+ private String namespace;
+
+ @JsonProperty("metadata")
+ private Map<String, String> labels;
+
+ public String getNamespace() {
+ return namespace;
+ }
+
+ public void setNamespace(String namespace) {
+ this.namespace = namespace;
+ }
+
+ public Map<String, String> getLabels() {
+ return labels;
+ }
+
+ public void setLabels(Map<String, String> labels) {
+ this.labels = labels;
+ }
+
+ @Override
+ public String toString() {
+ return "K8sStatusMetadata{" +
+ "namespace='" + namespace + '\'' +
+ ", labels=" + labels +
+ '}';
+ }
+}
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 5a729dd..82025ef 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
@@ -49,9 +49,12 @@ import org.onap.so.adapters.cnf.model.ConnectivityInfo;
import org.onap.so.adapters.cnf.model.ProfileEntity;
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.statuscheck.StatusCheckResponse;
import org.onap.so.adapters.cnf.service.CnfAdapterService;
+import org.onap.so.adapters.cnf.service.aai.AaiService;
import org.onap.so.adapters.cnf.service.statuscheck.SimpleStatusCheckService;
import org.onap.so.client.exception.BadResponseException;
import org.slf4j.Logger;
@@ -80,15 +83,18 @@ public class CnfAdapterRest {
private final SimpleStatusCheckService simpleStatusCheckService;
private final CnfAdapterService cnfAdapterService;
private final SoCallbackClient callbackClient;
+ private final AaiService aaiService;
private final String uri;
@Autowired
public CnfAdapterRest(SimpleStatusCheckService simpleStatusCheckService,
CnfAdapterService cnfAdapterService,
SoCallbackClient callbackClient,
+ AaiService aaiService,
MulticloudConfiguration multicloudConfiguration) {
this.simpleStatusCheckService = simpleStatusCheckService;
this.cnfAdapterService = cnfAdapterService;
+ this.aaiService = aaiService;
this.callbackClient = callbackClient;
this.uri = multicloudConfiguration.getMulticloudUrl();
}
@@ -119,6 +125,26 @@ 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) {
+ logger.info("aai-update called.");
+ DeferredResult<ResponseEntity> response = new DeferredResult<>();
+
+ ForkJoinPool.commonPool().submit(() -> {
+ logger.info("Processing aai update");
+// aaiService.aaiUpdate(aaiUpdateRequest);
+ AaiCallbackResponse mockCallbackResponse = new AaiCallbackResponse();
+ mockCallbackResponse.setCompletionStatus(AaiCallbackResponse.CompletionStatus.COMPLETED);
+ callbackClient.sendPostCallback(aaiUpdateRequest.getCallbackUrl(), mockCallbackResponse);
+ return response;
+ });
+
+ response.setResult(ResponseEntity.accepted().build());
+ return response;
+ }
+
+ @ResponseBody
@RequestMapping(value = {"/api/cnf-adapter/v1/statuscheck"}, method = RequestMethod.POST,
produces = "application/json")
public DeferredResult<ResponseEntity> statusCheck(@RequestBody CheckInstanceRequest statusCheckRequest) {
@@ -218,7 +244,7 @@ public class CnfAdapterRest {
// TODO
// Below URL should be changed as appropriate multicloud URL.
- HttpPost post = new HttpPost(uri +"/v1/rb/definition");
+ HttpPost post = new HttpPost(uri + "/v1/rb/definition");
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
String requestBody = objectMapper.writeValueAsString(rB);
@@ -226,7 +252,7 @@ public class CnfAdapterRest {
post.setEntity(requestEntity);
try (CloseableHttpClient httpClient = HttpClients.createDefault();
- CloseableHttpResponse response = httpClient.execute(post)) {
+ CloseableHttpResponse response = httpClient.execute(post)) {
logger.info("response:" + response.getEntity());
return EntityUtils.toString(response.getEntity());
}
@@ -242,7 +268,7 @@ public class CnfAdapterRest {
// TODO
// Below URL should be changed as appropriate multicloud URL.
- HttpGet req = new HttpGet(uri +"/v1/rb/definition/" + rbName + "/" + rbVersion);
+ HttpGet req = new HttpGet(uri + "/v1/rb/definition/" + rbName + "/" + rbVersion);
try (CloseableHttpResponse response = httpClient.execute(req)) {
logger.info("response:" + response.getEntity());
return EntityUtils.toString(response.getEntity());
@@ -259,7 +285,7 @@ public class CnfAdapterRest {
// TODO
// Below URL should be changed as appropriate multicloud URL.
- HttpDelete req = new HttpDelete(uri +"/v1/rb/definition/" + rbName + "/" + rbVersion);
+ HttpDelete req = new HttpDelete(uri + "/v1/rb/definition/" + rbName + "/" + rbVersion);
try (CloseableHttpResponse response = httpClient.execute(req)) {
logger.info("response:" + response.getEntity());
@@ -277,7 +303,7 @@ public class CnfAdapterRest {
// TODO
// Below URL should be changed as appropriate multicloud URL.
- HttpGet req = new HttpGet(uri +"/v1/rb/definition/" + rbName);
+ HttpGet req = new HttpGet(uri + "/v1/rb/definition/" + rbName);
try (CloseableHttpResponse response = httpClient.execute(req)) {
logger.info("response:" + response.getEntity());
@@ -295,7 +321,7 @@ public class CnfAdapterRest {
// TODO
// Below URL should be changed as appropriate multicloud URL.
- HttpGet req = new HttpGet(uri +"/v1/rb/definition");
+ HttpGet req = new HttpGet(uri + "/v1/rb/definition");
try (CloseableHttpResponse response = httpClient.execute(req)) {
logger.info("response:" + response.getEntity());
@@ -308,7 +334,7 @@ public class CnfAdapterRest {
@RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}/{rb-version}/content"},
method = RequestMethod.POST, produces = "multipart/form-data")
public String uploadArtifactForRB(@RequestParam("file") MultipartFile file, @PathVariable("rb-name") String rbName,
- @PathVariable("rb-version") String rbVersion) throws Exception {
+ @PathVariable("rb-version") String rbVersion) throws Exception {
logger.info("Upload Artifact For RB called.");
@@ -323,13 +349,13 @@ public class CnfAdapterRest {
// TODO
// Below URL should be changed as appropriate multicloud URL.
HttpPost post =
- new HttpPost(uri +"/v1/rb/definition/" + rbName + "/" + rbVersion + "/content");
+ new HttpPost(uri + "/v1/rb/definition/" + rbName + "/" + rbVersion + "/content");
post.setHeader("Content-Type", "multipart/form-data");
logger.info(String.valueOf(post));
post.setEntity(entity);
try (CloseableHttpClient httpClient = HttpClients.createDefault();
- CloseableHttpResponse response = httpClient.execute(post)) {
+ CloseableHttpResponse response = httpClient.execute(post)) {
logger.info("response:" + response.getEntity());
return EntityUtils.toString(response.getEntity());
}
@@ -339,21 +365,21 @@ public class CnfAdapterRest {
@RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}/{rb-version}/profile"},
method = RequestMethod.POST, produces = "application/json")
public String createProfile(@RequestBody ProfileEntity fE, @PathVariable("rb-name") String rbName,
- @PathVariable("rb-version") String rbVersion) throws Exception {
+ @PathVariable("rb-version") String rbVersion) throws Exception {
logger.info("create Profile called.");
// TODO
// Below URL should be changed as appropriate multicloud URL.
HttpPost post =
- new HttpPost(uri +"/v1/rb/definition/" + rbName + "/" + rbVersion + "/profile");
+ new HttpPost(uri + "/v1/rb/definition/" + rbName + "/" + rbVersion + "/profile");
ObjectMapper objectMapper = new ObjectMapper();
String requestBody = objectMapper.writeValueAsString(fE);
StringEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
post.setEntity(requestEntity);
try (CloseableHttpClient httpClient = HttpClients.createDefault();
- CloseableHttpResponse response = httpClient.execute(post)) {
+ CloseableHttpResponse response = httpClient.execute(post)) {
logger.info("response:" + response.getEntity());
return EntityUtils.toString(response.getEntity());
}
@@ -363,14 +389,14 @@ public class CnfAdapterRest {
@RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}/{rb-version}/profile/{pr-name}"},
method = RequestMethod.GET, produces = "application/json")
public String getProfile(@PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion,
- @PathVariable("pr-name") String prName) throws Exception {
+ @PathVariable("pr-name") String prName) throws Exception {
logger.info("get Profile called.");
// TODO
// Below URL should be changed as appropriate multicloud URL.
HttpGet req = new HttpGet(
- uri +"/v1/rb/definition/" + rbName + "/" + rbVersion + "/profile/" + prName);
+ uri + "/v1/rb/definition/" + rbName + "/" + rbVersion + "/profile/" + prName);
try (CloseableHttpResponse response = httpClient.execute(req)) {
logger.info("response:" + response.getEntity());
@@ -389,7 +415,7 @@ public class CnfAdapterRest {
// TODO
// Below URL should be changed as appropriate multicloud URL.
HttpGet req =
- new HttpGet(uri +"/v1/rb/definition/" + rbName + "/" + rbVersion + "/profile");
+ new HttpGet(uri + "/v1/rb/definition/" + rbName + "/" + rbVersion + "/profile");
try (CloseableHttpResponse response = httpClient.execute(req)) {
logger.info("response:" + response.getEntity());
@@ -401,14 +427,14 @@ public class CnfAdapterRest {
@RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}/{rb-version}/profile/{pr-name}"},
method = RequestMethod.DELETE, produces = "application/json")
public String deleteProfile(@PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion,
- @PathVariable("pr-name") String prName) throws Exception {
+ @PathVariable("pr-name") String prName) throws Exception {
logger.info("delete Profile called.");
// TODO
// Below URL should be changed as appropriate multicloud URL.
HttpDelete req = new HttpDelete(
- uri +"/v1/rb/definition/" + rbName + "/" + rbVersion + "/profile/" + prName);
+ uri + "/v1/rb/definition/" + rbName + "/" + rbVersion + "/profile/" + prName);
try (CloseableHttpResponse response = httpClient.execute(req)) {
logger.info("response:" + response.getEntity());
@@ -421,8 +447,8 @@ public class CnfAdapterRest {
@RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}/{rb-version}/profile/{pr-name}/content"},
method = RequestMethod.POST, produces = "multipart/form-data")
public String uploadArtifactForProfile(@RequestParam("file") MultipartFile file,
- @PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion,
- @PathVariable("pr-name") String prName) throws Exception {
+ @PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion,
+ @PathVariable("pr-name") String prName) throws Exception {
logger.info("Upload Artifact For Profile called.");
@@ -436,7 +462,7 @@ public class CnfAdapterRest {
// TODO
// Below URL should be changed as appropriate multicloud URL.
- HttpPost post = new HttpPost(uri +"/v1/rb/definition/" + rbName + "/" + rbVersion
+ HttpPost post = new HttpPost(uri + "/v1/rb/definition/" + rbName + "/" + rbVersion
+ "/profile/" + prName + "/content");
post.setHeader("Content-Type", "multipart/form-data");
@@ -444,7 +470,7 @@ public class CnfAdapterRest {
post.setEntity(entity);
try (CloseableHttpClient httpClient = HttpClients.createDefault();
- CloseableHttpResponse response = httpClient.execute(post)) {
+ CloseableHttpResponse response = httpClient.execute(post)) {
logger.info("response:" + response.getEntity());
return EntityUtils.toString(response.getEntity());
}
@@ -454,14 +480,14 @@ public class CnfAdapterRest {
@RequestMapping(value = {"/api/cnf-adapter/v1/definition/{rb-name}/{rb-version}/profile/{profile-name}/config"},
method = RequestMethod.POST, produces = "application/json")
public String createConfiguration(@RequestBody ConfigurationEntity cE, @PathVariable("rb-name") String rbName,
- @PathVariable("rb-version") String rbVersion, @PathVariable("profile-name") String prName)
+ @PathVariable("rb-version") String rbVersion, @PathVariable("profile-name") String prName)
throws Exception {
logger.info("create Configuration called.");
// TODO
// Below URL should be changed as appropriate multicloud URL.
- HttpPost post = new HttpPost(uri +"/v1/definition/" + rbName + "/" + rbVersion
+ HttpPost post = new HttpPost(uri + "/v1/definition/" + rbName + "/" + rbVersion
+ "/profile/" + prName + "/config");
ObjectMapper objectMapper = new ObjectMapper();
String requestBody = objectMapper.writeValueAsString(cE);
@@ -469,7 +495,7 @@ public class CnfAdapterRest {
post.setEntity(requestEntity);
try (CloseableHttpClient httpClient = HttpClients.createDefault();
- CloseableHttpResponse response = httpClient.execute(post)) {
+ CloseableHttpResponse response = httpClient.execute(post)) {
logger.info("response:" + response.getEntity());
return EntityUtils.toString(response.getEntity());
}
@@ -480,13 +506,13 @@ public class CnfAdapterRest {
value = {"/api/cnf-adapter/v1/definition/{rb-name}/{rb-version}/profile/{profile-name}/config/{cfg-name}"},
method = RequestMethod.GET, produces = "application/json")
public String getConfiguration(@PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion,
- @PathVariable("profile-name") String prName, @PathVariable("cfg-name") String cfgName) throws Exception {
+ @PathVariable("profile-name") String prName, @PathVariable("cfg-name") String cfgName) throws Exception {
logger.info("get Configuration called.");
// TODO
// Below URL should be changed as appropriate multicloud URL.
- HttpGet req = new HttpGet(uri +"/v1/definition/" + rbName + "/" + rbVersion + "/profile/"
+ HttpGet req = new HttpGet(uri + "/v1/definition/" + rbName + "/" + rbVersion + "/profile/"
+ prName + "/config/" + cfgName);
try (CloseableHttpResponse response = httpClient.execute(req)) {
@@ -500,14 +526,14 @@ public class CnfAdapterRest {
value = {"/api/cnf-adapter/v1/definition/{rb-name}/{rb-version}/profile/{profile-name}/config/{cfg-name}"},
method = RequestMethod.DELETE, produces = "application/json")
public String deleteConfiguration(@PathVariable("rb-name") String rbName,
- @PathVariable("rb-version") String rbVersion, @PathVariable("profile-name") String prName,
- @PathVariable("cfg-name") String cfgName) throws Exception {
+ @PathVariable("rb-version") String rbVersion, @PathVariable("profile-name") String prName,
+ @PathVariable("cfg-name") String cfgName) throws Exception {
logger.info("delete Configuration called.");
// TODO
// Below URL should be changed as appropriate multicloud URL.
- HttpDelete req = new HttpDelete(uri +"/v1/definition/" + rbName + "/" + rbVersion
+ HttpDelete req = new HttpDelete(uri + "/v1/definition/" + rbName + "/" + rbVersion
+ "/profile/" + prName + "/config/" + cfgName);
try (CloseableHttpResponse response = httpClient.execute(req)) {
@@ -522,14 +548,14 @@ public class CnfAdapterRest {
value = {"/api/cnf-adapter/v1/definition/{rb-name}/{rb-version}/profile/{profile-name}/config/{cfg-name}"},
method = RequestMethod.PUT, produces = "application/json")
public String updateConfiguration(@RequestBody ConfigurationEntity cE, @PathVariable("rb-name") String rbName,
- @PathVariable("rb-version") String rbVersion, @PathVariable("profile-name") String prName,
- @PathVariable("cfg-name") String cfgName) throws Exception {
+ @PathVariable("rb-version") String rbVersion, @PathVariable("profile-name") String prName,
+ @PathVariable("cfg-name") String cfgName) throws Exception {
logger.info("update Configuration called.");
// TODO
// Below URL should be changed as appropriate multicloud URL.
- HttpPut post = new HttpPut(uri +"/v1/definition/" + rbName + "/" + rbVersion + "/profile/"
+ HttpPut post = new HttpPut(uri + "/v1/definition/" + rbName + "/" + rbVersion + "/profile/"
+ prName + "/config/" + cfgName);
ObjectMapper objectMapper = new ObjectMapper();
String requestBody = objectMapper.writeValueAsString(cE);
@@ -537,7 +563,7 @@ public class CnfAdapterRest {
post.setEntity(requestEntity);
try (CloseableHttpClient httpClient = HttpClients.createDefault();
- CloseableHttpResponse response = httpClient.execute(post)) {
+ CloseableHttpResponse response = httpClient.execute(post)) {
logger.info("response:" + response.getEntity());
return EntityUtils.toString(response.getEntity());
}
@@ -547,12 +573,12 @@ public class CnfAdapterRest {
@RequestMapping(value = {"/api/cnf-adapter/v1/definition/{rb-name}/{rb-version}/profile/{profile-name}/tagit"},
method = RequestMethod.POST, produces = "application/json")
public String tagConfigurationValue(@RequestBody Tag tag, @PathVariable("rb-name") String rbName,
- @PathVariable("rb-version") String rbVersion, @PathVariable("pr-name") String prName) throws Exception {
+ @PathVariable("rb-version") String rbVersion, @PathVariable("pr-name") String prName) throws Exception {
logger.info("Tag Configuration called.");
// TODO
// Below URL should be changed as appropriate multicloud URL.
- HttpPost post = new HttpPost(uri +"/v1/definition/" + rbName + "/" + rbVersion
+ HttpPost post = new HttpPost(uri + "/v1/definition/" + rbName + "/" + rbVersion
+ "/profile/" + prName + "/config/tagit");
ObjectMapper objectMapper = new ObjectMapper();
@@ -561,7 +587,7 @@ public class CnfAdapterRest {
post.setEntity(requestEntity);
try (CloseableHttpClient httpClient = HttpClients.createDefault();
- CloseableHttpResponse response = httpClient.execute(post)) {
+ CloseableHttpResponse response = httpClient.execute(post)) {
logger.info("response:" + response.getEntity());
return EntityUtils.toString(response.getEntity());
}
@@ -576,14 +602,14 @@ public class CnfAdapterRest {
// TODO
// Below URL should be changed as appropriate multicloud URL.
- HttpPost post = new HttpPost(uri +"/v1/connectivity-info");
+ HttpPost post = new HttpPost(uri + "/v1/connectivity-info");
ObjectMapper objectMapper = new ObjectMapper();
String requestBody = objectMapper.writeValueAsString(cIE);
StringEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
post.setEntity(requestEntity);
try (CloseableHttpClient httpClient = HttpClients.createDefault();
- CloseableHttpResponse response = httpClient.execute(post)) {
+ CloseableHttpResponse response = httpClient.execute(post)) {
logger.info("response:" + response.getEntity());
return EntityUtils.toString(response.getEntity());
}
@@ -598,7 +624,7 @@ public class CnfAdapterRest {
// TODO
// Below URL should be changed as appropriate multicloud URL.
- HttpGet req = new HttpGet(uri +"/v1/connectivity-info/" + connName);
+ HttpGet req = new HttpGet(uri + "/v1/connectivity-info/" + connName);
try (CloseableHttpResponse response = httpClient.execute(req)) {
logger.info("response:" + response.getEntity());
@@ -615,7 +641,7 @@ public class CnfAdapterRest {
// TODO
// Below URL should be changed as appropriate multicloud URL.
- HttpDelete req = new HttpDelete(uri +"/v1/connectivity-info/" + connName);
+ HttpDelete req = new HttpDelete(uri + "/v1/connectivity-info/" + connName);
try (CloseableHttpResponse response = httpClient.execute(req)) {
logger.info("response:" + response.getEntity());
@@ -628,21 +654,21 @@ public class CnfAdapterRest {
@RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}/{rb-version}/config-template"},
method = RequestMethod.POST, produces = "application/json")
public String createConfigTemplate(@RequestBody ConfigTemplateEntity tE, @PathVariable("rb-name") String rbName,
- @PathVariable("rb-version") String rbVersion) throws Exception {
+ @PathVariable("rb-version") String rbVersion) throws Exception {
logger.info("createConfigTemplate called.");
// TODO
// Below URL should be changed as appropriate multicloud URL.
HttpPost post = new HttpPost(
- uri +"/v1/rb/definition/" + rbName + "/" + rbVersion + "/config-template");
+ uri + "/v1/rb/definition/" + rbName + "/" + rbVersion + "/config-template");
ObjectMapper objectMapper = new ObjectMapper();
String requestBody = objectMapper.writeValueAsString(tE);
StringEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
post.setEntity(requestEntity);
try (CloseableHttpClient httpClient = HttpClients.createDefault();
- CloseableHttpResponse response = httpClient.execute(post)) {
+ CloseableHttpResponse response = httpClient.execute(post)) {
logger.info("response:" + response.getEntity());
return EntityUtils.toString(response.getEntity());
}
@@ -652,13 +678,13 @@ public class CnfAdapterRest {
@RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}/{rb-version}/config-template/{tname}"},
method = RequestMethod.GET, produces = "application/json")
public String getConfigTemplate(@PathVariable("rb-name") String rbName,
- @PathVariable("rb-version") String rbVersion, @PathVariable("tname") String tName) throws Exception {
+ @PathVariable("rb-version") String rbVersion, @PathVariable("tname") String tName) throws Exception {
logger.info("getConfigTemplate called.");
// TODO
// Below URL should be changed as appropriate multicloud URL.
- HttpGet req = new HttpGet(uri +"/v1/rb/definition/" + rbName + "/" + rbVersion
+ HttpGet req = new HttpGet(uri + "/v1/rb/definition/" + rbName + "/" + rbVersion
+ "/config-template/" + tName);
try (CloseableHttpResponse response = httpClient.execute(req)) {
@@ -671,13 +697,13 @@ public class CnfAdapterRest {
@RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}/{rb-version}/config-template/{tname}"},
method = RequestMethod.DELETE, produces = "application/json")
public String deleteTemplate(@PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion,
- @PathVariable("tname") String tName) throws Exception {
+ @PathVariable("tname") String tName) throws Exception {
logger.info("deleteTemplate called.");
// TODO
// Below URL should be changed as appropriate multicloud URL.
- HttpDelete req = new HttpDelete(uri +"/v1/rb/definition/" + rbName + "/" + rbVersion
+ HttpDelete req = new HttpDelete(uri + "/v1/rb/definition/" + rbName + "/" + rbVersion
+ "/config-template/" + tName);
try (CloseableHttpResponse response = httpClient.execute(req)) {
@@ -692,8 +718,8 @@ public class CnfAdapterRest {
value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}/{rb-version}/config-template/{tname}/content"},
method = RequestMethod.POST, produces = "multipart/form-data")
public String uploadTarFileForTemplate(@RequestParam("file") MultipartFile file,
- @PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion,
- @PathVariable("tname") String tName) throws Exception {
+ @PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion,
+ @PathVariable("tname") String tName) throws Exception {
logger.info("uploadTarFileForTemplate called.");
@@ -707,7 +733,7 @@ public class CnfAdapterRest {
// TODO
// Below URL should be changed as appropriate multicloud URL.
- HttpPost post = new HttpPost(uri +"/v1/rb/definition/" + rbName + "/" + rbVersion
+ HttpPost post = new HttpPost(uri + "/v1/rb/definition/" + rbName + "/" + rbVersion
+ "/config-template/" + tName + "/content");
post.setHeader("Content-Type", "multipart/form-data");
@@ -715,7 +741,7 @@ public class CnfAdapterRest {
post.setEntity(entity);
try (CloseableHttpClient httpClient = HttpClients.createDefault();
- CloseableHttpResponse response = httpClient.execute(post)) {
+ CloseableHttpResponse response = httpClient.execute(post)) {
logger.info("response:" + response.getEntity());
return EntityUtils.toString(response.getEntity());
}
@@ -725,13 +751,13 @@ public class CnfAdapterRest {
@RequestMapping(value = {"/api/cnf-adapter/v1/definition/{rbName}/{rbVersion}/profile/{prName}/config/rollback"},
method = RequestMethod.DELETE, produces = "application/json")
public String rollbackConfiguration(@RequestBody ConfigurationRollbackEntity rE,
- @PathVariable("rbName") String rbName, @PathVariable("rbVersion") String rbVersion,
- @PathVariable("prName") String prName) throws Exception {
+ @PathVariable("rbName") String rbName, @PathVariable("rbVersion") String rbVersion,
+ @PathVariable("prName") String prName) throws Exception {
logger.info("rollbackConfiguration called.");
// TODO
// Below URL should be changed as appropriate multicloud URL.
- HttpPost post = new HttpPost(uri +"/v1/definition/" + rbName + "/" + rbVersion
+ HttpPost post = new HttpPost(uri + "/v1/definition/" + rbName + "/" + rbVersion
+ "/profile/" + prName + "/config/rollback");
ObjectMapper objectMapper = new ObjectMapper();
@@ -740,7 +766,7 @@ public class CnfAdapterRest {
post.setEntity(requestEntity);
try (CloseableHttpClient httpClient = HttpClients.createDefault();
- CloseableHttpResponse response = httpClient.execute(post)) {
+ CloseableHttpResponse response = httpClient.execute(post)) {
logger.info("response:" + response.getEntity());
return EntityUtils.toString(response.getEntity());
}
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
new file mode 100644
index 0000000..383a753
--- /dev/null
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiIdGeneratorService.java
@@ -0,0 +1,25 @@
+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.statuscheck.K8sRbInstanceGvk;
+import org.onap.so.adapters.cnf.model.statuscheck.K8sRbInstanceResourceStatus;
+import org.springframework.stereotype.Service;
+
+import java.nio.charset.StandardCharsets;
+
+@Service
+class AaiIdGeneratorService {
+
+ String generateId(K8sRbInstanceResourceStatus resourceStatus, AaiUpdateRequest aaiUpdateRequest) {
+ K8sRbInstanceGvk gvk = resourceStatus.getGvk();
+ String originalString = resourceStatus.getName() + gvk.getKind() + gvk.getGroup() + gvk.getVersion() +
+ aaiUpdateRequest.getInstanceId() + aaiUpdateRequest.getCloudOwner() +
+ aaiUpdateRequest.getCloudRegion() + aaiUpdateRequest.getTenantId();
+
+ return Hashing.sha256()
+ .hashString(originalString, StandardCharsets.UTF_8)
+ .toString();
+ }
+
+}
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
new file mode 100644
index 0000000..bf9e64b
--- /dev/null
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiService.java
@@ -0,0 +1,157 @@
+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.statuscheck.K8sRbInstanceGvk;
+import org.onap.so.adapters.cnf.model.statuscheck.K8sRbInstanceResourceStatus;
+import org.onap.so.adapters.cnf.model.statuscheck.K8sRbInstanceStatus;
+import org.onap.so.adapters.cnf.model.statuscheck.K8sStatusMetadata;
+import org.onap.so.client.exception.BadResponseException;
+import org.springframework.stereotype.Service;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+@Service
+public class AaiService {
+
+ private final static Gson gson = new Gson();
+ private final MulticloudClient multicloudClient;
+ private final AaiIdGeneratorService aaiIdGeneratorService;
+ private AAIResourcesClient aaiClient;
+
+ public AaiService(MulticloudClient multicloudClient, AaiIdGeneratorService aaiIdGeneratorService) {
+ this.multicloudClient = multicloudClient;
+ this.aaiIdGeneratorService = aaiIdGeneratorService;
+ }
+
+ public void aaiUpdate(AaiUpdateRequest aaiUpdateRequest) throws BadResponseException {
+ String instanceId = aaiUpdateRequest.getInstanceId();
+ K8sRbInstanceStatus instanceStatus = multicloudClient.getInstanceStatus(instanceId);
+
+ List<K8sRbInstanceResourceStatus> resourcesStatus = instanceStatus.getResourcesStatus();
+ List<ParseResult> parsedStatus = resourcesStatus.stream()
+ .map(status -> parse(status, aaiUpdateRequest))
+ .collect(Collectors.toList());
+
+ parsedStatus.forEach(status -> sendPostRequestToAai(status, aaiUpdateRequest));
+ }
+
+ private void sendPostRequestToAai(ParseResult parseResult, AaiUpdateRequest aaiUpdateRequest) {
+ AAIResourceUri aaiUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure()
+ .cloudRegion(aaiUpdateRequest.getCloudOwner(), aaiUpdateRequest.getCloudRegion())
+ .tenant(aaiUpdateRequest.getTenantId())
+ .build());
+ String payload = gson.toJson(parseResult);
+ getAaiClient().create(aaiUri, payload);
+ }
+
+ private AAIResourcesClient getAaiClient() {
+ if (aaiClient == null) {
+ aaiClient = new AAIResourcesClient();
+ }
+ return aaiClient;
+ }
+
+ private ParseResult parse(K8sRbInstanceResourceStatus status, AaiUpdateRequest aaiUpdateRequest) {
+ ParseResult result = new ParseResult();
+ K8sRbInstanceGvk gvk = status.getGvk();
+ K8sStatusMetadata metadata = status.getStatus().getK8sStatusMetadata();
+ String id = aaiIdGeneratorService.generateId(status, aaiUpdateRequest);
+ result.setId(id);
+ result.setName(status.getName());
+ result.setGroup(gvk.getGroup());
+ result.setVersion(gvk.getVersion());
+ result.setKind(gvk.getKind());
+ result.setNamespace(metadata.getNamespace());
+ Collection<String> labels = new ArrayList<>();
+ metadata.getLabels().forEach((key, value) -> {
+ labels.add(key);
+ labels.add(value);
+ });
+ result.setLabels(labels);
+ result.setK8sResourceSelfLink(String.format("http://so-cnf-adapter:8090/api/cnf-adapter/v1/instance/%s/query", aaiUpdateRequest.getInstanceId()));
+ return result;
+ }
+
+ private class ParseResult {
+ private String id;
+ private String name;
+ private String group;
+ private String version;
+ private String kind;
+ private String namespace;
+ private Collection<String> labels;
+ private String k8sResourceSelfLink;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getGroup() {
+ return group;
+ }
+
+ public void setGroup(String group) {
+ this.group = group;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ public String getKind() {
+ return kind;
+ }
+
+ public void setKind(String kind) {
+ this.kind = kind;
+ }
+
+ public String getNamespace() {
+ return namespace;
+ }
+
+ public void setNamespace(String namespace) {
+ this.namespace = namespace;
+ }
+
+ public Collection<String> getLabels() {
+ return labels;
+ }
+
+ public void setLabels(Collection<String> labels) {
+ this.labels = labels;
+ }
+
+ public String getK8sResourceSelfLink() {
+ return k8sResourceSelfLink;
+ }
+
+ public void setK8sResourceSelfLink(String k8sResourceSelfLink) {
+ this.k8sResourceSelfLink = k8sResourceSelfLink;
+ }
+ }
+}