diff options
author | Byung-Woo Jun <byung-woo.jun@est.tech> | 2020-09-17 05:48:03 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-09-17 05:48:03 +0000 |
commit | 633af62e329892feb8c7a3354a9bdb37eaef3f3d (patch) | |
tree | d4a5e082ec3b2204e9f84b80605ab8ef1539a6e9 /mso-api-handlers/mso-api-handler-infra | |
parent | 4b7611ffa47492aa6080fc58c0d04c23f32804b3 (diff) | |
parent | 30c6bacb158f5446915a772745f33a28d8da5ea2 (diff) |
Merge "Implement Subnet Capability query functionality"
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra')
4 files changed, 81 insertions, 12 deletions
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> 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> subnetTypes, String version) throws ApiException { + ObjectMapper oMapper = new ObjectMapper(); + InputStream inputStream = TypeReference.class.getResourceAsStream("/subnetCapability.json"); + Map<String, Object> 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<String, Object> 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> subnetTypes; - public SubnetTypes getSubnetType() { - return subnetType; + public List<SubnetTypes> getSubnetTypes() { + return subnetTypes; } - public void setSubnetType(SubnetTypes subnetType) { - this.subnetType = subnetType; + public void setSubnetTypes(List<SubnetTypes> 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); + } } |