chore: delete old-style DBRP mapping (#22339)

pull/22357/head
Daniel Moran 2021-08-30 18:27:11 -04:00 committed by GitHub
parent f251415a20
commit cc6accf106
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
48 changed files with 1724 additions and 3067 deletions

View File

@ -9,7 +9,7 @@ import (
) )
// AuthorizeFindDBRPs takes the given items and returns only the ones that the user is authorized to access. // AuthorizeFindDBRPs takes the given items and returns only the ones that the user is authorized to access.
func AuthorizeFindDBRPs(ctx context.Context, rs []*influxdb.DBRPMappingV2) ([]*influxdb.DBRPMappingV2, int, error) { func AuthorizeFindDBRPs(ctx context.Context, rs []*influxdb.DBRPMapping) ([]*influxdb.DBRPMapping, int, error) {
// This filters without allocating // This filters without allocating
// https://github.com/golang/go/wiki/SliceTricks#filtering-without-allocating // https://github.com/golang/go/wiki/SliceTricks#filtering-without-allocating
rrs := rs[:0] rrs := rs[:0]

View File

@ -1257,7 +1257,7 @@ func (m *Launcher) CheckService() platform.CheckService {
return m.apibackend.CheckService return m.apibackend.CheckService
} }
func (m *Launcher) DBRPMappingServiceV2() platform.DBRPMappingServiceV2 { func (m *Launcher) DBRPMappingService() platform.DBRPMappingService {
return m.apibackend.DBRPService return m.apibackend.DBRPService
} }

View File

@ -90,7 +90,7 @@ func upgradeDatabases(ctx context.Context, cli clients.CLI, v1 *influxDBv1, v2 *
return nil, fmt.Errorf("error creating database %s: %w", bucket.ID.String(), err) return nil, fmt.Errorf("error creating database %s: %w", bucket.ID.String(), err)
} }
mapping := &influxdb.DBRPMappingV2{ mapping := &influxdb.DBRPMapping{
Database: db.Name, Database: db.Name,
RetentionPolicy: rp.Name, RetentionPolicy: rp.Name,
Default: db.DefaultRetentionPolicy == rp.Name, Default: db.DefaultRetentionPolicy == rp.Name,

View File

@ -301,7 +301,7 @@ type influxDBv2 struct {
kvStore kv.SchemaStore kvStore kv.SchemaStore
tenantStore *tenant.Store tenantStore *tenant.Store
ts *tenant.Service ts *tenant.Service
dbrpSvc influxdb.DBRPMappingServiceV2 dbrpSvc influxdb.DBRPMappingService
bucketSvc influxdb.BucketService bucketSvc influxdb.BucketService
onboardSvc influxdb.OnboardingService onboardSvc influxdb.OnboardingService
authSvc *authv1.Service authSvc *authv1.Service

View File

@ -118,7 +118,7 @@ var v2DumpMetaCommand = &cobra.Command{
fmt.Fprintln(os.Stdout, "Mappings") fmt.Fprintln(os.Stdout, "Mappings")
fmt.Fprintln(os.Stdout, "---------") fmt.Fprintln(os.Stdout, "---------")
fmt.Fprintf(tw, "%s\t%s\t%s\t%s\t%s\n", "Database", "RP", "Org", "Bucket", "Default") fmt.Fprintf(tw, "%s\t%s\t%s\t%s\t%s\n", "Database", "RP", "Org", "Bucket", "Default")
mappings, _, err := svc.dbrpSvc.FindMany(ctx, influxdb.DBRPMappingFilterV2{}) mappings, _, err := svc.dbrpSvc.FindMany(ctx, influxdb.DBRPMappingFilter{})
if err != nil { if err != nil {
return err return err
} }

View File

@ -12,10 +12,10 @@ import (
type BucketService struct { type BucketService struct {
influxdb.BucketService influxdb.BucketService
Logger *zap.Logger Logger *zap.Logger
DBRPMappingService influxdb.DBRPMappingServiceV2 DBRPMappingService influxdb.DBRPMappingService
} }
func NewBucketService(logger *zap.Logger, bucketService influxdb.BucketService, dbrpService influxdb.DBRPMappingServiceV2) *BucketService { func NewBucketService(logger *zap.Logger, bucketService influxdb.BucketService, dbrpService influxdb.DBRPMappingService) *BucketService {
return &BucketService{ return &BucketService{
Logger: logger, Logger: logger,
BucketService: bucketService, BucketService: bucketService,
@ -33,7 +33,7 @@ func (s *BucketService) DeleteBucket(ctx context.Context, id platform.ID) error
} }
logger := s.Logger.With(zap.String("bucket_id", id.String())) logger := s.Logger.With(zap.String("bucket_id", id.String()))
mappings, _, err := s.DBRPMappingService.FindMany(ctx, influxdb.DBRPMappingFilterV2{ mappings, _, err := s.DBRPMappingService.FindMany(ctx, influxdb.DBRPMappingFilter{
OrgID: &bucket.OrgID, OrgID: &bucket.OrgID,
BucketID: &bucket.ID, BucketID: &bucket.ID,
}) })

View File

@ -26,7 +26,7 @@ func TestBucketService(t *testing.T) {
logger = zap.NewNop() logger = zap.NewNop()
bucketServiceMock = mocks.NewMockBucketService(ctrl) bucketServiceMock = mocks.NewMockBucketService(ctrl)
dbrpService = mocks.NewMockDBRPMappingServiceV2(ctrl) dbrpService = mocks.NewMockDBRPMappingService(ctrl)
bucket = &influxdb.Bucket{ bucket = &influxdb.Bucket{
ID: bucketID, ID: bucketID,
@ -42,10 +42,10 @@ func TestBucketService(t *testing.T) {
Return(nil) Return(nil)
findMapping := dbrpService.EXPECT(). findMapping := dbrpService.EXPECT().
FindMany(gomock.Any(), influxdb.DBRPMappingFilterV2{ FindMany(gomock.Any(), influxdb.DBRPMappingFilter{
BucketID: &bucketID, BucketID: &bucketID,
OrgID: &orgID, OrgID: &orgID,
}).Return([]*influxdb.DBRPMappingV2{ }).Return([]*influxdb.DBRPMapping{
{ID: mappingID}, {ID: mappingID},
}, 1, nil) }, 1, nil)
deleteMapping := dbrpService.EXPECT(). deleteMapping := dbrpService.EXPECT().

View File

@ -13,7 +13,7 @@ import (
"github.com/influxdata/influxdb/v2/pkg/httpc" "github.com/influxdata/influxdb/v2/pkg/httpc"
) )
var _ influxdb.DBRPMappingServiceV2 = (*Client)(nil) var _ influxdb.DBRPMappingService = (*Client)(nil)
// Client connects to Influx via HTTP using tokens to manage DBRPs. // Client connects to Influx via HTTP using tokens to manage DBRPs.
type Client struct { type Client struct {
@ -32,7 +32,7 @@ func (c *Client) dbrpURL(id platform.ID) string {
return path.Join(c.Prefix, id.String()) return path.Join(c.Prefix, id.String())
} }
func (c *Client) FindByID(ctx context.Context, orgID, id platform.ID) (*influxdb.DBRPMappingV2, error) { func (c *Client) FindByID(ctx context.Context, orgID, id platform.ID) (*influxdb.DBRPMapping, error) {
span, _ := tracing.StartSpanFromContext(ctx) span, _ := tracing.StartSpanFromContext(ctx)
defer span.Finish() defer span.Finish()
@ -47,7 +47,7 @@ func (c *Client) FindByID(ctx context.Context, orgID, id platform.ID) (*influxdb
return resp.Content, nil return resp.Content, nil
} }
func (c *Client) FindMany(ctx context.Context, filter influxdb.DBRPMappingFilterV2, opts ...influxdb.FindOptions) ([]*influxdb.DBRPMappingV2, int, error) { func (c *Client) FindMany(ctx context.Context, filter influxdb.DBRPMappingFilter, opts ...influxdb.FindOptions) ([]*influxdb.DBRPMapping, int, error) {
span, _ := tracing.StartSpanFromContext(ctx) span, _ := tracing.StartSpanFromContext(ctx)
defer span.Finish() defer span.Finish()
@ -84,11 +84,11 @@ func (c *Client) FindMany(ctx context.Context, filter influxdb.DBRPMappingFilter
return resp.Content, len(resp.Content), nil return resp.Content, len(resp.Content), nil
} }
func (c *Client) Create(ctx context.Context, dbrp *influxdb.DBRPMappingV2) error { func (c *Client) Create(ctx context.Context, dbrp *influxdb.DBRPMapping) error {
span, _ := tracing.StartSpanFromContext(ctx) span, _ := tracing.StartSpanFromContext(ctx)
defer span.Finish() defer span.Finish()
var newDBRP influxdb.DBRPMappingV2 var newDBRP influxdb.DBRPMapping
if err := c.Client. if err := c.Client.
PostJSON(createDBRPRequest{ PostJSON(createDBRPRequest{
Database: dbrp.Database, Database: dbrp.Database,
@ -105,7 +105,7 @@ func (c *Client) Create(ctx context.Context, dbrp *influxdb.DBRPMappingV2) error
return nil return nil
} }
func (c *Client) Update(ctx context.Context, dbrp *influxdb.DBRPMappingV2) error { func (c *Client) Update(ctx context.Context, dbrp *influxdb.DBRPMapping) error {
span, _ := tracing.StartSpanFromContext(ctx) span, _ := tracing.StartSpanFromContext(ctx)
defer span.Finish() defer span.Finish()
@ -113,7 +113,7 @@ func (c *Client) Update(ctx context.Context, dbrp *influxdb.DBRPMappingV2) error
return err return err
} }
var newDBRP influxdb.DBRPMappingV2 var newDBRP influxdb.DBRPMapping
if err := c.Client. if err := c.Client.
PatchJSON(dbrp, c.dbrpURL(dbrp.ID)). PatchJSON(dbrp, c.dbrpURL(dbrp.ID)).
QueryParams([2]string{"orgID", dbrp.OrganizationID.String()}). QueryParams([2]string{"orgID", dbrp.OrganizationID.String()}).

View File

@ -16,13 +16,13 @@ import (
func setup(t *testing.T) (*dbrp.Client, func()) { func setup(t *testing.T) (*dbrp.Client, func()) {
t.Helper() t.Helper()
dbrpSvc := &mock.DBRPMappingServiceV2{ dbrpSvc := &mock.DBRPMappingService{
CreateFn: func(ctx context.Context, dbrp *influxdb.DBRPMappingV2) error { CreateFn: func(ctx context.Context, dbrp *influxdb.DBRPMapping) error {
dbrp.ID = 1 dbrp.ID = 1
return nil return nil
}, },
FindByIDFn: func(ctx context.Context, orgID, id platform.ID) (*influxdb.DBRPMappingV2, error) { FindByIDFn: func(ctx context.Context, orgID, id platform.ID) (*influxdb.DBRPMapping, error) {
return &influxdb.DBRPMappingV2{ return &influxdb.DBRPMapping{
ID: id, ID: id,
Database: "db", Database: "db",
RetentionPolicy: "rp", RetentionPolicy: "rp",
@ -31,8 +31,8 @@ func setup(t *testing.T) (*dbrp.Client, func()) {
BucketID: 1, BucketID: 1,
}, nil }, nil
}, },
FindManyFn: func(ctx context.Context, dbrp influxdb.DBRPMappingFilterV2, opts ...influxdb.FindOptions) ([]*influxdb.DBRPMappingV2, int, error) { FindManyFn: func(ctx context.Context, dbrp influxdb.DBRPMappingFilter, opts ...influxdb.FindOptions) ([]*influxdb.DBRPMapping, int, error) {
return []*influxdb.DBRPMappingV2{}, 0, nil return []*influxdb.DBRPMapping{}, 0, nil
}, },
} }
orgSvc := &mock.OrganizationService{ orgSvc := &mock.OrganizationService{
@ -60,7 +60,7 @@ func TestClient(t *testing.T) {
client, shutdown := setup(t) client, shutdown := setup(t)
defer shutdown() defer shutdown()
if err := client.Create(context.Background(), &influxdb.DBRPMappingV2{ if err := client.Create(context.Background(), &influxdb.DBRPMapping{
Database: "db", Database: "db",
RetentionPolicy: "rp", RetentionPolicy: "rp",
Default: false, Default: false,
@ -79,7 +79,7 @@ func TestClient(t *testing.T) {
t.Error(err) t.Error(err)
} }
oid := platform.ID(1) oid := platform.ID(1)
if _, _, err := client.FindMany(context.Background(), influxdb.DBRPMappingFilterV2{OrgID: &oid}); err != nil { if _, _, err := client.FindMany(context.Background(), influxdb.DBRPMappingFilter{OrgID: &oid}); err != nil {
t.Error(err) t.Error(err)
} }
}) })
@ -88,7 +88,7 @@ func TestClient(t *testing.T) {
client, shutdown := setup(t) client, shutdown := setup(t)
defer shutdown() defer shutdown()
if err := client.Update(context.Background(), &influxdb.DBRPMappingV2{ if err := client.Update(context.Background(), &influxdb.DBRPMapping{
ID: 1, ID: 1,
Database: "db", Database: "db",
RetentionPolicy: "rp", RetentionPolicy: "rp",

View File

@ -23,12 +23,12 @@ type Handler struct {
chi.Router chi.Router
api *kithttp.API api *kithttp.API
log *zap.Logger log *zap.Logger
dbrpSvc influxdb.DBRPMappingServiceV2 dbrpSvc influxdb.DBRPMappingService
orgSvc influxdb.OrganizationService orgSvc influxdb.OrganizationService
} }
// NewHTTPHandler constructs a new http server. // NewHTTPHandler constructs a new http server.
func NewHTTPHandler(log *zap.Logger, dbrpSvc influxdb.DBRPMappingServiceV2, orgSvc influxdb.OrganizationService) *Handler { func NewHTTPHandler(log *zap.Logger, dbrpSvc influxdb.DBRPMappingService, orgSvc influxdb.OrganizationService) *Handler {
h := &Handler{ h := &Handler{
api: kithttp.NewAPI(kithttp.WithLog(log)), api: kithttp.NewAPI(kithttp.WithLog(log)),
log: log, log: log,
@ -114,7 +114,7 @@ func (h *Handler) handlePostDBRP(w http.ResponseWriter, r *http.Request) {
return return
} }
dbrp := &influxdb.DBRPMappingV2{ dbrp := &influxdb.DBRPMapping{
Database: req.Database, Database: req.Database,
RetentionPolicy: req.RetentionPolicy, RetentionPolicy: req.RetentionPolicy,
Default: req.Default, Default: req.Default,
@ -129,7 +129,7 @@ func (h *Handler) handlePostDBRP(w http.ResponseWriter, r *http.Request) {
} }
type getDBRPsResponse struct { type getDBRPsResponse struct {
Content []*influxdb.DBRPMappingV2 `json:"content"` Content []*influxdb.DBRPMapping `json:"content"`
} }
func (h *Handler) handleGetDBRPs(w http.ResponseWriter, r *http.Request) { func (h *Handler) handleGetDBRPs(w http.ResponseWriter, r *http.Request) {
@ -150,7 +150,7 @@ func (h *Handler) handleGetDBRPs(w http.ResponseWriter, r *http.Request) {
} }
type getDBRPResponse struct { type getDBRPResponse struct {
Content *influxdb.DBRPMappingV2 `json:"content"` Content *influxdb.DBRPMapping `json:"content"`
} }
func (h *Handler) handleGetDBRP(w http.ResponseWriter, r *http.Request) { func (h *Handler) handleGetDBRP(w http.ResponseWriter, r *http.Request) {
@ -244,7 +244,7 @@ func (h *Handler) handlePatchDBRP(w http.ResponseWriter, r *http.Request) {
} }
h.api.Respond(w, r, http.StatusOK, struct { h.api.Respond(w, r, http.StatusOK, struct {
Content *influxdb.DBRPMappingV2 `json:"content"` Content *influxdb.DBRPMapping `json:"content"`
}{ }{
Content: dbrp, Content: dbrp,
}) })
@ -281,7 +281,7 @@ func (h *Handler) handleDeleteDBRP(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNoContent) w.WriteHeader(http.StatusNoContent)
} }
func (h *Handler) getFilterFromHTTPRequest(r *http.Request) (f influxdb.DBRPMappingFilterV2, err error) { func (h *Handler) getFilterFromHTTPRequest(r *http.Request) (f influxdb.DBRPMappingFilter, err error) {
// Always provide OrgID. // Always provide OrgID.
f.OrgID, err = h.mustGetOrgIDFromHTTPRequest(r) f.OrgID, err = h.mustGetOrgIDFromHTTPRequest(r)
if err != nil { if err != nil {

View File

@ -22,7 +22,7 @@ import (
"go.uber.org/zap/zaptest" "go.uber.org/zap/zaptest"
) )
func initHttpService(t *testing.T) (influxdb.DBRPMappingServiceV2, *httptest.Server, func()) { func initHttpService(t *testing.T) (influxdb.DBRPMappingService, *httptest.Server, func()) {
t.Helper() t.Helper()
ctx := context.Background() ctx := context.Background()
bucketSvc := mock.NewBucketService() bucketSvc := mock.NewBucketService()
@ -56,7 +56,7 @@ func Test_handlePostDBRP(t *testing.T) {
table := []struct { table := []struct {
Name string Name string
ExpectedErr error ExpectedErr error
ExpectedDBRP *influxdb.DBRPMappingV2 ExpectedDBRP *influxdb.DBRPMapping
Input io.Reader Input io.Reader
}{ }{
{ {
@ -68,7 +68,7 @@ func Test_handlePostDBRP(t *testing.T) {
"retention_policy": "autogen", "retention_policy": "autogen",
"default": false "default": false
}`), }`),
ExpectedDBRP: &influxdb.DBRPMappingV2{ ExpectedDBRP: &influxdb.DBRPMapping{
OrganizationID: influxdbtesting.MustIDBase16("059af7ed2a034000"), OrganizationID: influxdbtesting.MustIDBase16("059af7ed2a034000"),
}, },
}, },
@ -81,7 +81,7 @@ func Test_handlePostDBRP(t *testing.T) {
"retention_policy": "autogen", "retention_policy": "autogen",
"default": false "default": false
}`), }`),
ExpectedDBRP: &influxdb.DBRPMappingV2{ ExpectedDBRP: &influxdb.DBRPMapping{
OrganizationID: influxdbtesting.MustIDBase16("059af7ed2a034000"), OrganizationID: influxdbtesting.MustIDBase16("059af7ed2a034000"),
}, },
}, },
@ -158,7 +158,7 @@ func Test_handlePostDBRP(t *testing.T) {
assert.Equal(t, tt.ExpectedErr.Error(), actualErr.Error()) assert.Equal(t, tt.ExpectedErr.Error(), actualErr.Error())
return return
} }
dbrp := &influxdb.DBRPMappingV2{} dbrp := &influxdb.DBRPMapping{}
if err := json.NewDecoder(resp.Body).Decode(&dbrp); err != nil { if err := json.NewDecoder(resp.Body).Decode(&dbrp); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -183,12 +183,12 @@ func Test_handleGetDBRPs(t *testing.T) {
Name string Name string
QueryParams string QueryParams string
ExpectedErr error ExpectedErr error
ExpectedDBRPs []influxdb.DBRPMappingV2 ExpectedDBRPs []influxdb.DBRPMapping
}{ }{
{ {
Name: "ok", Name: "ok",
QueryParams: "orgID=059af7ed2a034000", QueryParams: "orgID=059af7ed2a034000",
ExpectedDBRPs: []influxdb.DBRPMappingV2{ ExpectedDBRPs: []influxdb.DBRPMapping{
{ {
ID: influxdbtesting.MustIDBase16("1111111111111111"), ID: influxdbtesting.MustIDBase16("1111111111111111"),
BucketID: influxdbtesting.MustIDBase16("5555f7ed2a035555"), BucketID: influxdbtesting.MustIDBase16("5555f7ed2a035555"),
@ -225,12 +225,12 @@ func Test_handleGetDBRPs(t *testing.T) {
{ {
Name: "no match", Name: "no match",
QueryParams: "orgID=059af7ed2a034000&default=false", QueryParams: "orgID=059af7ed2a034000&default=false",
ExpectedDBRPs: []influxdb.DBRPMappingV2{}, ExpectedDBRPs: []influxdb.DBRPMapping{},
}, },
{ {
Name: "all match", Name: "all match",
QueryParams: "orgID=059af7ed2a034000&default=true&rp=autogen&db=mydb&bucketID=5555f7ed2a035555&id=1111111111111111", QueryParams: "orgID=059af7ed2a034000&default=true&rp=autogen&db=mydb&bucketID=5555f7ed2a035555&id=1111111111111111",
ExpectedDBRPs: []influxdb.DBRPMappingV2{ ExpectedDBRPs: []influxdb.DBRPMapping{
{ {
ID: influxdbtesting.MustIDBase16("1111111111111111"), ID: influxdbtesting.MustIDBase16("1111111111111111"),
BucketID: influxdbtesting.MustIDBase16("5555f7ed2a035555"), BucketID: influxdbtesting.MustIDBase16("5555f7ed2a035555"),
@ -244,7 +244,7 @@ func Test_handleGetDBRPs(t *testing.T) {
{ {
Name: "org name", Name: "org name",
QueryParams: "org=org", QueryParams: "org=org",
ExpectedDBRPs: []influxdb.DBRPMappingV2{ ExpectedDBRPs: []influxdb.DBRPMapping{
{ {
ID: influxdbtesting.MustIDBase16("1111111111111111"), ID: influxdbtesting.MustIDBase16("1111111111111111"),
BucketID: influxdbtesting.MustIDBase16("5555f7ed2a035555"), BucketID: influxdbtesting.MustIDBase16("5555f7ed2a035555"),
@ -269,7 +269,7 @@ func Test_handleGetDBRPs(t *testing.T) {
if svc, ok := svc.(*dbrp.Service); ok { if svc, ok := svc.(*dbrp.Service); ok {
svc.IDGen = mock.NewIDGenerator("1111111111111111", t) svc.IDGen = mock.NewIDGenerator("1111111111111111", t)
} }
db := &influxdb.DBRPMappingV2{ db := &influxdb.DBRPMapping{
BucketID: influxdbtesting.MustIDBase16("5555f7ed2a035555"), BucketID: influxdbtesting.MustIDBase16("5555f7ed2a035555"),
OrganizationID: influxdbtesting.MustIDBase16("059af7ed2a034000"), OrganizationID: influxdbtesting.MustIDBase16("059af7ed2a034000"),
Database: "mydb", Database: "mydb",
@ -301,7 +301,7 @@ func Test_handleGetDBRPs(t *testing.T) {
return return
} }
dbrps := struct { dbrps := struct {
Content []influxdb.DBRPMappingV2 `json:"content"` Content []influxdb.DBRPMapping `json:"content"`
}{} }{}
if err := json.NewDecoder(resp.Body).Decode(&dbrps); err != nil { if err := json.NewDecoder(resp.Body).Decode(&dbrps); err != nil {
t.Fatal(err) t.Fatal(err)
@ -323,7 +323,7 @@ func Test_handlePatchDBRP(t *testing.T) {
table := []struct { table := []struct {
Name string Name string
ExpectedErr error ExpectedErr error
ExpectedDBRP *influxdb.DBRPMappingV2 ExpectedDBRP *influxdb.DBRPMapping
URLSuffix string URLSuffix string
Input io.Reader Input io.Reader
}{ }{
@ -334,7 +334,7 @@ func Test_handlePatchDBRP(t *testing.T) {
"retention_policy": "updaterp", "retention_policy": "updaterp",
"database": "wont_change" "database": "wont_change"
}`), }`),
ExpectedDBRP: &influxdb.DBRPMappingV2{ ExpectedDBRP: &influxdb.DBRPMapping{
ID: influxdbtesting.MustIDBase16("1111111111111111"), ID: influxdbtesting.MustIDBase16("1111111111111111"),
BucketID: influxdbtesting.MustIDBase16("5555f7ed2a035555"), BucketID: influxdbtesting.MustIDBase16("5555f7ed2a035555"),
OrganizationID: influxdbtesting.MustIDBase16("059af7ed2a034000"), OrganizationID: influxdbtesting.MustIDBase16("059af7ed2a034000"),
@ -350,7 +350,7 @@ func Test_handlePatchDBRP(t *testing.T) {
"retention_policy": "updaterp", "retention_policy": "updaterp",
"database": "wont_change" "database": "wont_change"
}`), }`),
ExpectedDBRP: &influxdb.DBRPMappingV2{ ExpectedDBRP: &influxdb.DBRPMapping{
ID: influxdbtesting.MustIDBase16("1111111111111111"), ID: influxdbtesting.MustIDBase16("1111111111111111"),
BucketID: influxdbtesting.MustIDBase16("5555f7ed2a035555"), BucketID: influxdbtesting.MustIDBase16("5555f7ed2a035555"),
OrganizationID: influxdbtesting.MustIDBase16("059af7ed2a034000"), OrganizationID: influxdbtesting.MustIDBase16("059af7ed2a034000"),
@ -397,7 +397,7 @@ func Test_handlePatchDBRP(t *testing.T) {
svc.IDGen = mock.NewIDGenerator("1111111111111111", t) svc.IDGen = mock.NewIDGenerator("1111111111111111", t)
} }
dbrp := &influxdb.DBRPMappingV2{ dbrp := &influxdb.DBRPMapping{
BucketID: influxdbtesting.MustIDBase16("5555f7ed2a035555"), BucketID: influxdbtesting.MustIDBase16("5555f7ed2a035555"),
OrganizationID: influxdbtesting.MustIDBase16("059af7ed2a034000"), OrganizationID: influxdbtesting.MustIDBase16("059af7ed2a034000"),
Database: "mydb", Database: "mydb",
@ -429,7 +429,7 @@ func Test_handlePatchDBRP(t *testing.T) {
return return
} }
dbrpResponse := struct { dbrpResponse := struct {
Content *influxdb.DBRPMappingV2 `json:"content"` Content *influxdb.DBRPMapping `json:"content"`
}{} }{}
if err := json.NewDecoder(resp.Body).Decode(&dbrpResponse); err != nil { if err := json.NewDecoder(resp.Body).Decode(&dbrpResponse); err != nil {
@ -489,7 +489,7 @@ func Test_handleDeleteDBRP(t *testing.T) {
defer shutdown() defer shutdown()
client := server.Client() client := server.Client()
d := &influxdb.DBRPMappingV2{ d := &influxdb.DBRPMapping{
ID: influxdbtesting.MustIDBase16("1111111111111111"), ID: influxdbtesting.MustIDBase16("1111111111111111"),
BucketID: influxdbtesting.MustIDBase16("5555f7ed2a035555"), BucketID: influxdbtesting.MustIDBase16("5555f7ed2a035555"),
OrganizationID: influxdbtesting.MustIDBase16("059af7ed2a034000"), OrganizationID: influxdbtesting.MustIDBase16("059af7ed2a034000"),

View File

@ -9,7 +9,7 @@ import (
var ( var (
ByOrgIDIndexMapping = kv.NewIndexMapping(bucket, byOrgIDIndexBucket, func(v []byte) ([]byte, error) { ByOrgIDIndexMapping = kv.NewIndexMapping(bucket, byOrgIDIndexBucket, func(v []byte) ([]byte, error) {
var dbrp influxdb.DBRPMappingV2 var dbrp influxdb.DBRPMapping
if err := json.Unmarshal(v, &dbrp); err != nil { if err := json.Unmarshal(v, &dbrp); err != nil {
return nil, err return nil, err
} }

View File

@ -9,18 +9,18 @@ import (
"github.com/influxdata/influxdb/v2/authorizer" "github.com/influxdata/influxdb/v2/authorizer"
) )
var _ influxdb.DBRPMappingServiceV2 = (*AuthorizedService)(nil) var _ influxdb.DBRPMappingService = (*AuthorizedService)(nil)
type AuthorizedService struct { type AuthorizedService struct {
influxdb.DBRPMappingServiceV2 influxdb.DBRPMappingService
} }
func NewAuthorizedService(s influxdb.DBRPMappingServiceV2) *AuthorizedService { func NewAuthorizedService(s influxdb.DBRPMappingService) *AuthorizedService {
return &AuthorizedService{DBRPMappingServiceV2: s} return &AuthorizedService{DBRPMappingService: s}
} }
func (svc AuthorizedService) FindByID(ctx context.Context, orgID, id platform.ID) (*influxdb.DBRPMappingV2, error) { func (svc AuthorizedService) FindByID(ctx context.Context, orgID, id platform.ID) (*influxdb.DBRPMapping, error) {
mapping, err := svc.DBRPMappingServiceV2.FindByID(ctx, orgID, id) mapping, err := svc.DBRPMappingService.FindByID(ctx, orgID, id)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -30,35 +30,35 @@ func (svc AuthorizedService) FindByID(ctx context.Context, orgID, id platform.ID
return mapping, nil return mapping, nil
} }
func (svc AuthorizedService) FindMany(ctx context.Context, filter influxdb.DBRPMappingFilterV2, opts ...influxdb.FindOptions) ([]*influxdb.DBRPMappingV2, int, error) { func (svc AuthorizedService) FindMany(ctx context.Context, filter influxdb.DBRPMappingFilter, opts ...influxdb.FindOptions) ([]*influxdb.DBRPMapping, int, error) {
dbrps, _, err := svc.DBRPMappingServiceV2.FindMany(ctx, filter, opts...) dbrps, _, err := svc.DBRPMappingService.FindMany(ctx, filter, opts...)
if err != nil { if err != nil {
return nil, 0, err return nil, 0, err
} }
return authorizer.AuthorizeFindDBRPs(ctx, dbrps) return authorizer.AuthorizeFindDBRPs(ctx, dbrps)
} }
func (svc AuthorizedService) Create(ctx context.Context, t *influxdb.DBRPMappingV2) error { func (svc AuthorizedService) Create(ctx context.Context, t *influxdb.DBRPMapping) error {
if _, _, err := authorizer.AuthorizeWrite(ctx, influxdb.BucketsResourceType, t.BucketID, t.OrganizationID); err != nil { if _, _, err := authorizer.AuthorizeWrite(ctx, influxdb.BucketsResourceType, t.BucketID, t.OrganizationID); err != nil {
return err return err
} }
return svc.DBRPMappingServiceV2.Create(ctx, t) return svc.DBRPMappingService.Create(ctx, t)
} }
func (svc AuthorizedService) Update(ctx context.Context, u *influxdb.DBRPMappingV2) error { func (svc AuthorizedService) Update(ctx context.Context, u *influxdb.DBRPMapping) error {
if _, _, err := authorizer.AuthorizeWrite(ctx, influxdb.BucketsResourceType, u.BucketID, u.OrganizationID); err != nil { if _, _, err := authorizer.AuthorizeWrite(ctx, influxdb.BucketsResourceType, u.BucketID, u.OrganizationID); err != nil {
return err return err
} }
return svc.DBRPMappingServiceV2.Update(ctx, u) return svc.DBRPMappingService.Update(ctx, u)
} }
func (svc AuthorizedService) Delete(ctx context.Context, orgID, id platform.ID) error { func (svc AuthorizedService) Delete(ctx context.Context, orgID, id platform.ID) error {
mapping, err := svc.DBRPMappingServiceV2.FindByID(ctx, orgID, id) mapping, err := svc.DBRPMappingService.FindByID(ctx, orgID, id)
if err != nil { if err != nil {
return err return err
} }
if _, _, err := authorizer.AuthorizeWrite(ctx, influxdb.BucketsResourceType, mapping.BucketID, orgID); err != nil { if _, _, err := authorizer.AuthorizeWrite(ctx, influxdb.BucketsResourceType, mapping.BucketID, orgID); err != nil {
return err return err
} }
return svc.DBRPMappingServiceV2.Delete(ctx, orgID, id) return svc.DBRPMappingService.Delete(ctx, orgID, id)
} }

View File

@ -16,7 +16,7 @@ import (
func TestAuth_FindByID(t *testing.T) { func TestAuth_FindByID(t *testing.T) {
type fields struct { type fields struct {
service influxdb.DBRPMappingServiceV2 service influxdb.DBRPMappingService
} }
type args struct { type args struct {
orgID platform.ID orgID platform.ID
@ -36,9 +36,9 @@ func TestAuth_FindByID(t *testing.T) {
{ {
name: "authorized to access id by org id", name: "authorized to access id by org id",
fields: fields{ fields: fields{
service: &mock.DBRPMappingServiceV2{ service: &mock.DBRPMappingService{
FindByIDFn: func(_ context.Context, _, _ platform.ID) (*influxdb.DBRPMappingV2, error) { FindByIDFn: func(_ context.Context, _, _ platform.ID) (*influxdb.DBRPMapping, error) {
return &influxdb.DBRPMappingV2{ return &influxdb.DBRPMapping{
OrganizationID: platform.ID(1), OrganizationID: platform.ID(1),
BucketID: platform.ID(1), BucketID: platform.ID(1),
}, nil }, nil
@ -63,9 +63,9 @@ func TestAuth_FindByID(t *testing.T) {
{ {
name: "authorized to access id by id", name: "authorized to access id by id",
fields: fields{ fields: fields{
service: &mock.DBRPMappingServiceV2{ service: &mock.DBRPMappingService{
FindByIDFn: func(_ context.Context, _, _ platform.ID) (*influxdb.DBRPMappingV2, error) { FindByIDFn: func(_ context.Context, _, _ platform.ID) (*influxdb.DBRPMapping, error) {
return &influxdb.DBRPMappingV2{ return &influxdb.DBRPMapping{
OrganizationID: platform.ID(1), OrganizationID: platform.ID(1),
BucketID: platform.ID(1), BucketID: platform.ID(1),
}, nil }, nil
@ -90,9 +90,9 @@ func TestAuth_FindByID(t *testing.T) {
{ {
name: "unauthorized to access id by org id", name: "unauthorized to access id by org id",
fields: fields{ fields: fields{
service: &mock.DBRPMappingServiceV2{ service: &mock.DBRPMappingService{
FindByIDFn: func(_ context.Context, _, _ platform.ID) (*influxdb.DBRPMappingV2, error) { FindByIDFn: func(_ context.Context, _, _ platform.ID) (*influxdb.DBRPMapping, error) {
return &influxdb.DBRPMappingV2{ return &influxdb.DBRPMapping{
OrganizationID: platform.ID(2), OrganizationID: platform.ID(2),
BucketID: platform.ID(1), BucketID: platform.ID(1),
}, nil }, nil
@ -120,9 +120,9 @@ func TestAuth_FindByID(t *testing.T) {
{ {
name: "unauthorized to access id by id", name: "unauthorized to access id by id",
fields: fields{ fields: fields{
service: &mock.DBRPMappingServiceV2{ service: &mock.DBRPMappingService{
FindByIDFn: func(_ context.Context, _, _ platform.ID) (*influxdb.DBRPMappingV2, error) { FindByIDFn: func(_ context.Context, _, _ platform.ID) (*influxdb.DBRPMapping, error) {
return &influxdb.DBRPMappingV2{ return &influxdb.DBRPMapping{
OrganizationID: platform.ID(1), OrganizationID: platform.ID(1),
BucketID: platform.ID(1), BucketID: platform.ID(1),
}, nil }, nil
@ -164,15 +164,15 @@ func TestAuth_FindByID(t *testing.T) {
func TestAuth_FindMany(t *testing.T) { func TestAuth_FindMany(t *testing.T) {
type fields struct { type fields struct {
service influxdb.DBRPMappingServiceV2 service influxdb.DBRPMappingService
} }
type args struct { type args struct {
filter influxdb.DBRPMappingFilterV2 filter influxdb.DBRPMappingFilter
permissions []influxdb.Permission permissions []influxdb.Permission
} }
type wants struct { type wants struct {
err error err error
ms []*influxdb.DBRPMappingV2 ms []*influxdb.DBRPMapping
} }
tests := []struct { tests := []struct {
@ -184,9 +184,9 @@ func TestAuth_FindMany(t *testing.T) {
{ {
name: "no result", name: "no result",
fields: fields{ fields: fields{
service: &mock.DBRPMappingServiceV2{ service: &mock.DBRPMappingService{
FindManyFn: func(ctx context.Context, dbrp influxdb.DBRPMappingFilterV2, opts ...influxdb.FindOptions) ([]*influxdb.DBRPMappingV2, int, error) { FindManyFn: func(ctx context.Context, dbrp influxdb.DBRPMappingFilter, opts ...influxdb.FindOptions) ([]*influxdb.DBRPMapping, int, error) {
return []*influxdb.DBRPMappingV2{ return []*influxdb.DBRPMapping{
{ {
ID: 1, ID: 1,
OrganizationID: 1, OrganizationID: 1,
@ -219,19 +219,19 @@ func TestAuth_FindMany(t *testing.T) {
OrgID: influxdbtesting.IDPtr(42), OrgID: influxdbtesting.IDPtr(42),
}, },
}}, }},
filter: influxdb.DBRPMappingFilterV2{}, filter: influxdb.DBRPMappingFilter{},
}, },
wants: wants{ wants: wants{
err: nil, err: nil,
ms: []*influxdb.DBRPMappingV2{}, ms: []*influxdb.DBRPMapping{},
}, },
}, },
{ {
name: "partial", name: "partial",
fields: fields{ fields: fields{
service: &mock.DBRPMappingServiceV2{ service: &mock.DBRPMappingService{
FindManyFn: func(ctx context.Context, dbrp influxdb.DBRPMappingFilterV2, opts ...influxdb.FindOptions) ([]*influxdb.DBRPMappingV2, int, error) { FindManyFn: func(ctx context.Context, dbrp influxdb.DBRPMappingFilter, opts ...influxdb.FindOptions) ([]*influxdb.DBRPMapping, int, error) {
return []*influxdb.DBRPMappingV2{ return []*influxdb.DBRPMapping{
{ {
ID: 1, ID: 1,
OrganizationID: 1, OrganizationID: 1,
@ -264,11 +264,11 @@ func TestAuth_FindMany(t *testing.T) {
OrgID: influxdbtesting.IDPtr(1), OrgID: influxdbtesting.IDPtr(1),
}, },
}}, }},
filter: influxdb.DBRPMappingFilterV2{}, filter: influxdb.DBRPMappingFilter{},
}, },
wants: wants{ wants: wants{
err: nil, err: nil,
ms: []*influxdb.DBRPMappingV2{ ms: []*influxdb.DBRPMapping{
{ {
ID: 1, ID: 1,
OrganizationID: 1, OrganizationID: 1,
@ -285,9 +285,9 @@ func TestAuth_FindMany(t *testing.T) {
{ {
name: "all", name: "all",
fields: fields{ fields: fields{
service: &mock.DBRPMappingServiceV2{ service: &mock.DBRPMappingService{
FindManyFn: func(ctx context.Context, dbrp influxdb.DBRPMappingFilterV2, opts ...influxdb.FindOptions) ([]*influxdb.DBRPMappingV2, int, error) { FindManyFn: func(ctx context.Context, dbrp influxdb.DBRPMappingFilter, opts ...influxdb.FindOptions) ([]*influxdb.DBRPMapping, int, error) {
return []*influxdb.DBRPMappingV2{ return []*influxdb.DBRPMapping{
{ {
ID: 1, ID: 1,
OrganizationID: 1, OrganizationID: 1,
@ -336,11 +336,11 @@ func TestAuth_FindMany(t *testing.T) {
}, },
}, },
}, },
filter: influxdb.DBRPMappingFilterV2{}, filter: influxdb.DBRPMappingFilter{},
}, },
wants: wants{ wants: wants{
err: nil, err: nil,
ms: []*influxdb.DBRPMappingV2{ ms: []*influxdb.DBRPMapping{
{ {
ID: 1, ID: 1,
OrganizationID: 1, OrganizationID: 1,
@ -378,7 +378,7 @@ func TestAuth_FindMany(t *testing.T) {
t.Errorf("got wrong number back") t.Errorf("got wrong number back")
} }
influxdbtesting.ErrorsEqual(t, err, tt.wants.err) influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
if diff := cmp.Diff(tt.wants.ms, gots, influxdbtesting.DBRPMappingCmpOptionsV2...); diff != "" { if diff := cmp.Diff(tt.wants.ms, gots, influxdbtesting.DBRPMappingCmpOptions...); diff != "" {
t.Errorf("unexpected result -want/+got:\n\t%s", diff) t.Errorf("unexpected result -want/+got:\n\t%s", diff)
} }
}) })
@ -387,10 +387,10 @@ func TestAuth_FindMany(t *testing.T) {
func TestAuth_Create(t *testing.T) { func TestAuth_Create(t *testing.T) {
type fields struct { type fields struct {
service influxdb.DBRPMappingServiceV2 service influxdb.DBRPMappingService
} }
type args struct { type args struct {
m influxdb.DBRPMappingV2 m influxdb.DBRPMapping
permission influxdb.Permission permission influxdb.Permission
} }
type wants struct { type wants struct {
@ -406,10 +406,10 @@ func TestAuth_Create(t *testing.T) {
{ {
name: "authorized", name: "authorized",
fields: fields{ fields: fields{
service: &mock.DBRPMappingServiceV2{}, service: &mock.DBRPMappingService{},
}, },
args: args{ args: args{
m: influxdb.DBRPMappingV2{ m: influxdb.DBRPMapping{
ID: 1, ID: 1,
OrganizationID: 1, OrganizationID: 1,
BucketID: 2, BucketID: 2,
@ -430,10 +430,10 @@ func TestAuth_Create(t *testing.T) {
{ {
name: "unauthorized", name: "unauthorized",
fields: fields{ fields: fields{
service: &mock.DBRPMappingServiceV2{}, service: &mock.DBRPMappingService{},
}, },
args: args{ args: args{
m: influxdb.DBRPMappingV2{ m: influxdb.DBRPMapping{
ID: 1, ID: 1,
OrganizationID: 1, OrganizationID: 1,
BucketID: 2, BucketID: 2,
@ -471,7 +471,7 @@ func TestAuth_Create(t *testing.T) {
func TestAuth_Update(t *testing.T) { func TestAuth_Update(t *testing.T) {
type fields struct { type fields struct {
service influxdb.DBRPMappingServiceV2 service influxdb.DBRPMappingService
} }
type args struct { type args struct {
orgID platform.ID orgID platform.ID
@ -491,7 +491,7 @@ func TestAuth_Update(t *testing.T) {
{ {
name: "authorized", name: "authorized",
fields: fields{ fields: fields{
service: &mock.DBRPMappingServiceV2{}, service: &mock.DBRPMappingService{},
}, },
args: args{ args: args{
permission: influxdb.Permission{ permission: influxdb.Permission{
@ -511,7 +511,7 @@ func TestAuth_Update(t *testing.T) {
{ {
name: "unauthorized", name: "unauthorized",
fields: fields{ fields: fields{
service: &mock.DBRPMappingServiceV2{}, service: &mock.DBRPMappingService{},
}, },
args: args{ args: args{
permission: influxdb.Permission{ permission: influxdb.Permission{
@ -541,7 +541,7 @@ func TestAuth_Update(t *testing.T) {
ctx = influxdbcontext.SetAuthorizer(ctx, mock.NewMockAuthorizer(false, []influxdb.Permission{tt.args.permission})) ctx = influxdbcontext.SetAuthorizer(ctx, mock.NewMockAuthorizer(false, []influxdb.Permission{tt.args.permission}))
// Does not matter how we update, we only need to check auth. // Does not matter how we update, we only need to check auth.
err := s.Update(ctx, &influxdb.DBRPMappingV2{ID: tt.args.id, OrganizationID: tt.args.orgID, BucketID: 1}) err := s.Update(ctx, &influxdb.DBRPMapping{ID: tt.args.id, OrganizationID: tt.args.orgID, BucketID: 1})
influxdbtesting.ErrorsEqual(t, err, tt.wants.err) influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
}) })
} }
@ -549,7 +549,7 @@ func TestAuth_Update(t *testing.T) {
func TestAuth_Delete(t *testing.T) { func TestAuth_Delete(t *testing.T) {
type fields struct { type fields struct {
service influxdb.DBRPMappingServiceV2 service influxdb.DBRPMappingService
} }
type args struct { type args struct {
orgID platform.ID orgID platform.ID
@ -569,9 +569,9 @@ func TestAuth_Delete(t *testing.T) {
{ {
name: "authorized", name: "authorized",
fields: fields{ fields: fields{
service: &mock.DBRPMappingServiceV2{ service: &mock.DBRPMappingService{
FindByIDFn: func(_ context.Context, _, _ platform.ID) (*influxdb.DBRPMappingV2, error) { FindByIDFn: func(_ context.Context, _, _ platform.ID) (*influxdb.DBRPMapping, error) {
return &influxdb.DBRPMappingV2{ return &influxdb.DBRPMapping{
OrganizationID: platform.ID(1), OrganizationID: platform.ID(1),
BucketID: platform.ID(1), BucketID: platform.ID(1),
}, nil }, nil
@ -596,9 +596,9 @@ func TestAuth_Delete(t *testing.T) {
{ {
name: "unauthorized", name: "unauthorized",
fields: fields{ fields: fields{
service: &mock.DBRPMappingServiceV2{ service: &mock.DBRPMappingService{
FindByIDFn: func(_ context.Context, _, _ platform.ID) (*influxdb.DBRPMappingV2, error) { FindByIDFn: func(_ context.Context, _, _ platform.ID) (*influxdb.DBRPMapping, error) {
return &influxdb.DBRPMappingV2{ return &influxdb.DBRPMapping{
OrganizationID: platform.ID(1), OrganizationID: platform.ID(1),
BucketID: platform.ID(1), BucketID: platform.ID(1),
}, nil }, nil

View File

@ -0,0 +1,114 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: github.com/influxdata/influxdb/v2 (interfaces: DBRPMappingService)
// Package mocks is a generated GoMock package.
package mocks
import (
context "context"
gomock "github.com/golang/mock/gomock"
influxdb "github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/platform"
reflect "reflect"
)
// MockDBRPMappingService is a mock of DBRPMappingService interface
type MockDBRPMappingService struct {
ctrl *gomock.Controller
recorder *MockDBRPMappingServiceMockRecorder
}
// MockDBRPMappingServiceMockRecorder is the mock recorder for MockDBRPMappingService
type MockDBRPMappingServiceMockRecorder struct {
mock *MockDBRPMappingService
}
// NewMockDBRPMappingService creates a new mock instance
func NewMockDBRPMappingService(ctrl *gomock.Controller) *MockDBRPMappingService {
mock := &MockDBRPMappingService{ctrl: ctrl}
mock.recorder = &MockDBRPMappingServiceMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use
func (m *MockDBRPMappingService) EXPECT() *MockDBRPMappingServiceMockRecorder {
return m.recorder
}
// Create mocks base method
func (m *MockDBRPMappingService) Create(arg0 context.Context, arg1 *influxdb.DBRPMapping) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Create", arg0, arg1)
ret0, _ := ret[0].(error)
return ret0
}
// Create indicates an expected call of Create
func (mr *MockDBRPMappingServiceMockRecorder) Create(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockDBRPMappingService)(nil).Create), arg0, arg1)
}
// Delete mocks base method
func (m *MockDBRPMappingService) Delete(arg0 context.Context, arg1, arg2 platform.ID) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Delete", arg0, arg1, arg2)
ret0, _ := ret[0].(error)
return ret0
}
// Delete indicates an expected call of Delete
func (mr *MockDBRPMappingServiceMockRecorder) Delete(arg0, arg1, arg2 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockDBRPMappingService)(nil).Delete), arg0, arg1, arg2)
}
// FindByID mocks base method
func (m *MockDBRPMappingService) FindByID(arg0 context.Context, arg1, arg2 platform.ID) (*influxdb.DBRPMapping, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "FindByID", arg0, arg1, arg2)
ret0, _ := ret[0].(*influxdb.DBRPMapping)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// FindByID indicates an expected call of FindByID
func (mr *MockDBRPMappingServiceMockRecorder) FindByID(arg0, arg1, arg2 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindByID", reflect.TypeOf((*MockDBRPMappingService)(nil).FindByID), arg0, arg1, arg2)
}
// FindMany mocks base method
func (m *MockDBRPMappingService) FindMany(arg0 context.Context, arg1 influxdb.DBRPMappingFilter, arg2 ...influxdb.FindOptions) ([]*influxdb.DBRPMapping, int, error) {
m.ctrl.T.Helper()
varargs := []interface{}{arg0, arg1}
for _, a := range arg2 {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "FindMany", varargs...)
ret0, _ := ret[0].([]*influxdb.DBRPMapping)
ret1, _ := ret[1].(int)
ret2, _ := ret[2].(error)
return ret0, ret1, ret2
}
// FindMany indicates an expected call of FindMany
func (mr *MockDBRPMappingServiceMockRecorder) FindMany(arg0, arg1 interface{}, arg2 ...interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
varargs := append([]interface{}{arg0, arg1}, arg2...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindMany", reflect.TypeOf((*MockDBRPMappingService)(nil).FindMany), varargs...)
}
// Update mocks base method
func (m *MockDBRPMappingService) Update(arg0 context.Context, arg1 *influxdb.DBRPMapping) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Update", arg0, arg1)
ret0, _ := ret[0].(error)
return ret0
}
// Update indicates an expected call of Update
func (mr *MockDBRPMappingServiceMockRecorder) Update(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockDBRPMappingService)(nil).Update), arg0, arg1)
}

View File

@ -1,114 +0,0 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: github.com/influxdata/influxdb/v2 (interfaces: DBRPMappingServiceV2)
// Package mocks is a generated GoMock package.
package mocks
import (
context "context"
gomock "github.com/golang/mock/gomock"
influxdb "github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/platform"
reflect "reflect"
)
// MockDBRPMappingServiceV2 is a mock of DBRPMappingServiceV2 interface
type MockDBRPMappingServiceV2 struct {
ctrl *gomock.Controller
recorder *MockDBRPMappingServiceV2MockRecorder
}
// MockDBRPMappingServiceV2MockRecorder is the mock recorder for MockDBRPMappingServiceV2
type MockDBRPMappingServiceV2MockRecorder struct {
mock *MockDBRPMappingServiceV2
}
// NewMockDBRPMappingServiceV2 creates a new mock instance
func NewMockDBRPMappingServiceV2(ctrl *gomock.Controller) *MockDBRPMappingServiceV2 {
mock := &MockDBRPMappingServiceV2{ctrl: ctrl}
mock.recorder = &MockDBRPMappingServiceV2MockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use
func (m *MockDBRPMappingServiceV2) EXPECT() *MockDBRPMappingServiceV2MockRecorder {
return m.recorder
}
// Create mocks base method
func (m *MockDBRPMappingServiceV2) Create(arg0 context.Context, arg1 *influxdb.DBRPMappingV2) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Create", arg0, arg1)
ret0, _ := ret[0].(error)
return ret0
}
// Create indicates an expected call of Create
func (mr *MockDBRPMappingServiceV2MockRecorder) Create(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockDBRPMappingServiceV2)(nil).Create), arg0, arg1)
}
// Delete mocks base method
func (m *MockDBRPMappingServiceV2) Delete(arg0 context.Context, arg1, arg2 platform.ID) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Delete", arg0, arg1, arg2)
ret0, _ := ret[0].(error)
return ret0
}
// Delete indicates an expected call of Delete
func (mr *MockDBRPMappingServiceV2MockRecorder) Delete(arg0, arg1, arg2 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockDBRPMappingServiceV2)(nil).Delete), arg0, arg1, arg2)
}
// FindByID mocks base method
func (m *MockDBRPMappingServiceV2) FindByID(arg0 context.Context, arg1, arg2 platform.ID) (*influxdb.DBRPMappingV2, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "FindByID", arg0, arg1, arg2)
ret0, _ := ret[0].(*influxdb.DBRPMappingV2)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// FindByID indicates an expected call of FindByID
func (mr *MockDBRPMappingServiceV2MockRecorder) FindByID(arg0, arg1, arg2 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindByID", reflect.TypeOf((*MockDBRPMappingServiceV2)(nil).FindByID), arg0, arg1, arg2)
}
// FindMany mocks base method
func (m *MockDBRPMappingServiceV2) FindMany(arg0 context.Context, arg1 influxdb.DBRPMappingFilterV2, arg2 ...influxdb.FindOptions) ([]*influxdb.DBRPMappingV2, int, error) {
m.ctrl.T.Helper()
varargs := []interface{}{arg0, arg1}
for _, a := range arg2 {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "FindMany", varargs...)
ret0, _ := ret[0].([]*influxdb.DBRPMappingV2)
ret1, _ := ret[1].(int)
ret2, _ := ret[2].(error)
return ret0, ret1, ret2
}
// FindMany indicates an expected call of FindMany
func (mr *MockDBRPMappingServiceV2MockRecorder) FindMany(arg0, arg1 interface{}, arg2 ...interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
varargs := append([]interface{}{arg0, arg1}, arg2...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindMany", reflect.TypeOf((*MockDBRPMappingServiceV2)(nil).FindMany), varargs...)
}
// Update mocks base method
func (m *MockDBRPMappingServiceV2) Update(arg0 context.Context, arg1 *influxdb.DBRPMappingV2) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Update", arg0, arg1)
ret0, _ := ret[0].(error)
return ret0
}
// Update indicates an expected call of Update
func (mr *MockDBRPMappingServiceV2MockRecorder) Update(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockDBRPMappingServiceV2)(nil).Update), arg0, arg1)
}

View File

@ -43,7 +43,7 @@ var (
defaultBucket = []byte("dbrpdefaultv1") defaultBucket = []byte("dbrpdefaultv1")
) )
var _ influxdb.DBRPMappingServiceV2 = (*AuthorizedService)(nil) var _ influxdb.DBRPMappingService = (*AuthorizedService)(nil)
type Service struct { type Service struct {
store kv.Store store kv.Store
@ -54,7 +54,7 @@ type Service struct {
byOrg *kv.Index byOrg *kv.Index
} }
func indexForeignKey(dbrp influxdb.DBRPMappingV2) []byte { func indexForeignKey(dbrp influxdb.DBRPMapping) []byte {
return composeForeignKey(dbrp.OrganizationID, dbrp.Database) return composeForeignKey(dbrp.OrganizationID, dbrp.Database)
} }
@ -66,13 +66,13 @@ func composeForeignKey(orgID platform.ID, db string) []byte {
return key return key
} }
func NewService(ctx context.Context, bucketSvc influxdb.BucketService, st kv.Store) influxdb.DBRPMappingServiceV2 { func NewService(ctx context.Context, bucketSvc influxdb.BucketService, st kv.Store) influxdb.DBRPMappingService {
return &Service{ return &Service{
store: st, store: st,
IDGen: snowflake.NewDefaultIDGenerator(), IDGen: snowflake.NewDefaultIDGenerator(),
bucketSvc: bucketSvc, bucketSvc: bucketSvc,
byOrgAndDatabase: kv.NewIndex(kv.NewIndexMapping(bucket, indexBucket, func(v []byte) ([]byte, error) { byOrgAndDatabase: kv.NewIndex(kv.NewIndexMapping(bucket, indexBucket, func(v []byte) ([]byte, error) {
var dbrp influxdb.DBRPMappingV2 var dbrp influxdb.DBRPMapping
if err := json.Unmarshal(v, &dbrp); err != nil { if err := json.Unmarshal(v, &dbrp); err != nil {
return nil, err return nil, err
} }
@ -178,10 +178,10 @@ func (s *Service) getFirstBut(tx kv.Tx, compKey []byte, skipID []byte) (next []b
} }
// isDBRPUnique verifies if the triple orgID-database-retention-policy is unique. // isDBRPUnique verifies if the triple orgID-database-retention-policy is unique.
func (s *Service) isDBRPUnique(ctx context.Context, m influxdb.DBRPMappingV2) error { func (s *Service) isDBRPUnique(ctx context.Context, m influxdb.DBRPMapping) error {
return s.store.View(ctx, func(tx kv.Tx) error { return s.store.View(ctx, func(tx kv.Tx) error {
return s.byOrgAndDatabase.Walk(ctx, tx, composeForeignKey(m.OrganizationID, m.Database), func(k, v []byte) (bool, error) { return s.byOrgAndDatabase.Walk(ctx, tx, composeForeignKey(m.OrganizationID, m.Database), func(k, v []byte) (bool, error) {
dbrp := &influxdb.DBRPMappingV2{} dbrp := &influxdb.DBRPMapping{}
if err := json.Unmarshal(v, dbrp); err != nil { if err := json.Unmarshal(v, dbrp); err != nil {
return false, ErrInternalService(err) return false, ErrInternalService(err)
} }
@ -202,13 +202,13 @@ func (s *Service) isDBRPUnique(ctx context.Context, m influxdb.DBRPMappingV2) er
} }
// FindBy returns the mapping for the given ID. // FindBy returns the mapping for the given ID.
func (s *Service) FindByID(ctx context.Context, orgID, id platform.ID) (*influxdb.DBRPMappingV2, error) { func (s *Service) FindByID(ctx context.Context, orgID, id platform.ID) (*influxdb.DBRPMapping, error) {
encodedID, err := id.Encode() encodedID, err := id.Encode()
if err != nil { if err != nil {
return nil, ErrInvalidDBRPID(id.String(), err) return nil, ErrInvalidDBRPID(id.String(), err)
} }
m := &influxdb.DBRPMappingV2{} m := &influxdb.DBRPMapping{}
if err := s.store.View(ctx, func(tx kv.Tx) error { if err := s.store.View(ctx, func(tx kv.Tx) error {
bucket, err := tx.Bucket(bucket) bucket, err := tx.Bucket(bucket)
if err != nil { if err != nil {
@ -239,7 +239,7 @@ func (s *Service) FindByID(ctx context.Context, orgID, id platform.ID) (*influxd
// FindMany returns a list of mappings that match filter and the total count of matching dbrp mappings. // FindMany returns a list of mappings that match filter and the total count of matching dbrp mappings.
// TODO(affo): find a smart way to apply FindOptions to a list of items. // TODO(affo): find a smart way to apply FindOptions to a list of items.
func (s *Service) FindMany(ctx context.Context, filter influxdb.DBRPMappingFilterV2, opts ...influxdb.FindOptions) ([]*influxdb.DBRPMappingV2, int, error) { func (s *Service) FindMany(ctx context.Context, filter influxdb.DBRPMappingFilter, opts ...influxdb.FindOptions) ([]*influxdb.DBRPMapping, int, error) {
// Memoize default IDs. // Memoize default IDs.
defs := make(map[string]*platform.ID) defs := make(map[string]*platform.ID)
get := func(tx kv.Tx, orgID platform.ID, db string) (*platform.ID, error) { get := func(tx kv.Tx, orgID platform.ID, db string) (*platform.ID, error) {
@ -258,10 +258,10 @@ func (s *Service) FindMany(ctx context.Context, filter influxdb.DBRPMappingFilte
return defs[k], nil return defs[k], nil
} }
ms := []*influxdb.DBRPMappingV2{} ms := []*influxdb.DBRPMapping{}
add := func(tx kv.Tx) func(k, v []byte) (bool, error) { add := func(tx kv.Tx) func(k, v []byte) (bool, error) {
return func(k, v []byte) (bool, error) { return func(k, v []byte) (bool, error) {
m := influxdb.DBRPMappingV2{} m := influxdb.DBRPMapping{}
if err := json.Unmarshal(v, &m); err != nil { if err := json.Unmarshal(v, &m); err != nil {
return false, ErrInternalService(err) return false, ErrInternalService(err)
} }
@ -342,7 +342,7 @@ func (s *Service) FindMany(ctx context.Context, filter influxdb.DBRPMappingFilte
// Create creates a new mapping. // Create creates a new mapping.
// If another mapping with same organization ID, database, and retention policy exists, an error is returned. // If another mapping with same organization ID, database, and retention policy exists, an error is returned.
// If the mapping already contains a valid ID, that one is used for storing the mapping. // If the mapping already contains a valid ID, that one is used for storing the mapping.
func (s *Service) Create(ctx context.Context, dbrp *influxdb.DBRPMappingV2) error { func (s *Service) Create(ctx context.Context, dbrp *influxdb.DBRPMapping) error {
if !dbrp.ID.Valid() { if !dbrp.ID.Valid() {
dbrp.ID = s.IDGen.ID() dbrp.ID = s.IDGen.ID()
} }
@ -415,7 +415,7 @@ func (s *Service) Create(ctx context.Context, dbrp *influxdb.DBRPMappingV2) erro
// Updates a mapping. // Updates a mapping.
// If another mapping with same organization ID, database, and retention policy exists, an error is returned. // If another mapping with same organization ID, database, and retention policy exists, an error is returned.
// Un-setting `Default` for a mapping will cause the first one to become the default. // Un-setting `Default` for a mapping will cause the first one to become the default.
func (s *Service) Update(ctx context.Context, dbrp *influxdb.DBRPMappingV2) error { func (s *Service) Update(ctx context.Context, dbrp *influxdb.DBRPMapping) error {
if err := dbrp.Validate(); err != nil { if err := dbrp.Validate(); err != nil {
return ErrInvalidDBRP(err) return ErrInvalidDBRP(err)
} }
@ -524,7 +524,7 @@ func (s *Service) Delete(ctx context.Context, orgID, id platform.ID) error {
// filterFunc is capable to validate if the dbrp is valid from a given filter. // filterFunc is capable to validate if the dbrp is valid from a given filter.
// it runs true if the filtering data are contained in the dbrp. // it runs true if the filtering data are contained in the dbrp.
func filterFunc(dbrp *influxdb.DBRPMappingV2, filter influxdb.DBRPMappingFilterV2) bool { func filterFunc(dbrp *influxdb.DBRPMapping, filter influxdb.DBRPMappingFilter) bool {
return (filter.ID == nil || (*filter.ID) == dbrp.ID) && return (filter.ID == nil || (*filter.ID) == dbrp.ID) &&
(filter.OrgID == nil || (*filter.OrgID) == dbrp.OrganizationID) && (filter.OrgID == nil || (*filter.OrgID) == dbrp.OrganizationID) &&
(filter.BucketID == nil || (*filter.BucketID) == dbrp.BucketID) && (filter.BucketID == nil || (*filter.BucketID) == dbrp.BucketID) &&

View File

@ -4,7 +4,6 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"github.com/influxdata/influxdb/v2/kit/platform"
"io/ioutil" "io/ioutil"
"os" "os"
"testing" "testing"
@ -12,6 +11,7 @@ import (
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/bolt" "github.com/influxdata/influxdb/v2/bolt"
"github.com/influxdata/influxdb/v2/dbrp" "github.com/influxdata/influxdb/v2/dbrp"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/kv" "github.com/influxdata/influxdb/v2/kv"
"github.com/influxdata/influxdb/v2/kv/migration/all" "github.com/influxdata/influxdb/v2/kv/migration/all"
"github.com/influxdata/influxdb/v2/mock" "github.com/influxdata/influxdb/v2/mock"
@ -48,7 +48,7 @@ func NewTestBoltStore(t *testing.T) (kv.Store, func(), error) {
return s, close, nil return s, close, nil
} }
func initDBRPMappingService(f itesting.DBRPMappingFieldsV2, t *testing.T) (influxdb.DBRPMappingServiceV2, func()) { func initDBRPMappingService(f itesting.DBRPMappingFields, t *testing.T) (influxdb.DBRPMappingService, func()) {
s, closeStore, err := NewTestBoltStore(t) s, closeStore, err := NewTestBoltStore(t)
if err != nil { if err != nil {
t.Fatalf("failed to create new bolt kv store: %v", err) t.Fatalf("failed to create new bolt kv store: %v", err)
@ -79,7 +79,7 @@ func initDBRPMappingService(f itesting.DBRPMappingFieldsV2, t *testing.T) (influ
} }
} }
func TestBoltDBRPMappingServiceV2(t *testing.T) { func TestBoltDBRPMappingService(t *testing.T) {
t.Parallel() t.Parallel()
itesting.DBRPMappingServiceV2(initDBRPMappingService, t) itesting.DBRPMappingService(initDBRPMappingService, t)
} }

View File

@ -10,25 +10,25 @@ import (
"github.com/influxdata/influxdb/v2/kit/platform/errors" "github.com/influxdata/influxdb/v2/kit/platform/errors"
) )
// DBRPMappingServiceV2 provides CRUD to DBRPMappingV2s. // DBRPMappingService provides CRUD to DBRPMappingV2s.
type DBRPMappingServiceV2 interface { type DBRPMappingService interface {
// FindBy returns the dbrp mapping for the specified ID. // FindBy returns the dbrp mapping for the specified ID.
// Requires orgID because every resource will be org-scoped. // Requires orgID because every resource will be org-scoped.
FindByID(ctx context.Context, orgID, id platform.ID) (*DBRPMappingV2, error) FindByID(ctx context.Context, orgID, id platform.ID) (*DBRPMapping, error)
// FindMany returns a list of dbrp mappings that match filter and the total count of matching dbrp mappings. // FindMany returns a list of dbrp mappings that match filter and the total count of matching dbrp mappings.
FindMany(ctx context.Context, dbrp DBRPMappingFilterV2, opts ...FindOptions) ([]*DBRPMappingV2, int, error) FindMany(ctx context.Context, dbrp DBRPMappingFilter, opts ...FindOptions) ([]*DBRPMapping, int, error)
// Create creates a new dbrp mapping, if a different mapping exists an error is returned. // Create creates a new dbrp mapping, if a different mapping exists an error is returned.
Create(ctx context.Context, dbrp *DBRPMappingV2) error Create(ctx context.Context, dbrp *DBRPMapping) error
// Update a new dbrp mapping // Update a new dbrp mapping
Update(ctx context.Context, dbrp *DBRPMappingV2) error Update(ctx context.Context, dbrp *DBRPMapping) error
// Delete removes a dbrp mapping. // Delete removes a dbrp mapping.
// Deleting a mapping that does not exists is not an error. // Deleting a mapping that does not exists is not an error.
// Requires orgID because every resource will be org-scoped. // Requires orgID because every resource will be org-scoped.
Delete(ctx context.Context, orgID, id platform.ID) error Delete(ctx context.Context, orgID, id platform.ID) error
} }
// DBRPMappingV2 represents a mapping of a database and retention policy to an organization ID and bucket ID. // DBRPMapping represents a mapping of a database and retention policy to an organization ID and bucket ID.
type DBRPMappingV2 struct { type DBRPMapping struct {
ID platform.ID `json:"id"` ID platform.ID `json:"id"`
Database string `json:"database"` Database string `json:"database"`
RetentionPolicy string `json:"retention_policy"` RetentionPolicy string `json:"retention_policy"`
@ -41,7 +41,7 @@ type DBRPMappingV2 struct {
} }
// Validate reports any validation errors for the mapping. // Validate reports any validation errors for the mapping.
func (m DBRPMappingV2) Validate() error { func (m DBRPMapping) Validate() error {
if !validName(m.Database) { if !validName(m.Database) {
return &errors.Error{ return &errors.Error{
Code: errors.EInvalid, Code: errors.EInvalid,
@ -70,7 +70,7 @@ func (m DBRPMappingV2) Validate() error {
} }
// Equal checks if the two mappings are identical. // Equal checks if the two mappings are identical.
func (m *DBRPMappingV2) Equal(o *DBRPMappingV2) bool { func (m *DBRPMapping) Equal(o *DBRPMapping) bool {
if m == o { if m == o {
return true return true
} }
@ -90,8 +90,8 @@ func (m *DBRPMappingV2) Equal(o *DBRPMappingV2) bool {
m.BucketID == o.BucketID m.BucketID == o.BucketID
} }
// DBRPMappingFilterV2 represents a set of filters that restrict the returned results. // DBRPMappingFilter represents a set of filters that restrict the returned results.
type DBRPMappingFilterV2 struct { type DBRPMappingFilter struct {
ID *platform.ID ID *platform.ID
OrgID *platform.ID OrgID *platform.ID
BucketID *platform.ID BucketID *platform.ID
@ -101,7 +101,7 @@ type DBRPMappingFilterV2 struct {
Default *bool Default *bool
} }
func (f DBRPMappingFilterV2) String() string { func (f DBRPMappingFilter) String() string {
var s strings.Builder var s strings.Builder
s.WriteString("{ id:") s.WriteString("{ id:")
@ -149,69 +149,6 @@ func (f DBRPMappingFilterV2) String() string {
return s.String() return s.String()
} }
// DBRPMappingService provides a mapping of cluster, database and retention policy to an organization ID and bucket ID.
type DBRPMappingService interface {
// FindBy returns the dbrp mapping the for cluster, db and rp.
FindBy(ctx context.Context, cluster, db, rp string) (*DBRPMapping, error)
// Find returns the first dbrp mapping the matches the filter.
Find(ctx context.Context, filter DBRPMappingFilter) (*DBRPMapping, error)
// FindMany returns a list of dbrp mappings that match filter and the total count of matching dbrp mappings.
FindMany(ctx context.Context, filter DBRPMappingFilter, opt ...FindOptions) ([]*DBRPMapping, int, error)
// Create creates a new dbrp mapping, if a different mapping exists an error is returned.
Create(ctx context.Context, dbrpMap *DBRPMapping) error
// Delete removes a dbrp mapping.
// Deleting a mapping that does not exists is not an error.
Delete(ctx context.Context, cluster, db, rp string) error
}
// DBRPMapping represents a mapping of a cluster, database and retention policy to an organization ID and bucket ID.
type DBRPMapping struct {
Cluster string `json:"cluster"`
Database string `json:"database"`
RetentionPolicy string `json:"retention_policy"`
// Default indicates if this mapping is the default for the cluster and database.
Default bool `json:"default"`
OrganizationID platform.ID `json:"organization_id"`
BucketID platform.ID `json:"bucket_id"`
}
// Validate reports any validation errors for the mapping.
func (m DBRPMapping) Validate() error {
if !validName(m.Cluster) {
return &errors.Error{
Code: errors.EInvalid,
Msg: "cluster must contain at least one character and only be letters, numbers, '_', '-', and '.'",
}
}
if !validName(m.Database) {
return &errors.Error{
Code: errors.EInvalid,
Msg: "database must contain at least one character and only be letters, numbers, '_', '-', and '.'",
}
}
if !validName(m.RetentionPolicy) {
return &errors.Error{
Code: errors.EInvalid,
Msg: "retentionPolicy must contain at least one character and only be letters, numbers, '_', '-', and '.'",
}
}
if !m.OrganizationID.Valid() {
return &errors.Error{
Code: errors.EInvalid,
Msg: "organizationID is required",
}
}
if !m.BucketID.Valid() {
return &errors.Error{
Code: errors.EInvalid,
Msg: "bucketID is required",
}
}
return nil
}
// validName checks to see if the given name can would be valid for DB/RP name // validName checks to see if the given name can would be valid for DB/RP name
func validName(name string) bool { func validName(name string) bool {
for _, r := range name { for _, r := range name {
@ -224,65 +161,3 @@ func validName(name string) bool {
name != ".." && name != ".." &&
!strings.ContainsAny(name, `/\`) !strings.ContainsAny(name, `/\`)
} }
// Equal checks if the two mappings are identical.
func (m *DBRPMapping) Equal(o *DBRPMapping) bool {
if m == o {
return true
}
if m == nil || o == nil {
return false
}
return m.Cluster == o.Cluster &&
m.Database == o.Database &&
m.RetentionPolicy == o.RetentionPolicy &&
m.Default == o.Default &&
m.OrganizationID.Valid() &&
o.OrganizationID.Valid() &&
m.BucketID.Valid() &&
o.BucketID.Valid() &&
m.OrganizationID == o.OrganizationID &&
m.BucketID == o.BucketID
}
// DBRPMappingFilter represents a set of filters that restrict the returned results by cluster, database and retention policy.
type DBRPMappingFilter struct {
Cluster *string
Database *string
RetentionPolicy *string
Default *bool
}
func (f DBRPMappingFilter) String() string {
var s strings.Builder
s.WriteString("{")
s.WriteString("cluster:")
if f.Cluster != nil {
s.WriteString(*f.Cluster)
} else {
s.WriteString("<nil>")
}
s.WriteString(" db:")
if f.Database != nil {
s.WriteString(*f.Database)
} else {
s.WriteString("<nil>")
}
s.WriteString(" rp:")
if f.RetentionPolicy != nil {
s.WriteString(*f.RetentionPolicy)
} else {
s.WriteString("<nil>")
}
s.WriteString(" default:")
if f.Default != nil {
s.WriteString(strconv.FormatBool(*f.Default))
} else {
s.WriteString("<nil>")
}
s.WriteString("}")
return s.String()
}

View File

@ -1,16 +1,15 @@
package influxdb_test package influxdb_test
import ( import (
platform2 "github.com/influxdata/influxdb/v2/kit/platform"
"testing" "testing"
platform "github.com/influxdata/influxdb/v2" platform "github.com/influxdata/influxdb/v2"
platform2 "github.com/influxdata/influxdb/v2/kit/platform"
platformtesting "github.com/influxdata/influxdb/v2/testing" platformtesting "github.com/influxdata/influxdb/v2/testing"
) )
func TestDBRPMapping_Validate(t *testing.T) { func TestDBRPMapping_Validate(t *testing.T) {
type fields struct { type fields struct {
Cluster string
Database string Database string
RetentionPolicy string RetentionPolicy string
Default bool Default bool
@ -22,17 +21,9 @@ func TestDBRPMapping_Validate(t *testing.T) {
fields fields fields fields
wantErr bool wantErr bool
}{ }{
{
name: "mapping requires a cluster",
fields: fields{
Cluster: "",
},
wantErr: true,
},
{ {
name: "mapping requires a database", name: "mapping requires a database",
fields: fields{ fields: fields{
Cluster: "abc",
Database: "", Database: "",
}, },
wantErr: true, wantErr: true,
@ -40,7 +31,6 @@ func TestDBRPMapping_Validate(t *testing.T) {
{ {
name: "mapping requires an rp", name: "mapping requires an rp",
fields: fields{ fields: fields{
Cluster: "abc",
Database: "telegraf", Database: "telegraf",
RetentionPolicy: "", RetentionPolicy: "",
}, },
@ -49,7 +39,6 @@ func TestDBRPMapping_Validate(t *testing.T) {
{ {
name: "mapping requires an orgid", name: "mapping requires an orgid",
fields: fields{ fields: fields{
Cluster: "abc",
Database: "telegraf", Database: "telegraf",
RetentionPolicy: "autogen", RetentionPolicy: "autogen",
}, },
@ -58,24 +47,15 @@ func TestDBRPMapping_Validate(t *testing.T) {
{ {
name: "mapping requires a bucket id", name: "mapping requires a bucket id",
fields: fields{ fields: fields{
Cluster: "abc",
Database: "telegraf", Database: "telegraf",
RetentionPolicy: "autogen", RetentionPolicy: "autogen",
OrganizationID: platformtesting.MustIDBase16("debac1e0deadbeef"), OrganizationID: platformtesting.MustIDBase16("debac1e0deadbeef"),
}, },
wantErr: true, wantErr: true,
}, },
{
name: "cluster name cannot have non-printable characters.",
fields: fields{
Cluster: string([]byte{0x0D}),
},
wantErr: true,
},
{ {
name: "db cannot have non-letters/numbers/_/./-", name: "db cannot have non-letters/numbers/_/./-",
fields: fields{ fields: fields{
Cluster: "12345_.",
Database: string([]byte{0x0D}), Database: string([]byte{0x0D}),
}, },
wantErr: true, wantErr: true,
@ -83,7 +63,6 @@ func TestDBRPMapping_Validate(t *testing.T) {
{ {
name: "rp cannot have non-printable characters", name: "rp cannot have non-printable characters",
fields: fields{ fields: fields{
Cluster: "12345",
Database: "telegraf", Database: "telegraf",
RetentionPolicy: string([]byte{0x0D}), RetentionPolicy: string([]byte{0x0D}),
}, },
@ -92,7 +71,6 @@ func TestDBRPMapping_Validate(t *testing.T) {
{ {
name: "dash accepted as valid database", name: "dash accepted as valid database",
fields: fields{ fields: fields{
Cluster: "12345_.",
Database: "howdy-doody", Database: "howdy-doody",
RetentionPolicy: "autogen", RetentionPolicy: "autogen",
OrganizationID: platformtesting.MustIDBase16("debac1e0deadbeef"), OrganizationID: platformtesting.MustIDBase16("debac1e0deadbeef"),
@ -103,7 +81,6 @@ func TestDBRPMapping_Validate(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
m := platform.DBRPMapping{ m := platform.DBRPMapping{
Cluster: tt.fields.Cluster,
Database: tt.fields.Database, Database: tt.fields.Database,
RetentionPolicy: tt.fields.RetentionPolicy, RetentionPolicy: tt.fields.RetentionPolicy,
Default: tt.fields.Default, Default: tt.fields.Default,

View File

@ -73,7 +73,7 @@ type APIBackend struct {
PasswordV1Service influxdb.PasswordsService PasswordV1Service influxdb.PasswordsService
AuthorizerV1 influxdb.AuthorizerV1 AuthorizerV1 influxdb.AuthorizerV1
OnboardingService influxdb.OnboardingService OnboardingService influxdb.OnboardingService
DBRPService influxdb.DBRPMappingServiceV2 DBRPService influxdb.DBRPMappingService
BucketService influxdb.BucketService BucketService influxdb.BucketService
SessionService influxdb.SessionService SessionService influxdb.SessionService
UserService influxdb.UserService UserService influxdb.UserService

View File

@ -50,7 +50,7 @@ type Service struct {
*NotificationEndpointService *NotificationEndpointService
*TelegrafService *TelegrafService
*LabelService *LabelService
DBRPMappingServiceV2 *dbrp.Client DBRPMappingService *dbrp.Client
} }
// NewService returns a service that is an HTTP client to a remote. // NewService returns a service that is an HTTP client to a remote.
@ -80,7 +80,7 @@ func NewService(httpClient *httpc.Client, addr, token string) (*Service, error)
NotificationEndpointService: &NotificationEndpointService{Client: httpClient}, NotificationEndpointService: &NotificationEndpointService{Client: httpClient},
TelegrafService: NewTelegrafService(httpClient), TelegrafService: NewTelegrafService(httpClient),
LabelService: &LabelService{Client: httpClient}, LabelService: &LabelService{Client: httpClient},
DBRPMappingServiceV2: dbrp.NewClient(httpClient), DBRPMappingService: dbrp.NewClient(httpClient),
}, nil }, nil
} }

View File

@ -15,7 +15,7 @@ func newLegacyBackend(b *APIBackend) *legacy.Backend {
OrganizationService: b.OrganizationService, OrganizationService: b.OrganizationService,
BucketService: b.BucketService, BucketService: b.BucketService,
PointsWriter: b.PointsWriter, PointsWriter: b.PointsWriter,
DBRPMappingServiceV2: b.DBRPService, DBRPMappingService: b.DBRPService,
ProxyQueryService: b.InfluxQLService, ProxyQueryService: b.InfluxQLService,
InfluxqldQueryService: b.InfluxqldService, InfluxqldQueryService: b.InfluxqldService,
WriteEventRecorder: b.WriteEventRecorder, WriteEventRecorder: b.WriteEventRecorder,

View File

@ -33,7 +33,7 @@ type Backend struct {
OrganizationService influxdb.OrganizationService OrganizationService influxdb.OrganizationService
BucketService influxdb.BucketService BucketService influxdb.BucketService
PointsWriter storage.PointsWriter PointsWriter storage.PointsWriter
DBRPMappingServiceV2 influxdb.DBRPMappingServiceV2 DBRPMappingService influxdb.DBRPMappingService
ProxyQueryService query.ProxyQueryService ProxyQueryService query.ProxyQueryService
InfluxqldQueryService influxql.ProxyQueryService InfluxqldQueryService influxql.ProxyQueryService
} }

View File

@ -34,7 +34,7 @@ type PointsWriterBackend struct {
EventRecorder metric.EventRecorder EventRecorder metric.EventRecorder
BucketService influxdb.BucketService BucketService influxdb.BucketService
PointsWriter storage.PointsWriter PointsWriter storage.PointsWriter
DBRPMappingService influxdb.DBRPMappingServiceV2 DBRPMappingService influxdb.DBRPMappingService
} }
// NewPointsWriterBackend creates a new backend for legacy work. // NewPointsWriterBackend creates a new backend for legacy work.
@ -45,7 +45,7 @@ func NewPointsWriterBackend(b *Backend) *PointsWriterBackend {
EventRecorder: b.WriteEventRecorder, EventRecorder: b.WriteEventRecorder,
BucketService: b.BucketService, BucketService: b.BucketService,
PointsWriter: b.PointsWriter, PointsWriter: b.PointsWriter,
DBRPMappingService: b.DBRPMappingServiceV2, DBRPMappingService: b.DBRPMappingService,
} }
} }
@ -55,7 +55,7 @@ type WriteHandler struct {
EventRecorder metric.EventRecorder EventRecorder metric.EventRecorder
BucketService influxdb.BucketService BucketService influxdb.BucketService
PointsWriter storage.PointsWriter PointsWriter storage.PointsWriter
DBRPMappingService influxdb.DBRPMappingServiceV2 DBRPMappingService influxdb.DBRPMappingService
router *httprouter.Router router *httprouter.Router
logger *zap.Logger logger *zap.Logger
@ -201,10 +201,10 @@ func checkBucketWritePermissions(auth influxdb.Authorizer, orgID, bucketID platf
return nil return nil
} }
// findMapping finds a DBRPMappingV2 for the database and retention policy // findMapping finds a DBRPMapping for the database and retention policy
// combination. // combination.
func (h *WriteHandler) findMapping(ctx context.Context, orgID platform.ID, db, rp string) (*influxdb.DBRPMappingV2, error) { func (h *WriteHandler) findMapping(ctx context.Context, orgID platform.ID, db, rp string) (*influxdb.DBRPMapping, error) {
filter := influxdb.DBRPMappingFilterV2{ filter := influxdb.DBRPMappingFilter{
OrgID: &orgID, OrgID: &orgID,
Database: &db, Database: &db,
} }

View File

@ -35,7 +35,7 @@ func TestWriteHandler_BucketAndMappingExistsDefaultRP(t *testing.T) {
var ( var (
// Mocked Services // Mocked Services
eventRecorder = mocks.NewMockEventRecorder(ctrl) eventRecorder = mocks.NewMockEventRecorder(ctrl)
dbrpMappingSvc = mocks.NewMockDBRPMappingServiceV2(ctrl) dbrpMappingSvc = mocks.NewMockDBRPMappingService(ctrl)
bucketService = mocks.NewMockBucketService(ctrl) bucketService = mocks.NewMockBucketService(ctrl)
pointsWriter = mocks.NewMockPointsWriter(ctrl) pointsWriter = mocks.NewMockPointsWriter(ctrl)
@ -48,7 +48,7 @@ func TestWriteHandler_BucketAndMappingExistsDefaultRP(t *testing.T) {
RetentionPolicyName: "autogen", RetentionPolicyName: "autogen",
RetentionPeriod: 72 * time.Hour, RetentionPeriod: 72 * time.Hour,
} }
mapping = &influxdb.DBRPMappingV2{ mapping = &influxdb.DBRPMapping{
OrganizationID: orgID, OrganizationID: orgID,
BucketID: bucket.ID, BucketID: bucket.ID,
Database: "mydb", Database: "mydb",
@ -61,11 +61,11 @@ func TestWriteHandler_BucketAndMappingExistsDefaultRP(t *testing.T) {
findAutogenMapping := dbrpMappingSvc. findAutogenMapping := dbrpMappingSvc.
EXPECT(). EXPECT().
FindMany(gomock.Any(), influxdb.DBRPMappingFilterV2{ FindMany(gomock.Any(), influxdb.DBRPMappingFilter{
OrgID: &mapping.OrganizationID, OrgID: &mapping.OrganizationID,
Database: &mapping.Database, Database: &mapping.Database,
Default: &mapping.Default, Default: &mapping.Default,
}).Return([]*influxdb.DBRPMappingV2{mapping}, 1, nil) }).Return([]*influxdb.DBRPMapping{mapping}, 1, nil)
findBucketByID := bucketService. findBucketByID := bucketService.
EXPECT(). EXPECT().
@ -116,7 +116,7 @@ func TestWriteHandler_BucketAndMappingExistsSpecificRP(t *testing.T) {
var ( var (
// Mocked Services // Mocked Services
eventRecorder = mocks.NewMockEventRecorder(ctrl) eventRecorder = mocks.NewMockEventRecorder(ctrl)
dbrpMappingSvc = mocks.NewMockDBRPMappingServiceV2(ctrl) dbrpMappingSvc = mocks.NewMockDBRPMappingService(ctrl)
bucketService = mocks.NewMockBucketService(ctrl) bucketService = mocks.NewMockBucketService(ctrl)
pointsWriter = mocks.NewMockPointsWriter(ctrl) pointsWriter = mocks.NewMockPointsWriter(ctrl)
@ -129,7 +129,7 @@ func TestWriteHandler_BucketAndMappingExistsSpecificRP(t *testing.T) {
RetentionPolicyName: "autogen", RetentionPolicyName: "autogen",
RetentionPeriod: 72 * time.Hour, RetentionPeriod: 72 * time.Hour,
} }
mapping = &influxdb.DBRPMappingV2{ mapping = &influxdb.DBRPMapping{
OrganizationID: orgID, OrganizationID: orgID,
BucketID: bucket.ID, BucketID: bucket.ID,
Database: "mydb", Database: "mydb",
@ -142,11 +142,11 @@ func TestWriteHandler_BucketAndMappingExistsSpecificRP(t *testing.T) {
findAutogenMapping := dbrpMappingSvc. findAutogenMapping := dbrpMappingSvc.
EXPECT(). EXPECT().
FindMany(gomock.Any(), influxdb.DBRPMappingFilterV2{ FindMany(gomock.Any(), influxdb.DBRPMappingFilter{
OrgID: &mapping.OrganizationID, OrgID: &mapping.OrganizationID,
Database: &mapping.Database, Database: &mapping.Database,
RetentionPolicy: &mapping.RetentionPolicy, RetentionPolicy: &mapping.RetentionPolicy,
}).Return([]*influxdb.DBRPMappingV2{mapping}, 1, nil) }).Return([]*influxdb.DBRPMapping{mapping}, 1, nil)
findBucketByID := bucketService. findBucketByID := bucketService.
EXPECT(). EXPECT().
@ -197,7 +197,7 @@ func TestWriteHandler_PartialWrite(t *testing.T) {
var ( var (
// Mocked Services // Mocked Services
eventRecorder = mocks.NewMockEventRecorder(ctrl) eventRecorder = mocks.NewMockEventRecorder(ctrl)
dbrpMappingSvc = mocks.NewMockDBRPMappingServiceV2(ctrl) dbrpMappingSvc = mocks.NewMockDBRPMappingService(ctrl)
bucketService = mocks.NewMockBucketService(ctrl) bucketService = mocks.NewMockBucketService(ctrl)
pointsWriter = mocks.NewMockPointsWriter(ctrl) pointsWriter = mocks.NewMockPointsWriter(ctrl)
@ -210,7 +210,7 @@ func TestWriteHandler_PartialWrite(t *testing.T) {
RetentionPolicyName: "autogen", RetentionPolicyName: "autogen",
RetentionPeriod: 72 * time.Hour, RetentionPeriod: 72 * time.Hour,
} }
mapping = &influxdb.DBRPMappingV2{ mapping = &influxdb.DBRPMapping{
OrganizationID: orgID, OrganizationID: orgID,
BucketID: bucket.ID, BucketID: bucket.ID,
Database: "mydb", Database: "mydb",
@ -223,11 +223,11 @@ func TestWriteHandler_PartialWrite(t *testing.T) {
findAutogenMapping := dbrpMappingSvc. findAutogenMapping := dbrpMappingSvc.
EXPECT(). EXPECT().
FindMany(gomock.Any(), influxdb.DBRPMappingFilterV2{ FindMany(gomock.Any(), influxdb.DBRPMappingFilter{
OrgID: &mapping.OrganizationID, OrgID: &mapping.OrganizationID,
Database: &mapping.Database, Database: &mapping.Database,
RetentionPolicy: &mapping.RetentionPolicy, RetentionPolicy: &mapping.RetentionPolicy,
}).Return([]*influxdb.DBRPMappingV2{mapping}, 1, nil) }).Return([]*influxdb.DBRPMapping{mapping}, 1, nil)
findBucketByID := bucketService. findBucketByID := bucketService.
EXPECT(). EXPECT().
@ -279,7 +279,7 @@ func TestWriteHandler_BucketAndMappingExistsNoPermissions(t *testing.T) {
var ( var (
// Mocked Services // Mocked Services
eventRecorder = mocks.NewMockEventRecorder(ctrl) eventRecorder = mocks.NewMockEventRecorder(ctrl)
dbrpMappingSvc = mocks.NewMockDBRPMappingServiceV2(ctrl) dbrpMappingSvc = mocks.NewMockDBRPMappingService(ctrl)
bucketService = mocks.NewMockBucketService(ctrl) bucketService = mocks.NewMockBucketService(ctrl)
pointsWriter = mocks.NewMockPointsWriter(ctrl) pointsWriter = mocks.NewMockPointsWriter(ctrl)
@ -292,7 +292,7 @@ func TestWriteHandler_BucketAndMappingExistsNoPermissions(t *testing.T) {
RetentionPolicyName: "autogen", RetentionPolicyName: "autogen",
RetentionPeriod: 72 * time.Hour, RetentionPeriod: 72 * time.Hour,
} }
mapping = &influxdb.DBRPMappingV2{ mapping = &influxdb.DBRPMapping{
OrganizationID: orgID, OrganizationID: orgID,
BucketID: bucket.ID, BucketID: bucket.ID,
Database: "mydb", Database: "mydb",
@ -305,11 +305,11 @@ func TestWriteHandler_BucketAndMappingExistsNoPermissions(t *testing.T) {
findAutogenMapping := dbrpMappingSvc. findAutogenMapping := dbrpMappingSvc.
EXPECT(). EXPECT().
FindMany(gomock.Any(), influxdb.DBRPMappingFilterV2{ FindMany(gomock.Any(), influxdb.DBRPMappingFilter{
OrgID: &mapping.OrganizationID, OrgID: &mapping.OrganizationID,
Database: &mapping.Database, Database: &mapping.Database,
Default: &mapping.Default, Default: &mapping.Default,
}).Return([]*influxdb.DBRPMappingV2{mapping}, 1, nil) }).Return([]*influxdb.DBRPMapping{mapping}, 1, nil)
findBucketByID := bucketService. findBucketByID := bucketService.
EXPECT(). EXPECT().
@ -354,7 +354,7 @@ func TestWriteHandler_MappingNotExists(t *testing.T) {
var ( var (
// Mocked Services // Mocked Services
eventRecorder = mocks.NewMockEventRecorder(ctrl) eventRecorder = mocks.NewMockEventRecorder(ctrl)
dbrpMappingSvc = mocks.NewMockDBRPMappingServiceV2(ctrl) dbrpMappingSvc = mocks.NewMockDBRPMappingService(ctrl)
bucketService = mocks.NewMockBucketService(ctrl) bucketService = mocks.NewMockBucketService(ctrl)
pointsWriter = mocks.NewMockPointsWriter(ctrl) pointsWriter = mocks.NewMockPointsWriter(ctrl)
@ -367,7 +367,7 @@ func TestWriteHandler_MappingNotExists(t *testing.T) {
RetentionPolicyName: "autogen", RetentionPolicyName: "autogen",
RetentionPeriod: 72 * time.Hour, RetentionPeriod: 72 * time.Hour,
} }
mapping = &influxdb.DBRPMappingV2{ mapping = &influxdb.DBRPMapping{
OrganizationID: orgID, OrganizationID: orgID,
BucketID: bucket.ID, BucketID: bucket.ID,
Database: "mydb", Database: "mydb",
@ -380,7 +380,7 @@ func TestWriteHandler_MappingNotExists(t *testing.T) {
findAutogenMapping := dbrpMappingSvc. findAutogenMapping := dbrpMappingSvc.
EXPECT(). EXPECT().
FindMany(gomock.Any(), influxdb.DBRPMappingFilterV2{ FindMany(gomock.Any(), influxdb.DBRPMappingFilter{
OrgID: &mapping.OrganizationID, OrgID: &mapping.OrganizationID,
Database: &mapping.Database, Database: &mapping.Database,
RetentionPolicy: &badRp, RetentionPolicy: &badRp,

View File

@ -6,6 +6,7 @@ package mocks
import ( import (
context "context" context "context"
"github.com/influxdata/influxdb/v2/kit/platform"
reflect "reflect" reflect "reflect"
gomock "github.com/golang/mock/gomock" gomock "github.com/golang/mock/gomock"
@ -50,47 +51,32 @@ func (mr *MockDBRPMappingServiceMockRecorder) Create(arg0, arg1 interface{}) *go
} }
// Delete mocks base method // Delete mocks base method
func (m *MockDBRPMappingService) Delete(arg0 context.Context, arg1, arg2, arg3 string) error { func (m *MockDBRPMappingService) Delete(arg0 context.Context, arg1, arg2 platform.ID) error {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Delete", arg0, arg1, arg2, arg3) ret := m.ctrl.Call(m, "Delete", arg0, arg1, arg2)
ret0, _ := ret[0].(error) ret0, _ := ret[0].(error)
return ret0 return ret0
} }
// Delete indicates an expected call of Delete // Delete indicates an expected call of Delete
func (mr *MockDBRPMappingServiceMockRecorder) Delete(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { func (mr *MockDBRPMappingServiceMockRecorder) Delete(arg0, arg1, arg2 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper() mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockDBRPMappingService)(nil).Delete), arg0, arg1, arg2, arg3) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockDBRPMappingService)(nil).Delete), arg0, arg1, arg2)
} }
// Find mocks base method // FindByID mocks base method
func (m *MockDBRPMappingService) Find(arg0 context.Context, arg1 influxdb.DBRPMappingFilter) (*influxdb.DBRPMapping, error) { func (m *MockDBRPMappingService) FindByID(arg0 context.Context, arg1, arg2 platform.ID) (*influxdb.DBRPMapping, error) {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Find", arg0, arg1) ret := m.ctrl.Call(m, "FindByID", arg0, arg1, arg2)
ret0, _ := ret[0].(*influxdb.DBRPMapping) ret0, _ := ret[0].(*influxdb.DBRPMapping)
ret1, _ := ret[1].(error) ret1, _ := ret[1].(error)
return ret0, ret1 return ret0, ret1
} }
// Find indicates an expected call of Find // FindByID indicates an expected call of FindByID
func (mr *MockDBRPMappingServiceMockRecorder) Find(arg0, arg1 interface{}) *gomock.Call { func (mr *MockDBRPMappingServiceMockRecorder) FindByID(arg0, arg1, arg2 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper() mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Find", reflect.TypeOf((*MockDBRPMappingService)(nil).Find), arg0, arg1) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindByID", reflect.TypeOf((*MockDBRPMappingService)(nil).FindByID), arg0, arg1, arg2)
}
// FindBy mocks base method
func (m *MockDBRPMappingService) FindBy(arg0 context.Context, arg1, arg2, arg3 string) (*influxdb.DBRPMapping, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "FindBy", arg0, arg1, arg2, arg3)
ret0, _ := ret[0].(*influxdb.DBRPMapping)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// FindBy indicates an expected call of FindBy
func (mr *MockDBRPMappingServiceMockRecorder) FindBy(arg0, arg1, arg2, arg3 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindBy", reflect.TypeOf((*MockDBRPMappingService)(nil).FindBy), arg0, arg1, arg2, arg3)
} }
// FindMany mocks base method // FindMany mocks base method
@ -113,3 +99,17 @@ func (mr *MockDBRPMappingServiceMockRecorder) FindMany(arg0, arg1 interface{}, a
varargs := append([]interface{}{arg0, arg1}, arg2...) varargs := append([]interface{}{arg0, arg1}, arg2...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindMany", reflect.TypeOf((*MockDBRPMappingService)(nil).FindMany), varargs...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindMany", reflect.TypeOf((*MockDBRPMappingService)(nil).FindMany), varargs...)
} }
// Update mocks base method
func (m *MockDBRPMappingService) Update(arg0 context.Context, arg1 *influxdb.DBRPMapping) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Update", arg0, arg1)
ret0, _ := ret[0].(error)
return ret0
}
// Update indicates an expected call of Update
func (mr *MockDBRPMappingServiceMockRecorder) Update(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockDBRPMappingService)(nil).Update), arg0, arg1)
}

View File

@ -1,115 +0,0 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: github.com/influxdata/influxdb/v2 (interfaces: DBRPMappingServiceV2)
// Package mocks is a generated GoMock package.
package mocks
import (
context "context"
"github.com/influxdata/influxdb/v2/kit/platform"
reflect "reflect"
gomock "github.com/golang/mock/gomock"
influxdb "github.com/influxdata/influxdb/v2"
)
// MockDBRPMappingServiceV2 is a mock of DBRPMappingServiceV2 interface
type MockDBRPMappingServiceV2 struct {
ctrl *gomock.Controller
recorder *MockDBRPMappingServiceV2MockRecorder
}
// MockDBRPMappingServiceV2MockRecorder is the mock recorder for MockDBRPMappingServiceV2
type MockDBRPMappingServiceV2MockRecorder struct {
mock *MockDBRPMappingServiceV2
}
// NewMockDBRPMappingServiceV2 creates a new mock instance
func NewMockDBRPMappingServiceV2(ctrl *gomock.Controller) *MockDBRPMappingServiceV2 {
mock := &MockDBRPMappingServiceV2{ctrl: ctrl}
mock.recorder = &MockDBRPMappingServiceV2MockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use
func (m *MockDBRPMappingServiceV2) EXPECT() *MockDBRPMappingServiceV2MockRecorder {
return m.recorder
}
// Create mocks base method
func (m *MockDBRPMappingServiceV2) Create(arg0 context.Context, arg1 *influxdb.DBRPMappingV2) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Create", arg0, arg1)
ret0, _ := ret[0].(error)
return ret0
}
// Create indicates an expected call of Create
func (mr *MockDBRPMappingServiceV2MockRecorder) Create(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockDBRPMappingServiceV2)(nil).Create), arg0, arg1)
}
// Delete mocks base method
func (m *MockDBRPMappingServiceV2) Delete(arg0 context.Context, arg1, arg2 platform.ID) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Delete", arg0, arg1, arg2)
ret0, _ := ret[0].(error)
return ret0
}
// Delete indicates an expected call of Delete
func (mr *MockDBRPMappingServiceV2MockRecorder) Delete(arg0, arg1, arg2 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockDBRPMappingServiceV2)(nil).Delete), arg0, arg1, arg2)
}
// FindByID mocks base method
func (m *MockDBRPMappingServiceV2) FindByID(arg0 context.Context, arg1, arg2 platform.ID) (*influxdb.DBRPMappingV2, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "FindByID", arg0, arg1, arg2)
ret0, _ := ret[0].(*influxdb.DBRPMappingV2)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// FindByID indicates an expected call of FindByID
func (mr *MockDBRPMappingServiceV2MockRecorder) FindByID(arg0, arg1, arg2 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindByID", reflect.TypeOf((*MockDBRPMappingServiceV2)(nil).FindByID), arg0, arg1, arg2)
}
// FindMany mocks base method
func (m *MockDBRPMappingServiceV2) FindMany(arg0 context.Context, arg1 influxdb.DBRPMappingFilterV2, arg2 ...influxdb.FindOptions) ([]*influxdb.DBRPMappingV2, int, error) {
m.ctrl.T.Helper()
varargs := []interface{}{arg0, arg1}
for _, a := range arg2 {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "FindMany", varargs...)
ret0, _ := ret[0].([]*influxdb.DBRPMappingV2)
ret1, _ := ret[1].(int)
ret2, _ := ret[2].(error)
return ret0, ret1, ret2
}
// FindMany indicates an expected call of FindMany
func (mr *MockDBRPMappingServiceV2MockRecorder) FindMany(arg0, arg1 interface{}, arg2 ...interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
varargs := append([]interface{}{arg0, arg1}, arg2...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindMany", reflect.TypeOf((*MockDBRPMappingServiceV2)(nil).FindMany), varargs...)
}
// Update mocks base method
func (m *MockDBRPMappingServiceV2) Update(arg0 context.Context, arg1 *influxdb.DBRPMappingV2) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Update", arg0, arg1)
ret0, _ := ret[0].(error)
return ret0
}
// Update indicates an expected call of Update
func (mr *MockDBRPMappingServiceV2MockRecorder) Update(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockDBRPMappingServiceV2)(nil).Update), arg0, arg1)
}

View File

@ -161,8 +161,8 @@ func TestServer_Query_ShowDatabases(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
err = s.Launcher. err = s.Launcher.
DBRPMappingServiceV2(). DBRPMappingService().
Create(ctx, &influxdb.DBRPMappingV2{ Create(ctx, &influxdb.DBRPMapping{
Database: bi.db, Database: bi.db,
RetentionPolicy: bi.rp, RetentionPolicy: bi.rp,
Default: true, Default: true,

View File

@ -173,8 +173,8 @@ func (qt *Test) init(ctx context.Context, t *testing.T, p *tests.DefaultPipeline
if !qt.noDefaultMapping { if !qt.noDefaultMapping {
ctx = icontext.SetAuthorizer(ctx, auth) ctx = icontext.SetAuthorizer(ctx, auth)
err := p.Launcher. err := p.Launcher.
DBRPMappingServiceV2(). DBRPMappingService().
Create(ctx, &influxdb.DBRPMappingV2{ Create(ctx, &influxdb.DBRPMapping{
Database: qt.db, Database: qt.db,
RetentionPolicy: qt.rp, RetentionPolicy: qt.rp,
Default: true, Default: true,

View File

@ -154,7 +154,7 @@ func validate(t *testing.T, gf *TestSuite) {
ctx = icontext.SetAuthorizer(ctx, tests.MakeAuthorization(p.DefaultOrgID, p.DefaultUserID, influxdb.OperPermissions())) ctx = icontext.SetAuthorizer(ctx, tests.MakeAuthorization(p.DefaultOrgID, p.DefaultUserID, influxdb.OperPermissions()))
if err := p.Launcher.DBRPMappingServiceV2().Create(ctx, &influxdb.DBRPMappingV2{ if err := p.Launcher.DBRPMappingService().Create(ctx, &influxdb.DBRPMapping{
Database: "mydb", Database: "mydb",
RetentionPolicy: "autogen", RetentionPolicy: "autogen",
Default: true, Default: true,

View File

@ -1,160 +0,0 @@
package inmem
import (
"context"
"fmt"
"path"
"github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/influxdb/v2"
)
var (
errDBRPMappingNotFound = &errors.Error{
Code: errors.ENotFound,
Msg: "dbrp mapping not found",
}
)
func encodeDBRPMappingKey(cluster, db, rp string) string {
return path.Join(cluster, db, rp)
}
func (s *Service) loadDBRPMapping(ctx context.Context, cluster, db, rp string) (*influxdb.DBRPMapping, error) {
i, ok := s.dbrpMappingKV.Load(encodeDBRPMappingKey(cluster, db, rp))
if !ok {
return nil, errDBRPMappingNotFound
}
m, ok := i.(influxdb.DBRPMapping)
if !ok {
return nil, fmt.Errorf("type %T is not a dbrp mapping", i)
}
return &m, nil
}
// FindBy returns a single dbrp mapping by cluster, db and rp.
func (s *Service) FindBy(ctx context.Context, cluster, db, rp string) (*influxdb.DBRPMapping, error) {
return s.loadDBRPMapping(ctx, cluster, db, rp)
}
func (s *Service) forEachDBRPMapping(ctx context.Context, fn func(m *influxdb.DBRPMapping) bool) error {
var err error
s.dbrpMappingKV.Range(func(k, v interface{}) bool {
m, ok := v.(influxdb.DBRPMapping)
if !ok {
err = fmt.Errorf("type %T is not a dbrp mapping", v)
return false
}
return fn(&m)
})
return err
}
func (s *Service) filterDBRPMappings(ctx context.Context, fn func(m *influxdb.DBRPMapping) bool) ([]*influxdb.DBRPMapping, error) {
mappings := []*influxdb.DBRPMapping{}
err := s.forEachDBRPMapping(ctx, func(m *influxdb.DBRPMapping) bool {
if fn(m) {
mappings = append(mappings, m)
}
return true
})
if err != nil {
return nil, err
}
return mappings, nil
}
// Find returns the first dbrp mapping that matches filter.
func (s *Service) Find(ctx context.Context, filter influxdb.DBRPMappingFilter) (*influxdb.DBRPMapping, error) {
if filter.Cluster == nil && filter.Database == nil && filter.RetentionPolicy == nil {
return nil, &errors.Error{
Code: errors.EInvalid,
Msg: "no filter parameters provided",
}
}
// filter by dbrpMapping id
if filter.Cluster != nil && filter.Database != nil && filter.RetentionPolicy != nil {
return s.FindBy(ctx, *filter.Cluster, *filter.Database, *filter.RetentionPolicy)
}
mappings, n, err := s.FindMany(ctx, filter)
if err != nil {
return nil, err
}
if n < 1 {
return nil, errDBRPMappingNotFound
}
return mappings[0], nil
}
// FindMany returns a list of dbrpMappings that match filter and the total count of matching dbrp mappings.
// Additional options provide pagination & sorting.
func (s *Service) FindMany(ctx context.Context, filter influxdb.DBRPMappingFilter, opt ...influxdb.FindOptions) ([]*influxdb.DBRPMapping, int, error) {
// filter by dbrpMapping id
if filter.Cluster != nil && filter.Database != nil && filter.RetentionPolicy != nil {
m, err := s.FindBy(ctx, *filter.Cluster, *filter.Database, *filter.RetentionPolicy)
if err != nil {
return nil, 0, err
}
return []*influxdb.DBRPMapping{m}, 1, nil
}
filterFunc := func(mapping *influxdb.DBRPMapping) bool {
return (filter.Cluster == nil || (*filter.Cluster) == mapping.Cluster) &&
(filter.Database == nil || (*filter.Database) == mapping.Database) &&
(filter.RetentionPolicy == nil || (*filter.RetentionPolicy) == mapping.RetentionPolicy) &&
(filter.Default == nil || (*filter.Default) == mapping.Default)
}
mappings, err := s.filterDBRPMappings(ctx, filterFunc)
if err != nil {
return nil, 0, err
}
return mappings, len(mappings), nil
}
// Create creates a new dbrp mapping.
func (s *Service) Create(ctx context.Context, m *influxdb.DBRPMapping) error {
if err := m.Validate(); err != nil {
return nil
}
existing, err := s.loadDBRPMapping(ctx, m.Cluster, m.Database, m.RetentionPolicy)
if err != nil {
if err == errDBRPMappingNotFound {
return s.PutDBRPMapping(ctx, m)
}
return err
}
if !existing.Equal(m) {
return &errors.Error{
Code: errors.EConflict,
Msg: "dbrp mapping already exists",
}
}
return s.PutDBRPMapping(ctx, m)
}
// PutDBRPMapping sets dbrpMapping with the current ID.
func (s *Service) PutDBRPMapping(ctx context.Context, m *influxdb.DBRPMapping) error {
k := encodeDBRPMappingKey(m.Cluster, m.Database, m.RetentionPolicy)
s.dbrpMappingKV.Store(k, *m)
return nil
}
// Delete removes a dbrp mapping
func (s *Service) Delete(ctx context.Context, cluster, db, rp string) error {
s.dbrpMappingKV.Delete(encodeDBRPMappingKey(cluster, db, rp))
return nil
}

View File

@ -1,43 +0,0 @@
package inmem
import (
"context"
"testing"
platform "github.com/influxdata/influxdb/v2"
platformtesting "github.com/influxdata/influxdb/v2/testing"
)
func initDBRPMappingService(f platformtesting.DBRPMappingFields, t *testing.T) (platform.DBRPMappingService, func()) {
s := NewService()
ctx := context.TODO()
if err := f.Populate(ctx, s); err != nil {
t.Fatal(err)
}
return s, func() {}
}
func TestDBRPMappingService_CreateDBRPMapping(t *testing.T) {
t.Parallel()
platformtesting.CreateDBRPMapping(initDBRPMappingService, t)
}
func TestDBRPMappingService_FindDBRPMappingByKey(t *testing.T) {
t.Parallel()
platformtesting.FindDBRPMappingByKey(initDBRPMappingService, t)
}
func TestDBRPMappingService_FindDBRPMappings(t *testing.T) {
t.Parallel()
platformtesting.FindDBRPMappings(initDBRPMappingService, t)
}
func TestDBRPMappingService_DeleteDBRPMapping(t *testing.T) {
t.Parallel()
platformtesting.DeleteDBRPMapping(initDBRPMappingService, t)
}
func TestDBRPMappingService_FindDBRPMapping(t *testing.T) {
t.Parallel()
platformtesting.FindDBRPMapping(initDBRPMappingService, t)
}

View File

@ -8,91 +8,47 @@ import (
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
) )
var _ influxdb.DBRPMappingServiceV2 = (*DBRPMappingServiceV2)(nil) var _ influxdb.DBRPMappingService = (*DBRPMappingService)(nil)
type DBRPMappingServiceV2 struct { type DBRPMappingService struct {
FindByIDFn func(ctx context.Context, orgID, id platform.ID) (*influxdb.DBRPMappingV2, error) FindByIDFn func(ctx context.Context, orgID, id platform.ID) (*influxdb.DBRPMapping, error)
FindManyFn func(ctx context.Context, dbrp influxdb.DBRPMappingFilterV2, opts ...influxdb.FindOptions) ([]*influxdb.DBRPMappingV2, int, error) FindManyFn func(ctx context.Context, dbrp influxdb.DBRPMappingFilter, opts ...influxdb.FindOptions) ([]*influxdb.DBRPMapping, int, error)
CreateFn func(ctx context.Context, dbrp *influxdb.DBRPMappingV2) error CreateFn func(ctx context.Context, dbrp *influxdb.DBRPMapping) error
UpdateFn func(ctx context.Context, dbrp *influxdb.DBRPMappingV2) error UpdateFn func(ctx context.Context, dbrp *influxdb.DBRPMapping) error
DeleteFn func(ctx context.Context, orgID, id platform.ID) error DeleteFn func(ctx context.Context, orgID, id platform.ID) error
} }
func (s *DBRPMappingServiceV2) FindByID(ctx context.Context, orgID, id platform.ID) (*influxdb.DBRPMappingV2, error) { func (s *DBRPMappingService) FindByID(ctx context.Context, orgID, id platform.ID) (*influxdb.DBRPMapping, error) {
if s.FindByIDFn == nil { if s.FindByIDFn == nil {
return nil, nil return nil, nil
} }
return s.FindByIDFn(ctx, orgID, id) return s.FindByIDFn(ctx, orgID, id)
} }
func (s *DBRPMappingServiceV2) FindMany(ctx context.Context, dbrp influxdb.DBRPMappingFilterV2, opts ...influxdb.FindOptions) ([]*influxdb.DBRPMappingV2, int, error) { func (s *DBRPMappingService) FindMany(ctx context.Context, dbrp influxdb.DBRPMappingFilter, opts ...influxdb.FindOptions) ([]*influxdb.DBRPMapping, int, error) {
if s.FindManyFn == nil { if s.FindManyFn == nil {
return nil, 0, nil return nil, 0, nil
} }
return s.FindManyFn(ctx, dbrp, opts...) return s.FindManyFn(ctx, dbrp, opts...)
} }
func (s *DBRPMappingServiceV2) Create(ctx context.Context, dbrp *influxdb.DBRPMappingV2) error { func (s *DBRPMappingService) Create(ctx context.Context, dbrp *influxdb.DBRPMapping) error {
if s.CreateFn == nil { if s.CreateFn == nil {
return nil return nil
} }
return s.CreateFn(ctx, dbrp) return s.CreateFn(ctx, dbrp)
} }
func (s *DBRPMappingServiceV2) Update(ctx context.Context, dbrp *influxdb.DBRPMappingV2) error { func (s *DBRPMappingService) Update(ctx context.Context, dbrp *influxdb.DBRPMapping) error {
if s.UpdateFn == nil { if s.UpdateFn == nil {
return nil return nil
} }
return s.UpdateFn(ctx, dbrp) return s.UpdateFn(ctx, dbrp)
} }
func (s *DBRPMappingServiceV2) Delete(ctx context.Context, orgID, id platform.ID) error { func (s *DBRPMappingService) Delete(ctx context.Context, orgID, id platform.ID) error {
if s.DeleteFn == nil { if s.DeleteFn == nil {
return nil return nil
} }
return s.DeleteFn(ctx, orgID, id) return s.DeleteFn(ctx, orgID, id)
} }
type DBRPMappingService struct {
FindByFn func(ctx context.Context, cluster string, db string, rp string) (*influxdb.DBRPMapping, error)
FindFn func(ctx context.Context, filter influxdb.DBRPMappingFilter) (*influxdb.DBRPMapping, error)
FindManyFn func(ctx context.Context, filter influxdb.DBRPMappingFilter, opt ...influxdb.FindOptions) ([]*influxdb.DBRPMapping, int, error)
CreateFn func(ctx context.Context, dbrpMap *influxdb.DBRPMapping) error
DeleteFn func(ctx context.Context, cluster string, db string, rp string) error
}
func NewDBRPMappingService() *DBRPMappingService {
return &DBRPMappingService{
FindByFn: func(ctx context.Context, cluster string, db string, rp string) (*influxdb.DBRPMapping, error) {
return nil, nil
},
FindFn: func(ctx context.Context, filter influxdb.DBRPMappingFilter) (*influxdb.DBRPMapping, error) {
return nil, nil
},
FindManyFn: func(ctx context.Context, filter influxdb.DBRPMappingFilter, opt ...influxdb.FindOptions) ([]*influxdb.DBRPMapping, int, error) {
return nil, 0, nil
},
CreateFn: func(ctx context.Context, dbrpMap *influxdb.DBRPMapping) error { return nil },
DeleteFn: func(ctx context.Context, cluster string, db string, rp string) error { return nil },
}
}
func (s *DBRPMappingService) FindBy(ctx context.Context, cluster string, db string, rp string) (*influxdb.DBRPMapping, error) {
return s.FindByFn(ctx, cluster, db, rp)
}
func (s *DBRPMappingService) Find(ctx context.Context, filter influxdb.DBRPMappingFilter) (*influxdb.DBRPMapping, error) {
return s.FindFn(ctx, filter)
}
func (s *DBRPMappingService) FindMany(ctx context.Context, filter influxdb.DBRPMappingFilter, opt ...influxdb.FindOptions) ([]*influxdb.DBRPMapping, int, error) {
return s.FindManyFn(ctx, filter, opt...)
}
func (s *DBRPMappingService) Create(ctx context.Context, dbrpMap *influxdb.DBRPMapping) error {
return s.CreateFn(ctx, dbrpMap)
}
func (s *DBRPMappingService) Delete(ctx context.Context, cluster string, db string, rp string) error {
return s.DeleteFn(ctx, cluster, db, rp)
}

View File

@ -14,7 +14,7 @@ import (
const CompilerType = "influxql" const CompilerType = "influxql"
// AddCompilerMappings adds the influxql specific compiler mappings. // AddCompilerMappings adds the influxql specific compiler mappings.
func AddCompilerMappings(mappings flux.CompilerMappings, dbrpMappingSvc platform.DBRPMappingServiceV2) error { func AddCompilerMappings(mappings flux.CompilerMappings, dbrpMappingSvc platform.DBRPMappingService) error {
return mappings.Add(CompilerType, func() flux.Compiler { return mappings.Add(CompilerType, func() flux.Compiler {
return NewCompiler(dbrpMappingSvc) return NewCompiler(dbrpMappingSvc)
}) })
@ -31,12 +31,12 @@ type Compiler struct {
logicalPlannerOptions []plan.LogicalOption logicalPlannerOptions []plan.LogicalOption
dbrpMappingSvc platform.DBRPMappingServiceV2 dbrpMappingSvc platform.DBRPMappingService
} }
var _ flux.Compiler = &Compiler{} var _ flux.Compiler = &Compiler{}
func NewCompiler(dbrpMappingSvc platform.DBRPMappingServiceV2) *Compiler { func NewCompiler(dbrpMappingSvc platform.DBRPMappingService) *Compiler {
return &Compiler{ return &Compiler{
dbrpMappingSvc: dbrpMappingSvc, dbrpMappingSvc: dbrpMappingSvc,
} }

View File

@ -28,21 +28,21 @@ import (
const generatedInfluxQLDataDir = "testdata" const generatedInfluxQLDataDir = "testdata"
var dbrpMappingSvcE2E = &mock.DBRPMappingServiceV2{} var dbrpMappingSvcE2E = &mock.DBRPMappingService{}
func init() { func init() {
mapping := platform.DBRPMappingV2{ mapping := platform.DBRPMapping{
Database: "db0", Database: "db0",
RetentionPolicy: "autogen", RetentionPolicy: "autogen",
Default: true, Default: true,
OrganizationID: platformtesting.MustIDBase16("cadecadecadecade"), OrganizationID: platformtesting.MustIDBase16("cadecadecadecade"),
BucketID: platformtesting.MustIDBase16("da7aba5e5eedca5e"), BucketID: platformtesting.MustIDBase16("da7aba5e5eedca5e"),
} }
dbrpMappingSvcE2E.FindByIDFn = func(ctx context.Context, orgID, id platform2.ID) (*platform.DBRPMappingV2, error) { dbrpMappingSvcE2E.FindByIDFn = func(ctx context.Context, orgID, id platform2.ID) (*platform.DBRPMapping, error) {
return &mapping, nil return &mapping, nil
} }
dbrpMappingSvcE2E.FindManyFn = func(ctx context.Context, filter platform.DBRPMappingFilterV2, opt ...platform.FindOptions) ([]*platform.DBRPMappingV2, int, error) { dbrpMappingSvcE2E.FindManyFn = func(ctx context.Context, filter platform.DBRPMappingFilter, opt ...platform.FindOptions) ([]*platform.DBRPMapping, int, error) {
return []*platform.DBRPMappingV2{&mapping}, 1, nil return []*platform.DBRPMapping{&mapping}, 1, nil
} }
} }

View File

@ -20,35 +20,35 @@ import (
platformtesting "github.com/influxdata/influxdb/v2/testing" platformtesting "github.com/influxdata/influxdb/v2/testing"
) )
var dbrpMappingSvc = &mock.DBRPMappingServiceV2{} var dbrpMappingSvc = &mock.DBRPMappingService{}
var organizationID platform2.ID var organizationID platform2.ID
var bucketID platform2.ID var bucketID platform2.ID
var altBucketID platform2.ID var altBucketID platform2.ID
func init() { func init() {
mapping := platform.DBRPMappingV2{ mapping := platform.DBRPMapping{
Database: "db0", Database: "db0",
RetentionPolicy: "autogen", RetentionPolicy: "autogen",
Default: true, Default: true,
OrganizationID: organizationID, OrganizationID: organizationID,
BucketID: bucketID, BucketID: bucketID,
} }
altMapping := platform.DBRPMappingV2{ altMapping := platform.DBRPMapping{
Database: "db0", Database: "db0",
RetentionPolicy: "autogen", RetentionPolicy: "autogen",
Default: true, Default: true,
OrganizationID: organizationID, OrganizationID: organizationID,
BucketID: altBucketID, BucketID: altBucketID,
} }
dbrpMappingSvc.FindByIDFn = func(ctx context.Context, orgID, id platform2.ID) (*platform.DBRPMappingV2, error) { dbrpMappingSvc.FindByIDFn = func(ctx context.Context, orgID, id platform2.ID) (*platform.DBRPMapping, error) {
return &mapping, nil return &mapping, nil
} }
dbrpMappingSvc.FindManyFn = func(ctx context.Context, filter platform.DBRPMappingFilterV2, opt ...platform.FindOptions) ([]*platform.DBRPMappingV2, int, error) { dbrpMappingSvc.FindManyFn = func(ctx context.Context, filter platform.DBRPMappingFilter, opt ...platform.FindOptions) ([]*platform.DBRPMapping, int, error) {
m := &mapping m := &mapping
if filter.RetentionPolicy != nil && *filter.RetentionPolicy == "alternate" { if filter.RetentionPolicy != nil && *filter.RetentionPolicy == "alternate" {
m = &altMapping m = &altMapping
} }
return []*platform.DBRPMappingV2{m}, 1, nil return []*platform.DBRPMapping{m}, 1, nil
} }
} }

View File

@ -18,14 +18,14 @@ import (
// Transpiler converts InfluxQL queries into a query spec. // Transpiler converts InfluxQL queries into a query spec.
type Transpiler struct { type Transpiler struct {
Config *Config Config *Config
dbrpMappingSvc influxdb.DBRPMappingServiceV2 dbrpMappingSvc influxdb.DBRPMappingService
} }
func NewTranspiler(dbrpMappingSvc influxdb.DBRPMappingServiceV2) *Transpiler { func NewTranspiler(dbrpMappingSvc influxdb.DBRPMappingService) *Transpiler {
return NewTranspilerWithConfig(dbrpMappingSvc, Config{}) return NewTranspilerWithConfig(dbrpMappingSvc, Config{})
} }
func NewTranspilerWithConfig(dbrpMappingSvc influxdb.DBRPMappingServiceV2, cfg Config) *Transpiler { func NewTranspilerWithConfig(dbrpMappingSvc influxdb.DBRPMappingService, cfg Config) *Transpiler {
return &Transpiler{ return &Transpiler{
Config: &cfg, Config: &cfg,
dbrpMappingSvc: dbrpMappingSvc, dbrpMappingSvc: dbrpMappingSvc,
@ -58,10 +58,10 @@ type transpilerState struct {
config Config config Config
file *ast.File file *ast.File
assignments map[string]ast.Expression assignments map[string]ast.Expression
dbrpMappingSvc influxdb.DBRPMappingServiceV2 dbrpMappingSvc influxdb.DBRPMappingService
} }
func newTranspilerState(dbrpMappingSvc influxdb.DBRPMappingServiceV2, config *Config) *transpilerState { func newTranspilerState(dbrpMappingSvc influxdb.DBRPMappingService, config *Config) *transpilerState {
state := &transpilerState{ state := &transpilerState{
file: &ast.File{ file: &ast.File{
Package: &ast.PackageClause{ Package: &ast.PackageClause{
@ -697,7 +697,7 @@ func (t *transpilerState) from(m *influxql.Measurement) (ast.Expression, error)
} }
} }
var filter influxdb.DBRPMappingFilterV2 var filter influxdb.DBRPMappingFilter
if db != "" { if db != "" {
filter.Database = &db filter.Database = &db
} }

View File

@ -14,21 +14,21 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
) )
var dbrpMappingSvc = &mock.DBRPMappingServiceV2{} var dbrpMappingSvc = &mock.DBRPMappingService{}
func init() { func init() {
mapping := platform.DBRPMappingV2{ mapping := platform.DBRPMapping{
Database: "db0", Database: "db0",
RetentionPolicy: "autogen", RetentionPolicy: "autogen",
Default: true, Default: true,
OrganizationID: platformtesting.MustIDBase16("aaaaaaaaaaaaaaaa"), OrganizationID: platformtesting.MustIDBase16("aaaaaaaaaaaaaaaa"),
BucketID: platformtesting.MustIDBase16("bbbbbbbbbbbbbbbb"), BucketID: platformtesting.MustIDBase16("bbbbbbbbbbbbbbbb"),
} }
dbrpMappingSvc.FindByIDFn = func(ctx context.Context, orgID, id platform2.ID) (*platform.DBRPMappingV2, error) { dbrpMappingSvc.FindByIDFn = func(ctx context.Context, orgID, id platform2.ID) (*platform.DBRPMapping, error) {
return &mapping, nil return &mapping, nil
} }
dbrpMappingSvc.FindManyFn = func(ctx context.Context, filter platform.DBRPMappingFilterV2, opt ...platform.FindOptions) ([]*platform.DBRPMappingV2, int, error) { dbrpMappingSvc.FindManyFn = func(ctx context.Context, filter platform.DBRPMappingFilter, opt ...platform.FindOptions) ([]*platform.DBRPMapping, int, error) {
return []*platform.DBRPMappingV2{&mapping}, 1, nil return []*platform.DBRPMapping{&mapping}, 1, nil
} }
} }

View File

@ -43,7 +43,7 @@ func (s *LocalDatabasesProcedureSpec) Copy() plan.ProcedureSpec {
type DatabasesDecoder struct { type DatabasesDecoder struct {
orgID platform2.ID orgID platform2.ID
deps *DatabasesDependencies deps *DatabasesDependencies
databases []*platform.DBRPMappingV2 databases []*platform.DBRPMapping
alloc *memory.Allocator alloc *memory.Allocator
} }
@ -52,7 +52,7 @@ func (bd *DatabasesDecoder) Connect(ctx context.Context) error {
} }
func (bd *DatabasesDecoder) Fetch(ctx context.Context) (bool, error) { func (bd *DatabasesDecoder) Fetch(ctx context.Context) (bool, error) {
b, _, err := bd.deps.DBRP.FindMany(ctx, platform.DBRPMappingFilterV2{}) b, _, err := bd.deps.DBRP.FindMany(ctx, platform.DBRPMappingFilter{})
if err != nil { if err != nil {
return false, err return false, err
} }
@ -62,7 +62,7 @@ func (bd *DatabasesDecoder) Fetch(ctx context.Context) (bool, error) {
func (bd *DatabasesDecoder) Decode(ctx context.Context) (flux.Table, error) { func (bd *DatabasesDecoder) Decode(ctx context.Context) (flux.Table, error) {
type databaseInfo struct { type databaseInfo struct {
*platform.DBRPMappingV2 *platform.DBRPMapping
RetentionPeriod time.Duration RetentionPeriod time.Duration
} }
@ -77,7 +77,7 @@ func (bd *DatabasesDecoder) Decode(ctx context.Context) (flux.Table, error) {
return nil, err return nil, err
} }
databases = append(databases, databaseInfo{ databases = append(databases, databaseInfo{
DBRPMappingV2: db, DBRPMapping: db,
RetentionPeriod: bucket.RetentionPeriod, RetentionPeriod: bucket.RetentionPeriod,
}) })
} }
@ -172,7 +172,7 @@ type key int
const dependenciesKey key = iota const dependenciesKey key = iota
type DatabasesDependencies struct { type DatabasesDependencies struct {
DBRP platform.DBRPMappingServiceV2 DBRP platform.DBRPMappingService
BucketLookup platform.BucketService BucketLookup platform.BucketService
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -13,6 +13,13 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func strPtr(s string) *string {
return &s
}
func boolPtr(b bool) *bool {
return &b
}
// TODO(goller): remove opPrefix argument // TODO(goller): remove opPrefix argument
func diffPlatformErrors(name string, actual, expected error, opPrefix string, t *testing.T) { func diffPlatformErrors(name string, actual, expected error, opPrefix string, t *testing.T) {
t.Helper() t.Helper()

View File

@ -319,13 +319,13 @@ func (c *Client) MustCreateDBRPMapping(t *testing.T) platform.ID {
t.Helper() t.Helper()
ctx := context.Background() ctx := context.Background()
m := &influxdb.DBRPMappingV2{ m := &influxdb.DBRPMapping{
Database: "db", Database: "db",
RetentionPolicy: "rp", RetentionPolicy: "rp",
OrganizationID: c.OrgID, OrganizationID: c.OrgID,
BucketID: c.BucketID, BucketID: c.BucketID,
} }
if err := c.DBRPMappingServiceV2.Create(ctx, m); err != nil { if err := c.DBRPMappingService.Create(ctx, m); err != nil {
t.Fatalf("unable to create DBRP mapping: %v", err) t.Fatalf("unable to create DBRP mapping: %v", err)
} }
return m.ID return m.ID
@ -422,7 +422,7 @@ func (c *Client) DeleteResource(t *testing.T, r influxdb.ResourceType, id platfo
case influxdb.ChecksResourceType: // 16 case influxdb.ChecksResourceType: // 16
return c.DeleteCheck(ctx, id) return c.DeleteCheck(ctx, id)
case influxdb.DBRPResourceType: // 17 case influxdb.DBRPResourceType: // 17
return c.DBRPMappingServiceV2.Delete(ctx, c.OrgID, id) return c.DBRPMappingService.Delete(ctx, c.OrgID, id)
} }
return nil return nil
} }
@ -535,7 +535,7 @@ func (c *Client) FindAll(t *testing.T, r influxdb.ResourceType) ([]platform.ID,
ids = append(ids, r.ID) ids = append(ids, r.ID)
} }
case influxdb.DBRPResourceType: // 17 case influxdb.DBRPResourceType: // 17
rs, _, err := c.DBRPMappingServiceV2.FindMany(ctx, influxdb.DBRPMappingFilterV2{OrgID: &c.OrgID}) rs, _, err := c.DBRPMappingService.FindMany(ctx, influxdb.DBRPMappingFilter{OrgID: &c.OrgID})
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -32,7 +32,7 @@ type LocalShardMapper struct {
ShardGroup(ids []uint64) tsdb.ShardGroup ShardGroup(ids []uint64) tsdb.ShardGroup
} }
DBRP influxdb.DBRPMappingServiceV2 DBRP influxdb.DBRPMappingService
} }
// MapShards maps the sources to the appropriate shards into an IteratorCreator. // MapShards maps the sources to the appropriate shards into an IteratorCreator.
@ -63,7 +63,7 @@ func (e *LocalShardMapper) mapShards(ctx context.Context, a *LocalShardMapping,
// using. // using.
if _, ok := a.ShardMap[source]; !ok { if _, ok := a.ShardMap[source]; !ok {
// lookup bucket and create info // lookup bucket and create info
mappings, _, err := e.DBRP.FindMany(ctx, influxdb.DBRPMappingFilterV2{ mappings, _, err := e.DBRP.FindMany(ctx, influxdb.DBRPMappingFilter{
OrgID: &orgID, OrgID: &orgID,
Database: &s.Database, Database: &s.Database,
RetentionPolicy: &s.RetentionPolicy, RetentionPolicy: &s.RetentionPolicy,

View File

@ -22,13 +22,13 @@ func TestLocalShardMapper(t *testing.T) {
ctrl := gomock.NewController(t) ctrl := gomock.NewController(t)
defer ctrl.Finish() defer ctrl.Finish()
dbrp := mocks.NewMockDBRPMappingServiceV2(ctrl) dbrp := mocks.NewMockDBRPMappingService(ctrl)
orgID := platform.ID(0xff00) orgID := platform.ID(0xff00)
bucketID := platform.ID(0xffee) bucketID := platform.ID(0xffee)
db := "db0" db := "db0"
rp := "rp0" rp := "rp0"
filt := influxdb.DBRPMappingFilterV2{OrgID: &orgID, Database: &db, RetentionPolicy: &rp} filt := influxdb.DBRPMappingFilter{OrgID: &orgID, Database: &db, RetentionPolicy: &rp}
res := []*influxdb.DBRPMappingV2{{Database: db, RetentionPolicy: rp, OrganizationID: orgID, BucketID: bucketID}} res := []*influxdb.DBRPMapping{{Database: db, RetentionPolicy: rp, OrganizationID: orgID, BucketID: bucketID}}
dbrp.EXPECT(). dbrp.EXPECT().
FindMany(gomock.Any(), filt). FindMany(gomock.Any(), filt).
Times(2). Times(2).

View File

@ -35,7 +35,7 @@ type StatementExecutor struct {
// ShardMapper for mapping shards when executing a SELECT statement. // ShardMapper for mapping shards when executing a SELECT statement.
ShardMapper query.ShardMapper ShardMapper query.ShardMapper
DBRP influxdb.DBRPMappingServiceV2 DBRP influxdb.DBRPMappingService
// Select statement limits // Select statement limits
MaxSelectPointN int MaxSelectPointN int
@ -319,7 +319,7 @@ func (e *StatementExecutor) createIterators(ctx context.Context, stmt *influxql.
func (e *StatementExecutor) executeShowDatabasesStatement(ctx context.Context, q *influxql.ShowDatabasesStatement, ectx *query.ExecutionContext) (models.Rows, error) { func (e *StatementExecutor) executeShowDatabasesStatement(ctx context.Context, q *influxql.ShowDatabasesStatement, ectx *query.ExecutionContext) (models.Rows, error) {
row := &models.Row{Name: "databases", Columns: []string{"name"}} row := &models.Row{Name: "databases", Columns: []string{"name"}}
dbrps, _, err := e.DBRP.FindMany(ctx, influxdb.DBRPMappingFilterV2{ dbrps, _, err := e.DBRP.FindMany(ctx, influxdb.DBRPMappingFilter{
OrgID: &ectx.OrgID, OrgID: &ectx.OrgID,
}) })
if err != nil { if err != nil {
@ -349,9 +349,9 @@ func (e *StatementExecutor) executeShowDatabasesStatement(ctx context.Context, q
return []*models.Row{row}, nil return []*models.Row{row}, nil
} }
func (e *StatementExecutor) getDefaultRP(ctx context.Context, database string, ectx *query.ExecutionContext) (*influxdb.DBRPMappingV2, error) { func (e *StatementExecutor) getDefaultRP(ctx context.Context, database string, ectx *query.ExecutionContext) (*influxdb.DBRPMapping, error) {
defaultRP := true defaultRP := true
mappings, n, err := e.DBRP.FindMany(ctx, influxdb.DBRPMappingFilterV2{ mappings, n, err := e.DBRP.FindMany(ctx, influxdb.DBRPMappingFilter{
OrgID: &ectx.OrgID, OrgID: &ectx.OrgID,
Database: &database, Database: &database,
Default: &defaultRP, Default: &defaultRP,
@ -440,7 +440,7 @@ func (e *StatementExecutor) executeShowRetentionPoliciesStatement(ctx context.Co
return nil, ErrDatabaseNameRequired return nil, ErrDatabaseNameRequired
} }
dbrps, _, err := e.DBRP.FindMany(ctx, influxdb.DBRPMappingFilterV2{ dbrps, _, err := e.DBRP.FindMany(ctx, influxdb.DBRPMappingFilter{
OrgID: &ectx.OrgID, OrgID: &ectx.OrgID,
Database: &q.Database, Database: &q.Database,
}) })
@ -716,7 +716,7 @@ func (e *StatementExecutor) normalizeMeasurement(ctx context.Context, m *influxq
} }
// TODO(sgc): Validate database; fetch default RP // TODO(sgc): Validate database; fetch default RP
filter := influxdb.DBRPMappingFilterV2{ filter := influxdb.DBRPMappingFilter{
OrgID: &ectx.OrgID, OrgID: &ectx.OrgID,
Database: &m.Database, Database: &m.Database,
} }
@ -744,7 +744,7 @@ func (e *StatementExecutor) normalizeMeasurement(ctx context.Context, m *influxq
return nil return nil
} }
type mappings []*influxdb.DBRPMappingV2 type mappings []*influxdb.DBRPMapping
func (m mappings) DefaultRetentionPolicy(db string) string { func (m mappings) DefaultRetentionPolicy(db string) string {
for _, v := range m { for _, v := range m {

View File

@ -43,11 +43,11 @@ func TestQueryExecutor_ExecuteQuery_SelectStatement(t *testing.T) {
ctrl := gomock.NewController(t) ctrl := gomock.NewController(t)
defer ctrl.Finish() defer ctrl.Finish()
dbrp := mocks.NewMockDBRPMappingServiceV2(ctrl) dbrp := mocks.NewMockDBRPMappingService(ctrl)
orgID := platform.ID(0xff00) orgID := platform.ID(0xff00)
empty := "" empty := ""
filt := influxdb.DBRPMappingFilterV2{OrgID: &orgID, Database: &empty, RetentionPolicy: &empty} filt := influxdb.DBRPMappingFilter{OrgID: &orgID, Database: &empty, RetentionPolicy: &empty}
res := []*influxdb.DBRPMappingV2{{}} res := []*influxdb.DBRPMapping{{}}
dbrp.EXPECT(). dbrp.EXPECT().
FindMany(gomock.Any(), filt). FindMany(gomock.Any(), filt).
Return(res, 1, nil) Return(res, 1, nil)
@ -109,11 +109,11 @@ func TestQueryExecutor_ExecuteQuery_MaxSelectBucketsN(t *testing.T) {
ctrl := gomock.NewController(t) ctrl := gomock.NewController(t)
defer ctrl.Finish() defer ctrl.Finish()
dbrp := mocks.NewMockDBRPMappingServiceV2(ctrl) dbrp := mocks.NewMockDBRPMappingService(ctrl)
orgID := platform.ID(0xff00) orgID := platform.ID(0xff00)
empty := "" empty := ""
filt := influxdb.DBRPMappingFilterV2{OrgID: &orgID, Database: &empty, RetentionPolicy: &empty} filt := influxdb.DBRPMappingFilter{OrgID: &orgID, Database: &empty, RetentionPolicy: &empty}
res := []*influxdb.DBRPMappingV2{{}} res := []*influxdb.DBRPMapping{{}}
dbrp.EXPECT(). dbrp.EXPECT().
FindMany(gomock.Any(), filt). FindMany(gomock.Any(), filt).
Return(res, 1, nil) Return(res, 1, nil)
@ -227,11 +227,11 @@ func TestStatementExecutor_NormalizeStatement(t *testing.T) {
ctrl := gomock.NewController(t) ctrl := gomock.NewController(t)
defer ctrl.Finish() defer ctrl.Finish()
dbrp := mocks.NewMockDBRPMappingServiceV2(ctrl) dbrp := mocks.NewMockDBRPMappingService(ctrl)
orgID := platform.ID(0xff00) orgID := platform.ID(0xff00)
bucketID := platform.ID(0xffee) bucketID := platform.ID(0xffee)
filt := influxdb.DBRPMappingFilterV2{OrgID: &orgID, Database: &testCase.expectedDB} filt := influxdb.DBRPMappingFilter{OrgID: &orgID, Database: &testCase.expectedDB}
res := []*influxdb.DBRPMappingV2{{Database: testCase.expectedDB, RetentionPolicy: testCase.expectedRP, OrganizationID: orgID, BucketID: bucketID, Default: true}} res := []*influxdb.DBRPMapping{{Database: testCase.expectedDB, RetentionPolicy: testCase.expectedRP, OrganizationID: orgID, BucketID: bucketID, Default: true}}
dbrp.EXPECT(). dbrp.EXPECT().
FindMany(gomock.Any(), filt). FindMany(gomock.Any(), filt).
Return(res, 1, nil) Return(res, 1, nil)
@ -331,10 +331,10 @@ func TestQueryExecutor_ExecuteQuery_ShowDatabases(t *testing.T) {
ctrl := gomock.NewController(t) ctrl := gomock.NewController(t)
defer ctrl.Finish() defer ctrl.Finish()
dbrp := mocks.NewMockDBRPMappingServiceV2(ctrl) dbrp := mocks.NewMockDBRPMappingService(ctrl)
orgID := platform.ID(0xff00) orgID := platform.ID(0xff00)
filt := influxdb.DBRPMappingFilterV2{OrgID: &orgID} filt := influxdb.DBRPMappingFilter{OrgID: &orgID}
res := []*influxdb.DBRPMappingV2{ res := []*influxdb.DBRPMapping{
{Database: "db1", OrganizationID: orgID, BucketID: 0xffe0}, {Database: "db1", OrganizationID: orgID, BucketID: 0xffe0},
{Database: "db2", OrganizationID: orgID, BucketID: 0xffe1}, {Database: "db2", OrganizationID: orgID, BucketID: 0xffe1},
{Database: "db3", OrganizationID: orgID, BucketID: 0xffe2}, {Database: "db3", OrganizationID: orgID, BucketID: 0xffe2},
@ -393,7 +393,7 @@ type QueryExecutor struct {
MetaClient MetaClient MetaClient MetaClient
TSDBStore *internal.TSDBStoreMock TSDBStore *internal.TSDBStoreMock
DBRP *mocks.MockDBRPMappingServiceV2 DBRP *mocks.MockDBRPMappingService
StatementExecutor *coordinator.StatementExecutor StatementExecutor *coordinator.StatementExecutor
LogOutput bytes.Buffer LogOutput bytes.Buffer
} }
@ -439,7 +439,7 @@ func NewQueryExecutor(t *testing.T, opts ...optFn) *QueryExecutor {
type optFn func(qe *QueryExecutor) type optFn func(qe *QueryExecutor)
func WithDBRP(dbrp *mocks.MockDBRPMappingServiceV2) optFn { func WithDBRP(dbrp *mocks.MockDBRPMappingService) optFn {
return func(qe *QueryExecutor) { return func(qe *QueryExecutor) {
qe.DBRP = dbrp qe.DBRP = dbrp
} }