Remove RepositoriesMetaData variadic constructor (#29569)

The variadic constructor was only used in a few places and the
RepositoriesMetaData class is backed by a List anyway, so just using a
List will make it simpler to instantiate it.
This commit is contained in:
Michael Basnight 2018-05-01 15:02:06 -05:00 committed by GitHub
parent cdae8ff5a0
commit 62a9b8909e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 14 additions and 13 deletions

View File

@ -50,8 +50,8 @@ public class RepositoriesMetaData extends AbstractNamedDiffable<Custom> implemen
* *
* @param repositories list of repositories * @param repositories list of repositories
*/ */
public RepositoriesMetaData(RepositoryMetaData... repositories) { public RepositoriesMetaData(List<RepositoryMetaData> repositories) {
this.repositories = Arrays.asList(repositories); this.repositories = repositories;
} }
/** /**
@ -164,7 +164,7 @@ public class RepositoriesMetaData extends AbstractNamedDiffable<Custom> implemen
throw new ElasticsearchParseException("failed to parse repositories"); throw new ElasticsearchParseException("failed to parse repositories");
} }
} }
return new RepositoriesMetaData(repository.toArray(new RepositoryMetaData[repository.size()])); return new RepositoriesMetaData(repository);
} }
/** /**

View File

@ -114,7 +114,8 @@ public class RepositoriesService extends AbstractComponent implements ClusterSta
RepositoriesMetaData repositories = metaData.custom(RepositoriesMetaData.TYPE); RepositoriesMetaData repositories = metaData.custom(RepositoriesMetaData.TYPE);
if (repositories == null) { if (repositories == null) {
logger.info("put repository [{}]", request.name); 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 { } else {
boolean found = false; boolean found = false;
List<RepositoryMetaData> repositoriesMetaData = new ArrayList<>(repositories.repositories().size() + 1); List<RepositoryMetaData> repositoriesMetaData = new ArrayList<>(repositories.repositories().size() + 1);
@ -133,7 +134,7 @@ public class RepositoriesService extends AbstractComponent implements ClusterSta
} else { } else {
logger.info("update repository [{}]", request.name); logger.info("update repository [{}]", request.name);
} }
repositories = new RepositoriesMetaData(repositoriesMetaData.toArray(new RepositoryMetaData[repositoriesMetaData.size()])); repositories = new RepositoriesMetaData(repositoriesMetaData);
} }
mdBuilder.putCustom(RepositoriesMetaData.TYPE, repositories); mdBuilder.putCustom(RepositoriesMetaData.TYPE, repositories);
return ClusterState.builder(currentState).metaData(mdBuilder).build(); return ClusterState.builder(currentState).metaData(mdBuilder).build();
@ -185,7 +186,7 @@ public class RepositoriesService extends AbstractComponent implements ClusterSta
} }
} }
if (changed) { if (changed) {
repositories = new RepositoriesMetaData(repositoriesMetaData.toArray(new RepositoryMetaData[repositoriesMetaData.size()])); repositories = new RepositoriesMetaData(repositoriesMetaData);
mdBuilder.putCustom(RepositoriesMetaData.TYPE, repositories); mdBuilder.putCustom(RepositoriesMetaData.TYPE, repositories);
return ClusterState.builder(currentState).metaData(mdBuilder).build(); return ClusterState.builder(currentState).metaData(mdBuilder).build();
} }

View File

@ -640,7 +640,7 @@ public class ClusterStateDiffIT extends ESIntegTestCase {
@Override @Override
public MetaData.Custom randomCreate(String name) { public MetaData.Custom randomCreate(String name) {
if (randomBoolean()) { if (randomBoolean()) {
return new RepositoriesMetaData(); return new RepositoriesMetaData(Collections.emptyList());
} else { } else {
return IndexGraveyardTests.createRandom(); return IndexGraveyardTests.createRandom();
} }

View File

@ -45,7 +45,7 @@ public class RepositoriesMetaDataSerializationTests extends AbstractDiffableSeri
entries.add(new RepositoryMetaData(randomAlphaOfLength(10), randomAlphaOfLength(10), randomSettings())); entries.add(new RepositoryMetaData(randomAlphaOfLength(10), randomAlphaOfLength(10), randomSettings()));
} }
entries.sort(Comparator.comparing(RepositoryMetaData::name)); entries.sort(Comparator.comparing(RepositoryMetaData::name));
return new RepositoriesMetaData(entries.toArray(new RepositoryMetaData[entries.size()])); return new RepositoriesMetaData(entries);
} }
@Override @Override
@ -62,7 +62,7 @@ public class RepositoriesMetaDataSerializationTests extends AbstractDiffableSeri
} else { } else {
entries.remove(randomIntBetween(0, entries.size() - 1)); entries.remove(randomIntBetween(0, entries.size() - 1));
} }
return new RepositoriesMetaData(entries.toArray(new RepositoryMetaData[entries.size()])); return new RepositoriesMetaData(entries);
} }
public Settings randomSettings() { public Settings randomSettings() {
@ -94,7 +94,7 @@ public class RepositoriesMetaDataSerializationTests extends AbstractDiffableSeri
repos.add(new RepositoryMetaData(randomAlphaOfLength(10), randomAlphaOfLength(10), randomSettings())); repos.add(new RepositoryMetaData(randomAlphaOfLength(10), randomAlphaOfLength(10), randomSettings()));
} }
} }
return new RepositoriesMetaData(repos.toArray(new RepositoryMetaData[repos.size()])); return new RepositoriesMetaData(repos);
} }
@Override @Override
@ -114,7 +114,7 @@ public class RepositoriesMetaDataSerializationTests extends AbstractDiffableSeri
assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken()); assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken());
List<RepositoryMetaData> repos = repositoriesMetaData.repositories(); List<RepositoryMetaData> repos = repositoriesMetaData.repositories();
repos.sort(Comparator.comparing(RepositoryMetaData::name)); repos.sort(Comparator.comparing(RepositoryMetaData::name));
return new RepositoriesMetaData(repos.toArray(new RepositoryMetaData[repos.size()])); return new RepositoriesMetaData(repos);
} }
} }

View File

@ -64,7 +64,7 @@ public class LicensesMetaDataSerializationTests extends ESTestCase {
License license = TestUtils.generateSignedLicense(TimeValue.timeValueHours(2)); License license = TestUtils.generateSignedLicense(TimeValue.timeValueHours(2));
LicensesMetaData licensesMetaData = new LicensesMetaData(license, Version.CURRENT); LicensesMetaData licensesMetaData = new LicensesMetaData(license, Version.CURRENT);
RepositoryMetaData repositoryMetaData = new RepositoryMetaData("repo", "fs", Settings.EMPTY); 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(); final MetaData.Builder metaDataBuilder = MetaData.builder();
if (randomBoolean()) { // random order of insertion if (randomBoolean()) { // random order of insertion
metaDataBuilder.putCustom(licensesMetaData.getWriteableName(), licensesMetaData); metaDataBuilder.putCustom(licensesMetaData.getWriteableName(), licensesMetaData);

View File

@ -47,7 +47,7 @@ public class WatcherMetaDataSerializationTests extends ESTestCase {
boolean manuallyStopped = randomBoolean(); boolean manuallyStopped = randomBoolean();
WatcherMetaData watcherMetaData = new WatcherMetaData(manuallyStopped); WatcherMetaData watcherMetaData = new WatcherMetaData(manuallyStopped);
RepositoryMetaData repositoryMetaData = new RepositoryMetaData("repo", "fs", Settings.EMPTY); 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(); final MetaData.Builder metaDataBuilder = MetaData.builder();
if (randomBoolean()) { // random order of insertion if (randomBoolean()) { // random order of insertion
metaDataBuilder.putCustom(watcherMetaData.getWriteableName(), watcherMetaData); metaDataBuilder.putCustom(watcherMetaData.getWriteableName(), watcherMetaData);