2 * Copyright 2016-2017 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.base.openstack.impl;
19 import java.util.List;
22 import org.onap.vfc.nfvo.resmanagement.common.util.JsonUtil;
23 import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.Network;
24 import org.onap.vfc.nfvo.resmanagement.service.business.inf.NetworkBusiness;
25 import org.onap.vfc.nfvo.resmanagement.service.entity.NetworkEntity;
26 import org.onap.vfc.nfvo.resmanagement.common.util.restclient.ServiceException;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 import net.sf.json.JSONObject;
33 * Network implementation class.<br>
38 * @version VFC 1.0 Sep 10, 2016
40 public class NetworkImpl implements Network {
42 private static final Logger LOGGER = LoggerFactory.getLogger(NetworkImpl.class);
44 private NetworkBusiness networkBusiness;
47 public int add(JSONObject jsonObject) throws ServiceException {
48 LOGGER.warn("function=addPort; jsonObject={}", jsonObject);
49 JSONObject networkObj = dataParse(jsonObject);
50 return networkBusiness.addNetwork(NetworkEntity.toEntity(networkObj));
53 private JSONObject dataParse(JSONObject jsonObject) {
54 JSONObject portObj = new JSONObject();
55 portObj.put("id", JsonUtil.getJsonFieldStr(jsonObject, "id"));
56 portObj.put("name", JsonUtil.getJsonFieldStr(jsonObject, "name"));
57 portObj.put("status", JsonUtil.getJsonFieldStr(jsonObject, "status"));
58 portObj.put("tenantId", JsonUtil.getJsonFieldStr(jsonObject, "tenant_id"));
59 portObj.put("vimId", JsonUtil.getJsonFieldStr(jsonObject, "vimId"));
60 portObj.put("vimName", JsonUtil.getJsonFieldStr(jsonObject, "vimName"));
61 portObj.put("physicalNetwork", JsonUtil.getJsonFieldStr(jsonObject, "physicalNetwork"));
62 portObj.put("networkType", JsonUtil.getJsonFieldStr(jsonObject, "networkType"));
63 portObj.put("segmentationId", JsonUtil.getJsonFieldStr(jsonObject, "segmentationId"));
68 public int add(NetworkEntity entity) throws ServiceException {
69 return networkBusiness.addNetwork(entity);
73 public int update(JSONObject jsonObject) throws ServiceException {
74 return networkBusiness.updateNetworkSelective(NetworkEntity.toEntity(jsonObject));
78 public int delete(String id) throws ServiceException {
79 return networkBusiness.deleteNetwork(id);
83 public int updateStatusByVimId(JSONObject jsonObject) throws ServiceException {
84 return networkBusiness.updateNetworkByVimId(NetworkEntity.toEntity(jsonObject));
88 public List<NetworkEntity> getList(Map<String, Object> condition) throws ServiceException {
89 return networkBusiness.getNetworks(condition);
93 public int deleteResByVimId(String vimId) throws ServiceException {
94 return networkBusiness.deleteNetworkByVimId(vimId);
97 public void setNetworkBusiness(NetworkBusiness networkBusiness) {
98 this.networkBusiness = networkBusiness;