Search in sources :

Example 1 with Check

use of com.ecwid.consul.v1.health.model.Check in project motan by weibocom.

the class ConsulRegistryService method getNodes.

@Override
public List<JSONObject> getNodes(String dcGroup, String service, String nodeType) {
    List<JSONObject> results = new ArrayList<JSONObject>();
    List<Check> checks = consulClient.getHealthChecksForService(getGroupName(dcGroup), new QueryParams(getDcName(dcGroup))).getValue();
    for (Check check : checks) {
        String serviceId = check.getServiceId();
        String[] strings = serviceId.split("-");
        if (strings[1].equals(service)) {
            Check.CheckStatus status = check.getStatus();
            JSONObject node = new JSONObject();
            if (nodeType.equals(status.toString())) {
                node.put("host", strings[0]);
                node.put("info", null);
                results.add(node);
            }
        }
    }
    return results;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) Check(com.ecwid.consul.v1.health.model.Check) QueryParams(com.ecwid.consul.v1.QueryParams)

Example 2 with Check

use of com.ecwid.consul.v1.health.model.Check in project spring-cloud-consul by spring-cloud.

the class ConsulAutoServiceRegistrationCustomizedPropsTests method contextLoads.

@Test
public void contextLoads() {
    Response<Map<String, Service>> response = consul.getAgentServices();
    Map<String, Service> services = response.getValue();
    Service service = services.get("myTestService1-B");
    assertThat("service was null", service, is(notNullValue()));
    assertThat("service port is discovery port", service.getPort(), equalTo(4452));
    assertThat("service id was wrong", "myTestService1-B", equalTo(service.getId()));
    assertThat("service name was wrong", "myTestService-B", equalTo(service.getService()));
    assertThat("property hostname was wrong", "myhost", equalTo(this.properties.getHostname()));
    assertThat("property ipAddress was wrong", "10.0.0.1", equalTo(this.properties.getIpAddress()));
    assertThat("service address was wrong", "myhost", equalTo(service.getAddress()));
    Response<List<Check>> checkResponse = consul.getHealthChecksForService("myTestService-B", QueryParams.DEFAULT);
    List<Check> checks = checkResponse.getValue();
    assertThat("checks was wrong size", checks, hasSize(0));
}
Also used : Check(com.ecwid.consul.v1.health.model.Check) Service(com.ecwid.consul.v1.agent.model.Service) List(java.util.List) Map(java.util.Map) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with Check

use of com.ecwid.consul.v1.health.model.Check in project spring-cloud-consul by spring-cloud.

the class ConsulAutoRegistrationHealthCheckTlsSkipVerifyTests method contextLoads.

@Test
public void contextLoads() {
    NewService service = this.registration.getService();
    assertThat(service).as("service was null").isNotNull();
    NewService.Check check = service.getCheck();
    assertThat(check).as("check was null").isNotNull();
    assertThat(check.getTlsSkipVerify()).as("tls_skip_verify was wrong").isEqualTo(Boolean.TRUE);
// 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)

Example 4 with Check

use of com.ecwid.consul.v1.health.model.Check in project spring-cloud-consul by spring-cloud.

the class TtlSchedulerRemoveTests method should_not_send_check_if_service_removed.

@Test
public void should_not_send_check_if_service_removed() throws InterruptedException {
    // wait for Ttlscheduler to send a check to consul.
    Thread.sleep(1000);
    Check serviceCheck = getCheckForService("ttlSchedulerRemove");
    assertThat("Service check is in wrong state", serviceCheck.getStatus(), equalTo(PASSING));
    // Remove service from TtlScheduler and wait for TTL to expired.
    ttlScheduler.remove("ttlSchedulerRemove-id");
    Thread.sleep(2100);
    serviceCheck = getCheckForService("ttlSchedulerRemove");
    assertThat("Service check is in wrong state", serviceCheck.getStatus(), equalTo(CRITICAL));
}
Also used : Check(com.ecwid.consul.v1.health.model.Check) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with Check

use of com.ecwid.consul.v1.health.model.Check in project spring-cloud-consul by spring-cloud.

the class ConsulAutoRegistration method registration.

public static ConsulAutoRegistration registration(AutoServiceRegistrationProperties autoServiceRegistrationProperties, ConsulDiscoveryProperties properties, ApplicationContext context, List<ConsulRegistrationCustomizer> registrationCustomizers, HeartbeatProperties heartbeatProperties) {
    NewService service = new NewService();
    String appName = getAppName(properties, context.getEnvironment());
    service.setId(getInstanceId(properties, context));
    if (!properties.isPreferAgentAddress()) {
        service.setAddress(properties.getHostname());
    }
    service.setName(normalizeForDns(appName));
    service.setTags(createTags(properties));
    if (properties.getPort() != null) {
        service.setPort(properties.getPort());
        // we know the port and can set the check
        setCheck(service, autoServiceRegistrationProperties, properties, context, heartbeatProperties);
    }
    ConsulAutoRegistration registration = new ConsulAutoRegistration(service, autoServiceRegistrationProperties, properties, context, heartbeatProperties);
    customize(registrationCustomizers, registration);
    return registration;
}
Also used : NewService(com.ecwid.consul.v1.agent.model.NewService)

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