Skip to content

Commit

Permalink
Merge pull request #1130 from johnoliver/remove-kmongo
Browse files Browse the repository at this point in the history
Catch Collection creation issues
  • Loading branch information
johnoliver authored Aug 21, 2024
2 parents 95d334f + 2141c96 commit 8137102
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,30 @@ import com.mongodb.MongoCommandException
import com.mongodb.kotlin.client.coroutine.MongoCollection
import com.mongodb.kotlin.client.coroutine.MongoDatabase
import kotlinx.coroutines.runBlocking
import net.adoptium.api.v3.config.APIConfig
import net.adoptium.api.v3.config.DeploymentType
import org.slf4j.LoggerFactory

abstract class MongoInterface {

companion object {
@JvmStatic
val LOGGER = LoggerFactory.getLogger(MongoInterface::class.java)!!
}

inline fun <reified T : Any> createCollection(database: MongoDatabase, collectionName: String): MongoCollection<T> {

runBlocking {
try {
database.createCollection(collectionName)
} catch (e: MongoCommandException) {
if (e.errorCode == 48) {
// collection already exists ... ignore
} else {
throw e
if (APIConfig.DEPLOYMENT_TYPE == DeploymentType.UPDATER) {
LOGGER.warn("User does not have permission to create collection $collectionName", e)
throw e
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import io.quarkus.runtime.Quarkus

import io.quarkus.runtime.annotations.QuarkusMain
import net.adoptium.api.v3.ai.AppInsightsTelemetry
import net.adoptium.api.v3.config.APIConfig
import net.adoptium.api.v3.config.DeploymentType


@QuarkusMain
Expand All @@ -12,6 +14,8 @@ object Main {
fun main(args: Array<String>) {
// force eager startup of AppInsights, must be done from the main thread
AppInsightsTelemetry.enabled
APIConfig.DEPLOYMENT_TYPE = DeploymentType.FRONTEND

Quarkus.run(*args)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import io.quarkus.runtime.Startup
import jakarta.annotation.PostConstruct
import jakarta.enterprise.context.ApplicationScoped
import jakarta.inject.Inject
import net.adoptium.api.v3.config.APIConfig
import net.adoptium.api.v3.config.DeploymentType
import net.adoptium.api.v3.dataSources.APIDataStore

@ApplicationScoped
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ class APIConfig {

// We will only update pre-releases if they are less than n days old
var UPDATE_DAY_CUTOFF: Int = System.getenv("UPDATE_DAY_CUTOFF")?.toInt() ?: 90

var DEPLOYMENT_TYPE: DeploymentType = DeploymentType.valueOf((System.getenv("DEPLOYMENT_TYPE") ?: "FRONTEND").uppercase())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package net.adoptium.api.v3.config

enum class DeploymentType {
FRONTEND, UPDATER
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.adoptium.api.v3

import net.adoptium.api.v3.config.APIConfig
import net.adoptium.api.v3.config.DeploymentType
import org.jboss.weld.environment.se.Weld

class Main {
Expand All @@ -8,6 +10,7 @@ class Main {
fun main(args: Array<String>) {
// Force eager App insights loading
// AppInsightsTelemetry.enabled
APIConfig.DEPLOYMENT_TYPE = DeploymentType.UPDATER

val container = Weld().containerId("STATIC_INSTANCE").initialize()
val v3Updater = container.select(V3Updater::class.java).get()
Expand Down
2 changes: 2 additions & 0 deletions deploy/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ then
export MONGODB_SSL="true"
fi

export DEPLOYMENT_TYPE="${deploymentType}"

java $JAVA_OPTS -jar ${deploymentType}.jar

0 comments on commit 8137102

Please sign in to comment.