2 * Copyright 2017 BOCO Corporation. CMCC 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.
16 package org.onap.nfvo.emsdriver.serviceregister;
19 import java.util.ArrayList;
20 import java.util.List;
22 import org.onap.nfvo.emsdriver.commons.constant.Constant;
23 import org.onap.nfvo.emsdriver.northbound.client.HttpClientUtil;
24 import org.onap.nfvo.emsdriver.serviceregister.model.MsbRegisterVo;
25 import org.onap.nfvo.emsdriver.serviceregister.model.ServiceNodeVo;
27 import com.alibaba.fastjson.JSON;
29 public class MsbRestServiceProxy {
31 public static String registerService(MsbRegisterVo registerInfo){
32 String url = MsbConfiguration.getMsbAddress()+Constant.MSBAPIROOTDOMAIN;
33 String registerObj = JSON.toJSONString(registerInfo);
35 String registerResponse = HttpClientUtil.doPost(url, registerObj, Constant.ENCODING_UTF8);
36 return registerResponse;
39 public static void unRegiserService(String serviceName,String version,String ip,String port){
40 String url = MsbConfiguration.getMsbAddress()+Constant.MSBAPIROOTDOMAIN+"/"+serviceName+"/version/"+version+"/nodes/"+ip+"/"+port;
41 HttpClientUtil.doDelete(url, Constant.ENCODING_UTF8);
44 public static List<String> queryService(String serviceName,String version){
45 List<String> ipList = new ArrayList<String>();
46 String url = MsbConfiguration.getMsbAddress()+Constant.MSBAPIROOTDOMAIN+"/"+serviceName+"/version/"+version;
47 String response = HttpClientUtil.doGet(url, Constant.ENCODING_UTF8);
48 if(!response.equals("")){
49 MsbRegisterVo msbRegisterVo = JSON.parseObject(response,MsbRegisterVo.class);
50 List<ServiceNodeVo> nodeList = msbRegisterVo.getNodes();
52 for(ServiceNodeVo node :nodeList){
53 String ip = node.getIp();