-
Notifications
You must be signed in to change notification settings - Fork 124
/
event.go
191 lines (174 loc) · 8.15 KB
/
event.go
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
package model
import (
"context"
"time"
"github.com/evergreen-ci/evergreen"
"github.com/evergreen-ci/evergreen/model/event"
"github.com/evergreen-ci/utility"
"github.com/pkg/errors"
)
type TaskAPIEventLogEntry struct {
ID *string `bson:"_id" json:"-"`
ResourceType *string `bson:"r_type,omitempty" json:"resource_type,omitempty"`
ProcessedAt *time.Time `bson:"processed_at" json:"processed_at"`
Timestamp *time.Time `bson:"ts" json:"timestamp"`
ResourceId *string `bson:"r_id" json:"resource_id"`
EventType *string `bson:"e_type" json:"event_type"`
Data *TaskEventData `bson:"data" json:"data"`
}
type TaskEventData struct {
Execution int `bson:"execution" json:"execution"`
HostId *string `bson:"h_id,omitempty" json:"host_id,omitempty"`
PodId *string `bson:"pod_id,omitempty" json:"pod_id,omitempty"`
UserId *string `bson:"u_id,omitempty" json:"user_id,omitempty"`
Status *string `bson:"s,omitempty" json:"status,omitempty"`
JiraIssue *string `bson:"jira,omitempty" json:"jira,omitempty"`
JiraLink *string `bson:"jira_link,omitempty" json:"jira_link,omitempty"`
BlockedOn *string `bson:"blocked_on,omitempty" json:"blocked_on,omitempty"`
Timestamp *time.Time `bson:"ts,omitempty" json:"timestamp,omitempty"`
Priority int64 `bson:"pri,omitempty" json:"priority,omitempty"`
}
type HostAPIEventLogEntry struct {
ID *string `bson:"_id" json:"-"`
ResourceType *string `bson:"r_type,omitempty" json:"resource_type,omitempty"`
ProcessedAt *time.Time `bson:"processed_at" json:"processed_at"`
Timestamp *time.Time `bson:"ts" json:"timestamp"`
ResourceId *string `bson:"r_id" json:"resource_id"`
EventType *string `bson:"e_type" json:"event_type"`
Data *HostAPIEventData `bson:"data" json:"data"`
}
type HostAPIEventData struct {
AgentRevision *string `bson:"a_rev,omitempty" json:"agent_revision,omitempty"`
AgentBuild *string `bson:"a_build,omitempty" json:"agent_build,omitempty"`
JasperRevision *string `bson:"j_rev,omitempty" json:"jasper_revision,omitempty"`
OldStatus *string `bson:"o_s,omitempty" json:"old_status,omitempty"`
NewStatus *string `bson:"n_s,omitempty" json:"new_status,omitempty"`
Logs *string `bson:"log,omitempty" json:"logs,omitempty"`
Hostname *string `bson:"hn,omitempty" json:"hostname,omitempty"`
ProvisioningMethod *string `bson:"prov_method" json:"provisioning_method,omitempty"`
TaskId *string `bson:"t_id,omitempty" json:"task_id,omitempty"`
TaskPid *string `bson:"t_pid,omitempty" json:"task_pid,omitempty"`
TaskStatus *string `bson:"t_st,omitempty" json:"task_status,omitempty"`
Execution *string `bson:"execution,omitempty" json:"execution,omitempty"`
MonitorOp *string `bson:"monitor_op,omitempty" json:"monitor,omitempty"`
User *string `bson:"usr" json:"user,omitempty"`
Successful bool `bson:"successful,omitempty" json:"successful"`
Duration APIDuration `bson:"duration,omitempty" json:"duration"`
}
type PodAPIEventLogEntry struct {
ID *string `bson:"_id" json:"-"`
ResourceType *string `bson:"r_type,omitempty" json:"resource_type,omitempty"`
ProcessedAt *time.Time `bson:"processed_at" json:"processed_at"`
Timestamp *time.Time `bson:"ts" json:"timestamp"`
ResourceId *string `bson:"r_id" json:"resource_id"`
EventType *string `bson:"e_type" json:"event_type"`
Data *PodAPIEventData `bson:"data" json:"data"`
}
type PodAPIEventData struct {
OldStatus *string `bson:"old_status,omitempty" json:"old_status,omitempty"`
NewStatus *string `bson:"new_status,omitempty" json:"new_status,omitempty"`
Reason *string `bson:"reason,omitempty" json:"reason,omitempty"`
// Fields related to pods running tasks
TaskID *string `bson:"task_id,omitempty" json:"task_id,omitempty"`
TaskExecution *int `bson:"task_execution,omitempty" json:"task_execution,omitempty"`
TaskStatus *string `bson:"task_status,omitempty" json:"task_status,omitempty"`
}
func (el *TaskEventData) BuildFromService(ctx context.Context, v *event.TaskEventData) error {
settings, err := evergreen.GetConfig(ctx)
if err != nil {
return errors.Wrap(err, "getting admin settings")
}
jiraHost := settings.Jira.GetHostURL()
jiraLink := ""
if len(v.JiraIssue) != 0 {
jiraLink = jiraHost + "/browse/" + v.JiraIssue
}
el.Execution = v.Execution
el.HostId = utility.ToStringPtr(v.HostId)
el.PodId = utility.ToStringPtr(v.PodID)
el.UserId = utility.ToStringPtr(v.UserId)
el.JiraIssue = utility.ToStringPtr(v.JiraIssue)
el.JiraLink = utility.ToStringPtr(jiraLink)
el.Status = utility.ToStringPtr(v.Status)
el.BlockedOn = utility.ToStringPtr(v.BlockedOn)
el.Timestamp = ToTimePtr(v.Timestamp)
el.Priority = v.Priority
return nil
}
func (el *TaskAPIEventLogEntry) BuildFromService(ctx context.Context, v event.EventLogEntry) error {
d, ok := v.Data.(*event.TaskEventData)
if !ok {
return errors.Errorf("programmatic error: expected task event data but got type %T", v.Data)
}
taskEventData := TaskEventData{}
if err := taskEventData.BuildFromService(ctx, d); err != nil {
return errors.Wrap(err, "converting task event data to API model")
}
el.ID = utility.ToStringPtr(v.ID)
el.ResourceType = utility.ToStringPtr(v.ResourceType)
el.ProcessedAt = ToTimePtr(v.ProcessedAt)
el.Timestamp = ToTimePtr(v.Timestamp)
el.ResourceId = utility.ToStringPtr(v.ResourceId)
el.EventType = utility.ToStringPtr(v.EventType)
el.Data = &taskEventData
return nil
}
//HostEvent functions
func (el *HostAPIEventData) BuildFromService(v *event.HostEventData) {
el.AgentRevision = utility.ToStringPtr(v.AgentRevision)
el.AgentBuild = utility.ToStringPtr(v.AgentBuild)
el.JasperRevision = utility.ToStringPtr(v.JasperRevision)
el.OldStatus = utility.ToStringPtr(v.OldStatus)
el.NewStatus = utility.ToStringPtr(v.NewStatus)
el.Logs = utility.ToStringPtr(v.Logs)
el.Hostname = utility.ToStringPtr(v.Hostname)
el.ProvisioningMethod = utility.ToStringPtr(v.ProvisioningMethod)
el.TaskId = utility.ToStringPtr(v.TaskId)
el.TaskPid = utility.ToStringPtr(v.TaskPid)
el.TaskStatus = utility.ToStringPtr(v.TaskStatus)
el.Execution = utility.ToStringPtr(v.Execution)
el.MonitorOp = utility.ToStringPtr(v.MonitorOp)
el.User = utility.ToStringPtr(v.User)
el.Successful = v.Successful
el.Duration = NewAPIDuration(v.Duration)
}
func (el *HostAPIEventLogEntry) BuildFromService(entry event.EventLogEntry) error {
d, ok := entry.Data.(*event.HostEventData)
if !ok {
return errors.Errorf("programmatic error: expected host event data but got type %T", entry.Data)
}
hostAPIEventData := HostAPIEventData{}
hostAPIEventData.BuildFromService(d)
el.ID = utility.ToStringPtr(entry.ID)
el.ResourceType = utility.ToStringPtr(entry.ResourceType)
el.ProcessedAt = ToTimePtr(entry.ProcessedAt)
el.Timestamp = ToTimePtr(entry.Timestamp)
el.ResourceId = utility.ToStringPtr(entry.ResourceId)
el.EventType = utility.ToStringPtr(entry.EventType)
el.Data = &hostAPIEventData
return nil
}
func (el *PodAPIEventLogEntry) BuildFromService(entry event.EventLogEntry) error {
d, ok := entry.Data.(*event.PodData)
if !ok {
return errors.Errorf("programmatic error: expected pod event data but got type %T", entry.Data)
}
podAPIEventData := PodAPIEventData{}
podAPIEventData.BuildFromService(d)
el.ID = utility.ToStringPtr(entry.ID)
el.ResourceType = utility.ToStringPtr(entry.ResourceType)
el.ProcessedAt = ToTimePtr(entry.ProcessedAt)
el.Timestamp = ToTimePtr(entry.Timestamp)
el.ResourceId = utility.ToStringPtr(entry.ResourceId)
el.EventType = utility.ToStringPtr(entry.EventType)
el.Data = &podAPIEventData
return nil
}
func (el *PodAPIEventData) BuildFromService(v *event.PodData) {
el.OldStatus = utility.ToStringPtr(v.OldStatus)
el.NewStatus = utility.ToStringPtr(v.NewStatus)
el.Reason = utility.ToStringPtr(v.Reason)
el.TaskID = utility.ToStringPtr(v.TaskID)
el.TaskExecution = utility.ToIntPtr(v.TaskExecution)
el.TaskStatus = utility.ToStringPtr(v.TaskStatus)
}