Skip to content

Commit

Permalink
implement From<RequestType> for Request
Browse files Browse the repository at this point in the history
  • Loading branch information
Keksoj committed May 22, 2023
1 parent fcbe244 commit 1797600
Show file tree
Hide file tree
Showing 16 changed files with 669 additions and 820 deletions.
4 changes: 1 addition & 3 deletions bin/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,9 +662,7 @@ impl CommandServer {
new_worker
.send(
format!("RESTART-{new_worker_id}-STATUS"),
Request {
request_type: Some(RequestType::Status(Status {})),
},
RequestType::Status(Status {}).into(),
)
.await;

Expand Down
22 changes: 5 additions & 17 deletions bin/src/command/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,9 +563,7 @@ impl CommandServer {
.with_context(|| "No sender on new worker".to_string())?
.send(WorkerRequest {
id: format!("UPGRADE-{worker_id}-STATUS"),
content: Request {
request_type: Some(RequestType::Status(Status {})),
},
content: RequestType::Status(Status {}).into(),
})
.await
.with_context(|| {
Expand Down Expand Up @@ -595,11 +593,7 @@ impl CommandServer {
old_worker
.send(
id.clone(),
Request {
request_type: Some(RequestType::ReturnListenSockets(
ReturnListenSockets {},
)),
},
RequestType::ReturnListenSockets(ReturnListenSockets {}).into(),
)
.await;

Expand Down Expand Up @@ -661,9 +655,7 @@ impl CommandServer {
old_worker
.send(
softstop_id.clone(),
Request {
request_type: Some(RequestType::SoftStop(SoftStop {})),
},
RequestType::SoftStop(SoftStop {}).into(),
)
.await;

Expand Down Expand Up @@ -881,9 +873,7 @@ impl CommandServer {
worker
.send(
worker_request_id.clone(),
Request {
request_type: Some(RequestType::Status(Status {})),
},
RequestType::Status(Status {}).into(),
)
.await;
count += 1;
Expand Down Expand Up @@ -957,9 +947,7 @@ impl CommandServer {
worker
.send(
req_id.clone(),
Request {
request_type: Some(RequestType::ConfigureMetrics(config as i32)),
},
RequestType::ConfigureMetrics(config as i32).into(),
)
.await;
count += 1;
Expand Down
47 changes: 15 additions & 32 deletions bin/src/ctl/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ impl CommandManager {
pub fn upgrade_main(&mut self) -> Result<(), anyhow::Error> {
println!("Preparing to upgrade proxy...");

self.send_request(Request {
request_type: Some(RequestType::ListWorkers(ListWorkers {})),
})?;
self.send_request(RequestType::ListWorkers(ListWorkers {}).into())?;

loop {
let response = self.read_channel_message_with_timeout()?;
Expand Down Expand Up @@ -128,9 +126,7 @@ impl CommandManager {
table.printstd();
println!();

self.send_request(Request {
request_type: Some(RequestType::UpgradeMain(UpgradeMain {})),
})?;
self.send_request(RequestType::UpgradeMain(UpgradeMain {}).into())?;

println!("Upgrading main process");

Expand Down Expand Up @@ -197,9 +193,7 @@ impl CommandManager {
println!("upgrading worker {worker_id}");

//FIXME: we should be able to soft stop one specific worker
self.send_request(Request {
request_type: Some(RequestType::UpgradeWorker(worker_id)),
})?;
self.send_request(RequestType::UpgradeWorker(worker_id).into())?;

loop {
let response = self.read_channel_message_with_timeout()?;
Expand Down Expand Up @@ -229,14 +223,13 @@ impl CommandManager {
cluster_ids: Vec<String>,
backend_ids: Vec<String>,
) -> Result<(), anyhow::Error> {
let request = Request {
request_type: Some(RequestType::QueryMetrics(QueryMetricsOptions {
list,
cluster_ids,
backend_ids,
metric_names,
})),
};
let request: Request = RequestType::QueryMetrics(QueryMetricsOptions {
list,
cluster_ids,
backend_ids,
metric_names,
})
.into();

// a loop to reperform the query every refresh time
loop {
Expand Down Expand Up @@ -303,9 +296,7 @@ impl CommandManager {
}

let request = if let Some(ref cluster_id) = cluster_id {
Request {
request_type: Some(RequestType::QueryClusterById(cluster_id.to_string())),
}
RequestType::QueryClusterById(cluster_id.to_string()).into()
} else if let Some(ref domain) = domain {
let splitted: Vec<String> =
domain.splitn(2, '/').map(|elem| elem.to_string()).collect();
Expand All @@ -322,13 +313,9 @@ impl CommandManager {
path: splitted.get(1).cloned().map(|path| format!("/{path}")), // We add the / again because of the splitn removing it
};

Request {
request_type: Some(RequestType::QueryClustersByDomain(query_domain)),
}
RequestType::QueryClustersByDomain(query_domain).into()
} else {
Request {
request_type: Some(RequestType::QueryClustersHashes(QueryClustersHashes {})),
}
RequestType::QueryClustersHashes(QueryClustersHashes {}).into()
};

self.send_request(request)?;
Expand Down Expand Up @@ -385,9 +372,7 @@ impl CommandManager {
json: bool,
filters: QueryCertificatesFilters,
) -> Result<(), anyhow::Error> {
self.send_request(Request {
request_type: Some(RequestType::QueryCertificatesFromWorkers(filters)),
})?;
self.send_request(RequestType::QueryCertificatesFromWorkers(filters).into())?;

loop {
let response = self.read_channel_message_with_timeout()?;
Expand Down Expand Up @@ -424,9 +409,7 @@ impl CommandManager {
json: bool,
filters: QueryCertificatesFilters,
) -> anyhow::Result<()> {
self.send_request(Request {
request_type: Some(RequestType::QueryCertificatesFromTheState(filters)),
})?;
self.send_request(RequestType::QueryCertificatesFromTheState(filters).into())?;

loop {
let response = self.read_channel_message_with_timeout()?;
Expand Down

0 comments on commit 1797600

Please sign in to comment.