use of org.opensearch.cluster.metadata.RepositoriesMetadata in project OpenSearch by opensearch-project.
the class TransportGetRepositoriesAction method masterOperation.
@Override
protected void masterOperation(final GetRepositoriesRequest request, ClusterState state, final ActionListener<GetRepositoriesResponse> listener) {
Metadata metadata = state.metadata();
RepositoriesMetadata repositories = metadata.custom(RepositoriesMetadata.TYPE);
if (request.repositories().length == 0 || (request.repositories().length == 1 && "_all".equals(request.repositories()[0]))) {
if (repositories != null) {
listener.onResponse(new GetRepositoriesResponse(repositories));
} else {
listener.onResponse(new GetRepositoriesResponse(new RepositoriesMetadata(Collections.emptyList())));
}
} else {
if (repositories != null) {
// to keep insertion order
Set<String> repositoriesToGet = new LinkedHashSet<>();
for (String repositoryOrPattern : request.repositories()) {
if (Regex.isSimpleMatchPattern(repositoryOrPattern) == false) {
repositoriesToGet.add(repositoryOrPattern);
} else {
for (RepositoryMetadata repository : repositories.repositories()) {
if (Regex.simpleMatch(repositoryOrPattern, repository.name())) {
repositoriesToGet.add(repository.name());
}
}
}
}
List<RepositoryMetadata> repositoryListBuilder = new ArrayList<>();
for (String repository : repositoriesToGet) {
RepositoryMetadata repositoryMetadata = repositories.repository(repository);
if (repositoryMetadata == null) {
listener.onFailure(new RepositoryMissingException(repository));
return;
}
repositoryListBuilder.add(repositoryMetadata);
}
listener.onResponse(new GetRepositoriesResponse(new RepositoriesMetadata(repositoryListBuilder)));
} else {
listener.onFailure(new RepositoryMissingException(request.repositories()[0]));
}
}
}
Aggregations