@ -14,10 +14,12 @@
* See the License for the specific language governing permissions and
* See the License for the specific language governing permissions and
* limitations under the License .
* limitations under the License .
* /
* /
package org.apache.dolphinscheduler.api.service ;
package org.apache.dolphinscheduler.api.service ;
import com.baomidou.mybatisplus.core.metadata.IPage ;
import com.baomidou.mybatisplus.core.metadata.IPage ;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page ;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page ;
import org.apache.dolphinscheduler.api.dto.resources.ResourceComponent ;
import org.apache.dolphinscheduler.api.dto.resources.ResourceComponent ;
import org.apache.dolphinscheduler.api.dto.resources.visitor.ResourceTreeVisitor ;
import org.apache.dolphinscheduler.api.dto.resources.visitor.ResourceTreeVisitor ;
import org.apache.dolphinscheduler.api.enums.Status ;
import org.apache.dolphinscheduler.api.enums.Status ;
@ -33,6 +35,7 @@ import org.apache.dolphinscheduler.common.utils.*;
import org.apache.dolphinscheduler.dao.entity.* ;
import org.apache.dolphinscheduler.dao.entity.* ;
import org.apache.dolphinscheduler.dao.mapper.* ;
import org.apache.dolphinscheduler.dao.mapper.* ;
import org.apache.dolphinscheduler.dao.utils.ResourceProcessDefinitionUtils ;
import org.apache.dolphinscheduler.dao.utils.ResourceProcessDefinitionUtils ;
import org.slf4j.Logger ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
import org.slf4j.LoggerFactory ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Autowired ;
@ -109,7 +112,7 @@ public class UsersService extends BaseService {
String msg = this . checkUserParams ( userName , userPassword , email , phone ) ;
String msg = this . checkUserParams ( userName , userPassword , email , phone ) ;
if ( ! StringUtils . isEmpty ( msg ) ) {
if ( ! StringUtils . isEmpty ( msg ) ) {
putMsg ( result , Status . REQUEST_PARAMS_NOT_VALID_ERROR , msg ) ;
putMsg ( result , Status . REQUEST_PARAMS_NOT_VALID_ERROR , msg ) ;
return result ;
return result ;
}
}
if ( ! isAdmin ( loginUser ) ) {
if ( ! isAdmin ( loginUser ) ) {
@ -126,12 +129,12 @@ public class UsersService extends BaseService {
Tenant tenant = tenantMapper . queryById ( tenantId ) ;
Tenant tenant = tenantMapper . queryById ( tenantId ) ;
// resource upload startup
// resource upload startup
if ( PropertyUtils . getResUploadStartupState ( ) ) {
if ( PropertyUtils . getResUploadStartupState ( ) ) {
// if tenant not exists
// if tenant not exists
if ( ! HadoopUtils . getInstance ( ) . exists ( HadoopUtils . getHdfsTenantDir ( tenant . getTenantCode ( ) ) ) ) {
if ( ! HadoopUtils . getInstance ( ) . exists ( HadoopUtils . getHdfsTenantDir ( tenant . getTenantCode ( ) ) ) ) {
createTenantDirIfNotExists ( tenant . getTenantCode ( ) ) ;
createTenantDirIfNotExists ( tenant . getTenantCode ( ) ) ;
}
}
String userPath = HadoopUtils . getHdfsUserDir ( tenant . getTenantCode ( ) , user . getId ( ) ) ;
String userPath = HadoopUtils . getHdfsUserDir ( tenant . getTenantCode ( ) , user . getId ( ) ) ;
HadoopUtils . getInstance ( ) . mkdir ( userPath ) ;
HadoopUtils . getInstance ( ) . mkdir ( userPath ) ;
}
}
@ -161,7 +164,7 @@ public class UsersService extends BaseService {
user . setUserType ( UserType . GENERAL_USER ) ;
user . setUserType ( UserType . GENERAL_USER ) ;
user . setCreateTime ( now ) ;
user . setCreateTime ( now ) ;
user . setUpdateTime ( now ) ;
user . setUpdateTime ( now ) ;
if ( StringUtils . isEmpty ( queue ) ) {
if ( StringUtils . isEmpty ( queue ) ) {
queue = "" ;
queue = "" ;
}
}
user . setQueue ( queue ) ;
user . setQueue ( queue ) ;
@ -173,6 +176,7 @@ public class UsersService extends BaseService {
/ * *
/ * *
* query user by id
* query user by id
*
* @param id id
* @param id id
* @return user info
* @return user info
* /
* /
@ -182,6 +186,7 @@ public class UsersService extends BaseService {
/ * *
/ * *
* query user
* query user
*
* @param name name
* @param name name
* @return user info
* @return user info
* /
* /
@ -203,6 +208,7 @@ public class UsersService extends BaseService {
/ * *
/ * *
* get user id by user name
* get user id by user name
*
* @param name user name
* @param name user name
* @return if name empty 0 , user not exists - 1 , user exist user id
* @return if name empty 0 , user not exists - 1 , user exist user id
* /
* /
@ -242,7 +248,7 @@ public class UsersService extends BaseService {
IPage < User > scheduleList = userMapper . queryUserPaging ( page , searchVal ) ;
IPage < User > scheduleList = userMapper . queryUserPaging ( page , searchVal ) ;
PageInfo < User > pageInfo = new PageInfo < > ( pageNo , pageSize ) ;
PageInfo < User > pageInfo = new PageInfo < > ( pageNo , pageSize ) ;
pageInfo . setTotalCount ( ( int ) scheduleList . getTotal ( ) ) ;
pageInfo . setTotalCount ( ( int ) scheduleList . getTotal ( ) ) ;
pageInfo . setLists ( scheduleList . getRecords ( ) ) ;
pageInfo . setLists ( scheduleList . getRecords ( ) ) ;
result . put ( Constants . DATA_LIST , pageInfo ) ;
result . put ( Constants . DATA_LIST , pageInfo ) ;
putMsg ( result , Status . SUCCESS ) ;
putMsg ( result , Status . SUCCESS ) ;
@ -283,8 +289,8 @@ public class UsersService extends BaseService {
if ( StringUtils . isNotEmpty ( userName ) ) {
if ( StringUtils . isNotEmpty ( userName ) ) {
if ( ! CheckUtils . checkUserName ( userName ) ) {
if ( ! CheckUtils . checkUserName ( userName ) ) {
putMsg ( result , Status . REQUEST_PARAMS_NOT_VALID_ERROR , userName ) ;
putMsg ( result , Status . REQUEST_PARAMS_NOT_VALID_ERROR , userName ) ;
return result ;
return result ;
}
}
@ -297,23 +303,23 @@ public class UsersService extends BaseService {
}
}
if ( StringUtils . isNotEmpty ( userPassword ) ) {
if ( StringUtils . isNotEmpty ( userPassword ) ) {
if ( ! CheckUtils . checkPassword ( userPassword ) ) {
if ( ! CheckUtils . checkPassword ( userPassword ) ) {
putMsg ( result , Status . REQUEST_PARAMS_NOT_VALID_ERROR , userPassword ) ;
putMsg ( result , Status . REQUEST_PARAMS_NOT_VALID_ERROR , userPassword ) ;
return result ;
return result ;
}
}
user . setUserPassword ( EncryptionUtils . getMd5 ( userPassword ) ) ;
user . setUserPassword ( EncryptionUtils . getMd5 ( userPassword ) ) ;
}
}
if ( StringUtils . isNotEmpty ( email ) ) {
if ( StringUtils . isNotEmpty ( email ) ) {
if ( ! CheckUtils . checkEmail ( email ) ) {
if ( ! CheckUtils . checkEmail ( email ) ) {
putMsg ( result , Status . REQUEST_PARAMS_NOT_VALID_ERROR , email ) ;
putMsg ( result , Status . REQUEST_PARAMS_NOT_VALID_ERROR , email ) ;
return result ;
return result ;
}
}
user . setEmail ( email ) ;
user . setEmail ( email ) ;
}
}
if ( StringUtils . isNotEmpty ( phone ) & & ! CheckUtils . checkPhone ( phone ) ) {
if ( StringUtils . isNotEmpty ( phone ) & & ! CheckUtils . checkPhone ( phone ) ) {
putMsg ( result , Status . REQUEST_PARAMS_NOT_VALID_ERROR , phone ) ;
putMsg ( result , Status . REQUEST_PARAMS_NOT_VALID_ERROR , phone ) ;
return result ;
return result ;
}
}
user . setPhone ( phone ) ;
user . setPhone ( phone ) ;
@ -329,13 +335,13 @@ public class UsersService extends BaseService {
Tenant newTenant = tenantMapper . queryById ( tenantId ) ;
Tenant newTenant = tenantMapper . queryById ( tenantId ) ;
if ( newTenant ! = null ) {
if ( newTenant ! = null ) {
// if hdfs startup
// if hdfs startup
if ( PropertyUtils . getResUploadStartupState ( ) & & oldTenant ! = null ) {
if ( PropertyUtils . getResUploadStartupState ( ) & & oldTenant ! = null ) {
String newTenantCode = newTenant . getTenantCode ( ) ;
String newTenantCode = newTenant . getTenantCode ( ) ;
String oldResourcePath = HadoopUtils . getHdfsResDir ( oldTenant . getTenantCode ( ) ) ;
String oldResourcePath = HadoopUtils . getHdfsResDir ( oldTenant . getTenantCode ( ) ) ;
String oldUdfsPath = HadoopUtils . getHdfsUdfDir ( oldTenant . getTenantCode ( ) ) ;
String oldUdfsPath = HadoopUtils . getHdfsUdfDir ( oldTenant . getTenantCode ( ) ) ;
// if old tenant dir exists
// if old tenant dir exists
if ( HadoopUtils . getInstance ( ) . exists ( oldResourcePath ) ) {
if ( HadoopUtils . getInstance ( ) . exists ( oldResourcePath ) ) {
String newResourcePath = HadoopUtils . getHdfsResDir ( newTenantCode ) ;
String newResourcePath = HadoopUtils . getHdfsResDir ( newTenantCode ) ;
String newUdfsPath = HadoopUtils . getHdfsUdfDir ( newTenantCode ) ;
String newUdfsPath = HadoopUtils . getHdfsUdfDir ( newTenantCode ) ;
@ -358,18 +364,18 @@ public class UsersService extends BaseService {
}
}
//Delete the user from the old tenant directory
//Delete the user from the old tenant directory
String oldUserPath = HadoopUtils . getHdfsUserDir ( oldTenant . getTenantCode ( ) , userId ) ;
String oldUserPath = HadoopUtils . getHdfsUserDir ( oldTenant . getTenantCode ( ) , userId ) ;
HadoopUtils . getInstance ( ) . delete ( oldUserPath , true ) ;
HadoopUtils . getInstance ( ) . delete ( oldUserPath , true ) ;
} else {
} else {
// if old tenant dir not exists , create
// if old tenant dir not exists , create
createTenantDirIfNotExists ( oldTenant . getTenantCode ( ) ) ;
createTenantDirIfNotExists ( oldTenant . getTenantCode ( ) ) ;
}
}
if ( HadoopUtils . getInstance ( ) . exists ( HadoopUtils . getHdfsTenantDir ( newTenant . getTenantCode ( ) ) ) ) {
if ( HadoopUtils . getInstance ( ) . exists ( HadoopUtils . getHdfsTenantDir ( newTenant . getTenantCode ( ) ) ) ) {
//create user in the new tenant directory
//create user in the new tenant directory
String newUserPath = HadoopUtils . getHdfsUserDir ( newTenant . getTenantCode ( ) , user . getId ( ) ) ;
String newUserPath = HadoopUtils . getHdfsUserDir ( newTenant . getTenantCode ( ) , user . getId ( ) ) ;
HadoopUtils . getInstance ( ) . mkdir ( newUserPath ) ;
HadoopUtils . getInstance ( ) . mkdir ( newUserPath ) ;
} else {
} else {
// if new tenant dir not exists , create
// if new tenant dir not exists , create
createTenantDirIfNotExists ( newTenant . getTenantCode ( ) ) ;
createTenantDirIfNotExists ( newTenant . getTenantCode ( ) ) ;
}
}
@ -411,7 +417,7 @@ public class UsersService extends BaseService {
if ( user ! = null ) {
if ( user ! = null ) {
if ( PropertyUtils . getResUploadStartupState ( ) ) {
if ( PropertyUtils . getResUploadStartupState ( ) ) {
String userPath = HadoopUtils . getHdfsUserDir ( user . getTenantCode ( ) , id ) ;
String userPath = HadoopUtils . getHdfsUserDir ( user . getTenantCode ( ) , id ) ;
if ( HadoopUtils . getInstance ( ) . exists ( userPath ) ) {
if ( HadoopUtils . getInstance ( ) . exists ( userPath ) ) {
HadoopUtils . getInstance ( ) . delete ( userPath , true ) ;
HadoopUtils . getInstance ( ) . delete ( userPath , true ) ;
}
}
@ -490,7 +496,7 @@ public class UsersService extends BaseService {
return result ;
return result ;
}
}
User user = userMapper . selectById ( userId ) ;
User user = userMapper . selectById ( userId ) ;
if ( user = = null ) {
if ( user = = null ) {
putMsg ( result , Status . USER_NOT_EXIST , userId ) ;
putMsg ( result , Status . USER_NOT_EXIST , userId ) ;
return result ;
return result ;
}
}
@ -501,7 +507,7 @@ public class UsersService extends BaseService {
// need authorize resource id set
// need authorize resource id set
for ( String resourceFullId : resourceFullIdArr ) {
for ( String resourceFullId : resourceFullIdArr ) {
String [ ] resourceIdArr = resourceFullId . split ( "-" ) ;
String [ ] resourceIdArr = resourceFullId . split ( "-" ) ;
for ( int i = 0 ; i < = resourceIdArr . length - 1 ; i + + ) {
for ( int i = 0 ; i < = resourceIdArr . length - 1 ; i + + ) {
int resourceIdValue = Integer . parseInt ( resourceIdArr [ i ] ) ;
int resourceIdValue = Integer . parseInt ( resourceIdArr [ i ] ) ;
needAuthorizeResIds . add ( resourceIdValue ) ;
needAuthorizeResIds . add ( resourceIdValue ) ;
}
}
@ -528,7 +534,7 @@ public class UsersService extends BaseService {
if ( CollectionUtils . isNotEmpty ( resourceIdSet ) ) {
if ( CollectionUtils . isNotEmpty ( resourceIdSet ) ) {
logger . error ( "can't be deleted,because it is used of process definition" ) ;
logger . error ( "can't be deleted,because it is used of process definition" ) ;
for ( Integer resId : resourceIdSet ) {
for ( Integer resId : resourceIdSet ) {
logger . error ( "resource id:{} is used of process definition {}" , resId , resourceProcessMap . get ( resId ) ) ;
logger . error ( "resource id:{} is used of process definition {}" , resId , resourceProcessMap . get ( resId ) ) ;
}
}
putMsg ( result , Status . RESOURCE_IS_USED ) ;
putMsg ( result , Status . RESOURCE_IS_USED ) ;
return result ;
return result ;
@ -555,7 +561,7 @@ public class UsersService extends BaseService {
resourcesUser . setResourcesId ( resourceIdValue ) ;
resourcesUser . setResourcesId ( resourceIdValue ) ;
if ( resource . isDirectory ( ) ) {
if ( resource . isDirectory ( ) ) {
resourcesUser . setPerm ( Constants . AUTHORIZE_READABLE_PERM ) ;
resourcesUser . setPerm ( Constants . AUTHORIZE_READABLE_PERM ) ;
} else {
} else {
resourcesUser . setPerm ( Constants . AUTHORIZE_WRITABLE_PERM ) ;
resourcesUser . setPerm ( Constants . AUTHORIZE_WRITABLE_PERM ) ;
}
}
@ -588,7 +594,7 @@ public class UsersService extends BaseService {
return result ;
return result ;
}
}
User user = userMapper . selectById ( userId ) ;
User user = userMapper . selectById ( userId ) ;
if ( user = = null ) {
if ( user = = null ) {
putMsg ( result , Status . USER_NOT_EXIST , userId ) ;
putMsg ( result , Status . USER_NOT_EXIST , userId ) ;
return result ;
return result ;
}
}
@ -636,7 +642,7 @@ public class UsersService extends BaseService {
return result ;
return result ;
}
}
User user = userMapper . selectById ( userId ) ;
User user = userMapper . selectById ( userId ) ;
if ( user = = null ) {
if ( user = = null ) {
putMsg ( result , Status . USER_NOT_EXIST , userId ) ;
putMsg ( result , Status . USER_NOT_EXIST , userId ) ;
return result ;
return result ;
}
}
@ -676,23 +682,11 @@ public class UsersService extends BaseService {
Map < String , Object > result = new HashMap < > ( ) ;
Map < String , Object > result = new HashMap < > ( ) ;
User user = null ;
User user ;
if ( loginUser . getUserType ( ) = = UserType . ADMIN_USER ) {
if ( loginUser . getUserType ( ) = = UserType . ADMIN_USER ) {
user = loginUser ;
user = loginUser ;
} else {
} else {
user = userMapper . queryDetailsById ( loginUser . getId ( ) ) ;
user = userMapper . queryDetailsById ( loginUser . getId ( ) ) ;
List < AlertGroup > alertGroups = alertGroupMapper . queryByUserId ( loginUser . getId ( ) ) ;
StringBuilder sb = new StringBuilder ( ) ;
if ( alertGroups ! = null & & alertGroups . size ( ) > 0 ) {
for ( int i = 0 ; i < alertGroups . size ( ) - 1 ; i + + ) {
sb . append ( alertGroups . get ( i ) . getGroupName ( ) + "," ) ;
}
sb . append ( alertGroups . get ( alertGroups . size ( ) - 1 ) ) ;
user . setAlertGroup ( sb . toString ( ) ) ;
}
}
}
result . put ( Constants . DATA_LIST , user ) ;
result . put ( Constants . DATA_LIST , user ) ;
@ -735,7 +729,7 @@ public class UsersService extends BaseService {
return result ;
return result ;
}
}
List < User > userList = userMapper . selectList ( null ) ;
List < User > userList = userMapper . selectList ( null ) ;
result . put ( Constants . DATA_LIST , userList ) ;
result . put ( Constants . DATA_LIST , userList ) ;
putMsg ( result , Status . SUCCESS ) ;
putMsg ( result , Status . SUCCESS ) ;
@ -779,7 +773,7 @@ public class UsersService extends BaseService {
return result ;
return result ;
}
}
List < User > userList = userMapper . selectList ( null ) ;
List < User > userList = userMapper . selectList ( null ) ;
List < User > resultUsers = new ArrayList < > ( ) ;
List < User > resultUsers = new ArrayList < > ( ) ;
Set < User > userSet = null ;
Set < User > userSet = null ;
if ( userList ! = null & & userList . size ( ) > 0 ) {
if ( userList ! = null & & userList . size ( ) > 0 ) {
@ -848,7 +842,6 @@ public class UsersService extends BaseService {
}
}
/ * *
/ * *
*
* @param userName
* @param userName
* @param password
* @param password
* @param email
* @param email
@ -877,6 +870,7 @@ public class UsersService extends BaseService {
/ * *
/ * *
* copy resource files
* copy resource files
*
* @param resourceComponent resource component
* @param resourceComponent resource component
* @param srcBasePath src base path
* @param srcBasePath src base path
* @param dstBasePath dst base path
* @param dstBasePath dst base path
@ -886,26 +880,26 @@ public class UsersService extends BaseService {
List < ResourceComponent > components = resourceComponent . getChildren ( ) ;
List < ResourceComponent > components = resourceComponent . getChildren ( ) ;
if ( CollectionUtils . isNotEmpty ( components ) ) {
if ( CollectionUtils . isNotEmpty ( components ) ) {
for ( ResourceComponent component : components ) {
for ( ResourceComponent component : components ) {
// verify whether exist
// verify whether exist
if ( ! HadoopUtils . getInstance ( ) . exists ( String . format ( "%s/%s" , srcBasePath , component . getFullName ( ) ) ) ) {
if ( ! HadoopUtils . getInstance ( ) . exists ( String . format ( "%s/%s" , srcBasePath , component . getFullName ( ) ) ) ) {
logger . error ( "resource file: {} not exist,copy error" , component . getFullName ( ) ) ;
logger . error ( "resource file: {} not exist,copy error" , component . getFullName ( ) ) ;
throw new ServiceException ( Status . RESOURCE_NOT_EXIST ) ;
throw new ServiceException ( Status . RESOURCE_NOT_EXIST ) ;
}
}
if ( ! component . isDirctory ( ) ) {
if ( ! component . isDirctory ( ) ) {
// copy it to dst
// copy it to dst
HadoopUtils . getInstance ( ) . copy ( String . format ( "%s/%s" , srcBasePath , component . getFullName ( ) ) , String . format ( "%s/%s" , dstBasePath , component . getFullName ( ) ) , false , true ) ;
HadoopUtils . getInstance ( ) . copy ( String . format ( "%s/%s" , srcBasePath , component . getFullName ( ) ) , String . format ( "%s/%s" , dstBasePath , component . getFullName ( ) ) , false , true ) ;
continue ;
continue ;
}
}
if ( CollectionUtils . isEmpty ( component . getChildren ( ) ) ) {
if ( CollectionUtils . isEmpty ( component . getChildren ( ) ) ) {
// if not exist,need create it
// if not exist,need create it
if ( ! HadoopUtils . getInstance ( ) . exists ( String . format ( "%s/%s" , dstBasePath , component . getFullName ( ) ) ) ) {
if ( ! HadoopUtils . getInstance ( ) . exists ( String . format ( "%s/%s" , dstBasePath , component . getFullName ( ) ) ) ) {
HadoopUtils . getInstance ( ) . mkdir ( String . format ( "%s/%s" , dstBasePath , component . getFullName ( ) ) ) ;
HadoopUtils . getInstance ( ) . mkdir ( String . format ( "%s/%s" , dstBasePath , component . getFullName ( ) ) ) ;
}
}
} else {
} else {
copyResourceFiles ( component , srcBasePath , dstBasePath ) ;
copyResourceFiles ( component , srcBasePath , dstBasePath ) ;
}
}
}
}
}
}
@ -929,7 +923,7 @@ public class UsersService extends BaseService {
String msg = this . checkUserParams ( userName , userPassword , email , "" ) ;
String msg = this . checkUserParams ( userName , userPassword , email , "" ) ;
if ( ! StringUtils . isEmpty ( msg ) ) {
if ( ! StringUtils . isEmpty ( msg ) ) {
putMsg ( result , Status . REQUEST_PARAMS_NOT_VALID_ERROR , msg ) ;
putMsg ( result , Status . REQUEST_PARAMS_NOT_VALID_ERROR , msg ) ;
return result ;
return result ;
}
}
@ -959,7 +953,7 @@ public class UsersService extends BaseService {
return result ;
return result ;
}
}
if ( ! CheckUtils . checkUserName ( userName ) ) {
if ( ! CheckUtils . checkUserName ( userName ) ) {
putMsg ( result , Status . REQUEST_PARAMS_NOT_VALID_ERROR , userName ) ;
putMsg ( result , Status . REQUEST_PARAMS_NOT_VALID_ERROR , userName ) ;
return result ;
return result ;
}
}