You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2022/07/26 17:14:23 UTC

[GitHub] [nifi] jfrazee commented on a diff in pull request #6158: NIFI-10152 Storage client caching in Azure ADLS processors

jfrazee commented on code in PR #6158:
URL: https://github.com/apache/nifi/pull/6158#discussion_r930225774


##########
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:
   I need to see whether this extends to the proxy scenario, but in the basic case, for recent versions of the SDK, the *ServiceClient can be treated as threadsafe:
   
   https://github.com/Azure/azure-storage-java/blob/master/V12%20Upgrade%20Story.md
   
   > v12 [...] Some of the highlights include: [...] Thread-safety and immutability. It is still safe to share clients across threads, and there should still be no confusion about when the client is in sync with the service as there is no state maintained on the client. State may be returned as the result of a method call, but there is no pretense of storing state on a client that could be immediately invalid.
   
   https://techcommunity.microsoft.com/t5/azure-storage-blog/announcing-the-azure-storage-v12-client-libraries/ba-p/1482394
   
   > All of our v12 libraries have improved performance and ensure thread safety.
   
   https://azure.microsoft.com/en-us/blog/build-richer-applications-with-the-new-asynchronous-azure-storage-sdk-for-java/
   
   > Azure Storage SDK v10 for Java adopts the next-generation Storage SDK design providing thread-safe types [...] Some of the improvements in the new SDK are: [...] Thread-safe interfaces[.]
   
   https://azure.github.io/azure-sdk/java_introduction.html#service-client
   
   >  DO ensure that all service client classes are immutable and stateless upon instantiation.



-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org