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.vnfm.gvnfm.jujuvnfmadapter.common;
19 import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.servicetoken.JujuVnfmRestfulUtil;
20 import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.servicetoken.VnfmRestfulUtil;
21 import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.constant.Constant;
22 import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.constant.UrlConstant;
23 import org.openo.baseservice.roa.util.restclient.RestfulResponse;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 import net.sf.json.JSONArray;
28 import net.sf.json.JSONObject;
30 * Provide function of getting vnfmInfo
36 * @version NFVO 0.5 Aug 25, 2016
38 public final class VnfmUtil {
40 private static final Logger LOG = LoggerFactory.getLogger(VnfmUtil.class);
53 public static JSONObject getVnfmById(String vnfmId) {
54 if(SwitchController.isDebugModel()){
55 JSONObject json = new JSONObject();
56 json.put("vnfmId", vnfmId);
57 json.put("vnfdId","testVnfdId");
58 json.put("vnfPackageId", "testPackageId");
59 json.put("version", "1");
60 json.put("url",JujuConfigUtil.getValue("jujuvnfm_server_url"));
63 RestfulResponse rsp = VnfmRestfulUtil.getRemoteResponse(String.format(UrlConstant.REST_ESRINFO_GET, vnfmId), JujuVnfmRestfulUtil.GET_TYPE, null);
64 if(rsp == null || rsp.getStatus() != Constant.HTTP_OK) {
67 LOG.error("funtion=getVnfmById, status={}", rsp.getStatus());
68 return JSONObject.fromObject(rsp.getResponseContent());
79 public static String getVnfmIdByIp(String ip) {
81 VnfmRestfulUtil.getRemoteResponse(UrlConstant.REST_ESRINFO_GET, VnfmRestfulUtil.TYPE_GET, null);
82 if(rsp == null || rsp.getStatus() != Constant.HTTP_OK) {
86 JSONArray vnfmList = JSONArray.fromObject(rsp.getResponseContent());
87 for(int i = 0; i < vnfmList.size(); i++) {
88 if(vnfmList.getJSONObject(i).getString("url").contains(ip)) {
89 return vnfmList.getJSONObject(i).getString("vnfmId");