Search in sources :

Example 6 with DefaultServiceInstance

use of org.springframework.cloud.client.DefaultServiceInstance in project spring-boot-admin by codecentric.

the class DefaultServiceInstanceConverterTest method test_convert_with_custom_defaults.

@Test
public void test_convert_with_custom_defaults() {
    DefaultServiceInstanceConverter converter = new DefaultServiceInstanceConverter();
    converter.setHealthEndpointPath("ping");
    converter.setManagementContextPath("mgmt");
    ServiceInstance service = new DefaultServiceInstance("test", "localhost", 80, false);
    Application application = converter.convert(service);
    assertThat(application.getId(), nullValue());
    assertThat(application.getName(), is("test"));
    assertThat(application.getServiceUrl(), is("http://localhost:80"));
    assertThat(application.getManagementUrl(), is("http://localhost:80/mgmt"));
    assertThat(application.getHealthUrl(), is("http://localhost:80/mgmt/ping"));
}
Also used : DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) ServiceInstance(org.springframework.cloud.client.ServiceInstance) Application(de.codecentric.boot.admin.model.Application) Test(org.junit.Test)

Example 7 with DefaultServiceInstance

use of org.springframework.cloud.client.DefaultServiceInstance in project spring-boot-admin by codecentric.

the class DefaultServiceInstanceConverterTest method test_convert_with_defaults.

@Test
public void test_convert_with_defaults() {
    ServiceInstance service = new DefaultServiceInstance("test", "localhost", 80, false);
    Application application = new DefaultServiceInstanceConverter().convert(service);
    assertThat(application.getId(), nullValue());
    assertThat(application.getName(), is("test"));
    assertThat(application.getServiceUrl(), is("http://localhost:80"));
    assertThat(application.getManagementUrl(), is("http://localhost:80"));
    assertThat(application.getHealthUrl(), is("http://localhost:80/health"));
}
Also used : DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) ServiceInstance(org.springframework.cloud.client.ServiceInstance) Application(de.codecentric.boot.admin.model.Application) Test(org.junit.Test)

Example 8 with DefaultServiceInstance

use of org.springframework.cloud.client.DefaultServiceInstance in project spring-boot-admin by codecentric.

the class TurbineRouteLocatorTest method test_route_service_location.

@Test
public void test_route_service_location() {
    ZuulRoute route = new ZuulRoute("/path/**", "turbine");
    DiscoveryClient discovery = mock(DiscoveryClient.class);
    when(discovery.getInstances("turbine")).thenReturn(Arrays.<ServiceInstance>asList(new DefaultServiceInstance("turbine", "example.com", 80, false)));
    TurbineRouteLocator locator = new TurbineRouteLocator(route, "", new ZuulProperties(), discovery);
    Route matchingRoute = locator.getMatchingRoute("/path/foo");
    assertThat(matchingRoute.getLocation(), is("http://example.com:80"));
    assertThat(matchingRoute.getPath(), is("/foo/turbine.stream"));
}
Also used : DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) ZuulRoute(org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute) ZuulProperties(org.springframework.cloud.netflix.zuul.filters.ZuulProperties) DiscoveryClient(org.springframework.cloud.client.discovery.DiscoveryClient) NoopDiscoveryClient(org.springframework.cloud.client.discovery.noop.NoopDiscoveryClient) Route(org.springframework.cloud.netflix.zuul.filters.Route) ZuulRoute(org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute) Test(org.junit.Test)

Example 9 with DefaultServiceInstance

use of org.springframework.cloud.client.DefaultServiceInstance in project java-chassis by ServiceComb.

the class CseDiscoveryClient method getInstances.

