Search in sources :

Example 31 with Application

use of de.codecentric.boot.admin.model.Application in project spring-boot-admin by codecentric.

the class ApplicationRegistryTest method getApplication.

@Test
public void getApplication() throws Exception {
    Application app = registry.register(Application.create("abc").withHealthUrl("http://localhost/health").withManagementUrl("http://localhost:8080/").build());
    assertEquals(app, registry.getApplication(app.getId()));
    assertEquals("http://localhost:8080/", app.getManagementUrl());
}
Also used : Application(de.codecentric.boot.admin.model.Application) Test(org.junit.Test)

Example 32 with Application

use of de.codecentric.boot.admin.model.Application 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 33 with Application

use of de.codecentric.boot.admin.model.Application 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 34 with Application

use of de.codecentric.boot.admin.model.Application 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)

Example 35 with Application

use of de.codecentric.boot.admin.model.Application in project spring-boot-admin by codecentric.

the class ApplicationRouteLocator method locateRoutes.

protected List<ApplicationRoute> locateRoutes() {
    Collection<Application> applications = registry.getApplications();
    List<ApplicationRoute> locateRoutes = new ArrayList<>(applications.size() * (endpoints.length + 1));
    for (Application application : applications) {
        addRoute(locateRoutes, application, "health", application.getHealthUrl());
        if (!StringUtils.isEmpty(application.getManagementUrl())) {
            for (String endpoint : endpoints) {
                addRoute(locateRoutes, application, endpoint, application.getManagementUrl() + "/" + endpoint);
            }
        }
    }
    return locateRoutes;
}
Also used : ArrayList(java.util.ArrayList) Application(de.codecentric.boot.admin.model.Application)

Aggregations

Application (de.codecentric.boot.admin.model.Application)36 Test (org.junit.Test)27 DefaultServiceInstance (org.springframework.cloud.client.DefaultServiceInstance)7 ServiceInstance (org.springframework.cloud.client.ServiceInstance)7 ClientApplicationRegisteredEvent (de.codecentric.boot.admin.event.ClientApplicationRegisteredEvent)5 ClientApplicationDeregisteredEvent (de.codecentric.boot.admin.event.ClientApplicationDeregisteredEvent)4 InstanceInfo (com.netflix.appinfo.InstanceInfo)3 ClientApplicationEvent (de.codecentric.boot.admin.event.ClientApplicationEvent)3 StatusInfo (de.codecentric.boot.admin.model.StatusInfo)3 Collection (java.util.Collection)3 Map (java.util.Map)3 EurekaServiceInstance (org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient.EurekaServiceInstance)3 HttpHeaders (org.springframework.http.HttpHeaders)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 Serializable (java.io.Serializable)2 ArrayList (java.util.ArrayList)2 Collections.singletonMap (java.util.Collections.singletonMap)2 HttpEntity (org.springframework.http.HttpEntity)2 RequestContext (com.netflix.zuul.context.RequestContext)1 ClientApplicationStatusChangedEvent (de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent)1