All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zodiac.autoconfigure.kubernetes.leader.LeaderAutoConfiguration Maven / Gradle / Ivy

There is a newer version: 1.6.8
Show newest version
package org.zodiac.autoconfigure.kubernetes.leader;

import java.net.Inet4Address;
import java.net.UnknownHostException;

import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
import org.springframework.integration.leader.Candidate;
import org.springframework.integration.leader.DefaultCandidate;
import org.springframework.integration.leader.event.DefaultLeaderEventPublisher;
import org.springframework.integration.leader.event.LeaderEventPublisher;
import org.zodiac.autoconfigure.kubernetes.KubernetesClientProperties;
import org.zodic.kubernetes.base.constants.KubernetesSystemPropertiesConstants;

@SpringBootConfiguration
@ConditionalOnBean(value = {io.fabric8.kubernetes.client.KubernetesClient.class})
@ConditionalOnClass(value = {io.fabric8.kubernetes.client.KubernetesClient.class, io.fabric8.kubernetes.api.KubernetesResourceMappingProvider.class})
@ConditionalOnProperty(value = KubernetesSystemPropertiesConstants.SPRING_KUBERNETES_LEADER_ENABLED, havingValue = "true")
public class LeaderAutoConfiguration {

//    @Bean
//    @ConditionalOnMissingBean
//    @ConfigurationProperties(prefix = KubernetesSystemPropertiesConstants.SPRING_KUBERNETES_LEADER_PREFIX, ignoreInvalidFields = true)
//    protected LeaderProperties leaderProperties() {
//        return new LeaderProperties();
//    }

    @Bean
    @ConditionalOnMissingBean(LeaderEventPublisher.class)
    protected LeaderEventPublisher defaultLeaderEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        return new DefaultLeaderEventPublisher(applicationEventPublisher);
    }

    @Bean
    protected Candidate candidate(KubernetesClientProperties kubernetesClientProperties) throws UnknownHostException {
        String id = Inet4Address.getLocalHost().getHostName();
        String role = kubernetesClientProperties.getLeader().getRole();
        return new DefaultCandidate(id, role);
    }

    @Bean
    protected org.zodic.kubernetes.leader.LeadershipController leadershipController(Candidate candidate, KubernetesClientProperties kubernetesClientProperties,
        LeaderEventPublisher leaderEventPublisher, io.fabric8.kubernetes.client.KubernetesClient kubernetesClient) {
        return new org.zodic.kubernetes.leader.LeadershipController(candidate, kubernetesClientProperties.getLeader(), leaderEventPublisher, kubernetesClient);
    }

    @Bean
    protected org.zodic.kubernetes.leader.LeaderRecordWatcher leaderRecordWatcher(KubernetesClientProperties kubernetesClientProperties,
        org.zodic.kubernetes.leader.LeadershipController leadershipController, io.fabric8.kubernetes.client.KubernetesClient kubernetesClient) {
        return new org.zodic.kubernetes.leader.LeaderRecordWatcher(kubernetesClientProperties.getLeader(), leadershipController, kubernetesClient);
    }

    @Bean
    protected org.zodic.kubernetes.leader.PodReadinessWatcher hostPodWatcher(Candidate candidate, io.fabric8.kubernetes.client.KubernetesClient kubernetesClient,
        org.zodic.kubernetes.leader.LeadershipController leadershipController) {
        return new org.zodic.kubernetes.leader.PodReadinessWatcher(candidate.getId(), kubernetesClient, leadershipController);
    }

    @Bean(destroyMethod = "stop")
    protected org.zodic.kubernetes.leader.LeaderInitiator leaderInitiator(KubernetesClientProperties kubernetesClientProperties, org.zodic.kubernetes.leader.LeadershipController leadershipController,
        org.zodic.kubernetes.leader.LeaderRecordWatcher leaderRecordWatcher, org.zodic.kubernetes.leader.PodReadinessWatcher hostPodWatcher) {
        return new org.zodic.kubernetes.leader.LeaderInitiator(kubernetesClientProperties.getLeader(), leadershipController, leaderRecordWatcher, hostPodWatcher);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy