it's working!
parent
47c6308482
commit
65a0612496
|
@ -304,6 +304,7 @@ type Database struct {
|
|||
type Databases interface {
|
||||
// All lists all databases
|
||||
AllDB(context.Context) ([]Database, error)
|
||||
Connect(context.Context, *Source) error
|
||||
}
|
||||
|
||||
// DashboardID is the dashboard ID
|
||||
|
|
|
@ -65,17 +65,6 @@ type RoleAction struct {
|
|||
Role *Role `json:"role"`
|
||||
}
|
||||
|
||||
type Database struct {
|
||||
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)
|
||||
ShardDuration string `json:shardDuration,omitempty` // the shard duration (when creating a default retention policy)
|
||||
}
|
||||
|
||||
type Databases struct {
|
||||
Databases []Database `json:"databases,omitempty"`
|
||||
}
|
||||
|
||||
// Error is JSON error message return by Influx Enterprise's meta API.
|
||||
type Error struct {
|
||||
Error string `json:"error"`
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
)
|
||||
|
||||
var _ chronograf.TimeSeries = &Client{}
|
||||
var _ chronograf.Databases = &Client{}
|
||||
|
||||
// Shared transports for all clients to prevent leaking connections
|
||||
var (
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
|
@ -13,8 +14,8 @@ type dbResponse struct {
|
|||
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)
|
||||
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
|
||||
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
|
||||
}
|
||||
|
||||
type dbsResponse struct {
|
||||
|
@ -22,23 +23,39 @@ type dbsResponse struct {
|
|||
}
|
||||
|
||||
// Databases queries the list of all databases for a source
|
||||
func (h *Service) Databases(w http.ResponseWriter, r *http.Request) {
|
||||
func (h *Service) GetDatabases(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
srcID, ts, err := h.sourcesSeries(ctx, w, r)
|
||||
|
||||
srcID, err := paramID("id", r)
|
||||
if err != nil {
|
||||
Error(w, http.StatusUnprocessableEntity, err.Error(), h.Logger)
|
||||
return
|
||||
}
|
||||
|
||||
databases, err := ts.AllDB(ctx)
|
||||
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)
|
||||
if err != nil {
|
||||
Error(w, http.StatusBadRequest, err.Error(), h.Logger)
|
||||
return
|
||||
}
|
||||
|
||||
dbs := make([]dbResponse, len(databases))
|
||||
for i, d := range databases {
|
||||
|
||||
}
|
||||
// for i, d := range databases {
|
||||
//
|
||||
// }
|
||||
|
||||
res := dbsResponse{
|
||||
Databases: dbs,
|
||||
|
|
|
@ -132,7 +132,7 @@ func NewMux(opts MuxOpts, service Service) http.Handler {
|
|||
router.PATCH("/chronograf/v1/dashboards/:id", service.UpdateDashboard)
|
||||
|
||||
// Databases
|
||||
router.GET("/chronograf/v1/sources/:id/dbs", service.Databases)
|
||||
router.GET("/chronograf/v1/sources/:id/dbs", service.GetDatabases)
|
||||
// router.POST("/chronograf/v1/sources/:id/dbs", service.NewDatabase)
|
||||
//
|
||||
// router.DELETE("/chronograf/v1/sources/:id/dbs/:did", service.DropDatabase)
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
client "github.com/influxdata/usage-client/v1"
|
||||
flags "github.com/jessevdk/go-flags"
|
||||
"github.com/tylerb/graceful"
|
||||
"github.com/influxdata/chronograf/influx"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -292,6 +293,7 @@ func openService(boltPath, cannedPath string, logger chronograf.Logger, useAuth
|
|||
AlertRulesStore: db.AlertsStore,
|
||||
Logger: logger,
|
||||
UseAuth: useAuth,
|
||||
Databases: &influx.Client{Logger: logger},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ type Service struct {
|
|||
TimeSeriesClient TimeSeriesClient
|
||||
Logger chronograf.Logger
|
||||
UseAuth bool
|
||||
Databases chronograf.Databases
|
||||
}
|
||||
|
||||
// TimeSeriesClient returns the correct client for a time series database.
|
||||
|
|
Loading…
Reference in New Issue