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 void registerVnfm(String vnfmId, EsrVnfmDetail esrVnfmDetail) throws ExtsysException {
42 ClientConfig config = new ClientConfig(new VnfmRegisterProvider());
43 IExternalSystem registerVnfmServiceproxy =
44 ConsumerFactory.createConsumer(MsbConfig.getExternalSystemAddr(), config, IExternalSystem.class);
46 registerVnfmServiceproxy.registerVNFM(transactionId, fromAppId, authorization, vnfmId, esrVnfmDetail);
47 } catch (Exception e) {
48 throw new ExtsysException("PUT VNFM to A&AI failed.", e);
52 public String queryVnfmDetail(String vnfmId) throws ExtsysException {
54 return externalSystemproxy.queryVNFMDetail(transactionId, fromAppId, authorization, vnfmId);
55 } catch (Exception e) {
56 throw new ExtsysException("Query VNFM detail from A&AI failed.", e);
60 public String queryVnfmList() throws ExtsysException {
62 return externalSystemproxy.queryVNFMList(transactionId, fromAppId, authorization);
63 } catch (Exception e) {
64 throw new ExtsysException("Query VNFM list from A&AI failed.", e);
68 public void deleteVnfm(String vnfmId, String resourceVersion) throws ExtsysException {
70 externalSystemproxy.deleteVNFM(transactionId, fromAppId, authorization, vnfmId, resourceVersion);
71 } catch (Exception e) {
72 throw new ExtsysException("Delete VNFM from A&AI failed.", e);
76 public void registerSdnc(String thirdpartySdncId, EsrThirdpartySdncDetail esrSdncDetail)
77 throws ExtsysException {
78 if (!test.getIsTest()) {
79 ClientConfig config = new ClientConfig(new ThirdpartySdncRegisterProvider());
80 IExternalSystem registerSdncServiceproxy =
81 ConsumerFactory.createConsumer(MsbConfig.getExternalSystemAddr(), config, IExternalSystem.class);
83 registerSdncServiceproxy.registerThirdpartySdnc(transactionId, fromAppId, authorization,
84 thirdpartySdncId, esrSdncDetail);
85 } catch (Exception e) {
86 throw new ExtsysException("PUT thirdparty SDNC to A&AI failed.", e);
91 public String queryThirdpartySdncDetail(String thirdpartySdncId) throws ExtsysException {
92 if (test.getIsTest()) {
93 String sdncDetail = "{\"thirdparty-sdnc-id\":\"123456\",\"location\":\"edge\","
94 + "\"product-name\":\"thirdparty SDNC\",\"esr-system-info-list\":{\"esr-system-info\":"
95 + "[{\"esr-system-info-id\":\"987654\",\"system-name\":\"SDNC_TEST\",\"type\":\"SDNC\","
96 + "\"vendor\":\"zte\",\"version\":\"v1\",\"service-url\":\"http://ip:8000\","
97 + "\"user-name\":\"nancy\",\"password\":\"123987\",\"system-type\":\"thirdparty_SDNC\","
98 + "\"protocol\":\"protocol\"}]}}";
102 return externalSystemproxy.queryThirdpartySdncDetail(transactionId, fromAppId, authorization,
104 } catch (Exception e) {
105 throw new ExtsysException("Query thirdparty SDNC detail from A&AI failed.", e);
109 public String querySdncList() throws ExtsysException {
110 if (test.getIsTest()) {
112 "{\"esr-thirdparty-sdnc\": [{\"thirdparty-sdnc-id\": \"123456\",\"location\": \"edge\","
113 + "\"product-name\": \"thirdparty SDNC\",\"resource-version\": \"1\"}]}";
117 return externalSystemproxy.queryThirdpartySdncList(transactionId, fromAppId, authorization);
118 } catch (Exception e) {
119 throw new ExtsysException("Query thirdparty SDNC list from A&AI failed.", e);
123 public void deleteThirdpartySdnc(String sdncId, String resourceVersion) throws ExtsysException {
124 if (!test.getIsTest()) {
126 externalSystemproxy.deleteThirdpartySdnc(transactionId, fromAppId, authorization, sdncId,
128 } catch (Exception e) {
129 throw new ExtsysException("Delete thirdparty SDNC from A&AI failed.", e);
134 public void registerEms(String emsId, EsrEmsDetail emsDetail) throws ExtsysException {
135 ClientConfig config = new ClientConfig(new EmsRegisterProvider());
136 IExternalSystem registerEmsServiceproxy =
137 ConsumerFactory.createConsumer(MsbConfig.getExternalSystemAddr(), config, IExternalSystem.class);
139 registerEmsServiceproxy.registerEMS(transactionId, fromAppId, authorization, emsId, emsDetail);
140 } catch (Exception e) {
141 throw new ExtsysException("PUT EMS to A&AI failed.", e);
145 public String queryEmsDetail(String emsId) throws ExtsysException {
147 return externalSystemproxy.queryEMSDetail(transactionId, fromAppId, authorization, emsId);
148 } catch (Exception e) {
149 throw new ExtsysException("Query EMS detail from A&AI failed.", e);
153 public String queryEmsList() throws ExtsysException {
155 return externalSystemproxy.queryEMSList(transactionId, fromAppId, authorization);
156 } catch (Exception e) {
157 throw new ExtsysException("Query EMS list from A&AI failed.", e);
161 public void deleteEms(String emsId, String resourceVersion) throws ExtsysException {
163 externalSystemproxy.deleteEMS(transactionId, fromAppId, authorization, emsId, resourceVersion);
164 } catch (Exception e) {
165 throw new ExtsysException("Delete EMS from A&AI failed.", e);