use of org.springframework.cloud.client.ServiceInstance in project RestyPass by darren-fu.
the class CloudConsulServerContext method getServiceInstances.
@Override
protected List<ServerInstance> getServiceInstances(String serviceName) {
List<ServiceInstance> instances = new ArrayList<>();
Response<List<HealthService>> healthServices = consulClient.getHealthServices(serviceName, true, QueryParams.DEFAULT);
for (HealthService healthService : healthServices.getValue()) {
if (isPassingChecks(healthService)) {
String host = findHost(healthService);
instances.add(new DefaultServiceInstance(serviceName, host, healthService.getService().getPort(), false, getMetadata(healthService)));
}
}
return convertToServerInstanceList(instances);
}
use of org.springframework.cloud.client.ServiceInstance in project spring-boot-admin by codecentric.
the class KubernetesServiceInstanceConverterTest method convert_using_port_mgmt.
@Test
public void convert_using_port_mgmt() {
ServiceInstance service = mock(ServiceInstance.class);
when(service.getUri()).thenReturn(URI.create("http://localhost:80"));
when(service.getServiceId()).thenReturn("test");
when(service.getMetadata()).thenReturn(Collections.singletonMap("port.management", "9080"));
Registration registration = new KubernetesServiceInstanceConverter().convert(service);
assertThat(registration.getManagementUrl()).isEqualTo("http://localhost:9080/actuator");
assertThat(registration.getHealthUrl()).isEqualTo("http://localhost:9080/actuator/health");
}
use of org.springframework.cloud.client.ServiceInstance in project spring-boot-admin by codecentric.
the class DefaultServiceInstanceConverterTest method should_convert_with_metadata_having_null_value.
@Test
public void should_convert_with_metadata_having_null_value() {
ServiceInstance service = new DefaultServiceInstance("test-1", "test", "localhost", 80, false);
Map<String, String> metadata = new HashMap<>();
metadata.put("health.path", "ping");
metadata.put("management.scheme", "https");
metadata.put("management.address", "127.0.0.1");
metadata.put("management.port", "1234");
metadata.put("null.value", null);
metadata.put(null, "null.key");
service.getMetadata().putAll(metadata);
Registration registration = new DefaultServiceInstanceConverter().convert(service);
assertThat(registration.getHealthUrl()).isEqualTo("https://127.0.0.1:1234/actuator/ping");
}
use of org.springframework.cloud.client.ServiceInstance in project spring-boot-admin by codecentric.
the class DefaultServiceInstanceConverterTest method should_convert_service_with_uri_and_metadata.
@Test
public void should_convert_service_with_uri_and_metadata() {
Map<String, String> metadata = new HashMap<>();
metadata.put("health.path", "ping");
metadata.put("management.context-path", "mgmt");
ServiceInstance service = new TestServiceInstance("test", URI.create("http://localhost/test"), metadata);
Registration registration = new DefaultServiceInstanceConverter().convert(service);
assertThat(registration.getName()).isEqualTo("test");
assertThat(registration.getServiceUrl()).isEqualTo("http://localhost/test");
assertThat(registration.getManagementUrl()).isEqualTo("http://localhost/test/mgmt");
assertThat(registration.getHealthUrl()).isEqualTo("http://localhost/test/mgmt/ping");
assertThat(registration.getMetadata()).isEqualTo(metadata);
}
use of org.springframework.cloud.client.ServiceInstance in project spring-boot-admin by codecentric.
the class DefaultServiceInstanceConverterTest method should_convert_with_metadata.
@Test
public void should_convert_with_metadata() {
ServiceInstance service = new DefaultServiceInstance("test-1", "test", "localhost", 80, false);
Map<String, String> metadata = new HashMap<>();
metadata.put("health.path", "ping");
metadata.put("management.scheme", "https");
metadata.put("management.address", "127.0.0.1");
metadata.put("management.port", "1234");
metadata.put("management.context-path", "mgmt");
service.getMetadata().putAll(metadata);
Registration registration = new DefaultServiceInstanceConverter().convert(service);
assertThat(registration.getName()).isEqualTo("test");
assertThat(registration.getServiceUrl()).isEqualTo("http://localhost:80");
assertThat(registration.getManagementUrl()).isEqualTo("https://127.0.0.1:1234/mgmt");
assertThat(registration.getHealthUrl()).isEqualTo("https://127.0.0.1:1234/mgmt/ping");
assertThat(registration.getMetadata()).isEqualTo(metadata);
}
Aggregations