mirror of https://github.com/minio/minio.git
admin: Add version to service Status API response (#3605)
Add server's version field to service status API: "version":{ "version":"DEVELOPMENT.GOGET", "commitID":"DEVELOPMENT.GOGET" }
This commit is contained in:
parent
e1f64141a2
commit
d1d89116f1
|
@ -46,6 +46,18 @@ const (
|
|||
mgmtDryRun mgmtQueryKey = "dry-run"
|
||||
)
|
||||
|
||||
// ServerVersion - server version
|
||||
type ServerVersion struct {
|
||||
Version string `json:"version"`
|
||||
CommitID string `json:"commitID"`
|
||||
}
|
||||
|
||||
// ServerStatus - contains the response of service status API
|
||||
type ServerStatus struct {
|
||||
StorageInfo StorageInfo `json:"storageInfo"`
|
||||
ServerVersion ServerVersion `json:"serverVersion"`
|
||||
}
|
||||
|
||||
// ServiceStatusHandler - GET /?service
|
||||
// HTTP header x-minio-operation: status
|
||||
// ----------
|
||||
|
@ -57,8 +69,20 @@ func (adminAPI adminAPIHandlers) ServiceStatusHandler(w http.ResponseWriter, r *
|
|||
writeErrorResponse(w, adminAPIErr, r.URL)
|
||||
return
|
||||
}
|
||||
|
||||
// Fetch storage backend information
|
||||
storageInfo := newObjectLayerFn().StorageInfo()
|
||||
jsonBytes, err := json.Marshal(storageInfo)
|
||||
// Fetch server version
|
||||
serverVersion := ServerVersion{Version: Version, CommitID: CommitID}
|
||||
|
||||
// Create API response
|
||||
serverStatus := ServerStatus{
|
||||
StorageInfo: storageInfo,
|
||||
ServerVersion: serverVersion,
|
||||
}
|
||||
|
||||
// Marshal API response
|
||||
jsonBytes, err := json.Marshal(serverStatus)
|
||||
if err != nil {
|
||||
writeErrorResponse(w, ErrInternalError, r.URL)
|
||||
errorIf(err, "Failed to marshal storage info into json.")
|
||||
|
|
|
@ -227,8 +227,11 @@ func testServicesCmdHandler(cmd cmdType, args map[string]interface{}, t *testing
|
|||
adminTestBed.mux.ServeHTTP(rec, req)
|
||||
|
||||
if cmd == statusCmd {
|
||||
expectedInfo := newObjectLayerFn().StorageInfo()
|
||||
receivedInfo := StorageInfo{}
|
||||
expectedInfo := ServerStatus{
|
||||
StorageInfo: newObjectLayerFn().StorageInfo(),
|
||||
ServerVersion: ServerVersion{Version: Version, CommitID: CommitID},
|
||||
}
|
||||
receivedInfo := ServerStatus{}
|
||||
if jsonErr := json.Unmarshal(rec.Body.Bytes(), &receivedInfo); jsonErr != nil {
|
||||
t.Errorf("Failed to unmarshal StorageInfo - %v", jsonErr)
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
* Status
|
||||
- GET /?service
|
||||
- x-minio-operation: status
|
||||
- Response: On success 200, return json formatted StorageInfo object.
|
||||
- Response: On success 200, return json formatted object which contains StorageInfo and ServerVersion structures
|
||||
|
||||
* SetCredentials
|
||||
- GET /?service
|
||||
|
|
|
@ -74,9 +74,11 @@ Fetch service status, replies disk space used, backend type and total disks offl
|
|||
|
||||
| Param | Type | Description |
|
||||
|---|---|---|
|
||||
|`st.Total` | _int64_ | Total disk space. |
|
||||
|`st.Free` | _int64_ | Free disk space. |
|
||||
|`st.Backend`| _struct{}_ | Represents backend type embedded structure. |
|
||||
|`st.ServerVersion.Version` | _string_ | Server version. |
|
||||
|`st.ServerVersion.CommitID` | _string_ | Server commit id. |
|
||||
|`st.StorageInfo.Total` | _int64_ | Total disk space. |
|
||||
|`st.StorageInfo.Free` | _int64_ | Free disk space. |
|
||||
|`st.StorageInfo.Backend`| _struct{}_ | Represents backend type embedded structure. |
|
||||
|
||||
| Param | Type | Description |
|
||||
|---|---|---|
|
||||
|
|
|
@ -41,8 +41,8 @@ const (
|
|||
// Add your own backend.
|
||||
)
|
||||
|
||||
// ServiceStatusMetadata - represents total capacity of underlying storage.
|
||||
type ServiceStatusMetadata struct {
|
||||
// StorageInfo - represents total capacity of underlying storage.
|
||||
type StorageInfo struct {
|
||||
// Total disk space.
|
||||
Total int64
|
||||
// Free available disk space.
|
||||
|
@ -60,10 +60,23 @@ type ServiceStatusMetadata struct {
|
|||
}
|
||||
}
|
||||
|
||||
// ServerVersion - server version
|
||||
type ServerVersion struct {
|
||||
Version string `json:"version"`
|
||||
CommitID string `json:"commitID"`
|
||||
}
|
||||
|
||||
// ServiceStatusMetadata - contains the response of service status API
|
||||
type ServiceStatusMetadata struct {
|
||||
StorageInfo StorageInfo `json:"storageInfo"`
|
||||
ServerVersion ServerVersion `json:"serverVersion"`
|
||||
}
|
||||
|
||||
// ServiceStatus - Connect to a minio server and call Service Status Management API
|
||||
// to fetch server's storage information represented by ServiceStatusMetadata structure
|
||||
func (adm *AdminClient) ServiceStatus() (ServiceStatusMetadata, error) {
|
||||
|
||||
// Prepare web service request
|
||||
reqData := requestData{}
|
||||
reqData.queryValues = make(url.Values)
|
||||
reqData.queryValues.Set("service", "")
|
||||
|
@ -72,29 +85,30 @@ func (adm *AdminClient) ServiceStatus() (ServiceStatusMetadata, error) {
|
|||
|
||||
// Execute GET on bucket to list objects.
|
||||
resp, err := adm.executeMethod("GET", reqData)
|
||||
|
||||
defer closeResponse(resp)
|
||||
if err != nil {
|
||||
return ServiceStatusMetadata{}, err
|
||||
}
|
||||
|
||||
// Check response http status code
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return ServiceStatusMetadata{}, errors.New("Got HTTP Status: " + resp.Status)
|
||||
}
|
||||
|
||||
// Unmarshal the server's json response
|
||||
var serviceStatus ServiceStatusMetadata
|
||||
|
||||
respBytes, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return ServiceStatusMetadata{}, err
|
||||
}
|
||||
|
||||
var storageInfo ServiceStatusMetadata
|
||||
|
||||
err = json.Unmarshal(respBytes, &storageInfo)
|
||||
err = json.Unmarshal(respBytes, &serviceStatus)
|
||||
if err != nil {
|
||||
return ServiceStatusMetadata{}, err
|
||||
}
|
||||
|
||||
return storageInfo, nil
|
||||
return serviceStatus, nil
|
||||
}
|
||||
|
||||
// ServiceRestart - Call Service Restart API to restart a specified Minio server
|
||||
|
|
Loading…
Reference in New Issue