-
Notifications
You must be signed in to change notification settings - Fork 0
/
decommission-commands.go
127 lines (115 loc) · 3.9 KB
/
decommission-commands.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
//
// MinIO Inc [madmin-go]
// Copyright (c) 2014-2024 MinIO.
// All rights reserved. No warranty, explicit or implicit, provided.
//
package madmin
import (
"context"
"encoding/json"
"net/http"
"net/url"
"time"
)
// PoolDecommissionInfo currently draining information
type PoolDecommissionInfo struct {
StartTime time.Time `json:"startTime"`
StartSize int64 `json:"startSize"`
TotalSize int64 `json:"totalSize"`
CurrentSize int64 `json:"currentSize"`
Complete bool `json:"complete"`
Failed bool `json:"failed"`
Canceled bool `json:"canceled"`
ObjectsDecommissioned int64 `json:"objectsDecommissioned"`
ObjectsDecommissionFailed int64 `json:"objectsDecommissionedFailed"`
BytesDone int64 `json:"bytesDecommissioned"`
BytesFailed int64 `json:"bytesDecommissionedFailed"`
}
// PoolStatus captures current pool status
type PoolStatus struct {
ID int `json:"id"`
CmdLine string `json:"cmdline"`
LastUpdate time.Time `json:"lastUpdate"`
Decommission *PoolDecommissionInfo `json:"decommissionInfo,omitempty"`
}
// DecommissionPool - starts moving data from specified pool to all other existing pools.
// Decommissioning if successfully started this function will return `nil`, to check
// for on-going draining cycle use StatusPool.
func (adm *AdminClient) DecommissionPool(ctx context.Context, pool string) error {
values := url.Values{}
values.Set("pool", pool)
resp, err := adm.executeMethod(ctx, http.MethodPost, requestData{
// POST <endpoint>/<admin-API>/pools/decommission?pool=http://server{1...4}/disk{1...4}
relPath: adminAPIPrefix + "/pools/decommission",
queryValues: values,
})
if err != nil {
return err
}
defer closeResponse(resp)
if resp.StatusCode != http.StatusOK {
return httpRespToErrorResponse(resp)
}
return nil
}
// CancelDecommissionPool - cancels an on-going decommissioning process,
// this automatically makes the pool available for writing once canceled.
func (adm *AdminClient) CancelDecommissionPool(ctx context.Context, pool string) error {
values := url.Values{}
values.Set("pool", pool)
resp, err := adm.executeMethod(ctx, http.MethodPost, requestData{
// POST <endpoint>/<admin-API>/pools/cancel?pool=http://server{1...4}/disk{1...4}
relPath: adminAPIPrefix + "/pools/cancel",
queryValues: values,
})
if err != nil {
return err
}
defer closeResponse(resp)
if resp.StatusCode != http.StatusOK {
return httpRespToErrorResponse(resp)
}
return nil
}
// StatusPool return current status about pool, reports any draining activity in progress
// and elapsed time.
func (adm *AdminClient) StatusPool(ctx context.Context, pool string) (PoolStatus, error) {
values := url.Values{}
values.Set("pool", pool)
resp, err := adm.executeMethod(ctx, http.MethodGet, requestData{
// GET <endpoint>/<admin-API>/pools/status?pool=http://server{1...4}/disk{1...4}
relPath: adminAPIPrefix + "/pools/status",
queryValues: values,
})
if err != nil {
return PoolStatus{}, err
}
defer closeResponse(resp)
if resp.StatusCode != http.StatusOK {
return PoolStatus{}, httpRespToErrorResponse(resp)
}
var info PoolStatus
if err = json.NewDecoder(resp.Body).Decode(&info); err != nil {
return PoolStatus{}, err
}
return info, nil
}
// ListPoolsStatus returns list of pools currently configured and being used
// on the cluster.
func (adm *AdminClient) ListPoolsStatus(ctx context.Context) ([]PoolStatus, error) {
resp, err := adm.executeMethod(ctx, http.MethodGet, requestData{
relPath: adminAPIPrefix + "/pools/list", // GET <endpoint>/<admin-API>/pools/list
})
if err != nil {
return nil, err
}
defer closeResponse(resp)
if resp.StatusCode != http.StatusOK {
return nil, httpRespToErrorResponse(resp)
}
var pools []PoolStatus
if err = json.NewDecoder(resp.Body).Decode(&pools); err != nil {
return nil, err
}
return pools, nil
}