-
Notifications
You must be signed in to change notification settings - Fork 16
/
workflow.go
421 lines (371 loc) · 13.6 KB
/
workflow.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
package convert
import (
"reflect"
"strings"
"time"
workspaceproto "github.com/Bio-OS/bioos/internal/context/workspace/interface/grpc/proto"
"github.com/Bio-OS/bioos/pkg/consts"
)
type CreateWorkflowRequest struct {
ID string `json:"id"`
WorkspaceID string `path:"workspace-id"`
Name string `json:"name" validate:"required,resName"`
Description string `json:"description" validate:"required,workspaceDesc"`
Language string `json:"language" validate:"required,oneof=WDL"`
Source string `json:"source" validate:"required,oneof=git"`
Url string `json:"url" validate:"required"`
Tag string `json:"tag" validate:"required"`
Token string `json:"token"`
MainWorkflowPath string `json:"mainWorkflowPath" validate:"required"`
}
func (req *CreateWorkflowRequest) ToGRPC() *workspaceproto.CreateWorkflowRequest {
return &workspaceproto.CreateWorkflowRequest{
Id: &req.ID,
WorkspaceID: req.WorkspaceID,
Name: req.Name,
Description: &req.Description,
Language: req.Language,
Source: req.Source,
Url: &req.Url,
Tag: &req.Tag,
Token: &req.Token,
MainWorkflowPath: req.MainWorkflowPath,
}
}
type CreateWorkflowResponse struct {
ID string `json:"id"`
}
func (resp *CreateWorkflowResponse) FromGRPC(protoResp *workspaceproto.CreateWorkflowResponse) {
resp.ID = protoResp.GetId()
}
type GetWorkflowRequest struct {
WorkspaceID string `path:"workspace-id"`
ID string `path:"id"`
}
func (req *GetWorkflowRequest) ToGRPC() *workspaceproto.GetWorkflowRequest {
return &workspaceproto.GetWorkflowRequest{
WorkspaceID: req.WorkspaceID,
Id: req.ID,
}
}
type GetWorkflowResponse struct {
Workflow WorkflowItem `json:"workflow"`
}
func (resp *GetWorkflowResponse) FromGRPC(protoResp *workspaceproto.GetWorkflowResponse) {
resp.Workflow = convertWorkflowItem(protoResp.GetWorkflow())
}
type ListWorkflowsRequest struct {
Page int `query:"page"`
Size int `query:"size"`
OrderBy string `query:"orderBy"`
SearchWord string `query:"searchWord"`
IDs string `query:"ids"`
WorkspaceID string `path:"workspace-id"`
}
func (req *ListWorkflowsRequest) ToGRPC() *workspaceproto.ListWorkflowRequest {
return &workspaceproto.ListWorkflowRequest{
Page: int32(req.Page),
Size: int32(req.Size),
OrderBy: req.OrderBy,
SearchWord: req.SearchWord,
Ids: strings.Split(req.IDs, consts.QuerySliceDelimiter),
WorkspaceID: req.WorkspaceID,
}
}
type ListWorkflowsResponse struct {
Page int `json:"page"`
Size int `json:"size"`
Total int `json:"total"`
Items []WorkflowItem `json:"items"`
}
type listWorkflowsResponseBriefItems struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
LatestVersionStatus string `json:"status"`
LatestVersionMessage string `json:"message"`
LatestVersionLanguage string `json:"language"`
LatestVersionLanguageVersion string `json:"languageVersion"`
LatestVersionMainWorkflowPath string `json:"mainWorkflowPath"`
LatestVersionSource string `json:"source"`
}
func (resp *ListWorkflowsResponse) BriefItems() reflect.Value {
briefItems := make([]listWorkflowsResponseBriefItems, len(resp.Items))
for i, item := range resp.Items {
briefItems[i] = listWorkflowsResponseBriefItems{
ID: item.ID,
Name: item.Name,
Description: item.Description,
LatestVersionStatus: item.LatestVersion.Status,
LatestVersionMessage: item.LatestVersion.Message,
LatestVersionLanguage: item.LatestVersion.Language,
LatestVersionLanguageVersion: item.LatestVersion.LanguageVersion,
LatestVersionMainWorkflowPath: item.LatestVersion.MainWorkflowPath,
LatestVersionSource: item.LatestVersion.Source,
}
}
return reflect.ValueOf(briefItems)
}
func (resp *ListWorkflowsResponse) FromGRPC(protoResp *workspaceproto.ListWorkflowResponse) {
resp.Page = int(protoResp.Page)
resp.Size = int(protoResp.Size)
resp.Total = int(protoResp.Total)
resp.Items = make([]WorkflowItem, len(protoResp.Items))
for i := range protoResp.Items {
resp.Items[i] = convertWorkflowItem(protoResp.Items[i])
}
}
type UpdateWorkflowRequest struct {
ID string `path:"id"`
Name string `json:"name"`
Description string `json:"description"`
WorkspaceID string `path:"workspace-id"`
}
func (req *UpdateWorkflowRequest) ToGRPC() *workspaceproto.UpdateWorkflowRequest {
return &workspaceproto.UpdateWorkflowRequest{
Id: req.ID,
Name: &req.Name,
Description: &req.Description,
WorkspaceID: req.WorkspaceID,
}
}
type UpdateWorkflowResponse struct {
}
func (resp *UpdateWorkflowResponse) FromGRPC(protoResp *workspaceproto.UpdateWorkflowResponse) {
return
}
type DeleteWorkflowRequest struct {
ID string `path:"id"`
WorkspaceID string `path:"workspace-id"`
}
func (req *DeleteWorkflowRequest) ToGRPC() *workspaceproto.DeleteWorkflowRequest {
return &workspaceproto.DeleteWorkflowRequest{
Id: req.ID,
WorkspaceID: req.WorkspaceID,
}
}
type DeleteWorkflowResponse struct {
}
func (resp *DeleteWorkflowResponse) FromGRPC(protoResp *workspaceproto.DeleteWorkflowResponse) {
return
}
type GetWorkflowFileRequest struct {
ID string `path:"id"`
WorkspaceID string `path:"workspace-id"`
WorkflowID string `path:"workflow-id"`
}
func (req *GetWorkflowFileRequest) ToGRPC() *workspaceproto.GetWorkflowFileRequest {
return &workspaceproto.GetWorkflowFileRequest{
Id: req.ID,
WorkspaceID: req.WorkspaceID,
WorkflowID: req.WorkflowID,
}
}
type GetWorkflowFileResponse struct {
File *WorkflowFile `json:"file"`
}
func (resp *GetWorkflowFileResponse) FromGRPC(protoResp *workspaceproto.GetWorkflowFileResponse) {
resp.File = &WorkflowFile{
ID: protoResp.GetFile().GetId(),
WorkflowVersionID: protoResp.GetFile().GetWorkflowVersionID(),
Path: protoResp.GetFile().GetPath(),
Content: protoResp.GetFile().GetContent(),
CreatedAt: protoResp.GetFile().GetCreatedAt().AsTime(),
UpdatedAt: protoResp.GetFile().GetUpdatedAt().AsTime(),
}
}
type GetWorkflowVersionRequest struct {
ID string `path:"id"`
WorkspaceID string `path:"workspace-id"`
WorkflowID string `path:"workflow-id"`
}
func (req *GetWorkflowVersionRequest) ToGRPC() *workspaceproto.GetWorkflowVersionRequest {
return &workspaceproto.GetWorkflowVersionRequest{
Id: req.ID,
WorkspaceID: req.WorkspaceID,
WorkflowID: req.WorkflowID,
}
}
type GetWorkflowVersionResponse struct {
Version WorkflowVersion `json:"version"`
}
func (resp *GetWorkflowVersionResponse) FromGRPC(protoResp *workspaceproto.GetWorkflowVersionResponse) {
resp.Version = convertWorkflowVersion(protoResp.GetVersion())
}
type ListWorkflowFilesRequest struct {
Page int `query:"page"`
Size int `query:"size"`
OrderBy string `query:"orderBy"`
IDs string `query:"ids"`
WorkspaceID string `path:"workspace-id"`
WorkflowID string `path:"workflow-id"`
WorkflowVersionID string `query:"workflowVersionID,omitempty"`
}
func (req *ListWorkflowFilesRequest) ToGRPC() *workspaceproto.ListWorkflowFilesRequest {
return &workspaceproto.ListWorkflowFilesRequest{
Page: int32(req.Page),
Size: int32(req.Size),
OrderBy: req.OrderBy,
Ids: strings.Split(req.IDs, consts.QuerySliceDelimiter),
WorkspaceID: req.WorkspaceID,
WorkflowID: req.WorkflowID,
WorkflowVersionID: &req.WorkflowVersionID,
}
}
type ListWorkflowFilesResponse struct {
Page int `json:"page"`
Size int `json:"size"`
Total int `json:"total"`
WorkspaceID string `json:"workspaceID"`
WorkflowID string `json:"workflowID"`
Items []*WorkflowFile `json:"items"`
}
func (resp *ListWorkflowFilesResponse) FromGRPC(protoResp *workspaceproto.ListWorkflowFilesResponse) {
resp.Page = int(protoResp.GetPage())
resp.Size = int(protoResp.GetSize())
resp.Total = int(protoResp.GetTotal())
resp.WorkspaceID = protoResp.GetWorkspaceID()
resp.WorkflowID = protoResp.GetWorkflowID()
resp.Items = make([]*WorkflowFile, len(protoResp.GetFiles()))
for i, f := range protoResp.GetFiles() {
resp.Items[i] = &WorkflowFile{
ID: f.GetId(),
WorkflowVersionID: f.GetWorkflowVersionID(),
Path: f.GetPath(),
Content: f.GetContent(),
CreatedAt: f.GetCreatedAt().AsTime(),
UpdatedAt: f.GetUpdatedAt().AsTime(),
}
}
}
type ListWorkflowVersionsRequest struct {
Page int `query:"page"`
Size int `query:"size"`
OrderBy string `query:"orderBy"`
IDs string `query:"ids"`
WorkspaceID string `path:"workspace-id"`
WorkflowID string `path:"workflow-id"`
}
func (req *ListWorkflowVersionsRequest) ToGRPC() *workspaceproto.ListWorkflowVersionsRequest {
return &workspaceproto.ListWorkflowVersionsRequest{
Page: int32(req.Page),
Size: int32(req.Size),
OrderBy: req.OrderBy,
Ids: strings.Split(req.IDs, consts.QuerySliceDelimiter),
WorkspaceID: req.WorkspaceID,
WorkflowID: req.WorkflowID,
}
}
type ListWorkflowVersionsResponse struct {
Page int `json:"page"`
Size int `json:"size"`
Total int `json:"total"`
WorkspaceID string `json:"workspaceID"`
WorkflowID string `json:"workflowID"`
Items []WorkflowVersion `json:"items"`
}
func (resp *ListWorkflowVersionsResponse) FromGRPC(protoResp *workspaceproto.ListWorkflowVersionsResponse) {
resp.Page = int(protoResp.GetPage())
resp.Size = int(protoResp.GetSize())
resp.Total = int(protoResp.GetTotal())
resp.WorkspaceID = protoResp.GetWorkspaceID()
resp.WorkflowID = protoResp.GetWorkflowID()
resp.Items = make([]WorkflowVersion, len(protoResp.GetItems()))
for i, item := range protoResp.GetItems() {
resp.Items[i] = convertWorkflowVersion(item)
}
}
type WorkflowItem struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
LatestVersion WorkflowVersion `json:"latestVersion"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
}
type WorkflowVersion struct {
ID string `json:"id"`
Status string `json:"status"`
Message string `json:"message"`
Language string `json:"language"`
LanguageVersion string `json:"languageVersion"`
MainWorkflowPath string `json:"mainWorkflowPath"`
Inputs []*WorkflowParam `json:"inputs"`
Outputs []*WorkflowParam `json:"outputs"`
Graph string `json:"graph"`
Metadata map[string]string `json:"metadata"`
Source string `json:"source"`
Files []*WorkflowFileInfo `json:"files"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
}
type WorkflowFileInfo struct {
ID string `json:"id"`
Path string `json:"path"`
}
type WorkflowParam struct {
Name string `json:"name"`
Type string `json:"type"`
Optional bool `json:"optional"`
Default string `json:"default"`
}
type WorkflowFile struct {
ID string `json:"id"`
WorkflowVersionID string `json:"workflowVersionID"`
Path string `json:"path"`
Content string `json:"content"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
}
func convertWorkflowItem(workflow *workspaceproto.Workflow) WorkflowItem {
item := WorkflowItem{
ID: workflow.GetId(),
Name: workflow.GetName(),
Description: workflow.GetDescription(),
LatestVersion: convertWorkflowVersion(workflow.GetLatestVersion()),
CreatedAt: workflow.GetCreatedAt().AsTime(),
UpdatedAt: workflow.GetUpdatedAt().AsTime(),
}
return item
}
func convertWorkflowVersion(version *workspaceproto.WorkflowVersion) WorkflowVersion {
v := WorkflowVersion{
ID: version.GetId(),
Status: version.GetStatus(),
Message: version.GetMessage(),
Language: version.GetLanguage(),
LanguageVersion: version.GetLanguageVersion(),
MainWorkflowPath: version.GetMainWorkflowPath(),
Inputs: make([]*WorkflowParam, len(version.GetInputs())),
Outputs: make([]*WorkflowParam, len(version.GetOutputs())),
Graph: version.GetGraph(),
Metadata: version.GetMetadata(),
Source: version.GetSource(),
Files: make([]*WorkflowFileInfo, len(version.GetFiles())),
CreatedAt: version.GetCreatedAt().AsTime(),
UpdatedAt: version.GetUpdatedAt().AsTime(),
}
for i, param := range version.GetInputs() {
v.Inputs[i] = &WorkflowParam{
Name: param.Name,
Type: param.Type,
Optional: param.Optional,
Default: *param.Default,
}
}
for i, param := range version.GetOutputs() {
v.Outputs[i] = &WorkflowParam{
Name: param.Name,
Type: param.Type,
Optional: param.Optional,
Default: *param.Default,
}
}
for i, f := range version.GetFiles() {
v.Files[i] = &WorkflowFileInfo{
ID: f.Id,
Path: f.Path,
}
}
return v
}