Search in sources :

Example 41 with CloudBlobClient

use of com.microsoft.azure.storage.blob.CloudBlobClient in project elasticsearch by elastic.

the class AzureStorageServiceTests method testGetSelectedClientDefaultTimeout.

public void testGetSelectedClientDefaultTimeout() {
    AzureStorageServiceImpl azureStorageService = new AzureStorageServiceMock(settings);
    CloudBlobClient client1 = azureStorageService.getSelectedClient("azure1", LocationMode.PRIMARY_ONLY);
    assertThat(client1.getDefaultRequestOptions().getTimeoutIntervalInMs(), nullValue());
    CloudBlobClient client3 = azureStorageService.getSelectedClient("azure3", LocationMode.PRIMARY_ONLY);
    assertThat(client3.getDefaultRequestOptions().getTimeoutIntervalInMs(), is(30 * 1000));
}
Also used : CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient)

Example 42 with CloudBlobClient

use of com.microsoft.azure.storage.blob.CloudBlobClient in project elasticsearch by elastic.

the class AzureStorageServiceTests method testGetDefaultClientWithNoSecondary.

public void testGetDefaultClientWithNoSecondary() {
    AzureStorageServiceImpl azureStorageService = new AzureStorageServiceMock(Settings.builder().put("cloud.azure.storage.azure1.account", "myaccount1").put("cloud.azure.storage.azure1.key", "mykey1").build());
    CloudBlobClient client = azureStorageService.getSelectedClient(null, LocationMode.PRIMARY_ONLY);
    assertThat(client.getEndpoint(), is(URI.create("https://azure1")));
}
Also used : CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient)

Example 43 with CloudBlobClient

use of com.microsoft.azure.storage.blob.CloudBlobClient in project elasticsearch by elastic.

the class AzureStorageServiceImpl method createContainer.

@Override
public void createContainer(String account, LocationMode mode, String container) throws URISyntaxException, StorageException {
    try {
        CloudBlobClient client = this.getSelectedClient(account, mode);
        CloudBlobContainer blobContainer = client.getContainerReference(container);
        logger.trace("creating container [{}]", container);
        SocketAccess.doPrivilegedException(blobContainer::createIfNotExists);
    } catch (IllegalArgumentException e) {
        logger.trace((Supplier<?>) () -> new ParameterizedMessage("fails creating container [{}]", container), e);
        throw new RepositoryException(container, e.getMessage(), e);
    }
}
Also used : CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) Supplier(org.apache.logging.log4j.util.Supplier) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) RepositoryException(org.elasticsearch.repositories.RepositoryException)

Example 44 with CloudBlobClient

use of com.microsoft.azure.storage.blob.CloudBlobClient in project elasticsearch by elastic.

the class AzureStorageServiceImpl method getInputStream.

@Override
public InputStream getInputStream(String account, LocationMode mode, String container, String blob) throws URISyntaxException, StorageException {
    logger.trace("reading container [{}], blob [{}]", container, blob);
    CloudBlobClient client = this.getSelectedClient(account, mode);
    CloudBlockBlob blockBlobReference = client.getContainerReference(container).getBlockBlobReference(blob);
    return SocketAccess.doPrivilegedException(blockBlobReference::openInputStream);
}
Also used : CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob)

Example 45 with CloudBlobClient

use of com.microsoft.azure.storage.blob.CloudBlobClient in project elasticsearch by elastic.

the class AzureStorageServiceImpl method removeContainer.

@Override
public void removeContainer(String account, LocationMode mode, String container) throws URISyntaxException, StorageException {
    CloudBlobClient client = this.getSelectedClient(account, mode);
    CloudBlobContainer blobContainer = client.getContainerReference(container);
    logger.trace("removing container [{}]", container);
    SocketAccess.doPrivilegedException(blobContainer::deleteIfExists);
}
Also used : CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer)

Aggregations

CloudBlobClient (com.microsoft.azure.storage.blob.CloudBlobClient)71 CloudBlobContainer (com.microsoft.azure.storage.blob.CloudBlobContainer)40 CloudStorageAccount (com.microsoft.azure.storage.CloudStorageAccount)19 StorageException (com.microsoft.azure.storage.StorageException)19 URISyntaxException (java.net.URISyntaxException)17 CloudBlockBlob (com.microsoft.azure.storage.blob.CloudBlockBlob)16 ListBlobItem (com.microsoft.azure.storage.blob.ListBlobItem)10 Supplier (java.util.function.Supplier)9 CloudBlob (com.microsoft.azure.storage.blob.CloudBlob)8 URI (java.net.URI)8 InvalidKeyException (java.security.InvalidKeyException)8 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)6 TypeLiteral (com.google.inject.TypeLiteral)5 BlobListingDetails (com.microsoft.azure.storage.blob.BlobListingDetails)5 IOException (java.io.IOException)5 BlobProperties (com.microsoft.azure.storage.blob.BlobProperties)4 HashMap (java.util.HashMap)4 Settings (org.elasticsearch.common.settings.Settings)4