Skip to content
This repository was archived by the owner on Oct 14, 2021. It is now read-only.

Commit 2fda9d1

Browse files
authored
Merge pull request #525 from johnoliver/merge-adoptium-3
Bring in upstream changes
2 parents bd4bf7e + ff4f8b8 commit 2fda9d1

File tree

8 files changed

+128
-54
lines changed

8 files changed

+128
-54
lines changed

adoptopenjdk-frontend-parent/adoptopenjdk-api-v3-frontend/src/main/kotlin/net/adoptopenjdk/api/v3/routes/SwaggerUiRoute.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import org.eclipse.microprofile.openapi.annotations.media.Schema
55
import java.net.URI
66
import javax.ws.rs.GET
77
import javax.ws.rs.Path
8+
import javax.ws.rs.PathParam
89
import javax.ws.rs.Produces
910
import javax.ws.rs.core.MediaType
1011
import javax.ws.rs.core.Response
@@ -13,14 +14,14 @@ import javax.ws.rs.core.Response
1314
@Schema(hidden = true)
1415
@Produces(MediaType.TEXT_PLAIN)
1516
class SwaggerUiRoute {
16-
1717
@GET
1818
@Schema(hidden = true)
19-
@Path("/swagger-ui")
19+
@Path("/{path:openapi|swagger-ui}")
2020
@Operation(hidden = true)
21-
fun redirect(): Response = Response
22-
.status(Response.Status.FOUND)
23-
.location(URI("/q/swagger-ui"))
24-
.build()
25-
21+
fun redirectOpenAPIPaths(@PathParam("path") path: String): Response {
22+
return Response
23+
.status(Response.Status.FOUND)
24+
.location(URI("/q/${path}"))
25+
.build()
26+
}
2627
}
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
package net.adoptopenjdk.api.v3.stats
22

33
import net.adoptopenjdk.api.v3.dataSources.models.AdoptRepos
4+
import net.adoptopenjdk.api.v3.stats.dockerstats.DockerStatsInterfaceFactory
45
import javax.inject.Inject
56

67
class StatsInterface @Inject constructor(
78
private val gitHubDownloadStatsCalculator: GitHubDownloadStatsCalculator,
8-
private val dockerStatsInterface: DockerStatsInterface
9+
dockerStatsInterfaceFactory: DockerStatsInterfaceFactory
910
) {
11+
private val dockerStats = dockerStatsInterfaceFactory.get()
1012
suspend fun update(repos: AdoptRepos) {
1113
gitHubDownloadStatsCalculator.saveStats(repos)
12-
dockerStatsInterface.updateDb()
14+
dockerStats.updateDb()
1315
}
1416
}
Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,47 @@
1-
package net.adoptopenjdk.api.v3.stats
1+
package net.adoptopenjdk.api.v3.stats.dockerstats
22

33
import kotlinx.coroutines.runBlocking
4-
import net.adoptopenjdk.api.v3.TimeSource
4+
import net.adoptopenjdk.api.v3.config.Ecosystem
55
import net.adoptopenjdk.api.v3.dataSources.UpdaterHtmlClient
6-
76
import net.adoptopenjdk.api.v3.dataSources.UpdaterJsonMapper
87
import net.adoptopenjdk.api.v3.dataSources.persitence.ApiPersistence
98
import net.adoptopenjdk.api.v3.models.DockerDownloadStatsDbEntry
10-
import net.adoptopenjdk.api.v3.models.JvmImpl
119
import org.slf4j.LoggerFactory
10+
import javax.enterprise.inject.Produces
1211
import javax.inject.Inject
12+
import javax.inject.Singleton
1313
import javax.json.JsonObject
1414

