-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Azure client upgrade to allow identity options (#15287)
* Include new dependencies * Mostly implemented * More azure fixes * Tests passing * Unit tests running * Test running after removing storage exception * Happy with coverage now * Add more tests * fix client factory * cleanup from testing * Remove old client * update docs * Exclude from spellcheck * Add licenses * Fix identity version * Save work * Add azure clients * add licenses * typos * Add dependencies * Exception is not thrown * Fix intellij check * Don't need to override * specify length * urldecode * encode path * Fix checks * Revert urlencode changes * Urlencode with azure library * Update docs/development/extensions-core/azure.md Co-authored-by: Abhishek Agarwal <[email protected]> * PR changes * Update docs/development/extensions-core/azure.md Co-authored-by: 317brian <[email protected]> * Deprecate AzureTaskLogsConfig.maxRetries * Clean up azure retry block * logic update to reuse clients * fix comments * Create container conditionally * Fix key auth * Remove container client logic * Add some more testing * Update comments * Add a comment explaining client reuse * Move logic to factory class * use bom for dependency management * fix license versions --------- Co-authored-by: Abhishek Agarwal <[email protected]> Co-authored-by: 317brian <[email protected]>
- Loading branch information
1 parent
b8060fc
commit 8e95cea
Showing
34 changed files
with
1,287 additions
and
1,001 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...ore/azure-extensions/src/main/java/org/apache/druid/storage/azure/AzureClientFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.druid.storage.azure; | ||
|
||
import com.azure.core.http.policy.ExponentialBackoffOptions; | ||
import com.azure.core.http.policy.RetryOptions; | ||
import com.azure.identity.DefaultAzureCredentialBuilder; | ||
import com.azure.storage.blob.BlobServiceClient; | ||
import com.azure.storage.blob.BlobServiceClientBuilder; | ||
import com.azure.storage.common.StorageSharedKeyCredential; | ||
|
||
import java.time.Duration; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Factory class for generating BlobServiceClient objects. | ||
*/ | ||
public class AzureClientFactory | ||
{ | ||
|
||
private final AzureAccountConfig config; | ||
private final Map<Integer, BlobServiceClient> cachedBlobServiceClients; | ||
|
||
public AzureClientFactory(AzureAccountConfig config) | ||
{ | ||
this.config = config; | ||
this.cachedBlobServiceClients = new HashMap<>(); | ||
} | ||
|
||
// It's okay to store clients in a map here because all the configs for specifying azure retries are static, and there are only 2 of them. | ||
// The 2 configs are AzureAccountConfig.maxTries and AzureOutputConfig.maxRetrr. | ||
// We will only ever have at most 2 clients in cachedBlobServiceClients. | ||
public BlobServiceClient getBlobServiceClient(Integer retryCount) | ||
{ | ||
if (!cachedBlobServiceClients.containsKey(retryCount)) { | ||
BlobServiceClientBuilder clientBuilder = getAuthenticatedBlobServiceClientBuilder() | ||
.retryOptions(new RetryOptions( | ||
new ExponentialBackoffOptions() | ||
.setMaxRetries(retryCount != null ? retryCount : config.getMaxTries()) | ||
.setBaseDelay(Duration.ofMillis(1000)) | ||
.setMaxDelay(Duration.ofMillis(60000)) | ||
)); | ||
cachedBlobServiceClients.put(retryCount, clientBuilder.buildClient()); | ||
} | ||
|
||
return cachedBlobServiceClients.get(retryCount); | ||
} | ||
|
||
private BlobServiceClientBuilder getAuthenticatedBlobServiceClientBuilder() | ||
{ | ||
BlobServiceClientBuilder clientBuilder = new BlobServiceClientBuilder() | ||
.endpoint("https://" + config.getAccount() + ".blob.core.windows.net"); | ||
|
||
if (config.getKey() != null) { | ||
clientBuilder.credential(new StorageSharedKeyCredential(config.getAccount(), config.getKey())); | ||
} else if (config.getSharedAccessStorageToken() != null) { | ||
clientBuilder.sasToken(config.getSharedAccessStorageToken()); | ||
} else if (config.getUseAzureCredentialsChain()) { | ||
// We might not use the managed identity client id in the credential chain but we can just set it here and it will no-op. | ||
DefaultAzureCredentialBuilder defaultAzureCredentialBuilder = new DefaultAzureCredentialBuilder() | ||
.managedIdentityClientId(config.getManagedIdentityClientId()); | ||
clientBuilder.credential(defaultAzureCredentialBuilder.build()); | ||
} | ||
return clientBuilder; | ||
} | ||
} |
Oops, something went wrong.