caishunfeng commented on a change in pull request #6269:
URL: https://github.com/apache/dolphinscheduler/pull/6269#discussion_r737963794



##########
File path: 
dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/java_gateway.py
##########
@@ -0,0 +1,58 @@
+# 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.
+
+from typing import Any, Optional
+
+from py4j.java_collections import JavaMap
+from py4j.java_gateway import JavaGateway, GatewayParameters
+
+from pydolphinscheduler.constants import JavaGatewayDefault
+
+
+def launch_gateway() -> JavaGateway:
+    # TODO Note that automatic conversion makes calling Java methods slightly 
less efficient because
+    #  in the worst case, Py4J needs to go through all registered converters 
for all parameters.
+    #  This is why automatic conversion is disabled by default.
+    gateway = 
JavaGateway(gateway_parameters=GatewayParameters(auto_convert=True))
+    return gateway
+
+
+def gateway_result_checker(
+        result: JavaMap,
+        msg_check: Optional[str] = JavaGatewayDefault.RESULT_MESSAGE_SUCCESS
+) -> Any:
+    if result[JavaGatewayDefault.RESULT_STATUS_KEYWORD].toString() != \
+            JavaGatewayDefault.RESULT_STATUS_SUCCESS:
+        raise RuntimeError(f"Failed when try to got result for java gateway")
+    if msg_check is not None and 
result[JavaGatewayDefault.RESULT_MESSAGE_KEYWORD] != msg_check:
+        raise ValueError(f"Get result state not success.")
+    return result
+
+# try to add decorators bu failed
+# def gateway_result_checker(func, *args, **kwargs):

Review comment:
       Should the code remove?




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