north_common/registry/
service_instance.rs

1use crate::registry::service_instance_state::ServiceInstanceState;
2use crate::registry::service_status_constants::ServiceStatus;
3use std::collections::HashMap;
4
5#[derive(Default, Clone)]
6pub struct IService {
7    pub name: String,
8    pub id: String,
9    pub port: u32,
10
11    pub region: Option<String>,
12    pub zone: Option<String>,
13
14    pub host: String,
15    pub secure: bool,
16    pub metadata: Option<HashMap<String, String>>,
17    pub tag: Option<Vec<String>>,
18    pub state: ServiceInstanceState,
19}
20
21/// #### ServiceInstance
22#[derive(Default, Clone)]
23pub struct ServiceInstanceOptions {
24    ///instance_id the id of the instance.
25    pub instance_id: String,
26
27    ///Node the id of the instance.
28    pub node_id: Option<String>,
29
30    ///service_id the id of the service.
31    pub service_id: String,
32
33    ///host where the service instance can be found.
34    pub host: String,
35
36    ///service instance status.
37    pub status: ServiceStatus,
38
39    ///service tags.
40    pub tags: Option<Vec<String>>,
41
42    ///port the port on which the service is running.
43    pub port: u32,
44
45    ///secure indicates whether or not the connection needs to be secure.
46    pub secure: bool,
47
48    ///node instance state.
49    pub state: Option<ServiceInstanceState>,
50
51    ///metadata optional a map containing metadata.
52    pub metadata: Option<HashMap<String, String>>,
53}
54
55/// #### ServiceInstance
56/// Struct for service instance
57pub trait ServiceInstance {
58    /// Returns the unique instance ID as registered.
59    fn get_instance_id(&self) -> String;
60
61    /// Returns the service ID as registered
62    fn get_service_id(&self) -> String;
63
64    /// Returns hostname of the registered service
65    fn get_host(&self) -> String;
66
67    /// Returns port of the registered service
68    fn get_port(&self) -> u32;
69
70    /// Returns whether the registered service is secure
71    fn is_secure(&self) -> bool;
72
73    /// Returns service universal resource identifier
74    fn get_uri(&self) -> String;
75
76    /// Returns the scheme of the service.
77    fn get_scheme(&self) -> String;
78
79    /// Returns the key / value pair associated with the service id.
80    fn get_metadata(&self) -> HashMap<String, String>;
81
82    /// Returns the key / value pair associated with the service id.
83    fn get_tags(&self) -> Vec<String>;
84
85    /// Returns returns service instance health status.
86    fn get_status(&self) -> String;
87
88    /// Returns service instance cluster node ID
89    fn get_node_id(&self) -> String;
90
91    /// Returns service instance state
92    fn get_state(self) -> ServiceInstanceState;
93}