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.entity;
19 import org.apache.commons.lang3.StringUtils;
20 import org.openo.nfvo.resmanagement.common.util.JsonUtil;
22 import net.sf.json.JSONObject;
25 * Host entity class.<br/>
30 * @version NFVO 0.5 Aug 31, 2016
32 public class HostEntity {
40 private String memory;
46 private String vimName;
49 * @return Returns the id.
51 public String getId() {
56 * @param id The id to set.
58 public void setId(String id) {
63 * @return Returns the name.
65 public String getName() {
70 * @param name The name to set.
72 public void setName(String name) {
77 * @return Returns the cpu.
79 public String getCpu() {
84 * @param cpu The cpu to set.
86 public void setCpu(String cpu) {
91 * @return Returns the memory.
93 public String getMemory() {
98 * @param memory The memory to set.
100 public void setMemory(String memory) {
101 this.memory = memory;
105 * @return Returns the disk.
107 public String getDisk() {
112 * @param disk The disk to set.
114 public void setDisk(String disk) {
119 * @return Returns the vimId.
121 public String getVimId() {
126 * @param vimId The vimId to set.
128 public void setVimId(String vimId) {
133 * @return Returns the vimName.
135 public String getVimName() {
140 * @param vimName The vimName to set.
142 public void setVimName(String vimName) {
143 this.vimName = vimName;
154 public static HostEntity toEntity(JSONObject jsonObject) {
155 HostEntity hostEntity = new HostEntity();
156 hostEntity.setId(JsonUtil.getJsonFieldStr(jsonObject, "id"));
157 hostEntity.setName(JsonUtil.getJsonFieldStr(jsonObject, "name"));
158 hostEntity.setCpu(JsonUtil.getJsonFieldStr(jsonObject, "cpu"));
159 hostEntity.setMemory(JsonUtil.getJsonFieldStr(jsonObject, "memory"));
160 hostEntity.setDisk(JsonUtil.getJsonFieldStr(jsonObject, "disk"));
161 hostEntity.setVimId(JsonUtil.getJsonFieldStr(jsonObject, "vimId"));
162 hostEntity.setVimName(JsonUtil.getJsonFieldStr(jsonObject, "vimName"));
167 public String toString() {
168 JSONObject hostResJson = new JSONObject();
169 hostResJson.put("id", StringUtils.trimToEmpty(this.getId()));
170 hostResJson.put("name", StringUtils.trimToEmpty(this.getName()));
171 hostResJson.put("cpu", StringUtils.trimToEmpty(this.getCpu()));
172 hostResJson.put("memory", StringUtils.trimToEmpty(this.getMemory()));
173 hostResJson.put("disk", StringUtils.trimToEmpty(this.getDisk()));
174 hostResJson.put("vimId", StringUtils.trimToEmpty(this.getVimId()));
175 hostResJson.put("vimName", StringUtils.trimToEmpty(this.getVimName()));
176 return hostResJson.toString();