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

Plugable negotiators - integrate ya-negotiator library #1797

Draft
wants to merge 22 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
02e3074
Integrate ya-negotiator library (work in progress)
nieznanysprawiciel Jan 4, 2022
c4ed3de
Merge branch 'master' of github.com:golemfactory/yagna into provider/…
nieznanysprawiciel Feb 11, 2022
2c4c757
Pass invoice events to negotiators
nieznanysprawiciel Feb 14, 2022
5dd9347
Fix negotiator plugins directory
nieznanysprawiciel Feb 14, 2022
9b16f99
Emit SignedAgreement message to negotiators
nieznanysprawiciel May 22, 2022
e161ee4
Listen to InvoiceNotification signal from payments
nieznanysprawiciel May 22, 2022
ad9e487
Merge branch 'master' of github.com:golemfactory/yagna into provider/…
nieznanysprawiciel May 31, 2022
e47f03e
Update yagna after tokio upgrade
nieznanysprawiciel Jun 5, 2022
af15cee
Loading negotiators config log to info
nieznanysprawiciel Jun 6, 2022
c5c9d22
Merge branch 'master' of github.com:golemfactory/yagna into provider/…
nieznanysprawiciel Oct 14, 2022
f9f8c64
Merge master (not compiling)
nieznanysprawiciel Dec 2, 2022
733a4af
Merge master (not compiling)
nieznanysprawiciel Feb 3, 2023
4ca81c7
Merge branch 'master' of github.com:golemfactory/yagna into provider/…
nieznanysprawiciel Mar 27, 2023
a1742a1
Partial merge of ya-negotiators
nieznanysprawiciel Mar 28, 2023
f69797f
Integrate async negotiators
nieznanysprawiciel Mar 28, 2023
65be433
Integrate async negotiators
nieznanysprawiciel Mar 28, 2023
811150a
Merge branch 'provider/plugable-negotiators' of github.com:golemfacto…
nieznanysprawiciel Mar 29, 2023
07878d0
FileMonitor can be stopped without active waiting and sleeping
nieznanysprawiciel Mar 29, 2023
06489a9
Clippy fixes
nieznanysprawiciel Mar 31, 2023
f4c63cc
Forward Rulestore files to negotiators
nieznanysprawiciel Mar 31, 2023
25434a8
Merge branch 'master' of github.com:golemfactory/yagna into provider/…
nieznanysprawiciel Oct 29, 2023
64369e9
Clippy fixes
nieznanysprawiciel Oct 29, 2023
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
96 changes: 94 additions & 2 deletions Cargo.lock

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

11 changes: 9 additions & 2 deletions 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.5.0" }
ya-manifest-utils = { version = "0.2" }
ya-client = { version = "0.7", features = ['cli'] }
ya-client-model = "0.5"
Expand All @@ -27,6 +26,12 @@ ya-utils-process = { version = "0.2", features = ['lock'] }
ya-std-utils = "0.1"
golem-certificate = "0.1.1"

ya-negotiators = { git = "https://github.com/nieznanysprawiciel/ya-negotiator", rev = "86154fcc8ef2d1142e9f6d2816d7f0cb2ffc560f" }
ya-agreement-utils = { git = 'https://github.com/nieznanysprawiciel/ya-negotiator', rev = "86154fcc8ef2d1142e9f6d2816d7f0cb2ffc560f" }
#ya-negotiators = { path = "../../../../experiments/ya-negotiators" }
#ya-agreement-utils = { path = "../../../../experiments/ya-negotiators/agreement-utils" }


