Skip to content

Commit 4499ee7

Browse files
committed
refactor: Update transfer client and cache related code
1 parent 13f606f commit 4499ee7

File tree

12 files changed

+94
-85
lines changed

12 files changed

+94
-85
lines changed

rust/stackable-cockpit/src/common/list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ where
4949

5050
for file in files {
5151
let specs = transfer_client
52-
.get(file, &Yaml::<L>::new())
52+
.get(file, &Yaml::<L>::default())
5353
.await
5454
.context(FileTransferSnafu)?;
5555

rust/stackable-cockpit/src/platform/manifests.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ pub trait InstallManifestsExt {
9898
})?;
9999

100100
let helm_chart: helm::Chart = transfer_client
101-
.get(&helm_file, &Template::new(&parameters).then(Yaml::new()))
101+
.get(
102+
&helm_file,
103+
&Template::new(&parameters).then(Yaml::default()),
104+
)
102105
.await
103106
.context(FileTransferSnafu)?;
104107

rust/stackable-cockpit/src/xfer/processor.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ where
7878
}
7979
}
8080

81-
impl<T> Yaml<T> {
82-
pub fn new() -> Self {
81+
impl<T> Default for Yaml<T> {
82+
fn default() -> Self {
8383
Self(PhantomData)
8484
}
8585
}
@@ -99,8 +99,8 @@ where
9999
}
100100
}
101101

