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