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