Skip to content

Commit

Permalink
Implement serving scheduler.wasm and query.wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
tailhook committed Jul 9, 2018
1 parent 1fd32ec commit fd746b3
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Verwalter 0.13.0
``Content-Type: application/json``
* feature: add support for ``query.wasm`` which might be used for
overriding rendered roles and for custom queries
* feature: you can fetch current scheduler (and query) via API
``/v1/wasm/scheduler.wasm`` (only wasm scheduler though)


.. _changelog-0.12.1:
Expand Down
20 changes: 20 additions & 0 deletions src/daemon/frontend/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ lazy_static! {
.no_encodings() // always encoded
.content_type(false) // we replace content type
.done();
static ref WASM: Arc<Config> = Config::new()
.no_encodings() // never encode, so never out of sync
.done();
}

type ResponseFuture<S> = Box<Future<Item=server::EncoderDone<S>,
Expand Down Expand Up @@ -304,3 +307,20 @@ pub fn serve_backup<S>(name: String, head: &server::Head, schedule_dir: &Path)
kind: Kind::Backup,
}) as Request<S>)
}

pub fn serve_wasm<S>(head: &server::Head, file: PathBuf)
-> Result<Request<S>, server::Error>
where S: AsyncWrite + Send + 'static
{
let inp = Input::from_headers(&*CONFIG, head.method(), head.headers());
let fut = POOL.spawn_fn(move || {
inp.probe_file(&file).map_err(|e| {
error!("Error reading wasm {:?}: {}", file, e);
Status::InternalServerError
})
});
Ok(Box::new(Codec {
fut: Some(fut),
kind: Kind::Backup,
}) as Request<S>)
}
10 changes: 10 additions & 0 deletions src/daemon/frontend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ impl<S: AsyncWrite + Send + 'static> DispatcherTrait<S> for Dispatcher {
Log(ref route) => {
log::serve(headers, &self.state, route)
}
WasmScheduler => {
let path = self.state.options.config_dir
.join("scheduler/v1/scheduler.wasm");
disk::serve_wasm(headers, path)
}
WasmQuery => {
let path = self.state.options.config_dir
.join("scheduler/v1/query.wasm");
disk::serve_wasm(headers, path)
}
NotFound => {
serve_error_page(Status::NotFound)
}
Expand Down
4 changes: 4 additions & 0 deletions src/daemon/frontend/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ pub enum Route {
AlterStatic(String),
Api(ApiRoute, Format),
Log(LogRoute),
WasmScheduler,
WasmQuery,
NotFound,
BadContentType,
}
Expand Down Expand Up @@ -162,6 +164,8 @@ fn parse_api(path: &str, content_type: Option<&[u8]>) -> Option<Route> {
}
("query", _) => Some(Route::BadContentType),
("log", tail) => parse_log_route(tail).map(Log),
("wasm", "scheduler.wasm") => Some(Route::WasmScheduler),
("wasm", "query.wasm") => Some(Route::WasmQuery),
_ => None,
}
}
Expand Down

0 comments on commit fd746b3

Please sign in to comment.