use of org.elasticsearch.repositories.RepositoryMissingException in project elasticsearch by elastic.
the class SnapshotsService method validate.
/**
* Validates snapshot request
*
* @param request snapshot request
* @param state current cluster state
*/
private void validate(SnapshotRequest request, ClusterState state) {
RepositoriesMetaData repositoriesMetaData = state.getMetaData().custom(RepositoriesMetaData.TYPE);
final String repository = request.repositoryName;
if (repositoriesMetaData == null || repositoriesMetaData.repository(repository) == null) {
throw new RepositoryMissingException(repository);
}
validate(repository, request.snapshotName);
}
use of org.elasticsearch.repositories.RepositoryMissingException in project elasticsearch by elastic.
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.repositories()));
} else {
listener.onResponse(new GetRepositoriesResponse(Collections.<RepositoryMetaData>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(Collections.unmodifiableList(repositoryListBuilder)));
} else {
listener.onFailure(new RepositoryMissingException(request.repositories()[0]));
}
}
}
Aggregations