0361747572c6cecc6677210d44ca60d371ad9799
[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.exception.ExtsysException;
24 import com.eclipsesource.jaxrs.consumer.ConsumerFactory;
25
26 public class ExternalSystemProxy {
27
28     public static boolean isTest = false;
29     private static IExternalSystem externalSystemproxy;
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         externalSystemproxy =
36                 ConsumerFactory.createConsumer(MsbConfig.getExternalSystemAddr(), config, IExternalSystem.class);
37     }
38
39     public static void registerVnfm(String vnfmId, EsrVnfmDetail esrVnfmDetail) throws ExtsysException {
40         if (isTest) {
41
42         } else {
43             ClientConfig config = new ClientConfig(new VnfmRegisterProvider());
44             IExternalSystem registerVnfmServiceproxy =
45                     ConsumerFactory.createConsumer(MsbConfig.getExternalSystemAddr(), config, IExternalSystem.class);
46             try {
47                 registerVnfmServiceproxy.registerVNFM(transactionId, fromAppId, authorization, vnfmId, esrVnfmDetail);
48             } catch (Exception e) {
49                 throw new ExtsysException("PUT VNFM to A&AI failed.", e);
50             }
51         }
52     }
53
54     public static String queryVnfmDetail(String vnfmId) throws ExtsysException {
55         if (isTest) {
56             String esrVnfmDetailStr = "{\"vnfm-id\":\"123456\"," + "\"vim-id\":\"987654\","
57                     + "\"certificate-url\":\"http://11.22.33.44:5000/v3\"," + "\"esr-system-info-list\":{"
58                     + "\"esr-system-info\":[{" + "\"esr-system-info-id\":\"qwerty\"," + "\"system-name\":\"ONAP VNFM\","
59                     + "\"type\":\"vnfm\"," + "\"vendor\":\"zte\"," + "\"version\":\"v1\","
60                     + "\"service-url\":\"http://10.11.22.33:8000\"," + "\"user-name\":\"onap\","
61                     + "\"password\":\"987654\"," + "\"system-type\":\"VNFM\"}]}}";
62             return esrVnfmDetailStr;
63         }
64         try {
65             return externalSystemproxy.queryVNFMDetail(transactionId, fromAppId, authorization, vnfmId);
66         } catch (Exception e) {
67             throw new ExtsysException("Query VNFM detail from A&AI failed.", e);
68         }
69     }
70
71     public static String queryVnfmList() throws ExtsysException {
72         if (isTest) {
73             String vnfmListStr = "{\"esr-vnfm\": " + "[{\"vnfm-id\": \"123456\"," + "\"vim-id\": \"987654\","
74                     + "\"certificate-url\": \"http://11.22.33.44:5000/v3\"," + "\"resource-version\": \"1\"}]}";
75             return vnfmListStr;
76         }
77         try {
78             return externalSystemproxy.queryVNFMList(transactionId, fromAppId, authorization);
79         } catch (Exception e) {
80             throw new ExtsysException("Query VNFM list from A&AI failed.", e);
81         }
82     }
83
84     public static void deleteVnfm(String vnfmId, String resourceVersion) throws ExtsysException {
85         if (!isTest) {
86             try {
87                 externalSystemproxy.deleteVNFM(transactionId, fromAppId, authorization, vnfmId, resourceVersion);
88             } catch (Exception e) {
89                 throw new ExtsysException("Delete VNFM from A&AI failed.", e);
90             }
91         }
92     }
93
94     public static void registerSdnc(String thirdpartySdncId, EsrThirdpartySdncDetail esrSdncDetail)
95             throws ExtsysException {
96         if (!isTest) {
97             ClientConfig config = new ClientConfig(new ThirdpartySdncRegisterProvider());
98             IExternalSystem registerSdncServiceproxy =
99                     ConsumerFactory.createConsumer(MsbConfig.getExternalSystemAddr(), config, IExternalSystem.class);
100             try {
101                 registerSdncServiceproxy.registerThirdpartySdnc(transactionId, fromAppId, authorization,
102                         thirdpartySdncId, esrSdncDetail);
103             } catch (Exception e) {
104                 throw new ExtsysException("PUT thirdparty SDNC to A&AI failed.", e);
105             }
106         }
107     }
108
109     public static String queryThirdpartySdncDetail(String thirdpartySdncId) throws ExtsysException {
110         if (isTest) {
111             String sdncDetail = "{\"thirdparty-sdnc-id\":\"123456\"," + "\"location\":\"edge\","
112                     + "\"product-name\":\"thirdparty SDNC\"," + "\"esr-system-info-list\":{" + "\"esr-system-info\":"
113                     + "[{\"esr-system-info-id\":\"987654\"," + "\"system-name\":\"SDNC_TEST\"," + "\"type\":\"SDNC\","
114                     + "\"vendor\":\"zte\"," + "\"version\":\"v1\"," + "\"service-url\":\"http://127.0.0.1:8000\","
115                     + "\"user-name\":\"nancy\"," + "\"password\":\"123987\"," + "\"system-type\":\"thirdparty_SDNC\","
116                     + "\"protocol\":\"protocol\"}]}}";
117             return sdncDetail;
118         }
119         try {
120             return externalSystemproxy.queryThirdpartySdncDetail(transactionId, fromAppId, authorization,
121                     thirdpartySdncId);
122         } catch (Exception e) {
123             throw new ExtsysException("Query thirdparty SDNC detail from A&AI failed.", e);
124         }
125     }
126
127     public static String querySdncList() throws ExtsysException {
128         if (isTest) {
129             String sdncList =
130                     "{\"esr-thirdparty-sdnc\": " + "[{\"thirdparty-sdnc-id\": \"123456\"," + "\"location\": \"edge\","
131                             + "\"product-name\": \"thirdparty SDNC\"," + "\"resource-version\": \"1\"}]}";
132             return sdncList;
133         }
134         try {
135             return externalSystemproxy.queryThirdpartySdncList(transactionId, fromAppId, authorization);
136         } catch (Exception e) {
137             throw new ExtsysException("Query thirdparty SDNC list from A&AI failed.", e);
138         }
139     }
140
141     public static void deleteThirdpartySdnc(String sdncId, String resourceVersion) throws ExtsysException {
142         if (!isTest) {
143             try {
144                 externalSystemproxy.deleteThirdpartySdnc(transactionId, fromAppId, authorization, sdncId,
145                         resourceVersion);
146             } catch (Exception e) {
147                 throw new ExtsysException("Delete thirdparty SDNC from A&AI failed.", e);
148             }
149         }
150     }
151
152     public static 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 static String queryEmsDetail(String emsId) throws ExtsysException {
164         try {
165             return externalSystemproxy.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 static String queryEmsList() throws ExtsysException {
172         try {
173             return externalSystemproxy.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 static void deleteEms(String emsId, String resourceVersion) throws ExtsysException {
180         try {
181             externalSystemproxy.deleteEMS(transactionId, fromAppId, authorization, emsId, resourceVersion);
182         } catch (Exception e) {
183             throw new ExtsysException("Delete EMS from A&AI failed.", e);
184         }
185     }
186 }