feat: add dfcache command for d7y (#517)
Signed-off-by: Gaius <gaius.qi@gmail.com>
This commit is contained in:
parent
ffe991a8d6
commit
31e33aec29
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Copyright 2024 The Dragonfly Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
// NAME is the name of dfcache.
|
||||
pub const NAME: &str = "dfcache";
|
||||
|
||||
// default_dfcache_log_dir is the default log directory for dfcache.
|
||||
pub fn default_dfcache_log_dir() -> PathBuf {
|
||||
crate::default_log_dir().join(NAME)
|
||||
}
|
||||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub mod dfcache;
|
||||
pub mod dfdaemon;
|
||||
pub mod dfget;
|
||||
pub mod dfinit;
|
||||
|
|
|
|||
|
|
@ -23,6 +23,10 @@ path = "src/bin/dfget/main.rs"
|
|||
name = "dfstore"
|
||||
path = "src/bin/dfstore/main.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "dfcache"
|
||||
path = "src/bin/dfcache/main.rs"
|
||||
|
||||
[dependencies]
|
||||
dragonfly-client-core.workspace = true
|
||||
dragonfly-client-config.workspace = true
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ COPY dragonfly-client-util/src ./dragonfly-client-util/src
|
|||
COPY dragonfly-client-init/Cargo.toml ./dragonfly-client-init/Cargo.toml
|
||||
COPY dragonfly-client-init/src ./dragonfly-client-init/src
|
||||
|
||||
RUN cargo build --release --verbose --bin dfget --bin dfdaemon --bin dfstore
|
||||
RUN cargo build --release --verbose --bin dfget --bin dfdaemon --bin dfstore --bin dfcache
|
||||
|
||||
FROM alpine:3.17 as health
|
||||
|
||||
|
|
@ -61,6 +61,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends wget curl \
|
|||
COPY --from=builder /app/client/target/release/dfget /usr/local/bin/dfget
|
||||
COPY --from=builder /app/client/target/release/dfdaemon /usr/local/bin/dfdaemon
|
||||
COPY --from=builder /app/client/target/release/dfstore /usr/local/bin/dfstore
|
||||
COPY --from=builder /app/client/target/release/dfcache /usr/local/bin/dfcache
|
||||
COPY --from=health /bin/grpc_health_probe /bin/grpc_health_probe
|
||||
COPY --from=pprof /go/bin/pprof /bin/pprof
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,144 @@
|
|||
/*
|
||||
* Copyright 2024 The Dragonfly Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use clap::{Parser, Subcommand};
|
||||
use dragonfly_client::tracing::init_tracing;
|
||||
use dragonfly_client_config::{dfcache, dfdaemon};
|
||||
use std::path::PathBuf;
|
||||
use tracing::Level;
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
#[command(
|
||||
name = dfcache::NAME,
|
||||
author,
|
||||
version,
|
||||
about = "dfcache is a cache command line based on P2P technology in Dragonfly.",
|
||||
long_about = "A cache command line based on P2P technology in Dragonfly that can import file and export file in P2P network, \
|
||||
and it can copy multiple replicas during import. P2P cache is effectively used for fast read and write cache."
|
||||
)]
|
||||
struct Args {
|
||||
#[arg(
|
||||
short = 'e',
|
||||
long = "endpoint",
|
||||
default_value_os_t = dfdaemon::default_download_unix_socket_path(),
|
||||
help = "Endpoint of dfdaemon's GRPC server"
|
||||
)]
|
||||
endpoint: PathBuf,
|
||||
|
||||
#[arg(
|
||||
short = 'l',
|
||||
long,
|
||||
default_value = "info",
|
||||
help = "Specify the logging level [trace, debug, info, warn, error]"
|
||||
)]
|
||||
log_level: Level,
|
||||
|
||||
#[arg(
|
||||
long,
|
||||
default_value_os_t = dfcache::default_dfcache_log_dir(),
|
||||
help = "Specify the log directory"
|
||||
)]
|
||||
log_dir: PathBuf,
|
||||
|
||||
#[arg(
|
||||
long,
|
||||
default_value_t = 6,
|
||||
help = "Specify the max number of log files"
|
||||
)]
|
||||
log_max_files: usize,
|
||||
|
||||
#[arg(
|
||||
long = "verbose",
|
||||
default_value_t = false,
|
||||
help = "Specify whether to print log"
|
||||
)]
|
||||
verbose: bool,
|
||||
|
||||
#[command(subcommand)]
|
||||
command: Command,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Subcommand)]
|
||||
#[command()]
|
||||
pub enum Command {
|
||||
#[command(
|
||||
name = "import",
|
||||
author,
|
||||
version,
|
||||
about = "Import a file into Dragonfly P2P network",
|
||||
long_about = "Import a local file into Dragonfly P2P network and copy multiple replicas during import. If import successfully, it will return a task ID."
|
||||
)]
|
||||
Import(ImportCommand),
|
||||
|
||||
#[command(
|
||||
name = "export",
|
||||
author,
|
||||
version,
|
||||
about = "Export a file from Dragonfly P2P network",
|
||||
long_about = "Export a file from Dragonfly P2P network by task ID. If export successfully, it will return the local file path."
|
||||
)]
|
||||
Export(ExportCommand),
|
||||
|
||||
#[command(
|
||||
name = "stat",
|
||||
author,
|
||||
version,
|
||||
about = "Stat a file in Dragonfly P2P network",
|
||||
long_about = "Stat a file in Dragonfly P2P network by task ID. If stat successfully, it will return the file information."
|
||||
)]
|
||||
Stat(StatCommand),
|
||||
|
||||
#[command(
|
||||
name = "rm",
|
||||
author,
|
||||
version,
|
||||
about = "Remove a file from Dragonfly P2P network",
|
||||
long_about = "Remove the P2P cache in Dragonfly P2P network by task ID."
|
||||
)]
|
||||
Remove(RemoveCommand),
|
||||
}
|
||||
|
||||
// ImportCommand is the subcommand of import.
|
||||
#[derive(Debug, Clone, Parser)]
|
||||
pub struct ImportCommand {}
|
||||
|
||||
// ExportCommand is the subcommand of export.
|
||||
#[derive(Debug, Clone, Parser)]
|
||||
pub struct ExportCommand {}
|
||||
|
||||
// StatCommand is the subcommand of stat.
|
||||
#[derive(Debug, Clone, Parser)]
|
||||
pub struct StatCommand {}
|
||||
|
||||
// RemoveCommand is the subcommand of remove.
|
||||
#[derive(Debug, Clone, Parser)]
|
||||
pub struct RemoveCommand {}
|
||||
|
||||
fn main() {
|
||||
// Parse command line arguments.
|
||||
let args = Args::parse();
|
||||
|
||||
// Initialize tracing.
|
||||
let _guards = init_tracing(
|
||||
dfcache::NAME,
|
||||
&args.log_dir,
|
||||
args.log_level,
|
||||
args.log_max_files,
|
||||
None,
|
||||
false,
|
||||
args.verbose,
|
||||
);
|
||||
}
|
||||
Loading…
Reference in New Issue