change: Remove leader election and Kafka

This commit is contained in:
2025-03-20 17:57:29 +01:00
parent 10597b0b53
commit fa1f4b47b9
18 changed files with 17 additions and 175 deletions
@@ -1,44 +1,15 @@
package de.twomartens.timetable
import de.twomartens.support.model.LeadershipStatus
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.context.event.ApplicationReadyEvent
import org.springframework.boot.runApplication
import org.springframework.cloud.kubernetes.commons.leader.LeaderProperties
import org.springframework.context.event.EventListener
import org.springframework.data.mongodb.config.EnableMongoAuditing
import org.springframework.integration.leader.event.OnGrantedEvent
import org.springframework.integration.leader.event.OnRevokedEvent
import org.springframework.scheduling.annotation.EnableScheduling
@EnableMongoAuditing
@EnableScheduling
@SpringBootApplication(scanBasePackages = ["de.twomartens.support", "de.twomartens.timetable"])
open class MainApplication(
private val leadershipStatus: LeadershipStatus,
private val leaderProperties: LeaderProperties
) {
@EventListener(ApplicationReadyEvent::class)
fun ready(event: ApplicationReadyEvent) {
setInitialLeadershipStatus()
}
@EventListener(OnGrantedEvent::class)
fun onLeadershipGranted(event: OnGrantedEvent) {
leadershipStatus.isLeader = true
}
@EventListener(OnRevokedEvent::class)
fun onLeadershipRevoked(event: OnRevokedEvent) {
leadershipStatus.isLeader = false
}
private fun setInitialLeadershipStatus() {
leadershipStatus.isLeader = !leaderProperties.isEnabled
}
}
open class MainApplication() {}
fun main(args: Array<String>) {
runApplication<MainApplication>(*args)
}
}
@@ -1,8 +0,0 @@
package de.twomartens.timetable.configuration
import org.springframework.cloud.bus.jackson.RemoteApplicationEventScan
import org.springframework.context.annotation.Configuration
@Configuration
@RemoteApplicationEventScan(basePackages = ["de.twomartens.timetable", "de.twomartens.support"])
open class BusConfiguration
@@ -7,12 +7,10 @@ import de.twomartens.support.property.TimeProperties
import de.twomartens.timetable.bahnApi.property.BahnApiProperties
import de.twomartens.timetable.property.ServiceProperties
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.cloud.kubernetes.commons.leader.LeaderProperties
import org.springframework.context.annotation.Configuration
@Configuration
@EnableConfigurationProperties(RestTemplateTimeoutProperties::class, ServiceProperties::class,
StatusProbeProperties::class, TimeProperties::class, BahnApiProperties::class,
HealthCheckProperties::class,
LeaderProperties::class)
HealthCheckProperties::class)
open class PropertyConfiguration
@@ -5,11 +5,9 @@ import de.twomartens.timetable.model.common.LanguageCode
import de.twomartens.timetable.types.NonEmptyString
import io.swagger.v3.oas.annotations.media.Schema
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.cloud.context.config.annotation.RefreshScope
@RefreshScope
@ConfigurationProperties(prefix = "de.twomartens.timetable")
@Schema(description = "Properties, to configure this Application")
class ServiceProperties {
open class ServiceProperties {
lateinit var countryNames: Map<CountryCode, Map<LanguageCode, NonEmptyString>>
}
@@ -1,13 +1,2 @@
server.port: 12100
management.server.port: 12101
spring:
cloud:
kubernetes:
leader:
enabled: false
config:
import:
- "classpath:config/timetable.yaml"
- "optional:configserver:${CONFIGSERVER_SCHEME:http}://${CONFIGSERVER_HOST:localhost}:${CONFIGSERVER_PORT:8888}${CONFIGSERVER_PREFIX:/config}"
@@ -1,7 +0,0 @@
spring:
config:
import:
- "configserver:${CONFIGSERVER_SCHEME:http}://${CONFIGSERVER_HOST:configserver}:${CONFIGSERVER_PORT:8888}${CONFIGSERVER_PREFIX:/config}"
kafka:
bootstrap-servers:
- ${KAFKA_HOST:kafka}:${KAFKA_PORT:9092}
@@ -26,12 +26,6 @@ management:
http.server.requests: true
spring:
cloud:
config:
name: timetable
kubernetes:
leader:
enabled: true
main:
banner-mode: off
profiles:
@@ -84,6 +78,12 @@ de.twomartens.timetable:
bahn-api:
client-id: ${DB_CLIENT_ID}
client-secret: ${DB_CLIENT_SECRET}
greeting: "Hello %s, on millenium"
statusprobe:
scheduleDuration: 60
maxKafkaFailureDuration: 5
maxBlobFailureCount: 5
maxFailurePercent: 50
de.twomartens.support.health.greeting: "Good morning"
time: