/
task.go
111 lines (105 loc) · 3 KB
/
task.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
package design
import (
. "github.com/goadesign/goa/design"
. "github.com/goadesign/goa/design/apidsl"
)
var _ = Resource("task", func() {
BasePath("/task")
Action("create", func() {
Routing(PUT("/"))
Description("Creates a new Task in the Swarm according with the config provided in the JSON body")
Payload(TaskPayload)
Response("OK", func() {
Description("Task creation in progress")
Status(200)
Media(Task)
})
Response("Definition error", func() {
Description("The Task definition has errors or it's not complete")
Status(417)
Media(Task)
})
})
Action("inspect", func() {
Routing(GET("/:id"))
Description("Get Task's details")
Params(func() {
Param("id", String, "Task's UUID")
})
Response("OK", func() {
Description("Successful response containing Task data in JSON format")
Status(200)
Media(Task)
})
Response("Task not identified", func() {
Description("The given ID doesn't not exist")
Status(404)
})
Response("Error Creating the Task", func() {
Description("Response when the Task has not been created correctly")
Status(500)
Media(Task)
})
})
Action("delete", func() {
Routing(DELETE("/:id"))
Description("Deletes the Task specified and its components")
Response("OK", func() {
Description("Successfuly deleted")
Status(204)
})
Response("Task not identified", func() {
Description("The given ID doesn't not exist")
Status(404)
})
Response("Task could not be deleted", func() {
Description("Docker Engine error deleting the Task generated container infrastructure")
Status(500)
})
})
})
var TaskPayload = Type("TaskPayload", func() {
Attribute("name", String, func() {
Description("Task Name Identifier")
MinLength(3)
})
Attribute("master", ServicePayload)
Attribute("worker", ServicePayload)
Attribute("waitCommand", WaitCommand)
Attribute("delay", Integer, func() {
Minimum(0)
})
Required("name", "worker", "master")
})
var Task = MediaType("application/atq.task+json", func() {
Description("Task description")
Attributes(func() {
Attribute("id", String, "Task ID")
Attribute("status", func() {
Enum("initializing", "started", "stopped", "finished", "errored")
Description("Status of the Task")
})
Attribute("master", ServiceResponse, "Master Service definition")
Attribute("worker", ServiceResponse, "Worker Service definition")
Attribute("waitCommand", WaitCommand)
Attribute("delay", Integer, "Manual delay between starting Master and Worker services")
})
View("default", func() {
Attribute("id")
Attribute("status")
})
View("full", func() {
Attribute("id")
Attribute("status")
Attribute("master")
Attribute("worker")
Attribute("waitCommand")
Attribute("delay")
})
})
var WaitCommand = Type("WaitCommand", func() {
Description("Definition of a command to be executed")
Attribute("command", String, "Command to be executed")
Attribute("expectedResult", String, "Result expected")
Attribute("timeout", Integer, "Maximum seconds to wait until succesfull response")
})