Search in sources :

Example 36 with ServiceInstance

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);
}
Also used : DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) HealthService(com.ecwid.consul.v1.health.model.HealthService) DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) ServiceInstance(org.springframework.cloud.client.ServiceInstance)

Example 37 with ServiceInstance

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");
}
Also used : Registration(de.codecentric.boot.admin.server.domain.values.Registration) ServiceInstance(org.springframework.cloud.client.ServiceInstance) Test(org.junit.jupiter.api.Test)

Example 38 with ServiceInstance

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");
}
Also used : DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) HashMap(java.util.HashMap) Registration(de.codecentric.boot.admin.server.domain.values.Registration) DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) ServiceInstance(org.springframework.cloud.client.ServiceInstance) Test(org.junit.jupiter.api.Test)

Example 39 with ServiceInstance

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);
}
Also used : HashMap(java.util.HashMap) Registration(de.codecentric.boot.admin.server.domain.values.Registration) DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) ServiceInstance(org.springframework.cloud.client.ServiceInstance) Test(org.junit.jupiter.api.Test)

Example 40 with ServiceInstance

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);
}
Also used : DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) HashMap(java.util.HashMap) Registration(de.codecentric.boot.admin.server.domain.values.Registration) DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) ServiceInstance(org.springframework.cloud.client.ServiceInstance) Test(org.junit.jupiter.api.Test)

Aggregations

ServiceInstance (org.springframework.cloud.client.ServiceInstance)73 DefaultServiceInstance (org.springframework.cloud.client.DefaultServiceInstance)25 Test (org.junit.Test)24 HashMap (java.util.HashMap)12 URI (java.net.URI)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 Registration (de.codecentric.boot.admin.server.domain.values.Registration)10 ArrayList (java.util.ArrayList)10 Test (org.junit.jupiter.api.Test)10 Application (de.codecentric.boot.admin.model.Application)7 Map (java.util.Map)7 List (java.util.List)6 RibbonServer (org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.RibbonServer)6 IClientConfig (com.netflix.client.config.IClientConfig)5 Random (java.util.Random)4 Collections (java.util.Collections)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 MonitorProperties (com.alibaba.druid.admin.config.MonitorProperties)2 ServiceNode (com.alibaba.druid.admin.model.ServiceNode)2 ConnectionResult (com.alibaba.druid.admin.model.dto.ConnectionResult)2