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

Market decentralized - database models #269

Merged
merged 25 commits into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b1662df
Add database most important tables
nieznanysprawiciel May 6, 2020
de3be45
Insert offer to database
nieznanysprawiciel May 20, 2020
9809678
[Test] Check market state after subscribing offer
nieznanysprawiciel May 20, 2020
6d5bbe7
Unsubscribe offer
nieznanysprawiciel May 21, 2020
dfe14a0
[Test] Add check on not existing subsctiption id
nieznanysprawiciel May 21, 2020
bf4d731
Subscribe demand and unsubscribe [+Test]
nieznanysprawiciel May 21, 2020
98c189d
Add http endpoints
nieznanysprawiciel May 22, 2020
2701327
Decentralized market running instruction
nieznanysprawiciel May 25, 2020
fd6c148
SubscriptionId consists of random part and offer/demand hash
nieznanysprawiciel May 25, 2020
30edee1
rebased on service-ctx-sep-dbs
tworec May 25, 2020
723b88b
Add timestamps to Offer/Demand
nieznanysprawiciel May 27, 2020
84577c1
Merge branch 'master' of github.com:golemfactory/yagna into market-de…
nieznanysprawiciel May 27, 2020
7616d77
Cargo fmt
nieznanysprawiciel May 27, 2020
c0c501e
Merge branch 'master' into market-decentralized/db-models
tworec May 27, 2020
6fb8401
Offer/Demand - validating incoming subscription id hash [+Test]
nieznanysprawiciel May 26, 2020
0d91882
remove unwanted tomls
tworec Jun 2, 2020
9103138
Apply review requested changes
nieznanysprawiciel Jun 2, 2020
957e8ce
Merge branch 'master' of github.com:golemfactory/yagna into market-de…
nieznanysprawiciel Jun 2, 2020
69b9486
Review changes: Add hardcoded expiration time; Chnage terminate_agree…
nieznanysprawiciel Jun 3, 2020
fb4fc12
Added Offer/Demand timestamp of adding record to database
nieznanysprawiciel Jun 3, 2020
b57031d
Cargo fmt
nieznanysprawiciel Jun 3, 2020
19f0352
insertion_ts instead of modification_ts
nieznanysprawiciel Jun 3, 2020
2264d56
[mkt-matcher] error simplify
tworec Jun 3, 2020
989d4ee
Merge master
nieznanysprawiciel Jun 4, 2020
5db3197
Merge branch 'market-decentralized/db-models' of github.com:golemfact…
nieznanysprawiciel Jun 4, 2020
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
170 changes: 85 additions & 85 deletions Cargo.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
-- Your SQL goes here

CREATE TABLE market_offer (
id VARCHAR(255) NOT NULL PRIMARY KEY,
id VARCHAR(97) NOT NULL PRIMARY KEY,
properties TEXT NOT NULL,
constraints TEXT NOT NULL,
node_id VARCHAR(255) NOT NULL,
node_id VARCHAR(20) NOT NULL,

creation_time DATETIME NOT NULL,
addition_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
creation_ts DATETIME NOT NULL,
expiration_time DATETIME NOT NULL
);

CREATE TABLE market_demand (
id VARCHAR(255) NOT NULL PRIMARY KEY,
id VARCHAR(97) NOT NULL PRIMARY KEY,
properties TEXT NOT NULL,
constraints TEXT NOT NULL,
node_id VARCHAR(255) NOT NULL,
node_id VARCHAR(20) NOT NULL,

creation_time DATETIME NOT NULL,
addition_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
creation_ts DATETIME NOT NULL,
expiration_time DATETIME NOT NULL
);
16 changes: 2 additions & 14 deletions core/market/decentralized/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ pub mod response;

use serde::{Deserialize, Serialize};

