This repository has been archived by the owner on Oct 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release installer paths from staging (#198)
* Release installer paths * Possible solution to #209 on staging (#211) * Fix #209 * Added some reasoning Co-authored-by: Martijn Verburg <martijnverburg@gmail.com> Co-authored-by: Martijn Verburg <martijnverburg@gmail.com>
- Loading branch information
1 parent
ad86961
commit b4d664b
Showing
9 changed files
with
499 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
...-v3-frontend/src/main/kotlin/net/adoptopenjdk/api/v3/routes/packages/InstallerResource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
package net.adoptopenjdk.api.v3.routes.packages | ||
|
||
import net.adoptopenjdk.api.v3.OpenApiDocs | ||
import net.adoptopenjdk.api.v3.models.Architecture | ||
import net.adoptopenjdk.api.v3.models.Binary | ||
import net.adoptopenjdk.api.v3.models.HeapSize | ||
import net.adoptopenjdk.api.v3.models.ImageType | ||
import net.adoptopenjdk.api.v3.models.Installer | ||
import net.adoptopenjdk.api.v3.models.JvmImpl | ||
import net.adoptopenjdk.api.v3.models.OperatingSystem | ||
import net.adoptopenjdk.api.v3.models.Project | ||
import net.adoptopenjdk.api.v3.models.Release | ||
import net.adoptopenjdk.api.v3.models.ReleaseType | ||
import net.adoptopenjdk.api.v3.models.Vendor | ||
import org.eclipse.microprofile.openapi.annotations.Operation | ||
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType | ||
import org.eclipse.microprofile.openapi.annotations.media.Schema | ||
import org.eclipse.microprofile.openapi.annotations.parameters.Parameter | ||
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse | ||
import org.eclipse.microprofile.openapi.annotations.responses.APIResponses | ||
import org.eclipse.microprofile.openapi.annotations.tags.Tag | ||
import org.jboss.resteasy.annotations.jaxrs.PathParam | ||
import org.jboss.resteasy.annotations.jaxrs.QueryParam | ||
import javax.ws.rs.GET | ||
import javax.ws.rs.Path | ||
import javax.ws.rs.Produces | ||
import javax.ws.rs.core.MediaType | ||
import javax.ws.rs.core.Response | ||
|
||
@Tag(name = "Installer") | ||
@Path("/v3/installer/") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
class InstallerResource : PackageEndpoint() { | ||
|
||
@GET | ||
@Path("/version/{release_name}/{os}/{arch}/{image_type}/{jvm_impl}/{heap_size}/{vendor}") | ||
@Produces("application/octet-stream") | ||
@Operation(summary = "Redirects to the installer that matches your current query", description = "Redirects to the installer that matches your current query") | ||
@APIResponses(value = [ | ||
APIResponse(responseCode = "307", description = "link to installer that matches your current query"), | ||
APIResponse(responseCode = "400", description = "bad input parameter"), | ||
APIResponse(responseCode = "404", description = "No matching installer found") | ||
] | ||
) | ||
fun returnInstallerByVersion( | ||
@Parameter(name = "os", description = "Operating System", required = true) | ||
@PathParam("os") | ||
os: OperatingSystem?, | ||
|
||
@Parameter(name = "arch", description = "Architecture", required = true) | ||
@PathParam("arch") | ||
arch: Architecture?, | ||
|
||
@Parameter(name = "release_name", description = OpenApiDocs.RELASE_NAME, required = true, | ||
schema = Schema(defaultValue = "jdk-11.0.6+10", type = SchemaType.STRING) | ||
) | ||
@PathParam("release_name") | ||
release_name: String?, | ||
|
||
@Parameter(name = "image_type", description = "Image Type", required = true) | ||
@PathParam("image_type") | ||
image_type: ImageType?, | ||
|
||
@Parameter(name = "jvm_impl", description = "JVM Implementation", required = true) | ||
@PathParam("jvm_impl") | ||
jvm_impl: JvmImpl?, | ||
|
||
@Parameter(name = "heap_size", description = "Heap Size", required = true) | ||
@PathParam("heap_size") | ||
heap_size: HeapSize?, | ||
|
||
@Parameter(name = "vendor", description = OpenApiDocs.VENDOR, required = true) | ||
@PathParam("vendor") | ||
vendor: Vendor?, | ||
|
||
@Parameter(name = "project", description = "Project", schema = Schema(defaultValue = "jdk", enumeration = ["jdk", "valhalla", "metropolis", "jfr"], required = false), required = false) | ||
@QueryParam("project") | ||
project: Project? | ||
): Response { | ||
val releases = getReleases(release_name, vendor, os, arch, image_type, jvm_impl, heap_size, project) | ||
return formResponseInstaller(releases) | ||
} | ||
|
||
@GET | ||
@Path("/latest/{feature_version}/{release_type}/{os}/{arch}/{image_type}/{jvm_impl}/{heap_size}/{vendor}") | ||
@Produces("application/octet-stream") | ||
@Operation(summary = "Redirects to the installer that matches your current query", description = "Redirects to the installer that matches your current query") | ||
@APIResponses(value = [ | ||
APIResponse(responseCode = "307", description = "link to installer that matches your current query"), | ||
APIResponse(responseCode = "400", description = "bad input parameter"), | ||
APIResponse(responseCode = "404", description = "No matching installer found") | ||
] | ||
) | ||
fun returnInstaller( | ||
@Parameter(name = "feature_version", description = OpenApiDocs.FEATURE_RELEASE, required = true, | ||
schema = Schema(defaultValue = "8", type = SchemaType.INTEGER) | ||
) | ||
@PathParam("feature_version") | ||
version: Int?, | ||
|
||
@Parameter(name = "release_type", description = OpenApiDocs.RELEASE_TYPE, required = true) | ||
@PathParam("release_type") | ||
release_type: ReleaseType?, | ||
|
||
@Parameter(name = "os", description = "Operating System", required = true) | ||
@PathParam("os") | ||
os: OperatingSystem?, | ||
|
||
@Parameter(name = "arch", description = "Architecture", required = true) | ||
@PathParam("arch") | ||
arch: Architecture?, | ||
|
||
@Parameter(name = "image_type", description = "Image Type", required = true) | ||
@PathParam("image_type") | ||
image_type: ImageType?, | ||
|
||
@Parameter(name = "jvm_impl", description = "JVM Implementation", required = true) | ||
@PathParam("jvm_impl") | ||
jvm_impl: JvmImpl?, | ||
|
||
@Parameter(name = "heap_size", description = "Heap Size", required = true) | ||
@PathParam("heap_size") | ||
heap_size: HeapSize?, | ||
|
||
@Parameter(name = "vendor", description = OpenApiDocs.VENDOR, required = true) | ||
@PathParam("vendor") | ||
vendor: Vendor?, | ||
|
||
@Parameter(name = "project", description = "Project", schema = Schema(defaultValue = "jdk", enumeration = ["jdk", "valhalla", "metropolis", "jfr"], required = false), required = false) | ||
@QueryParam("project") | ||
project: Project? | ||
): Response { | ||
val releaseList = getRelease(release_type, version, vendor, os, arch, image_type, jvm_impl, heap_size, project) | ||
|
||
val release = releaseList | ||
.lastOrNull { release -> | ||
release.binaries.any { it.installer != null } | ||
} | ||
|
||
return formResponseInstaller(if (release == null) emptyList() else listOf(release)) | ||
} | ||
|
||
private fun formResponseInstaller(releases: List<Release>): Response { | ||
return formResponse(releases, extractInstaller(), redirectToAsset()) | ||
} | ||
|
||
private fun extractInstaller(): (Binary) -> Installer? { | ||
return { binary -> binary.installer } | ||
} | ||
} |
Oops, something went wrong.