1414 * limitations under the License.
1515 */
1616
17- package org .springframework .cloud .kubernetes .fabric8 .leader .election ;
17+ package org .springframework .cloud .kubernetes .commons .leader .election ;
1818
1919import java .util .concurrent .CompletableFuture ;
2020import java .util .concurrent .ExecutorService ;
2121import java .util .concurrent .TimeUnit ;
2222
23- import io .fabric8 .kubernetes .client .KubernetesClient ;
24- import io .fabric8 .kubernetes .client .extended .leaderelection .LeaderElectionConfig ;
25- import io .fabric8 .kubernetes .client .extended .leaderelection .LeaderElector ;
26-
27- import org .springframework .cloud .kubernetes .commons .leader .election .LeaderElectionProperties ;
2823import org .springframework .core .log .LogAccessor ;
2924
30- final class Fabric8LeaderElectionInitiatorUtil {
25+ /**
26+ * @author wind57
27+ */
28+ public final class LeaderElectionInitiatorUtil {
29+
30+ private static final LogAccessor LOG = new LogAccessor (LeaderElectionInitiatorUtil .class );
3131
32- private static final LogAccessor LOG = new LogAccessor ( Fabric8LeaderElectionInitiatorUtil . class );
32+ private LeaderElectionInitiatorUtil () {
3333
34- private Fabric8LeaderElectionInitiatorUtil () {
34+ }
3535
36+ public static void blockReadinessCheck (CompletableFuture <?> ready ) {
37+ try {
38+ ready .get ();
39+ }
40+ catch (Exception e ) {
41+ LOG .error (e , () -> "block readiness check failed with : " + e .getMessage ());
42+ throw new RuntimeException (e );
43+ }
44+ }
45+
46+ public static void shutDownExecutor (ExecutorService podReadyWaitingExecutor , String candidateIdentity ) {
47+ LOG .debug (() -> "podReadyWaitingExecutor will be shutdown for : " + candidateIdentity );
48+ podReadyWaitingExecutor .shutdownNow ();
49+ try {
50+ podReadyWaitingExecutor .awaitTermination (3 , TimeUnit .SECONDS );
51+ }
52+ catch (InterruptedException e ) {
53+ Thread .currentThread ().interrupt ();
54+ }
3655 }
3756
3857 /**
3958 * if 'ready' is already completed at this point, thread will run this, otherwise it
4059 * will attach the pipeline and move on to 'blockReadinessCheck'.
4160 */
42- static CompletableFuture <?> attachReadinessLoggerPipeline (CompletableFuture <?> innerPodReadyFuture ,
61+ public static CompletableFuture <?> attachReadinessLoggerPipeline (CompletableFuture <?> innerPodReadyFuture ,
4362 String candidateIdentity ) {
4463 return innerPodReadyFuture .whenComplete ((ok , error ) -> {
4564 if (error != null ) {
@@ -51,7 +70,7 @@ static CompletableFuture<?> attachReadinessLoggerPipeline(CompletableFuture<?> i
5170 });
5271 }
5372
54- static void sleep (LeaderElectionProperties leaderElectionProperties ) {
73+ public static void sleep (LeaderElectionProperties leaderElectionProperties ) {
5574 try {
5675 TimeUnit .SECONDS .sleep (leaderElectionProperties .waitAfterRenewalFailure ().toSeconds ());
5776 }
@@ -60,29 +79,4 @@ static void sleep(LeaderElectionProperties leaderElectionProperties) {
6079 }
6180 }
6281
63- static LeaderElector leaderElector (LeaderElectionConfig config , KubernetesClient fabric8KubernetesClient ) {
64- return fabric8KubernetesClient .leaderElector ().withConfig (config ).build ();
65- }
66-
67- static void blockReadinessCheck (CompletableFuture <?> ready ) {
68- try {
69- ready .get ();
70- }
71- catch (Exception e ) {
72- LOG .error (e , () -> "block readiness check failed with : " + e .getMessage ());
73- throw new RuntimeException (e );
74- }
75- }
76-
77- static void shutDownExecutor (ExecutorService podReadyWaitingExecutor , String candidateIdentity ) {
78- LOG .debug (() -> "podReadyWaitingExecutor will be shutdown for : " + candidateIdentity );
79- podReadyWaitingExecutor .shutdownNow ();
80- try {
81- podReadyWaitingExecutor .awaitTermination (3 , TimeUnit .SECONDS );
82- }
83- catch (InterruptedException e ) {
84- Thread .currentThread ().interrupt ();
85- }
86- }
87-
8882}
0 commit comments