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
8b355ad7
Commit
8b355ad7
authored
Oct 17, 2015
by
Johannes Edmeier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Decouple route-refreshing from registrationEvents
parent
275647ee
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
68 additions
and
129 deletions
+68
-129
AdminServerWebConfiguration.java
...entric/boot/admin/config/AdminServerWebConfiguration.java
+21
-10
HazelcastStoreConfiguration.java
...entric/boot/admin/config/HazelcastStoreConfiguration.java
+13
-60
RevereseZuulProxyConfiguration.java
...ric/boot/admin/config/RevereseZuulProxyConfiguration.java
+6
-4
RoutesOutdatedEvent.java
.../de/codecentric/boot/admin/event/RoutesOutdatedEvent.java
+28
-0
ApplicationRouteRefreshListener.java
...tric/boot/admin/zuul/ApplicationRouteRefreshListener.java
+0
-55
No files found.
spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/config/AdminServerWebConfiguration.java
View file @
8b355ad7
...
...
@@ -23,11 +23,11 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextAware
;
import
org.springframework.context.ApplicationEventPublisher
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.context.event.EventListener
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.converter.HttpMessageConverter
;
import
org.springframework.http.converter.json.Jackson2ObjectMapperBuilder
;
import
org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
;
...
...
@@ -40,7 +40,9 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import
de.codecentric.boot.admin.controller.JournalController
;
import
de.codecentric.boot.admin.controller.RegistryController
;
import
de.codecentric.boot.admin.event.ClientApplicationDeregisteredEvent
;
import
de.codecentric.boot.admin.event.ClientApplicationRegisteredEvent
;
import
de.codecentric.boot.admin.event.RoutesOutdatedEvent
;
import
de.codecentric.boot.admin.journal.ApplicationEventJournal
;
import
de.codecentric.boot.admin.journal.store.JournaledEventStore
;
import
de.codecentric.boot.admin.journal.store.SimpleJournaledEventStore
;
...
...
@@ -52,11 +54,20 @@ import de.codecentric.boot.admin.registry.store.ApplicationStore;
import
de.codecentric.boot.admin.registry.store.SimpleApplicationStore
;
@Configuration
public
class
AdminServerWebConfiguration
extends
WebMvcConfigurerAdapter
implements
ApplicationContextAware
{
public
class
AdminServerWebConfiguration
extends
WebMvcConfigurerAdapter
implements
ApplicationContextAware
{
private
ApplicationContext
applicationContext
;
@Autowired
private
ApplicationEventPublisher
publisher
;
@Autowired
private
ApplicationStore
applicationStore
;
@Value
(
"${spring.boot.admin.monitor.period:10000}"
)
private
long
monitorPeriod
;
@Override
public
void
setApplicationContext
(
ApplicationContext
applicationContext
)
{
this
.
applicationContext
=
applicationContext
;
...
...
@@ -81,12 +92,6 @@ public class AdminServerWebConfiguration extends WebMvcConfigurerAdapter impleme
return
false
;
}
@Autowired
private
ApplicationStore
applicationStore
;
@Value
(
"${spring.boot.admin.monitor.period:10000}"
)
private
long
monitorPeriod
;
/**
* @return Controller with REST-API for spring-boot applications to register itself.
*/
...
...
@@ -130,6 +135,12 @@ public class AdminServerWebConfiguration extends WebMvcConfigurerAdapter impleme
@EventListener
public
void
onClientApplicationRegistered
(
ClientApplicationRegisteredEvent
event
)
{
statusUpdater
().
updateStatus
(
event
.
getApplication
());
publisher
.
publishEvent
(
new
RoutesOutdatedEvent
());
}
@EventListener
public
void
onClientApplicationDeregistered
(
ClientApplicationDeregisteredEvent
event
)
{
publisher
.
publishEvent
(
new
RoutesOutdatedEvent
());
}
@Bean
...
...
spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/config/HazelcastStoreConfiguration.java
View file @
8b355ad7
...
...
@@ -15,8 +15,6 @@
*/
package
de
.
codecentric
.
boot
.
admin
.
config
;
import
java.util.Objects
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.autoconfigure.AutoConfigureBefore
;
...
...
@@ -28,18 +26,17 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
import
com.hazelcast.config.Config
;
import
com.hazelcast.core.EntryAdapter
;
import
com.hazelcast.core.EntryEvent
;
import
com.hazelcast.core.EntryListener
;
import
com.hazelcast.core.Hazelcast
;
import
com.hazelcast.core.HazelcastInstance
;
import
com.hazelcast.core.IMap
;
import
com.hazelcast.core.MapEvent
;
import
com.hazelcast.map.listener.MapListener
;
import
de.codecentric.boot.admin.event.ClientApplicationDeregisteredEvent
;
import
de.codecentric.boot.admin.event.ClientApplicationRegisteredEvent
;
import
de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent
;
import
de.codecentric.boot.admin.event.RoutesOutdatedEvent
;
import
de.codecentric.boot.admin.model.Application
;
import
de.codecentric.boot.admin.model.StatusInfo
;
import
de.codecentric.boot.admin.registry.store.ApplicationStore
;
import
de.codecentric.boot.admin.registry.store.HazelcastApplicationStore
;
...
...
@@ -52,6 +49,9 @@ public class HazelcastStoreConfiguration {
@Value
(
"${spring.boot.admin.hazelcast.map:spring-boot-admin-application-store}"
)
private
String
hazelcastMapName
;
@Autowired
private
ApplicationEventPublisher
publisher
;
@Bean
@ConditionalOnMissingBean
public
Config
hazelcastConfig
()
{
...
...
@@ -69,70 +69,23 @@ public class HazelcastStoreConfiguration {
public
ApplicationStore
applicationStore
()
{
IMap
<
String
,
Application
>
map
=
hazelcastInstance
().
getMap
(
hazelcastMapName
);
map
.
addIndex
(
"name"
,
false
);
map
.
addEntryListener
(
entryListener
(),
false
);
map
.
addEntryListener
(
(
MapListener
)
entryListener
(),
false
);
return
new
HazelcastApplicationStore
(
map
);
}
@Bean
public
EntryListener
<
String
,
Application
>
entryListener
()
{
return
new
ApplicationEntryListener
();
}
private
static
class
ApplicationEntryListener
implements
EntryListener
<
String
,
Application
>
{
@Autowired
private
ApplicationEventPublisher
publisher
;
return
new
EntryAdapter
<
String
,
Application
>()
{
@Override
public
void
entryAdded
(
EntryEvent
<
String
,
Application
>
event
)
{
if
(
event
.
getValue
()
!=
null
)
{
publisher
.
publishEvent
(
new
ClientApplicationRegisteredEvent
(
event
.
getValue
()));
}
public
void
onEntryEvent
(
EntryEvent
<
String
,
Application
>
event
)
{
publisher
.
publishEvent
(
new
RoutesOutdatedEvent
());
}
@Override
public
void
entryRemoved
(
EntryEvent
<
String
,
Application
>
event
)
{
if
(
event
.
getValue
()
!=
null
)
{
publisher
.
publishEvent
(
new
ClientApplicationDeregisteredEvent
(
event
.
getValue
()));
}
public
void
onMapEvent
(
MapEvent
event
)
{
publisher
.
publishEvent
(
new
RoutesOutdatedEvent
());
}
@Override
public
void
entryUpdated
(
EntryEvent
<
String
,
Application
>
event
)
{
if
(!
Objects
.
equals
(
event
.
getOldValue
(),
event
.
getValue
()))
{
if
(
event
.
getOldValue
()
!=
null
)
{
publisher
.
publishEvent
(
new
ClientApplicationDeregisteredEvent
(
event
.
getOldValue
()));
}
if
(
event
.
getValue
()
!=
null
)
{
publisher
.
publishEvent
(
new
ClientApplicationRegisteredEvent
(
event
.
getValue
()));
}
}
else
{
StatusInfo
from
=
event
.
getOldValue
()
!=
null
?
event
.
getOldValue
().
getStatusInfo
()
:
StatusInfo
.
ofUnknown
();
StatusInfo
to
=
event
.
getValue
()
!=
null
?
event
.
getValue
().
getStatusInfo
()
:
StatusInfo
.
ofUnknown
();
if
(!
from
.
equals
(
to
))
{
publisher
.
publishEvent
(
new
ClientApplicationStatusChangedEvent
(
event
.
getValue
(),
from
,
to
));
}
}
}
@Override
public
void
entryEvicted
(
EntryEvent
<
String
,
Application
>
event
)
{
if
(
event
.
getValue
()
!=
null
)
{
publisher
.
publishEvent
(
new
ClientApplicationDeregisteredEvent
(
event
.
getValue
()));
}
}
@Override
public
void
mapEvicted
(
MapEvent
event
)
{
publisher
.
publishEvent
(
new
ClientApplicationDeregisteredEvent
(
null
));
}
@Override
public
void
mapCleared
(
MapEvent
event
)
{
publisher
.
publishEvent
(
new
ClientApplicationDeregisteredEvent
(
null
));
}
};
}
}
spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/config/RevereseZuulProxyConfiguration.java
View file @
8b355ad7
...
...
@@ -39,13 +39,14 @@ import org.springframework.cloud.netflix.zuul.web.ZuulController;
import
org.springframework.cloud.netflix.zuul.web.ZuulHandlerMapping
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.event.EventListener
;
import
com.netflix.zuul.ZuulFilter
;
import
de.codecentric.boot.admin.controller.RegistryController
;
import
de.codecentric.boot.admin.event.RoutesOutdatedEvent
;
import
de.codecentric.boot.admin.registry.ApplicationRegistry
;
import
de.codecentric.boot.admin.zuul.ApplicationRouteLocator
;
import
de.codecentric.boot.admin.zuul.ApplicationRouteRefreshListener
;
@Configuration
@EnableConfigurationProperties
(
ZuulProperties
.
class
)
...
...
@@ -135,9 +136,10 @@ public class RevereseZuulProxyConfiguration {
}
@Bean
public
ApplicationRouteRefreshListener
applicationRouteRefreshListener
()
{
return
new
ApplicationRouteRefreshListener
(
routeLocator
(),
zuulHandlerMapping
());
@EventListener
public
void
onRoutesOutdatedEvent
(
RoutesOutdatedEvent
event
)
{
routeLocator
().
resetRoutes
();
zuulHandlerMapping
().
registerHandlers
();
}
@Configuration
...
...
spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/event/RoutesOutdatedEvent.java
0 → 100644
View file @
8b355ad7
/*
* Copyright 2014 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
.
event
;
import
java.io.Serializable
;
/**
* Signals that the routes needs to be recalculated.
*
* @author Johannes Edmeier
*/
public
class
RoutesOutdatedEvent
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
}
spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/zuul/ApplicationRouteRefreshListener.java
deleted
100644 → 0
View file @
275647ee
/*
* Copyright 2014 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
.
zuul
;
import
org.springframework.cloud.netflix.zuul.web.ZuulHandlerMapping
;
import
org.springframework.context.event.EventListener
;
import
de.codecentric.boot.admin.event.ClientApplicationDeregisteredEvent
;
import
de.codecentric.boot.admin.event.ClientApplicationRegisteredEvent
;
/**
* Listener to trigger recomputation of the applications' routes.
*
* @author Johannes Stelzer
*/
public
class
ApplicationRouteRefreshListener
{
private
final
ApplicationRouteLocator
routeLocator
;
private
final
ZuulHandlerMapping
zuulHandlerMapping
;
public
ApplicationRouteRefreshListener
(
ApplicationRouteLocator
routeLocator
,
ZuulHandlerMapping
zuulHandlerMapping
)
{
this
.
routeLocator
=
routeLocator
;
this
.
zuulHandlerMapping
=
zuulHandlerMapping
;
}
@EventListener
public
void
onClientApplicationDeregistered
(
ClientApplicationDeregisteredEvent
event
)
{
refreshRoutes
();
}
@EventListener
public
void
onClientApplicationRegistered
(
ClientApplicationRegisteredEvent
event
)
{
refreshRoutes
();
}
private
void
refreshRoutes
()
{
this
.
routeLocator
.
resetRoutes
();
this
.
zuulHandlerMapping
.
registerHandlers
();
}
}
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