Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove RepositoriesMetaData variadic constructor #29569

Merged
merged 9 commits into from
May 1, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public class RepositoriesMetaData extends AbstractNamedDiffable<Custom> implemen
*
* @param repositories list of repositories
*/
public RepositoriesMetaData(RepositoryMetaData... repositories) {
this.repositories = Arrays.asList(repositories);
public RepositoriesMetaData(List<RepositoryMetaData> repositories) {
this.repositories = repositories;
}

/**
Expand Down Expand Up @@ -164,7 +164,7 @@ public static RepositoriesMetaData fromXContent(XContentParser parser) throws IO
throw new ElasticsearchParseException("failed to parse repositories");
}
}
return new RepositoriesMetaData(repository.toArray(new RepositoryMetaData[repository.size()]));
return new RepositoriesMetaData(repository);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ public ClusterState execute(ClusterState currentState) throws IOException {
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<RepositoryMetaData> repositoriesMetaData = new ArrayList<>(repositories.repositories().size() + 1);
Expand All @@ -133,7 +134,7 @@ public ClusterState execute(ClusterState currentState) throws IOException {
} 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();
Expand Down Expand Up @@ -185,7 +186,7 @@ public ClusterState execute(ClusterState currentState) {
}
}
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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ public MetaData.Builder remove(MetaData.Builder builder, String name) {
@Override
public MetaData.Custom randomCreate(String name) {
if (randomBoolean()) {
return new RepositoriesMetaData();
return new RepositoriesMetaData(Collections.emptyList());
} else {
return IndexGraveyardTests.createRandom();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected Custom createTestInstance() {
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
Expand All @@ -62,7 +62,7 @@ protected Custom mutateInstance(Custom instance) {
} else {
entries.remove(randomIntBetween(0, entries.size() - 1));
}
return new RepositoriesMetaData(entries.toArray(new RepositoryMetaData[entries.size()]));
return new RepositoriesMetaData(entries);
}

public Settings randomSettings() {
Expand Down Expand Up @@ -94,7 +94,7 @@ protected Custom makeTestChanges(Custom testInstance) {
repos.add(new RepositoryMetaData(randomAlphaOfLength(10), randomAlphaOfLength(10), randomSettings()));
}
}
return new RepositoriesMetaData(repos.toArray(new RepositoryMetaData[repos.size()]));
return new RepositoriesMetaData(repos);
}

@Override
Expand All @@ -114,7 +114,7 @@ protected Custom doParseInstance(XContentParser parser) throws IOException {
assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken());
List<RepositoryMetaData> repos = repositoriesMetaData.repositories();
repos.sort(Comparator.comparing(RepositoryMetaData::name));
return new RepositoriesMetaData(repos.toArray(new RepositoryMetaData[repos.size()]));
return new RepositoriesMetaData(repos);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void testLicenseMetadataParsingDoesNotSwallowOtherMetaData() throws Excep
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void testWatcherMetadataParsingDoesNotSwallowOtherMetaData() throws Excep
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);
Expand Down