mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 16:57:49 +03:00
add fb303 thrift server
Summary: This commit adds a basic thrift server that responds to fb303 status check queries to Mononoke API Server. Reviewed By: farnz Differential Revision: D9092291 fbshipit-source-id: d1e4ddb280c252f549d40a0bb03d05afccbf73b8
This commit is contained in:
parent
c1b1005d91
commit
0fcfbda8b1
10
apiserver/if/apiserver.thrift
Normal file
10
apiserver/if/apiserver.thrift
Normal file
@ -0,0 +1,10 @@
|
||||
include "common/fb303/if/fb303.thrift"
|
||||
|
||||
struct MononokeGetRawParams {
|
||||
1: string changeset,
|
||||
2: string path,
|
||||
}
|
||||
|
||||
service MononokeAPIService extends fb303.FacebookService {
|
||||
binary get_raw(1: MononokeGetRawParams params),
|
||||
}
|
@ -9,16 +9,19 @@
|
||||
|
||||
extern crate actix;
|
||||
extern crate actix_web;
|
||||
extern crate apiserver_thrift;
|
||||
extern crate blobrepo;
|
||||
extern crate bookmarks;
|
||||
extern crate bytes;
|
||||
extern crate cachelib;
|
||||
extern crate chrono;
|
||||
#[macro_use]
|
||||
extern crate clap;
|
||||
#[macro_use]
|
||||
extern crate cloned;
|
||||
extern crate cmdlib;
|
||||
extern crate failure_ext as failure;
|
||||
extern crate fb303;
|
||||
extern crate futures;
|
||||
extern crate futures_ext;
|
||||
extern crate mercurial_types;
|
||||
@ -28,6 +31,7 @@ extern crate mononoke_types;
|
||||
extern crate panichandler;
|
||||
extern crate percent_encoding;
|
||||
extern crate reachabilityindex;
|
||||
extern crate rust_thrift;
|
||||
extern crate scuba_ext;
|
||||
extern crate secure_utils;
|
||||
extern crate serde;
|
||||
@ -42,13 +46,16 @@ extern crate slog_scope;
|
||||
extern crate slog_stats;
|
||||
extern crate slog_stdlog;
|
||||
extern crate slog_term;
|
||||
extern crate srserver;
|
||||
extern crate time_ext;
|
||||
extern crate tokio;
|
||||
extern crate tokio_threadpool;
|
||||
|
||||
mod actor;
|
||||
mod errors;
|
||||
mod from_string;
|
||||
mod middleware;
|
||||
mod thrift;
|
||||
|
||||
use std::path::Path;
|
||||
use std::str::FromStr;
|
||||
@ -258,6 +265,12 @@ fn main() -> Result<()> {
|
||||
.default_value("8000")
|
||||
.help("HTTP port to listen to"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("thrift-port")
|
||||
.long("thrift-port")
|
||||
.value_name("PORT")
|
||||
.help("Thrift port"),
|
||||
)
|
||||
.arg(Arg::with_name("with-scuba").long("with-scuba"))
|
||||
.arg(Arg::with_name("debug").short("p").long("debug"))
|
||||
.arg(
|
||||
@ -306,11 +319,11 @@ fn main() -> Result<()> {
|
||||
.help("path to the ssl ca file"),
|
||||
),
|
||||
).get_matches();
|
||||
|
||||
cmdlib::args::init_cachelib(&matches);
|
||||
|
||||
let host = matches.value_of("http-host").unwrap_or("127.0.0.1");
|
||||
let port = matches.value_of("http-port").unwrap_or("8000");
|
||||
let thrift_port = value_t!(matches.value_of("thrift-port"), i32);
|
||||
let debug = matches.is_present("debug");
|
||||
let stdlog = matches.is_present("stdlog");
|
||||
let config_path = matches
|
||||
@ -323,6 +336,7 @@ fn main() -> Result<()> {
|
||||
let root_logger = setup_logger(debug);
|
||||
let actix_logger = root_logger.clone();
|
||||
let mononoke_logger = root_logger.clone();
|
||||
let thrift_logger = root_logger.clone();
|
||||
|
||||
// These guards have to be placed in main or they would be destoried once the function ends
|
||||
let global_logger = root_logger.clone();
|
||||
@ -368,6 +382,11 @@ fn main() -> Result<()> {
|
||||
let use_ssl = ssl_acceptor.is_some();
|
||||
let sys = actix::System::new("mononoke-apiserver");
|
||||
let executor = runtime.executor();
|
||||
|
||||
if let Ok(port) = thrift_port {
|
||||
thrift::make_thrift(thrift_logger, host.to_string(), port)?;
|
||||
}
|
||||
|
||||
let addr = MononokeActor::create(move |_| {
|
||||
MononokeActor::new(mononoke_logger.clone(), repo_configs, executor)
|
||||
});
|
||||
|
39
apiserver/src/thrift/dispatcher.rs
Normal file
39
apiserver/src/thrift/dispatcher.rs
Normal file
@ -0,0 +1,39 @@
|
||||
// Copyright (c) 2018-present, Facebook, Inc.
|
||||
// All Rights Reserved.
|
||||
//
|
||||
// This software may be used and distributed according to the terms of the
|
||||
// GNU General Public License version 2 or any later version.
|
||||
|
||||
use actix::{Addr, Arbiter};
|
||||
use actix::msgs::Execute;
|
||||
use futures::Future;
|
||||
|
||||
use srserver::{ThriftExecutor, ThriftServer};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ThriftDispatcher(pub Addr<Arbiter>);
|
||||
|
||||
impl ThriftDispatcher {
|
||||
pub fn start<F: FnOnce(Self) -> ThriftServer + Send + 'static>(self, thrift: F) {
|
||||
let arbiter = Arbiter::new("thrift-server");
|
||||
|
||||
arbiter.do_send::<Execute>(Execute::new(move || {
|
||||
let mut thrift = thrift(self);
|
||||
|
||||
thrift
|
||||
.serve()
|
||||
.map_err(|e| eprintln!("Failed to start serve(): {}", e))
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
impl ThriftExecutor for ThriftDispatcher {
|
||||
fn spawn<F>(&self, future: F)
|
||||
where
|
||||
F: Future<Item = (), Error = ()> + Send + 'static,
|
||||
{
|
||||
self.0.do_send(Execute::new(move || -> Result<(), ()> {
|
||||
Ok(Arbiter::spawn(future))
|
||||
}));
|
||||
}
|
||||
}
|
25
apiserver/src/thrift/fb303.rs
Normal file
25
apiserver/src/thrift/fb303.rs
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright (c) 2018-present, Facebook, Inc.
|
||||
// All Rights Reserved.
|
||||
//
|
||||
// This software may be used and distributed according to the terms of the
|
||||
// GNU General Public License version 2 or any later version.
|
||||
|
||||
use futures::IntoFuture;
|
||||
use futures_ext::{BoxFuture, FutureExt};
|
||||
|
||||
use fb303::fb_status;
|
||||
use fb303::server::FacebookService;
|
||||
use fb303::services::facebook_service::{GetNameExn, GetStatusExn};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct FacebookServiceImpl {}
|
||||
|
||||
impl FacebookService for FacebookServiceImpl {
|
||||
fn getName(&self) -> BoxFuture<String, GetNameExn> {
|
||||
Ok("Mononoke API Server".to_string()).into_future().boxify()
|
||||
}
|
||||
|
||||
fn getStatus(&self) -> BoxFuture<fb_status, GetStatusExn> {
|
||||
Ok(fb_status::ALIVE).into_future().boxify()
|
||||
}
|
||||
}
|
44
apiserver/src/thrift/mod.rs
Normal file
44
apiserver/src/thrift/mod.rs
Normal file
@ -0,0 +1,44 @@
|
||||
// Copyright (c) 2018-present, Facebook, Inc.
|
||||
// All Rights Reserved.
|
||||
//
|
||||
// This software may be used and distributed according to the terms of the
|
||||
// GNU General Public License version 2 or any later version.
|
||||
|
||||
mod dispatcher;
|
||||
mod fb303;
|
||||
mod mononoke;
|
||||
|
||||
use actix::Arbiter;
|
||||
use failure::Error;
|
||||
use slog::Logger;
|
||||
|
||||
use apiserver_thrift::server::make_MononokeAPIService_server;
|
||||
use fb303::server::make_FacebookService_server;
|
||||
use srserver::ThriftServerBuilder;
|
||||
|
||||
use self::dispatcher::ThriftDispatcher;
|
||||
use self::fb303::FacebookServiceImpl;
|
||||
use self::mononoke::MononokeAPIServiceImpl;
|
||||
|
||||
pub fn make_thrift(logger: Logger, host: String, port: i32) -> Result<(), Error> {
|
||||
let dispatcher = ThriftDispatcher(Arbiter::new("thrift-worker"));
|
||||
|
||||
dispatcher.start(move |dispatcher| {
|
||||
info!(logger, "Starting thrift service at {}:{}", host, port);
|
||||
ThriftServerBuilder::new()
|
||||
.with_address(&host, port, false)
|
||||
.expect(&format!("cannot bind to {}:{}", host, port))
|
||||
.with_tls()
|
||||
.expect("cannot bind to tls")
|
||||
.with_factory(dispatcher, move || {
|
||||
move |proto| {
|
||||
make_MononokeAPIService_server(proto, MononokeAPIServiceImpl {}, |proto| {
|
||||
make_FacebookService_server(proto, FacebookServiceImpl {})
|
||||
})
|
||||
}
|
||||
})
|
||||
.build()
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
11
apiserver/src/thrift/mononoke.rs
Normal file
11
apiserver/src/thrift/mononoke.rs
Normal file
@ -0,0 +1,11 @@
|
||||
// Copyright (c) 2018-present, Facebook, Inc.
|
||||
// All Rights Reserved.
|
||||
//
|
||||
// This software may be used and distributed according to the terms of the
|
||||
// GNU General Public License version 2 or any later version.
|
||||
|
||||
use apiserver_thrift::server::MononokeApiservice;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct MononokeAPIServiceImpl {}
|
||||
impl MononokeApiservice for MononokeAPIServiceImpl {}
|
Loading…
Reference in New Issue
Block a user