remove dependency on s-c-config-client.
bump version to 1.0.0.BUILD-SNAPSHOT. form java files
This commit is contained in:
@@ -16,12 +16,13 @@
|
||||
|
||||
package org.springframework.cloud.consul;
|
||||
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@@ -29,27 +30,28 @@ import org.springframework.context.annotation.Configuration;
|
||||
@EnableConfigurationProperties
|
||||
public class ConsulAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ConsulProperties consulProperties() {
|
||||
return new ConsulProperties();
|
||||
}
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ConsulProperties consulProperties() {
|
||||
return new ConsulProperties();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ConsulClient consulClient() {
|
||||
return new ConsulClient(consulProperties().getHost(), consulProperties().getPort());
|
||||
}
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ConsulClient consulClient() {
|
||||
return new ConsulClient(consulProperties().getHost(), consulProperties()
|
||||
.getPort());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ConsulEndpoint consulEndpoint() {
|
||||
return new ConsulEndpoint();
|
||||
}
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ConsulEndpoint consulEndpoint() {
|
||||
return new ConsulEndpoint();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ConsulHealthIndicator consulHealthIndicator() {
|
||||
return new ConsulHealthIndicator();
|
||||
}
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ConsulHealthIndicator consulHealthIndicator() {
|
||||
return new ConsulHealthIndicator();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,20 +16,22 @@
|
||||
|
||||
package org.springframework.cloud.consul;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.endpoint.AbstractEndpoint;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
import com.ecwid.consul.v1.QueryParams;
|
||||
import com.ecwid.consul.v1.Response;
|
||||
import com.ecwid.consul.v1.agent.model.Service;
|
||||
import com.ecwid.consul.v1.catalog.model.CatalogService;
|
||||
import com.ecwid.consul.v1.catalog.model.Node;
|
||||
import lombok.Data;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.endpoint.AbstractEndpoint;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
@@ -37,43 +39,44 @@ import java.util.Map;
|
||||
@ConfigurationProperties(prefix = "endpoints.consul", ignoreUnknownFields = false)
|
||||
public class ConsulEndpoint extends AbstractEndpoint<ConsulEndpoint.ConsulData> {
|
||||
|
||||
@Autowired
|
||||
private ConsulClient consul;
|
||||
@Autowired
|
||||
private ConsulClient consul;
|
||||
|
||||
@Autowired
|
||||
public ConsulEndpoint() {
|
||||
super("consul", false, true);
|
||||
}
|
||||
@Autowired
|
||||
public ConsulEndpoint() {
|
||||
super("consul", false, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConsulData invoke() {
|
||||
ConsulData data = new ConsulData();
|
||||
//data.setKeyValues(kvClient.getKeyValueRecurse());
|
||||
Response<Map<String, Service>> agentServices = consul.getAgentServices();
|
||||
data.setAgentServices(agentServices.getValue());
|
||||
@Override
|
||||
public ConsulData invoke() {
|
||||
ConsulData data = new ConsulData();
|
||||
// data.setKeyValues(kvClient.getKeyValueRecurse());
|
||||
Response<Map<String, Service>> agentServices = consul.getAgentServices();
|
||||
data.setAgentServices(agentServices.getValue());
|
||||
|
||||
Response<Map<String, List<String>>> catalogServices = consul.getCatalogServices(QueryParams.DEFAULT);
|
||||
Response<Map<String, List<String>>> catalogServices = consul
|
||||
.getCatalogServices(QueryParams.DEFAULT);
|
||||
|
||||
for (String serviceId : catalogServices.getValue().keySet()) {
|
||||
Response<List<CatalogService>> response = consul.getCatalogService(serviceId,
|
||||
QueryParams.DEFAULT);
|
||||
data.getCatalogServices().put(serviceId, response.getValue());
|
||||
}
|
||||
|
||||
for (String serviceId : catalogServices.getValue().keySet()) {
|
||||
Response<List<CatalogService>> response = consul.getCatalogService(serviceId, QueryParams.DEFAULT);
|
||||
data.getCatalogServices().put(serviceId, response.getValue());
|
||||
}
|
||||
Response<List<Node>> catalogNodes = consul.getCatalogNodes(QueryParams.DEFAULT);
|
||||
data.setCatalogNodes(catalogNodes.getValue());
|
||||
|
||||
Response<List<Node>> catalogNodes = consul.getCatalogNodes(QueryParams.DEFAULT);
|
||||
data.setCatalogNodes(catalogNodes.getValue());
|
||||
return data;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
@Data
|
||||
public static class ConsulData {
|
||||
Map<String, List<CatalogService>> catalogServices = new LinkedHashMap<>();
|
||||
|
||||
@Data
|
||||
public static class ConsulData {
|
||||
Map<String, List<CatalogService>> catalogServices = new LinkedHashMap<>();
|
||||
Map<String, Service> agentServices;
|
||||
|
||||
Map<String, Service> agentServices;
|
||||
List<Node> catalogNodes;
|
||||
|
||||
List<Node> catalogNodes;
|
||||
|
||||
//List<KeyValue> keyValues;
|
||||
}
|
||||
// List<KeyValue> keyValues;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,35 +16,37 @@
|
||||
|
||||
package org.springframework.cloud.consul;
|
||||
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
import com.ecwid.consul.v1.QueryParams;
|
||||
import com.ecwid.consul.v1.Response;
|
||||
import com.ecwid.consul.v1.agent.model.Self;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
|
||||
import org.springframework.boot.actuate.health.Health;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
import com.ecwid.consul.v1.QueryParams;
|
||||
import com.ecwid.consul.v1.Response;
|
||||
import com.ecwid.consul.v1.agent.model.Self;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
public class ConsulHealthIndicator extends AbstractHealthIndicator {
|
||||
|
||||
@Autowired
|
||||
private ConsulClient consul;
|
||||
@Autowired
|
||||
private ConsulClient consul;
|
||||
|
||||
@Override
|
||||
protected void doHealthCheck(Health.Builder builder) throws Exception {
|
||||
try {
|
||||
Response<Self> self = consul.getAgentSelf();
|
||||
Response<Map<String, List<String>>> services = consul.getCatalogServices(QueryParams.DEFAULT);
|
||||
builder.up()
|
||||
.withDetail("services", services.getValue())
|
||||
.withDetail("agent", self.getValue());
|
||||
} catch (Exception e) {
|
||||
builder.down(e);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void doHealthCheck(Health.Builder builder) throws Exception {
|
||||
try {
|
||||
Response<Self> self = consul.getAgentSelf();
|
||||
Response<Map<String, List<String>>> services = consul
|
||||
.getCatalogServices(QueryParams.DEFAULT);
|
||||
builder.up().withDetail("services", services.getValue())
|
||||
.withDetail("agent", self.getValue());
|
||||
}
|
||||
catch (Exception e) {
|
||||
builder.down(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,31 +16,33 @@
|
||||
|
||||
package org.springframework.cloud.consul;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@ConfigurationProperties("consul")
|
||||
@Data
|
||||
public class ConsulProperties {
|
||||
@NotNull
|
||||
private String host = "localhost";
|
||||
@NotNull
|
||||
private String host = "localhost";
|
||||
|
||||
@NotNull
|
||||
private int port = 8500;
|
||||
@NotNull
|
||||
private int port = 8500;
|
||||
|
||||
private List<String> tags = new ArrayList<>();
|
||||
private List<String> tags = new ArrayList<>();
|
||||
|
||||
private boolean enabled = true;
|
||||
private boolean enabled = true;
|
||||
|
||||
private String prefix = "config";
|
||||
private String prefix = "config";
|
||||
|
||||
private List<String> managementTags = Arrays.asList("management");
|
||||
private List<String> managementTags = Arrays.asList("management");
|
||||
}
|
||||
|
||||
@@ -17,22 +17,18 @@
|
||||
package org.springframework.cloud.consul.model;
|
||||
|
||||
/**
|
||||
* Gossip pool (serf) statuses.
|
||||
* Created by nicu on 10.03.2015.
|
||||
* Gossip pool (serf) statuses. Created by nicu on 10.03.2015.
|
||||
*/
|
||||
public enum SerfStatusEnum {
|
||||
StatusAlive(1),
|
||||
StatusLeaving(2),
|
||||
StatusLeft(3),
|
||||
StatusFailed(4);
|
||||
private final int code;
|
||||
StatusAlive(1), StatusLeaving(2), StatusLeft(3), StatusFailed(4);
|
||||
private final int code;
|
||||
|
||||
SerfStatusEnum(int code) {
|
||||
this.code=code;
|
||||
}
|
||||
SerfStatusEnum(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user