-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit add the xline client with placeholders, currently no client function is implemented.
- Loading branch information
Showing
15 changed files
with
763 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[workspace] | ||
|
||
members = ["xline", "curp", "benchmark", "utils", "engine", "xlineapi"] | ||
members = ["xline", "curp", "benchmark", "utils", "engine", "xlineapi", "xline-client"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
[package] | ||
name = "xline-client" | ||
version = "0.1.0" | ||
edition = "2021" | ||
authors = ["DatenLord <dev@datenlord.io>"] | ||
description = "Client for Xline" | ||
license = "Apache-2.0" | ||
readme = "README.md" | ||
repository = "https://github.com/datenlord/Xline/tree/master/xline-client" | ||
categories = ["Client"] | ||
keywords = ["Client", "Xline", "RPC"] | ||
|
||
[dependencies] | ||
curp = { path = "../curp" } | ||
xline = { path = "../xline" } | ||
utils = { path = "../utils", features = ["parking_lot"] } | ||
xlineapi = { path = "../xlineapi" } | ||
tonic = "0.7.2" | ||
itertools = "0.10.3" | ||
uuid = { version = "1.1.2", features = ["v4"] } | ||
thiserror = "1.0.37" | ||
tower = { version = "0.4", features = ["discover"] } | ||
tokio = { version = "1.0", features = ["sync"] } | ||
futures = "0.3.25" | ||
clippy-utilities = "0.1.0" | ||
async-stream = "0.3.5" | ||
pbkdf2 = { version = "0.11.0", features = ["std"] } | ||
http = "0.2.9" | ||
|
||
[dev-dependencies] | ||
rand = "0.8.5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Xline Client | ||
|
||
This crate provides a client for Xline server. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// TODO: Remove these when the placeholder is implemented. | ||
#![allow(dead_code)] | ||
|
||
use std::sync::Arc; | ||
|
||
use curp::client::Client as CurpClient; | ||
use tonic::transport::Channel; | ||
use xline::server::Command; | ||
|
||
use crate::AuthService; | ||
|
||
/// Client for Auth operations. | ||
#[derive(Clone, Debug)] | ||
pub struct AuthClient { | ||
/// Name of the AuthClient | ||
name: String, | ||
/// The inner CURP client | ||
curp_client: Arc<CurpClient<Command>>, | ||
/// The standalone client | ||
standalone_client: xlineapi::AuthClient<AuthService<Channel>>, | ||
/// Auth token | ||
token: Option<String>, | ||
} | ||
|
||
impl AuthClient { | ||
/// New `AuthClient` | ||
#[inline] | ||
pub fn new( | ||
name: String, | ||
curp_client: Arc<CurpClient<Command>>, | ||
channel: Channel, | ||
token: Option<String>, | ||
) -> Self { | ||
Self { | ||
name, | ||
curp_client, | ||
standalone_client: xlineapi::AuthClient::new(AuthService::new( | ||
channel, | ||
token.as_ref().and_then(|t| t.parse().ok().map(Arc::new)), | ||
)), | ||
token, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// TODO: Remove these when the placeholder is implemented. | ||
#![allow(missing_copy_implementations)] | ||
#![allow(clippy::new_without_default)] | ||
|
||
/// The cluster client | ||
#[derive(Clone, Debug)] | ||
#[non_exhaustive] | ||
pub struct ClusterClient; | ||
|
||
impl ClusterClient { | ||
/// Create a new cluster client | ||
#[inline] | ||
#[must_use] | ||
pub fn new() -> Self { | ||
Self | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// TODO: Remove these when the placeholder is implemented. | ||
#![allow(missing_copy_implementations)] | ||
#![allow(clippy::new_without_default)] | ||
|
||
/// The election client | ||
#[derive(Clone, Debug)] | ||
#[non_exhaustive] | ||
pub struct ElectionClient; | ||
|
||
impl ElectionClient { | ||
/// Create a new election client | ||
#[inline] | ||
#[must_use] | ||
pub fn new() -> Self { | ||
Self | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// TODO: Remove these when the placeholder is implemented. | ||
#![allow(dead_code)] | ||
|
||
use std::sync::Arc; | ||
|
||
use curp::client::Client as CurpClient; | ||
use xline::server::Command; | ||
|
||
/// Client for KV operations. | ||
#[derive(Clone, Debug)] | ||
pub struct KvClient { | ||
/// Name of the KvClient | ||
name: String, | ||
/// The inner CURP client | ||
curp_client: Arc<CurpClient<Command>>, | ||
/// Auth token | ||
token: Option<String>, | ||
} | ||
|
||
impl KvClient { | ||
/// New `KvClient` | ||
#[inline] | ||
pub fn new(name: String, curp_client: Arc<CurpClient<Command>>, token: Option<String>) -> Self { | ||
Self { | ||
name, | ||
curp_client, | ||
token, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// TODO: Remove these when the placeholder is implemented. | ||
#![allow(dead_code)] | ||
|
||
use std::sync::Arc; | ||
|
||
use curp::client::Client as CurpClient; | ||
use tonic::transport::Channel; | ||
use xline::server::Command; | ||
|
||
use crate::AuthService; | ||
|
||
/// Client for Lease operations. | ||
#[derive(Clone, Debug)] | ||
pub struct LeaseClient { | ||
/// Name of the LeaseClient | ||
name: String, | ||
/// The CURP client | ||
curp_client: Arc<CurpClient<Command>>, | ||
/// The standalone client | ||
standalone_client: xlineapi::LeaseClient<AuthService<Channel>>, | ||
/// Auth token | ||
token: Option<String>, | ||
} | ||
|
||
impl LeaseClient { | ||
/// New `LeaseClient` | ||
#[inline] | ||
pub fn new( | ||
name: String, | ||
curp_client: Arc<CurpClient<Command>>, | ||
channel: Channel, | ||
token: Option<String>, | ||
) -> Self { | ||
Self { | ||
name, | ||
curp_client, | ||
standalone_client: xlineapi::LeaseClient::new(AuthService::new( | ||
channel, | ||
token.as_ref().and_then(|t| t.parse().ok().map(Arc::new)), | ||
)), | ||
token, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// TODO: Remove these when the placeholder is implemented. | ||
#![allow(dead_code)] | ||
|
||
use std::sync::Arc; | ||
|
||
use curp::client::Client as CurpClient; | ||
use tonic::transport::Channel; | ||
use xline::server::Command; | ||
|
||
use crate::clients::watch::WatchClient; | ||
|
||
/// Client for Lock operations. | ||
#[derive(Clone, Debug)] | ||
pub struct LockClient { | ||
/// Name of the LockClient | ||
name: String, | ||
/// The inner CURP client | ||
curp_client: Arc<CurpClient<Command>>, | ||
/// The watch client | ||
watch_client: WatchClient, | ||
/// Auth token | ||
token: Option<String>, | ||
} | ||
|
||
impl LockClient { | ||
/// New `LockClient` | ||
#[inline] | ||
pub fn new( | ||
name: String, | ||
curp_client: Arc<CurpClient<Command>>, | ||
channel: Channel, | ||
token: Option<String>, | ||
) -> Self { | ||
Self { | ||
name, | ||
curp_client, | ||
watch_client: WatchClient::new(channel, token.clone()), | ||
token, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// TODO: Remove these when the placeholder is implemented. | ||
#![allow(dead_code)] | ||
|
||
use std::{fmt::Debug, sync::Arc}; | ||
|
||
use tonic::transport::Channel; | ||
|
||
use crate::AuthService; | ||
|
||
/// The maintenance client | ||
#[derive(Clone, Debug)] | ||
pub struct MaintenanceClient { | ||
/// the inner RPC client | ||
inner: xlineapi::MaintenanceClient<AuthService<Channel>>, | ||
} | ||
|
||
impl MaintenanceClient { | ||
/// Create a new maintenance client | ||
#[inline] | ||
#[must_use] | ||
pub fn new(channel: Channel, token: Option<String>) -> Self { | ||
Self { | ||
inner: xlineapi::MaintenanceClient::new(AuthService::new( | ||
channel, | ||
token.and_then(|t| t.parse().ok().map(Arc::new)), | ||
)), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/// Auth client. | ||
pub mod auth; | ||
/// Cluster client | ||
pub mod cluster; | ||
/// Election client. | ||
pub mod election; | ||
/// Kv client. | ||
pub mod kv; | ||
/// Lease client. | ||
pub mod lease; | ||
/// Lock client. | ||
pub mod lock; | ||
/// Maintenance client. | ||
pub mod maintenance; | ||
/// Watch client. | ||
pub mod watch; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// TODO: Remove these when the placeholder is implemented. | ||
#![allow(dead_code)] | ||
|
||
use std::{fmt::Debug, sync::Arc}; | ||
|
||
use tonic::transport::Channel; | ||
|
||
use crate::AuthService; | ||
|
||
/// The maintenance client | ||
#[derive(Clone, Debug)] | ||
pub struct WatchClient { | ||
/// The inner RPC client | ||
inner: xlineapi::WatchClient<AuthService<Channel>>, | ||
} | ||
|
||
impl WatchClient { | ||
/// Create a new maintenance client | ||
#[inline] | ||
#[must_use] | ||
pub fn new(channel: Channel, token: Option<String>) -> Self { | ||
Self { | ||
inner: xlineapi::WatchClient::new(AuthService::new( | ||
channel, | ||
token.and_then(|t| t.parse().ok().map(Arc::new)), | ||
)), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use thiserror::Error; | ||
|
||
/// Xline client result | ||
pub type Result<T> = std::result::Result<T, ClientError>; | ||
|
||
/// Client Error | ||
#[derive(Error, Debug)] | ||
#[non_exhaustive] | ||
pub enum ClientError { | ||
/// Propose error | ||
#[error("propose error {0}")] | ||
ProposeError(#[from] curp::error::ProposeError), | ||
/// IO error | ||
#[error("IO error {0}")] | ||
IoError(#[from] std::io::Error), | ||
/// Rpc Error | ||
#[error("rpc error: {0}")] | ||
RpcError(String), | ||
/// Arguments invalid Error | ||
#[error("Invalid arguments: {0}")] | ||
InvalidArgs(String), | ||
/// error in watch client | ||
#[error("Watch client error: {0}")] | ||
WatchError(String), | ||
/// error in lease client | ||
#[error("Lease client error: {0}")] | ||
LeaseError(String), | ||
} | ||
|
||
impl From<tonic::transport::Error> for ClientError { | ||
#[inline] | ||
fn from(e: tonic::transport::Error) -> Self { | ||
Self::RpcError(e.to_string()) | ||
} | ||
} | ||
|
||
impl From<tonic::Status> for ClientError { | ||
#[inline] | ||
fn from(e: tonic::Status) -> Self { | ||
Self::RpcError(e.to_string()) | ||
} | ||
} |
Oops, something went wrong.