Skip to content

Commit 14f5b52

Browse files
committed
Test fixes and code compliance changes
1 parent efc3315 commit 14f5b52

File tree

3 files changed

+252
-167
lines changed

3 files changed

+252
-167
lines changed

gateway-ha/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@
207207
<artifactId>jakarta.annotation-api</artifactId>
208208
</dependency>
209209

210+
<dependency>
211+
<groupId>jakarta.inject</groupId>
212+
<artifactId>jakarta.inject-api</artifactId>
213+
</dependency>
214+
210215
<dependency>
211216
<groupId>jakarta.servlet</groupId>
212217
<artifactId>jakarta.servlet-api</artifactId>
@@ -273,6 +278,11 @@
273278
<version>2.5.2.Final</version>
274279
</dependency>
275280

281+
<dependency>
282+
<groupId>org.slf4j</groupId>
283+
<artifactId>slf4j-api</artifactId>
284+
</dependency>
285+
276286
<dependency>
277287
<groupId>org.weakref</groupId>
278288
<artifactId>jmxutils</artifactId>

gateway-ha/src/main/java/io/trino/gateway/ha/scheduler/ClusterScheduler.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.cronutils.model.definition.CronDefinitionBuilder;
2020
import com.cronutils.model.time.ExecutionTime;
2121
import com.cronutils.parser.CronParser;
22-
import com.google.common.annotations.VisibleForTesting;
2322
import io.trino.gateway.ha.config.ProxyBackendConfiguration;
2423
import io.trino.gateway.ha.config.ScheduleConfiguration;
2524
import io.trino.gateway.ha.router.GatewayBackendManager;
@@ -44,7 +43,7 @@ public class ClusterScheduler
4443
implements AutoCloseable
4544
{
4645
private static final Logger log = LoggerFactory.getLogger(ClusterScheduler.class);
47-
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
46+
private ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
4847
private final GatewayBackendManager backendManager;
4948
private final ScheduleConfiguration config;
5049
private final Map<String, ExecutionTime> executionTimes = new ConcurrentHashMap<>();
@@ -98,31 +97,28 @@ public void start()
9897
schedule.isActiveDuringCron());
9998
}
10099
catch (Exception e) {
101-
log.error("Failed to parse cron expression for cluster {}: {}",
100+
log.error("Skipping cluster {} due to invalid cron expression '{}': {}",
102101
schedule.getClusterName(),
103102
schedule.getCronExpression(),
104-
e);
103+
e.getMessage());
105104
}
106105
}
107106

108107
// Schedule the task
109-
scheduler.scheduleWithFixedDelay(
110-
this::checkAndUpdateClusterStatus,
108+
scheduler.scheduleAtFixedRate(
109+
() -> checkAndUpdateClusterStatus(ZonedDateTime.now(timezone)),
111110
0,
112-
(long) config.getCheckInterval().toMillis(),
111+
config.getCheckInterval().toMillis(),
113112
TimeUnit.MILLISECONDS);
114-
115113
log.info("Started cluster scheduler with check interval: {} (using {} timezone)",
116114
config.getCheckInterval(),
117115
timezone);
118116
}
119117

120-
@VisibleForTesting
121-
void checkAndUpdateClusterStatus()
118+
public void checkAndUpdateClusterStatus(ZonedDateTime currentTime)
122119
{
123120
try {
124-
ZonedDateTime now = ZonedDateTime.now(timezone);
125-
log.debug("Checking cluster status at: {} ({})", now, timezone);
121+
log.debug("Checking cluster status at: {} ({})", currentTime, timezone);
126122

127123
for (Map.Entry<String, ExecutionTime> entry : executionTimes.entrySet()) {
128124
String clusterName = entry.getKey();
@@ -139,7 +135,7 @@ void checkAndUpdateClusterStatus()
139135
}
140136

141137
ScheduleConfiguration.ClusterSchedule schedule = scheduleOpt.get();
142-
boolean cronMatches = executionTime.isMatch(now);
138+
boolean cronMatches = executionTime.isMatch(currentTime);
143139
boolean shouldBeActive = cronMatches == schedule.isActiveDuringCron();
144140

145141
log.info("Cluster: {}, cronMatches: {}, activeDuringCron: {}, shouldBeActive: {}",

0 commit comments

Comments
 (0)