540a0dad51bb0409bb396acee901e10130eb1620
[usecase-ui/server.git] / src / main / java / org / onap / usecaseui / server / service / lcm / impl / DefaultServiceInstanceService.java
1 /**
2  * Copyright 2016-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.usecaseui.server.service.lcm.impl;
17
18 import org.onap.usecaseui.server.service.lcm.ServiceInstanceService;
19 import org.onap.usecaseui.server.service.lcm.domain.aai.AAIService;
20 import org.onap.usecaseui.server.service.lcm.domain.aai.bean.ServiceInstance;
21 import org.onap.usecaseui.server.service.lcm.domain.aai.exceptions.AAIException;
22 import org.onap.usecaseui.server.util.RestfulServices;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25 import org.springframework.context.annotation.EnableAspectJAutoProxy;
26 import org.springframework.stereotype.Service;
27
28 import java.io.IOException;
29 import java.util.List;
30
31 @Service("ServiceInstanceService")
32 @org.springframework.context.annotation.Configuration
33 @EnableAspectJAutoProxy
34 public class DefaultServiceInstanceService implements ServiceInstanceService {
35
36     private static final Logger logger = LoggerFactory.getLogger(DefaultServiceInstanceService.class);
37
38     private AAIService aaiService;
39
40     public DefaultServiceInstanceService() {
41         this(RestfulServices.create(AAIService.class));
42     }
43
44     public DefaultServiceInstanceService(AAIService aaiService) {
45         this.aaiService = aaiService;
46     }
47
48     @Override
49     public List<ServiceInstance> listServiceInstances(String customerId, String serviceType) {
50         try {
51             return aaiService.listServiceInstances(customerId, serviceType).execute().body();
52         } catch (IOException e) {
53             logger.error("list services instances occur exception");
54             throw new AAIException("AAI is not available.", e);
55         }
56     }
57 }