1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//!
//! # Fetch SPUs
//!
//! Public API to fetch SPU metadata from the SC
//!
use kf_protocol::api::Request;
use kf_protocol::api::FlvErrorCode;
use kf_protocol::derive::Decode;
use kf_protocol::derive::Encode;

use crate::ScApiKey;
use crate::common::flv_spus::FlvRequestSpuType;
use crate::common::flv_spus::FlvSpuType;
use crate::common::flv_spus::FlvSpuResolution;

use super::spu::FlvEndPointMetadata;

// -----------------------------------
// FlvFetchSpusRequest
// -----------------------------------

/// Fetch SPUs by type
#[derive(Decode, Encode, Default, Debug)]
pub struct FlvFetchSpusRequest {
    /// SPU type All or Custom
    pub req_spu_type: FlvRequestSpuType,
}

// -----------------------------------
// FlvFetchSpusResponse
// -----------------------------------

#[derive(Encode, Decode, Default, Debug)]
pub struct FlvFetchSpusResponse {
    /// Each spu in the response.
    pub spus: Vec<FlvFetchSpuResponse>,
}

#[derive(Encode, Decode, Default, Debug)]
pub struct FlvFetchSpuResponse {
    /// The error code, None for no errors
    pub error_code: FlvErrorCode,

    /// The spu name
    pub name: String,

    /// Spu parameters, None if error
    pub spu: Option<FlvFetchSpu>,
}

#[derive(Encode, Decode, Default, Debug)]
pub struct FlvFetchSpu {
    /// Spu globally unique id.
    pub id: i32,

    /// Spu type: true for managed, false for custom.
    pub spu_type: FlvSpuType,

    /// Public endpoint server interface.
    pub public_ep: FlvEndPointMetadata,

    /// Private endpoint server interface.
    pub private_ep: FlvEndPointMetadata,

    /// Rack label, optional parameter used by replica assignment algorithm.
    pub rack: Option<String>,

    /// Status resolution
    pub resolution: FlvSpuResolution,
}

// -----------------------------------
// Implementation - FlvFetchSpusRequest
// -----------------------------------

impl Request for FlvFetchSpusRequest {
    const API_KEY: u16 = ScApiKey::FlvFetchSpus as u16;
    const DEFAULT_API_VERSION: i16 = 1;
    type Response = FlvFetchSpusResponse;
}