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
db74d27e
Commit
db74d27e
authored
May 22, 2014
by
Christian Dupuis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract AbstractHealthIndicator
to make it more simple to implement HealthIndicator
parent
1e6a4f3f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
74 additions
and
42 deletions
+74
-42
AbstractHealthIndicator.java
...ramework/boot/actuate/health/AbstractHealthIndicator.java
+51
-0
MongoHealthIndicator.java
...ngframework/boot/actuate/health/MongoHealthIndicator.java
+4
-12
RabbitHealthIndicator.java
...gframework/boot/actuate/health/RabbitHealthIndicator.java
+13
-19
RedisHealthIndicator.java
...ngframework/boot/actuate/health/RedisHealthIndicator.java
+3
-8
VanillaHealthIndicator.java
...framework/boot/actuate/health/VanillaHealthIndicator.java
+3
-3
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/AbstractHealthIndicator.java
0 → 100644
View file @
db74d27e
/*
* 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
;
/**
* Base {@link HealthIndicator} implementations that encapsulates creation of
* {@link Health} instance and error handling.
*
* <p>
* This implementation is only suitable if an {@link Exception} raised from
* {@link #doHealthCheck(Health)} should create a {@link Status#DOWN} health status.
*
* @author Christian Dupuis
* @since 1.1.0
*/
public
abstract
class
AbstractHealthIndicator
implements
HealthIndicator
{
@Override
public
final
Health
health
()
{
Health
health
=
new
Health
();
try
{
doHealthCheck
(
health
);
}
catch
(
Exception
ex
)
{
health
.
down
().
withException
(
ex
);
}
return
health
;
}
/**
* Actual health check logic.
* @param health {@link Health} instance of report status.
* @throws Exception any {@link Exception} that should create a {@link Status#DOWN}
* system status.
*/
protected
abstract
void
doHealthCheck
(
Health
health
)
throws
Exception
;
}
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/MongoHealthIndicator.java
View file @
db74d27e
...
...
@@ -28,7 +28,7 @@ import com.mongodb.CommandResult;
* @author Christian Dupuis
* @since 1.1.0
*/
public
class
MongoHealthIndicator
implements
HealthIndicator
{
public
class
MongoHealthIndicator
extends
Abstract
HealthIndicator
{
private
final
MongoTemplate
mongoTemplate
;
...
...
@@ -38,17 +38,9 @@ public class MongoHealthIndicator implements HealthIndicator {
}
@Override
public
Health
health
()
{
Health
health
=
new
Health
();
try
{
CommandResult
result
=
this
.
mongoTemplate
.
executeCommand
(
"{ serverStatus: 1 }"
);
health
.
up
().
withDetail
(
"version"
,
result
.
getString
(
"version"
));
}
catch
(
Exception
ex
)
{
health
.
down
().
withException
(
ex
);
}
return
health
;
protected
void
doHealthCheck
(
Health
health
)
throws
Exception
{
CommandResult
result
=
this
.
mongoTemplate
.
executeCommand
(
"{ serverStatus: 1 }"
);
health
.
up
().
withDetail
(
"version"
,
result
.
getString
(
"version"
));
}
}
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/RabbitHealthIndicator.java
View file @
db74d27e
...
...
@@ -31,7 +31,7 @@ import com.rabbitmq.client.Channel;
* @author Christian Dupuis
* @since 1.1.0
*/
public
class
RabbitHealthIndicator
implements
HealthIndicator
{
public
class
RabbitHealthIndicator
extends
Abstract
HealthIndicator
{
private
final
RabbitTemplate
rabbitTemplate
;
...
...
@@ -41,23 +41,17 @@ public class RabbitHealthIndicator implements HealthIndicator {
}
@Override
public
Health
health
()
{
Health
health
=
new
Health
();
try
{
health
.
up
().
withDetail
(
"version"
,
this
.
rabbitTemplate
.
execute
(
new
ChannelCallback
<
String
>()
{
@Override
public
String
doInRabbit
(
Channel
channel
)
throws
Exception
{
Map
<
String
,
Object
>
serverProperties
=
channel
.
getConnection
().
getServerProperties
();
return
serverProperties
.
get
(
"version"
).
toString
();
}
}));
}
catch
(
Exception
ex
)
{
health
.
down
().
withException
(
ex
);
}
return
health
;
protected
void
doHealthCheck
(
Health
health
)
throws
Exception
{
health
.
up
().
withDetail
(
"version"
,
this
.
rabbitTemplate
.
execute
(
new
ChannelCallback
<
String
>()
{
@Override
public
String
doInRabbit
(
Channel
channel
)
throws
Exception
{
Map
<
String
,
Object
>
serverProperties
=
channel
.
getConnection
()
.
getServerProperties
();
return
serverProperties
.
get
(
"version"
).
toString
();
}
}));
}
}
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/RedisHealthIndicator.java
View file @
db74d27e
...
...
@@ -30,7 +30,7 @@ import org.springframework.util.Assert;
* @author Christian Dupuis
* @since 1.1.0
*/
public
class
RedisHealthIndicator
implements
HealthIndicator
{
public
class
RedisHealthIndicator
extends
Abstract
HealthIndicator
{
private
final
RedisConnectionFactory
redisConnectionFactory
;
...
...
@@ -40,22 +40,17 @@ public class RedisHealthIndicator implements HealthIndicator {
}
@Override
public
Health
health
()
{
Health
health
=
new
Health
();
protected
void
doHealthCheck
(
Health
health
)
throws
Exception
{
RedisConnection
connection
=
null
;
try
{
connection
=
RedisConnectionUtils
.
getConnection
(
this
.
redisConnectionFactory
);
Properties
info
=
connection
.
info
();
health
.
up
().
withDetail
(
"version"
,
info
.
getProperty
(
"redis_version"
));
}
catch
(
Exception
ex
)
{
health
.
down
().
withException
(
ex
);
}
finally
{
RedisConnectionUtils
.
releaseConnection
(
connection
,
this
.
redisConnectionFactory
);
}
return
health
;
}
}
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/VanillaHealthIndicator.java
View file @
db74d27e
...
...
@@ -22,11 +22,11 @@ package org.springframework.boot.actuate.health;
* @author Dave Syer
* @author Christian Dupuis
*/
public
class
VanillaHealthIndicator
implements
HealthIndicator
{
public
class
VanillaHealthIndicator
extends
Abstract
HealthIndicator
{
@Override
p
ublic
Health
health
()
{
return
new
Health
(
Status
.
UP
);
p
rotected
void
doHealthCheck
(
Health
health
)
throws
Exception
{
health
.
up
(
);
}
}
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