Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-boot-admin
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
spring-boot-admin
Commits
393d3da5
Commit
393d3da5
authored
Feb 26, 2018
by
Johannes Edmeier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add MetadataContirbutor
in order to easily contribute programmatically to the metadata this commit adds an MetadataContributor as extionsion point.
parent
6a0c7b78
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
227 additions
and
20 deletions
+227
-20
SpringBootAdminClientAutoConfiguration.java
...client/config/SpringBootAdminClientAutoConfiguration.java
+32
-6
DefaultApplicationFactory.java
.../admin/client/registration/DefaultApplicationFactory.java
+6
-10
ServletApplicationFactory.java
.../admin/client/registration/ServletApplicationFactory.java
+4
-2
CompositeMetadataContributor.java
...t/registration/metadata/CompositeMetadataContributor.java
+36
-0
MetadataContributor.java
...min/client/registration/metadata/MetadataContributor.java
+26
-0
StartupDateMetadataContributor.java
...registration/metadata/StartupDateMetadataContributor.java
+32
-0
DefaultApplicationFactoryTest.java
...in/client/registration/DefaultApplicationFactoryTest.java
+6
-1
ServletApplicationFactoryTest.java
...in/client/registration/ServletApplicationFactoryTest.java
+2
-1
CompositeMetadataContributorTest.java
...gistration/metadata/CompositeMetadataContributorTest.java
+49
-0
StartupDateMetadataContributorTest.java
...stration/metadata/StartupDateMetadataContributorTest.java
+34
-0
No files found.
spring-boot-admin-client/src/main/java/de/codecentric/boot/admin/client/config/SpringBootAdminClientAutoConfiguration.java
View file @
393d3da5
...
...
@@ -21,8 +21,14 @@ import de.codecentric.boot.admin.client.registration.ApplicationRegistrator;
import
de.codecentric.boot.admin.client.registration.DefaultApplicationFactory
;
import
de.codecentric.boot.admin.client.registration.RegistrationApplicationListener
;
import
de.codecentric.boot.admin.client.registration.ServletApplicationFactory
;
import
de.codecentric.boot.admin.client.registration.metadata.CompositeMetadataContributor
;
import
de.codecentric.boot.admin.client.registration.metadata.MetadataContributor
;
import
de.codecentric.boot.admin.client.registration.metadata.StartupDateMetadataContributor
;
import
java.util.Collections
;
import
java.util.List
;
import
javax.servlet.ServletContext
;
import
org.springframework.beans.factory.ObjectProvider
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties
;
import
org.springframework.boot.actuate.autoconfigure.endpoint.web.servlet.WebMvcEndpointManagementContextConfiguration
;
...
...
@@ -37,6 +43,7 @@ import org.springframework.boot.web.client.RestTemplateBuilder;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Conditional
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.http.client.SimpleClientHttpRequestFactory
;
import
org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
;
import
org.springframework.scheduling.TaskScheduler
;
...
...
@@ -61,9 +68,10 @@ public class SpringBootAdminClientAutoConfiguration {
ServerProperties
server
,
ServletContext
servletContext
,
PathMappedEndpoints
pathMappedEndpoints
,
WebEndpointProperties
webEndpoint
)
{
WebEndpointProperties
webEndpoint
,
MetadataContributor
metadataContributor
)
{
return
new
ServletApplicationFactory
(
instance
,
management
,
server
,
servletContext
,
pathMappedEndpoints
,
webEndpoint
);
webEndpoint
,
metadataContributor
);
}
}
...
...
@@ -76,8 +84,10 @@ public class SpringBootAdminClientAutoConfiguration {
ManagementServerProperties
management
,
ServerProperties
server
,
PathMappedEndpoints
pathMappedEndpoints
,
WebEndpointProperties
webEndpoint
)
{
return
new
DefaultApplicationFactory
(
instance
,
management
,
server
,
pathMappedEndpoints
,
webEndpoint
);
WebEndpointProperties
webEndpoint
,
MetadataContributor
metadataContributor
)
{
return
new
DefaultApplicationFactory
(
instance
,
management
,
server
,
pathMappedEndpoints
,
webEndpoint
,
metadataContributor
);
}
}
...
...
@@ -102,8 +112,10 @@ public class SpringBootAdminClientAutoConfiguration {
ManagementServerProperties
management
,
ServerProperties
server
,
PathMappedEndpoints
pathMappedEndpoints
,
WebEndpointProperties
webEndpoint
)
{
return
new
DefaultApplicationFactory
(
instance
,
management
,
server
,
pathMappedEndpoints
,
webEndpoint
);
WebEndpointProperties
webEndpoint
,
MetadataContributor
metadataContributor
)
{
return
new
DefaultApplicationFactory
(
instance
,
management
,
server
,
pathMappedEndpoints
,
webEndpoint
,
metadataContributor
);
}
@Bean
...
...
@@ -127,4 +139,18 @@ public class SpringBootAdminClientAutoConfiguration {
listener
.
setRegisterPeriod
(
client
.
getPeriod
());
return
listener
;
}
@Bean
@Primary
@ConditionalOnMissingBean
public
CompositeMetadataContributor
metadataContributor
(
ObjectProvider
<
List
<
MetadataContributor
>>
contributorProvider
)
{
List
<
MetadataContributor
>
contributors
=
contributorProvider
.
getIfAvailable
(
Collections:
:
emptyList
);
return
new
CompositeMetadataContributor
(
contributors
);
}
@Bean
@ConditionalOnMissingBean
public
StartupDateMetadataContributor
startupDateMetadataContributor
()
{
return
new
StartupDateMetadataContributor
();
}
}
spring-boot-admin-client/src/main/java/de/codecentric/boot/admin/client/registration/DefaultApplicationFactory.java
View file @
393d3da5
...
...
@@ -17,11 +17,10 @@
package
de
.
codecentric
.
boot
.
admin
.
client
.
registration
;
import
de.codecentric.boot.admin.client.config.InstanceProperties
;
import
de.codecentric.boot.admin.client.registration.metadata.MetadataContributor
;
import
java.net.InetAddress
;
import
java.net.UnknownHostException
;
import
java.time.OffsetDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
import
org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties
;
...
...
@@ -47,7 +46,7 @@ public class DefaultApplicationFactory implements ApplicationFactory {
private
final
ManagementServerProperties
management
;
private
final
PathMappedEndpoints
pathMappedEndpoints
;
private
final
WebEndpointProperties
webEndpoint
;
private
final
OffsetDateTime
timestamp
;
private
final
MetadataContributor
metadataContributor
;
private
Integer
localServerPort
;
private
Integer
localManagementPort
;
...
...
@@ -56,13 +55,14 @@ public class DefaultApplicationFactory implements ApplicationFactory {
ManagementServerProperties
management
,
ServerProperties
server
,
PathMappedEndpoints
pathMappedEndpoints
,
WebEndpointProperties
webEndpoint
)
{
WebEndpointProperties
webEndpoint
,
MetadataContributor
metadataContributor
)
{
this
.
instance
=
instance
;
this
.
management
=
management
;
this
.
server
=
server
;
this
.
pathMappedEndpoints
=
pathMappedEndpoints
;
this
.
webEndpoint
=
webEndpoint
;
this
.
timestamp
=
OffsetDateTime
.
now
()
;
this
.
metadataContributor
=
metadataContributor
;
}
@Override
...
...
@@ -162,15 +162,11 @@ public class DefaultApplicationFactory implements ApplicationFactory {
}
protected
Map
<
String
,
String
>
getMetadata
()
{
if
(
instance
.
getMetadata
().
containsKey
(
"startup"
))
{
return
instance
.
getMetadata
();
}
else
{
Map
<
String
,
String
>
metadata
=
new
LinkedHashMap
<>();
metadata
.
put
(
"startup"
,
this
.
timestamp
.
format
(
DateTimeFormatter
.
ISO_DATE_TIME
));
metadata
.
putAll
(
metadataContributor
.
getMetadata
(
));
metadata
.
putAll
(
instance
.
getMetadata
());
return
metadata
;
}
}
protected
String
getServiceHost
()
{
InetAddress
address
=
server
.
getAddress
();
...
...
spring-boot-admin-client/src/main/java/de/codecentric/boot/admin/client/registration/ServletApplicationFactory.java
View file @
393d3da5
...
...
@@ -17,6 +17,7 @@
package
de
.
codecentric
.
boot
.
admin
.
client
.
registration
;
import
de.codecentric.boot.admin.client.config.InstanceProperties
;
import
de.codecentric.boot.admin.client.registration.metadata.MetadataContributor
;
import
javax.servlet.ServletContext
;
import
org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties
;
...
...
@@ -35,8 +36,9 @@ public class ServletApplicationFactory extends DefaultApplicationFactory {
ServerProperties
server
,
ServletContext
servletContext
,
PathMappedEndpoints
pathMappedEndpoints
,
WebEndpointProperties
webEndpoint
)
{
super
(
instance
,
management
,
server
,
pathMappedEndpoints
,
webEndpoint
);
WebEndpointProperties
webEndpoint
,
MetadataContributor
metadataContributor
)
{
super
(
instance
,
management
,
server
,
pathMappedEndpoints
,
webEndpoint
,
metadataContributor
);
this
.
servletContext
=
servletContext
;
this
.
servlet
=
server
.
getServlet
();
this
.
managementServlet
=
management
.
getServlet
();
...
...
spring-boot-admin-client/src/main/java/de/codecentric/boot/admin/client/registration/metadata/CompositeMetadataContributor.java
0 → 100644
View file @
393d3da5
/*
* Copyright 2014-2018 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
de
.
codecentric
.
boot
.
admin
.
client
.
registration
.
metadata
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
public
class
CompositeMetadataContributor
implements
MetadataContributor
{
private
final
List
<
MetadataContributor
>
delegates
;
public
CompositeMetadataContributor
(
List
<
MetadataContributor
>
delegates
)
{
this
.
delegates
=
delegates
;
}
@Override
public
Map
<
String
,
String
>
getMetadata
()
{
Map
<
String
,
String
>
metadata
=
new
LinkedHashMap
<>();
delegates
.
forEach
(
delegate
->
metadata
.
putAll
(
delegate
.
getMetadata
()));
return
metadata
;
}
}
spring-boot-admin-client/src/main/java/de/codecentric/boot/admin/client/registration/metadata/MetadataContributor.java
0 → 100644
View file @
393d3da5
/*
* Copyright 2014-2018 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
de
.
codecentric
.
boot
.
admin
.
client
.
registration
.
metadata
;
import
java.util.Map
;
@FunctionalInterface
public
interface
MetadataContributor
{
Map
<
String
,
String
>
getMetadata
();
}
spring-boot-admin-client/src/main/java/de/codecentric/boot/admin/client/registration/metadata/StartupDateMetadataContributor.java
0 → 100644
View file @
393d3da5
/*
* Copyright 2014-2018 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
de
.
codecentric
.
boot
.
admin
.
client
.
registration
.
metadata
;
import
java.time.OffsetDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.util.Map
;
import
static
java
.
util
.
Collections
.
singletonMap
;
public
class
StartupDateMetadataContributor
implements
MetadataContributor
{
private
final
OffsetDateTime
timestamp
=
OffsetDateTime
.
now
();
@Override
public
Map
<
String
,
String
>
getMetadata
()
{
return
singletonMap
(
"startup"
,
this
.
timestamp
.
format
(
DateTimeFormatter
.
ISO_DATE_TIME
));
}
}
spring-boot-admin-client/src/test/java/de/codecentric/boot/admin/client/registration/DefaultApplicationFactoryTest.java
View file @
393d3da5
...
...
@@ -31,8 +31,10 @@ import org.springframework.boot.web.context.WebServerInitializedEvent;
import
org.springframework.boot.web.server.Ssl
;
import
org.springframework.boot.web.server.WebServer
;
import
static
java
.
util
.
Collections
.
singletonMap
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatThrownBy
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
entry
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
when
;
...
...
@@ -44,7 +46,7 @@ public class DefaultApplicationFactoryTest {
private
WebEndpointProperties
webEndpoint
=
new
WebEndpointProperties
();
private
DefaultApplicationFactory
factory
=
new
DefaultApplicationFactory
(
instanceProperties
,
management
,
server
,
pathMappedEndpoints
,
webEndpoint
);
pathMappedEndpoints
,
webEndpoint
,
()
->
singletonMap
(
"contributor"
,
"test"
)
);
@Before
public
void
setup
()
{
...
...
@@ -65,6 +67,7 @@ public class DefaultApplicationFactoryTest {
@Test
public
void
test_default
()
{
instanceProperties
.
setMetadata
(
singletonMap
(
"instance"
,
"test"
));
when
(
pathMappedEndpoints
.
getPath
(
"health"
)).
thenReturn
(
"/actuator/health"
);
publishApplicationReadyEvent
(
factory
,
8080
,
null
);
...
...
@@ -72,6 +75,8 @@ public class DefaultApplicationFactoryTest {
assertThat
(
app
.
getManagementUrl
()).
isEqualTo
(
"http://"
+
getHostname
()
+
":8080/actuator"
);
assertThat
(
app
.
getHealthUrl
()).
isEqualTo
(
"http://"
+
getHostname
()
+
":8080/actuator/health"
);
assertThat
(
app
.
getServiceUrl
()).
isEqualTo
(
"http://"
+
getHostname
()
+
":8080/"
);
assertThat
(
app
.
getMetadata
()).
containsExactly
(
entry
(
"contributor"
,
"test"
),
entry
(
"instance"
,
"test"
));
}
@Test
...
...
spring-boot-admin-client/src/test/java/de/codecentric/boot/admin/client/registration/ServletApplicationFactoryTest.java
View file @
393d3da5
...
...
@@ -20,6 +20,7 @@ import de.codecentric.boot.admin.client.config.InstanceProperties;
import
java.net.InetAddress
;
import
java.net.UnknownHostException
;
import
java.util.Collections
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties
;
...
...
@@ -43,7 +44,7 @@ public class ServletApplicationFactoryTest {
private
PathMappedEndpoints
pathMappedEndpoints
=
mock
(
PathMappedEndpoints
.
class
);
private
WebEndpointProperties
webEndpoint
=
new
WebEndpointProperties
();
private
ServletApplicationFactory
factory
=
new
ServletApplicationFactory
(
instance
,
management
,
server
,
servletContext
,
pathMappedEndpoints
,
webEndpoint
);
servletContext
,
pathMappedEndpoints
,
webEndpoint
,
Collections:
:
emptyMap
);
@Before
public
void
setup
()
{
...
...
spring-boot-admin-client/src/test/java/de/codecentric/boot/admin/client/registration/metadata/CompositeMetadataContributorTest.java
0 → 100644
View file @
393d3da5
/*
* Copyright 2014-2018 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
de
.
codecentric
.
boot
.
admin
.
client
.
registration
.
metadata
;
import
java.util.Map
;
import
org.junit.Test
;
import
static
java
.
util
.
Arrays
.
asList
;
import
static
java
.
util
.
Collections
.
emptyList
;
import
static
java
.
util
.
Collections
.
singletonMap
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
entry
;
public
class
CompositeMetadataContributorTest
{
@Test
public
void
should_merge_metadata
()
{
CompositeMetadataContributor
contributor
=
new
CompositeMetadataContributor
(
asList
(()
->
singletonMap
(
"a"
,
"first"
),
()
->
singletonMap
(
"b"
,
"second"
),
()
->
singletonMap
(
"b"
,
"second-new"
)));
Map
<
String
,
String
>
metadata
=
contributor
.
getMetadata
();
assertThat
(
metadata
).
containsExactly
(
entry
(
"a"
,
"first"
),
entry
(
"b"
,
"second-new"
));
}
@Test
public
void
should_return_empty_metadata
()
{
CompositeMetadataContributor
contributor
=
new
CompositeMetadataContributor
(
emptyList
());
Map
<
String
,
String
>
metadata
=
contributor
.
getMetadata
();
assertThat
(
metadata
).
isEmpty
();
}
}
spring-boot-admin-client/src/test/java/de/codecentric/boot/admin/client/registration/metadata/StartupDateMetadataContributorTest.java
0 → 100644
View file @
393d3da5
/*
* Copyright 2014-2018 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
de
.
codecentric
.
boot
.
admin
.
client
.
registration
.
metadata
;
import
java.util.Map
;
import
org.junit.Test
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
public
class
StartupDateMetadataContributorTest
{
@Test
public
void
should_return_startupdate
()
{
StartupDateMetadataContributor
contributor
=
new
StartupDateMetadataContributor
();
Map
<
String
,
String
>
metadata
=
contributor
.
getMetadata
();
assertThat
(
metadata
).
hasSize
(
1
).
hasEntrySatisfying
(
"startup"
,
(
value
)
->
assertThat
(
value
).
isNotEmpty
());
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment