Search in sources :

Example 1 with RepositoryVerificationException

use of org.elasticsearch.repositories.RepositoryVerificationException in project elasticsearch by elastic.

the class RepositoriesIT method testRepositoryVerification.

public void testRepositoryVerification() throws Exception {
    Client client = client();
    Settings settings = Settings.builder().put("location", randomRepoPath()).put("random_control_io_exception_rate", 1.0).build();
    logger.info("-->  creating repository that cannot write any files - should fail");
    assertThrows(client.admin().cluster().preparePutRepository("test-repo-1").setType("mock").setSettings(settings), 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");
    assertThrows(client.admin().cluster().prepareVerifyRepository("test-repo-1"), 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.elasticsearch.repositories.RepositoryVerificationException) Client(org.elasticsearch.client.Client) Settings(org.elasticsearch.common.settings.Settings)

Example 2 with RepositoryVerificationException

use of org.elasticsearch.repositories.RepositoryVerificationException in project elasticsearch by elastic.

the class AzureSnapshotRestoreTests method testRemoveAndCreateContainer.

/**
     * When a user remove a container you can not immediately create it again.
     */
public void testRemoveAndCreateContainer() throws Exception {
    final String container = getContainerName().concat("-testremove");
    final AzureStorageService storageService = new AzureStorageServiceImpl(internalCluster().getDefaultSettings());
    // It could happen that we run this test really close to a previous one
    // so we might need some time to be able to create the container
    assertBusy(() -> {
        try {
            storageService.createContainer(null, LocationMode.PRIMARY_ONLY, container);
            logger.debug(" -> container created...");
        } catch (URISyntaxException e) {
            // Incorrect URL. This should never happen.
            fail();
        } catch (StorageException e) {
            // It could happen. Let's wait for a while.
            logger.debug(" -> container is being removed. Let's wait a bit...");
            fail();
        }
    }, 30, TimeUnit.SECONDS);
    storageService.removeContainer(null, LocationMode.PRIMARY_ONLY, container);
    ClusterAdminClient client = client().admin().cluster();
    logger.info("-->  creating azure repository while container is being removed");
    try {
        client.preparePutRepository("test-repo").setType("azure").setSettings(Settings.builder().put(Repository.CONTAINER_SETTING.getKey(), container)).get();
        fail("we should get a RepositoryVerificationException");
    } catch (RepositoryVerificationException e) {
    // Fine we expect that
    }
}
Also used : AzureStorageServiceImpl(org.elasticsearch.cloud.azure.storage.AzureStorageServiceImpl) ClusterAdminClient(org.elasticsearch.client.ClusterAdminClient) RepositoryVerificationException(org.elasticsearch.repositories.RepositoryVerificationException) URISyntaxException(java.net.URISyntaxException) AzureStorageService(org.elasticsearch.cloud.azure.storage.AzureStorageService) StorageException(com.microsoft.azure.storage.StorageException)

Example 3 with RepositoryVerificationException

use of org.elasticsearch.repositories.RepositoryVerificationException in project elasticsearch by elastic.

the class AzureSnapshotRestoreTests method checkContainerName.

/**
     * Create repository with wrong or correct container name
     * @param container Container name we want to create
     * @param correct Is this container name correct
     */
private void checkContainerName(final String container, final boolean correct) throws Exception {
    logger.info("-->  creating azure repository with container name [{}]", container);
    // It could happen that we just removed from a previous test the same container so
    // we can not create it yet.
    assertBusy(() -> {
        try {
            PutRepositoryResponse putRepositoryResponse = client().admin().cluster().preparePutRepository("test-repo").setType("azure").setSettings(Settings.builder().put(Repository.CONTAINER_SETTING.getKey(), container).put(Repository.BASE_PATH_SETTING.getKey(), getRepositoryPath()).put(Repository.CHUNK_SIZE_SETTING.getKey(), randomIntBetween(1000, 10000), ByteSizeUnit.BYTES)).get();
            client().admin().cluster().prepareDeleteRepository("test-repo").get();
            try {
                logger.info("--> remove container [{}]", container);
                cleanRepositoryFiles(container);
            } catch (StorageException | URISyntaxException e) {
            // We can ignore that as we just try to clean after the test
            }
            assertTrue(putRepositoryResponse.isAcknowledged() == correct);
        } catch (RepositoryVerificationException e) {
            if (correct) {
                logger.debug(" -> container is being removed. Let's wait a bit...");
                fail();
            }
        }
    }, 5, TimeUnit.MINUTES);
}
Also used : RepositoryVerificationException(org.elasticsearch.repositories.RepositoryVerificationException) PutRepositoryResponse(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse) URISyntaxException(java.net.URISyntaxException) StorageException(com.microsoft.azure.storage.StorageException)

Example 4 with RepositoryVerificationException

use of org.elasticsearch.repositories.RepositoryVerificationException in project crate by crate.

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 = seed.getBytes(StandardCharsets.UTF_8);
            BlobContainer testContainer = blobStore().blobContainer(basePath().add(testBlobPrefix(seed)));
            String blobName = "master.dat";
            BytesArray bytes = new BytesArray(testBytes);
            try (InputStream stream = bytes.streamInput()) {
                testContainer.writeBlobAtomic(blobName, stream, bytes.length(), true);
            }
            return seed;
        }
    } catch (Exception e) {
        Throwable cause = e.getCause();
        Throwable errorInfo = cause == null ? e : cause;
        throw new RepositoryVerificationException(metadata.name(), String.format(Locale.ENGLISH, "Unable to verify the repository, [%s] is not accessible on master node: %s '%s'", metadata.name(), errorInfo.getClass().getSimpleName(), errorInfo.getMessage()));
    }
}
Also used : BytesArray(org.elasticsearch.common.bytes.BytesArray) RateLimitingInputStream(org.elasticsearch.index.snapshots.blobstore.RateLimitingInputStream) FilterInputStream(java.io.FilterInputStream) SlicedInputStream(org.elasticsearch.index.snapshots.blobstore.SlicedInputStream) InputStream(java.io.InputStream) RepositoryVerificationException(org.elasticsearch.repositories.RepositoryVerificationException) BlobContainer(org.elasticsearch.common.blobstore.BlobContainer) FsBlobContainer(org.elasticsearch.common.blobstore.fs.FsBlobContainer) IndexShardSnapshotFailedException(org.elasticsearch.index.snapshots.IndexShardSnapshotFailedException) IndexFormatTooNewException(org.apache.lucene.index.IndexFormatTooNewException) InvalidArgumentException(io.crate.exceptions.InvalidArgumentException) SnapshotException(org.elasticsearch.snapshots.SnapshotException) IOException(java.io.IOException) SnapshotMissingException(org.elasticsearch.snapshots.SnapshotMissingException) NoSuchFileException(java.nio.file.NoSuchFileException) ConcurrentSnapshotExecutionException(org.elasticsearch.snapshots.ConcurrentSnapshotExecutionException) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) IndexShardRestoreFailedException(org.elasticsearch.index.snapshots.IndexShardRestoreFailedException) RepositoryException(org.elasticsearch.repositories.RepositoryException) NotXContentException(org.elasticsearch.common.compress.NotXContentException) IndexShardSnapshotException(org.elasticsearch.index.snapshots.IndexShardSnapshotException) RepositoryVerificationException(org.elasticsearch.repositories.RepositoryVerificationException) IndexFormatTooOldException(org.apache.lucene.index.IndexFormatTooOldException)

