|
| 1 | +// This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | +// License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | +// file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 4 | + |
| 5 | +use chrono::{DateTime, Utc}; |
| 6 | +use dropshot::{ |
| 7 | + EmptyScanParams, HttpError, HttpResponseDeleted, HttpResponseOk, |
| 8 | + HttpResponseUpdatedNoContent, PaginationParams, Query, RequestContext, |
| 9 | + ResultsPage, TypedBody, |
| 10 | +}; |
| 11 | +use omicron_common::api::internal::nexus::ProducerEndpoint; |
| 12 | +use schemars::JsonSchema; |
| 13 | +use serde::{Deserialize, Serialize}; |
| 14 | +use uuid::Uuid; |
| 15 | + |
| 16 | +#[dropshot::api_description { |
| 17 | + module = "oximeter_api_mod", |
| 18 | +}] |
| 19 | +pub trait OximeterApi { |
| 20 | + type Context; |
| 21 | + |
| 22 | + /// Handle a request from Nexus to register a new producer with this collector. |
| 23 | + #[endpoint { |
| 24 | + method = POST, |
| 25 | + path = "/producers", |
| 26 | + }] |
| 27 | + async fn producers_post( |
| 28 | + request_context: RequestContext<Self::Context>, |
| 29 | + body: TypedBody<ProducerEndpoint>, |
| 30 | + ) -> Result<HttpResponseUpdatedNoContent, HttpError>; |
| 31 | + |
| 32 | + /// List all producers. |
| 33 | + #[endpoint { |
| 34 | + method = GET, |
| 35 | + path = "/producers", |
| 36 | + }] |
| 37 | + async fn producers_list( |
| 38 | + request_context: RequestContext<Self::Context>, |
| 39 | + query: Query<PaginationParams<EmptyScanParams, ProducerPage>>, |
| 40 | + ) -> Result<HttpResponseOk<ResultsPage<ProducerEndpoint>>, HttpError>; |
| 41 | + |
| 42 | + /// Delete a producer by ID. |
| 43 | + #[endpoint { |
| 44 | + method = DELETE, |
| 45 | + path = "/producers/{producer_id}", |
| 46 | + }] |
| 47 | + async fn producer_delete( |
| 48 | + request_context: RequestContext<Self::Context>, |
| 49 | + path: dropshot::Path<ProducerIdPathParams>, |
| 50 | + ) -> Result<HttpResponseDeleted, HttpError>; |
| 51 | + |
| 52 | + /// Return identifying information about this collector. |
| 53 | + #[endpoint { |
| 54 | + method = GET, |
| 55 | + path = "/info", |
| 56 | + }] |
| 57 | + async fn collector_info( |
| 58 | + request_context: RequestContext<Self::Context>, |
| 59 | + ) -> Result<HttpResponseOk<CollectorInfo>, HttpError>; |
| 60 | +} |
| 61 | + |
| 62 | +/// Parameters for paginating the list of producers. |
| 63 | +#[derive(Clone, Copy, Debug, Deserialize, JsonSchema, Serialize)] |
| 64 | +pub struct ProducerPage { |
| 65 | + pub id: Uuid, |
| 66 | +} |
| 67 | + |
| 68 | +#[derive(Clone, Copy, Debug, Deserialize, JsonSchema, Serialize)] |
| 69 | +pub struct ProducerIdPathParams { |
| 70 | + pub producer_id: Uuid, |
| 71 | +} |
| 72 | + |
| 73 | +#[derive(Clone, Copy, Debug, Deserialize, JsonSchema, Serialize)] |
| 74 | +pub struct CollectorInfo { |
| 75 | + /// The collector's UUID. |
| 76 | + pub id: Uuid, |
| 77 | + /// Last time we refreshed our producer list with Nexus. |
| 78 | + pub last_refresh: Option<DateTime<Utc>>, |
| 79 | +} |
0 commit comments