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.onap.vfc.nfvo.resmanagement.service.business.impl;
19 import java.util.List;
21 import java.util.UUID;
23 import org.apache.commons.lang3.StringUtils;
24 import org.onap.vfc.nfvo.resmanagement.common.ResourceUtil;
25 import org.onap.vfc.nfvo.resmanagement.service.business.inf.HostBusiness;
26 import org.onap.vfc.nfvo.resmanagement.service.dao.inf.HostDao;
27 import org.onap.vfc.nfvo.resmanagement.service.entity.HostEntity;
28 import org.openo.baseservice.remoteservice.exception.ServiceException;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
34 * Host business implementation class.<br>
39 * @version NFVO 0.5 Sep 10, 2016
41 public class HostBusinessImpl implements HostBusiness {
43 private static final Logger LOGGER = LoggerFactory.getLogger(HostBusinessImpl.class);
45 private HostDao hostDao;
48 public HostEntity getHost(String id) {
49 if(StringUtils.isEmpty(id)) {
50 LOGGER.error("function=getHost; msg=get error, because id is empty.");
53 return hostDao.getHost(id);
57 public List<HostEntity> getHosts(Map<String, Object> condition) {
58 return hostDao.getHosts(condition);
62 public int deleteHost(String id) throws ServiceException {
63 if(StringUtils.isEmpty(id)) {
64 LOGGER.error("function=deleteHost; msg=delete error, because id is empty.");
65 throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.host.delete.id.null"));
67 HostEntity rp = hostDao.getHost(id);
69 return hostDao.deleteHost(id);
72 return hostDao.deleteHost(id);
76 public int addHost(HostEntity hostEntity) throws ServiceException {
77 if(null == hostEntity) {
78 LOGGER.error("function=addHost; msg=add error, because hostEntity is null.");
79 throw new ServiceException(
80 ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.host.add.entity.null"));
83 if(!checkId(hostEntity.getId())) {
84 LOGGER.error("function=addHost; msg=add error, because id is already exist.");
85 throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.host.add.id.check"));
87 if(StringUtils.isEmpty(hostEntity.getId())) {
88 hostEntity.setId(UUID.randomUUID().toString());
90 return hostDao.addHost(hostEntity);
94 public int addHostSelective(HostEntity hostEntity) throws ServiceException {
95 if(null == hostEntity) {
96 LOGGER.error("function=addHostSelective; msg=add error, because hostEntity is null.");
97 throw new ServiceException(
98 ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.host.add.entity.null"));
100 if(!checkId(hostEntity.getId())) {
101 LOGGER.error("function=addHostSelective; msg=add error, because id is allready exist.");
102 throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.host.add.id.check"));
105 if(StringUtils.isEmpty(hostEntity.getId())) {
106 hostEntity.setId(UUID.randomUUID().toString());
108 return hostDao.addHostSelective(hostEntity);
111 private boolean checkId(String id) {
112 HostEntity respool = hostDao.getHost(id);
113 if(null == respool) {
120 public int updateHostSelective(HostEntity hostEntity) throws ServiceException {
121 if(!checkId(hostEntity.getId())) {
122 return hostDao.updateHostSelective(hostEntity);
124 return addHostSelective(hostEntity);
129 public int updateHost(HostEntity hostEntity) throws ServiceException {
130 if(null == hostEntity) {
131 LOGGER.error("function=updateHost; msg=update error, because hostEntity is null.");
132 throw new ServiceException("update error, because hostEntity is null.");
135 return hostDao.updateHost(hostEntity);
139 public int updateHostByVimId(HostEntity hostEntity) throws ServiceException {
140 if(null == hostEntity) {
141 LOGGER.error("function=updateHostByVimId; msg=update error, because hostEntity is null.");
142 throw new ServiceException(
143 ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.host.update.entity.null"));
145 return hostDao.updateHostByVimId(hostEntity);
149 public int deleteHostByVimId(String vimId) throws ServiceException {
150 if(StringUtils.isEmpty(vimId)) {
151 LOGGER.error("function=deleteHostByVimId; msg=delete error, because VimId is empty.");
152 throw new ServiceException(
153 ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.host.delete.vimid.check"));
155 return hostDao.deleteHostByVimId(vimId);
158 public void setHostDao(HostDao hostDao) {
159 this.hostDao = hostDao;