Skip to content

Commit 6adbd32

Browse files
add admin APIs for Suspend,Resume,Drain,InfoPool
1 parent fe98cfa commit 6adbd32

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

pool-commands.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"encoding/json"
2222
"net/http"
23+
"net/url"
2324
"time"
2425
)
2526

@@ -48,6 +49,84 @@ type PoolInfo struct {
4849
Suspend bool `json:"suspend" msg:"sp"`
4950
}
5051

52+
// ResumePool - resume(allow) writes on previously suspended pool.
53+
func (adm *AdminClient) ResumePool(ctx context.Context, pool string) error {
54+
values := url.Values{}
55+
values.Set("pool", pool)
56+
resp, err := adm.executeMethod(ctx, http.MethodPost, requestData{
57+
relPath: adminAPIPrefix + "/pools/suspend", // POST <endpoint>/<admin-API>/pools/resume?pool=http://server{1...4}/disk{1...4}
58+
queryValues: values,
59+
})
60+
if err != nil {
61+
return err
62+
}
63+
defer closeResponse(resp)
64+
if resp.StatusCode != http.StatusOK {
65+
return httpRespToErrorResponse(resp)
66+
}
67+
return nil
68+
}
69+
70+
// SuspendPool - suspend(disallow) writes on a pool.
71+
func (adm *AdminClient) SuspendPool(ctx context.Context, pool string) error {
72+
values := url.Values{}
73+
values.Set("pool", pool)
74+
resp, err := adm.executeMethod(ctx, http.MethodPost, requestData{
75+
relPath: adminAPIPrefix + "/pools/suspend", // POST <endpoint>/<admin-API>/pools/suspend?pool=http://server{1...4}/disk{1...4}
76+
queryValues: values,
77+
})
78+
if err != nil {
79+
return err
80+
}
81+
defer closeResponse(resp)
82+
if resp.StatusCode != http.StatusOK {
83+
return httpRespToErrorResponse(resp)
84+
}
85+
return nil
86+
}
87+
88+
// DrainPool - starts moving data from specified pool to all other existing pools.
89+
// Draining if successfully started this function will return `nil`, to check
90+
// for on-going draining cycle use InfoPool.
91+
func (adm *AdminClient) DrainPool(ctx context.Context, pool string) error {
92+
values := url.Values{}
93+
values.Set("pool", pool)
94+
resp, err := adm.executeMethod(ctx, http.MethodPost, requestData{
95+
relPath: adminAPIPrefix + "/pools/drain", // POST <endpoint>/<admin-API>/pools/drain?pool=http://server{1...4}/disk{1...4}
96+
queryValues: values,
97+
})
98+
if err != nil {
99+
return err
100+
}
101+
defer closeResponse(resp)
102+
if resp.StatusCode != http.StatusOK {
103+
return httpRespToErrorResponse(resp)
104+
}
105+
return nil
106+
}
107+
108+
// InfoPool return current status about pool, reports any draining activity in progress
109+
// and elasped time.
110+
func (adm *AdminClient) InfoPool(ctx context.Context, pool string) (PoolInfo, error) {
111+
values := url.Values{}
112+
values.Set("pool", pool)
113+
resp, err := adm.executeMethod(ctx, http.MethodPost, requestData{
114+
relPath: adminAPIPrefix + "/pools/info", // GET <endpoint>/<admin-API>/pools/info?pool=http://server{1...4}/disk{1...4}
115+
queryValues: values,
116+
})
117+
if err != nil {
118+
return PoolInfo{}, err
119+
}
120+
defer closeResponse(resp)
121+
122+
var info PoolInfo
123+
if err = json.NewDecoder(resp.Body).Decode(&info); err != nil {
124+
return PoolInfo{}, err
125+
}
126+
127+
return info, nil
128+
}
129+
51130
// ListPools returns list of pools currently configured and being used
52131
// on the cluster.
53132
func (adm *AdminClient) ListPools(ctx context.Context) ([]Pool, error) {

0 commit comments

Comments
 (0)