Skip to content

Commit

Permalink
Polish contribution
Browse files Browse the repository at this point in the history
  • Loading branch information
joshiste committed Oct 11, 2019
1 parent e6e4069 commit fc2ce4b
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
import org.springframework.boot.actuate.endpoint.web.PathMappedEndpoints;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.util.StringUtils;

public class CloudFoundryApplicationFactory extends DefaultApplicationFactory {
private final CloudFoundryApplicationProperties cfApplicationProperties;
private final InstanceProperties instance;

public CloudFoundryApplicationFactory(InstanceProperties instance,
ManagementServerProperties management,
Expand All @@ -37,16 +39,21 @@ public CloudFoundryApplicationFactory(InstanceProperties instance,
CloudFoundryApplicationProperties cfApplicationProperties) {
super(instance, management, server, pathMappedEndpoints, webEndpoint, metadataContributor);
this.cfApplicationProperties = cfApplicationProperties;
this.instance = instance;
}

@Override
protected String getServiceBaseUrl() {
if (cfApplicationProperties.getUris().isEmpty()) {
return super.getServiceBaseUrl();
}
@Override
protected String getServiceBaseUrl() {
String baseUrl = this.instance.getServiceBaseUrl();
if (!StringUtils.isEmpty(baseUrl)) {
return baseUrl;
}

String uri = cfApplicationProperties.getUris().get(0);
String schema = this.getMetadata().getOrDefault("serviceSchema", "http");
return schema + "://" + uri;
}
if (this.cfApplicationProperties.getUris().isEmpty()) {
return super.getServiceBaseUrl();
}

return "http://" + this.cfApplicationProperties.getUris().get(0);
}
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2018 the original author or authors.
* Copyright 2014-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,57 +28,54 @@
import org.springframework.boot.autoconfigure.web.ServerProperties;

import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.util.HashMap;
import java.util.Map;

public class CloudFoundryApplicationFactoryTest {
private InstanceProperties instanceProperties = new InstanceProperties();
private ServerProperties server = new ServerProperties();
private ManagementServerProperties management = new ManagementServerProperties();
private PathMappedEndpoints pathMappedEndpoints = mock(PathMappedEndpoints.class);
private WebEndpointProperties webEndpoint = new WebEndpointProperties();
private CloudFoundryApplicationProperties cfApplicationProperties = new CloudFoundryApplicationProperties();
private Map<String, String> metadata = new HashMap<>();

private CloudFoundryApplicationFactory factory = new CloudFoundryApplicationFactory(instanceProperties, management,
server, pathMappedEndpoints, webEndpoint, () -> metadata, cfApplicationProperties);

@Before
public void setup() {
instanceProperties.setName("test");
metadata.put("contributor", "test");
}

@Test
public void should_use_application_uri() {

when(pathMappedEndpoints.getPath(EndpointId.of("health"))).thenReturn("/actuator/health");
cfApplicationProperties.setUris(singletonList("application/Uppercase"));

Application app = factory.createApplication();

assertThat(app.getManagementUrl()).isEqualTo("http://application/Uppercase/actuator");
assertThat(app.getHealthUrl()).isEqualTo("http://application/Uppercase/actuator/health");
assertThat(app.getServiceUrl()).isEqualTo("http://application/Uppercase/");
}

@Test
public void should_use_application_uri_with_defined_service_schema() {

metadata.put("serviceSchema", "https");

when(pathMappedEndpoints.getPath(EndpointId.of("health"))).thenReturn("/actuator/health");
cfApplicationProperties.setUris(singletonList("application/Uppercase"));

Application app = factory.createApplication();

assertThat(app.getManagementUrl()).isEqualTo("https://application/Uppercase/actuator");
assertThat(app.getHealthUrl()).isEqualTo("https://application/Uppercase/actuator/health");
assertThat(app.getServiceUrl()).isEqualTo("https://application/Uppercase/");
}

private CloudFoundryApplicationFactory factory = new CloudFoundryApplicationFactory(this.instanceProperties,
this.management,
this.server,
this.pathMappedEndpoints,
this.webEndpoint,
() -> singletonMap("contributor", "test"),
this.cfApplicationProperties
);

@Before
public void setup() {
this.instanceProperties.setName("test");
}

@Test
public void should_use_application_uri() {
when(this.pathMappedEndpoints.getPath(EndpointId.of("health"))).thenReturn("/actuator/health");
this.cfApplicationProperties.setUris(singletonList("application/Uppercase"));

Application app = this.factory.createApplication();

assertThat(app.getManagementUrl()).isEqualTo("http://application/Uppercase/actuator");
assertThat(app.getHealthUrl()).isEqualTo("http://application/Uppercase/actuator/health");
assertThat(app.getServiceUrl()).isEqualTo("http://application/Uppercase/");
}

@Test
public void should_use_service_base_uri() {
when(this.pathMappedEndpoints.getPath(EndpointId.of("health"))).thenReturn("/actuator/health");
this.cfApplicationProperties.setUris(singletonList("application/Uppercase"));
this.instanceProperties.setServiceBaseUrl("https://serviceBaseUrl");

Application app = this.factory.createApplication();

assertThat(app.getManagementUrl()).isEqualTo("https://serviceBaseUrl/actuator");
assertThat(app.getHealthUrl()).isEqualTo("https://serviceBaseUrl/actuator/health");
assertThat(app.getServiceUrl()).isEqualTo("https://serviceBaseUrl/");
}
}
28 changes: 16 additions & 12 deletions spring-boot-admin-docs/src/main/asciidoc/client.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
[[show-version-in-application-list]]
=== Show Version in Application List ===

For *Spring Boot* applications the easiest way to show the version, is to use the `build-info` goal from the `spring-boot-maven-plugin`, which generates the `META-INF/build-info.properties`. See also the http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#howto-build-info[Spring Boot Reference Guide].
For *Spring Boot* applications the easiest way to show the version, is to use the `build-info` goal from the `spring-boot-maven-plugin`, which generates the `META-INF/build-info.properties`.
See also the http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#howto-build-info[Spring Boot Reference Guide].

For *non-Spring Boot* applications you can either add a `version` or `build.version` to the registration metadata and the version will show up in the application list.

Expand All @@ -31,8 +32,10 @@ For *non-Spring Boot* applications you can either add a `version` or `build.vers
[[jmx-bean-management]]
=== JMX-Bean Management ===

To interact with JMX-beans in the admin UI you have to include https://jolokia.org/[Jolokia] in your application. As Jolokia is servlet based there is no support for reactive applications.
In case you are using the `spring-boot-admin-starter-client` it will be pulled in for you, if not add Jolokia to your dependencies. With Spring Boot 2.2.0 you might want to set `spring.jmx.enabled=true` if you want to expose Spring beans via JMX.
To interact with JMX-beans in the admin UI you have to include https://jolokia.org/[Jolokia] in your application.
As Jolokia is servlet based there is no support for reactive applications.
In case you are using the `spring-boot-admin-starter-client` it will be pulled in for you, if not add Jolokia to your dependencies.
With Spring Boot 2.2.0 you might want to set `spring.jmx.enabled=true` if you want to expose Spring beans via JMX.

[source,xml]
.pom.xml
Expand All @@ -52,14 +55,16 @@ In order to enable the logfile actuator endpoint you need to configure Spring Bo

Spring Boot Admin will detect everything that looks like an URL and render it as hyperlink.

ANSI color-escapes are also supported. You need to set a custom file log pattern as Spring Boot's default one doesn't use colors.
ANSI color-escapes are also supported.
You need to set a custom file log pattern as Spring Boot's default one doesn't use colors.

.application.properties
----
logging.file=/var/log/sample-boot-application.log <1>
logging.pattern.file=%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID}){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wEx <2>
----
<1> Destination the logfile is written to. Enables the logfile actuator endpoint.
<1> Destination the logfile is written to.
Enables the logfile actuator endpoint.
<2> File log pattern using ANSI colors.

[[show-instance-tags]]
Expand All @@ -80,9 +85,12 @@ info.tags.environment=test
[[spring-boot-admin-client]]
=== Spring Boot Admin Client ===

The Spring Boot Admin Client registers the application at the admin server. This is done by periodically doing a HTTP post request to the SBA Server providing information about the application. It also adds Jolokia to your application, so that JMX-beans are accessible via HTTP.
The Spring Boot Admin Client registers the application at the admin server.
This is done by periodically doing a HTTP post request to the SBA Server providing information about the application.
It also adds Jolokia to your application, so that JMX-beans are accessible via HTTP.

TIP: There are plenty of properties to influence the way how the SBA Client registers your application. In case that doesn't fit your needs, you can provide your own `ApplicationFactory` implementation.
TIP: There are plenty of properties to influence the way how the SBA Client registers your application.
In case that doesn't fit your needs, you can provide your own `ApplicationFactory` implementation.

.Spring Boot Admin Client configuration options
|===
Expand Down Expand Up @@ -142,7 +150,7 @@ spring.boot.admin.client.password
| Guessed based on management-base-url and `management.context-path`.

| spring.boot.admin.client.instance.service-base-url
| Base url for computing the service-url to register with. The path is inferred at runtime, and appended to the base url.
| Base url for computing the service-url to register with. The path is inferred at runtime, and appended to the base url. In Cloudfoundry environments you can switching to https like this: `spring.boot.admin.client.instance.service-base-url=https://${vcap.application.uris[0]}`
| Guessed based on hostname, `server.port`.

| spring.boot.admin.client.instance.service-url
Expand Down Expand Up @@ -178,8 +186,4 @@ spring.boot.admin.client.password
user.password
| Credentials being used to access the endpoints.
|
| serviceSchema
| schema used by SBA server to access the client/instance on CloudFoundry
| http
|===

Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,4 @@ eureka:
metadata-map:
applicationId: ${vcap.application.application_id}
instanceId: ${vcap.application.instance_index}
serviceSchema: https
----

0 comments on commit fc2ce4b

Please sign in to comment.