actix = { version = "0.13", default-features = false }
actix-rt = "2.7"
actix_derive = "0.6"
Expand All @@ -42,7 +47,8 @@ dotenv = "0.15.0"
futures = "0.3"
futures-util = "0.3.4"
hex = "0.4"
humantime = "2.0.0"
humantime = "2"
humantime-serde = "1"
itertools = "0.10"
lazy_static = "1.4.0"
libc = "0.2"
Expand All @@ -56,6 +62,7 @@ regex = "1.5"
semver = { version = "0.11", features = ["serde"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_yaml = "0.9"
shared_child = "0.3.4"
signal-hook = "0.3"
structopt = "0.3.20"
Expand Down
2 changes: 1 addition & 1 deletion agent/provider/src/execution/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use serde::{Deserialize, Serialize};
use serde_json::{Map, Value};
use thiserror::Error;

use ya_agreement_utils::OfferBuilder;
use crate::typed_props::OfferBuilder;

use super::{exe_unit_work_dir, exeunit_instance::ExeUnitInstance};

Expand Down
15 changes: 7 additions & 8 deletions agent/provider/src/execution/task_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use ya_client::model::activity::provider_event::ProviderEventType;
use ya_client::model::activity::{ActivityState, ProviderEvent, State, StatePair};
use ya_std_utils::LogErr;
use ya_utils_actix::actix_handler::ResultTypeGetter;
use ya_utils_actix::actix_signal::{Signal, SignalSlot};
use ya_utils_actix::actix_signal::{SendSignalActor, SignalSlot};
use ya_utils_actix::{actix_signal_handler, forward_actix_handler};
use ya_utils_path::SecurePath;
use ya_utils_process::ExeUnitExitStatus;
Expand Down Expand Up @@ -235,13 +235,12 @@ impl TaskRunner {
.map(|(event, myself)| async move {
let _ = match event.event_type {
ProviderEventType::CreateActivity { requestor_pub_key } => {
myself
.send(Signal(CreateActivity {
activity_id: event.activity_id,
agreement_id: event.agreement_id,
requestor_pub_key,
}))
.await?
myself.signal(CreateActivity {
activity_id: event.activity_id,
agreement_id: event.agreement_id,
requestor_pub_key,
});
Ok(())
}
ProviderEventType::DestroyActivity {} => {
myself
Expand Down
2 changes: 1 addition & 1 deletion agent/provider/src/hardware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ use serde::{Deserialize, Serialize};
use structopt::{clap, StructOpt};
use tokio::sync::watch;

use ya_agreement_utils::{CpuInfo, InfNodeInfo};
use ya_utils_path::SwapSave;

use crate::events::Event;
use crate::startup_config::{FileMonitor, ProviderConfig};
use crate::typed_props::{CpuInfo, InfNodeInfo};

pub const DEFAULT_PROFILE_NAME: &str = "default";
pub const CPU_THREADS_RESERVED: i32 = 1;
Expand Down
1 change: 1 addition & 0 deletions agent/provider/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub mod rules;
pub mod signal;
pub mod startup_config;
pub mod tasks;
mod typed_props;

pub use config::globals::GlobalsState;
pub use startup_config::ReceiverAccount;
55 changes: 50 additions & 5 deletions agent/provider/src/market/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
use serde::{Deserialize, Serialize};
use std::convert::TryFrom;
use std::path::{Path, PathBuf};
use structopt::StructOpt;

use crate::market::negotiator::factory::NegotiatorsConfig;
use crate::startup_config::{ProviderConfig, DEFAULT_PLUGINS_DIR};

lazy_static::lazy_static! {
pub static ref DEFAULT_NEGOTIATORS_PLUGINS_DIR: PathBuf = default_negotiators_plugins();
}

/// Configuration for ProviderMarket actor.
#[derive(StructOpt, Clone)]
Expand All @@ -11,12 +18,50 @@ 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,
#[structopt(long, env, parse(try_from_str = humantime::parse_duration), default_value = "20s")]
pub process_market_events_timeout: std::time::Duration,
#[structopt(long, env, parse(try_from_str = humantime::parse_duration), default_value = "10s")]
pub negotiators_shutdown_timeout: std::time::Duration,
/// 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_NEGOTIATORS_PLUGINS_DIR.as_ref(),
required = false,
)]
pub negotiators_plugins: PathBuf,
#[structopt(long, env)]
pub create_negotiators_config: bool,
}

/// Agent configuration that will be passed to negotiators.
#[derive(Clone, Serialize, Deserialize)]
pub struct AgentNegotiatorsConfig {
pub rules_file: PathBuf,
pub whitelist_file: PathBuf,
pub cert_dir: PathBuf,
}

fn default_negotiators_plugins() -> PathBuf {
PathBuf::from(&*DEFAULT_PLUGINS_DIR)
.parent()
.map(Path::to_path_buf)
.unwrap_or_else(|| "/.local/lib/yagna/plugins/".into())
}

impl TryFrom<ProviderConfig> for AgentNegotiatorsConfig {
type Error = anyhow::Error;

fn try_from(config: ProviderConfig) -> anyhow::Result<Self> {
let cert_dir = config.cert_dir_path()?;
Ok(AgentNegotiatorsConfig {
rules_file: config.rules_file,
whitelist_file: config.domain_whitelist_file,
cert_dir,
})
}
}
14 changes: 2 additions & 12 deletions agent/provider/src/market/negotiator.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
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 super::config::AgentNegotiatorsConfig;
pub use common::AgreementResult;
Loading
Loading