Search in sources :

Example 46 with RepositoryMetaData

use of org.elasticsearch.cluster.metadata.RepositoryMetaData in project crate by crate.

the class SysSnapshotsTest method testUnavailableSnapshotsAreFilteredOut.

@Test
public void testUnavailableSnapshotsAreFilteredOut() throws Exception {
    HashMap<String, SnapshotId> snapshots = new HashMap<>();
    SnapshotId s1 = new SnapshotId("s1", UUIDs.randomBase64UUID());
    SnapshotId s2 = new SnapshotId("s2", UUIDs.randomBase64UUID());
    snapshots.put(s1.getUUID(), s1);
    snapshots.put(s2.getUUID(), s2);
    RepositoryData repositoryData = new RepositoryData(1, snapshots, Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), ShardGenerations.EMPTY);
    Repository r1 = mock(Repository.class);
    doAnswer((Answer<Void>) invocation -> {
        ActionListener<RepositoryData> callback = invocation.getArgument(0);
        callback.onResponse(repositoryData);
        return null;
    }).when(r1).getRepositoryData(any());
    when(r1.getMetadata()).thenReturn(new RepositoryMetadata("repo1", "fs", Settings.EMPTY));
    doAnswer((Answer<Void>) invocation -> {
        ActionListener<SnapshotInfo> callback = invocation.getArgument(1);
        callback.onFailure(new SnapshotException("repo1", "s1", "Everything is wrong"));
        return null;
    }).when(r1).getSnapshotInfo(eq(s1), any());
    doAnswer((Answer<Void>) invocation -> {
        ActionListener<SnapshotInfo> callback = invocation.getArgument(1);
        callback.onResponse(new SnapshotInfo(s2, Collections.emptyList(), SnapshotState.SUCCESS));
        return null;
    }).when(r1).getSnapshotInfo(eq(s2), any());
    SysSnapshots sysSnapshots = new SysSnapshots(() -> Collections.singletonList(r1));
    Stream<SysSnapshot> currentSnapshots = StreamSupport.stream(Spliterators.spliteratorUnknownSize(sysSnapshots.currentSnapshots().get().iterator(), Spliterator.ORDERED), false);
    assertThat(currentSnapshots.map(SysSnapshot::name).collect(Collectors.toList()), containsInAnyOrder("s1", "s2"));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) SnapshotId(org.elasticsearch.snapshots.SnapshotId) ShardGenerations(org.elasticsearch.repositories.ShardGenerations) Spliterators(java.util.Spliterators) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) SnapshotInfo(org.elasticsearch.snapshots.SnapshotInfo) RepositoryMetadata(org.elasticsearch.cluster.metadata.RepositoryMetadata) Answer(org.mockito.stubbing.Answer) Settings(org.elasticsearch.common.settings.Settings) Mockito.doAnswer(org.mockito.Mockito.doAnswer) SnapshotState(org.elasticsearch.snapshots.SnapshotState) StreamSupport(java.util.stream.StreamSupport) ESTestCase(org.elasticsearch.test.ESTestCase) Repository(org.elasticsearch.repositories.Repository) UUIDs(org.elasticsearch.common.UUIDs) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) SnapshotException(org.elasticsearch.snapshots.SnapshotException) Collections(java.util.Collections) Spliterator(java.util.Spliterator) ActionListener(org.elasticsearch.action.ActionListener) RepositoryData(org.elasticsearch.repositories.RepositoryData) Mockito.mock(org.mockito.Mockito.mock) HashMap(java.util.HashMap) SnapshotException(org.elasticsearch.snapshots.SnapshotException) RepositoryData(org.elasticsearch.repositories.RepositoryData) SnapshotId(org.elasticsearch.snapshots.SnapshotId) Repository(org.elasticsearch.repositories.Repository) SnapshotInfo(org.elasticsearch.snapshots.SnapshotInfo) ActionListener(org.elasticsearch.action.ActionListener) RepositoryMetadata(org.elasticsearch.cluster.metadata.RepositoryMetadata) Test(org.junit.Test)

Example 47 with RepositoryMetaData

use of org.elasticsearch.cluster.metadata.RepositoryMetaData in project crate by crate.

the class BlobStoreRepositoryRestoreTests method createRepository.

/**
 * Create a {@link Repository} with a random name *
 */
private Repository createRepository() {
    Settings settings = Settings.builder().put("location", randomAlphaOfLength(10)).build();
    RepositoryMetadata repositoryMetadata = new RepositoryMetadata(randomAlphaOfLength(10), FsRepository.TYPE, settings);
    final ClusterService clusterService = BlobStoreTestUtil.mockClusterService(repositoryMetadata);
    final FsRepository repository = new FsRepository(repositoryMetadata, createEnvironment(), xContentRegistry(), clusterService) {

        @Override
        protected void assertSnapshotOrGenericThread() {
        // eliminate thread name check as we create repo manually
        }
    };
    clusterService.addStateApplier(event -> repository.updateState(event.state()));
    // Apply state once to initialize repo properly like RepositoriesService would
    repository.updateState(clusterService.state());
    repository.start();
    return repository;
}
Also used : ClusterService(org.elasticsearch.cluster.service.ClusterService) RepositoryMetadata(org.elasticsearch.cluster.metadata.RepositoryMetadata) Settings(org.elasticsearch.common.settings.Settings) FsRepository(org.elasticsearch.repositories.fs.FsRepository)