@Override
public List<ServiceInstance> getInstances(final String serviceId) {
    List<ServiceInstance> instances = new ArrayList<ServiceInstance>();
    ServiceRegistryClient client = RegistryClientFactory.getRegistryClient();
    String appId = DynamicPropertyFactory.getInstance().getStringProperty("APPLICATION_ID", "default").get();
    ReferenceConfig referenceConfig = consumerProviderManager.getReferenceConfig(serviceId);
    String versionRule = referenceConfig.getMicroserviceVersionRule();
    String cseServiceID = client.getMicroserviceId(appId, serviceId, versionRule);
    List<MicroserviceInstance> cseServices = client.getMicroserviceInstance(cseServiceID, cseServiceID);
    if (null != cseServices && !cseServices.isEmpty()) {
        for (MicroserviceInstance instance : cseServices) {
            List<String> eps = instance.getEndpoints();
            for (String ep : eps) {
                URIEndpointObject uri = new URIEndpointObject(ep);
                instances.add(new DefaultServiceInstance(instance.getServiceId(), uri.getHostOrIp(), uri.getPort(), false));
            }
        }
    }
    return instances;
}
Also used : DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) ArrayList(java.util.ArrayList) DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) ServiceInstance(org.springframework.cloud.client.ServiceInstance) MicroserviceInstance(io.servicecomb.serviceregistry.api.registry.MicroserviceInstance) ServiceRegistryClient(io.servicecomb.serviceregistry.client.ServiceRegistryClient) URIEndpointObject(io.servicecomb.foundation.common.net.URIEndpointObject)

Example 10 with DefaultServiceInstance

use of org.springframework.cloud.client.DefaultServiceInstance in project spring-boot-admin by codecentric.

the class ApplicationDiscoveryListenerTest method test_matching_and_ignore_pattern.

@Test
public void test_matching_and_ignore_pattern() {
    when(discovery.getServices()).thenReturn(asList("service-1", "service", "rabbit-1", "rabbit-2"));
    when(discovery.getInstances("service")).thenReturn(Collections.singletonList((ServiceInstance) new DefaultServiceInstance("service", "localhost", 80, false)));
    when(discovery.getInstances("service-1")).thenReturn(Collections.singletonList((ServiceInstance) new DefaultServiceInstance("service-1", "localhost", 80, false)));
    listener.setServices(singleton("ser*"));
    listener.setIgnoredServices(singleton("service-*"));
    listener.onInstanceRegistered(new InstanceRegisteredEvent<>(new Object(), null));
    Collection<Application> applications = registry.getApplications();
    assertEquals(1, applications.size());
    assertEquals("service", applications.iterator().next().getName());
}
Also used : DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) ServiceInstance(org.springframework.cloud.client.ServiceInstance) Application(de.codecentric.boot.admin.model.Application) Test(org.junit.Test)

Aggregations

DefaultServiceInstance (org.springframework.cloud.client.DefaultServiceInstance)13 Test (org.junit.Test)12 ServiceInstance (org.springframework.cloud.client.ServiceInstance)12 Application (de.codecentric.boot.admin.model.Application)7 ArrayList (java.util.ArrayList)2 HeartbeatEvent (org.springframework.cloud.client.discovery.event.HeartbeatEvent)2 ParentHeartbeatEvent (org.springframework.cloud.client.discovery.event.ParentHeartbeatEvent)2 URIEndpointObject (io.servicecomb.foundation.common.net.URIEndpointObject)1 MicroserviceInstance (io.servicecomb.serviceregistry.api.registry.MicroserviceInstance)1 ServiceRegistryClient (io.servicecomb.serviceregistry.client.ServiceRegistryClient)1 HashMap (java.util.HashMap)1 DiscoveryClient (org.springframework.cloud.client.discovery.DiscoveryClient)1 NoopDiscoveryClient (org.springframework.cloud.client.discovery.noop.NoopDiscoveryClient)1 Route (org.springframework.cloud.netflix.zuul.filters.Route)1 ZuulProperties (org.springframework.cloud.netflix.zuul.filters.ZuulProperties)1 ZuulRoute (org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute)1