Search in sources :

Example 1 with RepositoryMissingException

use of org.opensearch.repositories.RepositoryMissingException in project OpenSearch by opensearch-project.

the class SnapshotsService method validate.

/**
 * Validates snapshot request
 *
 * @param repositoryName repository name
 * @param snapshotName snapshot name
 * @param state   current cluster state
 */
private static void validate(String repositoryName, String snapshotName, ClusterState state) {
    RepositoriesMetadata repositoriesMetadata = state.getMetadata().custom(RepositoriesMetadata.TYPE);
    if (repositoriesMetadata == null || repositoriesMetadata.repository(repositoryName) == null) {
        throw new RepositoryMissingException(repositoryName);
    }
    validate(repositoryName, snapshotName);
}
Also used : RepositoriesMetadata(org.opensearch.cluster.metadata.RepositoriesMetadata) RepositoryMissingException(org.opensearch.repositories.RepositoryMissingException)

Example 2 with RepositoryMissingException

use of org.opensearch.repositories.RepositoryMissingException in project OpenSearch by opensearch-project.

the class OpenSearchMockAPIBasedRepositoryIntegTestCase method testRequestStats.

public void testRequestStats() throws Exception {
    final String repository = createRepository(randomName());
    final String index = "index-no-merges";
    createIndex(index, Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0).build());
    final long nbDocs = randomLongBetween(10_000L, 20_000L);
    try (BackgroundIndexer indexer = new BackgroundIndexer(index, "_doc", client(), (int) nbDocs)) {
        waitForDocs(nbDocs, indexer);
    }
    flushAndRefresh(index);
    ForceMergeResponse forceMerge = client().admin().indices().prepareForceMerge(index).setFlush(true).setMaxNumSegments(1).get();
    assertThat(forceMerge.getSuccessfulShards(), equalTo(1));
    assertHitCount(client().prepareSearch(index).setSize(0).setTrackTotalHits(true).get(), nbDocs);
    final String snapshot = "snapshot";
    assertSuccessfulSnapshot(client().admin().cluster().prepareCreateSnapshot(repository, snapshot).setWaitForCompletion(true).setIndices(index));
    assertAcked(client().admin().indices().prepareDelete(index));
    assertSuccessfulRestore(client().admin().cluster().prepareRestoreSnapshot(repository, snapshot).setWaitForCompletion(true));
    ensureGreen(index);
    assertHitCount(client().prepareSearch(index).setSize(0).setTrackTotalHits(true).get(), nbDocs);
    assertAcked(client().admin().cluster().prepareDeleteSnapshot(repository, snapshot).get());
    final RepositoryStats repositoryStats = StreamSupport.stream(internalCluster().getInstances(RepositoriesService.class).spliterator(), false).map(repositoriesService -> {
        try {
            return repositoriesService.repository(repository);
        } catch (RepositoryMissingException e) {
            return null;
        }
    }).filter(Objects::nonNull).map(Repository::stats).reduce(RepositoryStats::merge).get();
    Map<String, Long> sdkRequestCounts = repositoryStats.requestCounts;
    final Map<String, Long> mockCalls = getMockRequestCounts();
    String assertionErrorMsg = String.format("SDK sent [%s] calls and handler measured [%s] calls", sdkRequestCounts, mockCalls);
    assertEquals(assertionErrorMsg, mockCalls, sdkRequestCounts);
}
Also used : ForceMergeResponse(org.opensearch.action.admin.indices.forcemerge.ForceMergeResponse) Repository(org.opensearch.repositories.Repository) BackgroundIndexer(org.opensearch.test.BackgroundIndexer) RepositoriesService(org.opensearch.repositories.RepositoriesService) RepositoryStats(org.opensearch.repositories.RepositoryStats) RepositoryMissingException(org.opensearch.repositories.RepositoryMissingException)

Example 3 with RepositoryMissingException

use of org.opensearch.repositories.RepositoryMissingException 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]));
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) RepositoriesMetadata(org.opensearch.cluster.metadata.RepositoriesMetadata) RepositoryMetadata(org.opensearch.cluster.metadata.RepositoryMetadata) Metadata(org.opensearch.cluster.metadata.Metadata) RepositoriesMetadata(org.opensearch.cluster.metadata.RepositoriesMetadata) RepositoryMetadata(org.opensearch.cluster.metadata.RepositoryMetadata) ArrayList(java.util.ArrayList) RepositoryMissingException(org.opensearch.repositories.RepositoryMissingException)

Aggregations

RepositoryMissingException (org.opensearch.repositories.RepositoryMissingException)3 RepositoriesMetadata (org.opensearch.cluster.metadata.RepositoriesMetadata)2 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 ForceMergeResponse (org.opensearch.action.admin.indices.forcemerge.ForceMergeResponse)1 Metadata (org.opensearch.cluster.metadata.Metadata)1 RepositoryMetadata (org.opensearch.cluster.metadata.RepositoryMetadata)1 RepositoriesService (org.opensearch.repositories.RepositoriesService)1 Repository (org.opensearch.repositories.Repository)1 RepositoryStats (org.opensearch.repositories.RepositoryStats)1 BackgroundIndexer (org.opensearch.test.BackgroundIndexer)1