2 * Copyright 2018 ZTE Corporation.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.aai.esr.wrapper;
18 import java.util.ArrayList;
19 import java.util.List;
20 import javax.ws.rs.core.Response;
21 import org.onap.aai.esr.entity.aai.EsrVnfmList;
22 import org.onap.aai.esr.entity.aai.Pnf;
23 import org.onap.aai.esr.entity.aai.PnfList;
24 import org.onap.aai.esr.entity.rest.PnfRegisterInfo;
25 import org.onap.aai.esr.entity.rest.VnfmRegisterInfo;
26 import org.onap.aai.esr.exception.ExceptionUtil;
27 import org.onap.aai.esr.exception.ExtsysException;
28 import org.onap.aai.esr.externalservice.aai.NetworkProxy;
29 import org.onap.aai.esr.util.PnfManagerUtil;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import com.google.gson.Gson;
34 public class PnfManagerWrapper {
35 private static PnfManagerWrapper pnfManagerWrapper;
36 private static final Logger LOG = LoggerFactory.getLogger(PnfManagerWrapper.class);
38 private static PnfManagerUtil pnfManagerUtil = new PnfManagerUtil();
39 private static NetworkProxy networkProxy = new NetworkProxy();
42 * get PnfManagerWrapper instance.
44 * @return pnf manager wrapper instance
46 public static PnfManagerWrapper getInstance() {
47 if (pnfManagerWrapper == null) {
48 pnfManagerWrapper = new PnfManagerWrapper(networkProxy);
50 return pnfManagerWrapper;
53 public PnfManagerWrapper(NetworkProxy networkProxy){
54 PnfManagerWrapper.networkProxy = networkProxy;
60 public Response queryPnfList() {
61 List<PnfRegisterInfo> esrPnfList = new ArrayList<>();
62 PnfList pnfList = new PnfList();
64 String pnflistStr = networkProxy.queryPnfList();
65 pnfList = new Gson().fromJson(pnflistStr, PnfList.class);
66 LOG.info("Response from AAI by query PNF list: " + pnflistStr);
67 esrPnfList = getEsrPnfList(pnfList);
68 return Response.ok(esrPnfList).build();
69 } catch (ExtsysException e) {
70 LOG.error("Query VNFM list failed !", e);
71 return Response.ok(esrPnfList).build();
79 private List<PnfRegisterInfo> getEsrPnfList(PnfList pnfList) {
80 List<PnfRegisterInfo> esrPnfList = new ArrayList<>();
81 for (int i = 0; i < pnfList.getPnf().size(); i++) {
82 Pnf pnf = pnfList.getPnf().get(i);
83 PnfRegisterInfo pnfRegisterInfo = pnfManagerUtil.pnf2PnfRegisterInfo(pnf);
84 esrPnfList.add(pnfRegisterInfo);
93 public Response queryPnfById(String pnfId) {
94 PnfRegisterInfo pnfRegisterInfo = queryPnf(pnfId);
95 return Response.ok(pnfRegisterInfo).build();
98 private PnfRegisterInfo queryPnf(String pnfId) {
100 PnfRegisterInfo pnfRegisterInfo = new PnfRegisterInfo();
102 String pnfStr = networkProxy.queryPNF(pnfId);
103 LOG.info("Response from AAI by query PNF: " + pnfStr);
104 pnf = new Gson().fromJson(pnfStr, Pnf.class);
105 pnfRegisterInfo = pnfManagerUtil.pnf2PnfRegisterInfo(pnf);
106 } catch (ExtsysException e) {
107 LOG.error("Query PNF detail failed! PNF ID: " + pnfId, e);
109 return pnfRegisterInfo;
116 public Response delPnf(String pnfId) {
117 // TODO Auto-generated method stub
126 public Response updatePnf(PnfRegisterInfo pnf, String pnfId) {
127 // TODO Auto-generated method stub
135 public Response registerPnf(PnfRegisterInfo pnfRegisterInfo) {
136 Pnf pnf = pnfManagerUtil.pnfRegisterInfo2pnf(pnfRegisterInfo);
137 String pnfName = pnf.getPnfName();
139 networkProxy.registerPnf(pnfName, pnf);
140 return Response.ok().build();
141 } catch (ExtsysException e) {
142 LOG.error("Register PNF failed !", e);
143 throw ExceptionUtil.buildExceptionResponse(e.getMessage());