/
admin_proto.go
568 lines (507 loc) · 16 KB
/
admin_proto.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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
// Copyright 2018 The Chubao Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied. See the License for the specific language governing
// permissions and limitations under the License.
package proto
// api
const (
// Admin APIs
AdminGetCluster = "/admin/getCluster"
AdminGetDataPartition = "/dataPartition/get"
AdminLoadDataPartition = "/dataPartition/load"
AdminCreateDataPartition = "/dataPartition/create"
AdminDecommissionDataPartition = "/dataPartition/decommission"
AdminDiagnoseDataPartition = "/dataPartition/diagnose"
AdminDeleteDataReplica = "/dataReplica/delete"
AdminAddDataReplica = "/dataReplica/add"
AdminDeleteVol = "/vol/delete"
AdminUpdateVol = "/vol/update"
AdminVolShrink = "/vol/shrink"
AdminVolExpand = "/vol/expand"
AdminCreateVol = "/admin/createVol"
AdminGetVol = "/admin/getVol"
AdminClusterFreeze = "/cluster/freeze"
AdminClusterStat = "/cluster/stat"
AdminGetIP = "/admin/getIp"
AdminCreateMetaPartition = "/metaPartition/create"
AdminSetMetaNodeThreshold = "/threshold/set"
AdminListVols = "/vol/list"
AdminSetNodeInfo = "/admin/setNodeInfo"
AdminGetNodeInfo = "/admin/getNodeInfo"
AdminGetAllNodeSetGrpInfo = "/admin/getDomainInfo"
AdminGetNodeSetGrpInfo = "/admin/getDomainNodeSetGrpInfo"
AdminGetIsDomainOn = "/admin/getIsDomainOn"
AdminUpdateNodeSetCapcity = "/admin/updateNodeSetCapcity"
AdminUpdateNodeSetId = "/admin/updateNodeSetId"
AdminUpdateDomainDataUseRatio = "/admin/updateDomainDataRatio"
AdminUpdateZoneExcludeRatio = "/admin/updateZoneExcludeRatio"
AdminSetNodeRdOnly = "/admin/setNodeRdOnly"
//graphql master api
AdminClusterAPI = "/api/cluster"
AdminUserAPI = "/api/user"
AdminVolumeAPI = "/api/volume"
//graphql coonsole api
ConsoleIQL = "/iql"
ConsoleLoginAPI = "/login"
ConsoleMonitorAPI = "/cfs_monitor"
ConsoleFile = "/file"
ConsoleFileDown = "/file/down"
ConsoleFileUpload = "/file/upload"
// Client APIs
ClientDataPartitions = "/client/partitions"
ClientVol = "/client/vol"
ClientMetaPartition = "/metaPartition/get"
ClientVolStat = "/client/volStat"
ClientMetaPartitions = "/client/metaPartitions"
//raft node APIs
AddRaftNode = "/raftNode/add"
RemoveRaftNode = "/raftNode/remove"
// Node APIs
AddDataNode = "/dataNode/add"
DecommissionDataNode = "/dataNode/decommission"
MigrateDataNode = "/dataNode/migrate"
DecommissionDisk = "/disk/decommission"
GetDataNode = "/dataNode/get"
AddMetaNode = "/metaNode/add"
DecommissionMetaNode = "/metaNode/decommission"
MigrateMetaNode = "/metaNode/migrate"
GetMetaNode = "/metaNode/get"
AdminUpdateMetaNode = "/metaNode/update"
AdminUpdateDataNode = "/dataNode/update"
AdminGetInvalidNodes = "/invalid/nodes"
AdminLoadMetaPartition = "/metaPartition/load"
AdminDiagnoseMetaPartition = "/metaPartition/diagnose"
AdminDecommissionMetaPartition = "/metaPartition/decommission"
AdminAddMetaReplica = "/metaReplica/add"
AdminDeleteMetaReplica = "/metaReplica/delete"
// Operation response
GetMetaNodeTaskResponse = "/metaNode/response" // Method: 'POST', ContentType: 'application/json'
GetDataNodeTaskResponse = "/dataNode/response" // Method: 'POST', ContentType: 'application/json'
GetTopologyView = "/topo/get"
UpdateZone = "/zone/update"
GetAllZones = "/zone/list"
// Header keys
SkipOwnerValidation = "Skip-Owner-Validation"
ForceDelete = "Force-Delete"
// APIs for user management
UserCreate = "/user/create"
UserDelete = "/user/delete"
UserUpdate = "/user/update"
UserUpdatePolicy = "/user/updatePolicy"
UserRemovePolicy = "/user/removePolicy"
UserDeleteVolPolicy = "/user/deleteVolPolicy"
UserGetInfo = "/user/info"
UserGetAKInfo = "/user/akInfo"
UserTransferVol = "/user/transferVol"
UserList = "/user/list"
UsersOfVol = "/vol/users"
//graphql api for header
HeadAuthorized = "Authorization"
ParamAuthorized = "_authorization"
UserKey = "_user_key"
UserInfoKey = "_user_info_key"
)
const TimeFormat = "2006-01-02 15:04:05"
// HTTPReply uniform response structure
type HTTPReply struct {
Code int32 `json:"code"`
Msg string `json:"msg"`
Data interface{} `json:"data"`
}
// RegisterMetaNodeResp defines the response to register a meta node.
type RegisterMetaNodeResp struct {
ID uint64
}
// ClusterInfo defines the cluster infomation.
type ClusterInfo struct {
Cluster string
Ip string
MetaNodeDeleteBatchCount uint64
MetaNodeDeleteWorkerSleepMs uint64
DataNodeDeleteLimitRate uint64
DataNodeAutoRepairLimitRate uint64
}
// CreateDataPartitionRequest defines the request to create a data partition.
type CreateDataPartitionRequest struct {
PartitionType string
PartitionId uint64
PartitionSize int
VolumeId string
IsRandomWrite bool
Members []Peer
Hosts []string
CreateType int
}
// CreateDataPartitionResponse defines the response to the request of creating a data partition.
type CreateDataPartitionResponse struct {
PartitionId uint64
Status uint8
Result string
}
// DeleteDataPartitionRequest defines the request to delete a data partition.
type DeleteDataPartitionRequest struct {
DataPartitionType string
PartitionId uint64
PartitionSize int
}
// DeleteDataPartitionResponse defines the response to the request of deleting a data partition.
type DeleteDataPartitionResponse struct {
Status uint8
Result string
PartitionId uint64
}
// DataPartitionDecommissionRequest defines the request of decommissioning a data partition.
type DataPartitionDecommissionRequest struct {
PartitionId uint64
RemovePeer Peer
AddPeer Peer
}
// AddDataPartitionRaftMemberRequest defines the request of add raftMember a data partition.
type AddDataPartitionRaftMemberRequest struct {
PartitionId uint64
AddPeer Peer
}
// RemoveDataPartitionRaftMemberRequest defines the request of add raftMember a data partition.
type RemoveDataPartitionRaftMemberRequest struct {
PartitionId uint64
RemovePeer Peer
}
// AddMetaPartitionRaftMemberRequest defines the request of add raftMember a meta partition.
type AddMetaPartitionRaftMemberRequest struct {
PartitionId uint64
AddPeer Peer
}
// RemoveMetaPartitionRaftMemberRequest defines the request of add raftMember a meta partition.
type RemoveMetaPartitionRaftMemberRequest struct {
PartitionId uint64
RemovePeer Peer
}
// LoadDataPartitionRequest defines the request of loading a data partition.
type LoadDataPartitionRequest struct {
PartitionId uint64
}
// LoadDataPartitionResponse defines the response to the request of loading a data partition.
type LoadDataPartitionResponse struct {
PartitionId uint64
Used uint64
PartitionSnapshot []*File
Status uint8
PartitionStatus int
Result string
VolName string
}
// File defines the file struct.
type File struct {
Name string
Crc uint32
Size uint32
Modified int64
}
// LoadMetaPartitionMetricRequest defines the request of loading the meta partition metrics.
type LoadMetaPartitionMetricRequest struct {
PartitionID uint64
Start uint64
End uint64
}
// LoadMetaPartitionMetricResponse defines the response to the request of loading the meta partition metrics.
type LoadMetaPartitionMetricResponse struct {
Start uint64
End uint64
MaxInode uint64
Status uint8
Result string
}
// HeartBeatRequest define the heartbeat request.
type HeartBeatRequest struct {
CurrTime int64
MasterAddr string
}
// PartitionReport defines the partition report.
type PartitionReport struct {
VolName string
PartitionID uint64
PartitionStatus int
Total uint64
Used uint64
DiskPath string
IsLeader bool
ExtentCount int
NeedCompare bool
}
// DataNodeHeartbeatResponse defines the response to the data node heartbeat.
type DataNodeHeartbeatResponse struct {
Total uint64
Used uint64
Available uint64
TotalPartitionSize uint64 // volCnt * volsize
RemainingCapacity uint64 // remaining capacity to create partition
CreatedPartitionCnt uint32
MaxCapacity uint64 // maximum capacity to create partition
ZoneName string
PartitionReports []*PartitionReport
Status uint8
Result string
BadDisks []string
}
// MetaPartitionReport defines the meta partition report.
type MetaPartitionReport struct {
PartitionID uint64
Start uint64
End uint64
Status int
MaxInodeID uint64
IsLeader bool
VolName string
InodeCnt uint64
DentryCnt uint64
}
// MetaNodeHeartbeatResponse defines the response to the meta node heartbeat request.
type MetaNodeHeartbeatResponse struct {
ZoneName string
Total uint64
Used uint64
MetaPartitionReports []*MetaPartitionReport
Status uint8
Result string
}
// DeleteFileRequest defines the request to delete a file.
type DeleteFileRequest struct {
VolId uint64
Name string
}
// DeleteFileResponse defines the response to the request of deleting a file.
type DeleteFileResponse struct {
Status uint8
Result string
VolId uint64
Name string
}
// DeleteMetaPartitionRequest defines the request of deleting a meta partition.
type DeleteMetaPartitionRequest struct {
PartitionID uint64
}
// DeleteMetaPartitionResponse defines the response to the request of deleting a meta partition.
type DeleteMetaPartitionResponse struct {
PartitionID uint64
Status uint8
Result string
}
// UpdateMetaPartitionRequest defines the request to update a meta partition.
type UpdateMetaPartitionRequest struct {
PartitionID uint64
VolName string
Start uint64
End uint64
}
// UpdateMetaPartitionResponse defines the response to the request of updating the meta partition.
type UpdateMetaPartitionResponse struct {
PartitionID uint64
VolName string
End uint64
Status uint8
Result string
}
// MetaPartitionDecommissionRequest defines the request of decommissioning a meta partition.
type MetaPartitionDecommissionRequest struct {
PartitionID uint64
VolName string
RemovePeer Peer
AddPeer Peer
}
// MetaPartitionDecommissionResponse defines the response to the request of decommissioning a meta partition.
type MetaPartitionDecommissionResponse struct {
PartitionID uint64
VolName string
Status uint8
Result string
}
// MetaPartitionLoadRequest defines the request to load meta partition.
type MetaPartitionLoadRequest struct {
PartitionID uint64
}
// MetaPartitionLoadResponse defines the response to the request of loading meta partition.
type MetaPartitionLoadResponse struct {
PartitionID uint64
DoCompare bool
ApplyID uint64
MaxInode uint64
DentryCount uint64
InodeCount uint64
Addr string
}
// DataPartitionResponse defines the response from a data node to the master that is related to a data partition.
type DataPartitionResponse struct {
PartitionID uint64
Status int8
ReplicaNum uint8
Hosts []string
LeaderAddr string
Epoch uint64
IsRecover bool
}
// DataPartitionsView defines the view of a data partition
type DataPartitionsView struct {
DataPartitions []*DataPartitionResponse
}
func NewDataPartitionsView() (dataPartitionsView *DataPartitionsView) {
dataPartitionsView = new(DataPartitionsView)
dataPartitionsView.DataPartitions = make([]*DataPartitionResponse, 0)
return
}
// MetaPartitionView defines the view of a meta partition
type MetaPartitionView struct {
PartitionID uint64
Start uint64
End uint64
MaxInodeID uint64
InodeCount uint64
DentryCount uint64
IsRecover bool
Members []string
LeaderAddr string
Status int8
}
type OSSSecure struct {
AccessKey string
SecretKey string
}
// VolView defines the view of a volume
type VolView struct {
Name string
Owner string
Status uint8
FollowerRead bool
MetaPartitions []*MetaPartitionView
DataPartitions []*DataPartitionResponse
DomainOn bool
OSSSecure *OSSSecure
CreateTime int64
}
func (v *VolView) SetOwner(owner string) {
v.Owner = owner
}
func (v *VolView) SetOSSSecure(accessKey, secretKey string) {
v.OSSSecure = &OSSSecure{AccessKey: accessKey, SecretKey: secretKey}
}
func NewVolView(name string, status uint8, followerRead bool, createTime int64) (view *VolView) {
view = new(VolView)
view.Name = name
view.FollowerRead = followerRead
view.CreateTime = createTime
view.Status = status
view.MetaPartitions = make([]*MetaPartitionView, 0)
view.DataPartitions = make([]*DataPartitionResponse, 0)
return
}
func NewMetaPartitionView(partitionID, start, end uint64, status int8) (mpView *MetaPartitionView) {
mpView = new(MetaPartitionView)
mpView.PartitionID = partitionID
mpView.Start = start
mpView.End = end
mpView.Status = status
mpView.Members = make([]string, 0)
return
}
// SimpleVolView defines the simple view of a volume
type SimpleVolView struct {
ID uint64
Name string
Owner string
ZoneName string
DpReplicaNum uint8
MpReplicaNum uint8
InodeCount uint64
DentryCount uint64
MaxMetaPartitionID uint64
Status uint8
Capacity uint64 // GB
RwDpCnt int
MpCnt int
DpCnt int
FollowerRead bool
NeedToLowerReplica bool
Authenticate bool
CrossZone bool
DefaultPriority bool
DomainOn bool
CreateTime string
Description string
DpSelectorName string
DpSelectorParm string
DefaultZonePrior bool
}
type NodeSetInfo struct {
ID uint64
ZoneName string
Capacity int
DataUseRatio float64
MetaUseRatio float64
MetaUsed uint64
MetaTotal uint64
MetaNodes []*MetaNodeInfo
DataUsed uint64
DataTotal uint64
DataNodes []*DataNodeInfo
}
type SimpleNodeSetGrpInfo struct {
ID uint64
Status uint8
NodeSetInfo []NodeSetInfo
}
type SimpleNodeSetGrpInfoList struct {
DomainOn bool
DataRatioLimit float64
ZoneExcludeRatioLimit float64
NeedDomain bool
Status uint8
ExcludeZones []string
SimpleNodeSetGrpInfo []*SimpleNodeSetGrpInfo
}
// MasterAPIAccessResp defines the response for getting meta partition
type MasterAPIAccessResp struct {
APIResp APIAccessResp `json:"api_resp"`
Data []byte `json:"data"`
}
type VolInfo struct {
Name string
Owner string
CreateTime int64
Status uint8
TotalSize uint64
UsedSize uint64
}
func NewVolInfo(name, owner string, createTime int64, status uint8, totalSize, usedSize uint64) *VolInfo {
return &VolInfo{
Name: name,
Owner: owner,
CreateTime: createTime,
Status: status,
TotalSize: totalSize,
UsedSize: usedSize,
}
}
//ZoneView define the view of zone
type ZoneView struct {
Name string
Status string
NodeSet map[uint64]*NodeSetView
}
type NodeSetView struct {
DataNodeLen int
MetaNodeLen int
MetaNodes []NodeView
DataNodes []NodeView
}
// TopologyView provides the view of the topology view of the cluster
type TopologyView struct {
Zones []*ZoneView
}