-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from adpllc/dev
feat: support station busyout/release toggling via extension
- Loading branch information
Showing
7 changed files
with
173 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,13 +1,14 @@ | ||
[package] | ||
name = "angelsharkd" | ||
version = "0.2.1" | ||
version = "0.2.2" | ||
edition = "2021" | ||
authors = ["Adam T. Carpenter <[email protected]>"] | ||
description = "A HTTP interface into one or more Communication Managers" | ||
|
||
[features] | ||
simple_search = [] | ||
simple_deprov = [] | ||
simple_busy = [] | ||
|
||
[dependencies.libangelshark] | ||
path = "../libangelshark" | ||
|
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
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,50 @@ | ||
# Daemon Extension `simple_busy` | ||
|
||
This extension implements simple extension busyout and release toggling. | ||
|
||
## Getting Started | ||
|
||
To enable this feature, compile `angelsharkd` with the `simple_busy` flag: | ||
|
||
```sh | ||
cargo build --bin angelsharkd --features simple_busy ... | ||
``` | ||
|
||
## `POST /extensions/service/busyout` Busy-out a station | ||
|
||
The request consists of one or more entries including the ACM and extension to | ||
be operated on. | ||
|
||
```json | ||
POST /extensions/service/toggle | ||
[ | ||
{ | ||
"acm": "01", | ||
"ext": "17571230000" | ||
} | ||
] | ||
``` | ||
|
||
The response is a typical `angelsharkd` OSSI reponse. | ||
|
||
```json | ||
[ | ||
{ | ||
"acm": "01", | ||
"command": "busyout station 17571230000", | ||
"error": "", | ||
"fields": ["0001ff00", "0002ff00", "0005ff00", "0003ff00", "0004ff00"], | ||
"datas": [["S075157", "DIG-IP-S", "17571230000", "ABORT", "1010"]] | ||
} | ||
] | ||
``` | ||
|
||
## `POST /extensions/service/release` Release a station | ||
|
||
This endpoint works identically to the busyout endpoint, but the response will | ||
indicate whether the station was released. | ||
|
||
## `POST /extensions/service/toggle` Busyout and then immediately release a station | ||
|
||
This endpoint runs two OSSI commands for busyout-ing and releasing the given | ||
stations, respectively. |
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,98 @@ | ||
use crate::routes::dtos::{Error, Response}; | ||
use libangelshark::{AcmRunner, Message, ParallelIterator}; | ||
use log::error; | ||
use serde::Deserialize; | ||
use warp::{ | ||
body::{content_length_limit, json}, | ||
hyper::StatusCode, | ||
path, post, reply, Filter, Rejection, Reply, | ||
}; | ||
|
||
const SIXTEEN_K: u64 = 1024 * 16; | ||
|
||
pub fn busy_filter( | ||
runner: AcmRunner, | ||
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { | ||
post() | ||
.and(path!("service" / "busyout" / ..)) | ||
.and(content_length_limit(SIXTEEN_K)) | ||
.and(json()) | ||
.map(move |entries| queue_and_run(entries, "busyout", runner.to_owned())) | ||
} | ||
|
||
pub fn release_filter( | ||
runner: AcmRunner, | ||
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { | ||
post() | ||
.and(path!("service" / "release" / ..)) | ||
.and(content_length_limit(SIXTEEN_K)) | ||
.and(json()) | ||
.map(move |entries| queue_and_run(entries, "release", runner.to_owned())) | ||
} | ||
|
||
pub fn toggle_filter( | ||
runner: AcmRunner, | ||
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { | ||
post() | ||
.and(path!("service" / "toggle" / ..)) | ||
.and(content_length_limit(SIXTEEN_K)) | ||
.and(json()) | ||
.map(move |entries| queue_and_run(entries, "toggle", runner.to_owned())) | ||
} | ||
|
||
fn queue_and_run(entries: Entries, command: &str, mut runner: AcmRunner) -> impl Reply { | ||
for entry in entries.into_iter() { | ||
if command == "toggle" { | ||
runner.queue_input( | ||
&entry.acm, | ||
&Message::new(&format!("busyout station {}", entry.ext)), | ||
); | ||
runner.queue_input( | ||
&entry.acm, | ||
&Message::new(&format!("release station {}", entry.ext)), | ||
); | ||
} else { | ||
runner.queue_input( | ||
&entry.acm, | ||
&Message::new(&format!("{} station {}", command, entry.ext)), | ||
); | ||
} | ||
} | ||
|
||
// generate output on runner | ||
let output: Result<Vec<Vec<_>>, _> = runner | ||
.run() | ||
.map(|(name, output)| -> Result<Vec<Response>, anyhow::Error> { | ||
Ok(output? | ||
.into_iter() | ||
.filter_map(move |msg| { | ||
(msg.command != "logoff").then(|| Response::from((name.to_owned(), msg))) | ||
}) | ||
.collect()) | ||
}) | ||
.collect(); | ||
|
||
// handle errors and package output as json | ||
match output { | ||
Err(e) => { | ||
error!("busyout-release extension: {}", e); | ||
reply::with_status( | ||
reply::json(&Error { | ||
reason: e.to_string(), | ||
}), | ||
StatusCode::INTERNAL_SERVER_ERROR, | ||
) | ||
} | ||
Ok(r) => reply::with_status( | ||
reply::json(&r.into_iter().flatten().collect::<Vec<_>>()), | ||
StatusCode::OK, | ||
), | ||
} | ||
} | ||
|
||
type Entries = Vec<Entry>; | ||
#[derive(Debug, Deserialize)] | ||
struct Entry { | ||
acm: String, | ||
ext: String, | ||
} |
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
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