2 * Copyright 2016-2017 ZTE, Inc. and others.
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.msb.sdclient.wrapper;
18 import org.apache.commons.lang3.StringUtils;
19 import org.onap.msb.sdclient.core.AgentService;
20 import org.onap.msb.sdclient.core.Node;
21 import org.onap.msb.sdclient.wrapper.util.ConfigUtil;
22 import org.onap.msb.sdclient.wrapper.util.DiscoverUtil;
23 import org.onap.msb.sdclient.wrapper.util.HttpClientUtil;
24 import org.onap.msb.sdclient.wrapper.util.JacksonJsonUtil;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
29 public class ConsulAgentServiceWrapper {
31 private static ConsulAgentServiceWrapper instance = new ConsulAgentServiceWrapper();
33 private ConsulAgentServiceWrapper() {}
35 public static ConsulAgentServiceWrapper getInstance() {
38 private static final Logger LOGGER = LoggerFactory.getLogger(ConsulAgentServiceWrapper.class);
41 public synchronized int saveService(AgentService agentService) throws Exception{
42 String consulRegisterurl =
43 (new StringBuilder().append("http://").append(ConfigUtil.getInstance().getConsulAddress())
44 .append(DiscoverUtil.CONSUL_AGENT_URL).append("/register")).toString();
48 HttpClientUtil.httpPostWithJSON(consulRegisterurl,
49 JacksonJsonUtil.beanToJson(agentService));
51 return registerResult;
55 public synchronized int deleteService(String serviceId) throws Exception{
57 (new StringBuilder().append("http://").append(ConfigUtil.getInstance().getConsulAddress())
58 .append(DiscoverUtil.CONSUL_AGENT_URL).append("/deregister/").append(serviceId))
61 int delResult = HttpClientUtil.httpPostWithJSON(consulDelurl, "");