Skip to content

Commit 84d04a6

Browse files
authored
Rename methods in ChunkedToXContentHelper to be clearer (#119342)
1 parent 844594a commit 84d04a6

File tree

35 files changed

+141
-145
lines changed

35 files changed

+141
-145
lines changed

modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/IngestGeoIpMetadata.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public static IngestGeoIpMetadata fromXContent(XContentParser parser) throws IOE
9292

9393
@Override
9494
public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params ignored) {
95-
return Iterators.concat(ChunkedToXContentHelper.xContentValuesMap(DATABASES_FIELD.getPreferredName(), databases));
95+
return Iterators.concat(ChunkedToXContentHelper.xContentObjectFields(DATABASES_FIELD.getPreferredName(), databases));
9696
}
9797

9898
@Override

server/src/main/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplanation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import java.util.Locale;
3838

3939
import static org.elasticsearch.cluster.routing.allocation.AbstractAllocationDecision.discoveryNodeToXContent;
40-
import static org.elasticsearch.common.xcontent.ChunkedToXContentHelper.singleChunk;
40+
import static org.elasticsearch.common.xcontent.ChunkedToXContentHelper.chunk;
4141

4242
/**
4343
* A {@code ClusterAllocationExplanation} is an explanation of why a shard is unassigned,
@@ -169,7 +169,7 @@ public ShardAllocationDecision getShardAllocationDecision() {
169169
}
170170

171171
public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params params) {
172-
return Iterators.concat(singleChunk((builder, p) -> {
172+
return Iterators.concat(chunk((builder, p) -> {
173173
builder.startObject();
174174

175175
if (isSpecificShard() == false) {

server/src/main/java/org/elasticsearch/action/admin/cluster/allocation/DesiredBalanceResponse.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
import java.util.Objects;
3434
import java.util.Set;
3535

36+
import static org.elasticsearch.common.xcontent.ChunkedToXContentHelper.chunk;
3637
import static org.elasticsearch.common.xcontent.ChunkedToXContentHelper.endObject;
37-
import static org.elasticsearch.common.xcontent.ChunkedToXContentHelper.singleChunk;
3838
import static org.elasticsearch.common.xcontent.ChunkedToXContentHelper.startObject;
3939

4040
public class DesiredBalanceResponse extends ActionResponse implements ChunkedToXContentObject {
@@ -88,7 +88,7 @@ public void writeTo(StreamOutput out) throws IOException {
8888
@Override
8989
public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params params) {
9090
return Iterators.concat(
91-
singleChunk(
91+
chunk(
9292
(builder, p) -> builder.startObject()
9393
.field("stats", stats)
9494
.field("cluster_balance_stats", clusterBalanceStats)
@@ -101,16 +101,16 @@ public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params params
101101
Iterators.flatMap(
102102
indexEntry.getValue().entrySet().iterator(),
103103
shardEntry -> Iterators.concat(
104-
singleChunk((builder, p) -> builder.field(String.valueOf(shardEntry.getKey()))),
104+
chunk((builder, p) -> builder.field(String.valueOf(shardEntry.getKey()))),
105105
shardEntry.getValue().toXContentChunked(params)
106106
)
107107
),
108108
endObject()
109109
)
110110
),
111-
singleChunk((builder, p) -> builder.endObject().startObject("cluster_info")),
111+
chunk((builder, p) -> builder.endObject().startObject("cluster_info")),
112112
clusterInfo.toXContentChunked(params),
113-
singleChunk((builder, p) -> builder.endObject().endObject())
113+
chunk((builder, p) -> builder.endObject().endObject())
114114
);
115115
}
116116

@@ -173,9 +173,9 @@ public void writeTo(StreamOutput out) throws IOException {
173173
@Override
174174
public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params params) {
175175
return Iterators.concat(
176-
singleChunk((builder, p) -> builder.startObject().startArray("current")),
176+
chunk((builder, p) -> builder.startObject().startArray("current")),
177177
current().iterator(),
178-
singleChunk((builder, p) -> builder.endArray().field("desired").value(desired, p).endObject())
178+
chunk((builder, p) -> builder.endArray().field("desired").value(desired, p).endObject())
179179
);
180180
}
181181
}

server/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodeStats.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
import java.util.Map;
4646
import java.util.Objects;
4747

48-
import static org.elasticsearch.common.xcontent.ChunkedToXContentHelper.singleChunk;
48+
import static org.elasticsearch.common.xcontent.ChunkedToXContentHelper.chunk;
4949

5050
/**
5151
* Node statistics (dynamic, changes depending on when created).
@@ -347,7 +347,7 @@ public void writeTo(StreamOutput out) throws IOException {
347347

348348
@Override
349349
public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params outerParams) {
350-
return Iterators.concat(singleChunk((builder, params) -> {
350+
return Iterators.concat(chunk((builder, params) -> {
351351
builder.field("name", getNode().getName());
352352
builder.field("transport_address", getNode().getAddress().toString());
353353
builder.field("host", getNode().getHostName());
@@ -369,9 +369,7 @@ public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params outerP
369369
return builder;
370370
}),
371371
ifPresent(getIndices()).toXContentChunked(outerParams),
372-
singleChunk(
373-
(builder, p) -> builder.value(ifPresent(getOs()), p).value(ifPresent(getProcess()), p).value(ifPresent(getJvm()), p)
374-
),
372+
chunk((builder, p) -> builder.value(ifPresent(getOs()), p).value(ifPresent(getProcess()), p).value(ifPresent(getJvm()), p)),
375373
ifPresent(getThreadPool()).toXContentChunked(outerParams),
376374
singleChunkIfPresent(getFs()),
377375
ifPresent(getTransport()).toXContentChunked(outerParams),
@@ -382,7 +380,7 @@ public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params outerP
382380
ifPresent(getIngestStats()).toXContentChunked(outerParams),
383381
singleChunkIfPresent(getAdaptiveSelectionStats()),
384382
singleChunkIfPresent(getScriptCacheStats()),
385-
singleChunk(
383+
chunk(
386384
(builder, p) -> builder.value(ifPresent(getIndexingPressureStats()), p)
387385
.value(ifPresent(getRepositoriesStats()), p)
388386
.value(ifPresent(getNodeAllocationStats()), p)
@@ -399,6 +397,6 @@ private static ToXContent ifPresent(@Nullable ToXContent toXContent) {
399397
}
400398

401399
private static Iterator<ToXContent> singleChunkIfPresent(ToXContent toXContent) {
402-
return toXContent == null ? Collections.emptyIterator() : ChunkedToXContentHelper.singleChunk(toXContent);
400+
return toXContent == null ? Collections.emptyIterator() : ChunkedToXContentHelper.chunk(toXContent);
403401
}
404402
}

server/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params outerP
9797
return Iterators.concat(
9898
Iterators.single((builder, params) -> builder.startObject().field(ACKNOWLEDGED_KEY, isAcknowledged())),
9999
emitState(outerParams)
100-
? ChunkedToXContentHelper.wrapWithObject("state", state.toXContentChunked(outerParams))
100+
? ChunkedToXContentHelper.object("state", state.toXContentChunked(outerParams))
101101
: Collections.emptyIterator(),
102102
Iterators.single((builder, params) -> {
103103
if (params.paramAsBoolean("explain", false)) {

server/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentResponse.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ protected Iterator<ToXContent> customXContentChunks(ToXContent.Params params) {
7878
getIndices().values().iterator(),
7979
indexSegments -> Iterators.concat(
8080

81-
ChunkedToXContentHelper.singleChunk(
82-
(builder, p) -> builder.startObject(indexSegments.getIndex()).startObject(Fields.SHARDS)
83-
),
81+
ChunkedToXContentHelper.chunk((builder, p) -> builder.startObject(indexSegments.getIndex()).startObject(Fields.SHARDS)),
8482
Iterators.flatMap(
8583
indexSegments.iterator(),
8684
indexSegment -> Iterators.concat(
@@ -90,7 +88,7 @@ protected Iterator<ToXContent> customXContentChunks(ToXContent.Params params) {
9088
indexSegment.iterator(),
9189
shardSegments -> Iterators.concat(
9290

93-
ChunkedToXContentHelper.singleChunk((builder, p) -> {
91+
ChunkedToXContentHelper.chunk((builder, p) -> {
9492
builder.startObject();
9593

9694
builder.startObject(Fields.ROUTING);
@@ -112,7 +110,7 @@ protected Iterator<ToXContent> customXContentChunks(ToXContent.Params params) {
112110
shardSegments.iterator(),
113111
segment -> Iterators.concat(
114112

115-
ChunkedToXContentHelper.singleChunk((builder, p) -> {
113+
ChunkedToXContentHelper.chunk((builder, p) -> {
116114
builder.startObject(segment.getName());
117115
builder.field(Fields.GENERATION, segment.getGeneration());
118116
builder.field(Fields.NUM_DOCS, segment.getNumDocs());
@@ -132,7 +130,7 @@ protected Iterator<ToXContent> customXContentChunks(ToXContent.Params params) {
132130
return builder;
133131
}),
134132
getSegmentSortChunks(segment.getSegmentSort()),
135-
ChunkedToXContentHelper.singleChunk((builder, p) -> {
133+
ChunkedToXContentHelper.chunk((builder, p) -> {
136134
if (segment.attributes != null && segment.attributes.isEmpty() == false) {
137135
builder.field("attributes", segment.attributes);
138136
}
@@ -141,13 +139,13 @@ protected Iterator<ToXContent> customXContentChunks(ToXContent.Params params) {
141139
})
142140
)
143141
),
144-
ChunkedToXContentHelper.singleChunk((builder, p) -> builder.endObject().endObject())
142+
ChunkedToXContentHelper.chunk((builder, p) -> builder.endObject().endObject())
145143
)
146144
),
147145
ChunkedToXContentHelper.endArray()
148146
)
149147
),
150-
ChunkedToXContentHelper.singleChunk((builder, p) -> builder.endObject().endObject())
148+
ChunkedToXContentHelper.chunk((builder, p) -> builder.endObject().endObject())
151149
)
152150
),
153151
ChunkedToXContentHelper.endObject()

server/src/main/java/org/elasticsearch/action/admin/indices/stats/FieldUsageStatsResponse.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ protected Iterator<ToXContent> customXContentChunks(ToXContent.Params params) {
5050
return Iterators.flatMap(
5151
stats.entrySet().stream().sorted(Map.Entry.comparingByKey()).iterator(),
5252
entry -> Iterators.concat(
53-
ChunkedToXContentHelper.singleChunk((builder, p) -> builder.startObject(entry.getKey()).startArray("shards")),
53+
ChunkedToXContentHelper.chunk((builder, p) -> builder.startObject(entry.getKey()).startArray("shards")),
5454
entry.getValue().iterator(),
55-
ChunkedToXContentHelper.singleChunk((builder, p) -> builder.endArray().endObject())
55+
ChunkedToXContentHelper.chunk((builder, p) -> builder.endArray().endObject())
5656
)
5757
);
5858
}

server/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsResponse.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,15 @@ protected Iterator<ToXContent> customXContentChunks(ToXContent.Params params) {
204204
if (level == ClusterStatsLevel.INDICES || level == ClusterStatsLevel.SHARDS) {
205205
return Iterators.concat(
206206

207-
ChunkedToXContentHelper.singleChunk((builder, p) -> {
207+
ChunkedToXContentHelper.chunk((builder, p) -> {
208208
commonStats(builder, p);
209209
return builder.startObject(Fields.INDICES);
210210
}),
211211
Iterators.flatMap(
212212
getIndices().values().iterator(),
213213
indexStats -> Iterators.concat(
214214

215-
ChunkedToXContentHelper.singleChunk((builder, p) -> {
215+
ChunkedToXContentHelper.chunk((builder, p) -> {
216216
builder.startObject(indexStats.getIndex());
217217
builder.field("uuid", indexStats.getUuid());
218218
if (indexStats.getHealth() != null) {
@@ -257,7 +257,7 @@ protected Iterator<ToXContent> customXContentChunks(ToXContent.Params params) {
257257
ChunkedToXContentHelper.endObject()
258258
);
259259
} else {
260-
return ChunkedToXContentHelper.singleChunk((builder, p) -> {
260+
return ChunkedToXContentHelper.chunk((builder, p) -> {
261261
commonStats(builder, p);
262262
return builder;
263263
});

server/src/main/java/org/elasticsearch/action/search/SearchResponse.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,13 +391,13 @@ public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params params
391391

392392
public Iterator<? extends ToXContent> innerToXContentChunked(ToXContent.Params params) {
393393
return Iterators.concat(
394-
ChunkedToXContentHelper.singleChunk(SearchResponse.this::headerToXContent),
394+
ChunkedToXContentHelper.chunk(SearchResponse.this::headerToXContent),
395395
Iterators.single(clusters),
396396
Iterators.concat(
397397
hits.toXContentChunked(params),
398-
aggregations == null ? Collections.emptyIterator() : ChunkedToXContentHelper.singleChunk(aggregations),
399-
suggest == null ? Collections.emptyIterator() : ChunkedToXContentHelper.singleChunk(suggest),
400-
profileResults == null ? Collections.emptyIterator() : ChunkedToXContentHelper.singleChunk(profileResults)
398+
aggregations == null ? Collections.emptyIterator() : ChunkedToXContentHelper.chunk(aggregations),
399+
suggest == null ? Collections.emptyIterator() : ChunkedToXContentHelper.chunk(suggest),
400+
profileResults == null ? Collections.emptyIterator() : ChunkedToXContentHelper.chunk(profileResults)
401401
)
402402
);
403403
}

server/src/main/java/org/elasticsearch/cluster/ClusterInfo.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636

3737
import static org.elasticsearch.cluster.routing.ShardRouting.newUnassigned;
3838
import static org.elasticsearch.cluster.routing.UnassignedInfo.Reason.REINITIALIZED;
39+
import static org.elasticsearch.common.xcontent.ChunkedToXContentHelper.chunk;
3940
import static org.elasticsearch.common.xcontent.ChunkedToXContentHelper.endArray;
40-
import static org.elasticsearch.common.xcontent.ChunkedToXContentHelper.singleChunk;
4141
import static org.elasticsearch.common.xcontent.ChunkedToXContentHelper.startObject;
4242

4343
/**
@@ -162,7 +162,7 @@ public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params params
162162
}
163163
return builder.endObject(); // end $nodename
164164
}),
165-
singleChunk(
165+
chunk(
166166
(builder, p) -> builder.endObject() // end "nodes"
167167
.startObject("shard_sizes")
168168
),
@@ -171,7 +171,7 @@ public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params params
171171
shardSizes.entrySet().iterator(),
172172
c -> (builder, p) -> builder.humanReadableField(c.getKey() + "_bytes", c.getKey(), ByteSizeValue.ofBytes(c.getValue()))
173173
),
174-
singleChunk(
174+
chunk(
175175
(builder, p) -> builder.endObject() // end "shard_sizes"
176176
.startObject("shard_data_set_sizes")
177177
),
@@ -183,12 +183,12 @@ public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params params
183183
ByteSizeValue.ofBytes(c.getValue())
184184
)
185185
),
186-
singleChunk(
186+
chunk(
187187
(builder, p) -> builder.endObject() // end "shard_data_set_sizes"
188188
.startObject("shard_paths")
189189
),
190190
Iterators.map(dataPath.entrySet().iterator(), c -> (builder, p) -> builder.field(c.getKey().toString(), c.getValue())),
191-
singleChunk(
191+
chunk(
192192
(builder, p) -> builder.endObject() // end "shard_paths"
193193
.startArray("reserved_sizes")
194194
),

0 commit comments

Comments
 (0)