diff --git a/adoptium-api-v3-persistence/src/main/kotlin/net/adoptium/api/v3/dataSources/persitence/mongo/MongoInterface.kt b/adoptium-api-v3-persistence/src/main/kotlin/net/adoptium/api/v3/dataSources/persitence/mongo/MongoInterface.kt index 9086ceaa2..5b4e7d6f8 100644 --- a/adoptium-api-v3-persistence/src/main/kotlin/net/adoptium/api/v3/dataSources/persitence/mongo/MongoInterface.kt +++ b/adoptium-api-v3-persistence/src/main/kotlin/net/adoptium/api/v3/dataSources/persitence/mongo/MongoInterface.kt @@ -4,10 +4,19 @@ 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 createCollection(database: MongoDatabase, collectionName: String): MongoCollection { + runBlocking { try { database.createCollection(collectionName) @@ -15,7 +24,10 @@ abstract class MongoInterface { 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 + } } } } diff --git a/adoptium-frontend-parent/adoptium-api-v3-frontend/src/main/kotlin/net/adoptium/api/v3/Main.kt b/adoptium-frontend-parent/adoptium-api-v3-frontend/src/main/kotlin/net/adoptium/api/v3/Main.kt index 58b711181..d8d30d4ea 100644 --- a/adoptium-frontend-parent/adoptium-api-v3-frontend/src/main/kotlin/net/adoptium/api/v3/Main.kt +++ b/adoptium-frontend-parent/adoptium-api-v3-frontend/src/main/kotlin/net/adoptium/api/v3/Main.kt @@ -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 @@ -12,6 +14,8 @@ object Main { fun main(args: Array) { // force eager startup of AppInsights, must be done from the main thread AppInsightsTelemetry.enabled + APIConfig.DEPLOYMENT_TYPE = DeploymentType.FRONTEND + Quarkus.run(*args) } } diff --git a/adoptium-frontend-parent/adoptium-api-v3-frontend/src/main/kotlin/net/adoptium/api/v3/Startup.kt b/adoptium-frontend-parent/adoptium-api-v3-frontend/src/main/kotlin/net/adoptium/api/v3/Startup.kt index b44c35691..d51386863 100644 --- a/adoptium-frontend-parent/adoptium-api-v3-frontend/src/main/kotlin/net/adoptium/api/v3/Startup.kt +++ b/adoptium-frontend-parent/adoptium-api-v3-frontend/src/main/kotlin/net/adoptium/api/v3/Startup.kt @@ -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 diff --git a/adoptium-models-parent/adoptium-api-v3-models/src/main/kotlin/net/adoptium/api/v3/config/APIConfig.kt b/adoptium-models-parent/adoptium-api-v3-models/src/main/kotlin/net/adoptium/api/v3/config/APIConfig.kt index e522e05fb..dc7baf616 100644 --- a/adoptium-models-parent/adoptium-api-v3-models/src/main/kotlin/net/adoptium/api/v3/config/APIConfig.kt +++ b/adoptium-models-parent/adoptium-api-v3-models/src/main/kotlin/net/adoptium/api/v3/config/APIConfig.kt @@ -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()) } } diff --git a/adoptium-models-parent/adoptium-api-v3-models/src/main/kotlin/net/adoptium/api/v3/config/DeploymentType.kt b/adoptium-models-parent/adoptium-api-v3-models/src/main/kotlin/net/adoptium/api/v3/config/DeploymentType.kt new file mode 100644 index 000000000..0acebdf6b --- /dev/null +++ b/adoptium-models-parent/adoptium-api-v3-models/src/main/kotlin/net/adoptium/api/v3/config/DeploymentType.kt @@ -0,0 +1,5 @@ +package net.adoptium.api.v3.config + +enum class DeploymentType { + FRONTEND, UPDATER +} diff --git a/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/Main.kt b/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/Main.kt index 0c08e89ad..e3e917337 100644 --- a/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/Main.kt +++ b/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/Main.kt @@ -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 { @@ -8,6 +10,7 @@ class Main { fun main(args: Array) { // 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() diff --git a/deploy/run.sh b/deploy/run.sh index cc5e87f0b..14dd7f9b8 100644 --- a/deploy/run.sh +++ b/deploy/run.sh @@ -35,4 +35,6 @@ then export MONGODB_SSL="true" fi +export DEPLOYMENT_TYPE="${deploymentType}" + java $JAVA_OPTS -jar ${deploymentType}.jar