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.business.impl;
19 import org.onap.vfc.nfvo.resmanagement.common.VimUtil;
20 import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant;
21 import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant;
22 import org.onap.vfc.nfvo.resmanagement.common.util.RestfulUtil;
23 import org.onap.vfc.nfvo.resmanagement.service.business.inf.LimitsBusiness;
24 import org.onap.vfc.nfvo.resmanagement.common.util.restclient.ServiceException;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 import net.sf.json.JSONObject;
36 * @version VFC 1.0 Sep 10, 2016
38 public class LimitsBusinessImpl implements LimitsBusiness {
40 private static final Logger LOGGER = LoggerFactory.getLogger(LimitsBusinessImpl.class);
50 private JSONObject getResponse(String vimId, String tenantId) {
51 LOGGER.info("function=getResponse; vimId={}, tenantId={}", vimId, tenantId);
52 String url = String.format(UrlConstant.GET_LIMITS_URL, vimId, tenantId);
53 JSONObject result = RestfulUtil.getResponseObj(url, ParamConstant.PARAM_GET);
54 LOGGER.warn("function=getResponse; result={}", result);
56 JSONObject obj = new JSONObject();
57 obj.put("msg", "getLimits fail!");
64 public JSONObject getLimits(String vimId) throws ServiceException {
65 JSONObject vimInfo = VimUtil.getVimById(vimId);
66 LOGGER.info("GetLimits vimInfo: {}", vimInfo);
67 String vimName = vimInfo.getString("name");
68 String tenant = vimInfo.getString("tenant");
69 String tenantId = VimUtil.getTenantIdByName(tenant, vimId);
71 JSONObject limits = getResponse(vimId, tenantId);
73 String totalCPU = String.valueOf(limits.get("maxTotalCores"));
74 String totalMemory = String.valueOf(limits.get("maxTotalRAMSize"));
75 String totalDisk = String.valueOf(limits.get("maxTotalVolumeGigabytes"));
76 String usedCPU = String.valueOf(limits.get("totalCoresUsed"));
77 String usedMemory = String.valueOf(limits.get("totalRAMUsed"));
78 String usedDisk = String.valueOf(limits.get("totalGigabytesUsed"));
80 JSONObject result = new JSONObject();
81 result.put("vimId", vimId);
82 result.put("vimName", vimName);
83 result.put("totalCPU", totalCPU);
84 result.put("totalMemory", totalMemory);
85 result.put("totalDisk", totalDisk);
86 result.put("usedCPU", usedCPU);
87 result.put("usedMemory", usedMemory);
88 result.put("usedDisk", usedDisk);
89 LOGGER.info("getLimits result:{}", result);