1package structs
2
3// EventStreamRequest is used to stream events from a servers EventBroker
4type EventStreamRequest struct {
5	Topics map[Topic][]string
6	Index  int
7
8	QueryOptions
9}
10
11type EventStreamWrapper struct {
12	Error *RpcError
13	Event *EventJson
14}
15
16type Topic string
17
18const (
19	TopicDeployment Topic = "Deployment"
20	TopicEvaluation Topic = "Evaluation"
21	TopicAllocation Topic = "Allocation"
22	TopicJob        Topic = "Job"
23	TopicNode       Topic = "Node"
24	TopicACLPolicy  Topic = "ACLPolicy"
25	TopicACLToken   Topic = "ACLToken"
26	TopicAll        Topic = "*"
27
28	TypeNodeRegistration              = "NodeRegistration"
29	TypeNodeDeregistration            = "NodeDeregistration"
30	TypeNodeEligibilityUpdate         = "NodeEligibility"
31	TypeNodeDrain                     = "NodeDrain"
32	TypeNodeEvent                     = "NodeStreamEvent"
33	TypeDeploymentUpdate              = "DeploymentStatusUpdate"
34	TypeDeploymentPromotion           = "DeploymentPromotion"
35	TypeDeploymentAllocHealth         = "DeploymentAllocHealth"
36	TypeAllocationCreated             = "AllocationCreated"
37	TypeAllocationUpdated             = "AllocationUpdated"
38	TypeAllocationUpdateDesiredStatus = "AllocationUpdateDesiredStatus"
39	TypeEvalUpdated                   = "EvaluationUpdated"
40	TypeJobRegistered                 = "JobRegistered"
41	TypeJobDeregistered               = "JobDeregistered"
42	TypeJobBatchDeregistered          = "JobBatchDeregistered"
43	TypePlanResult                    = "PlanResult"
44	TypeACLTokenDeleted               = "ACLTokenDeleted"
45	TypeACLTokenUpserted              = "ACLTokenUpserted"
46	TypeACLPolicyDeleted              = "ACLPolicyDeleted"
47	TypeACLPolicyUpserted             = "ACLPolicyUpserted"
48)
49
50// Event represents a change in Nomads state.
51type Event struct {
52	// Topic represeents the primary object for the event
53	Topic Topic
54
55	// Type is a short string representing the reason for the event
56	Type string
57
58	// Key is the primary identifier of the Event, The involved objects ID
59	Key string
60
61	// Namespace is the namespace of the object, If the object is not namespace
62	// aware (Node) it is left blank
63	Namespace string
64
65	// FilterKeys are a set of additional related keys that are used to include
66	// events during filtering.
67	FilterKeys []string
68
69	// Index is the raft index that corresponds to the event
70	Index uint64
71
72	// Payload is the Event itself see state/events.go for a list of events
73	Payload interface{}
74}
75
76// Events is a wrapper that contains a set of events for a given index.
77type Events struct {
78	Index  uint64
79	Events []Event
80}
81
82// EventJson is a wrapper for a JSON object
83type EventJson struct {
84	Data []byte
85}
86
87func (j *EventJson) Copy() *EventJson {
88	n := new(EventJson)
89	*n = *j
90	n.Data = make([]byte, len(j.Data))
91	copy(n.Data, j.Data)
92	return n
93}
94
95// JobEvent holds a newly updated Job.
96type JobEvent struct {
97	Job *Job
98}
99
100// EvaluationEvent holds a newly updated Eval.
101type EvaluationEvent struct {
102	Evaluation *Evaluation
103}
104
105// AllocationEvent holds a newly updated Allocation. The
106// Allocs embedded Job has been removed to reduce size.
107type AllocationEvent struct {
108	Allocation *Allocation
109}
110
111// DeploymentEvent holds a newly updated Deployment.
112type DeploymentEvent struct {
113	Deployment *Deployment
114}
115
116// NodeStreamEvent holds a newly updated Node
117type NodeStreamEvent struct {
118	Node *Node
119}
120
121type ACLTokenEvent struct {
122	ACLToken *ACLToken
123	secretID string
124}
125
126// NewACLTokenEvent takes a token and creates a new ACLTokenEvent.  It creates
127// a copy of the passed in ACLToken and empties out the copied tokens SecretID
128func NewACLTokenEvent(token *ACLToken) *ACLTokenEvent {
129	c := token.Copy()
130	c.SecretID = ""
131
132	return &ACLTokenEvent{
133		ACLToken: c,
134		secretID: token.SecretID,
135	}
136}
137
138func (a *ACLTokenEvent) SecretID() string {
139	return a.secretID
140}
141
142type ACLPolicyEvent struct {
143	ACLPolicy *ACLPolicy
144}
145