diff options
author | zm330 <zhangminyj@chinamobile.com> | 2020-11-10 15:51:39 +0800 |
---|---|---|
committer | zm330 <zhangminyj@chinamobile.com> | 2020-11-10 15:51:49 +0800 |
commit | 7737166117a3d41b8c1297531d2e68829bf7fbc8 (patch) | |
tree | 4db9947dceadef882767e1e89bb650e4dfe27e6a /adapters/mso-nssmf-adapter/src/main/java | |
parent | db17dd3511b757cb4d5b0a63cfdcda3bb60b51a0 (diff) |
Update query subnet capability
Issue-ID: SO-2963
Signed-off-by: zm330 <zhangminyj@chinamobile.com>
Change-Id: I695cb9b6842c85c2f0a99cf95f12bbf3b6a04a6d
Diffstat (limited to 'adapters/mso-nssmf-adapter/src/main/java')
3 files changed, 44 insertions, 8 deletions
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 <T> RestResponse doQuerySubnetCapability(T req) throws ApplicationException; + protected abstract <T> 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 <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; } /** 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 <T> RestResponse doQuerySubnetCapability(T req) throws ApplicationException { + protected <T> RestResponse doQuerySubnetCapability(QuerySubnetCapability req) throws ApplicationException { // handler return sendRequest(marshal(req)); } |