add unit test for vnfmregister.
[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     try {
59       return externalSystemproxy.queryVNFMDetail(transactionId, fromAppId, authorization, vnfmId);
60     } catch (Exception e) {
61       throw new ExtsysException("Query VNFM detail from A&AI failed.", e);
62     }
63   }
64   
65   public static String queryVnfmList() throws ExtsysException {
66     try {
67       return externalSystemproxy.queryVNFMList(transactionId, fromAppId, authorization);
68     } catch (Exception e) {
69       throw new ExtsysException("Query VNFM list from A&AI failed.", e);
70     }
71   }
72   
73   public static void deleteVnfm(String vnfmId, String resourceVersion) throws ExtsysException {
74     try {
75       externalSystemproxy.deleteVNFM(transactionId, fromAppId, authorization, vnfmId, resourceVersion);
76     } catch (Exception e) {
77       throw new ExtsysException("Delete VNFM from A&AI failed.", e);
78     }
79   }
80   
81   public static void registerSdnc(String thirdpartySdncId, EsrThirdpartySdncDetail esrSdncDetail) throws ExtsysException {
82     ClientConfig config = new ClientConfig(new ThirdpartySdncRegisterProvider());
83     IExternalSystem registerSdncServiceproxy = ConsumerFactory
84         .createConsumer(MsbConfig.getExternalSystemAddr(), config, IExternalSystem.class);
85     try {
86       registerSdncServiceproxy.registerThirdpartySdnc(transactionId, fromAppId, authorization, thirdpartySdncId,
87           esrSdncDetail);
88     } catch (Exception e) {
89       throw new ExtsysException("PUT thirdparty SDNC to A&AI failed.", e);
90     }
91   }
92   
93   public static String queryThirdpartySdncDetail(String thirdpartySdncId) throws ExtsysException {
94     try {
95       return externalSystemproxy.queryThirdpartySdncDetail(transactionId, fromAppId, authorization, thirdpartySdncId);
96     } catch (Exception e) {
97       throw new ExtsysException("Query thirdparty SDNC detail from A&AI failed.", e);
98     }
99   }
100   
101   public static String querySdncList() throws ExtsysException {
102     try {
103       return externalSystemproxy.queryThirdpartySdncList(transactionId, fromAppId, authorization);
104     } catch (Exception e) {
105       throw new ExtsysException("Query thirdparty SDNC list from A&AI failed.", e);
106     }
107   }
108   
109   public static void deleteThirdpartySdnc(String sdncId, String resourceVersion) throws ExtsysException {
110     try {
111       externalSystemproxy.deleteThirdpartySdnc(transactionId, fromAppId, authorization, sdncId, resourceVersion);
112     } catch (Exception e) {
113       throw new ExtsysException("Delete thirdparty SDNC from A&AI failed.", e);
114     }
115   }
116   
117   public static void registerEms(String emsId, EsrEmsDetail emsDetail) throws ExtsysException {
118     ClientConfig config = new ClientConfig(new EmsRegisterProvider());
119     IExternalSystem registerEmsServiceproxy = ConsumerFactory
120         .createConsumer(MsbConfig.getExternalSystemAddr(), config, IExternalSystem.class);
121     try {
122       registerEmsServiceproxy.registerEMS(transactionId, fromAppId, authorization, emsId,
123           emsDetail);
124     } catch (Exception e) {
125       throw new ExtsysException("PUT EMS to A&AI failed.", e);
126     }
127   }
128   
129   public static String queryEmsDetail(String emsId) throws ExtsysException {
130     try {
131       return externalSystemproxy.queryEMSDetail(transactionId, fromAppId, authorization, emsId);
132     } catch (Exception e) {
133       throw new ExtsysException("Query EMS detail from A&AI failed.", e);
134     }
135   }
136   
137   public static String queryEmsList() throws ExtsysException {
138     try {
139       return externalSystemproxy.queryEMSList(transactionId, fromAppId, authorization);
140     } catch (Exception e) {
141       throw new ExtsysException("Query EMS list from A&AI failed.", e);
142     }
143   }
144   
145   public static void deleteEms(String emsId, String resourceVersion) throws ExtsysException {
146     try {
147       externalSystemproxy.deleteEMS(transactionId, fromAppId, authorization, emsId, resourceVersion);
148     } catch (Exception e) {
149       throw new ExtsysException("Delete EMS from A&AI failed.", e);
150     }
151   }
152 }