mirror of
https://github.com/kemko/nomad.git
synced 2026-01-04 17:35:43 +03:00
* Upgrade to using hashicorp/go-metrics@v0.5.4 This also requires bumping the dependencies for: * memberlist * serf * raft * raft-boltdb * (and indirectly hashicorp/mdns due to the memberlist or serf update) Unlike some other HashiCorp products, Nomads root module is currently expected to be consumed by others. This means that it needs to be treated more like our libraries and upgrade to hashicorp/go-metrics by utilizing its compat packages. This allows those importing the root module to control the metrics module used via build tags.
84 lines
2.2 KiB
Go
84 lines
2.2 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package client
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
metrics "github.com/hashicorp/go-metrics/compat"
|
|
cstructs "github.com/hashicorp/nomad/client/structs"
|
|
)
|
|
|
|
type HostVolume struct {
|
|
c *Client
|
|
}
|
|
|
|
func newHostVolumesEndpoint(c *Client) *HostVolume {
|
|
v := &HostVolume{c: c}
|
|
return v
|
|
}
|
|
|
|
var hostVolumeRequestTimeout = time.Minute
|
|
|
|
func (v *HostVolume) Create(
|
|
req *cstructs.ClientHostVolumeCreateRequest,
|
|
resp *cstructs.ClientHostVolumeCreateResponse) error {
|
|
|
|
defer metrics.MeasureSince([]string{"client", "host_volume", "create"}, time.Now())
|
|
ctx, cancelFn := v.requestContext()
|
|
defer cancelFn()
|
|
|
|
cresp, err := v.c.hostVolumeManager.Create(ctx, req)
|
|
if err != nil {
|
|
v.c.logger.Error("failed to create host volume", "name", req.Name, "error", err)
|
|
return err
|
|
}
|
|
|
|
resp.CapacityBytes = cresp.CapacityBytes
|
|
resp.HostPath = cresp.HostPath
|
|
|
|
v.c.logger.Info("created host volume", "id", req.ID, "path", resp.HostPath)
|
|
return nil
|
|
}
|
|
|
|
func (v *HostVolume) Register(
|
|
req *cstructs.ClientHostVolumeRegisterRequest,
|
|
resp *cstructs.ClientHostVolumeRegisterResponse) error {
|
|
|
|
defer metrics.MeasureSince([]string{"client", "host_volume", "register"}, time.Now())
|
|
ctx, cancelFn := v.requestContext()
|
|
defer cancelFn()
|
|
|
|
err := v.c.hostVolumeManager.Register(ctx, req)
|
|
if err != nil {
|
|
v.c.logger.Error("failed to register host volume", "name", req.Name, "error", err)
|
|
return err
|
|
}
|
|
|
|
v.c.logger.Info("registered host volume", "id", req.ID, "path", req.HostPath)
|
|
return nil
|
|
}
|
|
|
|
func (v *HostVolume) Delete(
|
|
req *cstructs.ClientHostVolumeDeleteRequest,
|
|
resp *cstructs.ClientHostVolumeDeleteResponse) error {
|
|
defer metrics.MeasureSince([]string{"client", "host_volume", "create"}, time.Now())
|
|
ctx, cancelFn := v.requestContext()
|
|
defer cancelFn()
|
|
|
|
_, err := v.c.hostVolumeManager.Delete(ctx, req)
|
|
if err != nil {
|
|
v.c.logger.Error("failed to delete host volume", "ID", req.ID, "error", err)
|
|
return err
|
|
}
|
|
|
|
v.c.logger.Info("deleted host volume", "id", req.ID, "path", req.HostPath)
|
|
return nil
|
|
}
|
|
|
|
func (v *HostVolume) requestContext() (context.Context, context.CancelFunc) {
|
|
return context.WithTimeout(context.Background(), hostVolumeRequestTimeout)
|
|
}
|