Search in sources :

Example 11 with Service

use of com.ecwid.consul.v1.agent.model.Service 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 12 with Service

use of com.ecwid.consul.v1.agent.model.Service 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 13 with Service

use of com.ecwid.consul.v1.agent.model.Service in project spring-cloud-consul by spring-cloud.

the class ConsulAutoServiceRegistrationDisabledTests method contextLoads.

@Test
public void contextLoads() {
    assertNull("ConsulAutoServiceRegistration was created", autoServiceRegistration);
    Response<Map<String, Service>> response = consul.getAgentServices();
    Map<String, Service> services = response.getValue();
    Service service = services.get("myTestNotRegisteredService2");
    assertNull("service was registered", service);
}
Also used : Service(com.ecwid.consul.v1.agent.model.Service) Map(java.util.Map) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 14 with Service

use of com.ecwid.consul.v1.agent.model.Service in project spring-cloud-consul by spring-cloud.

the class ConsulDiscoveryClient method addInstancesToList.

private void addInstancesToList(List<ServiceInstance> instances, String serviceId, QueryParams queryParams) {
    String aclToken = properties.getAclToken();
    Response<List<HealthService>> services;
    if (StringUtils.hasText(aclToken)) {
        services = client.getHealthServices(serviceId, this.properties.getDefaultQueryTag(), this.properties.isQueryPassing(), queryParams, aclToken);
    } else {
        services = client.getHealthServices(serviceId, this.properties.getDefaultQueryTag(), this.properties.isQueryPassing(), queryParams);
    }
    for (HealthService service : services.getValue()) {
        String host = findHost(service);
        instances.add(new DefaultServiceInstance(serviceId, host, service.getService().getPort(), false, getMetadata(service)));
    }
}
Also used : DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) HealthService(com.ecwid.consul.v1.health.model.HealthService) ArrayList(java.util.ArrayList) List(java.util.List)

Example 15 with Service

use of com.ecwid.consul.v1.agent.model.Service 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

Test (org.junit.Test)18 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)18 Service (com.ecwid.consul.v1.agent.model.Service)14 Map (java.util.Map)14 NewService (com.ecwid.consul.v1.agent.model.NewService)10 Check (com.ecwid.consul.v1.health.model.Check)6 HealthService (com.ecwid.consul.v1.health.model.HealthService)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 QueryParams (com.ecwid.consul.v1.QueryParams)3 CatalogService (com.ecwid.consul.v1.catalog.model.CatalogService)2 ConsulService (com.weibo.api.motan.registry.consul.ConsulService)2 JSONObject (com.alibaba.fastjson.JSONObject)1 ConsulClient (com.ecwid.consul.v1.ConsulClient)1 Service (com.ecwid.consul.v1.health.model.HealthService.Service)1 DefaultClientConfigImpl (com.netflix.client.config.DefaultClientConfigImpl)1 DefaultServiceInstance (org.springframework.cloud.client.DefaultServiceInstance)1 ConsulServer (org.springframework.cloud.consul.discovery.ConsulServer)1 ConsulServerList (org.springframework.cloud.consul.discovery.ConsulServerList)1