Update query subnet capability 30/114730/1
authorzm330 <zhangminyj@chinamobile.com>
Tue, 10 Nov 2020 07:51:39 +0000 (15:51 +0800)
committerzm330 <zhangminyj@chinamobile.com>
Tue, 10 Nov 2020 07:51:49 +0000 (15:51 +0800)
Issue-ID: SO-2963

Signed-off-by: zm330 <zhangminyj@chinamobile.com>
Change-Id: I695cb9b6842c85c2f0a99cf95f12bbf3b6a04a6d

adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/BaseNssmfManager.java
adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/ExternalNssmfManager.java
adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/InternalNssmfManager.java
adapters/mso-nssmf-adapter/src/main/resources/subnetCapability.json [new file with mode: 0644]
adapters/mso-nssmf-adapter/src/test/java/org/onap/so/adapters/nssmf/service/impl/NssmfManagerServiceImplTest.java
common/src/main/java/org/onap/so/beans/nsmf/NssmfAdapterNBIRequest.java
common/src/main/java/org/onap/so/beans/nsmf/QuerySubnetCapability.java [new file with mode: 0644]

index 789f4f2..acaa394 100644 (file)
@@ -193,7 +193,7 @@ public abstract class BaseNssmfManager implements NssmfManager {
         return doQuerySubnetCapability(nbiRequest.getSubnetCapabilityQuery());
     }
 
