summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--releases/1.9.1.yaml9
-rw-r--r--releases/1.9.2.yaml9
-rwxr-xr-xso-cnf-adapter-application/pom.xml16
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/AaiConfiguration.java20
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/MSOCnfApplication.java2
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/MulticloudConfiguration.java20
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/client/MulticloudApiUrl.java23
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/client/MulticloudClient.java166
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/exceptions/ApplicationException.java3
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/MulticloudInstanceRequest.java12
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/aai/AaiCallbackResponse.java20
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/aai/AaiRequest.java (renamed from so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/instantiation/AaiRequest.java)43
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/healthcheck/HealthCheckInstance.java20
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/healthcheck/HealthCheckInstanceResponse.java20
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/healthcheck/HealthCheckResponse.java44
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/healthcheck/K8sRbInstanceHealthCheck.java45
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/healthcheck/K8sRbInstanceHealthCheckSimple.java25
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/K8sOwnerReference.java96
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/K8sRbInstanceGvk.java22
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/K8sRbInstanceResourceStatus.java22
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/K8sRbInstanceStatus.java22
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/K8sStatus.java82
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/K8sStatusMetadata.java96
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/StatusCheckInstanceResponse.java22
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/StatusCheckResponse.java45
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/synchronization/NotificationRequest.java75
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/synchronization/SubscriptionRequest.java85
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/synchronization/SubscriptionResponse.java118
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/upgrade/InstanceUpgradeRequest.java158
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/rest/CnfAdapterRest.java95
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/rest/SubscriptionNotifyController.java81
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/CnfAdapterService.java29
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiIdGeneratorService.java32
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiRequestSender.java40
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiResponseParser.java83
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiService.java62
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/KubernetesResource.java160
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/ParseResult.java78
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/healthcheck/HealthCheckService.java42
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/statuscheck/SimpleStatusCheckService.java35
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/synchrornization/SubscriptionsRecoveryProvider.java29
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/synchrornization/SynchronizationService.java151
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/upgrade/InstanceUpgradeService.java60
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/util/AaiClientPropertiesImpl.java115
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/util/AaiRepository.java226
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/util/CnfAdapterUtil.java (renamed from so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/util/CNfAdapterUtil.java)52
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/util/IAaiRepository.java87
-rw-r--r--so-cnf-adapter-application/src/main/resources/META-INF/services/org.onap.so.client.RestProperties2
-rw-r--r--so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/AaiConfigurationTest.java16
-rw-r--r--so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/client/MulticloudApiUrlTest.java37
-rw-r--r--so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/client/MulticloudClientTest.java266
-rw-r--r--so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/exceptions/ApplicationExceptionTest.java12
-rw-r--r--so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/rest/CnfAdapterRestTest.java147
-rw-r--r--so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/rest/CnfRestTest.java174
-rw-r--r--so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/CnfAdapterServiceTest.java60
-rw-r--r--so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/aai/AaiIdGeneratorServiceTest.java12
-rw-r--r--so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/aai/AaiResponseParserTest.java61
-rw-r--r--so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/aai/AaiServiceTest.java26
-rw-r--r--so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/healthcheck/HealthCheckServiceTest.java72
-rw-r--r--so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/statuscheck/SimpleStatusCheckServiceTest.java2
-rw-r--r--so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/synchrornization/SubscriptionsRecoveryProvider.java17
-rw-r--r--so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/synchrornization/SynchronizationServiceTest.java96
-rw-r--r--so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/upgrade/InstanceUpgradeServiceTest.java108
-rw-r--r--so-cnf-adapter-application/src/test/resources/application.properties4
-rw-r--r--version.properties2
65 files changed, 3417 insertions, 494 deletions
diff --git a/releases/1.9.1.yaml b/releases/1.9.1.yaml
new file mode 100644
index 0000000..05e5162
--- /dev/null
+++ b/releases/1.9.1.yaml
@@ -0,0 +1,9 @@
+---
+distribution_type: 'container'
+container_release_tag: '1.9.1'
+project: 'so'
+log_dir: 'so-adapters-so-cnf-adapter-maven-docker-stage-master/258/'
+ref: '4c590aa29559a5de919dd41a5d592c1051c766bf'
+containers:
+ - name: 'so/so-cnf-adapter'
+ version: '1.9.1-20211007T1033'
diff --git a/releases/1.9.2.yaml b/releases/1.9.2.yaml
new file mode 100644
index 0000000..7ac6f66
--- /dev/null
+++ b/releases/1.9.2.yaml
@@ -0,0 +1,9 @@
+---
+distribution_type: 'container'
+container_release_tag: '1.9.2'
+project: 'so'
+log_dir: 'so-adapters-so-cnf-adapter-maven-docker-stage-master/274/'
+ref: '788d344848a4a37f2a86de233cfc90e7a306aca8'
+containers:
+ - name: 'so/so-cnf-adapter'
+ version: '1.9.2-20211022T1736'
diff --git a/so-cnf-adapter-application/pom.xml b/so-cnf-adapter-application/pom.xml
index 504d994..32254ca 100755
--- a/so-cnf-adapter-application/pom.xml
+++ b/so-cnf-adapter-application/pom.xml
@@ -94,6 +94,15 @@
</resource>
</resources>
</build>
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.onap.aai.schema-service</groupId>
+ <artifactId>aai-schema</artifactId>
+ <version>1.9.2</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
@@ -159,14 +168,9 @@
<type>pom</type>
</dependency>
<dependency>
- <groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
- <scope>test</scope>
+ <scope>provided</scope>
</dependency>
</dependencies>
</project>
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/AaiConfiguration.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/AaiConfiguration.java
index 49f95a6..3845bf4 100644
--- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/AaiConfiguration.java
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/AaiConfiguration.java
@@ -1,3 +1,23 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2021 Samsung Electronics Co. Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
package org.onap.so.adapters.cnf;
import org.springframework.beans.factory.annotation.Value;
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/MSOCnfApplication.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/MSOCnfApplication.java
index 0ba40e2..a437b9d 100644
--- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/MSOCnfApplication.java
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/MSOCnfApplication.java
@@ -34,7 +34,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
@SpringBootApplication
-@ComponentScan(basePackages = {"org.onap.so.adapters.cnf"})
+@ComponentScan(basePackages = {"org.onap.so.adapters.cnf", "org.onap.so.spring"})
@EnableAutoConfiguration(exclude = {LiquibaseAutoConfiguration.class, HibernateJpaAutoConfiguration.class,
DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class,
SecurityAutoConfiguration.class})
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/MulticloudConfiguration.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/MulticloudConfiguration.java
index 0890739..5eb5e6f 100644
--- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/MulticloudConfiguration.java
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/MulticloudConfiguration.java
@@ -1,3 +1,23 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2021 Samsung Electronics Co. Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
package org.onap.so.adapters.cnf;
import org.springframework.beans.factory.annotation.Value;
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/client/MulticloudApiUrl.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/client/MulticloudApiUrl.java
new file mode 100644
index 0000000..617eef7
--- /dev/null
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/client/MulticloudApiUrl.java
@@ -0,0 +1,23 @@
+package org.onap.so.adapters.cnf.client;
+
+import org.onap.so.adapters.cnf.MulticloudConfiguration;
+import org.springframework.stereotype.Component;
+
+@Component
+class MulticloudApiUrl {
+
+ private final MulticloudConfiguration multicloudConfiguration;
+
+ MulticloudApiUrl(MulticloudConfiguration multicloudConfiguration1) {
+ this.multicloudConfiguration = multicloudConfiguration1;
+ }
+
+ String apiUrl(String instanceId) {
+ String url = multicloudConfiguration.getMulticloudUrl() + "/v1/instance";
+ if (!instanceId.isEmpty()) {
+ url += "/" + instanceId;
+ }
+ return url;
+ }
+
+} \ No newline at end of file
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/client/MulticloudClient.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/client/MulticloudClient.java
index 762f192..0f5df15 100644
--- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/client/MulticloudClient.java
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/client/MulticloudClient.java
@@ -1,11 +1,35 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
+ * Modifications Copyright (C) 2021 Samsung Technologies Co.
+ * Modifications Copyright (C) 2021 Orange.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
package org.onap.so.adapters.cnf.client;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
-import org.onap.so.adapters.cnf.MulticloudConfiguration;
+import org.onap.so.adapters.cnf.model.InstanceResponse;
+import org.onap.so.adapters.cnf.model.MulticloudInstanceRequest;
import org.onap.so.adapters.cnf.model.healthcheck.K8sRbInstanceHealthCheck;
import org.onap.so.adapters.cnf.model.healthcheck.K8sRbInstanceHealthCheckSimple;
import org.onap.so.adapters.cnf.model.statuscheck.K8sRbInstanceStatus;
+import org.onap.so.adapters.cnf.model.synchronization.SubscriptionRequest;
+import org.onap.so.adapters.cnf.model.synchronization.SubscriptionResponse;
import org.onap.so.client.exception.BadResponseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -15,9 +39,11 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
+import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.RestTemplate;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import static org.springframework.http.HttpMethod.DELETE;
@@ -30,19 +56,99 @@ public class MulticloudClient {
private static final Logger log = LoggerFactory.getLogger(MulticloudClient.class);
private final RestTemplate restTemplate;
- private final MulticloudConfiguration multicloudConfiguration;
+ private final MulticloudApiUrl multicloudApiUrl;
private final ObjectMapper objectMapper;
- public MulticloudClient(RestTemplate restTemplate, MulticloudConfiguration multicloudConfiguration) {
+ public MulticloudClient(RestTemplate restTemplate, MulticloudApiUrl multicloudApiUrl) {
this.restTemplate = restTemplate;
- this.multicloudConfiguration = multicloudConfiguration;
+ this.multicloudApiUrl = multicloudApiUrl;
this.objectMapper = new ObjectMapper();
}
+ public List<InstanceResponse> getAllInstances() throws BadResponseException {
+ String endpoint = multicloudApiUrl.apiUrl("");
+ ResponseEntity<String> result = restTemplate.exchange(endpoint, GET, getHttpEntity(), String.class);
+ checkResponseStatusCode(result);
+ log.info("getAllInstances response status: {}", result.getStatusCode());
+ String body = result.getBody();
+ log.debug("getAllInstances response body: {}", body);
+
+ try {
+ return Arrays.asList(objectMapper.readValue(body, InstanceResponse[].class));
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public SubscriptionResponse registerSubscription(String instanceId, SubscriptionRequest subscriptionRequest) throws BadResponseException {
+ String endpoint = multicloudApiUrl.apiUrl(instanceId) + "/status/subscription";
+ ResponseEntity<String> result = restTemplate.exchange(endpoint, POST, getHttpEntity(subscriptionRequest), String.class);
+ checkResponseStatusCode(result);
+ log.info("registerSubscription response status: {}", result.getStatusCode());
+ String body = result.getBody();
+ log.debug("registerSubscription response body: {}", body);
+
+ try {
+ return objectMapper.readValue(body, SubscriptionResponse.class);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public Boolean hasSubscription(String instanceId, String subscriptionId) throws BadResponseException {
+ String endpoint = multicloudApiUrl.apiUrl(instanceId) + "/status/subscription/" + subscriptionId;
+ try {
+ ResponseEntity<String> result = restTemplate.exchange(endpoint, GET, getHttpEntity(), String.class);
+ checkResponseStatusCode(result);
+ log.info("hasSubscription response status: {}", result.getStatusCode());
+ return true;
+ } catch (HttpServerErrorException e) {
+ if (e.getMessage().contains("no documents")) {
+ log.info("hasSubscription response status: {}", 500);
+ return false;
+ } else
+ throw e;
+ }
+ }
+
+ public SubscriptionResponse getSubscription(String instanceId, String subscriptionId) throws BadResponseException {
+ String endpoint = multicloudApiUrl.apiUrl(instanceId) + "/status/subscription/" + subscriptionId;
+ try {
+ ResponseEntity<String> result = restTemplate.exchange(endpoint, GET, getHttpEntity(), String.class);
+ checkResponseStatusCode(result);
+ log.info("getSubscription response status: {}", result.getStatusCode());
+ String body = result.getBody();
+ log.debug("getSubscription response body: {}", body);
+ return objectMapper.readValue(body, SubscriptionResponse.class);
+ } catch (HttpServerErrorException e) {
+ if (e.getMessage().contains("no documents")) {
+ throw new BadResponseException("Multicloud response status error 404");
+ } else
+ throw e;
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void deleteSubscription(String instanceId, String subscriptionId) throws BadResponseException {
+ String endpoint = multicloudApiUrl.apiUrl(instanceId) + "/status/subscription/" + subscriptionId;
+ ResponseEntity<String> result = restTemplate.exchange(endpoint, DELETE, getHttpEntity(), String.class);
+ checkResponseStatusCode(result);
+ log.info("deleteSubscription response status: {}", result.getStatusCode());
+ }
+
+ public String upgradeInstance(String instanceId, MulticloudInstanceRequest upgradeRequest) throws BadResponseException {
+ String endpoint = multicloudApiUrl.apiUrl(instanceId) + "/upgrade";
+ ResponseEntity<String> result = restTemplate.exchange(endpoint, POST, getHttpEntity(upgradeRequest), String.class);
+ checkResponseStatusCode(result);
+ log.info("upgradeInstance response status: {}", result.getStatusCode());
+ String body = result.getBody();
+ log.debug("upgradeInstance response body: {}", body);
+ return body;
+ }
+
public K8sRbInstanceStatus getInstanceStatus(String instanceId) throws BadResponseException {
- MulticloudApiUrl multicloudApiUrl = new MulticloudApiUrl(multicloudConfiguration);
- multicloudApiUrl.setInstanceId(instanceId);
- String endpoint = multicloudApiUrl.apiUrl() + "/status";
+ String endpoint = multicloudApiUrl.apiUrl(instanceId) + "/status";
ResponseEntity<String> result = restTemplate.exchange(endpoint, GET, getHttpEntity(), String.class);
checkResponseStatusCode(result);
log.info("getInstanceStatus response status: {}", result.getStatusCode());
@@ -57,9 +163,7 @@ public class MulticloudClient {
}
public K8sRbInstanceHealthCheckSimple startInstanceHealthCheck(String instanceId) throws BadResponseException {
- MulticloudApiUrl multicloudApiUrl = new MulticloudApiUrl(multicloudConfiguration);
- multicloudApiUrl.setInstanceId(instanceId);
- String endpoint = multicloudApiUrl.apiUrl() + "/healthcheck";
+ String endpoint = multicloudApiUrl.apiUrl(instanceId) + "/healthcheck";
ResponseEntity<String> result = restTemplate.exchange(endpoint, POST, getHttpEntity(), String.class);
checkResponseStatusCode(result);
log.info("startInstanceHealthCheck response status: {}", result.getStatusCode());
@@ -74,9 +178,7 @@ public class MulticloudClient {
}
public K8sRbInstanceHealthCheck getInstanceHealthCheck(String instanceId, String healthCheckInstance) throws BadResponseException {
- MulticloudApiUrl multicloudApiUrl = new MulticloudApiUrl(multicloudConfiguration);
- multicloudApiUrl.setInstanceId(instanceId);
- String endpoint = multicloudApiUrl.apiUrl() + "/healthcheck/" + healthCheckInstance;
+ String endpoint = multicloudApiUrl.apiUrl(instanceId) + "/healthcheck/" + healthCheckInstance;
ResponseEntity<String> result = restTemplate.exchange(endpoint, GET, getHttpEntity(), String.class);
checkResponseStatusCode(result);
log.info("getInstanceHealthCheck response status: {}", result.getStatusCode());
@@ -91,9 +193,7 @@ public class MulticloudClient {
}
public void deleteInstanceHealthCheck(String instanceId, String healthCheckInstance) throws BadResponseException {
- MulticloudApiUrl multicloudApiUrl = new MulticloudApiUrl(multicloudConfiguration);
- multicloudApiUrl.setInstanceId(instanceId);
- String endpoint = multicloudApiUrl.apiUrl() + "/healthcheck/" + healthCheckInstance;
+ String endpoint = multicloudApiUrl.apiUrl(instanceId) + "/healthcheck/" + healthCheckInstance;
ResponseEntity<String> result = restTemplate.exchange(endpoint, DELETE, getHttpEntity(), String.class);
checkResponseStatusCode(result);
log.info("deleteInstanceHealthCheck response status: {}", result.getStatusCode());
@@ -105,14 +205,25 @@ public class MulticloudClient {
}
}
- private HttpEntity<?> getHttpEntity() {
+ private HttpEntity<Void> getHttpEntity() {
+ HttpHeaders headers = getHttpHeaders();
+
+ return new HttpEntity<>(headers);
+ }
+
+ private HttpHeaders getHttpHeaders() {
HttpHeaders headers = new HttpHeaders();
List<MediaType> acceptableMediaTypes = new ArrayList<>();
acceptableMediaTypes.add(MediaType.APPLICATION_JSON);
headers.setAccept(acceptableMediaTypes);
headers.setContentType(MediaType.APPLICATION_JSON);
+ return headers;
+ }
- return new HttpEntity<>(headers);
+ private <T> HttpEntity<T> getHttpEntity(T body) {
+ HttpHeaders headers = getHttpHeaders();
+
+ return new HttpEntity<>(body, headers);
}
private void checkResponseStatusCode(ResponseEntity<String> result) throws BadResponseException {
@@ -121,23 +232,4 @@ public class MulticloudClient {
throw new BadResponseException("Multicloud response status error", String.valueOf(statusCode.value()));
}
}
-
- private class MulticloudApiUrl {
-
- private String instanceId;
- private final MulticloudConfiguration multicloudConfiguration;
-
- MulticloudApiUrl(MulticloudConfiguration multicloudConfiguration1) {
- this.multicloudConfiguration = multicloudConfiguration1;
- }
-
- String apiUrl() {
- String instanceUri = multicloudConfiguration.getMulticloudUrl() + "/v1/instance/";
- return instanceId.equals("") ? instanceUri : instanceUri + instanceId;
- }
-
- void setInstanceId(String instanceId) {
- this.instanceId = instanceId;
- }
- }
}
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/exceptions/ApplicationException.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/exceptions/ApplicationException.java
index c950cf6..40d0933 100644
--- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/exceptions/ApplicationException.java
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/exceptions/ApplicationException.java
@@ -20,10 +20,11 @@
package org.onap.so.adapters.cnf.exceptions;
-import static org.onap.so.adapters.cnf.util.CNfAdapterUtil.marshal;
import org.onap.so.adapters.cnf.model.ErrorResponse;
import org.springframework.http.ResponseEntity;
+import static org.onap.so.adapters.cnf.util.CnfAdapterUtil.marshal;
+
public class ApplicationException extends Exception {
private static final long serialVersionUID = 1L;
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/MulticloudInstanceRequest.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/MulticloudInstanceRequest.java
index 20af63e..fa58cfd 100644
--- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/MulticloudInstanceRequest.java
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/MulticloudInstanceRequest.java
@@ -84,4 +84,16 @@ public class MulticloudInstanceRequest {
this.releaseName = releaseName;
}
+ @Override
+ public String toString() {
+ return "MulticloudInstanceRequest{" +
+ "cloudRegion='" + cloudRegion + '\'' +
+ ", rbName='" + rbName + '\'' +
+ ", rbVersion='" + rbVersion + '\'' +
+ ", profileName='" + profileName + '\'' +
+ ", labels=" + labels +
+ ", overrideValues=" + overrideValues +
+ ", releaseName='" + releaseName + '\'' +
+ '}';
+ }
}
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
index b6ebbb3..d72d1f9 100644
--- 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
@@ -1,3 +1,23 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2021 Samsung Electronics Co. Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
package org.onap.so.adapters.cnf.model.aai;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/instantiation/AaiRequest.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/aai/AaiRequest.java
index 0665d9a..21165b1 100644
--- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/instantiation/AaiRequest.java
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/aai/AaiRequest.java
@@ -1,4 +1,23 @@
-package org.onap.so.adapters.cnf.model.instantiation;
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.adapters.cnf.model.aai;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
@@ -18,6 +37,10 @@ public class AaiRequest {
private String tenantId;
@JsonProperty("callbackUrl")
private String callbackUrl;
+ @JsonProperty("genericVnfId")
+ private String genericVnfId;
+ @JsonProperty("vfModuleId")
+ private String vfModuleId;
public String getInstanceId() {
return instanceId;
@@ -59,6 +82,22 @@ public class AaiRequest {
this.callbackUrl = callbackUrl;
}
+ public String getVfModuleId() {
+ return vfModuleId;
+ }
+
+ public void setVfModuleId(String vfModuleId) {
+ this.vfModuleId = vfModuleId;
+ }
+
+ public String getGenericVnfId() {
+ return genericVnfId;
+ }
+
+ public void setGenericVnfId(String genericVnfId) {
+ this.genericVnfId = genericVnfId;
+ }
+
@Override
public String toString() {
return "AaiRequest{" +
@@ -67,6 +106,8 @@ public class AaiRequest {
", cloudOwner='" + cloudOwner + '\'' +
", tenantId='" + tenantId + '\'' +
", callbackUrl='" + callbackUrl + '\'' +
+ ", genericVnfId='" + genericVnfId + '\'' +
+ ", vfModuleId='" + vfModuleId + '\'' +
'}';
}
}
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/healthcheck/HealthCheckInstance.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/healthcheck/HealthCheckInstance.java
index df87768..841db97 100644
--- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/healthcheck/HealthCheckInstance.java
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/healthcheck/HealthCheckInstance.java
@@ -1,3 +1,23 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2021 Samsung Electronics Co. Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
package org.onap.so.adapters.cnf.model.healthcheck;
public class HealthCheckInstance {
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/healthcheck/HealthCheckInstanceResponse.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/healthcheck/HealthCheckInstanceResponse.java
index 7811fe1..e71d4ba 100644
--- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/healthcheck/HealthCheckInstanceResponse.java
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/healthcheck/HealthCheckInstanceResponse.java
@@ -1,3 +1,23 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2021 Samsung Electronics Co. Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
package org.onap.so.adapters.cnf.model.healthcheck;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/healthcheck/HealthCheckResponse.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/healthcheck/HealthCheckResponse.java
index 2d0bb88..1bc6253 100644
--- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/healthcheck/HealthCheckResponse.java
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/healthcheck/HealthCheckResponse.java
@@ -1,3 +1,24 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2021 Samsung Electronics Co. Ltd. All rights reserved.
+ * Modifications Copyright (C) 2021 Orange.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
package org.onap.so.adapters.cnf.model.healthcheck;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@@ -11,32 +32,19 @@ import java.util.List;
public class HealthCheckResponse {
@JsonProperty("result")
- private List<HealthCheckInstanceResponse> instanceResponse;
-
- @JsonProperty("error")
- private String errorMessage;
+ private List<HealthCheckInstanceResponse> result;
public List<HealthCheckInstanceResponse> getInstanceResponse() {
- return instanceResponse;
- }
-
- public void setInstanceResponse(List<HealthCheckInstanceResponse> instanceResponse) {
- this.instanceResponse = instanceResponse;
- }
-
- public String getErrorMessage() {
- return errorMessage;
+ return result;
}
- public void setErrorMessage(String errorMessage) {
- this.errorMessage = errorMessage;
+ public void setInstanceResponse(List<HealthCheckInstanceResponse> result) {
+ this.result = result;
}
@Override
public String toString() {
return "HealthCheckResponse{" +
- "instanceResponse=" + instanceResponse +
- ", errorMessage='" + errorMessage + '\'' +
- '}';
+ "result=" + result + '}';
}
}
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/healthcheck/K8sRbInstanceHealthCheck.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/healthcheck/K8sRbInstanceHealthCheck.java
index bab6a5a..21e58ee 100644
--- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/healthcheck/K8sRbInstanceHealthCheck.java
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/healthcheck/K8sRbInstanceHealthCheck.java
@@ -1,3 +1,24 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2021 Samsung Electronics Co. Ltd. All rights reserved.
+ * Modifications Copyright (C) 2021 Orange.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
package org.onap.so.adapters.cnf.model.healthcheck;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@@ -5,9 +26,15 @@ import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
@JsonInclude(JsonInclude.Include.NON_NULL)
-@JsonIgnoreProperties(value = "true")
+@JsonIgnoreProperties(ignoreUnknown = true)
public class K8sRbInstanceHealthCheck {
+ @JsonProperty("instance-id")
+ private String instanceId;
+
+ @JsonProperty("healthcheck-id")
+ private String healthcheckId;
+
@JsonProperty("status")
private String status;
@@ -19,6 +46,22 @@ public class K8sRbInstanceHealthCheck {
this.status = status;
}
+ public String getInstanceId() {
+ return instanceId;
+ }
+
+ public void setInstanceId(String instanceId) {
+ this.instanceId = instanceId;
+ }
+
+ public String getHealthcheckId() {
+ return healthcheckId;
+ }
+
+ public void setHealthcheckId(String healthcheckId) {
+ this.healthcheckId = healthcheckId;
+ }
+
@Override
public String toString() {
return "K8sRbInstanceHealthCheck{" +
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/healthcheck/K8sRbInstanceHealthCheckSimple.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/healthcheck/K8sRbInstanceHealthCheckSimple.java
index 8a2590d..474510d 100644
--- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/healthcheck/K8sRbInstanceHealthCheckSimple.java
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/healthcheck/K8sRbInstanceHealthCheckSimple.java
@@ -1,7 +1,32 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2021 Samsung Electronics Co. Ltd. All rights reserved.
+ * Modifications Copyright (C) 2021 Orange.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
package org.onap.so.adapters.cnf.model.healthcheck;
+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 K8sRbInstanceHealthCheckSimple {
@JsonProperty("healthcheck-id")
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/K8sOwnerReference.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/K8sOwnerReference.java
new file mode 100644
index 0000000..47ba8c3
--- /dev/null
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/K8sOwnerReference.java
@@ -0,0 +1,96 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2021 Orange. All rights reserved
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.cnf.model.statuscheck;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class K8sOwnerReference {
+
+ @JsonProperty("uid")
+ private String uid;
+
+ @JsonProperty("name")
+ private String name;
+
+ @JsonProperty("kind")
+ private String kind;
+
+ @JsonProperty("apiVersion")
+ private String apiVersion;
+
+ @JsonProperty("controller")
+ private Boolean controller;
+
+ @JsonProperty("blockOwnerDeletion")
+ private Boolean blockOwnerDeletion;
+
+ public String getUid() {
+ return uid;
+ }
+
+ public void setUid(String uid) {
+ this.uid = uid;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getKind() {
+ return kind;
+ }
+
+ public void setKind(String kind) {
+ this.kind = kind;
+ }
+
+ public String getApiVersion() {
+ return apiVersion;
+ }
+
+ public void setApiVersion(String apiVersion) {
+ this.apiVersion = apiVersion;
+ }
+
+ public Boolean getController() {
+ return controller;
+ }
+
+ public void setController(Boolean controller) {
+ this.controller = controller;
+ }
+
+ public Boolean getBlockOwnerDeletion() {
+ return blockOwnerDeletion;
+ }
+
+ public void setBlockOwnerDeletion(Boolean blockOwnerDeletion) {
+ this.blockOwnerDeletion = blockOwnerDeletion;
+ }
+}
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/K8sRbInstanceGvk.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/K8sRbInstanceGvk.java
index fee6496..33f3c74 100644
--- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/K8sRbInstanceGvk.java
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/K8sRbInstanceGvk.java
@@ -1,3 +1,23 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2021 Samsung Electronics Co. Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
package org.onap.so.adapters.cnf.model.statuscheck;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@@ -5,7 +25,7 @@ import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
@JsonInclude(JsonInclude.Include.NON_NULL)
-@JsonIgnoreProperties(value = "true")
+@JsonIgnoreProperties(ignoreUnknown = true)
public class K8sRbInstanceGvk {
@JsonProperty("Group")
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 fe11b03..a125e40 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
@@ -1,3 +1,23 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2021 Samsung Electronics Co. Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
package org.onap.so.adapters.cnf.model.statuscheck;
@@ -8,7 +28,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Map;
@JsonInclude(JsonInclude.Include.NON_NULL)
-@JsonIgnoreProperties(value = "true")
+@JsonIgnoreProperties(ignoreUnknown = true)
public class K8sRbInstanceResourceStatus {
@JsonProperty("name")
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/K8sRbInstanceStatus.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/K8sRbInstanceStatus.java
index f8680af..a8ab468 100644
--- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/K8sRbInstanceStatus.java
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/K8sRbInstanceStatus.java
@@ -1,3 +1,23 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2021 Samsung Electronics Co. Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
package org.onap.so.adapters.cnf.model.statuscheck;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@@ -8,7 +28,7 @@ import org.onap.so.adapters.cnf.model.MulticloudInstanceRequest;
import java.util.List;
@JsonInclude(JsonInclude.Include.NON_NULL)
-@JsonIgnoreProperties(value = "true")
+@JsonIgnoreProperties(ignoreUnknown = true)
public class K8sRbInstanceStatus {
@JsonProperty("request")
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
index 5fe4e30..796e5f3 100644
--- 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
@@ -1,14 +1,94 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2021 Samsung Electronics Co. Ltd. All rights reserved.
+ * Modifications Copyright (C) 2021 Orange.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
package org.onap.so.adapters.cnf.model.statuscheck;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
-@JsonIgnoreProperties
+import java.util.Map;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonIgnoreProperties(ignoreUnknown = true)
public class K8sStatus {
@JsonProperty("metadata")
private K8sStatusMetadata k8sStatusMetadata;
+ @JsonProperty("apiVersion")
+ private String apiVersion;
+
+ @JsonProperty("kind")
+ private String kind;
+
+ @JsonProperty("data")
+ private Map<String, String> data;
+
+ @JsonProperty("spec")
+ private Map<String, Object> spec;
+
+ @JsonProperty("status")
+ private Map<String, Object> status;
+
+ public Map<String, Object> getSpec() {
+ return spec;
+ }
+
+ public void setSpec(Map<String, Object> spec) {
+ this.spec = spec;
+ }
+
+ public Map<String, Object> getStatus() {
+ return status;
+ }
+
+ public void setStatus(Map<String, Object> status) {
+ this.status = status;
+ }
+
+ public String getApiVersion() {
+ return apiVersion;
+ }
+
+ public void setApiVersion(String apiVersion) {
+ this.apiVersion = apiVersion;
+ }
+
+ public String getKind() {
+ return kind;
+ }
+
+ public void setKind(String kind) {
+ this.kind = kind;
+ }
+
+ public Map<String, String> getData() {
+ return data;
+ }
+
+ public void setData(Map<String, String> data) {
+ this.data = data;
+ }
+
public K8sStatusMetadata getK8sStatusMetadata() {
return 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
index a69f7e7..b3efafb 100644
--- 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
@@ -1,19 +1,107 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2021 Samsung Electronics Co. Ltd. All rights reserved.
+ * Modifications Copyright (C) 2021 Orange.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
package org.onap.so.adapters.cnf.model.statuscheck;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
+import java.util.List;
import java.util.Map;
-@JsonIgnoreProperties
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonIgnoreProperties(ignoreUnknown = true)
public class K8sStatusMetadata {
- @JsonProperty("metadata")
+ @JsonProperty("namespace")
private String namespace;
- @JsonProperty("metadata")
+ @JsonProperty("creationTimestamp")
+ private String creationTimestamp;
+
+ @JsonProperty("name")
+ private String name;
+
+ @JsonProperty("generateName")
+ private String generateName;
+
+ @JsonProperty("uid")
+ private String uid;
+
+ @JsonProperty("selfLink")
+ private String selfLink;
+
+ @JsonProperty("resourceVersion")
+ private String resourceVersion;
+
+ @JsonProperty("labels")
private Map<String, String> labels;
+ @JsonProperty("ownerReferences")
+ private List<K8sOwnerReference> ownerReferences;
+
+ @JsonProperty("annotations")
+ private Map<String, String> annotations;
+
+ public String getCreationTimestamp() {
+ return creationTimestamp;
+ }
+
+ public void setCreationTimestamp(String creationTimestamp) {
+ this.creationTimestamp = creationTimestamp;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getUid() {
+ return uid;
+ }
+
+ public void setUid(String uid) {
+ this.uid = uid;
+ }
+
+ public String getSelfLink() {
+ return selfLink;
+ }
+
+ public void setSelfLink(String selfLink) {
+ this.selfLink = selfLink;
+ }
+
+ public String getResourceVersion() {
+ return resourceVersion;
+ }
+
+ public void setResourceVersion(String resourceVersion) {
+ this.resourceVersion = resourceVersion;
+ }
+
public String getNamespace() {
return namespace;
}
@@ -34,7 +122,7 @@ public class K8sStatusMetadata {
public String toString() {
return "K8sStatusMetadata{" +
"namespace='" + namespace + '\'' +
- ", labels=" + labels +
+ ", name=" + name +
'}';
}
}
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/StatusCheckInstanceResponse.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/StatusCheckInstanceResponse.java
index fc5da9b..e605fbe 100644
--- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/StatusCheckInstanceResponse.java
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/StatusCheckInstanceResponse.java
@@ -1,3 +1,23 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2021 Samsung Electronics Co. Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
package org.onap.so.adapters.cnf.model.statuscheck;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@@ -5,7 +25,7 @@ import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
@JsonInclude(JsonInclude.Include.NON_NULL)
-@JsonIgnoreProperties(value = "true")
+@JsonIgnoreProperties(ignoreUnknown = true)
public class StatusCheckInstanceResponse {
@JsonProperty("instanceId")
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/StatusCheckResponse.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/StatusCheckResponse.java
index 5fdf762..f1eada3 100644
--- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/StatusCheckResponse.java
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/statuscheck/StatusCheckResponse.java
@@ -1,3 +1,24 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2021 Samsung Electronics Co. Ltd. All rights reserved.
+ * Modifications Copyright (C) 2021 Orange.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
package org.onap.so.adapters.cnf.model.statuscheck;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@@ -7,36 +28,24 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
@JsonInclude(JsonInclude.Include.NON_NULL)
-@JsonIgnoreProperties(value = "true")
+@JsonIgnoreProperties(ignoreUnknown = true)
public class StatusCheckResponse {
@JsonProperty("result")
- private List<StatusCheckInstanceResponse> instanceResponse;
-
- @JsonProperty("error")
- private String errorMessage;
+ private List<StatusCheckInstanceResponse> result;
public List<StatusCheckInstanceResponse> getInstanceResponse() {
- return instanceResponse;
- }
-
- public void setInstanceResponse(List<StatusCheckInstanceResponse> instanceResponse) {
- this.instanceResponse = instanceResponse;
- }
-
- public String getErrorMessage() {
- return errorMessage;
+ return result;
}
- public void setErrorMessage(String errorMessage) {
- this.errorMessage = errorMessage;
+ public void setInstanceResponse(List<StatusCheckInstanceResponse> result) {
+ this.result = result;
}
@Override
public String toString() {
return "StatusCheckResponse{" +
- "instanceResponse=" + instanceResponse +
- ", errorMessage='" + errorMessage + '\'' +
+ "result=" + result +
'}';
}
}
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/synchronization/NotificationRequest.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/synchronization/NotificationRequest.java
new file mode 100644
index 0000000..e0b021f
--- /dev/null
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/synchronization/NotificationRequest.java
@@ -0,0 +1,75 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
+ * Modifications Copyright (C) 2021 Samsung Technologies Co.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.adapters.cnf.model.synchronization;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.onap.so.adapters.cnf.model.aai.AaiRequest;
+
+import java.util.Map;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonIgnoreProperties(value = "true")
+public class NotificationRequest {
+
+ @JsonProperty("instance-id")
+ private String instanceId;
+ @JsonProperty("subscription-name")
+ private String subscriptionName;
+ @JsonProperty("metadata")
+ private AaiRequest metadata;
+
+ public NotificationRequest() { }
+
+ public String getInstanceId() {
+ return instanceId;
+ }
+
+ public void setInstanceId(String instanceId) {
+ this.instanceId = instanceId;
+ }
+
+ public String getSubscriptionName() {
+ return subscriptionName;
+ }
+
+ public void setSubscriptionName(String subscriptionName) {
+ this.subscriptionName = subscriptionName;
+ }
+
+ public AaiRequest getMetadata() {
+ return metadata;
+ }
+
+ public void setMetadata(AaiRequest metadata) {
+ this.metadata = metadata;
+ }
+
+ @Override
+ public String toString() {
+ return "NotificationRequest{" +
+ "instanceId='" + instanceId + '\'' +
+ ", subscriptionName='" + subscriptionName + '\'' +
+ ", metadata=" + metadata +
+ '}';
+ }
+}
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/synchronization/SubscriptionRequest.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/synchronization/SubscriptionRequest.java
new file mode 100644
index 0000000..238eef5
--- /dev/null
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/synchronization/SubscriptionRequest.java
@@ -0,0 +1,85 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
+ * Modifications Copyright (C) 2021 Samsung Technologies Co.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.adapters.cnf.model.synchronization;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.onap.so.adapters.cnf.model.aai.AaiRequest;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonIgnoreProperties(value = "true")
+public class SubscriptionRequest {
+
+ @JsonProperty(value = "name")
+ private String name;
+
+ @JsonProperty(value = "callback-url")
+ private String callbackUrl;
+
+ @JsonProperty(value = "min-notify-interval")
+ private int minNotifyInterval;
+
+ @JsonProperty(value = "metadata")
+ private AaiRequest metadata;
+
+ public String getCallbackUrl() {
+ return callbackUrl;
+ }
+
+ public void setCallbackUrl(String callbackUrl) {
+ this.callbackUrl = callbackUrl;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getMinNotifyInterval() {
+ return minNotifyInterval;
+ }
+
+ public void setMinNotifyInterval(int minNotifyInterval) {
+ this.minNotifyInterval = minNotifyInterval;
+ }
+
+ public AaiRequest getMetadata() {
+ return metadata;
+ }
+
+ public void setMetadata(AaiRequest metadata) {
+ this.metadata = metadata;
+ }
+
+ @Override
+ public String toString() {
+ return "SubscriptionRequest{" +
+ "callbackUrl='" + callbackUrl + '\'' +
+ ", name='" + name + '\'' +
+ ", minNotifyInterval=" + minNotifyInterval +
+ ", metadata='" + metadata + '\'' +
+ '}';
+ }
+}
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/synchronization/SubscriptionResponse.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/synchronization/SubscriptionResponse.java
new file mode 100644
index 0000000..5f05126
--- /dev/null
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/synchronization/SubscriptionResponse.java
@@ -0,0 +1,118 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
+ * Modifications Copyright (C) 2021 Samsung Technologies Co.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.adapters.cnf.model.synchronization;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.Date;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class SubscriptionResponse {
+
+ @JsonProperty("callback-url")
+ private String callbackUrl;
+ @JsonProperty("name")
+ private String name;
+ @JsonProperty("last-update-time")
+ private Date lastUpdateTime;
+ @JsonProperty("last-notify-time")
+ private Date lastNotifyTime;
+ @JsonProperty("last-notify-status")
+ private int lastNotifyStatus;
+ @JsonProperty("min-notify-interval")
+ private int minNotifyInterval;
+ @JsonProperty("metadata ")
+ private String metadata;
+
+ public SubscriptionResponse() { }
+
+ public String getCallbackUrl() {
+ return callbackUrl;
+ }
+
+ public void setCallbackUrl(String callbackUrl) {
+ this.callbackUrl = callbackUrl;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Date getLastUpdateTime() {
+ return lastUpdateTime;
+ }
+
+ public void setLastUpdateTime(Date lastUpdateTime) {
+ this.lastUpdateTime = lastUpdateTime;
+ }
+
+ public Date getLastNotifyTime() {
+ return lastNotifyTime;
+ }
+
+ public void setLastNotifyTime(Date lastNotifyTime) {
+ this.lastNotifyTime = lastNotifyTime;
+ }
+
+ public int getLastNotifyStatus() {
+ return lastNotifyStatus;
+ }
+
+ public void setLastNotifyStatus(int lastNotifyStatus) {
+ this.lastNotifyStatus = lastNotifyStatus;
+ }
+
+ public int getMinNotifyInterval() {
+ return minNotifyInterval;
+ }
+
+ public void setMinNotifyInterval(int minNotifyInterval) {
+ this.minNotifyInterval = minNotifyInterval;
+ }
+
+ public String getMetadata() {
+ return metadata;
+ }
+
+ public void setMetadata(String metadata) {
+ this.metadata = metadata;
+ }
+
+ @Override
+ public String toString() {
+ return "SubscriptionResponse{" +
+ "callbackUrl='" + callbackUrl + '\'' +
+ ", name='" + name + '\'' +
+ ", lastUpdateTime=" + lastUpdateTime +
+ ", lastNotifyTime=" + lastNotifyTime +
+ ", lastNotifyStatus=" + lastNotifyStatus +
+ ", minNotifyInterval=" + minNotifyInterval +
+ ", metadata='" + metadata + '\'' +
+ '}';
+ }
+}
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/upgrade/InstanceUpgradeRequest.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/upgrade/InstanceUpgradeRequest.java
new file mode 100644
index 0000000..a4a9ebf
--- /dev/null
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/model/upgrade/InstanceUpgradeRequest.java
@@ -0,0 +1,158 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
+ * Modifications Copyright (C) 2021 Samsung Technologies Co.
+ * Modifications Copyright (C) 2021 Orange.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.adapters.cnf.model.upgrade;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.Map;
+import java.util.Objects;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonIgnoreProperties(value = "true")
+public class InstanceUpgradeRequest {
+
+ @JsonProperty("modelInvariantId")
+ private String modelInvariantId;
+
+ @JsonProperty("modelCustomizationId")
+ private String modelCustomizationId;
+
+ @JsonProperty("k8sRBProfileName")
+ private String k8sRBProfileName;
+
+ @JsonProperty("k8sRBInstanceStatusCheck")
+ private boolean k8sRBInstanceStatusCheck;
+
+ @JsonProperty("cloudRegionId")
+ private String cloudRegionId;
+
+ @JsonProperty("vfModuleUUID")
+ private String vfModuleUUID;
+
+ @JsonProperty("labels")
+ private Map<String, String> labels;
+
+ @JsonProperty("override-values")
+ private Map<String, String> overrideValues;
+
+
+ public String getModelInvariantId() {
+ return modelInvariantId;
+ }
+
+ public void setModelInvariantId(String modelInvariantId) {
+ this.modelInvariantId = modelInvariantId;
+ }
+
+ public String getModelCustomizationId() {
+ return modelCustomizationId;
+ }
+
+ public void setModelCustomizationId(String modelCustomizationId) {
+ this.modelCustomizationId = modelCustomizationId;
+ }
+
+ public String getK8sRBProfileName() {
+ return k8sRBProfileName;
+ }
+
+ public void setK8sRBProfileName(String k8sRBProfileName) {
+ this.k8sRBProfileName = k8sRBProfileName;
+ }
+
+ public boolean isK8sRBInstanceStatusCheck() {
+ return k8sRBInstanceStatusCheck;
+ }
+
+ public void setK8sRBInstanceStatusCheck(boolean k8sRBInstanceStatusCheck) {
+ this.k8sRBInstanceStatusCheck = k8sRBInstanceStatusCheck;
+ }
+
+ public String getCloudRegionId() {
+ return cloudRegionId;
+ }
+
+ public void setCloudRegionId(String cloudRegionId) {
+ this.cloudRegionId = cloudRegionId;
+ }
+
+ public String getVfModuleUUID() {
+ return vfModuleUUID;
+ }
+
+ public void setVfModuleUUID(String vfModuleUUID) {
+ this.vfModuleUUID = vfModuleUUID;
+ }
+
+ public Map<String, String> getLabels() {
+ return labels;
+ }
+
+ public void setLabels(Map<String, String> labels) {
+ this.labels = labels;
+ }
+
+ public Map<String, String> getOverrideValues() {
+ return overrideValues;
+ }
+
+ public void setOverrideValues(Map<String, String> overrideValues) {
+ this.overrideValues = overrideValues;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ InstanceUpgradeRequest that = (InstanceUpgradeRequest) o;
+ return k8sRBInstanceStatusCheck == that.k8sRBInstanceStatusCheck &&
+ Objects.equals(modelInvariantId, that.modelInvariantId) &&
+ Objects.equals(modelCustomizationId, that.modelCustomizationId) &&
+ Objects.equals(k8sRBProfileName, that.k8sRBProfileName) &&
+ Objects.equals(cloudRegionId, that.cloudRegionId) &&
+ Objects.equals(vfModuleUUID, that.vfModuleUUID) &&
+ Objects.equals(labels, that.labels) &&
+ Objects.equals(overrideValues, that.overrideValues);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(modelInvariantId, modelCustomizationId, k8sRBProfileName, k8sRBInstanceStatusCheck, cloudRegionId, vfModuleUUID, labels, overrideValues);
+ }
+
+ @Override
+ public String toString() {
+ return "InstanceUpgradeRequest{" +
+ "modelInvariantId='" + modelInvariantId + '\'' +
+ ", modelCustomizationId='" + modelCustomizationId + '\'' +
+ ", k8sRBProfileName='" + k8sRBProfileName + '\'' +
+ ", k8sRBInstanceStatusCheck=" + k8sRBInstanceStatusCheck +
+ ", cloudRegionId='" + cloudRegionId + '\'' +
+ ", vfModuleUUID='" + vfModuleUUID + '\'' +
+ ", labels=" + labels +
+ ", overrideValues=" + overrideValues +
+ '}';
+ }
+
+}
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 63d9880..df674f8 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
@@ -3,6 +3,8 @@
* ONAP - SO
* ================================================================================
* Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
+ * Modifications Copyright (C) 2021 Samsung Technologies Co.
+ * Modifications Copyright (C) 2021 Orange.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,7 +19,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.onap.so.adapters.cnf.rest;
import com.fasterxml.jackson.core.JsonParseException;
@@ -51,16 +52,19 @@ 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.AaiRequest;
+import org.onap.so.adapters.cnf.model.aai.AaiRequest;
import org.onap.so.adapters.cnf.model.statuscheck.StatusCheckResponse;
+import org.onap.so.adapters.cnf.model.upgrade.InstanceUpgradeRequest;
import org.onap.so.adapters.cnf.service.CnfAdapterService;
import org.onap.so.adapters.cnf.service.aai.AaiService;
+import org.onap.so.adapters.cnf.service.healthcheck.HealthCheckService;
import org.onap.so.adapters.cnf.service.statuscheck.SimpleStatusCheckService;
+import org.onap.so.adapters.cnf.service.synchrornization.SynchronizationService;
+import org.onap.so.adapters.cnf.service.upgrade.InstanceUpgradeService;
import org.onap.so.client.exception.BadResponseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
@@ -74,7 +78,6 @@ import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
-import java.util.concurrent.ForkJoinPool;
@RestController
public class CnfAdapterRest {
@@ -82,25 +85,44 @@ public class CnfAdapterRest {
private static final Logger logger = LoggerFactory.getLogger(CnfAdapterRest.class);
private final CloseableHttpClient httpClient = HttpClients.createDefault();
private final SimpleStatusCheckService simpleStatusCheckService;
+ private final HealthCheckService healthCheckService;
+ private final InstanceUpgradeService instanceUpgradeService;
private final CnfAdapterService cnfAdapterService;
private final SoCallbackClient callbackClient;
private final AaiService aaiService;
+ private final SynchronizationService synchronizationService;
private final String uri;
@Autowired
public CnfAdapterRest(SimpleStatusCheckService simpleStatusCheckService,
+ HealthCheckService healthCheckService,
+ InstanceUpgradeService instanceUpgradeService,
CnfAdapterService cnfAdapterService,
SoCallbackClient callbackClient,
AaiService aaiService,
+ SynchronizationService synchronizationService,
MulticloudConfiguration multicloudConfiguration) {
this.simpleStatusCheckService = simpleStatusCheckService;
+ this.healthCheckService = healthCheckService;
+ this.instanceUpgradeService = instanceUpgradeService;
this.cnfAdapterService = cnfAdapterService;
this.aaiService = aaiService;
this.callbackClient = callbackClient;
+ this.synchronizationService = synchronizationService;
this.uri = multicloudConfiguration.getMulticloudUrl();
}
@ResponseBody
+ @RequestMapping(value = {"/api/cnf-adapter/v1/instance/{instanceID}/upgrade"}, method = RequestMethod.POST,
+ produces = "application/json", consumes = "application/json")
+ public String upgrade(@PathVariable("instanceID") String instanceId,
+ @RequestBody InstanceUpgradeRequest upgradeRequest) throws BadResponseException {
+ logger.info("upgrade called for instance {}.", instanceId);
+ return instanceUpgradeService.upgradeInstance(instanceId, upgradeRequest);
+ }
+
+
+ @ResponseBody
@RequestMapping(value = {"/api/cnf-adapter/v1/healthcheck"}, method = RequestMethod.POST,
produces = "application/json")
public DeferredResult<ResponseEntity> healthCheck(@RequestBody CheckInstanceRequest healthCheckRequest) {
@@ -108,15 +130,14 @@ public class CnfAdapterRest {
DeferredResult<ResponseEntity> response = new DeferredResult<>();
new Thread(() -> {
- logger.info("Processing healthCheck service");
+ logger.info("Processing health check request");
+
HealthCheckResponse healthCheckResponse = null;
try {
- healthCheckResponse = cnfAdapterService.healthCheck(healthCheckRequest);
+ healthCheckResponse = healthCheckService.healthCheck(healthCheckRequest);
} catch (Exception e) {
- HealthCheckResponse errorHealthCheck = new HealthCheckResponse();
- errorHealthCheck.setErrorMessage(e.getMessage());
- callbackClient.sendPostCallback(healthCheckRequest.getCallbackUrl(), errorHealthCheck);
- return;
+ logger.error("END - Health check process failed", e);
+ healthCheckResponse = healthCheckService.healthCheckError(healthCheckRequest, e);
}
callbackClient.sendPostCallback(healthCheckRequest.getCallbackUrl(), healthCheckResponse);
}).start();
@@ -134,15 +155,17 @@ public class CnfAdapterRest {
new Thread(() -> {
logger.info("Processing aai update");
-// aaiService.aaiUpdate(aaiRequest);
- AaiCallbackResponse mockCallbackResponse = new AaiCallbackResponse();
- mockCallbackResponse.setCompletionStatus(AaiCallbackResponse.CompletionStatus.COMPLETED);
+ AaiCallbackResponse callbackResponse = new AaiCallbackResponse();
try {
- Thread.sleep(10_000L);
- } catch (InterruptedException e) {
- logger.error("InterruptedException occurred when aai-update");
+ aaiService.aaiUpdate(aaiRequest);
+ synchronizationService.createSubscriptionIfNotExists(aaiRequest);
+ callbackResponse.setCompletionStatus(AaiCallbackResponse.CompletionStatus.COMPLETED);
+ } catch (Exception e) {
+ logger.warn("Failed to create resource in AAI", e);
+ callbackResponse.setCompletionStatus(AaiCallbackResponse.CompletionStatus.FAILED);
+ callbackResponse.setMessage(e.getMessage());
}
- callbackClient.sendPostCallback(aaiRequest.getCallbackUrl(), mockCallbackResponse);
+ callbackClient.sendPostCallback(aaiRequest.getCallbackUrl(), callbackResponse);
}).start();
response.setResult(ResponseEntity.accepted().build());
@@ -158,15 +181,17 @@ public class CnfAdapterRest {
new Thread(() -> {
logger.info("Processing aai delete");
-// aaiService.aaiDelete(aaiRequest);
- AaiCallbackResponse mockCallbackResponse = new AaiCallbackResponse();
- mockCallbackResponse.setCompletionStatus(AaiCallbackResponse.CompletionStatus.COMPLETED);
+ AaiCallbackResponse callbackResponse = new AaiCallbackResponse();
try {
- Thread.sleep(10_000L);
- } catch (InterruptedException e) {
- logger.error("InterruptedException occurred when aai-delete");
+ synchronizationService.deleteSubscriptionIfExists(aaiRequest);
+ aaiService.aaiDelete(aaiRequest);
+ callbackResponse.setCompletionStatus(AaiCallbackResponse.CompletionStatus.COMPLETED);
+ } catch (Exception e) {
+ logger.warn("Failed to delete resource from AAI", e);
+ callbackResponse.setCompletionStatus(AaiCallbackResponse.CompletionStatus.FAILED);
+ callbackResponse.setMessage(e.getMessage());
}
- callbackClient.sendPostCallback(aaiRequest.getCallbackUrl(), mockCallbackResponse);
+ callbackClient.sendPostCallback(aaiRequest.getCallbackUrl(), callbackResponse);
}).start();
response.setResult(ResponseEntity.accepted().build());
@@ -181,15 +206,13 @@ public class CnfAdapterRest {
DeferredResult<ResponseEntity> response = new DeferredResult<>();
new Thread(() -> {
- logger.info("Processing healthCheck service");
+ logger.info("Processing status check request");
StatusCheckResponse statusCheckResponse = null;
try {
statusCheckResponse = simpleStatusCheckService.statusCheck(statusCheckRequest);
- } catch (BadResponseException e) {
- StatusCheckResponse errorStatusCheck = new StatusCheckResponse();
- errorStatusCheck.setErrorMessage(e.getMessage());
- callbackClient.sendPostCallback(statusCheckRequest.getCallbackUrl(), e);
- return;
+ } catch (Exception e) {
+ logger.error("END - Status check process failed", e);
+ statusCheckResponse = simpleStatusCheckService.statusCheckError(statusCheckRequest, e);
}
callbackClient.sendPostCallback(statusCheckRequest.getCallbackUrl(), statusCheckResponse);
}).start();
@@ -201,9 +224,7 @@ public class CnfAdapterRest {
@ResponseBody
@RequestMapping(value = {"/api/cnf-adapter/v1/instance"}, method = RequestMethod.POST,
produces = "application/json", consumes = "application/json")
- public String createInstance(@RequestBody BpmnInstanceRequest bpmnInstanceRequest)
- throws JsonParseException, JsonMappingException, IOException {
-
+ public String createInstance(@RequestBody BpmnInstanceRequest bpmnInstanceRequest) throws BadResponseException {
logger.info("createInstance called.");
return cnfAdapterService.createInstance(bpmnInstanceRequest);
}
@@ -277,10 +298,14 @@ public class CnfAdapterRest {
@ResponseBody
@RequestMapping(value = {"/api/cnf-adapter/v1/instance/{instID}"}, method = RequestMethod.DELETE,
produces = "application/json")
- public String deleteInstanceByInstanceId(@PathVariable("instID") String instanceID)
- throws JsonParseException, JsonMappingException, IOException {
+ public String deleteInstanceByInstanceId(@PathVariable("instID") String instanceID) throws BadResponseException {
logger.info("deleteInstanceByInstanceId called.");
+ if (instanceID == null || instanceID.isEmpty() || instanceID.equals("null")) {
+ //we skip deletion of instance that was not created properly and instance id was not stored in AAI
+ logger.warn("Undefined instance ID delete attempt. Skipping delete");
+ return "";
+ }
return cnfAdapterService.deleteInstanceByInstanceId(instanceID);
}
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/rest/SubscriptionNotifyController.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/rest/SubscriptionNotifyController.java
new file mode 100644
index 0000000..88df42b
--- /dev/null
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/rest/SubscriptionNotifyController.java
@@ -0,0 +1,81 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
+ * Modifications Copyright (C) 2021 Samsung Technologies Co.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.adapters.cnf.rest;
+
+
+import com.google.gson.Gson;
+import org.onap.so.adapters.cnf.model.aai.AaiRequest;
+import org.onap.so.adapters.cnf.model.synchronization.NotificationRequest;
+import org.onap.so.adapters.cnf.service.aai.AaiService;
+import org.onap.so.adapters.cnf.service.synchrornization.SynchronizationService;
+import org.onap.so.client.exception.BadResponseException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.Map;
+
+@RestController
+public class SubscriptionNotifyController {
+
+ private static final Logger logger = LoggerFactory.getLogger(SubscriptionNotifyController.class);
+ private final static Gson gson = new Gson();
+
+ private final AaiService aaiService;
+ private final SynchronizationService synchronizationService;
+
+ public SubscriptionNotifyController(AaiService aaiService, SynchronizationService synchronizationService) {
+ this.aaiService = aaiService;
+ this.synchronizationService = synchronizationService;
+ }
+
+ @PostMapping(value = "/api/cnf-adapter/v1/instance/{instanceId}/status/notify")
+ public ResponseEntity subscriptionNotifyEndpoint(@PathVariable String instanceId,
+ @RequestBody NotificationRequest body) throws BadResponseException {
+ String subscriptionName = synchronizationService.getSubscriptionName(instanceId);
+ boolean isSubscriptionActive = synchronizationService.isSubscriptionActive(subscriptionName);
+ if (isSubscriptionActive) {
+ logger.info("AAI update- START");
+ aaiService.aaiUpdate(body.getMetadata());
+ return ResponseEntity
+ .accepted()
+ .build();
+ } else {
+ return ResponseEntity
+ .badRequest()
+ .body(String.format("Cannot handle notification. Subscription %s not exists", subscriptionName));
+ }
+ }
+
+ private AaiRequest convertMetadataToAaiRequest(Map<String, Object> metadata) {
+ String json = gson.toJsonTree(metadata)
+ .getAsJsonObject()
+ .get("metadata")
+ .toString();
+
+ return gson.fromJson(json, AaiRequest.class);
+ }
+
+}
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/CnfAdapterService.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/CnfAdapterService.java
index 12aa4ad..6d84911 100644
--- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/CnfAdapterService.java
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/CnfAdapterService.java
@@ -3,6 +3,8 @@
* ONAP - SO
* ================================================================================
* Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
+ * Modifications Copyright (C) 2021 Samsung Technologies Co.
+ * Modifications Copyright (C) 2021 Orange.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,14 +24,15 @@ package org.onap.so.adapters.cnf.service;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
+import com.google.gson.Gson;
import org.apache.http.HttpStatus;
+import org.json.JSONObject;
import org.onap.so.adapters.cnf.MulticloudConfiguration;
import org.onap.so.adapters.cnf.model.BpmnInstanceRequest;
-import org.onap.so.adapters.cnf.model.CheckInstanceRequest;
import org.onap.so.adapters.cnf.model.MulticloudInstanceRequest;
-import org.onap.so.adapters.cnf.model.healthcheck.HealthCheckResponse;
-import org.onap.so.adapters.cnf.service.healthcheck.HealthCheckService;
-import org.onap.so.adapters.cnf.service.statuscheck.SimpleStatusCheckService;
+import org.onap.so.adapters.cnf.model.aai.AaiRequest;
+import org.onap.so.adapters.cnf.service.synchrornization.SynchronizationService;
+import org.onap.so.client.exception.BadResponseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -55,28 +58,16 @@ public class CnfAdapterService {
private static final String INSTANCE_CREATE_PATH = "/v1/instance";
private final RestTemplate restTemplate;
- private final HealthCheckService healthCheckService;
- private final SimpleStatusCheckService simpleStatusCheckService;
private final String uri;
@Autowired
public CnfAdapterService(RestTemplate restTemplate,
- HealthCheckService healthCheckService,
- SimpleStatusCheckService simpleStatusCheckService,
MulticloudConfiguration multicloudConfiguration) {
this.restTemplate = restTemplate;
- this.healthCheckService = healthCheckService;
- this.simpleStatusCheckService = simpleStatusCheckService;
this.uri = multicloudConfiguration.getMulticloudUrl();
}
- public HealthCheckResponse healthCheck(CheckInstanceRequest healthCheckRequest) throws Exception {
- logger.info("CnfAdapterService healthCheck called");
- return healthCheckService.healthCheck(healthCheckRequest);
- }
-
- public String createInstance(BpmnInstanceRequest bpmnInstanceRequest)
- throws JsonParseException, JsonMappingException, IOException {
+ public String createInstance(BpmnInstanceRequest bpmnInstanceRequest) {
try {
logger.info("CnfAdapterService createInstance called");
MulticloudInstanceRequest multicloudInstanceRequest = new MulticloudInstanceRequest();
@@ -271,8 +262,7 @@ public class CnfAdapterService {
}
}
- public String deleteInstanceByInstanceId(String instanceId)
- throws JsonParseException, JsonMappingException, IOException {
+ public String deleteInstanceByInstanceId(String instanceId) {
logger.info("CnfAdapterService deleteInstanceByInstanceId called");
ResponseEntity<String> result = null;
@@ -287,6 +277,7 @@ public class CnfAdapterService {
logger.info("request: " + requestEntity);
result = restTemplate.exchange(endpoint, HttpMethod.DELETE, requestEntity, String.class);
logger.info("response: " + result);
+
return result.getBody();
} catch (HttpClientErrorException e) {
logger.error("Error Calling Multicloud, e");
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 2e79b35..d7ee2d1 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,9 +1,31 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2021 Samsung Electronics Co. Ltd. All rights reserved.
+ * Modifications Copyright (C) 2021 Orange.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
package org.onap.so.adapters.cnf.service.aai;
import com.google.common.hash.Hashing;
-import org.onap.so.adapters.cnf.model.instantiation.AaiRequest;
+import org.onap.so.adapters.cnf.model.aai.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.K8sStatusMetadata;
import org.springframework.stereotype.Service;
import java.nio.charset.StandardCharsets;
@@ -13,9 +35,11 @@ class AaiIdGeneratorService {
String generateId(K8sRbInstanceResourceStatus resourceStatus, AaiRequest aaiRequest) {
K8sRbInstanceGvk gvk = resourceStatus.getGvk();
- String originalString = resourceStatus.getName() + gvk.getKind() + gvk.getGroup() + gvk.getVersion() +
- aaiRequest.getInstanceId() + aaiRequest.getCloudOwner() +
- aaiRequest.getCloudRegion() + aaiRequest.getTenantId();
+ K8sStatusMetadata metadata = resourceStatus.getStatus().getK8sStatusMetadata();
+ String originalString = aaiRequest.getInstanceId() + resourceStatus.getName() +
+ (metadata.getNamespace() != null ? metadata.getNamespace() : "") +
+ gvk.getKind() + gvk.getGroup() + gvk.getVersion() +
+ 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/AaiRequestSender.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiRequestSender.java
deleted file mode 100644
index 8dd7647..0000000
--- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiRequestSender.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package org.onap.so.adapters.cnf.service.aai;
-
-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.model.instantiation.AaiRequest;
-import org.springframework.stereotype.Component;
-
-@Component
-class AaiRequestSender {
-
- private final static Gson gson = new Gson();
- private AAIResourcesClient aaiClient;
-
- void sendUpdateRequestToAai(ParseResult parseResult, AaiRequest aaiRequest) {
- AAIResourceUri aaiUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure()
- .cloudRegion(aaiRequest.getCloudOwner(), aaiRequest.getCloudRegion())
- .tenant(aaiRequest.getTenantId())
- .build());
- String payload = gson.toJson(parseResult);
- getAaiClient().create(aaiUri, payload);
- }
-
- void sendDeleteRequestToAai(AaiRequest aaiRequest) {
- AAIResourceUri aaiUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure()
- .cloudRegion(aaiRequest.getCloudOwner(), aaiRequest.getCloudRegion())
- .tenant(aaiRequest.getTenantId())
- .build());
- getAaiClient().delete(aaiUri);
- }
-
- private AAIResourcesClient getAaiClient() {
- if (aaiClient == null) {
- aaiClient = new AAIResourcesClient();
- }
- return aaiClient;
- }
-}
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiResponseParser.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiResponseParser.java
index 304c023..0b300c4 100644
--- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiResponseParser.java
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiResponseParser.java
@@ -1,26 +1,53 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2021 Samsung Electronics Co. Ltd. All rights reserved.
+ * Modifications Copyright (C) 2021 Orange.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+
package org.onap.so.adapters.cnf.service.aai;
-import org.onap.so.adapters.cnf.model.instantiation.AaiRequest;
+import org.apache.http.client.utils.URIBuilder;
+import org.onap.so.adapters.cnf.model.aai.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.K8sStatus;
import org.onap.so.adapters.cnf.model.statuscheck.K8sStatusMetadata;
import org.springframework.stereotype.Component;
+import java.net.URISyntaxException;
import java.util.ArrayList;
-import java.util.Collection;
+import java.util.List;
+import java.util.Map;
@Component
public class AaiResponseParser {
+ private final static String INSTANCE_ID = "k8splugin.io/rb-instance-id";
+
private final AaiIdGeneratorService aaiIdGeneratorService;
public AaiResponseParser(AaiIdGeneratorService aaiIdGeneratorService) {
this.aaiIdGeneratorService = aaiIdGeneratorService;
}
- ParseResult parse(K8sRbInstanceResourceStatus status, AaiRequest aaiRequest) {
- ParseResult result = new ParseResult();
+ KubernetesResource parse(K8sRbInstanceResourceStatus status, AaiRequest aaiRequest) {
+ KubernetesResource result = new KubernetesResource();
K8sRbInstanceGvk gvk = status.getGvk();
K8sStatus k8sStatus = status.getStatus();
K8sStatusMetadata metadata = k8sStatus.getK8sStatusMetadata();
@@ -30,15 +57,49 @@ public class AaiResponseParser {
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.setDataOwner("CnfAdapter");
+ result.setDataSource("K8sPlugin");
+ result.setDataSourceVersion(metadata.getResourceVersion());
+ if (metadata.getNamespace() != null)
+ result.setNamespace(metadata.getNamespace());
+ else
+ result.setNamespace("");
+ List<String> labels = parseLabels(metadata.getLabels());
result.setLabels(labels);
- result.setK8sResourceSelfLink(String.format("http://so-cnf-adapter:8090/api/cnf-adapter/v1/instance/%s/query", aaiRequest.getInstanceId()));
+ URIBuilder uriBuilder = new URIBuilder();
+ String selfLink;
+ try {
+ selfLink = uriBuilder
+ .setScheme("http")
+ .setHost("so-cnf-adapter")
+ .setPort(8090)
+ .setPath("/api/cnf-adapter/v1/instance/" + aaiRequest.getInstanceId() + "/query")
+ .setParameter("ApiVersion", gvk.getVersion())
+ .setParameter("Kind", gvk.getKind())
+ .setParameter("Name", status.getName())
+ .setParameter("Namespace", result.getNamespace())
+ .build()
+ .toString();
+ } catch (URISyntaxException e) {
+ throw new RuntimeException(e);
+ }
+ result.setSelflink(selfLink);
return result;
}
+ private List<String> parseLabels(Map<String, String> labels) {
+ List<String> result = new ArrayList<>();
+ labels.entrySet().stream()
+ .filter(i -> i.getKey().equals(INSTANCE_ID))
+ .findFirst()
+ .ifPresent(i -> addLabelEntry(i, result));
+ labels.entrySet().stream()
+ .filter(i -> !i.getKey().equals(INSTANCE_ID))
+ .forEach(i -> addLabelEntry(i, result));
+ return result;
+ }
+
+ private void addLabelEntry(Map.Entry<String, String> label, List<String> labels) {
+ labels.add(label.getKey() + "=" + label.getValue());
+ }
}
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 71d34a3..ff454b8 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,10 +1,32 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2021 Samsung Electronics Co. Ltd. All rights reserved.
+ * Modifications Copyright (C) 2021 Orange.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
package org.onap.so.adapters.cnf.service.aai;
import org.onap.so.adapters.cnf.AaiConfiguration;
import org.onap.so.adapters.cnf.client.MulticloudClient;
-import org.onap.so.adapters.cnf.model.instantiation.AaiRequest;
+import org.onap.so.adapters.cnf.model.aai.AaiRequest;
import org.onap.so.adapters.cnf.model.statuscheck.K8sRbInstanceResourceStatus;
import org.onap.so.adapters.cnf.model.statuscheck.K8sRbInstanceStatus;
+import org.onap.so.adapters.cnf.util.IAaiRepository;
import org.onap.so.client.exception.BadResponseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -19,39 +41,37 @@ public class AaiService {
private final static Logger log = LoggerFactory.getLogger(AaiService.class);
private final MulticloudClient multicloudClient;
- private final AaiRequestSender aaiRequestSender;
private final AaiResponseParser responseParser;
- private final AaiConfiguration aaiConfiguration;
+ private final AaiConfiguration configuration;
- public AaiService(MulticloudClient multicloudClient,
- AaiRequestSender aaiRequestSender,
- AaiResponseParser responseParser,
- AaiConfiguration aaiConfiguration) {
+ public AaiService(MulticloudClient multicloudClient, AaiResponseParser responseParser, AaiConfiguration configuration) {
this.multicloudClient = multicloudClient;
- this.aaiRequestSender = aaiRequestSender;
this.responseParser = responseParser;
- this.aaiConfiguration = aaiConfiguration;
+ this.configuration = configuration;
}
public void aaiUpdate(AaiRequest aaiRequest) throws BadResponseException {
- if (aaiConfiguration.isEnabled()) {
- List<ParseResult> parseStatus = parseStatus(aaiRequest);
- parseStatus.forEach(status -> aaiRequestSender.sendUpdateRequestToAai(status, aaiRequest));
- } else {
- log.info("aai.enabled=false, do not execute aaiUpdate flow");
- }
+ List<KubernetesResource> k8sResList = parseStatus(aaiRequest);
+ IAaiRepository aaiRepository = IAaiRepository.instance(configuration.isEnabled());
+ k8sResList.forEach(status -> aaiRepository.update(status, aaiRequest));
+ aaiRepository.delete(aaiRequest, k8sResList);
+ aaiRepository.commit(false);
}
public void aaiDelete(AaiRequest aaiRequest) throws BadResponseException {
- if (aaiConfiguration.isEnabled()) {
- List<ParseResult> parseStatus = parseStatus(aaiRequest);
- parseStatus.forEach(status -> aaiRequestSender.sendDeleteRequestToAai(aaiRequest));
- } else {
- log.info("aai.enabled=false, do not execute aaiDelete flow");
+ String instanceID = aaiRequest.getInstanceId();
+ boolean enabled = configuration.isEnabled();
+ if (instanceID == null || instanceID.isEmpty() || instanceID.equals("null")) {
+ //we skip deletion of resources instance that was not created properly and instance id was not stored in AAI
+ log.warn("Undefined instance ID aai-delete attempt. Skipping aai-delete");
+ enabled = false;
}
+ IAaiRepository aaiRepository = IAaiRepository.instance(enabled);
+ aaiRepository.delete(aaiRequest, List.of());
+ aaiRepository.commit(false);
}
- private List<ParseResult> parseStatus(AaiRequest aaiRequest) throws BadResponseException {
+ private List<KubernetesResource> parseStatus(AaiRequest aaiRequest) throws BadResponseException {
String instanceId = aaiRequest.getInstanceId();
K8sRbInstanceStatus instanceStatus = multicloudClient.getInstanceStatus(instanceId);
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/KubernetesResource.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/KubernetesResource.java
new file mode 100644
index 0000000..98296a3
--- /dev/null
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/KubernetesResource.java
@@ -0,0 +1,160 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2021 Samsung Electronics Co. Ltd. All rights reserved.
+ * Modifications Copyright (C) 2021 Orange.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.cnf.service.aai;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Objects;
+
+import java.util.Collections;
+import java.util.List;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class KubernetesResource {
+ private String id;
+ private String name;
+ private String group;
+ private String version;
+ private String kind;
+ private String namespace;
+ private List<String> labels;
+ private String selflink;
+ @JsonProperty("data-owner")
+ private String dataOwner;
+ @JsonProperty("data-source")
+ private String dataSource;
+ @JsonProperty("data-source-version")
+ private String dataSourceVersion;
+ @JsonProperty("resource-version")
+ private String resourceVersion;
+
+ 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 List<String> getLabels() {
+ return labels;
+ }
+
+ public void setLabels(List<String> labels) {
+ if (labels != null)
+ Collections.sort(labels);
+ this.labels = labels;
+ }
+
+ public String getSelflink() { return selflink; }
+
+ public void setSelflink(String selflink) { this.selflink = selflink; }
+
+ public String getDataOwner() {
+ return dataOwner;
+ }
+
+ public void setDataOwner(String dataOwner) {
+ this.dataOwner = dataOwner;
+ }
+
+ public String getDataSource() {
+ return dataSource;
+ }
+
+ public void setDataSource(String dataSource) {
+ this.dataSource = dataSource;
+ }
+
+ public String getDataSourceVersion() {
+ return dataSourceVersion;
+ }
+
+ public void setDataSourceVersion(String dataSourceVersion) {
+ this.dataSourceVersion = dataSourceVersion;
+ }
+
+ public String getResourceVersion() {
+ return resourceVersion;
+ }
+
+ public void setResourceVersion(String resourceVersion) {
+ this.resourceVersion = resourceVersion;
+ }
+
+ public boolean compare(KubernetesResource reference) {
+ boolean result = reference != null &&
+ Objects.equal(id, reference.id) &&
+ Objects.equal(name, reference.name) &&
+ Objects.equal(version, reference.version) &&
+ Objects.equal(kind, reference.kind) &&
+ Objects.equal(group, reference.group) &&
+ Objects.equal(namespace, reference.namespace) &&
+ Objects.equal(dataOwner, reference.dataOwner) &&
+ Objects.equal(dataSource, reference.dataSource) &&
+ Objects.equal(dataSourceVersion, reference.dataSourceVersion);
+ Objects.equal(labels, reference.labels);
+ return result;
+ }
+} \ No newline at end of file
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/ParseResult.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/ParseResult.java
deleted file mode 100644
index e44a885..0000000
--- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/ParseResult.java
+++ /dev/null
@@ -1,78 +0,0 @@
-package org.onap.so.adapters.cnf.service.aai;
-
-import java.util.Collection;
-
-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;
- }
-} \ No newline at end of file
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/healthcheck/HealthCheckService.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/healthcheck/HealthCheckService.java
index 2f91be8..024ff1c 100644
--- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/healthcheck/HealthCheckService.java
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/healthcheck/HealthCheckService.java
@@ -1,3 +1,24 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2021 Samsung Electronics Co. Ltd. All rights reserved.
+ * Modifications Copyright (C) 2021 Orange.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
package org.onap.so.adapters.cnf.service.healthcheck;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
@@ -47,6 +68,20 @@ public class HealthCheckService {
return statuses;
}
+ public HealthCheckResponse healthCheckError(CheckInstanceRequest healthCheckRequest, Exception e) {
+ HealthCheckResponse result = new HealthCheckResponse();
+
+ List<HealthCheckInstanceResponse> instanceHealthCheckList = new ArrayList<>();
+ for (InstanceRequest instanceRequest : healthCheckRequest.getInstances()) {
+ HealthCheckInstanceResponse healthCheck = new HealthCheckInstanceResponse(
+ instanceRequest.getInstanceId(), e.getMessage(), "Failed");
+ instanceHealthCheckList.add(healthCheck);
+ }
+
+ result.setInstanceResponse(instanceHealthCheckList);
+ return result;
+ }
+
private List<HealthCheckInstance> startInstanceHealthCheck(CheckInstanceRequest healthCheckRequest) throws Exception {
log.debug("startInstanceHealthCheck - START");
List<HealthCheckInstance> healthCheckInstanceList = new ArrayList<>();
@@ -80,8 +115,7 @@ public class HealthCheckService {
InstanceStatusTuple instanceStatusTuple = future.get();
String instanceId = instanceStatusTuple.getInstanceId();
String status = instanceStatusTuple.getStatus();
- String reason = null;
- return new HealthCheckInstanceResponse(instanceId, reason, status);
+ return new HealthCheckInstanceResponse(instanceId, null, status);
} catch (Exception e) {
throw new RuntimeException(e);
}
@@ -122,7 +156,9 @@ public class HealthCheckService {
}
sleep(10_000L);
}
- return new InstanceStatusTuple(healthCheckInstance.getInstanceId(), "Timeout");
+ //Timeout
+ instanceApi.deleteInstanceHealthCheck(healthCheckInstance.getInstanceId(), healthCheckInstance.getHealthCheckInstance());
+ return new InstanceStatusTuple(healthCheckInstance.getInstanceId(), "Unknown");
}
}
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/statuscheck/SimpleStatusCheckService.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/statuscheck/SimpleStatusCheckService.java
index 510d6b8..7e750a9 100644
--- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/statuscheck/SimpleStatusCheckService.java
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/statuscheck/SimpleStatusCheckService.java
@@ -1,3 +1,24 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2021 Samsung Electronics Co. Ltd. All rights reserved.
+ * Modifications Copyright (C) 2021 Orange.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
package org.onap.so.adapters.cnf.service.statuscheck;
import org.onap.so.adapters.cnf.client.MulticloudClient;
@@ -41,6 +62,20 @@ public class SimpleStatusCheckService {
return result;
}
+ public StatusCheckResponse statusCheckError(CheckInstanceRequest instanceIds, Exception e) {
+ StatusCheckResponse result = new StatusCheckResponse();
+
+ List<StatusCheckInstanceResponse> simpleStatuses = new ArrayList<>();
+ for (InstanceRequest instanceRequest : instanceIds.getInstances()) {
+ StatusCheckInstanceResponse statusCheck = new StatusCheckInstanceResponse(
+ instanceRequest.getInstanceId(), e.getMessage(), false);
+ simpleStatuses.add(statusCheck);
+ }
+
+ result.setInstanceResponse(simpleStatuses);
+ return result;
+ }
+
private StatusCheckInstanceResponse getStatusCheck(String instanceId) throws BadResponseException {
log.debug("SIMPLE STATUS CHECK - START");
K8sRbInstanceStatus instanceStatus = instanceApi.getInstanceStatus(instanceId);
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/synchrornization/SubscriptionsRecoveryProvider.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/synchrornization/SubscriptionsRecoveryProvider.java
new file mode 100644
index 0000000..68b49a8
--- /dev/null
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/synchrornization/SubscriptionsRecoveryProvider.java
@@ -0,0 +1,29 @@
+package org.onap.so.adapters.cnf.service.synchrornization;
+
+import org.onap.so.adapters.cnf.client.MulticloudClient;
+import org.onap.so.adapters.cnf.model.InstanceResponse;
+import org.onap.so.client.exception.BadResponseException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@Component
+public class SubscriptionsRecoveryProvider {
+
+ private final MulticloudClient multicloudClient;
+
+ public SubscriptionsRecoveryProvider(MulticloudClient multicloudClient) {
+ this.multicloudClient = multicloudClient;
+ }
+
+ public Set<String> getInstanceList() throws BadResponseException {
+ Set<String> instanceIds;
+ instanceIds = multicloudClient.getAllInstances().stream()
+ .map(InstanceResponse::getId)
+ .collect(Collectors.toSet());
+ return instanceIds;
+ }
+}
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/synchrornization/SynchronizationService.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/synchrornization/SynchronizationService.java
new file mode 100644
index 0000000..643977e
--- /dev/null
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/synchrornization/SynchronizationService.java
@@ -0,0 +1,151 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
+ * Modifications Copyright (C) 2021 Samsung Technologies Co.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.adapters.cnf.service.synchrornization;
+
+import org.apache.http.client.utils.URIBuilder;
+import org.onap.so.adapters.cnf.client.MulticloudClient;
+import org.onap.so.adapters.cnf.model.InstanceResponse;
+import org.onap.so.adapters.cnf.model.aai.AaiRequest;
+import org.onap.so.adapters.cnf.model.synchronization.SubscriptionRequest;
+import org.onap.so.client.exception.BadResponseException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.PostConstruct;
+import java.net.URISyntaxException;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@Service
+public class SynchronizationService {
+
+ private static final Logger logger = LoggerFactory.getLogger(SynchronizationService.class);
+
+ private static final String PROTOCOL = "http";
+ private static final String HOST = "so-cnf-adapter";
+ private static final int PORT = 8090;
+
+ private final Set<String> subscriptions = new HashSet<>();
+ private final MulticloudClient multicloudClient;
+ private final SubscriptionsRecoveryProvider recoveryProvider;
+
+ public SynchronizationService(MulticloudClient multicloudClient, SubscriptionsRecoveryProvider recoveryProvider) {
+ this.multicloudClient = multicloudClient;
+ this.recoveryProvider = recoveryProvider;
+ }
+
+ @PostConstruct
+ private void postConstruct() {
+ recoverSubscriptions();
+ }
+
+ private void recoverSubscriptions() {
+ if (subscriptions.isEmpty()) {
+ Set<String> instanceIds;
+ try {
+
+ instanceIds = recoveryProvider.getInstanceList();
+
+ instanceIds.forEach(this::addSubscriptionIfSubscriptionFound);
+ } catch (BadResponseException e) {
+ logger.error("Instances not found", e);
+ }
+ }
+ }
+
+ private void addSubscriptionIfSubscriptionFound(String instanceId) {
+ String subscriptionName = getSubscriptionName(instanceId);
+ try {
+ if (multicloudClient.hasSubscription(instanceId, subscriptionName))
+ subscriptions.add(subscriptionName);
+ } catch (BadResponseException e) {
+ logger.warn("Subscriptions not found instanceId={} subscriptionName={}", instanceId, subscriptionName);
+ }
+ }
+
+ public void createSubscriptionIfNotExists(AaiRequest aaiRequest) throws BadResponseException {
+ logger.debug("createSubscriptionIfNotExists- START");
+ String instanceId = aaiRequest.getInstanceId();
+ String subscriptionName = getSubscriptionName(instanceId);
+ String callbackUrl = generateCallbackUrl(instanceId);
+
+ if (isSubscriptionActive(subscriptionName)) {
+ logger.info("Subscription: {} already exits", subscriptionName);
+ } else {
+ multicloudClient.registerSubscription(instanceId, getSubscriptionRequest(subscriptionName, callbackUrl, aaiRequest));
+ subscriptions.add(subscriptionName);
+ logger.info("Subscription: {} registered", subscriptionName);
+ }
+ logger.debug("createSubscriptionIfNotExists- END");
+ }
+
+ public void deleteSubscriptionIfExists(AaiRequest aaiRequest) throws BadResponseException {
+ logger.debug("deleteSubscriptionIfExists - START");
+ String instanceId = aaiRequest.getInstanceId();
+ String subscriptionName = getSubscriptionName(instanceId);
+
+ if (isSubscriptionActive(subscriptionName)) {
+ multicloudClient.deleteSubscription(instanceId, subscriptionName);
+ subscriptions.remove(subscriptionName);
+ logger.info("Subscription: {} removed", subscriptionName);
+ } else {
+ logger.info("Subscription: {} already removed or was not present", subscriptionName);
+ }
+ logger.debug("deleteSubscriptionIfExists - END");
+ }
+
+ public boolean isSubscriptionActive(String subscriptionName) {
+ return subscriptions.contains(subscriptionName);
+ }
+
+ public String getSubscriptionName(String instanceId) {
+ return instanceId + "-cnf-adapter";
+ }
+
+ private SubscriptionRequest getSubscriptionRequest(String name, String endpoint, AaiRequest aaiRequest) {
+ SubscriptionRequest subscriptionRequest = new SubscriptionRequest();
+
+ subscriptionRequest.setName(name);
+ subscriptionRequest.setCallbackUrl(endpoint);
+ subscriptionRequest.setMinNotifyInterval(30);
+
+ return subscriptionRequest;
+ }
+
+ private String generateCallbackUrl(String instanceId) {
+ String path = String.format("/api/cnf-adapter/v1/instance/%s/status/notify", instanceId);
+
+ URIBuilder uriBuilder = new URIBuilder();
+ try {
+ return uriBuilder
+ .setScheme(PROTOCOL)
+ .setHost(HOST)
+ .setPort(PORT)
+ .setPath(path)
+ .build()
+ .toString();
+ } catch (URISyntaxException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/upgrade/InstanceUpgradeService.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/upgrade/InstanceUpgradeService.java
new file mode 100644
index 0000000..2fd26fb
--- /dev/null
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/upgrade/InstanceUpgradeService.java
@@ -0,0 +1,60 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
+ * Modifications Copyright (C) 2021 Samsung Technologies Co.
+ * Modifications Copyright (C) 2021 Orange.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.adapters.cnf.service.upgrade;
+
+import org.onap.so.adapters.cnf.client.MulticloudClient;
+import org.onap.so.adapters.cnf.model.MulticloudInstanceRequest;
+import org.onap.so.adapters.cnf.model.upgrade.InstanceUpgradeRequest;
+import org.onap.so.client.exception.BadResponseException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+@Service
+public class InstanceUpgradeService {
+
+ private static final Logger logger = LoggerFactory.getLogger(InstanceUpgradeService.class);
+
+ private final MulticloudClient instanceApi;
+
+ public InstanceUpgradeService(MulticloudClient multicloudClient) {
+ this.instanceApi = multicloudClient;
+ }
+
+ public String upgradeInstance(String instanceId, InstanceUpgradeRequest upgradeRequest) throws BadResponseException {
+ logger.debug("UpgradeService upgradeInstance for instanceId: {}- START", instanceId);
+ MulticloudInstanceRequest multicloudInstanceRequest = new MulticloudInstanceRequest();
+ if (upgradeRequest.getK8sRBProfileName() != null) {
+ multicloudInstanceRequest.setRbName(upgradeRequest.getModelInvariantId());
+ multicloudInstanceRequest.setRbVersion(upgradeRequest.getModelCustomizationId());
+ multicloudInstanceRequest.setProfileName(upgradeRequest.getK8sRBProfileName());
+ multicloudInstanceRequest.setCloudRegion(upgradeRequest.getCloudRegionId());
+ multicloudInstanceRequest.setLabels(upgradeRequest.getLabels());
+ multicloudInstanceRequest.setOverrideValues(upgradeRequest.getOverrideValues());
+ } else {
+ throw new NullPointerException("k8sProfileName should not be null");
+ }
+ logger.info("Upgrade request: {}", multicloudInstanceRequest);
+ logger.debug("UpgradeService upgradeInstance- END");
+ return instanceApi.upgradeInstance(instanceId, multicloudInstanceRequest);
+ }
+}
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/util/AaiClientPropertiesImpl.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/util/AaiClientPropertiesImpl.java
new file mode 100644
index 0000000..6ee8879
--- /dev/null
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/util/AaiClientPropertiesImpl.java
@@ -0,0 +1,115 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.cnf.util;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.security.GeneralSecurityException;
+
+import org.apache.commons.codec.binary.Base64;
+import org.onap.aaiclient.client.aai.AAIProperties;
+import org.onap.aaiclient.client.aai.AAIVersion;
+import org.onap.so.client.CacheProperties;
+import org.onap.so.spring.SpringContextHelper;
+import org.onap.so.utils.CryptoUtils;
+import org.springframework.context.ApplicationContext;
+
+public class AaiClientPropertiesImpl implements AAIProperties {
+
+ private final static String aaiEndpoint;
+ private final static String auth;
+ private final static String key;
+ private final static Long readTimeout;
+ private final static Long connectionTimeout;
+ private final static boolean enableCaching;
+ private final static Long cacheMaxAge;
+ private static final String SYSTEM_NAME = "MSO";
+
+ static {
+ ApplicationContext context = SpringContextHelper.getAppContext();
+ aaiEndpoint = context.getEnvironment().getProperty("aai.endpoint");
+ readTimeout = context.getEnvironment().getProperty("aai.readTimeout", Long.class, 60000L);
+ connectionTimeout = context.getEnvironment().getProperty("aai.connectionTimeout", Long.class, 60000L);
+ enableCaching = context.getEnvironment().getProperty("aai.caching.enabled", Boolean.class, false);
+ cacheMaxAge = context.getEnvironment().getProperty("aai.caching.maxAge", Long.class, 60000L);
+ key = "07a7159d3bf51a0e53be7a8f89699be7";
+ String authTmp = context.getEnvironment().getProperty("aai.auth");
+ if (authTmp != null && !authTmp.isEmpty() && authTmp.split(" ").length == 2) {
+ authTmp = authTmp.split(" ")[1].trim();
+ authTmp = new String(Base64.decodeBase64(authTmp));
+ try {
+ authTmp = CryptoUtils.encrypt(authTmp, key);
+ } catch (GeneralSecurityException e) {
+ authTmp = "";
+ e.printStackTrace();
+ }
+ }
+ auth = authTmp;
+ }
+
+ @Override
+ public URL getEndpoint() throws MalformedURLException {
+ return new URL(aaiEndpoint != null ? aaiEndpoint : "");
+ }
+
+ @Override
+ public String getSystemName() {
+ return SYSTEM_NAME;
+ }
+
+ @Override
+ public AAIVersion getDefaultVersion() {
+ return AAIVersion.LATEST;
+ }
+
+ @Override
+ public String getAuth() { return auth; }
+
+ @Override
+ public String getKey() {
+ return key;
+ }
+
+ @Override
+ public Long getReadTimeout() {
+ return readTimeout;
+ }
+
+ @Override
+ public Long getConnectionTimeout() {
+ return connectionTimeout;
+ }
+
+ @Override
+ public boolean isCachingEnabled() {
+ return enableCaching;
+ }
+
+ @Override
+ public CacheProperties getCacheProperties() {
+ return new AAICacheProperties() {
+ @Override
+ public Long getMaxAge() {
+ return cacheMaxAge;
+ }
+ };
+ }
+}
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/util/AaiRepository.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/util/AaiRepository.java
new file mode 100644
index 0000000..3f89c53
--- /dev/null
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/util/AaiRepository.java
@@ -0,0 +1,226 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2021 Samsung Electronics Co. Ltd. All rights reserved.
+ * Modifications Copyright (C) 2021 Orange.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.cnf.util;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.onap.aaiclient.client.aai.AAIResourcesClient;
+import org.onap.aaiclient.client.aai.AAITransactionalClient;
+import org.onap.aaiclient.client.aai.AAIVersion;
+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.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types;
+import org.onap.aaiclient.client.generated.fluentbuilders.K8sResource;
+import org.onap.aaiclient.client.graphinventory.exceptions.BulkProcessFailed;
+import org.onap.so.adapters.cnf.model.aai.AaiRequest;
+import org.onap.so.adapters.cnf.service.aai.KubernetesResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+public class AaiRepository implements IAaiRepository {
+ private final static Logger logger = LoggerFactory.getLogger(IAaiRepository.class);
+
+ private final AAIResourcesClient aaiClient;
+ private final ObjectMapper objectMapper;
+ private final AAITransactionHelper aaiTransactionHelper;
+
+ public static IAaiRepository instance() {
+ return new AaiRepository();
+ }
+
+ private AaiRepository() {
+ aaiClient = new AAIResourcesClient(AAIVersion.LATEST);
+ aaiTransactionHelper = new AAITransactionHelper(aaiClient);
+ this.objectMapper = new ObjectMapper();
+ }
+
+ private AAITransactionHelper getTransaction() {
+ return aaiTransactionHelper;
+ }
+
+ @Override
+ public void commit(boolean dryrun) {
+ aaiTransactionHelper.execute(dryrun);
+ }
+
+ @Override
+ public void update(KubernetesResource resource, AaiRequest aaiRequest) {
+ logger.info("updating AAI with resource {} and request {}", resource, aaiRequest);
+
+ K8sResource k8sResource = AAIFluentTypeBuilder.cloudInfrastructure()
+ .cloudRegion(aaiRequest.getCloudOwner(), aaiRequest.getCloudRegion())
+ .tenant(aaiRequest.getTenantId())
+ .k8sResource(resource.getId());
+
+ AAIResourceUri k8sResourceUri =
+ AAIUriFactory.createResourceUri(k8sResource.build(), aaiRequest.getCloudOwner(), aaiRequest.getCloudRegion(), aaiRequest.getTenantId(), resource.getId());
+
+ var k8sResourceInstance = aaiClient.get(k8sResourceUri);
+ boolean updateK8sResource = true;
+ if (!k8sResourceInstance.isEmpty()) {
+ try {
+ KubernetesResource resourceReference = objectMapper.readValue(k8sResourceInstance.getJson(), KubernetesResource.class);
+ updateK8sResource = !resourceReference.compare(resource);
+ if (updateK8sResource)
+ resource.setResourceVersion(resourceReference.getResourceVersion());
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ if (updateK8sResource) {
+ String payload;
+ try {
+ payload = objectMapper.writeValueAsString(resource);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ logger.debug("K8s resource URI: " + k8sResourceUri + " with payload [" + payload + "]");
+ getTransaction().create(k8sResourceUri, payload);
+ }
+
+ final String genericVnfId = aaiRequest.getGenericVnfId();
+ final String vfModuleId = aaiRequest.getVfModuleId();
+
+ if (genericVnfId == null || vfModuleId == null) {
+ logger.debug("No genericVnfId or vfModuleId to create relations for payload [\" + payload + \"]\");");
+ return;
+ }
+
+ var vfModuleUri = AAIUriFactory.createResourceUri(
+ AAIFluentTypeBuilder.network().genericVnf(genericVnfId).vfModule(vfModuleId));
+ var instance = aaiClient.get(vfModuleUri);
+
+ if (instance.isEmpty())
+ logger.error("Specified VfModule [" + vfModuleId + "] does not exist in AAI");
+ else if (k8sResourceInstance.isEmpty() || !k8sResourceInstance.hasRelationshipsTo(Types.VF_MODULE)) {
+ getTransaction().connect(k8sResourceUri, vfModuleUri);
+ }
+
+ var genericVnfUri = AAIUriFactory.createResourceUri(
+ AAIFluentTypeBuilder.network().genericVnf(genericVnfId));
+ instance = aaiClient.get(genericVnfUri);
+
+ if (instance.isEmpty())
+ logger.error("Specified GenericVnf [" + genericVnfId + "] does not exist in AAI");
+ else if (k8sResourceInstance.isEmpty() || !k8sResourceInstance.hasRelationshipsTo(Types.GENERIC_VNF)) {
+ getTransaction().connect(k8sResourceUri, genericVnfUri);
+ }
+ }
+
+ @Override
+ public void delete(AaiRequest aaiRequest, List<KubernetesResource> excludedList) {
+ logger.info("deleting from AAI resource {}", aaiRequest);
+ final String genericVnfId = aaiRequest.getGenericVnfId();
+ final String vfModuleId = aaiRequest.getVfModuleId();
+ final List<String> excludedIds = excludedList == null ? List.of() :
+ excludedList.stream().map(KubernetesResource::getId).collect(Collectors.toList());
+
+ if (genericVnfId == null || vfModuleId == null) {
+ logger.debug("No genericVnfId or vfModuleId to delete k8s-resources");
+ return;
+ }
+
+ var vfModuleUri = AAIUriFactory.createResourceUri(
+ AAIFluentTypeBuilder.network().genericVnf(genericVnfId).vfModule(vfModuleId));
+ var instance = aaiClient.get(vfModuleUri);
+
+ if (instance.hasRelationshipsTo(Types.K8S_RESOURCE) && instance.getRelationships().isPresent()) {
+ List<KubernetesResource> resources = instance.getRelationships().get().getByType(Types.K8S_RESOURCE)
+ .stream()
+ .map(r -> r.asBean(KubernetesResource.class))
+ .filter(r -> r.isPresent() && !excludedIds.contains(r.get().getId()))
+ .map(Optional::get)
+ .collect(Collectors.toList());
+ resources.stream().map(r -> {
+ K8sResource k8sResource = AAIFluentTypeBuilder.cloudInfrastructure()
+ .cloudRegion(aaiRequest.getCloudOwner(), aaiRequest.getCloudRegion())
+ .tenant(aaiRequest.getTenantId())
+ .k8sResource(r.getId());
+ return AAIUriFactory.createResourceUri(k8sResource.build(), aaiRequest.getCloudOwner(), aaiRequest.getCloudRegion(), aaiRequest.getTenantId(), r.getId());
+ }).filter(r -> {
+ if (aaiClient.exists(r))
+ return true;
+ else {
+ logger.warn("K8sResource " + r.toString() + "] does not exist in AAI. Skipping delete in AAI");
+ return false;
+ }
+ }).forEach(uri -> getTransaction().delete(uri));
+ }
+ }
+
+ static class AAITransactionHelper {
+ private List<AAITransactionalClient> transactions;
+ private final AAIResourcesClient aaiClient;
+ private int transactionCount;
+
+ private static final int TRANSACTION_LIMIT = 30;
+
+ AAITransactionHelper(AAIResourcesClient aaiClient) {
+ this.aaiClient = aaiClient;
+ transactions = new ArrayList<>();
+ transactionCount = TRANSACTION_LIMIT;
+ }
+
+ private AAITransactionalClient getTransaction() {
+ if (transactionCount == TRANSACTION_LIMIT) {
+ transactions.add(aaiClient.beginTransaction());
+ transactionCount = 0;
+ }
+ return transactions.get(transactions.size() - 1);
+ }
+
+ void execute(boolean dryRun) {
+ if (transactions.size() > 0) {
+ transactions.forEach(transaction -> {
+ try {
+ transaction.execute(dryRun);
+ } catch (BulkProcessFailed e) {
+ throw new RuntimeException("Failed to execute transaction", e);
+ }
+ });
+ transactions.clear();
+ } else
+ logger.info("Nothing to commit in AAI");
+ }
+
+ void create(AAIResourceUri uri, String payload) {
+ getTransaction().create(uri, payload);
+ transactionCount++;
+ }
+
+ void connect(AAIResourceUri uriA, AAIResourceUri uriB) {
+ getTransaction().connect(uriA, uriB);
+ transactionCount++;
+ }
+
+ void delete(AAIResourceUri uri) {
+ getTransaction().delete(uri);
+ transactionCount++;
+ }
+ }
+}
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/util/CNfAdapterUtil.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/util/CnfAdapterUtil.java
index 25e506c..030849f 100644
--- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/util/CNfAdapterUtil.java
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/util/CnfAdapterUtil.java
@@ -21,66 +21,28 @@
package org.onap.so.adapters.cnf.util;
import com.fasterxml.jackson.databind.ObjectMapper;
+
import java.io.IOException;
+
import org.onap.so.adapters.cnf.exceptions.ApplicationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.onap.logging.filter.base.ErrorCode;
+
import static org.onap.so.logger.LoggingAnchor.THREE;
import static org.onap.so.logger.MessageEnum.RA_NS_EXC;
-public class CNfAdapterUtil {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(CNfAdapterUtil.class);
+public class CnfAdapterUtil {
- public static final int BAD_REQUEST = 400;
+ private static final Logger LOGGER = LoggerFactory.getLogger(CnfAdapterUtil.class);
- private static final String UNMARSHAL_FAIL_MSG = "Failed to unmarshal json";
+ private static final int BAD_REQUEST = 400;
private static final String MARSHAL_FAIL_MSG = "Failed to marshal object";
private static final ObjectMapper MAPPER = new ObjectMapper();
- public static class StatusDesc {
-
- public static final String ALLOCATE_NSS_SUCCESS = "Allocating nss is " + "successful";
-
- public static final String CREATE_NSS_SUCCESS = "Creating nss is " + "successful";
-
- public static final String DEALLOCATE_NSS_SUCCESS = "Deallocate nss " + "is successful";
-
- public static final String ACTIVATE_NSS_SUCCESS = "Activate nss " + "is successful";
-
- public static final String DEACTIVATE_NSS_SUCCESS = "Deactivate nss " + "is successful";
-
- public static final String QUERY_JOB_STATUS_FAILED = "Query job " + "status failed";
-
- public static final String QUERY_JOB_STATUS_SUCCESS = "Query job " + "status is successful";
-
- private StatusDesc() {
-
- }
- }
-
- private CNfAdapterUtil() {
-
- }
-
- public static void assertObjectNotNull(Object object) throws ApplicationException {
- if (null == object) {
- LOGGER.error("Object is null.");
- throw new ApplicationException(BAD_REQUEST, "An object is null.");
- }
- }
-
- public static <T> T unMarshal(String jsonstr, Class<T> type) throws ApplicationException {
- try {
- return MAPPER.readValue(jsonstr, type);
- } catch (IOException e) {
- LOGGER.error(THREE, RA_NS_EXC.toString(), ErrorCode.BusinessProcessError.getValue(), UNMARSHAL_FAIL_MSG, e);
- throw new ApplicationException(BAD_REQUEST, UNMARSHAL_FAIL_MSG);
- }
- }
+ private CnfAdapterUtil() { }
public static String marshal(Object srcObj) throws ApplicationException {
try {
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/util/IAaiRepository.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/util/IAaiRepository.java
new file mode 100644
index 0000000..8a865d7
--- /dev/null
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/util/IAaiRepository.java
@@ -0,0 +1,87 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2021 Samsung Electronics Co. Ltd. All rights reserved.
+ * Modifications Copyright (C) 2021 Orange.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.cnf.util;
+
+import org.onap.so.adapters.cnf.model.aai.AaiRequest;
+import org.onap.so.adapters.cnf.service.aai.KubernetesResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+
+import static java.lang.Thread.sleep;
+
+public interface IAaiRepository {
+ static IAaiRepository instance(boolean enabled) {
+ if (enabled)
+ return AaiRepository.instance();
+ else
+ return AaiRepositoryDummy.instance();
+ }
+
+ void update(KubernetesResource resource, AaiRequest request);
+
+ void delete(AaiRequest request, List<KubernetesResource> excludedList);
+
+ void commit(boolean dryRun) throws RuntimeException;
+
+ static class AaiRepositoryDummy implements IAaiRepository {
+ private static final Logger logger = LoggerFactory.getLogger(IAaiRepository.class);
+ private static final IAaiRepository instance = new AaiRepositoryDummy();
+
+ private static final Long SLEEP_TIME = 5000l;
+
+ public static IAaiRepository instance() {
+ return instance;
+ }
+
+ private AaiRepositoryDummy() {
+
+ }
+
+ @Override
+ public void update(KubernetesResource resource, AaiRequest request) {
+ logger.info("aai synchronization disabled - mocking update AAI with resource {} and request {}", resource, request);
+ try {
+ sleep(SLEEP_TIME);
+ } catch (InterruptedException e) {
+ logger.debug("aai synchronization disabled [update] - sleep failed");
+ }
+ }
+
+ @Override
+ public void delete(AaiRequest aaiRequest, List<KubernetesResource> excludedList) {
+ logger.info("aai synchronization disabled - mocking delete from AAI resource {}", aaiRequest);
+ try {
+ sleep(SLEEP_TIME);
+ } catch (InterruptedException e) {
+ logger.debug("aai synchronization disabled [delete] - sleep failed");
+ }
+
+ }
+
+ @Override
+ public void commit(boolean dryrun) {
+ logger.info("aai synchronization disabled - commiting");
+ }
+ }
+}
diff --git a/so-cnf-adapter-application/src/main/resources/META-INF/services/org.onap.so.client.RestProperties b/so-cnf-adapter-application/src/main/resources/META-INF/services/org.onap.so.client.RestProperties
index bccd43a..98f7d2d 100644
--- a/so-cnf-adapter-application/src/main/resources/META-INF/services/org.onap.so.client.RestProperties
+++ b/so-cnf-adapter-application/src/main/resources/META-INF/services/org.onap.so.client.RestProperties
@@ -1 +1 @@
-org.onap.so.adapters.cnf.extclients.aai.AaiClientPropertiesImpl \ No newline at end of file
+org.onap.so.adapters.cnf.util.AaiClientPropertiesImpl \ No newline at end of file
diff --git a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/AaiConfigurationTest.java b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/AaiConfigurationTest.java
new file mode 100644
index 0000000..93ab257
--- /dev/null
+++ b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/AaiConfigurationTest.java
@@ -0,0 +1,16 @@
+package org.onap.so.adapters.cnf;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class AaiConfigurationTest {
+
+ private AaiConfiguration tested = new AaiConfiguration();
+
+ @Test
+ public void shouldReturnDefaultFalse() {
+ boolean actual = tested.isEnabled();
+ assertFalse(actual);
+ }
+} \ No newline at end of file
diff --git a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/client/MulticloudApiUrlTest.java b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/client/MulticloudApiUrlTest.java
new file mode 100644
index 0000000..f67c239
--- /dev/null
+++ b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/client/MulticloudApiUrlTest.java
@@ -0,0 +1,37 @@
+package org.onap.so.adapters.cnf.client;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.onap.so.adapters.cnf.MulticloudConfiguration;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
+
+@RunWith(SpringRunner.class)
+public class MulticloudApiUrlTest {
+
+ private static final String BASE_URL = "http://test-multicloud.com:8080";
+
+ @InjectMocks
+ private MulticloudApiUrl tested;
+
+ @Mock
+ private MulticloudConfiguration multicloudConfiguration;
+
+ @Test
+ public void shouldPresentInstanceIdInPath() {
+ // given
+ String instanceId = "instanceId";
+ // when
+ when(multicloudConfiguration.getMulticloudUrl()).thenReturn(BASE_URL);
+
+ // then
+ String actual = tested.apiUrl(instanceId);
+
+ assertEquals(BASE_URL + "/v1/instance/instanceId", actual);
+ }
+
+} \ No newline at end of file
diff --git a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/client/MulticloudClientTest.java b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/client/MulticloudClientTest.java
new file mode 100644
index 0000000..87b0853
--- /dev/null
+++ b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/client/MulticloudClientTest.java
@@ -0,0 +1,266 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
+ * Modifications Copyright (C) 2021 Samsung Technologies Co.
+ * Modifications Copyright (C) 2021 Orange.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.adapters.cnf.client;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.onap.so.adapters.cnf.model.InstanceResponse;
+import org.onap.so.adapters.cnf.model.MulticloudInstanceRequest;
+import org.onap.so.adapters.cnf.model.healthcheck.K8sRbInstanceHealthCheck;
+import org.onap.so.adapters.cnf.model.healthcheck.K8sRbInstanceHealthCheckSimple;
+import org.onap.so.adapters.cnf.model.statuscheck.K8sRbInstanceStatus;
+import org.onap.so.adapters.cnf.model.synchronization.SubscriptionRequest;
+import org.onap.so.adapters.cnf.model.synchronization.SubscriptionResponse;
+import org.onap.so.client.exception.BadResponseException;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.web.client.RestTemplate;
+
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.springframework.http.HttpMethod.DELETE;
+import static org.springframework.http.HttpMethod.GET;
+import static org.springframework.http.HttpMethod.POST;
+
+@RunWith(SpringRunner.class)
+public class MulticloudClientTest {
+
+ private static final String instanceId = "INSTANCE_ID";
+ private static final String endpoint = "API_URL";
+
+ @InjectMocks
+ private MulticloudClient tested;
+
+ @Mock
+ private RestTemplate restTemplate;
+ @Mock
+ private MulticloudApiUrl multicloudApiUrl;
+ @Captor
+ private ArgumentCaptor<String> instanceIdCaptor;
+
+
+ @Test
+ public void shouldRegisterSubscription() throws BadResponseException {
+ // given
+ SubscriptionRequest request = mock(SubscriptionRequest.class);
+ ResponseEntity result = mock(ResponseEntity.class);
+ String body = "{\"name\":\"name\"}";
+
+ // when
+ when(multicloudApiUrl.apiUrl(instanceId)).thenReturn(endpoint);
+ when(restTemplate.exchange(eq(getUrl("/status/subscription")), eq(POST), any(), eq(String.class))).thenReturn(result);
+ when(result.getStatusCode()).thenReturn(HttpStatus.OK);
+ when(result.getBody()).thenReturn(body);
+
+ // then
+ SubscriptionResponse actual = tested.registerSubscription(instanceId, request);
+
+ assertEquals("name", actual.getName());
+ verify(multicloudApiUrl).apiUrl(instanceIdCaptor.capture());
+ assertInstanceIdCaperedValue(instanceIdCaptor.getValue());
+ }
+
+ @Test
+ public void shouldGetSubscription() throws BadResponseException {
+ // given
+ String request = "subscriptionId";
+ ResponseEntity result = mock(ResponseEntity.class);
+ String body = "{\"name\":\"name\"}";
+
+ // when
+ when(multicloudApiUrl.apiUrl(instanceId)).thenReturn(endpoint);
+ when(restTemplate.exchange(eq(getUrl("/status/subscription/" + request)), eq(GET), any(), eq(String.class))).thenReturn(result);
+ when(result.getStatusCode()).thenReturn(HttpStatus.OK);
+ when(result.getBody()).thenReturn(body);
+
+ // then
+ SubscriptionResponse actual = tested.getSubscription(instanceId, request);
+
+ assertEquals("name", actual.getName());
+ verify(multicloudApiUrl).apiUrl(instanceIdCaptor.capture());
+ assertInstanceIdCaperedValue(instanceIdCaptor.getValue());
+ }
+
+ @Test
+ public void shouldDeleteSubscription() throws BadResponseException {
+ // given
+ String request = "subscriptionId";
+ ResponseEntity result = mock(ResponseEntity.class);
+ String body = "{\"name\":\"name\"}";
+
+ // when
+ when(multicloudApiUrl.apiUrl(instanceId)).thenReturn(endpoint);
+ when(restTemplate.exchange(eq(getUrl("/status/subscription/" + request)), eq(DELETE), any(), eq(String.class))).thenReturn(result);
+ when(result.getStatusCode()).thenReturn(HttpStatus.OK);
+ when(result.getBody()).thenReturn(body);
+
+ // then
+ tested.deleteSubscription(instanceId, request);
+
+ verify(multicloudApiUrl).apiUrl(instanceIdCaptor.capture());
+ assertInstanceIdCaperedValue(instanceIdCaptor.getValue());
+ }
+
+ @Test
+ public void shouldUpgradeInstance() throws BadResponseException {
+ // given
+ MulticloudInstanceRequest request = mock(MulticloudInstanceRequest.class);
+ ResponseEntity result = mock(ResponseEntity.class);
+ String body = "body";
+
+ // when
+ when(multicloudApiUrl.apiUrl(instanceId)).thenReturn(endpoint);
+ when(restTemplate.exchange(eq(getUrl("/upgrade")), eq(POST), any(), eq(String.class))).thenReturn(result);
+ when(result.getStatusCode()).thenReturn(HttpStatus.OK);
+ when(result.getBody()).thenReturn(body);
+
+ // then
+ String actual = tested.upgradeInstance(instanceId, request);
+
+ assertEquals(body, actual);
+ verify(multicloudApiUrl).apiUrl(instanceIdCaptor.capture());
+ assertInstanceIdCaperedValue(instanceIdCaptor.getValue());
+ }
+
+ @Test
+ public void shouldGetInstanceStatus() throws BadResponseException {
+ // given
+ ResponseEntity result = mock(ResponseEntity.class);
+ String body = "{\"ready\":true}";
+
+ // when
+ when(multicloudApiUrl.apiUrl(instanceId)).thenReturn(endpoint);
+ when(restTemplate.exchange(eq(getUrl("/status")), eq(GET), any(), eq(String.class))).thenReturn(result);
+ when(result.getStatusCode()).thenReturn(HttpStatus.OK);
+ when(result.getBody()).thenReturn(body);
+
+ // then
+ K8sRbInstanceStatus actual = tested.getInstanceStatus(instanceId);
+
+ assertEquals(true, actual.isReady());
+ verify(multicloudApiUrl).apiUrl(instanceIdCaptor.capture());
+ assertInstanceIdCaperedValue(instanceIdCaptor.getValue());
+ }
+
+ @Test
+ public void shouldStartInstanceHealthCheck() throws BadResponseException {
+ // given
+ ResponseEntity result = mock(ResponseEntity.class);
+ String body = "{\"status\":\"SUCCEED\"}";
+
+ // when
+ when(multicloudApiUrl.apiUrl(instanceId)).thenReturn(endpoint);
+ when(restTemplate.exchange(eq(getUrl("/healthcheck")), eq(POST), any(), eq(String.class))).thenReturn(result);
+ when(result.getStatusCode()).thenReturn(HttpStatus.OK);
+ when(result.getBody()).thenReturn(body);
+
+ // then
+ K8sRbInstanceHealthCheckSimple actual = tested.startInstanceHealthCheck(instanceId);
+
+ assertEquals("SUCCEED", actual.getStatus());
+ verify(multicloudApiUrl).apiUrl(instanceIdCaptor.capture());
+ assertInstanceIdCaperedValue(instanceIdCaptor.getValue());
+ }
+
+ @Test
+ public void shouldGetInstanceHealthCheck() throws BadResponseException {
+ // given
+ ResponseEntity result = mock(ResponseEntity.class);
+ String healthCheckInstance = "healthCheckInstance";
+ String body = "{\"status\":\"SUCCEED\"}";
+
+ // when
+ when(multicloudApiUrl.apiUrl(instanceId)).thenReturn(endpoint);
+ when(restTemplate.exchange(eq(getUrl("/healthcheck/" + healthCheckInstance)), eq(GET), any(), eq(String.class))).thenReturn(result);
+ when(result.getStatusCode()).thenReturn(HttpStatus.OK);
+ when(result.getBody()).thenReturn(body);
+
+ // then
+ K8sRbInstanceHealthCheck actual = tested.getInstanceHealthCheck(instanceId, healthCheckInstance);
+
+ assertEquals("SUCCEED", actual.getStatus());
+ verify(multicloudApiUrl).apiUrl(instanceIdCaptor.capture());
+ assertInstanceIdCaperedValue(instanceIdCaptor.getValue());
+ }
+
+ @Test
+ public void shouldDeleteInstanceHealthCheck() throws BadResponseException {
+ // given
+ ResponseEntity result = mock(ResponseEntity.class);
+ String healthCheckInstance = "healthCheckInstance";
+ String body = "body";
+
+ // when
+ when(multicloudApiUrl.apiUrl(instanceId)).thenReturn(endpoint);
+ when(restTemplate.exchange(eq(getUrl("/healthcheck/" + healthCheckInstance)), eq(DELETE), any(), eq(String.class))).thenReturn(result);
+ when(result.getStatusCode()).thenReturn(HttpStatus.OK);
+ when(result.getBody()).thenReturn(body);
+
+ // then
+ tested.deleteInstanceHealthCheck(instanceId, healthCheckInstance);
+
+ verify(multicloudApiUrl).apiUrl(instanceIdCaptor.capture());
+ assertInstanceIdCaperedValue(instanceIdCaptor.getValue());
+ }
+
+ @Test
+ public void shouldGetAllInstances() throws BadResponseException {
+ // given
+ ResponseEntity result = mock(ResponseEntity.class);
+ String body = "[{\"id\":\"clever_proskuriakova\",\"release-name\":\"rel-1-apache\",\"namespace\":\"test-cnf\"}]";
+
+ // when
+ when(multicloudApiUrl.apiUrl("")).thenReturn(endpoint);
+ when(restTemplate.exchange(eq(getUrl("")), eq(GET), any(), eq(String.class))).thenReturn(result);
+ when(result.getStatusCode()).thenReturn(HttpStatus.OK);
+ when(result.getBody()).thenReturn(body);
+
+ // then
+ List<InstanceResponse> actual = tested.getAllInstances();
+
+ verify(multicloudApiUrl).apiUrl(instanceIdCaptor.capture());
+ assertEquals("", instanceIdCaptor.getValue());
+ assertEquals(1, actual.size());
+ assertEquals("clever_proskuriakova", actual.get(0).getId());
+ assertEquals("rel-1-apache", actual.get(0).getReleaseName());
+ assertEquals("test-cnf", actual.get(0).getNamespace());
+ }
+
+ private void assertInstanceIdCaperedValue(String instanceIdCapturedValue) {
+ assertEquals(instanceId, instanceIdCapturedValue);
+ }
+
+ private String getUrl(String path) {
+ return endpoint + path;
+ }
+} \ No newline at end of file
diff --git a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/exceptions/ApplicationExceptionTest.java b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/exceptions/ApplicationExceptionTest.java
index bc39e95..8e11913 100644
--- a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/exceptions/ApplicationExceptionTest.java
+++ b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/exceptions/ApplicationExceptionTest.java
@@ -22,13 +22,18 @@ package org.onap.so.adapters.cnf.exceptions;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.onap.so.adapters.cnf.model.*;
-import org.springframework.http.HttpStatus;
+import org.onap.so.adapters.cnf.model.GroupVersionKind;
+import org.onap.so.adapters.cnf.model.InstanceStatusResponse;
+import org.onap.so.adapters.cnf.model.MulticloudInstanceRequest;
+import org.onap.so.adapters.cnf.model.PodStatus;
+import org.onap.so.adapters.cnf.model.Resource;
+import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.List;
+@SpringBootTest
@RunWith(SpringRunner.class)
public class ApplicationExceptionTest {
@@ -89,4 +94,5 @@ public class ApplicationExceptionTest {
applicationexception.buildErrorResponse();
}
-} \ No newline at end of file
+
+}
diff --git a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/rest/CnfAdapterRestTest.java b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/rest/CnfAdapterRestTest.java
index 48eecaa..1b16580 100644
--- a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/rest/CnfAdapterRestTest.java
+++ b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/rest/CnfAdapterRestTest.java
@@ -27,22 +27,49 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.onap.so.adapters.cnf.MulticloudConfiguration;
-import org.onap.so.adapters.cnf.model.*;
+import org.onap.so.adapters.cnf.client.SoCallbackClient;
+import org.onap.so.adapters.cnf.model.BpmnInstanceRequest;
+import org.onap.so.adapters.cnf.model.CheckInstanceRequest;
+import org.onap.so.adapters.cnf.model.ConfigTemplateEntity;
+import org.onap.so.adapters.cnf.model.ConfigurationEntity;
+import org.onap.so.adapters.cnf.model.ConfigurationRollbackEntity;
+import org.onap.so.adapters.cnf.model.ConnectivityInfo;
+import org.onap.so.adapters.cnf.model.InstanceMiniResponse;
+import org.onap.so.adapters.cnf.model.InstanceMiniResponseList;
+import org.onap.so.adapters.cnf.model.InstanceResponse;
+import org.onap.so.adapters.cnf.model.InstanceStatusResponse;
+import org.onap.so.adapters.cnf.model.MulticloudInstanceRequest;
+import org.onap.so.adapters.cnf.model.ProfileEntity;
+import org.onap.so.adapters.cnf.model.Resource;
+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.aai.AaiRequest;
import org.onap.so.adapters.cnf.model.healthcheck.HealthCheckResponse;
+import org.onap.so.adapters.cnf.model.statuscheck.StatusCheckResponse;
+import org.onap.so.adapters.cnf.model.upgrade.InstanceUpgradeRequest;
import org.onap.so.adapters.cnf.service.CnfAdapterService;
+import org.onap.so.adapters.cnf.service.aai.AaiService;
+import org.onap.so.adapters.cnf.service.healthcheck.HealthCheckService;
+import org.onap.so.adapters.cnf.service.statuscheck.SimpleStatusCheckService;
+import org.onap.so.adapters.cnf.service.upgrade.InstanceUpgradeService;
+import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.context.request.async.DeferredResult;
import org.springframework.web.multipart.MultipartFile;
+
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import static org.junit.Assert.assertEquals;
+
import static org.assertj.core.api.Java6Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+@SpringBootTest
@RunWith(SpringRunner.class)
public class CnfAdapterRestTest {
@@ -53,27 +80,25 @@ public class CnfAdapterRestTest {
CnfAdapterService cnfAdapterService;
@Mock
- private MulticloudConfiguration multicloudConfiguration;
+ InstanceUpgradeService instanceUpgradeService;
@Mock
- ResponseEntity<InstanceMiniResponseList> instacneMiniResponseList;
+ HealthCheckService healthCheckService;
@Mock
- ResponseEntity<InstanceStatusResponse> instanceStatusResponse;
+ private SoCallbackClient callbackClient;
- @Test
- public void healthCheckTest() throws Exception {
- HealthCheckResponse response = new HealthCheckResponse();
- DeferredResult<HealthCheckResponse> deferredResponse = new DeferredResult<>();
- deferredResponse.setResult(response);
- CnfAdapterService cnfAdapterService = Mockito.mock(CnfAdapterService.class);
- CheckInstanceRequest healthCheckRequest = Mockito.mock(CheckInstanceRequest.class);
- Mockito.when(cnfAdapterService.healthCheck(healthCheckRequest)).thenReturn(response);
+ @Mock
+ SimpleStatusCheckService simpleStatusCheckService;
- cnfAdapterRest.healthCheck(healthCheckRequest);
+ @Mock
+ private MulticloudConfiguration multicloudConfiguration;
- Assert.assertNotNull(response);
- }
+ @Mock
+ ResponseEntity<InstanceMiniResponseList> instacneMiniResponseList;
+
+ @Mock
+ ResponseEntity<InstanceStatusResponse> instanceStatusResponse;
@Test
public void createInstanceTest() throws Exception {
@@ -596,4 +621,94 @@ public class CnfAdapterRestTest {
assert(true);
}
}
+
+ @Test
+ public void upgradeTest() throws Exception {
+
+ Map<String, String> labels = new HashMap<String, String>();
+ labels.put("custom-label-1", "label1");
+ Map<String, String> overrideValues = new HashMap<String, String>();
+ labels.put("image.tag", "latest");
+ labels.put("dcae_collector_ip", "1.2.3.4");
+ InstanceUpgradeRequest instanceUpgradeRequest = new InstanceUpgradeRequest();
+ instanceUpgradeRequest.setCloudRegionId("v1");
+ instanceUpgradeRequest.setK8sRBInstanceStatusCheck(true);
+ instanceUpgradeRequest.setK8sRBProfileName("test");
+ instanceUpgradeRequest.setLabels(labels);
+ instanceUpgradeRequest.setModelCustomizationId("12345");
+ instanceUpgradeRequest.setModelInvariantId("krd");
+ instanceUpgradeRequest.setOverrideValues(overrideValues);
+ instanceUpgradeRequest.setVfModuleUUID("20200824");
+
+ ResponseEntity<String> upgradeResponse = new ResponseEntity<String>(HttpStatus.OK);
+ InstanceUpgradeService instanceUpgradeService = Mockito.mock(InstanceUpgradeService.class);
+ Mockito.when(instanceUpgradeService.upgradeInstance("123", instanceUpgradeRequest))
+ .thenReturn(String.valueOf(upgradeResponse));
+ cnfAdapterRest.upgrade("123", instanceUpgradeRequest);
+ Assert.assertNotNull(upgradeResponse);
+ assertEquals(HttpStatus.OK, upgradeResponse.getStatusCode());
+ }
+
+ @Test
+ public void healthCheckTest() throws Exception {
+ HealthCheckResponse response = new HealthCheckResponse();
+ DeferredResult<HealthCheckResponse> deferredResponse = new DeferredResult<>();
+ deferredResponse.setResult(response);
+ HealthCheckService healthCheckService = Mockito.mock(HealthCheckService.class);
+ CheckInstanceRequest healthCheckRequest = Mockito.mock(CheckInstanceRequest.class);
+ Mockito.when(healthCheckService.healthCheck(healthCheckRequest)).thenReturn(response);
+
+ cnfAdapterRest.healthCheck(healthCheckRequest);
+
+ Assert.assertNotNull(response);
+ }
+
+ @Test
+ public void aaiUpdateTest() throws Exception {
+ AaiCallbackResponse response = new AaiCallbackResponse();
+ DeferredResult<AaiCallbackResponse> deferredResponse = new DeferredResult<>();
+ deferredResponse.setResult(response);
+
+ AaiRequest aaiRequest = new AaiRequest();
+ aaiRequest.setCallbackUrl("asdf");
+ aaiRequest.setVfModuleId("20200824");
+ AaiService aaiService = Mockito.mock(AaiService.class);
+ SoCallbackClient callbackClient = Mockito.mock(SoCallbackClient.class);
+
+ cnfAdapterRest.aaiUpdate(aaiRequest);
+
+ Assert.assertNotNull(response);
+ }
+
+ @Test
+ public void aaiDeleteTest() throws Exception {
+ AaiCallbackResponse response = new AaiCallbackResponse();
+ DeferredResult<AaiCallbackResponse> deferredResponse = new DeferredResult<>();
+ deferredResponse.setResult(response);
+
+ AaiRequest aaiRequest = new AaiRequest();
+ aaiRequest.setCallbackUrl("asdfds");
+ aaiRequest.setVfModuleId("20200824");
+ AaiService aaiService = Mockito.mock(AaiService.class);
+ SoCallbackClient callbackClient = Mockito.mock(SoCallbackClient.class);
+
+ cnfAdapterRest.aaiDelete(aaiRequest);
+
+ Assert.assertNotNull(response);
+ }
+
+ @Test
+ public void statusCheckTest() throws Exception {
+ StatusCheckResponse response = new StatusCheckResponse();
+ DeferredResult<StatusCheckResponse> deferredResponse = new DeferredResult<>();
+ deferredResponse.setResult(response);
+
+ CheckInstanceRequest statusCheckRequest = Mockito.mock(CheckInstanceRequest.class);
+ SimpleStatusCheckService simpleStatusCheckService = Mockito.mock(SimpleStatusCheckService.class);
+ SoCallbackClient callbackClient = Mockito.mock(SoCallbackClient.class);
+ Mockito.when(simpleStatusCheckService.statusCheck(statusCheckRequest)).thenReturn(response);
+ cnfAdapterRest.statusCheck(statusCheckRequest);
+
+ Assert.assertNotNull(response);
+ }
}
diff --git a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/rest/CnfRestTest.java b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/rest/CnfRestTest.java
new file mode 100644
index 0000000..77c8e50
--- /dev/null
+++ b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/rest/CnfRestTest.java
@@ -0,0 +1,174 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.cnf.rest;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.onap.so.adapters.cnf.MulticloudConfiguration;
+import org.onap.so.adapters.cnf.client.SoCallbackClient;
+import org.onap.so.adapters.cnf.model.CheckInstanceRequest;
+import org.onap.so.adapters.cnf.model.InstanceMiniResponseList;
+import org.onap.so.adapters.cnf.model.InstanceStatusResponse;
+import org.onap.so.adapters.cnf.model.aai.AaiCallbackResponse;
+import org.onap.so.adapters.cnf.model.aai.AaiRequest;
+import org.onap.so.adapters.cnf.model.healthcheck.HealthCheckResponse;
+import org.onap.so.adapters.cnf.model.statuscheck.StatusCheckResponse;
+import org.onap.so.adapters.cnf.model.upgrade.InstanceUpgradeRequest;
+import org.onap.so.adapters.cnf.service.CnfAdapterService;
+import org.onap.so.adapters.cnf.service.aai.AaiService;
+import org.onap.so.adapters.cnf.service.healthcheck.HealthCheckService;
+import org.onap.so.adapters.cnf.service.statuscheck.SimpleStatusCheckService;
+import org.onap.so.adapters.cnf.service.upgrade.InstanceUpgradeService;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.web.context.request.async.DeferredResult;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+
+
+@RunWith(SpringRunner.class)
+public class CnfRestTest {
+
+ @InjectMocks
+ org.onap.so.adapters.cnf.rest.CnfAdapterRest cnfAdapterRest;
+
+ @Mock
+ CnfAdapterService cnfAdapterService;
+
+ @Mock
+ InstanceUpgradeService instanceUpgradeService;
+
+ @Mock
+ HealthCheckService healthCheckService;
+
+ @Mock
+ private SoCallbackClient callbackClient;
+
+ @Mock
+ SimpleStatusCheckService simpleStatusCheckService;
+
+ @Mock
+ private MulticloudConfiguration multicloudConfiguration;
+
+ @Mock
+ ResponseEntity<InstanceMiniResponseList> instacneMiniResponseList;
+
+ @Mock
+ ResponseEntity<InstanceStatusResponse> instanceStatusResponse;
+
+ @Test
+ public void upgradeTest() throws Exception {
+
+ Map<String, String> labels = new HashMap<String, String>();
+ labels.put("custom-label-1", "label1");
+ Map<String, String> overrideValues = new HashMap<String, String>();
+ labels.put("image.tag", "latest");
+ labels.put("dcae_collector_ip", "1.2.3.4");
+ InstanceUpgradeRequest instanceUpgradeRequest = new InstanceUpgradeRequest();
+ instanceUpgradeRequest.setCloudRegionId("v1");
+ instanceUpgradeRequest.setK8sRBInstanceStatusCheck(true);
+ instanceUpgradeRequest.setK8sRBProfileName("test");
+ instanceUpgradeRequest.setLabels(labels);
+ instanceUpgradeRequest.setModelCustomizationId("12345");
+ instanceUpgradeRequest.setModelInvariantId("krd");
+ instanceUpgradeRequest.setOverrideValues(overrideValues);
+ instanceUpgradeRequest.setVfModuleUUID("20200824");
+
+ ResponseEntity<String> upgradeResponse = new ResponseEntity<String>(HttpStatus.OK);
+ InstanceUpgradeService instanceUpgradeService = Mockito.mock(InstanceUpgradeService.class);
+ Mockito.when(instanceUpgradeService.upgradeInstance("123", instanceUpgradeRequest))
+ .thenReturn(String.valueOf(upgradeResponse));
+ cnfAdapterRest.upgrade("123", instanceUpgradeRequest);
+ Assert.assertNotNull(upgradeResponse);
+ assertEquals(HttpStatus.OK, upgradeResponse.getStatusCode());
+ }
+
+ @Test
+ public void healthCheckTest() throws Exception {
+ HealthCheckResponse response = new HealthCheckResponse();
+ DeferredResult<HealthCheckResponse> deferredResponse = new DeferredResult<>();
+ deferredResponse.setResult(response);
+ HealthCheckService healthCheckService = Mockito.mock(HealthCheckService.class);
+ CheckInstanceRequest healthCheckRequest = Mockito.mock(CheckInstanceRequest.class);
+ Mockito.when(healthCheckService.healthCheck(healthCheckRequest)).thenReturn(response);
+
+ cnfAdapterRest.healthCheck(healthCheckRequest);
+
+ Assert.assertNotNull(response);
+ }
+
+ @Test
+ public void aaiUpdateTest() throws Exception {
+ AaiCallbackResponse response = new AaiCallbackResponse();
+ DeferredResult<AaiCallbackResponse> deferredResponse = new DeferredResult<>();
+ deferredResponse.setResult(response);
+
+ AaiRequest aaiRequest = new AaiRequest();
+ aaiRequest.setCallbackUrl("asdf");
+ aaiRequest.setVfModuleId("20200824");
+ AaiService aaiService = Mockito.mock(AaiService.class);
+ SoCallbackClient callbackClient = Mockito.mock(SoCallbackClient.class);
+
+ cnfAdapterRest.aaiUpdate(aaiRequest);
+
+ Assert.assertNotNull(response);
+ }
+
+ @Test
+ public void aaiDeleteTest() throws Exception {
+ AaiCallbackResponse response = new AaiCallbackResponse();
+ DeferredResult<AaiCallbackResponse> deferredResponse = new DeferredResult<>();
+ deferredResponse.setResult(response);
+
+ AaiRequest aaiRequest = new AaiRequest();
+ aaiRequest.setCallbackUrl("asdfds");
+ aaiRequest.setVfModuleId("20200824");
+ AaiService aaiService = Mockito.mock(AaiService.class);
+ SoCallbackClient callbackClient = Mockito.mock(SoCallbackClient.class);
+
+ cnfAdapterRest.aaiDelete(aaiRequest);
+
+ Assert.assertNotNull(response);
+ }
+
+ @Test
+ public void statusCheckTest() throws Exception {
+ StatusCheckResponse response = new StatusCheckResponse();
+ DeferredResult<StatusCheckResponse> deferredResponse = new DeferredResult<>();
+ deferredResponse.setResult(response);
+
+ CheckInstanceRequest statusCheckRequest = Mockito.mock(CheckInstanceRequest.class);
+ SimpleStatusCheckService simpleStatusCheckService = Mockito.mock(SimpleStatusCheckService.class);
+ SoCallbackClient callbackClient = Mockito.mock(SoCallbackClient.class);
+ Mockito.when(simpleStatusCheckService.statusCheck(statusCheckRequest)).thenReturn(response);
+ cnfAdapterRest.statusCheck(statusCheckRequest);
+
+ Assert.assertNotNull(response);
+ }
+}
diff --git a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/CnfAdapterServiceTest.java b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/CnfAdapterServiceTest.java
index f049310..d50f633 100644
--- a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/CnfAdapterServiceTest.java
+++ b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/CnfAdapterServiceTest.java
@@ -17,15 +17,9 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.onap.so.adapters.cnf.service;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-
+import lombok.Data;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -35,22 +29,25 @@ import org.onap.so.adapters.cnf.MulticloudConfiguration;
import org.onap.so.adapters.cnf.model.BpmnInstanceRequest;
import org.onap.so.adapters.cnf.service.healthcheck.HealthCheckService;
import org.onap.so.adapters.cnf.service.statuscheck.SimpleStatusCheckService;
+import org.onap.so.adapters.cnf.service.synchrornization.SynchronizationService;
+import org.onap.so.client.exception.BadResponseException;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.client.RestTemplate;
+import javax.persistence.EntityNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
-import javax.persistence.EntityNotFoundException;
-
-import lombok.Data;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
@RunWith(SpringRunner.class)
public class CnfAdapterServiceTest {
@@ -68,12 +65,15 @@ public class CnfAdapterServiceTest {
@Mock
SimpleStatusCheckService simpleStatusCheckService;
+ @Mock
+ SynchronizationService synchronizationService;
+
@Before
public void setUp() {
MulticloudConfiguration multicloudConfiguration = mock(MulticloudConfiguration.class);
doReturn("http://test.url").when(multicloudConfiguration).getMulticloudUrl();
- cnfAdapterService = spy(new CnfAdapterService(restTemplate, healthCheckService, simpleStatusCheckService, multicloudConfiguration));
+ cnfAdapterService = spy(new CnfAdapterService(restTemplate, multicloudConfiguration));
}
@@ -87,25 +87,17 @@ public class CnfAdapterServiceTest {
}
@Test(expected = EntityNotFoundException.class)
- public void testcreateInstanceHttpException() {
+ public void testcreateInstanceHttpException() throws BadResponseException {
doThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND)).when(restTemplate).exchange(ArgumentMatchers.anyString(),
ArgumentMatchers.any(HttpMethod.class), ArgumentMatchers.any(), ArgumentMatchers.<Class<String>>any());
- try {
- cnfAdapterService.createInstance(getBpmnInstanceRequest());
- } catch (IOException e) {
- e.printStackTrace();
- }
+ cnfAdapterService.createInstance(getBpmnInstanceRequest());
}
@Test(expected = HttpStatusCodeException.class)
- public void testcreateInstanceHttpStatusCodeException() {
+ public void testCreateInstanceHttpStatusCodeException() throws BadResponseException {
doThrow(new HttpServerErrorException(HttpStatus.CONFLICT)).when(restTemplate).exchange(ArgumentMatchers.anyString(),
ArgumentMatchers.any(HttpMethod.class), ArgumentMatchers.any(), ArgumentMatchers.<Class<String>>any());
- try {
- cnfAdapterService.createInstance(getBpmnInstanceRequest());
- } catch (IOException e) {
- e.printStackTrace();
- }
+ cnfAdapterService.createInstance(getBpmnInstanceRequest());
}
@Test
@@ -217,25 +209,17 @@ public class CnfAdapterServiceTest {
}
@Test(expected = EntityNotFoundException.class)
- public void testdeleteInstanceByInstanceIdHttpException() {
+ public void testdeleteInstanceByInstanceIdHttpException() throws BadResponseException {
doThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND)).when(restTemplate).exchange(ArgumentMatchers.anyString(),
ArgumentMatchers.any(HttpMethod.class), ArgumentMatchers.any(), ArgumentMatchers.<Class<String>>any());
- try {
- cnfAdapterService.deleteInstanceByInstanceId(INSTANCE_ID);
- } catch (IOException e) {
- e.printStackTrace();
- }
+ cnfAdapterService.deleteInstanceByInstanceId(INSTANCE_ID);
}
@Test(expected = HttpStatusCodeException.class)
- public void testdeleteInstanceByInstanceIdException() {
+ public void testDeleteInstanceByInstanceIdException() throws BadResponseException {
doThrow(new HttpServerErrorException(HttpStatus.CONFLICT)).when(restTemplate).exchange(ArgumentMatchers.anyString(),
ArgumentMatchers.any(HttpMethod.class), ArgumentMatchers.any(), ArgumentMatchers.<Class<String>>any());
- try {
- cnfAdapterService.deleteInstanceByInstanceId(INSTANCE_ID);
- } catch (IOException e) {
- e.printStackTrace();
- }
+ cnfAdapterService.deleteInstanceByInstanceId(INSTANCE_ID);
}
@Test
@@ -271,9 +255,9 @@ public class CnfAdapterServiceTest {
}
private BpmnInstanceRequest getBpmnInstanceRequest() {
- Map<String, String> labels = new HashMap<String, String>();
+ Map<String, String> labels = new HashMap<>();
labels.put("custom-label-1", "label1");
- Map<String, String> overrideValues = new HashMap<String, String>();
+ Map<String, String> overrideValues = new HashMap<>();
overrideValues.put("a", "b");
labels.put("image.tag", "latest");
labels.put("dcae_collector_ip", "1.2.3.4");
diff --git a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/aai/AaiIdGeneratorServiceTest.java b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/aai/AaiIdGeneratorServiceTest.java
index 70070e4..c79e29f 100644
--- a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/aai/AaiIdGeneratorServiceTest.java
+++ b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/aai/AaiIdGeneratorServiceTest.java
@@ -3,14 +3,18 @@ package org.onap.so.adapters.cnf.service.aai;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.onap.so.adapters.cnf.model.instantiation.AaiRequest;
+import org.onap.so.adapters.cnf.model.aai.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.K8sStatus;
+import org.onap.so.adapters.cnf.model.statuscheck.K8sStatusMetadata;
+import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+@SpringBootTest
@RunWith(SpringRunner.class)
public class AaiIdGeneratorServiceTest {
@@ -28,12 +32,16 @@ public class AaiIdGeneratorServiceTest {
String cloudRegion = "cloudRegion";
String tenantId = "tenantId";
K8sRbInstanceResourceStatus resourceStatus = mock(K8sRbInstanceResourceStatus.class);
+ K8sStatus status = mock(K8sStatus.class);
+ K8sStatusMetadata metadata = mock(K8sStatusMetadata.class);
AaiRequest aaiRequest = mock(AaiRequest.class);
K8sRbInstanceGvk gvk = mock(K8sRbInstanceGvk.class);
// when
when(resourceStatus.getGvk()).thenReturn(gvk);
when(resourceStatus.getName()).thenReturn(name);
+ when(resourceStatus.getStatus()).thenReturn(status);
+ when(status.getK8sStatusMetadata()).thenReturn(metadata);
when(gvk.getKind()).thenReturn(kind);
when(gvk.getGroup()).thenReturn(group);
when(gvk.getVersion()).thenReturn(version);
@@ -44,7 +52,7 @@ public class AaiIdGeneratorServiceTest {
// then
String actual = tested.generateId(resourceStatus, aaiRequest);
- String expected = "a1b2c1f3dd0c76d65c6dbe97b17e0239163bc2c08e8e88e167bb90de9c7b0da1";
+ String expected = "335d6ab87744a3140b36e70eee7537e97523b5e09f26d1d0ee887fd5839f87e2";
Assert.assertEquals(expected, actual);
}
diff --git a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/aai/AaiResponseParserTest.java b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/aai/AaiResponseParserTest.java
index f3c0558..ea7510a 100644
--- a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/aai/AaiResponseParserTest.java
+++ b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/aai/AaiResponseParserTest.java
@@ -1,3 +1,23 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2021 Samsung Electronics Co. Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
package org.onap.so.adapters.cnf.service.aai;
import org.junit.Assert;
@@ -5,15 +25,14 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.onap.so.adapters.cnf.model.instantiation.AaiRequest;
+import org.onap.so.adapters.cnf.model.aai.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.K8sStatus;
import org.onap.so.adapters.cnf.model.statuscheck.K8sStatusMetadata;
+import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
-import java.util.ArrayList;
-import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@@ -21,9 +40,13 @@ import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+@SpringBootTest
@RunWith(SpringRunner.class)
public class AaiResponseParserTest {
+ private final static String INSTANCE_ID = "k8splugin.io/rb-instance-id";
+ private final static String INSTANCE_ID_VALUE = "rb-instance-id_value";
+
@InjectMocks
private AaiResponseParser aaiResponseParser;
@@ -42,6 +65,7 @@ public class AaiResponseParserTest {
String namespace = "namespace";
Map<String, String> labelsMap = new HashMap<>();
labelsMap.put("key", "value");
+ labelsMap.put(INSTANCE_ID, INSTANCE_ID_VALUE);
K8sRbInstanceResourceStatus status = mock(K8sRbInstanceResourceStatus.class);
AaiRequest aaiRequest = mock(AaiRequest.class);
K8sRbInstanceGvk gvk = mock(K8sRbInstanceGvk.class);
@@ -63,7 +87,7 @@ public class AaiResponseParserTest {
when(metadata.getLabels()).thenReturn(labelsMap);
// then
- ParseResult actual = aaiResponseParser.parse(status, aaiRequest);
+ KubernetesResource actual = aaiResponseParser.parse(status, aaiRequest);
Assert.assertNotNull(actual);
assertEquals(id, actual.getId());
@@ -73,29 +97,8 @@ public class AaiResponseParserTest {
assertEquals(kind, actual.getKind());
assertEquals(namespace, actual.getNamespace());
assertEquals(2, actual.getLabels().size());
- assertEquals("http://so-cnf-adapter:8090/api/cnf-adapter/v1/instance/id/query", actual.getK8sResourceSelfLink());
-
- }
-
- ParseResult parse(K8sRbInstanceResourceStatus status, AaiRequest aaiRequest) {
- ParseResult result = new ParseResult();
- K8sRbInstanceGvk gvk = status.getGvk();
- K8sStatus k8sStatus = status.getStatus();
- K8sStatusMetadata metadata = k8sStatus.getK8sStatusMetadata();
- String id = aaiIdGeneratorService.generateId(status, aaiRequest);
- 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", aaiRequest.getInstanceId()));
- return result;
+ assertEquals("k8splugin.io/rb-instance-id=rb-instance-id_value", actual.getLabels().get(0));
+ assertEquals("key=value", actual.getLabels().get(1));
+ assertEquals("http://so-cnf-adapter:8090/api/cnf-adapter/v1/instance/id/query?ApiVersion=version&Kind=kind&Name=name&Namespace=namespace", actual.getSelflink());
}
-} \ No newline at end of file
+}
diff --git a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/aai/AaiServiceTest.java b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/aai/AaiServiceTest.java
index f8f9597..651b433 100644
--- a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/aai/AaiServiceTest.java
+++ b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/aai/AaiServiceTest.java
@@ -6,21 +6,22 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.onap.so.adapters.cnf.AaiConfiguration;
import org.onap.so.adapters.cnf.client.MulticloudClient;
-import org.onap.so.adapters.cnf.model.instantiation.AaiRequest;
+import org.onap.so.adapters.cnf.model.aai.AaiRequest;
import org.onap.so.adapters.cnf.model.statuscheck.K8sRbInstanceResourceStatus;
import org.onap.so.adapters.cnf.model.statuscheck.K8sRbInstanceStatus;
import org.onap.so.client.exception.BadResponseException;
+import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.ArrayList;
import java.util.List;
import static org.mockito.Mockito.atLeast;
-import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+@SpringBootTest
@RunWith(SpringRunner.class)
public class AaiServiceTest {
@@ -30,8 +31,6 @@ public class AaiServiceTest {
@Mock
private MulticloudClient multicloudClient;
@Mock
- private AaiRequestSender aaiRequestSender;
- @Mock
private AaiResponseParser responseParser;
@Mock
private AaiConfiguration aaiConfiguration;
@@ -45,8 +44,8 @@ public class AaiServiceTest {
K8sRbInstanceResourceStatus status = mock(K8sRbInstanceResourceStatus.class);
List<K8sRbInstanceResourceStatus> resourcesStatus = new ArrayList<>();
resourcesStatus.add(status);
- ParseResult parseResult = mock(ParseResult.class);
- List<ParseResult> parseResultList = new ArrayList<>();
+ KubernetesResource parseResult = mock(KubernetesResource.class);
+ List<KubernetesResource> parseResultList = new ArrayList<>();
parseResultList.add(parseResult);
// when
@@ -54,14 +53,11 @@ public class AaiServiceTest {
when(multicloudClient.getInstanceStatus(instanceId)).thenReturn(instanceStatus);
when(instanceStatus.getResourcesStatus()).thenReturn(resourcesStatus);
when(responseParser.parse(status, aaiRequest)).thenReturn(parseResult);
- when(aaiConfiguration.isEnabled()).thenReturn(true);
- doNothing().when(aaiRequestSender).sendUpdateRequestToAai(parseResult, aaiRequest);
// then
aaiServiceTested.aaiUpdate(aaiRequest);
verify(responseParser, atLeast(1)).parse(status, aaiRequest);
- verify(aaiRequestSender, atLeast(1)).sendUpdateRequestToAai(parseResult, aaiRequest);
}
@@ -74,22 +70,16 @@ public class AaiServiceTest {
K8sRbInstanceResourceStatus status = mock(K8sRbInstanceResourceStatus.class);
List<K8sRbInstanceResourceStatus> resourcesStatus = new ArrayList<>();
resourcesStatus.add(status);
- ParseResult parseResult = mock(ParseResult.class);
- List<ParseResult> parseResultList = new ArrayList<>();
+ KubernetesResource parseResult = mock(KubernetesResource.class);
+ List<KubernetesResource> parseResultList = new ArrayList<>();
parseResultList.add(parseResult);
// when
when(aaiRequest.getInstanceId()).thenReturn(instanceId);
when(multicloudClient.getInstanceStatus(instanceId)).thenReturn(instanceStatus);
when(instanceStatus.getResourcesStatus()).thenReturn(resourcesStatus);
- when(responseParser.parse(status, aaiRequest)).thenReturn(parseResult);
- when(aaiConfiguration.isEnabled()).thenReturn(true);
- doNothing().when(aaiRequestSender).sendUpdateRequestToAai(parseResult, aaiRequest);
// then
aaiServiceTested.aaiDelete(aaiRequest);
-
- verify(responseParser, atLeast(1)).parse(status, aaiRequest);
- verify(aaiRequestSender, atLeast(1)).sendDeleteRequestToAai(aaiRequest);
}
-} \ No newline at end of file
+}
diff --git a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/healthcheck/HealthCheckServiceTest.java b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/healthcheck/HealthCheckServiceTest.java
index 9a043ba..18dc656 100644
--- a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/healthcheck/HealthCheckServiceTest.java
+++ b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/healthcheck/HealthCheckServiceTest.java
@@ -1,81 +1,77 @@
package org.onap.so.adapters.cnf.service.healthcheck;
-import static java.util.Arrays.asList;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.jupiter.api.Assertions.*;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.UUID;
-
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
+import com.github.tomakehurst.wiremock.junit.WireMockRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
import org.onap.so.adapters.cnf.client.MulticloudClient;
import org.onap.so.adapters.cnf.model.CheckInstanceRequest;
import org.onap.so.adapters.cnf.model.InstanceRequest;
import org.onap.so.adapters.cnf.model.healthcheck.HealthCheckResponse;
import org.onap.so.adapters.cnf.model.healthcheck.K8sRbInstanceHealthCheck;
import org.onap.so.adapters.cnf.model.healthcheck.K8sRbInstanceHealthCheckSimple;
-import org.onap.so.client.exception.BadResponseException;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.util.UUID;
+
+import static java.util.Arrays.asList;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
-class HealthCheckServiceTest {
+@RunWith(SpringRunner.class)
+public class HealthCheckServiceTest {
+ private final int portNumber = 8443;
+ @Rule
+ public WireMockRule wireMockRule = new WireMockRule(portNumber);
@InjectMocks
- HealthCheckService healthCheckService;
+ private HealthCheckService healthCheckService;
@Mock
- MulticloudClient multicloudClient;
-
- @BeforeEach
- void setUp() {
- MockitoAnnotations.initMocks(this);
- }
+ private MulticloudClient multicloudClient;
@Test
- void healthCheckTest() {
+ public void healthCheckTest() {
try {
doReturn(getK8sRbInstanceHealthCheckSimple()).when(multicloudClient).startInstanceHealthCheck(any());
- doReturn(getK8sRbInstanceHealthCheck()).when(multicloudClient).getInstanceHealthCheck(any(),any());
+ doReturn(getK8sRbInstanceHealthCheck()).when(multicloudClient).getInstanceHealthCheck(any(), any());
HealthCheckResponse response = healthCheckService.healthCheck(getTestCheckInstanceRequest());
verify(multicloudClient, times(3)).startInstanceHealthCheck(any());
- verify(multicloudClient, times(3)).getInstanceHealthCheck(any(),any());
+ verify(multicloudClient, times(3)).getInstanceHealthCheck(any(), any());
assertThat(response.getInstanceResponse()).hasSize(getTestCheckInstanceRequest().getInstances().size());
} catch (Exception e) {
e.printStackTrace();
}
}
- private CheckInstanceRequest getTestCheckInstanceRequest(){
- CheckInstanceRequest checkInstanceRequest=new CheckInstanceRequest() ;
- checkInstanceRequest.setInstances(asList(getRandomInstance(),getRandomInstance(),getRandomInstance()));
+ private CheckInstanceRequest getTestCheckInstanceRequest() {
+ CheckInstanceRequest checkInstanceRequest = new CheckInstanceRequest();
+ checkInstanceRequest.setInstances(asList(getRandomInstance(), getRandomInstance(), getRandomInstance()));
return checkInstanceRequest;
}
- private InstanceRequest getRandomInstance(){
- InstanceRequest instanceRequest=new InstanceRequest();
+ private InstanceRequest getRandomInstance() {
+ InstanceRequest instanceRequest = new InstanceRequest();
instanceRequest.setInstanceId(UUID.randomUUID().toString());
return instanceRequest;
}
- private K8sRbInstanceHealthCheckSimple getK8sRbInstanceHealthCheckSimple(){
- K8sRbInstanceHealthCheckSimple k8sRbInstanceHealthCheckSimple=new K8sRbInstanceHealthCheckSimple();
+ private K8sRbInstanceHealthCheckSimple getK8sRbInstanceHealthCheckSimple() {
+ K8sRbInstanceHealthCheckSimple k8sRbInstanceHealthCheckSimple = new K8sRbInstanceHealthCheckSimple();
k8sRbInstanceHealthCheckSimple.setId(UUID.randomUUID().toString());
k8sRbInstanceHealthCheckSimple.setStatus("RUNNING");
return k8sRbInstanceHealthCheckSimple;
}
- private K8sRbInstanceHealthCheck getK8sRbInstanceHealthCheck(){
- K8sRbInstanceHealthCheck k8sRbInstanceHealthCheck=new K8sRbInstanceHealthCheck();
+ private K8sRbInstanceHealthCheck getK8sRbInstanceHealthCheck() {
+ K8sRbInstanceHealthCheck k8sRbInstanceHealthCheck = new K8sRbInstanceHealthCheck();
k8sRbInstanceHealthCheck.setStatus("STOPPED");
return k8sRbInstanceHealthCheck;
}
-} \ No newline at end of file
+}
diff --git a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/statuscheck/SimpleStatusCheckServiceTest.java b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/statuscheck/SimpleStatusCheckServiceTest.java
index f9fbe31..bd3d326 100644
--- a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/statuscheck/SimpleStatusCheckServiceTest.java
+++ b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/statuscheck/SimpleStatusCheckServiceTest.java
@@ -11,6 +11,7 @@ import org.onap.so.adapters.cnf.model.InstanceRequest;
import org.onap.so.adapters.cnf.model.statuscheck.K8sRbInstanceStatus;
import org.onap.so.adapters.cnf.model.statuscheck.StatusCheckResponse;
import org.onap.so.client.exception.BadResponseException;
+import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.ArrayList;
@@ -19,6 +20,7 @@ import java.util.List;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+@SpringBootTest
@RunWith(SpringRunner.class)
public class SimpleStatusCheckServiceTest {
diff --git a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/synchrornization/SubscriptionsRecoveryProvider.java b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/synchrornization/SubscriptionsRecoveryProvider.java
new file mode 100644
index 0000000..32feb78
--- /dev/null
+++ b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/synchrornization/SubscriptionsRecoveryProvider.java
@@ -0,0 +1,17 @@
+package org.onap.so.adapters.cnf.service.synchrornization;
+
+import org.onap.so.client.exception.BadResponseException;
+import org.springframework.context.annotation.Primary;
+import org.springframework.stereotype.Component;
+
+import java.util.Collections;
+import java.util.Set;
+
+@Component
+@Primary
+public class SubscriptionsRecoveryProvider {
+
+ public Set<String> getInstanceList() throws BadResponseException {
+ return Collections.emptySet();
+ }
+} \ No newline at end of file
diff --git a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/synchrornization/SynchronizationServiceTest.java b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/synchrornization/SynchronizationServiceTest.java
new file mode 100644
index 0000000..4a159bc
--- /dev/null
+++ b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/synchrornization/SynchronizationServiceTest.java
@@ -0,0 +1,96 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
+ * Modifications Copyright (C) 2021 Samsung Technologies Co.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.adapters.cnf.service.synchrornization;
+
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.onap.so.adapters.cnf.client.MulticloudClient;
+import org.onap.so.adapters.cnf.model.aai.AaiRequest;
+import org.onap.so.adapters.cnf.model.synchronization.SubscriptionRequest;
+import org.onap.so.client.exception.BadResponseException;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@RunWith(SpringRunner.class)
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class SynchronizationServiceTest {
+
+ private static final String INSTANCE_ID = "INSTANCE_ID";
+ private static final String SUFFIX = "-cnf-adapter";
+ private static final String SUBSCRIPTION_NAME = INSTANCE_ID + SUFFIX;
+
+ @InjectMocks
+ private SynchronizationService tested;
+
+ @Mock
+ private MulticloudClient multicloudClient;
+ @Captor
+ private ArgumentCaptor<SubscriptionRequest> subscriptionRequestCaptor;
+
+ @Test
+ public void shouldCreateSubscription() throws BadResponseException {
+ // given
+ String callbackUrl = "http://so-cnf-adapter:8090/api/cnf-adapter/v1/instance/INSTANCE_ID/status/notify";
+ AaiRequest aaiRequest = mock(AaiRequest.class);
+
+ // when
+ when(aaiRequest.getInstanceId()).thenReturn(INSTANCE_ID);
+
+ // then
+ tested.createSubscriptionIfNotExists(aaiRequest);
+
+ verify(multicloudClient).registerSubscription(eq(INSTANCE_ID), subscriptionRequestCaptor.capture());
+ SubscriptionRequest subscriptionRequest = subscriptionRequestCaptor.getValue();
+ assertEquals(SUBSCRIPTION_NAME, subscriptionRequest.getName());
+ assertEquals(callbackUrl, subscriptionRequest.getCallbackUrl());
+ assertEquals(30, subscriptionRequest.getMinNotifyInterval());
+ }
+
+ @Test
+ public void shouldGetSubscriptionName() {
+ // given
+ // when
+ // then
+ String actual = tested.getSubscriptionName(INSTANCE_ID);
+ assertEquals(SUBSCRIPTION_NAME, actual);
+ }
+
+ @Test
+ public void shouldCheckIfSubscriptionActive() {
+ // given
+ // when
+ // then
+ boolean subscriptionActive = tested.isSubscriptionActive(INSTANCE_ID);
+ assertFalse(subscriptionActive);
+ }
+} \ No newline at end of file
diff --git a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/upgrade/InstanceUpgradeServiceTest.java b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/upgrade/InstanceUpgradeServiceTest.java
new file mode 100644
index 0000000..e291538
--- /dev/null
+++ b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/upgrade/InstanceUpgradeServiceTest.java
@@ -0,0 +1,108 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
+ * Modifications Copyright (C) 2021 Samsung Technologies Co.
+ * Modifications Copyright (C) 2021 Orange.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.adapters.cnf.service.upgrade;
+
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.onap.so.adapters.cnf.client.MulticloudClient;
+import org.onap.so.adapters.cnf.model.MulticloudInstanceRequest;
+import org.onap.so.adapters.cnf.model.upgrade.InstanceUpgradeRequest;
+import org.onap.so.client.exception.BadResponseException;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@RunWith(SpringRunner.class)
+public class InstanceUpgradeServiceTest {
+
+ @InjectMocks
+ private InstanceUpgradeService tested;
+
+ @Mock
+ MulticloudClient instanceApi;
+
+ @Captor
+ ArgumentCaptor<MulticloudInstanceRequest> multicloudInstanceRequestCaptor;
+
+
+ @Test
+ public void shouldUpgradeInstanceSuccessfully() throws BadResponseException {
+ // given
+ String instanceId = "instanceId";
+ InstanceUpgradeRequest upgradeRequest = mock(InstanceUpgradeRequest.class);
+ String k8sRBProfileName = "k8sRBProfileName";
+ String modelInvariantId = "modelInvariantId";
+ String modelCustomizationId = "modelCustomizationId";
+ String cloudRegionId = "cloudRegionId";
+ Map<String, String> labels = mock(Map.class);
+ Map<String, String> overrideValues = mock(Map.class);
+ String response = "response";
+
+ // when
+ when(upgradeRequest.getK8sRBProfileName()).thenReturn(k8sRBProfileName);
+ when(upgradeRequest.getModelInvariantId()).thenReturn(modelInvariantId);
+ when(upgradeRequest.getModelCustomizationId()).thenReturn(modelCustomizationId);
+ when(upgradeRequest.getCloudRegionId()).thenReturn(cloudRegionId);
+ when(upgradeRequest.getLabels()).thenReturn(labels);
+ when(upgradeRequest.getOverrideValues()).thenReturn(overrideValues);
+ when(instanceApi.upgradeInstance(eq(instanceId), any(MulticloudInstanceRequest.class))).thenReturn(response);
+
+ // than
+ String actual = tested.upgradeInstance(instanceId, upgradeRequest);
+
+ assertEquals(actual, response);
+ verify(instanceApi).upgradeInstance(eq(instanceId), multicloudInstanceRequestCaptor.capture());
+ MulticloudInstanceRequest requestCaptureValue = multicloudInstanceRequestCaptor.getValue();
+ assertEquals(requestCaptureValue.getRbName(), modelInvariantId);
+ assertEquals(requestCaptureValue.getRbVersion(), modelCustomizationId);
+ assertEquals(requestCaptureValue.getProfileName(), k8sRBProfileName);
+ assertEquals(requestCaptureValue.getLabels(), labels);
+ assertEquals(requestCaptureValue.getOverrideValues(), overrideValues);
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void shouldThrowRuntimeExceptionWhenProfileNameIsNull() throws BadResponseException {
+ // given
+ String instanceId = "instanceId";
+ InstanceUpgradeRequest upgradeRequest = mock(InstanceUpgradeRequest.class);
+
+ // when
+ when(upgradeRequest.getK8sRBProfileName()).thenReturn(null);
+
+ // than
+
+ tested.upgradeInstance(instanceId, upgradeRequest);
+ }
+
+} \ No newline at end of file
diff --git a/so-cnf-adapter-application/src/test/resources/application.properties b/so-cnf-adapter-application/src/test/resources/application.properties
new file mode 100644
index 0000000..154283c
--- /dev/null
+++ b/so-cnf-adapter-application/src/test/resources/application.properties
@@ -0,0 +1,4 @@
+aai.enabled=true
+aai.endpoint=http://localhost:8443
+aai.auth=5E12ACACBD552A415E081E29F2C4772F9835792A51C766CCFDD7433DB5220B59969CB2798C
+mso.msoKey=07a7159d3bf51a0e53be7a8f89699be7 \ No newline at end of file
diff --git a/version.properties b/version.properties
index 326a100..50edce8 100644
--- a/version.properties
+++ b/version.properties
@@ -4,7 +4,7 @@
major=1
minor=9
-patch=0
+patch=2
base_version=${major}.${minor}.${patch}