Skip to content

Commit

Permalink
Upgraded to jdk 19. Updated Openstack client, faster-jackson and kotl…
Browse files Browse the repository at this point in the history
…in version.
  • Loading branch information
nikko-andersen committed Aug 14, 2024
1 parent e703d80 commit b4eb35f
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-push-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
tags: |
ghcr.io/aau-claaudia/openstackgateway:${{ env.GITHUB_SHA_SHORT }}
- name: Build documentation
uses: actions/setup-python@v3
uses: actions/setup-python@v4.1.0
with:
python-version: 3.x
- run: pip install mkdocs-material
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM gradle:jdk17 as build
FROM gradle:jdk19 as build

WORKDIR "/home/gradle/"

Expand All @@ -12,6 +12,6 @@ RUN /home/gradle/gradlew dependencies && \
# /home/gradle/gradlew dokkaGfm # FIXME this outputs somewhere mkdocs cannot find it?


FROM openjdk:17-jdk-alpine
FROM openjdk:19-jdk-alpine
COPY --from=build /home/gradle/build/libs/gradle-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
46 changes: 26 additions & 20 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

val openstack4jVersion = "3.11"
val jacksonVersion = "2.15.2"
val kotlinVersion = "1.9.0"
val openstack4jVersion = "3.12"
val jacksonVersion = "2.17.2"
val kotlinVersion = "1.9.24"
// TODO: we can't update to springboot 3 while we use the old sdu provider library, since that breaks dependencies
//val springBootVersion = "3.3.2"
val springBootVersion = "2.7.18"
val ktorClientVersion = "1.6.8"

plugins {
id("org.springframework.boot") version "2.7.14"
//id("org.springframework.boot") version "3.3.2"
id("org.springframework.boot") version "2.7.18"
id("io.spring.dependency-management") version "1.1.2"
kotlin("jvm") version "1.9.0"
kotlin("plugin.spring") version "1.9.0"
kotlin("plugin.jpa") version "1.9.0"
kotlin("kapt") version "1.9.0"
kotlin("jvm") version "1.9.24"
kotlin("plugin.spring") version "1.9.24"
kotlin("plugin.jpa") version "1.9.24"
kotlin("kapt") version "1.9.24"
id("org.jetbrains.dokka") version "1.8.20"
}

group = "dk.aau.claaudia"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17
java.sourceCompatibility = JavaVersion.VERSION_19

