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.entity;
19 import java.io.Serializable;
21 import org.apache.commons.lang.StringUtils;
22 import org.onap.vfc.nfvo.resmanagement.common.conf.Config;
23 import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant;
24 import org.onap.vfc.nfvo.resmanagement.common.util.JsonUtil;
25 import org.onap.vfc.nfvo.resmanagement.common.util.RestfulUtil;
26 import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil;
27 import org.onap.vfc.nfvo.resmanagement.common.util.restclient.RestfulParametes;
28 import org.onap.vfc.nfvo.resmanagement.common.util.restclient.RestfulResponse;
30 import net.sf.json.JSONArray;
31 import net.sf.json.JSONObject;
37 public class VnfEntity implements Serializable {
39 private static final String RESOURCE_VERSION = "resource-version";
41 private static final String VNF_ID = "vnf-id";
43 private static final String RELATIONSHIP_KEY = "relationship-key";
45 private static final String RELATIONSHIP_VALUE = "relationship-value";
51 private String vnfInstanceId;
54 private String vnfInstanceName;
60 private String nsName;
63 private String vnfmId;
66 private String vnfmName;
69 private String vnfPackageName;
72 private String vnfDescriptorName;
78 private String vimName;
81 private String vimTenant;
87 private String vnfStatus;
90 private String vnfType;
93 private Integer maxVm;
96 private Integer maxCpu;
99 private Integer maxDisk;
102 private Integer maxRam;
105 private Integer maxShd;
108 private Integer maxNet;
114 private String vnfResourceVersion;
116 private String vnfmResourceVersion;
118 private static final long serialVersionUID = 1L;
120 public String getId() {
124 public void setId(String id) {
128 public String getVnfInstanceId() {
129 return vnfInstanceId;
132 public void setVnfInstanceId(String vnfInstanceId) {
133 this.vnfInstanceId = vnfInstanceId;
136 public String getVnfInstanceName() {
137 return vnfInstanceName;
140 public void setVnfInstanceName(String vnfInstanceName) {
141 this.vnfInstanceName = vnfInstanceName;
144 public String getNsId() {
148 public void setNsId(String nsId) {
152 public String getNsName() {
156 public void setNsName(String nsName) {
157 this.nsName = nsName;
160 public String getVnfmId() {
164 public void setVnfmId(String vnfmId) {
165 this.vnfmId = vnfmId;
168 public String getVnfmName() {
172 public void setVnfmName(String vnfmName) {
173 this.vnfmName = vnfmName;
176 public String getVnfPackageName() {
177 return vnfPackageName;
180 public void setVnfPackageName(String vnfPackageName) {
181 this.vnfPackageName = vnfPackageName;
184 public String getVnfDescriptorName() {
185 return vnfDescriptorName;
188 public void setVnfDescriptorName(String vnfDescriptorName) {
189 this.vnfDescriptorName = vnfDescriptorName;
192 public String getVimId() {
196 public void setVimId(String vimId) {
200 public String getVimName() {
204 public void setVimName(String vimName) {
205 this.vimName = vimName;
208 public String getVimTenant() {
212 public void setVimTenant(String vimTenant) {
213 this.vimTenant = vimTenant;
216 public String getJobId() {
220 public void setJobId(String jobId) {
224 public String getVnfStatus() {
228 public void setVnfStatus(String vnfStatus) {
229 this.vnfStatus = vnfStatus;
232 public String getVnfType() {
236 public void setVnfType(String vnfType) {
237 this.vnfType = vnfType;
240 public Integer getMaxVm() {
244 public void setMaxVm(Integer maxVm) {
248 public Integer getMaxCpu() {
252 public void setMaxCpu(Integer maxCpu) {
253 this.maxCpu = maxCpu;
256 public Integer getMaxDisk() {
260 public void setMaxDisk(Integer maxDisk) {
261 this.maxDisk = maxDisk;
264 public Integer getMaxRam() {
268 public void setMaxRam(Integer maxRam) {
269 this.maxRam = maxRam;
272 public Integer getMaxShd() {
276 public void setMaxShd(Integer maxShd) {
277 this.maxShd = maxShd;
280 public Integer getMaxNet() {
284 public void setMaxNet(Integer maxNet) {
285 this.maxNet = maxNet;
288 public String getName() {
292 public void setName(String name) {
303 public static VnfEntity toEntity(JSONObject jsonObject) {
304 VnfEntity vnfEntity = new VnfEntity();
305 vnfEntity.setId(JsonUtil.getJsonFieldStr(jsonObject, "id"));
306 vnfEntity.setName(JsonUtil.getJsonFieldStr(jsonObject, "name"));
307 vnfEntity.setVnfInstanceId(JsonUtil.getJsonFieldStr(jsonObject, "vnfInstanceId"));
308 vnfEntity.setVnfInstanceName(JsonUtil.getJsonFieldStr(jsonObject, "vnfInstanceName"));
309 vnfEntity.setNsId(JsonUtil.getJsonFieldStr(jsonObject, "nsId"));
310 vnfEntity.setNsName(JsonUtil.getJsonFieldStr(jsonObject, "nsName"));
311 vnfEntity.setVnfmId(JsonUtil.getJsonFieldStr(jsonObject, "vnfmId"));
312 vnfEntity.setVnfmName(JsonUtil.getJsonFieldStr(jsonObject, "vnfmName"));
313 vnfEntity.setVnfPackageName(JsonUtil.getJsonFieldStr(jsonObject, "vnfPackageName"));
314 vnfEntity.setVnfDescriptorName(JsonUtil.getJsonFieldStr(jsonObject, "vnfDescriptorName"));
315 vnfEntity.setVimId(JsonUtil.getJsonFieldStr(jsonObject, "vimId"));
316 vnfEntity.setVimName(JsonUtil.getJsonFieldStr(jsonObject, "vimName"));
317 vnfEntity.setVimTenant(JsonUtil.getJsonFieldStr(jsonObject, "vimTenant"));
318 vnfEntity.setJobId(JsonUtil.getJsonFieldStr(jsonObject, "jobId"));
319 vnfEntity.setVnfStatus(JsonUtil.getJsonFieldStr(jsonObject, "vnfStatus"));
320 vnfEntity.setVnfType(JsonUtil.getJsonFieldStr(jsonObject, "vnfType"));
321 vnfEntity.setMaxVm(JsonUtil.getJsonFieldInt(jsonObject, "maxVm"));
322 vnfEntity.setMaxCpu(JsonUtil.getJsonFieldInt(jsonObject, "maxCpu"));
323 vnfEntity.setMaxDisk(JsonUtil.getJsonFieldInt(jsonObject, "maxDisk"));
324 vnfEntity.setMaxRam(JsonUtil.getJsonFieldInt(jsonObject, "maxRam"));
325 vnfEntity.setMaxShd(JsonUtil.getJsonFieldInt(jsonObject, "maxShd"));
326 vnfEntity.setMaxNet(JsonUtil.getJsonFieldInt(jsonObject, "maxNet"));
327 vnfEntity.setVnfResourceVersion(JsonUtil.getJsonFieldStr(jsonObject, RESOURCE_VERSION));
331 public static VnfEntity toEntityFromAai(JSONObject jsonObject) {
332 VnfEntity vnfEntity = new VnfEntity();
333 vnfEntity.setId(JsonUtil.getJsonFieldStr(jsonObject, VNF_ID));
334 vnfEntity.setVnfInstanceId(JsonUtil.getJsonFieldStr(jsonObject, VNF_ID));
335 vnfEntity.setVnfInstanceName(JsonUtil.getJsonFieldStr(jsonObject, "vnf-name"));
336 vnfEntity.setName(JsonUtil.getJsonFieldStr(jsonObject, "vnf-name2"));
337 vnfEntity.setNsId(JsonUtil.getJsonFieldStr(jsonObject, "service-id"));
338 vnfEntity.setVnfStatus(JsonUtil.getJsonFieldStr(jsonObject, "orchestration-status"));
339 vnfEntity.setVnfType(JsonUtil.getJsonFieldStr(jsonObject, "vnf-type"));
340 vnfEntity.setVnfPackageName(JsonUtil.getJsonFieldStr(jsonObject, "vnf-package-name"));
341 vnfEntity.setVnfDescriptorName(JsonUtil.getJsonFieldStr(jsonObject, "vnf-discriptor-name"));
342 vnfEntity.setJobId(JsonUtil.getJsonFieldStr(jsonObject, "job-id"));
343 vnfEntity.setMaxCpu(JsonUtil.getJsonFieldInt(jsonObject, "vcpu"));
344 vnfEntity.setMaxDisk(JsonUtil.getJsonFieldInt(jsonObject, "vdisk"));
345 vnfEntity.setMaxRam(JsonUtil.getJsonFieldInt(jsonObject, "vmemory"));
346 vnfEntity.setMaxNet(JsonUtil.getJsonFieldInt(jsonObject, "vnet"));
347 vnfEntity.setMaxShd(JsonUtil.getJsonFieldInt(jsonObject, "nshd"));
348 vnfEntity.setMaxVm(JsonUtil.getJsonFieldInt(jsonObject, "nvm"));
349 vnfEntity.setVnfResourceVersion(JsonUtil.getJsonFieldStr(jsonObject, RESOURCE_VERSION));
353 public static void updateEntityWithVnfmInfo(VnfEntity vnfEntity, JSONObject jsonObject) {
354 vnfEntity.setVnfmId(JsonUtil.getJsonFieldStr(jsonObject, "vnfm-id"));
355 vnfEntity.setVnfmName(JsonUtil.getJsonFieldStr(jsonObject, "vnfm-name"));
356 vnfEntity.setVnfmResourceVersion(JsonUtil.getJsonFieldStr(jsonObject, RESOURCE_VERSION));
357 vnfEntity.setVimId(JsonUtil.getJsonFieldStr(jsonObject, "vim-id"));
359 // vim id stores the info as vim-id: <cloud-region-owner>_<cloud-region-id>
360 // and esr-system-info contains vim info.
361 String str = vnfEntity.getVimId();
363 if(!(str == null) && str.contains("_")) {
364 String[] result = str.split("_");
365 RestfulParametes restfulParametes = new RestfulParametes();
366 restfulParametes.setHeaderMap(RequestUtil.getAAIHeaderMap());
367 RestfulResponse restfulResponse =
370 Config.getHost() + ":" + Config.getPort() + UrlConstant.CLOUD_REGION_URL + result[0]
371 + "/" + result[1] + "/esr-system-info-list/esr-system-info",
372 restfulParametes, "get");
374 if(restfulResponse.isSuccess()) {
375 vnfEntity.setVimId(JsonUtil.getJsonFieldStr(JSONObject.fromObject(restfulResponse.getResponseContent()),
376 "esr-system-info-id"));
377 vnfEntity.setVimName(JsonUtil
378 .getJsonFieldStr(JSONObject.fromObject(restfulResponse.getResponseContent()), "system-name"));
379 vnfEntity.setVimTenant(JsonUtil.getJsonFieldStr(
380 JSONObject.fromObject(restfulResponse.getResponseContent()), "default-tenant"));
388 public static void updateEntityWithNsInfo(VnfEntity vnfEntity, JSONObject jsonObject) {
389 vnfEntity.setNsId(JsonUtil.getJsonFieldStr(jsonObject, "service-instance-id"));
390 vnfEntity.setNsName(JsonUtil.getJsonFieldStr(jsonObject, "service-instance-name"));
393 public String toStringForAai() {
394 JSONObject vnfResJson = new JSONObject();
395 vnfResJson.put(VNF_ID, StringUtils.trimToEmpty(this.getId()));
396 vnfResJson.put("vnf-name", StringUtils.trimToEmpty(this.getVnfInstanceName()));
397 vnfResJson.put("vnf-name2", StringUtils.trimToEmpty(this.getName()));
398 vnfResJson.put("service-id", StringUtils.trimToEmpty(this.getNsId()));
399 vnfResJson.put("vnf-type", StringUtils.trimToEmpty(this.getVnfType()));
400 vnfResJson.put("vcpu", this.getMaxCpu());
401 vnfResJson.put("vdisk", this.getMaxDisk());
402 vnfResJson.put("vmemory", this.getMaxRam());
403 vnfResJson.put("nshd", this.getMaxShd());
404 vnfResJson.put("nvm", this.getMaxVm());
405 vnfResJson.put("nnet", this.getMaxNet());
406 vnfResJson.put("vnf-package-name", StringUtils.trimToEmpty(this.getVnfPackageName()));
407 vnfResJson.put("vnf-discriptor-name", StringUtils.trimToEmpty(this.getVnfDescriptorName()));
408 vnfResJson.put("job-id", StringUtils.trimToEmpty(this.getJobId()));
409 vnfResJson.put("orchestration-status", StringUtils.trimToEmpty(this.getVnfStatus()));
411 JSONObject relationshipDataEntry = new JSONObject();
412 relationshipDataEntry.put(RELATIONSHIP_KEY, "esr-vnfm.vnfm-id");
413 relationshipDataEntry.put(RELATIONSHIP_VALUE, this.getVnfmId());
415 JSONArray relationshipData1 = new JSONArray();
416 JSONObject customer = new JSONObject();
417 customer.put(RELATIONSHIP_KEY, "customer.global-customer-id");
418 customer.put(RELATIONSHIP_VALUE, Config.getGlobalCustomerId());
419 JSONObject service = new JSONObject();
420 service.put(RELATIONSHIP_KEY, "service-subscription.service-type");
421 service.put(RELATIONSHIP_VALUE, Config.getServiceType());
422 JSONObject serviceInstance = new JSONObject();
423 serviceInstance.put(RELATIONSHIP_KEY, "service-instance.service-instance-id");
424 serviceInstance.put(RELATIONSHIP_VALUE, this.getNsId());
425 relationshipData1.add(customer);
426 relationshipData1.add(service);
427 relationshipData1.add(serviceInstance);
429 JSONArray relationshipData = new JSONArray();
430 relationshipData.add(relationshipDataEntry);
431 JSONArray relationship = new JSONArray();
432 JSONObject relationshipEntry = new JSONObject();
433 relationshipEntry.put("related-to", "esr-vnfm");
434 relationshipEntry.put("relationship-data", relationshipData);
435 JSONObject relationshipEntry1 = new JSONObject();
436 relationshipEntry1.put("related-to", "service-instance");
437 relationshipEntry1.put("relationship-data", relationshipData1);
438 relationship.add(relationshipEntry);
439 relationship.add(relationshipEntry1);
441 JSONObject relation = new JSONObject();
442 relation.put("relationship", relationship);
444 vnfResJson.put("relationship-list", relation);
445 return vnfResJson.toString();
448 public String toEsrVnfmStringForAai() {
449 JSONObject esrVnfm = new JSONObject();
450 esrVnfm.put("vnfm-id", StringUtils.trimToEmpty(this.getVnfmId()));
451 esrVnfm.put("vim-id", StringUtils.trimToEmpty(this.getVimId()));
452 return esrVnfm.toString();
456 public String toString() {
457 JSONObject vnfResJson = new JSONObject();
458 vnfResJson.put("id", StringUtils.trimToEmpty(this.getId()));
459 vnfResJson.put("name", StringUtils.trimToEmpty(this.getName()));
460 vnfResJson.put("vnfInstanceId", StringUtils.trimToEmpty(this.getName()));
461 vnfResJson.put("vnfInstanceName", StringUtils.trimToEmpty(this.getName()));
462 vnfResJson.put("nsId", StringUtils.trimToEmpty(this.getName()));
463 vnfResJson.put("nsName", StringUtils.trimToEmpty(this.getName()));
464 vnfResJson.put("vnfmId", StringUtils.trimToEmpty(this.getName()));
465 vnfResJson.put("vnfmName", StringUtils.trimToEmpty(this.getName()));
466 vnfResJson.put("vnfPackageName", StringUtils.trimToEmpty(this.getId()));
467 vnfResJson.put("vnfDescriptorName", StringUtils.trimToEmpty(this.getName()));
468 vnfResJson.put("vimId", StringUtils.trimToEmpty(this.getName()));
469 vnfResJson.put("vimName", StringUtils.trimToEmpty(this.getName()));
470 vnfResJson.put("vimTenant", StringUtils.trimToEmpty(this.getName()));
471 vnfResJson.put("jobId", StringUtils.trimToEmpty(this.getName()));
472 vnfResJson.put("vnfStatus", StringUtils.trimToEmpty(this.getName()));
473 vnfResJson.put("vnfType", StringUtils.trimToEmpty(this.getName()));
474 vnfResJson.put("maxVm", StringUtils.trimToEmpty(this.getName()));
475 vnfResJson.put("maxCpu", StringUtils.trimToEmpty(this.getName()));
476 vnfResJson.put("maxDisk", StringUtils.trimToEmpty(this.getName()));
477 vnfResJson.put("maxRam", StringUtils.trimToEmpty(this.getName()));
478 vnfResJson.put("maxShd", StringUtils.trimToEmpty(this.getName()));
479 vnfResJson.put("maxNet", StringUtils.trimToEmpty(this.getName()));
480 return vnfResJson.toString();
483 public String getVnfmResourceVersion() {
484 return vnfmResourceVersion;
487 public void setVnfmResourceVersion(String vnfmResourceVersion) {
488 this.vnfmResourceVersion = vnfmResourceVersion;
491 public String getVnfResourceVersion() {
492 return vnfResourceVersion;
495 public void setVnfResourceVersion(String vnfResourceVersion) {
496 this.vnfResourceVersion = vnfResourceVersion;