2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2015-11-24 05:47:11 +00:00
|
|
|
package nomad
|
|
|
|
|
2018-09-15 23:23:13 +00:00
|
|
|
import (
|
2022-12-01 15:05:15 +00:00
|
|
|
"github.com/hashicorp/go-hclog"
|
2018-09-15 23:23:13 +00:00
|
|
|
|
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
|
|
)
|
2015-11-24 05:47:11 +00:00
|
|
|
|
|
|
|
// Region is used to query and list the known regions
|
|
|
|
type Region struct {
|
2018-09-15 23:23:13 +00:00
|
|
|
srv *Server
|
2022-12-01 15:05:15 +00:00
|
|
|
ctx *RPCContext
|
|
|
|
logger hclog.Logger
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewRegionEndpoint(srv *Server, ctx *RPCContext) *Region {
|
|
|
|
return &Region{srv: srv, ctx: ctx, logger: srv.logger.Named("region")}
|
2015-11-24 05:47:11 +00:00
|
|
|
}
|
|
|
|
|
2015-11-24 06:00:56 +00:00
|
|
|
// List is used to list all of the known regions. No leader forwarding is
|
|
|
|
// required for this endpoint because memberlist is used to populate the
|
|
|
|
// peers list we read from.
|
2015-11-24 05:47:11 +00:00
|
|
|
func (r *Region) List(args *structs.GenericRequest, reply *[]string) error {
|
2023-01-26 20:05:51 +00:00
|
|
|
// note: we're intentionally throwing away any auth error here and only
|
|
|
|
// authenticate so that we can measure rate metrics
|
|
|
|
r.srv.Authenticate(r.ctx, args)
|
|
|
|
r.srv.MeasureRPCRate("region", structs.RateMetricList, args)
|
|
|
|
|
2015-11-24 05:47:11 +00:00
|
|
|
*reply = r.srv.Regions()
|
|
|
|
return nil
|
|
|
|
}
|