2 * Copyright 2016 Huawei Technologies Co., Ltd.
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.
17 package org.openo.nfvo.resmanagement.service.group.impl;
19 import java.util.List;
21 import java.util.UUID;
23 import org.apache.commons.lang3.StringUtils;
24 import org.openo.baseservice.remoteservice.exception.ServiceException;
25 import org.openo.nfvo.resmanagement.common.ResourceUtil;
26 import org.openo.nfvo.resmanagement.service.dao.inf.VnfDao;
27 import org.openo.nfvo.resmanagement.service.entity.VnfEntity;
28 import org.openo.nfvo.resmanagement.service.group.inf.VnfInfoService;
29 import org.openo.nfvo.resmanagement.service.group.inf.VnfService;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 import net.sf.json.JSONObject;
41 * @version NFVO 0.5 Oct 28, 2016
43 public class VnfServiceImpl implements VnfService {
45 private static final Logger LOGGER = LoggerFactory.getLogger(VnfServiceImpl.class);
47 private VnfDao vnfDao;
49 private VnfInfoService vnfInfoService;
56 * @throws ServiceException
60 public JSONObject addVnf(VnfEntity vnfEntity) throws ServiceException {
61 if(!checkId(vnfEntity.getId())) {
62 LOGGER.error("function=addVnf; msg=add error, because id is already exist.");
63 throw new ServiceException(ResourceUtil
64 .getMessage("org.openo.nfvo.resmanagement.service.group.impl.VnfServiceImpl.add.id.check"));
66 if(StringUtils.isEmpty(vnfEntity.getId())) {
67 vnfEntity.setId(UUID.randomUUID().toString());
69 int result = vnfDao.addVnf(vnfEntity);
70 JSONObject restJson = new JSONObject();
72 restJson.put("id", vnfEntity.getId());
73 restJson.put("name", vnfEntity.getName());
75 LOGGER.error("function=addVnf; msg=add vnf into DB error.");
76 restJson.put("message", "Add vnf into DB error.");
88 private boolean checkId(String id) {
89 VnfEntity vnf = vnfDao.getVnf(id);
101 * @throws ServiceException
105 public List<VnfEntity> getList(Map<String, Object> map) throws ServiceException {
106 return vnfDao.getVnfs(map);
114 * @throws ServiceException
118 public int delete(String id) throws ServiceException {
120 return vnfDao.deleteVnfById(id);
127 * @throws ServiceException
130 private void deleteVnfInfo(String vnfInstanceId) throws ServiceException {
131 vnfInfoService.delete(vnfInstanceId);
134 public void setVnfDao(VnfDao vnfDao) {
135 this.vnfDao = vnfDao;
138 public void setVnfInfoService(VnfInfoService vnfInfoService) {
139 this.vnfInfoService = vnfInfoService;