|
|
|
@ -25,9 +25,13 @@ import org.apache.dolphinscheduler.common.utils.StringUtils;
|
|
|
|
|
import org.apache.dolphinscheduler.remote.utils.Constants; |
|
|
|
|
import org.apache.dolphinscheduler.remote.utils.NamedThreadFactory; |
|
|
|
|
import org.apache.dolphinscheduler.server.registry.ZookeeperRegistryCenter; |
|
|
|
|
import org.apache.dolphinscheduler.server.worker.config.WorkerConfig; |
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import javax.annotation.PostConstruct; |
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.concurrent.Executors; |
|
|
|
|
import java.util.concurrent.ScheduledExecutorService; |
|
|
|
@ -41,6 +45,7 @@ import static org.apache.dolphinscheduler.common.Constants.SLASH;
|
|
|
|
|
/** |
|
|
|
|
* worker registry |
|
|
|
|
*/ |
|
|
|
|
@Service |
|
|
|
|
public class WorkerRegistry { |
|
|
|
|
|
|
|
|
|
private final Logger logger = LoggerFactory.getLogger(WorkerRegistry.class); |
|
|
|
@ -48,54 +53,31 @@ public class WorkerRegistry {
|
|
|
|
|
/** |
|
|
|
|
* zookeeper registry center |
|
|
|
|
*/ |
|
|
|
|
private final ZookeeperRegistryCenter zookeeperRegistryCenter; |
|
|
|
|
@Autowired |
|
|
|
|
private ZookeeperRegistryCenter zookeeperRegistryCenter; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* port |
|
|
|
|
* worker config |
|
|
|
|
*/ |
|
|
|
|
private final int port; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* heartbeat interval |
|
|
|
|
*/ |
|
|
|
|
private final long heartBeatInterval; |
|
|
|
|
@Autowired |
|
|
|
|
private WorkerConfig workerConfig; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* heartbeat executor |
|
|
|
|
*/ |
|
|
|
|
private final ScheduledExecutorService heartBeatExecutor; |
|
|
|
|
private ScheduledExecutorService heartBeatExecutor; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* worker start time |
|
|
|
|
*/ |
|
|
|
|
private final String startTime; |
|
|
|
|
private String startTime; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* worker group |
|
|
|
|
*/ |
|
|
|
|
private String workerGroup; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* construct |
|
|
|
|
* |
|
|
|
|
* @param zookeeperRegistryCenter zookeeperRegistryCenter |
|
|
|
|
* @param port port |
|
|
|
|
* @param heartBeatInterval heartBeatInterval |
|
|
|
|
*/ |
|
|
|
|
public WorkerRegistry(ZookeeperRegistryCenter zookeeperRegistryCenter, int port, long heartBeatInterval){ |
|
|
|
|
this(zookeeperRegistryCenter, port, heartBeatInterval, DEFAULT_WORKER_GROUP); |
|
|
|
|
} |
|
|
|
|
private String workerGroup; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* construct |
|
|
|
|
* @param zookeeperRegistryCenter zookeeperRegistryCenter |
|
|
|
|
* @param port port |
|
|
|
|
*/ |
|
|
|
|
public WorkerRegistry(ZookeeperRegistryCenter zookeeperRegistryCenter, int port, long heartBeatInterval, String workerGroup){ |
|
|
|
|
this.zookeeperRegistryCenter = zookeeperRegistryCenter; |
|
|
|
|
this.port = port; |
|
|
|
|
this.heartBeatInterval = heartBeatInterval; |
|
|
|
|
this.workerGroup = workerGroup; |
|
|
|
|
@PostConstruct |
|
|
|
|
public void init(){ |
|
|
|
|
this.workerGroup = workerConfig.getWorkerGroup(); |
|
|
|
|
this.startTime = DateUtils.dateToString(new Date()); |
|
|
|
|
this.heartBeatExecutor = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("HeartBeatExecutor")); |
|
|
|
|
} |
|
|
|
@ -120,8 +102,9 @@ public class WorkerRegistry {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
this.heartBeatExecutor.scheduleAtFixedRate(new HeartBeatTask(), heartBeatInterval, heartBeatInterval, TimeUnit.SECONDS); |
|
|
|
|
logger.info("worker node : {} registry to ZK successfully with heartBeatInterval : {}s", address, heartBeatInterval); |
|
|
|
|
int workerHeartbeatInterval = workerConfig.getWorkerHeartbeatInterval(); |
|
|
|
|
this.heartBeatExecutor.scheduleAtFixedRate(new HeartBeatTask(), workerHeartbeatInterval, workerHeartbeatInterval, TimeUnit.SECONDS); |
|
|
|
|
logger.info("worker node : {} registry to ZK successfully with heartBeatInterval : {}s", address, workerHeartbeatInterval); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -159,7 +142,7 @@ public class WorkerRegistry {
|
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private String getLocalAddress(){ |
|
|
|
|
return Constants.LOCAL_ADDRESS + ":" + port; |
|
|
|
|
return Constants.LOCAL_ADDRESS + ":" + workerConfig.getListenPort(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|