-    protected abstract <T> RestResponse doQuerySubnetCapability(T req) throws ApplicationException;
+    protected abstract <T> RestResponse doQuerySubnetCapability(QuerySubnetCapability req) throws ApplicationException;
 
     /**
      * send request to nssmf
index 72d1b53..9dcd2d4 100644 (file)
 
 package org.onap.so.adapters.nssmf.manager.impl;
 
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import org.apache.http.Header;
+import org.apache.http.HttpStatus;
 import org.apache.http.message.BasicHeader;
 import org.onap.aai.domain.yang.ServiceInstance;
 import org.onap.so.adapters.nssmf.entity.NssmfInfo;
@@ -31,14 +35,23 @@ import org.onap.so.adapters.nssmf.exceptions.ApplicationException;
 import org.onap.so.adapters.nssmf.util.NssmfAdapterUtil;
 import org.onap.so.beans.nsmf.*;
 import org.onap.so.db.request.beans.ResourceOperationStatus;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import static java.lang.String.valueOf;
 import static org.onap.so.adapters.nssmf.enums.JobStatus.*;
-import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.StatusDesc.*;
+import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.StatusDesc.QUERY_JOB_STATUS_FAILED;
+import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.StatusDesc.QUERY_JOB_STATUS_SUCCESS;
 import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.marshal;
 import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.unMarshal;
 
 public abstract class ExternalNssmfManager extends BaseNssmfManager {
 
+    private static final Logger logger = LoggerFactory.getLogger(ExternalNssmfManager.class);
+
     @Override
     protected String wrapAllocateReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException {
         return doWrapExtAllocateReqBody(nbiRequest);
@@ -167,11 +180,34 @@ public abstract class ExternalNssmfManager extends BaseNssmfManager {
     }
 
     @Override
-    protected <T> RestResponse doQuerySubnetCapability(T req) throws ApplicationException {
-        RestResponse response = new RestResponse();
-        response.setStatus(200);
-        response.setResponseContent(null);
-        return response;
+    protected <T> RestResponse doQuerySubnetCapability(QuerySubnetCapability req) throws ApplicationException {
+
+        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<>();
+        List<String> subnetTypes = req.getSubnetTypes();
+        for (String value : subnetTypes) {
+            if (subnetCapability.containsKey(value)) {
+                responseMap.put(value, subnetCapability.get(value));
+            }
+        }
+        String response = null;
+        try {
+            response = oMapper.writeValueAsString(responseMap);
+        } catch (JsonProcessingException e) {
+            logger.debug("Exception while converting subnet capability object to String {}", e);
+        }
+
+        RestResponse rsp = new RestResponse();
+        rsp.setStatus(HttpStatus.SC_OK);
+        rsp.setResponseContent(response);
+        return rsp;
     }
 
     /**
index 88b5071..296c30c 100644 (file)
@@ -122,7 +122,7 @@ public abstract class InternalNssmfManager extends BaseNssmfManager {
     protected abstract String doWrapModifyReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException;
 
     @Override
-    protected <T> RestResponse doQuerySubnetCapability(T req) throws ApplicationException {
+    protected <T> RestResponse doQuerySubnetCapability(QuerySubnetCapability req) throws ApplicationException {
         // handler
         return sendRequest(marshal(req));
     }
diff --git a/adapters/mso-nssmf-adapter/src/main/resources/subnetCapability.json b/adapters/mso-nssmf-adapter/src/main/resources/subnetCapability.json
new file mode 100644 (file)
index 0000000..8db5216
--- /dev/null
@@ -0,0 +1,19 @@
+{
+  "AN": {
+    "latency": "5",
+    "maxNumberofUEs": "100"
+  },
+  "CN": {
+    "latency": "10",
+    "maxNumberofConns": "100"
+  },
+  "TN_FH": {
+    "latency": "10"
+  },
+  "TN_MH": {
+    "latency": "5"
+  },
+  "TN_BH": {
+    "latency": "10"
+  }
+}
index 4a659e1..0d86056 100644 (file)
@@ -38,6 +38,7 @@ import org.onap.so.adapters.nssmf.entity.TokenResponse;
 import org.onap.so.adapters.nssmf.enums.HttpMethod;
 import org.onap.so.adapters.nssmf.util.RestUtil;
 import org.onap.so.beans.nsmf.*;
+import org.onap.so.beans.nsmf.oof.SubnetCapability;
 import org.onap.so.db.request.beans.ResourceOperationStatus;
 import org.onap.so.db.request.data.repository.ResourceOperationStatusRepository;
 import org.springframework.http.ResponseEntity;
@@ -429,7 +430,9 @@ public class NssmfManagerServiceImplTest {
     public void querySubnetCapability() {
         NssmfAdapterNBIRequest nbiRequest = createNbiRequest();
 
-        String subnetCapabilityQuery = "\"subnetTypes\": [\"TN-FH\",\"TN-MH\",\"TN-BH\"]";
+        QuerySubnetCapability subnetCapabilityQuery = new QuerySubnetCapability();
+        List<String> subnetTypes = Arrays.asList("TN-FH", "TN-MH", "TN-BH");
+        subnetCapabilityQuery.setSubnetTypes(subnetTypes);
         nbiRequest.setSubnetCapabilityQuery(subnetCapabilityQuery);
         ResponseEntity res = nssiManagerService.queryNSSISelectionCapability(nbiRequest);
         assertNotNull(res);
index e498905..8dd3691 100644 (file)
@@ -44,7 +44,7 @@ public class NssmfAdapterNBIRequest implements Serializable {
 
     private DeAllocateNssi deAllocateNssi;
 
-    private Object subnetCapabilityQuery;
+    private QuerySubnetCapability subnetCapabilityQuery;
 
     private String responseId;
 }
diff --git a/common/src/main/java/org/onap/so/beans/nsmf/QuerySubnetCapability.java b/common/src/main/java/org/onap/so/beans/nsmf/QuerySubnetCapability.java
new file mode 100644 (file)
index 0000000..7485b38
--- /dev/null
@@ -0,0 +1,49 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Wipro Limited.
+ * ================================================================================
+ * 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.beans.nsmf;
+
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import java.util.List;
+
+/**
+ * Model class for slice subnet capability query
+ */
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class QuerySubnetCapability {
+
+    @JsonProperty("subnetTypes")
+    private List<String> subnetTypes;
+
+    public List<String> getSubnetTypes() {
+        return subnetTypes;
+    }
+
+    public void setSubnetTypes(List<String> subnetTypes) {
+        this.subnetTypes = subnetTypes;
+    }
+
+    @Override
+    public String toString() {
+        return "QuerySubnetCapability [subnetType=" + subnetTypes + "]";
+    }
+}