7bb3777a3958756604dca319f148050aeba2cd80
[usecase-ui/server.git] / src / main / java / org / onap / usecaseui / server / service / lcm / impl / DefaultServiceLcmService.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.ServiceLcmService;
19 import org.onap.usecaseui.server.service.lcm.domain.so.SOService;
20 import org.onap.usecaseui.server.service.lcm.domain.so.bean.OperationProgressInformation;
21 import org.onap.usecaseui.server.service.lcm.domain.so.bean.ServiceInstantiationRequest;
22 import org.onap.usecaseui.server.service.lcm.domain.so.bean.ServiceOperation;
23 import org.onap.usecaseui.server.service.lcm.domain.so.exceptions.SOException;
24 import org.onap.usecaseui.server.util.RestfulServices;
25 import org.springframework.context.annotation.EnableAspectJAutoProxy;
26 import org.springframework.stereotype.Service;
27
28 import java.io.IOException;
29
30 @Service("ServiceLcmService")
31 @org.springframework.context.annotation.Configuration
32 @EnableAspectJAutoProxy
33 public class DefaultServiceLcmService implements ServiceLcmService {
34
35     private SOService soService;
36
37     public DefaultServiceLcmService() {
38         this(RestfulServices.create(SOService.class));
39     }
40
41     public DefaultServiceLcmService(SOService soService) {
42         this.soService = soService;
43     }
44
45     @Override
46     public ServiceOperation instantiateService(ServiceInstantiationRequest request) {
47         try {
48             return soService.instantiateService(request).execute().body();
49         } catch (IOException e) {
50             throw new SOException("SO Service is not available!", e);
51         }
52     }
53
54     @Override
55     public OperationProgressInformation queryOperationProgress(String serviceId, String operationId) {
56         try {
57             return soService.queryOperationProgress(serviceId, operationId).execute().body();
58         } catch (IOException e) {
59             throw new SOException("SO Service is not available!", e);
60         }
61     }
62
63     @Override
64     public ServiceOperation terminateService(String serviceId) {
65         try {
66             return soService.terminateService(serviceId).execute().body();
67         } catch (IOException e) {
68             throw new SOException("SO Service is not available!", e);
69         }
70     }
71 }