102-
impl<T> Json<T> {
103-
pub fn new() -> Self {
102+
impl<T> Default for Json<T> {
103+
fn default() -> Self {
104104
Self(PhantomData)
105105
}
106106
}

rust/stackablectl/src/cmds/cache.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use std::time::Duration;
1+
use std::{sync::Arc, time::Duration};
22

33
use clap::{Args, Subcommand};
44
use comfy_table::{ColumnConstraint, Table, Width, presets::UTF8_FULL};
55
use snafu::{ResultExt, Snafu};
6-
use stackable_cockpit::xfer::cache::{self, Cache, DeleteFilter};
6+
use stackable_cockpit::xfer::{self, cache::DeleteFilter};
77
use tracing::{info, instrument};
88

99
use crate::cli::Cli;
@@ -35,26 +35,29 @@ pub struct CacheCleanArgs {
3535
#[derive(Debug, Snafu)]
3636
pub enum CmdError {
3737
#[snafu(display("failed to list cached files"))]
38-
ListCachedFiles { source: cache::Error },
38+
ListCachedFiles { source: xfer::Error },
3939

4040
#[snafu(display("failed to purge cached files"))]
41-
PurgeCachedFiles { source: cache::Error },
41+
PurgeCachedFiles { source: xfer::Error },
4242
}
4343

4444
impl CacheArgs {
45-
pub async fn run(&self, cli: &Cli, cache: Cache) -> Result<String, CmdError> {
45+
pub async fn run(&self, transfer_client: Arc<xfer::Client>) -> Result<String, CmdError> {
4646
match &self.subcommand {
47-
CacheCommands::List => list_cmd(cache, cli).await,
48-
CacheCommands::Clean(args) => clean_cmd(args, cache).await,
47+
CacheCommands::List => list_cmd(transfer_client).await,
48+
CacheCommands::Clean(args) => clean_cmd(args, transfer_client).await,
4949
}
5050
}
5151
}
5252

5353
#[instrument(skip_all)]
54-
async fn list_cmd(cache: Cache, cli: &Cli) -> Result<String, CmdError> {
54+
async fn list_cmd(transfer_client: Arc<xfer::Client>) -> Result<String, CmdError> {
5555
info!("Listing cached files");
5656

57-
let files = cache.list().await.context(ListCachedFilesSnafu)?;
57+
let files = transfer_client
58+
.list_cached_files()
59+
.await
60+
.context(ListCachedFilesSnafu)?;
5861

5962
if files.is_empty() {
6063
return Ok("No cached files".into());
@@ -77,7 +80,7 @@ async fn list_cmd(cache: Cache, cli: &Cli) -> Result<String, CmdError> {
7780
table.add_row(vec![file_path, format!("{modified} seconds ago")]);
7881
}
7982

80-
let mut result = cli.result();
83+
let mut result = Cli::result();
8184

8285
result
8386
.with_command_hint("stackablectl cache clean", "to clean all cached files")
@@ -87,7 +90,10 @@ async fn list_cmd(cache: Cache, cli: &Cli) -> Result<String, CmdError> {
8790
}
8891

8992
#[instrument(skip_all)]
90-
async fn clean_cmd(args: &CacheCleanArgs, cache: Cache) -> Result<String, CmdError> {
93+
async fn clean_cmd(
94+
args: &CacheCleanArgs,
95+
transfer_client: Arc<xfer::Client>,
96+
) -> Result<String, CmdError> {
9197
info!("Cleaning cached files");
9298

9399
let delete_filter = if args.only_remove_old_files {
@@ -96,8 +102,8 @@ async fn clean_cmd(args: &CacheCleanArgs, cache: Cache) -> Result<String, CmdErr
96102
DeleteFilter::All
97103
};
98104

99-
cache
100-
.purge(delete_filter)
105+
transfer_client
106+
.purge_cached_files(delete_filter)
101107
.await
102108
.context(PurgeCachedFilesSnafu)?;
103109

rust/stackablectl/src/cmds/debug.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ use tokio::{
2727
};
2828
use tracing::{Instrument, error, info, info_span, warn};
2929

30-
use crate::cli::Cli;
31-
3230
#[derive(Debug, Snafu)]
3331
pub enum CmdError {
3432
#[snafu(display("failed to create Kubernetes client"))]
@@ -136,7 +134,7 @@ pub struct DebugArgs {
136134
}
137135

138136
impl DebugArgs {
139-
pub async fn run(&self, _cli: &Cli) -> Result<String, CmdError> {
137+
pub async fn run(&self) -> Result<String, CmdError> {
140138
let kube = kube::Client::try_default()
141139
.await
142140
.context(KubeClientCreateSnafu)?;

rust/stackablectl/src/cmds/demo.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::sync::Arc;
2+
13
use clap::{Args, Subcommand};
24
use comfy_table::{
35
ContentArrangement, Row, Table,
@@ -16,7 +18,7 @@ use stackable_cockpit::{
1618
k8s::{self, Client},
1719
path::PathOrUrlParseError,
1820
},
19-
xfer::{self, cache::Cache},
21+
xfer,
2022
};
2123
use stackable_operator::kvp::{LabelError, Labels};
2224
use tracing::{Span, debug, info, instrument};
@@ -161,11 +163,13 @@ pub enum CmdError {
161163

162164
impl DemoArgs {
163165
#[instrument(skip_all, fields(with_cache = !cli.no_cache))]
164-
pub async fn run(&self, cli: &Cli, cache: Cache) -> Result<String, CmdError> {
166+
pub async fn run(
167+
&self,
168+
cli: &Cli,
169+
transfer_client: Arc<xfer::Client>,
170+
) -> Result<String, CmdError> {
165171
debug!("Handle demo args");
166172

167-
let transfer_client = xfer::Client::new_with(cache);
168-
169173
let release_files = cli.get_release_files().context(PathOrUrlParseSnafu)?;
170174
let release_list = release::ReleaseList::build(&release_files, &transfer_client)
171175
.await
@@ -201,8 +205,8 @@ impl DemoArgs {
201205
.context(BuildListSnafu)?;
202206

203207
match &self.subcommand {
204-
DemoCommands::List(args) => list_cmd(args, cli, list).await,
205-
DemoCommands::Describe(args) => describe_cmd(args, cli, list).await,
208+
DemoCommands::List(args) => list_cmd(args, list).await,
209+
DemoCommands::Describe(args) => describe_cmd(args, list).await,
206210
DemoCommands::Install(args) => {
207211
install_cmd(args, cli, list, &transfer_client, &release_branch).await
208212
}
@@ -212,7 +216,7 @@ impl DemoArgs {
212216

213217
/// Print out a list of demos, either as a table (plain), JSON or YAML
214218
#[instrument(skip_all, fields(indicatif.pb_show = true))]
215-
async fn list_cmd(args: &DemoListArgs, cli: &Cli, list: demo::List) -> Result<String, CmdError> {
219+
async fn list_cmd(args: &DemoListArgs, list: demo::List) -> Result<String, CmdError> {
216220
info!("Listing demos");
217221
Span::current().pb_set_message("Fetching demo information");
218222

@@ -239,7 +243,7 @@ async fn list_cmd(args: &DemoListArgs, cli: &Cli, list: demo::List) -> Result<St
239243
table.add_row(row);
240244
}
241245

242-
let mut result = cli.result();
246+
let mut result = Cli::result();
243247

244248
result
245249
.with_command_hint(
@@ -261,11 +265,7 @@ async fn list_cmd(args: &DemoListArgs, cli: &Cli, list: demo::List) -> Result<St
261265

262266
/// Describe a specific demo by printing out a table (plain), JSON or YAML
263267
#[instrument(skip_all, fields(indicatif.pb_show = true))]
264-
async fn describe_cmd(
265-
args: &DemoDescribeArgs,
266-
cli: &Cli,
267-
list: demo::List,
268-
) -> Result<String, CmdError> {
268+
async fn describe_cmd(args: &DemoDescribeArgs, list: demo::List) -> Result<String, CmdError> {
269269
info!(demo_name = %args.demo_name, "Describing demo");
270270
Span::current().pb_set_message("Fetching demo information");
271271

@@ -299,7 +299,7 @@ async fn describe_cmd(
299299

300300
// TODO (Techassi): Add parameter output
301301

302-
let mut result = cli.result();
302+
let mut result = Cli::result();
303303

304304
result
305305
.with_command_hint(
@@ -337,7 +337,7 @@ async fn install_cmd(
337337
Span::current().pb_set_message("Installing demo");
338338

339339
// Init result output and progress output
340-
let mut output = cli.result();
340+
let mut output = Cli::result();
341341

342342
let demo = list.get(&args.demo_name).ok_or(CmdError::NoSuchDemo {
343343
name: args.demo_name.clone(),

rust/stackablectl/src/cmds/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ pub mod operator;
66
pub mod release;
77
pub mod stack;
88
pub mod stacklet;
9+
pub mod version;

rust/stackablectl/src/cmds/operator.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ impl OperatorArgs {
183183
OperatorCommands::List(args) => list_cmd(args, cli).await,
184184
OperatorCommands::Describe(args) => describe_cmd(args, cli).await,
185185
OperatorCommands::Install(args) => install_cmd(args, cli).await,
186-
OperatorCommands::Uninstall(args) => uninstall_cmd(args, cli),
187-
OperatorCommands::Installed(args) => installed_cmd(args, cli),
186+
OperatorCommands::Uninstall(args) => uninstall_cmd(args),
187+
OperatorCommands::Installed(args) => installed_cmd(args),
188188
}
189189
}
190190
}
@@ -227,7 +227,7 @@ async fn list_cmd(args: &OperatorListArgs, cli: &Cli) -> Result<String, CmdError
227227
]);
228228
}
229229

230-
let mut result = cli.result();
230+
let mut result = Cli::result();
231231

232232
result
233233
.with_command_hint(
@@ -290,7 +290,7 @@ async fn describe_cmd(args: &OperatorDescribeArgs, cli: &Cli) -> Result<String,
290290
.add_row(vec!["TEST VERSIONS", test_versions_string.as_str()])
291291
.add_row(vec!["DEV VERSIONS", dev_versions_string.as_str()]);
292292

293-
let mut result = cli.result();
293+
let mut result = Cli::result();
294294

295295
result
296296
.with_command_hint(
@@ -340,7 +340,7 @@ async fn install_cmd(args: &OperatorInstallArgs, cli: &Cli) -> Result<String, Cm
340340
indicatif_println!("Installed {operator} operator");
341341
}
342342

343-
let mut result = cli.result();
343+
let mut result = Cli::result();
344344

345345
result
346346
.with_command_hint(
@@ -361,7 +361,7 @@ async fn install_cmd(args: &OperatorInstallArgs, cli: &Cli) -> Result<String, Cm
361361
}
362362

363363
#[instrument(skip_all, fields(indicatif.pb_show = true))]
364-
fn uninstall_cmd(args: &OperatorUninstallArgs, cli: &Cli) -> Result<String, CmdError> {
364+
fn uninstall_cmd(args: &OperatorUninstallArgs) -> Result<String, CmdError> {
365365
info!("Uninstalling operator(s)");
366366
Span::current().pb_set_message("Uninstalling operator(s)");
367367

@@ -371,7 +371,7 @@ fn uninstall_cmd(args: &OperatorUninstallArgs, cli: &Cli) -> Result<String, CmdE
371371
.context(HelmSnafu)?;
372372
}
373373

374-
let mut result = cli.result();
374+
let mut result = Cli::result();
375375

376376
result
377377
.with_command_hint(
@@ -392,7 +392,7 @@ fn uninstall_cmd(args: &OperatorUninstallArgs, cli: &Cli) -> Result<String, CmdE
392392
}
393393

394394
#[instrument(skip_all, fields(indicatif.pb_show = true))]
395-
fn installed_cmd(args: &OperatorInstalledArgs, cli: &Cli) -> Result<String, CmdError> {
395+
fn installed_cmd(args: &OperatorInstalledArgs) -> Result<String, CmdError> {
396396
info!("Listing installed operators");
397397
Span::current().pb_set_message("Fetching operator information");
398398

@@ -443,7 +443,7 @@ fn installed_cmd(args: &OperatorInstalledArgs, cli: &Cli) -> Result<String, CmdE
443443
]);
444444
}
445445

446-
let mut result = cli.result();
446+
let mut result = Cli::result();
447447

448448
result
449449
.with_command_hint(

0 commit comments

Comments
 (0)