Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version/service #961

Merged
merged 23 commits into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3fecec2
update CODEOWNERS
tworec Jan 22, 2021
968e260
main Cargo.toml cleanup
tworec Jan 22, 2021
1b8ce80
[core model] added version module
tworec Jan 22, 2021
89cc620
ya-version as Yagna Service
tworec Jan 22, 2021
2931d9a
Merge branch 'version-notifier' into version/service
tworec Jan 22, 2021
2c7afa4
[web-middleware] allow /version wo auth
tworec Jan 22, 2021
05c970c
[ya-version] all parts fastened together
tworec Jan 22, 2021
1d3ab10
[ya-version] messages better UX + counter fix
tworec Jan 22, 2021
0a51a7d
[ya-version] check only latest release and save it + msgs & logs UX
tworec Jan 22, 2021
17597e5
[ya-version] splitted modules into files
tworec Jan 22, 2021
68d2d94
[ya-version] rest and cli json unification + show command added + dao…
tworec Jan 22, 2021
9bbbc7b
[ya-version] pending release sorted by release_ts and version
tworec Jan 22, 2021
c829ff4
[golemsp] new version notification in status
tworec Jan 22, 2021
b5fa96d
[ya-version] further UX improovements
tworec Jan 22, 2021
8de9732
[ya-version] tuneup creation of (initial) release from binary-hardcod…
tworec Jan 22, 2021
ad5fa7e
[ya-version] log warning interval 30min
tworec Jan 22, 2021
1eb4cdc
[ya-version] v0.1 + github fns in separate module
tworec Jan 23, 2021
0032bb2
Revert "update CODEOWNERS"; moved to separate PR #963
tworec Jan 25, 2021
98dea9f
get current release on start, to not request GH unnecessary
tworec Jan 25, 2021
3ff8f06
[ya-version] show help message for the main cli entry + hide skip option
tworec Jan 25, 2021
d1bdc1b
[ya-version] first check running release and then latest
tworec Jan 25, 2021
cca57ae
[ya-version] apply review comments by @jiivan: fixed release_ts ordering
tworec Jan 25, 2021
104b707
[ya-version] fixed tag stripping + aux order by insertion_ts
tworec Jan 25, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ya-sgx = "0.1"
ya-utils-path = "0.1"
ya-utils-futures = "0.1"
ya-utils-process = { version = "0.1", features = ["lock"] }
ya-version = "0.0.1"
ya-version = "0.1"

