1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.codelibs.fess.entity;
17
18 import java.io.IOException;
19
20 import org.codelibs.core.lang.StringUtil;
21 import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
22 import org.elasticsearch.cluster.health.ClusterHealthStatus;
23 import org.elasticsearch.common.xcontent.ToXContent;
24 import org.elasticsearch.common.xcontent.XContentBuilder;
25 import org.elasticsearch.common.xcontent.XContentFactory;
26
27 public class PingResponse {
28 private final int status;
29
30 private final String clusterName;
31
32 private final String clusterStatus;
33
34 private String message = StringUtil.EMPTY;
35
36 public PingResponse(final ClusterHealthResponse response) {
37 status = response.getStatus() == ClusterHealthStatus.RED ? 1 : 0;
38 clusterName = response.getClusterName();
39 clusterStatus = response.getStatus().toString();
40 try {
41 final XContentBuilder builder = XContentFactory.jsonBuilder();
42 builder.startObject();
43 response.toXContent(builder, ToXContent.EMPTY_PARAMS);
44 builder.endObject();
45 message = builder.string();
46 } catch (final IOException e) {
47 message = "{ \"error\" : \"" + e.getMessage() + "\"}";
48 }
49 }
50
51 public int getStatus() {
52 return status;
53 }
54
55 public String getClusterName() {
56 return clusterName;
57 }
58
59 public String getClusterStatus() {
60 return clusterStatus;
61 }
62
63 public String getMessage() {
64 return message;
65 }
66
67 }