2 * Copyright (C) 2018 CMCC, Inc. and others. All rights reserved.
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.usecaseui.server.service.sotn.impl;
18 import static org.onap.usecaseui.server.util.RestfulServices.extractBody;
20 import java.io.IOException;
21 import java.util.Collections;
22 import java.util.List;
24 import javax.servlet.http.HttpServletRequest;
26 import org.onap.usecaseui.server.bean.sotn.Pinterface;
27 import org.onap.usecaseui.server.bean.sotn.PinterfaceRsp;
28 import org.onap.usecaseui.server.constant.CommonConstant;
29 import org.onap.usecaseui.server.service.lcm.domain.aai.AAIService;
30 import org.onap.usecaseui.server.service.lcm.domain.aai.exceptions.AAIException;
31 import org.onap.usecaseui.server.service.lcm.domain.so.exceptions.SOException;
32 import org.onap.usecaseui.server.service.sotn.SOTNService;
33 import org.onap.usecaseui.server.util.RestfulServices;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36 import org.springframework.context.annotation.EnableAspectJAutoProxy;
37 import org.springframework.stereotype.Service;
39 import okhttp3.RequestBody;
40 import okhttp3.ResponseBody;
41 import retrofit2.Response;
43 @Service("SOTNService")
44 @org.springframework.context.annotation.Configuration
45 @EnableAspectJAutoProxy
46 public class SOTNServiceImpl implements SOTNService{
48 private static final Logger logger = LoggerFactory.getLogger(SOTNServiceImpl.class);
50 private AAIService aaiService;
52 public SOTNServiceImpl() {
53 this(RestfulServices.create(AAIService.class));
56 public SOTNServiceImpl(AAIService aaiService) {
57 this.aaiService = aaiService;
61 public String getNetWorkResources() {
64 logger.info("aai getNetWorkResources is starting!");
65 Response<ResponseBody> response = this.aaiService.listNetWorkResources().execute();
66 logger.info("aai getNetWorkResources has finished!");
67 if (response.isSuccessful()) {
68 result=new String(response.body().bytes());
70 logger.info(String.format("Can not get getNetWorkResources[code=%s, message=%s]", response.code(), response.message()));
71 result = CommonConstant.CONSTANT_FAILED;
73 } catch (IOException e) {
74 logger.error("getNetWorkResources occur exception:"+e);
75 result = CommonConstant.CONSTANT_FAILED;
81 public List<Pinterface> getPinterfaceByPnfName(String pnfName) {
83 logger.info("aai getPinterfaceByPnfName is starting!");
84 Response<PinterfaceRsp> response = this.aaiService.getPinterfaceByPnfName(pnfName).execute();
85 logger.info(String.format("excute aai interface:/api/aai-network/v13/pnfs/pnf/%s/p-interfaces",pnfName));
86 logger.info("aai getPinterfaceByPnfName has finished!");
87 if (response.isSuccessful()) {
88 return response.body().getPinterfaces();
90 logger.info(String.format("Can not get getPinterfaceByPnfName[code=%s, message=%s]", response.code(), response.message()));
91 return Collections.emptyList();
93 } catch (IOException e) {
94 logger.error("getPinterfaceByPnfName occur exception:"+e);
95 throw new AAIException("AAI is not available.", e);
100 public String getLogicalLinks() {
103 logger.info("aai getLogicalLinks is starting!");
104 Response<ResponseBody> response = this.aaiService.getLogicalLinks().execute();
105 logger.info("aai getLogicalLinks has finished!");
106 if (response.isSuccessful()) {
107 result=new String(response.body().bytes());
109 logger.info(String.format("Can not get getLogicalLinks[code=%s, message=%s]", response.code(), response.message()));
110 result= CommonConstant.CONSTANT_FAILED;
112 } catch (IOException e) {
113 logger.error("getLogicalLinks occur exception:"+e);
114 result= CommonConstant.CONSTANT_FAILED;
120 public String getSpecificLogicalLink(String linkName) {
123 logger.info("aai getSpecificLogicalLink is starting!");
124 Response<ResponseBody> response = this.aaiService.getSpecificLogicalLink(linkName).execute();
125 logger.info("aai getSpecificLogicalLink has finished!");
126 if (response.isSuccessful()) {
127 result=new String(response.body().bytes());
129 logger.info(String.format("Can not get getSpecificLogicalLink[code=%s, message=%s]", response.code(), response.message()));
130 result= CommonConstant.CONSTANT_FAILED;
132 } catch (IOException e) {
133 logger.error("getSpecificLogicalLink occur exception:"+e);
134 result= CommonConstant.CONSTANT_FAILED;
140 public String getHostUrl(String aaiId) {
143 logger.info("aai getHostUrl is starting!");
144 Response<ResponseBody> response = this.aaiService.getHostUrl(aaiId).execute();
145 logger.info("aai getHostUrl has finished!");
146 if (response.isSuccessful()) {
147 result=new String(response.body().bytes());
149 logger.info(String.format("Can not get getHostUrl[code=%s, message=%s]", response.code(), response.message()));
150 result= CommonConstant.CONSTANT_FAILED;
152 } catch (IOException e) {
153 logger.error("getHostUrl occur exception:"+e);
154 result= CommonConstant.CONSTANT_FAILED;
160 public String getExtAaiId(String aaiId) {
163 logger.info("aai getExtAaiId is starting!");
164 Response<ResponseBody> response = this.aaiService.getExtAaiId(aaiId).execute();
165 logger.info("aai getExtAaiId has finished!");
166 if (response.isSuccessful()) {
167 result=new String(response.body().bytes());
169 logger.info(String.format("Can not get getExtAaiId[code=%s, message=%s]", response.code(), response.message()));
170 result= CommonConstant.CONSTANT_FAILED;
172 } catch (IOException e) {
173 logger.error("getExtAaiId occur exception:"+e);
174 result= CommonConstant.CONSTANT_FAILED;
180 public String createHostUrl(HttpServletRequest request,String aaiId) {
183 logger.info("aai createHostUrl is starting");
184 RequestBody requestBody = extractBody(request);
185 Response<ResponseBody> response = aaiService.createHostUrl(requestBody,aaiId).execute();
186 logger.info("aai createHostUrl has finished");
187 if (response.isSuccessful()) {
188 result= CommonConstant.CONSTANT_SUCCESS;
190 result= CommonConstant.CONSTANT_FAILED;
191 logger.error(String.format("Can not createHostUrl[code=%s, message=%s]", response.code(), response.message()));
193 } catch (Exception e) {
194 result= CommonConstant.CONSTANT_FAILED;
195 logger.error("createHostUrl occur exception:"+e);
201 public String createTopoNetwork(HttpServletRequest request,String networkId) {
204 logger.info("aai createTopoNetwork is starting");
205 RequestBody requestBody = extractBody(request);
206 Response<ResponseBody> response = aaiService.createTopoNetwork(requestBody,networkId).execute();
207 logger.info("aai createTopoNetwork has finished");
208 if (response.isSuccessful()) {
209 result= CommonConstant.CONSTANT_SUCCESS;
211 result= CommonConstant.CONSTANT_FAILED;
212 logger.error(String.format("Can not createTopoNetwork[code=%s, message=%s]", response.code(), response.message()));
214 } catch (Exception e) {
215 result= CommonConstant.CONSTANT_FAILED;
216 logger.error("createTopoNetwork occur exception:"+e);
222 public String createTerminationPoint(HttpServletRequest request,String pnfName,String tpId) {
225 logger.info("aai createTerminationPoint is starting");
226 RequestBody requestBody = extractBody(request);
227 Response<ResponseBody> response = aaiService.createTerminationPoint(requestBody,pnfName,tpId).execute();
228 logger.info("aai createTerminationPoint has finished");
229 if (response.isSuccessful()) {
230 result= CommonConstant.CONSTANT_SUCCESS;
232 result= CommonConstant.CONSTANT_FAILED;
233 logger.error(String.format("Can not createTerminationPoint[code=%s, message=%s]", response.code(), response.message()));
235 } catch (Exception e) {
236 result= CommonConstant.CONSTANT_FAILED;
237 logger.error("createTerminationPoint occur exception:"+e);
243 public String createLink(HttpServletRequest request,String linkName) {
246 logger.info("aai createLink is starting");
247 RequestBody requestBody = extractBody(request);
248 Response<ResponseBody> response = aaiService.createLink(requestBody,linkName).execute();
249 logger.info("aai createLink has finished");
250 if (response.isSuccessful()) {
251 result= CommonConstant.CONSTANT_SUCCESS;
253 result= CommonConstant.CONSTANT_FAILED;
254 logger.error(String.format("Can not createLink[code=%s, message=%s]", response.code(), response.message()));
256 } catch (Exception e) {
258 logger.error("createLink occur exception:"+e);
264 public String createPnf(HttpServletRequest request,String pnfName) {
267 logger.info("aai createPnf is starting");
268 RequestBody requestBody = extractBody(request);
269 Response<ResponseBody> response = aaiService.createPnf(requestBody,pnfName).execute();
270 logger.info("aai createPnf has finished");
271 if (response.isSuccessful()) {
272 result= CommonConstant.CONSTANT_SUCCESS;
274 result= CommonConstant.CONSTANT_FAILED;
275 logger.error(String.format("Can not createPnf[code=%s, message=%s]", response.code(), response.message()));
277 } catch (Exception e) {
278 result= CommonConstant.CONSTANT_FAILED;
279 logger.error("createPnf occur exception:"+e);
285 public String deleteLink(String linkName,String resourceVersion) {
288 logger.info("aai deleteLink is starting");
289 Response<ResponseBody> response = aaiService.deleteLink(linkName,resourceVersion).execute();
290 logger.info("aai deleteLink has finished");
291 if (response.isSuccessful()) {
292 result= CommonConstant.CONSTANT_SUCCESS;
294 result= CommonConstant.CONSTANT_FAILED;
295 logger.error(String.format("Can not deleteLink[code=%s, message=%s]", response.code(), response.message()));
297 } catch (Exception e) {
298 result= CommonConstant.CONSTANT_FAILED;
299 logger.error("deleteLink occur exception:"+e);
305 public String getServiceInstances(String customerId, String serviceType) {
308 logger.info("aai getServiceInstances is starting");
309 Response<ResponseBody> response = aaiService.getServiceInstances(customerId, serviceType).execute();
310 logger.info("aai getServiceInstances has finished");
311 if (response.isSuccessful()) {
312 result=new String(response.body().bytes());
314 logger.error(String.format("Can not getServiceInstances[code=%s, message=%s]", response.code(), response.message()));
315 result= CommonConstant.CONSTANT_FAILED;
317 } catch (Exception e) {
318 logger.error("getServiceInstances occur exception:"+e);
319 result= CommonConstant.CONSTANT_FAILED;
325 public String serviceInstanceInfo(String customerId, String serviceType, String serviceInstanceId) {
327 logger.info("aai serviceInstanceInfo is starting");
328 Response<ResponseBody> response = aaiService.serviceInstaneInfo(customerId, serviceType, serviceInstanceId).execute();
329 logger.info("aai serviceInstanceInfo has finished");
330 if (response.isSuccessful()) {
331 String result=new String(response.body().bytes());
334 logger.error(String.format("Can not serviceInstanceInfo[code=%s, message=%s]", response.code(), response.message()));
335 throw new SOException("aai serviceInstanceInfo failed!");
337 } catch (Exception e) {
338 logger.error("serviceInstanceInfo occur exception:"+e);
339 throw new SOException("aai serviceInstanceInfo is not available!", e);
344 public String getPnfInfo(String pnfName) {
347 logger.info("aai getPnfInfo is starting!");
348 Response<ResponseBody> response = this.aaiService.getPnfInfo(pnfName).execute();
349 logger.info("aai getPnfInfo has finished!");
350 if (response.isSuccessful()) {
351 result=new String(response.body().bytes());
353 logger.info(String.format("Can not get getPnfInfo[code=%s, message=%s]", response.code(), response.message()));
354 result= CommonConstant.CONSTANT_FAILED;
356 } catch (IOException e) {
357 logger.error("getPnfInfo occur exception:"+e);
358 result= CommonConstant.CONSTANT_FAILED;
364 public String getAllottedResources(String customerId, String serviceType, String serviceId) {
367 logger.info("aai getAllottedResources is starting!");
368 Response<ResponseBody> response = this.aaiService.getAllottedResources(customerId, serviceType, serviceId).execute();
369 logger.info("aai getAllottedResources has finished!");
370 if (response.isSuccessful()) {
371 result=new String(response.body().bytes());
373 logger.info(String.format("Can not get getAllottedResources[code=%s, message=%s]", response.code(), response.message()));
374 result= CommonConstant.CONSTANT_FAILED;
376 } catch (IOException e) {
377 logger.error("getAllottedResources occur exception:"+e);
378 result= CommonConstant.CONSTANT_FAILED;
384 public String getConnectivityInfo(String connectivityId) {
387 logger.info("aai getConnectivityInfo is starting!");
388 Response<ResponseBody> response = this.aaiService.getConnectivityInfo(connectivityId).execute();
389 logger.info("aai getConnectivityInfo has finished!");
390 if (response.isSuccessful()) {
391 result=new String(response.body().bytes());
393 logger.info(String.format("Can not get getConnectivityInfo[code=%s, message=%s]", response.code(), response.message()));
394 result= CommonConstant.CONSTANT_FAILED;
396 } catch (IOException e) {
397 logger.error("getConnectivityInfo occur exception:"+e);
398 result= CommonConstant.CONSTANT_FAILED;
404 public String getPinterfaceByVpnId(String vpnId) {
407 logger.info("aai getPinterfaceByVpnId is starting!");
408 Response<ResponseBody> response = this.aaiService.getPinterfaceByVpnId(vpnId).execute();
409 logger.info("aai getPinterfaceByVpnId has finished!");
410 if (response.isSuccessful()) {
411 result=new String(response.body().bytes());
413 logger.info(String.format("Can not get getPinterfaceByVpnId[code=%s, message=%s]", response.code(), response.message()));
414 result= CommonConstant.CONSTANT_FAILED;
416 } catch (IOException e) {
417 logger.error("getPinterfaceByVpnId occur exception:"+e);
418 result= CommonConstant.CONSTANT_FAILED;
424 public String deleteExtNetwork(String networkId,String resourceVersion) {
427 logger.info("aai deleteExtNetwork is starting");
428 Response<ResponseBody> response = aaiService.deleteExtNetwork(networkId,resourceVersion).execute();
429 logger.info("aai deleteExtNetwork has finished");
430 if (response.isSuccessful()) {
431 result= CommonConstant.CONSTANT_SUCCESS;
433 result= CommonConstant.CONSTANT_FAILED;
434 logger.error(String.format("Can not deleteExtNetwork[code=%s, message=%s]", response.code(), response.message()));
436 } catch (Exception e) {
437 result= CommonConstant.CONSTANT_FAILED;
438 logger.error("deleteExtNetwork occur exception:"+e);