这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 98 additions & 12 deletions bayard-cli/src/cli/subcommand.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::net::ToSocketAddrs;

use clap::ArgMatches;
use serde_json::Value;

Expand All @@ -8,7 +10,14 @@ pub fn leave(matches: &ArgMatches) -> Result<(), std::io::Error> {
let server = matches.value_of("SERVER").unwrap();
let id = matches.value_of("ID").unwrap().parse::<u64>().unwrap();

let mut raft_client = RaftClient::new(server);
let server = server
.to_socket_addrs()
.unwrap()
.next()
.unwrap()
.to_string();

let mut raft_client = RaftClient::new(server.as_str());

match raft_client.leave(id) {
Ok(v) => {
Expand All @@ -25,7 +34,14 @@ pub fn leave(matches: &ArgMatches) -> Result<(), std::io::Error> {
pub fn status(matches: &ArgMatches) -> Result<(), std::io::Error> {
let server = matches.value_of("SERVER").unwrap();

let mut index_client = IndexClient::new(server);
let server = server
.to_socket_addrs()
.unwrap()
.next()
.unwrap()
.to_string();

let mut index_client = IndexClient::new(server.as_str());

match index_client.status() {
Ok(v) => {
Expand All @@ -42,7 +58,14 @@ pub fn status(matches: &ArgMatches) -> Result<(), std::io::Error> {
pub fn schema(matches: &ArgMatches) -> Result<(), std::io::Error> {
let server = matches.value_of("SERVER").unwrap();

let mut index_client = IndexClient::new(server);
let server = server
.to_socket_addrs()
.unwrap()
.next()
.unwrap()
.to_string();

let mut index_client = IndexClient::new(server.as_str());

match index_client.schema() {
Ok(v) => {
Expand All @@ -60,7 +83,14 @@ pub fn get(matches: &ArgMatches) -> Result<(), std::io::Error> {
let server = matches.value_of("SERVER").unwrap();
let id = matches.value_of("ID").unwrap();

let mut index_client = IndexClient::new(server);
let server = server
.to_socket_addrs()
.unwrap()
.next()
.unwrap()
.to_string();

let mut index_client = IndexClient::new(server.as_str());

match index_client.get(id.to_string()) {
Ok(v) => {
Expand Down Expand Up @@ -89,7 +119,14 @@ pub fn search(matches: &ArgMatches) -> Result<(), std::io::Error> {
}
let query = matches.value_of("QUERY").unwrap();

let mut index_client = IndexClient::new(server);
let server = server
.to_socket_addrs()
.unwrap()
.next()
.unwrap()
.to_string();

let mut index_client = IndexClient::new(server.as_str());

match index_client.search(
query,
Expand Down Expand Up @@ -120,7 +157,14 @@ pub fn set(matches: &ArgMatches) -> Result<(), std::io::Error> {
doc_json["_id"] = Value::String(id.to_string());
let doc = serde_json::to_string(&doc_json).unwrap();

let mut index_client = IndexClient::new(server);
let server = server
.to_socket_addrs()
.unwrap()
.next()
.unwrap()
.to_string();

let mut index_client = IndexClient::new(server.as_str());

index_client.set(doc)
}
Expand All @@ -129,7 +173,14 @@ pub fn delete(matches: &ArgMatches) -> Result<(), std::io::Error> {
let server = matches.value_of("SERVER").unwrap();
let id = matches.value_of("ID").unwrap();

let mut index_client = IndexClient::new(server);
let server = server
.to_socket_addrs()
.unwrap()
.next()
.unwrap()
.to_string();

let mut index_client = IndexClient::new(server.as_str());

index_client.delete(id.to_string())
}
Expand All @@ -138,7 +189,14 @@ pub fn bulk_set(matches: &ArgMatches) -> Result<(), std::io::Error> {
let server = matches.value_of("SERVER").unwrap();
let docs = matches.value_of("DOCS").unwrap();

let mut index_client = IndexClient::new(server);
let server = server
.to_socket_addrs()
.unwrap()
.next()
.unwrap()
.to_string();

let mut index_client = IndexClient::new(server.as_str());

index_client.bulk_set(docs.to_string())
}
Expand All @@ -147,31 +205,59 @@ pub fn bulk_delete(matches: &ArgMatches) -> Result<(), std::io::Error> {
let server = matches.value_of("SERVER").unwrap();
let docs = matches.value_of("DOCS").unwrap();

let mut index_client = IndexClient::new(server);
let server = server
.to_socket_addrs()
.unwrap()
.next()
.unwrap()
.to_string();

let mut index_client = IndexClient::new(server.as_str());

index_client.bulk_delete(docs.to_string())
}

pub fn commit(matches: &ArgMatches) -> Result<(), std::io::Error> {
let server = matches.value_of("SERVER").unwrap();

let mut index_client = IndexClient::new(server);
let server = server
.to_socket_addrs()
.unwrap()
.next()
.unwrap()
.to_string();

let mut index_client = IndexClient::new(server.as_str());

index_client.commit()
}

pub fn rollback(matches: &ArgMatches) -> Result<(), std::io::Error> {
let server = matches.value_of("SERVER").unwrap();

let mut index_client = IndexClient::new(server);
let server = server
.to_socket_addrs()
.unwrap()
.next()
.unwrap()
.to_string();

let mut index_client = IndexClient::new(server.as_str());

index_client.rollback()
}

pub fn merge(matches: &ArgMatches) -> Result<(), std::io::Error> {
let server = matches.value_of("SERVER").unwrap();

let mut index_client = IndexClient::new(server);
let server = server
.to_socket_addrs()
.unwrap()
.next()
.unwrap()
.to_string();

let mut index_client = IndexClient::new(server.as_str());

index_client.merge()
}
8 changes: 4 additions & 4 deletions bayard/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
.to_string();

let node_address = NodeAddress {
index_address,
raft_address,
index_address: index_address.clone(),
raft_address: raft_address.clone(),
};

let mut addresses = HashMap::new();
Expand Down Expand Up @@ -233,12 +233,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {

let mut index_server = ServerBuilder::new(env_index)
.register_service(index_service)
.bind(host, index_port)
.bind(index_address.split(":").next().unwrap(), index_port)
.build()
.unwrap();
let mut raft_server = ServerBuilder::new(env_raft)
.register_service(raft_service)
.bind(host, raft_port)
.bind(raft_address.split(":").next().unwrap(), raft_port)
.build()
.unwrap();

Expand Down