status
stringclasses 1
value | repo_name
stringclasses 31
values | repo_url
stringclasses 31
values | issue_id
int64 1
104k
| title
stringlengths 4
233
| body
stringlengths 0
186k
⌀ | issue_url
stringlengths 38
56
| pull_url
stringlengths 37
54
| before_fix_sha
stringlengths 40
40
| after_fix_sha
stringlengths 40
40
| report_datetime
timestamp[us, tz=UTC] | language
stringclasses 5
values | commit_datetime
timestamp[us, tz=UTC] | updated_file
stringlengths 7
188
| chunk_content
stringlengths 1
1.03M
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,214 | [Bug] [WorkFlow] Delete online workflows in batches, prompt information is inaccurate | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
Delete online workflows in batches, prompt information is inaccurate
### What you expected to happen
Delete online workflows in batches, prompt information is accurate
### How to reproduce

### Anything else
_No response_
### Version
3.0.0-alpha
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10214 | https://github.com/apache/dolphinscheduler/pull/10215 | 4dbe27bb8f7e87fcf18582e970d08236f2dbf3d5 | edcb7aad23f73fb166efc3863dfb58e137ca05b4 | 2022-05-23T19:06:15Z | java | 2022-05-24T02:18:03Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java | return result;
}
processDefinition.setReleaseState(releaseState);
processDefinitionMapper.updateById(processDefinition);
schedulerService.setScheduleState(loginUser, projectCode, scheduleObj.getId(), ReleaseState.ONLINE);
break;
case OFFLINE:
processDefinition.setReleaseState(releaseState);
int updateProcess = processDefinitionMapper.updateById(processDefinition);
if (updateProcess > 0) {
logger.info("set schedule offline, project code: {}, schedule id: {}, process definition code: {}", projectCode, scheduleObj.getId(), code);
scheduleObj.setReleaseState(ReleaseState.OFFLINE);
int updateSchedule = scheduleMapper.updateById(scheduleObj);
if (updateSchedule == 0) {
putMsg(result, Status.OFFLINE_SCHEDULE_ERROR);
throw new ServiceException(Status.OFFLINE_SCHEDULE_ERROR);
}
schedulerService.deleteSchedule(project.getId(), scheduleObj.getId());
}
break;
default:
putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, RELEASESTATE);
return result;
}
putMsg(result, Status.SUCCESS);
return result;
}
} |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 9,779 | [Bug] [python] release_state do not work in process definition | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
When users set `OFFLINE` to process definition and submit to python-gateway-service, they want to submit process definition but keep it offline. but we currently do not pass attr `self.release_state` to python-gateway-service.
https://github.com/apache/dolphinscheduler/blob/5289b09817396046489b28857ad54a85c5ffddb2/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/process_definition.py#L357-L372
and the default process definition state always online
https://github.com/apache/dolphinscheduler/blob/3457cee96047ab7ab0371a61852cac3e5a98d991/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java#L249-L250
### What you expected to happen
when set process definition state as offline, it should be offline
### How to reproduce
see what happend
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/9779 | https://github.com/apache/dolphinscheduler/pull/10151 | edcb7aad23f73fb166efc3863dfb58e137ca05b4 | 56e0ea802d93667de8c48796a9291a775abddd49 | 2022-04-26T06:58:48Z | java | 2022-05-24T02:25:19Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java | /*
* 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 |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 9,779 | [Bug] [python] release_state do not work in process definition | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
When users set `OFFLINE` to process definition and submit to python-gateway-service, they want to submit process definition but keep it offline. but we currently do not pass attr `self.release_state` to python-gateway-service.
https://github.com/apache/dolphinscheduler/blob/5289b09817396046489b28857ad54a85c5ffddb2/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/process_definition.py#L357-L372
and the default process definition state always online
https://github.com/apache/dolphinscheduler/blob/3457cee96047ab7ab0371a61852cac3e5a98d991/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java#L249-L250
### What you expected to happen
when set process definition state as offline, it should be offline
### How to reproduce
see what happend
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/9779 | https://github.com/apache/dolphinscheduler/pull/10151 | edcb7aad23f73fb166efc3863dfb58e137ca05b4 | 56e0ea802d93667de8c48796a9291a775abddd49 | 2022-04-26T06:58:48Z | java | 2022-05-24T02:25:19Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java | * limitations under the License.
*/
package org.apache.dolphinscheduler.api.python;
import org.apache.dolphinscheduler.api.dto.resources.ResourceComponent;
import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.service.ExecutorService;
import org.apache.dolphinscheduler.api.service.ProcessDefinitionService;
import org.apache.dolphinscheduler.api.service.ProjectService;
import org.apache.dolphinscheduler.api.service.QueueService;
import org.apache.dolphinscheduler.api.service.ResourcesService;
import org.apache.dolphinscheduler.api.service.SchedulerService;
import org.apache.dolphinscheduler.api.service.TaskDefinitionService;
import org.apache.dolphinscheduler.api.service.TenantService;
import org.apache.dolphinscheduler.api.service.UsersService;
import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.common.enums.ComplementDependentMode;
import org.apache.dolphinscheduler.common.enums.FailureStrategy;
import org.apache.dolphinscheduler.common.enums.Priority;
import org.apache.dolphinscheduler.common.enums.ProcessExecutionTypeEnum;
import org.apache.dolphinscheduler.common.enums.ProgramType;
import org.apache.dolphinscheduler.common.enums.ReleaseState;
import org.apache.dolphinscheduler.common.enums.RunMode;
import org.apache.dolphinscheduler.common.enums.TaskDependType;
import org.apache.dolphinscheduler.common.enums.UserType;
import org.apache.dolphinscheduler.common.enums.WarningType;
import org.apache.dolphinscheduler.common.utils.CodeGenerateUtils;
import org.apache.dolphinscheduler.dao.entity.DataSource;
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
import org.apache.dolphinscheduler.dao.entity.Project; |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 9,779 | [Bug] [python] release_state do not work in process definition | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
When users set `OFFLINE` to process definition and submit to python-gateway-service, they want to submit process definition but keep it offline. but we currently do not pass attr `self.release_state` to python-gateway-service.
https://github.com/apache/dolphinscheduler/blob/5289b09817396046489b28857ad54a85c5ffddb2/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/process_definition.py#L357-L372
and the default process definition state always online
https://github.com/apache/dolphinscheduler/blob/3457cee96047ab7ab0371a61852cac3e5a98d991/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java#L249-L250
### What you expected to happen
when set process definition state as offline, it should be offline
### How to reproduce
see what happend
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/9779 | https://github.com/apache/dolphinscheduler/pull/10151 | edcb7aad23f73fb166efc3863dfb58e137ca05b4 | 56e0ea802d93667de8c48796a9291a775abddd49 | 2022-04-26T06:58:48Z | java | 2022-05-24T02:25:19Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java | import org.apache.dolphinscheduler.dao.entity.ProjectUser;
import org.apache.dolphinscheduler.dao.entity.Queue;
import org.apache.dolphinscheduler.dao.entity.Schedule;
import org.apache.dolphinscheduler.dao.entity.TaskDefinition;
import org.apache.dolphinscheduler.dao.entity.Tenant;
import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.dao.mapper.DataSourceMapper;
import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper;
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper;
import org.apache.dolphinscheduler.dao.mapper.ProjectUserMapper;
import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper;
import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper;
import org.apache.dolphinscheduler.api.configuration.PythonGatewayConfiguration;
import org.apache.dolphinscheduler.spi.enums.ResourceType;
import org.apache.commons.collections.CollectionUtils;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import py4j.GatewayServer;
@Component |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 9,779 | [Bug] [python] release_state do not work in process definition | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
When users set `OFFLINE` to process definition and submit to python-gateway-service, they want to submit process definition but keep it offline. but we currently do not pass attr `self.release_state` to python-gateway-service.
https://github.com/apache/dolphinscheduler/blob/5289b09817396046489b28857ad54a85c5ffddb2/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/process_definition.py#L357-L372
and the default process definition state always online
https://github.com/apache/dolphinscheduler/blob/3457cee96047ab7ab0371a61852cac3e5a98d991/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java#L249-L250
### What you expected to happen
when set process definition state as offline, it should be offline
### How to reproduce
see what happend
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/9779 | https://github.com/apache/dolphinscheduler/pull/10151 | edcb7aad23f73fb166efc3863dfb58e137ca05b4 | 56e0ea802d93667de8c48796a9291a775abddd49 | 2022-04-26T06:58:48Z | java | 2022-05-24T02:25:19Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java | public class PythonGateway {
private static final Logger logger = LoggerFactory.getLogger(PythonGateway.class);
private static final FailureStrategy DEFAULT_FAILURE_STRATEGY = FailureStrategy.CONTINUE;
private static final Priority DEFAULT_PRIORITY = Priority.MEDIUM;
private static final Long DEFAULT_ENVIRONMENT_CODE = -1L;
private static final TaskDependType DEFAULT_TASK_DEPEND_TYPE = TaskDependType.TASK_POST;
private static final RunMode DEFAULT_RUN_MODE = RunMode.RUN_MODE_SERIAL;
private static final int DEFAULT_DRY_RUN = 0;
private static final ComplementDependentMode COMPLEMENT_DEPENDENT_MODE = ComplementDependentMode.OFF_MODE;
@Autowired
private ProcessDefinitionMapper processDefinitionMapper;
@Autowired
private ProjectService projectService;
@Autowired
private TenantService tenantService;
@Autowired
private ExecutorService executorService;
@Autowired
private ProcessDefinitionService processDefinitionService;
@Autowired
private TaskDefinitionService taskDefinitionService;
@Autowired
private UsersService usersService;
@Autowired
private QueueService queueService;
@Autowired
private ResourcesService resourceService;
@Autowired |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 9,779 | [Bug] [python] release_state do not work in process definition | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
When users set `OFFLINE` to process definition and submit to python-gateway-service, they want to submit process definition but keep it offline. but we currently do not pass attr `self.release_state` to python-gateway-service.
https://github.com/apache/dolphinscheduler/blob/5289b09817396046489b28857ad54a85c5ffddb2/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/process_definition.py#L357-L372
and the default process definition state always online
https://github.com/apache/dolphinscheduler/blob/3457cee96047ab7ab0371a61852cac3e5a98d991/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java#L249-L250
### What you expected to happen
when set process definition state as offline, it should be offline
### How to reproduce
see what happend
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/9779 | https://github.com/apache/dolphinscheduler/pull/10151 | edcb7aad23f73fb166efc3863dfb58e137ca05b4 | 56e0ea802d93667de8c48796a9291a775abddd49 | 2022-04-26T06:58:48Z | java | 2022-05-24T02:25:19Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java | private ProjectMapper projectMapper;
@Autowired
private TaskDefinitionMapper taskDefinitionMapper;
@Autowired
private SchedulerService schedulerService;
@Autowired
private ScheduleMapper scheduleMapper;
@Autowired
private DataSourceMapper dataSourceMapper;
@Autowired
private PythonGatewayConfiguration pythonGatewayConfiguration;
@Autowired
private ProjectUserMapper projectUserMapper;
private final User dummyAdminUser = new User() {
{
setId(Integer.MAX_VALUE);
setUserName("dummyUser");
setUserType(UserType.ADMIN_USER);
}
};
private final Queue queuePythonGateway = new Queue() {
{
setId(Integer.MAX_VALUE);
setQueueName("queuePythonGateway");
}
};
public String ping() {
return "PONG";
} |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 9,779 | [Bug] [python] release_state do not work in process definition | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
When users set `OFFLINE` to process definition and submit to python-gateway-service, they want to submit process definition but keep it offline. but we currently do not pass attr `self.release_state` to python-gateway-service.
https://github.com/apache/dolphinscheduler/blob/5289b09817396046489b28857ad54a85c5ffddb2/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/process_definition.py#L357-L372
and the default process definition state always online
https://github.com/apache/dolphinscheduler/blob/3457cee96047ab7ab0371a61852cac3e5a98d991/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java#L249-L250
### What you expected to happen
when set process definition state as offline, it should be offline
### How to reproduce
see what happend
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/9779 | https://github.com/apache/dolphinscheduler/pull/10151 | edcb7aad23f73fb166efc3863dfb58e137ca05b4 | 56e0ea802d93667de8c48796a9291a775abddd49 | 2022-04-26T06:58:48Z | java | 2022-05-24T02:25:19Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java | public Map<String, Object> genTaskCodeList(Integer genNum) {
return taskDefinitionService.genTaskCodeList(genNum);
}
public Map<String, Long> getCodeAndVersion(String projectName, String taskName) throws CodeGenerateUtils.CodeGenerateException {
Project project = projectMapper.queryByName(projectName);
Map<String, Long> result = new HashMap<>();
if (project == null) {
result.put("code", CodeGenerateUtils.getInstance().genCode());
result.put("version", 0L);
return result;
}
TaskDefinition taskDefinition = taskDefinitionMapper.queryByName(project.getCode(), taskName);
if (taskDefinition == null) {
result.put("code", CodeGenerateUtils.getInstance().genCode());
result.put("version", 0L);
} else {
result.put("code", taskDefinition.getCode());
result.put("version", (long) taskDefinition.getVersion());
}
return result;
}
/**
* create or update process definition.
* If process definition do not exists in Project=`projectCode` would create a new one
* If process definition already exists in Project=`projectCode` would update it
*
* @param userName user name who create or update process definition |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 9,779 | [Bug] [python] release_state do not work in process definition | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
When users set `OFFLINE` to process definition and submit to python-gateway-service, they want to submit process definition but keep it offline. but we currently do not pass attr `self.release_state` to python-gateway-service.
https://github.com/apache/dolphinscheduler/blob/5289b09817396046489b28857ad54a85c5ffddb2/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/process_definition.py#L357-L372
and the default process definition state always online
https://github.com/apache/dolphinscheduler/blob/3457cee96047ab7ab0371a61852cac3e5a98d991/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java#L249-L250
### What you expected to happen
when set process definition state as offline, it should be offline
### How to reproduce
see what happend
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/9779 | https://github.com/apache/dolphinscheduler/pull/10151 | edcb7aad23f73fb166efc3863dfb58e137ca05b4 | 56e0ea802d93667de8c48796a9291a775abddd49 | 2022-04-26T06:58:48Z | java | 2022-05-24T02:25:19Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java | * @param projectName project name which process definition belongs to
* @param name process definition name
* @param description description
* @param globalParams global params
* @param schedule schedule for process definition, will not set schedule if null,
* and if would always fresh exists schedule if not null
* @param warningType warning type
* @param warningGroupId warning group id
* @param locations locations json object about all tasks
* @param timeout timeout for process definition working, if running time longer than timeout,
* task will mark as fail
* @param workerGroup run task in which worker group
* @param tenantCode tenantCode
* @param taskRelationJson relation json for nodes
* @param taskDefinitionJson taskDefinitionJson
* @return create result code
*/
public Long createOrUpdateProcessDefinition(String userName,
String projectName,
String name,
String description,
String globalParams,
String schedule,
String warningType,
int warningGroupId,
String locations,
int timeout,
String workerGroup,
String tenantCode,
String taskRelationJson, |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 9,779 | [Bug] [python] release_state do not work in process definition | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
When users set `OFFLINE` to process definition and submit to python-gateway-service, they want to submit process definition but keep it offline. but we currently do not pass attr `self.release_state` to python-gateway-service.
https://github.com/apache/dolphinscheduler/blob/5289b09817396046489b28857ad54a85c5ffddb2/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/process_definition.py#L357-L372
and the default process definition state always online
https://github.com/apache/dolphinscheduler/blob/3457cee96047ab7ab0371a61852cac3e5a98d991/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java#L249-L250
### What you expected to happen
when set process definition state as offline, it should be offline
### How to reproduce
see what happend
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/9779 | https://github.com/apache/dolphinscheduler/pull/10151 | edcb7aad23f73fb166efc3863dfb58e137ca05b4 | 56e0ea802d93667de8c48796a9291a775abddd49 | 2022-04-26T06:58:48Z | java | 2022-05-24T02:25:19Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java | String taskDefinitionJson,
ProcessExecutionTypeEnum executionType) {
User user = usersService.queryUser(userName);
Project project = projectMapper.queryByName(projectName);
long projectCode = project.getCode();
ProcessDefinition processDefinition = getProcessDefinition(user, projectCode, name);
long processDefinitionCode;
if (processDefinition != null) {
processDefinitionCode = processDefinition.getCode();
processDefinitionService.releaseProcessDefinition(user, projectCode, processDefinitionCode, ReleaseState.OFFLINE);
Map<String, Object> result = processDefinitionService.updateProcessDefinition(user, projectCode, name, processDefinitionCode, description, globalParams,
locations, timeout, tenantCode, taskRelationJson, taskDefinitionJson, executionType);
} else {
Map<String, Object> result = processDefinitionService.createProcessDefinition(user, projectCode, name, description, globalParams,
locations, timeout, tenantCode, taskRelationJson, taskDefinitionJson, executionType);
processDefinition = (ProcessDefinition) result.get(Constants.DATA_LIST);
processDefinitionCode = processDefinition.getCode();
}
if (schedule != null) {
createOrUpdateSchedule(user, projectCode, processDefinitionCode, schedule, workerGroup, warningType, warningGroupId);
}
processDefinitionService.releaseProcessDefinition(user, projectCode, processDefinitionCode, ReleaseState.ONLINE);
return processDefinitionCode;
}
/**
* get process definition
* |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 9,779 | [Bug] [python] release_state do not work in process definition | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
When users set `OFFLINE` to process definition and submit to python-gateway-service, they want to submit process definition but keep it offline. but we currently do not pass attr `self.release_state` to python-gateway-service.
https://github.com/apache/dolphinscheduler/blob/5289b09817396046489b28857ad54a85c5ffddb2/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/process_definition.py#L357-L372
and the default process definition state always online
https://github.com/apache/dolphinscheduler/blob/3457cee96047ab7ab0371a61852cac3e5a98d991/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java#L249-L250
### What you expected to happen
when set process definition state as offline, it should be offline
### How to reproduce
see what happend
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/9779 | https://github.com/apache/dolphinscheduler/pull/10151 | edcb7aad23f73fb166efc3863dfb58e137ca05b4 | 56e0ea802d93667de8c48796a9291a775abddd49 | 2022-04-26T06:58:48Z | java | 2022-05-24T02:25:19Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java | * @param user user who create or update schedule
* @param projectCode project which process definition belongs to
* @param processDefinitionName process definition name
*/
private ProcessDefinition getProcessDefinition(User user, long projectCode, String processDefinitionName) {
Map<String, Object> verifyProcessDefinitionExists = processDefinitionService.verifyProcessDefinitionName(user, projectCode, processDefinitionName);
Status verifyStatus = (Status) verifyProcessDefinitionExists.get(Constants.STATUS);
ProcessDefinition processDefinition = null;
if (verifyStatus == Status.PROCESS_DEFINITION_NAME_EXIST) {
processDefinition = processDefinitionMapper.queryByDefineName(projectCode, processDefinitionName);
} else if (verifyStatus != Status.SUCCESS) {
String msg = "Verify process definition exists status is invalid, neither SUCCESS or PROCESS_DEFINITION_NAME_EXIST.";
logger.error(msg);
throw new RuntimeException(msg);
}
return processDefinition;
}
/**
* create or update process definition schedule.
* It would always use latest schedule define in workflow-as-code, and set schedule online when
* it's not null
*
* @param user user who create or update schedule
* @param projectCode project which process definition belongs to
* @param processDefinitionCode process definition code
* @param schedule schedule expression
* @param workerGroup work group
* @param warningType warning type
* @param warningGroupId warning group id
*/ |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 9,779 | [Bug] [python] release_state do not work in process definition | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
When users set `OFFLINE` to process definition and submit to python-gateway-service, they want to submit process definition but keep it offline. but we currently do not pass attr `self.release_state` to python-gateway-service.
https://github.com/apache/dolphinscheduler/blob/5289b09817396046489b28857ad54a85c5ffddb2/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/process_definition.py#L357-L372
and the default process definition state always online
https://github.com/apache/dolphinscheduler/blob/3457cee96047ab7ab0371a61852cac3e5a98d991/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java#L249-L250
### What you expected to happen
when set process definition state as offline, it should be offline
### How to reproduce
see what happend
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/9779 | https://github.com/apache/dolphinscheduler/pull/10151 | edcb7aad23f73fb166efc3863dfb58e137ca05b4 | 56e0ea802d93667de8c48796a9291a775abddd49 | 2022-04-26T06:58:48Z | java | 2022-05-24T02:25:19Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java | private void createOrUpdateSchedule(User user,
long projectCode,
long processDefinitionCode,
String schedule,
String workerGroup,
String warningType,
int warningGroupId) {
Schedule scheduleObj = scheduleMapper.queryByProcessDefinitionCode(processDefinitionCode);
int scheduleId;
if (scheduleObj == null) {
processDefinitionService.releaseProcessDefinition(user, projectCode, processDefinitionCode, ReleaseState.ONLINE);
Map<String, Object> result = schedulerService.insertSchedule(user, projectCode, processDefinitionCode, schedule, WarningType.valueOf(warningType),
warningGroupId, DEFAULT_FAILURE_STRATEGY, DEFAULT_PRIORITY, workerGroup, DEFAULT_ENVIRONMENT_CODE);
scheduleId = (int) result.get("scheduleId");
} else {
scheduleId = scheduleObj.getId();
processDefinitionService.releaseProcessDefinition(user, projectCode, processDefinitionCode, ReleaseState.OFFLINE);
schedulerService.updateSchedule(user, projectCode, scheduleId, schedule, WarningType.valueOf(warningType),
warningGroupId, DEFAULT_FAILURE_STRATEGY, DEFAULT_PRIORITY, workerGroup, DEFAULT_ENVIRONMENT_CODE);
}
schedulerService.setScheduleState(user, projectCode, scheduleId, ReleaseState.ONLINE);
}
public void execProcessInstance(String userName,
String projectName,
String processDefinitionName,
String cronTime,
String workerGroup,
String warningType,
int warningGroupId, |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 9,779 | [Bug] [python] release_state do not work in process definition | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
When users set `OFFLINE` to process definition and submit to python-gateway-service, they want to submit process definition but keep it offline. but we currently do not pass attr `self.release_state` to python-gateway-service.
https://github.com/apache/dolphinscheduler/blob/5289b09817396046489b28857ad54a85c5ffddb2/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/process_definition.py#L357-L372
and the default process definition state always online
https://github.com/apache/dolphinscheduler/blob/3457cee96047ab7ab0371a61852cac3e5a98d991/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java#L249-L250
### What you expected to happen
when set process definition state as offline, it should be offline
### How to reproduce
see what happend
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/9779 | https://github.com/apache/dolphinscheduler/pull/10151 | edcb7aad23f73fb166efc3863dfb58e137ca05b4 | 56e0ea802d93667de8c48796a9291a775abddd49 | 2022-04-26T06:58:48Z | java | 2022-05-24T02:25:19Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java | Integer timeout
) {
User user = usersService.queryUser(userName);
Project project = projectMapper.queryByName(projectName);
ProcessDefinition processDefinition = processDefinitionMapper.queryByDefineName(project.getCode(), processDefinitionName);
processDefinitionService.releaseProcessDefinition(user, project.getCode(), processDefinition.getCode(), ReleaseState.ONLINE);
executorService.execProcessInstance(user,
project.getCode(),
processDefinition.getCode(),
cronTime,
null,
DEFAULT_FAILURE_STRATEGY,
null,
DEFAULT_TASK_DEPEND_TYPE,
WarningType.valueOf(warningType),
warningGroupId,
DEFAULT_RUN_MODE,
DEFAULT_PRIORITY,
workerGroup,
DEFAULT_ENVIRONMENT_CODE,
timeout,
null,
null,
DEFAULT_DRY_RUN,
COMPLEMENT_DEPENDENT_MODE
);
}
/* |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 9,779 | [Bug] [python] release_state do not work in process definition | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
When users set `OFFLINE` to process definition and submit to python-gateway-service, they want to submit process definition but keep it offline. but we currently do not pass attr `self.release_state` to python-gateway-service.
https://github.com/apache/dolphinscheduler/blob/5289b09817396046489b28857ad54a85c5ffddb2/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/process_definition.py#L357-L372
and the default process definition state always online
https://github.com/apache/dolphinscheduler/blob/3457cee96047ab7ab0371a61852cac3e5a98d991/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java#L249-L250
### What you expected to happen
when set process definition state as offline, it should be offline
### How to reproduce
see what happend
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/9779 | https://github.com/apache/dolphinscheduler/pull/10151 | edcb7aad23f73fb166efc3863dfb58e137ca05b4 | 56e0ea802d93667de8c48796a9291a775abddd49 | 2022-04-26T06:58:48Z | java | 2022-05-24T02:25:19Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java | Grant project's permission to user. Use when project's created user not current but
Python API use it to change process definition.
*/
private Integer grantProjectToUser(Project project, User user) {
Date now = new Date();
ProjectUser projectUser = new ProjectUser();
projectUser.setUserId(user.getId());
projectUser.setProjectId(project.getId());
projectUser.setPerm(Constants.AUTHORIZE_WRITABLE_PERM);
projectUser.setCreateTime(now);
projectUser.setUpdateTime(now);
return projectUserMapper.insert(projectUser);
}
/*
Grant or create project. Create a new project if project do not exists, and grant the project
permission to user if project exists but without permission to this user.
*/
public void createOrGrantProject(String userName, String name, String desc) {
User user = usersService.queryUser(userName);
Project project;
project = projectMapper.queryByName(name);
if (project == null) {
projectService.createProject(user, name, desc);
} else if (project.getUserId() != user.getId()) {
ProjectUser projectUser = projectUserMapper.queryProjectRelation(project.getId(), user.getId());
if (projectUser == null) {
grantProjectToUser(project, user);
}
}
} |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 9,779 | [Bug] [python] release_state do not work in process definition | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
When users set `OFFLINE` to process definition and submit to python-gateway-service, they want to submit process definition but keep it offline. but we currently do not pass attr `self.release_state` to python-gateway-service.
https://github.com/apache/dolphinscheduler/blob/5289b09817396046489b28857ad54a85c5ffddb2/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/process_definition.py#L357-L372
and the default process definition state always online
https://github.com/apache/dolphinscheduler/blob/3457cee96047ab7ab0371a61852cac3e5a98d991/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java#L249-L250
### What you expected to happen
when set process definition state as offline, it should be offline
### How to reproduce
see what happend
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/9779 | https://github.com/apache/dolphinscheduler/pull/10151 | edcb7aad23f73fb166efc3863dfb58e137ca05b4 | 56e0ea802d93667de8c48796a9291a775abddd49 | 2022-04-26T06:58:48Z | java | 2022-05-24T02:25:19Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java | public Map<String, Object> createQueue(String name, String queueName) {
Result<Object> verifyQueueExists = queueService.verifyQueue(name, queueName);
if (verifyQueueExists.getCode() == 0) {
return queueService.createQueue(dummyAdminUser, name, queueName);
} else {
Map<String, Object> result = new HashMap<>();
result.put(Constants.STATUS, Status.SUCCESS);
result.put(Constants.MSG, Status.SUCCESS.getMsg());
return result;
}
}
public Map<String, Object> createTenant(String tenantCode, String desc, String queueName) throws Exception {
if (tenantService.checkTenantExists(tenantCode)) {
Map<String, Object> result = new HashMap<>();
result.put(Constants.STATUS, Status.SUCCESS);
result.put(Constants.MSG, Status.SUCCESS.getMsg());
return result;
} else {
Result<Object> verifyQueueExists = queueService.verifyQueue(queueName, queueName);
if (verifyQueueExists.getCode() == 0) {
queueService.createQueue(dummyAdminUser, queueName, queueName);
}
Map<String, Object> result = queueService.queryQueueName(queueName);
List<Queue> queueList = (List<Queue>) result.get(Constants.DATA_LIST);
Queue queue = queueList.get(0);
return tenantService.createTenant(dummyAdminUser, tenantCode, queue.getId(), desc);
} |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 9,779 | [Bug] [python] release_state do not work in process definition | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
When users set `OFFLINE` to process definition and submit to python-gateway-service, they want to submit process definition but keep it offline. but we currently do not pass attr `self.release_state` to python-gateway-service.
https://github.com/apache/dolphinscheduler/blob/5289b09817396046489b28857ad54a85c5ffddb2/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/process_definition.py#L357-L372
and the default process definition state always online
https://github.com/apache/dolphinscheduler/blob/3457cee96047ab7ab0371a61852cac3e5a98d991/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java#L249-L250
### What you expected to happen
when set process definition state as offline, it should be offline
### How to reproduce
see what happend
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/9779 | https://github.com/apache/dolphinscheduler/pull/10151 | edcb7aad23f73fb166efc3863dfb58e137ca05b4 | 56e0ea802d93667de8c48796a9291a775abddd49 | 2022-04-26T06:58:48Z | java | 2022-05-24T02:25:19Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java | }
public void createUser(String userName,
String userPassword,
String email,
String phone,
String tenantCode,
String queue,
int state) {
User user = usersService.queryUser(userName);
if (Objects.isNull(user)) {
Map<String, Object> tenantResult = tenantService.queryByTenantCode(tenantCode);
Tenant tenant = (Tenant) tenantResult.get(Constants.DATA_LIST);
usersService.createUser(userName, userPassword, email, tenant.getId(), phone, queue, state);
}
}
/**
* Get datasource by given datasource name. It return map contain datasource id, type, name.
* Useful in Python API create sql task which need datasource information.
*
* @param datasourceName user who create or update schedule
*/
public Map<String, Object> getDatasourceInfo(String datasourceName) {
Map<String, Object> result = new HashMap<>();
List<DataSource> dataSourceList = dataSourceMapper.queryDataSourceByName(datasourceName);
if (dataSourceList == null || dataSourceList.isEmpty()) {
String msg = String.format("Can not find any datasource by name %s", datasourceName);
logger.error(msg);
throw new IllegalArgumentException(msg);
} else if (dataSourceList.size() > 1) {
String msg = String.format("Get more than one datasource by name %s", datasourceName); |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 9,779 | [Bug] [python] release_state do not work in process definition | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
When users set `OFFLINE` to process definition and submit to python-gateway-service, they want to submit process definition but keep it offline. but we currently do not pass attr `self.release_state` to python-gateway-service.
https://github.com/apache/dolphinscheduler/blob/5289b09817396046489b28857ad54a85c5ffddb2/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/process_definition.py#L357-L372
and the default process definition state always online
https://github.com/apache/dolphinscheduler/blob/3457cee96047ab7ab0371a61852cac3e5a98d991/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java#L249-L250
### What you expected to happen
when set process definition state as offline, it should be offline
### How to reproduce
see what happend
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/9779 | https://github.com/apache/dolphinscheduler/pull/10151 | edcb7aad23f73fb166efc3863dfb58e137ca05b4 | 56e0ea802d93667de8c48796a9291a775abddd49 | 2022-04-26T06:58:48Z | java | 2022-05-24T02:25:19Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java | logger.error(msg);
throw new IllegalArgumentException(msg);
} else {
DataSource dataSource = dataSourceList.get(0);
result.put("id", dataSource.getId());
result.put("type", dataSource.getType().name());
result.put("name", dataSource.getName());
}
return result;
}
/**
* Get processDefinition by given processDefinitionName name. It return map contain processDefinition id, name, code.
* Useful in Python API create subProcess task which need processDefinition information.
*
* @param userName user who create or update schedule
* @param projectName project name which process definition belongs to
* @param processDefinitionName process definition name
*/
public Map<String, Object> getProcessDefinitionInfo(String userName, String projectName, String processDefinitionName) {
Map<String, Object> result = new HashMap<>();
User user = usersService.queryUser(userName);
Project project = (Project) projectService.queryByName(user, projectName).get(Constants.DATA_LIST);
long projectCode = project.getCode();
ProcessDefinition processDefinition = getProcessDefinition(user, projectCode, processDefinitionName);
if (processDefinition != null) {
processDefinitionService.releaseProcessDefinition(user, projectCode, processDefinition.getCode(), ReleaseState.ONLINE);
result.put("id", processDefinition.getId());
result.put("name", processDefinition.getName()); |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 9,779 | [Bug] [python] release_state do not work in process definition | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
When users set `OFFLINE` to process definition and submit to python-gateway-service, they want to submit process definition but keep it offline. but we currently do not pass attr `self.release_state` to python-gateway-service.
https://github.com/apache/dolphinscheduler/blob/5289b09817396046489b28857ad54a85c5ffddb2/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/process_definition.py#L357-L372
and the default process definition state always online
https://github.com/apache/dolphinscheduler/blob/3457cee96047ab7ab0371a61852cac3e5a98d991/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java#L249-L250
### What you expected to happen
when set process definition state as offline, it should be offline
### How to reproduce
see what happend
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/9779 | https://github.com/apache/dolphinscheduler/pull/10151 | edcb7aad23f73fb166efc3863dfb58e137ca05b4 | 56e0ea802d93667de8c48796a9291a775abddd49 | 2022-04-26T06:58:48Z | java | 2022-05-24T02:25:19Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java | result.put("code", processDefinition.getCode());
} else {
String msg = String.format("Can not find valid process definition by name %s", processDefinitionName);
logger.error(msg);
throw new IllegalArgumentException(msg);
}
return result;
}
/**
* Get project, process definition, task code.
* Useful in Python API create dependent task which need processDefinition information.
*
* @param projectName project name which process definition belongs to
* @param processDefinitionName process definition name
* @param taskName task name
*/
public Map<String, Object> getDependentInfo(String projectName, String processDefinitionName, String taskName) {
Map<String, Object> result = new HashMap<>();
Project project = projectMapper.queryByName(projectName);
if (project == null) {
String msg = String.format("Can not find valid project by name %s", projectName);
logger.error(msg);
throw new IllegalArgumentException(msg);
}
long projectCode = project.getCode();
result.put("projectCode", projectCode);
ProcessDefinition processDefinition = processDefinitionMapper.queryByDefineName(projectCode, processDefinitionName);
if (processDefinition == null) {
String msg = String.format("Can not find valid process definition by name %s", processDefinitionName);
logger.error(msg); |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 9,779 | [Bug] [python] release_state do not work in process definition | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
When users set `OFFLINE` to process definition and submit to python-gateway-service, they want to submit process definition but keep it offline. but we currently do not pass attr `self.release_state` to python-gateway-service.
https://github.com/apache/dolphinscheduler/blob/5289b09817396046489b28857ad54a85c5ffddb2/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/process_definition.py#L357-L372
and the default process definition state always online
https://github.com/apache/dolphinscheduler/blob/3457cee96047ab7ab0371a61852cac3e5a98d991/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java#L249-L250
### What you expected to happen
when set process definition state as offline, it should be offline
### How to reproduce
see what happend
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/9779 | https://github.com/apache/dolphinscheduler/pull/10151 | edcb7aad23f73fb166efc3863dfb58e137ca05b4 | 56e0ea802d93667de8c48796a9291a775abddd49 | 2022-04-26T06:58:48Z | java | 2022-05-24T02:25:19Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java | throw new IllegalArgumentException(msg);
}
result.put("processDefinitionCode", processDefinition.getCode());
if (taskName != null) {
TaskDefinition taskDefinition = taskDefinitionMapper.queryByName(projectCode, taskName);
result.put("taskDefinitionCode", taskDefinition.getCode());
}
return result;
}
/**
* Get resource by given program type and full name. It return map contain resource id, name.
* Useful in Python API create flink or spark task which need processDefinition information.
*
* @param programType program type one of SCALA, JAVA and PYTHON
* @param fullName full name of the resource
*/
public Map<String, Object> getResourcesFileInfo(String programType, String fullName) {
Map<String, Object> result = new HashMap<>();
Map<String, Object> resources = resourceService.queryResourceByProgramType(dummyAdminUser, ResourceType.FILE, ProgramType.valueOf(programType));
List<ResourceComponent> resourcesComponent = (List<ResourceComponent>) resources.get(Constants.DATA_LIST);
List<ResourceComponent> namedResources = resourcesComponent.stream().filter(s -> fullName.equals(s.getFullName())).collect(Collectors.toList());
if (CollectionUtils.isEmpty(namedResources)) {
String msg = String.format("Can not find valid resource by program type %s and name %s", programType, fullName);
logger.error(msg);
throw new IllegalArgumentException(msg);
}
result.put("id", namedResources.get(0).getId());
result.put("name", namedResources.get(0).getName());
return result;
} |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 9,779 | [Bug] [python] release_state do not work in process definition | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
When users set `OFFLINE` to process definition and submit to python-gateway-service, they want to submit process definition but keep it offline. but we currently do not pass attr `self.release_state` to python-gateway-service.
https://github.com/apache/dolphinscheduler/blob/5289b09817396046489b28857ad54a85c5ffddb2/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/process_definition.py#L357-L372
and the default process definition state always online
https://github.com/apache/dolphinscheduler/blob/3457cee96047ab7ab0371a61852cac3e5a98d991/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java#L249-L250
### What you expected to happen
when set process definition state as offline, it should be offline
### How to reproduce
see what happend
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/9779 | https://github.com/apache/dolphinscheduler/pull/10151 | edcb7aad23f73fb166efc3863dfb58e137ca05b4 | 56e0ea802d93667de8c48796a9291a775abddd49 | 2022-04-26T06:58:48Z | java | 2022-05-24T02:25:19Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java | @PostConstruct
public void init() {
if (pythonGatewayConfiguration.getEnabled()) {
this.start();
}
}
private void start() {
GatewayServer server;
try {
InetAddress gatewayHost = InetAddress.getByName(pythonGatewayConfiguration.getGatewayServerAddress());
InetAddress pythonHost = InetAddress.getByName(pythonGatewayConfiguration.getPythonAddress());
server = new GatewayServer(
this,
pythonGatewayConfiguration.getGatewayServerPort(),
pythonGatewayConfiguration.getPythonPort(),
gatewayHost,
pythonHost,
pythonGatewayConfiguration.getConnectTimeout(),
pythonGatewayConfiguration.getReadTimeout(),
null
);
GatewayServer.turnLoggingOn();
logger.info("PythonGatewayService started on: " + gatewayHost.toString());
server.start();
} catch (UnknownHostException e) {
logger.error("exception occurred while constructing PythonGatewayService().", e);
}
}
} |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,225 | [Improvement][Mysql] Change Mysql Driver | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar feature requirement.
### Description
```
Loading class `com.mysql.jdbc.Driver'.
This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'.
The driver is automatically registered via the SPI and manual loading
of the driver class is generally unnecessary.
```
We need to change to `com.mysql.cj.jdbc.Driver`.
### Use case
_No response_
### Related issues
_No response_
### Are you willing to submit a PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10225 | https://github.com/apache/dolphinscheduler/pull/10220 | 87d9ec1deee4d7e492d4fe4da404ec513655636d | aba5f8a40e9b86068cf9bff374bf1842c0beaf3f | 2022-05-24T07:36:08Z | java | 2022-05-25T06:09:15Z | dolphinscheduler-data-quality/src/test/java/org/apache/dolphinscheduler/data/quality/configuration/ConfigurationParserTest.java | /*
* 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.
*/
package org.apache.dolphinscheduler.data.quality.configuration;
import org.apache.dolphinscheduler.data.quality.config.DataQualityConfiguration;
import org.apache.dolphinscheduler.data.quality.utils.JsonUtils;
import org.junit.Assert;
import org.junit.Test;
/**
* ConfigurationParserTest
*/
public class ConfigurationParserTest { |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,225 | [Improvement][Mysql] Change Mysql Driver | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar feature requirement.
### Description
```
Loading class `com.mysql.jdbc.Driver'.
This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'.
The driver is automatically registered via the SPI and manual loading
of the driver class is generally unnecessary.
```
We need to change to `com.mysql.cj.jdbc.Driver`.
### Use case
_No response_
### Related issues
_No response_
### Are you willing to submit a PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10225 | https://github.com/apache/dolphinscheduler/pull/10220 | 87d9ec1deee4d7e492d4fe4da404ec513655636d | aba5f8a40e9b86068cf9bff374bf1842c0beaf3f | 2022-05-24T07:36:08Z | java | 2022-05-25T06:09:15Z | dolphinscheduler-data-quality/src/test/java/org/apache/dolphinscheduler/data/quality/configuration/ConfigurationParserTest.java | @Test
public void testConfigurationValidate() {
Assert.assertEquals(1,verifyConfigurationValidate());
}
private int verifyConfigurationValidate() {
int flag = 1;
try {
String parameterStr = "{\"name\":\"data quality test\",\"env\":{\"type\":\"batch\",\"config\":null},"
+ "\"readers\":[{\"type\":\"JDBC\",\"config\":{\"database\":\"test\",\"password\":\"Test@123!\","
+ "\"driver\":\"com.mysql.jdbc.Driver\",\"user\":\"test\",\"output_table\":\"test1\",\"table\":\"test1\","
+ "\"url\":\"jdbc:mysql://172.16.100.199:3306/test\"} }],\"transformers\":[{\"type\":\"sql\",\"config\":"
+ "{\"index\":1,\"output_table\":\"miss_count\",\"sql\":\"SELECT COUNT(*) AS miss FROM test1 WHERE (c1 is null or c1 = '') \"} },"
+ "{\"type\":\"sql\",\"config\":{\"index\":2,\"output_table\":\"total_count\",\"sql\":\"SELECT COUNT(*) AS total FROM test1 \"} }],"
+ "\"writers\":[{\"type\":\"JDBC\",\"config\":{\"database\":\"dolphinscheduler\",\"password\":\"test\","
+ "\"driver\":\"org.postgresql.Driver\",\"user\":\"test\",\"table\":\"t_ds_dq_execute_result\","
+ "\"url\":\"jdbc:postgresql://172.16.100.199:5432/dolphinscheduler?stringtype=unspecified\","
+ "\"sql\":\"SELECT 0 as rule_type,'data quality test' as rule_name,7 as process_definition_id,80 as process_instance_id,"
+ "80 as task_instance_id,miss_count.miss AS statistics_value, total_count.total AS comparison_value,2 as check_type,10 as"
+ " threshold, 3 as operator, 0 as failure_strategy, '2021-06-29 10:18:59' as create_time,'2021-06-29 10:18:59' as update_time "
+ "from miss_count FULL JOIN total_count\"} }]}";
DataQualityConfiguration dataQualityConfiguration = JsonUtils.fromJson(parameterStr,DataQualityConfiguration.class);
dataQualityConfiguration.validate();
} catch (Exception e) {
flag = 0;
e.printStackTrace();
}
return flag;
}
} |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,225 | [Improvement][Mysql] Change Mysql Driver | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar feature requirement.
### Description
```
Loading class `com.mysql.jdbc.Driver'.
This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'.
The driver is automatically registered via the SPI and manual loading
of the driver class is generally unnecessary.
```
We need to change to `com.mysql.cj.jdbc.Driver`.
### Use case
_No response_
### Related issues
_No response_
### Are you willing to submit a PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10225 | https://github.com/apache/dolphinscheduler/pull/10220 | 87d9ec1deee4d7e492d4fe4da404ec513655636d | aba5f8a40e9b86068cf9bff374bf1842c0beaf3f | 2022-05-24T07:36:08Z | java | 2022-05-25T06:09:15Z | dolphinscheduler-data-quality/src/test/java/org/apache/dolphinscheduler/data/quality/flow/reader/ReaderFactoryTest.java | /*
* 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.
*/
package org.apache.dolphinscheduler.data.quality.flow.reader;
import static org.apache.dolphinscheduler.data.quality.Constants.DATABASE;
import static org.apache.dolphinscheduler.data.quality.Constants.DRIVER;
import static org.apache.dolphinscheduler.data.quality.Constants.PASSWORD;
import static org.apache.dolphinscheduler.data.quality.Constants.TABLE;
import static org.apache.dolphinscheduler.data.quality.Constants.URL;
import static org.apache.dolphinscheduler.data.quality.Constants.USER;
import org.apache.dolphinscheduler.data.quality.config.ReaderConfig;
import org.apache.dolphinscheduler.data.quality.exception.DataQualityException;
import org.apache.dolphinscheduler.data.quality.flow.batch.BatchReader;
import org.apache.dolphinscheduler.data.quality.flow.batch.reader.ReaderFactory;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,225 | [Improvement][Mysql] Change Mysql Driver | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar feature requirement.
### Description
```
Loading class `com.mysql.jdbc.Driver'.
This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'.
The driver is automatically registered via the SPI and manual loading
of the driver class is generally unnecessary.
```
We need to change to `com.mysql.cj.jdbc.Driver`.
### Use case
_No response_
### Related issues
_No response_
### Are you willing to submit a PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10225 | https://github.com/apache/dolphinscheduler/pull/10220 | 87d9ec1deee4d7e492d4fe4da404ec513655636d | aba5f8a40e9b86068cf9bff374bf1842c0beaf3f | 2022-05-24T07:36:08Z | java | 2022-05-25T06:09:15Z | dolphinscheduler-data-quality/src/test/java/org/apache/dolphinscheduler/data/quality/flow/reader/ReaderFactoryTest.java | import java.util.Map;
import org.junit.Assert;
import org.junit.Test;
/**
* ConnectorFactoryTest
*/
public class ReaderFactoryTest {
@Test
public void testConnectorGenerate() throws DataQualityException {
List<ReaderConfig> readerConfigs = new ArrayList<>();
ReaderConfig readerConfig = new ReaderConfig();
readerConfig.setType("JDBC");
Map<String,Object> config = new HashMap<>();
config.put(DATABASE,"test");
config.put(TABLE,"test1");
config.put(URL,"jdbc:mysql://localhost:3306/test");
config.put(USER,"test");
config.put(PASSWORD,"123456");
config.put(DRIVER,"com.mysql.jdbc.Driver");
readerConfig.setConfig(config);
readerConfigs.add(readerConfig);
int flag = 0;
List<BatchReader> readers = ReaderFactory.getInstance().getReaders(null,readerConfigs);
if (readers != null && readers.size() >= 1) {
flag = 1;
}
Assert.assertEquals(1,flag);
}
} |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,277 | [Bug] [DolphinScheduler-alert-email] Running unit test testGetMessageFromTemplate() fails | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
I can pass this test case on linux, but there is a problem on windows. Through debug, it is found that there is a problem with the newline character of the string generated by the `generateMockTableTypeResultByHand()` method. This method does not consider platform independence and uses `LF` hard-coded as a newline
### What you expected to happen
`generateMockTableTypeResultByHand()` generates platform-independent strings that pass the test case
### How to reproduce
OS : windows 10
JDK : JDK 8
Run `mvn clean test -e` in command line window
### Anything else
Bug info
`
[INFO] Running org.apache.dolphinscheduler.plugin.alert.email.template.DefaultHTMLTemplateTest
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.004 s <<< FAILURE! - in org.apache.dolphinscheduler.plugin.alert.email.template.DefaultHTMLTemplateTest
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.004 s <<< FAILURE! - in org.apache.dolphinscheduler.plugin.alert.email.template.DefaultHTMLTemplateTest
testGetMessageFromTemplate(org.apache.dolphinscheduler.plugin.alert.email.template.DefaultHTMLTemplateTest) Time elapsed: 0.004 s <<< FAILURE!
org.junit.ComparisonFailure:
]
<tr><td>mysql200</t...> but was:<...er</th></tr></thead>[]
<tr><td>mysql200</t...>
at org.apache.dolphinscheduler.plugin.alert.email.template.DefaultHTMLTemplateTest.testGetMessageFromTemplate(DefaultHTMLTemplateTest.java:44)
[INFO]
[INFO] Results:
[INFO]
[ERROR] Failures:
Failures:
]
<tr><td>mysql200</t...> but was:<...er</th></tr></thead>[]
<tr><td>mysql200</t...>
[INFO]
[ERROR] Tests run: 10, Failures: 1, Errors: 0, Skipped: 0
Tests run: 10, Failures: 1, Errors: 0, Skipped: 0
[INFO]
`
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10277 | https://github.com/apache/dolphinscheduler/pull/10278 | 7ac8ea493cf6f458097c695baa500dd0c22b3bb8 | 62bd9d2c4c0ee110687d1454a34209a77f175d94 | 2022-05-29T08:54:07Z | java | 2022-05-29T10:44:26Z | dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/template/DefaultHTMLTemplateTest.java | /*
* 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.
*/
package org.apache.dolphinscheduler.plugin.alert.email.template;
import static org.junit.Assert.assertEquals;
import org.apache.dolphinscheduler.alert.api.ShowType;
import org.apache.dolphinscheduler.plugin.alert.email.EmailConstants;
import org.apache.dolphinscheduler.spi.utils.JSONUtils;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DefaultHTMLTemplateTest { |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,277 | [Bug] [DolphinScheduler-alert-email] Running unit test testGetMessageFromTemplate() fails | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
I can pass this test case on linux, but there is a problem on windows. Through debug, it is found that there is a problem with the newline character of the string generated by the `generateMockTableTypeResultByHand()` method. This method does not consider platform independence and uses `LF` hard-coded as a newline
### What you expected to happen
`generateMockTableTypeResultByHand()` generates platform-independent strings that pass the test case
### How to reproduce
OS : windows 10
JDK : JDK 8
Run `mvn clean test -e` in command line window
### Anything else
Bug info
`
[INFO] Running org.apache.dolphinscheduler.plugin.alert.email.template.DefaultHTMLTemplateTest
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.004 s <<< FAILURE! - in org.apache.dolphinscheduler.plugin.alert.email.template.DefaultHTMLTemplateTest
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.004 s <<< FAILURE! - in org.apache.dolphinscheduler.plugin.alert.email.template.DefaultHTMLTemplateTest
testGetMessageFromTemplate(org.apache.dolphinscheduler.plugin.alert.email.template.DefaultHTMLTemplateTest) Time elapsed: 0.004 s <<< FAILURE!
org.junit.ComparisonFailure:
]
<tr><td>mysql200</t...> but was:<...er</th></tr></thead>[]
<tr><td>mysql200</t...>
at org.apache.dolphinscheduler.plugin.alert.email.template.DefaultHTMLTemplateTest.testGetMessageFromTemplate(DefaultHTMLTemplateTest.java:44)
[INFO]
[INFO] Results:
[INFO]
[ERROR] Failures:
Failures:
]
<tr><td>mysql200</t...> but was:<...er</th></tr></thead>[]
<tr><td>mysql200</t...>
[INFO]
[ERROR] Tests run: 10, Failures: 1, Errors: 0, Skipped: 0
Tests run: 10, Failures: 1, Errors: 0, Skipped: 0
[INFO]
`
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10277 | https://github.com/apache/dolphinscheduler/pull/10278 | 7ac8ea493cf6f458097c695baa500dd0c22b3bb8 | 62bd9d2c4c0ee110687d1454a34209a77f175d94 | 2022-05-29T08:54:07Z | java | 2022-05-29T10:44:26Z | dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/template/DefaultHTMLTemplateTest.java | private static final Logger logger = LoggerFactory.getLogger(DefaultHTMLTemplateTest.class);
@Test
public void testGetMessageFromTemplate() {
DefaultHTMLTemplate template = new DefaultHTMLTemplate();
String tableTypeMessage = template.getMessageFromTemplate(list2String(), ShowType.TABLE, true);
assertEquals(tableTypeMessage, generateMockTableTypeResultByHand());
String textTypeMessage = template.getMessageFromTemplate(list2String(), ShowType.TEXT, true);
assertEquals(textTypeMessage, generateMockTextTypeResultByHand());
}
private String list2String() {
LinkedHashMap<String, Object> map1 = new LinkedHashMap<>();
map1.put("mysql service name", "mysql200");
map1.put("mysql address", "192.168.xx.xx");
map1.put("database client connections", "190");
map1.put("port", "3306");
map1.put("no index of number", "80"); |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,277 | [Bug] [DolphinScheduler-alert-email] Running unit test testGetMessageFromTemplate() fails | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
I can pass this test case on linux, but there is a problem on windows. Through debug, it is found that there is a problem with the newline character of the string generated by the `generateMockTableTypeResultByHand()` method. This method does not consider platform independence and uses `LF` hard-coded as a newline
### What you expected to happen
`generateMockTableTypeResultByHand()` generates platform-independent strings that pass the test case
### How to reproduce
OS : windows 10
JDK : JDK 8
Run `mvn clean test -e` in command line window
### Anything else
Bug info
`
[INFO] Running org.apache.dolphinscheduler.plugin.alert.email.template.DefaultHTMLTemplateTest
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.004 s <<< FAILURE! - in org.apache.dolphinscheduler.plugin.alert.email.template.DefaultHTMLTemplateTest
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.004 s <<< FAILURE! - in org.apache.dolphinscheduler.plugin.alert.email.template.DefaultHTMLTemplateTest
testGetMessageFromTemplate(org.apache.dolphinscheduler.plugin.alert.email.template.DefaultHTMLTemplateTest) Time elapsed: 0.004 s <<< FAILURE!
org.junit.ComparisonFailure:
]
<tr><td>mysql200</t...> but was:<...er</th></tr></thead>[]
<tr><td>mysql200</t...>
at org.apache.dolphinscheduler.plugin.alert.email.template.DefaultHTMLTemplateTest.testGetMessageFromTemplate(DefaultHTMLTemplateTest.java:44)
[INFO]
[INFO] Results:
[INFO]
[ERROR] Failures:
Failures:
]
<tr><td>mysql200</t...> but was:<...er</th></tr></thead>[]
<tr><td>mysql200</t...>
[INFO]
[ERROR] Tests run: 10, Failures: 1, Errors: 0, Skipped: 0
Tests run: 10, Failures: 1, Errors: 0, Skipped: 0
[INFO]
`
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10277 | https://github.com/apache/dolphinscheduler/pull/10278 | 7ac8ea493cf6f458097c695baa500dd0c22b3bb8 | 62bd9d2c4c0ee110687d1454a34209a77f175d94 | 2022-05-29T08:54:07Z | java | 2022-05-29T10:44:26Z | dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/template/DefaultHTMLTemplateTest.java | LinkedHashMap<String, Object> map2 = new LinkedHashMap<>();
map2.put("mysql service name", "mysql210");
map2.put("mysql address", "192.168.xx.xx");
map2.put("database client connections", "90");
map2.put("port", "3306");
map2.put("no index of number", "10");
List<LinkedHashMap<String, Object>> maps = new ArrayList<>();
maps.add(0, map1);
maps.add(1, map2);
String mapjson = JSONUtils.toJsonString(maps);
logger.info(mapjson);
return mapjson;
}
private String generateMockTableTypeResultByHand() {
return EmailConstants.HTML_HEADER_PREFIX
+ "<thead>"
+ "<tr><th>mysql service name</th><th>mysql address</th><th>database client connections</th><th>port</th><th>no index of number</th></tr>"
+ "</thead>\n"
+ "<tr><td>mysql200</td><td>192.168.xx.xx</td><td>190</td><td>3306</td><td>80</td></tr>"
+ "<tr><td>mysql210</td><td>192.168.xx.xx</td><td>90</td><td>3306</td><td>10</td></tr>"
+ EmailConstants.TABLE_BODY_HTML_TAIL;
}
private String generateMockTextTypeResultByHand() {
return EmailConstants.HTML_HEADER_PREFIX
+ "<tr><td>{\"mysql service name\":\"mysql200\",\"mysql address\":\"192.168.xx.xx\",\"database client connections\":\"190\",\"port\":\"3306\",\"no index of number\":\"80\"}</td></tr>"
+ "<tr><td>{\"mysql service name\":\"mysql210\",\"mysql address\":\"192.168.xx.xx\",\"database client connections\":\"90\",\"port\":\"3306\",\"no index of number\":\"10\"}</td></tr>"
+ EmailConstants.TABLE_BODY_HTML_TAIL;
}
} |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 9,977 | [Feature][Task Plugin] Add support for dynamic form for zeppelin task plugin | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar feature requirement.
### Description
* Add support for Apache Zeppelin `dynamic form` in zeppelin task plugin. Click [here](https://zeppelin.apache.org/docs/0.10.1/usage/dynamic_form/intro.html#text-input-form-1) for details about `dynamic form`.
* Besides adding the support in backend, we need to add one more field in zeppelin task plugin UI for users to input json format parameters. Also we need to update related docs to give users an example.
### Use case
* Already described above.
### Related issues
related: #9814
### Are you willing to submit a PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/9977 | https://github.com/apache/dolphinscheduler/pull/10269 | c5961aed25329b1cbd0aab34fc49cc7cffb39753 | a8a5da367ad37911ee2400df894cdf8ff16fb73e | 2022-05-11T01:56:49Z | java | 2022-05-31T03:19:41Z | dolphinscheduler-task-plugin/dolphinscheduler-task-zeppelin/src/main/java/org/apache/dolphinscheduler/plugin/task/zeppelin/ZeppelinParameters.java | /*
* 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.
*/
package org.apache.dolphinscheduler.plugin.task.zeppelin;
import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo;
import org.apache.dolphinscheduler.plugin.task.api.parameters.AbstractParameters;
import org.apache.dolphinscheduler.spi.utils.StringUtils;
import java.util.Collections;
import java.util.List;
public class ZeppelinParameters extends AbstractParameters {
/**
* parameters for zeppelin client API
* @see <a href="https://zeppelin.apache.org/docs/0.9.0/usage/zeppelin_sdk/client_api.html">Zeppelin_Client_API_Examples</a>
*/
private String noteId; |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 9,977 | [Feature][Task Plugin] Add support for dynamic form for zeppelin task plugin | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar feature requirement.
### Description
* Add support for Apache Zeppelin `dynamic form` in zeppelin task plugin. Click [here](https://zeppelin.apache.org/docs/0.10.1/usage/dynamic_form/intro.html#text-input-form-1) for details about `dynamic form`.
* Besides adding the support in backend, we need to add one more field in zeppelin task plugin UI for users to input json format parameters. Also we need to update related docs to give users an example.
### Use case
* Already described above.
### Related issues
related: #9814
### Are you willing to submit a PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/9977 | https://github.com/apache/dolphinscheduler/pull/10269 | c5961aed25329b1cbd0aab34fc49cc7cffb39753 | a8a5da367ad37911ee2400df894cdf8ff16fb73e | 2022-05-11T01:56:49Z | java | 2022-05-31T03:19:41Z | dolphinscheduler-task-plugin/dolphinscheduler-task-zeppelin/src/main/java/org/apache/dolphinscheduler/plugin/task/zeppelin/ZeppelinParameters.java | private String paragraphId;
@Override
public boolean checkParameters() {
return StringUtils.isNotEmpty(this.noteId) && StringUtils.isNotEmpty(this.paragraphId);
}
@Override
public List<ResourceInfo> getResourceFilesList() {
return Collections.emptyList();
}
public String getNoteId() {
return noteId;
}
public void setNoteId(String noteId) {
this.noteId = noteId;
}
public String getParagraphId() {
return paragraphId;
}
public void setParagraphId(String paragraphId) {
this.paragraphId = paragraphId;
}
@Override
public String toString() {
return "ZeppelinParameters{" +
"noteId='" + noteId + '\'' +
", paragraphId='" + paragraphId + '\'' +
'}';
}
} |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 9,977 | [Feature][Task Plugin] Add support for dynamic form for zeppelin task plugin | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar feature requirement.
### Description
* Add support for Apache Zeppelin `dynamic form` in zeppelin task plugin. Click [here](https://zeppelin.apache.org/docs/0.10.1/usage/dynamic_form/intro.html#text-input-form-1) for details about `dynamic form`.
* Besides adding the support in backend, we need to add one more field in zeppelin task plugin UI for users to input json format parameters. Also we need to update related docs to give users an example.
### Use case
* Already described above.
### Related issues
related: #9814
### Are you willing to submit a PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/9977 | https://github.com/apache/dolphinscheduler/pull/10269 | c5961aed25329b1cbd0aab34fc49cc7cffb39753 | a8a5da367ad37911ee2400df894cdf8ff16fb73e | 2022-05-11T01:56:49Z | java | 2022-05-31T03:19:41Z | dolphinscheduler-task-plugin/dolphinscheduler-task-zeppelin/src/main/java/org/apache/dolphinscheduler/plugin/task/zeppelin/ZeppelinTask.java | /*
* 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.
*/
package org.apache.dolphinscheduler.plugin.task.zeppelin;
import org.apache.dolphinscheduler.plugin.task.api.AbstractTaskExecutor;
import org.apache.dolphinscheduler.plugin.task.api.TaskConstants;
import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
import org.apache.dolphinscheduler.plugin.task.api.parameters.AbstractParameters;
import org.apache.dolphinscheduler.spi.utils.JSONUtils;
import org.apache.dolphinscheduler.spi.utils.PropertyUtils;
import org.apache.zeppelin.client.ClientConfig;
import org.apache.zeppelin.client.ParagraphResult;
import org.apache.zeppelin.client.Status;
import org.apache.zeppelin.client.ZeppelinClient;
public class ZeppelinTask extends AbstractTaskExecutor { |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 9,977 | [Feature][Task Plugin] Add support for dynamic form for zeppelin task plugin | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar feature requirement.
### Description
* Add support for Apache Zeppelin `dynamic form` in zeppelin task plugin. Click [here](https://zeppelin.apache.org/docs/0.10.1/usage/dynamic_form/intro.html#text-input-form-1) for details about `dynamic form`.
* Besides adding the support in backend, we need to add one more field in zeppelin task plugin UI for users to input json format parameters. Also we need to update related docs to give users an example.
### Use case
* Already described above.
### Related issues
related: #9814
### Are you willing to submit a PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/9977 | https://github.com/apache/dolphinscheduler/pull/10269 | c5961aed25329b1cbd0aab34fc49cc7cffb39753 | a8a5da367ad37911ee2400df894cdf8ff16fb73e | 2022-05-11T01:56:49Z | java | 2022-05-31T03:19:41Z | dolphinscheduler-task-plugin/dolphinscheduler-task-zeppelin/src/main/java/org/apache/dolphinscheduler/plugin/task/zeppelin/ZeppelinTask.java | /**
* taskExecutionContext
*/
private final TaskExecutionContext taskExecutionContext;
/**
* zeppelin parameters
*/
private ZeppelinParameters zeppelinParameters;
/**
* zeppelin api client
*/
private ZeppelinClient zClient;
/**
* constructor
*
* @param taskExecutionContext taskExecutionContext |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 9,977 | [Feature][Task Plugin] Add support for dynamic form for zeppelin task plugin | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar feature requirement.
### Description
* Add support for Apache Zeppelin `dynamic form` in zeppelin task plugin. Click [here](https://zeppelin.apache.org/docs/0.10.1/usage/dynamic_form/intro.html#text-input-form-1) for details about `dynamic form`.
* Besides adding the support in backend, we need to add one more field in zeppelin task plugin UI for users to input json format parameters. Also we need to update related docs to give users an example.
### Use case
* Already described above.
### Related issues
related: #9814
### Are you willing to submit a PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/9977 | https://github.com/apache/dolphinscheduler/pull/10269 | c5961aed25329b1cbd0aab34fc49cc7cffb39753 | a8a5da367ad37911ee2400df894cdf8ff16fb73e | 2022-05-11T01:56:49Z | java | 2022-05-31T03:19:41Z | dolphinscheduler-task-plugin/dolphinscheduler-task-zeppelin/src/main/java/org/apache/dolphinscheduler/plugin/task/zeppelin/ZeppelinTask.java | */
protected ZeppelinTask(TaskExecutionContext taskExecutionContext) {
super(taskExecutionContext);
this.taskExecutionContext = taskExecutionContext;
}
@Override
public void init() {
final String taskParams = taskExecutionContext.getTaskParams();
logger.info("zeppelin task params:{}", taskParams);
this.zeppelinParameters = JSONUtils.parseObject(taskParams, ZeppelinParameters.class);
if (this.zeppelinParameters == null || !this.zeppelinParameters.checkParameters()) {
throw new ZeppelinTaskException("zeppelin task params is not valid");
}
this.zClient = getZeppelinClient();
}
@Override
public void handle() throws Exception {
try {
String noteId = this.zeppelinParameters.getNoteId();
String paragraphId = this.zeppelinParameters.getParagraphId();
ParagraphResult paragraphResult = this.zClient.executeParagraph(noteId, paragraphId);
String resultContent = paragraphResult.getResultInText();
Status status = paragraphResult.getStatus();
final int exitStatusCode = mapStatusToExitCode(status);
setAppIds(String.format("%s-%s", noteId, paragraphId));
setExitStatusCode(exitStatusCode);
logger.info("zeppelin task finished with results: {}", resultContent);
} catch (Exception e) { |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 9,977 | [Feature][Task Plugin] Add support for dynamic form for zeppelin task plugin | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar feature requirement.
### Description
* Add support for Apache Zeppelin `dynamic form` in zeppelin task plugin. Click [here](https://zeppelin.apache.org/docs/0.10.1/usage/dynamic_form/intro.html#text-input-form-1) for details about `dynamic form`.
* Besides adding the support in backend, we need to add one more field in zeppelin task plugin UI for users to input json format parameters. Also we need to update related docs to give users an example.
### Use case
* Already described above.
### Related issues
related: #9814
### Are you willing to submit a PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/9977 | https://github.com/apache/dolphinscheduler/pull/10269 | c5961aed25329b1cbd0aab34fc49cc7cffb39753 | a8a5da367ad37911ee2400df894cdf8ff16fb73e | 2022-05-11T01:56:49Z | java | 2022-05-31T03:19:41Z | dolphinscheduler-task-plugin/dolphinscheduler-task-zeppelin/src/main/java/org/apache/dolphinscheduler/plugin/task/zeppelin/ZeppelinTask.java | setExitStatusCode(TaskConstants.EXIT_CODE_FAILURE);
logger.error("zeppelin task submit failed with error", e);
}
}
/**
* create zeppelin client from zeppelin config
*
* @return ZeppelinClient
*/
private ZeppelinClient getZeppelinClient() {
final String zeppelinRestUrl = PropertyUtils.getString(TaskConstants.ZEPPELIN_REST_URL);
ClientConfig clientConfig = new ClientConfig(zeppelinRestUrl);
ZeppelinClient zClient = null;
try {
zClient = new ZeppelinClient(clientConfig);
String zeppelinVersion = zClient.getVersion();
logger.info("zeppelin version: {}", zeppelinVersion);
} catch (Exception e) {
logger.error("some error");
}
return zClient;
}
/**
* map zeppelin task status to exitStatusCode
*
* @param status zeppelin job status
* @return exitStatusCode
*/
private int mapStatusToExitCode(Status status) { |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 9,977 | [Feature][Task Plugin] Add support for dynamic form for zeppelin task plugin | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar feature requirement.
### Description
* Add support for Apache Zeppelin `dynamic form` in zeppelin task plugin. Click [here](https://zeppelin.apache.org/docs/0.10.1/usage/dynamic_form/intro.html#text-input-form-1) for details about `dynamic form`.
* Besides adding the support in backend, we need to add one more field in zeppelin task plugin UI for users to input json format parameters. Also we need to update related docs to give users an example.
### Use case
* Already described above.
### Related issues
related: #9814
### Are you willing to submit a PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/9977 | https://github.com/apache/dolphinscheduler/pull/10269 | c5961aed25329b1cbd0aab34fc49cc7cffb39753 | a8a5da367ad37911ee2400df894cdf8ff16fb73e | 2022-05-11T01:56:49Z | java | 2022-05-31T03:19:41Z | dolphinscheduler-task-plugin/dolphinscheduler-task-zeppelin/src/main/java/org/apache/dolphinscheduler/plugin/task/zeppelin/ZeppelinTask.java | switch (status) {
case FINISHED:
return TaskConstants.EXIT_CODE_SUCCESS;
case ABORT:
return TaskConstants.EXIT_CODE_KILL;
default:
return TaskConstants.EXIT_CODE_FAILURE;
}
}
@Override
public AbstractParameters getParameters() {
return zeppelinParameters;
}
@Override
public void cancelApplication(boolean status) throws Exception {
super.cancelApplication(status);
String noteId = this.zeppelinParameters.getNoteId();
String paragraphId = this.zeppelinParameters.getParagraphId();
logger.info("trying terminate zeppelin task, taskId: {}, noteId: {}, paragraphId: {}",
this.taskExecutionContext.getTaskInstanceId(),
noteId,
paragraphId);
this.zClient.cancelParagraph(noteId, paragraphId);
logger.info("zeppelin task terminated, taskId: {}, noteId: {}, paragraphId: {}",
this.taskExecutionContext.getTaskInstanceId(),
noteId,
paragraphId);
}
} |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 9,977 | [Feature][Task Plugin] Add support for dynamic form for zeppelin task plugin | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar feature requirement.
### Description
* Add support for Apache Zeppelin `dynamic form` in zeppelin task plugin. Click [here](https://zeppelin.apache.org/docs/0.10.1/usage/dynamic_form/intro.html#text-input-form-1) for details about `dynamic form`.
* Besides adding the support in backend, we need to add one more field in zeppelin task plugin UI for users to input json format parameters. Also we need to update related docs to give users an example.
### Use case
* Already described above.
### Related issues
related: #9814
### Are you willing to submit a PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/9977 | https://github.com/apache/dolphinscheduler/pull/10269 | c5961aed25329b1cbd0aab34fc49cc7cffb39753 | a8a5da367ad37911ee2400df894cdf8ff16fb73e | 2022-05-11T01:56:49Z | java | 2022-05-31T03:19:41Z | dolphinscheduler-task-plugin/dolphinscheduler-task-zeppelin/src/test/java/org/apache/dolphinscheduler/plugin/task/zeppelin/ZeppelinTaskTest.java | /*
* 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.
*/
package org.apache.dolphinscheduler.plugin.task.zeppelin;
import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.EXIT_CODE_FAILURE;
import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.EXIT_CODE_KILL;
import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.EXIT_CODE_SUCCESS;
import static org.mockito.ArgumentMatchers.any;
import static org.powermock.api.mockito.PowerMockito.doReturn; |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 9,977 | [Feature][Task Plugin] Add support for dynamic form for zeppelin task plugin | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar feature requirement.
### Description
* Add support for Apache Zeppelin `dynamic form` in zeppelin task plugin. Click [here](https://zeppelin.apache.org/docs/0.10.1/usage/dynamic_form/intro.html#text-input-form-1) for details about `dynamic form`.
* Besides adding the support in backend, we need to add one more field in zeppelin task plugin UI for users to input json format parameters. Also we need to update related docs to give users an example.
### Use case
* Already described above.
### Related issues
related: #9814
### Are you willing to submit a PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/9977 | https://github.com/apache/dolphinscheduler/pull/10269 | c5961aed25329b1cbd0aab34fc49cc7cffb39753 | a8a5da367ad37911ee2400df894cdf8ff16fb73e | 2022-05-11T01:56:49Z | java | 2022-05-31T03:19:41Z | dolphinscheduler-task-plugin/dolphinscheduler-task-zeppelin/src/test/java/org/apache/dolphinscheduler/plugin/task/zeppelin/ZeppelinTaskTest.java | import static org.powermock.api.mockito.PowerMockito.mock;
import static org.powermock.api.mockito.PowerMockito.spy;
import static org.powermock.api.mockito.PowerMockito.when;
import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
import org.apache.dolphinscheduler.spi.utils.JSONUtils;
import org.apache.zeppelin.client.ParagraphResult;
import org.apache.zeppelin.client.Status;
import org.apache.zeppelin.client.ZeppelinClient;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
@PrepareForTest({
ZeppelinTask.class,
ZeppelinClient.class,
})
@PowerMockIgnore({"javax.*"})
public class ZeppelinTaskTest {
private static final String MOCK_NOTE_ID = "2GYJR92R7";
private static final String MOCK_PARAGRAPH_ID = "paragraph_1648793472526_1771221396";
private ZeppelinClient zClient;
private ZeppelinTask zeppelinTask;
private ParagraphResult paragraphResult;
@Before |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 9,977 | [Feature][Task Plugin] Add support for dynamic form for zeppelin task plugin | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar feature requirement.
### Description
* Add support for Apache Zeppelin `dynamic form` in zeppelin task plugin. Click [here](https://zeppelin.apache.org/docs/0.10.1/usage/dynamic_form/intro.html#text-input-form-1) for details about `dynamic form`.
* Besides adding the support in backend, we need to add one more field in zeppelin task plugin UI for users to input json format parameters. Also we need to update related docs to give users an example.
### Use case
* Already described above.
### Related issues
related: #9814
### Are you willing to submit a PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/9977 | https://github.com/apache/dolphinscheduler/pull/10269 | c5961aed25329b1cbd0aab34fc49cc7cffb39753 | a8a5da367ad37911ee2400df894cdf8ff16fb73e | 2022-05-11T01:56:49Z | java | 2022-05-31T03:19:41Z | dolphinscheduler-task-plugin/dolphinscheduler-task-zeppelin/src/test/java/org/apache/dolphinscheduler/plugin/task/zeppelin/ZeppelinTaskTest.java | public void before() throws Exception {
String zeppelinParameters = buildZeppelinTaskParameters();
TaskExecutionContext taskExecutionContext = PowerMockito.mock(TaskExecutionContext.class);
when(taskExecutionContext.getTaskParams()).thenReturn(zeppelinParameters);
this.zeppelinTask = spy(new ZeppelinTask(taskExecutionContext));
this.zClient = mock(ZeppelinClient.class);
this.paragraphResult = mock(ParagraphResult.class);
doReturn(this.zClient).when(this.zeppelinTask, "getZeppelinClient");
when(this.zClient.executeParagraph(any(), any())).thenReturn(this.paragraphResult);
when(paragraphResult.getResultInText()).thenReturn("mock-zeppelin-paragraph-execution-result");
this.zeppelinTask.init();
}
@Test
public void testHandleWithParagraphExecutionSucess() throws Exception {
when(this.paragraphResult.getStatus()).thenReturn(Status.FINISHED);
this.zeppelinTask.handle();
Mockito.verify(this.zClient).executeParagraph(MOCK_NOTE_ID, MOCK_PARAGRAPH_ID);
Mockito.verify(this.paragraphResult).getResultInText();
Mockito.verify(this.paragraphResult).getStatus();
Assert.assertEquals(EXIT_CODE_SUCCESS, this.zeppelinTask.getExitStatusCode());
}
@Test
public void testHandleWithParagraphExecutionAborted() throws Exception {
when(this.paragraphResult.getStatus()).thenReturn(Status.ABORT);
this.zeppelinTask.handle();
Mockito.verify(this.zClient).executeParagraph(MOCK_NOTE_ID, MOCK_PARAGRAPH_ID);
Mockito.verify(this.paragraphResult).getResultInText();
Mockito.verify(this.paragraphResult).getStatus(); |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 9,977 | [Feature][Task Plugin] Add support for dynamic form for zeppelin task plugin | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar feature requirement.
### Description
* Add support for Apache Zeppelin `dynamic form` in zeppelin task plugin. Click [here](https://zeppelin.apache.org/docs/0.10.1/usage/dynamic_form/intro.html#text-input-form-1) for details about `dynamic form`.
* Besides adding the support in backend, we need to add one more field in zeppelin task plugin UI for users to input json format parameters. Also we need to update related docs to give users an example.
### Use case
* Already described above.
### Related issues
related: #9814
### Are you willing to submit a PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/9977 | https://github.com/apache/dolphinscheduler/pull/10269 | c5961aed25329b1cbd0aab34fc49cc7cffb39753 | a8a5da367ad37911ee2400df894cdf8ff16fb73e | 2022-05-11T01:56:49Z | java | 2022-05-31T03:19:41Z | dolphinscheduler-task-plugin/dolphinscheduler-task-zeppelin/src/test/java/org/apache/dolphinscheduler/plugin/task/zeppelin/ZeppelinTaskTest.java | Assert.assertEquals(EXIT_CODE_KILL, this.zeppelinTask.getExitStatusCode());
}
@Test
public void testHandleWithParagraphExecutionError() throws Exception {
when(this.paragraphResult.getStatus()).thenReturn(Status.ERROR);
this.zeppelinTask.handle();
Mockito.verify(this.zClient).executeParagraph(MOCK_NOTE_ID, MOCK_PARAGRAPH_ID);
Mockito.verify(this.paragraphResult).getResultInText();
Mockito.verify(this.paragraphResult).getStatus();
Assert.assertEquals(EXIT_CODE_FAILURE, this.zeppelinTask.getExitStatusCode());
}
@Test
public void testHandleWithParagraphExecutionException() throws Exception {
when(this.zClient.executeParagraph(any(), any())).
thenThrow(new Exception("Something wrong happens from zeppelin side"));
this.zeppelinTask.handle();
Mockito.verify(this.zClient).executeParagraph(MOCK_NOTE_ID, MOCK_PARAGRAPH_ID);
Mockito.verify(this.paragraphResult, Mockito.times(0)).getResultInText();
Mockito.verify(this.paragraphResult, Mockito.times(0)).getStatus();
Assert.assertEquals(EXIT_CODE_FAILURE, this.zeppelinTask.getExitStatusCode());
}
private String buildZeppelinTaskParameters() {
ZeppelinParameters zeppelinParameters = new ZeppelinParameters();
String noteId = MOCK_NOTE_ID;
String paragraphId = MOCK_PARAGRAPH_ID;
zeppelinParameters.setNoteId(noteId);
zeppelinParameters.setParagraphId(paragraphId);
return JSONUtils.toJsonString(zeppelinParameters);
}
} |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | /*
* 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, |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | * 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.
*/
package org.apache.dolphinscheduler.api.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.google.common.base.Joiner;
import com.google.common.io.Files;
import org.apache.commons.beanutils.BeanMap;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant;
import org.apache.dolphinscheduler.api.dto.resources.ResourceComponent;
import org.apache.dolphinscheduler.api.dto.resources.filter.ResourceFilter;
import org.apache.dolphinscheduler.api.dto.resources.visitor.ResourceTreeVisitor;
import org.apache.dolphinscheduler.api.dto.resources.visitor.Visitor;
import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.exceptions.ServiceException;
import org.apache.dolphinscheduler.api.service.ResourcesService;
import org.apache.dolphinscheduler.api.utils.PageInfo;
import org.apache.dolphinscheduler.api.utils.RegexUtils;
import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.common.enums.AuthorizationType;
import org.apache.dolphinscheduler.common.enums.ProgramType;
import org.apache.dolphinscheduler.common.enums.ResUploadType;
import org.apache.dolphinscheduler.common.storage.StorageOperate;
import org.apache.dolphinscheduler.common.utils.FileUtils; |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.common.utils.PropertyUtils;
import org.apache.dolphinscheduler.dao.entity.Resource;
import org.apache.dolphinscheduler.dao.entity.ResourcesUser;
import org.apache.dolphinscheduler.dao.entity.Tenant;
import org.apache.dolphinscheduler.dao.entity.UdfFunc;
import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper;
import org.apache.dolphinscheduler.dao.mapper.ResourceMapper;
import org.apache.dolphinscheduler.dao.mapper.ResourceUserMapper;
import org.apache.dolphinscheduler.dao.mapper.TenantMapper;
import org.apache.dolphinscheduler.dao.mapper.UdfFuncMapper;
import org.apache.dolphinscheduler.dao.mapper.UserMapper;
import org.apache.dolphinscheduler.dao.utils.ResourceProcessDefinitionUtils;
import org.apache.dolphinscheduler.service.permission.ResourcePermissionCheckService;
import org.apache.dolphinscheduler.spi.enums.ResourceType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.rmi.ServerException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date; |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.stream.Collectors;
import static org.apache.dolphinscheduler.common.Constants.ALIAS;
import static org.apache.dolphinscheduler.common.Constants.CONTENT;
import static org.apache.dolphinscheduler.common.Constants.FOLDER_SEPARATOR;
import static org.apache.dolphinscheduler.common.Constants.FORMAT_SS;
import static org.apache.dolphinscheduler.common.Constants.FORMAT_S_S;
import static org.apache.dolphinscheduler.common.Constants.JAR;
/**
* resources service impl
*/
@Service
public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesService {
private static final Logger logger = LoggerFactory.getLogger(ResourcesServiceImpl.class);
@Autowired
private ResourceMapper resourcesMapper;
@Autowired
private UdfFuncMapper udfFunctionMapper;
@Autowired
private TenantMapper tenantMapper;
@Autowired
private UserMapper userMapper;
@Autowired |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | private ResourceUserMapper resourceUserMapper;
@Autowired
private ProcessDefinitionMapper processDefinitionMapper;
@Autowired(required = false)
private StorageOperate storageOperate;
@Autowired
private ResourcePermissionCheckService resourcePermissionCheckService;
/**
* create directory
*
* @param loginUser login user
* @param name alias
* @param description description
* @param type type
* @param pid parent id
* @param currentDir current directory
* @return create directory result
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Result<Object> createDirectory(User loginUser,
String name,
String description,
ResourceType type,
int pid,
String currentDir) {
Result<Object> result = new Result<>();
String funcPermissionKey = type.equals(ResourceType.FILE) ? ApiFuncIdentificationConstant.FOLDER_ONLINE_CREATE : ApiFuncIdentificationConstant.UDF_FOLDER_ONLINE_CREATE;
boolean canOperatorPermissions = canOperatorPermissions(loginUser, null, AuthorizationType.RESOURCE_FILE_ID, funcPermissionKey); |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | if (!canOperatorPermissions){
putMsg(result, Status.NO_CURRENT_OPERATING_PERMISSION);
return result;
}
result = checkResourceUploadStartupState();
if (!result.getCode().equals(Status.SUCCESS.getCode())) {
return result;
}
if (FileUtils.directoryTraversal(name)) {
putMsg(result, Status.VERIFY_PARAMETER_NAME_FAILED);
return result;
}
String fullName = getFullName(currentDir, name);
result = verifyResource(loginUser, type, fullName, pid);
if (!result.getCode().equals(Status.SUCCESS.getCode())) {
return result;
}
if (checkResourceExists(fullName, type.ordinal())) {
logger.error("resource directory {} has exist, can't recreate", fullName);
putMsg(result, Status.RESOURCE_EXIST);
return result;
}
Date now = new Date();
Resource resource = new Resource(pid, name, fullName, true, description, name, loginUser.getId(), type, 0, now, now);
try {
resourcesMapper.insert(resource);
putMsg(result, Status.SUCCESS);
Map<String, Object> resultMap = new HashMap<>();
for (Map.Entry<Object, Object> entry : new BeanMap(resource).entrySet()) {
if (!"class".equalsIgnoreCase(entry.getKey().toString())) { |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | resultMap.put(entry.getKey().toString(), entry.getValue());
}
}
result.setData(resultMap);
} catch (DuplicateKeyException e) {
logger.error("resource directory {} has exist, can't recreate", fullName);
putMsg(result, Status.RESOURCE_EXIST);
return result;
} catch (Exception e) {
logger.error("resource already exists, can't recreate ", e);
throw new ServiceException("resource already exists, can't recreate");
}
createDirectory(loginUser, fullName, type, result);
return result;
}
private String getFullName(String currentDir, String name) {
return currentDir.equals(FOLDER_SEPARATOR) ? String.format(FORMAT_SS, currentDir, name) : String.format(FORMAT_S_S, currentDir, name);
}
/**
* create resource
*
* @param loginUser login user
* @param name alias
* @param desc description
* @param file file
* @param type type
* @param pid parent id
* @param currentDir current directory
* @return create result code |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | */
@Override
@Transactional(rollbackFor = Exception.class)
public Result<Object> createResource(User loginUser,
String name,
String desc,
ResourceType type,
MultipartFile file,
int pid,
String currentDir) {
Result<Object> result = new Result<>();
String funcPermissionKey = type.equals(ResourceType.FILE) ? ApiFuncIdentificationConstant.FILE_ONLINE_CREATE : ApiFuncIdentificationConstant.UDF_FOLDER_ONLINE_CREATE;
boolean canOperatorPermissions = canOperatorPermissions(loginUser, null, AuthorizationType.RESOURCE_FILE_ID, funcPermissionKey);
if (!canOperatorPermissions){
putMsg(result, Status.NO_CURRENT_OPERATING_PERMISSION);
return result;
}
result = checkResourceUploadStartupState();
if (!result.getCode().equals(Status.SUCCESS.getCode())) {
return result;
}
result = verifyPid(loginUser, pid);
if (!result.getCode().equals(Status.SUCCESS.getCode())) {
return result;
}
result = verifyFile(name, type, file);
if (!result.getCode().equals(Status.SUCCESS.getCode())) {
return result;
} |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | String fullName = getFullName(currentDir, name);
if (checkResourceExists(fullName, type.ordinal())) {
logger.error("resource {} has exist, can't recreate", RegexUtils.escapeNRT(name));
putMsg(result, Status.RESOURCE_EXIST);
return result;
}
if (fullName.length() > Constants.RESOURCE_FULL_NAME_MAX_LENGTH) {
logger.error("resource {}'s full name {}' is longer than the max length {}", RegexUtils.escapeNRT(name), fullName, Constants.RESOURCE_FULL_NAME_MAX_LENGTH);
putMsg(result, Status.RESOURCE_FULL_NAME_TOO_LONG_ERROR);
return result;
}
Date now = new Date();
Resource resource = new Resource(pid, name, fullName, false, desc, file.getOriginalFilename(), loginUser.getId(), type, file.getSize(), now, now);
try {
resourcesMapper.insert(resource);
updateParentResourceSize(resource, resource.getSize());
putMsg(result, Status.SUCCESS);
Map<String, Object> resultMap = new HashMap<>();
for (Map.Entry<Object, Object> entry : new BeanMap(resource).entrySet()) {
if (!"class".equalsIgnoreCase(entry.getKey().toString())) {
resultMap.put(entry.getKey().toString(), entry.getValue());
}
}
result.setData(resultMap);
} catch (Exception e) {
logger.error("resource already exists, can't recreate ", e);
throw new ServiceException("resource already exists, can't recreate");
}
if (!upload(loginUser, fullName, file, type)) { |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | logger.error("upload resource: {} file: {} failed.", RegexUtils.escapeNRT(name), RegexUtils.escapeNRT(file.getOriginalFilename()));
putMsg(result, Status.STORE_OPERATE_CREATE_ERROR);
throw new ServiceException(String.format("upload resource: %s file: %s failed.", name, file.getOriginalFilename()));
}
return result;
}
/**
* update the folder's size of the resource
*
* @param resource the current resource
* @param size size
*/
private void updateParentResourceSize(Resource resource, long size) {
if (resource.getSize() > 0) {
String[] splits = resource.getFullName().split("/");
for (int i = 1; i < splits.length; i++) {
String parentFullName = Joiner.on("/").join(Arrays.copyOfRange(splits, 0, i));
if (StringUtils.isNotBlank(parentFullName)) {
List<Resource> resources = resourcesMapper.queryResource(parentFullName, resource.getType().ordinal());
if (CollectionUtils.isNotEmpty(resources)) {
Resource parentResource = resources.get(0);
if (parentResource.getSize() + size >= 0) {
parentResource.setSize(parentResource.getSize() + size);
} else {
parentResource.setSize(0L);
}
resourcesMapper.updateById(parentResource);
}
}
} |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | }
}
/**
* check resource is exists
*
* @param fullName fullName
* @param type type
* @return true if resource exists
*/
private boolean checkResourceExists(String fullName, int type) {
Boolean existResource = resourcesMapper.existResource(fullName, type);
return Boolean.TRUE.equals(existResource);
}
/**
* update resource
*
* @param loginUser login user
* @param resourceId resource id
* @param name name
* @param desc description
* @param type resource type
* @param file resource file
* @return update result code
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Result<Object> updateResource(User loginUser,
int resourceId,
String name,
String desc, |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | ResourceType type,
MultipartFile file) {
Result<Object> result = new Result<>();
String funcPermissionKey = type.equals(ResourceType.FILE) ? ApiFuncIdentificationConstant.FILE_UPDATE : ApiFuncIdentificationConstant.UDF_UPDATE;
boolean canOperatorPermissions = canOperatorPermissions(loginUser, new Object[]{resourceId}, AuthorizationType.RESOURCE_FILE_ID, funcPermissionKey);
if (!canOperatorPermissions){
putMsg(result, Status.NO_CURRENT_OPERATING_PERMISSION);
return result;
}
result = checkResourceUploadStartupState();
if (!result.getCode().equals(Status.SUCCESS.getCode())) {
return result;
}
Resource resource = resourcesMapper.selectById(resourceId);
if (resource == null) {
putMsg(result, Status.RESOURCE_NOT_EXIST);
return result;
}
if (!PropertyUtils.getResUploadStartupState()){
putMsg(result, Status.STORAGE_NOT_STARTUP);
return result;
}
if (resource.isDirectory() && storageOperate.returnStorageType().equals(ResUploadType.S3) && !resource.getFileName().equals(name)) {
putMsg(result, Status.S3_CANNOT_RENAME);
return result;
}
if (!canOperator(loginUser, resource.getUserId())) {
putMsg(result, Status.USER_NO_OPERATION_PERM);
return result;
} |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | if (file == null && name.equals(resource.getAlias()) && desc.equals(resource.getDescription())) {
putMsg(result, Status.SUCCESS);
return result;
}
String originFullName = resource.getFullName();
String originResourceName = resource.getAlias();
String fullName = String.format(FORMAT_SS, originFullName.substring(0, originFullName.lastIndexOf(FOLDER_SEPARATOR) + 1), name);
if (!originResourceName.equals(name) && checkResourceExists(fullName, type.ordinal())) {
logger.error("resource {} already exists, can't recreate", name);
putMsg(result, Status.RESOURCE_EXIST);
return result;
}
result = verifyFile(name, type, file);
if (!result.getCode().equals(Status.SUCCESS.getCode())) {
return result;
}
String tenantCode = getTenantCode(resource.getUserId(), result);
if (StringUtils.isEmpty(tenantCode)) {
return result;
}
String originFileName = storageOperate.getFileName(resource.getType(), tenantCode, originFullName);
try {
if (!storageOperate.exists(tenantCode, originFileName)) {
logger.error("{} not exist", originFileName);
putMsg(result, Status.RESOURCE_NOT_EXIST);
return result; |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | }
} catch (IOException e) {
logger.error(e.getMessage(), e);
throw new ServiceException(Status.HDFS_OPERATION_ERROR);
}
if (!resource.isDirectory()) {
String originSuffix = Files.getFileExtension(originFullName);
String suffix = Files.getFileExtension(fullName);
boolean suffixIsChanged = false;
if (StringUtils.isBlank(suffix) && StringUtils.isNotBlank(originSuffix)) {
suffixIsChanged = true;
}
if (StringUtils.isNotBlank(suffix) && !suffix.equals(originSuffix)) {
suffixIsChanged = true;
}
if (suffixIsChanged) {
Map<String, Object> columnMap = new HashMap<>();
columnMap.put("resources_id", resourceId);
List<ResourcesUser> resourcesUsers = resourceUserMapper.selectByMap(columnMap);
if (CollectionUtils.isNotEmpty(resourcesUsers)) {
List<Integer> userIds = resourcesUsers.stream().map(ResourcesUser::getUserId).collect(Collectors.toList());
List<User> users = userMapper.selectBatchIds(userIds);
String userNames = users.stream().map(User::getUserName).collect(Collectors.toList()).toString();
logger.error("resource is authorized to user {},suffix not allowed to be modified", userNames);
putMsg(result, Status.RESOURCE_IS_AUTHORIZED, userNames);
return result;
} |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | }
}
Date now = new Date();
long originFileSize = resource.getSize();
resource.setAlias(name);
resource.setFileName(name);
resource.setFullName(fullName);
resource.setDescription(desc);
resource.setUpdateTime(now);
if (file != null) {
resource.setSize(file.getSize());
}
try {
resourcesMapper.updateById(resource);
if (resource.isDirectory()) {
List<Integer> childrenResource = listAllChildren(resource, false);
if (CollectionUtils.isNotEmpty(childrenResource)) {
String matcherFullName = Matcher.quoteReplacement(fullName);
List<Resource> childResourceList;
Integer[] childResIdArray = childrenResource.toArray(new Integer[childrenResource.size()]);
List<Resource> resourceList = resourcesMapper.listResourceByIds(childResIdArray);
childResourceList = resourceList.stream().map(t -> {
t.setFullName(t.getFullName().replaceFirst(originFullName, matcherFullName));
t.setUpdateTime(now);
return t;
}).collect(Collectors.toList());
resourcesMapper.batchUpdateResource(childResourceList);
if (ResourceType.UDF.equals(resource.getType())) {
List<UdfFunc> udfFuncs = udfFunctionMapper.listUdfByResourceId(childResIdArray); |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | if (CollectionUtils.isNotEmpty(udfFuncs)) {
udfFuncs = udfFuncs.stream().map(t -> {
t.setResourceName(t.getResourceName().replaceFirst(originFullName, matcherFullName));
t.setUpdateTime(now);
return t;
}).collect(Collectors.toList());
udfFunctionMapper.batchUpdateUdfFunc(udfFuncs);
}
}
}
} else if (ResourceType.UDF.equals(resource.getType())) {
List<UdfFunc> udfFuncs = udfFunctionMapper.listUdfByResourceId(new Integer[]{resourceId});
if (CollectionUtils.isNotEmpty(udfFuncs)) {
udfFuncs = udfFuncs.stream().map(t -> {
t.setResourceName(fullName);
t.setUpdateTime(now);
return t;
}).collect(Collectors.toList());
udfFunctionMapper.batchUpdateUdfFunc(udfFuncs);
}
}
putMsg(result, Status.SUCCESS);
Map<String, Object> resultMap = new HashMap<>();
for (Map.Entry<Object, Object> entry : new BeanMap(resource).entrySet()) {
if (!Constants.CLASS.equalsIgnoreCase(entry.getKey().toString())) {
resultMap.put(entry.getKey().toString(), entry.getValue());
}
}
result.setData(resultMap);
} catch (Exception e) { |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | logger.error(Status.UPDATE_RESOURCE_ERROR.getMsg(), e);
throw new ServiceException(Status.UPDATE_RESOURCE_ERROR);
}
if (originResourceName.equals(name) && file == null) {
return result;
}
if (file != null) {
if (!upload(loginUser, fullName, file, type)) {
logger.error("upload resource: {} file: {} failed.", name, RegexUtils.escapeNRT(file.getOriginalFilename()));
putMsg(result, Status.HDFS_OPERATION_ERROR);
throw new ServiceException(String.format("upload resource: %s file: %s failed.", name, file.getOriginalFilename()));
}
if (!fullName.equals(originFullName)) {
try {
storageOperate.delete(tenantCode, originFileName, false);
} catch (IOException e) {
logger.error(e.getMessage(), e);
throw new ServiceException(String.format("delete resource: %s failed.", originFullName));
}
}
updateParentResourceSize(resource, resource.getSize() - originFileSize);
return result;
}
String destHdfsFileName = storageOperate.getFileName(resource.getType(), tenantCode, fullName);
try {
logger.info("start copy {} -> {}", originFileName, destHdfsFileName);
storageOperate.copy(originFileName, destHdfsFileName, true, true); |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | } catch (Exception e) {
logger.error(MessageFormat.format(" copy {0} -> {1} fail", originFileName, destHdfsFileName), e);
putMsg(result, Status.HDFS_COPY_FAIL);
throw new ServiceException(Status.HDFS_COPY_FAIL);
}
return result;
}
private Result<Object> verifyFile(String name, ResourceType type, MultipartFile file) {
Result<Object> result = new Result<>();
putMsg(result, Status.SUCCESS);
if (FileUtils.directoryTraversal(name)) {
logger.error("file alias name {} verify failed", name);
putMsg(result, Status.VERIFY_PARAMETER_NAME_FAILED);
return result;
}
if (file != null && FileUtils.directoryTraversal(Objects.requireNonNull(file.getOriginalFilename()))) {
logger.error("file original name {} verify failed", file.getOriginalFilename());
putMsg(result, Status.VERIFY_PARAMETER_NAME_FAILED);
return result;
}
if (file != null) {
if (file.isEmpty()) {
logger.error("file is empty: {}", RegexUtils.escapeNRT(file.getOriginalFilename()));
putMsg(result, Status.RESOURCE_FILE_IS_EMPTY);
return result;
}
String fileSuffix = Files.getFileExtension(file.getOriginalFilename());
String nameSuffix = Files.getFileExtension(name); |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | if (!fileSuffix.equalsIgnoreCase(nameSuffix)) {
logger.error("rename file suffix and original suffix must be consistent: {}", RegexUtils.escapeNRT(file.getOriginalFilename()));
putMsg(result, Status.RESOURCE_SUFFIX_FORBID_CHANGE);
return result;
}
if (Constants.UDF.equals(type.name()) && !JAR.equalsIgnoreCase(fileSuffix)) {
logger.error(Status.UDF_RESOURCE_SUFFIX_NOT_JAR.getMsg());
putMsg(result, Status.UDF_RESOURCE_SUFFIX_NOT_JAR);
return result;
}
if (file.getSize() > Constants.MAX_FILE_SIZE) {
logger.error("file size is too large: {}", RegexUtils.escapeNRT(file.getOriginalFilename()));
putMsg(result, Status.RESOURCE_SIZE_EXCEED_LIMIT);
return result;
}
}
return result;
}
/**
* query resources list paging
*
* @param loginUser login user
* @param type resource type
* @param searchVal search value
* @param pageNo page number
* @param pageSize page size
* @return resource list page |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | */
@Override
public Result queryResourceListPaging(User loginUser, int directoryId, ResourceType type, String searchVal, Integer pageNo, Integer pageSize) {
Result<Object> result = new Result<>();
String funcPermissionKey = type.equals(ResourceType.FILE) ? ApiFuncIdentificationConstant.FILE_VIEW : ApiFuncIdentificationConstant.UDF_FILE_VIEW;
boolean canOperatorPermissions = canOperatorPermissions(loginUser, null, AuthorizationType.RESOURCE_FILE_ID, funcPermissionKey);
if (!canOperatorPermissions){
putMsg(result, Status.NO_CURRENT_OPERATING_PERMISSION);
return result;
}
Page<Resource> page = new Page<>(pageNo, pageSize);
int userId = loginUser.getId();
if (isAdmin(loginUser)) {
userId = 0;
}
if (directoryId != -1) {
Resource directory = resourcesMapper.selectById(directoryId);
if (directory == null) {
putMsg(result, Status.RESOURCE_NOT_EXIST);
return result;
}
}
Set<Integer> resourcesIds = resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.RESOURCE_FILE_ID, loginUser.getId(), logger);
IPage<Resource> resourceIPage = resourcesMapper.queryResourcePaging(page, directoryId, type.ordinal(), loginUser.getId(), searchVal, new ArrayList<>(resourcesIds));
PageInfo<Resource> pageInfo = new PageInfo<>(pageNo, pageSize);
pageInfo.setTotal((int) resourceIPage.getTotal());
pageInfo.setTotalList(resourceIPage.getRecords());
result.setData(pageInfo);
putMsg(result, Status.SUCCESS);
return result; |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | }
/**
* create directory
* xxx The steps to verify resources are cumbersome and can be optimized
*
* @param loginUser login user
* @param fullName full name
* @param type resource type
* @param result Result
*/
private void createDirectory(User loginUser, String fullName, ResourceType type, Result<Object> result) {
String tenantCode = tenantMapper.queryById(loginUser.getTenantId()).getTenantCode();
String directoryName = storageOperate.getFileName(type, tenantCode, fullName);
String resourceRootPath = storageOperate.getDir(type, tenantCode);
try {
if (!storageOperate.exists(tenantCode, resourceRootPath)) {
storageOperate.createTenantDirIfNotExists(tenantCode);
}
if (!storageOperate.mkdir(tenantCode, directoryName)) {
logger.error("create resource directory {} failed", directoryName);
putMsg(result, Status.STORE_OPERATE_CREATE_ERROR);
throw new ServiceException(String.format("create resource directory: %s failed.", directoryName));
}
} catch (Exception e) {
logger.error("create resource directory {} failed", directoryName);
putMsg(result, Status.STORE_OPERATE_CREATE_ERROR);
throw new ServiceException(String.format("create resource directory: %s failed.", directoryName));
}
}
/** |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | * upload file to hdfs
*
* @param loginUser login user
* @param fullName full name
* @param file file
*/
private boolean upload(User loginUser, String fullName, MultipartFile file, ResourceType type) {
String fileSuffix = Files.getFileExtension(file.getOriginalFilename());
String nameSuffix = Files.getFileExtension(fullName);
if (!fileSuffix.equalsIgnoreCase(nameSuffix)) {
return false;
}
String tenantCode = tenantMapper.queryById(loginUser.getTenantId()).getTenantCode();
String localFilename = FileUtils.getUploadFilename(tenantCode, UUID.randomUUID().toString());
String fileName = storageOperate.getFileName(type, tenantCode, fullName);
String resourcePath = storageOperate.getDir(type, tenantCode);
try {
if (!storageOperate.exists(tenantCode, resourcePath)) {
storageOperate.createTenantDirIfNotExists(tenantCode);
}
org.apache.dolphinscheduler.api.utils.FileUtils.copyInputStreamToFile(file, localFilename);
storageOperate.upload(tenantCode, localFilename, fileName, true, true);
} catch (Exception e) {
FileUtils.deleteFile(localFilename); |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | logger.error(e.getMessage(), e);
return false;
}
return true;
}
/**
* query resource list
*
* @param loginUser login user
* @param type resource type
* @return resource list
*/
@Override
public Map<String, Object> queryResourceList(User loginUser, ResourceType type) {
Map<String, Object> result = new HashMap<>();
String funcPermissionKey = type.equals(ResourceType.FILE) ? ApiFuncIdentificationConstant.FILE_VIEW : ApiFuncIdentificationConstant.UDF_FILE_VIEW;
boolean canOperatorPermissions = canOperatorPermissions(loginUser, null, AuthorizationType.RESOURCE_FILE_ID, funcPermissionKey);
if (!canOperatorPermissions){
putMsg(result, Status.NO_CURRENT_OPERATING_PERMISSION);
return result;
}
List<Resource> allResourceList = queryAuthoredResourceList(loginUser, type);
Visitor resourceTreeVisitor = new ResourceTreeVisitor(allResourceList);
result.put(Constants.DATA_LIST, resourceTreeVisitor.visit().getChildren());
putMsg(result, Status.SUCCESS);
return result;
}
/**
* query resource list by program type
* |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | * @param loginUser login user
* @param type resource type
* @return resource list
*/
@Override
public Result<Object> queryResourceByProgramType(User loginUser, ResourceType type, ProgramType programType) {
Result<Object> result = new Result<>();
String funcPermissionKey = type.equals(ResourceType.FILE) ? ApiFuncIdentificationConstant.FILE_VIEW : ApiFuncIdentificationConstant.UDF_FILE_VIEW;
boolean canOperatorPermissions = canOperatorPermissions(loginUser, null, AuthorizationType.RESOURCE_FILE_ID, funcPermissionKey);
if (!canOperatorPermissions){
putMsg(result, Status.NO_CURRENT_OPERATING_PERMISSION);
return result;
}
Set<Integer> resourceIds = resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.RESOURCE_FILE_ID, loginUser.getId(), logger);
if (resourceIds.isEmpty()){
result.setData(Collections.emptyList());
putMsg(result, Status.SUCCESS);
return result;
}
List<Resource> allResourceList = resourcesMapper.selectBatchIds(resourceIds);
String suffix = ".jar";
if (programType != null) {
switch (programType) {
case JAVA:
case SCALA:
break;
case PYTHON:
suffix = ".py";
break;
default: |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | }
}
List<Resource> resources = new ResourceFilter(suffix, new ArrayList<>(allResourceList)).filter();
Visitor resourceTreeVisitor = new ResourceTreeVisitor(resources);
result.setData(resourceTreeVisitor.visit().getChildren());
putMsg(result, Status.SUCCESS);
return result;
}
/**
* delete resource
*
* @param loginUser login user
* @param resourceId resource id
* @return delete result code
* @throws IOException exception
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Result<Object> delete(User loginUser, int resourceId) throws IOException {
Result<Object> resultCheck = new Result<>();
Resource resource = resourcesMapper.selectById(resourceId);
if (resource == null) {
putMsg(resultCheck, Status.RESOURCE_NOT_EXIST);
return resultCheck;
}
String funcPermissionKey = resource.getType().equals(ResourceType.FILE) ? ApiFuncIdentificationConstant.FILE_DELETE : ApiFuncIdentificationConstant.UDF_DELETE;
boolean canOperatorPermissions = canOperatorPermissions(loginUser, new Object[]{resourceId}, AuthorizationType.RESOURCE_FILE_ID, funcPermissionKey);
if (!canOperatorPermissions){
putMsg(resultCheck, Status.NO_CURRENT_OPERATING_PERMISSION); |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | return resultCheck;
}
Result<Object> result = checkResourceUploadStartupState();
if (!result.getCode().equals(Status.SUCCESS.getCode())) {
return result;
}
if (!canOperator(loginUser, resource.getUserId())) {
putMsg(result, Status.USER_NO_OPERATION_PERM);
return result;
}
String tenantCode = getTenantCode(resource.getUserId(), result);
if (StringUtils.isEmpty(tenantCode)) {
return result;
}
List<Map<String, Object>> list = processDefinitionMapper.listResources();
Map<Integer, Set<Long>> resourceProcessMap = ResourceProcessDefinitionUtils.getResourceProcessDefinitionMap(list);
Set<Integer> resourceIdSet = resourceProcessMap.keySet();
List<Integer> allChildren = listAllChildren(resource, true);
Integer[] needDeleteResourceIdArray = allChildren.toArray(new Integer[allChildren.size()]);
if (resource.getType() == (ResourceType.UDF)) {
List<UdfFunc> udfFuncs = udfFunctionMapper.listUdfByResourceId(needDeleteResourceIdArray);
if (CollectionUtils.isNotEmpty(udfFuncs)) {
logger.error("can't be deleted,because it is bound by UDF functions:{}", udfFuncs);
putMsg(result, Status.UDF_RESOURCE_IS_BOUND, udfFuncs.get(0).getFuncName());
return result;
} |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | }
if (resourceIdSet.contains(resource.getPid())) {
logger.error("can't be deleted,because it is used of process definition");
putMsg(result, Status.RESOURCE_IS_USED);
return result;
}
resourceIdSet.retainAll(allChildren);
if (CollectionUtils.isNotEmpty(resourceIdSet)) {
logger.error("can't be deleted,because it is used of process definition");
for (Integer resId : resourceIdSet) {
logger.error("resource id:{} is used of process definition {}",resId,resourceProcessMap.get(resId));
}
putMsg(result, Status.RESOURCE_IS_USED);
return result;
}
String storageFilename = storageOperate.getFileName(resource.getType(), tenantCode, resource.getFullName());
resourcesMapper.selectBatchIds(Arrays.asList(needDeleteResourceIdArray)).forEach(item -> {
updateParentResourceSize(item, item.getSize() * -1);
});
resourcesMapper.deleteIds(needDeleteResourceIdArray);
resourceUserMapper.deleteResourceUserArray(0, needDeleteResourceIdArray);
storageOperate.delete(tenantCode, storageFilename, true);
putMsg(result, Status.SUCCESS);
return result;
}
/** |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | * verify resource by name and type
*
* @param loginUser login user
* @param fullName resource full name
* @param type resource type
* @return true if the resource name not exists, otherwise return false
*/
@Override
public Result<Object> verifyResourceName(String fullName, ResourceType type, User loginUser) {
Result<Object> result = new Result<>();
String funcPermissionKey = type.equals(ResourceType.FILE) ? ApiFuncIdentificationConstant.FILE_RENAME : ApiFuncIdentificationConstant.UDF_FILE_VIEW;
boolean canOperatorPermissions = canOperatorPermissions(loginUser, null, AuthorizationType.RESOURCE_FILE_ID, funcPermissionKey);
if (!canOperatorPermissions){
putMsg(result, Status.NO_CURRENT_OPERATING_PERMISSION);
return result;
}
putMsg(result, Status.SUCCESS);
if (checkResourceExists(fullName, type.ordinal())) {
logger.error("resource type:{} name:{} has exist, can't create again.", type, RegexUtils.escapeNRT(fullName));
putMsg(result, Status.RESOURCE_EXIST);
} else {
Tenant tenant = tenantMapper.queryById(loginUser.getTenantId());
if (tenant != null) {
String tenantCode = tenant.getTenantCode();
try {
String filename = storageOperate.getFileName(type, tenantCode, fullName);
if (storageOperate.exists(tenantCode, filename)) {
putMsg(result, Status.RESOURCE_FILE_EXIST, filename);
} |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | } catch (Exception e) {
logger.error("verify resource failed and the reason is {}", e.getMessage());
putMsg(result, Status.STORE_OPERATE_CREATE_ERROR);
}
} else {
putMsg(result, Status.CURRENT_LOGIN_USER_TENANT_NOT_EXIST);
}
}
return result;
}
/**
* verify resource by full name or pid and type
*
* @param fullName resource full name
* @param id resource id
* @param type resource type
* @return true if the resource full name or pid not exists, otherwise return false
*/
@Override
public Result<Object> queryResource(User loginUser, String fullName, Integer id, ResourceType type) {
Result<Object> result = new Result<>();
if (StringUtils.isBlank(fullName) && id == null) {
putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR);
return result;
}
Resource resource;
if (StringUtils.isNotBlank(fullName)) {
List<Resource> resourceList = resourcesMapper.queryResource(fullName, type.ordinal());
if (CollectionUtils.isEmpty(resourceList)) {
putMsg(result, Status.RESOURCE_NOT_EXIST); |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | return result;
}
resource = resourceList.get(0);
} else {
resource = resourcesMapper.selectById(id);
if (resource == null) {
putMsg(result, Status.RESOURCE_NOT_EXIST);
return result;
}
resource = resourcesMapper.selectById(resource.getPid());
if (resource == null) {
putMsg(result, Status.RESOURCE_NOT_EXIST);
return result;
}
}
String funcPermissionKey = type.equals(ResourceType.FILE) ? ApiFuncIdentificationConstant.FILE_VIEW : ApiFuncIdentificationConstant.UDF_FILE_VIEW;
boolean canOperatorPermissions = canOperatorPermissions(loginUser, new Object[]{resource.getId()}, AuthorizationType.RESOURCE_FILE_ID, funcPermissionKey);
if (!canOperatorPermissions){
putMsg(result, Status.NO_CURRENT_OPERATING_PERMISSION);
return result;
}
putMsg(result, Status.SUCCESS);
result.setData(resource);
return result;
}
/**
* get resource by id
* @param id resource id
* @return resource
*/ |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | @Override
public Result<Object> queryResourceById(User loginUser, Integer id) {
Result<Object> result = new Result<>();
Resource resource = resourcesMapper.selectById(id);
if (resource == null) {
putMsg(result, Status.RESOURCE_NOT_EXIST);
return result;
}
String funcPermissionKey = resource.getType().equals(ResourceType.FILE) ? ApiFuncIdentificationConstant.FILE_VIEW : ApiFuncIdentificationConstant.UDF_FILE_VIEW;
boolean canOperatorPermissions = canOperatorPermissions(loginUser, new Object[]{id}, AuthorizationType.RESOURCE_FILE_ID, funcPermissionKey);
if (!canOperatorPermissions){
putMsg(result, Status.NO_CURRENT_OPERATING_PERMISSION);
return result;
}
putMsg(result, Status.SUCCESS);
result.setData(resource);
return result;
}
/**
* view resource file online
*
* @param resourceId resource id
* @param skipLineNum skip line number
* @param limit limit
* @return resource content
*/
@Override
public Result<Object> readResource(User loginUser, int resourceId, int skipLineNum, int limit) {
Result<Object> result = checkResourceUploadStartupState();
if (!result.getCode().equals(Status.SUCCESS.getCode())) { |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | return result;
}
Resource resource = resourcesMapper.selectById(resourceId);
if (resource == null) {
putMsg(result, Status.RESOURCE_NOT_EXIST);
return result;
}
String funcPermissionKey = resource.getType().equals(ResourceType.FILE) ? ApiFuncIdentificationConstant.FILE_VIEW : ApiFuncIdentificationConstant.UDF_FILE_VIEW;
boolean canOperatorPermissions = canOperatorPermissions(loginUser, new Object[]{resourceId}, AuthorizationType.RESOURCE_FILE_ID, funcPermissionKey);
if (!canOperatorPermissions){
putMsg(result, Status.NO_CURRENT_OPERATING_PERMISSION);
return result;
}
String nameSuffix = Files.getFileExtension(resource.getAlias());
String resourceViewSuffixes = FileUtils.getResourceViewSuffixes();
if (StringUtils.isNotEmpty(resourceViewSuffixes)) {
List<String> strList = Arrays.asList(resourceViewSuffixes.split(","));
if (!strList.contains(nameSuffix)) {
logger.error("resource suffix {} not support view, resource id {}", nameSuffix, resourceId);
putMsg(result, Status.RESOURCE_SUFFIX_NOT_SUPPORT_VIEW);
return result;
}
}
String tenantCode = getTenantCode(resource.getUserId(), result);
if (StringUtils.isEmpty(tenantCode)) {
return result;
} |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | String resourceFileName = storageOperate.getResourceFileName(tenantCode, resource.getFullName());
logger.info("resource path is {}", resourceFileName);
try {
if (storageOperate.exists(tenantCode, resourceFileName)) {
List<String> content = storageOperate.vimFile(tenantCode, resourceFileName, skipLineNum, limit);
putMsg(result, Status.SUCCESS);
Map<String, Object> map = new HashMap<>();
map.put(ALIAS, resource.getAlias());
map.put(CONTENT, String.join("\n", content));
result.setData(map);
} else {
logger.error("read file {} not exist in storage", resourceFileName);
putMsg(result, Status.RESOURCE_FILE_NOT_EXIST, resourceFileName);
}
} catch (Exception e) {
logger.error("Resource {} read failed", resourceFileName, e);
putMsg(result, Status.HDFS_OPERATION_ERROR);
}
return result;
}
/**
* create resource file online
*
* @param loginUser login user
* @param type resource type
* @param fileName file name
* @param fileSuffix file suffix
* @param desc description
* @param content content
* @param pid pid |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | * @param currentDir current directory
* @return create result code
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Result<Object> onlineCreateResource(User loginUser, ResourceType type, String fileName, String fileSuffix, String desc, String content, int pid, String currentDir) {
Result<Object> result = new Result<>();
boolean canOperatorPermissions = canOperatorPermissions(loginUser, null, AuthorizationType.RESOURCE_FILE_ID, ApiFuncIdentificationConstant.FILE_ONLINE_CREATE);
if (!canOperatorPermissions){
putMsg(result, Status.NO_CURRENT_OPERATING_PERMISSION);
return result;
}
result = checkResourceUploadStartupState();
if (!result.getCode().equals(Status.SUCCESS.getCode())) {
return result;
}
if (FileUtils.directoryTraversal(fileName)) {
putMsg(result, Status.VERIFY_PARAMETER_NAME_FAILED);
return result;
}
String nameSuffix = fileSuffix.trim();
String resourceViewSuffixes = FileUtils.getResourceViewSuffixes();
if (StringUtils.isNotEmpty(resourceViewSuffixes)) {
List<String> strList = Arrays.asList(resourceViewSuffixes.split(","));
if (!strList.contains(nameSuffix)) {
logger.error("resource suffix {} not support create", nameSuffix);
putMsg(result, Status.RESOURCE_SUFFIX_NOT_SUPPORT_VIEW);
return result; |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | }
}
String name = fileName.trim() + "." + nameSuffix;
String fullName = getFullName(currentDir, name);
result = verifyResource(loginUser, type, fullName, pid);
if (!result.getCode().equals(Status.SUCCESS.getCode())) {
return result;
}
Date now = new Date();
Resource resource = new Resource(pid, name, fullName, false, desc, name, loginUser.getId(), type, content.getBytes().length, now, now);
resourcesMapper.insert(resource);
updateParentResourceSize(resource, resource.getSize());
putMsg(result, Status.SUCCESS);
Map<String, Object> resultMap = new HashMap<>();
for (Map.Entry<Object, Object> entry : new BeanMap(resource).entrySet()) {
if (!Constants.CLASS.equalsIgnoreCase(entry.getKey().toString())) {
resultMap.put(entry.getKey().toString(), entry.getValue());
}
}
result.setData(resultMap);
String tenantCode = tenantMapper.queryById(loginUser.getTenantId()).getTenantCode();
result = uploadContentToStorage(loginUser, fullName, tenantCode, content);
if (!result.getCode().equals(Status.SUCCESS.getCode())) {
throw new ServiceException(result.getMsg());
}
return result;
}
private Result<Object> checkResourceUploadStartupState() {
Result<Object> result = new Result<>(); |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | putMsg(result, Status.SUCCESS);
if (!PropertyUtils.getResUploadStartupState()) {
logger.error("resource upload startup state: {}", PropertyUtils.getResUploadStartupState());
putMsg(result, Status.STORAGE_NOT_STARTUP);
return result;
}
return result;
}
private Result<Object> verifyResource(User loginUser, ResourceType type, String fullName, int pid) {
Result<Object> result = verifyResourceName(fullName, type, loginUser);
if (!result.getCode().equals(Status.SUCCESS.getCode())) {
return result;
}
return verifyPid(loginUser, pid);
}
private Result<Object> verifyPid(User loginUser, int pid) {
Result<Object> result = new Result<>();
putMsg(result, Status.SUCCESS);
if (pid != -1) {
Resource parentResource = resourcesMapper.selectById(pid);
if (parentResource == null) {
putMsg(result, Status.PARENT_RESOURCE_NOT_EXIST);
return result;
}
if (!canOperator(loginUser, parentResource.getUserId())) {
putMsg(result, Status.USER_NO_OPERATION_PERM);
return result;
}
} |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | return result;
}
/**
* updateProcessInstance resource
*
* @param resourceId resource id
* @param content content
* @return update result cod
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Result<Object> updateResourceContent(User loginUser, int resourceId, String content) {
Result<Object> result = checkResourceUploadStartupState();
if (!result.getCode().equals(Status.SUCCESS.getCode())) {
return result;
}
Resource resource = resourcesMapper.selectById(resourceId);
if (resource == null) {
logger.error("read file not exist, resource id {}", resourceId);
putMsg(result, Status.RESOURCE_NOT_EXIST);
return result;
}
String funcPermissionKey = resource.getType().equals(ResourceType.FILE) ? ApiFuncIdentificationConstant.FILE_UPDATE : ApiFuncIdentificationConstant.UDF_UPDATE;
boolean canOperatorPermissions = canOperatorPermissions(loginUser, new Object[]{resourceId}, AuthorizationType.RESOURCE_FILE_ID, funcPermissionKey);
if (!canOperatorPermissions){
putMsg(result, Status.NO_CURRENT_OPERATING_PERMISSION);
return result;
}
String nameSuffix = Files.getFileExtension(resource.getAlias()); |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | String resourceViewSuffixes = FileUtils.getResourceViewSuffixes();
if (StringUtils.isNotEmpty(resourceViewSuffixes)) {
List<String> strList = Arrays.asList(resourceViewSuffixes.split(","));
if (!strList.contains(nameSuffix)) {
logger.error("resource suffix {} not support updateProcessInstance, resource id {}", nameSuffix, resourceId);
putMsg(result, Status.RESOURCE_SUFFIX_NOT_SUPPORT_VIEW);
return result;
}
}
String tenantCode = getTenantCode(resource.getUserId(), result);
if (StringUtils.isEmpty(tenantCode)) {
return result;
}
long originFileSize = resource.getSize();
resource.setSize(content.getBytes().length);
resource.setUpdateTime(new Date());
resourcesMapper.updateById(resource);
result = uploadContentToStorage(loginUser, resource.getFullName(), tenantCode, content);
updateParentResourceSize(resource, resource.getSize() - originFileSize);
if (!result.getCode().equals(Status.SUCCESS.getCode())) {
throw new ServiceException(result.getMsg());
}
return result;
}
/**
* @param resourceName resource name
* @param tenantCode tenant code
* @param content content
* @return result
*/ |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | private Result<Object> uploadContentToStorage(User loginUser,String resourceName, String tenantCode, String content) {
Result<Object> result = new Result<>();
String localFilename = "";
String storageFileName = "";
try {
localFilename = FileUtils.getUploadFilename(tenantCode, UUID.randomUUID().toString());
if (!FileUtils.writeContent2File(content, localFilename)) {
logger.error("file {} fail, content is {}", localFilename, RegexUtils.escapeNRT(content));
putMsg(result, Status.RESOURCE_NOT_EXIST);
return result;
}
storageFileName = storageOperate.getResourceFileName(tenantCode, resourceName);
String resourcePath = storageOperate.getResDir(tenantCode);
logger.info("resource path is {}, resource dir is {}", storageFileName, resourcePath);
if (!storageOperate.exists(tenantCode, resourcePath)) {
storageOperate.createTenantDirIfNotExists(tenantCode);
}
if (storageOperate.exists(tenantCode, storageFileName)) {
storageOperate.delete(tenantCode, storageFileName, false);
}
storageOperate.upload(tenantCode, localFilename, storageFileName, true, true);
} catch (Exception e) {
logger.error(e.getMessage(), e);
result.setCode(Status.HDFS_OPERATION_ERROR.getCode());
result.setMsg(String.format("copy %s to hdfs %s fail", localFilename, storageFileName));
return result;
} |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | putMsg(result, Status.SUCCESS);
return result;
}
/**
* download file
*
* @param resourceId resource id
* @return resource content
* @throws IOException exception
*/
@Override
public org.springframework.core.io.Resource downloadResource(User loginUser, int resourceId) throws IOException {
if (!PropertyUtils.getResUploadStartupState()) {
logger.error("resource upload startup state: {}", PropertyUtils.getResUploadStartupState());
throw new ServiceException("hdfs not startup");
}
Resource resource = resourcesMapper.selectById(resourceId);
if (resource == null) {
logger.error("download file not exist, resource id {}", resourceId);
return null;
}
String funcPermissionKey = resource.getType().equals(ResourceType.FILE) ? ApiFuncIdentificationConstant.FILE_DOWNLOAD : ApiFuncIdentificationConstant.UDF_DOWNLOAD;
boolean canOperatorPermissions = canOperatorPermissions(loginUser, new Object[]{resourceId}, AuthorizationType.RESOURCE_FILE_ID, funcPermissionKey);
if (!canOperatorPermissions){
logger.error("{}: {}", Status.NO_CURRENT_OPERATING_PERMISSION.getMsg(), PropertyUtils.getResUploadStartupState());
throw new ServiceException(Status.NO_CURRENT_OPERATING_PERMISSION.getMsg());
}
if (resource.isDirectory()) {
logger.error("resource id {} is directory,can't download it", resourceId); |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | throw new ServiceException("can't download directory");
}
int userId = resource.getUserId();
User user = userMapper.selectById(userId);
if (user == null) {
logger.error("user id {} not exists", userId);
throw new ServiceException(String.format("resource owner id %d not exist", userId));
}
Tenant tenant = tenantMapper.queryById(user.getTenantId());
if (tenant == null) {
logger.error("tenant id {} not exists", user.getTenantId());
throw new ServiceException(String.format("The tenant id %d of resource owner not exist", user.getTenantId()));
}
String tenantCode = tenant.getTenantCode();
String fileName = storageOperate.getFileName(resource.getType(), tenantCode, resource.getFullName());
String localFileName = FileUtils.getDownloadFilename(resource.getAlias());
logger.info("resource path is {}, download local filename is {}", fileName, localFileName);
try {
storageOperate.download(tenantCode, fileName, localFileName, false, true);
return org.apache.dolphinscheduler.api.utils.FileUtils.file2Resource(localFileName);
} catch (IOException e) {
logger.error("download resource error, the path is {}, and local filename is {}, the error message is {}", fileName, localFileName, e.getMessage());
throw new ServerException("download the resource file failed ,it may be related to your storage");
}
}
/**
* list all file
*
* @param loginUser login user
* @param userId user id |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | * @return unauthorized result code
*/
@Override
public Map<String, Object> authorizeResourceTree(User loginUser, Integer userId) {
Map<String, Object> result = new HashMap<>();
if (!resourcePermissionCheckService.functionDisabled()){
putMsg(result, Status.FUNCTION_DISABLED);
return result;
}
List<Resource> resourceList;
if (isAdmin(loginUser)) {
resourceList = resourcesMapper.queryResourceExceptUserId(userId);
} else {
resourceList = resourcesMapper.queryResourceListAuthored(loginUser.getId(), -1);
}
List<ResourceComponent> list;
if (CollectionUtils.isNotEmpty(resourceList)) {
Visitor visitor = new ResourceTreeVisitor(resourceList);
list = visitor.visit().getChildren();
} else {
list = new ArrayList<>(0);
}
result.put(Constants.DATA_LIST, list);
putMsg(result, Status.SUCCESS);
return result;
}
/**
* unauthorized file |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | *
* @param loginUser login user
* @param userId user id
* @return unauthorized result code
*/
@Override
public Map<String, Object> unauthorizedFile(User loginUser, Integer userId) {
Map<String, Object> result = new HashMap<>();
List<Resource> resourceList;
if (isAdmin(loginUser)) {
resourceList = resourcesMapper.queryResourceExceptUserId(userId);
} else {
resourceList = resourcesMapper.queryResourceListAuthored(loginUser.getId(), -1);
}
List<Resource> list;
if (resourceList != null && !resourceList.isEmpty()) {
Set<Resource> resourceSet = new HashSet<>(resourceList);
List<Resource> authedResourceList = queryResourceList(userId, Constants.AUTHORIZE_WRITABLE_PERM);
getAuthorizedResourceList(resourceSet, authedResourceList);
list = new ArrayList<>(resourceSet);
} else {
list = new ArrayList<>(0);
}
Visitor visitor = new ResourceTreeVisitor(list);
result.put(Constants.DATA_LIST, visitor.visit().getChildren());
putMsg(result, Status.SUCCESS);
return result;
} |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | /**
* unauthorized udf function
*
* @param loginUser login user
* @param userId user id
* @return unauthorized result code
*/
@Override
public Map<String, Object> unauthorizedUDFFunction(User loginUser, Integer userId) {
Map<String, Object> result = new HashMap<>();
if (!resourcePermissionCheckService.functionDisabled()){
putMsg(result, Status.FUNCTION_DISABLED);
return result;
}
List<UdfFunc> udfFuncList;
if (isAdmin(loginUser)) {
udfFuncList = udfFunctionMapper.queryUdfFuncExceptUserId(userId);
} else {
udfFuncList = udfFunctionMapper.selectByMap(Collections.singletonMap("user_id", loginUser.getId()));
}
List<UdfFunc> resultList = new ArrayList<>();
Set<UdfFunc> udfFuncSet;
if (CollectionUtils.isNotEmpty(udfFuncList)) {
udfFuncSet = new HashSet<>(udfFuncList);
List<UdfFunc> authedUDFFuncList = udfFunctionMapper.queryAuthedUdfFunc(userId);
getAuthorizedResourceList(udfFuncSet, authedUDFFuncList);
resultList = new ArrayList<>(udfFuncSet); |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | }
result.put(Constants.DATA_LIST, resultList);
putMsg(result, Status.SUCCESS);
return result;
}
/**
* authorized udf function
*
* @param loginUser login user
* @param userId user id
* @return authorized result code
*/
@Override
public Map<String, Object> authorizedUDFFunction(User loginUser, Integer userId) {
Map<String, Object> result = new HashMap<>();
if (!resourcePermissionCheckService.functionDisabled()){
putMsg(result, Status.FUNCTION_DISABLED);
return result;
}
List<UdfFunc> udfFuncs = udfFunctionMapper.queryAuthedUdfFunc(userId);
result.put(Constants.DATA_LIST, udfFuncs);
putMsg(result, Status.SUCCESS);
return result;
}
/**
* authorized file
*
* @param loginUser login user
* @param userId user id
* @return authorized result |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | */
@Override
public Map<String, Object> authorizedFile(User loginUser, Integer userId) {
Map<String, Object> result = new HashMap<>();
if (!resourcePermissionCheckService.functionDisabled()){
putMsg(result, Status.FUNCTION_DISABLED);
return result;
}
List<Resource> authedResources = queryResourceList(userId, Constants.AUTHORIZE_WRITABLE_PERM);
Visitor visitor = new ResourceTreeVisitor(authedResources);
String visit = JSONUtils.toJsonString(visitor.visit(), SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS);
logger.info(visit);
String jsonTreeStr = JSONUtils.toJsonString(visitor.visit().getChildren(), SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS);
logger.info(jsonTreeStr);
result.put(Constants.DATA_LIST, visitor.visit().getChildren());
putMsg(result, Status.SUCCESS);
return result;
}
/**
* get authorized resource list
*
* @param resourceSet resource set
* @param authedResourceList authorized resource list
*/
private void getAuthorizedResourceList(Set<?> resourceSet, List<?> authedResourceList) {
Set<?> authedResourceSet;
if (CollectionUtils.isNotEmpty(authedResourceList)) {
authedResourceSet = new HashSet<>(authedResourceList);
resourceSet.removeAll(authedResourceSet);
} |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | }
/**
* get tenantCode by UserId
*
* @param userId user id
* @param result return result
* @return tenant code
*/
private String getTenantCode(int userId, Result<Object> result) {
User user = userMapper.selectById(userId);
if (user == null) {
logger.error("user {} not exists", userId);
putMsg(result, Status.USER_NOT_EXIST, userId);
return null;
}
Tenant tenant = tenantMapper.queryById(user.getTenantId());
if (tenant == null) {
logger.error("tenant not exists");
putMsg(result, Status.CURRENT_LOGIN_USER_TENANT_NOT_EXIST);
return null;
}
return tenant.getTenantCode();
}
/**
* list all children id
*
* @param resource resource
* @param containSelf whether add self to children list
* @return all children id
*/ |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | List<Integer> listAllChildren(Resource resource, boolean containSelf) {
List<Integer> childList = new ArrayList<>();
if (resource.getId() != -1 && containSelf) {
childList.add(resource.getId());
}
if (resource.isDirectory()) {
listAllChildren(resource.getId(), childList);
}
return childList;
}
/**
* list all children id
*
* @param resourceId resource id
* @param childList child list
*/
void listAllChildren(int resourceId, List<Integer> childList) {
List<Integer> children = resourcesMapper.listChildren(resourceId);
for (int childId : children) {
childList.add(childId);
listAllChildren(childId, childList);
}
}
/**
* query authored resource list (own and authorized)
*
* @param loginUser login user
* @param type ResourceType
* @return all authored resource list
*/ |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java | private List<Resource> queryAuthoredResourceList(User loginUser, ResourceType type) {
List<Resource> relationResources;
int userId = loginUser.getId();
if (isAdmin(loginUser)) {
userId = 0;
relationResources = new ArrayList<>();
} else {
relationResources = queryResourceList(userId, 0);
}
List<Resource> relationTypeResources =
relationResources.stream().filter(rs -> rs.getType() == type).collect(Collectors.toList());
List<Resource> ownResourceList = resourcesMapper.queryResourceListAuthored(userId, type.ordinal());
ownResourceList.addAll(relationTypeResources);
return ownResourceList;
}
/**
* query resource list by userId and perm
*
* @param userId userId
* @param perm perm
* @return resource list
*/
private List<Resource> queryResourceList(Integer userId, int perm) {
List<Integer> resIds = resourceUserMapper.queryResourcesIdListByUserIdAndPerm(userId, perm);
return CollectionUtils.isEmpty(resIds) ? new ArrayList<>() : resourcesMapper.queryResourceListById(resIds);
}
} |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ResourcesServiceTest.java | /*
* 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.
*/ |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ResourcesServiceTest.java | package org.apache.dolphinscheduler.api.service;
import static org.mockito.ArgumentMatchers.eq;
import org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant;
import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.service.impl.BaseServiceImpl;
import org.apache.dolphinscheduler.api.service.impl.ResourcesServiceImpl;
import org.apache.dolphinscheduler.api.utils.PageInfo;
import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.common.enums.AuthorizationType;
import org.apache.dolphinscheduler.common.enums.UserType;
import org.apache.dolphinscheduler.common.storage.StorageOperate;
import org.apache.dolphinscheduler.common.utils.FileUtils;
import org.apache.dolphinscheduler.common.utils.PropertyUtils;
import org.apache.dolphinscheduler.dao.entity.Resource;
import org.apache.dolphinscheduler.dao.entity.Tenant;
import org.apache.dolphinscheduler.dao.entity.UdfFunc;
import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper;
import org.apache.dolphinscheduler.dao.mapper.ResourceMapper;
import org.apache.dolphinscheduler.dao.mapper.ResourceUserMapper;
import org.apache.dolphinscheduler.dao.mapper.TenantMapper;
import org.apache.dolphinscheduler.dao.mapper.UdfFuncMapper;
import org.apache.dolphinscheduler.dao.mapper.UserMapper;
import org.apache.dolphinscheduler.service.permission.ResourcePermissionCheckService;
import org.apache.dolphinscheduler.spi.enums.ResourceType;
import org.apache.commons.collections.CollectionUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays; |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ResourcesServiceTest.java | import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.mock.web.MockMultipartFile;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.io.Files;
/**
* resources service test
*/
@RunWith(PowerMockRunner.class)
@PowerMockIgnore({"sun.security.*", "javax.net.*"})
@PrepareForTest({PropertyUtils.class, |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ResourcesServiceTest.java | FileUtils.class, org.apache.dolphinscheduler.api.utils.FileUtils.class,
Files.class})
public class ResourcesServiceTest {
private static final Logger logger = LoggerFactory.getLogger(ResourcesServiceTest.class);
@InjectMocks
private ResourcesServiceImpl resourcesService;
@Mock
private ResourceMapper resourcesMapper;
@Mock
private TenantMapper tenantMapper;
@Mock
private StorageOperate storageOperate;
@Mock
private UserMapper userMapper;
@Mock
private UdfFuncMapper udfFunctionMapper;
@Mock
private ProcessDefinitionMapper processDefinitionMapper;
@Mock
private ResourceUserMapper resourceUserMapper;
@Mock
private ResourcePermissionCheckService resourcePermissionCheckService;
private static final Logger serviceLogger = LoggerFactory.getLogger(BaseServiceImpl.class);
@Before
public void setUp() {
PowerMockito.mockStatic(FileUtils.class);
PowerMockito.mockStatic(Files.class);
PowerMockito.mockStatic(org.apache.dolphinscheduler.api.utils.FileUtils.class);
try { |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ResourcesServiceTest.java | } catch (Exception e) {
e.printStackTrace();
}
PowerMockito.mockStatic(PropertyUtils.class);
}
@Test
public void testCreateResource() {
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.FILE_ONLINE_CREATE, serviceLogger)).thenReturn(true);
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, 1, serviceLogger)).thenReturn(true);
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(false);
User user = new User();
user.setId(1);
user.setUserType(UserType.GENERAL_USER);
Result result = resourcesService.createResource(user, "ResourcesServiceTest", "ResourcesServiceTest", ResourceType.FILE, null, -1, "/");
logger.info(result.toString());
Assert.assertEquals(Status.STORAGE_NOT_STARTUP.getMsg(), result.getMsg());
MockMultipartFile mockMultipartFile = new MockMultipartFile("test.pdf", "".getBytes());
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true);
result = resourcesService.createResource(user, "ResourcesServiceTest", "ResourcesServiceTest", ResourceType.FILE, mockMultipartFile, -1, "/");
logger.info(result.toString());
Assert.assertEquals(Status.RESOURCE_FILE_IS_EMPTY.getMsg(), result.getMsg());
mockMultipartFile = new MockMultipartFile("test.pdf", "test.pdf", "pdf", "test".getBytes());
PowerMockito.when(Files.getFileExtension("test.pdf")).thenReturn("pdf");
PowerMockito.when(Files.getFileExtension("ResourcesServiceTest.jar")).thenReturn("jar");
result = resourcesService.createResource(user, "ResourcesServiceTest.jar", "ResourcesServiceTest", ResourceType.FILE, mockMultipartFile, -1, "/"); |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ResourcesServiceTest.java | logger.info(result.toString());
Assert.assertEquals(Status.RESOURCE_SUFFIX_FORBID_CHANGE.getMsg(), result.getMsg());
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.UDF_FOLDER_ONLINE_CREATE, serviceLogger)).thenReturn(true);
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, 1, serviceLogger)).thenReturn(true);
mockMultipartFile = new MockMultipartFile("ResourcesServiceTest.pdf", "ResourcesServiceTest.pdf", "pdf", "test".getBytes());
PowerMockito.when(Files.getFileExtension("ResourcesServiceTest.pdf")).thenReturn("pdf");
result = resourcesService.createResource(user, "ResourcesServiceTest.pdf", "ResourcesServiceTest", ResourceType.UDF, mockMultipartFile, -1, "/");
logger.info(result.toString());
Assert.assertEquals(Status.UDF_RESOURCE_SUFFIX_NOT_JAR.getMsg(), result.getMsg());
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.FILE_ONLINE_CREATE, serviceLogger)).thenReturn(true);
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, 1, serviceLogger)).thenReturn(true);
String tooLongFileName = getRandomStringWithLength(Constants.RESOURCE_FULL_NAME_MAX_LENGTH) + ".pdf";
mockMultipartFile = new MockMultipartFile(tooLongFileName, tooLongFileName, "pdf", "test".getBytes());
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true);
PowerMockito.when(Files.getFileExtension(tooLongFileName)).thenReturn("pdf");
result = resourcesService.createResource(user, tooLongFileName, tooLongFileName, ResourceType.FILE, mockMultipartFile, -1, "/");
logger.info(result.toString());
Assert.assertEquals(Status.RESOURCE_FULL_NAME_TOO_LONG_ERROR.getMsg(), result.getMsg());
}
@Test
public void testCreateDirecotry() {
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.FOLDER_ONLINE_CREATE, serviceLogger)).thenReturn(true);
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, 1, serviceLogger)).thenReturn(true);
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(false);
User user = new User();
user.setId(1);
user.setUserType(UserType.GENERAL_USER); |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ResourcesServiceTest.java | Result result = resourcesService.createDirectory(user, "directoryTest", "directory test", ResourceType.FILE, -1, "/");
logger.info(result.toString());
Assert.assertEquals(Status.STORAGE_NOT_STARTUP.getMsg(), result.getMsg());
user.setId(1);
user.setTenantId(1);
Mockito.when(userMapper.selectById(1)).thenReturn(getUser());
Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant());
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true);
Mockito.when(resourcesMapper.selectById(Mockito.anyInt())).thenReturn(null);
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.FOLDER_ONLINE_CREATE, serviceLogger)).thenReturn(true);
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, 1, serviceLogger)).thenReturn(true);
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.FILE_RENAME, serviceLogger)).thenReturn(true);
result = resourcesService.createDirectory(user, "directoryTest", "directory test", ResourceType.FILE, 1, "/");
logger.info(result.toString());
Assert.assertEquals(Status.PARENT_RESOURCE_NOT_EXIST.getMsg(), result.getMsg());
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true);
Mockito.when(resourcesMapper.existResource("/directoryTest", 0)).thenReturn(true);
result = resourcesService.createDirectory(user, "directoryTest", "directory test", ResourceType.FILE, -1, "/");
logger.info(result.toString());
Assert.assertEquals(Status.RESOURCE_EXIST.getMsg(), result.getMsg());
}
@Test
public void testUpdateResource() {
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.FILE_UPDATE, serviceLogger)).thenReturn(true);
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, new Object[]{1}, 1, serviceLogger)).thenReturn(true);
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(false);
User user = new User();
user.setId(1); |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ResourcesServiceTest.java | user.setUserType(UserType.GENERAL_USER);
Result result = resourcesService.updateResource(user, 1, "ResourcesServiceTest", "ResourcesServiceTest", ResourceType.FILE, null);
logger.info(result.toString());
Assert.assertEquals(Status.STORAGE_NOT_STARTUP.getMsg(), result.getMsg());
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.FILE_UPDATE, serviceLogger)).thenReturn(true);
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, new Object[]{0}, 1, serviceLogger)).thenReturn(true);
Mockito.when(resourcesMapper.selectById(1)).thenReturn(getResource());
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true);
result = resourcesService.updateResource(user, 0, "ResourcesServiceTest", "ResourcesServiceTest", ResourceType.FILE, null);
logger.info(result.toString());
Assert.assertEquals(Status.RESOURCE_NOT_EXIST.getMsg(), result.getMsg());
user.setId(2);
user.setUserType(UserType.GENERAL_USER);
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 2, ApiFuncIdentificationConstant.FILE_UPDATE, serviceLogger)).thenReturn(true);
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, new Object[]{1}, 2, serviceLogger)).thenReturn(true);
result = resourcesService.updateResource(user, 1, "ResourcesServiceTest", "ResourcesServiceTest", ResourceType.FILE, null);
logger.info(result.toString());
Assert.assertEquals(Status.USER_NO_OPERATION_PERM.getMsg(), result.getMsg());
user.setId(1);
Mockito.when(userMapper.selectById(1)).thenReturn(getUser());
Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant());
PowerMockito.when(storageOperate.getFileName(Mockito.any(), Mockito.any(), Mockito.anyString())).thenReturn("test1");
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.UDF_UPDATE, serviceLogger)).thenReturn(true);
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, new Object[]{1}, 1, serviceLogger)).thenReturn(true);
try {
Mockito.when(storageOperate.exists(Mockito.any(), Mockito.any())).thenReturn(false); |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ResourcesServiceTest.java | } catch (IOException e) {
logger.error(e.getMessage(), e);
}
result = resourcesService.updateResource(user, 1, "ResourcesServiceTest1.jar", "ResourcesServiceTest", ResourceType.UDF, null);
Assert.assertEquals(Status.RESOURCE_NOT_EXIST.getMsg(), result.getMsg());
user.setId(1);
Mockito.when(userMapper.queryDetailsById(1)).thenReturn(getUser());
Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant());
try {
Mockito.when(storageOperate.exists(Mockito.any(), Mockito.any())).thenReturn(true);
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.FILE_UPDATE, serviceLogger)).thenReturn(true);
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, new Object[]{1}, 1, serviceLogger)).thenReturn(true);
result = resourcesService.updateResource(user, 1, "ResourcesServiceTest.jar", "ResourcesServiceTest", ResourceType.FILE, null);
logger.info(result.toString());
Assert.assertEquals(Status.SUCCESS.getMsg(), result.getMsg());
Mockito.when(resourcesMapper.existResource("/ResourcesServiceTest1.jar", 0)).thenReturn(true);
result = resourcesService.updateResource(user, 1, "ResourcesServiceTest1.jar", "ResourcesServiceTest", ResourceType.FILE, null);
logger.info(result.toString());
Assert.assertEquals(Status.RESOURCE_EXIST.getMsg(), result.getMsg());
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.UDF_UPDATE, serviceLogger)).thenReturn(true);
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, new Object[]{1}, 1, serviceLogger)).thenReturn(true);
Mockito.when(userMapper.selectById(Mockito.anyInt())).thenReturn(null);
result = resourcesService.updateResource(user, 1, "ResourcesServiceTest1.jar", "ResourcesServiceTest", ResourceType.UDF, null);
logger.info(result.toString()); |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ResourcesServiceTest.java | Assert.assertTrue(Status.USER_NOT_EXIST.getCode() == result.getCode());
Mockito.when(userMapper.selectById(1)).thenReturn(getUser());
Mockito.when(tenantMapper.queryById(Mockito.anyInt())).thenReturn(null);
result = resourcesService.updateResource(user, 1, "ResourcesServiceTest1.jar", "ResourcesServiceTest", ResourceType.UDF, null);
logger.info(result.toString());
Assert.assertEquals(Status.CURRENT_LOGIN_USER_TENANT_NOT_EXIST.getMsg(), result.getMsg());
Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant());
PowerMockito.when(storageOperate.getResourceFileName(Mockito.any(), Mockito.any())).thenReturn("test");
try {
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
result = resourcesService.updateResource(user, 1, "ResourcesServiceTest1.jar", "ResourcesServiceTest1.jar", ResourceType.UDF, null);
logger.info(result.toString());
Assert.assertEquals(Status.SUCCESS.getMsg(), result.getMsg());
}
@Test
public void testQueryResourceListPaging() {
User loginUser = new User();
loginUser.setId(1);
loginUser.setUserType(UserType.ADMIN_USER);
IPage<Resource> resourcePage = new Page<>(1, 10);
resourcePage.setTotal(1);
resourcePage.setRecords(getResourceList());
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.FILE_VIEW, serviceLogger)).thenReturn(true);
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, 0, serviceLogger)).thenReturn(true);
PowerMockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.RESOURCE_FILE_ID, 1, serviceLogger)).thenReturn(getSetIds()); |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ResourcesServiceTest.java | Mockito.when(resourcesMapper.queryResourcePaging(Mockito.any(Page.class), eq(-1), eq(0), eq(1), eq("test"), Mockito.any())).thenReturn(resourcePage);
Result result = resourcesService.queryResourceListPaging(loginUser, -1, ResourceType.FILE, "test", 1, 10);
logger.info(result.toString());
Assert.assertEquals(Status.SUCCESS.getCode(), (int) result.getCode());
PageInfo pageInfo = (PageInfo) result.getData();
Assert.assertTrue(CollectionUtils.isNotEmpty(pageInfo.getTotalList()));
}
@Test
public void testQueryResourceList() {
User loginUser = new User();
loginUser.setId(0);
loginUser.setUserType(UserType.ADMIN_USER);
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 0, ApiFuncIdentificationConstant.FILE_VIEW, serviceLogger)).thenReturn(true);
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, 0, serviceLogger)).thenReturn(true);
PowerMockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.RESOURCE_FILE_ID, 0, serviceLogger)).thenReturn(getSetIds());
Mockito.when(resourcesMapper.queryResourceListAuthored(0, 0)).thenReturn(getResourceList());
Map<String, Object> result = resourcesService.queryResourceList(loginUser, ResourceType.FILE);
logger.info(result.toString());
Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
List<Resource> resourceList = (List<Resource>) result.get(Constants.DATA_LIST);
Assert.assertTrue(CollectionUtils.isNotEmpty(resourceList));
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 0, ApiFuncIdentificationConstant.UDF_FILE_VIEW, serviceLogger)).thenReturn(true);
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, 0, serviceLogger)).thenReturn(true);
PowerMockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.RESOURCE_FILE_ID, 0, serviceLogger)).thenReturn(getSetIds());
loginUser.setUserType(UserType.GENERAL_USER);
Mockito.when(resourceUserMapper.queryResourcesIdListByUserIdAndPerm(0, 0))
.thenReturn(Arrays.asList(Integer.valueOf(10), Integer.valueOf(11)));
Mockito.when(resourcesMapper.queryResourceListById(Arrays.asList(Integer.valueOf(10), Integer.valueOf(11))))
.thenReturn(Arrays.asList(getResource(10, ResourceType.FILE), getResource(11, ResourceType.UDF))); |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ResourcesServiceTest.java | Mockito.when(resourcesMapper.queryResourceListAuthored(0, 1)).thenReturn(getResourceList());
result = resourcesService.queryResourceList(loginUser, ResourceType.UDF);
logger.info(result.toString());
Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
resourceList = (List<Resource>) result.get(Constants.DATA_LIST);
Assert.assertTrue(resourceList.size() == 4);
}
@Test
public void testDelete() {
User loginUser = new User();
loginUser.setId(0);
loginUser.setUserType(UserType.GENERAL_USER);
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(false);
Mockito.when(resourcesMapper.selectById(1)).thenReturn(getResource());
Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant());
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 0, ApiFuncIdentificationConstant.FILE_DELETE, serviceLogger)).thenReturn(true);
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, new Object[]{1}, 0, serviceLogger)).thenReturn(true);
try {
Result result = resourcesService.delete(loginUser, 1);
logger.info(result.toString());
Assert.assertEquals(Status.STORAGE_NOT_STARTUP.getMsg(), result.getMsg());
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true);
Mockito.when(resourcesMapper.selectById(1)).thenReturn(getResource());
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 0, ApiFuncIdentificationConstant.FILE_DELETE, serviceLogger)).thenReturn(true);
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, new Object[]{2}, 0, serviceLogger)).thenReturn(true);
result = resourcesService.delete(loginUser, 2);
logger.info(result.toString());
Assert.assertEquals(Status.RESOURCE_NOT_EXIST.getMsg(), result.getMsg()); |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ResourcesServiceTest.java | result = resourcesService.delete(loginUser, 2);
logger.info(result.toString());
Assert.assertEquals(Status.RESOURCE_NOT_EXIST.getMsg(), result.getMsg());
loginUser.setUserType(UserType.ADMIN_USER);
loginUser.setTenantId(2);
Mockito.when(userMapper.selectById(Mockito.anyInt())).thenReturn(loginUser);
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 0, ApiFuncIdentificationConstant.FILE_DELETE, serviceLogger)).thenReturn(true);
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, new Object[]{1}, 0, serviceLogger)).thenReturn(true);
result = resourcesService.delete(loginUser, 1);
logger.info(result.toString());
Assert.assertEquals(Status.CURRENT_LOGIN_USER_TENANT_NOT_EXIST.getMsg(), result.getMsg());
loginUser.setTenantId(1);
Mockito.when(storageOperate.delete(Mockito.any(), Mockito.anyString(), Mockito.anyBoolean())).thenReturn(true);
Mockito.when(processDefinitionMapper.listResources()).thenReturn(getResources());
Mockito.when(resourcesMapper.deleteIds(Mockito.any())).thenReturn(1);
Mockito.when(resourceUserMapper.deleteResourceUserArray(Mockito.anyInt(), Mockito.any())).thenReturn(1);
result = resourcesService.delete(loginUser, 1);
logger.info(result.toString());
Assert.assertEquals(Status.SUCCESS.getMsg(), result.getMsg());
} catch (Exception e) {
logger.error("delete error", e);
Assert.assertTrue(false);
}
}
@Test
public void testVerifyResourceName() {
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.FILE_RENAME, serviceLogger)).thenReturn(true); |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 10,293 | [Bug] [Api-Server] Improve exception handling when admin user uploads file in resource center | ### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues.
### What happened
* If user logs in with admin role and does not set tenant, there will be `null pointer exception` when he / she tries to upload files in `resource center`.

