jerryshao commented on code in PR #5020:
URL: https://github.com/apache/gravitino/pull/5020#discussion_r1802395715


##########
catalogs/catalog-hadoop/src/main/java/org/apache/gravitino/catalog/hadoop/fs/FileSystemUtils.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * 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.gravitino.catalog.hadoop.fs;
+
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import java.util.Arrays;
+import java.util.Map;
+import java.util.ServiceLoader;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+public class FileSystemUtils {
+
+  private FileSystemUtils() {}
+
+  public static Map<String, FileSystemProvider> getFileSystemProviders(String 
fileSystemProviders) {
+    Map<String, FileSystemProvider> resultMap = Maps.newHashMap();
+    ServiceLoader<FileSystemProvider> allFileSystemProviders =
+        ServiceLoader.load(FileSystemProvider.class);
+
+    Set<String> providersInUses =
+        fileSystemProviders != null
+            ? Arrays.stream(fileSystemProviders.split(","))
+                .map(String::trim)
+                .collect(java.util.stream.Collectors.toSet())
+            : Sets.newHashSet();
+
+    // Only get the file system providers that are in the use list.
+    allFileSystemProviders.forEach(
+        fileSystemProvider -> {
+          if (providersInUses.contains(fileSystemProvider.name())) {
+            if (resultMap.containsKey(fileSystemProvider.scheme())) {
+              throw new UnsupportedOperationException(
+                  String.format(
+                      "File system provider with scheme '%s' already exists in 
the use provider list "
+                          + "Please make sure the file system provider scheme 
is unique.",
+                      fileSystemProvider.name()));
+            }
+            resultMap.put(fileSystemProvider.scheme(), fileSystemProvider);
+          }
+        });
+
+    // Always add the built-in LocalFileSystemProvider and 
HDFSFileSystemProvider to the catalog.
+    FileSystemProvider builtInLocalFileSystemProvider = new 
LocalFileSystemProvider();
+    FileSystemProvider builtInHDFSFileSystemProvider = new 
HDFSFileSystemProvider();
+    resultMap.put(builtInLocalFileSystemProvider.scheme(), 
builtInLocalFileSystemProvider);
+    resultMap.put(builtInHDFSFileSystemProvider.scheme(), 
builtInHDFSFileSystemProvider);

Review Comment:
   They will be initialized by service loader, do you have to new these classes 
again?



-- 
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]

Reply via email to