use of com.ecwid.consul.v1.health.model.Check in project spring-cloud-consul by spring-cloud.
the class HealthServiceServerListFilterTests method newServer.
private ConsulServer newServer(Check.CheckStatus checkStatus) {
HealthService healthService = new HealthService();
HealthService.Node node = new HealthService.Node();
node.setAddress("nodeaddr" + checkStatus.name());
node.setNode("nodenode" + checkStatus.name());
healthService.setNode(node);
HealthService.Service service = new HealthService.Service();
service.setAddress("serviceaddr" + checkStatus.name());
service.setId("serviceid" + checkStatus.name());
service.setPort(8080);
service.setService("serviceservice" + checkStatus.name());
healthService.setService(service);
ArrayList<Check> checks = new ArrayList<>();
Check check = new Check();
check.setStatus(checkStatus);
checks.add(check);
healthService.setChecks(checks);
return new ConsulServer(healthService);
}
use of com.ecwid.consul.v1.health.model.Check in project motan by weibocom.
the class ConsulEcwidClient method convertService.
private NewService convertService(ConsulService service) {
NewService newService = new NewService();
newService.setAddress(service.getAddress());
newService.setId(service.getId());
newService.setName(service.getName());
newService.setPort(service.getPort());
newService.setTags(service.getTags());
NewService.Check check = new NewService.Check();
check.setTtl(service.getTtl() + "s");
newService.setCheck(check);
return newService;
}
use of com.ecwid.consul.v1.health.model.Check in project spring-cloud-consul by spring-cloud.
the class ConsulServiceRegistry method getStatus.
@Override
public Object getStatus(ConsulRegistration registration) {
String serviceId = registration.getServiceId();
Response<List<Check>> response = client.getHealthChecksForService(serviceId, QueryParams.DEFAULT);
List<Check> checks = response.getValue();
for (Check check : checks) {
if (check.getServiceId().equals(registration.getInstanceId())) {
if (check.getName().equalsIgnoreCase("Service Maintenance Mode")) {
return OUT_OF_SERVICE.getCode();
}
}
}
return UP.getCode();
}
use of com.ecwid.consul.v1.health.model.Check in project spring-cloud-consul by spring-cloud.
the class ServiceCheckServerListFilter method getFilteredListOfServers.
@Override
public List<Server> getFilteredListOfServers(List<Server> servers) {
List<Server> okServers = new ArrayList<>(servers.size());
for (Server server : servers) {
String appName = server.getMetaInfo().getAppName();
String instanceId = server.getMetaInfo().getInstanceId();
// TODO: cache getHealthChecks? this is hit often
List<Check> serviceChecks = client.getHealthChecksForService(appName, QueryParams.DEFAULT).getValue();
boolean serviceOk = true;
for (Check check : serviceChecks) {
if (check.getServiceId().equals(instanceId) && check.getStatus() != Check.CheckStatus.PASSING) {
serviceOk = false;
// just need one to fail
break;
}
}
if (serviceOk) {
okServers.add(server);
}
}
return okServers;
}
use of com.ecwid.consul.v1.health.model.Check in project spring-cloud-consul by spring-cloud.
the class ConsulAutoServiceRegistrationCustomizedDiscoveryPortTests method contextLoads.
@Test
public void contextLoads() {
NewService service = this.registration.getService();
assertThat(service).as("service was null").isNotNull();
assertThat(service.getPort()).as("service port is 0").isGreaterThan(0);
NewService.Check check = service.getCheck();
assertThat(check).as("check was null").isNotNull();
String httpCheck = String.format("%s://%s:%s%s", properties.getScheme(), properties.getHostname(), properties.getPort(), properties.getHealthCheckPath());
assertThat(check.getHttp()).as("http check was wrong").isEqualTo(httpCheck);
// unable to call consul api to get health check details
}
Aggregations