actix-rt = "1.0"
actix-service = "1.0"
Expand Down Expand Up @@ -145,17 +145,18 @@ members = [

[patch.crates-io]
## SERVICES
ya-identity = { path = "core/identity" }
ya-net = { path = "core/net" }
ya-market = { path = "core/market" }
ya-market-resolver = { path = "core/market/resolver" }
ya-activity = { path = "core/activity" }
ya-sgx = { path = "core/sgx" }
ya-payment = { path = "core/payment" }
ya-payment-driver = { path = "core/payment-driver/base" }
ya-dummy-driver = { path = "core/payment-driver/dummy" }
ya-gnt-driver = { path = "core/payment-driver/gnt" }
ya-zksync-driver = { path = "core/payment-driver/zksync" }
ya-identity = { path = "core/identity" }
ya-market = { path = "core/market" }
ya-market-resolver = { path = "core/market/resolver" }
ya-net = { path = "core/net" }
ya-payment = { path = "core/payment" }
ya-sgx = { path = "core/sgx" }
ya-version = { path = "core/version" }

## CORE UTILS
ya-core-model = { path = "core/model" }
Expand Down Expand Up @@ -194,4 +195,3 @@ ya-utils-path = { path = "utils/path"}
ya-utils-process = { path = "utils/process"}
ya-diesel-utils = { path = "utils/diesel-utils"}
ya-metrics = { path = "core/metrics" }
ya-version = { path = "core/version" }
4 changes: 3 additions & 1 deletion core/model/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ full = [
'net',
'payment',
'gftp',
'sgx'
'sgx',
'version',
]
activity = []
appkey = []
Expand All @@ -31,6 +32,7 @@ market = []
net = []
payment = ['bigdecimal', 'bitflags']
sgx = ['graphene-sgx']
version = []

[dependencies]
ya-client-model = "0.2"
Expand Down
3 changes: 3 additions & 0 deletions core/model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ pub mod gftp;
#[cfg(feature = "sgx")]
pub mod sgx;

#[cfg(feature = "version")]
pub mod version;

use derive_more::Display;
use serde::{Deserialize, Serialize};
pub use ya_client_model::NodeId;
Expand Down
110 changes: 110 additions & 0 deletions core/model/src/version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
//! Version handling service bus API.

use chrono::NaiveDateTime;
use serde::{Deserialize, Serialize};

use ya_client_model::ErrorMessage;
use ya_service_bus::RpcMessage;

pub const BUS_ID: &'static str = "/local/version";

/// Skip upgrading to the latest Yagna release.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Skip();

impl RpcMessage for Skip {
const ID: &'static str = "skip";
type Item = Option<Release>;
type Error = ErrorMessage;
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Get {
pub check: bool,
}

impl Get {
pub fn show_only() -> Self {
Get { check: false }
}

pub fn with_check() -> Self {
Get { check: true }
}
}

impl RpcMessage for Get {
const ID: &'static str = "check";
type Item = VersionInfo;
type Error = ErrorMessage;
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, thiserror::Error)]
#[serde(rename_all = "camelCase")]
#[error("Version {version}{} '{name}' released {}",
gitrev.as_ref().map(|r| format!(" ({})",r)).unwrap_or("".into()),
release_ts.format("%Y-%m-%d")
)]
pub struct Release {
pub version: String,
pub name: String,
pub gitrev: Option<String>,
pub seen: bool,
pub release_ts: NaiveDateTime,
pub insertion_ts: Option<NaiveDateTime>,
pub update_ts: Option<NaiveDateTime>,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct VersionInfo {
pub current: Release,
pub pending: Option<Release>,
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn test_release_no_gitrev_to_string() {
let now = NaiveDateTime::parse_from_str("2015-10-13T15:43:00GMT+2", "%Y-%m-%dT%H:%M:%S%Z")
.unwrap();
let r = Release {
version: "0.6.1".to_string(),
name: "some code name".to_string(),
gitrev: None,
seen: false,
release_ts: now,
insertion_ts: None,
update_ts: None,
};

assert_eq!(
r.to_string(),
"Version 0.6.1 'some code name' released 2015-10-13"
);
}

#[test]
fn test_release_gitrev_to_string() {
let now = NaiveDateTime::parse_from_str("2015-10-13T15:43:00GMT+2", "%Y-%m-%dT%H:%M:%S%Z")
.unwrap();
let r = Release {
version: "0.6.1".to_string(),
name: "some code name".to_string(),
gitrev: Some("0032bb27".into()),
seen: false,
release_ts: now,
insertion_ts: None,
update_ts: None,
};

assert_eq!(
r.to_string(),
"Version 0.6.1 (0032bb27) 'some code name' released 2015-10-13"
);
}
}
4 changes: 3 additions & 1 deletion core/serv-api/web/src/middleware/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ where
let service = self.service.clone();

// TODO: remove this hack; possibly by enabling creation of arbitrary appkey from CLI
if req.uri().to_string().starts_with("/metrics-api") {
if req.uri().to_string().starts_with("/metrics-api")
|| req.uri().to_string().starts_with("/version")
{
log::debug!("skipping authorization for uri={}", req.uri());
return Box::pin(service.borrow_mut().call(req));
}
Expand Down
7 changes: 3 additions & 4 deletions core/serv/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ use ya_market::MarketService;
use ya_metrics::{MetricsPusherOpts, MetricsService};
use ya_net::Net as NetService;
use ya_payment::{accounts as payment_accounts, PaymentService};
use ya_version::VersionService;

use ya_persistence::executor::DbExecutor;
use ya_sb_proto::{DEFAULT_GSB_URL, GSB_URL_ENV_VAR};
use ya_service_api::{CliCtx, CommandOutput};
Expand All @@ -32,6 +30,7 @@ use ya_service_api_web::{
use ya_sgx::SgxService;
use ya_utils_path::data_dir::DataDir;
use ya_utils_process::lock::ProcLock;
use ya_version::VersionService;

mod autocomplete;
use autocomplete::CompleteCommand;
Expand Down Expand Up @@ -189,10 +188,10 @@ enum Services {
// other services to initialize counters and other metrics.
#[enable(gsb, rest)]
Metrics(MetricsService),
#[enable(gsb, rest, cli)]
Version(VersionService),
#[enable(gsb, cli(flatten))]
Identity(IdentityService),
#[enable(rest)]
Version(VersionService),
#[enable(gsb)]
Net(NetService),
#[enable(gsb, rest)]
Expand Down
20 changes: 12 additions & 8 deletions core/version/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
[package]
name = "ya-version"
version = "0.0.1"
version = "0.1.0"
description = "Version handling"
authors = ["Golem Factory <contact@golem.network>"]
edition = "2018"

[dependencies]
ya-client = "0.4"
ya-compile-time-utils = "0.1"
ya-core-model = { version = "0.2.0", features = ["version"] }
ya-persistence = "0.2"
ya-service-api = "0.1"
ya-service-api-interfaces = "0.1"
ya-service-api-web = "0.1"
ya-service-bus = "0.2.2"

actix-web = "^3.2"
anyhow = "^1.0"
actix-web = "3.2"
anyhow = "1.0"
chrono = { version = "0.4", features = ["serde"] }
diesel = { version = "1.4", features = ["chrono", "sqlite", "r2d2"] }
diesel_migrations = "1.4"
log = "^0.4"
log = "0.4"
metrics = "0.12"
self_update = "0.23"
serde = { version = "^1.0", features = ["derive"] }
serde_json = "^1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
structopt = "0.3.21"
thiserror = "^1.0"
tokio = { version = "^0.2", features = ["time", "sync"] }
tokio = { version = "0.2", features = ["time", "sync"] }
Loading