Example 5 with RepositoryVerificationException

use of org.elasticsearch.repositories.RepositoryVerificationException in project crate by crate.

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 (IOException exp) {
            throw new RepositoryVerificationException(metadata.name(), "cannot delete test data at " + basePath(), exp);
        }
    }
}
Also used : RepositoryVerificationException(org.elasticsearch.repositories.RepositoryVerificationException) IOException(java.io.IOException)

Aggregations

RepositoryVerificationException (org.elasticsearch.repositories.RepositoryVerificationException)9 Client (org.elasticsearch.client.Client)4 Settings (org.elasticsearch.common.settings.Settings)4 IOException (java.io.IOException)3 ClusterAdminClient (org.elasticsearch.client.ClusterAdminClient)3 StorageException (com.microsoft.azure.storage.StorageException)2 FilterInputStream (java.io.FilterInputStream)2 InputStream (java.io.InputStream)2 URISyntaxException (java.net.URISyntaxException)2 Path (java.nio.file.Path)2 BlobContainer (org.elasticsearch.common.blobstore.BlobContainer)2 BytesArray (org.elasticsearch.common.bytes.BytesArray)2 RateLimitingInputStream (org.elasticsearch.index.snapshots.blobstore.RateLimitingInputStream)2 SlicedInputStream (org.elasticsearch.index.snapshots.blobstore.SlicedInputStream)2 InvalidArgumentException (io.crate.exceptions.InvalidArgumentException)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 CorruptIndexException (org.apache.lucene.index.CorruptIndexException)1 IndexFormatTooNewException (org.apache.lucene.index.IndexFormatTooNewException)1 IndexFormatTooOldException (org.apache.lucene.index.IndexFormatTooOldException)1 PutRepositoryResponse (org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse)1