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

Adapt to new Market Api 1.6.1 #775

Merged
merged 1 commit into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ ya-sb-router = { path = "service-bus/router" }
ya-sb-util = { path = "service-bus/util" }

## CLIENT
ya-client = { git = "https://github.com/golemfactory/ya-client.git", rev = "2e745dbc2056c8064a62f80cf51c5d6fc03411cb"}
ya-client-model = { git = "https://github.com/golemfactory/ya-client.git", rev = "2e745dbc2056c8064a62f80cf51c5d6fc03411cb"}
ya-client = { git = "https://github.com/golemfactory/ya-client.git", rev = "ba89a542f39ba659dcacecfe64930ed7e1e465de"}
ya-client-model = { git = "https://github.com/golemfactory/ya-client.git", rev = "ba89a542f39ba659dcacecfe64930ed7e1e465de"}

## OTHERS
gftp = { path = "core/gftp" }
Expand Down
21 changes: 18 additions & 3 deletions agent/provider/src/market/mock_negotiator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,25 @@ impl Negotiator for LimitAgreementsNegotiator {
"Negotiator: Reject proposal [{:?}] due to expiration limits.",
demand.proposal_id
);
Ok(ProposalResponse::RejectProposal)
Ok(ProposalResponse::RejectProposal {
reason: Some(format!(
"proposal expired at: {} which is less than 5 min or more than 30 min from now",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"proposal expired at: {} which is less than 5 min or more than 30 min from now",
"Proposal expires at: {} which is less than 5 min or more than 30 min from now",

expiration
)),
})
} else if self.has_free_slot() {
Ok(ProposalResponse::AcceptProposal)
} else {
log::info!(
"Negotiator: Reject proposal [{:?}] due to limit.",
demand.proposal_id
);
Ok(ProposalResponse::RejectProposal)
Ok(ProposalResponse::RejectProposal {
reason: Some(format!(
"available agreements limit: {} reached",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"available agreements limit: {} reached",
"Node busy. Reached Agreements limit: {}",

self.max_agreements
)),
})
}
}

Expand All @@ -109,7 +119,12 @@ impl Negotiator for LimitAgreementsNegotiator {
"Negotiator: Reject agreement proposal [{}] due to limit.",
agreement.agreement_id
);
Ok(AgreementResponse::RejectAgreement)
Ok(AgreementResponse::RejectAgreement {
reason: Some(format!(
"available agreements limit: {} reached",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"available agreements limit: {} reached",
"Node busy. Reached Agreements limit: {}",

self.max_agreements
)),
})
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions agent/provider/src/market/negotiator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ pub enum ProposalResponse {
offer: DemandOfferBase,
},
AcceptProposal,
RejectProposal,
#[display(fmt = "RejectProposal( reason: {:?})", reason)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be awfull message with Some()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's cover it in other PR, as this is blocking others.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported as #776

RejectProposal {
reason: Option<String>,
},
///< Don't send any message to requestor. Could be useful to wait for other offers.
IgnoreProposal,
}
Expand All @@ -26,7 +29,10 @@ pub enum ProposalResponse {
#[allow(dead_code)]
pub enum AgreementResponse {
ApproveAgreement,
RejectAgreement,
#[display(fmt = "RejectAgreement( reason: {:?})", reason)]
RejectAgreement {
reason: Option<String>,
},
}

/// Result of agreement execution.
Expand Down
16 changes: 11 additions & 5 deletions agent/provider/src/market/provider_market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::sync::Arc;

use ya_agreement_utils::{AgreementView, OfferDefinition};
use ya_client::market::MarketProviderApi;
use ya_client_model::market::{Agreement, DemandOfferBase, Proposal, ProviderEvent};
use ya_client_model::market::{Agreement, DemandOfferBase, Proposal, ProviderEvent, Reason};
use ya_utils_actix::{
actix_handler::ResultTypeGetter,
actix_signal::{SignalSlot, Subscribe},
Expand Down Expand Up @@ -303,8 +303,13 @@ async fn process_proposal(
.await?;
}
ProposalResponse::IgnoreProposal => log::info!("Ignoring proposal {:?}", proposal_id),
ProposalResponse::RejectProposal => {
api.reject_proposal(&subscription.id, proposal_id).await?;
ProposalResponse::RejectProposal { reason } => {
api.reject_proposal_with_reason(
&subscription.id,
proposal_id,
reason.map(|r| Reason::new(r)),
)
.await?;
}
},
Err(error) => log::error!(
Expand Down Expand Up @@ -366,8 +371,9 @@ async fn process_agreement(

let _ = market.send(message).await?;
}
AgreementResponse::RejectAgreement => {
api.reject_agreement(&agreement.agreement_id).await?;
AgreementResponse::RejectAgreement { reason } => {
api.reject_agreement(&agreement.agreement_id, reason.map(|r| Reason::new(r)))
.await?;
}
},
Err(error) => log::error!(
Expand Down
1 change: 1 addition & 0 deletions core/market/src/db/model/agreement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ impl Agreement {
.map(|d| DateTime::<Utc>::from_utc(d, Utc)),
state: self.state.into(),
timestamp: Utc.from_utc_datetime(&self.creation_ts),
app_session_id: None,
proposed_signature: self.proposed_signature,
approved_signature: self.approved_signature,
committed_signature: self.committed_signature,
Expand Down
1 change: 1 addition & 0 deletions core/payment/examples/payment_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ async fn main() -> anyhow::Result<()> {
approved_date: None,
state: market::agreement::State::Proposal,
timestamp: Utc::now(),
app_session_id: None,
proposed_signature: None,
approved_signature: None,
committed_signature: None,
Expand Down