Example 48 with RepositoryMetaData

use of org.elasticsearch.cluster.metadata.RepositoryMetaData in project crate by crate.

the class RepositoriesMetadataSerializationTests method createTestInstance.

@Override
protected Custom createTestInstance() {
    int numberOfRepositories = randomInt(10);
    List<RepositoryMetadata> entries = new ArrayList<>();
    for (int i = 0; i < numberOfRepositories; i++) {
        // divide by 2 to not overflow when adding to this number for the pending generation below
        final long generation = randomNonNegativeLong() / 2L;
        entries.add(new RepositoryMetadata(randomAlphaOfLength(10), randomAlphaOfLength(10), randomSettings(), generation, generation + randomLongBetween(0, generation)));
    }
    entries.sort(Comparator.comparing(RepositoryMetadata::name));
    return new RepositoriesMetadata(entries);
}
Also used : RepositoriesMetadata(org.elasticsearch.cluster.metadata.RepositoriesMetadata) RepositoryMetadata(org.elasticsearch.cluster.metadata.RepositoryMetadata) ArrayList(java.util.ArrayList)

Example 49 with RepositoryMetaData

use of org.elasticsearch.cluster.metadata.RepositoryMetaData in project crate by crate.

the class RepositoriesMetadataSerializationTests method doParseInstance.

@Override
protected Custom doParseInstance(XContentParser parser) throws IOException {
    assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
    RepositoriesMetadata repositoriesMetadata = RepositoriesMetadata.fromXContent(parser);
    assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken());
    List<RepositoryMetadata> repos = new ArrayList<>(repositoriesMetadata.repositories());
    repos.sort(Comparator.comparing(RepositoryMetadata::name));
    return new RepositoriesMetadata(repos);
}
Also used : RepositoriesMetadata(org.elasticsearch.cluster.metadata.RepositoriesMetadata) RepositoryMetadata(org.elasticsearch.cluster.metadata.RepositoryMetadata) ArrayList(java.util.ArrayList)

Example 50 with RepositoryMetaData

use of org.elasticsearch.cluster.metadata.RepositoryMetaData in project crate by crate.

the class MockEventuallyConsistentRepositoryTests method testOverwriteRandomBlobFails.

public void testOverwriteRandomBlobFails() throws IOException {
    MockEventuallyConsistentRepository.Context blobStoreContext = new MockEventuallyConsistentRepository.Context();
    try (BlobStoreRepository repository = new MockEventuallyConsistentRepository(new RepositoryMetadata("testRepo", "mockEventuallyConsistent", Settings.EMPTY), xContentRegistry(), BlobStoreTestUtil.mockClusterService(), blobStoreContext, random())) {
        repository.start();
        final BlobContainer container = repository.blobStore().blobContainer(repository.basePath());
        final String blobName = randomAlphaOfLength(10);
        final int lengthWritten = randomIntBetween(1, 100);
        final byte[] blobData = randomByteArrayOfLength(lengthWritten);
        container.writeBlob(blobName, new ByteArrayInputStream(blobData), lengthWritten, false);
        final AssertionError assertionError = expectThrows(AssertionError.class, () -> container.writeBlob(blobName, new ByteArrayInputStream(blobData), lengthWritten - 1, false));
        assertThat(assertionError.getMessage(), startsWith("Tried to overwrite blob [" + blobName + "]"));
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) BlobStoreRepository(org.elasticsearch.repositories.blobstore.BlobStoreRepository) RepositoryMetadata(org.elasticsearch.cluster.metadata.RepositoryMetadata) BlobContainer(org.elasticsearch.common.blobstore.BlobContainer)

Aggregations

RepositoryMetadata (org.elasticsearch.cluster.metadata.RepositoryMetadata)29 RepositoryMetaData (org.elasticsearch.cluster.metadata.RepositoryMetaData)24 ClusterState (org.elasticsearch.cluster.ClusterState)13 RepositoriesMetadata (org.elasticsearch.cluster.metadata.RepositoriesMetadata)13 ArrayList (java.util.ArrayList)11 Settings (org.elasticsearch.common.settings.Settings)11 RepositoriesMetaData (org.elasticsearch.cluster.metadata.RepositoriesMetaData)10 IOException (java.io.IOException)8 ClusterName (org.elasticsearch.cluster.ClusterName)8 Before (org.junit.Before)7 HashMap (java.util.HashMap)6 BlobStoreRepository (org.elasticsearch.repositories.blobstore.BlobStoreRepository)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)5 ActionListener (org.elasticsearch.action.ActionListener)5 BlobContainer (org.elasticsearch.common.blobstore.BlobContainer)5 RepositoryException (org.elasticsearch.repositories.RepositoryException)5 Test (org.junit.Test)5 List (java.util.List)4 Map (java.util.Map)4