You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by GitBox <gi...@apache.org> on 2022/08/02 02:23:06 UTC

[GitHub] [dolphinscheduler] zhongjiajie commented on a diff in pull request #11188: [Feature][Python] Migrate exists method call in PythonGateway to corresponding service

zhongjiajie commented on code in PR #11188:
URL: https://github.com/apache/dolphinscheduler/pull/11188#discussion_r935055634


##########
dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/resource.py:
##########
@@ -28,16 +30,46 @@ class Resource(Base):
     :param name: The fullname of resource.Includes path and suffix.
     :param content: The description of resource.
     :param description: The description of resource.
+    :param user_name: The user name of resource.
     """
 
-    _DEFINE_ATTR = {"name", "content", "description"}
+    _DEFINE_ATTR = {"name", "content", "description", "user_name"}
 
     def __init__(
         self,
         name: str,
-        content: str,
+        content: Optional[str] = None,
         description: Optional[str] = None,
+        user_name: Optional[str] = None,
     ):
         super().__init__(name, description)
         self.content = content
+        self.user_name = user_name
         self._resource_code = None
+
+    def get_info_from_database(self):
+        """Get resource info from java gateway, contains resource id, name."""
+        if not self.user_name:
+            raise PyDSParamException(
+                "`user_name` is required when querying resources from python gate."
+            )
+        gateway = launch_gateway()
+        return gateway.entry_point.queryResourcesFileInfo(self.user_name, self.name)
+
+    def get_id_from_database(self):
+        """Get resource id from java gateway."""
+        return self.get_info_from_database().getId()
+
+    def create_or_update_resource(self):
+        """Create or update resource via java gateway."""
+        gateway = launch_gateway()
+        if not self.content or not self.user_name:
+            raise PyDSParamException(
+                "`user_name` and `content` are required when create or update resource from python gate."
+            )

Review Comment:
   Can you add some tests when `user_name` empty, and also in function `get_info_from_database`



-- 
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-unsubscribe@dolphinscheduler.apache.org

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