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]
async-std = { version = "1.12.0", features = ["attributes"] }
color-eyre = "0.5.11"
custom_debug = "0.5.1"
isahc = "1.7.2"
serde = { version = "1.0.132", features = ["derive"] }
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"

View File

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

View File

@ -7,12 +7,15 @@ use color_eyre::{
};
use isahc::HttpClient;
use serde::{Deserialize, Serialize};
use tracing::{debug, error, instrument, trace, warn};
/// Abstraction over an adoptium API instance
#[derive(custom_debug::Debug)]
pub struct AdoptiumAPI {
/// Base URL
base_url: String,
/// Client
#[debug(skip)]
client: HttpClient,
/// Jvm_Impl string
jvm_impl: String,
@ -38,6 +41,7 @@ impl AdoptiumAPI {
}
/// Get the availble releases
#[instrument]
pub async fn available_releases(&self) -> Result<AvailableReleases> {
let response = self
.client
@ -86,6 +90,7 @@ impl AdoptiumAPI {
}
/// Return latest release
#[instrument(skip(arch), fields(arch = arch.as_ref()))]
pub async fn latest(
&self,
version: u32,
@ -93,30 +98,41 @@ impl AdoptiumAPI {
pre_release: bool,
) -> Result<Release> {
let release_type = if pre_release { "ea" } else { "ga" };
debug!(?release_type);
let arch = arch.as_ref();
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.jvm_impl
);
trace!(?url);
let mut response = self
.client
.get_async(url)
.get_async(&url)
.await
.context("Failed to request release")?;
debug!(?response);
// If we get a 301, respond to it
if response.status().as_u16() == 301 {
let location = response
.headers()
.get("location")
.context("Failed to get redirect location")?
.to_str()
.context("Failed to parse redirect location")?;
response = self
.client
.get_async(location)
.await
.context("Failed to request release")?;
match response.status().as_u16() {
301 => {
let location = response
.headers()
.get("location")
.context("Failed to get redirect location")?
.to_str()
.context("Failed to parse redirect location")?;
warn!(?location, ?url, "Redirecting");
response = self
.client
.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 body = String::new();
@ -148,16 +164,22 @@ impl AdoptiumAPI {
output_release,
);
}
let latest: OutputRelease = self
let latest: OutputRelease = match self
.latest(input_versions.most_recent_feature_version, arch, true)
.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
.latest(
input_versions.available_releases[input_versions.available_releases.len() - 1],
arch,
true,
false,
)
.await
.context("Failed to get version - stable")?
@ -167,7 +189,7 @@ impl AdoptiumAPI {
input_versions.available_lts_releases
[input_versions.available_lts_releases.len() - 1],
arch,
true,
false,
)
.await
.context("Failed to get version - lts")?

View File

@ -1,10 +1,8 @@
use std::collections::BTreeMap;
use api::OutputReleases;
use color_eyre::{
eyre::{Context, Result},
};
use color_eyre::eyre::{Context, Result};
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
use crate::api::AdoptiumAPI;
@ -14,6 +12,12 @@ pub mod api;
#[async_std::main]
async fn main() -> Result<()> {
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();
// Create the api instances
let adoptium = AdoptiumAPI::adoptium().context("Creating api")?;