Fix the nonstandard coding.
[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
25 import com.eclipsesource.jaxrs.consumer.ConsumerFactory;
26
27 public class ExternalSystemProxy {
28
29   public static boolean isTest = false;
30   private static IExternalSystem externalSystemproxy;
31   private static String transactionId = "9999";
32   private static String fromAppId = "esr-server";
33   private static String authorization = AaiCommon.getAuthenticationCredentials();
34   static {
35     ClientConfig config = new ClientConfig();
36     externalSystemproxy = ConsumerFactory.createConsumer(MsbConfig.getExternalSystemAddr(),
37         config, IExternalSystem.class);
38   }
39
40   public static void registerVnfm(String vnfmId, EsrVnfmDetail esrVnfmDetail)
41       throws ExtsysException {
42     if (isTest) {
43
44     } else {
45       ClientConfig config = new ClientConfig(new VnfmRegisterProvider());
46       IExternalSystem registerVnfmServiceproxy = ConsumerFactory
47           .createConsumer(MsbConfig.getExternalSystemAddr(), config, IExternalSystem.class);
48       try {
49         registerVnfmServiceproxy.registerVNFM(transactionId, fromAppId, authorization, vnfmId,
50             esrVnfmDetail);
51       } catch (Exception e) {
52         throw new ExtsysException("PUT VNFM to A&AI failed.", e);
53       }
54     }
55   }
56   
57   public static String queryVnfmDetail(String vnfmId) throws ExtsysException {
58     if(isTest) {
59       String esrVnfmDetailStr = "{\"vnfm-id\":\"123456\","
60           + "\"vim-id\":\"987654\","
61           + "\"certificate-url\":\"http://11.22.33.44:5000/v3\","
62           + "\"esr-system-info-list\":{"
63           + "\"esr-system-info\":[{"
64           + "\"esr-system-info-id\":\"qwerty\","
65           + "\"system-name\":\"ONAP VNFM\","
66           + "\"type\":\"vnfm\","
67           + "\"vendor\":\"zte\","
68           + "\"version\":\"v1\","
69           + "\"service-url\":\"http://10.11.22.33:8000\","
70           + "\"user-name\":\"onap\","
71           + "\"password\":\"987654\","
72           + "\"system-type\":\"VNFM\"}]}}";
73       return esrVnfmDetailStr;
74     }
75     try {
76       return externalSystemproxy.queryVNFMDetail(transactionId, fromAppId, authorization, vnfmId);
77     } catch (Exception e) {
78       throw new ExtsysException("Query VNFM detail from A&AI failed.", e);
79     }
80   }
81   
82   public static String queryVnfmList() throws ExtsysException {
83     if(isTest) {
84       String vnfmListStr = "{\"esr-vnfm\": "
85           + "[{\"vnfm-id\": \"123456\","
86           + "\"vim-id\": \"987654\","
87           + "\"certificate-url\": \"http://11.22.33.44:5000/v3\","
88           + "\"resource-version\": \"1\"}]}";
89       return vnfmListStr;
90     }
91     try {
92       return externalSystemproxy.queryVNFMList(transactionId, fromAppId, authorization);
93     } catch (Exception e) {
94       throw new ExtsysException("Query VNFM list from A&AI failed.", e);
95     }
96   }
97   
98   public static void deleteVnfm(String vnfmId, String resourceVersion) throws ExtsysException {
99     if(!isTest) {
100       try {
101         externalSystemproxy.deleteVNFM(transactionId, fromAppId, authorization, vnfmId, resourceVersion);
102       } catch (Exception e) {
103         throw new ExtsysException("Delete VNFM from A&AI failed.", e);
104       }
105     }
106   }
107   
108   public static void registerSdnc(String thirdpartySdncId, EsrThirdpartySdncDetail esrSdncDetail) throws ExtsysException {
109     if(!isTest) {
110       ClientConfig config = new ClientConfig(new ThirdpartySdncRegisterProvider());
111       IExternalSystem registerSdncServiceproxy = ConsumerFactory
112           .createConsumer(MsbConfig.getExternalSystemAddr(), config, IExternalSystem.class);
113       try {
114         registerSdncServiceproxy.registerThirdpartySdnc(transactionId, fromAppId, authorization, thirdpartySdncId,
115             esrSdncDetail);
116       } catch (Exception e) {
117         throw new ExtsysException("PUT thirdparty SDNC to A&AI failed.", e);
118       }
119     }
120   }
121   
122   public static String queryThirdpartySdncDetail(String thirdpartySdncId) throws ExtsysException {
123     if(isTest) {
124       String sdncDetail = "{\"thirdparty-sdnc-id\":\"123456\","
125         + "\"location\":\"edge\","
126         + "\"product-name\":\"thirdparty SDNC\","
127         + "\"esr-system-info-list\":{"
128         + "\"esr-system-info\":"
129         + "[{\"esr-system-info-id\":\"987654\","
130         + "\"system-name\":\"SDNC_TEST\","
131         + "\"type\":\"SDNC\","
132         + "\"vendor\":\"zte\","
133         + "\"version\":\"v1\","
134         + "\"service-url\":\"http://127.0.0.1:8000\","
135         + "\"user-name\":\"nancy\","
136         + "\"password\":\"123987\","
137         + "\"system-type\":\"thirdparty_SDNC\","
138         + "\"protocol\":\"protocol\"}]}}";
139       return sdncDetail;
140     }
141     try {
142       return externalSystemproxy.queryThirdpartySdncDetail(transactionId, fromAppId, authorization, thirdpartySdncId);
143     } catch (Exception e) {
144       throw new ExtsysException("Query thirdparty SDNC detail from A&AI failed.", e);
145     }
146   }
147   
148   public static String querySdncList() throws ExtsysException {
149     if(isTest) {
150       String sdncList = "{\"esr-thirdparty-sdnc\": "
151           + "[{\"thirdparty-sdnc-id\": \"123456\","
152           + "\"location\": \"edge\","
153           + "\"product-name\": \"thirdparty SDNC\","
154           + "\"resource-version\": \"1\"}]}";
155       return sdncList;
156     }
157     try {
158       return externalSystemproxy.queryThirdpartySdncList(transactionId, fromAppId, authorization);
159     } catch (Exception e) {
160       throw new ExtsysException("Query thirdparty SDNC list from A&AI failed.", e);
161     }
162   }
163   
164   public static void deleteThirdpartySdnc(String sdncId, String resourceVersion) throws ExtsysException {
165     if(!isTest) {
166       try {
167         externalSystemproxy.deleteThirdpartySdnc(transactionId, fromAppId, authorization, sdncId, resourceVersion);
168       } catch (Exception e) {
169         throw new ExtsysException("Delete thirdparty SDNC from A&AI failed.", e);
170       }
171     }
172   }
173   
174   public static void registerEms(String emsId, EsrEmsDetail emsDetail) throws ExtsysException {
175     ClientConfig config = new ClientConfig(new EmsRegisterProvider());
176     IExternalSystem registerEmsServiceproxy = ConsumerFactory
177         .createConsumer(MsbConfig.getExternalSystemAddr(), config, IExternalSystem.class);
178     try {
179       registerEmsServiceproxy.registerEMS(transactionId, fromAppId, authorization, emsId,
180           emsDetail);
181     } catch (Exception e) {
182       throw new ExtsysException("PUT EMS to A&AI failed.", e);
183     }
184   }
185   
186   public static String queryEmsDetail(String emsId) throws ExtsysException {
187     try {
188       return externalSystemproxy.queryEMSDetail(transactionId, fromAppId, authorization, emsId);
189     } catch (Exception e) {
190       throw new ExtsysException("Query EMS detail from A&AI failed.", e);
191     }
192   }
193   
194   public static String queryEmsList() throws ExtsysException {
195     try {
196       return externalSystemproxy.queryEMSList(transactionId, fromAppId, authorization);
197     } catch (Exception e) {
198       throw new ExtsysException("Query EMS list from A&AI failed.", e);
199     }
200   }
201   
202   public static void deleteEms(String emsId, String resourceVersion) throws ExtsysException {
203     try {
204       externalSystemproxy.deleteEMS(transactionId, fromAppId, authorization, emsId, resourceVersion);
205     } catch (Exception e) {
206       throw new ExtsysException("Delete EMS from A&AI failed.", e);
207     }
208   }
209 }