Search in sources :

Example 46 with ServiceInstance

use of org.springframework.cloud.client.ServiceInstance in project topcom-cloud by 545314690.

the class HelloController method index.

@RequestMapping(value = "/hello")
public String index() {
    ServiceInstance instance = client.getLocalServiceInstance();
    logger.info("/hello:" + instance.getHost() + ",service_id: " + instance.getServiceId());
    return "hello world";
}
Also used : ServiceInstance(org.springframework.cloud.client.ServiceInstance) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 47 with ServiceInstance

use of org.springframework.cloud.client.ServiceInstance 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)

Example 48 with ServiceInstance

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

the class ApplicationDiscoveryListenerTest method test_matching_pattern.

@Test
public void test_matching_pattern() {
    when(discovery.getServices()).thenReturn(asList("service", "rabbit-1", "rabbit-2"));
    when(discovery.getInstances("service")).thenReturn(Collections.singletonList((ServiceInstance) new DefaultServiceInstance("service", "localhost", 80, false)));
    listener.setServices(singleton("ser*"));
    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)

Example 49 with ServiceInstance

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

the class ApplicationDiscoveryListenerTest method test_matching.

@Test
public void test_matching() {
    when(discovery.getServices()).thenReturn(Collections.singletonList("service"));
    when(discovery.getInstances("service")).thenReturn(Collections.singletonList((ServiceInstance) new DefaultServiceInstance("service", "localhost", 80, false)));
    listener.setServices(singleton("notService"));
    listener.onInstanceRegistered(new InstanceRegisteredEvent<>(new Object(), null));
    assertEquals(0, registry.getApplications().size());
}
Also used : DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) ServiceInstance(org.springframework.cloud.client.ServiceInstance) Test(org.junit.Test)

Example 50 with ServiceInstance

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

the class DefaultServiceInstanceConverterTest method test_convert_with_metadata.

@Test
public void test_convert_with_metadata() {
    ServiceInstance service = new DefaultServiceInstance("test", "localhost", 80, false);
    Map<String, String> metadata = new HashMap<>();
    metadata.put("health.path", "ping");
    metadata.put("management.context-path", "mgmt");
    metadata.put("management.port", "1234");
    service.getMetadata().putAll(metadata);
    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:1234/mgmt"));
    assertThat(application.getHealthUrl(), is("http://localhost:1234/mgmt/ping"));
    assertThat(application.getMetadata(), is(metadata));
}
Also used : DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) HashMap(java.util.HashMap) DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) ServiceInstance(org.springframework.cloud.client.ServiceInstance) Application(de.codecentric.boot.admin.model.Application) Test(org.junit.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