diff options
author | Zi Li <li.zi30@zte.com.cn> | 2018-08-20 12:05:39 +0000 |
---|---|---|
committer | Zi Li <li.zi30@zte.com.cn> | 2018-08-20 12:05:47 +0000 |
commit | 2af1528498f33d0f60fcce157a9d6b0472b9b956 (patch) | |
tree | 800fb7c006bdf5e7b0c458d8ec607cb7e34b2f08 /esr-mgr/src | |
parent | 15dd5f02e728d546e6ba8c4d460b5f1a1e57d2b7 (diff) |
Add the API of query PNF.
Issue-ID: AAI-1498
Change-Id: Ie073f6b2643324b2038a2404886fa6e0286ab326
Signed-off-by: Zi Li <li.zi30@zte.com.cn>
Diffstat (limited to 'esr-mgr/src')
5 files changed, 119 insertions, 6 deletions
diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/INetwork.java b/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/INetwork.java index c159da7..20a7a25 100644 --- a/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/INetwork.java +++ b/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/INetwork.java @@ -16,11 +16,14 @@ package org.onap.aai.esr.externalservice.aai; import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; import javax.ws.rs.HeaderParam; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import org.onap.aai.esr.entity.aai.Pnf; import org.onap.aai.esr.exception.ExtsysException; @@ -34,4 +37,29 @@ public interface INetwork { public void registerPnfService(@HeaderParam("X-TransactionId") String transactionId, @HeaderParam("X-FromAppId") String fromApp, @HeaderParam("Authorization") String authorization, @PathParam("pnfName") String pnfName, Pnf pnf) throws ExtsysException; + + @GET + @Path("/pnfs/pnf/{pnfName}") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public String queryPNF(@HeaderParam("X-TransactionId") String transactionId, + @HeaderParam("X-FromAppId") String fromApp, @HeaderParam("Authorization") String authorization, + @PathParam("pnfName") String pnfName) throws ExtsysException; + + @GET + @Path("/pnfs") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public String queryPNFList(@HeaderParam("X-TransactionId") String transactionId, + @HeaderParam("X-FromAppId") String fromApp, @HeaderParam("Authorization") String authorization) + throws ExtsysException; + + @DELETE + @Path("/pnfs/pnf/{pnfName}") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public void deletePNF(@HeaderParam("X-TransactionId") String transactionId, + @HeaderParam("X-FromAppId") String fromApp, @HeaderParam("Authorization") String authorization, + @PathParam("pnfName") String pnfName, @QueryParam("resource-version") String resourceVersion) + throws ExtsysException; } diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/NetworkProxy.java b/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/NetworkProxy.java index 933ecea..075c959 100644 --- a/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/NetworkProxy.java +++ b/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/NetworkProxy.java @@ -43,4 +43,12 @@ public class NetworkProxy { throw new ExtsysException("PUT PNF to A&AI failed.", e); } } + + public String queryPNF(String pnfId) throws ExtsysException { + try { + return network.queryPNF(transactionId, fromAppId, authorization, pnfId); + } catch (Exception e) { + throw new ExtsysException("Query PNF from A&AI failed.", e); + } + } } diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/util/PnfManagerUtil.java b/esr-mgr/src/main/java/org/onap/aai/esr/util/PnfManagerUtil.java index f159cd2..bb9b47e 100644 --- a/esr-mgr/src/main/java/org/onap/aai/esr/util/PnfManagerUtil.java +++ b/esr-mgr/src/main/java/org/onap/aai/esr/util/PnfManagerUtil.java @@ -24,7 +24,7 @@ public class PnfManagerUtil { * @param pnfRegisterInfo * @return */ - public static Pnf pnfRegisterInfo2pnf(PnfRegisterInfo pnfRegisterInfo) { + public Pnf pnfRegisterInfo2pnf(PnfRegisterInfo pnfRegisterInfo) { Pnf pnf = new Pnf(); pnf.setPnfName(pnfRegisterInfo.getPnfId()); pnf.setPnfName2(pnfRegisterInfo.getUserLabel()); @@ -39,4 +39,31 @@ public class PnfManagerUtil { return pnf; } + /** + * @param pnf + * @return + */ + public PnfRegisterInfo pnf2PnfRegisterInfo(Pnf pnf) { + PnfRegisterInfo pnfRegisterInfo = new PnfRegisterInfo(); + pnfRegisterInfo.setPnfId(pnf.getPnfName()); + pnfRegisterInfo.setUserLabel(pnf.getPnfName2()); + String subnetNeId = pnf.getPnfId(); + + String[] ids = subnetNeId.split("-"); + pnfRegisterInfo.setSubnetId(ids[0].toString()); + pnfRegisterInfo.setNeId(ids[1].toString()); + + pnfRegisterInfo.setManagementType(pnf.getEquipType()); + pnfRegisterInfo.setVendor(pnf.getEquipVendor()); + pnfRegisterInfo.setPnfdId(pnf.getEquipModel()); + pnfRegisterInfo.setEmsId(pnf.getManagementOption()); + + String location = pnf.getFrameId(); + String[] locates = location.split("-"); + pnfRegisterInfo.setLattitude(locates[0].toString()); + pnfRegisterInfo.setLongitude(locates[1].toString()); + + return pnfRegisterInfo; + } + } diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/wrapper/PnfManagerWrapper.java b/esr-mgr/src/main/java/org/onap/aai/esr/wrapper/PnfManagerWrapper.java index eb694d0..5efa743 100644 --- a/esr-mgr/src/main/java/org/onap/aai/esr/wrapper/PnfManagerWrapper.java +++ b/esr-mgr/src/main/java/org/onap/aai/esr/wrapper/PnfManagerWrapper.java @@ -24,12 +24,13 @@ import org.onap.aai.esr.externalservice.aai.NetworkProxy; import org.onap.aai.esr.util.PnfManagerUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.gson.Gson; public class PnfManagerWrapper { private static PnfManagerWrapper pnfManagerWrapper; private static final Logger LOG = LoggerFactory.getLogger(PnfManagerWrapper.class); -// private static PnfManagerUtil pnfManagerUtil = new PnfManagerUtil(); + private static PnfManagerUtil pnfManagerUtil = new PnfManagerUtil(); private static NetworkProxy networkProxy = new NetworkProxy(); /** @@ -61,8 +62,22 @@ public class PnfManagerWrapper { * @return */ public Response queryPnfById(String pnfId) { - // TODO Auto-generated method stub - return null; + PnfRegisterInfo pnfRegisterInfo = queryPnf(pnfId); + return Response.ok(pnfRegisterInfo).build(); + } + + private PnfRegisterInfo queryPnf(String pnfId) { + Pnf pnf = new Pnf(); + PnfRegisterInfo pnfRegisterInfo = new PnfRegisterInfo(); + try { + String pnfStr = networkProxy.queryPNF(pnfId); + LOG.info("Response from AAI by query PNF: " + pnfStr); + pnf = new Gson().fromJson(pnfStr, Pnf.class); + pnfRegisterInfo = pnfManagerUtil.pnf2PnfRegisterInfo(pnf); + } catch (ExtsysException e) { + LOG.error("Query PNF detail failed! PNF ID: " + pnfId, e); + } + return pnfRegisterInfo; } /** @@ -89,7 +104,7 @@ public class PnfManagerWrapper { * @return */ public Response registerPnf(PnfRegisterInfo pnfRegisterInfo) { - Pnf pnf = PnfManagerUtil.pnfRegisterInfo2pnf(pnfRegisterInfo); + Pnf pnf = pnfManagerUtil.pnfRegisterInfo2pnf(pnfRegisterInfo); String pnfName = pnf.getPnfName(); try { networkProxy.registerPnf(pnfName, pnf); diff --git a/esr-mgr/src/test/java/org/onap/aai/esr/wrapper/PnfManagerWrapperTest.java b/esr-mgr/src/test/java/org/onap/aai/esr/wrapper/PnfManagerWrapperTest.java index ec65cba..a408fdf 100644 --- a/esr-mgr/src/test/java/org/onap/aai/esr/wrapper/PnfManagerWrapperTest.java +++ b/esr-mgr/src/test/java/org/onap/aai/esr/wrapper/PnfManagerWrapperTest.java @@ -15,6 +15,7 @@ */ package org.onap.aai.esr.wrapper; +import static org.junit.Assert.assertEquals; import javax.ws.rs.core.Response; import org.junit.Assert; import org.junit.Test; @@ -24,6 +25,7 @@ import org.onap.aai.esr.entity.aai.Pnf; import org.onap.aai.esr.entity.rest.PnfRegisterInfo; import org.onap.aai.esr.exception.ExtsysException; import org.onap.aai.esr.externalservice.aai.NetworkProxy; +import org.onap.aai.esr.util.ExtsysUtil; public class PnfManagerWrapperTest { @@ -35,7 +37,7 @@ public class PnfManagerWrapperTest { public void test_registerPnf() throws ExtsysException { PnfRegisterInfo pnfRegisterInfo = new PnfRegisterInfo(); pnfRegisterInfo.setPnfId("pnf1"); - pnfRegisterInfo.setUserLabel("PNF-test"); + pnfRegisterInfo.setUserLabel("PNF test"); pnfRegisterInfo.setSubnetId("subnetId1"); pnfRegisterInfo.setNeId("neId1"); pnfRegisterInfo.setManagementType("Test"); @@ -52,4 +54,37 @@ public class PnfManagerWrapperTest { Assert.assertTrue(response.getStatus() == 200); } } + + @Test + public void test_queryPnfById() throws ExtsysException { + ExtsysUtil extsysUtil = new ExtsysUtil(); + PnfRegisterInfo pnfRegisterInfo = new PnfRegisterInfo(); + pnfRegisterInfo.setPnfId("pnf1"); + pnfRegisterInfo.setUserLabel("PNF test"); + pnfRegisterInfo.setSubnetId("subnetId1"); + pnfRegisterInfo.setNeId("neId1"); + pnfRegisterInfo.setManagementType("Test"); + pnfRegisterInfo.setVendor("ZTE"); + pnfRegisterInfo.setPnfdId("pnfdId1"); + pnfRegisterInfo.setEmsId("emsId1"); + pnfRegisterInfo.setLattitude("121.546"); + pnfRegisterInfo.setLongitude("14.22"); + String PnfStr = "{\"pnf-name\": \"pnf1\"," + + "\"pnf-name2\": \"PNF test\"," + + "\"pnf-id\": \"subnetId1-neId1\"," + + "\"equip-type\": \"Test\"," + + "\"equip-vendor\": \"ZTE\"," + + "\"equip-model\": \"pnfdId1\"," + + "\"management-option\": \"emsId1\"," + + "\"in-maint\": false," + + "\"frame-id\": \"121.546-14.22\"}"; + NetworkProxy mockNetworkProxy = Mockito.mock(NetworkProxy.class); + Mockito.when(mockNetworkProxy.queryPNF(Mockito.anyString())).thenReturn(PnfStr); + PnfManagerWrapper pnfManagerWrapper = new PnfManagerWrapper(mockNetworkProxy); + Response response = pnfManagerWrapper.queryPnfById("pnf1"); + if (response != null) { + Assert.assertTrue(response.getStatus() == 200); + assertEquals(extsysUtil.objectToString(pnfRegisterInfo), extsysUtil.objectToString(response.getEntity())); + } + } } |