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;
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();
}
return response;
}
+ @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")
// 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);
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());
}
// 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());
// 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());
// 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());
// 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());
@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.");
// 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());
}
@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());
}
@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());
// 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());
@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());
@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.");
// 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");
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());
}
@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);
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());
}
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)) {
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)) {
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);
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());
}
@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();
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());
}
// 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());
}
// 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());
// 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());
@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());
}
@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)) {
@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)) {
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.");
// 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");
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());
}
@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();
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());
}
--- /dev/null
+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;
+ }
+ }
+}