repositories {
mavenLocal()
Expand All @@ -28,24 +33,25 @@ repositories {
}

dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-webflux:2.7.14")
implementation("org.springframework.cloud:spring-cloud-starter-config:3.1.8")
implementation("org.springframework.cloud:spring-cloud-starter-bootstrap:3.1.7")
implementation("com.auth0:java-jwt:3.19.1")
implementation("org.springframework.boot:spring-boot-starter-web:$springBootVersion")
implementation("org.springframework.boot:spring-boot-starter-webflux:$springBootVersion")
implementation("org.springframework.cloud:spring-cloud-starter-config:3.1.8") // TODO: update when updating spring boot version to 3.x
implementation("org.springframework.cloud:spring-cloud-starter-bootstrap:3.1.7") // TODO: update when updating spring boot version to 3.x
implementation("com.auth0:java-jwt:4.4.0")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonVersion")
implementation("org.springdoc:springdoc-openapi-ui:1.6.7")
implementation("org.springdoc:springdoc-openapi-ui:1.8.0")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("com.github.openstack4j.core:openstack4j-core:$openstack4jVersion")
implementation("com.github.openstack4j.core.connectors:openstack4j-httpclient:$openstack4jVersion")

// SDU UCloud Provider Module
implementation("dk.sdu.cloud:jvm-provider-support:2022.1.51-devel-hippo")
implementation("io.ktor:ktor-client-core:1.6.8")
implementation("io.ktor:ktor-client-cio:1.6.8")
implementation("io.ktor:ktor-client-websockets:1.6.8")
implementation("io.ktor:ktor-client-okhttp:1.6.8")
// TODO: we need to upgrade the sdu library before we can update the ktor libraries because of dependencies
implementation("io.ktor:ktor-client-core:$ktorClientVersion")
implementation("io.ktor:ktor-client-cio:$ktorClientVersion")
implementation("io.ktor:ktor-client-websockets:$ktorClientVersion")
implementation("io.ktor:ktor-client-okhttp:$ktorClientVersion")

implementation("com.squareup.okhttp3:okhttp:4.9.3")
implementation("org.springframework.boot:spring-boot-starter-websocket")
Expand Down Expand Up @@ -73,7 +79,7 @@ tasks.withType<Test> {
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs += "-Xjsr305=strict"
jvmTarget = "17"
jvmTarget = "19"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
import com.fasterxml.jackson.module.kotlin.KotlinFeature
import com.fasterxml.jackson.module.kotlin.KotlinModule
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder

Expand All @@ -23,7 +24,9 @@ class ObjectmapperConfig {
@Bean(name = ["YAMLMapper"])
fun yamlObjectMapper(): ObjectMapper {
val mapper = ObjectMapper(YAMLFactory())
mapper.registerModule(KotlinModule())
mapper.registerModule(
KotlinModule.Builder().build()
)
mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true)
mapper.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dk.aau.claaudia.openstackgateway.config

import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.boot.task.TaskSchedulerBuilder
//import org.springframework.boot.task.ThreadPoolTaskSchedulerBuilder //TODO: use this from spring boot 3
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.scheduling.annotation.EnableScheduling
Expand All @@ -15,6 +16,7 @@ class SchedulingConfig {
// This is required because the default task scheduler conflicts with the one needed for websocket support
@Qualifier("taskscheduler")
@Bean
//fun taskScheduler(builder: ThreadPoolTaskSchedulerBuilder): ThreadPoolTaskScheduler? { TODO: use this from spring boot 3
fun taskScheduler(builder: TaskSchedulerBuilder): ThreadPoolTaskScheduler? {
return builder.build()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package dk.aau.claaudia.openstackgateway.interceptors

import dk.aau.claaudia.openstackgateway.extensions.getLogger
import org.springframework.stereotype.Component
import org.springframework.web.servlet.HandlerInterceptor
import org.springframework.web.util.ContentCachingRequestWrapper
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse
import org.springframework.web.servlet.HandlerInterceptor

@Component
class UcloudRequestInterceptor : HandlerInterceptor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class OpenStackService(

fun listFlavors(): List<Flavor?> {
val list = getClient().compute().flavors().list(true)
logger.info("Getting flavors from openstack:", list.size)
logger.info("Getting flavors from openstack: ${list.size}")
return list
}

Expand Down Expand Up @@ -477,14 +477,14 @@ class OpenStackService(
val startTime = System.currentTimeMillis()
while (startTime + config.monitor.timeout > System.currentTimeMillis()) {
val stack = getStackByJob(job)
logger.info("Monitoring stack status", stack, stack?.status)
logger.info("Monitoring stack status $stack ${stack?.status}")
if (stack != null && stack.status == StackStatus.CREATE_COMPLETE.name) {
logger.info("Stack CREATE complete")
val outputIP = stack.outputs?.find { it["output_key"] == "server_ip" }
if (!outputIP.isNullOrEmpty()) {
sendJobRunningMessage(job.id, outputIP["output_value"] as String)
} else {
logger.error("Did not receive IP output from openstack", job, stack)
logger.error("Did not receive IP output from openstack $job $stack")
sendJobFailedMessage(job.id, "Did not receive IP output from openstack")
}

Expand Down Expand Up @@ -898,9 +898,9 @@ class OpenStackService(
val update = client.heat().stacks().update(stack.name, stack.id, stackUpdate)

if (update.isSuccess) {
logger.info("Stack lastcharged timestamp updated", stack)
logger.info("Stack lastcharged timestamp updated: $stack}")
} else {
logger.error("Stack lastcharged timestamp could no be updated", stack)
logger.error("Stack lastcharged timestamp could no be updated: $stack}")
}

return update.isSuccess
Expand Down Expand Up @@ -933,19 +933,19 @@ class OpenStackService(
while (startTime + config.monitor.timeout > System.currentTimeMillis()) {
val instance = getInstanceFromId(server.id)
if (instance != null && instance.status == Server.Status.SHUTOFF) {
logger.info("Found instance with status SHUTOFF: ", instance.id)
logger.info("Found instance with status SHUTOFF: ${instance.id}")
sendInstanceShutdownMessage(job.id, estimateProductPriceForPeriod(job, period))
return
} else if (instance == null) {
logger.info("Instance stopping could not find instance: ", server.id)
logger.info("Instance stopping could not find instance: ${server.id}")
} else {
logger.info("Instance stopping could not be verified. Status: ", server.status)
logger.info("Instance stopping could not be verified. Status: ${server.status}")
}
// Sleep until next retry
logger.info("Waiting to retry")
Thread.sleep(config.monitor.delay)
}
logger.error("Instance could no be stopped. Serverid: ", server.id)
logger.error("Instance could no be stopped. Serverid: ${server.id}")
}

fun sendInstanceStartAction(server: Server) {
Expand All @@ -970,19 +970,19 @@ class OpenStackService(
while (startTime + config.monitor.timeout > System.currentTimeMillis()) {
val instance = getInstanceFromId(server.id)
if (instance != null && instance.status == Server.Status.ACTIVE) {
logger.info("Found instance with status ACTIVE: ", instance.id)
logger.info("Found instance with status ACTIVE: ${instance.id}")
sendInstanceRestartedMessage(job.id)
return
} else if (instance == null) {
logger.info("Instance starting could not find instance: ", server.id)
logger.info("Instance starting could not find instance: ${server.id}")
} else {
logger.info("Instance starting could not be verified. Status: ", server.status)
logger.info("Instance starting could not be verified. Status: ${server.status}")
}
// Sleep until next retry
logger.info("Waiting to retry")
Thread.sleep(config.monitor.delay)
}
logger.error("Instance could no be started within timeout. Serverid: ", server.id)
logger.error("Instance could no be started within timeout. Serverid: ${server.id}")
}

fun getStackEvents(stackName: String, stackIdentity: String): MutableList<out Event>? {
Expand All @@ -1004,7 +1004,7 @@ class OpenStackService(
threadPool.execute {
val stack = getStackByJob(job)
if (stack != null) {
logger.error("AsyncChargeDeleteJob could not delete. Job: ${job.id} Stack: ${job.openstackName}")
logger.info("AsyncChargeDeleteJob attempting to charge and delete job: ${job.id} Stack: ${job.openstackName}")
chargeStack(stack)
deleteJob(job)
}
Expand Down Expand Up @@ -1063,19 +1063,19 @@ class OpenStackService(
while (startTime + config.monitor.timeout > System.currentTimeMillis()) {
val stack = findStackIncludeDeleted(job)
if (stack != null && stack.status == StackStatus.DELETE_COMPLETE.name) {
logger.info("Found stack with status delete complete: ", job.openstackName)
logger.info("Found stack with status delete complete: ${job.openstackName}")
sendJobStatusMessage(job.id, JobState.SUCCESS, "Stack DELETE complete")
return
} else if (stack == null) {
logger.info("Stack deletion could not find stack: ", job.openstackName)
logger.info("Stack deletion could not find stack: ${job.openstackName}")
} else {
logger.info("Stack deletion could not be verified. Status: ", stack.status)
logger.info("Stack deletion could not be verified. Status: ${stack.status}")
}
// Sleep until next retry
logger.info("Waiting to retry")
Thread.sleep(config.monitor.delay)
}
logger.error("Job could no be deleted", job)
logger.error("Job could not be deleted: $job")
}

fun asyncMonitorStackSuspensions(jobs: List<Job>) {
Expand Down Expand Up @@ -1172,8 +1172,12 @@ class OpenStackService(

when {
expectedUcloudJobState == null -> {
// Unknown stack status.
logger.error("Unhandled status: ${stack.status}. JobID: ${job.id}. Stack: ${stack.id}")
if (StackStatus.valueOf(stack.status) == StackStatus.DELETE_IN_PROGRESS) {
logger.info("Delete in progress, waiting to verify status: ${stack.status}. JobID: ${job.id}. Stack: ${stack.id}")
} else {
// Unknown stack status.
logger.error("Unhandled status: ${stack.status}. JobID: ${job.id}. Stack: ${stack.id}")
}
}

job.status.state != expectedUcloudJobState -> {
Expand Down

0 comments on commit b4eb35f

Please sign in to comment.