Search in sources :

Example 1 with AzureStorageServiceImpl

use of org.elasticsearch.cloud.azure.storage.AzureStorageServiceImpl 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 2 with AzureStorageServiceImpl

use of org.elasticsearch.cloud.azure.storage.AzureStorageServiceImpl in project elasticsearch by elastic.

the class AzureSnapshotRestoreTests method cleanRepositoryFiles.

/**
     * Purge the test containers
     */
public void cleanRepositoryFiles(String... containers) throws StorageException, URISyntaxException {
    Settings settings = readSettingsFromFile();
    AzureStorageService client = new AzureStorageServiceImpl(settings);
    for (String container : containers) {
        client.removeContainer(null, LocationMode.PRIMARY_ONLY, container);
    }
}
Also used : AzureStorageServiceImpl(org.elasticsearch.cloud.azure.storage.AzureStorageServiceImpl) AzureStorageService(org.elasticsearch.cloud.azure.storage.AzureStorageService) Settings(org.elasticsearch.common.settings.Settings)

Aggregations

AzureStorageService (org.elasticsearch.cloud.azure.storage.AzureStorageService)2 AzureStorageServiceImpl (org.elasticsearch.cloud.azure.storage.AzureStorageServiceImpl)2 StorageException (com.microsoft.azure.storage.StorageException)1 URISyntaxException (java.net.URISyntaxException)1 ClusterAdminClient (org.elasticsearch.client.ClusterAdminClient)1 Settings (org.elasticsearch.common.settings.Settings)1 RepositoryVerificationException (org.elasticsearch.repositories.RepositoryVerificationException)1