pub const DEFAULT_ACK_TIMEOUT: u32 = 60; // seconds
pub const DEFAULT_EVENT_TIMEOUT: f32 = 0.0; // seconds
pub const DEFAULT_REQUEST_TIMEOUT: f32 = 12.0;
pub const DEFAULT_QUERY_TIMEOUT: f32 = 12.0;

#[derive(Deserialize)]
pub struct PathAgreement {
Expand Down Expand Up @@ -50,21 +49,10 @@ pub struct QueryTimeoutMaxEvents {

#[inline(always)]
pub(crate) fn default_query_timeout() -> Option<f32> {
Some(DEFAULT_REQUEST_TIMEOUT)
}

#[inline(always)]
pub(crate) fn default_ack_timeout() -> u32 {
DEFAULT_ACK_TIMEOUT
Some(DEFAULT_QUERY_TIMEOUT)
}

#[inline(always)]
pub(crate) fn default_event_timeout() -> Option<f32> {
Some(DEFAULT_EVENT_TIMEOUT)
}

#[derive(Deserialize)]
pub struct Timeout {
#[serde(default = "default_ack_timeout")]
pub timeout: u32,
}
30 changes: 23 additions & 7 deletions core/market/decentralized/src/api/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ pub fn register_endpoints(scope: Scope) -> Scope {
.service(reject_proposal)
.service(approve_agreement)
.service(reject_agreement)
.service(terminate_agreement)
.service(get_agreement)
}

#[actix_web::post("/offers")]
Expand All @@ -52,13 +54,9 @@ async fn unsubscribe(
path: Path<PathSubscription>,
id: Identity,
) -> HttpResponse {
match market
.matcher
.get_offer(path.into_inner().subscription_id)
.await
{
Ok(Some(offer)) => response::ok(offer),
Ok(None) => response::not_found(),
let subscription_id = path.into_inner().subscription_id;
match market.unsubscribe_offer(subscription_id.clone(), id).await {
Ok(()) => response::ok(subscription_id),
// TODO: Translate MatcherError to better HTTP response.
Err(error) => response::server_error(&format!("{}", error)),
}
Expand Down Expand Up @@ -120,3 +118,21 @@ async fn reject_agreement(
) -> HttpResponse {
response::not_implemented()
}
nieznanysprawiciel marked this conversation as resolved.
Show resolved Hide resolved

#[actix_web::delete("/agreements/{agreement_id}/terminate")]
nieznanysprawiciel marked this conversation as resolved.
Show resolved Hide resolved
async fn terminate_agreement(
market: Data<Arc<MarketService>>,
path: Path<PathAgreement>,
id: Identity,
) -> HttpResponse {
response::not_implemented()
}

#[actix_web::get("/agreements/{agreement_id}")]
async fn get_agreement(
market: Data<Arc<MarketService>>,
path: Path<PathAgreement>,
id: Identity,
) -> HttpResponse {
response::not_implemented()
}
10 changes: 3 additions & 7 deletions core/market/decentralized/src/api/requestor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,9 @@ async fn unsubscribe(
path: Path<PathSubscription>,
id: Identity,
) -> HttpResponse {
match market
.matcher
.get_demand(path.into_inner().subscription_id)
.await
{
Ok(Some(demand)) => response::ok(demand),
Ok(None) => response::not_found(),
let subscription_id = path.into_inner().subscription_id;
match market.unsubscribe_demand(subscription_id.clone(), id).await {
Ok(()) => response::ok(subscription_id),
// TODO: Translate MatcherError to better HTTP response.
Err(error) => response::server_error(&format!("{}", error)),
}
Expand Down
10 changes: 3 additions & 7 deletions core/market/decentralized/src/db/models/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ pub struct Demand {
pub node_id: String,

/// Creation time of Demand on Requestor side.
pub creation_time: NaiveDateTime,
/// Time when this Demand was added to our local database.
pub addition_time: NaiveDateTime,
pub creation_ts: NaiveDateTime,
/// Time when Demand expires set by Requestor.
pub expiration_time: NaiveDateTime,
}
Expand All @@ -46,8 +44,7 @@ impl Demand {
properties,
constraints,
node_id,
creation_time: creation_time.clone(),
addition_time: creation_time.clone(),
creation_ts: creation_time.clone(),
expiration_time: creation_time.clone(),
tworec marked this conversation as resolved.
Show resolved Hide resolved
})
}
Expand All @@ -70,8 +67,7 @@ impl Demand {
properties,
constraints,
node_id,
creation_time: creation_time.clone(),
addition_time: creation_time.clone(),
creation_ts: creation_time.clone(),
expiration_time: creation_time.clone(),
}
}
Expand Down
12 changes: 3 additions & 9 deletions core/market/decentralized/src/db/models/offer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ pub struct Offer {
pub node_id: String,

/// Creation time of Offer on Provider side.
pub creation_time: NaiveDateTime,
/// Time when this Offer was added to our local database.
pub addition_time: NaiveDateTime,
pub creation_ts: NaiveDateTime,
/// Time when Offer expires set by Provider.
pub expiration_time: NaiveDateTime,
}
Expand All @@ -49,8 +47,7 @@ impl Offer {
properties,
constraints,
node_id,
creation_time: creation_time.clone(),
addition_time: creation_time.clone(),
creation_ts: creation_time.clone(),
expiration_time: creation_time.clone(),
})
}
Expand All @@ -73,8 +70,7 @@ impl Offer {
properties,
constraints,
node_id,
creation_time: creation_time.clone(),
addition_time: creation_time.clone(),
creation_ts: creation_time.clone(),
expiration_time: creation_time.clone(),
}
}
Expand All @@ -94,7 +90,6 @@ impl Offer {
}
}


