42ee079fccb44053aa84f0bad39d1edbbcf04ed4
[aai/esr-server.git] / esr-mgr / src / main / java / org / onap / aai / esr / externalservice / aai / NetworkProxy.java
1 /**
2  * Copyright 2018 ZTE Corporation.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.onap.aai.esr.externalservice.aai;
17
18 import org.glassfish.jersey.client.ClientConfig;
19 import org.onap.aai.esr.common.MsbConfig;
20 import org.onap.aai.esr.entity.aai.Pnf;
21 import org.onap.aai.esr.exception.ExtsysException;
22 import com.eclipsesource.jaxrs.consumer.ConsumerFactory;
23
24 public class NetworkProxy {
25
26     private static INetwork network;
27     private static String transactionId = "9999";
28     private static String fromAppId = "esr-server";
29     private static String authorization = AaiCommon.getAuthenticationCredentials();
30     static {
31         ClientConfig config = new ClientConfig();
32         network =
33                 ConsumerFactory.createConsumer(MsbConfig.getNetworkAddr(), config, INetwork.class);
34     }
35
36     public void registerPnf(String pnfName, Pnf pnf) throws ExtsysException {
37         ClientConfig config = new ClientConfig(new PnfRegisterProvider());
38         INetwork registerPnfServiceproxy =
39                 ConsumerFactory.createConsumer(MsbConfig.getNetworkAddr(), config, INetwork.class);
40         try {
41             registerPnfServiceproxy.registerPnfService(transactionId, fromAppId, authorization, pnfName, pnf);
42         } catch (Exception e) {
43             throw new ExtsysException("PUT PNF to A&AI failed.", e);
44         }
45     }
46     
47     public String queryPNF(String pnfId) throws ExtsysException {
48         try {
49             return network.queryPNF(transactionId, fromAppId, authorization, pnfId);
50         } catch (Exception e) {
51             throw new ExtsysException("Query PNF from A&AI failed.", e);
52         }
53     }
54     
55     public String queryPnfList() throws ExtsysException {
56         try {
57             return network.queryPNFList(transactionId, fromAppId, authorization);
58         } catch (Exception e) {
59             throw new ExtsysException("Query PNF List from A&AI failed.", e);
60         }
61     }
62 }