diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/RepositoriesMetaData.java b/server/src/main/java/org/elasticsearch/cluster/metadata/RepositoriesMetaData.java index 6aa2d83fa8d..7a0b9285896 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/RepositoriesMetaData.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/RepositoriesMetaData.java @@ -50,8 +50,8 @@ public class RepositoriesMetaData extends AbstractNamedDiffable implemen * * @param repositories list of repositories */ - public RepositoriesMetaData(RepositoryMetaData... repositories) { - this.repositories = Arrays.asList(repositories); + public RepositoriesMetaData(List repositories) { + this.repositories = repositories; } /** @@ -164,7 +164,7 @@ public class RepositoriesMetaData extends AbstractNamedDiffable implemen throw new ElasticsearchParseException("failed to parse repositories"); } } - return new RepositoriesMetaData(repository.toArray(new RepositoryMetaData[repository.size()])); + return new RepositoriesMetaData(repository); } /** diff --git a/server/src/main/java/org/elasticsearch/repositories/RepositoriesService.java b/server/src/main/java/org/elasticsearch/repositories/RepositoriesService.java index 577ccc78de7..636e108468e 100644 --- a/server/src/main/java/org/elasticsearch/repositories/RepositoriesService.java +++ b/server/src/main/java/org/elasticsearch/repositories/RepositoriesService.java @@ -114,7 +114,8 @@ public class RepositoriesService extends AbstractComponent implements ClusterSta RepositoriesMetaData repositories = metaData.custom(RepositoriesMetaData.TYPE); if (repositories == null) { logger.info("put repository [{}]", request.name); - repositories = new RepositoriesMetaData(new RepositoryMetaData(request.name, request.type, request.settings)); + repositories = new RepositoriesMetaData( + Collections.singletonList(new RepositoryMetaData(request.name, request.type, request.settings))); } else { boolean found = false; List repositoriesMetaData = new ArrayList<>(repositories.repositories().size() + 1); @@ -133,7 +134,7 @@ public class RepositoriesService extends AbstractComponent implements ClusterSta } else { logger.info("update repository [{}]", request.name); } - repositories = new RepositoriesMetaData(repositoriesMetaData.toArray(new RepositoryMetaData[repositoriesMetaData.size()])); + repositories = new RepositoriesMetaData(repositoriesMetaData); } mdBuilder.putCustom(RepositoriesMetaData.TYPE, repositories); return ClusterState.builder(currentState).metaData(mdBuilder).build(); @@ -185,7 +186,7 @@ public class RepositoriesService extends AbstractComponent implements ClusterSta } } if (changed) { - repositories = new RepositoriesMetaData(repositoriesMetaData.toArray(new RepositoryMetaData[repositoriesMetaData.size()])); + repositories = new RepositoriesMetaData(repositoriesMetaData); mdBuilder.putCustom(RepositoriesMetaData.TYPE, repositories); return ClusterState.builder(currentState).metaData(mdBuilder).build(); } diff --git a/server/src/test/java/org/elasticsearch/cluster/ClusterStateDiffIT.java b/server/src/test/java/org/elasticsearch/cluster/ClusterStateDiffIT.java index 29e3080bfe1..a5d865a2741 100644 --- a/server/src/test/java/org/elasticsearch/cluster/ClusterStateDiffIT.java +++ b/server/src/test/java/org/elasticsearch/cluster/ClusterStateDiffIT.java @@ -640,7 +640,7 @@ public class ClusterStateDiffIT extends ESIntegTestCase { @Override public MetaData.Custom randomCreate(String name) { if (randomBoolean()) { - return new RepositoriesMetaData(); + return new RepositoriesMetaData(Collections.emptyList()); } else { return IndexGraveyardTests.createRandom(); } diff --git a/server/src/test/java/org/elasticsearch/snapshots/RepositoriesMetaDataSerializationTests.java b/server/src/test/java/org/elasticsearch/snapshots/RepositoriesMetaDataSerializationTests.java index dc0c7b55c6d..7627dafa5a9 100644 --- a/server/src/test/java/org/elasticsearch/snapshots/RepositoriesMetaDataSerializationTests.java +++ b/server/src/test/java/org/elasticsearch/snapshots/RepositoriesMetaDataSerializationTests.java @@ -45,7 +45,7 @@ public class RepositoriesMetaDataSerializationTests extends AbstractDiffableSeri entries.add(new RepositoryMetaData(randomAlphaOfLength(10), randomAlphaOfLength(10), randomSettings())); } entries.sort(Comparator.comparing(RepositoryMetaData::name)); - return new RepositoriesMetaData(entries.toArray(new RepositoryMetaData[entries.size()])); + return new RepositoriesMetaData(entries); } @Override @@ -62,7 +62,7 @@ public class RepositoriesMetaDataSerializationTests extends AbstractDiffableSeri } else { entries.remove(randomIntBetween(0, entries.size() - 1)); } - return new RepositoriesMetaData(entries.toArray(new RepositoryMetaData[entries.size()])); + return new RepositoriesMetaData(entries); } public Settings randomSettings() { @@ -94,7 +94,7 @@ public class RepositoriesMetaDataSerializationTests extends AbstractDiffableSeri repos.add(new RepositoryMetaData(randomAlphaOfLength(10), randomAlphaOfLength(10), randomSettings())); } } - return new RepositoriesMetaData(repos.toArray(new RepositoryMetaData[repos.size()])); + return new RepositoriesMetaData(repos); } @Override @@ -114,7 +114,7 @@ public class RepositoriesMetaDataSerializationTests extends AbstractDiffableSeri assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken()); List repos = repositoriesMetaData.repositories(); repos.sort(Comparator.comparing(RepositoryMetaData::name)); - return new RepositoriesMetaData(repos.toArray(new RepositoryMetaData[repos.size()])); + return new RepositoriesMetaData(repos); } } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicensesMetaDataSerializationTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicensesMetaDataSerializationTests.java index b85a3480fa7..f3ed04ed22d 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicensesMetaDataSerializationTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicensesMetaDataSerializationTests.java @@ -64,7 +64,7 @@ public class LicensesMetaDataSerializationTests extends ESTestCase { License license = TestUtils.generateSignedLicense(TimeValue.timeValueHours(2)); LicensesMetaData licensesMetaData = new LicensesMetaData(license, Version.CURRENT); RepositoryMetaData repositoryMetaData = new RepositoryMetaData("repo", "fs", Settings.EMPTY); - RepositoriesMetaData repositoriesMetaData = new RepositoriesMetaData(repositoryMetaData); + RepositoriesMetaData repositoriesMetaData = new RepositoriesMetaData(Collections.singletonList(repositoryMetaData)); final MetaData.Builder metaDataBuilder = MetaData.builder(); if (randomBoolean()) { // random order of insertion metaDataBuilder.putCustom(licensesMetaData.getWriteableName(), licensesMetaData); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherMetaDataSerializationTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherMetaDataSerializationTests.java index 50a7fec4749..0556b8535e4 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherMetaDataSerializationTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherMetaDataSerializationTests.java @@ -47,7 +47,7 @@ public class WatcherMetaDataSerializationTests extends ESTestCase { boolean manuallyStopped = randomBoolean(); WatcherMetaData watcherMetaData = new WatcherMetaData(manuallyStopped); RepositoryMetaData repositoryMetaData = new RepositoryMetaData("repo", "fs", Settings.EMPTY); - RepositoriesMetaData repositoriesMetaData = new RepositoriesMetaData(repositoryMetaData); + RepositoriesMetaData repositoriesMetaData = new RepositoriesMetaData(Collections.singletonList(repositoryMetaData)); final MetaData.Builder metaDataBuilder = MetaData.builder(); if (randomBoolean()) { // random order of insertion metaDataBuilder.putCustom(watcherMetaData.getWriteableName(), watcherMetaData);