Search in sources :

Example 1 with ConsulServer

use of org.springframework.cloud.consul.discovery.ConsulServer in project spring-cloud-consul by spring-cloud.

the class AliveServerListFilter method getFilteredListOfServers.

@Override
public List<Server> getFilteredListOfServers(List<Server> servers) {
    Set<String> liveNodes = filteringAgentClient.getAliveAgentsAddresses();
    List<Server> filteredServers = new ArrayList<>();
    for (Server server : servers) {
        ConsulServer consulServer = ConsulServer.class.cast(server);
        if (liveNodes.contains(consulServer.getHealthService().getService().getAddress())) {
            filteredServers.add(server);
        }
    }
    return filteredServers;
}
Also used : ConsulServer(org.springframework.cloud.consul.discovery.ConsulServer) Server(com.netflix.loadbalancer.Server) ArrayList(java.util.ArrayList) ConsulServer(org.springframework.cloud.consul.discovery.ConsulServer)

Example 2 with ConsulServer

use of org.springframework.cloud.consul.discovery.ConsulServer 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)

Aggregations

ConsulServer (org.springframework.cloud.consul.discovery.ConsulServer)2 Service (com.ecwid.consul.v1.agent.model.Service)1 DefaultClientConfigImpl (com.netflix.client.config.DefaultClientConfigImpl)1 Server (com.netflix.loadbalancer.Server)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 ConsulServerList (org.springframework.cloud.consul.discovery.ConsulServerList)1