From b0ea891d6443beec5ba03d2703495951cf5b1784 Mon Sep 17 00:00:00 2001 From: wind57 Date: Tue, 23 Apr 2024 11:57:52 +0300 Subject: [PATCH 1/5] clean-up --- .../leaderelection/LeaderCallbacks.java | 6 ++-- .../leaderelection/LeaderElectionConfig.java | 30 ++----------------- .../leaderelection/LeaderElector.java | 6 ++-- 3 files changed, 7 insertions(+), 35 deletions(-) diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extended/leaderelection/LeaderCallbacks.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extended/leaderelection/LeaderCallbacks.java index 2fdb5047ec7..71ed61dc0c0 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extended/leaderelection/LeaderCallbacks.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extended/leaderelection/LeaderCallbacks.java @@ -20,9 +20,9 @@ public class LeaderCallbacks { - private Runnable onStartLeading; - private Runnable onStopLeading; - private Consumer onNewLeader; + private final Runnable onStartLeading; + private final Runnable onStopLeading; + private final Consumer onNewLeader; public LeaderCallbacks(Runnable onStartLeading, Runnable onStopLeading, Consumer onNewLeader) { this.onStartLeading = Objects.requireNonNull(onStartLeading, "onStartLeading callback is required"); diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extended/leaderelection/LeaderElectionConfig.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extended/leaderelection/LeaderElectionConfig.java index a6bf4047217..75a7ef15b13 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extended/leaderelection/LeaderElectionConfig.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extended/leaderelection/LeaderElectionConfig.java @@ -17,9 +17,11 @@ import io.fabric8.kubernetes.client.extended.leaderelection.resourcelock.Lock; import io.sundr.builder.annotations.Buildable; +import lombok.Getter; import java.time.Duration; +@Getter @Buildable(editableEnabled = false, lazyCollectionInitEnabled = false, builderPackage = "io.fabric8.kubernetes.api.builder") public class LeaderElectionConfig { @@ -42,32 +44,4 @@ public LeaderElectionConfig(Lock lock, Duration leaseDuration, Duration renewDea this.name = name; } - public Lock getLock() { - return lock; - } - - public Duration getLeaseDuration() { - return leaseDuration; - } - - public Duration getRenewDeadline() { - return renewDeadline; - } - - public Duration getRetryPeriod() { - return retryPeriod; - } - - public LeaderCallbacks getLeaderCallbacks() { - return leaderCallbacks; - } - - public boolean isReleaseOnCancel() { - return releaseOnCancel; - } - - public String getName() { - return name; - } - } diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extended/leaderelection/LeaderElector.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extended/leaderelection/LeaderElector.java index 8b63cfbd229..d29206e4895 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extended/leaderelection/LeaderElector.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extended/leaderelection/LeaderElector.java @@ -46,10 +46,9 @@ public class LeaderElector { protected static final Double JITTER_FACTOR = 1.2; - private KubernetesClient kubernetesClient; - private LeaderElectionConfig leaderElectionConfig; + private final KubernetesClient kubernetesClient; + private final LeaderElectionConfig leaderElectionConfig; private final AtomicReference observedRecord = new AtomicReference<>(); - private final AtomicReference observedTime = new AtomicReference<>(); private final Executor executor; private boolean started; private boolean stopped; @@ -254,7 +253,6 @@ synchronized boolean tryAcquireOrRenew() { private void updateObserved(LeaderElectionRecord leaderElectionRecord) { final LeaderElectionRecord current = observedRecord.getAndSet(leaderElectionRecord); if (!Objects.equals(leaderElectionRecord, current)) { - observedTime.set(LocalDateTime.now()); final String currentLeader = current == null ? null : current.getHolderIdentity(); final String newLeader = leaderElectionRecord.getHolderIdentity(); if (!Objects.equals(newLeader, currentLeader)) { From 5e0d7caaa0bc09fd21a9d2572f8b7c20f0d60167 Mon Sep 17 00:00:00 2001 From: wind57 Date: Tue, 23 Apr 2024 12:22:23 +0300 Subject: [PATCH 2/5] chekstyle --- .../kubernetes/client/extended/leaderelection/LeaderElector.java | 1 - 1 file changed, 1 deletion(-) diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extended/leaderelection/LeaderElector.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extended/leaderelection/LeaderElector.java index d29206e4895..7d02e0cf7f2 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extended/leaderelection/LeaderElector.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extended/leaderelection/LeaderElector.java @@ -25,7 +25,6 @@ import java.net.HttpURLConnection; import java.time.Duration; -import java.time.LocalDateTime; import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.time.temporal.ChronoUnit; From df0cceb5ebcb583ced549320e8a0167c0407649e Mon Sep 17 00:00:00 2001 From: wind57 Date: Tue, 23 Apr 2024 12:41:24 +0300 Subject: [PATCH 3/5] drop @Getter --- .../leaderelection/LeaderElectionConfig.java | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extended/leaderelection/LeaderElectionConfig.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extended/leaderelection/LeaderElectionConfig.java index 75a7ef15b13..684e45124cd 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extended/leaderelection/LeaderElectionConfig.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extended/leaderelection/LeaderElectionConfig.java @@ -17,11 +17,9 @@ import io.fabric8.kubernetes.client.extended.leaderelection.resourcelock.Lock; import io.sundr.builder.annotations.Buildable; -import lombok.Getter; import java.time.Duration; -@Getter @Buildable(editableEnabled = false, lazyCollectionInitEnabled = false, builderPackage = "io.fabric8.kubernetes.api.builder") public class LeaderElectionConfig { @@ -34,7 +32,7 @@ public class LeaderElectionConfig { private final String name; public LeaderElectionConfig(Lock lock, Duration leaseDuration, Duration renewDeadline, Duration retryPeriod, - LeaderCallbacks leaderCallbacks, boolean releaseOnCancel, String name) { + LeaderCallbacks leaderCallbacks, boolean releaseOnCancel, String name) { this.lock = lock; this.leaseDuration = leaseDuration; this.renewDeadline = renewDeadline; @@ -44,4 +42,32 @@ public LeaderElectionConfig(Lock lock, Duration leaseDuration, Duration renewDea this.name = name; } + public Lock getLock() { + return lock; + } + + public Duration getLeaseDuration() { + return leaseDuration; + } + + public Duration getRenewDeadline() { + return renewDeadline; + } + + public Duration getRetryPeriod() { + return retryPeriod; + } + + public LeaderCallbacks getLeaderCallbacks() { + return leaderCallbacks; + } + + public boolean isReleaseOnCancel() { + return releaseOnCancel; + } + + public String getName() { + return name; + } + } From 2ebe392d3d19221c68232bfbbc420b261771bfdc Mon Sep 17 00:00:00 2001 From: wind57 Date: Tue, 23 Apr 2024 12:42:00 +0300 Subject: [PATCH 4/5] chekstyle --- .../client/extended/leaderelection/LeaderElectionConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extended/leaderelection/LeaderElectionConfig.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extended/leaderelection/LeaderElectionConfig.java index 684e45124cd..a6bf4047217 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extended/leaderelection/LeaderElectionConfig.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extended/leaderelection/LeaderElectionConfig.java @@ -32,7 +32,7 @@ public class LeaderElectionConfig { private final String name; public LeaderElectionConfig(Lock lock, Duration leaseDuration, Duration renewDeadline, Duration retryPeriod, - LeaderCallbacks leaderCallbacks, boolean releaseOnCancel, String name) { + LeaderCallbacks leaderCallbacks, boolean releaseOnCancel, String name) { this.lock = lock; this.leaseDuration = leaseDuration; this.renewDeadline = renewDeadline; From 6e49ab82646e39f9ffcdb44aa8dc3d69888ae1da Mon Sep 17 00:00:00 2001 From: wind57 Date: Tue, 23 Apr 2024 14:15:33 +0300 Subject: [PATCH 5/5] placeholder commit