25
25
import org .elasticsearch .common .inject .Inject ;
26
26
import org .elasticsearch .common .settings .Settings ;
27
27
import org .elasticsearch .common .xcontent .XContentBuilder ;
28
+ import org .elasticsearch .common .xcontent .XContentBuilderString ;
28
29
import org .elasticsearch .rest .*;
29
30
import org .elasticsearch .rest .action .support .RestActions ;
30
31
import org .elasticsearch .rest .action .support .RestXContentBuilder ;
@@ -84,18 +85,18 @@ public class RestClusterHealthAction extends BaseRestHandler {
84
85
XContentBuilder builder = RestXContentBuilder .restContentBuilder (request );
85
86
builder .startObject ();
86
87
87
- builder .field ("cluster_name" , response .clusterName ());
88
- builder .field ("status" , response .status ().name ().toLowerCase ());
89
- builder .field ("timed_out" , response .timedOut ());
90
- builder .field ("number_of_nodes" , response .numberOfNodes ());
91
- builder .field ("active_primary_shards" , response .activePrimaryShards ());
92
- builder .field ("active_shards" , response .activeShards ());
93
- builder .field ("relocating_shards" , response .relocatingShards ());
94
- builder .field ("initializing_shards" , response .initializingShards ());
95
- builder .field ("unassigned_shards" , response .unassignedShards ());
88
+ builder .field (Fields . CLUSTER_NAME , response .clusterName ());
89
+ builder .field (Fields . STATUS , response .status ().name ().toLowerCase ());
90
+ builder .field (Fields . TIMED_OUT , response .timedOut ());
91
+ builder .field (Fields . NUMBER_OF_NODES , response .numberOfNodes ());
92
+ builder .field (Fields . ACTIVE_PRIMARY_SHARDS , response .activePrimaryShards ());
93
+ builder .field (Fields . ACTIVE_SHARDS , response .activeShards ());
94
+ builder .field (Fields . RELOCATING_SHARDS , response .relocatingShards ());
95
+ builder .field (Fields . INITIALIZING_SHARDS , response .initializingShards ());
96
+ builder .field (Fields . UNASSIGNED_SHARDS , response .unassignedShards ());
96
97
97
98
if (!response .validationFailures ().isEmpty ()) {
98
- builder .startArray ("validation_failures" );
99
+ builder .startArray (Fields . VALIDATION_FAILURES );
99
100
for (String validationFailure : response .validationFailures ()) {
100
101
builder .value (validationFailure );
101
102
}
@@ -106,7 +107,7 @@ public class RestClusterHealthAction extends BaseRestHandler {
106
107
builder .startObject (indexHealth .index ());
107
108
108
109
if (!indexHealth .validationFailures ().isEmpty ()) {
109
- builder .startArray ("validation_failures" );
110
+ builder .startArray (Fields . VALIDATION_FAILURES );
110
111
for (String validationFailure : indexHealth .validationFailures ()) {
111
112
builder .value (validationFailure );
112
113
}
@@ -120,39 +121,39 @@ public class RestClusterHealthAction extends BaseRestHandler {
120
121
}
121
122
122
123
if (fLevel > 0 ) {
123
- builder .startObject ("indices" );
124
+ builder .startObject (Fields . INDICES );
124
125
for (ClusterIndexHealth indexHealth : response ) {
125
- builder .startObject (indexHealth .index ());
126
+ builder .startObject (indexHealth .index (), XContentBuilder . FieldCaseConversion . NONE );
126
127
127
- builder .field ("status" , indexHealth .status ().name ().toLowerCase ());
128
- builder .field ("number_of_shards" , indexHealth .numberOfShards ());
129
- builder .field ("number_of_replicas" , indexHealth .numberOfReplicas ());
130
- builder .field ("active_primary_shards" , indexHealth .activePrimaryShards ());
131
- builder .field ("active_shards" , indexHealth .activeShards ());
132
- builder .field ("relocating_shards" , indexHealth .relocatingShards ());
133
- builder .field ("initializing_shards" , indexHealth .initializingShards ());
134
- builder .field ("unassigned_shards" , indexHealth .unassignedShards ());
128
+ builder .field (Fields . STATUS , indexHealth .status ().name ().toLowerCase ());
129
+ builder .field (Fields . NUMBER_OF_SHARDS , indexHealth .numberOfShards ());
130
+ builder .field (Fields . NUMBER_OF_REPLICAS , indexHealth .numberOfReplicas ());
131
+ builder .field (Fields . ACTIVE_PRIMARY_SHARDS , indexHealth .activePrimaryShards ());
132
+ builder .field (Fields . ACTIVE_SHARDS , indexHealth .activeShards ());
133
+ builder .field (Fields . RELOCATING_SHARDS , indexHealth .relocatingShards ());
134
+ builder .field (Fields . INITIALIZING_SHARDS , indexHealth .initializingShards ());
135
+ builder .field (Fields . UNASSIGNED_SHARDS , indexHealth .unassignedShards ());
135
136
136
137
if (!indexHealth .validationFailures ().isEmpty ()) {
137
- builder .startArray ("validation_failures" );
138
+ builder .startArray (Fields . VALIDATION_FAILURES );
138
139
for (String validationFailure : indexHealth .validationFailures ()) {
139
140
builder .value (validationFailure );
140
141
}
141
142
builder .endArray ();
142
143
}
143
144
144
145
if (fLevel > 1 ) {
145
- builder .startObject ("shards" );
146
+ builder .startObject (Fields . SHARDS );
146
147
147
148
for (ClusterShardHealth shardHealth : indexHealth ) {
148
149
builder .startObject (Integer .toString (shardHealth .id ()));
149
150
150
- builder .field ("status" , shardHealth .status ().name ().toLowerCase ());
151
- builder .field ("primary_active" , shardHealth .primaryActive ());
152
- builder .field ("active_shards" , shardHealth .activeShards ());
153
- builder .field ("relocating_shards" , shardHealth .relocatingShards ());
154
- builder .field ("initializing_shards" , shardHealth .initializingShards ());
155
- builder .field ("unassigned_shards" , shardHealth .unassignedShards ());
151
+ builder .field (Fields . STATUS , shardHealth .status ().name ().toLowerCase ());
152
+ builder .field (Fields . PRIMARY_ACTIVE , shardHealth .primaryActive ());
153
+ builder .field (Fields . ACTIVE_SHARDS , shardHealth .activeShards ());
154
+ builder .field (Fields . RELOCATING_SHARDS , shardHealth .relocatingShards ());
155
+ builder .field (Fields . INITIALIZING_SHARDS , shardHealth .initializingShards ());
156
+ builder .field (Fields . UNASSIGNED_SHARDS , shardHealth .unassignedShards ());
156
157
157
158
builder .endObject ();
158
159
}
@@ -182,4 +183,22 @@ public class RestClusterHealthAction extends BaseRestHandler {
182
183
}
183
184
});
184
185
}
186
+
187
+ static final class Fields {
188
+ static final XContentBuilderString CLUSTER_NAME = new XContentBuilderString ("cluster_name" );
189
+ static final XContentBuilderString STATUS = new XContentBuilderString ("status" );
190
+ static final XContentBuilderString TIMED_OUT = new XContentBuilderString ("timed_out" );
191
+ static final XContentBuilderString NUMBER_OF_SHARDS = new XContentBuilderString ("number_of_shards" );
192
+ static final XContentBuilderString NUMBER_OF_REPLICAS = new XContentBuilderString ("number_of_replicas" );
193
+ static final XContentBuilderString NUMBER_OF_NODES = new XContentBuilderString ("number_of_nodes" );
194
+ static final XContentBuilderString ACTIVE_PRIMARY_SHARDS = new XContentBuilderString ("active_primary_shards" );
195
+ static final XContentBuilderString ACTIVE_SHARDS = new XContentBuilderString ("active_shards" );
196
+ static final XContentBuilderString RELOCATING_SHARDS = new XContentBuilderString ("relocating_shards" );
197
+ static final XContentBuilderString INITIALIZING_SHARDS = new XContentBuilderString ("initializing_shards" );
198
+ static final XContentBuilderString UNASSIGNED_SHARDS = new XContentBuilderString ("unassigned_shards" );
199
+ static final XContentBuilderString VALIDATION_FAILURES = new XContentBuilderString ("validation_failures" );
200
+ static final XContentBuilderString INDICES = new XContentBuilderString ("indices" );
201
+ static final XContentBuilderString SHARDS = new XContentBuilderString ("shards" );
202
+ static final XContentBuilderString PRIMARY_ACTIVE = new XContentBuilderString ("primary_active" );
203
+ }
185
204
}
0 commit comments