summaryrefslogtreecommitdiffstats
path: root/so-cnf-adapter-application/src/main/java/org
diff options
context:
space:
mode:
authorLukasz Rajewski <lukasz.rajewski@orange.com>2021-08-23 22:12:16 +0200
committerLukasz Rajewski <lukasz.rajewski@orange.com>2021-08-23 22:14:27 +0200
commit70922296650d550bcfa76f388420bfd32a7f7463 (patch)
treeb66d0c12a13a7f5c398c73caf356ae3533f0232f /so-cnf-adapter-application/src/main/java/org
parente6e5786b73378509900ef5e1b7ea2bfdddbcf8d3 (diff)
Implement query API handlers with query params
Implement query API handlers with query params Issue-ID: SO-3696 Signed-off-by: Lukasz Rajewski <lukasz.rajewski@orange.com> Change-Id: I2b4996de340022264d8d563d4a27f984941d4dec
Diffstat (limited to 'so-cnf-adapter-application/src/main/java/org')
-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
2 files changed, 76 insertions, 17 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 2036f46..1e66a5e 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
@@ -123,10 +123,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 faef1d0..913cae7 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;
@@ -41,8 +38,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 {
@@ -199,17 +200,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());