Search in sources :

Example 1 with RepositoryMissingException

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);
}
Also used : RepositoriesMetaData(org.elasticsearch.cluster.metadata.RepositoriesMetaData) RepositoryMissingException(org.elasticsearch.repositories.RepositoryMissingException)

Example 2 with RepositoryMissingException

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]));
        }
    }
}
Also used : RepositoriesMetaData(org.elasticsearch.cluster.metadata.RepositoriesMetaData) LinkedHashSet(java.util.LinkedHashSet) MetaData(org.elasticsearch.cluster.metadata.MetaData) RepositoriesMetaData(org.elasticsearch.cluster.metadata.RepositoriesMetaData) RepositoryMetaData(org.elasticsearch.cluster.metadata.RepositoryMetaData) RepositoryMetaData(org.elasticsearch.cluster.metadata.RepositoryMetaData) ArrayList(java.util.ArrayList) RepositoryMissingException(org.elasticsearch.repositories.RepositoryMissingException)

Aggregations

RepositoriesMetaData (org.elasticsearch.cluster.metadata.RepositoriesMetaData)2 RepositoryMissingException (org.elasticsearch.repositories.RepositoryMissingException)2 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 MetaData (org.elasticsearch.cluster.metadata.MetaData)1 RepositoryMetaData (org.elasticsearch.cluster.metadata.RepositoryMetaData)1