Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ChunkedToXContent;
import org.elasticsearch.common.xcontent.NewChunkedXContentBuilder;
import org.elasticsearch.ingest.geoip.direct.DatabaseConfigurationMetadata;
import org.elasticsearch.xcontent.ConstructingObjectParser;
import org.elasticsearch.xcontent.ParseField;
Expand Down Expand Up @@ -91,7 +91,7 @@ public static IngestGeoIpMetadata fromXContent(XContentParser parser) throws IOE

@Override
public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params params) {
return ChunkedToXContent.builder(params).xContentObjectFields(DATABASES_FIELD.getPreferredName(), databases);
return NewChunkedXContentBuilder.xContentObjectFields(DATABASES_FIELD.getPreferredName(), databases);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ChunkedToXContent;
import org.elasticsearch.common.xcontent.NewChunkedXContentBuilder;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.discovery.DiscoveryStats;
import org.elasticsearch.http.HttpStats;
Expand All @@ -42,6 +43,8 @@
import java.util.Map;
import java.util.Objects;

import static org.elasticsearch.common.xcontent.NewChunkedXContentBuilder.chunk;

/**
* Node statistics (dynamic, changes depending on when created).
*/
Expand Down Expand Up @@ -342,7 +345,7 @@ public void writeTo(StreamOutput out) throws IOException {

@Override
public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params outerParams) {
return ChunkedToXContent.builder(outerParams).append((builder, params) -> {
return NewChunkedXContentBuilder.of(chunk((builder, params) -> {
builder.field("name", getNode().getName());
builder.field("transport_address", getNode().getAddress().toString());
builder.field("host", getNode().getHostName());
Expand All @@ -362,29 +365,32 @@ public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params outerP
builder.endObject();
}
return builder;
})

.appendIfPresent(getIndices())
.append((builder, p) -> builder.value(ifPresent(getOs()), p).value(ifPresent(getProcess()), p).value(ifPresent(getJvm()), p))

.appendIfPresent(getThreadPool())
.appendIfPresent(getFs())
.appendIfPresent(getTransport())
.appendIfPresent(getHttp())
.appendIfPresent(getBreaker())
.appendIfPresent(getScriptStats())
.appendIfPresent(getDiscoveryStats())
.appendIfPresent(getIngestStats())
.appendIfPresent(getAdaptiveSelectionStats())
.appendIfPresent(getScriptCacheStats())
.append(
}),
ifPresent(getIndices()).toXContentChunked(outerParams),
chunk((builder, p) -> builder.value(ifPresent(getOs()), p).value(ifPresent(getProcess()), p).value(ifPresent(getJvm()), p)),
ifPresent(getThreadPool()).toXContentChunked(outerParams),
chunk(ifPresent(getFs())),
ifPresent(getTransport()).toXContentChunked(outerParams),
ifPresent(getHttp()).toXContentChunked(outerParams),
chunk(ifPresent(getBreaker())),
ifPresent(getScriptStats()).toXContentChunked(outerParams),
chunk(ifPresent(getDiscoveryStats())),
ifPresent(getIngestStats()).toXContentChunked(outerParams),
chunk(ifPresent(getAdaptiveSelectionStats())),
ifPresent(getScriptCacheStats()).toXContentChunked(outerParams),
chunk(
(builder, p) -> builder.value(ifPresent(getIndexingPressureStats()), p)
.value(ifPresent(getRepositoriesStats()), p)
.value(ifPresent(getNodeAllocationStats()), p)
);
)
);
}

private static ToXContent ifPresent(@Nullable ToXContent toXContent) {
return Objects.requireNonNullElse(toXContent, ToXContent.EMPTY);
}

