Change: add OPEN-O seed code for VF-C
[vfc/nfvo/driver/vnfm/svnfm.git] / huawei / vnfmadapter / VnfmadapterService / service / src / main / java / org / openo / nfvo / vnfmadapter / service / process / RegisterMgr.java
1 /*
2  * Copyright 2016 Huawei 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
17 package org.openo.nfvo.vnfmadapter.service.process;
18
19 import java.util.HashMap;
20 import java.util.Map;
21
22 import org.openo.baseservice.roa.util.restclient.RestfulResponse;
23 import org.openo.nfvo.vnfmadapter.common.RegisterConfigInfo;
24 import org.openo.nfvo.vnfmadapter.common.servicetoken.VnfmRestfulUtil;
25 import org.openo.nfvo.vnfmadapter.service.constant.ParamConstants;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 import net.sf.json.JSONObject;
30
31 /**
32  * Provide function for register or unregister service to Bus.
33  * <br/>
34  *
35  * @author
36  * @version NFVO 0.5 Aug 24, 2016
37  */
38 public class RegisterMgr {
39
40     private static final Logger LOG = LoggerFactory.getLogger(RegisterMgr.class);
41
42     /**
43      * Register service to the Bus
44      * <br/>
45      *
46      * @since NFVO 0.5
47      */
48     public void register() {
49         RestfulResponse rsp = VnfmRestfulUtil.getRemoteResponse(ParamConstants.MSB_REGISTER_URL,
50                 VnfmRestfulUtil.TYPE_POST, getRegsiterBody());
51
52         LOG.error("funtion=register, status={}", rsp.getStatus());
53     }
54
55     /**
56      * UnRegister service to the Bus
57      * <br/>
58      *
59      * @since NFVO 0.5
60      */
61     public void unRegister() {
62         Map<String, String> paramsMap = new HashMap<>();
63         paramsMap.put("url", ParamConstants.MSB_UNREGISTER_URL);
64         paramsMap.put("methodType", VnfmRestfulUtil.TYPE_DEL);
65         RestfulResponse rsp = VnfmRestfulUtil.getRemoteResponse(ParamConstants.MSB_UNREGISTER_URL,
66                 VnfmRestfulUtil.TYPE_DEL, null);
67
68         LOG.error("funtion=register, status={}", rsp.getStatus());
69     }
70
71     private String getRegsiterBody() {
72         JSONObject body = new JSONObject();
73         body.put("serviceName", RegisterConfigInfo.getInstance().getServiceName());
74         body.put("version", RegisterConfigInfo.getInstance().getVersion());
75         body.put("url", RegisterConfigInfo.getInstance().getUrl());
76         body.put("protocol", RegisterConfigInfo.getInstance().getProtocol());
77         body.put("port", RegisterConfigInfo.getInstance().getPort());
78         body.put("ip", RegisterConfigInfo.getInstance().getIp());
79         body.put("ttl", RegisterConfigInfo.getInstance().getTtl());
80
81         return body.toString();
82     }
83 }