X-Git-Url: https://gerrit.onap.org/r/gitweb?p=aai%2Fesr-server.git;a=blobdiff_plain;f=esr-mgr%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faai%2Fesr%2Fwrapper%2FPnfManagerWrapper.java;h=c017ebaca90994c1f42071bce30e8abf1785944f;hp=b363c04545e24703bc401089a76219a6deb1fa01;hb=d5eb2430bf0013b8be832eb02813c3844c0cef91;hpb=16e963509621830d8828054750f9512b535b1948 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 b363c04..c017eba 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 @@ -15,18 +15,28 @@ */ 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.externalservice.aai.ExternalSystemProxy; +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; +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 ExternalSystemProxy externalSystemProxy = new ExternalSystemProxy(); + private static PnfManagerUtil pnfManagerUtil = new PnfManagerUtil(); + private static NetworkProxy networkProxy = new NetworkProxy(); /** * get PnfManagerWrapper instance. @@ -35,21 +45,45 @@ public class PnfManagerWrapper { */ public static PnfManagerWrapper getInstance() { if (pnfManagerWrapper == null) { - pnfManagerWrapper = new PnfManagerWrapper(externalSystemProxy); + pnfManagerWrapper = new PnfManagerWrapper(networkProxy); } return pnfManagerWrapper; } - public PnfManagerWrapper(ExternalSystemProxy externalSystemProxy){ - PnfManagerWrapper.externalSystemProxy = externalSystemProxy; + public PnfManagerWrapper(NetworkProxy networkProxy){ + PnfManagerWrapper.networkProxy = networkProxy; } /** * @return */ public Response queryPnfList() { - // TODO Auto-generated method stub - return null; + List esrPnfList = new ArrayList<>(); + PnfList pnfList = new PnfList(); + try { + String pnflistStr = networkProxy.queryPnfList(); + pnfList = new Gson().fromJson(pnflistStr, PnfList.class); + LOG.info("Response from AAI by query PNF list: " + pnflistStr); + esrPnfList = getEsrPnfList(pnfList); + return Response.ok(esrPnfList).build(); + } catch (ExtsysException e) { + LOG.error("Query VNFM list failed !", e); + return Response.ok(esrPnfList).build(); + } + } + + /** + * @param pnfList + * @return + */ + private List getEsrPnfList(PnfList pnfList) { + List esrPnfList = new ArrayList<>(); + for (int i = 0; i < pnfList.getPnf().size(); i++) { + Pnf pnf = pnfList.getPnf().get(i); + PnfRegisterInfo pnfRegisterInfo = pnfManagerUtil.pnf2PnfRegisterInfo(pnf); + esrPnfList.add(pnfRegisterInfo); + } + return esrPnfList; } /** @@ -57,8 +91,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; } /** @@ -84,8 +132,15 @@ public class PnfManagerWrapper { * @param pnf * @return */ - public Response registerPnf(PnfRegisterInfo pnf) { - // TODO Auto-generated method stub - return null; + public Response registerPnf(PnfRegisterInfo pnfRegisterInfo) { + Pnf pnf = pnfManagerUtil.pnfRegisterInfo2pnf(pnfRegisterInfo); + String pnfName = pnf.getPnfName(); + try { + networkProxy.registerPnf(pnfName, pnf); + return Response.ok().build(); + } catch (ExtsysException e) { + LOG.error("Register PNF failed !", e); + throw ExceptionUtil.buildExceptionResponse(e.getMessage()); + } } }