Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mackdk committed Oct 28, 2024
1 parent 25215a4 commit 846b443
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
import org.hibernate.Hibernate;
import org.hibernate.query.Query;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
Expand All @@ -39,7 +39,7 @@
*/
public class HubReportDbUpdateDriver extends AbstractQueueDriver<MgrServerInfo> {

private static Set<MgrServerInfo> currentMgrServerInfos = Collections.synchronizedSet(new HashSet<>());
private static final Set<MgrServerInfo> CURRENT_MGR_SERVER_INFOS = Collections.synchronizedSet(new HashSet<>());
private Logger log;

@Override
Expand All @@ -53,7 +53,7 @@ public Logger getLogger() {
}

public static Set<MgrServerInfo> getCurrentMgrServerInfos() {
return currentMgrServerInfos;
return CURRENT_MGR_SERVER_INFOS;
}

/**
Expand All @@ -70,18 +70,18 @@ public Set<MgrServerInfo> getMgrServers() {
}

@Override
public List<MgrServerInfo> getCandidates() {
synchronized (currentMgrServerInfos) {
protected List<MgrServerInfo> getCandidates() {
synchronized (CURRENT_MGR_SERVER_INFOS) {
Set<MgrServerInfo> candidates = getMgrServers();
// Do not return candidates we are talking to already
for (MgrServerInfo s : currentMgrServerInfos) {
for (MgrServerInfo s : CURRENT_MGR_SERVER_INFOS) {
if (candidates.contains(s)) {
log.debug("Skipping system: {}", s.getServer().getName());
candidates.remove(s);
}
}
candidates.forEach(e -> Hibernate.initialize(e.getReportDbCredentials()));
return candidates.stream().collect(Collectors.toList());
return new ArrayList<>(candidates);
}
}

Expand All @@ -92,7 +92,7 @@ public int getMaxWorkers() {
}

@Override
public QueueWorker makeWorker(MgrServerInfo workItem) {
protected QueueWorker makeWorker(MgrServerInfo workItem) {
return new HubReportDbUpdateWorker(log, workItem);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public int getMaxWorkers() {
}

@Override
public QueueWorker makeWorker(Task task) {
protected QueueWorker makeWorker(Task task) {
return new ErrataCacheWorker(task, logger);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class ErrataQueueDriver extends AbstractQueueDriver<Map<String, Long>> {
private Logger logger = null;

@Override
public List<Map<String, Long>> getCandidates() {
protected List<Map<String, Long>> getCandidates() {
SelectMode select = ModeFactory.getMode(TaskConstants.MODE_NAME,
TaskConstants.TASK_QUERY_ERRATA_QUEUE_FIND_CANDIDATES);
try {
Expand All @@ -62,7 +62,7 @@ public int getMaxWorkers() {
}

@Override
public QueueWorker makeWorker(Map<String, Long> workItem) {
protected QueueWorker makeWorker(Map<String, Long> workItem) {
return new ErrataQueueWorker(workItem, logger);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void initialize() {
}

@Override
public List<Map<String, Object>> getCandidates() {
protected List<Map<String, Object>> getCandidates() {
SelectMode select = ModeFactory.getMode(TaskConstants.MODE_NAME,
TaskConstants.TASK_QUERY_REPOMD_DRIVER_QUERY);

Expand Down Expand Up @@ -87,7 +87,7 @@ public int getMaxWorkers() {
}

@Override
public QueueWorker makeWorker(Map<String, Object> workItem) {
protected QueueWorker makeWorker(Map<String, Object> workItem) {
return new ChannelRepodataWorker(workItem, getLogger());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void initialize() {
}

@Override
public List<SystemSummary> getCandidates() {
protected List<SystemSummary> getCandidates() {
List<SystemSummary> candidates = new LinkedList<>();

// Find Salt systems currently rebooting,
Expand Down Expand Up @@ -150,7 +150,7 @@ public List<SystemSummary> getCandidates() {
}

@Override
public QueueWorker makeWorker(SystemSummary system) {
protected QueueWorker makeWorker(SystemSummary system) {
return new SSHServiceWorker(getLogger(), system,
GlobalInstanceHolder.SALT_API,
GlobalInstanceHolder.SALT_API.getSaltSSHService(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Logger getLogger() {
}

@Override
public List<Long> getCandidates() {
protected List<Long> getCandidates() {
// Candidates are system IDs, deduplicated to avoid useless updates
return TaskFactory.getTaskListByNameLike(TASK_NAME).stream()
.map(task -> task.getData())
Expand All @@ -57,7 +57,7 @@ public int getMaxWorkers() {
}

@Override
public QueueWorker makeWorker(Long sid) {
protected QueueWorker makeWorker(Long sid) {
return new SystemsOverviewUpdateWorker(sid, logger);
}
}

0 comments on commit 846b443

Please sign in to comment.