--- /dev/null
+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;
+ }
+}
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;
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,
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;
@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");
// 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);
// 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);
// 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());
// 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());
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());
// 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;
// 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());
tomcat:
max-threads: 50
+multicloud:
+ protocol: "http"
+ host: "multicloud-k8s"
+ port: 9015
+
#mso:
# key: 07a7159d3bf51a0e53be7a8f89699be7
# site-name: localSite
+++ /dev/null
-/*-
- * ============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);
- }
-
-}
-*/
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.service.CnfAdapterService;
import org.springframework.http.HttpStatus;
@Mock
CnfAdapterService cnfAdapterService;
+ @Mock
+ private MulticloudConfiguration multicloudConfiguration;
+
@Mock
ResponseEntity<InstanceMiniResponseList> instacneMiniResponseList;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
+import org.onap.so.adapters.cnf.MulticloudConfiguration;
import org.onap.so.adapters.cnf.model.BpmnInstanceRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Map;
@RunWith(SpringRunner.class)
-
public class CnfAdapterServiceTest {
private static final String INSTANCE_CREATE_PATH = "/v1/instance";
@Mock
@InjectMocks
CnfAdapterService cnfAdapterService;
+ @Mock
+ private MulticloudConfiguration multicloudConfiguration;
+
@Mock
ResponseEntity<String> instanceResponse;