Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
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
DEMO
spring-boot
Commits
40b55b0f
Commit
40b55b0f
authored
May 22, 2014
by
Christian Dupuis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract AbstractHealthAggregator
This commit makes it easier for users to implement HealthAggregators
parent
f9aeb6ae
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
28 deletions
+65
-28
AbstractHealthAggregator.java
...amework/boot/actuate/health/AbstractHealthAggregator.java
+46
-0
OrderedHealthAggregator.java
...ramework/boot/actuate/health/OrderedHealthAggregator.java
+19
-28
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/AbstractHealthAggregator.java
0 → 100644
View file @
40b55b0f
/*
* Copyright 2012-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
org
.
springframework
.
boot
.
actuate
.
health
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
/**
* Base {@link HealthAggregator} implementation to allow subclasses to focus on
* aggregating the {@link Status} instances and not deal with contextual details etc.
*
* @author Christian Dupuis
* @since 1.1.0
*/
public
abstract
class
AbstractHealthAggregator
implements
HealthAggregator
{
@Override
public
final
Health
aggregate
(
Map
<
String
,
Health
>
healths
)
{
Health
health
=
new
Health
();
List
<
Status
>
status
=
new
ArrayList
<
Status
>();
for
(
Map
.
Entry
<
String
,
Health
>
h
:
healths
.
entrySet
())
{
health
.
withDetail
(
h
.
getKey
(),
h
.
getValue
());
status
.
add
(
h
.
getValue
().
getStatus
());
}
health
.
status
(
aggregateStatus
(
status
));
return
health
;
}
protected
abstract
Status
aggregateStatus
(
List
<
Status
>
status
);
}
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/OrderedHealthAggregator.java
View file @
40b55b0f
...
...
@@ -16,12 +16,10 @@
package
org
.
springframework
.
boot
.
actuate
.
health
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.List
;
import
java.util.Map
;
/**
* Default {@link HealthAggregator} implementation that aggregates {@link Health}
...
...
@@ -34,48 +32,41 @@ import java.util.Map;
* @author Christian Dupuis
* @since 1.1.0
*/
public
class
OrderedHealthAggregator
implements
HealthAggregator
{
public
class
OrderedHealthAggregator
extends
Abstract
HealthAggregator
{
private
List
<
String
>
statusOrder
=
Arrays
.
asList
(
"DOWN"
,
"OUT_OF_SERVICE"
,
"UP"
,
"UNKOWN"
);
@Override
public
Health
aggregate
(
Map
<
String
,
Health
>
healths
)
{
Health
health
=
new
Health
();
List
<
Status
>
status
=
new
ArrayList
<
Status
>();
for
(
Map
.
Entry
<
String
,
Health
>
h
:
healths
.
entrySet
())
{
health
.
withDetail
(
h
.
getKey
(),
h
.
getValue
());
status
.
add
(
h
.
getValue
().
getStatus
());
}
health
.
status
(
aggregateStatus
(
status
));
return
health
;
}
public
void
setStatusOrder
(
List
<
String
>
statusOrder
)
{
this
.
statusOrder
=
statusOrder
;
}
@Override
protected
Status
aggregateStatus
(
List
<
Status
>
status
)
{
// If no status is given return UNKOWN
if
(
status
.
size
()
==
0
)
{
return
Status
.
UNKOWN
;
}
Collections
.
sort
(
status
,
new
Comparator
<
Status
>()
{
// Sort given Status instances by configured order
Collections
.
sort
(
status
,
new
StatusComparator
(
this
.
statusOrder
));
return
status
.
get
(
0
);
}
@Override
public
int
compare
(
Status
s1
,
Status
s2
)
{
return
Integer
.
valueOf
(
OrderedHealthAggregator
.
this
.
statusOrder
.
indexOf
(
s1
.
getCode
()))
.
compareTo
(
Integer
.
valueOf
(
OrderedHealthAggregator
.
this
.
statusOrder
.
indexOf
(
s2
.
getCode
())));
private
class
StatusComparator
implements
Comparator
<
Status
>
{
}
});
private
final
List
<
String
>
statusOrder
;
public
StatusComparator
(
List
<
String
>
statusOrder
)
{
this
.
statusOrder
=
statusOrder
;
}
@Override
public
int
compare
(
Status
s1
,
Status
s2
)
{
return
Integer
.
valueOf
(
this
.
statusOrder
.
indexOf
(
s1
.
getCode
())).
compareTo
(
Integer
.
valueOf
(
this
.
statusOrder
.
indexOf
(
s2
.
getCode
())));
}
return
status
.
get
(
0
);
}
}
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