Search in sources :

Example 26 with Service

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

the class ConsulServerList method transformResponse.

/**
 * Transforms the response from Consul in to a list of usable {@link ConsulServer}s.
 *
 * @param healthServices the initial list of servers from Consul. Guaranteed to be non-empty list
 * @return ConsulServer instances
 * @see ConsulServer#ConsulServer(HealthService)
 */
protected List<ConsulServer> transformResponse(List<HealthService> healthServices) {
    List<ConsulServer> servers = new ArrayList<>();
    for (HealthService service : healthServices) {
        ConsulServer server = new ConsulServer(service);
        if (server.getMetadata().containsKey(this.properties.getDefaultZoneMetadataName())) {
            server.setZone(server.getMetadata().get(this.properties.getDefaultZoneMetadataName()));
        }
        servers.add(server);
    }
    return servers;
}
Also used : HealthService(com.ecwid.consul.v1.health.model.HealthService) ArrayList(java.util.ArrayList)

Example 27 with Service

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

the class ConsulAutoServiceRegistrationCustomizedAgentAddressTests method contextLoads.

@Test
public void contextLoads() {
    Response<Map<String, Service>> response = consul.getAgentServices();
    Map<String, Service> services = response.getValue();
    Service service = services.get("myTestService1-AA");
    assertNotNull("service was null", service);
    assertNotEquals("service port is 0", 0, service.getPort().intValue());
    assertEquals("service id was wrong", "myTestService1-AA", service.getId());
    assertEquals("service name was wrong", "myprefix-myTestService-AA", service.getService());
    assertTrue("service address must be empty", StringUtils.isEmpty(service.getAddress()));
}
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 28 with Service

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

Example 29 with Service

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

the class ConsulAutoServiceRegistrationCustomizedInstanceGroupTests method contextLoads.

@Test
public void contextLoads() {
    Response<Map<String, Service>> response = consul.getAgentServices();
    Map<String, Service> services = response.getValue();
    Service service = services.get("myTestService1-WithGroup");
    assertNotNull("service was null", service);
    assertNotEquals("service port is 0", 0, service.getPort().intValue());
    assertEquals("service id was wrong", "myTestService1-WithGroup", service.getId());
    assertTrue("service group was wrong", service.getTags().contains("group=test"));
    ConsulServerList serverList = new ConsulServerList(consul, properties);
    DefaultClientConfigImpl config = new DefaultClientConfigImpl();
    config.setClientName("myTestService-WithGroup");
    serverList.initWithNiwsConfig(config);
    List<ConsulServer> servers = serverList.getInitialListOfServers();
    assertEquals("servers was wrong size", 1, servers.size());
    assertEquals("service group was wrong", "test", servers.get(0).getMetaInfo().getServerGroup());
}
Also used : ConsulServerList(org.springframework.cloud.consul.discovery.ConsulServerList) Service(com.ecwid.consul.v1.agent.model.Service) Map(java.util.Map) DefaultClientConfigImpl(com.netflix.client.config.DefaultClientConfigImpl) ConsulServer(org.springframework.cloud.consul.discovery.ConsulServer) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 30 with Service

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

the class ConsulAutoServiceRegistrationCustomizedInstanceZoneTests method contextLoads.

@Test
public void contextLoads() {
    Response<Map<String, Service>> response = consul.getAgentServices();
    Map<String, Service> services = response.getValue();
    Service service = services.get("myTestService1-WithZone");
    assertNotNull("service was null", service);
    assertNotEquals("service port is 0", 0, service.getPort().intValue());
    assertEquals("service id was wrong", "myTestService1-WithZone", service.getId());
    assertTrue("service zone was wrong", service.getTags().contains("myZone=zone1"));
}
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)

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