Search in sources :

Example 1 with RepositoryVerificationException

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

the class RepositoriesIT method testRepositoryVerification.

public void testRepositoryVerification() throws Exception {
    disableRepoConsistencyCheck("This test does not create any data in the repository.");
    Client client = client();
    Settings settings = Settings.builder().put("location", randomRepoPath()).put("random_control_io_exception_rate", 1.0).build();
    Settings readonlySettings = Settings.builder().put(settings).put("readonly", true).build();
    logger.info("-->  creating repository that cannot write any files - should fail");
    assertRequestBuilderThrows(client.admin().cluster().preparePutRepository("test-repo-1").setType("mock").setSettings(settings), RepositoryVerificationException.class);
    logger.info("-->  creating read-only repository that cannot read any files - should fail");
    assertRequestBuilderThrows(client.admin().cluster().preparePutRepository("test-repo-2").setType("mock").setSettings(readonlySettings), RepositoryVerificationException.class);
    logger.info("-->  creating repository that cannot write any files, but suppress verification - should be acked");
    assertAcked(client.admin().cluster().preparePutRepository("test-repo-1").setType("mock").setSettings(settings).setVerify(false));
    logger.info("-->  verifying repository");
    assertRequestBuilderThrows(client.admin().cluster().prepareVerifyRepository("test-repo-1"), RepositoryVerificationException.class);
    logger.info("-->  creating read-only repository that cannot read any files, but suppress verification - should be acked");
    assertAcked(client.admin().cluster().preparePutRepository("test-repo-2").setType("mock").setSettings(readonlySettings).setVerify(false));
    logger.info("-->  verifying repository");
    assertRequestBuilderThrows(client.admin().cluster().prepareVerifyRepository("test-repo-2"), RepositoryVerificationException.class);
    Path location = randomRepoPath();
    logger.info("-->  creating repository");
    try {
        client.admin().cluster().preparePutRepository("test-repo-1").setType("mock").setSettings(Settings.builder().put("location", location).put("localize_location", true)).get();
        fail("RepositoryVerificationException wasn't generated");
    } catch (RepositoryVerificationException ex) {
        assertThat(ex.getMessage(), containsString("is not shared"));
    }
}
Also used : Path(java.nio.file.Path) RepositoryVerificationException(org.opensearch.repositories.RepositoryVerificationException) Client(org.opensearch.client.Client) Settings(org.opensearch.common.settings.Settings)

Example 2 with RepositoryVerificationException

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

the class BlobStoreRepository method endVerification.

@Override
public void endVerification(String seed) {
    if (isReadOnly() == false) {
        try {
            final String testPrefix = testBlobPrefix(seed);
            blobStore().blobContainer(basePath().add(testPrefix)).delete();
        } catch (Exception exp) {
            throw new RepositoryVerificationException(metadata.name(), "cannot delete test data at " + basePath(), exp);
        }
    }
}
Also used : RepositoryVerificationException(org.opensearch.repositories.RepositoryVerificationException) IndexFormatTooNewException(org.apache.lucene.index.IndexFormatTooNewException) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) AbortedSnapshotException(org.opensearch.snapshots.AbortedSnapshotException) SnapshotMissingException(org.opensearch.snapshots.SnapshotMissingException) SnapshotException(org.opensearch.snapshots.SnapshotException) RepositoryVerificationException(org.opensearch.repositories.RepositoryVerificationException) IOException(java.io.IOException) IndexShardSnapshotFailedException(org.opensearch.index.snapshots.IndexShardSnapshotFailedException) NotXContentException(org.opensearch.common.compress.NotXContentException) NoSuchFileException(java.nio.file.NoSuchFileException) SnapshotCreationException(org.opensearch.snapshots.SnapshotCreationException) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) RepositoryException(org.opensearch.repositories.RepositoryException) IndexShardRestoreFailedException(org.opensearch.index.snapshots.IndexShardRestoreFailedException) IndexFormatTooOldException(org.apache.lucene.index.IndexFormatTooOldException)

Example 3 with RepositoryVerificationException

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

