Skip to content
This repository has been archived by the owner on Nov 3, 2022. It is now read-only.

Commit

Permalink
Merge pull request #259 from golemfactory/hub-hardware-rest-api
Browse files Browse the repository at this point in the history
Add hardware query to Golem Unlimited Hub REST API
  • Loading branch information
filipgolem authored Aug 9, 2019
2 parents b9fef77 + 949cf98 commit ade9f1e
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions gu-hub/src/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ pub fn scope<S: 'static>(scope: Scope<S>) -> Scope<S> {
scope
.route("", Method::GET, list_peers)
.resource("/{nodeId}", |r| r.get().with(fetch_peer))
.resource("/{nodeId}/hardware", |r| r.get().with(fetch_peer_hardware))
.resource("/{nodeId}/deployments", |r| {
r.get().with(fetch_deployments);
r.post().with(new_deployment)
Expand Down Expand Up @@ -186,6 +187,30 @@ fn fetch_peer(info: Path<PeerPath>) -> impl Responder {
.responder()
}

fn fetch_peer_hardware(info: Path<PeerPath>) -> impl Responder {
use gu_hardware::actor::HardwareQuery;
peer(info.node_id)
.into_endpoint()
.send(HardwareQuery::default())
.map_err(|e| match e {
SendError::NoDestination => {
actix_web::error::ErrorNotFound("Peer not found (no destination error)")
}
SendError::NotConnected(node_id) => {
actix_web::error::ErrorNotFound(format!("Peer not connected: {:?}", node_id))
}
_ => actix_web::error::ErrorInternalServerError(format!("{}", e)),
})
.and_then(|hardware_result| match hardware_result {
Ok(hardware) => Ok(HttpResponse::Ok().json(hardware)),
Err(e) => Err(actix_web::error::ErrorInternalServerError(format!(
"Error: {:?}",
e
))),
})
.responder()
}

fn fetch_deployments(info: Path<PeerPath>) -> impl Responder {
use gu_model::deployment::DeploymentInfo;
use gu_model::envman::GetSessions;
Expand Down

0 comments on commit ade9f1e

Please sign in to comment.