-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmessages.go
103 lines (94 loc) · 3.54 KB
/
messages.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
package saurontypes
import (
"strings"
)
// Task is a struct that encapsulates the mapping between the
// queue to place a task on and the name of the image to be run
type Task struct {
Queue string `json:"queue" mapstructure:"queue"`
ImageName string `json:"image" mapstructure:"image"`
Name string `json:"name" mapstructure:"name"`
Data string `json:"data" mapstructure:"data"`
}
// SauronConfig is the top level config for sauron
// This will come from the config file for sauron
// This will contain different config for different assignments
type SauronConfig struct {
Assignments []Assignment `json:"assignments" mapstructure:"assignments"`
}
// Assignment is the config for a particular assignment
// including the name, description, prefix and the associated Tasks
type Assignment struct {
Name string `json:"name" mapstructure:"name"`
Description string `json:"description" mapstructure:"description"`
Prefix string `json:"prefix" mapstructure:"prefix"`
Tasks []Task `json:"tasks" mapstructure:"tasks"`
}
// AngmarMessage is a struct that encapsulates the message that Angmar
// listens to on a queue for.
type AngmarMessage struct {
URL string `json:"url" mapstructure:"url"`
Stream string `json:"stream" mapstructure:"stream"`
SHA string `json:"sha" mapstructure:"sha"`
FlowID string `json:"flowID" mapstructure:"flowID"`
Pusher string `json:"pusher" mapstructure:"pusher"`
Project string `json:"project" mapstructure:"project"`
Tasks []Task `json:"tasks" mapstructure:"tasks"`
}
// String returns a stringified version of AngmarMessage, but doesn't
// stringify the list of Tasks.
func (m AngmarMessage) String() string {
var builder strings.Builder
builder.WriteString("Flow ID: " + m.FlowID + "\n")
builder.WriteString("Stream: " + m.Stream + "\n")
builder.WriteString("URL: " + m.URL + "\n")
builder.WriteString("Project: " + m.Project + "\n")
builder.WriteString("SHA: " + m.SHA + "\n")
builder.WriteString("Pusher: " + m.Pusher + "\n")
return builder.String()
}
// UrukMessage is a struct that encapsulates the message that Uruk
// listens to on a queue for
type UrukMessage struct {
FlowID string
Pusher string
Project string
Stream string
ImageName string
RepoLocation string
DataPath string
Job string
SHA string
}
// String returns a stringified version of UrukMessage
func (m UrukMessage) String() string {
var builder strings.Builder
builder.WriteString("Flow ID: " + m.FlowID + "\n")
builder.WriteString("Pusher: " + m.Pusher + "\n")
builder.WriteString("Stream: " + m.Stream + "\n")
builder.WriteString("Image: " + m.ImageName + "\n")
builder.WriteString("Project: " + m.Project + "\n")
builder.WriteString("Repo Location: " + m.RepoLocation + "\n")
builder.WriteString("SHA: " + m.SHA + "\n")
return builder.String()
}
// ConvertAngmarToUrukMessages converts an Angmar message to a map of queue names and
// their respective UrukMessage
func ConvertAngmarToUrukMessages(angmarMessage AngmarMessage, repoLocation string) map[string]UrukMessage {
urukMessages := make(map[string]UrukMessage)
for _, task := range angmarMessage.Tasks {
urukMessage := UrukMessage{
FlowID: angmarMessage.FlowID,
Stream: angmarMessage.Stream,
Pusher: angmarMessage.Pusher,
Project: angmarMessage.Project,
SHA: angmarMessage.SHA,
ImageName: task.ImageName,
RepoLocation: repoLocation,
DataPath: task.Data,
Job: task.Name,
}
urukMessages[task.Queue] = urukMessage
}
return urukMessages
}