turcsanyip commented on code in PR #6158: URL: https://github.com/apache/nifi/pull/6158#discussion_r960254709
########## nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/main/java/org/apache/nifi/processors/azure/storage/utils/StorageClientFactory.java: ########## @@ -0,0 +1,117 @@ +/* + * 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.nifi.processors.azure.storage.utils; + +import com.azure.core.credential.AccessToken; +import com.azure.core.credential.TokenCredential; +import com.azure.core.http.HttpClient; +import com.azure.core.http.ProxyOptions; +import com.azure.core.http.netty.NettyAsyncHttpClientBuilder; +import com.azure.identity.ClientSecretCredential; +import com.azure.identity.ClientSecretCredentialBuilder; +import com.azure.identity.ManagedIdentityCredential; +import com.azure.identity.ManagedIdentityCredentialBuilder; +import com.azure.storage.common.StorageSharedKeyCredential; +import com.azure.storage.file.datalake.DataLakeServiceClient; +import com.azure.storage.file.datalake.DataLakeServiceClientBuilder; +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; +import org.apache.commons.lang3.StringUtils; +import org.apache.nifi.services.azure.storage.ADLSCredentialsDetails; +import reactor.core.publisher.Mono; + +public class StorageClientFactory { + + private static final long STORAGE_CLIENT_CACHE_SIZE = 10; + + private final Cache<Integer, DataLakeServiceClient> storageClientCache; + + public StorageClientFactory() { + this.storageClientCache = createCache(); + } + + private Cache<Integer, DataLakeServiceClient> createCache() { + return Caffeine.newBuilder() + .maximumSize(STORAGE_CLIENT_CACHE_SIZE) + .build(); + } + + public Cache<Integer, DataLakeServiceClient> getCache() { + return storageClientCache; + } + + /** + * Retrieves a {@link DataLakeServiceClient} + * + * @param proxyOptions not used for caching, because proxy parameters are set in the ProxyConfiguration service + * @param credentialsDetails used for caching because it can contain properties that are results of an expression + * @return DataLakeServiceClient + */ + public DataLakeServiceClient getStorageClient(ProxyOptions proxyOptions, ADLSCredentialsDetails credentialsDetails) { Review Comment: @jfrazee Do you have any update on the proxy scenario? In my opinion, if a library/class declares itself as thread-safe (as the Azure v12 storage client in the referenced docs above), it must be thread-safe in all setup/usage. So I would go forward and merge this PR. Would you have any objections? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
