@ -20,7 +20,7 @@ package org.apache.dolphinscheduler.api.service.impl;
import org.apache.dolphinscheduler.api.enums.Status ;
import org.apache.dolphinscheduler.api.enums.Status ;
import org.apache.dolphinscheduler.api.service.WorkerGroupService ;
import org.apache.dolphinscheduler.api.service.WorkerGroupService ;
import org.apache.dolphinscheduler.api.utils.PageInfo ;
import org.apache.dolphinscheduler.api.utils.PageInfo ;
import org.apache.dolphinscheduler.api.utils.RegistryMonitor ;
import org.apache.dolphinscheduler.api.utils.RegistryCenterUtils ;
import org.apache.dolphinscheduler.common.Constants ;
import org.apache.dolphinscheduler.common.Constants ;
import org.apache.dolphinscheduler.common.enums.NodeType ;
import org.apache.dolphinscheduler.common.enums.NodeType ;
import org.apache.dolphinscheduler.common.utils.CollectionUtils ;
import org.apache.dolphinscheduler.common.utils.CollectionUtils ;
@ -31,7 +31,6 @@ import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.dao.entity.WorkerGroup ;
import org.apache.dolphinscheduler.dao.entity.WorkerGroup ;
import org.apache.dolphinscheduler.dao.mapper.ProcessInstanceMapper ;
import org.apache.dolphinscheduler.dao.mapper.ProcessInstanceMapper ;
import org.apache.dolphinscheduler.dao.mapper.WorkerGroupMapper ;
import org.apache.dolphinscheduler.dao.mapper.WorkerGroupMapper ;
import org.apache.dolphinscheduler.service.registry.RegistryClient ;
import java.util.ArrayList ;
import java.util.ArrayList ;
import java.util.Date ;
import java.util.Date ;
@ -40,8 +39,6 @@ import java.util.List;
import java.util.Map ;
import java.util.Map ;
import java.util.stream.Collectors ;
import java.util.stream.Collectors ;
import javax.annotation.Resource ;
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 ;
@ -61,16 +58,9 @@ public class WorkerGroupServiceImpl extends BaseServiceImpl implements WorkerGro
@Autowired
@Autowired
WorkerGroupMapper workerGroupMapper ;
WorkerGroupMapper workerGroupMapper ;
@Autowired
private RegistryMonitor registryMonitor ;
@Autowired
@Autowired
ProcessInstanceMapper processInstanceMapper ;
ProcessInstanceMapper processInstanceMapper ;
@Resource
RegistryClient registryClient ;
/ * *
/ * *
* create or update a worker group
* create or update a worker group
*
*
@ -147,7 +137,7 @@ public class WorkerGroupServiceImpl extends BaseServiceImpl implements WorkerGro
}
}
// check zookeeper
// check zookeeper
String workerGroupPath = Constants . REGISTRY_DOLPHINSCHEDULER_WORKERS + Constants . SLASH + workerGroup . getName ( ) ;
String workerGroupPath = Constants . REGISTRY_DOLPHINSCHEDULER_WORKERS + Constants . SLASH + workerGroup . getName ( ) ;
return registryClient . isExisted ( workerGroupPath ) ;
return RegistryCenterUtils . isNode Existed ( workerGroupPath ) ;
}
}
/ * *
/ * *
@ -157,7 +147,7 @@ public class WorkerGroupServiceImpl extends BaseServiceImpl implements WorkerGro
* @return boolean
* @return boolean
* /
* /
private String checkWorkerGroupAddrList ( WorkerGroup workerGroup ) {
private String checkWorkerGroupAddrList ( WorkerGroup workerGroup ) {
Map < String , String > serverMaps = registryMonitor . getServerMaps ( NodeType . WORKER , true ) ;
Map < String , String > serverMaps = RegistryCenterUtils . getServerMaps ( NodeType . WORKER , true ) ;
if ( Strings . isNullOrEmpty ( workerGroup . getAddrList ( ) ) ) {
if ( Strings . isNullOrEmpty ( workerGroup . getAddrList ( ) ) ) {
return null ;
return null ;
}
}
@ -258,7 +248,7 @@ public class WorkerGroupServiceImpl extends BaseServiceImpl implements WorkerGro
String workerPath = Constants . REGISTRY_DOLPHINSCHEDULER_WORKERS ;
String workerPath = Constants . REGISTRY_DOLPHINSCHEDULER_WORKERS ;
List < String > workerGroupList = null ;
List < String > workerGroupList = null ;
try {
try {
workerGroupList = registryClient . getChildrenKey s( workerPath ) ;
workerGroupList = RegistryCenterUtils . getChildrenNode s( workerPath ) ;
} catch ( Exception e ) {
} catch ( Exception e ) {
logger . error ( "getWorkerGroups exception: {}, workerPath: {}, isPaging: {}" , e . getMessage ( ) , workerPath , isPaging ) ;
logger . error ( "getWorkerGroups exception: {}, workerPath: {}, isPaging: {}" , e . getMessage ( ) , workerPath , isPaging ) ;
}
}
@ -276,7 +266,7 @@ public class WorkerGroupServiceImpl extends BaseServiceImpl implements WorkerGro
String workerGroupPath = workerPath + Constants . SLASH + workerGroup ;
String workerGroupPath = workerPath + Constants . SLASH + workerGroup ;
List < String > childrenNodes = null ;
List < String > childrenNodes = null ;
try {
try {
childrenNodes = registryClient . getChildrenKey s( workerGroupPath ) ;
childrenNodes = RegistryCenterUtils . getChildrenNode s( workerGroupPath ) ;
} catch ( Exception e ) {
} catch ( Exception e ) {
logger . error ( "getChildrenNodes exception: {}, workerGroupPath: {}" , e . getMessage ( ) , workerGroupPath ) ;
logger . error ( "getChildrenNodes exception: {}, workerGroupPath: {}" , e . getMessage ( ) , workerGroupPath ) ;
}
}
@ -287,7 +277,7 @@ public class WorkerGroupServiceImpl extends BaseServiceImpl implements WorkerGro
wg . setName ( workerGroup ) ;
wg . setName ( workerGroup ) ;
if ( isPaging ) {
if ( isPaging ) {
wg . setAddrList ( String . join ( Constants . COMMA , childrenNodes ) ) ;
wg . setAddrList ( String . join ( Constants . COMMA , childrenNodes ) ) ;
String registeredValue = registryClient . get ( workerGroupPath + Constants . SLASH + childrenNodes . get ( 0 ) ) ;
String registeredValue = RegistryCenterUtils . getNodeData ( workerGroupPath + Constants . SLASH + childrenNodes . get ( 0 ) ) ;
wg . setCreateTime ( DateUtils . stringToDate ( registeredValue . split ( Constants . COMMA ) [ 6 ] ) ) ;
wg . setCreateTime ( DateUtils . stringToDate ( registeredValue . split ( Constants . COMMA ) [ 6 ] ) ) ;
wg . setUpdateTime ( DateUtils . stringToDate ( registeredValue . split ( Constants . COMMA ) [ 7 ] ) ) ;
wg . setUpdateTime ( DateUtils . stringToDate ( registeredValue . split ( Constants . COMMA ) [ 7 ] ) ) ;
wg . setSystemDefault ( true ) ;
wg . setSystemDefault ( true ) ;
@ -334,7 +324,7 @@ public class WorkerGroupServiceImpl extends BaseServiceImpl implements WorkerGro
@Override
@Override
public Map < String , Object > getWorkerAddressList ( ) {
public Map < String , Object > getWorkerAddressList ( ) {
Map < String , Object > result = new HashMap < > ( ) ;
Map < String , Object > result = new HashMap < > ( ) ;
List < String > serverNodeList = registryMonitor . getServerNodeList ( NodeType . WORKER , true ) ;
List < String > serverNodeList = RegistryCenterUtils . getServerNodeList ( NodeType . WORKER , true ) ;
result . put ( Constants . DATA_LIST , serverNodeList ) ;
result . put ( Constants . DATA_LIST , serverNodeList ) ;
putMsg ( result , Status . SUCCESS ) ;
putMsg ( result , Status . SUCCESS ) ;
return result ;
return result ;