### What you expected to happen
* We need some exception handling here and provide users with instructive error message: https://github.com/apache/dolphinscheduler/blob/8d26d4fe72aa81437103716b22f52ef6dc515a14/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L653-L656
* We need to remind users that tenant should be set before playing with `resource center` if they log in with `admin` role.
### How to reproduce
* Already described above.
### Anything else
_No response_
### Version
dev
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
| https://github.com/apache/dolphinscheduler/issues/10293 | https://github.com/apache/dolphinscheduler/pull/10303 | 3f2a21293d1b7cc8fe12a5e951fda15d231b05ac | 442f93544eef5436f82a0c9f7dacde93d4347090 | 2022-05-30T07:41:04Z | java | 2022-06-01T09:22:36Z | dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ResourcesServiceTest.java | PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, 1, serviceLogger)).thenReturn(true);
User user = new User();
user.setId(1);
user.setUserType(UserType.GENERAL_USER);
Mockito.when(resourcesMapper.existResource("/ResourcesServiceTest.jar", 0)).thenReturn(true);
Result result = resourcesService.verifyResourceName("/ResourcesServiceTest.jar", ResourceType.FILE, user);
logger.info(result.toString());
Assert.assertEquals(Status.RESOURCE_EXIST.getMsg(), result.getMsg());
Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant());
String unExistFullName = "/test.jar";
try {
Mockito.when(storageOperate.exists(Mockito.anyString(), eq(unExistFullName))).thenReturn(false);
} catch (IOException e) {
logger.error("hadoop error", e);
}
result = resourcesService.verifyResourceName("/test.jar", ResourceType.FILE, user);
logger.info(result.toString());
Assert.assertEquals(Status.CURRENT_LOGIN_USER_TENANT_NOT_EXIST.getMsg(), result.getMsg());
user.setTenantId(1);
try {
Mockito.when(storageOperate.exists(Mockito.any(), eq("test"))).thenReturn(true);
} catch (IOException e) {
logger.error("hadoop error", e);
}
PowerMockito.when(storageOperate.getResourceFileName("123", "test1")).thenReturn("test");
result = resourcesService.verifyResourceName("/ResourcesServiceTest.jar", ResourceType.FILE, user);
logger.info(result.toString());
Assert.assertTrue(Status.RESOURCE_EXIST.getCode() == result.getCode()); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.