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 {
41 ClientConfig config = new ClientConfig(new VnfmRegisterProvider());
42 IExternalSystem registerVnfmServiceproxy =
43 ConsumerFactory.createConsumer(MsbConfig.getExternalSystemAddr(), config, IExternalSystem.class);
45 registerVnfmServiceproxy.registerVNFM(transactionId, fromAppId, authorization, vnfmId, esrVnfmDetail);
46 } catch (Exception e) {
47 throw new ExtsysException("PUT VNFM to A&AI failed.", e);
52 public static String queryVnfmDetail(String vnfmId) throws ExtsysException {
54 String esrVnfmDetailStr = "{\"vnfm-id\":\"123456\"," + "\"vim-id\":\"987654\","
55 + "\"certificate-url\":\"http://11.22.33.44:5000/v3\"," + "\"esr-system-info-list\":{"
56 + "\"esr-system-info\":[{" + "\"esr-system-info-id\":\"qwerty\"," + "\"system-name\":\"ONAP VNFM\","
57 + "\"type\":\"vnfm\"," + "\"vendor\":\"zte\"," + "\"version\":\"v1\","
58 + "\"service-url\":\"http://10.11.22.33:8000\"," + "\"user-name\":\"onap\","
59 + "\"password\":\"987654\"," + "\"system-type\":\"VNFM\"}]}}";
60 return esrVnfmDetailStr;
63 return externalSystemproxy.queryVNFMDetail(transactionId, fromAppId, authorization, vnfmId);
64 } catch (Exception e) {
65 throw new ExtsysException("Query VNFM detail from A&AI failed.", e);
69 public static String queryVnfmList() throws ExtsysException {
71 String vnfmListStr = "{\"esr-vnfm\": " + "[{\"vnfm-id\": \"123456\"," + "\"vim-id\": \"987654\","
72 + "\"certificate-url\": \"http://11.22.33.44:5000/v3\"," + "\"resource-version\": \"1\"}]}";
76 return externalSystemproxy.queryVNFMList(transactionId, fromAppId, authorization);
77 } catch (Exception e) {
78 throw new ExtsysException("Query VNFM list from A&AI failed.", e);
82 public static void deleteVnfm(String vnfmId, String resourceVersion) throws ExtsysException {
85 externalSystemproxy.deleteVNFM(transactionId, fromAppId, authorization, vnfmId, resourceVersion);
86 } catch (Exception e) {
87 throw new ExtsysException("Delete VNFM from A&AI failed.", e);
92 public static void registerSdnc(String thirdpartySdncId, EsrThirdpartySdncDetail esrSdncDetail)
93 throws ExtsysException {
95 ClientConfig config = new ClientConfig(new ThirdpartySdncRegisterProvider());
96 IExternalSystem registerSdncServiceproxy =
97 ConsumerFactory.createConsumer(MsbConfig.getExternalSystemAddr(), config, IExternalSystem.class);
99 registerSdncServiceproxy.registerThirdpartySdnc(transactionId, fromAppId, authorization,
100 thirdpartySdncId, esrSdncDetail);
101 } catch (Exception e) {
102 throw new ExtsysException("PUT thirdparty SDNC to A&AI failed.", e);
107 public static String queryThirdpartySdncDetail(String thirdpartySdncId) throws ExtsysException {
109 String sdncDetail = "{\"thirdparty-sdnc-id\":\"123456\"," + "\"location\":\"edge\","
110 + "\"product-name\":\"thirdparty SDNC\"," + "\"esr-system-info-list\":{" + "\"esr-system-info\":"
111 + "[{\"esr-system-info-id\":\"987654\"," + "\"system-name\":\"SDNC_TEST\"," + "\"type\":\"SDNC\","
112 + "\"vendor\":\"zte\"," + "\"version\":\"v1\"," + "\"service-url\":\"http://127.0.0.1:8000\","
113 + "\"user-name\":\"nancy\"," + "\"password\":\"123987\"," + "\"system-type\":\"thirdparty_SDNC\","
114 + "\"protocol\":\"protocol\"}]}}";
118 return externalSystemproxy.queryThirdpartySdncDetail(transactionId, fromAppId, authorization,
120 } catch (Exception e) {
121 throw new ExtsysException("Query thirdparty SDNC detail from A&AI failed.", e);
125 public static String querySdncList() throws ExtsysException {
128 "{\"esr-thirdparty-sdnc\": " + "[{\"thirdparty-sdnc-id\": \"123456\"," + "\"location\": \"edge\","
129 + "\"product-name\": \"thirdparty SDNC\"," + "\"resource-version\": \"1\"}]}";
133 return externalSystemproxy.queryThirdpartySdncList(transactionId, fromAppId, authorization);
134 } catch (Exception e) {
135 throw new ExtsysException("Query thirdparty SDNC list from A&AI failed.", e);
139 public static void deleteThirdpartySdnc(String sdncId, String resourceVersion) throws ExtsysException {
142 externalSystemproxy.deleteThirdpartySdnc(transactionId, fromAppId, authorization, sdncId,
144 } catch (Exception e) {
145 throw new ExtsysException("Delete thirdparty SDNC from A&AI failed.", e);
150 public static void registerEms(String emsId, EsrEmsDetail emsDetail) throws ExtsysException {
152 ClientConfig config = new ClientConfig(new EmsRegisterProvider());
153 IExternalSystem registerEmsServiceproxy =
154 ConsumerFactory.createConsumer(MsbConfig.getExternalSystemAddr(), config, IExternalSystem.class);
156 registerEmsServiceproxy.registerEMS(transactionId, fromAppId, authorization, emsId, emsDetail);
157 } catch (Exception e) {
158 throw new ExtsysException("PUT EMS to A&AI failed.", e);
163 public static String queryEmsDetail(String emsId) throws ExtsysException {
165 String emsDetailStr = "{\"ems-id\":\"123456\"," + "\"esr-system-info-list\":" + "{\"esr-system-info\":"
166 + "[{\"esr-system-info-id\":\"234567\"," + "\"system-name\":\"EMS_TEST\"," + "\"type\":\"sftp\","
167 + "\"vendor\":\"ZTE\"," + "\"version\":\"V1\"," + "\"user-name\":\"nancy\"," + "\"password\":\"asdf\","
168 + "\"system-type\":\"EMS_RESOUCE\"," + "\"ip-address\":\"127.0.0.1\"," + "\"port\":\"5000\","
169 + "\"passive\":true," + "\"remote-path\":\"/home/per\"}," + "{\"esr-system-info-id\":\"345678\","
170 + "\"system-name\":\"EMS_TEST\"," + "\"type\":\"sftp\"," + "\"vendor\":\"ZTE\"," + "\"version\":\"V1\","
171 + "\"user-name\":\"nancy\"," + "\"password\":\"asdf\"," + "\"system-type\":\"EMS_PERFORMANCE\","
172 + "\"ip-address\":\"127.0.0.1\"," + "\"port\":\"5000\"," + "\"passive\":true,"
173 + "\"remote-path\":\"/home/per\"}," + "{\"esr-system-info-id\":\"456789\","
174 + "\"system-name\":\"EMS_TEST\"," + "\"vendor\":\"ZTE\"," + "\"version\":\"V1\","
175 + "\"user-name\":\"nancy\"," + "\"password\":\"987654\"," + "\"system-type\":\"EMS_ALARM\","
176 + "\"ip-address\":\"127.0.0.1\"," + "\"port\":\"5000\"}]}}";
180 return externalSystemproxy.queryEMSDetail(transactionId, fromAppId, authorization, emsId);
181 } catch (Exception e) {
182 throw new ExtsysException("Query EMS detail from A&AI failed.", e);
186 public static String queryEmsList() throws ExtsysException {
188 return "{\"esr-ems\": [ {\"ems-id\": \"123456\",\"resource-version\": \"1\"}]}";
191 return externalSystemproxy.queryEMSList(transactionId, fromAppId, authorization);
192 } catch (Exception e) {
193 throw new ExtsysException("Query EMS list from A&AI failed.", e);
197 public static void deleteEms(String emsId, String resourceVersion) throws ExtsysException {
200 externalSystemproxy.deleteEMS(transactionId, fromAppId, authorization, emsId, resourceVersion);
201 } catch (Exception e) {
202 throw new ExtsysException("Delete EMS from A&AI failed.", e);