2 * Copyright 2016-2017 ZTE, Inc. and others.
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software distributed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 * or implied. See the License for the specific language governing permissions and limitations under
14 package org.onap.msb.sdclient.wrapper;
16 import org.onap.msb.sdclient.core.AgentService;
17 import org.onap.msb.sdclient.wrapper.util.ConfigUtil;
18 import org.onap.msb.sdclient.wrapper.util.DiscoverUtil;
19 import org.onap.msb.sdclient.wrapper.util.HttpClientUtil;
20 import org.onap.msb.sdclient.wrapper.util.JacksonJsonUtil;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 public class ConsulAgentServiceWrapper {
27 private static ConsulAgentServiceWrapper instance = new ConsulAgentServiceWrapper();
29 private ConsulAgentServiceWrapper() {}
31 public static ConsulAgentServiceWrapper getInstance() {
35 private static final Logger LOGGER = LoggerFactory.getLogger(ConsulAgentServiceWrapper.class);
38 public synchronized int saveService(AgentService agentService) throws Exception {
39 String consulRegisterurl =
40 (new StringBuilder().append("http://").append(ConfigUtil.getInstance().getConsulAddress())
41 .append(DiscoverUtil.CONSUL_AGENT_URL).append("/register")).toString();
45 HttpClientUtil.httpPutWithJSON(consulRegisterurl, JacksonJsonUtil.beanToJson(agentService));
47 return registerResult;
51 public synchronized int deleteService(String serviceId) throws Exception {
52 String consulDelurl = (new StringBuilder().append("http://").append(ConfigUtil.getInstance().getConsulAddress())
53 .append(DiscoverUtil.CONSUL_AGENT_URL).append("/deregister/").append(serviceId)).toString();
55 int delResult = HttpClientUtil.httpPutWithJSON(consulDelurl, "");