9650cf69f7e29a2641b60963db851bb29940e60a
[usecase-ui/server.git] /
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.bean.lcm.VfNsPackageInfo;
19 import org.onap.usecaseui.server.service.lcm.PackageDistributionService;
20 import org.onap.usecaseui.server.service.lcm.domain.sdc.SDCCatalogService;
21 import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.SDCServiceTemplate;
22 import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.Vnf;
23 import org.onap.usecaseui.server.service.lcm.domain.sdc.exceptions.SDCCatalogException;
24 import org.onap.usecaseui.server.service.lcm.domain.vfc.VfcService;
25 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.Csar;
26 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.DistributionResult;
27 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.Job;
28 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.JobStatus;
29 import org.onap.usecaseui.server.service.lcm.domain.vfc.exceptions.VfcException;
30 import org.springframework.context.annotation.EnableAspectJAutoProxy;
31 import org.springframework.stereotype.Service;
32
33 import java.io.IOException;
34 import java.util.List;
35
36 import static org.onap.usecaseui.server.service.lcm.domain.sdc.consts.SDCConsts.*;
37 import static org.onap.usecaseui.server.util.RestfulServices.create;
38
39 @Service("PackageDistributionService")
40 @org.springframework.context.annotation.Configuration
41 @EnableAspectJAutoProxy
42 public class DefaultPackageDistributionService implements PackageDistributionService {
43
44     private SDCCatalogService sdcCatalogService;
45
46     private VfcService vfcService;
47
48     public DefaultPackageDistributionService() {
49         this(create(SDCCatalogService.class), create(VfcService.class));
50     }
51
52     public DefaultPackageDistributionService(SDCCatalogService sdcCatalogService, VfcService vfcService) {
53         this.sdcCatalogService = sdcCatalogService;
54         this.vfcService = vfcService;
55     }
56
57     @Override
58     public VfNsPackageInfo retrievePackageInfo() {
59         try {
60             List<SDCServiceTemplate> nsTemplate = sdcCatalogService.listServices(CATEGORY_NS, DISTRIBUTION_STATUS_DISTRIBUTED).execute().body();
61             List<Vnf> vnf = sdcCatalogService.listResources(RESOURCETYPE_VF, DISTRIBUTION_STATUS_DISTRIBUTED).execute().body();
62             return new VfNsPackageInfo(nsTemplate, vnf);
63         } catch (IOException e) {
64             throw new SDCCatalogException("SDC Service is not available!", e);
65         }
66     }
67
68     @Override
69     public DistributionResult postNsPackage(Csar csar) {
70         try {
71             return vfcService.distributeNsPackage(csar).execute().body();
72         } catch (IOException e) {
73             throw new VfcException("VFC service is not available!", e);
74         }
75     }
76
77     @Override
78     public Job postVfPackage(Csar csar) {
79         try {
80             return vfcService.distributeVnfPackage(csar).execute().body();
81         } catch (IOException e) {
82             throw new VfcException("VFC service is not available!", e);
83         }
84     }
85
86     @Override
87     public JobStatus getJobStatus(String jobId) {
88         try {
89             return vfcService.getJobStatus(jobId).execute().body();
90         } catch (IOException e) {
91             throw new VfcException("VFC service is not available!", e);
92         }
93     }
94 }