You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by zh...@apache.org on 2022/11/29 12:19:37 UTC

[dolphinscheduler] branch 3.1.2-prepare updated: [fix] python api upload resource center failed

This is an automated email from the ASF dual-hosted git repository.

zhongjiajie pushed a commit to branch 3.1.2-prepare
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git


The following commit(s) were added to refs/heads/3.1.2-prepare by this push:
     new 56ca041182 [fix] python api upload resource center failed
56ca041182 is described below

commit 56ca0411825a46d718951a690bc6f69f1d32ff2a
Author: Jay Chung <zh...@gmail.com>
AuthorDate: Tue Nov 29 20:19:12 2022 +0800

    [fix] python api upload resource center failed
    
    branch dev already exists in apache/dolphinscheduler#13042
---
 .../apache/dolphinscheduler/api/python/PythonGateway.java   |  5 ++---
 .../dolphinscheduler/api/service/ResourcesService.java      |  3 +--
 .../api/service/impl/ResourcesServiceImpl.java              | 13 ++++++-------
 .../dolphinscheduler/api/python/PythonGatewayTest.java      | 10 ++--------
 4 files changed, 11 insertions(+), 20 deletions(-)

diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java
index a7ffbbaec8..4ad807bb1b 100644
--- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java
+++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java
@@ -637,11 +637,10 @@ public class PythonGateway {
      * @param fullName The fullname of resource.Includes path and suffix.
      * @param description description of resource
      * @param resourceContent content of resource
-     * @return id of resource
      */
-    public Integer createOrUpdateResource(
+    public void createOrUpdateResource(
             String userName, String fullName, String description, String resourceContent) {
-        return resourceService.createOrUpdateResource(userName, fullName, description, resourceContent);
+        resourceService.createOrUpdateResource(userName, fullName, description, resourceContent);
     }
 
     @PostConstruct
diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ResourcesService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ResourcesService.java
index 00c6fa151b..a396a7f3e4 100644
--- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ResourcesService.java
+++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ResourcesService.java
@@ -189,9 +189,8 @@ public interface ResourcesService {
      * @param fullName The fullname of resource.Includes path and suffix.
      * @param description description of resource
      * @param resourceContent content of resource
-     * @return id of resource
      */
-    Integer createOrUpdateResource(String userName, String fullName, String description, String resourceContent);
+    void createOrUpdateResource(String userName, String fullName, String description, String resourceContent);
 
     /**
      * updateProcessInstance resource
diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java
index 377f90b54b..5cabd39734 100644
--- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java
+++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java
@@ -1233,7 +1233,7 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe
 
     @Override
     @Transactional
-    public Integer createOrUpdateResource(String userName, String fullName, String description,
+    public void createOrUpdateResource(String userName, String fullName, String description,
                                           String resourceContent) {
         User user = userMapper.queryByUserNameAccurately(userName);
         int suffixLabelIndex = fullName.indexOf(PERIOD);
@@ -1247,13 +1247,9 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe
         }
         Result<Object> createResult = onlineCreateOrUpdateResourceWithDir(
                 user, fullName, description, resourceContent);
-        if (createResult.getCode() == Status.SUCCESS.getCode()) {
-            Map<String, Object> resultMap = (Map<String, Object>) createResult.getData();
-            return (int) resultMap.get("id");
+        if (createResult.getCode() != Status.SUCCESS.getCode()) {
+            throw new IllegalArgumentException(String.format("Can not create or update resource : %s", fullName));
         }
-        String msg = String.format("Can not create or update resource : %s", fullName);
-        logger.error(msg);
-        throw new IllegalArgumentException(msg);
     }
 
     private int queryOrCreateDirId(User user, int pid, String currentDir, String dirName) {
@@ -1532,6 +1528,9 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe
     @Override
     public Resource queryResourcesFileInfo(String userName, String fullName) {
         User user = userMapper.queryByUserNameAccurately(userName);
+        if (!fullName.startsWith(FOLDER_SEPARATOR)) {
+            fullName = FOLDER_SEPARATOR + fullName;
+        }
         Result<Object> resourceResponse = this.queryResource(user, fullName, null, ResourceType.FILE);
         if (resourceResponse.getCode() != Status.SUCCESS.getCode()) {
             String msg = String.format("Can not find valid resource by name %s", fullName);
diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/python/PythonGatewayTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/python/PythonGatewayTest.java
index 2a49ed307b..f48b53986f 100644
--- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/python/PythonGatewayTest.java
+++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/python/PythonGatewayTest.java
@@ -30,6 +30,7 @@ import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper;
 import org.apache.dolphinscheduler.spi.enums.ResourceType;
 import org.junit.Assert;
 import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
 import org.junit.runner.RunWith;
 import org.mockito.InjectMocks;
 import org.mockito.Mock;
@@ -100,14 +101,7 @@ public class PythonGatewayTest {
         String content = "content";
         String resourceFullName = resourceDir + resourceName + "." + resourceSuffix;
 
-        int resourceId = 3;
-
-        Mockito.when(resourcesService.createOrUpdateResource(user.getUserName(), resourceFullName, desc, content))
-                .thenReturn(resourceId);
-
-        int id = pythonGateway.createOrUpdateResource(
-                user.getUserName(), resourceFullName, desc, content);
-        Assert.assertEquals(id, resourceId);
+        Assertions.assertDoesNotThrow(() -> resourcesService.createOrUpdateResource(user.getUserName(), resourceFullName, desc, content));
     }