forked from cloudfoundry/fileserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
desired_lrp.go
54 lines (43 loc) · 1.22 KB
/
desired_lrp.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
package models
import "encoding/json"
type DesiredLRP struct {
ProcessGuid string `json:"process_guid"`
Domain string `json:"domain"`
RootFSPath string `json:"root_fs"`
Instances int `json:"instances"`
Stack string `json:"stack"`
Actions []ExecutorAction `json:"actions"`
DiskMB int `json:"disk_mb"`
MemoryMB int `json:"memory_mb"`
Ports []PortMapping `json:"ports"`
Routes []string `json:"routes"`
Log LogConfig `json:"log"`
}
type DesiredLRPChange struct {
Before *DesiredLRP
After *DesiredLRP
}
func NewDesiredLRPFromJSON(payload []byte) (DesiredLRP, error) {
var task DesiredLRP
err := json.Unmarshal(payload, &task)
if err != nil {
return DesiredLRP{}, err
}
if task.ProcessGuid == "" {
return DesiredLRP{}, ErrInvalidJSONMessage{"process_guid"}
}
if task.Stack == "" {
return DesiredLRP{}, ErrInvalidJSONMessage{"stack"}
}
if len(task.Actions) == 0 {
return DesiredLRP{}, ErrInvalidJSONMessage{"actions"}
}
return task, nil
}
func (desired DesiredLRP) ToJSON() []byte {
bytes, err := json.Marshal(desired)
if err != nil {
panic(err)
}
return bytes
}