[fix] python api upload resource center failed
branch dev already exists in apache/dolphinscheduler#13042
This commit is contained in:
parent
1bfd8f5327
commit
56ca041182
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue