From 7737166117a3d41b8c1297531d2e68829bf7fbc8 Mon Sep 17 00:00:00 2001 From: zm330 Date: Tue, 10 Nov 2020 15:51:39 +0800 Subject: Update query subnet capability Issue-ID: SO-2963 Signed-off-by: zm330 Change-Id: I695cb9b6842c85c2f0a99cf95f12bbf3b6a04a6d --- .../nssmf/manager/impl/BaseNssmfManager.java | 2 +- .../nssmf/manager/impl/ExternalNssmfManager.java | 48 +++++++++++++++++++--- .../nssmf/manager/impl/InternalNssmfManager.java | 2 +- 3 files changed, 44 insertions(+), 8 deletions(-) (limited to 'adapters/mso-nssmf-adapter/src/main/java') diff --git a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/BaseNssmfManager.java b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/BaseNssmfManager.java index 789f4f239d..acaa3945bd 100644 --- a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/BaseNssmfManager.java +++ b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/BaseNssmfManager.java @@ -193,7 +193,7 @@ public abstract class BaseNssmfManager implements NssmfManager { return doQuerySubnetCapability(nbiRequest.getSubnetCapabilityQuery()); } - protected abstract RestResponse doQuerySubnetCapability(T req) throws ApplicationException; + protected abstract RestResponse doQuerySubnetCapability(QuerySubnetCapability req) throws ApplicationException; /** * send request to nssmf diff --git a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/ExternalNssmfManager.java b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/ExternalNssmfManager.java index 72d1b53781..9dcd2d4cfb 100644 --- a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/ExternalNssmfManager.java +++ b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/ExternalNssmfManager.java @@ -20,7 +20,11 @@ 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 RestResponse doQuerySubnetCapability(T req) throws ApplicationException { - RestResponse response = new RestResponse(); - response.setStatus(200); - response.setResponseContent(null); - return response; + protected RestResponse doQuerySubnetCapability(QuerySubnetCapability req) throws ApplicationException { + + 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<>(); + List 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; } /** diff --git a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/InternalNssmfManager.java b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/InternalNssmfManager.java index 88b5071371..296c30c1d8 100644 --- a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/InternalNssmfManager.java +++ b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/InternalNssmfManager.java @@ -122,7 +122,7 @@ public abstract class InternalNssmfManager extends BaseNssmfManager { protected abstract String doWrapModifyReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException; @Override - protected RestResponse doQuerySubnetCapability(T req) throws ApplicationException { + protected RestResponse doQuerySubnetCapability(QuerySubnetCapability req) throws ApplicationException { // handler return sendRequest(marshal(req)); } -- cgit 1.2.3-korg