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