From 8c4d0d90eda21638826a9c31166cc814f699c40b Mon Sep 17 00:00:00 2001 From: Zi Li Date: Tue, 21 Aug 2018 03:18:38 +0000 Subject: Realize the delete PNF list API. Issue-ID: AAI-1499 Change-Id: I443d9bb7459058b7387d2170d5e43530de1efece Signed-off-by: Zi Li --- .../aai/esr/externalservice/aai/NetworkProxy.java | 8 ++++++ .../onap/aai/esr/wrapper/PnfManagerWrapper.java | 30 +++++++++++++++++++--- .../aai/esr/wrapper/PnfManagerWrapperTest.java | 13 ++++++++-- 3 files changed, 45 insertions(+), 6 deletions(-) (limited to 'esr-mgr/src') 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 42ee079..c891d19 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 @@ -59,4 +59,12 @@ public class NetworkProxy { throw new ExtsysException("Query PNF List from A&AI failed.", e); } } + + public void deletePnf(String pnfId, String resourceVersion) throws ExtsysException { + try { + network.deletePNF(transactionId, fromAppId, authorization, pnfId, resourceVersion); + } catch (Exception e) { + throw new ExtsysException("Delete PNF from A&AI failed.", e); + } + } } 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 c017eba..0683769 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 @@ -18,11 +18,9 @@ package org.onap.aai.esr.wrapper; import java.util.ArrayList; import java.util.List; import javax.ws.rs.core.Response; -import org.onap.aai.esr.entity.aai.EsrVnfmList; import org.onap.aai.esr.entity.aai.Pnf; import org.onap.aai.esr.entity.aai.PnfList; import org.onap.aai.esr.entity.rest.PnfRegisterInfo; -import org.onap.aai.esr.entity.rest.VnfmRegisterInfo; import org.onap.aai.esr.exception.ExceptionUtil; import org.onap.aai.esr.exception.ExtsysException; import org.onap.aai.esr.externalservice.aai.NetworkProxy; @@ -114,8 +112,32 @@ public class PnfManagerWrapper { * @return */ public Response delPnf(String pnfId) { - // TODO Auto-generated method stub - return null; + String resourceVersion = getResourceVersion(pnfId); + try { + networkProxy.deletePnf(pnfId, resourceVersion); + return Response.noContent().build(); + } catch (ExtsysException e) { + LOG.error("Delete PNF from A&AI failed! PNF ID: " + pnfId + "resouce-version:" + resourceVersion, e); + throw ExceptionUtil.buildExceptionResponse(e.getMessage()); + } + } + + /** + * @param pnfId + * @return + */ + private String getResourceVersion(String pnfId) { + String resourceVersion = null; + try { + String pnfStr = networkProxy.queryPNF(pnfId); + Pnf pnf = new Gson().fromJson(pnfStr, Pnf.class); + if (pnf != null && pnf.getResourceVersion() != null) { + resourceVersion = pnf.getResourceVersion(); + } + } catch (ExtsysException e) { + LOG.error("Query PNF detail failed! PNF ID: " + pnfId, e); + } + return resourceVersion; } /** 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 038e275..aa6a364 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 @@ -25,9 +25,7 @@ import org.mockito.Mockito; import org.onap.aai.esr.common.MsbConfig; import org.onap.aai.esr.entity.aai.Pnf; import org.onap.aai.esr.entity.rest.PnfRegisterInfo; -import org.onap.aai.esr.entity.rest.VnfmRegisterInfo; import org.onap.aai.esr.exception.ExtsysException; -import org.onap.aai.esr.externalservice.aai.ExternalSystemProxy; import org.onap.aai.esr.externalservice.aai.NetworkProxy; import org.onap.aai.esr.util.ExtsysUtil; @@ -126,4 +124,15 @@ public class PnfManagerWrapperTest { assertEquals(extsysUtil.objectToString(esrPnfList), extsysUtil.objectToString(response.getEntity())); } } + + @Test + public void test_delPnf() throws ExtsysException { + NetworkProxy mockNetworkProxy = Mockito.mock(NetworkProxy.class); + Mockito.doNothing().when(mockNetworkProxy).deletePnf(Mockito.anyString(), Mockito.anyString()); + PnfManagerWrapper pnfManagerWrapper = new PnfManagerWrapper(mockNetworkProxy); + Response response = pnfManagerWrapper.delPnf("pnf1"); + if (response != null) { + Assert.assertTrue(response.getStatus() == 204); + } + } } -- cgit 1.2.3-korg