-
Notifications
You must be signed in to change notification settings - Fork 374
/
runtime.go
160 lines (137 loc) · 4.42 KB
/
runtime.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
// 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 apistructs
import (
"encoding/json"
)
// Request for API `GET /api/runtimes/{idOrName}`
//
// 两种使用场景:
// 1) idOrName is id: 只需要传 id 即可
// e.g. GET /api/runtimes/123
// 2) idOrName is name: 此时需要传 applicationId 和 workspace
// e.g. GET /api/runtimes/test.develop?applicationId=456&workspace=TEST
type RuntimeInspectRequest struct {
// 应用实例 ID / Name
IDOrName string `path:"idOrName"`
// 环境, idOrName 为 Name 时必传, 为 ID 时不必传
Workspace string `query:"workspace"`
// 应用 ID, idOrName 为 Name 时必传, 为 ID 时不必传
ApplicationID uint64 `query:"applicationId"`
}
// Response for API `GET /api/runtimes/{idOrName}`
type RuntimeInspectResponse struct {
Header
Data RuntimeInspectDTO `json:"data"`
}
type RuntimeListResponse struct {
Header
UserInfoHeader
Data []RuntimeSummaryDTO `json:"data"`
}
// RuntimeCreateV2Request 创建 Runtime 请求
type RuntimeCreateV2Request struct {
ApplicationID uint64 `json:"applicationID"`
Workspace string `json:"workspace"`
Name string `json:"name"`
ClusterName string `json:"clusterName"`
Operator string `json:"operator"`
Source RuntimeSource `json:"source"`
}
// RuntimeCreateV2Response 创建 Runtime 响应
type RuntimeCreateV2Response struct {
Header
Data *RuntimeCreateV2ResponseData `json:"data"`
}
// RuntimeCreateV2Response 创建 Runtime 响应数据
type RuntimeCreateV2ResponseData struct {
RuntimeID uint64 `json:"runtimeID"`
}
type RuntimeCreateRequest struct {
Name string `json:"name"`
ReleaseID string `json:"releaseId"`
Operator string `json:"operator"`
ClusterName string `json:"clusterName"`
Source RuntimeSource `json:"source"`
Extra RuntimeCreateRequestExtra `json:"extra,omitempty"`
SkipPushByOrch bool `json:"skipPushByOrch"`
}
type RuntimeKillPodRequest struct {
RuntimeID uint64 `json:"runtimeID"`
PodName string `json:"podName"`
}
type RuntimeReleaseCreatePipelineResponse struct {
PipelineID uint64 `json:"pipelineId"`
}
type RuntimeReleaseCreateRequest struct {
// 制品ID
ReleaseID string `json:"releaseId"`
// 环境
Workspace string `json:"workspace"`
// 项目ID
ProjectID uint64 `json:"projectId"`
// 应用ID
ApplicationID uint64 `json:"applicationId"`
}
type RuntimeCreateRequestExtra struct {
OrgID uint64 `json:"orgId,omitempty"`
ProjectID uint64 `json:"projectId,omitempty"`
ApplicationID uint64 `json:"applicationId,omitempty"`
ApplicationName string `json:"applicationName,omitempty"`
Workspace string `json:"workspace,omitempty"`
BuildID uint64 `json:"buildId,omitempty"`
DeployType string `json:"deployType,omitempty"`
InstanceID json.Number `json:"instanceId,omitempty"`
// Deprecated
ClusterId json.Number `json:"clusterId,omitempty"`
// for addon actions
AddonActions map[string]interface{} `json:"actions,omitempty"`
}
type RuntimeCreateResponse struct {
Header
Data DeploymentCreateResponseDTO `json:"data"`
}
type RuntimeRedeployResponse struct {
Header
Data DeploymentCreateResponseDTO `json:"data"`
}
type RuntimeRollbackRequest struct {
DeploymentID uint64 `json:"deploymentId"`
}
type RuntimeRollbackResponse struct {
Header
Data DeploymentCreateResponseDTO `json:"data"`
}
type RuntimeDeleteResponse struct {
Header
Data RuntimeDTO `json:"data"`
}
type PageInfo struct {
// 页码
PageNO int `query:"pageNo"`
// 每页大小
PageSize int `query:"pageSize"`
}
func (p PageInfo) GetOffset() int {
offset := (p.PageNO - 1) * p.PageSize
if offset > 0 {
return offset
}
return 0
}
func (p PageInfo) GetLimit() int {
if p.PageSize > 0 {
return p.PageSize
}
return 0
}