@@ -24,6 +24,7 @@ import (
24
24
"github.com/dustin/go-humanize"
25
25
"github.com/go-openapi/runtime/middleware"
26
26
"github.com/minio/console/api/operations"
27
+ "github.com/minio/console/api/operations/tiering"
27
28
tieringApi "github.com/minio/console/api/operations/tiering"
28
29
"github.com/minio/console/models"
29
30
"github.com/minio/madmin-go/v3"
@@ -38,6 +39,13 @@ func registerAdminTiersHandlers(api *operations.ConsoleAPI) {
38
39
}
39
40
return tieringApi .NewTiersListOK ().WithPayload (tierList )
40
41
})
42
+ api .TieringTiersListNamesHandler = tiering .TiersListNamesHandlerFunc (func (params tiering.TiersListNamesParams , session * models.Principal ) middleware.Responder {
43
+ tierList , err := getTiersNameResponse (session , params )
44
+ if err != nil {
45
+ return tieringApi .NewTiersListDefault (err .Code ).WithPayload (err .APIError )
46
+ }
47
+ return tieringApi .NewTiersListNamesOK ().WithPayload (tierList )
48
+ })
41
49
// add a new tiers
42
50
api .TieringAddTierHandler = tieringApi .AddTierHandlerFunc (func (params tieringApi.AddTierParams , session * models.Principal ) middleware.Responder {
43
51
err := getAddTierResponse (session , params )
@@ -72,33 +80,36 @@ func registerAdminTiersHandlers(api *operations.ConsoleAPI) {
72
80
})
73
81
}
74
82
75
- // getNotificationEndpoints invokes admin info and returns a list of notification endpoints
83
+ // getTiers returns a list of tiers with their stats
76
84
func getTiers (ctx context.Context , client MinioAdmin ) (* models.TierListResponse , error ) {
77
85
tiers , err := client .listTiers (ctx )
78
86
if err != nil {
79
87
return nil , err
80
88
}
81
- tiersInfo , err := client .tierStats (ctx )
89
+
90
+ tierStatsInfo , err := client .tierStats (ctx )
82
91
if err != nil {
83
92
return nil , err
84
93
}
94
+ tiersStatsMap := make (map [string ]madmin.TierStats , len (tierStatsInfo ))
95
+ for _ , stat := range tierStatsInfo {
96
+ tiersStatsMap [stat .Name ] = stat .Stats
97
+ }
98
+
85
99
var tiersList []* models.Tier
86
100
for _ , tierData := range tiers {
87
-
88
101
// Default Tier Stats
89
- stats := madmin.TierStats {
102
+ tierStats := madmin.TierStats {
90
103
NumObjects : 0 ,
91
104
NumVersions : 0 ,
92
105
TotalSize : 0 ,
93
106
}
94
-
95
- // We look for the correct tier stats & set the values.
96
- for _ , stat := range tiersInfo {
97
- if stat .Name == tierData .Name {
98
- stats = stat .Stats
99
- break
100
- }
107
+ if stats , ok := tiersStatsMap [tierData .Name ]; ok {
108
+ tierStats = stats
101
109
}
110
+
111
+ status := client .verifyTierStatus (ctx , tierData .Name ) == nil
112
+
102
113
switch tierData .Type {
103
114
case madmin .S3 :
104
115
tiersList = append (tiersList , & models.Tier {
@@ -112,11 +123,11 @@ func getTiers(ctx context.Context, client MinioAdmin) (*models.TierListResponse,
112
123
Region : tierData .S3 .Region ,
113
124
Secretkey : tierData .S3 .SecretKey ,
114
125
Storageclass : tierData .S3 .StorageClass ,
115
- Usage : humanize .IBytes (stats .TotalSize ),
116
- Objects : strconv .Itoa (stats .NumObjects ),
117
- Versions : strconv .Itoa (stats .NumVersions ),
126
+ Usage : humanize .IBytes (tierStats .TotalSize ),
127
+ Objects : strconv .Itoa (tierStats .NumObjects ),
128
+ Versions : strconv .Itoa (tierStats .NumVersions ),
118
129
},
119
- Status : client . verifyTierStatus ( ctx , tierData . Name ) == nil ,
130
+ Status : status ,
120
131
})
121
132
case madmin .MinIO :
122
133
tiersList = append (tiersList , & models.Tier {
@@ -129,11 +140,11 @@ func getTiers(ctx context.Context, client MinioAdmin) (*models.TierListResponse,
129
140
Prefix : tierData .MinIO .Prefix ,
130
141
Region : tierData .MinIO .Region ,
131
142
Secretkey : tierData .MinIO .SecretKey ,
132
- Usage : humanize .IBytes (stats .TotalSize ),
133
- Objects : strconv .Itoa (stats .NumObjects ),
134
- Versions : strconv .Itoa (stats .NumVersions ),
143
+ Usage : humanize .IBytes (tierStats .TotalSize ),
144
+ Objects : strconv .Itoa (tierStats .NumObjects ),
145
+ Versions : strconv .Itoa (tierStats .NumVersions ),
135
146
},
136
- Status : client . verifyTierStatus ( ctx , tierData . Name ) == nil ,
147
+ Status : status ,
137
148
})
138
149
case madmin .GCS :
139
150
tiersList = append (tiersList , & models.Tier {
@@ -145,11 +156,11 @@ func getTiers(ctx context.Context, client MinioAdmin) (*models.TierListResponse,
145
156
Name : tierData .Name ,
146
157
Prefix : tierData .GCS .Prefix ,
147
158
Region : tierData .GCS .Region ,
148
- Usage : humanize .IBytes (stats .TotalSize ),
149
- Objects : strconv .Itoa (stats .NumObjects ),
150
- Versions : strconv .Itoa (stats .NumVersions ),
159
+ Usage : humanize .IBytes (tierStats .TotalSize ),
160
+ Objects : strconv .Itoa (tierStats .NumObjects ),
161
+ Versions : strconv .Itoa (tierStats .NumVersions ),
151
162
},
152
- Status : client . verifyTierStatus ( ctx , tierData . Name ) == nil ,
163
+ Status : status ,
153
164
})
154
165
case madmin .Azure :
155
166
tiersList = append (tiersList , & models.Tier {
@@ -162,16 +173,16 @@ func getTiers(ctx context.Context, client MinioAdmin) (*models.TierListResponse,
162
173
Name : tierData .Name ,
163
174
Prefix : tierData .Azure .Prefix ,
164
175
Region : tierData .Azure .Region ,
165
- Usage : humanize .IBytes (stats .TotalSize ),
166
- Objects : strconv .Itoa (stats .NumObjects ),
167
- Versions : strconv .Itoa (stats .NumVersions ),
176
+ Usage : humanize .IBytes (tierStats .TotalSize ),
177
+ Objects : strconv .Itoa (tierStats .NumObjects ),
178
+ Versions : strconv .Itoa (tierStats .NumVersions ),
168
179
},
169
- Status : client . verifyTierStatus ( ctx , tierData . Name ) == nil ,
180
+ Status : status ,
170
181
})
171
182
case madmin .Unsupported :
172
183
tiersList = append (tiersList , & models.Tier {
173
184
Type : models .TierTypeUnsupported ,
174
- Status : client . verifyTierStatus ( ctx , tierData . Name ) == nil ,
185
+ Status : status ,
175
186
})
176
187
}
177
188
}
@@ -200,6 +211,42 @@ func getTiersResponse(session *models.Principal, params tieringApi.TiersListPara
200
211
return tiersResp , nil
201
212
}
202
213
214
+ // getTiersNameResponse returns a response with a list of tiers' names
215
+ func getTiersNameResponse (session * models.Principal , params tieringApi.TiersListNamesParams ) (* models.TiersNameListResponse , * CodedAPIError ) {
216
+ ctx , cancel := context .WithCancel (params .HTTPRequest .Context ())
217
+ defer cancel ()
218
+ mAdmin , err := NewMinioAdminClient (params .HTTPRequest .Context (), session )
219
+ if err != nil {
220
+ return nil , ErrorWithContext (ctx , err )
221
+ }
222
+ // create a minioClient interface implementation
223
+ // defining the client to be used
224
+ adminClient := AdminClient {Client : mAdmin }
225
+ // serialize output
226
+ tiersResp , err := getTiersName (ctx , adminClient )
227
+ if err != nil {
228
+ return nil , ErrorWithContext (ctx , err )
229
+ }
230
+ return tiersResp , nil
231
+ }
232
+
233
+ // getTiersName fetches listTiers and returns a list of the tiers' names
234
+ func getTiersName (ctx context.Context , client MinioAdmin ) (* models.TiersNameListResponse , error ) {
235
+ tiers , err := client .listTiers (ctx )
236
+ if err != nil {
237
+ return nil , err
238
+ }
239
+
240
+ tiersNameList := make ([]string , len (tiers ))
241
+ for i , tierData := range tiers {
242
+ tiersNameList [i ] = tierData .Name
243
+ }
244
+
245
+ return & models.TiersNameListResponse {
246
+ Items : tiersNameList ,
247
+ }, nil
248
+ }
249
+
203
250
func addTier (ctx context.Context , client MinioAdmin , params * tieringApi.AddTierParams ) error {
204
251
var cfg * madmin.TierConfig
205
252
var err error
0 commit comments