Search in sources :

Example 1 with ProxyOptions

use of com.azure.core.http.ProxyOptions in project ambry by linkedin.

the class StorageClient method createBlobStorageClient.

/**
 * Create the {@link BlobServiceClient} object.
 * @param {@link CloudConfig} object.
 * @param {@link AzureCloudConfig} object.
 * @return {@link BlobServiceClient} object.
 */
protected BlobServiceClient createBlobStorageClient() {
    validateABSAuthConfigs(azureCloudConfig);
    Configuration storageConfiguration = new Configuration();
    // Check for network proxy
    ProxyOptions proxyOptions = (cloudConfig.vcrProxyHost == null) ? null : new ProxyOptions(ProxyOptions.Type.HTTP, new InetSocketAddress(cloudConfig.vcrProxyHost, cloudConfig.vcrProxyPort));
    if (proxyOptions != null) {
        logger.info("Using proxy: {}:{}", cloudConfig.vcrProxyHost, cloudConfig.vcrProxyPort);
    }
    HttpClient client = new NettyAsyncHttpClientBuilder().proxy(proxyOptions).build();
    // Note: retry decisions are made at CloudBlobStore level.  Configure storageClient with no retries.
    RequestRetryOptions noRetries = new RequestRetryOptions(RetryPolicyType.FIXED, 1, (Integer) null, null, null, null);
    try {
        return buildBlobServiceClient(client, storageConfiguration, noRetries, azureCloudConfig);
    } catch (MalformedURLException | InterruptedException | ExecutionException ex) {
        logger.error("Error building ABS blob service client: {}", ex.getMessage());
        throw new IllegalStateException(ex);
    }
}
Also used : RequestRetryOptions(com.azure.storage.common.policy.RequestRetryOptions) MalformedURLException(java.net.MalformedURLException) Configuration(com.azure.core.util.Configuration) ProxyOptions(com.azure.core.http.ProxyOptions) InetSocketAddress(java.net.InetSocketAddress) HttpClient(com.azure.core.http.HttpClient) NettyAsyncHttpClientBuilder(com.azure.core.http.netty.NettyAsyncHttpClientBuilder) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with ProxyOptions

use of com.azure.core.http.ProxyOptions in project ambry by linkedin.

the class AzureUtils method getClientSecretCredential.

/**
 * @param azureCloudConfig the {@link AzureCloudConfig} to source credential configs from.
 * @return the {@link ClientSecretCredential}.
 */
static ClientSecretCredential getClientSecretCredential(AzureCloudConfig azureCloudConfig) {
    ClientSecretCredentialBuilder builder = new ClientSecretCredentialBuilder().tenantId(azureCloudConfig.azureIdentityTenantId).clientId(azureCloudConfig.azureIdentityClientId).clientSecret(azureCloudConfig.azureIdentitySecret);
    if (!azureCloudConfig.azureIdentityProxyHost.isEmpty()) {
        logger.info("Using proxy for ClientSecretCredential: {}:{}", azureCloudConfig.azureIdentityProxyHost, azureCloudConfig.azureIdentityProxyPort);
        ProxyOptions proxyOptions = new ProxyOptions(ProxyOptions.Type.HTTP, new InetSocketAddress(azureCloudConfig.azureIdentityProxyHost, azureCloudConfig.azureIdentityProxyPort));
        HttpClient httpClient = new NettyAsyncHttpClientBuilder().proxy(proxyOptions).build();
        builder.httpClient(httpClient);
    }
    return builder.build();
}
Also used : ProxyOptions(com.azure.core.http.ProxyOptions) ClientSecretCredentialBuilder(com.azure.identity.ClientSecretCredentialBuilder) InetSocketAddress(java.net.InetSocketAddress) HttpClient(com.azure.core.http.HttpClient) NettyAsyncHttpClientBuilder(com.azure.core.http.netty.NettyAsyncHttpClientBuilder)

Example 3 with ProxyOptions

use of com.azure.core.http.ProxyOptions in project ambry by linkedin.

the class StorageClient method createBlobStorageAsyncClient.

/**
 * Create the {@link BlobServiceAsyncClient} object.
 * @param {@link CloudConfig} object.
 * @param {@link AzureCloudConfig} object.
 * @return {@link BlobServiceAsyncClient} object.
 */
protected BlobServiceAsyncClient createBlobStorageAsyncClient() {
    validateABSAuthConfigs(azureCloudConfig);
    Configuration storageConfiguration = new Configuration();
    // Check for network proxy
    ProxyOptions proxyOptions = (cloudConfig.vcrProxyHost == null) ? null : new ProxyOptions(ProxyOptions.Type.HTTP, new InetSocketAddress(cloudConfig.vcrProxyHost, cloudConfig.vcrProxyPort));
    if (proxyOptions != null) {
        logger.info("Using proxy: {}:{}", cloudConfig.vcrProxyHost, cloudConfig.vcrProxyPort);
    }
    HttpClient client = new NettyAsyncHttpClientBuilder().proxy(proxyOptions).build();
    // Note: retry decisions are made at CloudBlobStore level.  Configure storageClient with no retries.
    RequestRetryOptions noRetries = new RequestRetryOptions(RetryPolicyType.FIXED, 1, (Integer) null, null, null, null);
    try {
        return buildBlobServiceAsyncClient(client, storageConfiguration, noRetries, azureCloudConfig);
    } catch (MalformedURLException | InterruptedException | ExecutionException ex) {
        logger.error("Error building ABS blob service client: {}", ex.getMessage());
        throw new IllegalStateException(ex);
    }
}
Also used : RequestRetryOptions(com.azure.storage.common.policy.RequestRetryOptions) MalformedURLException(java.net.MalformedURLException) Configuration(com.azure.core.util.Configuration) ProxyOptions(com.azure.core.http.ProxyOptions) InetSocketAddress(java.net.InetSocketAddress) HttpClient(com.azure.core.http.HttpClient) NettyAsyncHttpClientBuilder(com.azure.core.http.netty.NettyAsyncHttpClientBuilder) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

HttpClient (com.azure.core.http.HttpClient)3 ProxyOptions (com.azure.core.http.ProxyOptions)3 NettyAsyncHttpClientBuilder (com.azure.core.http.netty.NettyAsyncHttpClientBuilder)3 InetSocketAddress (java.net.InetSocketAddress)3 Configuration (com.azure.core.util.Configuration)2 RequestRetryOptions (com.azure.storage.common.policy.RequestRetryOptions)2 MalformedURLException (java.net.MalformedURLException)2 ExecutionException (java.util.concurrent.ExecutionException)2 ClientSecretCredentialBuilder (com.azure.identity.ClientSecretCredentialBuilder)1