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 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;
35 import java.io.IOException;
36 import java.util.List;
38 import static org.onap.usecaseui.server.service.lcm.domain.sdc.consts.SDCConsts.*;
39 import static org.onap.usecaseui.server.util.RestfulServices.create;
41 @Service("PackageDistributionService")
42 @org.springframework.context.annotation.Configuration
43 @EnableAspectJAutoProxy
44 public class DefaultPackageDistributionService implements PackageDistributionService {
46 private SDCCatalogService sdcCatalogService;
48 private AAIService aaiService;
50 private VfcService vfcService;
52 public DefaultPackageDistributionService() {
53 this(create(SDCCatalogService.class), create(AAIService.class), create(VfcService.class));
56 public DefaultPackageDistributionService(SDCCatalogService sdcCatalogService, AAIService aaiService, VfcService vfcService) {
57 this.sdcCatalogService = sdcCatalogService;
58 this.aaiService = aaiService;
59 this.vfcService = vfcService;
63 public VfNsPackageInfo retrievePackageInfo() {
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);
75 public DistributionResult postNsPackage(Csar csar) {
77 return vfcService.distributeNsPackage(csar).execute().body();
78 } catch (IOException e) {
79 throw new VfcException("VFC service is not available!", e);
84 public Job postVfPackage(Csar csar) {
86 return vfcService.distributeVnfPackage(csar).execute().body();
87 } catch (IOException e) {
88 throw new VfcException("VFC service is not available!", e);
93 public JobStatus getJobStatus(String jobId) {
95 return vfcService.getJobStatus(jobId).execute().body();
96 } catch (IOException e) {
97 throw new VfcException("VFC service is not available!", e);