Merge pull request #79273 from humblec/heketi-update

Update heketi vendor dependency to v9.0.0
This commit is contained in:
Kubernetes Prow Robot
2019-06-22 22:56:07 -07:00
committed by GitHub
8 changed files with 264 additions and 26 deletions

View File

@@ -13,6 +13,7 @@ go_library(
"logging.go",
"node.go",
"operations.go",
"state.go",
"topology.go",
"volume.go",
],

View File

@@ -50,3 +50,35 @@ func (c *Client) DbDump() (string, error) {
respJSON := string(respBytes)
return respJSON, nil
}
// DbCheck provides a JSON summary of the DB check operation
func (c *Client) DbCheck() (string, error) {
req, err := http.NewRequest("GET", c.host+"/db/check", nil)
if err != nil {
return "", err
}
// Set token
err = c.setToken(req)
if err != nil {
return "", err
}
// Send request
r, err := c.do(req)
if err != nil {
return "", err
}
defer r.Body.Close()
if r.StatusCode != http.StatusOK {
return "", utils.GetErrorFromResponse(r)
}
respBytes, err := ioutil.ReadAll(r.Body)
if err != nil {
return "", err
}
respJSON := string(respBytes)
return respJSON, nil
}

View File

@@ -13,7 +13,10 @@
package client
import (
"bytes"
"encoding/json"
"net/http"
"time"
"github.com/heketi/heketi/pkg/glusterfs/api"
"github.com/heketi/heketi/pkg/utils"
@@ -37,6 +40,9 @@ func (c *Client) OperationsInfo() (*api.OperationsInfo, error) {
if err != nil {
return nil, err
}
if r.StatusCode != http.StatusOK {
return nil, utils.GetErrorFromResponse(r)
}
var oi api.OperationsInfo
err = utils.GetJsonFromResponse(r, &oi)
if err != nil {
@@ -44,3 +50,113 @@ func (c *Client) OperationsInfo() (*api.OperationsInfo, error) {
}
return &oi, nil
}
func (c *Client) PendingOperationList() (*api.PendingOperationListResponse, error) {
req, err := http.NewRequest("GET", c.host+"/operations/pending", nil)
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/json")
// Set token
err = c.setToken(req)
if err != nil {
return nil, err
}
// Send request
r, err := c.do(req)
if err != nil {
return nil, err
}
if r.StatusCode != http.StatusOK {
return nil, utils.GetErrorFromResponse(r)
}
var ol api.PendingOperationListResponse
err = utils.GetJsonFromResponse(r, &ol)
if err != nil {
return nil, err
}
return &ol, nil
}
func (c *Client) PendingOperationDetails(
id string) (*api.PendingOperationDetails, error) {
req, err := http.NewRequest("GET", c.host+"/operations/pending/"+id, nil)
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/json")
// Set token
err = c.setToken(req)
if err != nil {
return nil, err
}
// Send request
r, err := c.do(req)
if err != nil {
return nil, err
}
if r.StatusCode != http.StatusOK {
return nil, utils.GetErrorFromResponse(r)
}
var pd api.PendingOperationDetails
err = utils.GetJsonFromResponse(r, &pd)
if err != nil {
return nil, err
}
return &pd, nil
}
func (c *Client) PendingOperationCleanUp(
request *api.PendingOperationsCleanRequest) error {
buffer, err := json.Marshal(request)
if err != nil {
return err
}
req, err := http.NewRequest("POST",
c.host+"/operations/pending/cleanup",
bytes.NewBuffer(buffer))
if err != nil {
return err
}
req.Header.Set("Content-Type", "application/json")
// Set token
err = c.setToken(req)
if err != nil {
return err
}
r, err := c.do(req)
if err != nil {
return err
}
defer r.Body.Close()
switch r.StatusCode {
case http.StatusAccepted: // expected
case http.StatusOK:
return nil
default:
return utils.GetErrorFromResponse(r)
}
// NOTE: I (jjm) wanted this to truly async at first. But in
// order to not deviate from the current model too much
// AND that the rest async framework in heketi needs to be
// polled in order to remove things from its map, the traditional
// poll server after request behavior is retained here.
r, err = c.waitForResponseWithTimer(r, time.Second)
if err != nil {
return err
}
if r.StatusCode != http.StatusNoContent {
return utils.GetErrorFromResponse(r)
}
return nil
}

View File

@@ -0,0 +1,52 @@
//
// Copyright (c) 2018 The heketi Authors
//
// This file is licensed to you under your choice of the GNU Lesser
// General Public License, version 3 or any later version (LGPLv3 or
// later), as published by the Free Software Foundation,
// or under the Apache License, Version 2.0 <LICENSE-APACHE2 or
// http://www.apache.org/licenses/LICENSE-2.0>.
//
// You may not use this file except in compliance with those terms.
//
package client
import (
"io/ioutil"
"net/http"
"github.com/heketi/heketi/pkg/utils"
)
// StateExamineGluster provides a comparision of DB and Gluster
func (c *Client) StateExamineGluster() (string, error) {
req, err := http.NewRequest("GET", c.host+"/internal/state/examine/gluster", nil)
if err != nil {
return "", err
}
// Set token
err = c.setToken(req)
if err != nil {
return "", err
}
// Send request
r, err := c.do(req)
if err != nil {
return "", err
}
defer r.Body.Close()
if r.StatusCode != http.StatusOK {
return "", utils.GetErrorFromResponse(r)
}
respBytes, err := ioutil.ReadAll(r.Body)
if err != nil {
return "", err
}
respJSON := string(respBytes)
return respJSON, nil
}

View File

@@ -226,8 +226,10 @@ type ClusterFlags struct {
type Cluster struct {
Volumes []VolumeInfoResponse `json:"volumes"`
Nodes []NodeInfoResponse `json:"nodes"`
Id string `json:"id"`
//currently BlockVolumes will be used only for metrics
BlockVolumes []BlockVolumeInfoResponse `json:"blockvolumes,omitempty"`
Nodes []NodeInfoResponse `json:"nodes"`
Id string `json:"id"`
ClusterFlags
}
@@ -535,23 +537,6 @@ func (v *VolumeInfoResponse) String() string {
s += fmt.Sprintf("Snapshot Factor: %.2f\n",
v.Snapshot.Factor)
}
/*
s += "\nBricks:\n"
for _, b := range v.Bricks {
s += fmt.Sprintf("Id: %v\n"+
"Path: %v\n"+
"Size (GiB): %v\n"+
"Node: %v\n"+
"Device: %v\n\n",
b.Id,
b.Path,
b.Size/(1024*1024),
b.NodeId,
b.DeviceId)
}
*/
return s
}
@@ -611,8 +596,9 @@ type OperationsInfo struct {
Total uint64 `json:"total"`
InFlight uint64 `json:"in_flight"`
// state based counts:
Stale uint64 `json:"stale"`
New uint64 `json:"new"`
Stale uint64 `json:"stale"`
Failed uint64 `json:"failed"`
New uint64 `json:"new"`
}
type AdminState string
@@ -641,3 +627,54 @@ type DeviceDeleteOptions struct {
// orphaning metadata on the node
ForceForget bool `json:"forceforget"`
}
// PendingOperationInfo contains metadata to summarize a pending
// operation.
type PendingOperationInfo struct {
Id string `json:"id"`
TypeName string `json:"type_name"`
Status string `json:"status"`
SubStatus string `json:"sub_status"`
// TODO label, timestamp?
}
type PendingChangeInfo struct {
Id string `json:"id"`
Description string `json:"description"`
}
type PendingOperationDetails struct {
PendingOperationInfo
Changes []PendingChangeInfo `json:"changes"`
}
type PendingOperationListResponse struct {
PendingOperations []PendingOperationInfo `json:"pendingoperations"`
}
type PendingOperationsCleanRequest struct {
Operations []string `json:"operations,omitempty"`
}
func (pocr PendingOperationsCleanRequest) Validate() error {
return validation.ValidateStruct(&pocr,
validation.Field(&pocr.Operations, validation.By(ValidateIds)),
)
}
func ValidateIds(v interface{}) error {
ids, ok := v.([]string)
if !ok {
return fmt.Errorf("must be a list of strings")
}
if len(ids) > 32 {
return fmt.Errorf("too many ids specified (%v), up to %v supported",
len(ids), 32)
}
for _, id := range ids {
if err := ValidateUUID(id); err != nil {
return err
}
}
return nil
}