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
d1879b19
Commit
d1879b19
authored
Jun 11, 2016
by
Johannes Edmeier
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.3.x'
parents
e8d11a2e
991119e9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
5 deletions
+43
-5
ApplicationDiscoveryListener.java
...ic/boot/admin/discovery/ApplicationDiscoveryListener.java
+21
-5
ApplicationDiscoveryListenerTest.java
...oot/admin/discovery/ApplicationDiscoveryListenerTest.java
+22
-0
No files found.
spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/discovery/ApplicationDiscoveryListener.java
View file @
d1879b19
...
@@ -77,26 +77,42 @@ public class ApplicationDiscoveryListener {
...
@@ -77,26 +77,42 @@ public class ApplicationDiscoveryListener {
}
}
protected
void
discover
()
{
protected
void
discover
()
{
final
Set
<
String
>
staleApplicationIds
=
getAllApplicationIdsFromRegistry
();
for
(
String
serviceId
:
discoveryClient
.
getServices
())
{
for
(
String
serviceId
:
discoveryClient
.
getServices
())
{
for
(
ServiceInstance
instance
:
discoveryClient
.
getInstances
(
serviceId
))
{
if
(!
ignoredServices
.
contains
(
serviceId
))
{
if
(!
ignoredServices
.
contains
(
serviceId
))
{
for
(
ServiceInstance
instance
:
discoveryClient
.
getInstances
(
serviceId
))
{
register
(
instance
);
String
applicationId
=
register
(
instance
);
staleApplicationIds
.
remove
(
applicationId
);
}
}
}
}
}
}
for
(
String
staleApplicationId
:
staleApplicationIds
)
{
LOGGER
.
info
(
"Application ({}) missing in DiscoveryClient services "
,
staleApplicationId
);
registry
.
deregister
(
staleApplicationId
);
}
}
protected
final
Set
<
String
>
getAllApplicationIdsFromRegistry
()
{
Set
<
String
>
result
=
new
HashSet
<>();
for
(
Application
application
:
registry
.
getApplications
())
{
result
.
add
(
application
.
getId
());
}
return
result
;
}
}
protected
void
register
(
ServiceInstance
instance
)
{
protected
String
register
(
ServiceInstance
instance
)
{
try
{
try
{
Application
application
=
converter
.
convert
(
instance
);
Application
application
=
converter
.
convert
(
instance
);
if
(
application
!=
null
)
{
if
(
application
!=
null
)
{
re
gistry
.
register
(
application
);
re
turn
registry
.
register
(
application
).
getId
(
);
}
else
{
}
else
{
LOGGER
.
warn
(
"No application for service {} registered"
,
instance
);
LOGGER
.
warn
(
"No application for service {} registered"
,
instance
);
}
}
}
catch
(
Exception
ex
)
{
}
catch
(
Exception
ex
)
{
LOGGER
.
error
(
"Couldn't register application for service {}"
,
instance
,
ex
);
LOGGER
.
error
(
"Couldn't register application for service {}"
,
instance
,
ex
);
}
}
return
null
;
}
}
public
void
setConverter
(
ServiceInstanceConverter
converter
)
{
public
void
setConverter
(
ServiceInstanceConverter
converter
)
{
...
...
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/discovery/ApplicationDiscoveryListenerTest.java
View file @
d1879b19
...
@@ -19,7 +19,9 @@ import static org.junit.Assert.assertEquals;
...
@@ -19,7 +19,9 @@ import static org.junit.Assert.assertEquals;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.List
;
import
org.junit.Before
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.Test
;
...
@@ -95,4 +97,24 @@ public class ApplicationDiscoveryListenerTest {
...
@@ -95,4 +97,24 @@ public class ApplicationDiscoveryListenerTest {
assertEquals
(
1
,
registry
.
getApplications
().
size
());
assertEquals
(
1
,
registry
.
getApplications
().
size
());
}
}
@Test
public
void
deregister_removed_app
()
{
Object
heartbeat
=
new
Object
();
List
<
ServiceInstance
>
instances
=
new
ArrayList
<>();
instances
.
add
(
new
DefaultServiceInstance
(
"service"
,
"localhost"
,
80
,
false
));
instances
.
add
(
new
DefaultServiceInstance
(
"service"
,
"example.net"
,
80
,
false
));
when
(
discovery
.
getServices
()).
thenReturn
(
Collections
.
singletonList
(
"service"
));
when
(
discovery
.
getInstances
(
"service"
)).
thenReturn
(
instances
);
listener
.
onApplicationEvent
(
new
HeartbeatEvent
(
new
Object
(),
heartbeat
));
assertEquals
(
2
,
registry
.
getApplications
().
size
());
instances
.
remove
(
0
);
listener
.
onApplicationEvent
(
new
HeartbeatEvent
(
new
Object
(),
new
Object
()));
assertEquals
(
1
,
registry
.
getApplications
().
size
());
}
}
}
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