2 * Copyright 2017 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.externalservice.aai;
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;
26 public class ExternalSystemProxy {
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();
34 ClientConfig config = new ClientConfig();
36 ConsumerFactory.createConsumer(MsbConfig.getExternalSystemAddr(), config, IExternalSystem.class);
39 public static void registerVnfm(String vnfmId, EsrVnfmDetail esrVnfmDetail) throws ExtsysException {
43 ClientConfig config = new ClientConfig(new VnfmRegisterProvider());
44 IExternalSystem registerVnfmServiceproxy =
45 ConsumerFactory.createConsumer(MsbConfig.getExternalSystemAddr(), config, IExternalSystem.class);
47 registerVnfmServiceproxy.registerVNFM(transactionId, fromAppId, authorization, vnfmId, esrVnfmDetail);
48 } catch (Exception e) {
49 throw new ExtsysException("PUT VNFM to A&AI failed.", e);
54 public static String queryVnfmDetail(String vnfmId) throws ExtsysException {
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;
65 return externalSystemproxy.queryVNFMDetail(transactionId, fromAppId, authorization, vnfmId);
66 } catch (Exception e) {
67 throw new ExtsysException("Query VNFM detail from A&AI failed.", e);
71 public static String queryVnfmList() throws ExtsysException {
73 String vnfmListStr = "{\"esr-vnfm\": " + "[{\"vnfm-id\": \"123456\"," + "\"vim-id\": \"987654\","
74 + "\"certificate-url\": \"http://11.22.33.44:5000/v3\"," + "\"resource-version\": \"1\"}]}";
78 return externalSystemproxy.queryVNFMList(transactionId, fromAppId, authorization);
79 } catch (Exception e) {
80 throw new ExtsysException("Query VNFM list from A&AI failed.", e);
84 public static void deleteVnfm(String vnfmId, String resourceVersion) throws ExtsysException {
87 externalSystemproxy.deleteVNFM(transactionId, fromAppId, authorization, vnfmId, resourceVersion);
88 } catch (Exception e) {
89 throw new ExtsysException("Delete VNFM from A&AI failed.", e);
94 public static void registerSdnc(String thirdpartySdncId, EsrThirdpartySdncDetail esrSdncDetail)
95 throws ExtsysException {
97 ClientConfig config = new ClientConfig(new ThirdpartySdncRegisterProvider());
98 IExternalSystem registerSdncServiceproxy =
99 ConsumerFactory.createConsumer(MsbConfig.getExternalSystemAddr(), config, IExternalSystem.class);
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);
109 public static String queryThirdpartySdncDetail(String thirdpartySdncId) throws ExtsysException {
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\"}]}}";
120 return externalSystemproxy.queryThirdpartySdncDetail(transactionId, fromAppId, authorization,
122 } catch (Exception e) {
123 throw new ExtsysException("Query thirdparty SDNC detail from A&AI failed.", e);
127 public static String querySdncList() throws ExtsysException {
130 "{\"esr-thirdparty-sdnc\": " + "[{\"thirdparty-sdnc-id\": \"123456\"," + "\"location\": \"edge\","
131 + "\"product-name\": \"thirdparty SDNC\"," + "\"resource-version\": \"1\"}]}";
135 return externalSystemproxy.queryThirdpartySdncList(transactionId, fromAppId, authorization);
136 } catch (Exception e) {
137 throw new ExtsysException("Query thirdparty SDNC list from A&AI failed.", e);
141 public static void deleteThirdpartySdnc(String sdncId, String resourceVersion) throws ExtsysException {
144 externalSystemproxy.deleteThirdpartySdnc(transactionId, fromAppId, authorization, sdncId,
146 } catch (Exception e) {
147 throw new ExtsysException("Delete thirdparty SDNC from A&AI failed.", e);
152 public static void registerEms(String emsId, EsrEmsDetail emsDetail) throws ExtsysException {
154 ClientConfig config = new ClientConfig(new EmsRegisterProvider());
155 IExternalSystem registerEmsServiceproxy =
156 ConsumerFactory.createConsumer(MsbConfig.getExternalSystemAddr(), config, IExternalSystem.class);
158 registerEmsServiceproxy.registerEMS(transactionId, fromAppId, authorization, emsId, emsDetail);
159 } catch (Exception e) {
160 throw new ExtsysException("PUT EMS to A&AI failed.", e);
165 public static String queryEmsDetail(String emsId) throws ExtsysException {
167 String emsDetailStr = "{\"ems-id\":\"123456\"," + "\"esr-system-info-list\":" + "{\"esr-system-info\":"
168 + "[{\"esr-system-info-id\":\"234567\"," + "\"system-name\":\"EMS_TEST\"," + "\"type\":\"sftp\","
169 + "\"vendor\":\"ZTE\"," + "\"version\":\"V1\"," + "\"user-name\":\"nancy\"," + "\"password\":\"asdf\","
170 + "\"system-type\":\"EMS_RESOUCE\"," + "\"ip-address\":\"127.0.0.1\"," + "\"port\":\"5000\","
171 + "\"passive\":true," + "\"remote-path\":\"/home/per\"}," + "{\"esr-system-info-id\":\"345678\","
172 + "\"system-name\":\"EMS_TEST\"," + "\"type\":\"sftp\"," + "\"vendor\":\"ZTE\"," + "\"version\":\"V1\","
173 + "\"user-name\":\"nancy\"," + "\"password\":\"asdf\"," + "\"system-type\":\"EMS_PERFORMANCE\","
174 + "\"ip-address\":\"127.0.0.1\"," + "\"port\":\"5000\"," + "\"passive\":true,"
175 + "\"remote-path\":\"/home/per\"}," + "{\"esr-system-info-id\":\"456789\","
176 + "\"system-name\":\"EMS_TEST\"," + "\"vendor\":\"ZTE\"," + "\"version\":\"V1\","
177 + "\"user-name\":\"nancy\"," + "\"password\":\"987654\"," + "\"system-type\":\"EMS_ALARM\","
178 + "\"ip-address\":\"127.0.0.1\"," + "\"port\":\"5000\"}]}}";
182 return externalSystemproxy.queryEMSDetail(transactionId, fromAppId, authorization, emsId);
183 } catch (Exception e) {
184 throw new ExtsysException("Query EMS detail from A&AI failed.", e);
188 public static String queryEmsList() throws ExtsysException {
190 return "{\"esr-ems\": [ {\"ems-id\": \"123456\",\"resource-version\": \"1\"}]}";
193 return externalSystemproxy.queryEMSList(transactionId, fromAppId, authorization);
194 } catch (Exception e) {
195 throw new ExtsysException("Query EMS list from A&AI failed.", e);
199 public static void deleteEms(String emsId, String resourceVersion) throws ExtsysException {
202 externalSystemproxy.deleteEMS(transactionId, fromAppId, authorization, emsId, resourceVersion);
203 } catch (Exception e) {
204 throw new ExtsysException("Delete EMS from A&AI failed.", e);