Skip to content
Merged
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 @@ -744,7 +744,26 @@ public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params p) {
// and not include it in the project xcontent output (through the lack of multi-project params)
clusterReservedState.putAll(project.reservedStateMetadata());

@FixForMultiProject(description = "consider include cluster-scoped persistent tasks")
// Similarly, combine cluster and project persistent tasks and report them under a single key
Iterator<ToXContent> customs = Iterators.flatMap(customs().entrySet().iterator(), entry -> {
if (entry.getValue().context().contains(context)
&& ClusterPersistentTasksCustomMetadata.TYPE.equals(entry.getKey()) == false) {
return ChunkedToXContentHelper.object(entry.getKey(), entry.getValue().toXContentChunked(p));
} else {
return Collections.emptyIterator();
}
});
final var combinedTasks = PersistentTasksCustomMetadata.combine(
ClusterPersistentTasksCustomMetadata.get(this),
PersistentTasksCustomMetadata.get(project)
);
if (combinedTasks != null) {
customs = Iterators.concat(
customs,
ChunkedToXContentHelper.object(PersistentTasksCustomMetadata.TYPE, combinedTasks.toXContentChunked(p))
);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally think this method is getting quite big and with the if-statement splitting the method pretty much in two big chunks, I'd be inclined to do some method extraction to keep it readable. That's more personal preference, so I'll leave it up to you if you feel like giving that a go.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me tackle this in a follow-up. I prefer it to be a separate, pure-refactor PR.

final var iterators = Iterators.concat(start, Iterators.single((builder, params) -> {
builder.field("cluster_uuid", clusterUUID);
builder.field("cluster_uuid_committed", clusterUUIDCommitted);
Expand All @@ -754,12 +773,7 @@ public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params p) {
}),
persistentSettings,
project.toXContentChunked(p),
Iterators.flatMap(
customs.entrySet().iterator(),
entry -> entry.getValue().context().contains(context)
? ChunkedToXContentHelper.object(entry.getKey(), entry.getValue().toXContentChunked(p))
: Collections.emptyIterator()
),
customs,
ChunkedToXContentHelper.object("reserved_state", clusterReservedState.values().iterator()),
ChunkedToXContentHelper.endObject()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.persistent.PersistentTasksCustomMetadata;
import org.elasticsearch.plugins.FieldPredicate;
import org.elasticsearch.plugins.MapperPlugin;
import org.elasticsearch.transport.Transports;
Expand Down Expand Up @@ -2111,14 +2112,18 @@ public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params p) {
? ChunkedToXContentHelper.object("indices", indices().values().iterator())
: Collections.emptyIterator();

Iterator<ToXContent> customs = Iterators.flatMap(
customs().entrySet().iterator(),
entry -> entry.getValue().context().contains(context)
? ChunkedToXContentHelper.object(entry.getKey(), entry.getValue().toXContentChunked(p))
: Collections.emptyIterator()
);

final var multiProject = p.paramAsBoolean("multi-project", false);
Iterator<ToXContent> customs = Iterators.flatMap(customs().entrySet().iterator(), entry -> {
if (entry.getValue().context().contains(context)
// Include persistent tasks in the output only when multi-project=true.
// In single-project-mode (multi-project=false), we already output them in Metadata.
&& (multiProject || PersistentTasksCustomMetadata.TYPE.equals(entry.getKey()) == false)) {
return ChunkedToXContentHelper.object(entry.getKey(), entry.getValue().toXContentChunked(p));
} else {
return Collections.emptyIterator();
}
});

return Iterators.concat(
ChunkedToXContentHelper.object(
"templates",
Expand Down
Loading