Skip to content

Commit

Permalink
Integrate ya-negotiator library (work in progress)
Browse files Browse the repository at this point in the history
  • Loading branch information
nieznanysprawiciel committed Feb 11, 2022
1 parent cae1ece commit 3421001
Show file tree
Hide file tree
Showing 21 changed files with 790 additions and 1,012 deletions.
337 changes: 264 additions & 73 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion agent/provider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ name = "ya-provider"
path = "src/main.rs"

[dependencies]
ya-agreement-utils = { version = "^0.2"}
ya-client = { version = "0.5", features = ['cli'] }
ya-client-model = "0.3"
ya-compile-time-utils = "0.2"
Expand All @@ -23,6 +22,8 @@ ya-utils-actix = "0.1"
ya-utils-path = "0.1"
ya-utils-process = { version = "0.1", features = ['lock'] }
ya-std-utils = "0.1"
ya-negotiators = { version = "0.1", path = "../../../../experiments/ya-negotiators"}
ya-agreement-utils = { version = "0.2", path = "../../../../experiments/ya-negotiators/agreement-utils"}

actix = { version = "0.10", default-features = false }
actix-rt = "1.1.1"
Expand All @@ -39,6 +40,7 @@ dotenv = "0.15.0"
futures = "0.3"
futures-util = "0.3.4"
humantime = "2.0.0"
humantime-serde = "1"
lazy_static = "1.4.0"
libc = "0.2"
log = "0.4.8"
Expand All @@ -49,6 +51,7 @@ path-clean = "0.1.0"
semver = { version = "0.11", features = ["serde"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_yaml = "0.8"
shared_child = "0.3.4"
signal-hook = "0.1.13"
structopt = "0.3.20"
Expand Down
2 changes: 1 addition & 1 deletion agent/provider/src/execution/task_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ impl TaskRunner {
log::debug!("[TaskRunner] Got new Agreement: {}", msg.agreement);

// Agreement waits for first create activity event.
let agreement_id = msg.agreement.agreement_id.clone();
let agreement_id = msg.agreement.id.clone();
self.active_agreements.insert(agreement_id, msg.agreement);
Ok(())
}
Expand Down
26 changes: 21 additions & 5 deletions agent/provider/src/market/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
use std::path::PathBuf;
use structopt::StructOpt;

use crate::market::negotiator::factory::NegotiatorsConfig;
use crate::startup_config::DEFAULT_DATA_DIR;
use crate::startup_config::DEFAULT_PLUGINS_DIR;

lazy_static::lazy_static! {
pub static ref DEFAULT_NEGOTIATORS_WORKDIR_DIR: PathBuf = default_negotiators_workdir();
}

/// Configuration for ProviderMarket actor.
#[derive(StructOpt, Clone, Debug)]
Expand All @@ -11,10 +17,20 @@ pub struct MarketConfig {
pub negotiation_events_interval: f32,
#[structopt(long, env, default_value = "10.0")]
pub agreement_approve_timeout: f32,
#[structopt(long, env, default_value = "Composite")]
pub negotiator_type: String,
#[structopt(flatten)]
pub negotiator_config: NegotiatorsConfig,
#[structopt(skip = "you-forgot-to-set-session-id")]
pub session_id: String,
/// Relative to Provider DataDir
#[structopt(long, env, default_value = "negotiations")]
pub negotiators_workdir: String,
/// Uses ExeUnit plugins directory by default
#[structopt(
long,
default_value_os = DEFAULT_PLUGINS_DIR.as_ref(),
required = false,
)]
pub negotiators_plugins: PathBuf,
}

fn default_negotiators_workdir() -> PathBuf {
PathBuf::from(&*DEFAULT_DATA_DIR).join("negotiations")
}
13 changes: 1 addition & 12 deletions agent/provider/src/market/negotiator.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
mod accept_all;
pub mod builtin;
mod common;
mod component;
mod composite;
pub mod factory;

pub use accept_all::AcceptAllNegotiator;
pub use composite::CompositeNegotiator;

pub use common::{
AgreementResponse, AgreementResult, Negotiator, NegotiatorAddr, ProposalResponse,
};

pub use component::{NegotiationResult, NegotiatorComponent, NegotiatorsPack, ProposalView};
pub use common::AgreementResult;
55 changes: 0 additions & 55 deletions agent/provider/src/market/negotiator/accept_all.rs

This file was deleted.

20 changes: 20 additions & 0 deletions agent/provider/src/market/negotiator/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,23 @@ pub mod max_agreements;

pub use expiration::LimitExpiration;
pub use max_agreements::MaxAgreements;

use ya_negotiators::component::register_negotiator;
use ya_negotiators::NegotiatorComponent;

pub fn register_negotiators() {
register_negotiator(
"ya-provider",
"LimitExpiration",
Box::new(|config, _| {
Ok(Box::new(LimitExpiration::new(config)?) as Box<dyn NegotiatorComponent>)
}),
);
register_negotiator(
"ya-provider",
"LimitAgreements",
Box::new(|config, _| {
Ok(Box::new(MaxAgreements::new(config)?) as Box<dyn NegotiatorComponent>)
}),
);
}
Loading

0 comments on commit 3421001

Please sign in to comment.