Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cant detect workgroup #7

Merged
merged 5 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public void start() {
this.registryClient.subscribe(RegistryNodeType.MASTER.getRegistryPath(), masterClusters);
this.registryClient.subscribe(RegistryNodeType.WORKER.getRegistryPath(), workerClusters);
this.workerGroupChangeNotifier.subscribeWorkerGroupsChange(workerClusters);
this.workerGroupChangeNotifier.startScheduleThread();
log.info("ClusterManager started...");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
import org.apache.dolphinscheduler.common.utils.MapComparator;
import org.apache.dolphinscheduler.dao.entity.WorkerGroup;
import org.apache.dolphinscheduler.dao.repository.WorkerGroupDao;
import org.apache.dolphinscheduler.server.master.config.MasterConfig;
import org.apache.dolphinscheduler.server.master.utils.MasterThreadFactory;

import org.apache.commons.collections4.CollectionUtils;

import java.time.Duration;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -35,6 +36,7 @@

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
Expand All @@ -44,7 +46,8 @@
@Component
public class WorkerGroupChangeNotifier {

private static final long DEFAULT_REFRESH_WORKER_INTERVAL = 10;
@Autowired
private MasterConfig masterConfig;

private final WorkerGroupDao workerGroupDao;
private final List<WorkerGroupListener> listeners = new CopyOnWriteArrayList<>();
Expand All @@ -53,17 +56,21 @@ public class WorkerGroupChangeNotifier {

public WorkerGroupChangeNotifier(WorkerGroupDao workerGroupDao) {
this.workerGroupDao = workerGroupDao;
}

public void startScheduleThread() {
detectWorkerGroupChanges();
final long workerGroupRefreshIntervalSeconds = masterConfig.getWorkerGroupRefreshInterval().getSeconds();
MasterThreadFactory.getDefaultSchedulerThreadExecutor().scheduleWithFixedDelay(
this::detectWorkerGroupChanges,
DEFAULT_REFRESH_WORKER_INTERVAL,
DEFAULT_REFRESH_WORKER_INTERVAL,
workerGroupRefreshIntervalSeconds,
workerGroupRefreshIntervalSeconds,
TimeUnit.SECONDS);
}

public void subscribeWorkerGroupsChange(WorkerGroupListener listener) {

//add all group when listener added
// add all group when listener added
listener.onWorkerGroupAdd(new ArrayList<>(workerGroupMap.values()));

listeners.add(listener);
Expand Down
Loading