1919import com .cronutils .model .definition .CronDefinitionBuilder ;
2020import com .cronutils .model .time .ExecutionTime ;
2121import com .cronutils .parser .CronParser ;
22+ import io .airlift .log .Logger ;
2223import io .trino .gateway .ha .config .ProxyBackendConfiguration ;
2324import io .trino .gateway .ha .config .ScheduleConfiguration ;
2425import io .trino .gateway .ha .router .GatewayBackendManager ;
2526import jakarta .annotation .PostConstruct ;
2627import jakarta .annotation .PreDestroy ;
2728import jakarta .inject .Inject ;
28- import org .slf4j .Logger ;
29- import org .slf4j .LoggerFactory ;
3029
3130import java .time .ZoneId ;
3231import java .time .ZonedDateTime ;
4241public class ClusterScheduler
4342 implements AutoCloseable
4443{
45- private static final Logger log = LoggerFactory . getLogger (ClusterScheduler .class );
44+ private static final Logger log = Logger . get (ClusterScheduler .class );
4645 private ScheduledExecutorService scheduler = Executors .newScheduledThreadPool (1 );
4746 private final GatewayBackendManager backendManager ;
4847 private final ScheduleConfiguration config ;
@@ -68,12 +67,12 @@ public ClusterScheduler(GatewayBackendManager backendManager, ScheduleConfigurat
6867 }
6968 else {
7069 configuredTimezone = ZoneId .of (timezoneStr );
71- log .info ("Using configured timezone: {} " , timezoneStr );
70+ log .info ("Using configured timezone: %s " , timezoneStr );
7271 }
7372 }
7473 catch (Exception e ) {
7574 configuredTimezone = ZoneId .of ("GMT" );
76- log .warn ("Invalid timezone '{} ' in configuration, falling back to GMT" , config .getTimezone (), e );
75+ log .warn (e , "Invalid timezone '%s ' in configuration, falling back to GMT" , config .getTimezone ());
7776 }
7877 this .timezone = configuredTimezone ;
7978 }
@@ -110,15 +109,15 @@ public void start()
110109 0 ,
111110 config .getCheckInterval ().toMillis (),
112111 TimeUnit .MILLISECONDS );
113- log .info ("Started cluster scheduler with check interval: {} (using {} timezone)" ,
112+ log .info ("Started cluster scheduler with check interval: %s (using %s timezone)" ,
114113 config .getCheckInterval (),
115114 timezone );
116115 }
117116
118117 public void checkAndUpdateClusterStatus (ZonedDateTime currentTime )
119118 {
120119 try {
121- log .debug ("Checking cluster status at: {} ({} )" , currentTime , timezone );
120+ log .debug ("Checking cluster status at: %s (%s )" , currentTime , timezone );
122121
123122 for (Map .Entry <String , ExecutionTime > entry : executionTimes .entrySet ()) {
124123 String clusterName = entry .getKey ();
@@ -130,15 +129,15 @@ public void checkAndUpdateClusterStatus(ZonedDateTime currentTime)
130129 .findFirst ();
131130
132131 if (scheduleOpt .isEmpty ()) {
133- log .warn ("No schedule configuration found for cluster: {} " , clusterName );
132+ log .warn ("No schedule configuration found for cluster: %s " , clusterName );
134133 continue ;
135134 }
136135
137136 ScheduleConfiguration .ClusterSchedule schedule = scheduleOpt .get ();
138137 boolean cronMatches = executionTime .isMatch (currentTime );
139138 boolean shouldBeActive = cronMatches == schedule .isActiveDuringCron ();
140139
141- log .info ("Cluster: {} , cronMatches: {} , activeDuringCron: {} , shouldBeActive: {} " ,
140+ log .info ("Cluster: %s , cronMatches: %s , activeDuringCron: %s , shouldBeActive: %s " ,
142141 clusterName ,
143142 cronMatches ,
144143 schedule .isActiveDuringCron (),
@@ -150,38 +149,38 @@ public void checkAndUpdateClusterStatus(ZonedDateTime currentTime)
150149 ProxyBackendConfiguration cluster = clusterOpt .get ();
151150 boolean currentlyActive = cluster .isActive ();
152151
153- log .debug ("Cluster: {} , currentlyActive: {} , shouldBeActive: {} " ,
152+ log .debug ("Cluster: %s , currentlyActive: %s , shouldBeActive: %s " ,
154153 clusterName ,
155154 currentlyActive ,
156155 shouldBeActive );
157156
158157 if (currentlyActive != shouldBeActive ) {
159158 if (shouldBeActive ) {
160159 backendManager .activateBackend (clusterName );
161- log .info ("Activated cluster {} based on schedule (cron match: {} , activeDuringCron: {} )" ,
160+ log .info ("Activated cluster %s based on schedule (cron match: %s , activeDuringCron: %s )" ,
162161 clusterName ,
163162 cronMatches ,
164163 schedule .isActiveDuringCron ());
165164 }
166165 else {
167166 backendManager .deactivateBackend (clusterName );
168- log .info ("Deactivated cluster {} based on schedule (cron match: {} , activeDuringCron: {} )" ,
167+ log .info ("Deactivated cluster %s based on schedule (cron match: %s , activeDuringCron: %s )" ,
169168 clusterName ,
170169 cronMatches ,
171170 schedule .isActiveDuringCron ());
172171 }
173172 }
174173 else {
175- log .debug ("Cluster {} status unchanged: active={} " , clusterName , currentlyActive );
174+ log .debug ("Cluster %s status unchanged: active=%s " , clusterName , currentlyActive );
176175 }
177176 }
178177 else {
179- log .warn ("Cluster {} not found in backend manager" , clusterName );
178+ log .warn ("Cluster %s not found in backend manager" , clusterName );
180179 }
181180 }
182181 }
183182 catch (Exception e ) {
184- log .error ("Error in cluster scheduler task" , e );
183+ log .error (e , "Error in cluster scheduler task" );
185184 }
186185 }
187186
@@ -197,7 +196,7 @@ public void close()
197196 }
198197 catch (InterruptedException e ) {
199198 Thread .currentThread ().interrupt ();
200- log .warn ("Interrupted while waiting for scheduler to terminate" , e );
199+ log .warn (e , "Interrupted while waiting for scheduler to terminate" );
201200 }
202201 }
203202}
0 commit comments