|
@@ -29,6 +29,7 @@ import org.apache.dolphinscheduler.common.utils.CollectionUtils;
|
|
|
import org.apache.dolphinscheduler.common.utils.OSUtils;
|
|
|
import org.apache.dolphinscheduler.dao.AlertDao;
|
|
|
import org.apache.dolphinscheduler.dao.entity.TaskInstance;
|
|
|
+import org.apache.dolphinscheduler.server.master.MasterServer;
|
|
|
import org.apache.dolphinscheduler.server.utils.ProcessUtils;
|
|
|
import org.apache.dolphinscheduler.server.worker.config.WorkerConfig;
|
|
|
import org.apache.dolphinscheduler.server.worker.runner.FetchTaskThread;
|
|
@@ -43,10 +44,13 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.boot.WebApplicationType;
|
|
|
+import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
|
|
import org.springframework.context.annotation.ComponentScan;
|
|
|
+import org.springframework.context.annotation.FilterType;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
+import javax.annotation.PreDestroy;
|
|
|
import java.util.Set;
|
|
|
import java.util.concurrent.CountDownLatch;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
@@ -56,7 +60,10 @@ import java.util.concurrent.TimeUnit;
|
|
|
/**
|
|
|
* worker server
|
|
|
*/
|
|
|
-@ComponentScan("org.apache.dolphinscheduler")
|
|
|
+@SpringBootApplication
|
|
|
+@ComponentScan(value = "org.apache.dolphinscheduler", excludeFilters = {
|
|
|
+ @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {MasterServer.class})
|
|
|
+})
|
|
|
public class WorkerServer implements IStoppable {
|
|
|
|
|
|
/**
|
|
@@ -104,11 +111,6 @@ public class WorkerServer implements IStoppable {
|
|
|
*/
|
|
|
private ExecutorService fetchTaskExecutorService;
|
|
|
|
|
|
- /**
|
|
|
- * CountDownLatch latch
|
|
|
- */
|
|
|
- private CountDownLatch latch;
|
|
|
-
|
|
|
@Value("${server.is-combined-server:false}")
|
|
|
private Boolean isCombinedServer;
|
|
|
|
|
@@ -149,7 +151,7 @@ public class WorkerServer implements IStoppable {
|
|
|
|
|
|
this.fetchTaskExecutorService = ThreadUtils.newDaemonSingleThreadExecutor("Worker-Fetch-Thread-Executor");
|
|
|
|
|
|
- heartbeatWorkerService = ThreadUtils.newDaemonThreadScheduledExecutor("Worker-Heartbeat-Thread-Executor", Constants.DEFAUL_WORKER_HEARTBEAT_THREAD_NUM);
|
|
|
+ heartbeatWorkerService = ThreadUtils.newThreadScheduledExecutor("Worker-Heartbeat-Thread-Executor", Constants.DEFAUL_WORKER_HEARTBEAT_THREAD_NUM, false);
|
|
|
|
|
|
// heartbeat thread implement
|
|
|
Runnable heartBeatThread = heartBeatThread();
|
|
@@ -171,29 +173,15 @@ public class WorkerServer implements IStoppable {
|
|
|
|
|
|
// submit fetch task thread
|
|
|
fetchTaskExecutorService.execute(fetchTaskThread);
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * register hooks, which are called before the process exits
|
|
|
- */
|
|
|
- Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- // worker server exit alert
|
|
|
- if (zkWorkerClient.getActiveMasterNum() <= 1) {
|
|
|
- alertDao.sendServerStopedAlert(1, OSUtils.getHost(), "Worker-Server");
|
|
|
- }
|
|
|
- stop("shutdownhook");
|
|
|
- }
|
|
|
- }));
|
|
|
-
|
|
|
- //let the main thread await
|
|
|
- latch = new CountDownLatch(1);
|
|
|
- if (!isCombinedServer) {
|
|
|
- try {
|
|
|
- latch.await();
|
|
|
- } catch (InterruptedException ignore) {
|
|
|
- }
|
|
|
+ @PreDestroy
|
|
|
+ public void destroy() {
|
|
|
+ // worker server exit alert
|
|
|
+ if (zkWorkerClient.getActiveMasterNum() <= 1) {
|
|
|
+ alertDao.sendServerStopedAlert(1, OSUtils.getHost(), "Worker-Server");
|
|
|
}
|
|
|
+ stop("shutdownhook");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -251,7 +239,6 @@ public class WorkerServer implements IStoppable {
|
|
|
}catch (Exception e){
|
|
|
logger.warn("zookeeper service stopped exception:{}",e.getMessage());
|
|
|
}
|
|
|
- latch.countDown();
|
|
|
logger.info("zookeeper service stopped");
|
|
|
|
|
|
} catch (Exception e) {
|