summaryrefslogtreecommitdiffstats
path: root/so-cnf-adapter-application/src/main
diff options
context:
space:
mode:
authorGrzegorz Wielgosinski <g.wielgosins@samsung.com>2021-07-13 13:23:41 +0200
committerGrzegorz Wielgosinski <g.wielgosins@samsung.com>2021-07-14 16:08:49 +0200
commit8ee120e21f2c894a18e0585504cc1f95c08a8f4b (patch)
tree131d3cd16faf4f4423e7aa6e54cb31377fff5970 /so-cnf-adapter-application/src/main
parent98d2c727788cc2fa24baa23c1d82cc309fcf6295 (diff)
Multicloud URL refactoring
Issue-ID: SO-3711 Signed-off-by: Grzegorz Wielgosinski <g.wielgosins@samsung.com> Change-Id: Id1ee3f40c703b480d1296e657e1f7977cdd60f08
Diffstat (limited to 'so-cnf-adapter-application/src/main')
-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/rest/CnfAdapterRest.java9
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/CnfAdapterService.java20
-rw-r--r--so-cnf-adapter-application/src/main/resources/application.yaml5
4 files changed, 43 insertions, 11 deletions
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
new file mode 100644
index 0000000..6107681
--- /dev/null
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/MulticloudConfiguration.java
@@ -0,0 +1,20 @@
+package org.onap.so.adapters.cnf;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class MulticloudConfiguration {
+
+ @Value("${multicloud.protocol}")
+ private String protocol;
+ @Value("${multicloud.host}")
+ private String host;
+ @Value("${multicloud.port}")
+ private Integer port;
+
+ public String getMulticloudUrl() {
+ return protocol + "://" + host + ":" + port;
+ }
+}
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 430a5e5..2036f46 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
@@ -36,6 +36,7 @@ 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.MulticloudConfiguration;
import org.onap.so.adapters.cnf.model.BpmnInstanceRequest;
import org.onap.so.adapters.cnf.model.ConfigTemplateEntity;
import org.onap.so.adapters.cnf.model.ConfigurationEntity;
@@ -66,10 +67,14 @@ public class CnfAdapterRest {
private static final Logger logger = LoggerFactory.getLogger(CnfAdapterRest.class);
private final CloseableHttpClient httpClient = HttpClients.createDefault();
- private String uri = "http://multicloud-k8s:9015";
+ private final CnfAdapterService cnfAdapterService;
+ private final String uri;
@Autowired
- private CnfAdapterService cnfAdapterService;
+ public CnfAdapterRest(CnfAdapterService cnfAdapterService, MulticloudConfiguration multicloudConfiguration) {
+ this.cnfAdapterService = cnfAdapterService;
+ this.uri = multicloudConfiguration.getMulticloudUrl();
+ }
@ResponseBody
@RequestMapping(value = {"/api/cnf-adapter/v1/healthcheck"}, method = RequestMethod.GET,
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 bfb84c3..b50658f 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
@@ -26,6 +26,7 @@ import java.util.List;
import javax.persistence.EntityNotFoundException;
import javax.ws.rs.core.UriBuilder;
import org.apache.http.HttpStatus;
+import org.onap.so.adapters.cnf.MulticloudConfiguration;
import org.onap.so.adapters.cnf.model.BpmnInstanceRequest;
import org.onap.so.adapters.cnf.model.MulticloudInstanceRequest;
import org.slf4j.Logger;
@@ -46,11 +47,19 @@ import com.fasterxml.jackson.databind.JsonMappingException;
@Service
public class CnfAdapterService {
private static final Logger logger = LoggerFactory.getLogger(CnfAdapterService.class);
- @Autowired
- private RestTemplate restTemplate;
private static final String INSTANCE_CREATE_PATH = "/v1/instance";
private static final String HEALTH_CHECK = "/v1/healthcheck";
+ private final RestTemplate restTemplate;
+ private final String uri;
+
+ @Autowired
+ public CnfAdapterService(RestTemplate restTemplate,
+ MulticloudConfiguration multicloudConfiguration) {
+ this.restTemplate = restTemplate;
+ this.uri = multicloudConfiguration.getMulticloudUrl();
+ }
+
public String healthCheck() {
logger.info("CnfAdapterService healthCheck called");
@@ -60,7 +69,6 @@ public class CnfAdapterService {
// String uri = env.getRequiredProperty("multicloud.endpoint"); //TODO:
// This needs to be added as well
// for configuration
- String uri = "http://multicloud-k8s:9015"; // TODO: What is the correct uri?
String endpoint = UriBuilder.fromUri(uri).path(HEALTH_CHECK).build().toString();
HttpEntity<?> requestEntity = new HttpEntity<>(getHttpHeaders());
result = restTemplate.exchange(endpoint, HttpMethod.GET, requestEntity, String.class);
@@ -103,7 +111,6 @@ public class CnfAdapterService {
// String uri = env.getRequiredProperty("multicloud.endpoint"); //TODO:
// This needs to be added as well
// for configuration
- String uri = "http://multicloud-k8s:9015"; // TODO: What is the correct uri?
String endpoint = UriBuilder.fromUri(uri).path(INSTANCE_CREATE_PATH).build().toString();
HttpEntity<?> entity = getHttpEntity(multicloudInstanceRequest);
instanceResponse = restTemplate.exchange(endpoint, HttpMethod.POST, entity, String.class);
@@ -130,7 +137,6 @@ public class CnfAdapterService {
// String uri = env.getRequiredProperty("multicloud.endpoint"); //TODO:
// This needs to be added as well
// for configuration
- String uri = "http://multicloud-k8s:9015"; // TODO: What is the correct uri?
String path = "/v1/instance/" + instanceId;
String endpoint = UriBuilder.fromUri(uri).path(path).build().toString();
HttpEntity<?> requestEntity = new HttpEntity<>(getHttpHeaders());
@@ -158,7 +164,6 @@ public class CnfAdapterService {
// String uri = env.getRequiredProperty("multicloud.endpoint"); //TODO:
// This needs to be added as well
// for configuration
- String uri = "http://multicloud-k8s:9015"; // TODO: What is the correct uri?
String path = "/v1/instance/" + instanceId + "/status";
String endpoint = UriBuilder.fromUri(uri).path(path).build().toString();
HttpEntity<?> requestEntity = new HttpEntity<>(getHttpHeaders());
@@ -181,7 +186,6 @@ public class CnfAdapterService {
logger.info("CnfAdapterService getInstanceQueryByInstanceId called");
ResponseEntity<String> instanceResponse = null;
try {
- String uri = "http://multicloud-k8s:9015";
String path = "/v1/instance/" + instanceId + "/query";
String endpoint = UriBuilder.fromUri(uri).path(path).build().toString();
HttpEntity<?> requestEntity = new HttpEntity<>(getHttpHeaders());
@@ -205,7 +209,6 @@ public class CnfAdapterService {
// String uri = env.getRequiredProperty("multicloud.endpoint"); //TODO:
// This needs to be added as well
// for configuration
- String uri = "http://multicloud-k8s:9015"; // TODO: What is the correct uri?
String path =
"/v1/instance" + "?rb-name=" + rbName + "&rb-version=" + rbVersion + "&profile-name=" + profileName;
String endPoint = uri + path;
@@ -234,7 +237,6 @@ public class CnfAdapterService {
// String uri = env.getRequiredProperty("multicloud.endpoint"); //TODO:
// This needs to be added as well
// for configuration
- String uri = "http://multicloud-k8s:9015"; // TODO: What is the correct uri?
String path = "/v1/instance/" + instanceId;
String endpoint = UriBuilder.fromUri(uri).path(path).build().toString();
HttpEntity<?> requestEntity = new HttpEntity<>(getHttpHeaders());
diff --git a/so-cnf-adapter-application/src/main/resources/application.yaml b/so-cnf-adapter-application/src/main/resources/application.yaml
index 5a9adbf..50e667a 100644
--- a/so-cnf-adapter-application/src/main/resources/application.yaml
+++ b/so-cnf-adapter-application/src/main/resources/application.yaml
@@ -42,6 +42,11 @@ server:
tomcat:
max-threads: 50
+multicloud:
+ protocol: "http"
+ host: "multicloud-k8s"
+ port: 9015
+
#mso:
# key: 07a7159d3bf51a0e53be7a8f89699be7
# site-name: localSite