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.svnfm.vnfmadapter.service.process;
19 import java.util.HashMap;
22 import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.RegisterConfigInfo;
23 import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.servicetoken.VnfmRestfulUtil;
24 import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.ParamConstants;
25 import org.openo.baseservice.roa.util.restclient.RestfulResponse;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 import net.sf.json.JSONObject;
32 * Provide function for register or unregister service to Bus.
36 * @version NFVO 0.5 Aug 24, 2016
38 public class RegisterMgr {
40 private static final Logger LOG = LoggerFactory.getLogger(RegisterMgr.class);
43 * Register service to the Bus
48 public void register() {
49 RestfulResponse rsp = VnfmRestfulUtil.getRemoteResponse(ParamConstants.MSB_REGISTER_URL,
50 VnfmRestfulUtil.TYPE_POST, getRegsiterBody());
52 LOG.error("funtion=register, status={}", rsp.getStatus());
56 * UnRegister service to the Bus
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);
68 LOG.error("funtion=register, status={}", rsp.getStatus());
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());
81 return body.toString();