the class BlobStoreRepository method startVerification.

@Override
public String startVerification() {
    try {
        if (isReadOnly()) {
            // It's readonly - so there is not much we can do here to verify it apart from reading the blob store metadata
            latestIndexBlobId();
            return "read-only";
        } else {
            String seed = UUIDs.randomBase64UUID();
            byte[] testBytes = Strings.toUTF8Bytes(seed);
            BlobContainer testContainer = blobStore().blobContainer(basePath().add(testBlobPrefix(seed)));
            BytesArray bytes = new BytesArray(testBytes);
            try (InputStream stream = bytes.streamInput()) {
                testContainer.writeBlobAtomic("master.dat", stream, bytes.length(), true);
            }
            return seed;
        }
    } catch (Exception exp) {
        throw new RepositoryVerificationException(metadata.name(), "path " + basePath() + " is not accessible on master node", exp);
    }
}
Also used : BytesArray(org.opensearch.common.bytes.BytesArray) SlicedInputStream(org.opensearch.index.snapshots.blobstore.SlicedInputStream) RateLimitingInputStream(org.opensearch.index.snapshots.blobstore.RateLimitingInputStream) FilterInputStream(java.io.FilterInputStream) InputStream(java.io.InputStream) RepositoryVerificationException(org.opensearch.repositories.RepositoryVerificationException) FsBlobContainer(org.opensearch.common.blobstore.fs.FsBlobContainer) BlobContainer(org.opensearch.common.blobstore.BlobContainer) IndexFormatTooNewException(org.apache.lucene.index.IndexFormatTooNewException) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) AbortedSnapshotException(org.opensearch.snapshots.AbortedSnapshotException) SnapshotMissingException(org.opensearch.snapshots.SnapshotMissingException) SnapshotException(org.opensearch.snapshots.SnapshotException) RepositoryVerificationException(org.opensearch.repositories.RepositoryVerificationException) IOException(java.io.IOException) IndexShardSnapshotFailedException(org.opensearch.index.snapshots.IndexShardSnapshotFailedException) NotXContentException(org.opensearch.common.compress.NotXContentException) NoSuchFileException(java.nio.file.NoSuchFileException) SnapshotCreationException(org.opensearch.snapshots.SnapshotCreationException) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) RepositoryException(org.opensearch.repositories.RepositoryException) IndexShardRestoreFailedException(org.opensearch.index.snapshots.IndexShardRestoreFailedException) IndexFormatTooOldException(org.apache.lucene.index.IndexFormatTooOldException)

Aggregations

RepositoryVerificationException (org.opensearch.repositories.RepositoryVerificationException)3 IOException (java.io.IOException)2 NoSuchFileException (java.nio.file.NoSuchFileException)2 CorruptIndexException (org.apache.lucene.index.CorruptIndexException)2 IndexFormatTooNewException (org.apache.lucene.index.IndexFormatTooNewException)2 IndexFormatTooOldException (org.apache.lucene.index.IndexFormatTooOldException)2 AlreadyClosedException (org.apache.lucene.store.AlreadyClosedException)2 NotXContentException (org.opensearch.common.compress.NotXContentException)2 IndexShardRestoreFailedException (org.opensearch.index.snapshots.IndexShardRestoreFailedException)2 IndexShardSnapshotFailedException (org.opensearch.index.snapshots.IndexShardSnapshotFailedException)2 RepositoryException (org.opensearch.repositories.RepositoryException)2 AbortedSnapshotException (org.opensearch.snapshots.AbortedSnapshotException)2 SnapshotCreationException (org.opensearch.snapshots.SnapshotCreationException)2 SnapshotException (org.opensearch.snapshots.SnapshotException)2 SnapshotMissingException (org.opensearch.snapshots.SnapshotMissingException)2 FilterInputStream (java.io.FilterInputStream)1 InputStream (java.io.InputStream)1 Path (java.nio.file.Path)1 Client (org.opensearch.client.Client)1 BlobContainer (org.opensearch.common.blobstore.BlobContainer)1