Skip to content

Commit

Permalink
write AddBackend and LoadBalancingParams in protobuf
Browse files Browse the repository at this point in the history
use ..Default::default() in state.rs
  • Loading branch information
Keksoj committed Apr 5, 2023
1 parent 685bb16 commit bdd402f
Show file tree
Hide file tree
Showing 16 changed files with 88 additions and 124 deletions.
4 changes: 2 additions & 2 deletions bin/src/acme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ use sozu_command_lib::{
channel::Channel,
config::Config,
proto::command::{
AddCertificate, CertificateAndKey, PathRule, RemoveBackend, ReplaceCertificate,
AddBackend, AddCertificate, CertificateAndKey, PathRule, RemoveBackend, ReplaceCertificate,
RequestHttpFrontend, RulePosition, TlsVersion,
},
request::{AddBackend, Request},
request::Request,
response::{Response, ResponseStatus},
};

Expand Down
10 changes: 5 additions & 5 deletions bin/src/ctl/request_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ use sozu_command_lib::{
certificate::{calculate_fingerprint, split_certificate_chain, Fingerprint},
config::{Config, ListenerBuilder},
proto::command::{
AddCertificate, CertificateAndKey, Cluster, FrontendFilters, PathRule, ProxyProtocolConfig,
RemoveBackend, RemoveCertificate, ReplaceCertificate, RequestHttpFrontend,
RequestTcpFrontend, RulePosition, TlsVersion,
AddBackend, AddCertificate, CertificateAndKey, Cluster, FrontendFilters,
LoadBalancingParams, PathRule, ProxyProtocolConfig, RemoveBackend, RemoveCertificate,
ReplaceCertificate, RequestHttpFrontend, RequestTcpFrontend, RulePosition, TlsVersion,
},
request::{
ActivateListener, AddBackend, DeactivateListener, ListenerType, LoadBalancingParams,
MetricsConfiguration, RemoveListener, Request,
ActivateListener, DeactivateListener, ListenerType, MetricsConfiguration, RemoveListener,
Request,
},
};

Expand Down
15 changes: 15 additions & 0 deletions command/src/command.proto
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,25 @@ enum LoadMetric {
CONNECTION_TIME = 2;
}

// add a backend
message AddBackend {
required string cluster_id = 1;
required string backend_id = 2;
// the socket address of the backend
required string address = 3;
optional string sticky_id = 4;
optional LoadBalancingParams load_balancing_parameters = 5;
optional bool backup = 6;
}

// remove an existing backend
message RemoveBackend {
required string cluster_id = 1;
required string backend_id = 2;
// the socket address of the backend
required string address = 3 ;
}

message LoadBalancingParams {
required int32 weight = 1;
}
13 changes: 6 additions & 7 deletions command/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ use toml;
use crate::{
certificate::split_certificate_chain,
proto::command::{
AddCertificate, CertificateAndKey, Cluster, LoadBalancingAlgorithms, LoadMetric, PathRule,
ProxyProtocolConfig, RequestHttpFrontend, RequestTcpFrontend, RulePosition, TlsVersion,
},
request::{
ActivateListener, AddBackend, ListenerType, LoadBalancingParams, Request, WorkerRequest,
AddBackend, AddCertificate, CertificateAndKey, Cluster, LoadBalancingAlgorithms,
LoadBalancingParams, LoadMetric, PathRule, ProxyProtocolConfig, RequestHttpFrontend,
RequestTcpFrontend, RulePosition, TlsVersion,
},
request::{ActivateListener, ListenerType, Request, WorkerRequest},
response::{HttpListenerConfig, HttpsListenerConfig, TcpListenerConfig},
};

Expand Down Expand Up @@ -817,7 +816,7 @@ impl HttpClusterConfig {

for (backend_count, backend) in self.backends.iter().enumerate() {
let load_balancing_parameters = Some(LoadBalancingParams {
weight: backend.weight.unwrap_or(100),
weight: backend.weight.unwrap_or(100) as i32,
});

v.push(Request::AddBackend(AddBackend {
Expand Down Expand Up @@ -875,7 +874,7 @@ impl TcpClusterConfig {

for (backend_count, backend) in self.backends.iter().enumerate() {
let load_balancing_parameters = Some(LoadBalancingParams {
weight: backend.weight.unwrap_or(100),
weight: backend.weight.unwrap_or(100) as i32,
});

v.push(Request::AddBackend(AddBackend {
Expand Down
21 changes: 4 additions & 17 deletions command/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use anyhow::Context;
use crate::{
certificate::Fingerprint,
proto::command::{
AddCertificate, Cluster, FrontendFilters, LoadBalancingAlgorithms, PathRuleKind,
RemoveBackend, RemoveCertificate, ReplaceCertificate, RequestHttpFrontend,
AddBackend, AddCertificate, Cluster, FrontendFilters, LoadBalancingAlgorithms,
PathRuleKind, RemoveBackend, RemoveCertificate, ReplaceCertificate, RequestHttpFrontend,
RequestTcpFrontend, RulePosition,
},
response::{
Expand Down Expand Up @@ -282,16 +282,6 @@ impl Display for RequestHttpFrontend {
}
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct AddBackend {
pub cluster_id: String,
pub backend_id: String,
pub address: String,
pub sticky_id: Option<String>,
pub load_balancing_parameters: Option<LoadBalancingParams>,
pub backup: Option<bool>,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum MetricsConfiguration {
Enabled,
Expand Down Expand Up @@ -347,10 +337,6 @@ impl FromStr for LoadBalancingAlgorithms {
}
}
}
#[derive(Default, Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
pub struct LoadBalancingParams {
pub weight: u8,
}

pub fn is_false(b: &bool) -> bool {
!*b
Expand All @@ -363,7 +349,8 @@ mod tests {
use super::*;
use crate::certificate::split_certificate_chain;
use crate::proto::command::{
CertificateAndKey, PathRule, ProxyProtocolConfig, RulePosition, TlsVersion,
CertificateAndKey, LoadBalancingParams, PathRule, ProxyProtocolConfig, RulePosition,
TlsVersion,
};
use crate::response::HttpFrontend;
use serde_json;
Expand Down
9 changes: 6 additions & 3 deletions command/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use std::{

use crate::{
proto::command::{
CertificateSummary, Cluster, PathRule, PathRuleKind, RequestHttpFrontend,
RequestTcpFrontend, RulePosition, TlsVersion,
AddBackend, CertificateSummary, Cluster, LoadBalancingParams, PathRule, PathRuleKind,
RequestHttpFrontend, RequestTcpFrontend, RulePosition, TlsVersion,
},
request::{default_sticky_name, is_false, AddBackend, LoadBalancingParams, PROTOCOL_VERSION},
request::{default_sticky_name, is_false, PROTOCOL_VERSION},
state::{ClusterId, ConfigState},
};

Expand Down Expand Up @@ -294,6 +294,7 @@ pub struct ListenersList {
pub tcp_listeners: HashMap<String, TcpListenerConfig>,
}

// TODO: implement Default
/// details of an HTTP listener, sent by the main process to the worker
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct HttpListenerConfig {
Expand All @@ -319,6 +320,7 @@ pub struct HttpListenerConfig {
pub active: bool,
}

// TODO: implement Default
/// details of an HTTPS listener, sent by the main process to the worker
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct HttpsListenerConfig {
Expand Down Expand Up @@ -353,6 +355,7 @@ pub struct HttpsListenerConfig {
pub active: bool,
}

// TODO: implement Default
/// details of an TCP listener, sent by the main process to the worker
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct TcpListenerConfig {
Expand Down

0 comments on commit bdd402f

Please sign in to comment.