Skip to content

Commit

Permalink
chore(java17): upgrade java runtime to JRE17 and compilation using JD…
Browse files Browse the repository at this point in the history
…K17, but target remains Java11

While upgrading java 17, encountered below error during the test execution process of keel-core-test and keel-sql modules:
```
retrieves timestamp successfully

SqlArtifactRepositoryTests retrieves timestamp successfully FAILED (11.5s)

  ▼ Expect that 2024-11-04T16:23:59.680067Z:
    ✗ is equal to 2024-11-04T16:23:59.680066531Z
            found 2024-11-04T16:23:59.680067Z
```

```
SqlDeliveryConfigRepositoryTests deletes data successfully for known application FAILED (11.5s)

  org.jooq.exception.DataAccessException: SQL [insert into `keel`.`event` (`uid`, `scope`, `json`) values (?, ?, ?)]; Incorrect datetime value: '2024-11-04T16:47:17.740578522Z' for function str_to_date

  Caused by: java.sql.SQLException: Incorrect datetime value: '2024-11-04T16:47:17.740578522Z' for function str_to_date

SqlDeliveryConfigRepositoryTests throws exception for unknown application FAILED (12.8s)

  org.jooq.exception.DataAccessException: SQL [insert into `keel`.`event` (`uid`, `scope`, `json`) values (?, ?, ?)]; Incorrect datetime value: '2024-11-04T16:47:29.434469839Z' for function str_to_date

  Caused by: java.sql.SQLException: Incorrect datetime value: '2024-11-04T16:47:29.434469839Z' for function str_to_date

SqlDeliveryConfigRepositoryTests deletes related application events FAILED (12s)

  org.jooq.exception.DataAccessException: SQL [insert into `keel`.`event` (`uid`, `scope`, `json`) values (?, ?, ?)]; Incorrect datetime value: '2024-11-04T16:47:42.199694193Z' for function str_to_date

  Caused by: java.sql.SQLException: Incorrect datetime value: '2024-11-04T16:47:42.199694193Z' for function str_to_date

SqlDeliveryConfigRepositoryTests deletes related resource events FAILED (12.6s)

  org.jooq.exception.DataAccessException: SQL [insert into `keel`.`event` (`uid`, `scope`, `json`) values (?, ?, ?)]; Incorrect datetime value: '2024-11-04T16:47:54.338147807Z' for function str_to_date

  Caused by: java.sql.SQLException: Incorrect datetime value: '2024-11-04T16:47:54.338147807Z' for function str_to_date

SqlDeliveryConfigRepositoryTests deletes related application pause records FAILED (11.5s)

  org.jooq.exception.DataAccessException: SQL [insert into `keel`.`event` (`uid`, `scope`, `json`) values (?, ?, ?)]; Incorrect datetime value: '2024-11-04T16:48:06.896010045Z' for function str_to_date

  Caused by: java.sql.SQLException: Incorrect datetime value: '2024-11-04T16:48:06.896010045Z' for function str_to_date

SqlDeliveryConfigRepositoryTests deletes related resource pause records FAILED (12.6s)

  org.jooq.exception.DataAccessException: SQL [insert into `keel`.`event` (`uid`, `scope`, `json`) values (?, ?, ?)]; Incorrect datetime value: '2024-11-04T16:48:18.409434437Z' for function str_to_date

  Caused by: java.sql.SQLException: Incorrect datetime value: '2024-11-04T16:48:18.409434437Z' for function str_to_date

SqlDeliveryConfigRepositoryTests deletes any older versions of resources FAILED (11.8s)

  org.jooq.exception.DataAccessException: SQL [insert into `keel`.`event` (`uid`, `scope`, `json`) values (?, ?, ?)]; Incorrect datetime value: '2024-11-04T16:48:31.166252032Z' for function str_to_date

  Caused by: java.sql.SQLException: Incorrect datetime value: '2024-11-04T16:48:31.166252032Z' for function str_to_date

SqlDeliveryConfigRepositoryTests deletes data successfully for known delivery config FAILED (11.7s)

  org.jooq.exception.DataAccessException: SQL [insert into `keel`.`event` (`uid`, `scope`, `json`) values (?, ?, ?)]; Incorrect datetime value: '2024-11-04T16:48:42.855107042Z' for function str_to_date

  Caused by: java.sql.SQLException: Incorrect datetime value: '2024-11-04T16:48:42.855107042Z' for function str_to_date

SqlDeliveryConfigRepositoryTests throws exception for unknown delivery config FAILED (12.1s)

  org.jooq.exception.DataAccessException: SQL [insert into `keel`.`event` (`uid`, `scope`, `json`) values (?, ?, ?)]; Incorrect datetime value: '2024-11-04T16:48:54.920960756Z' for function str_to_date

  Caused by: java.sql.SQLException: Incorrect datetime value: '2024-11-04T16:48:54.920960756Z' for function str_to_date

```
The error occurred due to change in behaviour of `java.time.Instant` class from Java 11 to Java 17. In Java 17, Instant class returns clock with precision of microsecond and nanosecond based on underlying system, which is not the case with Java 11. This causes the MYSQL str_to_date function fail while data insertion.
In order to fix this issue, truncated the microseconds from the Instant.

