Modify groupId for ems driver
[vfc/nfvo/driver/ems.git] / ems / boco / src / main / java / org / onap / nfvo / emsdriver / serviceregister / MsbRestServiceProxy.java
1 /**
2  * Copyright 2017 BOCO Corporation.  CMCC Technologies Co., Ltd
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.onap.nfvo.emsdriver.serviceregister;
17
18
19 import java.util.ArrayList;
20 import java.util.List;
21
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;
26
27 import com.alibaba.fastjson.JSON;
28
29 public class MsbRestServiceProxy {
30
31     public static String registerService(MsbRegisterVo registerInfo){
32         String url = MsbConfiguration.getMsbAddress()+Constant.MSBAPIROOTDOMAIN;
33         String registerObj = JSON.toJSONString(registerInfo);
34         
35         String registerResponse = HttpClientUtil.doPost(url, registerObj, Constant.ENCODING_UTF8);
36         return registerResponse;
37     }
38
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);
42     }
43     
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();
51                 
52                 for(ServiceNodeVo node :nodeList){
53                         String ip = node.getIp();
54                         ipList.add(ip);
55                 }
56         }
57                 return ipList;
58                 
59     }
60
61 }