influxdb/server/databases.go

66 lines
1.7 KiB
Go
Raw Normal View History

2017-03-20 22:26:48 +00:00
package server
import (
2017-03-22 20:27:36 +00:00
"fmt"
2017-03-21 19:59:27 +00:00
"net/http"
2017-03-20 22:26:48 +00:00
)
2017-03-21 19:59:27 +00:00
type dbLinks struct {
Self string `json:"self"` // Self link mapping to this resource
RPs string `json:"rps"` // URL for retention policies for this database
}
2017-03-22 08:40:30 +00:00
type dbResponse struct {
2017-03-21 19:59:27 +00:00
Name string `json:"name"` // a unique string identifier for the database
Duration string `json:"duration,omitempty"` // the duration (when creating a default retention policy)
Replication int32 `json:"replication,omitempty"` // the replication factor (when creating a default retention policy)
2017-03-22 20:27:36 +00:00
ShardDuration string `json:"shardDuration,omitempty"` // the shard duration (when creating a default retention policy)
Links dbLinks `json:"links"` // Links are URI locations related to the database
2017-03-21 19:59:27 +00:00
}
2017-03-22 08:40:30 +00:00
type dbsResponse struct {
Databases []dbResponse `json:"databases"`
2017-03-20 22:26:48 +00:00
}
2017-03-22 08:40:30 +00:00
// Databases queries the list of all databases for a source
2017-03-22 20:27:36 +00:00
func (h *Service) GetDatabases(w http.ResponseWriter, r *http.Request) {
2017-03-22 08:40:30 +00:00
ctx := r.Context()
2017-03-21 19:59:27 +00:00
2017-03-22 20:27:36 +00:00
srcID, err := paramID("id", r)
if err != nil {
Error(w, http.StatusUnprocessableEntity, err.Error(), h.Logger)
return
}
src, err := h.SourcesStore.Get(ctx, srcID)
if err != nil {
notFound(w, srcID, h.Logger)
return
}
db := h.Databases
if err = db.Connect(ctx, &src); err != nil {
msg := fmt.Sprintf("Unable to connect to source %d: %v", srcID, err)
Error(w, http.StatusBadRequest, msg, h.Logger)
return
}
databases, err := db.AllDB(ctx)
2017-03-22 08:40:30 +00:00
if err != nil {
Error(w, http.StatusBadRequest, err.Error(), h.Logger)
return
}
2017-03-21 19:59:27 +00:00
2017-03-22 08:40:30 +00:00
dbs := make([]dbResponse, len(databases))
2017-03-22 20:27:36 +00:00
// for i, d := range databases {
//
// }
2017-03-21 19:59:27 +00:00
2017-03-22 08:40:30 +00:00
res := dbsResponse{
Databases: dbs,
2017-03-21 19:59:27 +00:00
}
2017-03-20 22:26:48 +00:00
2017-03-21 19:59:27 +00:00
encodeJSON(w, http.StatusOK, res, h.Logger)
2017-03-20 22:26:48 +00:00
}