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;
}
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());
}
Aggregations