From a71e6744cc79157c17ac0db8c0f84743baaf991e Mon Sep 17 00:00:00 2001 From: taoran1250 <543121890@qq.com> Date: Wed, 25 Dec 2024 11:28:19 +0800 Subject: [PATCH 1/2] feat: Parse UDF function name interface submission --- .../apache/linkis/udf/api/UDFRestfulApi.java | 17 ++++++++++------- .../org/apache/linkis/udf/utils/UdfUtils.java | 4 +++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/linkis-public-enhancements/linkis-udf-service/src/main/java/org/apache/linkis/udf/api/UDFRestfulApi.java b/linkis-public-enhancements/linkis-udf-service/src/main/java/org/apache/linkis/udf/api/UDFRestfulApi.java index 81a1b7755a..7030503ecb 100644 --- a/linkis-public-enhancements/linkis-udf-service/src/main/java/org/apache/linkis/udf/api/UDFRestfulApi.java +++ b/linkis-public-enhancements/linkis-udf-service/src/main/java/org/apache/linkis/udf/api/UDFRestfulApi.java @@ -1440,23 +1440,26 @@ public Message pythonUpload( } @ApiImplicitParam( - name = "path", - dataType = "String", - value = "path", - example = "file:///test-dir/test-sub-dir/test1012_01.py") + name = "path", + dataType = "String", + value = "path", + example = "file:///test-dir/test-sub-dir/test1012_01.py") @RequestMapping(path = "/get-register-functions", method = RequestMethod.GET) public Message getRegisterFunctions(HttpServletRequest req, @RequestParam("path") String path) { if (StringUtils.endsWithIgnoreCase(path, Constants.FILE_EXTENSION_PY) - || StringUtils.endsWithIgnoreCase(path, Constants.FILE_EXTENSION_SCALA)) { + || StringUtils.endsWithIgnoreCase(path, Constants.FILE_EXTENSION_SCALA)) { if (StringUtils.startsWithIgnoreCase(path, StorageUtils$.MODULE$.FILE_SCHEMA())) { try { + // 获取登录用户 + String userName = ModuleUserUtils.getOperationUser(req, "get-register-functions"); + FsPath fsPath = new FsPath(path); // 获取文件系统实例 - FileSystem fileSystem = (FileSystem) FSFactory.getFs(fsPath); + FileSystem fileSystem = (FileSystem) FSFactory.getFsByProxyUser(fsPath, userName); fileSystem.init(null); if (fileSystem.canRead(fsPath)) { return Message.ok() - .data("functions", UdfUtils.getRegisterFunctions(fileSystem, fsPath, path)); + .data("functions", UdfUtils.getRegisterFunctions(fileSystem, fsPath, path)); } else { return Message.error("您没有权限访问该文件"); } diff --git a/linkis-public-enhancements/linkis-udf-service/src/main/java/org/apache/linkis/udf/utils/UdfUtils.java b/linkis-public-enhancements/linkis-udf-service/src/main/java/org/apache/linkis/udf/utils/UdfUtils.java index f7401fc1f4..ea7437fd4e 100644 --- a/linkis-public-enhancements/linkis-udf-service/src/main/java/org/apache/linkis/udf/utils/UdfUtils.java +++ b/linkis-public-enhancements/linkis-udf-service/src/main/java/org/apache/linkis/udf/utils/UdfUtils.java @@ -324,12 +324,14 @@ public static List extractPythonMethodNames(String udfPath) throws Excep String exec = Utils.exec( (new String[] { + "sudo", Constants.PYTHON_COMMAND.getValue(), Configuration.getLinkisHome() + "/admin/" + "linkis_udf_get_python_methods.py", localPath })); logger.info( - "execute python script to get python method name...{} {} {}", + "execute python script to get python method name...{} {} {} {}", + "sudo", Constants.PYTHON_COMMAND.getValue(), Configuration.getLinkisHome() + "/admin/" + "linkis_udf_get_python_methods.py", localPath); From d10e4aaf4b42829393113d012f89e0d7daa51578 Mon Sep 17 00:00:00 2001 From: taoran1250 <543121890@qq.com> Date: Wed, 25 Dec 2024 11:32:44 +0800 Subject: [PATCH 2/2] feat: Parse UDF function name interface submission --- .../org/apache/linkis/udf/api/UDFRestfulApi.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/linkis-public-enhancements/linkis-udf-service/src/main/java/org/apache/linkis/udf/api/UDFRestfulApi.java b/linkis-public-enhancements/linkis-udf-service/src/main/java/org/apache/linkis/udf/api/UDFRestfulApi.java index 7030503ecb..6a750cc4a1 100644 --- a/linkis-public-enhancements/linkis-udf-service/src/main/java/org/apache/linkis/udf/api/UDFRestfulApi.java +++ b/linkis-public-enhancements/linkis-udf-service/src/main/java/org/apache/linkis/udf/api/UDFRestfulApi.java @@ -1440,14 +1440,14 @@ public Message pythonUpload( } @ApiImplicitParam( - name = "path", - dataType = "String", - value = "path", - example = "file:///test-dir/test-sub-dir/test1012_01.py") + name = "path", + dataType = "String", + value = "path", + example = "file:///test-dir/test-sub-dir/test1012_01.py") @RequestMapping(path = "/get-register-functions", method = RequestMethod.GET) public Message getRegisterFunctions(HttpServletRequest req, @RequestParam("path") String path) { if (StringUtils.endsWithIgnoreCase(path, Constants.FILE_EXTENSION_PY) - || StringUtils.endsWithIgnoreCase(path, Constants.FILE_EXTENSION_SCALA)) { + || StringUtils.endsWithIgnoreCase(path, Constants.FILE_EXTENSION_SCALA)) { if (StringUtils.startsWithIgnoreCase(path, StorageUtils$.MODULE$.FILE_SCHEMA())) { try { // 获取登录用户 @@ -1459,7 +1459,7 @@ public Message getRegisterFunctions(HttpServletRequest req, @RequestParam("path" fileSystem.init(null); if (fileSystem.canRead(fsPath)) { return Message.ok() - .data("functions", UdfUtils.getRegisterFunctions(fileSystem, fsPath, path)); + .data("functions", UdfUtils.getRegisterFunctions(fileSystem, fsPath, path)); } else { return Message.error("您没有权限访问该文件"); }