From 30c6bacb158f5446915a772745f33a28d8da5ea2 Mon Sep 17 00:00:00 2001 From: deepikasatheesh Date: Tue, 8 Sep 2020 05:51:24 -0700 Subject: Implement Subnet Capability query functionality Issue-ID: SO-3222 Signed-off-by: deepikasatheesh Change-Id: I1797aeb1f2b4b461cee627200bda8312a0803524 --- .../apihandlerinfra/Onap3gppServiceInstances.java | 35 +++++++++++++++++++--- .../QuerySubnetCapability.java | 16 +++++----- .../src/main/resources/subnetCapability.json | 25 ++++++++++++++++ .../Onap3gppServiceInstancesTest.java | 17 +++++++++++ 4 files changed, 81 insertions(+), 12 deletions(-) create mode 100644 mso-api-handlers/mso-api-handler-infra/src/main/resources/subnetCapability.json (limited to 'mso-api-handlers') diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Onap3gppServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Onap3gppServiceInstances.java index e7b96b16a9..3f05c79dad 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Onap3gppServiceInstances.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Onap3gppServiceInstances.java @@ -23,6 +23,11 @@ package org.onap.so.apihandlerinfra; import java.sql.Timestamp; import java.util.HashMap; import java.util.UUID; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.function.Function; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; @@ -54,6 +59,7 @@ import org.onap.so.apihandlerinfra.onap3gppserviceinstancebeans.Allocate3gppServ import org.onap.so.apihandlerinfra.onap3gppserviceinstancebeans.DeAllocate3gppService; import org.onap.so.apihandlerinfra.onap3gppserviceinstancebeans.Modify3gppService; import org.onap.so.apihandlerinfra.onap3gppserviceinstancebeans.QuerySubnetCapability; +import org.onap.so.apihandlerinfra.onap3gppserviceinstancebeans.SubnetTypes; import org.onap.so.constants.Status; import org.onap.so.db.catalog.beans.Service; import org.onap.so.db.catalog.beans.ServiceRecipe; @@ -70,6 +76,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.core.type.TypeReference; import io.swagger.v3.oas.annotations.OpenAPIDefinition; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.info.Info; @@ -238,8 +245,8 @@ public class Onap3gppServiceInstances { public Response getSliceSubnetCapabilities(QuerySubnetCapability request, @PathParam("version") String version) throws ApiException { logger.debug("Request received {}", request); - String subnetType = null; - return getSubnetCapabilities(subnetType, version); + List subnetTypes = request.getSubnetTypes(); + return getSubnetCapabilities(subnetTypes, version); } /** @@ -577,8 +584,28 @@ public class Onap3gppServiceInstances { } // To be implemented for fetching Subnet capabilities - private Response getSubnetCapabilities(String subnetType, String version) throws ApiException { - return null; + private Response getSubnetCapabilities(List subnetTypes, String version) throws ApiException { + ObjectMapper oMapper = new ObjectMapper(); + InputStream inputStream = TypeReference.class.getResourceAsStream("/subnetCapability.json"); + Map subnetCapability = new HashMap<>(); + try { + subnetCapability = oMapper.readValue(inputStream, Map.class); + } catch (Exception e) { + logger.debug("Exception while reading subnet capability value from json", e); + } + Map responseMap = new HashMap<>(); + for (SubnetTypes value : subnetTypes) { + if (subnetCapability.containsKey(value.toString())) { + responseMap.put(value.toString(), subnetCapability.get(value.toString())); + } + } + String response = null; + try { + response = oMapper.writeValueAsString(responseMap); + } catch (JsonProcessingException e) { + logger.debug("Exception while converting subnet capability object to String {}", e); + } + return builder.buildResponse(HttpStatus.SC_OK, null, response, version); } /** diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/onap3gppserviceinstancebeans/QuerySubnetCapability.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/onap3gppserviceinstancebeans/QuerySubnetCapability.java index 2e479e1ecb..c66b053609 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/onap3gppserviceinstancebeans/QuerySubnetCapability.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/onap3gppserviceinstancebeans/QuerySubnetCapability.java @@ -22,26 +22,26 @@ package org.onap.so.apihandlerinfra.onap3gppserviceinstancebeans; import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; /** * Model class for slice subnet capability query */ public class QuerySubnetCapability { - private SubnetTypes subnetType; + @JsonProperty("subnetTypes") + private List subnetTypes; - public SubnetTypes getSubnetType() { - return subnetType; + public List getSubnetTypes() { + return subnetTypes; } - public void setSubnetType(SubnetTypes subnetType) { - this.subnetType = subnetType; + public void setSubnetTypes(List subnetTypes) { + this.subnetTypes = subnetTypes; } @Override public String toString() { - return "QuerySubnetCapability [subnetType=" + subnetType + "]"; + return "QuerySubnetCapability [subnetType=" + subnetTypes + "]"; } - } - diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/resources/subnetCapability.json b/mso-api-handlers/mso-api-handler-infra/src/main/resources/subnetCapability.json new file mode 100644 index 0000000000..0d5acef64a --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/main/resources/subnetCapability.json @@ -0,0 +1,25 @@ +{ + "AN": { + "latency": "5", + "maxNumberofUEs": "100", + "maxThroughput": "150", + "terminalDensity": "50" + }, + "CN": { + "latency": "10", + "maxThroughput": "50", + "maxNumberofConns": "100" + }, + "TN_FH": { + "latency": "10", + "maxThroughput": "100" + }, + "TN_MH": { + "latency": "5", + "maxThroughput": "50" + }, + "TN_BH": { + "latency": "10", + "maxThroughput": "100" + } +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/Onap3gppServiceInstancesTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/Onap3gppServiceInstancesTest.java index 503af1bdcb..c3c92be013 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/Onap3gppServiceInstancesTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/Onap3gppServiceInstancesTest.java @@ -49,6 +49,9 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.util.UriComponentsBuilder; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import org.onap.so.apihandlerinfra.exceptions.ApiException; +import org.onap.so.apihandlerinfra.onap3gppserviceinstancebeans.QuerySubnetCapability; +import org.springframework.beans.factory.annotation.Autowired; public class Onap3gppServiceInstancesTest extends BaseTest { @@ -56,6 +59,9 @@ public class Onap3gppServiceInstancesTest extends BaseTest { private final ObjectMapper mapper = new ObjectMapper(); + @Autowired + private Onap3gppServiceInstances objUnderTest; + @Before public void init() throws JsonProcessingException { @@ -176,6 +182,17 @@ public class Onap3gppServiceInstancesTest extends BaseTest { assertEquals(expectedResponse, actualResponse); } + @Test + public void getSliceSubnetCapabilitiesTest() throws IOException, ApiException { + String request = "{\"subnetTypes\":[\"AN\"]}"; + QuerySubnetCapability subnetCapabilityRequest = mapper.readValue(request, QuerySubnetCapability.class); + String expectedResponse = + "{\"AN\":{\"latency\":\"5\",\"maxNumberofUEs\":\"100\",\"maxThroughput\":\"150\",\"terminalDensity\":\"50\"}}"; + Response response = objUnderTest.getSliceSubnetCapabilities(subnetCapabilityRequest, "v1"); + String actualResponse = (String) response.getEntity(); + assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); + assertEquals(expectedResponse, actualResponse); + } } -- cgit 1.2.3-korg