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.vnfm.svnfm.vnfmadapter.common;
19 import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.servicetoken.VnfmRestfulUtil;
20 import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.Constant;
21 import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.ParamConstants;
22 import org.openo.baseservice.roa.util.restclient.RestfulResponse;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 import net.sf.json.JSONArray;
27 import net.sf.json.JSONObject;
30 * Provide function of getting vnfmInfo
34 * @version NFVO 0.5 Aug 25, 2016
36 public final class VnfmUtil {
38 private static final Logger LOGGER = LoggerFactory.getLogger(VnfmUtil.class);
52 public static JSONObject getVnfmById(String vnfmId) {
53 RestfulResponse rsp = VnfmRestfulUtil.getRemoteResponse(String.format(ParamConstants.ESR_GET_VNFM_URL, vnfmId),
54 VnfmRestfulUtil.TYPE_GET, null);
55 if(rsp == null || rsp.getStatus() != Constant.HTTP_OK) {
56 LOGGER.error("funtion=getVnfmById, status={}", rsp.getStatus());
59 return JSONObject.fromObject(rsp.getResponseContent());
62 public static JSONObject mockForTest(String vnfmId){
63 String vInfo = "{\"vnfmId\":\"1234\", \"name\":\"vnfm\", \"type\":\"Tacker\", \"vimId\":\"\", \"vendor\":\"huawei\", \"version\":\"v1.0\", \"description\":\"vnfm\", \"certificateUrl\":\"\", \"url\":\"https://192.168.44.126:30001\", \"userName\":\"manoadmin\", \"password\":\"User@12345\", \"createTime\":\"2016-07-06 15:33:18\"}";
64 JSONObject json = JSONObject.fromObject(vInfo);
65 json.put("vnfmId",vnfmId);
77 public static String getVnfmIdByIp(String ip) {
79 VnfmRestfulUtil.getRemoteResponse(ParamConstants.ESR_GET_VNFMS_URL, VnfmRestfulUtil.TYPE_GET, null);
80 if(rsp == null || rsp.getStatus() != Constant.HTTP_OK) {
84 JSONArray vnfmList = JSONArray.fromObject(rsp.getResponseContent());
85 LOGGER.info("vnfm ip: {}, vnfmList: {}", ip, vnfmList);
86 for(int i = 0; i < vnfmList.size(); i++) {
87 if(vnfmList.getJSONObject(i).getString("url").contains(ip)) {
88 return vnfmList.getJSONObject(i).getString("vnfmId");