-
Notifications
You must be signed in to change notification settings - Fork 375
/
types.go
144 lines (120 loc) · 4.33 KB
/
types.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
// Copyright (c) 2021 Terminus, Inc.
//
// This program is free software: you can use, redistribute, and/or modify
// it under the terms of the GNU Affero General Public License, version 3
// or later ("AGPL"), as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package edas
import (
"strings"
"time"
api "github.com/aliyun/alibaba-cloud-sdk-go/services/edas"
)
// SlbType slb type
type SlbType string
const (
EDAS_SLB_INTERNAL SlbType = "intranet"
EDAS_SLB_EXTERNAL SlbType = "internet"
)
// ChangeOrderStatus change orderId status
type ChangeOrderStatus int
const (
CHANGE_ORDER_STATUS_ERROR ChangeOrderStatus = -1
CHANGE_ORDER_STATUS_PENDING ChangeOrderStatus = 0
CHANGE_ORDER_STATUS_EXECUTING ChangeOrderStatus = 1
CHANGE_ORDER_STATUS_SUCC ChangeOrderStatus = 2
CHANGE_ORDER_STATUS_FAILED ChangeOrderStatus = 3
CHANGE_ORDER_STATUS_STOPPED ChangeOrderStatus = 6
CHANGE_ORDER_STATUS_ABNORMAL ChangeOrderStatus = 10
)
var ChangeOrderStatusString = map[ChangeOrderStatus]string{
CHANGE_ORDER_STATUS_ERROR: "error",
CHANGE_ORDER_STATUS_PENDING: "pending",
CHANGE_ORDER_STATUS_EXECUTING: "executing",
CHANGE_ORDER_STATUS_SUCC: "success",
CHANGE_ORDER_STATUS_FAILED: "failed",
CHANGE_ORDER_STATUS_STOPPED: "stopped",
CHANGE_ORDER_STATUS_ABNORMAL: "abnormal",
}
// AppState app state
type AppState int
const (
APP_STATE_AGENT_OFF AppState = 0
APP_STATE_STOPPED AppState = 1
APP_STATE_RUNNING_BUT_URL_FAILED AppState = 3
APP_STATE_RUNNING AppState = 7
)
var AppStateString = map[AppState]string{
APP_STATE_AGENT_OFF: "agent off",
APP_STATE_STOPPED: "stopped",
APP_STATE_RUNNING_BUT_URL_FAILED: "running but url failed",
APP_STATE_RUNNING: "running",
}
// TaskState task state
type TaskState int
const (
TASK_STATE_UNKNOWN TaskState = iota
TASK_STATE_PROCESSING
TASK_STATE_SUCCESS
TASK_STATE_FAILED
)
var TaskStateString = map[TaskState]string{
TASK_STATE_UNKNOWN: "unknown",
TASK_STATE_PROCESSING: "processing",
TASK_STATE_SUCCESS: "success",
TASK_STATE_FAILED: "failed",
}
// AppStatus app status
type AppStatus string
const (
AppStatusRunning AppStatus = "Running"
AppStatusDeploying AppStatus = "Deploying"
AppStatusStopped AppStatus = "Stopped"
AppStatusFailed AppStatus = "Failed"
AppStatusUnknown AppStatus = "Unknown"
)
type ServiceSpec struct {
Name string `json:"name"`
Image string `json:"image"`
Cmd string `json:"cmd"`
Args string `json:"args"` // e.g. [{"argument":"-c"},{"argument":"test"}]
Instances int `json:"instances"`
CPU int `json:"cpu"`
Mcpu int `json:"mcpu"`
Mem int `json:"mem"`
Ports []int `json:"ports"`
LocalVolume string `json:"localVolume"`
Envs string `json:"envs"` // e.g. [{"name":"testkey","value":"testValue"}]
// e.g. {"failureThreshold": 3,"initialDelaySeconds": 5,"successThreshold": 1,"timeoutSeconds": 1,"tcpSocket":{"host":"", "port":8080}}
Liveness string `json:"liveness"`
// e.g. {"failureThreshold": 3,"initialDelaySeconds": 5,"successThreshold": 1,"timeoutSeconds": 1,"httpGet": {"path": "/consumer","port": 8080,"scheme": "HTTP","httpHeaders": [{"name": "test","value": "testvalue"}]}}
Readiness string `json:"readiness"`
}
// ByCreateTime change order for sort
type ByCreateTime []api.ChangeOrder
func (a ByCreateTime) Len() int { return len(a) }
func (a ByCreateTime) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByCreateTime) Less(i, j int) bool {
it, ierr := time.Parse("2006-01-02 15:04:05", a[i].CreateTime)
jt, jerr := time.Parse("2006-01-02 15:04:05", a[j].CreateTime)
if ierr != nil || jerr != nil {
return -1 == strings.Compare(a[i].CreateTime, a[j].CreateTime)
}
return it.Unix() < jt.Unix()
}
type ChangeType string
const (
CHANGE_TYPE_CREATE ChangeType = "Create"
CHANGE_TYPE_DEPLOY ChangeType = "Deploy"
CHANGE_TYPE_STOP ChangeType = "Stop"
)
type EdasEnv struct {
Name string `json:"name"`
Value string `json:"value"`
}