private static ChunkedToXContent ifPresent(@Nullable ChunkedToXContent toXContent) {
return Objects.requireNonNullElse(toXContent, ChunkedToXContent.EMPTY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ChunkedToXContent;
import org.elasticsearch.common.xcontent.NewChunkedXContentBuilder;
import org.elasticsearch.xcontent.ToXContent;

import java.io.IOException;
import java.util.Iterator;
import java.util.List;

import static org.elasticsearch.common.collect.Iterators.flatMap;
import static org.elasticsearch.common.xcontent.NewChunkedXContentBuilder.chunk;

public class NodesStatsResponse extends BaseNodesXContentResponse<NodeStats> {

public NodesStatsResponse(ClusterName clusterName, List<NodeStats> nodes, List<FailedNodeException> failures) {
Expand All @@ -41,12 +44,17 @@ protected void writeNodesTo(StreamOutput out, List<NodeStats> nodes) throws IOEx

@Override
protected Iterator<? extends ToXContent> xContentChunks(ToXContent.Params outerParams) {
return ChunkedToXContent.builder(outerParams)
.object(
"nodes",
return NewChunkedXContentBuilder.object(
"nodes",
flatMap(
getNodes().iterator(),
(b, ns) -> b.object(ns.getNode().getId(), ob -> ob.field("timestamp", ns.getTimestamp()).append(ns))
);
ns -> NewChunkedXContentBuilder.object(
ns.getNode().getId(),
chunk((b, p) -> b.field("timestamp", ns.getTimestamp())),
ns.toXContentChunked(outerParams)
)
)
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.logging.DeprecationCategory;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.xcontent.ChunkedToXContent;
import org.elasticsearch.common.xcontent.ChunkedToXContentObject;
import org.elasticsearch.common.xcontent.NewChunkedXContentBuilder;
import org.elasticsearch.core.RestApiVersion;
import org.elasticsearch.core.UpdateForV10;
import org.elasticsearch.rest.action.search.RestSearchAction;
Expand All @@ -29,6 +29,9 @@
import java.util.Objects;

import static org.elasticsearch.action.support.master.AcknowledgedResponse.ACKNOWLEDGED_KEY;
import static org.elasticsearch.common.xcontent.NewChunkedXContentBuilder.chunk;
import static org.elasticsearch.common.xcontent.NewChunkedXContentBuilder.empty;
import static org.elasticsearch.common.xcontent.NewChunkedXContentBuilder.object;

/**
* Response returned after a cluster reroute request
Expand Down Expand Up @@ -92,14 +95,12 @@ public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params outerP
if (emitState(outerParams)) {
deprecationLogger.critical(DeprecationCategory.API, "reroute_cluster_state", STATE_FIELD_DEPRECATION_MESSAGE);
}
return ChunkedToXContent.builder(outerParams).object(b -> {
b.field(ACKNOWLEDGED_KEY, isAcknowledged());
if (emitState(outerParams)) {
b.xContentObject("state", state);
}
if (outerParams.paramAsBoolean("explain", false)) {
b.append(explanations);
}
});
return NewChunkedXContentBuilder.of(
object(
chunk((b, p) -> b.field(ACKNOWLEDGED_KEY, isAcknowledged())),
emitState(outerParams) ? NewChunkedXContentBuilder.object("state", state.toXContentChunked(outerParams)) : empty(),
outerParams.paramAsBoolean("explain", false) ? chunk(explanations) : empty()
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@
import org.elasticsearch.common.collect.Iterators;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ChunkedToXContent;
import org.elasticsearch.common.xcontent.ChunkedToXContentObject;
import org.elasticsearch.common.xcontent.NewChunkedXContentBuilder;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.xcontent.ToXContent;

import java.io.IOException;
import java.util.Iterator;

import static org.elasticsearch.common.xcontent.NewChunkedXContentBuilder.array;
import static org.elasticsearch.common.xcontent.NewChunkedXContentBuilder.chunk;
import static org.elasticsearch.common.xcontent.NewChunkedXContentBuilder.object;

/**
* A response of a bulk execution. Holding a response for each item responding (in order) of the
* bulk requests. Each item holds the index/type/id is operated on, and if it failed or not (with the
Expand Down Expand Up @@ -158,13 +162,13 @@ public void writeTo(StreamOutput out) throws IOException {

@Override
public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params params) {
return ChunkedToXContent.builder(params).object(ob -> ob.append((b, p) -> {
return NewChunkedXContentBuilder.of(object(chunk((b, p) -> {
b.field(ERRORS, hasFailures());
b.field(TOOK, tookInMillis);
if (ingestTookInMillis != BulkResponse.NO_INGEST_TOOK) {
b.field(INGEST_TOOK, ingestTookInMillis);
}
return b;
}).array(ITEMS, Iterators.forArray(responses)));
}), array(ITEMS, Iterators.forArray(responses))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
import org.elasticsearch.common.xcontent.ChunkedToXContent;
import org.elasticsearch.common.xcontent.ChunkedToXContentObject;
import org.elasticsearch.common.xcontent.NewChunkedXContentBuilder;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.core.RefCounted;
import org.elasticsearch.core.SimpleRefCounted;
Expand Down Expand Up @@ -382,7 +383,7 @@ public Clusters getClusters() {
@Override
public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params params) {
assert hasReferences();
return ChunkedToXContent.builder(params).xContentObject(innerToXContentChunked(params));
return NewChunkedXContentBuilder.object(innerToXContentChunked(params));
}

public Iterator<? extends ToXContent> innerToXContentChunked(ToXContent.Params params) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@

import org.elasticsearch.action.support.DefaultShardOperationFailedException;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.xcontent.ChunkedToXContent;
import org.elasticsearch.common.xcontent.ChunkedToXContentObject;
import org.elasticsearch.common.xcontent.NewChunkedXContentBuilder;
import org.elasticsearch.rest.action.RestActions;
import org.elasticsearch.xcontent.ToXContent;

import java.io.IOException;
import java.util.Iterator;
import java.util.List;

import static org.elasticsearch.common.xcontent.NewChunkedXContentBuilder.chunk;
import static org.elasticsearch.common.xcontent.NewChunkedXContentBuilder.object;

public abstract class ChunkedBroadcastResponse extends BaseBroadcastResponse implements ChunkedToXContentObject {
public ChunkedBroadcastResponse(StreamInput in) throws IOException {
super(in);
Expand All @@ -34,9 +37,10 @@ public ChunkedBroadcastResponse(
}

@Override
public final Iterator<ToXContent> toXContentChunked(ToXContent.Params params) {
return ChunkedToXContent.builder(params)
.object(ob -> ob.append((b, p) -> RestActions.buildBroadcastShardsHeader(b, p, this)).append(this::customXContentChunks));
public final Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params params) {
return NewChunkedXContentBuilder.of(
object(chunk((b, p) -> RestActions.buildBroadcastShardsHeader(b, p, this)), customXContentChunks(params))
);
}

protected abstract Iterator<ToXContent> customXContentChunks(ToXContent.Params params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@

import org.elasticsearch.action.FailedNodeException;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.common.xcontent.ChunkedToXContent;
import org.elasticsearch.common.xcontent.ChunkedToXContentObject;
import org.elasticsearch.common.xcontent.NewChunkedXContentBuilder;
import org.elasticsearch.rest.action.RestActions;
import org.elasticsearch.xcontent.ToXContent;

import java.util.Iterator;
import java.util.List;

import static org.elasticsearch.common.xcontent.NewChunkedXContentBuilder.chunk;
import static org.elasticsearch.common.xcontent.NewChunkedXContentBuilder.object;

public abstract class BaseNodesXContentResponse<TNodeResponse extends BaseNodeResponse> extends BaseNodesResponse<TNodeResponse>
implements
ChunkedToXContentObject {
Expand All @@ -29,12 +32,12 @@ protected BaseNodesXContentResponse(ClusterName clusterName, List<TNodeResponse>

@Override
public final Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params params) {
return ChunkedToXContent.builder(params)
.object(
ob -> ob.append((b, p) -> RestActions.buildNodesHeader(b, p, this))
.field("cluster_name", getClusterName().value())
.append(xContentChunks(params))
);
return NewChunkedXContentBuilder.of(
object(
chunk((b, p) -> RestActions.buildNodesHeader(b, p, this).field("cluster_name", getClusterName().value())),
xContentChunks(params)
)
);
}

protected abstract Iterator<? extends ToXContent> xContentChunks(ToXContent.Params outerParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ChunkedToXContent;
import org.elasticsearch.common.xcontent.ChunkedToXContentObject;
import org.elasticsearch.common.xcontent.NewChunkedXContentBuilder;
import org.elasticsearch.features.NodeFeature;
import org.elasticsearch.xcontent.ToXContent;

Expand All @@ -34,6 +34,9 @@
import java.util.TreeSet;
import java.util.stream.Collectors;

import static org.elasticsearch.common.collect.Iterators.map;
import static org.elasticsearch.common.xcontent.NewChunkedXContentBuilder.array;

/**
* Stores information on what features are present throughout the cluster
*/
Expand Down Expand Up @@ -278,12 +281,13 @@ public ClusterFeatures apply(ClusterFeatures part) {

@Override
public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params params) {
return ChunkedToXContent.builder(params)
.array(nodeFeatures.entrySet().stream().sorted(Map.Entry.comparingByKey()).iterator(), e -> (builder, p) -> {
return NewChunkedXContentBuilder.of(
array(map(nodeFeatures.entrySet().stream().sorted(Map.Entry.comparingByKey()).iterator(), e -> (builder, p) -> {
String[] features = e.getValue().toArray(String[]::new);
Arrays.sort(features);
return builder.startObject().field("node_id", e.getKey()).array("features", features).endObject();
});
}))
);
}

@Override
Expand Down
Loading