Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch Collection creation issues #1130

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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