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.IsTest;
20 import org.onap.aai.esr.common.MsbConfig;
21 import org.onap.aai.esr.entity.aai.EsrEmsDetail;
22 import org.onap.aai.esr.entity.aai.EsrThirdpartySdncDetail;
23 import org.onap.aai.esr.entity.aai.EsrVnfmDetail;
24 import org.onap.aai.esr.exception.ExtsysException;
25 import com.eclipsesource.jaxrs.consumer.ConsumerFactory;
27 public class ExternalSystemProxy {
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 IsTest test = new IsTest(false);
41 public static void registerVnfm(String vnfmId, EsrVnfmDetail esrVnfmDetail) throws ExtsysException {
42 if (!test.getIsTest()){
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 {
55 if (test.getIsTest()) {
56 String esrVnfmDetailStr = "{\"vnfm-id\":\"123456\",\"vim-id\":\"987654\","
57 + "\"certificate-url\":\"http://ip: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://ip: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 {
72 if (test.getIsTest()) {
73 String vnfmListStr = "{\"esr-vnfm\": [{\"vnfm-id\": \"123456\",\"vim-id\": \"987654\","
74 + "\"certificate-url\": \"http://ip: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 {
85 if (!test.getIsTest()) {
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 {
96 if (!test.getIsTest()) {
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 {
110 if (test.getIsTest()) {
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://ip: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 {
128 if (test.getIsTest()) {
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 {
142 if (!test.getIsTest()) {
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 {
153 if (!test.getIsTest()) {
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 {
166 if (test.getIsTest()) {
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\":\"ip\",\"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\":\"ip\",\"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\":\"ip\",\"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 {
189 if (test.getIsTest()) {
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 {
200 if (!test.getIsTest()) {
202 externalSystemproxy.deleteEMS(transactionId, fromAppId, authorization, emsId, resourceVersion);
203 } catch (Exception e) {
204 throw new ExtsysException("Delete EMS from A&AI failed.", e);