rename a number of API methods

This commit is contained in:
Matthew Jaffee 2018-04-11 13:49:51 -05:00
parent feec5f07e1
commit 9daef2180c
No known key found for this signature in database
GPG key ID: 51C676AF9FFCDB87
2 changed files with 19 additions and 19 deletions

22
api.go
View file

@ -58,8 +58,8 @@ func NewAPI() *API {
}
}
// ExecuteQuery parses a PQL query out of the request and executes it.
func (api *API) ExecuteQuery(ctx context.Context, req *QueryRequest) (QueryResponse, error) {
// Query parses a PQL query out of the request and executes it.
func (api *API) Query(ctx context.Context, req *QueryRequest) (QueryResponse, error) {
resp := QueryResponse{}
q, err := pql.NewParser(strings.NewReader(req.Query)).Parse()
@ -143,7 +143,7 @@ func (api *API) CreateIndex(ctx context.Context, indexName string, options Index
return index, nil
}
func (api *API) ReadIndex(ctx context.Context, indexName string) (*Index, error) {
func (api *API) Index(ctx context.Context, indexName string) (*Index, error) {
index := api.Holder.Index(indexName)
if index == nil {
return nil, ErrIndexNotFound
@ -393,9 +393,9 @@ func (api *API) RestoreFrame(ctx context.Context, indexName string, frameName st
return nil
}
// ClusterHosts returns a list of the hosts in the cluster including their ID,
// Hosts returns a list of the hosts in the cluster including their ID,
// URL, and which is the coordinator.
func (api *API) ClusterHosts(ctx context.Context) []*Node {
func (api *API) Hosts(ctx context.Context) []*Node {
return api.Cluster.Nodes
}
@ -522,7 +522,7 @@ func (api *API) Status(ctx context.Context) (proto.Message, error) {
return api.StatusHandler.ClusterStatus()
}
func (api *API) CreateFrameField(ctx context.Context, indexName string, frameName string, field *Field) error {
func (api *API) CreateField(ctx context.Context, indexName string, frameName string, field *Field) error {
// Retrieve frame by name.
f := api.Holder.Frame(indexName, frameName)
if f == nil {
@ -547,7 +547,7 @@ func (api *API) CreateFrameField(ctx context.Context, indexName string, frameNam
return err
}
func (api *API) DeleteFrameField(ctx context.Context, indexName string, frameName string, fieldName string) error {
func (api *API) DeleteField(ctx context.Context, indexName string, frameName string, fieldName string) error {
// Retrieve frame by name.
f := api.Holder.Frame(indexName, frameName)
if f == nil {
@ -572,7 +572,7 @@ func (api *API) DeleteFrameField(ctx context.Context, indexName string, frameNam
return err
}
func (api *API) FrameFields(ctx context.Context, indexName string, frameName string) ([]*Field, error) {
func (api *API) Fields(ctx context.Context, indexName string, frameName string) ([]*Field, error) {
index := api.Holder.index(indexName)
if index == nil {
return nil, ErrIndexNotFound
@ -586,7 +586,7 @@ func (api *API) FrameFields(ctx context.Context, indexName string, frameName str
return frame.GetFields()
}
func (api *API) FrameViews(ctx context.Context, indexName string, frameName string) ([]*View, error) {
func (api *API) Views(ctx context.Context, indexName string, frameName string) ([]*View, error) {
// Retrieve views.
f := api.Holder.Frame(indexName, frameName)
if f == nil {
@ -764,9 +764,9 @@ func (api *API) StatsWithTags(tags []string) StatsClient {
return api.Holder.Stats.WithTags(tags...)
}
// ClusterLongQueryTime returns the configured threshold for logging/statting
// LongQueryTime returns the configured threshold for logging/statting
// long running queries.
func (api *API) ClusterLongQueryTime() time.Duration {
func (api *API) LongQueryTime() time.Duration {
if api.Cluster == nil {
return 0
}

View file

@ -241,7 +241,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Calculate per request StatsD metrics when the handler is fully configured.
statsTags := make([]string, 0, 3)
longQueryTime := h.API.ClusterLongQueryTime()
longQueryTime := h.API.LongQueryTime()
if longQueryTime > 0 && dif > longQueryTime {
h.Logger.Printf("%s %s %v", r.Method, r.URL.String(), dif)
statsTags = append(statsTags, "slow_query")
@ -328,7 +328,7 @@ func (h *Handler) handlePostQuery(w http.ResponseWriter, r *http.Request) {
// TODO: Remove
req.Index = mux.Vars(r)["index"]
resp, err := h.API.ExecuteQuery(r.Context(), req)
resp, err := h.API.Query(r.Context(), req)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
h.writeQueryResponse(w, r, &QueryResponse{Err: err})
@ -374,7 +374,7 @@ func (h *Handler) handleGetIndexes(w http.ResponseWriter, r *http.Request) {
// handleGetIndex handles GET /index/<indexname> requests.
func (h *Handler) handleGetIndex(w http.ResponseWriter, r *http.Request) {
indexName := mux.Vars(r)["index"]
index, err := h.API.ReadIndex(r.Context(), indexName)
index, err := h.API.Index(r.Context(), indexName)
if err != nil {
http.Error(w, err.Error(), http.StatusNotFound)
return
@ -742,7 +742,7 @@ func (h *Handler) handlePostFrameField(w http.ResponseWriter, r *http.Request) {
Max: req.Max,
}
if err := h.API.CreateFrameField(r.Context(), indexName, frameName, field); err != nil {
if err := h.API.CreateField(r.Context(), indexName, frameName, field); err != nil {
if err == ErrFrameNotFound {
http.Error(w, err.Error(), http.StatusNotFound)
} else {
@ -771,7 +771,7 @@ func (h *Handler) handleDeleteFrameField(w http.ResponseWriter, r *http.Request)
frameName := mux.Vars(r)["frame"]
fieldName := mux.Vars(r)["field"]
if err := h.API.DeleteFrameField(r.Context(), indexName, frameName, fieldName); err != nil {
if err := h.API.DeleteField(r.Context(), indexName, frameName, fieldName); err != nil {
if err == ErrFrameNotFound {
http.Error(w, err.Error(), http.StatusNotFound)
} else {
@ -790,7 +790,7 @@ func (h *Handler) handleGetFrameFields(w http.ResponseWriter, r *http.Request) {
indexName := mux.Vars(r)["index"]
frameName := mux.Vars(r)["frame"]
fields, err := h.API.FrameFields(r.Context(), indexName, frameName)
fields, err := h.API.Fields(r.Context(), indexName, frameName)
if err != nil {
switch err {
case ErrIndexNotFound:
@ -824,7 +824,7 @@ func (h *Handler) handleGetFrameViews(w http.ResponseWriter, r *http.Request) {
indexName := mux.Vars(r)["index"]
frameName := mux.Vars(r)["frame"]
views, err := h.API.FrameViews(r.Context(), indexName, frameName)
views, err := h.API.Views(r.Context(), indexName, frameName)
if err != nil {
if err == ErrFrameNotFound {
http.Error(w, err.Error(), http.StatusNotFound)
@ -1329,7 +1329,7 @@ func (h *Handler) handlePostFrameRestore(w http.ResponseWriter, r *http.Request)
// handleGetHosts handles /hosts requests.
func (h *Handler) handleGetHosts(w http.ResponseWriter, r *http.Request) {
hosts := h.API.ClusterHosts(r.Context())
hosts := h.API.Hosts(r.Context())
if err := json.NewEncoder(w).Encode(hosts); err != nil {
h.Logger.Printf("write version response error: %s", err)
}