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
d12e42e8
Commit
d12e42e8
authored
Nov 28, 2018
by
Brian Clozel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
Closes gh-15211
parent
0a4ba499
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
13 deletions
+24
-13
pom.xml
...g-boot-project/spring-boot-actuator-autoconfigure/pom.xml
+5
-0
ElasticSearchRestHealthIndicatorAutoConfiguration.java
...ch/ElasticSearchRestHealthIndicatorAutoConfiguration.java
+1
-1
spring.factories
...utoconfigure/src/main/resources/META-INF/spring.factories
+1
-0
ElasticsearchRestHealthIndicator.java
...tuate/elasticsearch/ElasticsearchRestHealthIndicator.java
+17
-12
No files found.
spring-boot-project/spring-boot-actuator-autoconfigure/pom.xml
View file @
d12e42e8
...
...
@@ -264,6 +264,11 @@
<artifactId>
jetty-server
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.elasticsearch
</groupId>
<artifactId>
elasticsearch
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.elasticsearch.client
</groupId>
<artifactId>
elasticsearch-rest-client
</artifactId>
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/elasticsearch/ElasticSearchRestHealthIndicatorAutoConfiguration.java
View file @
d12e42e8
...
...
@@ -40,7 +40,7 @@ import org.springframework.context.annotation.Configuration;
* {@link ElasticsearchRestHealthIndicator} using the {@link RestClient}.
*
* @author Artsiom Yudovin
* @since 2.1.
0
* @since 2.1.
1
*/
@Configuration
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/spring.factories
View file @
d12e42e8
...
...
@@ -15,6 +15,7 @@ org.springframework.boot.actuate.autoconfigure.couchbase.CouchbaseHealthIndicato
org.springframework.boot.actuate.autoconfigure.couchbase.CouchbaseReactiveHealthIndicatorAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.elasticsearch.ElasticSearchClientHealthIndicatorAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.elasticsearch.ElasticSearchJestHealthIndicatorAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.elasticsearch.ElasticSearchRestHealthIndicatorAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.endpoint.jmx.JmxEndpointAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointAutoConfiguration,\
...
...
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/elasticsearch/ElasticsearchRestHealthIndicator.java
View file @
d12e42e8
...
...
@@ -16,11 +16,10 @@
package
org
.
springframework
.
boot
.
actuate
.
elasticsearch
;
import
java.io.InputStream
Reader
;
import
java.io.InputStream
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Map
;
import
com.google.gson.JsonElement
;
import
com.google.gson.JsonParser
;
import
org.apache.http.HttpStatus
;
import
org.elasticsearch.client.Request
;
import
org.elasticsearch.client.Response
;
...
...
@@ -29,22 +28,29 @@ import org.elasticsearch.client.RestClient;
import
org.springframework.boot.actuate.health.AbstractHealthIndicator
;
import
org.springframework.boot.actuate.health.Health
;
import
org.springframework.boot.actuate.health.HealthIndicator
;
import
org.springframework.boot.json.JsonParser
;
import
org.springframework.boot.json.JsonParserFactory
;
import
org.springframework.util.StreamUtils
;
/**
* {@link HealthIndicator} for an Elasticsearch cluster
by REST
.
* {@link HealthIndicator} for an Elasticsearch cluster
using a {@link RestClient}
.
*
* @author Artsiom Yudovin
* @since 2.1.0
* @author Brian Clozel
* @since 2.1.1
*/
public
class
ElasticsearchRestHealthIndicator
extends
AbstractHealthIndicator
{
private
static
final
String
RED_STATUS
=
"red"
;
private
final
RestClient
client
;
private
final
JsonParser
jsonParser
=
new
JsonParser
()
;
private
final
JsonParser
jsonParser
;
public
ElasticsearchRestHealthIndicator
(
RestClient
client
)
{
super
(
"Elasticsearch health check failed"
);
this
.
client
=
client
;
this
.
jsonParser
=
JsonParserFactory
.
getJsonParser
();
}
@Override
...
...
@@ -56,12 +62,11 @@ public class ElasticsearchRestHealthIndicator extends AbstractHealthIndicator {
builder
.
down
();
}
else
{
try
(
InputStreamReader
reader
=
new
InputStreamReader
(
response
.
getEntity
().
getContent
(),
StandardCharsets
.
UTF_8
))
{
JsonElement
root
=
this
.
jsonParser
.
parse
(
reader
);
JsonElement
status
=
root
.
getAsJsonObject
().
get
(
"status"
);
if
(
status
.
getAsString
()
.
equals
(
io
.
searchbox
.
cluster
.
Health
.
Status
.
RED
.
getKey
()))
{
try
(
InputStream
is
=
response
.
getEntity
().
getContent
())
{
Map
<
String
,
Object
>
root
=
this
.
jsonParser
.
parseMap
(
StreamUtils
.
copyToString
(
is
,
StandardCharsets
.
UTF_8
));
String
status
=
(
String
)
root
.
get
(
"status"
);
if
(
status
.
equals
(
RED_STATUS
))
{
builder
.
outOfService
();
}
else
{
...
...
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