kaori-seasons commented on code in PR #7384:
URL: https://github.com/apache/gravitino/pull/7384#discussion_r2157985307


##########
clients/client-python/gravitino/filesystem/gvfs_storage_handler.py:
##########
@@ -737,3 +740,103 @@ def get_storage_handler_by_path(actual_path: str) -> 
StorageHandler:
     raise GravitinoRuntimeException(
         f"Storage type doesn't support now. Path:{actual_path}"
     )
+
+def register_storage_handler_providers(options: Dict[str, str]):
+    """
+    Register storage handler providers from configuration.
+
+    This function dynamically loads and registers storage handler providers
+    specified in the configuration, allowing users to extend GVFS with custom
+    storage systems without modifying core code.
+
+    :param options: Configuration options dictionary
+    """
+    if not options:
+        return
+
+    providers_config = options.get("storage_handler_providers")
+    if not providers_config:
+        return
+
+    # Import here to avoid circular imports
+    from gravitino.filesystem.storage_handler_provider import 
StorageHandlerProvider
+
+    for provider_class_name in providers_config.split(','):
+        provider_class_name = provider_class_name.strip()
+        if not provider_class_name:
+            continue
+
+        try:
+            # Dynamic import and instantiation
+            module_name, class_name = provider_class_name.rsplit(".", 1)
+            module = importlib.import_module(module_name)
+            provider_class = getattr(module, class_name)
+
+            # Validate that it's a StorageHandlerProvider
+            if not issubclass(provider_class, StorageHandlerProvider):
+                raise GravitinoRuntimeException(
+                    f"Class {provider_class_name} must extend 
StorageHandlerProvider"
+                )
+
+            provider = provider_class()
+            storage_handler = provider.get_storage_handler()
+            scheme = provider.scheme()
+
+            # Check for scheme conflicts
+            scheme_enum = None
+            for storage_type in StorageType:
+                if storage_type.value == scheme:
+                    scheme_enum = storage_type
+                    break
+
+            if scheme_enum is None:
+                # Create a new storage type dynamically for custom schemes
+                # Note: This is a limitation of using Enum, but we can work 
around it
+                # by directly adding to the dictionaries
+                pass
+            else:
+                # Check if scheme already exists
+                if scheme_enum in storage_handlers:
+                    raise GravitinoRuntimeException(
+                        f"Storage handler for scheme '{scheme}' already 
exists. "
+                        f"Provider: {provider_class_name}"
+                    )
+
+            # Register the storage handler
+            if scheme_enum:
+                storage_handlers[scheme_enum] = storage_handler
+            else:
+                # For custom schemes, we need to extend our lookup mechanism
+                # Add to storage_handlers with a custom key approach
+                custom_storage_type = type('CustomStorageType', (), {'value': 
scheme})()
+                storage_handlers[custom_storage_type] = storage_handler

Review Comment:
   @yuqi1129 Hello, thank you very much for your reply. I have been busy with 
work recently so I just saw it. You are right, but I am not very clear about 
the custom types related to storage handlers. Can you give me some examples?



-- 
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: commits-unsubscr...@gravitino.apache.org

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

Reply via email to