Merge "Modify JAVA Env Setting"
[aai/esr-server.git] / esr-mgr / src / main / java / org / onap / aai / esr / externalservice / aai / ExternalSystemProxy.java
1 /**
2  * Copyright 2017 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.EsrEmsDetail;
21 import org.onap.aai.esr.entity.aai.EsrThirdpartySdncDetail;
22 import org.onap.aai.esr.entity.aai.EsrVnfmDetail;
23 import org.onap.aai.esr.entity.aai.EsrNfvoDetail;
24 import org.onap.aai.esr.exception.ExtsysException;
25 import com.eclipsesource.jaxrs.consumer.ConsumerFactory;
26
27 public class ExternalSystemProxy {
28
29     private static IExternalSystem externalSystem, externalSystemV16;
30     private static String transactionId = "9999";
31     private static String fromAppId = "esr-server";
32     private static String authorization = AaiCommon.getAuthenticationCredentials();
33     static {
34         ClientConfig config = new ClientConfig();
35         externalSystem =
36                 ConsumerFactory.createConsumer(MsbConfig.getExternalSystemAddr(), config, IExternalSystem.class);
37         externalSystemV16 =
38                 ConsumerFactory.createConsumer(MsbConfig.getExternalSystemAddrV16(), config, IExternalSystem.class);
39     }
40     
41     public void registerVnfm(String vnfmId, EsrVnfmDetail esrVnfmDetail) throws ExtsysException {
42         ClientConfig config = new ClientConfig(new VnfmRegisterProvider());
43         IExternalSystem registerVnfmServiceproxy =
44                 ConsumerFactory.createConsumer(MsbConfig.getExternalSystemAddr(), config, IExternalSystem.class);
45         try {
46             registerVnfmServiceproxy.registerVNFM(transactionId, fromAppId, authorization, vnfmId, esrVnfmDetail);
47         } catch (Exception e) {
48             throw new ExtsysException("PUT VNFM to A&AI failed.", e);
49         }
50     }
51
52     public String queryVnfmDetail(String vnfmId) throws ExtsysException {
53         try {
54             return externalSystem.queryVNFMDetail(transactionId, fromAppId, authorization, vnfmId);
55         } catch (Exception e) {
56             throw new ExtsysException("Query VNFM detail from A&AI failed.", e);
57         }
58     }
59
60     public String queryVnfmList() throws ExtsysException {
61         try {
62             return externalSystem.queryVNFMList(transactionId, fromAppId, authorization);
63         } catch (Exception e) {
64             throw new ExtsysException("Query VNFM list from A&AI failed.", e);
65         }
66     }
67
68     public void deleteVnfm(String vnfmId, String resourceVersion) throws ExtsysException {
69         try {
70             externalSystem.deleteVNFM(transactionId, fromAppId, authorization, vnfmId, resourceVersion);
71         } catch (Exception e) {
72             throw new ExtsysException("Delete VNFM from A&AI failed.", e);
73         }
74     }
75
76     public void registerNfvo(String nfvoId, EsrNfvoDetail esrNfvoDetail) throws ExtsysException {
77         ClientConfig config = new ClientConfig(new NfvoRegisterProvider());
78         IExternalSystem registerNfvoServiceproxy =
79                 ConsumerFactory.createConsumer(MsbConfig.getExternalSystemAddrV16(), config, IExternalSystem.class);
80         try {
81             registerNfvoServiceproxy.registerNFVO(transactionId, fromAppId, authorization, nfvoId, esrNfvoDetail);
82         } catch (Exception e) {
83             throw new ExtsysException("PUT NFVO to A&AI failed.", e);
84         }
85     }
86
87     public String queryNfvoDetail(String nfvoId) throws ExtsysException {
88         try {
89             return externalSystemV16.queryNFVODetail(transactionId, fromAppId, authorization, nfvoId);
90         } catch (Exception e) {
91             throw new ExtsysException("Query NFVO detail from A&AI failed.", e);
92         }
93     }
94
95     public String queryNfvoList() throws ExtsysException {
96         try {
97             return externalSystemV16.queryNFVOList(transactionId, fromAppId, authorization);
98         } catch (Exception e) {
99             throw new ExtsysException("Query NFVO list from A&AI failed.", e);
100         }
101     }
102
103     public void deleteNfvo(String nfvoId, String resourceVersion) throws ExtsysException {
104         try {
105             externalSystemV16.deleteNFVO(transactionId, fromAppId, authorization, nfvoId, resourceVersion);
106         } catch (Exception e) {
107             throw new ExtsysException("Delete NFVO from A&AI failed.", e);
108         }
109     }
110
111
112
113
114
115     public void registerSdnc(String thirdpartySdncId, EsrThirdpartySdncDetail esrSdncDetail) throws ExtsysException {
116         ClientConfig config = new ClientConfig(new ThirdpartySdncRegisterProvider());
117         IExternalSystem registerSdncServiceproxy =
118                 ConsumerFactory.createConsumer(MsbConfig.getExternalSystemAddr(), config, IExternalSystem.class);
119         try {
120             registerSdncServiceproxy.registerThirdpartySdnc(transactionId, fromAppId, authorization, thirdpartySdncId,
121                     esrSdncDetail);
122         } catch (Exception e) {
123             throw new ExtsysException("PUT thirdparty SDNC to A&AI failed.", e);
124         }
125     }
126
127     public String queryThirdpartySdncDetail(String thirdpartySdncId) throws ExtsysException {
128         try {
129             return externalSystem.queryThirdpartySdncDetail(transactionId, fromAppId, authorization,
130                     thirdpartySdncId);
131         } catch (Exception e) {
132             throw new ExtsysException("Query thirdparty SDNC detail from A&AI failed.", e);
133         }
134     }
135
136     public String querySdncList() throws ExtsysException {
137         try {
138             return externalSystem.queryThirdpartySdncList(transactionId, fromAppId, authorization);
139         } catch (Exception e) {
140             throw new ExtsysException("Query thirdparty SDNC list from A&AI failed.", e);
141         }
142     }
143
144     public void deleteThirdpartySdnc(String sdncId, String resourceVersion) throws ExtsysException {
145         try {
146             externalSystem.deleteThirdpartySdnc(transactionId, fromAppId, authorization, sdncId, resourceVersion);
147         } catch (Exception e) {
148             throw new ExtsysException("Delete thirdparty SDNC from A&AI failed.", e);
149         }
150     }
151
152     public void registerEms(String emsId, EsrEmsDetail emsDetail) throws ExtsysException {
153         ClientConfig config = new ClientConfig(new EmsRegisterProvider());
154         IExternalSystem registerEmsServiceproxy =
155                 ConsumerFactory.createConsumer(MsbConfig.getExternalSystemAddr(), config, IExternalSystem.class);
156         try {
157             registerEmsServiceproxy.registerEMS(transactionId, fromAppId, authorization, emsId, emsDetail);
158         } catch (Exception e) {
159             throw new ExtsysException("PUT EMS to A&AI failed.", e);
160         }
161     }
162
163     public String queryEmsDetail(String emsId) throws ExtsysException {
164         try {
165             return externalSystem.queryEMSDetail(transactionId, fromAppId, authorization, emsId);
166         } catch (Exception e) {
167             throw new ExtsysException("Query EMS detail from A&AI failed.", e);
168         }
169     }
170
171     public String queryEmsList() throws ExtsysException {
172         try {
173             return externalSystem.queryEMSList(transactionId, fromAppId, authorization);
174         } catch (Exception e) {
175             throw new ExtsysException("Query EMS list from A&AI failed.", e);
176         }
177     }
178
179     public void deleteEms(String emsId, String resourceVersion) throws ExtsysException {
180         try {
181             externalSystem.deleteEMS(transactionId, fromAppId, authorization, emsId, resourceVersion);
182         } catch (Exception e) {
183             throw new ExtsysException("Delete EMS from A&AI failed.", e);
184         }
185     }
186 }