Skip to content

Commit

Permalink
NIFI-10975 Updated LeaderElectionCommand to run LeaderElector in loop
Browse files Browse the repository at this point in the history
  • Loading branch information
exceptionfactory committed Jan 11, 2023
1 parent 0ee6620 commit 02ce8ac
Showing 1 changed file with 12 additions and 3 deletions.
Expand Up @@ -70,15 +70,24 @@ class LeaderElectionCommand implements Runnable {

@Override
public void run() {
logger.info("Starting Election Command Name [{}] ID [{}]", name, lock.identity());
logger.info("Election Name [{}] ID [{}] Participation STARTED", name, lock.identity());

while (!Thread.currentThread().isInterrupted()) {
runLeaderElector();
}

logger.info("Election Name [{}] ID [{}] Participation STOPPED", name, lock.identity());
}

private void runLeaderElector() {
logger.info("Election Name [{}] ID [{}] Command STARTED", name, lock.identity());
try {
final LeaderElectionConfig leaderElectionConfig = getLeaderElectionConfig();
final LeaderElector leaderElector = kubernetesClient.leaderElector().withConfig(leaderElectionConfig).build();
leaderElector.run();
logger.info("Completed Election Command Name [{}] ID [{}]", name, lock.identity());
logger.info("Election Name [{}] ID [{}] Command STOPPED", name, lock.identity());
} catch (final RuntimeException e) {
logger.error("Failed Election Command Name [{}] ID [{}]", name, lock.identity(), e);
logger.error("Election Name [{}] ID [{}] Command FAILED", name, lock.identity(), e);
}
}

Expand Down

0 comments on commit 02ce8ac

Please sign in to comment.