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 javax.ws.rs.core.Response;
19 import org.onap.aai.esr.entity.aai.Pnf;
20 import org.onap.aai.esr.entity.rest.PnfRegisterInfo;
21 import org.onap.aai.esr.exception.ExceptionUtil;
22 import org.onap.aai.esr.exception.ExtsysException;
23 import org.onap.aai.esr.externalservice.aai.NetworkProxy;
24 import org.onap.aai.esr.util.PnfManagerUtil;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27 import com.google.gson.Gson;
29 public class PnfManagerWrapper {
30 private static PnfManagerWrapper pnfManagerWrapper;
31 private static final Logger LOG = LoggerFactory.getLogger(PnfManagerWrapper.class);
33 private static PnfManagerUtil pnfManagerUtil = new PnfManagerUtil();
34 private static NetworkProxy networkProxy = new NetworkProxy();
37 * get PnfManagerWrapper instance.
39 * @return pnf manager wrapper instance
41 public static PnfManagerWrapper getInstance() {
42 if (pnfManagerWrapper == null) {
43 pnfManagerWrapper = new PnfManagerWrapper(networkProxy);
45 return pnfManagerWrapper;
48 public PnfManagerWrapper(NetworkProxy networkProxy){
49 PnfManagerWrapper.networkProxy = networkProxy;
55 public Response queryPnfList() {
56 // TODO Auto-generated method stub
64 public Response queryPnfById(String pnfId) {
65 PnfRegisterInfo pnfRegisterInfo = queryPnf(pnfId);
66 return Response.ok(pnfRegisterInfo).build();
69 private PnfRegisterInfo queryPnf(String pnfId) {
71 PnfRegisterInfo pnfRegisterInfo = new PnfRegisterInfo();
73 String pnfStr = networkProxy.queryPNF(pnfId);
74 LOG.info("Response from AAI by query PNF: " + pnfStr);
75 pnf = new Gson().fromJson(pnfStr, Pnf.class);
76 pnfRegisterInfo = pnfManagerUtil.pnf2PnfRegisterInfo(pnf);
77 } catch (ExtsysException e) {
78 LOG.error("Query PNF detail failed! PNF ID: " + pnfId, e);
80 return pnfRegisterInfo;
87 public Response delPnf(String pnfId) {
88 // TODO Auto-generated method stub
97 public Response updatePnf(PnfRegisterInfo pnf, String pnfId) {
98 // TODO Auto-generated method stub
106 public Response registerPnf(PnfRegisterInfo pnfRegisterInfo) {
107 Pnf pnf = pnfManagerUtil.pnfRegisterInfo2pnf(pnfRegisterInfo);
108 String pnfName = pnf.getPnfName();
110 networkProxy.registerPnf(pnfName, pnf);
111 return Response.ok().build();
112 } catch (ExtsysException e) {
113 LOG.error("Register PNF failed !", e);
114 throw ExceptionUtil.buildExceptionResponse(e.getMessage());