Fix updater to properly grab openj9 versions

This commit is contained in:
Nathan McCarty 2023-05-16 12:15:01 -04:00
parent 916328221d
commit 50809fa040
Signed by: thatonelutenist
SSH Key Fingerprint: SHA256:hwQEcmak9E6sdU9bXc98RHw/Xd1AhpB5HZT7ZSVJkRM
5 changed files with 490 additions and 255 deletions

644
updater/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -8,7 +8,10 @@ edition = "2021"
[dependencies] [dependencies]
async-std = { version = "1.12.0", features = ["attributes"] } async-std = { version = "1.12.0", features = ["attributes"] }
color-eyre = "0.5.11" color-eyre = "0.5.11"
custom_debug = "0.5.1"
isahc = "1.7.2" isahc = "1.7.2"
serde = { version = "1.0.132", features = ["derive"] } serde = { version = "1.0.132", features = ["derive"] }
serde_json = "1.0.73" serde_json = "1.0.73"
tracing = { version = "0.1.37", features = ["log"] }
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
urlencoding = "2.1.2" urlencoding = "2.1.2"

View File

@ -57,11 +57,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1684120848, "lastModified": 1684212024,
"narHash": "sha256-gIwJ5ac1FwZEkCRwjY+gLwgD4G1Bw3Xtr2jr2XihMPo=", "narHash": "sha256-/3ZvkPuIXdyZqPR53qC7aaV5wiwMOY+ddbESOykZ9Vo=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "0cb867999eec4085e1c9ca61c09b72261fa63bb4", "rev": "d4825e5e4ac1de7d5bb99381534fd0af3875a26d",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -71,11 +71,11 @@
}, },
"nixpkgs_2": { "nixpkgs_2": {
"locked": { "locked": {
"lastModified": 1684120848, "lastModified": 1684181436,
"narHash": "sha256-gIwJ5ac1FwZEkCRwjY+gLwgD4G1Bw3Xtr2jr2XihMPo=", "narHash": "sha256-FxGaVF3KYOe3uAHGsToSPM7sfpdudRozeF1iGiyjRBE=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "0cb867999eec4085e1c9ca61c09b72261fa63bb4", "rev": "9f9fcc1483fb041f4d8708a78d025614d7a03430",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -100,11 +100,11 @@
"utils": "utils" "utils": "utils"
}, },
"locked": { "locked": {
"lastModified": 1684183882, "lastModified": 1684207659,
"narHash": "sha256-Ed692aLxADTPRThPE6FdgGXWdKuLWgj84jX7Hsl4zpY=", "narHash": "sha256-EVVCm5u/tWPHDVjXPDEKioLsDiQLcrASw9Yo8i4l6dI=",
"ref": "refs/heads/trunk", "ref": "refs/heads/trunk",
"rev": "9c6ccfcbc17736559181ca214e711bc493944e8a", "rev": "4cca422b3b3cf2eef688306437eee165abf79687",
"revCount": 12, "revCount": 13,
"type": "git", "type": "git",
"url": "https://git.stranger.systems/nix/Rust" "url": "https://git.stranger.systems/nix/Rust"
}, },
@ -122,11 +122,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1684117262, "lastModified": 1684203630,
"narHash": "sha256-ZSF4CZqeyk6QwTjal73KPMuTWiU6w/p8ygEimrPb7u4=", "narHash": "sha256-ZOWNixdHU4qFZUgYNEULFB3ifctMQO9H4Oo+Zrz+4L8=",
"owner": "oxalica", "owner": "oxalica",
"repo": "rust-overlay", "repo": "rust-overlay",
"rev": "4679872d2dd3e94ffef75efcbf77ea11549d90a7", "rev": "65c3f2655f52a81e1b3e629d4c07df4873d0f2bb",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@ -7,12 +7,15 @@ use color_eyre::{
}; };
use isahc::HttpClient; use isahc::HttpClient;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tracing::{debug, error, instrument, trace, warn};
/// Abstraction over an adoptium API instance /// Abstraction over an adoptium API instance
#[derive(custom_debug::Debug)]
pub struct AdoptiumAPI { pub struct AdoptiumAPI {
/// Base URL /// Base URL
base_url: String, base_url: String,
/// Client /// Client
#[debug(skip)]
client: HttpClient, client: HttpClient,
/// Jvm_Impl string /// Jvm_Impl string
jvm_impl: String, jvm_impl: String,
@ -38,6 +41,7 @@ impl AdoptiumAPI {
} }
/// Get the availble releases /// Get the availble releases
#[instrument]
pub async fn available_releases(&self) -> Result<AvailableReleases> { pub async fn available_releases(&self) -> Result<AvailableReleases> {
let response = self let response = self
.client .client
@ -86,6 +90,7 @@ impl AdoptiumAPI {
} }
/// Return latest release /// Return latest release
#[instrument(skip(arch), fields(arch = arch.as_ref()))]
pub async fn latest( pub async fn latest(
&self, &self,
version: u32, version: u32,
@ -93,30 +98,41 @@ impl AdoptiumAPI {
pre_release: bool, pre_release: bool,
) -> Result<Release> { ) -> Result<Release> {
let release_type = if pre_release { "ea" } else { "ga" }; let release_type = if pre_release { "ea" } else { "ga" };
debug!(?release_type);
let arch = arch.as_ref(); let arch = arch.as_ref();
let url = format!( let url = format!(
"{}/v3/assets/feature_releases/{version}/{release_type}?architecture={arch}&heap_size=normal&image_type=jdk&jvm_impl=hotspot&os=linux&page=0&page_size=10&project=jdk&sort_method=DATE&sort_order=DESC&jvm_impl={}", "{}/v3/assets/feature_releases/{version}/{release_type}?architecture={arch}&heap_size=normal&image_type=jdk&os=linux&page=0&page_size=10&project=jdk&sort_method=DATE&sort_order=DESC&jvm_impl={}",
self.base_url, self.base_url,
self.jvm_impl self.jvm_impl
); );
trace!(?url);
let mut response = self let mut response = self
.client .client
.get_async(url) .get_async(&url)
.await .await
.context("Failed to request release")?; .context("Failed to request release")?;
debug!(?response);
// If we get a 301, respond to it // If we get a 301, respond to it
if response.status().as_u16() == 301 { match response.status().as_u16() {
let location = response 301 => {
.headers() let location = response
.get("location") .headers()
.context("Failed to get redirect location")? .get("location")
.to_str() .context("Failed to get redirect location")?
.context("Failed to parse redirect location")?; .to_str()
response = self .context("Failed to parse redirect location")?;
.client warn!(?location, ?url, "Redirecting");
.get_async(location) response = self
.await .client
.context("Failed to request release")?; .get_async(location)
.await
.context("Failed to request release")?;
debug!(?response, "New response");
}
404 => {
error!(?url, "Location not found");
}
_ => (),
} }
let mut response = response.into_body(); let mut response = response.into_body();
let mut body = String::new(); let mut body = String::new();
@ -148,16 +164,22 @@ impl AdoptiumAPI {
output_release, output_release,
); );
} }
let latest: OutputRelease = self let latest: OutputRelease = match self
.latest(input_versions.most_recent_feature_version, arch, true) .latest(input_versions.most_recent_feature_version, arch, true)
.await .await
.context("Failed to get version - latest")? {
.into(); Ok(x) => x.into(),
Err(_) => self
.latest(input_versions.most_recent_feature_release, arch, false)
.await
.context("Failed to get latest version")?
.into(),
};
let stable: OutputRelease = self let stable: OutputRelease = self
.latest( .latest(
input_versions.available_releases[input_versions.available_releases.len() - 1], input_versions.available_releases[input_versions.available_releases.len() - 1],
arch, arch,
true, false,
) )
.await .await
.context("Failed to get version - stable")? .context("Failed to get version - stable")?
@ -167,7 +189,7 @@ impl AdoptiumAPI {
input_versions.available_lts_releases input_versions.available_lts_releases
[input_versions.available_lts_releases.len() - 1], [input_versions.available_lts_releases.len() - 1],
arch, arch,
true, false,
) )
.await .await
.context("Failed to get version - lts")? .context("Failed to get version - lts")?

View File

@ -1,10 +1,8 @@
use std::collections::BTreeMap; use std::collections::BTreeMap;
use api::OutputReleases; use api::OutputReleases;
use color_eyre::{ use color_eyre::eyre::{Context, Result};
eyre::{Context, Result}, use tracing_subscriber::{fmt, prelude::*, EnvFilter};
};
use crate::api::AdoptiumAPI; use crate::api::AdoptiumAPI;
@ -14,6 +12,12 @@ pub mod api;
#[async_std::main] #[async_std::main]
async fn main() -> Result<()> { async fn main() -> Result<()> {
color_eyre::install()?; color_eyre::install()?;
tracing_subscriber::registry()
.with(fmt::layer().pretty().with_writer(std::io::stderr))
.with(EnvFilter::from_default_env())
.init();
let mut output: BTreeMap<String, BTreeMap<String, OutputReleases>> = BTreeMap::new(); let mut output: BTreeMap<String, BTreeMap<String, OutputReleases>> = BTreeMap::new();
// Create the api instances // Create the api instances
let adoptium = AdoptiumAPI::adoptium().context("Creating api")?; let adoptium = AdoptiumAPI::adoptium().context("Creating api")?;