15-
class DockerStatsInterface @Inject constructor(
15+
@Singleton
16+
class DockerStatsInterfaceFactory @Inject constructor(
1617
private var database: ApiPersistence,
1718
private val updaterHtmlClient: UpdaterHtmlClient
1819
) {
20+
var cached: DockerStatsInterface? = null
21+
22+
@Produces
23+
@Singleton
24+
fun get(): DockerStatsInterface {
25+
if (cached == null) {
26+
cached = when (Ecosystem.CURRENT) {
27+
Ecosystem.adoptopenjdk -> DockerStatsInterfaceAdoptOpenJdk(database, updaterHtmlClient)
28+
Ecosystem.adoptium -> DockerStatsInterfaceAdoptium(database, updaterHtmlClient)
29+
}
30+
}
31+
32+
return cached!!
33+
}
34+
}
35+
36+
@Singleton
37+
interface DockerStatsInterface {
38+
suspend fun updateDb()
39+
}
40+
41+
abstract class DockerStats @Inject constructor(
42+
private var database: ApiPersistence,
43+
private val updaterHtmlClient: UpdaterHtmlClient
44+
) : DockerStatsInterface {
1945
companion object {
2046
@JvmStatic
2147
private val LOGGER = LoggerFactory.getLogger(this::class.java)
@@ -25,10 +51,10 @@ class DockerStatsInterface @Inject constructor(
2551
}
2652
}
2753

28-
private val downloadStatsUrl = "https://hub.docker.com/v2/repositories/adoptopenjdk/"
29-
private val officialStatsUrl = "https://hub.docker.com/v2/repositories/library/adoptopenjdk/"
54+
abstract fun getDownloadStats(): List<DockerDownloadStatsDbEntry>
55+
abstract fun pullOfficalStats(): DockerDownloadStatsDbEntry
3056

31-
suspend fun updateDb() {
57+
override suspend fun updateDb() {
3258
try {
3359
val stats = mutableListOf<DockerDownloadStatsDbEntry>()
3460

@@ -42,29 +68,7 @@ class DockerStatsInterface @Inject constructor(
4268
}
4369
}
4470

45-
private fun getDownloadStats(): List<DockerDownloadStatsDbEntry> {
46-
val now = TimeSource.now()
47-
48-
return pullAllStats()
49-
.map {
50-
DockerDownloadStatsDbEntry(
51-
now,
52-
it.getJsonNumber("pull_count").longValue(),
53-
it.getString("name"),
54-
getOpenjdkVersionFromString(it.getString("name")),
55-
if (it.getString("name").contains("openj9")) JvmImpl.openj9 else JvmImpl.hotspot // Will need to be updated with a new JVMImpl
56-
)
57-
}
58-
}
59-
60-
private fun pullOfficalStats(): DockerDownloadStatsDbEntry {
61-
val result = getStatsForUrl(officialStatsUrl)
62-
val now = TimeSource.now()
63-
64-
return DockerDownloadStatsDbEntry(now, result.getJsonNumber("pull_count").longValue(), "official", null, null)
65-
}
66-
67-
private fun pullAllStats(): ArrayList<JsonObject> {
71+
protected fun pullAllStats(downloadStatsUrl: String): ArrayList<JsonObject> {
6872
var next: String? = downloadStatsUrl
6973

7074
val results = ArrayList<JsonObject>()
@@ -76,7 +80,7 @@ class DockerStatsInterface @Inject constructor(
7680
return results
7781
}
7882

79-
private fun getStatsForUrl(url: String): JsonObject {
83+
protected fun getStatsForUrl(url: String): JsonObject {
8084
return runBlocking {
8185
val stats = updaterHtmlClient.get(url)
8286
if (stats == null) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package net.adoptopenjdk.api.v3.stats.dockerstats
2+
3+
import net.adoptopenjdk.api.v3.TimeSource
4+
import net.adoptopenjdk.api.v3.dataSources.UpdaterHtmlClient
5+
import net.adoptopenjdk.api.v3.dataSources.persitence.ApiPersistence
6+
import net.adoptopenjdk.api.v3.models.DockerDownloadStatsDbEntry
7+
import net.adoptopenjdk.api.v3.models.JvmImpl
8+
import javax.inject.Inject
9+
10+
class DockerStatsInterfaceAdoptOpenJdk @Inject constructor(
11+
database: ApiPersistence,
12+
updaterHtmlClient: UpdaterHtmlClient,
13+
) : DockerStats(database, updaterHtmlClient) {
14+
15+
private val downloadStatsUrl = "https://hub.docker.com/v2/repositories/adoptopenjdk/"
16+
private val officialStatsUrl = "https://hub.docker.com/v2/repositories/library/adoptopenjdk/"
17+
18+
override fun getDownloadStats(): List<DockerDownloadStatsDbEntry> {
19+
val now = TimeSource.now()
20+
21+
return pullAllStats(downloadStatsUrl)
22+
.map {
23+
DockerDownloadStatsDbEntry(
24+
now,
25+
it.getJsonNumber("pull_count").longValue(),
26+
it.getString("name"),
27+
getOpenjdkVersionFromString(it.getString("name")),
28+
if (it.getString("name").contains("openj9")) JvmImpl.openj9 else JvmImpl.hotspot // Will need to be updated with a new JVMImpl
29+
)
30+
}
31+
}
32+
33+
override fun pullOfficalStats(): DockerDownloadStatsDbEntry {
34+
val result = getStatsForUrl(officialStatsUrl)
35+
val now = TimeSource.now()
36+
37+
return DockerDownloadStatsDbEntry(now, result.getJsonNumber("pull_count").longValue(), "official", null, null)
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package net.adoptopenjdk.api.v3.stats.dockerstats
2+
3+
import net.adoptopenjdk.api.v3.TimeSource
4+
import net.adoptopenjdk.api.v3.dataSources.UpdaterHtmlClient
5+
import net.adoptopenjdk.api.v3.dataSources.persitence.ApiPersistence
6+
import net.adoptopenjdk.api.v3.models.DockerDownloadStatsDbEntry
7+
import javax.inject.Inject
8+
9+
class DockerStatsInterfaceAdoptium @Inject constructor(
10+
database: ApiPersistence,
11+
updaterHtmlClient: UpdaterHtmlClient
12+
) : DockerStats(database, updaterHtmlClient) {
13+
14+
private val officialStatsUrl = "https://hub.docker.com/v2/repositories/library/eclipse-temurin/"
15+
16+
override fun getDownloadStats(): List<DockerDownloadStatsDbEntry> {
17+
return emptyList()
18+
}
19+
20+
override fun pullOfficalStats(): DockerDownloadStatsDbEntry {
21+
val result = getStatsForUrl(officialStatsUrl)
22+
val now = TimeSource.now()
23+
24+
return DockerDownloadStatsDbEntry(now, result.getJsonNumber("pull_count").longValue(), "eclipse-temurin", null, null)
25+
}
26+
}

adoptopenjdk-updater-parent/adoptopenjdk-api-v3-updater/src/test/kotlin/net/adoptopenjdk/api/DockerStatsInterfaceTest.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import net.adoptopenjdk.api.v3.models.DockerDownloadStatsDbEntry
1313
import net.adoptopenjdk.api.v3.models.GitHubDownloadStatsDbEntry
1414
import net.adoptopenjdk.api.v3.models.JvmImpl
1515
import net.adoptopenjdk.api.v3.models.StatsSource
16-
import net.adoptopenjdk.api.v3.stats.DockerStatsInterface
16+
import net.adoptopenjdk.api.v3.stats.dockerstats.DockerStats
17+
import net.adoptopenjdk.api.v3.stats.dockerstats.DockerStatsInterface
18+
import net.adoptopenjdk.api.v3.stats.dockerstats.DockerStatsInterfaceFactory
1719
import org.jboss.weld.junit5.auto.AddPackages
1820
import org.junit.Assert
1921
import org.junit.jupiter.api.Test
@@ -26,7 +28,7 @@ class DockerStatsInterfaceTest : BaseTest() {
2628
fun dbEntryIsCreated(defaultUpdaterHtmlClient: DefaultUpdaterHtmlClient) {
2729
runBlocking {
2830
val apiPersistence = InMemoryApiPersistence(adoptRepos)
29-
val dockerStatsInterface = DockerStatsInterface(apiPersistence, defaultUpdaterHtmlClient)
31+
val dockerStatsInterface = DockerStatsInterfaceFactory(apiPersistence, defaultUpdaterHtmlClient).get()
3032

3133
dockerStatsInterface.updateDb()
3234

@@ -90,12 +92,12 @@ class DockerStatsInterfaceTest : BaseTest() {
9092
@Test
9193
fun testGetOpenjdkVersionFromString() {
9294
runBlocking {
93-
assertEquals(11, DockerStatsInterface.getOpenjdkVersionFromString("openjdk11"))
94-
assertEquals(8, DockerStatsInterface.getOpenjdkVersionFromString("openjdk8-openj9"))
95-
assertEquals(12, DockerStatsInterface.getOpenjdkVersionFromString("maven-openjdk12"))
96-
assertEquals(14, DockerStatsInterface.getOpenjdkVersionFromString("maven-openjdk14-openj9"))
95+
assertEquals(11, DockerStats.getOpenjdkVersionFromString("openjdk11"))
96+
assertEquals(8, DockerStats.getOpenjdkVersionFromString("openjdk8-openj9"))
97+
assertEquals(12, DockerStats.getOpenjdkVersionFromString("maven-openjdk12"))
98+
assertEquals(14, DockerStats.getOpenjdkVersionFromString("maven-openjdk14-openj9"))
9799

98-
assertEquals(null, DockerStatsInterface.getOpenjdkVersionFromString("official"))
100+
assertEquals(null, DockerStats.getOpenjdkVersionFromString("official"))
99101
}
100102
}
101103
}

adoptopenjdk-updater-parent/adoptopenjdk-api-v3-updater/src/test/kotlin/net/adoptopenjdk/api/StatsCalculatorTest.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import net.adoptopenjdk.api.v3.models.Release
2020
import net.adoptopenjdk.api.v3.models.ReleaseType
2121
import net.adoptopenjdk.api.v3.models.Vendor
2222
import net.adoptopenjdk.api.v3.models.VersionData
23-
import net.adoptopenjdk.api.v3.stats.DockerStatsInterface
2423
import net.adoptopenjdk.api.v3.stats.GitHubDownloadStatsCalculator
24+
import net.adoptopenjdk.api.v3.stats.dockerstats.DockerStats
2525
import org.junit.jupiter.api.Test
2626

2727
class StatsCalculatorTest : BaseTest() {
@@ -41,10 +41,10 @@ class StatsCalculatorTest : BaseTest() {
4141

4242
@Test
4343
fun testDockerVersionNumber() {
44-
assert(DockerStatsInterface.getOpenjdkVersionFromString("openjdk11") == 11)
45-
assert(DockerStatsInterface.getOpenjdkVersionFromString("openjdk7") == 7)
46-
assert(DockerStatsInterface.getOpenjdkVersionFromString("openjdk") == null)
47-
assert(DockerStatsInterface.getOpenjdkVersionFromString("blah") == null)
44+
assert(DockerStats.getOpenjdkVersionFromString("openjdk11") == 11)
45+
assert(DockerStats.getOpenjdkVersionFromString("openjdk7") == 7)
46+
assert(DockerStats.getOpenjdkVersionFromString("openjdk") == null)
47+
assert(DockerStats.getOpenjdkVersionFromString("blah") == null)
4848
}
4949

5050
private fun generateFeatureRelease(): FeatureRelease {

adoptopenjdk-updater-parent/adoptopenjdk-mappers-parent/adopt-mappers/src/main/kotlin/net/adoptopenjdk/api/v3/mapping/adopt/AdoptReleaseMapper.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private class AdoptReleaseMapper constructor(
120120

121121
return if (release.release_type == ReleaseType.ea) {
122122
// remove all 14.0.1+7.1 and 15.0.0+24.1 nightlies - https://github.com/AdoptOpenJDK/openjdk-api-v3/issues/213
123-
// also ignore jdk-2021-01-13-07-01 - https://github.com/AdoptOpenJDK/openjdk-api-v3/issues/449
123+
// also ignore jdk-2021-01-13-07-01
124124
if (release.version_data.semver.startsWith("14.0.1+7.1.") ||
125125
release.version_data.semver.startsWith("15.0.0+24.1.") ||
126126
release.release_name == "jdk-2021-01-13-07-01"

0 commit comments

Comments
 (0)