From 2297709d97ee0d9ee61df17ab3b37b463fb56338 Mon Sep 17 00:00:00 2001 From: Adam Kobor Date: Tue, 4 Jan 2022 15:16:44 +0100 Subject: [PATCH] Upgrade tooling & dependencies (#52) * Upgrade Gradle to 7.3.3 * Update testcontainers * Replace dep update checker Gradle plugin * Upgrade detekt * Move away from jcenter * Add ktlint and fix violations * Remove micronaut-cli.yml * Update jacoco and add Flyway Gradle plugin * Update jib * Update logbook * Update arrow-data to 0.12.1 * Update mockk to 1.12.2 * Update shadowJar to 7.1.2 * Update Micronaut, kotlin and depending libs - jOOQ to 3.14.12 - Kotlin to 1.6.10 - Micronaut to 3.2.4 * Rewrite GlobalErrorHandlerTest to use built-in mocking * Update JavaMailer to 7.0.0 * Fix native image building --- .github/workflows/main.yml | 3 - Dockerfile | 15 - build.gradle | 116 +++++--- config/detekt/detekt.yml | 279 ++++++------------ docker-build-native.sh | 17 -- docs/api-doc/kuvasz-latest.yml | 210 +++++++------ gradle.properties | 35 ++- gradle/wrapper/gradle-wrapper.properties | 2 +- micronaut-cli.yml | 6 - .../kuvaszuptime/kuvasz/DefaultCatalog.java | 2 +- .../kuvaszuptime/kuvasz/DefaultSchema.java | 2 +- .../java/com/kuvaszuptime/kuvasz/Indexes.java | 28 +- .../java/com/kuvaszuptime/kuvasz/Keys.java | 62 +--- .../com/kuvaszuptime/kuvasz/Sequences.java | 11 +- .../java/com/kuvaszuptime/kuvasz/Tables.java | 2 +- .../kuvaszuptime/kuvasz/enums/SslStatus.java | 2 +- .../kuvasz/enums/UptimeStatus.java | 2 +- .../kuvasz/tables/LatencyLog.java | 42 +-- .../kuvaszuptime/kuvasz/tables/Monitor.java | 45 +-- .../kuvaszuptime/kuvasz/tables/SslEvent.java | 48 +-- .../kuvasz/tables/UptimeEvent.java | 48 +-- .../kuvasz/tables/pojos/LatencyLogPojo.java | 44 ++- .../kuvasz/tables/pojos/MonitorPojo.java | 71 ++++- .../kuvasz/tables/pojos/SslEventPojo.java | 68 ++++- .../kuvasz/tables/pojos/UptimeEventPojo.java | 68 ++++- .../tables/records/LatencyLogRecord.java | 28 +- .../kuvasz/tables/records/MonitorRecord.java | 35 ++- .../kuvasz/tables/records/SslEventRecord.java | 40 +-- .../tables/records/UptimeEventRecord.java | 40 +-- .../com/kuvaszuptime/kuvasz/Application.kt | 2 +- .../kuvasz/config/SMTPMailerConfig.kt | 2 +- .../config/handlers/SMTPEventHandlerConfig.kt | 2 +- .../handlers/TelegramEventHandlerConfig.kt | 2 +- .../kuvasz/controllers/MonitorController.kt | 20 +- .../kuvasz/controllers/MonitorOperations.kt | 36 +-- .../kuvasz/factories/LogbookFactory.kt | 2 +- .../kuvasz/handlers/HandlersInfoSource.kt | 2 +- .../kuvasz/models/events/MonitorEvent.kt | 2 +- .../repositories/LatencyLogRepository.kt | 2 +- .../kuvasz/repositories/MonitorRepository.kt | 13 +- .../kuvasz/repositories/SSLEventRepository.kt | 2 +- .../repositories/UptimeEventRepository.kt | 2 +- .../kuvasz/security/AdminAuthProvider.kt | 13 +- .../kuvasz/services/CheckScheduler.kt | 2 +- .../kuvasz/services/DatabaseCleaner.kt | 2 +- .../kuvasz/services/EventDispatcher.kt | 2 +- .../services/HttpCommunicationLogger.kt | 2 +- .../kuvasz/services/MonitorCrudService.kt | 2 +- .../kuvasz/services/SMTPMailer.kt | 7 +- .../kuvasz/services/SSLChecker.kt | 2 +- .../kuvasz/services/SSLValidator.kt | 8 +- .../kuvasz/services/SlackWebhookService.kt | 2 +- .../kuvasz/services/TelegramAPIService.kt | 2 +- .../kuvasz/services/UptimeChecker.kt | 6 +- .../validation/UsernamePasswordNotEquals.kt | 2 +- .../native-image.properties | 4 +- .../kuvasz-application/reflect-config.json | 6 +- .../kuvasz-application/resource-config.json | 2 +- .../kuvasz/DatabaseBehaviorSpec.kt | 2 +- .../kuvasz/config/AppConfigTest.kt | 2 +- .../config/TelegramEventHandlerConfigTest.kt | 12 +- .../controllers/GlobalErrorHandlerTest.kt | 215 ++++++++------ .../kuvasz/controllers/InfoEndpointTest.kt | 2 +- .../controllers/MonitorControllerTest.kt | 4 +- .../kuvasz/handlers/SlackEventHandlerTest.kt | 19 +- .../handlers/TelegramEventHandlerTest.kt | 19 +- .../formatters/LogMessageFormatterTest.kt | 17 +- .../PlainTextMessageFormatterTest.kt | 16 +- .../formatters/SlackTextFormatterTest.kt | 14 +- .../formatters/TelegramTextFormatterTest.kt | 14 +- .../kuvasz/security/AuthenticationTest.kt | 2 +- .../kuvasz/services/CheckSchedulerTest.kt | 2 +- .../kuvasz/services/SSLCheckerTest.kt | 6 +- .../kuvasz/testutils/MicronautTestUtils.kt | 26 -- .../kuvasz/testutils/TestDbContainer.kt | 5 +- .../kuvasz/testutils/TestMailhogContainer.kt | 33 +-- 76 files changed, 977 insertions(+), 957 deletions(-) delete mode 100644 Dockerfile delete mode 100755 docker-build-native.sh delete mode 100644 micronaut-cli.yml delete mode 100644 src/test/kotlin/com/kuvaszuptime/kuvasz/testutils/MicronautTestUtils.kt diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ba52f41..0b8e2e9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -29,6 +29,3 @@ jobs: with: token: ${{ secrets.CODECOV_UPLOAD_TOKEN }} fail_ci_if_error: false - - name: Build shadowJar - run: ./gradlew shadowJar - diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 158b56d..0000000 --- a/Dockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM oracle/graalvm-ce:20.3.0-java11 as graalvm -ARG VERSION="" -RUN gu install native-image - -COPY . /home/app/kuvasz -WORKDIR /home/app/kuvasz - -RUN native-image --no-server --verbose -cp build/libs/kuvasz-${VERSION}-all.jar \ ---initialize-at-build-time=com.sun.mail.util.LineInputStream - -FROM frolvlad/alpine-glibc:alpine-3.12_glibc-2.32 -RUN apk --no-cache add libstdc++ -EXPOSE 8080 -COPY --from=graalvm /home/app/kuvasz/kuvasz /app/kuvasz -ENTRYPOINT ["/app/kuvasz", "-Xms64M ", "-Xmx128m", "-Dio.netty.allocator.maxOrder=8"] diff --git a/build.gradle b/build.gradle index 063db15..676b7ed 100644 --- a/build.gradle +++ b/build.gradle @@ -12,21 +12,23 @@ plugins { id "org.jetbrains.kotlin.plugin.allopen" version "${kotlinVersion}" id "application" id "com.google.cloud.tools.jib" version "${jibVersion}" - id "com.github.johnrengelman.shadow" version "${shadowVersion}" id "io.gitlab.arturbosch.detekt" version "${detektVersion}" id "jacoco" id "nu.studer.jooq" version "${jooqPluginVersion}" id "com.palantir.git-version" version "${palantirGitVersion}" - id "name.remal.check-updates" version "${checkUpdatesVersion}" + id "com.github.ben-manes.versions" version "${checkUpdatesVersion}" id "io.micronaut.application" version "${micronautPluginVersion}" + id "org.jlleitschuh.gradle.ktlint" version "${ktLintPluginVersion}" + id "org.flywaydb.flyway" version "${flywayPluginVersion}" } version gitVersion() group "com.kuvaszuptime.kuvasz" +def javaTargetVersion = "11" repositories { + gradlePluginPortal() mavenCentral() - jcenter() } micronaut { @@ -45,51 +47,48 @@ configurations { } dependencies { - kapt("io.micronaut:micronaut-graal") - kapt("io.micronaut.configuration:micronaut-openapi") + kapt("io.micronaut.openapi:micronaut-openapi") kapt("io.micronaut.security:micronaut-security-annotations") + kapt("io.micronaut:micronaut-graal") + runtimeOnly("com.fasterxml.jackson.module:jackson-module-kotlin") compileOnly("org.graalvm.nativeimage:svm") - implementation("io.micronaut:micronaut-validation") + implementation "nu.studer:gradle-jooq-plugin:$jooqPluginVersion" + implementation("ch.qos.logback:logback-classic") implementation("io.arrow-kt:arrow-core-data:${arrowDataVersion}") - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:${kotlinCoroutinesVersion}") - implementation("io.micronaut:micronaut-validation") - implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}") - implementation("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}") - implementation("io.micronaut.kotlin:micronaut-kotlin-runtime") - implementation("io.micronaut:micronaut-runtime") - implementation("javax.annotation:javax.annotation-api") - implementation("io.micronaut:micronaut-http-client") - implementation("io.swagger.core.v3:swagger-annotations") implementation("io.micronaut.flyway:micronaut-flyway") + implementation("io.micronaut.kotlin:micronaut-kotlin-extension-functions") + implementation("io.micronaut.kotlin:micronaut-kotlin-runtime") + implementation("io.micronaut.rxjava2:micronaut-rxjava2") + implementation("io.micronaut.rxjava2:micronaut-rxjava2-http-client") + implementation("io.micronaut.security:micronaut-security-jwt") implementation("io.micronaut.sql:micronaut-jdbc-hikari") implementation("io.micronaut.sql:micronaut-jooq") - implementation("io.micronaut.security:micronaut-security-jwt") - implementation("io.micronaut.kotlin:micronaut-kotlin-extension-functions") - implementation "nu.studer:gradle-jooq-plugin:$jooqPluginVersion" + implementation("io.micronaut:micronaut-http-client") + implementation("io.micronaut:micronaut-runtime") + implementation("io.micronaut:micronaut-validation") + implementation("io.micronaut:micronaut-validation") + implementation("io.swagger.core.v3:swagger-annotations") + implementation("javax.annotation:javax.annotation-api") + implementation("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}") + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}") + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:${kotlinCoroutinesVersion}") implementation("org.postgresql:postgresql:${postgresVersion}") - implementation("org.simplejavamail:simple-java-mail:${simpleJavaMailVersion}") implementation("org.simplejavamail:batch-module:${simpleJavaMailVersion}") - implementation("ch.qos.logback:logback-classic") + implementation("org.simplejavamail:simple-java-mail:${simpleJavaMailVersion}") implementation("org.zalando:logbook-core:$logbookVersion") - implementation("org.zalando:logbook-netty:$logbookVersion") implementation("org.zalando:logbook-json:$logbookVersion") - runtimeOnly("com.fasterxml.jackson.module:jackson-module-kotlin") - detektPlugins "io.gitlab.arturbosch.detekt:detekt-formatting:$detektVersion" + implementation("org.zalando:logbook-netty:$logbookVersion") + jooqGenerator("org.postgresql:postgresql:${postgresVersion}") testImplementation("io.mockk:mockk:${mockkVersion}") testImplementation("org.testcontainers:postgresql:${postgresTestContainersVersion}") - jooqGenerator("org.postgresql:postgresql:${postgresVersion}") } test.classpath += configurations.developmentOnly mainClassName = "com.kuvaszuptime.kuvasz.Application" -shadowJar { - mergeServiceFiles() -} - jacoco { - toolVersion = "0.8.5" + toolVersion = jacocoVersion } jacocoTestReport { @@ -136,6 +135,11 @@ detekt { ) } +ktlint { + version.set(ktLintVersion) + disabledRules = ["no-wildcard-imports"] +} + build { dependsOn("detekt") } @@ -149,15 +153,16 @@ test { } java { - sourceCompatibility = JavaVersion.toVersion('11') + sourceCompatibility = JavaVersion.toVersion(javaTargetVersion) } allOpen { - annotation("io.micronaut.aop.Around") + annotation("jakarta.inject.Singleton") } + compileKotlin { kotlinOptions { - jvmTarget = '11' + jvmTarget = javaTargetVersion //Will retain parameter names for Java reflection javaParameters = true freeCompilerArgs += "-Xuse-experimental=kotlin.time.ExperimentalTime" @@ -166,7 +171,7 @@ compileKotlin { } compileTestKotlin { kotlinOptions { - jvmTarget = '11' + jvmTarget = javaTargetVersion javaParameters = true freeCompilerArgs += "-Xuse-experimental=kotlin.time.ExperimentalTime" } @@ -194,6 +199,9 @@ tasks.withType(JavaExec) { } jib { + from { + image = "gcr.io/distroless/java:11" + } to { image = "kuvaszmonitoring/kuvasz:${version}" tags = ["latest"] @@ -203,12 +211,6 @@ jib { } } -task buildNativeImage(type: Exec) { - dependsOn("shadowJar") - workingDir projectDir - commandLine "sh", "./docker-build-native.sh", "-v${version}" -} - task pushNativeImage(type: Exec) { workingDir projectDir commandLine "sh", "./docker-push-native.sh", "-t${version}-native" @@ -216,10 +218,10 @@ task pushNativeImage(type: Exec) { task releaseDockerImages() { dependsOn("jib") - dependsOn("buildNativeImage") + dependsOn("dockerBuildNative") dependsOn("pushNativeImage") - tasks.findByName("buildNativeImage").mustRunAfter "jib" - tasks.findByName("pushNativeImage").mustRunAfter "buildNativeImage" + tasks.findByName("dockerBuildNative").mustRunAfter "jib" + tasks.findByName("pushNativeImage").mustRunAfter "dockerBuildNative" } task updateApiDoc(type: Copy) { @@ -228,6 +230,12 @@ task updateApiDoc(type: Copy) { into "$projectDir/docs/api-doc" } +def dbUrl = "jdbc:postgresql://localhost:5432/postgres" +def dbUser = "postgres" +def dbPassword = System.getenv("DB_PASSWORD") ?: "pass" +def dbSchema = "kuvasz" +def dbDriver = "org.postgresql.Driver" + jooq { version = jooqVersion configurations { @@ -235,9 +243,9 @@ jooq { generateSchemaSourceOnCompilation = false generationTool { jdbc { - url = "jdbc:postgresql://localhost:5432/postgres" - user = "postgres" - password = "pass" + url = dbUrl + user = dbUser + password = dbPassword driver = "org.postgresql.Driver" } generator { @@ -253,7 +261,7 @@ jooq { fluentSetters = true } database { - inputSchema = "kuvasz" + inputSchema = dbSchema outputSchemaToDefault = true excludes = "flyway_schema_history" } @@ -275,3 +283,19 @@ jooq { } } } + +flyway { + url = dbUrl + user = dbUser + password = dbPassword + schemas = [dbSchema] + driver = dbDriver +} + +tasks.named("dockerfileNative") { + args("-Xms64M ", "-Xmx128m", "-Dio.netty.allocator.maxOrder=8") +} + +tasks.named("dockerBuildNative") { + images = ["kuvaszmonitoring/kuvasz:$version-native", "kuvaszmonitoring/kuvasz:latest-native"] +} diff --git a/config/detekt/detekt.yml b/config/detekt/detekt.yml index 6ac5826..425295b 100644 --- a/config/detekt/detekt.yml +++ b/config/detekt/detekt.yml @@ -2,10 +2,10 @@ build: maxIssues: 0 excludeCorrectable: false weights: - # complexity: 2 - # LongParameterList: 1 - # style: 1 - # comments: 1 + # complexity: 2 + # LongParameterList: 1 + # style: 1 + # comments: 1 config: validation: true @@ -25,15 +25,14 @@ processors: console-reports: active: true exclude: - # - 'ProjectStatisticsReport' - # - 'ComplexityReport' - - 'NotificationReport' - # - 'FindingsReport' - - 'FileBasedFindingsReport' + # - 'ProjectStatisticsReport' + # - 'ComplexityReport' + - 'NotificationReport' + # - 'FindingsReport' + - 'FileBasedFindingsReport' comments: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] AbsentOrWrongFileLicense: active: false licenseTemplateFile: 'license.template' @@ -65,19 +64,21 @@ complexity: threshold: 10 includeStaticDeclarations: false includePrivateDeclarations: false + excludes: [ '**/controllers/**' ] ComplexMethod: active: true threshold: 15 ignoreSingleWhenExpression: false ignoreSimpleWhenEntries: false ignoreNestingFunctions: false - nestingFunctions: [run, let, apply, with, also, use, forEach, isNotNull, ifNull] + nestingFunctions: [ run, let, apply, with, also, use, forEach, isNotNull, ifNull ] LabeledExpression: active: false - ignoredLabels: [] + ignoredLabels: [ ] LargeClass: active: true threshold: 600 + excludes: [ '**/test/**' ] LongMethod: active: true threshold: 60 @@ -87,7 +88,8 @@ complexity: constructorThreshold: 7 ignoreDefaultParameters: false ignoreDataClasses: true - ignoreAnnotated: [] + ignoreAnnotated: [ ] + excludes: [ '**/test/**' ] MethodOverloading: active: false threshold: 6 @@ -96,14 +98,14 @@ complexity: threshold: 4 StringLiteralDuplication: active: false - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] threshold: 3 ignoreAnnotation: true excludeStringsWithLessThan5Characters: true ignoreStringsRegex: '$^' TooManyFunctions: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**', '**/controllers/**' ] thresholdInFiles: 11 thresholdInClasses: 11 thresholdInInterfaces: 11 @@ -159,10 +161,10 @@ exceptions: active: true ExceptionRaisedInUnexpectedLocation: active: true - methodNames: [toString, hashCode, equals, finalize] + methodNames: [ toString, hashCode, equals, finalize ] InstanceOfCheckForException: active: false - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] NotImplementedDeclaration: active: true PrintStackTrace: @@ -175,10 +177,10 @@ exceptions: SwallowedException: active: false ignoredExceptionTypes: - - InterruptedException - - NumberFormatException - - ParseException - - MalformedURLException + - InterruptedException + - NumberFormatException + - ParseException + - MalformedURLException allowedExceptionNameRegex: '_|(ignore|expected).*' ThrowingExceptionFromFinally: active: false @@ -187,190 +189,74 @@ exceptions: ThrowingExceptionsWithoutMessageOrCause: active: false exceptions: - - IllegalArgumentException - - IllegalStateException - - IOException + - IllegalArgumentException + - IllegalStateException + - IOException ThrowingNewInstanceOfSameException: active: false TooGenericExceptionCaught: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] exceptionNames: - - ArrayIndexOutOfBoundsException - - Error - - Exception - - IllegalMonitorStateException - - NullPointerException - - IndexOutOfBoundsException - - RuntimeException - - Throwable + - ArrayIndexOutOfBoundsException + - Error + - Exception + - IllegalMonitorStateException + - NullPointerException + - IndexOutOfBoundsException + - RuntimeException + - Throwable allowedExceptionNameRegex: '_|(ignore|expected).*' TooGenericExceptionThrown: active: true exceptionNames: - - Error - - Exception - - Throwable - - RuntimeException + - Error + - Exception + - Throwable + - RuntimeException formatting: - active: true - android: false - autoCorrect: true - AnnotationOnSeparateLine: - active: false - autoCorrect: true - ChainWrapping: - active: true - autoCorrect: true - CommentSpacing: - active: true - autoCorrect: true - EnumEntryNameCase: - active: false - autoCorrect: true - Filename: - active: true - FinalNewline: - active: true - autoCorrect: true - insertFinalNewLine: true - ImportOrdering: - active: true - autoCorrect: true - layout: 'idea' - Indentation: - active: false - autoCorrect: true - indentSize: 4 - continuationIndentSize: 4 - MaximumLineLength: - active: true - maxLineLength: 120 - ModifierOrdering: - active: true - autoCorrect: true - MultiLineIfElse: - active: true - autoCorrect: true - NoBlankLineBeforeRbrace: - active: true - autoCorrect: true - NoConsecutiveBlankLines: - active: true - autoCorrect: true - NoEmptyClassBody: - active: true - autoCorrect: true - NoEmptyFirstLineInMethodBlock: - active: false - autoCorrect: true - NoLineBreakAfterElse: - active: true - autoCorrect: true - NoLineBreakBeforeAssignment: - active: true - autoCorrect: true - NoMultipleSpaces: - active: true - autoCorrect: true - NoSemicolons: - active: true - autoCorrect: true - NoTrailingSpaces: - active: true - autoCorrect: true - NoUnitReturn: - active: true - autoCorrect: true - NoUnusedImports: - active: true - autoCorrect: true - NoWildcardImports: - active: true - PackageName: - active: true - autoCorrect: true - ParameterListWrapping: - active: true - autoCorrect: true - indentSize: 4 - SpacingAroundColon: - active: true - autoCorrect: true - SpacingAroundComma: - active: true - autoCorrect: true - SpacingAroundCurly: - active: true - autoCorrect: true - SpacingAroundDot: - active: true - autoCorrect: true - SpacingAroundDoubleColon: - active: false - autoCorrect: true - SpacingAroundKeyword: - active: true - autoCorrect: true - SpacingAroundOperators: - active: true - autoCorrect: true - SpacingAroundParens: - active: true - autoCorrect: true - SpacingAroundRangeOperator: - active: true - autoCorrect: true - SpacingBetweenDeclarationsWithAnnotations: - active: false - autoCorrect: true - SpacingBetweenDeclarationsWithComments: - active: false - autoCorrect: true - StringTemplate: - active: true - autoCorrect: true + active: false naming: active: true ClassNaming: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] classPattern: '[A-Z][a-zA-Z0-9]*' ConstructorParameterNaming: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] parameterPattern: '[a-z][A-Za-z0-9]*' privateParameterPattern: '[a-z][A-Za-z0-9]*' excludeClassPattern: '$^' ignoreOverridden: true EnumNaming: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] enumEntryPattern: '[A-Z][_a-zA-Z0-9]*' ForbiddenClassName: active: false - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] - forbiddenName: [] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] + forbiddenName: [ ] FunctionMaxLength: active: false - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] maximumFunctionNameLength: 30 FunctionMinLength: active: false - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] minimumFunctionNameLength: 3 FunctionNaming: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] functionPattern: '([a-z][a-zA-Z0-9]*)|(`.*`)' excludeClassPattern: '$^' ignoreOverridden: true - ignoreAnnotated: ['Composable'] + ignoreAnnotated: [ 'Composable' ] FunctionParameterNaming: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] parameterPattern: '[a-z][A-Za-z0-9]*' excludeClassPattern: '$^' ignoreOverridden: true @@ -385,31 +271,31 @@ naming: ignoreOverridden: true ObjectPropertyNaming: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] constantPattern: '[A-Za-z][_A-Za-z0-9]*' propertyPattern: '[A-Za-z][_A-Za-z0-9]*' privatePropertyPattern: '(_)?[A-Za-z][_A-Za-z0-9]*' PackageNaming: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] packagePattern: '[a-z]+(\.[a-z][A-Za-z0-9]*)*' TopLevelPropertyNaming: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] constantPattern: '[A-Z][_A-Z0-9]*' propertyPattern: '[A-Za-z][_A-Za-z0-9]*' privatePropertyPattern: '_?[A-Za-z][_A-Za-z0-9]*' VariableMaxLength: active: false - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] maximumVariableNameLength: 64 VariableMinLength: active: false - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] minimumVariableNameLength: 1 VariableNaming: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] variablePattern: '[a-z][A-Za-z0-9]*' privateVariablePattern: '(_)?[a-z][A-Za-z0-9]*' excludeClassPattern: '$^' @@ -421,10 +307,10 @@ performance: active: true ForEachOnRange: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] SpreadOperator: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] UnnecessaryTemporaryInstantiation: active: true @@ -445,7 +331,7 @@ potential-bugs: IgnoredReturnValue: active: false restrictToAnnotatedMethods: true - returnValueAnnotations: ['*.CheckReturnValue', '*.CheckResult'] + returnValueAnnotations: [ '*.CheckReturnValue', '*.CheckResult' ] ImplicitDefaultLocale: active: false ImplicitUnitReturnType: @@ -459,13 +345,14 @@ potential-bugs: active: true LateinitUsage: active: false - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] - excludeAnnotatedProperties: [] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] + ignoreAnnotated: [ ] ignoreOnClassesPattern: '' MapGetWithNotNullAssertionOperator: - active: false + active: true MissingWhenCase: active: true + allowElseExpression: false RedundantElseInWhen: active: true UnconditionalJumpStatementInLoop: @@ -473,7 +360,7 @@ potential-bugs: UnnecessaryNotNullOperator: active: true UnnecessarySafeCall: - active: false + active: true UnreachableCode: active: true UnsafeCallOnNullableType: @@ -481,7 +368,7 @@ potential-bugs: UnsafeCast: active: true UselessPostfixExpression: - active: false + active: true WrongEqualsTypeParameter: active: true @@ -493,7 +380,7 @@ style: active: false conversionFunctionPrefix: 'to' DataClassShouldBeImmutable: - active: false + active: true EqualsNullCall: active: true EqualsOnSignatureLine: @@ -501,24 +388,24 @@ style: ExplicitCollectionElementAccessMethod: active: false ExplicitItLambdaParameter: - active: false + active: true ExpressionBodySyntax: active: false includeLineWrapping: false ForbiddenComment: active: true - values: ['TODO:', 'FIXME:', 'STOPSHIP:'] + values: [ 'TODO:', 'FIXME:', 'STOPSHIP:' ] allowedPatterns: '' ForbiddenImport: active: false - imports: [] + imports: [ ] forbiddenPatterns: '' ForbiddenMethodCall: active: false - methods: ['kotlin.io.println', 'kotlin.io.print'] + methods: [ 'kotlin.io.println', 'kotlin.io.print' ] ForbiddenPublicDataClass: active: false - ignorePackages: ['*.internal', '*.internal.*'] + ignorePackages: [ '*.internal', '*.internal.*' ] ForbiddenVoid: active: false ignoreOverridden: false @@ -527,7 +414,7 @@ style: active: true ignoreOverridableFunction: true excludedFunctions: 'describeContents' - excludeAnnotatedFunction: ['dagger.Provides'] + ignoreAnnotated: [ 'dagger.Provides' ] LibraryCodeMustSpecifyReturnType: active: true LoopWithTooManyJumpStatements: @@ -535,8 +422,8 @@ style: maxJumpCount: 1 MagicNumber: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] - ignoreNumbers: ['-1', '0', '1', '2'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] + ignoreNumbers: [ '-1', '0', '1', '2' ] ignoreHashCodeFunction: true ignorePropertyDeclaration: false ignoreLocalVariableDeclaration: false @@ -560,6 +447,8 @@ style: active: true ModifierOrder: active: true + MultilineLambdaItParameter: + active: true NestedClassesVisibility: active: false NewLineAtEndOfFile: @@ -600,10 +489,10 @@ style: active: false UnderscoresInNumericLiterals: active: false - acceptableDecimalLength: 5 + acceptableLength: 5 UnnecessaryAbstractClass: active: true - excludeAnnotatedClasses: ['dagger.Module'] + ignoreAnnotated: [ 'dagger.Module' ] UnnecessaryAnnotationUseSiteTarget: active: false UnnecessaryApply: @@ -629,8 +518,12 @@ style: active: false UseDataClass: active: false - excludeAnnotatedClasses: [] + ignoreAnnotated: [ ] allowVars: false + UseEmptyCounterpart: + active: true + UseIfEmptyOrIfBlank: + active: true UseIfInsteadOfWhen: active: true UseRequire: @@ -642,6 +535,6 @@ style: VarCouldBeVal: active: true WildcardImport: - active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] - excludeImports: ['java.util.*', 'kotlinx.android.synthetic.*'] + active: false + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ] + excludeImports: [ 'java.util.*', 'kotlinx.android.synthetic.*' ] diff --git a/docker-build-native.sh b/docker-build-native.sh deleted file mode 100755 index 6a0b200..0000000 --- a/docker-build-native.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh -VERSION="" -TAG="" -DIR="$(cd "$(dirname "$0")" && pwd)" - -while getopts 'v:' OPTION; do - case "$OPTION" in - v) VERSION=$OPTARG ;; - *) exit 1 ;; - esac -done - -TAG="${VERSION}-native" - -echo "Building docker image with tag: ${TAG}..." -docker build . -t kuvaszmonitoring/kuvasz:${TAG} -t kuvaszmonitoring/kuvasz:latest-native --build-arg VERSION=${VERSION} -echo "Building docker image with tag: ${TAG}...OK" diff --git a/docs/api-doc/kuvasz-latest.yml b/docs/api-doc/kuvasz-latest.yml index f311f26..5010a78 100644 --- a/docs/api-doc/kuvasz-latest.yml +++ b/docs/api-doc/kuvasz-latest.yml @@ -12,30 +12,6 @@ tags: - name: Management operations - name: Monitor operations paths: - /login: - post: - tags: - - Security operations - summary: Login endpoint - description: After a successful login it returns a valid access token that you - should use in your authenticated request - operationId: login - parameters: [] - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/UserNamePasswordCredentials' - required: true - responses: - "200": - description: Successful login - content: - application/json: - schema: - $ref: '#/components/schemas/BearerAccessRefreshToken' - "401": - description: Unauthorized /health: get: tags: @@ -80,6 +56,30 @@ paths: slack-event-handler.enabled: true telegram-event-handler.enabled: true pagerduty-event-handler.enabled: true + /login: + post: + tags: + - Security operations + summary: Login endpoint + description: After a successful login it returns a valid access token that you + should use in your authenticated request + operationId: login + parameters: [] + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/UserNamePasswordCredentials' + required: true + responses: + "200": + description: Successful login + content: + application/json: + schema: + $ref: '#/components/schemas/BearerAccessRefreshToken' + "401": + description: Unauthorized /monitors: get: tags: @@ -284,12 +284,12 @@ paths: $ref: '#/components/schemas/ServiceError' security: - bearerAuth: [] - /monitors/{monitorId}/uptime-events: + /monitors/{monitorId}/ssl-events: get: tags: - Monitor operations - summary: Returns the uptime events of the given monitor - operationId: getUptimeEvents + summary: Returns the SSL events of the given monitor + operationId: getSSLEvents parameters: - name: monitorId in: path @@ -305,15 +305,15 @@ paths: schema: type: array items: - $ref: '#/components/schemas/UptimeEventDto' + $ref: '#/components/schemas/SSLEventDto' security: - bearerAuth: [] - /monitors/{monitorId}/ssl-events: + /monitors/{monitorId}/uptime-events: get: tags: - Monitor operations - summary: Returns the SSL events of the given monitor - operationId: getSSLEvents + summary: Returns the uptime events of the given monitor + operationId: getUptimeEvents parameters: - name: monitorId in: path @@ -329,18 +329,11 @@ paths: schema: type: array items: - $ref: '#/components/schemas/SSLEventDto' + $ref: '#/components/schemas/UptimeEventDto' security: - bearerAuth: [] components: schemas: - UserNamePasswordCredentials: - type: object - properties: - username: - type: string - password: - type: string BearerAccessRefreshToken: type: object properties: @@ -376,7 +369,42 @@ components: properties: handlers: type: object + MonitorCreateDto: + required: + - name + - uptimeCheckInterval + - url + type: object + properties: + name: + minLength: 1 + type: string + url: + pattern: "^(https?)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]" + type: string + uptimeCheckInterval: + minimum: 60 + type: integer + format: int32 + enabled: + type: boolean + nullable: true + sslCheckEnabled: + type: boolean + nullable: true + pagerdutyIntegrationKey: + type: string + nullable: true MonitorDetailsDto: + required: + - createdAt + - enabled + - id + - name + - pagerdutyKeyPresent + - sslCheckEnabled + - uptimeCheckInterval + - url type: object properties: id: @@ -402,7 +430,9 @@ components: format: date-time nullable: true uptimeStatus: - $ref: '#/components/schemas/UptimeStatus' + allOf: + - $ref: '#/components/schemas/UptimeStatus' + - nullable: true uptimeStatusStartedAt: type: string format: date-time @@ -412,7 +442,9 @@ components: format: date-time nullable: true sslStatus: - $ref: '#/components/schemas/SslStatus' + allOf: + - $ref: '#/components/schemas/SslStatus' + - nullable: true sslStatusStartedAt: type: string format: date-time @@ -431,34 +463,26 @@ components: type: integer format: int32 nullable: true - p95LatencyInMs: + P95LatencyInMs: type: integer format: int32 nullable: true - p99LatencyInMs: + P99LatencyInMs: type: integer format: int32 nullable: true pagerdutyKeyPresent: type: boolean - UptimeStatus: - type: string - enum: - - UP - - DOWN - SslStatus: - type: string - enum: - - VALID - - INVALID - - WILL_EXPIRE - ServiceError: - type: object - properties: - message: - type: string - nullable: true MonitorDto: + required: + - createdAt + - enabled + - id + - name + - pagerdutyKeyPresent + - sslCheckEnabled + - uptimeCheckInterval + - url type: object properties: id: @@ -484,32 +508,6 @@ components: type: string format: date-time nullable: true - MonitorCreateDto: - required: - - name - - uptimeCheckInterval - - url - type: object - properties: - name: - minLength: 1 - type: string - url: - pattern: "^(https?)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]" - type: string - uptimeCheckInterval: - minimum: 60 - type: integer - format: int32 - enabled: - type: boolean - nullable: true - sslCheckEnabled: - type: boolean - nullable: true - pagerdutyIntegrationKey: - type: string - nullable: true MonitorUpdateDto: type: object properties: @@ -539,11 +537,15 @@ components: pagerdutyIntegrationKey: minLength: 1 type: string - UptimeEventDto: + SSLEventDto: + required: + - startedAt + - status + - updatedAt type: object properties: status: - $ref: '#/components/schemas/UptimeStatus' + $ref: '#/components/schemas/SslStatus' error: type: string nullable: true @@ -557,11 +559,27 @@ components: updatedAt: type: string format: date-time - SSLEventDto: + ServiceError: + type: object + properties: + message: + type: string + nullable: true + SslStatus: + type: string + enum: + - VALID + - INVALID + - WILL_EXPIRE + UptimeEventDto: + required: + - startedAt + - status + - updatedAt type: object properties: status: - $ref: '#/components/schemas/SslStatus' + $ref: '#/components/schemas/UptimeStatus' error: type: string nullable: true @@ -575,6 +593,18 @@ components: updatedAt: type: string format: date-time + UptimeStatus: + type: string + enum: + - UP + - DOWN + UserNamePasswordCredentials: + type: object + properties: + username: + type: string + password: + type: string securitySchemes: bearerAuth: type: http diff --git a/gradle.properties b/gradle.properties index 80d6611..957d8fc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,17 +1,20 @@ -arrowDataVersion=0.11.0 -checkUpdatesVersion=1.1.4 -detektVersion=1.14.2 -jibVersion=2.6.0 -jooqPluginVersion=5.2 -jooqVersion=3.13.1 -kotlinCoroutinesVersion=1.4.1 -kotlinVersion=1.4.20 -logbookVersion=2.4.1 -micronautPluginVersion=1.2.0 -micronautVersion=2.1.4 -mockkVersion=1.10.2 +arrowDataVersion=0.12.1 +checkUpdatesVersion=0.40.0 +detektVersion=1.19.0 +flywayPluginVersion=8.3.0 +jacocoVersion=0.8.7 +jibVersion=3.1.4 +jooqPluginVersion=6.0.1 +jooqVersion=3.14.12 +kotlinCoroutinesVersion=1.6.0 +kotlinVersion=1.6.10 +ktLintPluginVersion=10.2.1 +ktLintVersion=0.43.2 +logbookVersion=2.14.0 +micronautPluginVersion=3.1.1 +micronautVersion=3.2.4 +mockkVersion=1.12.2 palantirGitVersion=0.12.3 -postgresTestContainersVersion=1.15.0 -postgresVersion=42.2.18 -shadowVersion=6.1.0 -simpleJavaMailVersion=6.4.4 +postgresTestContainersVersion=1.16.2 +postgresVersion=42.3.1 +simpleJavaMailVersion=7.0.0 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9216860..ed17507 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ #Sat Jul 18 09:10:10 CEST 2020 -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStorePath=wrapper/dists diff --git a/micronaut-cli.yml b/micronaut-cli.yml deleted file mode 100644 index 699cf24..0000000 --- a/micronaut-cli.yml +++ /dev/null @@ -1,6 +0,0 @@ -applicationType: default -defaultPackage: com.kuvaszuptime.kuvasz -testFramework: kotlintest -sourceLanguage: kotlin -buildTool: gradle -features: [annotation-api, app-name, docker, file-watch, flyway, graalvm, gradle, http-client, jackson-xml, jdbc-hikari, jib, jooq, kotlin, kotlin-application, kotlin-extension-functions, kotlintest, logback, netty-server, openapi, postgres, properties, readme, security, security-annotations] diff --git a/src/jooq/java/com/kuvaszuptime/kuvasz/DefaultCatalog.java b/src/jooq/java/com/kuvaszuptime/kuvasz/DefaultCatalog.java index e282655..76ba603 100644 --- a/src/jooq/java/com/kuvaszuptime/kuvasz/DefaultCatalog.java +++ b/src/jooq/java/com/kuvaszuptime/kuvasz/DefaultCatalog.java @@ -17,7 +17,7 @@ @SuppressWarnings({ "all", "unchecked", "rawtypes" }) public class DefaultCatalog extends CatalogImpl { - private static final long serialVersionUID = 1946704898; + private static final long serialVersionUID = 1L; /** * The reference instance of DEFAULT_CATALOG diff --git a/src/jooq/java/com/kuvaszuptime/kuvasz/DefaultSchema.java b/src/jooq/java/com/kuvaszuptime/kuvasz/DefaultSchema.java index 585310f..3ef84a6 100644 --- a/src/jooq/java/com/kuvaszuptime/kuvasz/DefaultSchema.java +++ b/src/jooq/java/com/kuvaszuptime/kuvasz/DefaultSchema.java @@ -24,7 +24,7 @@ @SuppressWarnings({ "all", "unchecked", "rawtypes" }) public class DefaultSchema extends SchemaImpl { - private static final long serialVersionUID = -839450692; + private static final long serialVersionUID = 1L; /** * The reference instance of DEFAULT_SCHEMA diff --git a/src/jooq/java/com/kuvaszuptime/kuvasz/Indexes.java b/src/jooq/java/com/kuvaszuptime/kuvasz/Indexes.java index ddc13fb..0452808 100644 --- a/src/jooq/java/com/kuvaszuptime/kuvasz/Indexes.java +++ b/src/jooq/java/com/kuvaszuptime/kuvasz/Indexes.java @@ -10,11 +10,12 @@ import org.jooq.Index; import org.jooq.OrderField; +import org.jooq.impl.DSL; import org.jooq.impl.Internal; /** - * A class modelling indexes of tables of the schema. + * A class modelling indexes of tables in the default schema. */ @SuppressWarnings({ "all", "unchecked", "rawtypes" }) public class Indexes { @@ -23,23 +24,10 @@ public class Indexes { // INDEX definitions // ------------------------------------------------------------------------- - public static final Index LATENCY_LOG_LATENCY_IDX = Indexes0.LATENCY_LOG_LATENCY_IDX; - public static final Index LATENCY_LOG_MONITOR_IDX = Indexes0.LATENCY_LOG_MONITOR_IDX; - public static final Index SSL_EVENT_ENDED_AT_IDX = Indexes0.SSL_EVENT_ENDED_AT_IDX; - public static final Index SSL_EVENT_MONITOR_IDX = Indexes0.SSL_EVENT_MONITOR_IDX; - public static final Index UPTIME_EVENT_ENDED_AT_IDX = Indexes0.UPTIME_EVENT_ENDED_AT_IDX; - public static final Index UPTIME_EVENT_MONITOR_IDX = Indexes0.UPTIME_EVENT_MONITOR_IDX; - - // ------------------------------------------------------------------------- - // [#1459] distribute members to avoid static initialisers > 64kb - // ------------------------------------------------------------------------- - - private static class Indexes0 { - public static Index LATENCY_LOG_LATENCY_IDX = Internal.createIndex("latency_log_latency_idx", LatencyLog.LATENCY_LOG, new OrderField[] { LatencyLog.LATENCY_LOG.LATENCY }, false); - public static Index LATENCY_LOG_MONITOR_IDX = Internal.createIndex("latency_log_monitor_idx", LatencyLog.LATENCY_LOG, new OrderField[] { LatencyLog.LATENCY_LOG.MONITOR_ID }, false); - public static Index SSL_EVENT_ENDED_AT_IDX = Internal.createIndex("ssl_event_ended_at_idx", SslEvent.SSL_EVENT, new OrderField[] { SslEvent.SSL_EVENT.ENDED_AT }, false); - public static Index SSL_EVENT_MONITOR_IDX = Internal.createIndex("ssl_event_monitor_idx", SslEvent.SSL_EVENT, new OrderField[] { SslEvent.SSL_EVENT.MONITOR_ID }, false); - public static Index UPTIME_EVENT_ENDED_AT_IDX = Internal.createIndex("uptime_event_ended_at_idx", UptimeEvent.UPTIME_EVENT, new OrderField[] { UptimeEvent.UPTIME_EVENT.ENDED_AT }, false); - public static Index UPTIME_EVENT_MONITOR_IDX = Internal.createIndex("uptime_event_monitor_idx", UptimeEvent.UPTIME_EVENT, new OrderField[] { UptimeEvent.UPTIME_EVENT.MONITOR_ID }, false); - } + public static final Index LATENCY_LOG_LATENCY_IDX = Internal.createIndex(DSL.name("latency_log_latency_idx"), LatencyLog.LATENCY_LOG, new OrderField[] { LatencyLog.LATENCY_LOG.LATENCY }, false); + public static final Index LATENCY_LOG_MONITOR_IDX = Internal.createIndex(DSL.name("latency_log_monitor_idx"), LatencyLog.LATENCY_LOG, new OrderField[] { LatencyLog.LATENCY_LOG.MONITOR_ID }, false); + public static final Index SSL_EVENT_ENDED_AT_IDX = Internal.createIndex(DSL.name("ssl_event_ended_at_idx"), SslEvent.SSL_EVENT, new OrderField[] { SslEvent.SSL_EVENT.ENDED_AT }, false); + public static final Index SSL_EVENT_MONITOR_IDX = Internal.createIndex(DSL.name("ssl_event_monitor_idx"), SslEvent.SSL_EVENT, new OrderField[] { SslEvent.SSL_EVENT.MONITOR_ID }, false); + public static final Index UPTIME_EVENT_ENDED_AT_IDX = Internal.createIndex(DSL.name("uptime_event_ended_at_idx"), UptimeEvent.UPTIME_EVENT, new OrderField[] { UptimeEvent.UPTIME_EVENT.ENDED_AT }, false); + public static final Index UPTIME_EVENT_MONITOR_IDX = Internal.createIndex(DSL.name("uptime_event_monitor_idx"), UptimeEvent.UPTIME_EVENT, new OrderField[] { UptimeEvent.UPTIME_EVENT.MONITOR_ID }, false); } diff --git a/src/jooq/java/com/kuvaszuptime/kuvasz/Keys.java b/src/jooq/java/com/kuvaszuptime/kuvasz/Keys.java index 3893437..1c54833 100644 --- a/src/jooq/java/com/kuvaszuptime/kuvasz/Keys.java +++ b/src/jooq/java/com/kuvaszuptime/kuvasz/Keys.java @@ -14,72 +14,36 @@ import com.kuvaszuptime.kuvasz.tables.records.UptimeEventRecord; import org.jooq.ForeignKey; -import org.jooq.Identity; import org.jooq.TableField; import org.jooq.UniqueKey; +import org.jooq.impl.DSL; import org.jooq.impl.Internal; /** - * A class modelling foreign key relationships and constraints of tables of - * the schema. + * A class modelling foreign key relationships and constraints of tables in + * the default schema. */ @SuppressWarnings({ "all", "unchecked", "rawtypes" }) public class Keys { - // ------------------------------------------------------------------------- - // IDENTITY definitions - // ------------------------------------------------------------------------- - - public static final Identity IDENTITY_LATENCY_LOG = Identities0.IDENTITY_LATENCY_LOG; - public static final Identity IDENTITY_MONITOR = Identities0.IDENTITY_MONITOR; - public static final Identity IDENTITY_SSL_EVENT = Identities0.IDENTITY_SSL_EVENT; - public static final Identity IDENTITY_UPTIME_EVENT = Identities0.IDENTITY_UPTIME_EVENT; - // ------------------------------------------------------------------------- // UNIQUE and PRIMARY KEY definitions // ------------------------------------------------------------------------- - public static final UniqueKey LATENCY_LOG_PKEY = UniqueKeys0.LATENCY_LOG_PKEY; - public static final UniqueKey MONITOR_PKEY = UniqueKeys0.MONITOR_PKEY; - public static final UniqueKey UNIQUE_MONITOR_NAME = UniqueKeys0.UNIQUE_MONITOR_NAME; - public static final UniqueKey SSL_EVENT_PKEY = UniqueKeys0.SSL_EVENT_PKEY; - public static final UniqueKey SSL_EVENT_KEY = UniqueKeys0.SSL_EVENT_KEY; - public static final UniqueKey UPTIME_EVENT_PKEY = UniqueKeys0.UPTIME_EVENT_PKEY; - public static final UniqueKey UPTIME_EVENT_KEY = UniqueKeys0.UPTIME_EVENT_KEY; + public static final UniqueKey LATENCY_LOG_PKEY = Internal.createUniqueKey(LatencyLog.LATENCY_LOG, DSL.name("latency_log_pkey"), new TableField[] { LatencyLog.LATENCY_LOG.ID }, true); + public static final UniqueKey MONITOR_PKEY = Internal.createUniqueKey(Monitor.MONITOR, DSL.name("monitor_pkey"), new TableField[] { Monitor.MONITOR.ID }, true); + public static final UniqueKey UNIQUE_MONITOR_NAME = Internal.createUniqueKey(Monitor.MONITOR, DSL.name("unique_monitor_name"), new TableField[] { Monitor.MONITOR.NAME }, true); + public static final UniqueKey SSL_EVENT_KEY = Internal.createUniqueKey(SslEvent.SSL_EVENT, DSL.name("ssl_event_key"), new TableField[] { SslEvent.SSL_EVENT.MONITOR_ID, SslEvent.SSL_EVENT.STATUS, SslEvent.SSL_EVENT.ENDED_AT }, true); + public static final UniqueKey SSL_EVENT_PKEY = Internal.createUniqueKey(SslEvent.SSL_EVENT, DSL.name("ssl_event_pkey"), new TableField[] { SslEvent.SSL_EVENT.ID }, true); + public static final UniqueKey UPTIME_EVENT_KEY = Internal.createUniqueKey(UptimeEvent.UPTIME_EVENT, DSL.name("uptime_event_key"), new TableField[] { UptimeEvent.UPTIME_EVENT.MONITOR_ID, UptimeEvent.UPTIME_EVENT.STATUS, UptimeEvent.UPTIME_EVENT.ENDED_AT }, true); + public static final UniqueKey UPTIME_EVENT_PKEY = Internal.createUniqueKey(UptimeEvent.UPTIME_EVENT, DSL.name("uptime_event_pkey"), new TableField[] { UptimeEvent.UPTIME_EVENT.ID }, true); // ------------------------------------------------------------------------- // FOREIGN KEY definitions // ------------------------------------------------------------------------- - public static final ForeignKey LATENCY_LOG__LATENCY_LOG_MONITOR_ID_FKEY = ForeignKeys0.LATENCY_LOG__LATENCY_LOG_MONITOR_ID_FKEY; - public static final ForeignKey SSL_EVENT__SSL_EVENT_MONITOR_ID_FKEY = ForeignKeys0.SSL_EVENT__SSL_EVENT_MONITOR_ID_FKEY; - public static final ForeignKey UPTIME_EVENT__UPTIME_EVENT_MONITOR_ID_FKEY = ForeignKeys0.UPTIME_EVENT__UPTIME_EVENT_MONITOR_ID_FKEY; - - // ------------------------------------------------------------------------- - // [#1459] distribute members to avoid static initialisers > 64kb - // ------------------------------------------------------------------------- - - private static class Identities0 { - public static Identity IDENTITY_LATENCY_LOG = Internal.createIdentity(LatencyLog.LATENCY_LOG, LatencyLog.LATENCY_LOG.ID); - public static Identity IDENTITY_MONITOR = Internal.createIdentity(Monitor.MONITOR, Monitor.MONITOR.ID); - public static Identity IDENTITY_SSL_EVENT = Internal.createIdentity(SslEvent.SSL_EVENT, SslEvent.SSL_EVENT.ID); - public static Identity IDENTITY_UPTIME_EVENT = Internal.createIdentity(UptimeEvent.UPTIME_EVENT, UptimeEvent.UPTIME_EVENT.ID); - } - - private static class UniqueKeys0 { - public static final UniqueKey LATENCY_LOG_PKEY = Internal.createUniqueKey(LatencyLog.LATENCY_LOG, "latency_log_pkey", new TableField[] { LatencyLog.LATENCY_LOG.ID }, true); - public static final UniqueKey MONITOR_PKEY = Internal.createUniqueKey(Monitor.MONITOR, "monitor_pkey", new TableField[] { Monitor.MONITOR.ID }, true); - public static final UniqueKey UNIQUE_MONITOR_NAME = Internal.createUniqueKey(Monitor.MONITOR, "unique_monitor_name", new TableField[] { Monitor.MONITOR.NAME }, true); - public static final UniqueKey SSL_EVENT_PKEY = Internal.createUniqueKey(SslEvent.SSL_EVENT, "ssl_event_pkey", new TableField[] { SslEvent.SSL_EVENT.ID }, true); - public static final UniqueKey SSL_EVENT_KEY = Internal.createUniqueKey(SslEvent.SSL_EVENT, "ssl_event_key", new TableField[] { SslEvent.SSL_EVENT.MONITOR_ID, SslEvent.SSL_EVENT.STATUS, SslEvent.SSL_EVENT.ENDED_AT }, true); - public static final UniqueKey UPTIME_EVENT_PKEY = Internal.createUniqueKey(UptimeEvent.UPTIME_EVENT, "uptime_event_pkey", new TableField[] { UptimeEvent.UPTIME_EVENT.ID }, true); - public static final UniqueKey UPTIME_EVENT_KEY = Internal.createUniqueKey(UptimeEvent.UPTIME_EVENT, "uptime_event_key", new TableField[] { UptimeEvent.UPTIME_EVENT.MONITOR_ID, UptimeEvent.UPTIME_EVENT.STATUS, UptimeEvent.UPTIME_EVENT.ENDED_AT }, true); - } - - private static class ForeignKeys0 { - public static final ForeignKey LATENCY_LOG__LATENCY_LOG_MONITOR_ID_FKEY = Internal.createForeignKey(Keys.MONITOR_PKEY, LatencyLog.LATENCY_LOG, "latency_log_monitor_id_fkey", new TableField[] { LatencyLog.LATENCY_LOG.MONITOR_ID }, true); - public static final ForeignKey SSL_EVENT__SSL_EVENT_MONITOR_ID_FKEY = Internal.createForeignKey(Keys.MONITOR_PKEY, SslEvent.SSL_EVENT, "ssl_event_monitor_id_fkey", new TableField[] { SslEvent.SSL_EVENT.MONITOR_ID }, true); - public static final ForeignKey UPTIME_EVENT__UPTIME_EVENT_MONITOR_ID_FKEY = Internal.createForeignKey(Keys.MONITOR_PKEY, UptimeEvent.UPTIME_EVENT, "uptime_event_monitor_id_fkey", new TableField[] { UptimeEvent.UPTIME_EVENT.MONITOR_ID }, true); - } + public static final ForeignKey LATENCY_LOG__LATENCY_LOG_MONITOR_ID_FKEY = Internal.createForeignKey(LatencyLog.LATENCY_LOG, DSL.name("latency_log_monitor_id_fkey"), new TableField[] { LatencyLog.LATENCY_LOG.MONITOR_ID }, Keys.MONITOR_PKEY, new TableField[] { Monitor.MONITOR.ID }, true); + public static final ForeignKey SSL_EVENT__SSL_EVENT_MONITOR_ID_FKEY = Internal.createForeignKey(SslEvent.SSL_EVENT, DSL.name("ssl_event_monitor_id_fkey"), new TableField[] { SslEvent.SSL_EVENT.MONITOR_ID }, Keys.MONITOR_PKEY, new TableField[] { Monitor.MONITOR.ID }, true); + public static final ForeignKey UPTIME_EVENT__UPTIME_EVENT_MONITOR_ID_FKEY = Internal.createForeignKey(UptimeEvent.UPTIME_EVENT, DSL.name("uptime_event_monitor_id_fkey"), new TableField[] { UptimeEvent.UPTIME_EVENT.MONITOR_ID }, Keys.MONITOR_PKEY, new TableField[] { Monitor.MONITOR.ID }, true); } diff --git a/src/jooq/java/com/kuvaszuptime/kuvasz/Sequences.java b/src/jooq/java/com/kuvaszuptime/kuvasz/Sequences.java index df920b2..aab809d 100644 --- a/src/jooq/java/com/kuvaszuptime/kuvasz/Sequences.java +++ b/src/jooq/java/com/kuvaszuptime/kuvasz/Sequences.java @@ -6,10 +6,11 @@ import org.jooq.Sequence; import org.jooq.impl.Internal; +import org.jooq.impl.SQLDataType; /** - * Convenience access to all sequences in + * Convenience access to all sequences in the default schema. */ @SuppressWarnings({ "all", "unchecked", "rawtypes" }) public class Sequences { @@ -17,20 +18,20 @@ public class Sequences { /** * The sequence latency_log_id_seq */ - public static final Sequence LATENCY_LOG_ID_SEQ = Internal.createSequence("latency_log_id_seq", DefaultSchema.DEFAULT_SCHEMA, org.jooq.impl.SQLDataType.INTEGER.nullable(false), null, null, null, null, false, null); + public static final Sequence LATENCY_LOG_ID_SEQ = Internal.createSequence("latency_log_id_seq", DefaultSchema.DEFAULT_SCHEMA, SQLDataType.INTEGER.nullable(false), null, null, null, null, false, null); /** * The sequence monitor_id_seq */ - public static final Sequence MONITOR_ID_SEQ = Internal.createSequence("monitor_id_seq", DefaultSchema.DEFAULT_SCHEMA, org.jooq.impl.SQLDataType.INTEGER.nullable(false), null, null, null, null, false, null); + public static final Sequence MONITOR_ID_SEQ = Internal.createSequence("monitor_id_seq", DefaultSchema.DEFAULT_SCHEMA, SQLDataType.INTEGER.nullable(false), null, null, null, null, false, null); /** * The sequence ssl_event_id_seq */ - public static final Sequence SSL_EVENT_ID_SEQ = Internal.createSequence("ssl_event_id_seq", DefaultSchema.DEFAULT_SCHEMA, org.jooq.impl.SQLDataType.INTEGER.nullable(false), null, null, null, null, false, null); + public static final Sequence SSL_EVENT_ID_SEQ = Internal.createSequence("ssl_event_id_seq", DefaultSchema.DEFAULT_SCHEMA, SQLDataType.INTEGER.nullable(false), null, null, null, null, false, null); /** * The sequence uptime_event_id_seq */ - public static final Sequence UPTIME_EVENT_ID_SEQ = Internal.createSequence("uptime_event_id_seq", DefaultSchema.DEFAULT_SCHEMA, org.jooq.impl.SQLDataType.INTEGER.nullable(false), null, null, null, null, false, null); + public static final Sequence UPTIME_EVENT_ID_SEQ = Internal.createSequence("uptime_event_id_seq", DefaultSchema.DEFAULT_SCHEMA, SQLDataType.INTEGER.nullable(false), null, null, null, null, false, null); } diff --git a/src/jooq/java/com/kuvaszuptime/kuvasz/Tables.java b/src/jooq/java/com/kuvaszuptime/kuvasz/Tables.java index 086ba4a..46525ad 100644 --- a/src/jooq/java/com/kuvaszuptime/kuvasz/Tables.java +++ b/src/jooq/java/com/kuvaszuptime/kuvasz/Tables.java @@ -11,7 +11,7 @@ /** - * Convenience access to all tables in + * Convenience access to all tables in the default schema. */ @SuppressWarnings({ "all", "unchecked", "rawtypes" }) public class Tables { diff --git a/src/jooq/java/com/kuvaszuptime/kuvasz/enums/SslStatus.java b/src/jooq/java/com/kuvaszuptime/kuvasz/enums/SslStatus.java index aee39d5..689c5b6 100644 --- a/src/jooq/java/com/kuvaszuptime/kuvasz/enums/SslStatus.java +++ b/src/jooq/java/com/kuvaszuptime/kuvasz/enums/SslStatus.java @@ -31,7 +31,7 @@ private SslStatus(String literal) { @Override public Catalog getCatalog() { - return getSchema() == null ? null : getSchema().getCatalog(); + return getSchema().getCatalog(); } @Override diff --git a/src/jooq/java/com/kuvaszuptime/kuvasz/enums/UptimeStatus.java b/src/jooq/java/com/kuvaszuptime/kuvasz/enums/UptimeStatus.java index 9c95501..1eeb57a 100644 --- a/src/jooq/java/com/kuvaszuptime/kuvasz/enums/UptimeStatus.java +++ b/src/jooq/java/com/kuvaszuptime/kuvasz/enums/UptimeStatus.java @@ -29,7 +29,7 @@ private UptimeStatus(String literal) { @Override public Catalog getCatalog() { - return getSchema() == null ? null : getSchema().getCatalog(); + return getSchema().getCatalog(); } @Override diff --git a/src/jooq/java/com/kuvaszuptime/kuvasz/tables/LatencyLog.java b/src/jooq/java/com/kuvaszuptime/kuvasz/tables/LatencyLog.java index 616e72d..9e69dda 100644 --- a/src/jooq/java/com/kuvaszuptime/kuvasz/tables/LatencyLog.java +++ b/src/jooq/java/com/kuvaszuptime/kuvasz/tables/LatencyLog.java @@ -26,6 +26,7 @@ import org.jooq.TableOptions; import org.jooq.UniqueKey; import org.jooq.impl.DSL; +import org.jooq.impl.SQLDataType; import org.jooq.impl.TableImpl; @@ -35,7 +36,7 @@ @SuppressWarnings({ "all", "unchecked", "rawtypes" }) public class LatencyLog extends TableImpl { - private static final long serialVersionUID = -466401116; + private static final long serialVersionUID = 1L; /** * The reference instance of latency_log @@ -53,28 +54,29 @@ public Class getRecordType() { /** * The column latency_log.id. */ - public final TableField ID = createField(DSL.name("id"), org.jooq.impl.SQLDataType.INTEGER.nullable(false).defaultValue(org.jooq.impl.DSL.field("nextval('kuvasz.latency_log_id_seq'::regclass)", org.jooq.impl.SQLDataType.INTEGER)), this, ""); + public final TableField ID = createField(DSL.name("id"), SQLDataType.INTEGER.nullable(false).identity(true), this, ""); /** * The column latency_log.monitor_id. */ - public final TableField MONITOR_ID = createField(DSL.name("monitor_id"), org.jooq.impl.SQLDataType.INTEGER.nullable(false), this, ""); + public final TableField MONITOR_ID = createField(DSL.name("monitor_id"), SQLDataType.INTEGER.nullable(false), this, ""); /** * The column latency_log.latency. Lateny in ms */ - public final TableField LATENCY = createField(DSL.name("latency"), org.jooq.impl.SQLDataType.INTEGER.nullable(false), this, "Lateny in ms"); + public final TableField LATENCY = createField(DSL.name("latency"), SQLDataType.INTEGER.nullable(false), this, "Lateny in ms"); /** * The column latency_log.created_at. */ - public final TableField CREATED_AT = createField(DSL.name("created_at"), org.jooq.impl.SQLDataType.TIMESTAMPWITHTIMEZONE.nullable(false).defaultValue(org.jooq.impl.DSL.field("now()", org.jooq.impl.SQLDataType.TIMESTAMPWITHTIMEZONE)), this, ""); + public final TableField CREATED_AT = createField(DSL.name("created_at"), SQLDataType.TIMESTAMPWITHTIMEZONE(6).nullable(false).defaultValue(DSL.field("now()", SQLDataType.TIMESTAMPWITHTIMEZONE)), this, ""); - /** - * Create a latency_log table reference - */ - public LatencyLog() { - this(DSL.name("latency_log"), null); + private LatencyLog(Name alias, Table aliased) { + this(alias, aliased, null); + } + + private LatencyLog(Name alias, Table aliased, Field[] parameters) { + super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.table()); } /** @@ -91,12 +93,11 @@ public LatencyLog(Name alias) { this(alias, LATENCY_LOG); } - private LatencyLog(Name alias, Table aliased) { - this(alias, aliased, null); - } - - private LatencyLog(Name alias, Table aliased, Field[] parameters) { - super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.table()); + /** + * Create a latency_log table reference + */ + public LatencyLog() { + this(DSL.name("latency_log"), null); } public LatencyLog(Table child, ForeignKey key) { @@ -115,7 +116,7 @@ public List getIndexes() { @Override public Identity getIdentity() { - return Keys.IDENTITY_LATENCY_LOG; + return (Identity) super.getIdentity(); } @Override @@ -133,8 +134,13 @@ public List> getKeys() { return Arrays.>asList(Keys.LATENCY_LOG__LATENCY_LOG_MONITOR_ID_FKEY); } + private transient Monitor _monitor; + public Monitor monitor() { - return new Monitor(this, Keys.LATENCY_LOG__LATENCY_LOG_MONITOR_ID_FKEY); + if (_monitor == null) + _monitor = new Monitor(this, Keys.LATENCY_LOG__LATENCY_LOG_MONITOR_ID_FKEY); + + return _monitor; } @Override diff --git a/src/jooq/java/com/kuvaszuptime/kuvasz/tables/Monitor.java b/src/jooq/java/com/kuvaszuptime/kuvasz/tables/Monitor.java index 186ea2d..fccedf7 100644 --- a/src/jooq/java/com/kuvaszuptime/kuvasz/tables/Monitor.java +++ b/src/jooq/java/com/kuvaszuptime/kuvasz/tables/Monitor.java @@ -24,6 +24,7 @@ import org.jooq.TableOptions; import org.jooq.UniqueKey; import org.jooq.impl.DSL; +import org.jooq.impl.SQLDataType; import org.jooq.impl.TableImpl; @@ -33,7 +34,7 @@ @SuppressWarnings({ "all", "unchecked", "rawtypes" }) public class Monitor extends TableImpl { - private static final long serialVersionUID = 2078797674; + private static final long serialVersionUID = 1L; /** * The reference instance of monitor @@ -51,53 +52,54 @@ public Class getRecordType() { /** * The column monitor.id. */ - public final TableField ID = createField(DSL.name("id"), org.jooq.impl.SQLDataType.INTEGER.nullable(false).defaultValue(org.jooq.impl.DSL.field("nextval('kuvasz.monitor_id_seq'::regclass)", org.jooq.impl.SQLDataType.INTEGER)), this, ""); + public final TableField ID = createField(DSL.name("id"), SQLDataType.INTEGER.nullable(false).identity(true), this, ""); /** * The column monitor.name. Monitor's name */ - public final TableField NAME = createField(DSL.name("name"), org.jooq.impl.SQLDataType.VARCHAR(255).nullable(false), this, "Monitor's name"); + public final TableField NAME = createField(DSL.name("name"), SQLDataType.VARCHAR(255).nullable(false), this, "Monitor's name"); /** * The column monitor.url. URL to check */ - public final TableField URL = createField(DSL.name("url"), org.jooq.impl.SQLDataType.CLOB.nullable(false), this, "URL to check"); + public final TableField URL = createField(DSL.name("url"), SQLDataType.CLOB.nullable(false), this, "URL to check"); /** * The column monitor.uptime_check_interval. Uptime checking interval in seconds */ - public final TableField UPTIME_CHECK_INTERVAL = createField(DSL.name("uptime_check_interval"), org.jooq.impl.SQLDataType.INTEGER.nullable(false), this, "Uptime checking interval in seconds"); + public final TableField UPTIME_CHECK_INTERVAL = createField(DSL.name("uptime_check_interval"), SQLDataType.INTEGER.nullable(false), this, "Uptime checking interval in seconds"); /** * The column monitor.enabled. Flag to toggle the monitor */ - public final TableField ENABLED = createField(DSL.name("enabled"), org.jooq.impl.SQLDataType.BOOLEAN.nullable(false).defaultValue(org.jooq.impl.DSL.field("true", org.jooq.impl.SQLDataType.BOOLEAN)), this, "Flag to toggle the monitor"); + public final TableField ENABLED = createField(DSL.name("enabled"), SQLDataType.BOOLEAN.nullable(false).defaultValue(DSL.field("true", SQLDataType.BOOLEAN)), this, "Flag to toggle the monitor"); /** * The column monitor.created_at. */ - public final TableField CREATED_AT = createField(DSL.name("created_at"), org.jooq.impl.SQLDataType.TIMESTAMPWITHTIMEZONE.nullable(false).defaultValue(org.jooq.impl.DSL.field("now()", org.jooq.impl.SQLDataType.TIMESTAMPWITHTIMEZONE)), this, ""); + public final TableField CREATED_AT = createField(DSL.name("created_at"), SQLDataType.TIMESTAMPWITHTIMEZONE(6).nullable(false).defaultValue(DSL.field("now()", SQLDataType.TIMESTAMPWITHTIMEZONE)), this, ""); /** * The column monitor.updated_at. */ - public final TableField UPDATED_AT = createField(DSL.name("updated_at"), org.jooq.impl.SQLDataType.TIMESTAMPWITHTIMEZONE, this, ""); + public final TableField UPDATED_AT = createField(DSL.name("updated_at"), SQLDataType.TIMESTAMPWITHTIMEZONE(6), this, ""); /** * The column monitor.ssl_check_enabled. */ - public final TableField SSL_CHECK_ENABLED = createField(DSL.name("ssl_check_enabled"), org.jooq.impl.SQLDataType.BOOLEAN.nullable(false).defaultValue(org.jooq.impl.DSL.field("false", org.jooq.impl.SQLDataType.BOOLEAN)), this, ""); + public final TableField SSL_CHECK_ENABLED = createField(DSL.name("ssl_check_enabled"), SQLDataType.BOOLEAN.nullable(false).defaultValue(DSL.field("false", SQLDataType.BOOLEAN)), this, ""); /** * The column monitor.pagerduty_integration_key. */ - public final TableField PAGERDUTY_INTEGRATION_KEY = createField(DSL.name("pagerduty_integration_key"), org.jooq.impl.SQLDataType.VARCHAR, this, ""); + public final TableField PAGERDUTY_INTEGRATION_KEY = createField(DSL.name("pagerduty_integration_key"), SQLDataType.VARCHAR, this, ""); - /** - * Create a monitor table reference - */ - public Monitor() { - this(DSL.name("monitor"), null); + private Monitor(Name alias, Table aliased) { + this(alias, aliased, null); + } + + private Monitor(Name alias, Table aliased, Field[] parameters) { + super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.table()); } /** @@ -114,12 +116,11 @@ public Monitor(Name alias) { this(alias, MONITOR); } - private Monitor(Name alias, Table aliased) { - this(alias, aliased, null); - } - - private Monitor(Name alias, Table aliased, Field[] parameters) { - super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.table()); + /** + * Create a monitor table reference + */ + public Monitor() { + this(DSL.name("monitor"), null); } public Monitor(Table child, ForeignKey key) { @@ -133,7 +134,7 @@ public Schema getSchema() { @Override public Identity getIdentity() { - return Keys.IDENTITY_MONITOR; + return (Identity) super.getIdentity(); } @Override diff --git a/src/jooq/java/com/kuvaszuptime/kuvasz/tables/SslEvent.java b/src/jooq/java/com/kuvaszuptime/kuvasz/tables/SslEvent.java index ca91bc4..d3cb7d0 100644 --- a/src/jooq/java/com/kuvaszuptime/kuvasz/tables/SslEvent.java +++ b/src/jooq/java/com/kuvaszuptime/kuvasz/tables/SslEvent.java @@ -27,6 +27,7 @@ import org.jooq.TableOptions; import org.jooq.UniqueKey; import org.jooq.impl.DSL; +import org.jooq.impl.SQLDataType; import org.jooq.impl.TableImpl; @@ -36,7 +37,7 @@ @SuppressWarnings({ "all", "unchecked", "rawtypes" }) public class SslEvent extends TableImpl { - private static final long serialVersionUID = 2029223819; + private static final long serialVersionUID = 1L; /** * The reference instance of ssl_event @@ -54,43 +55,44 @@ public Class getRecordType() { /** * The column ssl_event.id. */ - public final TableField ID = createField(DSL.name("id"), org.jooq.impl.SQLDataType.INTEGER.nullable(false).defaultValue(org.jooq.impl.DSL.field("nextval('kuvasz.ssl_event_id_seq'::regclass)", org.jooq.impl.SQLDataType.INTEGER)), this, ""); + public final TableField ID = createField(DSL.name("id"), SQLDataType.INTEGER.nullable(false).identity(true), this, ""); /** * The column ssl_event.monitor_id. */ - public final TableField MONITOR_ID = createField(DSL.name("monitor_id"), org.jooq.impl.SQLDataType.INTEGER.nullable(false), this, ""); + public final TableField MONITOR_ID = createField(DSL.name("monitor_id"), SQLDataType.INTEGER.nullable(false), this, ""); /** * The column ssl_event.status. Status of the event */ - public final TableField STATUS = createField(DSL.name("status"), org.jooq.impl.SQLDataType.VARCHAR.nullable(false).asEnumDataType(com.kuvaszuptime.kuvasz.enums.SslStatus.class), this, "Status of the event"); + public final TableField STATUS = createField(DSL.name("status"), SQLDataType.VARCHAR.nullable(false).asEnumDataType(com.kuvaszuptime.kuvasz.enums.SslStatus.class), this, "Status of the event"); /** * The column ssl_event.error. */ - public final TableField ERROR = createField(DSL.name("error"), org.jooq.impl.SQLDataType.CLOB, this, ""); + public final TableField ERROR = createField(DSL.name("error"), SQLDataType.CLOB, this, ""); /** * The column ssl_event.started_at. The current event started at */ - public final TableField STARTED_AT = createField(DSL.name("started_at"), org.jooq.impl.SQLDataType.TIMESTAMPWITHTIMEZONE.nullable(false).defaultValue(org.jooq.impl.DSL.field("now()", org.jooq.impl.SQLDataType.TIMESTAMPWITHTIMEZONE)), this, "The current event started at"); + public final TableField STARTED_AT = createField(DSL.name("started_at"), SQLDataType.TIMESTAMPWITHTIMEZONE(6).nullable(false).defaultValue(DSL.field("now()", SQLDataType.TIMESTAMPWITHTIMEZONE)), this, "The current event started at"); /** * The column ssl_event.ended_at. The current event ended at */ - public final TableField ENDED_AT = createField(DSL.name("ended_at"), org.jooq.impl.SQLDataType.TIMESTAMPWITHTIMEZONE, this, "The current event ended at"); + public final TableField ENDED_AT = createField(DSL.name("ended_at"), SQLDataType.TIMESTAMPWITHTIMEZONE(6), this, "The current event ended at"); /** * The column ssl_event.updated_at. */ - public final TableField UPDATED_AT = createField(DSL.name("updated_at"), org.jooq.impl.SQLDataType.TIMESTAMPWITHTIMEZONE.nullable(false), this, ""); + public final TableField UPDATED_AT = createField(DSL.name("updated_at"), SQLDataType.TIMESTAMPWITHTIMEZONE(6).nullable(false), this, ""); - /** - * Create a ssl_event table reference - */ - public SslEvent() { - this(DSL.name("ssl_event"), null); + private SslEvent(Name alias, Table aliased) { + this(alias, aliased, null); + } + + private SslEvent(Name alias, Table aliased, Field[] parameters) { + super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.table()); } /** @@ -107,12 +109,11 @@ public SslEvent(Name alias) { this(alias, SSL_EVENT); } - private SslEvent(Name alias, Table aliased) { - this(alias, aliased, null); - } - - private SslEvent(Name alias, Table aliased, Field[] parameters) { - super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.table()); + /** + * Create a ssl_event table reference + */ + public SslEvent() { + this(DSL.name("ssl_event"), null); } public SslEvent(Table child, ForeignKey key) { @@ -131,7 +132,7 @@ public List getIndexes() { @Override public Identity getIdentity() { - return Keys.IDENTITY_SSL_EVENT; + return (Identity) super.getIdentity(); } @Override @@ -149,8 +150,13 @@ public List> getKeys() { return Arrays.>asList(Keys.SSL_EVENT__SSL_EVENT_MONITOR_ID_FKEY); } + private transient Monitor _monitor; + public Monitor monitor() { - return new Monitor(this, Keys.SSL_EVENT__SSL_EVENT_MONITOR_ID_FKEY); + if (_monitor == null) + _monitor = new Monitor(this, Keys.SSL_EVENT__SSL_EVENT_MONITOR_ID_FKEY); + + return _monitor; } @Override diff --git a/src/jooq/java/com/kuvaszuptime/kuvasz/tables/UptimeEvent.java b/src/jooq/java/com/kuvaszuptime/kuvasz/tables/UptimeEvent.java index 78d7f57..5114865 100644 --- a/src/jooq/java/com/kuvaszuptime/kuvasz/tables/UptimeEvent.java +++ b/src/jooq/java/com/kuvaszuptime/kuvasz/tables/UptimeEvent.java @@ -27,6 +27,7 @@ import org.jooq.TableOptions; import org.jooq.UniqueKey; import org.jooq.impl.DSL; +import org.jooq.impl.SQLDataType; import org.jooq.impl.TableImpl; @@ -36,7 +37,7 @@ @SuppressWarnings({ "all", "unchecked", "rawtypes" }) public class UptimeEvent extends TableImpl { - private static final long serialVersionUID = -1860882345; + private static final long serialVersionUID = 1L; /** * The reference instance of uptime_event @@ -54,43 +55,44 @@ public Class getRecordType() { /** * The column uptime_event.id. */ - public final TableField ID = createField(DSL.name("id"), org.jooq.impl.SQLDataType.INTEGER.nullable(false).defaultValue(org.jooq.impl.DSL.field("nextval('kuvasz.uptime_event_id_seq'::regclass)", org.jooq.impl.SQLDataType.INTEGER)), this, ""); + public final TableField ID = createField(DSL.name("id"), SQLDataType.INTEGER.nullable(false).identity(true), this, ""); /** * The column uptime_event.monitor_id. */ - public final TableField MONITOR_ID = createField(DSL.name("monitor_id"), org.jooq.impl.SQLDataType.INTEGER.nullable(false), this, ""); + public final TableField MONITOR_ID = createField(DSL.name("monitor_id"), SQLDataType.INTEGER.nullable(false), this, ""); /** * The column uptime_event.status. Status of the event */ - public final TableField STATUS = createField(DSL.name("status"), org.jooq.impl.SQLDataType.VARCHAR.nullable(false).asEnumDataType(com.kuvaszuptime.kuvasz.enums.UptimeStatus.class), this, "Status of the event"); + public final TableField STATUS = createField(DSL.name("status"), SQLDataType.VARCHAR.nullable(false).asEnumDataType(com.kuvaszuptime.kuvasz.enums.UptimeStatus.class), this, "Status of the event"); /** * The column uptime_event.error. */ - public final TableField ERROR = createField(DSL.name("error"), org.jooq.impl.SQLDataType.CLOB, this, ""); + public final TableField ERROR = createField(DSL.name("error"), SQLDataType.CLOB, this, ""); /** * The column uptime_event.started_at. The current event started at */ - public final TableField STARTED_AT = createField(DSL.name("started_at"), org.jooq.impl.SQLDataType.TIMESTAMPWITHTIMEZONE.nullable(false).defaultValue(org.jooq.impl.DSL.field("now()", org.jooq.impl.SQLDataType.TIMESTAMPWITHTIMEZONE)), this, "The current event started at"); + public final TableField STARTED_AT = createField(DSL.name("started_at"), SQLDataType.TIMESTAMPWITHTIMEZONE(6).nullable(false).defaultValue(DSL.field("now()", SQLDataType.TIMESTAMPWITHTIMEZONE)), this, "The current event started at"); /** * The column uptime_event.ended_at. The current event ended at */ - public final TableField ENDED_AT = createField(DSL.name("ended_at"), org.jooq.impl.SQLDataType.TIMESTAMPWITHTIMEZONE, this, "The current event ended at"); + public final TableField ENDED_AT = createField(DSL.name("ended_at"), SQLDataType.TIMESTAMPWITHTIMEZONE(6), this, "The current event ended at"); /** * The column uptime_event.updated_at. */ - public final TableField UPDATED_AT = createField(DSL.name("updated_at"), org.jooq.impl.SQLDataType.TIMESTAMPWITHTIMEZONE.nullable(false), this, ""); + public final TableField UPDATED_AT = createField(DSL.name("updated_at"), SQLDataType.TIMESTAMPWITHTIMEZONE(6).nullable(false), this, ""); - /** - * Create a uptime_event table reference - */ - public UptimeEvent() { - this(DSL.name("uptime_event"), null); + private UptimeEvent(Name alias, Table aliased) { + this(alias, aliased, null); + } + + private UptimeEvent(Name alias, Table aliased, Field[] parameters) { + super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.table()); } /** @@ -107,12 +109,11 @@ public UptimeEvent(Name alias) { this(alias, UPTIME_EVENT); } - private UptimeEvent(Name alias, Table aliased) { - this(alias, aliased, null); - } - - private UptimeEvent(Name alias, Table aliased, Field[] parameters) { - super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.table()); + /** + * Create a uptime_event table reference + */ + public UptimeEvent() { + this(DSL.name("uptime_event"), null); } public UptimeEvent(Table child, ForeignKey key) { @@ -131,7 +132,7 @@ public List getIndexes() { @Override public Identity getIdentity() { - return Keys.IDENTITY_UPTIME_EVENT; + return (Identity) super.getIdentity(); } @Override @@ -149,8 +150,13 @@ public List> getKeys() { return Arrays.>asList(Keys.UPTIME_EVENT__UPTIME_EVENT_MONITOR_ID_FKEY); } + private transient Monitor _monitor; + public Monitor monitor() { - return new Monitor(this, Keys.UPTIME_EVENT__UPTIME_EVENT_MONITOR_ID_FKEY); + if (_monitor == null) + _monitor = new Monitor(this, Keys.UPTIME_EVENT__UPTIME_EVENT_MONITOR_ID_FKEY); + + return _monitor; } @Override diff --git a/src/jooq/java/com/kuvaszuptime/kuvasz/tables/pojos/LatencyLogPojo.java b/src/jooq/java/com/kuvaszuptime/kuvasz/tables/pojos/LatencyLogPojo.java index 730046c..39d887e 100644 --- a/src/jooq/java/com/kuvaszuptime/kuvasz/tables/pojos/LatencyLogPojo.java +++ b/src/jooq/java/com/kuvaszuptime/kuvasz/tables/pojos/LatencyLogPojo.java @@ -23,15 +23,19 @@ */ @SuppressWarnings({ "all", "unchecked", "rawtypes" }) @Entity -@Table(name = "latency_log", uniqueConstraints = { - @UniqueConstraint(name = "latency_log_pkey", columnNames = {"id"}) -}, indexes = { - @Index(name = "latency_log_latency_idx", columnList = "latency ASC"), - @Index(name = "latency_log_monitor_idx", columnList = "monitor_id ASC") -}) +@Table( + name = "latency_log", + uniqueConstraints = { + @UniqueConstraint(name = "latency_log_pkey", columnNames = { "id" }) + }, + indexes = { + @Index(name = "latency_log_latency_idx", columnList = "latency ASC"), + @Index(name = "latency_log_monitor_idx", columnList = "monitor_id ASC") + } +) public class LatencyLogPojo implements Serializable { - private static final long serialVersionUID = 1568220283; + private static final long serialVersionUID = 1L; private Integer id; private Integer monitorId; @@ -59,6 +63,9 @@ public LatencyLogPojo( this.createdAt = createdAt; } + /** + * Getter for latency_log.id. + */ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", nullable = false, precision = 32) @@ -66,38 +73,59 @@ public Integer getId() { return this.id; } + /** + * Setter for latency_log.id. + */ public LatencyLogPojo setId(Integer id) { this.id = id; return this; } + /** + * Getter for latency_log.monitor_id. + */ @Column(name = "monitor_id", nullable = false, precision = 32) @NotNull public Integer getMonitorId() { return this.monitorId; } + /** + * Setter for latency_log.monitor_id. + */ public LatencyLogPojo setMonitorId(Integer monitorId) { this.monitorId = monitorId; return this; } + /** + * Getter for latency_log.latency. Lateny in ms + */ @Column(name = "latency", nullable = false, precision = 32) @NotNull public Integer getLatency() { return this.latency; } + /** + * Setter for latency_log.latency. Lateny in ms + */ public LatencyLogPojo setLatency(Integer latency) { this.latency = latency; return this; } - @Column(name = "created_at", nullable = false) + /** + * Getter for latency_log.created_at. + */ + @Column(name = "created_at", nullable = false, precision = 6) public OffsetDateTime getCreatedAt() { return this.createdAt; } + /** + * Setter for latency_log.created_at. + */ public LatencyLogPojo setCreatedAt(OffsetDateTime createdAt) { this.createdAt = createdAt; return this; diff --git a/src/jooq/java/com/kuvaszuptime/kuvasz/tables/pojos/MonitorPojo.java b/src/jooq/java/com/kuvaszuptime/kuvasz/tables/pojos/MonitorPojo.java index 89ea8a4..0aa088d 100644 --- a/src/jooq/java/com/kuvaszuptime/kuvasz/tables/pojos/MonitorPojo.java +++ b/src/jooq/java/com/kuvaszuptime/kuvasz/tables/pojos/MonitorPojo.java @@ -23,13 +23,16 @@ */ @SuppressWarnings({ "all", "unchecked", "rawtypes" }) @Entity -@Table(name = "monitor", uniqueConstraints = { - @UniqueConstraint(name = "monitor_pkey", columnNames = {"id"}), - @UniqueConstraint(name = "unique_monitor_name", columnNames = {"name"}) -}) +@Table( + name = "monitor", + uniqueConstraints = { + @UniqueConstraint(name = "monitor_pkey", columnNames = { "id" }), + @UniqueConstraint(name = "unique_monitor_name", columnNames = { "name" }) + } +) public class MonitorPojo implements Serializable { - private static final long serialVersionUID = -1828922669; + private static final long serialVersionUID = 1L; private Integer id; private String name; @@ -77,6 +80,9 @@ public MonitorPojo( this.pagerdutyIntegrationKey = pagerdutyIntegrationKey; } + /** + * Getter for monitor.id. + */ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", nullable = false, precision = 32) @@ -84,11 +90,17 @@ public Integer getId() { return this.id; } + /** + * Setter for monitor.id. + */ public MonitorPojo setId(Integer id) { this.id = id; return this; } + /** + * Getter for monitor.name. Monitor's name + */ @Column(name = "name", nullable = false, length = 255) @NotNull @Size(max = 255) @@ -96,78 +108,123 @@ public String getName() { return this.name; } + /** + * Setter for monitor.name. Monitor's name + */ public MonitorPojo setName(String name) { this.name = name; return this; } + /** + * Getter for monitor.url. URL to check + */ @Column(name = "url", nullable = false) @NotNull public String getUrl() { return this.url; } + /** + * Setter for monitor.url. URL to check + */ public MonitorPojo setUrl(String url) { this.url = url; return this; } + /** + * Getter for monitor.uptime_check_interval. Uptime checking interval in seconds + */ @Column(name = "uptime_check_interval", nullable = false, precision = 32) @NotNull public Integer getUptimeCheckInterval() { return this.uptimeCheckInterval; } + /** + * Setter for monitor.uptime_check_interval. Uptime checking interval in seconds + */ public MonitorPojo setUptimeCheckInterval(Integer uptimeCheckInterval) { this.uptimeCheckInterval = uptimeCheckInterval; return this; } + /** + * Getter for monitor.enabled. Flag to toggle the monitor + */ @Column(name = "enabled", nullable = false) public Boolean getEnabled() { return this.enabled; } + /** + * Setter for monitor.enabled. Flag to toggle the monitor + */ public MonitorPojo setEnabled(Boolean enabled) { this.enabled = enabled; return this; } - @Column(name = "created_at", nullable = false) + /** + * Getter for monitor.created_at. + */ + @Column(name = "created_at", nullable = false, precision = 6) public OffsetDateTime getCreatedAt() { return this.createdAt; } + /** + * Setter for monitor.created_at. + */ public MonitorPojo setCreatedAt(OffsetDateTime createdAt) { this.createdAt = createdAt; return this; } - @Column(name = "updated_at") + /** + * Getter for monitor.updated_at. + */ + @Column(name = "updated_at", precision = 6) public OffsetDateTime getUpdatedAt() { return this.updatedAt; } + /** + * Setter for monitor.updated_at. + */ public MonitorPojo setUpdatedAt(OffsetDateTime updatedAt) { this.updatedAt = updatedAt; return this; } + /** + * Getter for monitor.ssl_check_enabled. + */ @Column(name = "ssl_check_enabled", nullable = false) public Boolean getSslCheckEnabled() { return this.sslCheckEnabled; } + /** + * Setter for monitor.ssl_check_enabled. + */ public MonitorPojo setSslCheckEnabled(Boolean sslCheckEnabled) { this.sslCheckEnabled = sslCheckEnabled; return this; } + /** + * Getter for monitor.pagerduty_integration_key. + */ @Column(name = "pagerduty_integration_key") public String getPagerdutyIntegrationKey() { return this.pagerdutyIntegrationKey; } + /** + * Setter for monitor.pagerduty_integration_key. + */ public MonitorPojo setPagerdutyIntegrationKey(String pagerdutyIntegrationKey) { this.pagerdutyIntegrationKey = pagerdutyIntegrationKey; return this; diff --git a/src/jooq/java/com/kuvaszuptime/kuvasz/tables/pojos/SslEventPojo.java b/src/jooq/java/com/kuvaszuptime/kuvasz/tables/pojos/SslEventPojo.java index e3ee89e..9750bd2 100644 --- a/src/jooq/java/com/kuvaszuptime/kuvasz/tables/pojos/SslEventPojo.java +++ b/src/jooq/java/com/kuvaszuptime/kuvasz/tables/pojos/SslEventPojo.java @@ -25,16 +25,20 @@ */ @SuppressWarnings({ "all", "unchecked", "rawtypes" }) @Entity -@Table(name = "ssl_event", uniqueConstraints = { - @UniqueConstraint(name = "ssl_event_pkey", columnNames = {"id"}), - @UniqueConstraint(name = "ssl_event_key", columnNames = {"monitor_id", "status", "ended_at"}) -}, indexes = { - @Index(name = "ssl_event_ended_at_idx", columnList = "ended_at ASC"), - @Index(name = "ssl_event_monitor_idx", columnList = "monitor_id ASC") -}) +@Table( + name = "ssl_event", + uniqueConstraints = { + @UniqueConstraint(name = "ssl_event_pkey", columnNames = { "id" }), + @UniqueConstraint(name = "ssl_event_key", columnNames = { "monitor_id", "status", "ended_at" }) + }, + indexes = { + @Index(name = "ssl_event_ended_at_idx", columnList = "ended_at ASC"), + @Index(name = "ssl_event_monitor_idx", columnList = "monitor_id ASC") + } +) public class SslEventPojo implements Serializable { - private static final long serialVersionUID = -231279334; + private static final long serialVersionUID = 1L; private Integer id; private Integer monitorId; @@ -74,6 +78,9 @@ public SslEventPojo( this.updatedAt = updatedAt; } + /** + * Getter for ssl_event.id. + */ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", nullable = false, precision = 32) @@ -81,69 +88,108 @@ public Integer getId() { return this.id; } + /** + * Setter for ssl_event.id. + */ public SslEventPojo setId(Integer id) { this.id = id; return this; } + /** + * Getter for ssl_event.monitor_id. + */ @Column(name = "monitor_id", nullable = false, precision = 32) @NotNull public Integer getMonitorId() { return this.monitorId; } + /** + * Setter for ssl_event.monitor_id. + */ public SslEventPojo setMonitorId(Integer monitorId) { this.monitorId = monitorId; return this; } + /** + * Getter for ssl_event.status. Status of the event + */ @Column(name = "status", nullable = false) @NotNull public SslStatus getStatus() { return this.status; } + /** + * Setter for ssl_event.status. Status of the event + */ public SslEventPojo setStatus(SslStatus status) { this.status = status; return this; } + /** + * Getter for ssl_event.error. + */ @Column(name = "error") public String getError() { return this.error; } + /** + * Setter for ssl_event.error. + */ public SslEventPojo setError(String error) { this.error = error; return this; } - @Column(name = "started_at", nullable = false) + /** + * Getter for ssl_event.started_at. The current event started at + */ + @Column(name = "started_at", nullable = false, precision = 6) public OffsetDateTime getStartedAt() { return this.startedAt; } + /** + * Setter for ssl_event.started_at. The current event started at + */ public SslEventPojo setStartedAt(OffsetDateTime startedAt) { this.startedAt = startedAt; return this; } - @Column(name = "ended_at") + /** + * Getter for ssl_event.ended_at. The current event ended at + */ + @Column(name = "ended_at", precision = 6) public OffsetDateTime getEndedAt() { return this.endedAt; } + /** + * Setter for ssl_event.ended_at. The current event ended at + */ public SslEventPojo setEndedAt(OffsetDateTime endedAt) { this.endedAt = endedAt; return this; } - @Column(name = "updated_at", nullable = false) + /** + * Getter for ssl_event.updated_at. + */ + @Column(name = "updated_at", nullable = false, precision = 6) @NotNull public OffsetDateTime getUpdatedAt() { return this.updatedAt; } + /** + * Setter for ssl_event.updated_at. + */ public SslEventPojo setUpdatedAt(OffsetDateTime updatedAt) { this.updatedAt = updatedAt; return this; diff --git a/src/jooq/java/com/kuvaszuptime/kuvasz/tables/pojos/UptimeEventPojo.java b/src/jooq/java/com/kuvaszuptime/kuvasz/tables/pojos/UptimeEventPojo.java index e1ed1b4..5178a78 100644 --- a/src/jooq/java/com/kuvaszuptime/kuvasz/tables/pojos/UptimeEventPojo.java +++ b/src/jooq/java/com/kuvaszuptime/kuvasz/tables/pojos/UptimeEventPojo.java @@ -25,16 +25,20 @@ */ @SuppressWarnings({ "all", "unchecked", "rawtypes" }) @Entity -@Table(name = "uptime_event", uniqueConstraints = { - @UniqueConstraint(name = "uptime_event_pkey", columnNames = {"id"}), - @UniqueConstraint(name = "uptime_event_key", columnNames = {"monitor_id", "status", "ended_at"}) -}, indexes = { - @Index(name = "uptime_event_ended_at_idx", columnList = "ended_at ASC"), - @Index(name = "uptime_event_monitor_idx", columnList = "monitor_id ASC") -}) +@Table( + name = "uptime_event", + uniqueConstraints = { + @UniqueConstraint(name = "uptime_event_pkey", columnNames = { "id" }), + @UniqueConstraint(name = "uptime_event_key", columnNames = { "monitor_id", "status", "ended_at" }) + }, + indexes = { + @Index(name = "uptime_event_ended_at_idx", columnList = "ended_at ASC"), + @Index(name = "uptime_event_monitor_idx", columnList = "monitor_id ASC") + } +) public class UptimeEventPojo implements Serializable { - private static final long serialVersionUID = 1847709210; + private static final long serialVersionUID = 1L; private Integer id; private Integer monitorId; @@ -74,6 +78,9 @@ public UptimeEventPojo( this.updatedAt = updatedAt; } + /** + * Getter for uptime_event.id. + */ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", nullable = false, precision = 32) @@ -81,69 +88,108 @@ public Integer getId() { return this.id; } + /** + * Setter for uptime_event.id. + */ public UptimeEventPojo setId(Integer id) { this.id = id; return this; } + /** + * Getter for uptime_event.monitor_id. + */ @Column(name = "monitor_id", nullable = false, precision = 32) @NotNull public Integer getMonitorId() { return this.monitorId; } + /** + * Setter for uptime_event.monitor_id. + */ public UptimeEventPojo setMonitorId(Integer monitorId) { this.monitorId = monitorId; return this; } + /** + * Getter for uptime_event.status. Status of the event + */ @Column(name = "status", nullable = false) @NotNull public UptimeStatus getStatus() { return this.status; } + /** + * Setter for uptime_event.status. Status of the event + */ public UptimeEventPojo setStatus(UptimeStatus status) { this.status = status; return this; } + /** + * Getter for uptime_event.error. + */ @Column(name = "error") public String getError() { return this.error; } + /** + * Setter for uptime_event.error. + */ public UptimeEventPojo setError(String error) { this.error = error; return this; } - @Column(name = "started_at", nullable = false) + /** + * Getter for uptime_event.started_at. The current event started at + */ + @Column(name = "started_at", nullable = false, precision = 6) public OffsetDateTime getStartedAt() { return this.startedAt; } + /** + * Setter for uptime_event.started_at. The current event started at + */ public UptimeEventPojo setStartedAt(OffsetDateTime startedAt) { this.startedAt = startedAt; return this; } - @Column(name = "ended_at") + /** + * Getter for uptime_event.ended_at. The current event ended at + */ + @Column(name = "ended_at", precision = 6) public OffsetDateTime getEndedAt() { return this.endedAt; } + /** + * Setter for uptime_event.ended_at. The current event ended at + */ public UptimeEventPojo setEndedAt(OffsetDateTime endedAt) { this.endedAt = endedAt; return this; } - @Column(name = "updated_at", nullable = false) + /** + * Getter for uptime_event.updated_at. + */ + @Column(name = "updated_at", nullable = false, precision = 6) @NotNull public OffsetDateTime getUpdatedAt() { return this.updatedAt; } + /** + * Setter for uptime_event.updated_at. + */ public UptimeEventPojo setUpdatedAt(OffsetDateTime updatedAt) { this.updatedAt = updatedAt; return this; diff --git a/src/jooq/java/com/kuvaszuptime/kuvasz/tables/records/LatencyLogRecord.java b/src/jooq/java/com/kuvaszuptime/kuvasz/tables/records/LatencyLogRecord.java index fc7f817..9590824 100644 --- a/src/jooq/java/com/kuvaszuptime/kuvasz/tables/records/LatencyLogRecord.java +++ b/src/jooq/java/com/kuvaszuptime/kuvasz/tables/records/LatencyLogRecord.java @@ -30,15 +30,19 @@ */ @SuppressWarnings({ "all", "unchecked", "rawtypes" }) @Entity -@Table(name = "latency_log", uniqueConstraints = { - @UniqueConstraint(name = "latency_log_pkey", columnNames = {"id"}) -}, indexes = { - @Index(name = "latency_log_latency_idx", columnList = "latency ASC"), - @Index(name = "latency_log_monitor_idx", columnList = "monitor_id ASC") -}) +@Table( + name = "latency_log", + uniqueConstraints = { + @UniqueConstraint(name = "latency_log_pkey", columnNames = { "id" }) + }, + indexes = { + @Index(name = "latency_log_latency_idx", columnList = "latency ASC"), + @Index(name = "latency_log_monitor_idx", columnList = "monitor_id ASC") + } +) public class LatencyLogRecord extends UpdatableRecordImpl implements Record4 { - private static final long serialVersionUID = 936267229; + private static final long serialVersionUID = 1L; /** * Setter for latency_log.id. @@ -103,7 +107,7 @@ public LatencyLogRecord setCreatedAt(OffsetDateTime value) { /** * Getter for latency_log.created_at. */ - @Column(name = "created_at", nullable = false) + @Column(name = "created_at", nullable = false, precision = 6) public OffsetDateTime getCreatedAt() { return (OffsetDateTime) get(3); } @@ -241,9 +245,9 @@ public LatencyLogRecord() { public LatencyLogRecord(Integer id, Integer monitorId, Integer latency, OffsetDateTime createdAt) { super(LatencyLog.LATENCY_LOG); - set(0, id); - set(1, monitorId); - set(2, latency); - set(3, createdAt); + setId(id); + setMonitorId(monitorId); + setLatency(latency); + setCreatedAt(createdAt); } } diff --git a/src/jooq/java/com/kuvaszuptime/kuvasz/tables/records/MonitorRecord.java b/src/jooq/java/com/kuvaszuptime/kuvasz/tables/records/MonitorRecord.java index a09069e..a4ec7b1 100644 --- a/src/jooq/java/com/kuvaszuptime/kuvasz/tables/records/MonitorRecord.java +++ b/src/jooq/java/com/kuvaszuptime/kuvasz/tables/records/MonitorRecord.java @@ -30,13 +30,16 @@ */ @SuppressWarnings({ "all", "unchecked", "rawtypes" }) @Entity -@Table(name = "monitor", uniqueConstraints = { - @UniqueConstraint(name = "monitor_pkey", columnNames = {"id"}), - @UniqueConstraint(name = "unique_monitor_name", columnNames = {"name"}) -}) +@Table( + name = "monitor", + uniqueConstraints = { + @UniqueConstraint(name = "monitor_pkey", columnNames = { "id" }), + @UniqueConstraint(name = "unique_monitor_name", columnNames = { "name" }) + } +) public class MonitorRecord extends UpdatableRecordImpl implements Record9 { - private static final long serialVersionUID = -1258639093; + private static final long serialVersionUID = 1L; /** * Setter for monitor.id. @@ -135,7 +138,7 @@ public MonitorRecord setCreatedAt(OffsetDateTime value) { /** * Getter for monitor.created_at. */ - @Column(name = "created_at", nullable = false) + @Column(name = "created_at", nullable = false, precision = 6) public OffsetDateTime getCreatedAt() { return (OffsetDateTime) get(5); } @@ -151,7 +154,7 @@ public MonitorRecord setUpdatedAt(OffsetDateTime value) { /** * Getter for monitor.updated_at. */ - @Column(name = "updated_at") + @Column(name = "updated_at", precision = 6) public OffsetDateTime getUpdatedAt() { return (OffsetDateTime) get(6); } @@ -431,14 +434,14 @@ public MonitorRecord() { public MonitorRecord(Integer id, String name, String url, Integer uptimeCheckInterval, Boolean enabled, OffsetDateTime createdAt, OffsetDateTime updatedAt, Boolean sslCheckEnabled, String pagerdutyIntegrationKey) { super(Monitor.MONITOR); - set(0, id); - set(1, name); - set(2, url); - set(3, uptimeCheckInterval); - set(4, enabled); - set(5, createdAt); - set(6, updatedAt); - set(7, sslCheckEnabled); - set(8, pagerdutyIntegrationKey); + setId(id); + setName(name); + setUrl(url); + setUptimeCheckInterval(uptimeCheckInterval); + setEnabled(enabled); + setCreatedAt(createdAt); + setUpdatedAt(updatedAt); + setSslCheckEnabled(sslCheckEnabled); + setPagerdutyIntegrationKey(pagerdutyIntegrationKey); } } diff --git a/src/jooq/java/com/kuvaszuptime/kuvasz/tables/records/SslEventRecord.java b/src/jooq/java/com/kuvaszuptime/kuvasz/tables/records/SslEventRecord.java index 02e4404..53a877d 100644 --- a/src/jooq/java/com/kuvaszuptime/kuvasz/tables/records/SslEventRecord.java +++ b/src/jooq/java/com/kuvaszuptime/kuvasz/tables/records/SslEventRecord.java @@ -31,16 +31,20 @@ */ @SuppressWarnings({ "all", "unchecked", "rawtypes" }) @Entity -@Table(name = "ssl_event", uniqueConstraints = { - @UniqueConstraint(name = "ssl_event_pkey", columnNames = {"id"}), - @UniqueConstraint(name = "ssl_event_key", columnNames = {"monitor_id", "status", "ended_at"}) -}, indexes = { - @Index(name = "ssl_event_ended_at_idx", columnList = "ended_at ASC"), - @Index(name = "ssl_event_monitor_idx", columnList = "monitor_id ASC") -}) +@Table( + name = "ssl_event", + uniqueConstraints = { + @UniqueConstraint(name = "ssl_event_pkey", columnNames = { "id" }), + @UniqueConstraint(name = "ssl_event_key", columnNames = { "monitor_id", "status", "ended_at" }) + }, + indexes = { + @Index(name = "ssl_event_ended_at_idx", columnList = "ended_at ASC"), + @Index(name = "ssl_event_monitor_idx", columnList = "monitor_id ASC") + } +) public class SslEventRecord extends UpdatableRecordImpl implements Record7 { - private static final long serialVersionUID = -877029403; + private static final long serialVersionUID = 1L; /** * Setter for ssl_event.id. @@ -121,7 +125,7 @@ public SslEventRecord setStartedAt(OffsetDateTime value) { /** * Getter for ssl_event.started_at. The current event started at */ - @Column(name = "started_at", nullable = false) + @Column(name = "started_at", nullable = false, precision = 6) public OffsetDateTime getStartedAt() { return (OffsetDateTime) get(4); } @@ -137,7 +141,7 @@ public SslEventRecord setEndedAt(OffsetDateTime value) { /** * Getter for ssl_event.ended_at. The current event ended at */ - @Column(name = "ended_at") + @Column(name = "ended_at", precision = 6) public OffsetDateTime getEndedAt() { return (OffsetDateTime) get(5); } @@ -153,7 +157,7 @@ public SslEventRecord setUpdatedAt(OffsetDateTime value) { /** * Getter for ssl_event.updated_at. */ - @Column(name = "updated_at", nullable = false) + @Column(name = "updated_at", nullable = false, precision = 6) @NotNull public OffsetDateTime getUpdatedAt() { return (OffsetDateTime) get(6); @@ -358,12 +362,12 @@ public SslEventRecord() { public SslEventRecord(Integer id, Integer monitorId, SslStatus status, String error, OffsetDateTime startedAt, OffsetDateTime endedAt, OffsetDateTime updatedAt) { super(SslEvent.SSL_EVENT); - set(0, id); - set(1, monitorId); - set(2, status); - set(3, error); - set(4, startedAt); - set(5, endedAt); - set(6, updatedAt); + setId(id); + setMonitorId(monitorId); + setStatus(status); + setError(error); + setStartedAt(startedAt); + setEndedAt(endedAt); + setUpdatedAt(updatedAt); } } diff --git a/src/jooq/java/com/kuvaszuptime/kuvasz/tables/records/UptimeEventRecord.java b/src/jooq/java/com/kuvaszuptime/kuvasz/tables/records/UptimeEventRecord.java index 50873ba..a8295c0 100644 --- a/src/jooq/java/com/kuvaszuptime/kuvasz/tables/records/UptimeEventRecord.java +++ b/src/jooq/java/com/kuvaszuptime/kuvasz/tables/records/UptimeEventRecord.java @@ -31,16 +31,20 @@ */ @SuppressWarnings({ "all", "unchecked", "rawtypes" }) @Entity -@Table(name = "uptime_event", uniqueConstraints = { - @UniqueConstraint(name = "uptime_event_pkey", columnNames = {"id"}), - @UniqueConstraint(name = "uptime_event_key", columnNames = {"monitor_id", "status", "ended_at"}) -}, indexes = { - @Index(name = "uptime_event_ended_at_idx", columnList = "ended_at ASC"), - @Index(name = "uptime_event_monitor_idx", columnList = "monitor_id ASC") -}) +@Table( + name = "uptime_event", + uniqueConstraints = { + @UniqueConstraint(name = "uptime_event_pkey", columnNames = { "id" }), + @UniqueConstraint(name = "uptime_event_key", columnNames = { "monitor_id", "status", "ended_at" }) + }, + indexes = { + @Index(name = "uptime_event_ended_at_idx", columnList = "ended_at ASC"), + @Index(name = "uptime_event_monitor_idx", columnList = "monitor_id ASC") + } +) public class UptimeEventRecord extends UpdatableRecordImpl implements Record7 { - private static final long serialVersionUID = -32451597; + private static final long serialVersionUID = 1L; /** * Setter for uptime_event.id. @@ -121,7 +125,7 @@ public UptimeEventRecord setStartedAt(OffsetDateTime value) { /** * Getter for uptime_event.started_at. The current event started at */ - @Column(name = "started_at", nullable = false) + @Column(name = "started_at", nullable = false, precision = 6) public OffsetDateTime getStartedAt() { return (OffsetDateTime) get(4); } @@ -137,7 +141,7 @@ public UptimeEventRecord setEndedAt(OffsetDateTime value) { /** * Getter for uptime_event.ended_at. The current event ended at */ - @Column(name = "ended_at") + @Column(name = "ended_at", precision = 6) public OffsetDateTime getEndedAt() { return (OffsetDateTime) get(5); } @@ -153,7 +157,7 @@ public UptimeEventRecord setUpdatedAt(OffsetDateTime value) { /** * Getter for uptime_event.updated_at. */ - @Column(name = "updated_at", nullable = false) + @Column(name = "updated_at", nullable = false, precision = 6) @NotNull public OffsetDateTime getUpdatedAt() { return (OffsetDateTime) get(6); @@ -358,12 +362,12 @@ public UptimeEventRecord() { public UptimeEventRecord(Integer id, Integer monitorId, UptimeStatus status, String error, OffsetDateTime startedAt, OffsetDateTime endedAt, OffsetDateTime updatedAt) { super(UptimeEvent.UPTIME_EVENT); - set(0, id); - set(1, monitorId); - set(2, status); - set(3, error); - set(4, startedAt); - set(5, endedAt); - set(6, updatedAt); + setId(id); + setMonitorId(monitorId); + setStatus(status); + setError(error); + setStartedAt(startedAt); + setEndedAt(endedAt); + setUpdatedAt(updatedAt); } } diff --git a/src/main/kotlin/com/kuvaszuptime/kuvasz/Application.kt b/src/main/kotlin/com/kuvaszuptime/kuvasz/Application.kt index a4d3077..2e6978b 100644 --- a/src/main/kotlin/com/kuvaszuptime/kuvasz/Application.kt +++ b/src/main/kotlin/com/kuvaszuptime/kuvasz/Application.kt @@ -14,7 +14,7 @@ import io.swagger.v3.oas.annotations.tags.Tag title = "kuvasz", version = "latest", description = "Kuvasz [pronounce as 'koovas'] is an open-source, headless uptime and SSL monitoring service, " + - "built in Kotlin on top of the awesome Micronaut framework", + "built in Kotlin on top of the awesome Micronaut framework", contact = Contact( url = "https://github.com/kuvasz-uptime/kuvasz" ) diff --git a/src/main/kotlin/com/kuvaszuptime/kuvasz/config/SMTPMailerConfig.kt b/src/main/kotlin/com/kuvaszuptime/kuvasz/config/SMTPMailerConfig.kt index cc3f0dd..3ee3980 100644 --- a/src/main/kotlin/com/kuvaszuptime/kuvasz/config/SMTPMailerConfig.kt +++ b/src/main/kotlin/com/kuvaszuptime/kuvasz/config/SMTPMailerConfig.kt @@ -2,7 +2,7 @@ package com.kuvaszuptime.kuvasz.config import io.micronaut.context.annotation.ConfigurationProperties import io.micronaut.core.annotation.Introspected -import javax.inject.Singleton +import jakarta.inject.Singleton import javax.validation.constraints.NotBlank import javax.validation.constraints.NotNull import org.simplejavamail.api.mailer.config.TransportStrategy as JavaMailerTransportStrategy diff --git a/src/main/kotlin/com/kuvaszuptime/kuvasz/config/handlers/SMTPEventHandlerConfig.kt b/src/main/kotlin/com/kuvaszuptime/kuvasz/config/handlers/SMTPEventHandlerConfig.kt index 75f4ad6..e496b9f 100644 --- a/src/main/kotlin/com/kuvaszuptime/kuvasz/config/handlers/SMTPEventHandlerConfig.kt +++ b/src/main/kotlin/com/kuvaszuptime/kuvasz/config/handlers/SMTPEventHandlerConfig.kt @@ -2,7 +2,7 @@ package com.kuvaszuptime.kuvasz.config.handlers import io.micronaut.context.annotation.ConfigurationProperties import io.micronaut.core.annotation.Introspected -import javax.inject.Singleton +import jakarta.inject.Singleton import javax.validation.constraints.Email import javax.validation.constraints.NotBlank diff --git a/src/main/kotlin/com/kuvaszuptime/kuvasz/config/handlers/TelegramEventHandlerConfig.kt b/src/main/kotlin/com/kuvaszuptime/kuvasz/config/handlers/TelegramEventHandlerConfig.kt index 71b4530..add069d 100644 --- a/src/main/kotlin/com/kuvaszuptime/kuvasz/config/handlers/TelegramEventHandlerConfig.kt +++ b/src/main/kotlin/com/kuvaszuptime/kuvasz/config/handlers/TelegramEventHandlerConfig.kt @@ -2,7 +2,7 @@ package com.kuvaszuptime.kuvasz.config.handlers import io.micronaut.context.annotation.ConfigurationProperties import io.micronaut.core.annotation.Introspected -import javax.inject.Singleton +import jakarta.inject.Singleton import javax.validation.constraints.NotBlank @ConfigurationProperties("handler-config.telegram-event-handler") diff --git a/src/main/kotlin/com/kuvaszuptime/kuvasz/controllers/MonitorController.kt b/src/main/kotlin/com/kuvaszuptime/kuvasz/controllers/MonitorController.kt index cf599ae..5ee3d91 100644 --- a/src/main/kotlin/com/kuvaszuptime/kuvasz/controllers/MonitorController.kt +++ b/src/main/kotlin/com/kuvaszuptime/kuvasz/controllers/MonitorController.kt @@ -15,6 +15,9 @@ import io.micronaut.http.MediaType import io.micronaut.http.annotation.Controller import io.micronaut.http.annotation.QueryValue import io.micronaut.http.annotation.Status +import io.micronaut.scheduling.TaskExecutors +import io.micronaut.scheduling.annotation.ExecuteOn +import io.micronaut.validation.Validated import io.swagger.v3.oas.annotations.media.ArraySchema import io.swagger.v3.oas.annotations.media.Content import io.swagger.v3.oas.annotations.media.Schema @@ -22,8 +25,10 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse import io.swagger.v3.oas.annotations.responses.ApiResponses import io.swagger.v3.oas.annotations.security.SecurityRequirement import io.swagger.v3.oas.annotations.tags.Tag +import javax.validation.Valid @Controller("/monitors", produces = [MediaType.APPLICATION_JSON]) +@Validated @Tag(name = "Monitor operations") @SecurityRequirement(name = "bearerAuth") class MonitorController( @@ -37,6 +42,7 @@ class MonitorController( content = [Content(array = ArraySchema(schema = Schema(implementation = MonitorDetailsDto::class)))] ) ) + @ExecuteOn(TaskExecutors.IO) override fun getMonitorsWithDetails(@QueryValue enabledOnly: Boolean?): List = monitorCrudService.getMonitorsWithDetails(enabledOnly ?: false) @@ -52,6 +58,7 @@ class MonitorController( content = [Content(schema = Schema(implementation = ServiceError::class))] ) ) + @ExecuteOn(TaskExecutors.IO) override fun getMonitorDetails(monitorId: Int): MonitorDetailsDto = monitorCrudService.getMonitorDetails(monitorId) ?: throw MonitorNotFoundError(monitorId) @@ -68,7 +75,8 @@ class MonitorController( content = [Content(schema = Schema(implementation = ServiceError::class))] ) ) - override fun createMonitor(monitor: MonitorCreateDto): MonitorDto { + @ExecuteOn(TaskExecutors.IO) + override fun createMonitor(@Valid monitor: MonitorCreateDto): MonitorDto { val updatedPojo = monitorCrudService.createMonitor(monitor) return MonitorDto.fromMonitorPojo(updatedPojo) } @@ -85,6 +93,7 @@ class MonitorController( content = [Content(schema = Schema(implementation = ServiceError::class))] ) ) + @ExecuteOn(TaskExecutors.IO) override fun deleteMonitor(monitorId: Int) = monitorCrudService.deleteMonitorById(monitorId) @ApiResponses( @@ -104,7 +113,8 @@ class MonitorController( content = [Content(schema = Schema(implementation = ServiceError::class))] ) ) - override fun updateMonitor(monitorId: Int, monitorUpdateDto: MonitorUpdateDto): MonitorDto { + @ExecuteOn(TaskExecutors.IO) + override fun updateMonitor(monitorId: Int, @Valid monitorUpdateDto: MonitorUpdateDto): MonitorDto { val updatedPojo = monitorCrudService.updateMonitor(monitorId, monitorUpdateDto) return MonitorDto.fromMonitorPojo(updatedPojo) } @@ -126,7 +136,8 @@ class MonitorController( content = [Content(schema = Schema(implementation = ServiceError::class))] ) ) - override fun upsertPagerdutyIntegrationKey(monitorId: Int, upsertDto: PagerdutyKeyUpdateDto): MonitorDto { + @ExecuteOn(TaskExecutors.IO) + override fun upsertPagerdutyIntegrationKey(monitorId: Int, @Valid upsertDto: PagerdutyKeyUpdateDto): MonitorDto { val updatedPojo = monitorCrudService.updatePagerdutyIntegrationKey(monitorId, upsertDto.pagerdutyIntegrationKey) return MonitorDto.fromMonitorPojo(updatedPojo) } @@ -143,6 +154,7 @@ class MonitorController( content = [Content(schema = Schema(implementation = ServiceError::class))] ) ) + @ExecuteOn(TaskExecutors.IO) override fun deletePagerdutyIntegrationKey(monitorId: Int) { monitorCrudService.updatePagerdutyIntegrationKey(monitorId, null) } @@ -154,6 +166,7 @@ class MonitorController( content = [Content(array = ArraySchema(schema = Schema(implementation = UptimeEventDto::class)))] ) ) + @ExecuteOn(TaskExecutors.IO) override fun getUptimeEvents(monitorId: Int): List = monitorCrudService.getUptimeEventsByMonitorId(monitorId) @@ -164,5 +177,6 @@ class MonitorController( content = [Content(array = ArraySchema(schema = Schema(implementation = SSLEventDto::class)))] ) ) + @ExecuteOn(TaskExecutors.IO) override fun getSSLEvents(monitorId: Int): List = monitorCrudService.getSSLEventsByMonitorId(monitorId) } diff --git a/src/main/kotlin/com/kuvaszuptime/kuvasz/controllers/MonitorOperations.kt b/src/main/kotlin/com/kuvaszuptime/kuvasz/controllers/MonitorOperations.kt index 786dbb5..c46fb20 100644 --- a/src/main/kotlin/com/kuvaszuptime/kuvasz/controllers/MonitorOperations.kt +++ b/src/main/kotlin/com/kuvaszuptime/kuvasz/controllers/MonitorOperations.kt @@ -1,32 +1,14 @@ package com.kuvaszuptime.kuvasz.controllers -import com.kuvaszuptime.kuvasz.models.dto.MonitorCreateDto -import com.kuvaszuptime.kuvasz.models.dto.MonitorDetailsDto -import com.kuvaszuptime.kuvasz.models.dto.MonitorDto -import com.kuvaszuptime.kuvasz.models.dto.MonitorUpdateDto -import com.kuvaszuptime.kuvasz.models.dto.PagerdutyKeyUpdateDto -import com.kuvaszuptime.kuvasz.models.dto.SSLEventDto -import com.kuvaszuptime.kuvasz.models.dto.UptimeEventDto -import io.micronaut.http.annotation.Body -import io.micronaut.http.annotation.Delete -import io.micronaut.http.annotation.Get -import io.micronaut.http.annotation.Patch -import io.micronaut.http.annotation.Post -import io.micronaut.http.annotation.Put -import io.micronaut.http.annotation.QueryValue -import io.micronaut.scheduling.TaskExecutors -import io.micronaut.scheduling.annotation.ExecuteOn -import io.micronaut.validation.Validated +import com.kuvaszuptime.kuvasz.models.dto.* +import io.micronaut.http.annotation.* import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.Parameter -import javax.validation.Valid -@Validated interface MonitorOperations { @Operation(summary = "Returns all monitors with their details") @Get("/") - @ExecuteOn(TaskExecutors.IO) fun getMonitorsWithDetails( @QueryValue @Parameter(required = false) @@ -35,41 +17,33 @@ interface MonitorOperations { @Operation(summary = "Returns a monitor's details") @Get("/{monitorId}") - @ExecuteOn(TaskExecutors.IO) fun getMonitorDetails(monitorId: Int): MonitorDetailsDto @Operation(summary = "Creates a monitor") @Post("/") - @ExecuteOn(TaskExecutors.IO) - fun createMonitor(@Valid @Body monitor: MonitorCreateDto): MonitorDto + fun createMonitor(@Body monitor: MonitorCreateDto): MonitorDto @Operation(summary = "Deletes a monitor by ID") @Delete("/{monitorId}") - @ExecuteOn(TaskExecutors.IO) fun deleteMonitor(monitorId: Int) @Operation(summary = "Updates a monitor by ID") @Patch("/{monitorId}") - @ExecuteOn(TaskExecutors.IO) - fun updateMonitor(monitorId: Int, @Valid @Body monitorUpdateDto: MonitorUpdateDto): MonitorDto + fun updateMonitor(monitorId: Int, @Body monitorUpdateDto: MonitorUpdateDto): MonitorDto @Operation(summary = "Updates or creates a Pagerduty integration key for the given monitor") @Put("/{monitorId}/pagerduty-integration-key") - @ExecuteOn(TaskExecutors.IO) - fun upsertPagerdutyIntegrationKey(monitorId: Int, @Valid @Body upsertDto: PagerdutyKeyUpdateDto): MonitorDto + fun upsertPagerdutyIntegrationKey(monitorId: Int, @Body upsertDto: PagerdutyKeyUpdateDto): MonitorDto @Operation(summary = "Deletes the Pagerduty integration key of the given monitor") @Delete("/{monitorId}/pagerduty-integration-key") - @ExecuteOn(TaskExecutors.IO) fun deletePagerdutyIntegrationKey(monitorId: Int) @Operation(summary = "Returns the uptime events of the given monitor") @Get("/{monitorId}/uptime-events") - @ExecuteOn(TaskExecutors.IO) fun getUptimeEvents(monitorId: Int): List @Operation(summary = "Returns the SSL events of the given monitor") @Get("/{monitorId}/ssl-events") - @ExecuteOn(TaskExecutors.IO) fun getSSLEvents(monitorId: Int): List } diff --git a/src/main/kotlin/com/kuvaszuptime/kuvasz/factories/LogbookFactory.kt b/src/main/kotlin/com/kuvaszuptime/kuvasz/factories/LogbookFactory.kt index 00f7da9..e213ec9 100644 --- a/src/main/kotlin/com/kuvaszuptime/kuvasz/factories/LogbookFactory.kt +++ b/src/main/kotlin/com/kuvaszuptime/kuvasz/factories/LogbookFactory.kt @@ -1,6 +1,7 @@ package com.kuvaszuptime.kuvasz.factories import io.micronaut.context.annotation.Factory +import jakarta.inject.Singleton import org.zalando.logbook.Conditions.exclude import org.zalando.logbook.Conditions.requestTo import org.zalando.logbook.DefaultHttpLogWriter @@ -9,7 +10,6 @@ import org.zalando.logbook.Logbook import org.zalando.logbook.SecurityStrategy import org.zalando.logbook.WithoutBodyStrategy import org.zalando.logbook.json.JsonHttpLogFormatter -import javax.inject.Singleton @Factory class LogbookFactory { diff --git a/src/main/kotlin/com/kuvaszuptime/kuvasz/handlers/HandlersInfoSource.kt b/src/main/kotlin/com/kuvaszuptime/kuvasz/handlers/HandlersInfoSource.kt index 7152f0e..2ab0cca 100644 --- a/src/main/kotlin/com/kuvaszuptime/kuvasz/handlers/HandlersInfoSource.kt +++ b/src/main/kotlin/com/kuvaszuptime/kuvasz/handlers/HandlersInfoSource.kt @@ -5,8 +5,8 @@ import io.micronaut.context.env.MapPropertySource import io.micronaut.context.env.PropertySource import io.micronaut.management.endpoint.info.InfoSource import io.reactivex.Flowable +import jakarta.inject.Singleton import org.reactivestreams.Publisher -import javax.inject.Singleton @Singleton class HandlersInfoSource(private val environment: Environment) : InfoSource { diff --git a/src/main/kotlin/com/kuvaszuptime/kuvasz/models/events/MonitorEvent.kt b/src/main/kotlin/com/kuvaszuptime/kuvasz/models/events/MonitorEvent.kt index 970ec37..462a024 100644 --- a/src/main/kotlin/com/kuvaszuptime/kuvasz/models/events/MonitorEvent.kt +++ b/src/main/kotlin/com/kuvaszuptime/kuvasz/models/events/MonitorEvent.kt @@ -75,7 +75,7 @@ data class MonitorDownEvent( override fun toStructuredMessage() = StructuredMonitorDownMessage( summary = "Your monitor \"${monitor.name}\" (${monitor.url}) is DOWN" + - (status?.let { " (" + it.code + ")" } ?: ""), + (status?.let { " (" + it.code + ")" } ?: ""), error = "Reason: ${error.message}", previousUpTime = getEndedEventDuration().toDurationString()?.let { "Was up for $it" } ) diff --git a/src/main/kotlin/com/kuvaszuptime/kuvasz/repositories/LatencyLogRepository.kt b/src/main/kotlin/com/kuvaszuptime/kuvasz/repositories/LatencyLogRepository.kt index f5d57f6..d197b72 100644 --- a/src/main/kotlin/com/kuvaszuptime/kuvasz/repositories/LatencyLogRepository.kt +++ b/src/main/kotlin/com/kuvaszuptime/kuvasz/repositories/LatencyLogRepository.kt @@ -4,12 +4,12 @@ import com.kuvaszuptime.kuvasz.tables.LatencyLog.LATENCY_LOG import com.kuvaszuptime.kuvasz.tables.daos.LatencyLogDao import com.kuvaszuptime.kuvasz.tables.pojos.LatencyLogPojo import io.micronaut.core.annotation.Introspected +import jakarta.inject.Singleton import org.jooq.Configuration import org.jooq.impl.DSL import org.jooq.impl.DSL.field import org.jooq.impl.DSL.min import java.time.OffsetDateTime -import javax.inject.Singleton @Singleton class LatencyLogRepository(jooqConfig: Configuration) : LatencyLogDao(jooqConfig) { diff --git a/src/main/kotlin/com/kuvaszuptime/kuvasz/repositories/MonitorRepository.kt b/src/main/kotlin/com/kuvaszuptime/kuvasz/repositories/MonitorRepository.kt index 27b742e..0646217 100644 --- a/src/main/kotlin/com/kuvaszuptime/kuvasz/repositories/MonitorRepository.kt +++ b/src/main/kotlin/com/kuvaszuptime/kuvasz/repositories/MonitorRepository.kt @@ -15,14 +15,11 @@ import com.kuvaszuptime.kuvasz.tables.records.MonitorRecord import com.kuvaszuptime.kuvasz.util.fetchOneIntoOrThrow import com.kuvaszuptime.kuvasz.util.getCurrentTimestamp import com.kuvaszuptime.kuvasz.util.toPersistenceError +import jakarta.inject.Singleton import org.jooq.Configuration import org.jooq.exception.DataAccessException -import org.jooq.impl.DSL.`when` -import org.jooq.impl.DSL.avg -import org.jooq.impl.DSL.inline -import org.jooq.impl.DSL.round +import org.jooq.impl.DSL.* import org.jooq.impl.SQLDataType -import javax.inject.Singleton @Singleton class MonitorRepository(jooqConfig: Configuration) : MonitorDao(jooqConfig) { @@ -59,7 +56,7 @@ class MonitorRepository(jooqConfig: Configuration) : MonitorDao(jooqConfig) { fun returningInsert(monitorPojo: MonitorPojo): Either = try { - Either.right( + Either.Right( dsl .insertInto(MONITOR) .set(dsl.newRecord(MONITOR, monitorPojo)) @@ -72,7 +69,7 @@ class MonitorRepository(jooqConfig: Configuration) : MonitorDao(jooqConfig) { fun returningUpdate(updatedPojo: MonitorPojo): Either = try { - Either.right( + Either.Right( dsl .update(MONITOR) .set(MONITOR.NAME, updatedPojo.name) @@ -124,7 +121,7 @@ class MonitorRepository(jooqConfig: Configuration) : MonitorDao(jooqConfig) { private fun DataAccessException.handle(): Either { val persistenceError = toPersistenceError() - return Either.left( + return Either.Left( if (persistenceError is DuplicationError) { MonitorDuplicatedError() } else persistenceError diff --git a/src/main/kotlin/com/kuvaszuptime/kuvasz/repositories/SSLEventRepository.kt b/src/main/kotlin/com/kuvaszuptime/kuvasz/repositories/SSLEventRepository.kt index 346cb37..f3438d3 100644 --- a/src/main/kotlin/com/kuvaszuptime/kuvasz/repositories/SSLEventRepository.kt +++ b/src/main/kotlin/com/kuvaszuptime/kuvasz/repositories/SSLEventRepository.kt @@ -6,10 +6,10 @@ import com.kuvaszuptime.kuvasz.models.events.SSLMonitorEvent import com.kuvaszuptime.kuvasz.tables.SslEvent.SSL_EVENT import com.kuvaszuptime.kuvasz.tables.daos.SslEventDao import com.kuvaszuptime.kuvasz.tables.pojos.SslEventPojo +import jakarta.inject.Singleton import org.jooq.Configuration import org.jooq.impl.DSL import java.time.OffsetDateTime -import javax.inject.Singleton @Singleton class SSLEventRepository(private val jooqConfig: Configuration) : SslEventDao(jooqConfig) { diff --git a/src/main/kotlin/com/kuvaszuptime/kuvasz/repositories/UptimeEventRepository.kt b/src/main/kotlin/com/kuvaszuptime/kuvasz/repositories/UptimeEventRepository.kt index 0c0547d..7cd4734 100644 --- a/src/main/kotlin/com/kuvaszuptime/kuvasz/repositories/UptimeEventRepository.kt +++ b/src/main/kotlin/com/kuvaszuptime/kuvasz/repositories/UptimeEventRepository.kt @@ -7,10 +7,10 @@ import com.kuvaszuptime.kuvasz.models.events.UptimeMonitorEvent import com.kuvaszuptime.kuvasz.tables.UptimeEvent.UPTIME_EVENT import com.kuvaszuptime.kuvasz.tables.daos.UptimeEventDao import com.kuvaszuptime.kuvasz.tables.pojos.UptimeEventPojo +import jakarta.inject.Singleton import org.jooq.Configuration import org.jooq.impl.DSL import java.time.OffsetDateTime -import javax.inject.Singleton @Singleton class UptimeEventRepository(private val jooqConfig: Configuration) : UptimeEventDao(jooqConfig) { diff --git a/src/main/kotlin/com/kuvaszuptime/kuvasz/security/AdminAuthProvider.kt b/src/main/kotlin/com/kuvaszuptime/kuvasz/security/AdminAuthProvider.kt index f06f294..84b30cb 100644 --- a/src/main/kotlin/com/kuvaszuptime/kuvasz/security/AdminAuthProvider.kt +++ b/src/main/kotlin/com/kuvaszuptime/kuvasz/security/AdminAuthProvider.kt @@ -2,17 +2,14 @@ package com.kuvaszuptime.kuvasz.security import com.kuvaszuptime.kuvasz.config.AdminAuthConfig import io.micronaut.http.HttpRequest -import io.micronaut.security.authentication.AuthenticationException -import io.micronaut.security.authentication.AuthenticationFailed import io.micronaut.security.authentication.AuthenticationProvider import io.micronaut.security.authentication.AuthenticationRequest import io.micronaut.security.authentication.AuthenticationResponse -import io.micronaut.security.authentication.UserDetails import io.reactivex.BackpressureStrategy import io.reactivex.Flowable import io.reactivex.FlowableEmitter +import jakarta.inject.Singleton import org.reactivestreams.Publisher -import javax.inject.Singleton @Singleton class AdminAuthProvider(private val authConfig: AdminAuthConfig) : AuthenticationProvider { @@ -26,15 +23,15 @@ class AdminAuthProvider(private val authConfig: AdminAuthConfig) : Authenticatio if (authenticationRequest.identity == authConfig.username && authenticationRequest.secret == authConfig.password ) { - val userDetails = - UserDetails( + emitter.onNext( + AuthenticationResponse.success( authenticationRequest.identity as String, listOf(Role.ADMIN.alias) ) - emitter.onNext(userDetails) + ) emitter.onComplete() } else { - emitter.onError(AuthenticationException(AuthenticationFailed())) + emitter.onError(AuthenticationResponse.exception()) } }, BackpressureStrategy.ERROR diff --git a/src/main/kotlin/com/kuvaszuptime/kuvasz/services/CheckScheduler.kt b/src/main/kotlin/com/kuvaszuptime/kuvasz/services/CheckScheduler.kt index 9e62eed..81ebf73 100644 --- a/src/main/kotlin/com/kuvaszuptime/kuvasz/services/CheckScheduler.kt +++ b/src/main/kotlin/com/kuvaszuptime/kuvasz/services/CheckScheduler.kt @@ -11,11 +11,11 @@ import com.kuvaszuptime.kuvasz.util.toDurationOfSeconds import io.micronaut.context.annotation.Context import io.micronaut.scheduling.TaskExecutors import io.micronaut.scheduling.TaskScheduler +import jakarta.inject.Named import org.slf4j.LoggerFactory import java.time.Duration import java.util.concurrent.ScheduledFuture import javax.annotation.PostConstruct -import javax.inject.Named @Context class CheckScheduler( diff --git a/src/main/kotlin/com/kuvaszuptime/kuvasz/services/DatabaseCleaner.kt b/src/main/kotlin/com/kuvaszuptime/kuvasz/services/DatabaseCleaner.kt index a711d6e..2a8d9fd 100644 --- a/src/main/kotlin/com/kuvaszuptime/kuvasz/services/DatabaseCleaner.kt +++ b/src/main/kotlin/com/kuvaszuptime/kuvasz/services/DatabaseCleaner.kt @@ -8,8 +8,8 @@ import com.kuvaszuptime.kuvasz.util.getCurrentTimestamp import io.micronaut.context.annotation.Requires import io.micronaut.context.env.Environment import io.micronaut.scheduling.annotation.Scheduled +import jakarta.inject.Singleton import org.slf4j.LoggerFactory -import javax.inject.Singleton @Singleton class DatabaseCleaner( diff --git a/src/main/kotlin/com/kuvaszuptime/kuvasz/services/EventDispatcher.kt b/src/main/kotlin/com/kuvaszuptime/kuvasz/services/EventDispatcher.kt index 69fe498..39bf278 100644 --- a/src/main/kotlin/com/kuvaszuptime/kuvasz/services/EventDispatcher.kt +++ b/src/main/kotlin/com/kuvaszuptime/kuvasz/services/EventDispatcher.kt @@ -9,7 +9,7 @@ import com.kuvaszuptime.kuvasz.models.events.SSLValidEvent import com.kuvaszuptime.kuvasz.models.events.SSLWillExpireEvent import io.reactivex.disposables.Disposable import io.reactivex.subjects.PublishSubject -import javax.inject.Singleton +import jakarta.inject.Singleton @Singleton class EventDispatcher { diff --git a/src/main/kotlin/com/kuvaszuptime/kuvasz/services/HttpCommunicationLogger.kt b/src/main/kotlin/com/kuvaszuptime/kuvasz/services/HttpCommunicationLogger.kt index 741a5eb..2184b22 100644 --- a/src/main/kotlin/com/kuvaszuptime/kuvasz/services/HttpCommunicationLogger.kt +++ b/src/main/kotlin/com/kuvaszuptime/kuvasz/services/HttpCommunicationLogger.kt @@ -5,10 +5,10 @@ import io.micronaut.context.event.BeanCreatedEvent import io.micronaut.context.event.BeanCreatedEventListener import io.micronaut.http.netty.channel.ChannelPipelineCustomizer import io.netty.channel.ChannelPipeline +import jakarta.inject.Singleton import org.zalando.logbook.Logbook import org.zalando.logbook.netty.LogbookClientHandler import org.zalando.logbook.netty.LogbookServerHandler -import javax.inject.Singleton @Singleton @Requires(property = "http-communication-log.enabled", value = "true") diff --git a/src/main/kotlin/com/kuvaszuptime/kuvasz/services/MonitorCrudService.kt b/src/main/kotlin/com/kuvaszuptime/kuvasz/services/MonitorCrudService.kt index 5ce6bea..6dc2765 100644 --- a/src/main/kotlin/com/kuvaszuptime/kuvasz/services/MonitorCrudService.kt +++ b/src/main/kotlin/com/kuvaszuptime/kuvasz/services/MonitorCrudService.kt @@ -11,7 +11,7 @@ import com.kuvaszuptime.kuvasz.repositories.MonitorRepository import com.kuvaszuptime.kuvasz.repositories.SSLEventRepository import com.kuvaszuptime.kuvasz.repositories.UptimeEventRepository import com.kuvaszuptime.kuvasz.tables.pojos.MonitorPojo -import javax.inject.Singleton +import jakarta.inject.Singleton @Singleton class MonitorCrudService( diff --git a/src/main/kotlin/com/kuvaszuptime/kuvasz/services/SMTPMailer.kt b/src/main/kotlin/com/kuvaszuptime/kuvasz/services/SMTPMailer.kt index a0aa9f4..4ca2463 100644 --- a/src/main/kotlin/com/kuvaszuptime/kuvasz/services/SMTPMailer.kt +++ b/src/main/kotlin/com/kuvaszuptime/kuvasz/services/SMTPMailer.kt @@ -1,11 +1,11 @@ package com.kuvaszuptime.kuvasz.services import com.kuvaszuptime.kuvasz.config.SMTPMailerConfig +import jakarta.inject.Singleton import org.simplejavamail.api.email.Email -import org.simplejavamail.api.mailer.AsyncResponse import org.simplejavamail.mailer.MailerBuilder import org.slf4j.LoggerFactory -import javax.inject.Singleton +import java.util.concurrent.CompletableFuture @Singleton class SMTPMailer(smtpMailerConfig: SMTPMailerConfig) { @@ -19,6 +19,7 @@ class SMTPMailer(smtpMailerConfig: SMTPMailerConfig) { .withTransportStrategy(smtpMailerConfig.transportStrategy.toJavaMailerTransportStrategy()) .withSMTPServerHost(smtpMailerConfig.host) .withSMTPServerPort(smtpMailerConfig.port) + .async() .apply { if (!smtpMailerConfig.username.isNullOrBlank() && !smtpMailerConfig.password.isNullOrBlank()) { withSMTPServerUsername(smtpMailerConfig.username) @@ -37,5 +38,5 @@ class SMTPMailer(smtpMailerConfig: SMTPMailerConfig) { } } - fun sendAsync(email: Email): AsyncResponse? = mailerClient.sendMail(email, true) + fun sendAsync(email: Email): CompletableFuture = mailerClient.sendMail(email, true) } diff --git a/src/main/kotlin/com/kuvaszuptime/kuvasz/services/SSLChecker.kt b/src/main/kotlin/com/kuvaszuptime/kuvasz/services/SSLChecker.kt index 14d36e2..29613a4 100644 --- a/src/main/kotlin/com/kuvaszuptime/kuvasz/services/SSLChecker.kt +++ b/src/main/kotlin/com/kuvaszuptime/kuvasz/services/SSLChecker.kt @@ -7,8 +7,8 @@ import com.kuvaszuptime.kuvasz.repositories.SSLEventRepository import com.kuvaszuptime.kuvasz.repositories.UptimeEventRepository import com.kuvaszuptime.kuvasz.tables.pojos.MonitorPojo import com.kuvaszuptime.kuvasz.util.getCurrentTimestamp +import jakarta.inject.Singleton import java.net.URL -import javax.inject.Singleton @Singleton class SSLChecker( diff --git a/src/main/kotlin/com/kuvaszuptime/kuvasz/services/SSLValidator.kt b/src/main/kotlin/com/kuvaszuptime/kuvasz/services/SSLValidator.kt index 9d615ad..bb72ca7 100644 --- a/src/main/kotlin/com/kuvaszuptime/kuvasz/services/SSLValidator.kt +++ b/src/main/kotlin/com/kuvaszuptime/kuvasz/services/SSLValidator.kt @@ -4,9 +4,9 @@ import arrow.core.Either import com.kuvaszuptime.kuvasz.models.CertificateInfo import com.kuvaszuptime.kuvasz.models.SSLValidationError import com.kuvaszuptime.kuvasz.util.toOffsetDateTime +import jakarta.inject.Singleton import java.net.URL import java.security.cert.X509Certificate -import javax.inject.Singleton import javax.net.ssl.HttpsURLConnection @Singleton @@ -19,10 +19,10 @@ class SSLValidator { conn.connect() conn.serverCertificates.filterIsInstance().firstOrNull()?.let { cert -> - Either.right(CertificateInfo(validTo = cert.notAfter.toOffsetDateTime())) - } ?: Either.left(SSLValidationError("There were no matching CN for the given host")) + Either.Right(CertificateInfo(validTo = cert.notAfter.toOffsetDateTime())) + } ?: Either.Left(SSLValidationError("There were no matching CN for the given host")) } catch (e: Throwable) { - Either.left(SSLValidationError(e.message)) + Either.Left(SSLValidationError(e.message)) } } } diff --git a/src/main/kotlin/com/kuvaszuptime/kuvasz/services/SlackWebhookService.kt b/src/main/kotlin/com/kuvaszuptime/kuvasz/services/SlackWebhookService.kt index 13a06fc..6c715bb 100644 --- a/src/main/kotlin/com/kuvaszuptime/kuvasz/services/SlackWebhookService.kt +++ b/src/main/kotlin/com/kuvaszuptime/kuvasz/services/SlackWebhookService.kt @@ -7,7 +7,7 @@ import io.micronaut.http.annotation.Post import io.micronaut.http.client.annotation.Client import io.micronaut.retry.annotation.Retryable import io.reactivex.Single -import javax.inject.Singleton +import jakarta.inject.Singleton @Client("\${handler-config.slack-event-handler.webhook-url}") @Retryable diff --git a/src/main/kotlin/com/kuvaszuptime/kuvasz/services/TelegramAPIService.kt b/src/main/kotlin/com/kuvaszuptime/kuvasz/services/TelegramAPIService.kt index 805bf16..d2ea960 100644 --- a/src/main/kotlin/com/kuvaszuptime/kuvasz/services/TelegramAPIService.kt +++ b/src/main/kotlin/com/kuvaszuptime/kuvasz/services/TelegramAPIService.kt @@ -8,7 +8,7 @@ import io.micronaut.http.annotation.Post import io.micronaut.http.client.annotation.Client import io.micronaut.retry.annotation.Retryable import io.reactivex.Single -import javax.inject.Singleton +import jakarta.inject.Singleton @Client("https://api.telegram.org/bot\${handler-config.telegram-event-handler.token}") @Retryable diff --git a/src/main/kotlin/com/kuvaszuptime/kuvasz/services/UptimeChecker.kt b/src/main/kotlin/com/kuvaszuptime/kuvasz/services/UptimeChecker.kt index 5183fdc..d50f531 100644 --- a/src/main/kotlin/com/kuvaszuptime/kuvasz/services/UptimeChecker.kt +++ b/src/main/kotlin/com/kuvaszuptime/kuvasz/services/UptimeChecker.kt @@ -13,12 +13,12 @@ import io.micronaut.http.HttpHeaders import io.micronaut.http.HttpRequest import io.micronaut.http.client.DefaultHttpClientConfiguration import io.micronaut.http.client.HttpClientConfiguration -import io.micronaut.http.client.RxHttpClient import io.micronaut.http.client.annotation.Client import io.micronaut.http.client.exceptions.HttpClientResponseException +import io.micronaut.rxjava2.http.client.RxHttpClient +import jakarta.inject.Named +import jakarta.inject.Singleton import java.net.URI -import javax.inject.Named -import javax.inject.Singleton @Singleton class UptimeChecker( diff --git a/src/main/kotlin/com/kuvaszuptime/kuvasz/validation/UsernamePasswordNotEquals.kt b/src/main/kotlin/com/kuvaszuptime/kuvasz/validation/UsernamePasswordNotEquals.kt index 1148070..20d8f20 100644 --- a/src/main/kotlin/com/kuvaszuptime/kuvasz/validation/UsernamePasswordNotEquals.kt +++ b/src/main/kotlin/com/kuvaszuptime/kuvasz/validation/UsernamePasswordNotEquals.kt @@ -3,7 +3,7 @@ package com.kuvaszuptime.kuvasz.validation import com.kuvaszuptime.kuvasz.config.AdminAuthConfig import io.micronaut.context.annotation.Factory import io.micronaut.validation.validator.constraints.ConstraintValidator -import javax.inject.Singleton +import jakarta.inject.Singleton import javax.validation.Constraint @Retention(AnnotationRetention.RUNTIME) diff --git a/src/main/resources/META-INF/native-image/com.kuvaszuptime/kuvasz-application/native-image.properties b/src/main/resources/META-INF/native-image/com.kuvaszuptime/kuvasz-application/native-image.properties index 1482f13..a29ad98 100644 --- a/src/main/resources/META-INF/native-image/com.kuvaszuptime/kuvasz-application/native-image.properties +++ b/src/main/resources/META-INF/native-image/com.kuvaszuptime/kuvasz-application/native-image.properties @@ -1,4 +1,2 @@ -Args=-H:Name=kuvasz \ - -H:Class=com.kuvaszuptime.kuvasz.Application \ - -H:ResourceConfigurationResources=${.}/resource-config.json \ +Args=-H:ResourceConfigurationResources=${.}/resource-config.json \ -H:ReflectionConfigurationResources=${.}/reflect-config.json diff --git a/src/main/resources/META-INF/native-image/com.kuvaszuptime/kuvasz-application/reflect-config.json b/src/main/resources/META-INF/native-image/com.kuvaszuptime/kuvasz-application/reflect-config.json index 24de86d..717628d 100644 --- a/src/main/resources/META-INF/native-image/com.kuvaszuptime/kuvasz-application/reflect-config.json +++ b/src/main/resources/META-INF/native-image/com.kuvaszuptime/kuvasz-application/reflect-config.json @@ -5,8 +5,8 @@ { "name": "", "parameterTypes": [ - "javax.mail.Session", - "javax.mail.URLName" + "jakarta.mail.Session", + "jakarta.mail.URLName" ] } ] @@ -21,6 +21,6 @@ ] }, { - "name": "javax.activation.MailcapCommandMap" + "name": "jakarta.activation.MailcapCommandMap" } ] diff --git a/src/main/resources/META-INF/native-image/com.kuvaszuptime/kuvasz-application/resource-config.json b/src/main/resources/META-INF/native-image/com.kuvaszuptime/kuvasz-application/resource-config.json index 75d273c..912a77a 100644 --- a/src/main/resources/META-INF/native-image/com.kuvaszuptime/kuvasz-application/resource-config.json +++ b/src/main/resources/META-INF/native-image/com.kuvaszuptime/kuvasz-application/resource-config.json @@ -16,7 +16,7 @@ "pattern": "\\QMETA-INF/mailcap\\E" }, { - "pattern": "\\QMETA-INF/services/javax.mail.Provider\\E" + "pattern": "\\QMETA-INF/services/jakarta.mail.Provider\\E" } ], "bundles": [] diff --git a/src/test/kotlin/com/kuvaszuptime/kuvasz/DatabaseBehaviorSpec.kt b/src/test/kotlin/com/kuvaszuptime/kuvasz/DatabaseBehaviorSpec.kt index f643f29..665949d 100644 --- a/src/test/kotlin/com/kuvaszuptime/kuvasz/DatabaseBehaviorSpec.kt +++ b/src/test/kotlin/com/kuvaszuptime/kuvasz/DatabaseBehaviorSpec.kt @@ -3,8 +3,8 @@ package com.kuvaszuptime.kuvasz import io.kotest.core.spec.style.BehaviorSpec import io.kotest.core.test.TestCase import io.kotest.core.test.TestResult +import jakarta.inject.Inject import org.flywaydb.core.Flyway -import javax.inject.Inject abstract class DatabaseBehaviorSpec(body: BehaviorSpec.() -> Unit = {}) : BehaviorSpec(body) { diff --git a/src/test/kotlin/com/kuvaszuptime/kuvasz/config/AppConfigTest.kt b/src/test/kotlin/com/kuvaszuptime/kuvasz/config/AppConfigTest.kt index 16b9e66..9c7d9ee 100644 --- a/src/test/kotlin/com/kuvaszuptime/kuvasz/config/AppConfigTest.kt +++ b/src/test/kotlin/com/kuvaszuptime/kuvasz/config/AppConfigTest.kt @@ -23,7 +23,7 @@ class AppConfigTest : BehaviorSpec( ApplicationContext.run(properties) } exceptionToMessage(exception) shouldContain - "Error resolving property value [app-config.data-retention-days]" + "Error resolving property value [app-config.data-retention-days]" } } diff --git a/src/test/kotlin/com/kuvaszuptime/kuvasz/config/TelegramEventHandlerConfigTest.kt b/src/test/kotlin/com/kuvaszuptime/kuvasz/config/TelegramEventHandlerConfigTest.kt index 2b21139..0b19a99 100644 --- a/src/test/kotlin/com/kuvaszuptime/kuvasz/config/TelegramEventHandlerConfigTest.kt +++ b/src/test/kotlin/com/kuvaszuptime/kuvasz/config/TelegramEventHandlerConfigTest.kt @@ -24,8 +24,8 @@ class TelegramEventHandlerConfigTest : BehaviorSpec( ApplicationContext.run(properties) } exceptionToMessage(exception) shouldContain - "Bean definition [com.kuvaszuptime.kuvasz.handlers.TelegramEventHandler] " + - "could not be loaded" + "Bean definition [com.kuvaszuptime.kuvasz.handlers.TelegramEventHandler] " + + "could not be loaded" } } @@ -42,8 +42,8 @@ class TelegramEventHandlerConfigTest : BehaviorSpec( ApplicationContext.run(properties) } exceptionToMessage(exception) shouldContain - "Bean definition [com.kuvaszuptime.kuvasz.handlers.TelegramEventHandler] " + - "could not be loaded" + "Bean definition [com.kuvaszuptime.kuvasz.handlers.TelegramEventHandler] " + + "could not be loaded" } } @@ -61,8 +61,8 @@ class TelegramEventHandlerConfigTest : BehaviorSpec( ApplicationContext.run(properties) } exceptionToMessage(exception) shouldContain - "Bean definition [com.kuvaszuptime.kuvasz.handlers.TelegramEventHandler] " + - "could not be loaded" + "Bean definition [com.kuvaszuptime.kuvasz.handlers.TelegramEventHandler] " + + "could not be loaded" } } } diff --git a/src/test/kotlin/com/kuvaszuptime/kuvasz/controllers/GlobalErrorHandlerTest.kt b/src/test/kotlin/com/kuvaszuptime/kuvasz/controllers/GlobalErrorHandlerTest.kt index 461c30a..ce68447 100644 --- a/src/test/kotlin/com/kuvaszuptime/kuvasz/controllers/GlobalErrorHandlerTest.kt +++ b/src/test/kotlin/com/kuvaszuptime/kuvasz/controllers/GlobalErrorHandlerTest.kt @@ -1,14 +1,9 @@ package com.kuvaszuptime.kuvasz.controllers -import com.kuvaszuptime.kuvasz.models.DuplicationError -import com.kuvaszuptime.kuvasz.models.PersistenceError -import com.kuvaszuptime.kuvasz.models.SchedulingError -import com.kuvaszuptime.kuvasz.models.ServiceError +import com.kuvaszuptime.kuvasz.models.* import com.kuvaszuptime.kuvasz.models.dto.MonitorCreateDto import com.kuvaszuptime.kuvasz.services.MonitorCrudService import com.kuvaszuptime.kuvasz.tables.pojos.MonitorPojo -import com.kuvaszuptime.kuvasz.testutils.getLowLevelClient -import com.kuvaszuptime.kuvasz.testutils.startTestApplication import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.BehaviorSpec import io.kotest.matchers.shouldBe @@ -16,109 +11,135 @@ import io.kotest.matchers.string.shouldStartWith import io.micronaut.core.type.Argument import io.micronaut.http.HttpRequest import io.micronaut.http.HttpStatus +import io.micronaut.http.client.HttpClient +import io.micronaut.http.client.annotation.Client import io.micronaut.http.client.exceptions.HttpClientResponseException +import io.micronaut.test.annotation.MockBean +import io.micronaut.test.extensions.kotest.MicronautKotestExtension.getMock +import io.micronaut.test.extensions.kotest.annotation.MicronautTest import io.mockk.every import io.mockk.mockk -class GlobalErrorHandlerTest : BehaviorSpec( - { - val crudServiceMock = mockk() - val server = startTestApplication(mockBeans = listOf(crudServiceMock)) - val client = server.getLowLevelClient() - - given("an endpoint that accepts a payload") { - `when`("it is called with an invalid JSON") { - val request = HttpRequest.POST("/monitors", "not-a-json") - val exception = shouldThrow { - client.toBlocking() - .exchange(request, Argument.of(MonitorPojo::class.java), Argument.of(ServiceError::class.java)) - } - then("should return a 400 with the correct error message") { - exception.status shouldBe HttpStatus.BAD_REQUEST - val responseBody = exception.response.getBody(ServiceError::class.java).get() - responseBody.message shouldBe "Can't parse the JSON in the payload" - } +@MicronautTest +class GlobalErrorHandlerTest( + @Client("/") client: HttpClient, + monitorCrudService: MonitorCrudService +) : BehaviorSpec({ + + given("an endpoint that accepts a payload") { + + `when`("it is called with an invalid JSON") { + + val request = HttpRequest.POST("/monitors", "not-a-json") + val exception = shouldThrow { + client.toBlocking() + .exchange(request, Argument.of(MonitorPojo::class.java), Argument.of(ServiceError::class.java)) + } + + then("should return a 400 with the correct error message") { + + exception.status shouldBe HttpStatus.BAD_REQUEST + val responseBody = exception.response.getBody(ServiceError::class.java).get() + responseBody.message shouldBe "Can't parse the JSON in the payload" } + } + + `when`("it is called with a JSON that contains a non-convertible property") { - `when`("it is called with a JSON that contains a non-convertible property") { - val request = - HttpRequest.POST("/monitors", "{\"uptimeCheckInterval\":\"not-a-number\"}") - val exception = shouldThrow { - client.toBlocking() - .exchange(request, Argument.of(MonitorPojo::class.java), Argument.of(ServiceError::class.java)) - } - then("should return a 400 with the correct error message") { - exception.status shouldBe HttpStatus.BAD_REQUEST - val responseBody = exception.response.getBody(ServiceError::class.java).get() - responseBody.message shouldStartWith "Failed to convert argument:" - } + val request = + HttpRequest.POST("/monitors", "{\"uptimeCheckInterval\":\"not-a-number\"}") + val exception = shouldThrow { + client.toBlocking() + .exchange(request, Argument.of(MonitorPojo::class.java), Argument.of(ServiceError::class.java)) } - `when`("it is called with a valid body but the underlying logic throws a PersistenceError") { - val monitorDto = MonitorCreateDto( - name = "test", - url = "https://valid-url.com", - uptimeCheckInterval = 60 - ) - val request = HttpRequest.POST("/monitors", monitorDto) - - every { crudServiceMock.createMonitor(any()) } throws PersistenceError("This is an error message") - - val exception = shouldThrow { - client - .toBlocking() - .exchange(request, Argument.of(MonitorPojo::class.java), Argument.of(ServiceError::class.java)) - } - then("should return a 500 with the correct error message") { - exception.status shouldBe HttpStatus.INTERNAL_SERVER_ERROR - val responseBody = exception.response.getBody(ServiceError::class.java).get() - responseBody.message shouldBe "This is an error message" - } + then("should return a 400 with the correct error message") { + + exception.status shouldBe HttpStatus.BAD_REQUEST + val responseBody = exception.response.getBody(ServiceError::class.java).get() + responseBody.message shouldStartWith "Failed to convert argument:" } + } + + `when`("it is called with a valid body but the underlying logic throws a PersistenceError") { + + val crudServiceMock = getMock(monitorCrudService) + val monitorDto = MonitorCreateDto( + name = "test", + url = "https://valid-url.com", + uptimeCheckInterval = 60 + ) + val request = HttpRequest.POST("/monitors", monitorDto) - `when`("it is called with a valid body but the underlying logic throws a SchedulingError") { - val monitorDto = MonitorCreateDto( - name = "test", - url = "https://valid-url.com", - uptimeCheckInterval = 60 - ) - val request = HttpRequest.POST("/monitors", monitorDto) - - every { crudServiceMock.createMonitor(any()) } throws SchedulingError("This is an error message") - - val exception = shouldThrow { - client - .toBlocking() - .exchange(request, Argument.of(MonitorPojo::class.java), Argument.of(ServiceError::class.java)) - } - then("should return a 500 with the correct error message") { - exception.status shouldBe HttpStatus.INTERNAL_SERVER_ERROR - val responseBody = exception.response.getBody(ServiceError::class.java).get() - responseBody.message shouldBe "This is an error message" - } + every { crudServiceMock.createMonitor(any()) } throws PersistenceError("This is an error message") + + val exception = shouldThrow { + client + .toBlocking() + .exchange(request, Argument.of(MonitorPojo::class.java), Argument.of(ServiceError::class.java)) } - `when`("it is called with a valid body but the underlying logic throws a DuplicationError") { - val monitorDto = MonitorCreateDto( - name = "test", - url = "https://valid-url.com", - uptimeCheckInterval = 60 - ) - val request = HttpRequest.POST("/monitors", monitorDto) - - every { crudServiceMock.createMonitor(any()) } throws DuplicationError("This is an error message") - - val exception = shouldThrow { - client - .toBlocking() - .exchange(request, Argument.of(MonitorPojo::class.java), Argument.of(ServiceError::class.java)) - } - then("should return a 409 with the correct error message") { - exception.status shouldBe HttpStatus.CONFLICT - val responseBody = exception.response.getBody(ServiceError::class.java).get() - responseBody.message shouldBe "This is an error message" - } + then("should return a 500 with the correct error message") { + + exception.status shouldBe HttpStatus.INTERNAL_SERVER_ERROR + val responseBody = exception.response.getBody(ServiceError::class.java).get() + responseBody.message shouldBe "This is an error message" } } + + `when`("it is called with a valid body but the underlying logic throws a SchedulingError") { + + val crudServiceMock = getMock(monitorCrudService) + val monitorDto = MonitorCreateDto( + name = "test", + url = "https://valid-url.com", + uptimeCheckInterval = 60 + ) + val request = HttpRequest.POST("/monitors", monitorDto) + + every { crudServiceMock.createMonitor(any()) } throws SchedulingError("This is an error message") + + val exception = shouldThrow { + client + .toBlocking() + .exchange(request, Argument.of(MonitorPojo::class.java), Argument.of(ServiceError::class.java)) + } + then("should return a 500 with the correct error message") { + exception.status shouldBe HttpStatus.INTERNAL_SERVER_ERROR + val responseBody = exception.response.getBody(ServiceError::class.java).get() + responseBody.message shouldBe "This is an error message" + } + } + + `when`("it is called with a valid body but the underlying logic throws a DuplicationError") { + + val crudServiceMock = getMock(monitorCrudService) + val monitorDto = MonitorCreateDto( + name = "test", + url = "https://valid-url.com", + uptimeCheckInterval = 60 + ) + val request = HttpRequest.POST("/monitors", monitorDto) + + every { crudServiceMock.createMonitor(any()) } throws DuplicationError("This is an error message") + + val exception = shouldThrow { + client + .toBlocking() + .exchange(request, Argument.of(MonitorPojo::class.java), Argument.of(ServiceError::class.java)) + } + + then("should return a 409 with the correct error message") { + + exception.status shouldBe HttpStatus.CONFLICT + val responseBody = exception.response.getBody(ServiceError::class.java).get() + responseBody.message shouldBe "This is an error message" + } + } + } +}) { + @MockBean(MonitorCrudService::class) + fun monitorCrudService(): MonitorCrudService { + return mockk() } -) +} diff --git a/src/test/kotlin/com/kuvaszuptime/kuvasz/controllers/InfoEndpointTest.kt b/src/test/kotlin/com/kuvaszuptime/kuvasz/controllers/InfoEndpointTest.kt index 30c624b..632d52a 100644 --- a/src/test/kotlin/com/kuvaszuptime/kuvasz/controllers/InfoEndpointTest.kt +++ b/src/test/kotlin/com/kuvaszuptime/kuvasz/controllers/InfoEndpointTest.kt @@ -2,8 +2,8 @@ package com.kuvaszuptime.kuvasz.controllers import io.kotest.core.spec.style.BehaviorSpec import io.kotest.matchers.string.shouldContain -import io.micronaut.http.client.RxHttpClient import io.micronaut.http.client.annotation.Client +import io.micronaut.rxjava2.http.client.RxHttpClient import io.micronaut.test.extensions.kotest.annotation.MicronautTest @MicronautTest diff --git a/src/test/kotlin/com/kuvaszuptime/kuvasz/controllers/MonitorControllerTest.kt b/src/test/kotlin/com/kuvaszuptime/kuvasz/controllers/MonitorControllerTest.kt index 1ce4978..77c4b81 100644 --- a/src/test/kotlin/com/kuvaszuptime/kuvasz/controllers/MonitorControllerTest.kt +++ b/src/test/kotlin/com/kuvaszuptime/kuvasz/controllers/MonitorControllerTest.kt @@ -30,9 +30,9 @@ import io.kotest.matchers.shouldNotBe import io.kotest.matchers.string.shouldContain import io.micronaut.http.HttpRequest import io.micronaut.http.HttpStatus -import io.micronaut.http.client.RxHttpClient import io.micronaut.http.client.annotation.Client import io.micronaut.http.client.exceptions.HttpClientResponseException +import io.micronaut.rxjava2.http.client.RxHttpClient import io.micronaut.test.extensions.kotest.annotation.MicronautTest @Suppress("LongParameterList") @@ -257,7 +257,7 @@ class MonitorControllerTest( then("it should return a 400") { response.status shouldBe HttpStatus.BAD_REQUEST exceptionToMessage(response) shouldContain - "uptimeCheckInterval: must be greater than or equal to 60" + "uptimeCheckInterval: must be greater than or equal to 60" } } } diff --git a/src/test/kotlin/com/kuvaszuptime/kuvasz/handlers/SlackEventHandlerTest.kt b/src/test/kotlin/com/kuvaszuptime/kuvasz/handlers/SlackEventHandlerTest.kt index 1b9abe9..2bbc68f 100644 --- a/src/test/kotlin/com/kuvaszuptime/kuvasz/handlers/SlackEventHandlerTest.kt +++ b/src/test/kotlin/com/kuvaszuptime/kuvasz/handlers/SlackEventHandlerTest.kt @@ -4,11 +4,7 @@ import com.kuvaszuptime.kuvasz.DatabaseBehaviorSpec import com.kuvaszuptime.kuvasz.mocks.createMonitor import com.kuvaszuptime.kuvasz.mocks.generateCertificateInfo import com.kuvaszuptime.kuvasz.models.SSLValidationError -import com.kuvaszuptime.kuvasz.models.events.MonitorDownEvent -import com.kuvaszuptime.kuvasz.models.events.MonitorUpEvent -import com.kuvaszuptime.kuvasz.models.events.SSLInvalidEvent -import com.kuvaszuptime.kuvasz.models.events.SSLValidEvent -import com.kuvaszuptime.kuvasz.models.events.SSLWillExpireEvent +import com.kuvaszuptime.kuvasz.models.events.* import com.kuvaszuptime.kuvasz.repositories.LatencyLogRepository import com.kuvaszuptime.kuvasz.repositories.MonitorRepository import com.kuvaszuptime.kuvasz.repositories.SSLEventRepository @@ -27,12 +23,7 @@ import io.micronaut.http.HttpResponse import io.micronaut.http.HttpStatus import io.micronaut.http.client.exceptions.HttpClientResponseException import io.micronaut.test.extensions.kotest.annotation.MicronautTest -import io.mockk.clearAllMocks -import io.mockk.every -import io.mockk.mockk -import io.mockk.slot -import io.mockk.spyk -import io.mockk.verify +import io.mockk.* import io.reactivex.Single import org.jooq.Configuration import java.time.OffsetDateTime @@ -236,7 +227,7 @@ class SlackEventHandlerTest( verify(exactly = 1) { webhookServiceSpy.sendMessage(capture(slot)) } slot.captured shouldContain - "Your site \"${monitor.name}\" (${monitor.url}) has a VALID certificate" + "Your site \"${monitor.name}\" (${monitor.url}) has a VALID certificate" } } @@ -256,7 +247,7 @@ class SlackEventHandlerTest( verify(exactly = 1) { webhookServiceSpy.sendMessage(capture(slot)) } slot.captured shouldContain - "Your site \"${monitor.name}\" (${monitor.url}) has an INVALID certificate" + "Your site \"${monitor.name}\" (${monitor.url}) has an INVALID certificate" } } @@ -382,7 +373,7 @@ class SlackEventHandlerTest( verify(exactly = 1) { webhookServiceSpy.sendMessage(capture(slot)) } slot.captured shouldContain - "Your SSL certificate for ${monitor.url} will expire soon" + "Your SSL certificate for ${monitor.url} will expire soon" } } diff --git a/src/test/kotlin/com/kuvaszuptime/kuvasz/handlers/TelegramEventHandlerTest.kt b/src/test/kotlin/com/kuvaszuptime/kuvasz/handlers/TelegramEventHandlerTest.kt index e34c5f3..71e8b07 100644 --- a/src/test/kotlin/com/kuvaszuptime/kuvasz/handlers/TelegramEventHandlerTest.kt +++ b/src/test/kotlin/com/kuvaszuptime/kuvasz/handlers/TelegramEventHandlerTest.kt @@ -5,11 +5,7 @@ import com.kuvaszuptime.kuvasz.config.handlers.TelegramEventHandlerConfig import com.kuvaszuptime.kuvasz.mocks.createMonitor import com.kuvaszuptime.kuvasz.mocks.generateCertificateInfo import com.kuvaszuptime.kuvasz.models.SSLValidationError -import com.kuvaszuptime.kuvasz.models.events.MonitorDownEvent -import com.kuvaszuptime.kuvasz.models.events.MonitorUpEvent -import com.kuvaszuptime.kuvasz.models.events.SSLInvalidEvent -import com.kuvaszuptime.kuvasz.models.events.SSLValidEvent -import com.kuvaszuptime.kuvasz.models.events.SSLWillExpireEvent +import com.kuvaszuptime.kuvasz.models.events.* import com.kuvaszuptime.kuvasz.repositories.LatencyLogRepository import com.kuvaszuptime.kuvasz.repositories.MonitorRepository import com.kuvaszuptime.kuvasz.repositories.SSLEventRepository @@ -28,12 +24,7 @@ import io.micronaut.http.HttpResponse import io.micronaut.http.HttpStatus import io.micronaut.http.client.exceptions.HttpClientResponseException import io.micronaut.test.extensions.kotest.annotation.MicronautTest -import io.mockk.clearAllMocks -import io.mockk.every -import io.mockk.mockk -import io.mockk.slot -import io.mockk.spyk -import io.mockk.verify +import io.mockk.* import io.reactivex.Single import org.jooq.Configuration import java.time.OffsetDateTime @@ -241,7 +232,7 @@ class TelegramEventHandlerTest( verify(exactly = 1) { apiServiceSpy.sendMessage(capture(slot)) } slot.captured shouldContain - "Your site \"${monitor.name}\" (${monitor.url}) has a VALID certificate" + "Your site \"${monitor.name}\" (${monitor.url}) has a VALID certificate" } } @@ -261,7 +252,7 @@ class TelegramEventHandlerTest( verify(exactly = 1) { apiServiceSpy.sendMessage(capture(slot)) } slot.captured shouldContain - "Your site \"${monitor.name}\" (${monitor.url}) has an INVALID certificate" + "Your site \"${monitor.name}\" (${monitor.url}) has an INVALID certificate" } } @@ -387,7 +378,7 @@ class TelegramEventHandlerTest( verify(exactly = 1) { apiServiceSpy.sendMessage(capture(slot)) } slot.captured shouldContain - "Your SSL certificate for ${monitor.url} will expire soon" + "Your SSL certificate for ${monitor.url} will expire soon" } } diff --git a/src/test/kotlin/com/kuvaszuptime/kuvasz/models/events/formatters/LogMessageFormatterTest.kt b/src/test/kotlin/com/kuvaszuptime/kuvasz/models/events/formatters/LogMessageFormatterTest.kt index 5e4bf3e..d3b653c 100644 --- a/src/test/kotlin/com/kuvaszuptime/kuvasz/models/events/formatters/LogMessageFormatterTest.kt +++ b/src/test/kotlin/com/kuvaszuptime/kuvasz/models/events/formatters/LogMessageFormatterTest.kt @@ -4,12 +4,7 @@ import com.kuvaszuptime.kuvasz.enums.SslStatus import com.kuvaszuptime.kuvasz.enums.UptimeStatus import com.kuvaszuptime.kuvasz.mocks.generateCertificateInfo import com.kuvaszuptime.kuvasz.models.SSLValidationError -import com.kuvaszuptime.kuvasz.models.events.MonitorDownEvent -import com.kuvaszuptime.kuvasz.models.events.MonitorUpEvent -import com.kuvaszuptime.kuvasz.models.events.RedirectEvent -import com.kuvaszuptime.kuvasz.models.events.SSLInvalidEvent -import com.kuvaszuptime.kuvasz.models.events.SSLValidEvent -import com.kuvaszuptime.kuvasz.models.events.SSLWillExpireEvent +import com.kuvaszuptime.kuvasz.models.events.* import com.kuvaszuptime.kuvasz.tables.pojos.MonitorPojo import com.kuvaszuptime.kuvasz.tables.pojos.SslEventPojo import com.kuvaszuptime.kuvasz.tables.pojos.UptimeEventPojo @@ -63,7 +58,7 @@ class LogMessageFormatterTest : BehaviorSpec( previousEvent.startedAt.diffToDuration(event.dispatchedAt).toDurationString() val expectedMessage = "✅ Your monitor \"test_monitor\" (https://test.url) is UP (200). Latency: 300ms. " + - "Was down for $expectedDurationString" + "Was down for $expectedDurationString" formatter.toFormattedMessage(event) shouldBe expectedMessage } } @@ -109,7 +104,7 @@ class LogMessageFormatterTest : BehaviorSpec( previousEvent.startedAt.diffToDuration(event.dispatchedAt).toDurationString() val expectedMessage = "🚨 Your monitor \"test_monitor\" (https://test.url) is DOWN (400). Reason: uptime error. " + - "Was up for $expectedDurationString" + "Was up for $expectedDurationString" formatter.toFormattedMessage(event) shouldBe expectedMessage } } @@ -161,7 +156,7 @@ class LogMessageFormatterTest : BehaviorSpec( previousEvent.startedAt.diffToDuration(event.dispatchedAt).toDurationString() val expectedMessage = "\uD83D\uDD12️ Your site \"test_monitor\" (https://test.url) has a VALID certificate. " + - "Was INVALID for $expectedDurationString" + "Was INVALID for $expectedDurationString" formatter.toFormattedMessage(event) shouldBe expectedMessage } } @@ -197,7 +192,7 @@ class LogMessageFormatterTest : BehaviorSpec( previousEvent.startedAt.diffToDuration(event.dispatchedAt).toDurationString() val expectedMessage = "🚨 Your site \"test_monitor\" (https://test.url) has an INVALID certificate. " + - "Reason: ssl error. Was VALID for $expectedDurationString" + "Reason: ssl error. Was VALID for $expectedDurationString" formatter.toFormattedMessage(event) shouldBe expectedMessage } } @@ -208,7 +203,7 @@ class LogMessageFormatterTest : BehaviorSpec( then("it should return the correct message") { val expectedMessage = "⚠️ Your SSL certificate for https://test.url will expire soon. " + - "Expiry date: ${event.certInfo.validTo}" + "Expiry date: ${event.certInfo.validTo}" formatter.toFormattedMessage(event) shouldBe expectedMessage } } diff --git a/src/test/kotlin/com/kuvaszuptime/kuvasz/models/events/formatters/PlainTextMessageFormatterTest.kt b/src/test/kotlin/com/kuvaszuptime/kuvasz/models/events/formatters/PlainTextMessageFormatterTest.kt index 91ee87a..ab8559d 100644 --- a/src/test/kotlin/com/kuvaszuptime/kuvasz/models/events/formatters/PlainTextMessageFormatterTest.kt +++ b/src/test/kotlin/com/kuvaszuptime/kuvasz/models/events/formatters/PlainTextMessageFormatterTest.kt @@ -4,11 +4,7 @@ import com.kuvaszuptime.kuvasz.enums.SslStatus import com.kuvaszuptime.kuvasz.enums.UptimeStatus import com.kuvaszuptime.kuvasz.mocks.generateCertificateInfo import com.kuvaszuptime.kuvasz.models.SSLValidationError -import com.kuvaszuptime.kuvasz.models.events.MonitorDownEvent -import com.kuvaszuptime.kuvasz.models.events.MonitorUpEvent -import com.kuvaszuptime.kuvasz.models.events.SSLInvalidEvent -import com.kuvaszuptime.kuvasz.models.events.SSLValidEvent -import com.kuvaszuptime.kuvasz.models.events.SSLWillExpireEvent +import com.kuvaszuptime.kuvasz.models.events.* import com.kuvaszuptime.kuvasz.tables.pojos.MonitorPojo import com.kuvaszuptime.kuvasz.tables.pojos.SslEventPojo import com.kuvaszuptime.kuvasz.tables.pojos.UptimeEventPojo @@ -61,7 +57,7 @@ class PlainTextMessageFormatterTest : BehaviorSpec( previousEvent.startedAt.diffToDuration(event.dispatchedAt).toDurationString() val expectedMessage = "Your monitor \"test_monitor\" (https://test.url) is UP (200)\nLatency: 300ms\n" + - "Was down for $expectedDurationString" + "Was down for $expectedDurationString" formatter.toFormattedMessage(event) shouldBe expectedMessage } } @@ -107,7 +103,7 @@ class PlainTextMessageFormatterTest : BehaviorSpec( previousEvent.startedAt.diffToDuration(event.dispatchedAt).toDurationString() val expectedMessage = "Your monitor \"test_monitor\" (https://test.url) is DOWN (400)\nReason: uptime error\n" + - "Was up for $expectedDurationString" + "Was up for $expectedDurationString" formatter.toFormattedMessage(event) shouldBe expectedMessage } } @@ -146,7 +142,7 @@ class PlainTextMessageFormatterTest : BehaviorSpec( previousEvent.startedAt.diffToDuration(event.dispatchedAt).toDurationString() val expectedMessage = "Your site \"test_monitor\" (https://test.url) has a VALID certificate\n" + - "Was INVALID for $expectedDurationString" + "Was INVALID for $expectedDurationString" formatter.toFormattedMessage(event) shouldBe expectedMessage } } @@ -182,7 +178,7 @@ class PlainTextMessageFormatterTest : BehaviorSpec( previousEvent.startedAt.diffToDuration(event.dispatchedAt).toDurationString() val expectedMessage = "Your site \"test_monitor\" (https://test.url) has an INVALID certificate\n" + - "Reason: ssl error\nWas VALID for $expectedDurationString" + "Reason: ssl error\nWas VALID for $expectedDurationString" formatter.toFormattedMessage(event) shouldBe expectedMessage } } @@ -193,7 +189,7 @@ class PlainTextMessageFormatterTest : BehaviorSpec( then("it should return the correct message") { val expectedMessage = "Your SSL certificate for https://test.url will expire soon\n" + - "Expiry date: ${event.certInfo.validTo}" + "Expiry date: ${event.certInfo.validTo}" formatter.toFormattedMessage(event) shouldBe expectedMessage } } diff --git a/src/test/kotlin/com/kuvaszuptime/kuvasz/models/events/formatters/SlackTextFormatterTest.kt b/src/test/kotlin/com/kuvaszuptime/kuvasz/models/events/formatters/SlackTextFormatterTest.kt index e493606..ebbcde5 100644 --- a/src/test/kotlin/com/kuvaszuptime/kuvasz/models/events/formatters/SlackTextFormatterTest.kt +++ b/src/test/kotlin/com/kuvaszuptime/kuvasz/models/events/formatters/SlackTextFormatterTest.kt @@ -61,7 +61,7 @@ class SlackTextFormatterTest : BehaviorSpec( previousEvent.startedAt.diffToDuration(event.dispatchedAt).toDurationString() val expectedMessage = "✅ *Your monitor \"test_monitor\" (https://test.url) is UP (200)*\n_Latency: 300ms_\n" + - "Was down for $expectedDurationString" + "Was down for $expectedDurationString" formatter.toFormattedMessage(event) shouldBe expectedMessage } } @@ -107,7 +107,7 @@ class SlackTextFormatterTest : BehaviorSpec( previousEvent.startedAt.diffToDuration(event.dispatchedAt).toDurationString() val expectedMessage = "🚨 *Your monitor \"test_monitor\" (https://test.url) is DOWN (400)*\n" + - "Was up for $expectedDurationString" + "Was up for $expectedDurationString" formatter.toFormattedMessage(event) shouldBe expectedMessage } } @@ -146,7 +146,7 @@ class SlackTextFormatterTest : BehaviorSpec( previousEvent.startedAt.diffToDuration(event.dispatchedAt).toDurationString() val expectedMessage = "\uD83D\uDD12️ *Your site \"test_monitor\" (https://test.url) has a VALID certificate*\n" + - "Was INVALID for $expectedDurationString" + "Was INVALID for $expectedDurationString" formatter.toFormattedMessage(event) shouldBe expectedMessage } } @@ -157,7 +157,7 @@ class SlackTextFormatterTest : BehaviorSpec( then("it should return the correct message") { val expectedMessage = "🚨 *Your site \"test_monitor\" (https://test.url) has an INVALID " + - "certificate*\n_Reason: ssl error_" + "certificate*\n_Reason: ssl error_" formatter.toFormattedMessage(event) shouldBe expectedMessage } } @@ -168,7 +168,7 @@ class SlackTextFormatterTest : BehaviorSpec( then("it should return the correct message") { val expectedMessage = "🚨 *Your site \"test_monitor\" (https://test.url) has an INVALID " + - "certificate*\n_Reason: ssl error_" + "certificate*\n_Reason: ssl error_" formatter.toFormattedMessage(event) shouldBe expectedMessage } } @@ -183,7 +183,7 @@ class SlackTextFormatterTest : BehaviorSpec( previousEvent.startedAt.diffToDuration(event.dispatchedAt).toDurationString() val expectedMessage = "🚨 *Your site \"test_monitor\" (https://test.url) has an INVALID certificate*\n" + - "_Reason: ssl error_\nWas VALID for $expectedDurationString" + "_Reason: ssl error_\nWas VALID for $expectedDurationString" formatter.toFormattedMessage(event) shouldBe expectedMessage } } @@ -194,7 +194,7 @@ class SlackTextFormatterTest : BehaviorSpec( then("it should return the correct message") { val expectedMessage = "⚠️ *Your SSL certificate for https://test.url will expire soon*\n" + - "_Expiry date: ${event.certInfo.validTo}_" + "_Expiry date: ${event.certInfo.validTo}_" formatter.toFormattedMessage(event) shouldBe expectedMessage } } diff --git a/src/test/kotlin/com/kuvaszuptime/kuvasz/models/events/formatters/TelegramTextFormatterTest.kt b/src/test/kotlin/com/kuvaszuptime/kuvasz/models/events/formatters/TelegramTextFormatterTest.kt index 87911d1..2c8f5ec 100644 --- a/src/test/kotlin/com/kuvaszuptime/kuvasz/models/events/formatters/TelegramTextFormatterTest.kt +++ b/src/test/kotlin/com/kuvaszuptime/kuvasz/models/events/formatters/TelegramTextFormatterTest.kt @@ -61,7 +61,7 @@ class TelegramTextFormatterTest : BehaviorSpec( previousEvent.startedAt.diffToDuration(event.dispatchedAt).toDurationString() val expectedMessage = "✅ Your monitor \"test_monitor\" (https://test.url) is UP (200)\nLatency: 300ms" + - "\nWas down for $expectedDurationString" + "\nWas down for $expectedDurationString" formatter.toFormattedMessage(event) shouldBe expectedMessage } } @@ -107,7 +107,7 @@ class TelegramTextFormatterTest : BehaviorSpec( previousEvent.startedAt.diffToDuration(event.dispatchedAt).toDurationString() val expectedMessage = "🚨 Your monitor \"test_monitor\" (https://test.url) is DOWN (400)\n" + - "Was up for $expectedDurationString" + "Was up for $expectedDurationString" formatter.toFormattedMessage(event) shouldBe expectedMessage } } @@ -146,7 +146,7 @@ class TelegramTextFormatterTest : BehaviorSpec( previousEvent.startedAt.diffToDuration(event.dispatchedAt).toDurationString() val expectedMessage = "\uD83D\uDD12️ Your site \"test_monitor\" (https://test.url) has a VALID certificate\n" + - "Was INVALID for $expectedDurationString" + "Was INVALID for $expectedDurationString" formatter.toFormattedMessage(event) shouldBe expectedMessage } } @@ -157,7 +157,7 @@ class TelegramTextFormatterTest : BehaviorSpec( then("it should return the correct message") { val expectedMessage = "🚨 Your site \"test_monitor\" (https://test.url) has an INVALID " + - "certificate\nReason: ssl error" + "certificate\nReason: ssl error" formatter.toFormattedMessage(event) shouldBe expectedMessage } } @@ -168,7 +168,7 @@ class TelegramTextFormatterTest : BehaviorSpec( then("it should return the correct message") { val expectedMessage = "🚨 Your site \"test_monitor\" (https://test.url) has an INVALID " + - "certificate\nReason: ssl error" + "certificate\nReason: ssl error" formatter.toFormattedMessage(event) shouldBe expectedMessage } } @@ -183,7 +183,7 @@ class TelegramTextFormatterTest : BehaviorSpec( previousEvent.startedAt.diffToDuration(event.dispatchedAt).toDurationString() val expectedMessage = "🚨 Your site \"test_monitor\" (https://test.url) has an INVALID certificate\n" + - "Reason: ssl error\nWas VALID for $expectedDurationString" + "Reason: ssl error\nWas VALID for $expectedDurationString" formatter.toFormattedMessage(event) shouldBe expectedMessage } } @@ -194,7 +194,7 @@ class TelegramTextFormatterTest : BehaviorSpec( then("it should return the correct message") { val expectedMessage = "⚠️ Your SSL certificate for https://test.url will expire soon\n" + - "Expiry date: ${event.certInfo.validTo}" + "Expiry date: ${event.certInfo.validTo}" formatter.toFormattedMessage(event) shouldBe expectedMessage } } diff --git a/src/test/kotlin/com/kuvaszuptime/kuvasz/security/AuthenticationTest.kt b/src/test/kotlin/com/kuvaszuptime/kuvasz/security/AuthenticationTest.kt index 1ed2ed5..15f7bb1 100644 --- a/src/test/kotlin/com/kuvaszuptime/kuvasz/security/AuthenticationTest.kt +++ b/src/test/kotlin/com/kuvaszuptime/kuvasz/security/AuthenticationTest.kt @@ -11,9 +11,9 @@ import io.kotest.matchers.shouldNotBe import io.micronaut.context.annotation.Property import io.micronaut.http.HttpRequest import io.micronaut.http.HttpStatus -import io.micronaut.http.client.RxHttpClient import io.micronaut.http.client.annotation.Client import io.micronaut.http.client.exceptions.HttpClientResponseException +import io.micronaut.rxjava2.http.client.RxHttpClient import io.micronaut.security.token.jwt.render.BearerAccessRefreshToken import io.micronaut.test.extensions.kotest.annotation.MicronautTest diff --git a/src/test/kotlin/com/kuvaszuptime/kuvasz/services/CheckSchedulerTest.kt b/src/test/kotlin/com/kuvaszuptime/kuvasz/services/CheckSchedulerTest.kt index 9288a20..038fd1a 100644 --- a/src/test/kotlin/com/kuvaszuptime/kuvasz/services/CheckSchedulerTest.kt +++ b/src/test/kotlin/com/kuvaszuptime/kuvasz/services/CheckSchedulerTest.kt @@ -56,7 +56,7 @@ class CheckSchedulerTest( `when`( "there is an enabled monitor in the database with disabled SSL checks" + - " and initialize has been called" + " and initialize has been called" ) { val monitor = createMonitor(monitorRepository, sslCheckEnabled = false) diff --git a/src/test/kotlin/com/kuvaszuptime/kuvasz/services/SSLCheckerTest.kt b/src/test/kotlin/com/kuvaszuptime/kuvasz/services/SSLCheckerTest.kt index 5531b57..0774f5e 100644 --- a/src/test/kotlin/com/kuvaszuptime/kuvasz/services/SSLCheckerTest.kt +++ b/src/test/kotlin/com/kuvaszuptime/kuvasz/services/SSLCheckerTest.kt @@ -185,9 +185,9 @@ class SSLCheckerTest( ) { val certInfo = CertificateInfo(validTo) val mockResult: Either = when (status) { - SslStatus.VALID -> Either.right(certInfo) - SslStatus.WILL_EXPIRE -> Either.right(certInfo) - SslStatus.INVALID -> Either.left(SSLValidationError("validation error")) + SslStatus.VALID -> Either.Right(certInfo) + SslStatus.WILL_EXPIRE -> Either.Right(certInfo) + SslStatus.INVALID -> Either.Left(SSLValidationError("validation error")) } every { sslValidator.validate(any()) } returns mockResult } diff --git a/src/test/kotlin/com/kuvaszuptime/kuvasz/testutils/MicronautTestUtils.kt b/src/test/kotlin/com/kuvaszuptime/kuvasz/testutils/MicronautTestUtils.kt deleted file mode 100644 index a7859ce..0000000 --- a/src/test/kotlin/com/kuvaszuptime/kuvasz/testutils/MicronautTestUtils.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.kuvaszuptime.kuvasz.testutils - -import io.micronaut.context.ApplicationContext -import io.micronaut.http.client.RxHttpClient -import io.micronaut.runtime.server.EmbeddedServer - -fun startTestApplication(mockBeans: List = emptyList(), withRealAuth: Boolean = false): EmbeddedServer = - ApplicationContext - .build() - .apply { - if (withRealAuth) { - properties(mapOf("micronaut.security.enabled" to "true")) - } - } - .build() - .apply { - mockBeans.forEach { registerSingleton(it) } - } - .start() - .getBean(EmbeddedServer::class.java) - .start() - -inline fun EmbeddedServer.getBean(): T = this.applicationContext.getBean(T::class.java) - -fun EmbeddedServer.getLowLevelClient(): RxHttpClient = - this.applicationContext.createBean(RxHttpClient::class.java, this.url) diff --git a/src/test/kotlin/com/kuvaszuptime/kuvasz/testutils/TestDbContainer.kt b/src/test/kotlin/com/kuvaszuptime/kuvasz/testutils/TestDbContainer.kt index f127587..18609db 100644 --- a/src/test/kotlin/com/kuvaszuptime/kuvasz/testutils/TestDbContainer.kt +++ b/src/test/kotlin/com/kuvaszuptime/kuvasz/testutils/TestDbContainer.kt @@ -4,12 +4,11 @@ import org.testcontainers.containers.PostgreSQLContainer class TestDbContainer : PostgreSQLContainer("postgres:12") { companion object { - lateinit var instance: TestDbContainer + private lateinit var instance: TestDbContainer fun start() { if (!Companion::instance.isInitialized) { - instance = - TestDbContainer() + instance = TestDbContainer() instance.start() System.setProperty("datasources.default.url", instance.jdbcUrl) diff --git a/src/test/kotlin/com/kuvaszuptime/kuvasz/testutils/TestMailhogContainer.kt b/src/test/kotlin/com/kuvaszuptime/kuvasz/testutils/TestMailhogContainer.kt index 520c1b7..d1f1e7c 100644 --- a/src/test/kotlin/com/kuvaszuptime/kuvasz/testutils/TestMailhogContainer.kt +++ b/src/test/kotlin/com/kuvaszuptime/kuvasz/testutils/TestMailhogContainer.kt @@ -3,25 +3,24 @@ package com.kuvaszuptime.kuvasz.testutils import com.kuvaszuptime.kuvasz.config.TransportStrategy import org.testcontainers.containers.GenericContainer -class TestMailhogContainer : GenericContainer("mailhog/mailhog") { - companion object { - lateinit var instance: TestMailhogContainer - const val SMTP_PORT = 1025 - const val HTTP_PORT = 8025 +class KGenericContainer(imageName: String) : GenericContainer(imageName) - fun start() { - if (!Companion::instance.isInitialized) { - instance = TestMailhogContainer().withExposedPorts(SMTP_PORT, HTTP_PORT) - instance.start() +object TestMailhogContainer { + private lateinit var instance: KGenericContainer + private const val IMAGE_NAME = "mailhog/mailhog" + private const val SMTP_PORT = 1025 + private const val HTTP_PORT = 8025 - System.setProperty("smtp-config.host", instance.containerIpAddress) - System.setProperty("smtp-config.port", instance.getMappedPort(SMTP_PORT).toString()) - System.setProperty("smtp-config.transport-strategy", TransportStrategy.SMTP.name) - } - } + fun start() { + instance = KGenericContainer(IMAGE_NAME).withExposedPorts(SMTP_PORT, HTTP_PORT) + instance.start() - fun stop() { - instance.stop() - } + System.setProperty("smtp-config.host", instance.containerIpAddress) + System.setProperty("smtp-config.port", instance.getMappedPort(SMTP_PORT).toString()) + System.setProperty("smtp-config.transport-strategy", TransportStrategy.SMTP.name) + } + + fun stop() { + instance.stop() } }