@@ -156,50 +156,66 @@ func GetExternalType(filePath string, mountedData []DiskInfo) string {
156
156
157
157
func MountPathIncluster (r * http.Request ) (map [string ]interface {}, error ) {
158
158
externalType := r .URL .Query ().Get ("external_type" )
159
- var url = ""
159
+ var urls [] string
160
160
if externalType == "smb" {
161
- url = "http://" + TerminusdHost + "/command/mount-samba"
161
+ urls = [] string { "http://" + TerminusdHost + "/command/v2/ mount-samba" , "http://" + TerminusdHost + "/command/mount-samba" }
162
162
} else {
163
163
return nil , fmt .Errorf ("Unsupported external type: %s" , externalType )
164
164
}
165
165
166
- bodyBytes , err := ioutil .ReadAll (r .Body )
167
- if err != nil {
168
- return nil , err
169
- }
170
- r .Body = ioutil .NopCloser (bytes .NewBuffer (bodyBytes ))
166
+ for _ , url := range urls {
167
+ bodyBytes , err := ioutil .ReadAll (r .Body )
168
+ if err != nil {
169
+ return nil , err
170
+ }
171
+ r .Body = ioutil .NopCloser (bytes .NewBuffer (bodyBytes ))
171
172
172
- headers := r .Header .Clone ()
173
- headers .Set ("Content-Type" , "application/json" )
174
- headers .Set ("X-Signature" , "temp_signature" )
173
+ headers := r .Header .Clone ()
174
+ headers .Set ("Content-Type" , "application/json" )
175
+ headers .Set ("X-Signature" , "temp_signature" )
175
176
176
- client := & http.Client {}
177
- req , err := http .NewRequest ("POST" , url , bytes .NewReader (bodyBytes ))
178
- if err != nil {
179
- return nil , err
180
- }
181
- req .Header = headers
177
+ client := & http.Client {}
178
+ req , err := http .NewRequest ("POST" , url , bytes .NewReader (bodyBytes ))
179
+ if err != nil {
180
+ return nil , err
181
+ }
182
+ req .Header = headers
182
183
183
- resp , err := client .Do (req )
184
- if err != nil {
185
- return nil , err
186
- }
187
- if resp != nil {
188
- defer resp .Body .Close ()
189
- }
184
+ resp , err := client .Do (req )
185
+ if err != nil {
186
+ return nil , err
187
+ }
190
188
191
- respBody , err := ioutil . ReadAll ( resp . Body )
192
- if err != nil {
193
- return nil , err
194
- }
189
+ if resp == nil {
190
+ klog . Errorf ( "not get response from %s" , url )
191
+ continue
192
+ }
195
193
196
- var responseMap map [string ]interface {}
197
- err = json .Unmarshal (respBody , & responseMap )
198
- if err != nil {
199
- return nil , err
200
- }
194
+ respBody , err := ioutil .ReadAll (resp .Body )
195
+ if err != nil {
196
+ return nil , err
197
+ }
201
198
202
- return responseMap , nil
199
+ var responseMap map [string ]interface {}
200
+ err = json .Unmarshal (respBody , & responseMap )
201
+ if err != nil {
202
+ return nil , err
203
+ }
204
+
205
+ err = resp .Body .Close ()
206
+ if err != nil {
207
+ return responseMap , err
208
+ }
209
+
210
+ if resp .StatusCode >= 400 {
211
+ klog .Errorf ("Failed to mount by %s to %s" , url , TerminusdHost )
212
+ klog .Infof ("response status: %d, response body: %v" , resp .Status , responseMap )
213
+ continue
214
+ }
215
+
216
+ return responseMap , nil
217
+ }
218
+ return nil , fmt .Errorf ("failed to mount samba" )
203
219
}
204
220
205
221
func UnmountPathIncluster (r * http.Request , path string ) (map [string ]interface {}, error ) {
0 commit comments