|
|
@ -53,9 +53,10 @@ type mgmtQueryKey string |
|
|
|
// Only valid query params for mgmt admin APIs.
|
|
|
|
// Only valid query params for mgmt admin APIs.
|
|
|
|
const ( |
|
|
|
const ( |
|
|
|
mgmtBucket mgmtQueryKey = "bucket" |
|
|
|
mgmtBucket mgmtQueryKey = "bucket" |
|
|
|
mgmtPrefix mgmtQueryKey = "prefix" |
|
|
|
mgmtPrefix = "prefix" |
|
|
|
mgmtClientToken mgmtQueryKey = "clientToken" |
|
|
|
mgmtClientToken = "clientToken" |
|
|
|
mgmtForceStart mgmtQueryKey = "forceStart" |
|
|
|
mgmtForceStart = "forceStart" |
|
|
|
|
|
|
|
mgmtForceStop = "forceStop" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
var ( |
|
|
@ -402,7 +403,7 @@ func (a adminAPIHandlers) DownloadProfilingHandler(w http.ResponseWriter, r *htt |
|
|
|
|
|
|
|
|
|
|
|
// extractHealInitParams - Validates params for heal init API.
|
|
|
|
// extractHealInitParams - Validates params for heal init API.
|
|
|
|
func extractHealInitParams(r *http.Request) (bucket, objPrefix string, |
|
|
|
func extractHealInitParams(r *http.Request) (bucket, objPrefix string, |
|
|
|
hs madmin.HealOpts, clientToken string, forceStart bool, |
|
|
|
hs madmin.HealOpts, clientToken string, forceStart bool, forceStop bool, |
|
|
|
err APIErrorCode) { |
|
|
|
err APIErrorCode) { |
|
|
|
|
|
|
|
|
|
|
|
vars := mux.Vars(r) |
|
|
|
vars := mux.Vars(r) |
|
|
@ -433,7 +434,9 @@ func extractHealInitParams(r *http.Request) (bucket, objPrefix string, |
|
|
|
if _, ok := qParms[string(mgmtForceStart)]; ok { |
|
|
|
if _, ok := qParms[string(mgmtForceStart)]; ok { |
|
|
|
forceStart = true |
|
|
|
forceStart = true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if _, ok := qParms[string(mgmtForceStop)]; ok { |
|
|
|
|
|
|
|
forceStop = true |
|
|
|
|
|
|
|
} |
|
|
|
// ignore body if clientToken is provided
|
|
|
|
// ignore body if clientToken is provided
|
|
|
|
if clientToken == "" { |
|
|
|
if clientToken == "" { |
|
|
|
jerr := json.NewDecoder(r.Body).Decode(&hs) |
|
|
|
jerr := json.NewDecoder(r.Body).Decode(&hs) |
|
|
@ -484,7 +487,7 @@ func (a adminAPIHandlers) HealHandler(w http.ResponseWriter, r *http.Request) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bucket, objPrefix, hs, clientToken, forceStart, apiErr := extractHealInitParams(r) |
|
|
|
bucket, objPrefix, hs, clientToken, forceStart, forceStop, apiErr := extractHealInitParams(r) |
|
|
|
if apiErr != ErrNone { |
|
|
|
if apiErr != ErrNone { |
|
|
|
writeErrorResponseJSON(w, apiErr, r.URL) |
|
|
|
writeErrorResponseJSON(w, apiErr, r.URL) |
|
|
|
return |
|
|
|
return |
|
|
@ -518,13 +521,35 @@ func (a adminAPIHandlers) HealHandler(w http.ResponseWriter, r *http.Request) { |
|
|
|
w.Write([]byte("\n\r")) |
|
|
|
w.Write([]byte("\n\r")) |
|
|
|
w.(http.Flusher).Flush() |
|
|
|
w.(http.Flusher).Flush() |
|
|
|
case hr := <-respCh: |
|
|
|
case hr := <-respCh: |
|
|
|
switch { |
|
|
|
switch hr.errCode { |
|
|
|
case hr.errCode == ErrNone: |
|
|
|
case ErrNone: |
|
|
|
|
|
|
|
if started { |
|
|
|
|
|
|
|
w.Write(hr.respBytes) |
|
|
|
|
|
|
|
w.(http.Flusher).Flush() |
|
|
|
|
|
|
|
} else { |
|
|
|
writeSuccessResponseJSON(w, hr.respBytes) |
|
|
|
writeSuccessResponseJSON(w, hr.respBytes) |
|
|
|
case hr.errBody == "": |
|
|
|
} |
|
|
|
writeErrorResponseJSON(w, hr.errCode, r.URL) |
|
|
|
|
|
|
|
default: |
|
|
|
default: |
|
|
|
writeCustomErrorResponseJSON(w, hr.errCode, hr.errBody, r.URL) |
|
|
|
apiError := getAPIError(hr.errCode) |
|
|
|
|
|
|
|
var errorRespJSON []byte |
|
|
|
|
|
|
|
if hr.errBody == "" { |
|
|
|
|
|
|
|
errorRespJSON = encodeResponseJSON(getAPIErrorResponse(apiError, r.URL.Path, w.Header().Get(responseRequestIDKey))) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
errorRespJSON = encodeResponseJSON(APIErrorResponse{ |
|
|
|
|
|
|
|
Code: apiError.Code, |
|
|
|
|
|
|
|
Message: hr.errBody, |
|
|
|
|
|
|
|
Resource: r.URL.Path, |
|
|
|
|
|
|
|
RequestID: w.Header().Get(responseRequestIDKey), |
|
|
|
|
|
|
|
HostID: "3L137", |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if !started { |
|
|
|
|
|
|
|
setCommonHeaders(w) |
|
|
|
|
|
|
|
w.Header().Set("Content-Type", string(mimeJSON)) |
|
|
|
|
|
|
|
w.WriteHeader(apiError.HTTPStatusCode) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
w.Write(errorRespJSON) |
|
|
|
|
|
|
|
w.(http.Flusher).Flush() |
|
|
|
} |
|
|
|
} |
|
|
|
break forLoop |
|
|
|
break forLoop |
|
|
|
} |
|
|
|
} |
|
|
@ -535,34 +560,61 @@ func (a adminAPIHandlers) HealHandler(w http.ResponseWriter, r *http.Request) { |
|
|
|
info := objLayer.StorageInfo(ctx) |
|
|
|
info := objLayer.StorageInfo(ctx) |
|
|
|
numDisks := info.Backend.OfflineDisks + info.Backend.OnlineDisks |
|
|
|
numDisks := info.Backend.OfflineDisks + info.Backend.OnlineDisks |
|
|
|
|
|
|
|
|
|
|
|
if clientToken == "" { |
|
|
|
healPath := pathJoin(bucket, objPrefix) |
|
|
|
// Not a status request
|
|
|
|
if clientToken == "" && !forceStart && !forceStop { |
|
|
|
nh := newHealSequence(bucket, objPrefix, handlers.GetSourceIP(r), |
|
|
|
nh, exists := globalAllHealState.getHealSequence(healPath) |
|
|
|
numDisks, hs, forceStart) |
|
|
|
if exists && !nh.hasEnded() && len(nh.currentStatus.Items) > 0 { |
|
|
|
|
|
|
|
b, err := json.Marshal(madmin.HealStartSuccess{ |
|
|
|
|
|
|
|
ClientToken: nh.clientToken, |
|
|
|
|
|
|
|
ClientAddress: nh.clientAddress, |
|
|
|
|
|
|
|
StartTime: nh.startTime, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
logger.LogIf(context.Background(), err) |
|
|
|
|
|
|
|
writeErrorResponse(w, toAPIErrorCode(err), r.URL) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Client token not specified but a heal sequence exists on a path,
|
|
|
|
|
|
|
|
// Send the token back to client.
|
|
|
|
|
|
|
|
writeSuccessResponseJSON(w, b) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if clientToken != "" && !forceStart && !forceStop { |
|
|
|
|
|
|
|
// Since clientToken is given, fetch heal status from running
|
|
|
|
|
|
|
|
// heal sequence.
|
|
|
|
|
|
|
|
respBytes, errCode := globalAllHealState.PopHealStatusJSON( |
|
|
|
|
|
|
|
healPath, clientToken) |
|
|
|
|
|
|
|
if errCode != ErrNone { |
|
|
|
|
|
|
|
writeErrorResponseJSON(w, errCode, r.URL) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
writeSuccessResponseJSON(w, respBytes) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
respCh := make(chan healResp) |
|
|
|
respCh := make(chan healResp) |
|
|
|
|
|
|
|
switch { |
|
|
|
|
|
|
|
case forceStop: |
|
|
|
|
|
|
|
go func() { |
|
|
|
|
|
|
|
respBytes, errCode := globalAllHealState.stopHealSequence(healPath) |
|
|
|
|
|
|
|
hr := healResp{respBytes: respBytes, errCode: errCode} |
|
|
|
|
|
|
|
respCh <- hr |
|
|
|
|
|
|
|
}() |
|
|
|
|
|
|
|
case clientToken == "": |
|
|
|
|
|
|
|
nh := newHealSequence(bucket, objPrefix, handlers.GetSourceIP(r), numDisks, hs, forceStart) |
|
|
|
go func() { |
|
|
|
go func() { |
|
|
|
respBytes, errCode, errMsg := globalAllHealState.LaunchNewHealSequence(nh) |
|
|
|
respBytes, errCode, errMsg := globalAllHealState.LaunchNewHealSequence(nh) |
|
|
|
hr := healResp{respBytes, errCode, errMsg} |
|
|
|
hr := healResp{respBytes, errCode, errMsg} |
|
|
|
respCh <- hr |
|
|
|
respCh <- hr |
|
|
|
}() |
|
|
|
}() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Due to the force-starting functionality, the Launch
|
|
|
|
// Due to the force-starting functionality, the Launch
|
|
|
|
// call above can take a long time - to keep the
|
|
|
|
// call above can take a long time - to keep the
|
|
|
|
// connection alive, we start sending whitespace
|
|
|
|
// connection alive, we start sending whitespace
|
|
|
|
keepConnLive(w, respCh) |
|
|
|
keepConnLive(w, respCh) |
|
|
|
} else { |
|
|
|
|
|
|
|
// Since clientToken is given, fetch heal status from running
|
|
|
|
|
|
|
|
// heal sequence.
|
|
|
|
|
|
|
|
path := bucket + "/" + objPrefix |
|
|
|
|
|
|
|
respBytes, errCode := globalAllHealState.PopHealStatusJSON( |
|
|
|
|
|
|
|
path, clientToken) |
|
|
|
|
|
|
|
if errCode != ErrNone { |
|
|
|
|
|
|
|
writeErrorResponseJSON(w, errCode, r.URL) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
writeSuccessResponseJSON(w, respBytes) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetConfigHandler - GET /minio/admin/v1/config
|
|
|
|
// GetConfigHandler - GET /minio/admin/v1/config
|
|
|
|