summaryrefslogtreecommitdiffstats
path: root/so-cnf-adapter-application/src
diff options
context:
space:
mode:
Diffstat (limited to 'so-cnf-adapter-application/src')
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/rest/CnfAdapterRest.java27
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/CnfAdapterService.java66
-rw-r--r--so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/rest/CnfAdapterRestTest.java25
3 files changed, 98 insertions, 20 deletions
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 488b384..074fd45 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
@@ -226,10 +226,31 @@ public class CnfAdapterRest {
@ResponseBody
@RequestMapping(value = {"/api/cnf-adapter/v1/instance/{instanceId}/query"}, method = RequestMethod.GET,
produces = "application/json")
- public String getInstanceQueryByInstanceId(@PathVariable("instanceId") String instanceId) {
- logger.info("getInstanceQueryByInstanceId called.");
+ public String queryInstanceResources(
+ @PathVariable("instanceId") String instanceId,
+ @RequestParam(value = "Kind") String kind,
+ @RequestParam(value = "ApiVersion") String apiVersion,
+ @RequestParam(value = "Labels", required = false) String labels,
+ @RequestParam(value = "Namespace", required = false) String namespace,
+ @RequestParam(value = "Name", required = false) String name) {
+ logger.info("queryInstanceResources called.");
- return cnfAdapterService.getInstanceQueryByInstanceId(instanceId);
+ return cnfAdapterService.queryInstanceResources(instanceId, kind, apiVersion, name, labels, namespace);
+ }
+
+ @ResponseBody
+ @RequestMapping(value = {"/api/cnf-adapter/v1/query"}, method = RequestMethod.GET,
+ produces = "application/json")
+ public String queryResources(
+ @RequestParam(value = "Kind") String kind,
+ @RequestParam(value = "ApiVersion") String apiVersion,
+ @RequestParam(value = "Labels", required = false) String labels,
+ @RequestParam(value = "Namespace", required = false) String namespace,
+ @RequestParam(value = "Name", required = false) String name,
+ @RequestParam(value = "CloudRegion") String cloudRegion) {
+ logger.info("queryResources called.");
+
+ return cnfAdapterService.queryResources(kind, apiVersion, name, labels, namespace, cloudRegion);
}
@RequestMapping(value = {"/api/cnf-adapter/v1/instance"}, method = RequestMethod.GET, produces = "application/json")
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 a74a9b3..12aa4ad 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
@@ -20,11 +20,8 @@
package org.onap.so.adapters.cnf.service;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import javax.persistence.EntityNotFoundException;
-import javax.ws.rs.core.UriBuilder;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
import org.apache.http.HttpStatus;
import org.onap.so.adapters.cnf.MulticloudConfiguration;
import org.onap.so.adapters.cnf.model.BpmnInstanceRequest;
@@ -45,8 +42,12 @@ import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.client.RestTemplate;
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.databind.JsonMappingException;
+
+import javax.persistence.EntityNotFoundException;
+import javax.ws.rs.core.UriBuilder;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
@Service
public class CnfAdapterService {
@@ -186,17 +187,54 @@ public class CnfAdapterService {
}
- public String getInstanceQueryByInstanceId(String instanceId) {
- logger.info("CnfAdapterService getInstanceQueryByInstanceId called");
- ResponseEntity<String> instanceResponse = null;
+ public String queryInstanceResources(String instanceId, String kind, String apiVersion, String name, String labels,
+ String namespace) {
+ logger.info("CnfAdapterService queryInstanceResources called");
+ ResponseEntity<String> queryResponse = null;
try {
String path = "/v1/instance/" + instanceId + "/query";
- String endpoint = UriBuilder.fromUri(uri).path(path).build().toString();
+ UriBuilder builder = UriBuilder.fromUri(uri).path(path).queryParam("Kind", kind).
+ queryParam("ApiVersion", apiVersion);
+ if (namespace != null)
+ builder = builder.queryParam("Namespace", namespace);
+ if (name != null)
+ builder = builder.queryParam("Name", name);
+ if (labels != null)
+ builder = builder.queryParam("Labels", labels);
+ String endpoint = builder.build().toString();
HttpEntity<?> requestEntity = new HttpEntity<>(getHttpHeaders());
logger.info("request: " + requestEntity);
- instanceResponse = restTemplate.exchange(endpoint, HttpMethod.GET, requestEntity, String.class);
- logger.info("response: " + instanceResponse);
- return instanceResponse.getBody();
+ queryResponse = restTemplate.exchange(endpoint, HttpMethod.GET, requestEntity, String.class);
+ logger.info("response: " + queryResponse);
+ return queryResponse.getBody();
+ } catch (HttpClientErrorException e) {
+ if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) {
+ throw new EntityNotFoundException(e.getResponseBodyAsString());
+ }
+ throw e;
+ }
+ }
+
+ public String queryResources(String kind, String apiVersion, String name, String labels,
+ String namespace, String cloudRegion) {
+ logger.info("CnfAdapterService queryResources called");
+ ResponseEntity<String> queryResponse = null;
+ try {
+ String path = "/v1/query";
+ UriBuilder builder = UriBuilder.fromUri(uri).path(path).queryParam("Kind", kind).
+ queryParam("ApiVersion", apiVersion).queryParam("CloudRegion", cloudRegion);
+ if (namespace != null)
+ builder = builder.queryParam("Namespace", namespace);
+ if (name != null)
+ builder = builder.queryParam("Name", name);
+ if (labels != null)
+ builder = builder.queryParam("Labels", labels);
+ String endpoint = builder.build().toString();
+ HttpEntity<?> requestEntity = new HttpEntity<>(getHttpHeaders());
+ logger.info("request: " + requestEntity);
+ queryResponse = restTemplate.exchange(endpoint, HttpMethod.GET, requestEntity, String.class);
+ logger.info("response: " + queryResponse);
+ return queryResponse.getBody();
} catch (HttpClientErrorException e) {
if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) {
throw new EntityNotFoundException(e.getResponseBodyAsString());
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 c85031a..48eecaa 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
@@ -144,13 +144,32 @@ public class CnfAdapterRestTest {
}
@Test
- public void getInstanceQueryByInstanceIdTest() {
+ public void queryInstanceResourcesTest() {
String instanceId = "123";
+ String kind = "Service";
+ String apiVersion = "v1";
String queryResponseMock = "queryResponseMock";
- Mockito.when(cnfAdapterService.getInstanceQueryByInstanceId(instanceId)).thenReturn(queryResponseMock);
+ Mockito.when(cnfAdapterService.queryInstanceResources(instanceId, kind, apiVersion, null, null,
+ null)).thenReturn(queryResponseMock);
- String result = cnfAdapterRest.getInstanceQueryByInstanceId(instanceId);
+ String result = cnfAdapterRest.queryInstanceResources(instanceId, kind, apiVersion, null, null,
+ null);
+ assertThat(result).isEqualTo(queryResponseMock);
+ }
+
+ @Test
+ public void queryResourcesTest() {
+ String kind = "Service";
+ String apiVersion = "v1";
+ String cloudRegion = "region";
+ String queryResponseMock = "queryResponseMock";
+
+ Mockito.when(cnfAdapterService.queryResources(kind, apiVersion, null, null,
+ null, cloudRegion)).thenReturn(queryResponseMock);
+
+ String result = cnfAdapterRest.queryResources(kind, apiVersion, null, null,
+ null, cloudRegion);
assertThat(result).isEqualTo(queryResponseMock);
}