Browse Source

[Improvement-10760][dolphinscheduler-api] Some variables are redundant and fix checkstyle (#11213)

* [fix-10729]The request's url given by the test case looks different from the controller layer. Some usages and parameter format errors

* [fix-10729]The request's url given by the test case looks different from the controller layer. Some usages and parameter format errors

* [fix-10729]The request's url given by the test case looks different from the controller layer. Some usages and parameter format errors

* [fix-10729]The request's url given by the test case looks different from the controller layer. Some usages and parameter format errors

* [fix-10729]fix the code smell

* [fix-10729]decorate DataSourceControllerTest with public

* [fix-10729]replace import *

* [fix-10729]checkstyle

* [Improvement][ExecutorServiceImpl] remove some unnecessary

* [fix-11181]text check and word spell

* Update dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ExecutorServiceImpl.java

Co-authored-by: Eric Gao <ericgao.apache@gmail.com>

* Update dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ExecutorServiceImpl.java

Co-authored-by: Eric Gao <ericgao.apache@gmail.com>

* Update ExecutorServiceImpl.java

remove the error logging and update the comment

* Update dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ExecutorServiceImpl.java

Co-authored-by: Eric Gao <ericgao.apache@gmail.com>

* [Improvement-10760][dolphinscheduler-api] Some variables are redundant

* [Improvement-10760][dolphinscheduler-api] Some variables are redundant and fix checkstyle

* [Improvement-10760][dolphinscheduler-api] Some variables are redundant and fix checkstyle

* [Improvement-10760][dolphinscheduler-api] add import

* [Improvement-10760][dolphinscheduler-api] remove not use

Co-authored-by: fuchanghai <changhai.fu@marketingforce.com>
Co-authored-by: Eric Gao <ericgao.apache@gmail.com>
3.1.0-release
fuchanghai 2 years ago committed by GitHub
parent
commit
cb001b581a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataSourceServiceImpl.java
  2. 3
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java
  3. 54
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java
  4. 92
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java

16
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataSourceServiceImpl.java

@ -17,6 +17,10 @@
package org.apache.dolphinscheduler.api.service.impl;
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.DATASOURCE_DELETE;
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.DATASOURCE_UPDATE;
import org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant;
import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.service.DataSourceService;
import org.apache.dolphinscheduler.api.utils.PageInfo;
@ -32,7 +36,6 @@ import org.apache.dolphinscheduler.dao.mapper.DataSourceUserMapper;
import org.apache.dolphinscheduler.plugin.datasource.api.datasource.BaseDataSourceParamDTO;
import org.apache.dolphinscheduler.plugin.datasource.api.plugin.DataSourceClientProvider;
import org.apache.dolphinscheduler.plugin.datasource.api.utils.DataSourceUtils;
import org.apache.dolphinscheduler.api.permission.ResourcePermissionCheckService;
import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam;
import org.apache.dolphinscheduler.spi.datasource.ConnectionParam;
import org.apache.dolphinscheduler.spi.enums.DbType;
@ -40,7 +43,7 @@ import org.apache.dolphinscheduler.spi.params.base.ParamsOptions;
import org.apache.dolphinscheduler.spi.utils.StringUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.IOUtils;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
@ -52,8 +55,8 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import org.slf4j.Logger;
@ -67,7 +70,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.databind.node.ObjectNode;
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.*;
/**
* data source service impl
@ -83,8 +86,6 @@ public class DataSourceServiceImpl extends BaseServiceImpl implements DataSource
@Autowired
private DataSourceUserMapper datasourceUserMapper;
@Autowired
private ResourcePermissionCheckService resourcePermissionCheckService;
private static final String TABLE = "TABLE";
private static final String VIEW = "VIEW";
@ -104,7 +105,7 @@ public class DataSourceServiceImpl extends BaseServiceImpl implements DataSource
public Result<Object> createDataSource(User loginUser, BaseDataSourceParamDTO datasourceParam) {
DataSourceUtils.checkDatasourceParam(datasourceParam);
Result<Object> result = new Result<>();
if (!canOperatorPermissions(loginUser,null, AuthorizationType.DATASOURCE, DATASOURCE_CREATE_DATASOURCE)) {
if (!canOperatorPermissions(loginUser,null, AuthorizationType.DATASOURCE, ApiFuncIdentificationConstant.DATASOURCE_CREATE_DATASOURCE)) {
putMsg(result, Status.USER_NO_OPERATION_PERM);
return result;
}
@ -264,7 +265,6 @@ public class DataSourceServiceImpl extends BaseServiceImpl implements DataSource
dataSourceList = dataSourceMapper.selectPagingByIds(dataSourcePage, new ArrayList<>(ids), searchVal);
}
List<DataSource> dataSources = dataSourceList != null ? dataSourceList.getRecords() : new ArrayList<>();
handlePasswd(dataSources);
pageInfo.setTotal((int) (dataSourceList != null ? dataSourceList.getTotal() : 0L));

3
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java

@ -23,7 +23,6 @@ import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationCon
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.PROJECT_UPDATE;
import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.permission.ResourcePermissionCheckService;
import org.apache.dolphinscheduler.api.service.ProjectService;
import org.apache.dolphinscheduler.api.utils.PageInfo;
import org.apache.dolphinscheduler.api.utils.Result;
@ -82,8 +81,6 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic
@Autowired
private UserMapper userMapper;
@Autowired
private ResourcePermissionCheckService resourcePermissionCheckService;
/**
* create project

54
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java

@ -17,14 +17,15 @@
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 static org.apache.dolphinscheduler.common.Constants.ALIAS;
import static org.apache.dolphinscheduler.common.Constants.CONTENT;
import static org.apache.dolphinscheduler.common.Constants.EMPTY_STRING;
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;
import static org.apache.dolphinscheduler.common.Constants.PERIOD;
import org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant;
import org.apache.dolphinscheduler.api.dto.resources.ResourceComponent;
import org.apache.dolphinscheduler.api.dto.resources.filter.ResourceFilter;
@ -56,15 +57,11 @@ 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.api.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 org.apache.commons.beanutils.BeanMap;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import java.io.IOException;
import java.rmi.ServerException;
@ -83,14 +80,19 @@ 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.EMPTY_STRING;
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;
import static org.apache.dolphinscheduler.common.Constants.PERIOD;
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 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;
/**
* resources service impl
@ -121,8 +123,6 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe
@Autowired(required = false)
private StorageOperate storageOperate;
@Autowired
private ResourcePermissionCheckService resourcePermissionCheckService;
/**
* create directory
@ -364,7 +364,6 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe
return result;
}
Resource resource = resourcesMapper.selectById(resourceId);
if (resource == null) {
putMsg(result, Status.RESOURCE_NOT_EXIST);
@ -1333,7 +1332,6 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe
String resourcePath = storageOperate.getResDir(tenantCode);
logger.info("resource path is {}, resource dir is {}", storageFileName, resourcePath);
if (!storageOperate.exists(tenantCode, resourcePath)) {
// create if tenant dir not exists
storageOperate.createTenantDirIfNotExists(tenantCode);

92
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java

@ -17,11 +17,8 @@
package org.apache.dolphinscheduler.api.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.USER_MANAGER;
import org.apache.dolphinscheduler.api.dto.resources.ResourceComponent;
import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.exceptions.ServiceException;
@ -59,28 +56,34 @@ import org.apache.dolphinscheduler.dao.mapper.TenantMapper;
import org.apache.dolphinscheduler.dao.mapper.UDFUserMapper;
import org.apache.dolphinscheduler.dao.mapper.UserMapper;
import org.apache.dolphinscheduler.dao.utils.ResourceProcessDefinitionUtils;
import org.apache.dolphinscheduler.api.permission.ResourcePermissionCheckService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
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.TimeZone;
import java.util.Arrays;
import java.util.Objects;
import java.util.stream.Collectors;
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.USER_MANAGER;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
/**
* users service impl
@ -129,8 +132,6 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService {
@Autowired
private K8sNamespaceUserMapper k8sNamespaceUserMapper;
@Autowired
private ResourcePermissionCheckService resourcePermissionCheckService;
/**
* create user, only system admin have permission
@ -185,7 +186,6 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService {
// resource upload startup
if (PropertyUtils.getResUploadStartupState()) {
storageOperate.createTenantDirIfNotExists(tenant.getTenantCode());
//
}
result.put(Constants.DATA_LIST, user);
@ -453,62 +453,6 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService {
user.setState(state);
Date now = new Date();
user.setUpdateTime(now);
//if user switches the tenant, the user's resources need to be copied to the new tenant
// if (user.getTenantId() != tenantId) {
// Tenant oldTenant = tenantMapper.queryById(user.getTenantId());
// //query tenant
// Tenant newTenant = tenantMapper.queryById(tenantId);
// // if hdfs startup
// if (null != newTenant && PropertyUtils.getResUploadStartupState() && oldTenant != null) {
// String newTenantCode = newTenant.getTenantCode();
// String oldResourcePath = storageOperate.getResDir(oldTenant.getTenantCode());
// String oldUdfsPath = storageOperate.getUdfDir(oldTenant.getTenantCode());
//
// try {// if old tenant dir exists
// if (storageOperate.exists(oldTenant.getTenantCode(), oldResourcePath)) {
// String newResourcePath = storageOperate.getResDir(newTenantCode);
// String newUdfsPath = storageOperate.getUdfDir(newTenantCode);
//
// //file resources list
// List<Resource> fileResourcesList = resourceMapper.queryResourceList(
// null, userId, ResourceType.FILE.ordinal());
// if (CollectionUtils.isNotEmpty(fileResourcesList)) {
// ResourceTreeVisitor resourceTreeVisitor = new ResourceTreeVisitor(fileResourcesList);
// ResourceComponent resourceComponent = resourceTreeVisitor.visit();
// copyResourceFiles(oldTenant.getTenantCode(), newTenantCode, resourceComponent, oldResourcePath, newResourcePath);
// }
//
// //udf resources
// List<Resource> udfResourceList = resourceMapper.queryResourceList(
// null, userId, ResourceType.UDF.ordinal());
// if (CollectionUtils.isNotEmpty(udfResourceList)) {
// ResourceTreeVisitor resourceTreeVisitor = new ResourceTreeVisitor(udfResourceList);
// ResourceComponent resourceComponent = resourceTreeVisitor.visit();
// copyResourceFiles(oldTenant.getTenantCode(), newTenantCode, resourceComponent, oldUdfsPath, newUdfsPath);
// }
//
// } else {
// // if old tenant dir not exists , create
// storageOperate.createTenantDirIfNotExists(oldTenant.getTenantCode());
//
// if (!storageOperate.exists(newTenant.getTenantCode(), storageOperate.getDir(null,newTenant.getTenantCode()))) {
// storageOperate.createTenantDirIfNotExists(newTenant.getTenantCode());
// }
// }
// } catch (Exception e) {
// logger.error("create tenant {} failed ,the reason is {}", oldTenant, e.getMessage());
// }
//
//
// try {
// storageOperate.createTenantDirIfNotExists(newTenant.getTenantCode());
// } catch (Exception e) {
// logger.error("create tenant {} failed ,the reason is {}", newTenant, e.getMessage());
// }
// }
// user.setTenantId(tenantId);
// }
user.setTenantId(tenantId);
// updateProcessInstance user
userMapper.updateById(user);
@ -553,7 +497,6 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService {
// delete user
userMapper.queryTenantCodeByUserId(id);
accessTokenMapper.deleteAccessTokenByUserId(id);
userMapper.deleteById(id);
@ -1141,7 +1084,6 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService {
return tenantMapper.queryById(tenantId) != null;
}
/**
* @return if check failed return the field, otherwise return null
*/

Loading…
Cancel
Save