aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeshu Kumar M <seshu.kumar.m@huawei.com>2020-08-27 04:28:36 +0000
committerGerrit Code Review <gerrit@onap.org>2020-08-27 04:28:36 +0000
commit2f307833ea41225b6e38255f0690174fad654953 (patch)
tree0a34b63c6c962712cbfdba099a2234e16e9e93d7
parent96f7bcf737cc10a3258b5c8cf11b5cc5fd1ee65c (diff)
parent577c10b380e795edeae4911a456a95e114a39caa (diff)
Merge "mso-cnf-adapter sample delete , update api's Issue-ID: SO-3183"
-rw-r--r--adapters/mso-cnf-adapter/pom.xml4
-rw-r--r--adapters/mso-cnf-adapter/src/main/java/org/onap/so/adapters/cnf/exceptions/ApplicationException.java66
-rw-r--r--adapters/mso-cnf-adapter/src/main/java/org/onap/so/adapters/cnf/model/BpmnInstanceRequest.java87
-rw-r--r--adapters/mso-cnf-adapter/src/main/java/org/onap/so/adapters/cnf/model/ErrorResponse.java63
-rw-r--r--adapters/mso-cnf-adapter/src/main/java/org/onap/so/adapters/cnf/model/MulticloudInstanceRequest.java (renamed from adapters/mso-cnf-adapter/src/main/java/org/onap/so/adapters/cnf/model/InstanceEntity.java)13
-rw-r--r--adapters/mso-cnf-adapter/src/main/java/org/onap/so/adapters/cnf/rest/CnfAdapterRest.java509
-rw-r--r--adapters/mso-cnf-adapter/src/main/java/org/onap/so/adapters/cnf/util/CNfAdapterUtil.java94
-rw-r--r--adapters/mso-cnf-adapter/src/test/java/org/onap/so/adapters/cnf/CnfAdapterRestTest.java62
8 files changed, 857 insertions, 41 deletions
diff --git a/adapters/mso-cnf-adapter/pom.xml b/adapters/mso-cnf-adapter/pom.xml
index fb25157a96..0928da084e 100644
--- a/adapters/mso-cnf-adapter/pom.xml
+++ b/adapters/mso-cnf-adapter/pom.xml
@@ -110,11 +110,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
- <!-- <dependency>
+ <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
- </dependency> -->
+ </dependency>
<!-- <dependency>
<groupId>org.onap.so</groupId>
<artifactId>mso-requests-db</artifactId>
diff --git a/adapters/mso-cnf-adapter/src/main/java/org/onap/so/adapters/cnf/exceptions/ApplicationException.java b/adapters/mso-cnf-adapter/src/main/java/org/onap/so/adapters/cnf/exceptions/ApplicationException.java
new file mode 100644
index 0000000000..c950cf6b2a
--- /dev/null
+++ b/adapters/mso-cnf-adapter/src/main/java/org/onap/so/adapters/cnf/exceptions/ApplicationException.java
@@ -0,0 +1,66 @@
+/*-
+ * ============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.exceptions;
+
+import static org.onap.so.adapters.cnf.util.CNfAdapterUtil.marshal;
+import org.onap.so.adapters.cnf.model.ErrorResponse;
+import org.springframework.http.ResponseEntity;
+
+public class ApplicationException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ private int errorCode;
+
+ private String errorMsg;
+
+ public ApplicationException(int errorCode, String errorMsg) {
+ this.errorCode = errorCode;
+ this.errorMsg = errorMsg;
+ }
+
+ public int getErrorCode() {
+ return errorCode;
+ }
+
+ public void setErrorCode(int errorCode) {
+ this.errorCode = errorCode;
+ }
+
+ public String getErrorMsg() {
+ return errorMsg;
+ }
+
+ public void setErrorMsg(String errorMsg) {
+ this.errorMsg = errorMsg;
+ }
+
+ public ResponseEntity buildErrorResponse() {
+ String message;
+ try {
+ ErrorResponse err = new ErrorResponse(errorCode, errorMsg);
+ message = marshal(err);
+ } catch (ApplicationException e) {
+ return ResponseEntity.status(500).body("Internal Server Error");
+ }
+ return ResponseEntity.status(errorCode).body(message);
+ }
+}
diff --git a/adapters/mso-cnf-adapter/src/main/java/org/onap/so/adapters/cnf/model/BpmnInstanceRequest.java b/adapters/mso-cnf-adapter/src/main/java/org/onap/so/adapters/cnf/model/BpmnInstanceRequest.java
new file mode 100644
index 0000000000..2e76d51da2
--- /dev/null
+++ b/adapters/mso-cnf-adapter/src/main/java/org/onap/so/adapters/cnf/model/BpmnInstanceRequest.java
@@ -0,0 +1,87 @@
+package org.onap.so.adapters.cnf.model;
+
+import java.util.Map;
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+@JsonIgnoreProperties(value = "true")
+public class BpmnInstanceRequest {
+
+ @JsonProperty(value = "modelInvariantId")
+ private String modelInvariantId;
+
+ @JsonProperty(value = "modelVersionId")
+ private String modelVersionId;
+
+ @JsonProperty(value = "k8sRBProfileName")
+ private String k8sRBProfileName;
+
+ @JsonProperty(value = "cloudRegionId")
+ private String cloudRegionId;
+
+ @JsonProperty(value = "vfModuleUUID")
+ private String vfModuleUUID;
+
+ @JsonProperty(value = "labels")
+ private Map<String, String> labels;
+
+ @JsonProperty(value = "overrideValues")
+ private Map<String, String> overrideValues;
+
+ public String getModelInvariantId() {
+ return modelInvariantId;
+ }
+
+ public void setModelInvariantId(String modelInvariantId) {
+ this.modelInvariantId = modelInvariantId;
+ }
+
+ public String getModelVersionId() {
+ return modelVersionId;
+ }
+
+ public void setModelVersionId(String modelVersionId) {
+ this.modelVersionId = modelVersionId;
+ }
+
+ public String getK8sRBProfileName() {
+ return k8sRBProfileName;
+ }
+
+ public void setK8sRBProfileName(String k8sRBProfileName) {
+ this.k8sRBProfileName = k8sRBProfileName;
+ }
+
+ 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;
+ }
+
+}
diff --git a/adapters/mso-cnf-adapter/src/main/java/org/onap/so/adapters/cnf/model/ErrorResponse.java b/adapters/mso-cnf-adapter/src/main/java/org/onap/so/adapters/cnf/model/ErrorResponse.java
new file mode 100644
index 0000000000..135adcc143
--- /dev/null
+++ b/adapters/mso-cnf-adapter/src/main/java/org/onap/so/adapters/cnf/model/ErrorResponse.java
@@ -0,0 +1,63 @@
+/*-
+ * ============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;
+
+public class ErrorResponse {
+
+ private int status;
+
+ private String error;
+
+ private String message;
+
+ public ErrorResponse(int status, String message) {
+ this.status = status;
+ this.message = message;
+ this.error = "Bad Request";
+ }
+
+ public int getStatus() {
+ return status;
+ }
+
+ public void setStatus(int status) {
+ this.status = status;
+ }
+
+ public String getError() {
+ if (status == 500) {
+ this.error = "Internal Server Error";
+ }
+ return error;
+ }
+
+ public void setError(String error) {
+ this.error = error;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+}
diff --git a/adapters/mso-cnf-adapter/src/main/java/org/onap/so/adapters/cnf/model/InstanceEntity.java b/adapters/mso-cnf-adapter/src/main/java/org/onap/so/adapters/cnf/model/MulticloudInstanceRequest.java
index 04f2f9d030..b1719cbd7d 100644
--- a/adapters/mso-cnf-adapter/src/main/java/org/onap/so/adapters/cnf/model/InstanceEntity.java
+++ b/adapters/mso-cnf-adapter/src/main/java/org/onap/so/adapters/cnf/model/MulticloudInstanceRequest.java
@@ -5,7 +5,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
@JsonIgnoreProperties(value = "true")
-public class InstanceEntity {
+public class MulticloudInstanceRequest {
@JsonProperty(value = "cloud-region")
private String cloudRegion;
@@ -25,6 +25,9 @@ public class InstanceEntity {
@JsonProperty(value = "override-values")
private Map<String, String> overrideValues;
+ @JsonProperty(value = "release-name")
+ private String vfModuleUuid;
+
public String getCloudRegion() {
return cloudRegion;
}
@@ -73,4 +76,12 @@ public class InstanceEntity {
this.overrideValues = overrideValues;
}
+ public String getVfModuleUuid() {
+ return vfModuleUuid;
+ }
+
+ public void setVfModuleUuid(String vfModuleUuid) {
+ this.vfModuleUuid = vfModuleUuid;
+ }
+
}
diff --git a/adapters/mso-cnf-adapter/src/main/java/org/onap/so/adapters/cnf/rest/CnfAdapterRest.java b/adapters/mso-cnf-adapter/src/main/java/org/onap/so/adapters/cnf/rest/CnfAdapterRest.java
index 952edef7f6..b6d50da557 100644
--- a/adapters/mso-cnf-adapter/src/main/java/org/onap/so/adapters/cnf/rest/CnfAdapterRest.java
+++ b/adapters/mso-cnf-adapter/src/main/java/org/onap/so/adapters/cnf/rest/CnfAdapterRest.java
@@ -1,27 +1,39 @@
package org.onap.so.adapters.cnf.rest;
+import java.io.File;
+import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
+import org.apache.http.entity.mime.HttpMultipartMode;
+import org.apache.http.entity.mime.MultipartEntityBuilder;
+import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
+import org.onap.so.adapters.cnf.model.BpmnInstanceRequest;
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.InstanceEntity;
+import org.onap.so.adapters.cnf.model.MulticloudInstanceRequest;
import org.onap.so.adapters.cnf.model.ProfileEntity;
import org.onap.so.adapters.cnf.model.ResourceBundleEntity;
+import org.onap.so.adapters.cnf.model.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
@@ -32,14 +44,14 @@ public class CnfAdapterRest {
private final CloseableHttpClient httpClient = HttpClients.createDefault();
@ResponseBody
- @RequestMapping(value = {"/api/multicloud-k8s/v1/healthcheck"}, method = RequestMethod.GET,
+ @RequestMapping(value = {"/api/cnf-adapter/v1/healthcheck"}, method = RequestMethod.GET,
produces = "application/json")
public String healthCheck() throws Exception {
logger.info("health check called.");
// TODO
- HttpGet req = new HttpGet("https://localhost:32780/api/multicloud-k8s/v1/healthcheck");
+ HttpGet req = new HttpGet("http://172.17.0.2:31770/v1/healthcheck");
try (CloseableHttpResponse response = httpClient.execute(req)) {
logger.info("response:" + response.getEntity());
return EntityUtils.toString(response.getEntity());
@@ -47,7 +59,7 @@ public class CnfAdapterRest {
}
@ResponseBody
- @RequestMapping(value = {"/api/multicloud-k8s/v1/v1/rb/definition"}, method = RequestMethod.POST,
+ @RequestMapping(value = {"/api/cnf-adapter/v1/v1/rb/definition"}, method = RequestMethod.POST,
produces = "application/json")
public String createRB(@RequestBody ResourceBundleEntity rB) throws Exception {
@@ -55,7 +67,7 @@ public class CnfAdapterRest {
// TODO
// Below URL should be changed as appropriate multicloud URL.
- HttpPost post = new HttpPost("https://localhost:32780/api/multicloud-k8s/v1/v1/rb/definition");
+ HttpPost post = new HttpPost("http://172.17.0.2:31770/v1/rb/definition");
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
String requestBody = objectMapper.writeValueAsString(rB);
@@ -70,8 +82,8 @@ public class CnfAdapterRest {
}
@ResponseBody
- @RequestMapping(value = {"/api/multicloud-k8s/v1/v1/rb/definition/{rb-name}/{rb-version}"},
- method = RequestMethod.GET, produces = "application/json")
+ @RequestMapping(value = {"/api/cnf-adapter/v1/v1/rb/definition/{rb-name}/{rb-version}"}, method = RequestMethod.GET,
+ produces = "application/json")
public String getRB(@PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion)
throws Exception {
@@ -79,16 +91,101 @@ public class CnfAdapterRest {
// TODO
// Below URL should be changed as appropriate multicloud URL.
- HttpGet req = new HttpGet(
- "https://localhost:32780/api/multicloud-k8s/v1/v1/rb/definition/" + rbName + "/" + rbVersion);
+ HttpGet req = new HttpGet("http://172.17.0.2:31770/v1/rb/definition/" + rbName + "/" + rbVersion);
+ try (CloseableHttpResponse response = httpClient.execute(req)) {
+ logger.info("response:" + response.getEntity());
+ return EntityUtils.toString(response.getEntity());
+ }
+ }
+
+ @ResponseBody
+ @RequestMapping(value = {"/api/cnf-adapter/v1/v1/rb/definition/{rb-name}/{rb-version}"},
+ method = RequestMethod.DELETE, produces = "application/json")
+ public String deleteRB(@PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion)
+ throws Exception {
+
+ logger.info("delete RB called.");
+
+ // TODO
+ // Below URL should be changed as appropriate multicloud URL.
+ HttpDelete req = new HttpDelete("http://172.17.0.2:31770/v1/rb/definition/" + rbName + "/" + rbVersion);
+
+ try (CloseableHttpResponse response = httpClient.execute(req)) {
+ logger.info("response:" + response.getEntity());
+ return EntityUtils.toString(response.getEntity());
+ }
+
+ }
+
+ @ResponseBody
+ @RequestMapping(value = {"/api/cnf-adapter/v1/v1/rb/definition/{rb-name}"}, method = RequestMethod.GET,
+ produces = "application/json")
+ public String getListOfRB(@PathVariable("rb-name") String rbName) throws Exception {
+
+ logger.info("getListOfRB called.");
+
+ // TODO
+ // Below URL should be changed as appropriate multicloud URL.
+ HttpGet req = new HttpGet("http://172.17.0.2:31770/v1/rb/definition/" + rbName);
+
+ try (CloseableHttpResponse response = httpClient.execute(req)) {
+ logger.info("response:" + response.getEntity());
+ return EntityUtils.toString(response.getEntity());
+ }
+
+ }
+
+ @ResponseBody
+ @RequestMapping(value = {"/api/cnf-adapter/v1/v1/rb/definition"}, method = RequestMethod.GET,
+ produces = "application/json")
+ public String getListOfRBWithoutUsingRBName() throws Exception {
+
+ logger.info("getListOfRBWithoutUsingRBName called.");
+
+ // TODO
+ // Below URL should be changed as appropriate multicloud URL.
+ HttpGet req = new HttpGet("http://172.17.0.2:31770/v1/rb/definition");
+
try (CloseableHttpResponse response = httpClient.execute(req)) {
logger.info("response:" + response.getEntity());
return EntityUtils.toString(response.getEntity());
}
+
}
@ResponseBody
- @RequestMapping(value = {"/api/multicloud-k8s/v1/v1/rb/definition/{rb-name}/{rb-version}/profile"},
+ @RequestMapping(value = {"/api/cnf-adapter/v1/v1/rb/definition/{rb-name}/{rb-version}/content"},
+ method = RequestMethod.POST, produces = "multipart/form-data")
+ public String uploadArtifactForRB(@RequestParam("file") MultipartFile file, @PathVariable("rb-name") String rbName,
+ @PathVariable("rb-version") String rbVersion) throws Exception {
+
+ logger.info("Upload Artifact For RB called.");
+
+ File convFile = new File(file.getOriginalFilename());
+ file.transferTo(convFile);
+ FileBody fileBody = new FileBody(convFile, ContentType.DEFAULT_BINARY);
+ MultipartEntityBuilder builder = MultipartEntityBuilder.create();
+ builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
+ builder.addPart("file", fileBody);
+ HttpEntity entity = builder.build();
+
+ // TODO
+ // Below URL should be changed as appropriate multicloud URL.
+ HttpPost post =
+ new HttpPost("http://172.17.0.2:31770/v1/rb/definition/" + rbName + "/" + rbVersion + "/content");
+ post.setHeader("Content-Type", "multipart/form-data");
+ logger.info(String.valueOf(post));
+ post.setEntity(entity);
+
+ try (CloseableHttpClient httpClient = HttpClients.createDefault();
+ CloseableHttpResponse response = httpClient.execute(post)) {
+ logger.info("response:" + response.getEntity());
+ return EntityUtils.toString(response.getEntity());
+ }
+ }
+
+ @ResponseBody
+ @RequestMapping(value = {"/api/cnf-adapter/v1/v1/rb/definition/{rb-name}/{rb-version}/profile"},
method = RequestMethod.POST, produces = "application/json")
public String createProfile(@RequestBody ProfileEntity fE, @PathVariable("rb-name") String rbName,
@PathVariable("rb-version") String rbVersion) throws Exception {
@@ -97,8 +194,8 @@ public class CnfAdapterRest {
// TODO
// Below URL should be changed as appropriate multicloud URL.
- HttpPost post = new HttpPost("http://localhost:32780/api/multicloud-k8s/v1/v1/rb/definition/" + rbName + "/"
- + rbVersion + "/profile");
+ HttpPost post =
+ new HttpPost("http://172.17.0.2:31770/v1/rb/definition/" + rbName + "/" + rbVersion + "/profile");
ObjectMapper objectMapper = new ObjectMapper();
String requestBody = objectMapper.writeValueAsString(fE);
StringEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
@@ -112,7 +209,7 @@ public class CnfAdapterRest {
}
@ResponseBody
- @RequestMapping(value = {"/api/multicloud-k8s/v1/v1/rb/definition/{rb-name}/{rb-version}/profile/{pr-name}"},
+ @RequestMapping(value = {"/api/cnf-adapter/v1/v1/rb/definition/{rb-name}/{rb-version}/profile/{pr-name}"},
method = RequestMethod.GET, produces = "application/json")
public String getProfile(@PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion,
@PathVariable("pr-name") String prName) throws Exception {
@@ -121,8 +218,8 @@ public class CnfAdapterRest {
// TODO
// Below URL should be changed as appropriate multicloud URL.
- HttpGet req = new HttpGet("https://localhost:32780/api/multicloud-k8s/v1/v1/rb/definition/" + rbName + "/"
- + rbVersion + "/profile/" + prName);
+ HttpGet req = new HttpGet(
+ "http://172.17.0.2:31770/v1/rb/definition/" + rbName + "/" + rbVersion + "/profile/" + prName);
try (CloseableHttpResponse response = httpClient.execute(req)) {
logger.info("response:" + response.getEntity());
@@ -131,18 +228,130 @@ public class CnfAdapterRest {
}
@ResponseBody
- @RequestMapping(value = {"/api/multicloud-k8s/v1/v1/instance"}, method = RequestMethod.POST,
+ @RequestMapping(value = {"/api/cnf-adapter/v1/v1/rb/definition/{rb-name}/{rb-version}/profile"},
+ method = RequestMethod.GET, produces = "application/json")
+ public String getListOfProfile(@PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion)
+ throws Exception {
+
+ logger.info("getListOfProfile called.");
+
+ // TODO
+ // Below URL should be changed as appropriate multicloud URL.
+ HttpGet req = new HttpGet("http://172.17.0.2:31770/v1/rb/definition/" + rbName + "/" + rbVersion + "/profile");
+
+ try (CloseableHttpResponse response = httpClient.execute(req)) {
+ logger.info("response:" + response.getEntity());
+ return EntityUtils.toString(response.getEntity());
+ }
+ }
+
+ @ResponseBody
+ @RequestMapping(value = {"/api/cnf-adapter/v1/v1/rb/definition/{rb-name}/{rb-version}/profile/{pr-name}"},
+ method = RequestMethod.DELETE, produces = "application/json")
+ public String deleteProfile(@PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion,
+ @PathVariable("pr-name") String prName) throws Exception {
+
+ logger.info("delete Profile called.");
+
+ // TODO
+ // Below URL should be changed as appropriate multicloud URL.
+ HttpDelete req = new HttpDelete(
+ "http://172.17.0.2:31770/v1/rb/definition/" + rbName + "/" + rbVersion + "/profile/" + prName);
+
+ try (CloseableHttpResponse response = httpClient.execute(req)) {
+ logger.info("response:" + response.getEntity());
+ return EntityUtils.toString(response.getEntity());
+ }
+
+ }
+
+ @ResponseBody
+ @RequestMapping(value = {"/api/cnf-adapter/v1/v1/rb/definition/{rb-name}/{rb-version}/profile/{pr-name}/content"},
+ method = RequestMethod.POST, produces = "multipart/form-data")
+ public String uploadArtifactForProfile(@RequestParam("file") MultipartFile file,
+ @PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion,
+ @PathVariable("pr-name") String prName) throws Exception {
+
+ logger.info("Upload Artifact For Profile called.");
+
+ File convFile = new File(file.getOriginalFilename());
+ file.transferTo(convFile);
+ FileBody fileBody = new FileBody(convFile, ContentType.DEFAULT_BINARY);
+ MultipartEntityBuilder builder = MultipartEntityBuilder.create();
+ builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
+ builder.addPart("file", fileBody);
+ HttpEntity entity = builder.build();
+
+ // TODO
+ // Below URL should be changed as appropriate multicloud URL.
+ HttpPost post = new HttpPost("http://172.17.0.2:31770/v1/rb/definition/" + rbName + "/" + rbVersion
+ + "/profile/" + prName + "/content");
+ post.setHeader("Content-Type", "multipart/form-data");
+
+ logger.info(String.valueOf(post));
+ post.setEntity(entity);
+
+ try (CloseableHttpClient httpClient = HttpClients.createDefault();
+ CloseableHttpResponse response = httpClient.execute(post)) {
+ logger.info("response:" + response.getEntity());
+ return EntityUtils.toString(response.getEntity());
+ }
+ }
+
+ @ResponseBody
+ @RequestMapping(value = {"/api/cnf-adapter/v1/v1/instance"}, method = RequestMethod.POST,
produces = "application/json")
- public String createInstance(@RequestBody InstanceEntity iE) throws Exception {
+ public String createInstance(@RequestBody BpmnInstanceRequest bpmnInstanceRequest) throws Exception {
logger.info("create Instance called.");
+ MulticloudInstanceRequest multicloudInstanceRequest = new MulticloudInstanceRequest();
+
+ if (bpmnInstanceRequest.getK8sRBProfileName() != null) {
+ multicloudInstanceRequest.setCloudRegion(bpmnInstanceRequest.getCloudRegionId());
+ multicloudInstanceRequest.setLabels(bpmnInstanceRequest.getLabels());
+ multicloudInstanceRequest.setOverrideValues(bpmnInstanceRequest.getOverrideValues());
+ multicloudInstanceRequest.setProfileName(bpmnInstanceRequest.getK8sRBProfileName());
+ multicloudInstanceRequest.setRbName(bpmnInstanceRequest.getModelInvariantId());
+ multicloudInstanceRequest.setRbVersion(bpmnInstanceRequest.getModelVersionId());
+ multicloudInstanceRequest.setVfModuleUuid(bpmnInstanceRequest.getVfModuleUUID());
+ } else {
+
+ logger.info("K8sRBProfileName is required");
+ return "K8sRBProfileName is required";
+ }
+
// TODO
// Below URL should be changed as appropriate multicloud URL.
- HttpPost post = new HttpPost("https://localhost:32780/api/multicloud-k8s/v1/v1/instance");
+ HttpPost post = new HttpPost("http://172.17.0.2:31770/v1/instance");
+ ObjectMapper objectMapper = new ObjectMapper();
+
+ String requestBody = objectMapper.writeValueAsString(multicloudInstanceRequest);
+ StringEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
+ post.setEntity(requestEntity);
+
+ try (CloseableHttpClient httpClient = HttpClients.createDefault();
+ CloseableHttpResponse response = httpClient.execute(post)) {
+ logger.info("response:" + response.getEntity());
+ return EntityUtils.toString(response.getEntity());
+ }
+ }
+
+ // This api is not enabled in multicloud project ,but this is required in
+ // future.
+ @ResponseBody
+ @RequestMapping(value = {"/api/cnf-adapter/v1/v1/instance/{vnfInstanceId}"}, method = RequestMethod.PUT,
+ produces = "application/json")
+ public String updateInstance(@RequestBody MulticloudInstanceRequest iE,
+ @PathVariable("vnfInstanceId") String instanceId) throws Exception {
+
+ logger.info("create Instance called.");
+
+ // TODO
+ // Below URL should be changed as appropriate multicloud URL.
+ HttpPut post = new HttpPut("http://172.17.0.2:31770/v1/instance/" + instanceId);
ObjectMapper objectMapper = new ObjectMapper();
- objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
String requestBody = objectMapper.writeValueAsString(iE);
StringEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
post.setEntity(requestEntity);
@@ -155,14 +364,15 @@ public class CnfAdapterRest {
}
@ResponseBody
- @RequestMapping(value = {"/api/multicloud-k8s/v1/v1/instance/{instID}"}, method = RequestMethod.GET,
+ @RequestMapping(value = {"/api/cnf-adapter/v1/v1/instance/{instID}"}, method = RequestMethod.GET,
produces = "application/json")
public String getInstance(@PathVariable("instID") String instanceId) throws Exception {
logger.info("get Instance called.");
+
// TODO
// Below URL should be changed as appropriate multicloud URL.
- HttpGet req = new HttpGet("https://localhost:32780/api/multicloud-k8s/v1/v1/instance/" + instanceId);
+ HttpGet req = new HttpGet("http://172.17.0.2:31770/v1/instance/" + instanceId);
try (CloseableHttpResponse response = httpClient.execute(req)) {
logger.info("response:" + response.getEntity());
@@ -171,8 +381,62 @@ public class CnfAdapterRest {
}
@ResponseBody
- @RequestMapping(
- value = {"/api/multicloud-k8s/v1/v1/definition/{rb-name}/{rb-version}/profile/{profile-name}/config"},
+ @RequestMapping(value = {"/api/cnf-adapter/v1/v1/instance/{instID}/status"}, method = RequestMethod.GET,
+ produces = "application/json")
+ public String getInstanceStatus(@PathVariable("instID") String instanceId) throws Exception {
+
+ logger.info("getInstanceStatus called.");
+
+ // TODO
+ // Below URL should be changed as appropriate multicloud URL.
+ HttpGet req = new HttpGet("http://172.17.0.2:31770/v1/instance/" + instanceId + "/status");
+
+ try (CloseableHttpResponse response = httpClient.execute(req)) {
+ logger.info("response:" + response.getEntity());
+ return EntityUtils.toString(response.getEntity());
+ }
+ }
+
+ @RequestMapping(value = {"/api/cnf-adapter/v1/v1/instance"}, method = RequestMethod.GET,
+ produces = "application/json")
+ public String getInstanceBasedOnRBNameOrRBVersionOrProfileName(
+ @RequestParam(value = "rb-name", required = false) String rbName,
+ @RequestParam(value = "rb-version", required = false) String rbVersion,
+ @RequestParam(value = "profile-name", required = false) String profileName) throws Exception {
+
+ logger.info("getInstanceBasedOnRBNameOrRBVersionOrProfileName called.");
+
+ // TODO
+ // Below URL should be changed as appropriate multicloud URL.
+ HttpGet req = new HttpGet("http://172.17.0.2:31770/v1/instance?rb-name=" + rbName + "&rb-version=" + rbVersion
+ + "&profile-name=" + profileName);
+
+ try (CloseableHttpResponse response = httpClient.execute(req)) {
+ logger.info("response:" + response.getEntity());
+ return EntityUtils.toString(response.getEntity());
+ }
+ }
+
+ @ResponseBody
+ @RequestMapping(value = {"/api/cnf-adapter/v1/v1/instance/{instID}"}, method = RequestMethod.DELETE,
+ produces = "application/json")
+ public String deleteInstance(@PathVariable("instID") String instanceID) throws Exception {
+
+ logger.info("delete Instance called.");
+
+ // TODO
+ // Below URL should be changed as appropriate multicloud URL.
+ HttpDelete req = new HttpDelete("http://172.17.0.2:31770/v1/instance/" + instanceID);
+
+ try (CloseableHttpResponse response = httpClient.execute(req)) {
+ logger.info("response:" + response.getEntity());
+ return EntityUtils.toString(response.getEntity());
+ }
+
+ }
+
+ @ResponseBody
+ @RequestMapping(value = {"/api/cnf-adapter/v1/v1/definition/{rb-name}/{rb-version}/profile/{profile-name}/config"},
method = RequestMethod.POST, produces = "application/json")
public String createConfiguration(@RequestBody ConfigurationEntity cE, @PathVariable("rb-name") String rbName,
@PathVariable("rb-version") String rbVersion, @PathVariable("profile-name") String prName)
@@ -182,8 +446,8 @@ public class CnfAdapterRest {
// TODO
// Below URL should be changed as appropriate multicloud URL.
- HttpPost post = new HttpPost("https://localhost:32780/api/multicloud-k8s/v1/v1/definition/" + rbName + "/"
- + rbVersion + "/profile/" + prName + "/config");
+ HttpPost post = new HttpPost(
+ "http://172.17.0.2:31770/v1/definition/" + rbName + "/" + rbVersion + "/profile/" + prName + "/config");
ObjectMapper objectMapper = new ObjectMapper();
String requestBody = objectMapper.writeValueAsString(cE);
StringEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
@@ -198,7 +462,7 @@ public class CnfAdapterRest {
@ResponseBody
@RequestMapping(value = {
- "/api/multicloud-k8s/v1/v1/definition/{rb-name}/{rb-version}/profile/{profile-name}/config/{cfg-name}"},
+ "/api/cnf-adapter/v1/v1/definition/{rb-name}/{rb-version}/profile/{profile-name}/config/{cfg-name}"},
method = RequestMethod.GET, produces = "application/json")
public String getConfiguration(@PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion,
@PathVariable("profile-name") String prName, @PathVariable("cfg-name") String cfgName) throws Exception {
@@ -207,8 +471,8 @@ public class CnfAdapterRest {
// TODO
// Below URL should be changed as appropriate multicloud URL.
- HttpGet req = new HttpGet("https://localhost:32780/api/multicloud-k8s/v1/v1/definition/" + rbName + "/"
- + rbVersion + "/profile/" + prName + "/config/" + cfgName);
+ HttpGet req = new HttpGet("http://172.17.0.2:31770/v1/definition/" + rbName + "/" + rbVersion + "/profile/"
+ + prName + "/config/" + cfgName);
try (CloseableHttpResponse response = httpClient.execute(req)) {
logger.info("response:" + response.getEntity());
@@ -217,7 +481,79 @@ public class CnfAdapterRest {
}
@ResponseBody
- @RequestMapping(value = {"/api/multicloud-k8s/v1/v1/connectivity-info"}, method = RequestMethod.POST,
+ @RequestMapping(value = {
+ "/api/cnf-adapter/v1/v1/definition/{rb-name}/{rb-version}/profile/{profile-name}/config/{cfg-name}"},
+ method = RequestMethod.DELETE, produces = "application/json")
+ public String deleteConfiguration(@PathVariable("rb-name") String rbName,
+ @PathVariable("rb-version") String rbVersion, @PathVariable("profile-name") String prName,
+ @PathVariable("cfg-name") String cfgName) throws Exception {
+
+ logger.info("delete Configuration called.");
+
+ // TODO
+ // Below URL should be changed as appropriate multicloud URL.
+ HttpDelete req = new HttpDelete("http://172.17.0.2:31770/v1/definition/" + rbName + "/" + rbVersion
+ + "/profile/" + prName + "/config/" + cfgName);
+
+ try (CloseableHttpResponse response = httpClient.execute(req)) {
+ logger.info("response:" + response.getEntity());
+ return EntityUtils.toString(response.getEntity());
+ }
+
+ }
+
+ @ResponseBody
+ @RequestMapping(value = {
+ "/api/cnf-adapter/v1/v1/definition/{rb-name}/{rb-version}/profile/{profile-name}/config/{cfg-name}"},
+ method = RequestMethod.PUT, produces = "application/json")
+ public String updateConfiguration(@RequestBody ConfigurationEntity cE, @PathVariable("rb-name") String rbName,
+ @PathVariable("rb-version") String rbVersion, @PathVariable("profile-name") String prName,
+ @PathVariable("cfg-name") String cfgName) throws Exception {
+
+ logger.info("update Configuration called.");
+
+ // TODO
+ // Below URL should be changed as appropriate multicloud URL.
+ HttpPut post = new HttpPut("http://172.17.0.2:31770/v1/definition/" + rbName + "/" + rbVersion + "/profile/"
+ + prName + "/config/" + cfgName);
+ ObjectMapper objectMapper = new ObjectMapper();
+ String requestBody = objectMapper.writeValueAsString(cE);
+ StringEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
+ post.setEntity(requestEntity);
+
+ try (CloseableHttpClient httpClient = HttpClients.createDefault();
+ CloseableHttpResponse response = httpClient.execute(post)) {
+ logger.info("response:" + response.getEntity());
+ return EntityUtils.toString(response.getEntity());
+ }
+ }
+
+ @ResponseBody
+ @RequestMapping(value = {"/api/cnf-adapter/v1/v1/definition/{rb-name}/{rb-version}/profile/{profile-name}/tagit"},
+ method = RequestMethod.POST, produces = "application/json")
+ public String tagConfigurationValue(@RequestBody Tag tag, @PathVariable("rb-name") String rbName,
+ @PathVariable("rb-version") String rbVersion, @PathVariable("pr-name") String prName) throws Exception {
+ logger.info("Tag Configuration called.");
+
+ // TODO
+ // Below URL should be changed as appropriate multicloud URL.
+ HttpPost post = new HttpPost("http://172.17.0.2:31770/v1/definition/" + rbName + "/" + rbVersion + "/profile/"
+ + prName + "/config/tagit");
+
+ ObjectMapper objectMapper = new ObjectMapper();
+ String requestBody = objectMapper.writeValueAsString(tag);
+ StringEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
+ post.setEntity(requestEntity);
+
+ try (CloseableHttpClient httpClient = HttpClients.createDefault();
+ CloseableHttpResponse response = httpClient.execute(post)) {
+ logger.info("response:" + response.getEntity());
+ return EntityUtils.toString(response.getEntity());
+ }
+ }
+
+ @ResponseBody
+ @RequestMapping(value = {"/api/cnf-adapter/v1/v1/connectivity-info"}, method = RequestMethod.POST,
produces = "application/json")
public String createConnectivityInfo(@RequestBody ConnectivityInfo cIE) throws Exception {
@@ -225,7 +561,7 @@ public class CnfAdapterRest {
// TODO
// Below URL should be changed as appropriate multicloud URL.
- HttpPost post = new HttpPost("https://localhost:32780/api/multicloud-k8s/v1/v1/connectivity-info");
+ HttpPost post = new HttpPost("http://172.17.0.2:31770/v1/connectivity-info");
ObjectMapper objectMapper = new ObjectMapper();
String requestBody = objectMapper.writeValueAsString(cIE);
StringEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
@@ -239,7 +575,7 @@ public class CnfAdapterRest {
}
@ResponseBody
- @RequestMapping(value = {"/api/multicloud-k8s/v1/v1/connectivity-info/{connname}"}, method = RequestMethod.GET,
+ @RequestMapping(value = {"/api/cnf-adapter/v1/v1/connectivity-info/{connname}"}, method = RequestMethod.GET,
produces = "application/json")
public String getConnectivityInfo(@PathVariable("connname") String connName) throws Exception {
@@ -247,7 +583,7 @@ public class CnfAdapterRest {
// TODO
// Below URL should be changed as appropriate multicloud URL.
- HttpGet req = new HttpGet("https://localhost:32780/api/multicloud-k8s/v1/v1/connectivity-info/" + connName);
+ HttpGet req = new HttpGet("http://172.17.0.2:31770/v1/connectivity-info/" + connName);
try (CloseableHttpResponse response = httpClient.execute(req)) {
logger.info("response:" + response.getEntity());
@@ -256,7 +592,25 @@ public class CnfAdapterRest {
}
@ResponseBody
- @RequestMapping(value = {"/api/multicloud-k8s/v1/v1/rb/definition/{rb-name}/{rb-version}/config-template"},
+ @RequestMapping(value = {"/api/cnf-adapter/v1/v1/connectivity-info/{connname}"}, method = RequestMethod.DELETE,
+ produces = "application/json")
+ public String deleteConnectivityInfo(@PathVariable("connname") String connName) throws Exception {
+
+ logger.info("delete Connectivity Info called.");
+
+ // TODO
+ // Below URL should be changed as appropriate multicloud URL.
+ HttpDelete req = new HttpDelete("http://172.17.0.2:31770/v1/connectivity-info/" + connName);
+
+ try (CloseableHttpResponse response = httpClient.execute(req)) {
+ logger.info("response:" + response.getEntity());
+ return EntityUtils.toString(response.getEntity());
+ }
+
+ }
+
+ @ResponseBody
+ @RequestMapping(value = {"/api/cnf-adapter/v1/v1/rb/definition/{rb-name}/{rb-version}/config-template"},
method = RequestMethod.POST, produces = "application/json")
public String createConfigTemplate(@RequestBody ConfigTemplateEntity tE, @PathVariable("rb-name") String rbName,
@PathVariable("rb-version") String rbVersion) throws Exception {
@@ -265,8 +619,8 @@ public class CnfAdapterRest {
// TODO
// Below URL should be changed as appropriate multicloud URL.
- HttpPost post = new HttpPost("http://localhost:32780/api/multicloud-k8s/v1/v1/rb/definition/" + rbName + "/"
- + rbVersion + "/config-template");
+ HttpPost post = new HttpPost(
+ "http://172.17.0.2:31770/v1/rb/definition/" + rbName + "/" + rbVersion + "/config-template");
ObjectMapper objectMapper = new ObjectMapper();
String requestBody = objectMapper.writeValueAsString(tE);
StringEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
@@ -280,7 +634,7 @@ public class CnfAdapterRest {
}
@ResponseBody
- @RequestMapping(value = {"/api/multicloud-k8s/v1/v1/rb/definition/{rb-name}/{rb-version}/config-template/{tname}"},
+ @RequestMapping(value = {"/api/cnf-adapter/v1/v1/rb/definition/{rb-name}/{rb-version}/config-template/{tname}"},
method = RequestMethod.GET, produces = "application/json")
public String getConfigTemplate(@PathVariable("rb-name") String rbName,
@PathVariable("rb-version") String rbVersion, @PathVariable("tname") String tName) throws Exception {
@@ -289,8 +643,8 @@ public class CnfAdapterRest {
// TODO
// Below URL should be changed as appropriate multicloud URL.
- HttpGet req = new HttpGet("https://localhost:32780/api/multicloud-k8s/v1/v1/rb/definition/" + rbName + "/"
- + rbVersion + "/config-template/" + tName);
+ HttpGet req = new HttpGet(
+ "http://172.17.0.2:31770/v1/rb/definition/" + rbName + "/" + rbVersion + "/config-template/" + tName);
try (CloseableHttpResponse response = httpClient.execute(req)) {
logger.info("response:" + response.getEntity());
@@ -298,4 +652,83 @@ public class CnfAdapterRest {
}
}
+ @ResponseBody
+ @RequestMapping(value = {"/api/cnf-adapter/v1/v1/rb/definition/{rb-name}/{rb-version}/config-template/{tname}"},
+ method = RequestMethod.DELETE, produces = "application/json")
+ public String deleteTemplate(@PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion,
+ @PathVariable("tname") String tName) throws Exception {
+
+ logger.info("deleteTemplate called.");
+
+ // TODO
+ // Below URL should be changed as appropriate multicloud URL.
+ HttpDelete req = new HttpDelete(
+ "http://172.17.0.2:31770/v1/rb/definition/" + rbName + "/" + rbVersion + "/config-template/" + tName);
+
+ try (CloseableHttpResponse response = httpClient.execute(req)) {
+ logger.info("response:" + response.getEntity());
+ return EntityUtils.toString(response.getEntity());
+ }
+
+ }
+
+ @ResponseBody
+ @RequestMapping(
+ value = {"/api/cnf-adapter/v1/v1/rb/definition/{rb-name}/{rb-version}/config-template/{tname}/content"},
+ method = RequestMethod.POST, produces = "multipart/form-data")
+ public String uploadTarFileForTemplate(@RequestParam("file") MultipartFile file,
+ @PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion,
+ @PathVariable("tname") String tName) throws Exception {
+
+ logger.info("uploadTarFileForTemplate called.");
+
+ File convFile = new File(file.getOriginalFilename());
+ file.transferTo(convFile);
+ FileBody fileBody = new FileBody(convFile, ContentType.DEFAULT_BINARY);
+ MultipartEntityBuilder builder = MultipartEntityBuilder.create();
+ builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
+ builder.addPart("file", fileBody);
+ HttpEntity entity = builder.build();
+
+ // TODO
+ // Below URL should be changed as appropriate multicloud URL.
+ HttpPost post = new HttpPost("http://172.17.0.2:31770/v1/rb/definition/" + rbName + "/" + rbVersion
+ + "/config-template/" + tName + "/content");
+ post.setHeader("Content-Type", "multipart/form-data");
+
+ logger.info(String.valueOf(post));
+ post.setEntity(entity);
+
+ try (CloseableHttpClient httpClient = HttpClients.createDefault();
+ CloseableHttpResponse response = httpClient.execute(post)) {
+ logger.info("response:" + response.getEntity());
+ return EntityUtils.toString(response.getEntity());
+ }
+ }
+
+ @ResponseBody
+ @RequestMapping(value = {"/api/cnf-adapter/v1/v1/definition/{rbName}/{rbVersion}/profile/{prName}/config/rollback"},
+ method = RequestMethod.DELETE, produces = "application/json")
+ public String rollbackConfiguration(@RequestBody ConfigurationRollbackEntity rE,
+ @PathVariable("rbName") String rbName, @PathVariable("rbVersion") String rbVersion,
+ @PathVariable("prName") String prName) throws Exception {
+ logger.info("rollbackConfiguration called.");
+
+ // TODO
+ // Below URL should be changed as appropriate multicloud URL.
+ HttpPost post = new HttpPost("http://172.17.0.2:31770/v1/definition/" + rbName + "/" + rbVersion + "/profile/"
+ + prName + "/config/rollback");
+
+ ObjectMapper objectMapper = new ObjectMapper();
+ String requestBody = objectMapper.writeValueAsString(rE);
+ StringEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
+ post.setEntity(requestEntity);
+
+ try (CloseableHttpClient httpClient = HttpClients.createDefault();
+ CloseableHttpResponse response = httpClient.execute(post)) {
+ logger.info("response:" + response.getEntity());
+ return EntityUtils.toString(response.getEntity());
+ }
+ }
+
}
diff --git a/adapters/mso-cnf-adapter/src/main/java/org/onap/so/adapters/cnf/util/CNfAdapterUtil.java b/adapters/mso-cnf-adapter/src/main/java/org/onap/so/adapters/cnf/util/CNfAdapterUtil.java
new file mode 100644
index 0000000000..25e506c55e
--- /dev/null
+++ b/adapters/mso-cnf-adapter/src/main/java/org/onap/so/adapters/cnf/util/CNfAdapterUtil.java
@@ -0,0 +1,94 @@
+/*-
+ * ============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.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 static final int BAD_REQUEST = 400;
+
+ private static final String UNMARSHAL_FAIL_MSG = "Failed to unmarshal json";
+
+ 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);
+ }
+ }
+
+ public static String marshal(Object srcObj) throws ApplicationException {
+ try {
+ return MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(srcObj);
+ } catch (IOException e) {
+ LOGGER.error(THREE, RA_NS_EXC.toString(), ErrorCode.BusinessProcessError.getValue(), MARSHAL_FAIL_MSG, e);
+ throw new ApplicationException(BAD_REQUEST, MARSHAL_FAIL_MSG);
+ }
+ }
+
+}
diff --git a/adapters/mso-cnf-adapter/src/test/java/org/onap/so/adapters/cnf/CnfAdapterRestTest.java b/adapters/mso-cnf-adapter/src/test/java/org/onap/so/adapters/cnf/CnfAdapterRestTest.java
new file mode 100644
index 0000000000..38a10918bc
--- /dev/null
+++ b/adapters/mso-cnf-adapter/src/test/java/org/onap/so/adapters/cnf/CnfAdapterRestTest.java
@@ -0,0 +1,62 @@
+/*-
+ * ============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;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.onap.so.adapters.cnf.model.BpmnInstanceRequest;
+import org.onap.so.adapters.cnf.rest.CnfAdapterRest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+public class CnfAdapterRestTest {
+
+ @InjectMocks
+ CnfAdapterRest cnfAdapterRest;
+
+ @Test
+ public void createInstanceTest() 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");
+ BpmnInstanceRequest bpmnInstanceRequest = new BpmnInstanceRequest();
+ bpmnInstanceRequest.setCloudRegionId("v1");
+ bpmnInstanceRequest.setLabels(labels);
+ bpmnInstanceRequest.setModelInvariantId("krd");
+ bpmnInstanceRequest.setModelVersionId("p1");
+ bpmnInstanceRequest.setOverrideValues(overrideValues);
+ bpmnInstanceRequest.setVfModuleUUID("20200824");
+
+ String mockedResponse = "K8sRBProfileName is required";
+ String actualResponse = cnfAdapterRest.createInstance(bpmnInstanceRequest);
+ assertNotNull(actualResponse);
+ assertEquals(mockedResponse, actualResponse);
+ }
+
+}