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.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;
33 import java.io.IOException;
34 import java.util.List;
36 import static org.onap.usecaseui.server.service.lcm.domain.sdc.consts.SDCConsts.*;
37 import static org.onap.usecaseui.server.util.RestfulServices.create;
39 @Service("PackageDistributionService")
40 @org.springframework.context.annotation.Configuration
41 @EnableAspectJAutoProxy
42 public class DefaultPackageDistributionService implements PackageDistributionService {
44 private SDCCatalogService sdcCatalogService;
46 private VfcService vfcService;
48 public DefaultPackageDistributionService() {
49 this(create(SDCCatalogService.class), create(VfcService.class));
52 public DefaultPackageDistributionService(SDCCatalogService sdcCatalogService, VfcService vfcService) {
53 this.sdcCatalogService = sdcCatalogService;
54 this.vfcService = vfcService;
58 public VfNsPackageInfo retrievePackageInfo() {
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);
69 public DistributionResult postNsPackage(Csar csar) {
71 return vfcService.distributeNsPackage(csar).execute().body();
72 } catch (IOException e) {
73 throw new VfcException("VFC service is not available!", e);
78 public Job postVfPackage(Csar csar) {
80 return vfcService.distributeVnfPackage(csar).execute().body();
81 } catch (IOException e) {
82 throw new VfcException("VFC service is not available!", e);
87 public JobStatus getJobStatus(String jobId) {
89 return vfcService.getJobStatus(jobId).execute().body();
90 } catch (IOException e) {
91 throw new VfcException("VFC service is not available!", e);