Skip to content

Commit f485ccb

Browse files
committed
Remove deprecated Metadata.Builder#putProjectCustom
Replaces the deprecated method with appropriate substitute.
1 parent a27784b commit f485ccb

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

server/src/main/java/org/elasticsearch/cluster/metadata/Metadata.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,7 @@ public static Metadata readFrom(StreamInput in) throws IOException {
12101210
for (int i = 0; i < size; i++) {
12111211
projectBuilder.put(IndexTemplateMetadata.readFrom(in));
12121212
}
1213-
readBwcCustoms(in, builder);
1213+
readBwcCustoms(in, builder, projectBuilder);
12141214

12151215
int reservedStateSize = in.readVInt();
12161216
for (int i = 0; i < reservedStateSize; i++) {
@@ -1229,7 +1229,7 @@ public static Metadata readFrom(StreamInput in) throws IOException {
12291229
return builder.build();
12301230
}
12311231

1232-
private static void readBwcCustoms(StreamInput in, Builder builder) throws IOException {
1232+
private static void readBwcCustoms(StreamInput in, Builder builder, ProjectMetadata.Builder projectBuilder) throws IOException {
12331233
final Set<String> clusterScopedNames = in.namedWriteableRegistry().getReaders(ClusterCustom.class).keySet();
12341234
final Set<String> projectScopedNames = in.namedWriteableRegistry().getReaders(ProjectCustom.class).keySet();
12351235
final int count = in.readVInt();
@@ -1245,9 +1245,9 @@ private static void readBwcCustoms(StreamInput in, Builder builder) throws IOExc
12451245
if (custom instanceof PersistentTasksCustomMetadata persistentTasksCustomMetadata) {
12461246
final var tuple = persistentTasksCustomMetadata.split();
12471247
builder.putCustom(tuple.v1().getWriteableName(), tuple.v1());
1248-
builder.putProjectCustom(tuple.v2().getWriteableName(), tuple.v2());
1248+
projectBuilder.putCustom(tuple.v2().getWriteableName(), tuple.v2());
12491249
} else {
1250-
builder.putProjectCustom(custom.getWriteableName(), custom);
1250+
projectBuilder.putCustom(custom.getWriteableName(), custom);
12511251
}
12521252
} else {
12531253
throw new IllegalArgumentException("Unknown custom name [" + name + "]");
@@ -1569,7 +1569,8 @@ public Builder putCustom(String type, ClusterCustom custom) {
15691569

15701570
@Deprecated(forRemoval = true)
15711571
public Builder putCustom(String type, ProjectCustom custom) {
1572-
return putProjectCustom(type, custom);
1572+
getSingleProject().putCustom(type, Objects.requireNonNull(custom, type));
1573+
return this;
15731574
}
15741575

15751576
public ClusterCustom getCustom(String type) {
@@ -1592,12 +1593,6 @@ public Builder customs(Map<String, ClusterCustom> clusterCustoms) {
15921593
return this;
15931594
}
15941595

1595-
@Deprecated(forRemoval = true)
1596-
public Builder putProjectCustom(String type, ProjectCustom custom) {
1597-
getSingleProject().putCustom(type, Objects.requireNonNull(custom, type));
1598-
return this;
1599-
}
1600-
16011596
@Deprecated(forRemoval = true)
16021597
public Builder projectCustoms(Map<String, ProjectCustom> projectCustoms) {
16031598
projectCustoms.forEach((key, value) -> Objects.requireNonNull(value, key));

server/src/test/java/org/elasticsearch/cluster/metadata/MetadataPersistentTasksTests.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,13 +306,16 @@ private Tuple<Metadata, Metadata> randomMetadataAndUpdate() {
306306
ClusterPersistentTasksCustomMetadata::new
307307
)
308308
)
309-
.putProjectCustom(
310-
PersistentTasksCustomMetadata.TYPE,
311-
mutatePersistentTasks(
312-
PersistentTasksCustomMetadata.get(before.getProject(Metadata.DEFAULT_PROJECT_ID)),
313-
MetadataPersistentTasksTests::oneProjectPersistentTask,
314-
PersistentTasksCustomMetadata::new
315-
)
309+
.put(
310+
ProjectMetadata.builder(before.getProject(Metadata.DEFAULT_PROJECT_ID))
311+
.putCustom(
312+
PersistentTasksCustomMetadata.TYPE,
313+
mutatePersistentTasks(
314+
PersistentTasksCustomMetadata.get(before.getProject(Metadata.DEFAULT_PROJECT_ID)),
315+
MetadataPersistentTasksTests::oneProjectPersistentTask,
316+
PersistentTasksCustomMetadata::new
317+
)
318+
)
316319
)
317320
.build();
318321
return new Tuple<>(before, after);

server/src/test/java/org/elasticsearch/cluster/metadata/MetadataTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1359,7 +1359,6 @@ public void testBuilderRejectsNullCustom() {
13591359
expectThrows(NullPointerException.class, () -> builder.putCustom(key, (Metadata.ClusterCustom) null)).getMessage(),
13601360
containsString(key)
13611361
);
1362-
assertThat(expectThrows(NullPointerException.class, () -> builder.putProjectCustom(key, null)).getMessage(), containsString(key));
13631362
}
13641363

13651364
public void testBuilderRejectsNullInCustoms() {

0 commit comments

Comments
 (0)