Search in sources :

Example 6 with Check

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);
}
Also used : HealthService(com.ecwid.consul.v1.health.model.HealthService) Check(com.ecwid.consul.v1.health.model.Check) ArrayList(java.util.ArrayList) HealthService(com.ecwid.consul.v1.health.model.HealthService)

Example 7 with Check

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;
}
Also used : NewService(com.ecwid.consul.v1.agent.model.NewService)

Example 8 with Check

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();
}
Also used : Check(com.ecwid.consul.v1.health.model.Check) List(java.util.List)

Example 9 with Check

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;
}
Also used : Server(com.netflix.loadbalancer.Server) ArrayList(java.util.ArrayList) Check(com.ecwid.consul.v1.health.model.Check)

Example 10 with Check

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
}
Also used : NewService(com.ecwid.consul.v1.agent.model.NewService) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Check (com.ecwid.consul.v1.health.model.Check)7 Test (org.junit.Test)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 NewService (com.ecwid.consul.v1.agent.model.NewService)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2 JSONObject (com.alibaba.fastjson.JSONObject)1 QueryParams (com.ecwid.consul.v1.QueryParams)1 Service (com.ecwid.consul.v1.agent.model.Service)1 HealthService (com.ecwid.consul.v1.health.model.HealthService)1 Server (com.netflix.loadbalancer.Server)1 Map (java.util.Map)1