https://stackoverflow.com/questions/74781495/changes-in-instant-now-between-java-11-and-java-17-in-aws-ubuntu-standard-6-0
  • Loading branch information
j-sandy committed Nov 14, 2024
1 parent 072ccd6 commit 45770a3
Show file tree
Hide file tree
Showing 14 changed files with 137 additions and 41 deletions.
31 changes: 29 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ jobs:
uses: docker/setup-buildx-action@v3
- uses: actions/setup-java@v4
with:
java-version: 11
java-version: |
11
17
distribution: 'zulu'
cache: 'gradle'
- name: Prepare build variables
Expand All @@ -36,7 +38,7 @@ jobs:
- name: Build
env:
ORG_GRADLE_PROJECT_version: ${{ steps.build_variables.outputs.VERSION }}
run: ./gradlew build --stacktrace ${{ steps.build_variables.outputs.REPO }}-web:installDist
run: ./gradlew -PenableCrossCompilerPlugin=true build --stacktrace ${{ steps.build_variables.outputs.REPO }}-web:installDist
- name: Login to GAR
# Only run this on repositories in the 'spinnaker' org, not on forks.
if: startsWith(github.repository, 'spinnaker/')
Expand Down Expand Up @@ -71,3 +73,28 @@ jobs:
tags: |
"${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ github.ref_name }}-latest-unvalidated-ubuntu"
"${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.build_variables.outputs.VERSION }}-unvalidated-ubuntu"
- name: Build and publish slim JRE 11 container image
# Only run this on repositories in the 'spinnaker' org, not on forks.
if: startsWith(github.repository, 'spinnaker/')
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile.java11.slim
platforms: linux/amd64,linux/arm64
push: true
tags: |
"${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ github.ref_name }}-latest-java11-unvalidated"
"${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.build_variables.outputs.VERSION }}-java11-unvalidated"
"${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ github.ref_name }}-latest-java11-unvalidated-slim"
"${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.build_variables.outputs.VERSION }}-java11-unvalidated-slim"
- name: Build and publish ubuntu JRE11 container image
# Only run this on repositories in the 'spinnaker' org, not on forks.
if: startsWith(github.repository, 'spinnaker/')
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile.java11.ubuntu
push: true
tags: |
"${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ github.ref_name }}-latest-java11-unvalidated-ubuntu"
"${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.build_variables.outputs.VERSION }}-java11-unvalidated-ubuntu"
26 changes: 24 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ jobs:
uses: docker/setup-buildx-action@v3
- uses: actions/setup-java@v4
with:
java-version: 11
java-version: |
11
17
distribution: 'zulu'
cache: 'gradle'
- name: Prepare build variables
Expand All @@ -30,7 +32,7 @@ jobs:
- name: Build
env:
ORG_GRADLE_PROJECT_version: ${{ steps.build_variables.outputs.VERSION }}
run: ./gradlew build ${{ steps.build_variables.outputs.REPO }}-web:installDist
run: ./gradlew -PenableCrossCompilerPlugin=true build ${{ steps.build_variables.outputs.REPO }}-web:installDist
- name: Build slim container image
uses: docker/build-push-action@v6
with:
Expand All @@ -51,3 +53,23 @@ jobs:
tags: |
"${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:latest-ubuntu"
"${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.build_variables.outputs.VERSION }}-ubuntu"
- name: Build slim JRE 11 container image
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile.java11.slim
platforms: linux/amd64,linux/arm64
tags: |
"${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:latest-java11"
"${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.build_variables.outputs.VERSION }}-java11"
"${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:latest-java11-slim"
"${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.build_variables.outputs.VERSION }}-java11-slim"
- name: Build ubuntu JRE 11 container image
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile.java11.ubuntu
platforms: linux/amd64,linux/arm64
tags: |
"${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:latest-java11-ubuntu"
"${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.build_variables.outputs.VERSION }}-java11-ubuntu"
33 changes: 30 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ jobs:
uses: docker/setup-buildx-action@v3
- uses: actions/setup-java@v4
with:
java-version: 11
java-version: |
11
17
distribution: 'zulu'
cache: 'gradle'
- name: Assemble release info
Expand All @@ -50,14 +52,14 @@ jobs:
ORG_GRADLE_PROJECT_nexusPgpSigningKey: ${{ secrets.NEXUS_PGP_SIGNING_KEY }}
ORG_GRADLE_PROJECT_nexusPgpSigningPassword: ${{ secrets.NEXUS_PGP_SIGNING_PASSWORD }}
run: |
./gradlew --info build ${{ steps.build_variables.outputs.REPO }}-web:installDist publishToNexus closeAndReleaseNexusStagingRepository
./gradlew --info -PenableCrossCompilerPlugin=true build ${{ steps.build_variables.outputs.REPO }}-web:installDist publishToNexus closeAndReleaseNexusStagingRepository
- name: Publish apt packages to Google Artifact Registry
env:
ORG_GRADLE_PROJECT_version: ${{ steps.release_info.outputs.RELEASE_VERSION }}
ORG_GRADLE_PROJECT_artifactRegistryPublishEnabled: true
GAR_JSON_KEY: ${{ secrets.GAR_JSON_KEY }}
run: |
./gradlew --info publish
./gradlew --info -PenableCrossCompilerPlugin=true publish
- name: Login to GAR
# Only run this on repositories in the 'spinnaker' org, not on forks.
if: startsWith(github.repository, 'spinnaker/')
Expand Down Expand Up @@ -92,6 +94,31 @@ jobs:
tags: |
"${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.release_info.outputs.RELEASE_VERSION }}-unvalidated-ubuntu"
"${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.release_info.outputs.RELEASE_VERSION }}-${{ steps.build_variables.outputs.VERSION }}-unvalidated-ubuntu"
- name: Build and publish slim JRE 11 container image
# Only run this on repositories in the 'spinnaker' org, not on forks.
if: startsWith(github.repository, 'spinnaker/')
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile.java11.slim
platforms: linux/amd64,linux/arm64
push: true
tags: |
"${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.release_info.outputs.RELEASE_VERSION }}-java11-unvalidated"
"${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.release_info.outputs.RELEASE_VERSION }}-java11-unvalidated-slim"
"${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.release_info.outputs.RELEASE_VERSION }}-${{ steps.build_variables.outputs.VERSION }}-java11-unvalidated-slim"
- name: Build and publish ubuntu JRE 11 container image
# Only run this on repositories in the 'spinnaker' org, not on forks.
if: startsWith(github.repository, 'spinnaker/')
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile.java11.ubuntu
platforms: linux/amd64,linux/arm64
push: true
tags: |
"${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.release_info.outputs.RELEASE_VERSION }}-java11-unvalidated-ubuntu"
"${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.release_info.outputs.RELEASE_VERSION }}-${{ steps.build_variables.outputs.VERSION }}-java11-unvalidated-ubuntu"
- name: Create release
if: steps.release_info.outputs.SKIP_RELEASE == 'false'
uses: softprops/action-gh-release@v2
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.compile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ LABEL maintainer="sig-platform@spinnaker.io"
RUN echo "mysql-server mysql-server/root_password password sa" | debconf-set-selections
RUN echo "mysql-server mysql-server/root_password_again password sa" | debconf-set-selections
RUN apt-get update && apt-get install -y \
openjdk-11-jdk \
openjdk-17-jdk \
mysql-server \
&& rm -rf /var/lib/apt/lists/*
ENV GRADLE_USER_HOME /workspace/.gradle
Expand Down
9 changes: 9 additions & 0 deletions Dockerfile.java11.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM alpine:3.11
LABEL maintainer="sig-platform@spinnaker.io"
RUN apk --no-cache add --update bash openjdk11-jre
RUN addgroup -S -g 10111 spinnaker
RUN adduser -S -G spinnaker -u 10111 spinnaker
COPY keel-web/build/install/keel /opt/keel
RUN mkdir -p /opt/keel/plugins && chown -R spinnaker:nogroup /opt/keel/plugins
USER spinnaker
CMD ["/opt/keel/bin/keel"]
8 changes: 8 additions & 0 deletions Dockerfile.java11.ubuntu
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM ubuntu:bionic
LABEL maintainer="sig-platform@spinnaker.io"
RUN apt-get update && apt-get -y install openjdk-11-jre-headless wget
RUN adduser --system --uid 10111 --group spinnaker
COPY keel-web/build/install/keel /opt/keel
RUN mkdir -p /opt/keel/plugins && chown -R spinnaker:nogroup /opt/keel/plugins
USER spinnaker
CMD ["/opt/keel/bin/keel"]
4 changes: 2 additions & 2 deletions Dockerfile.slim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM alpine:3.11
FROM alpine:3.16
LABEL maintainer="sig-platform@spinnaker.io"
RUN apk --no-cache add --update bash openjdk11-jre
RUN apk --no-cache add --update bash openjdk17-jre
RUN addgroup -S -g 10111 spinnaker
RUN adduser -S -G spinnaker -u 10111 spinnaker
COPY keel-web/build/install/keel /opt/keel
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.ubuntu
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM ubuntu:bionic
LABEL maintainer="sig-platform@spinnaker.io"
RUN apt-get update && apt-get -y install openjdk-11-jre-headless wget
RUN apt-get update && apt-get -y install openjdk-17-jre-headless wget
RUN adduser --system --uid 10111 --group spinnaker
COPY keel-web/build/install/keel /opt/keel
RUN mkdir -p /opt/keel/plugins && chown -R spinnaker:nogroup /opt/keel/plugins
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ allprojects {
apply(plugin: "com.diffplug.spotless")

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

dependencies {
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ testContainersVersion=1.15.3
okHttpVersion=4.5.0
resilience4jVersion=1.5.0
spinnakerGradleVersion=8.32.1
targetJava17=false

# Used to control whether to spin up docker to run liquibase before jooq
buildingInDocker=false
Expand Down
8 changes: 4 additions & 4 deletions gradle/kotlin.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ apply plugin: "kotlin-allopen"
compileKotlin {
kotlinOptions {
languageVersion = "1.6"
jvmTarget = "11"
jvmTarget = "17"
// see https://kotlinlang.org/docs/java-to-kotlin-interop.html#compatibility-mode-for-default-methods
freeCompilerArgs += "-Xjvm-default=enable"
freeCompilerArgs += "-Xjvm-default=all"
}
}

compileTestKotlin {
kotlinOptions {
languageVersion = "1.6"
jvmTarget = "11"
freeCompilerArgs += "-Xjvm-default=enable"
jvmTarget = "17"
freeCompilerArgs += "-Xjvm-default=all"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import strikt.assertions.isNull
import strikt.assertions.isTrue
import java.time.Clock
import java.time.Instant
import java.time.temporal.ChronoUnit

abstract class ArtifactRepositoryTests<T : ArtifactRepository> : JUnit5Minutests {
val publisher: ApplicationEventPublisher = mockk(relaxed = true)
Expand Down Expand Up @@ -649,8 +650,7 @@ abstract class ArtifactRepositoryTests<T : ArtifactRepository> : JUnit5Minutests
}

context("artifact creation timestamp exists") {
val createdAt = Instant.now()

val createdAt = Instant.now().truncatedTo(ChronoUnit.MICROS)
before {
subject.register(versionedSnapshotDebian)
subject.storeArtifactVersion(versionedSnapshotDebian.toArtifactVersion(version1, SNAPSHOT, createdAt = createdAt))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo
import java.time.Clock
import java.time.Instant
import com.netflix.spinnaker.keel.events.EventLevel.WARNING
import java.time.temporal.ChronoUnit

@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
Expand Down Expand Up @@ -41,7 +42,7 @@ data class ApplicationActuationPaused(

constructor(application: String, triggeredBy: String, comment: String? = null, clock: Clock = Companion.clock) : this(
application,
clock.instant(),
clock.instant().truncatedTo(ChronoUnit.MICROS),
triggeredBy,
comment
)
Expand All @@ -61,6 +62,6 @@ data class ApplicationActuationResumed(
constructor(application: String, triggeredBy: String, clock: Clock = Companion.clock) : this(
application,
triggeredBy,
clock.instant()
clock.instant().truncatedTo(ChronoUnit.MICROS)
)
}
Loading

0 comments on commit 45770a3

Please sign in to comment.