2 * Copyright 2016-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.usecaseui.server.service.lcm.impl;
18 import java.io.IOException;
19 import java.util.Collections;
20 import java.util.List;
22 import org.onap.usecaseui.server.service.lcm.ServiceInstanceService;
23 import org.onap.usecaseui.server.service.lcm.domain.aai.AAIService;
24 import org.onap.usecaseui.server.service.lcm.domain.aai.bean.ServiceInstanceRsp;
25 import org.onap.usecaseui.server.service.lcm.domain.aai.exceptions.AAIException;
26 import org.onap.usecaseui.server.util.RestfulServices;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29 import org.springframework.context.annotation.EnableAspectJAutoProxy;
30 import org.springframework.stereotype.Service;
32 import okhttp3.ResponseBody;
33 import retrofit2.Response;
35 @Service("ServiceInstanceService")
36 @org.springframework.context.annotation.Configuration
37 @EnableAspectJAutoProxy
38 public class DefaultServiceInstanceService implements ServiceInstanceService {
40 private static final Logger logger = LoggerFactory.getLogger(DefaultServiceInstanceService.class);
42 private AAIService aaiService;
44 public DefaultServiceInstanceService() {
45 this(RestfulServices.create(AAIService.class));
48 public DefaultServiceInstanceService(AAIService aaiService) {
49 this.aaiService = aaiService;
53 public List<String> listServiceInstances(String customerId, String serviceType) {
55 Response<ServiceInstanceRsp> response = aaiService.listServiceInstances(customerId, serviceType).execute();
56 if (response.isSuccessful()) {
57 return response.body().getServiceInstances();
59 logger.info(String.format("Can not get service instances[code=%s, message=%s]", response.code(), response.message()));
60 return Collections.emptyList();
62 } catch (IOException e) {
63 logger.error("list services instances occur exception");
64 throw new AAIException("AAI is not available.", e);
69 public String getRelationShipData(String customerId, String serviceType, String serviceId) {
71 Response<ResponseBody> response = aaiService.getAAIServiceInstance(customerId, serviceType,serviceId).execute();
72 if (response.isSuccessful()) {
73 String result=new String(response.body().bytes());
76 logger.info(String.format("Can not get service instances[code=%s, message=%s]", response.code(), response.message()));
79 } catch (IOException e) {
80 logger.error("list services instances occur exception");
81 throw new AAIException("AAI is not available.", e);