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
81
use serde::Deserialize;
use crate::models::allocation::Allocation;
#[derive(Deserialize, Debug)]
#[serde(rename_all = "PascalCase")]
pub struct EventCollection {
pub index: i32,
pub events: Vec<Event>,
}
#[derive(Deserialize, Debug)]
#[serde(rename_all = "PascalCase")]
pub struct Event {
pub index: i32,
pub key: String,
pub namespace: String,
pub topic: Option<EventTopic>,
pub r#type: Option<EventType>,
pub payload: Option<EventPayload>,
}
impl Event {
pub fn get_alloc_id(&self) -> Option<String> {
match self.payload {
Some(ref payload) => match payload.allocation {
Some(ref allocation) => allocation.job_id.as_ref().map(|job_id| job_id.to_string()),
None => None,
},
None => None,
}
}
}
#[derive(Deserialize, Debug)]
#[serde(rename_all = "PascalCase")]
pub struct EventPayload {
pub allocation: Option<Allocation>,
}
#[derive(Deserialize, Debug)]
pub enum EventTopic {
ACLToken,
ACLPolicy,
ACLRole,
Job,
Allocation,
Deployment,
Evaluation,
Node,
Service,
}
#[derive(Deserialize, Debug)]
pub enum EventType {
ACLTokenUpserted,
ACLTokenDeleted,
ACLPolicyUpserted,
ACLPolicyDeleted,
ACLRoleUpserted,
ACLRoleDeleted,
AllocationCreated,
AllocationUpdated,
AllocationUpdateDesiredStatus,
DeploymentStatusUpdate,
DeploymentPromotion,
DeploymentAllocHealth,
EvaluationUpdated,
JobRegistered,
JobDeregistered,
JobBatchDeregistered,
NodeRegistration,
NodeDeregistration,
NodeEligibility,
NodeStreamEvent,
NodeDrain,
NodeEvent,
PlanResult,
ServiceRegistration,
ServiceDeregistration,
}