From 8b85abdb37966eb3f8b289510ea2c86ffd94d4ea Mon Sep 17 00:00:00 2001 From: Nikola Stankovic Date: Fri, 28 Jan 2022 23:32:43 +0100 Subject: [PATCH] chore: clean up for release --- README.md | 50 +++++++++++++------ build.gradle | 2 +- .../MaintenanceAutoConfiguration.kt | 3 +- .../MaintenanceConfigurationProperties.kt | 5 -- .../core/config/MaintenanceProperties.kt | 5 +- .../database/MaintenanceMetricsInitializer.kt | 49 ------------------ 6 files changed, 39 insertions(+), 75 deletions(-) delete mode 100644 src/main/kotlin/io/viascom/devutils/springbootstartermaintenance/database/MaintenanceMetricsInitializer.kt diff --git a/README.md b/README.md index 151ff76..c7a9009 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,13 @@ [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.viascom.devutils/spring-boot-starter-maintenance/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.viascom.devutils/spring-boot-starter-maintenance/) -spring-boot-starter-maintenance is a maintenance mode library and auto-configuration for spring boot web and security projects. +**spring-boot-starter-maintenance** is an extensible auto-configuration library for spring boot web and security projects supporting Java and Kotlin applications to block access to this application during maintenances and still provide an open door for the maintainers. -With spring-boot-starter-maintenance anyone can easily use best practices during maintenance work on their applications. In fact, every HTTP client will receive a response with status code 503 - Service Unavailable during maintenance. This library provides injection points for alert- and clean-up tasks and detailed metrics. Everything is customizable and extendable programmed. +With spring-boot-starter-maintenance anyone can easily use best practices during maintenance work on their applications. In fact, every HTTP client will receive a response with status code 503 - Service Unavailable during maintenance. This library provides injection points for alert- and clean-up tasks. -### Requirements +spring-boot-starter-maintenance is ready to use out of the box for most common setups. Even for uncommon applications and technologies, it should be simple to implement the necessary interfaces to connect a library/framework/etc. to it. + +## Requirements JDK >= 1.8 @@ -16,14 +18,13 @@ spring-boot-starter-maintenance depends on the following two dependencies and wi - org.springframework.boot:spring-boot-starter-web *(required)* - org.springframework.boot:spring-boot-starter-security *(required)* -- org.springframework.boot:spring-boot-starter-data-jpa *(optional, needed only if you enable metrics)* -### Download +## Download Gradle: ```gradle dependencies { - implementation 'io.viascom.devutils:spring-boot-starter-maintenance:0.0.2' + implementation 'io.viascom.devutils:spring-boot-starter-maintenance:0.0.1' } ``` @@ -32,13 +33,13 @@ Maven: io.viascom.devutils spring-boot-starter-maintenance - 0.0.2 + 0.0.1 ``` [spring-boot-starter-maintenance jar downloads](https://maven-badges.herokuapp.com/maven-central/io.viascom.devutils/spring-boot-starter-maintenance) are available from Maven Central. -### Getting Started +## Getting Started Open your implementation of the WebSecurityConfigurerAdapter (f.e. named WebSecurityConfig) and add the following three parts: @@ -59,7 +60,29 @@ private Maintenance maintenance; .exceptionHandling() .accessDeniedHandler(new DefaultMaintenanceAccessDeniedHandler(maintenance)) ``` +## Configuration Properties + +### Basic configuration example +```yaml +maintenance: + enabled: true + roles: + - MAINTAINER +``` + +### Full configuration example +```yaml +maintenance: + enabled: true + roles: + - MAINTAINER + - ADMIN + alert: true + clean: true + retry-after: 30 + events: true +``` ### Maintenance properties All properties can be accessed under the property `maintenance`. @@ -72,29 +95,28 @@ All properties can be accessed under the property `maintenance`. | clean | Enable to run all classes implementing the MaintenanceCleaner interface during the stop maintenance process. | false | | retry-after | Default value for the "Retry-After" response HTTP header in seconds, which is used in the DefaultMaintenanceAccessDeniedHandler. | 60 | | events | Enable to publish spring events for maintenance events. | false | -| metrics | Enable to persist metrics for maintenances. Requires spring-boot-starter-data-jpa to work. | false | -### Versioning ๐Ÿ”– [![GitHub release](https://img.shields.io/github/release/viascom/spring-boot-starter-maintenance/all?logo=GitHub)](https://github.com/viascom/spring-boot-starter-maintenance/releases/latest) +## Versioning ๐Ÿ”– [![GitHub release](https://img.shields.io/github/release/viascom/spring-boot-starter-maintenance/all?logo=GitHub)](https://github.com/viascom/spring-boot-starter-maintenance/releases/latest) This project is developed by [Viascom](https://github.com/viascom) using the [Semantic Versioning specification](https://semver.org). For the versions available, see the [releases on this repository](https://github.com/viascom/spring-boot-starter-maintenance/releases). -### Change log ๐Ÿ“ +## Change log ๐Ÿ“ See the [CHANGELOG](CHANGELOG.md) file for details. -### Authors ๐Ÿ–ฅ๏ธ +## Authors ๐Ÿ–ฅ๏ธ * **Nikola Stankoviฤ‡** - *Initial work* - [botscripter](https://github.com/botscripter) * **Patrick Bรถsch** - *Initial work* - [itsmefox](https://github.com/itsmefox) See also the list of [contributors](https://github.com/viascom/spring-boot-starter-maintenance/contributors) who participated in this project. ๐Ÿ’• -### Contributing +## Contributing See [CONTRIBUTING.md](CONTRIBUTING.md) file. ๐Ÿ™ If you like spring-boot-starter-maintenance you can show support by starring โญ this repository. -### License +## License spring-boot-starter-maintenance is released under the [Unlicense](LICENSE). diff --git a/build.gradle b/build.gradle index c97231a..529be14 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ plugins { } group "io.viascom.devutils" -version "0.0.2" +version "0.0.1" sourceCompatibility = 1.8 targetCompatibility = 1.8 diff --git a/src/main/kotlin/io/viascom/devutils/springbootstartermaintenance/autoconfiguration/MaintenanceAutoConfiguration.kt b/src/main/kotlin/io/viascom/devutils/springbootstartermaintenance/autoconfiguration/MaintenanceAutoConfiguration.kt index c60fc74..51ec405 100644 --- a/src/main/kotlin/io/viascom/devutils/springbootstartermaintenance/autoconfiguration/MaintenanceAutoConfiguration.kt +++ b/src/main/kotlin/io/viascom/devutils/springbootstartermaintenance/autoconfiguration/MaintenanceAutoConfiguration.kt @@ -55,8 +55,7 @@ open class MaintenanceAutoConfiguration( properties.alert, properties.clean, properties.retryAfter, - properties.events, - properties.metrics + properties.events ), alerts, cleaners, diff --git a/src/main/kotlin/io/viascom/devutils/springbootstartermaintenance/autoconfiguration/MaintenanceConfigurationProperties.kt b/src/main/kotlin/io/viascom/devutils/springbootstartermaintenance/autoconfiguration/MaintenanceConfigurationProperties.kt index 0e19d58..c82844d 100644 --- a/src/main/kotlin/io/viascom/devutils/springbootstartermaintenance/autoconfiguration/MaintenanceConfigurationProperties.kt +++ b/src/main/kotlin/io/viascom/devutils/springbootstartermaintenance/autoconfiguration/MaintenanceConfigurationProperties.kt @@ -44,9 +44,4 @@ open class MaintenanceConfigurationProperties { * Enable to publish spring events for maintenance events. */ var events: Boolean = false - - /** - * Enable to persist metrics for maintenances. - */ - var metrics: Boolean = false } \ No newline at end of file diff --git a/src/main/kotlin/io/viascom/devutils/springbootstartermaintenance/core/config/MaintenanceProperties.kt b/src/main/kotlin/io/viascom/devutils/springbootstartermaintenance/core/config/MaintenanceProperties.kt index 0656b34..95513a1 100644 --- a/src/main/kotlin/io/viascom/devutils/springbootstartermaintenance/core/config/MaintenanceProperties.kt +++ b/src/main/kotlin/io/viascom/devutils/springbootstartermaintenance/core/config/MaintenanceProperties.kt @@ -1,13 +1,10 @@ package io.viascom.devutils.springbootstartermaintenance.core.config -import java.time.Duration - data class MaintenanceProperties( val enabled: Boolean, val roles: MutableList, val alert: Boolean, val clean: Boolean, val retryAfter: Int, - val events: Boolean, - val metrics: Boolean, + val events: Boolean ) \ No newline at end of file diff --git a/src/main/kotlin/io/viascom/devutils/springbootstartermaintenance/database/MaintenanceMetricsInitializer.kt b/src/main/kotlin/io/viascom/devutils/springbootstartermaintenance/database/MaintenanceMetricsInitializer.kt deleted file mode 100644 index 0132fc1..0000000 --- a/src/main/kotlin/io/viascom/devutils/springbootstartermaintenance/database/MaintenanceMetricsInitializer.kt +++ /dev/null @@ -1,49 +0,0 @@ -package io.viascom.devutils.springbootstartermaintenance.database - -import io.viascom.devutils.springbootstartermaintenance.autoconfiguration.MaintenanceConfigurationProperties -import org.springframework.boot.context.event.ApplicationReadyEvent -import org.springframework.context.event.EventListener -import org.springframework.core.io.ClassPathResource -import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator -import org.springframework.stereotype.Component -import java.sql.DatabaseMetaData -import javax.sql.DataSource - -@Component -class MaintenanceMetricsInitializer( - private val datasource: DataSource, - private val properties: MaintenanceConfigurationProperties -) { - @EventListener(ApplicationReadyEvent::class) - fun initialize() { - if (properties.metrics) { - if (!checkIfMaintenanceTableExists()) { - val resourceDatabasePopulator = ResourceDatabasePopulator(false, false, "UTF-8", ClassPathResource("database/init-maintenance.sql")) - resourceDatabasePopulator.execute(datasource) - } else { - - } - - - // yes: - // TODO: check for maintenance table version - // update - } - } - - private fun checkIfMaintenanceTableExists(): Boolean { - val databaseMetaData: DatabaseMetaData = datasource.connection.metaData - val tables = databaseMetaData.getTables(null, null, null, arrayOf("TABLE")) - - var maintenanceTableExists = false - while (tables.next()) { - val tableName: String = tables.getString("TABLE_NAME") - if (tableName == "MAINTENANCE") { - maintenanceTableExists = true - break - } - } - - return maintenanceTableExists - } -} \ No newline at end of file