#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -132,4 +127,3 @@ mod tests {
assert!(Offer::from(&offer).is_ok());
}
}

6 changes: 3 additions & 3 deletions core/market/decentralized/src/db/models/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ use ya_client::model::ErrorMessage;

#[derive(Error, Debug)]
pub enum SubscriptionParseError {
#[error("Subscription id [{}] has invalid format.", .0)]
#[error("Subscription id [{0}] has invalid format.")]
InvalidFormat(String),
#[error("Subscription id [{}] contains non hexadecimal characters.", .0)]
#[error("Subscription id [{0}] contains non hexadecimal characters.")]
NotHexadecimal(String),
#[error("Subscription id [{}] has invalid length.", .0)]
#[error("Subscription id [{0}] has invalid length.")]
InvalidLength(String),
}

Expand Down
6 changes: 2 additions & 4 deletions core/market/decentralized/src/db/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ table! {
properties -> Text,
constraints -> Text,
node_id -> Text,
creation_time -> Timestamp,
addition_time -> Timestamp,
creation_ts -> Timestamp,
expiration_time -> Timestamp,
}
}
Expand All @@ -16,8 +15,7 @@ table! {
properties -> Text,
constraints -> Text,
node_id -> Text,
creation_time -> Timestamp,
addition_time -> Timestamp,
creation_ts -> Timestamp,
expiration_time -> Timestamp,
}
}
Expand Down
6 changes: 3 additions & 3 deletions core/market/decentralized/src/market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,11 @@ impl MarketService {
let offer = ModelOffer::from_new(&offer, &id);
let subscription_id = offer.id.to_string();

self.matcher.subscribe_offer(&offer).await?;
self.provider_negotiation_engine
.subscribe_offer(&offer)
.await?;
self.matcher.subscribe_offer(&offer).await?;

Ok(subscription_id)
}

Expand All @@ -129,11 +130,10 @@ impl MarketService {
let demand = ModelDemand::from_new(&demand, &id);
let subscription_id = demand.id.to_string();

self.matcher.subscribe_demand(&demand).await?;
self.requestor_negotiation_engine
.subscribe_demand(&demand)
.await?;

self.matcher.subscribe_demand(&demand).await?;
Ok(subscription_id)
}

Expand Down