2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2020-10-23 18:23:00 +00:00
|
|
|
package structs
|
|
|
|
|
|
|
|
// EventStreamRequest is used to stream events from a servers EventBroker
|
|
|
|
type EventStreamRequest struct {
|
|
|
|
Topics map[Topic][]string
|
|
|
|
Index int
|
|
|
|
|
|
|
|
QueryOptions
|
|
|
|
}
|
|
|
|
|
|
|
|
type EventStreamWrapper struct {
|
|
|
|
Error *RpcError
|
|
|
|
Event *EventJson
|
|
|
|
}
|
|
|
|
|
|
|
|
type Topic string
|
|
|
|
|
|
|
|
const (
|
2022-12-14 13:49:49 +00:00
|
|
|
TopicDeployment Topic = "Deployment"
|
|
|
|
TopicEvaluation Topic = "Evaluation"
|
|
|
|
TopicAllocation Topic = "Allocation"
|
|
|
|
TopicJob Topic = "Job"
|
|
|
|
TopicNode Topic = "Node"
|
2023-06-06 14:14:47 +00:00
|
|
|
TopicNodePool Topic = "NodePool"
|
2022-12-14 13:49:49 +00:00
|
|
|
TopicACLPolicy Topic = "ACLPolicy"
|
|
|
|
TopicACLToken Topic = "ACLToken"
|
|
|
|
TopicACLRole Topic = "ACLRole"
|
|
|
|
TopicACLAuthMethod Topic = "ACLAuthMethod"
|
|
|
|
TopicACLBindingRule Topic = "ACLBindingRule"
|
|
|
|
TopicService Topic = "Service"
|
|
|
|
TopicAll Topic = "*"
|
2020-11-23 19:01:10 +00:00
|
|
|
|
2020-12-03 16:48:18 +00:00
|
|
|
TypeNodeRegistration = "NodeRegistration"
|
|
|
|
TypeNodeDeregistration = "NodeDeregistration"
|
|
|
|
TypeNodeEligibilityUpdate = "NodeEligibility"
|
|
|
|
TypeNodeDrain = "NodeDrain"
|
|
|
|
TypeNodeEvent = "NodeStreamEvent"
|
2023-06-06 14:14:47 +00:00
|
|
|
TypeNodePoolUpserted = "NodePoolUpserted"
|
|
|
|
TypeNodePoolDeleted = "NodePoolDeleted"
|
2020-12-03 16:48:18 +00:00
|
|
|
TypeDeploymentUpdate = "DeploymentStatusUpdate"
|
|
|
|
TypeDeploymentPromotion = "DeploymentPromotion"
|
|
|
|
TypeDeploymentAllocHealth = "DeploymentAllocHealth"
|
|
|
|
TypeAllocationCreated = "AllocationCreated"
|
|
|
|
TypeAllocationUpdated = "AllocationUpdated"
|
|
|
|
TypeAllocationUpdateDesiredStatus = "AllocationUpdateDesiredStatus"
|
|
|
|
TypeEvalUpdated = "EvaluationUpdated"
|
|
|
|
TypeJobRegistered = "JobRegistered"
|
|
|
|
TypeJobDeregistered = "JobDeregistered"
|
|
|
|
TypeJobBatchDeregistered = "JobBatchDeregistered"
|
|
|
|
TypePlanResult = "PlanResult"
|
|
|
|
TypeACLTokenDeleted = "ACLTokenDeleted"
|
|
|
|
TypeACLTokenUpserted = "ACLTokenUpserted"
|
|
|
|
TypeACLPolicyDeleted = "ACLPolicyDeleted"
|
|
|
|
TypeACLPolicyUpserted = "ACLPolicyUpserted"
|
2022-10-20 07:43:35 +00:00
|
|
|
TypeACLRoleDeleted = "ACLRoleDeleted"
|
|
|
|
TypeACLRoleUpserted = "ACLRoleUpserted"
|
2022-11-21 09:06:05 +00:00
|
|
|
TypeACLAuthMethodUpserted = "ACLAuthMethodUpserted"
|
|
|
|
TypeACLAuthMethodDeleted = "ACLAuthMethodDeleted"
|
2022-12-14 13:49:49 +00:00
|
|
|
TypeACLBindingRuleUpserted = "ACLBindingRuleUpserted"
|
|
|
|
TypeACLBindingRuleDeleted = "ACLBindingRuleDeleted"
|
2022-02-28 09:44:58 +00:00
|
|
|
TypeServiceRegistration = "ServiceRegistration"
|
|
|
|
TypeServiceDeregistration = "ServiceDeregistration"
|
2020-10-23 18:23:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Event represents a change in Nomads state.
|
|
|
|
type Event struct {
|
2021-08-21 11:32:07 +00:00
|
|
|
// Topic represents the primary object for the event
|
2020-10-23 18:23:00 +00:00
|
|
|
Topic Topic
|
|
|
|
|
|
|
|
// Type is a short string representing the reason for the event
|
|
|
|
Type string
|
|
|
|
|
|
|
|
// Key is the primary identifier of the Event, The involved objects ID
|
|
|
|
Key string
|
|
|
|
|
|
|
|
// Namespace is the namespace of the object, If the object is not namespace
|
|
|
|
// aware (Node) it is left blank
|
|
|
|
Namespace string
|
|
|
|
|
|
|
|
// FilterKeys are a set of additional related keys that are used to include
|
|
|
|
// events during filtering.
|
|
|
|
FilterKeys []string
|
|
|
|
|
|
|
|
// Index is the raft index that corresponds to the event
|
|
|
|
Index uint64
|
|
|
|
|
|
|
|
// Payload is the Event itself see state/events.go for a list of events
|
|
|
|
Payload interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Events is a wrapper that contains a set of events for a given index.
|
|
|
|
type Events struct {
|
|
|
|
Index uint64
|
|
|
|
Events []Event
|
|
|
|
}
|
|
|
|
|
|
|
|
// EventJson is a wrapper for a JSON object
|
|
|
|
type EventJson struct {
|
|
|
|
Data []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *EventJson) Copy() *EventJson {
|
|
|
|
n := new(EventJson)
|
|
|
|
*n = *j
|
|
|
|
n.Data = make([]byte, len(j.Data))
|
|
|
|
copy(n.Data, j.Data)
|
|
|
|
return n
|
|
|
|
}
|
|
|
|
|
2020-11-23 19:01:10 +00:00
|
|
|
// JobEvent holds a newly updated Job.
|
|
|
|
type JobEvent struct {
|
|
|
|
Job *Job
|
|
|
|
}
|
|
|
|
|
2020-12-03 16:48:18 +00:00
|
|
|
// EvaluationEvent holds a newly updated Eval.
|
|
|
|
type EvaluationEvent struct {
|
|
|
|
Evaluation *Evaluation
|
2020-11-23 19:01:10 +00:00
|
|
|
}
|
|
|
|
|
2020-12-03 16:48:18 +00:00
|
|
|
// AllocationEvent holds a newly updated Allocation. The
|
2020-11-23 19:01:10 +00:00
|
|
|
// Allocs embedded Job has been removed to reduce size.
|
2020-12-03 16:48:18 +00:00
|
|
|
type AllocationEvent struct {
|
|
|
|
Allocation *Allocation
|
2020-11-23 19:01:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DeploymentEvent holds a newly updated Deployment.
|
|
|
|
type DeploymentEvent struct {
|
|
|
|
Deployment *Deployment
|
|
|
|
}
|
|
|
|
|
|
|
|
// NodeStreamEvent holds a newly updated Node
|
|
|
|
type NodeStreamEvent struct {
|
|
|
|
Node *Node
|
|
|
|
}
|
2020-12-01 16:11:34 +00:00
|
|
|
|
2023-06-06 14:14:47 +00:00
|
|
|
// NodePoolEvent holds a newly updated NodePool.
|
|
|
|
type NodePoolEvent struct {
|
|
|
|
NodePool *NodePool
|
|
|
|
}
|
|
|
|
|
2020-12-01 16:11:34 +00:00
|
|
|
type ACLTokenEvent struct {
|
|
|
|
ACLToken *ACLToken
|
2020-12-11 15:40:50 +00:00
|
|
|
secretID string
|
|
|
|
}
|
|
|
|
|
2022-02-28 09:44:58 +00:00
|
|
|
// ServiceRegistrationStreamEvent holds a newly updated or deleted service
|
|
|
|
// registration.
|
|
|
|
type ServiceRegistrationStreamEvent struct {
|
|
|
|
Service *ServiceRegistration
|
|
|
|
}
|
|
|
|
|
2020-12-11 15:40:50 +00:00
|
|
|
// NewACLTokenEvent takes a token and creates a new ACLTokenEvent. It creates
|
|
|
|
// a copy of the passed in ACLToken and empties out the copied tokens SecretID
|
|
|
|
func NewACLTokenEvent(token *ACLToken) *ACLTokenEvent {
|
|
|
|
c := token.Copy()
|
|
|
|
c.SecretID = ""
|
|
|
|
|
|
|
|
return &ACLTokenEvent{
|
|
|
|
ACLToken: c,
|
|
|
|
secretID: token.SecretID,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *ACLTokenEvent) SecretID() string {
|
|
|
|
return a.secretID
|
2020-12-01 16:11:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ACLPolicyEvent struct {
|
|
|
|
ACLPolicy *ACLPolicy
|
|
|
|
}
|
2022-10-20 07:43:35 +00:00
|
|
|
|
2022-11-21 09:06:05 +00:00
|
|
|
// ACLRoleStreamEvent holds a newly updated or deleted ACL role to be used as an
|
2022-10-20 07:43:35 +00:00
|
|
|
// event within the event stream.
|
|
|
|
type ACLRoleStreamEvent struct {
|
|
|
|
ACLRole *ACLRole
|
|
|
|
}
|
2022-11-21 09:06:05 +00:00
|
|
|
|
|
|
|
// ACLAuthMethodEvent holds a newly updated or deleted ACL auth method to be
|
|
|
|
// used as an event in the event stream.
|
|
|
|
type ACLAuthMethodEvent struct {
|
|
|
|
AuthMethod *ACLAuthMethod
|
|
|
|
}
|
2022-12-14 13:49:49 +00:00
|
|
|
|
|
|
|
// ACLBindingRuleEvent holds a newly updated or deleted ACL binding rule to be
|
|
|
|
// used as an event in the event stream.
|
|
|
|
type ACLBindingRuleEvent struct {
|
|
|
|
ACLBindingRule *ACLBindingRule
|
|
|
|
}
|