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.
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
// https://github.com/golang/go/wiki/SliceTricks#filtering-without-allocating
rrs := rs[:0]

View File

@ -1257,7 +1257,7 @@ func (m *Launcher) CheckService() platform.CheckService {
return m.apibackend.CheckService
}
func (m *Launcher) DBRPMappingServiceV2() platform.DBRPMappingServiceV2 {
func (m *Launcher) DBRPMappingService() platform.DBRPMappingService {
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)
}
mapping := &influxdb.DBRPMappingV2{
mapping := &influxdb.DBRPMapping{
Database: db.Name,
RetentionPolicy: rp.Name,
Default: db.DefaultRetentionPolicy == rp.Name,

View File

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

View File

@ -118,7 +118,7 @@ var v2DumpMetaCommand = &cobra.Command{
fmt.Fprintln(os.Stdout, "Mappings")
fmt.Fprintln(os.Stdout, "---------")
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 {
return err
}

View File

@ -12,10 +12,10 @@ import (
type BucketService struct {
influxdb.BucketService
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{
Logger: logger,
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()))
mappings, _, err := s.DBRPMappingService.FindMany(ctx, influxdb.DBRPMappingFilterV2{
mappings, _, err := s.DBRPMappingService.FindMany(ctx, influxdb.DBRPMappingFilter{
OrgID: &bucket.OrgID,
BucketID: &bucket.ID,
})

View File

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

View File

@ -13,7 +13,7 @@ import (
"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.
type Client struct {
@ -32,7 +32,7 @@ func (c *Client) dbrpURL(id platform.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)
defer span.Finish()
@ -47,7 +47,7 @@ func (c *Client) FindByID(ctx context.Context, orgID, id platform.ID) (*influxdb
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)
defer span.Finish()
@ -84,11 +84,11 @@ func (c *Client) FindMany(ctx context.Context, filter influxdb.DBRPMappingFilter
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)
defer span.Finish()
var newDBRP influxdb.DBRPMappingV2
var newDBRP influxdb.DBRPMapping
if err := c.Client.
PostJSON(createDBRPRequest{
Database: dbrp.Database,
@ -105,7 +105,7 @@ func (c *Client) Create(ctx context.Context, dbrp *influxdb.DBRPMappingV2) error
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)
defer span.Finish()
@ -113,7 +113,7 @@ func (c *Client) Update(ctx context.Context, dbrp *influxdb.DBRPMappingV2) error
return err
}
var newDBRP influxdb.DBRPMappingV2
var newDBRP influxdb.DBRPMapping
if err := c.Client.
PatchJSON(dbrp, c.dbrpURL(dbrp.ID)).
QueryParams([2]string{"orgID", dbrp.OrganizationID.String()}).

View File

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

View File

@ -23,12 +23,12 @@ type Handler struct {
chi.Router
api *kithttp.API
log *zap.Logger
dbrpSvc influxdb.DBRPMappingServiceV2
dbrpSvc influxdb.DBRPMappingService
orgSvc influxdb.OrganizationService
}
// 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{
api: kithttp.NewAPI(kithttp.WithLog(log)),
log: log,
@ -114,7 +114,7 @@ func (h *Handler) handlePostDBRP(w http.ResponseWriter, r *http.Request) {
return
}
dbrp := &influxdb.DBRPMappingV2{
dbrp := &influxdb.DBRPMapping{
Database: req.Database,
RetentionPolicy: req.RetentionPolicy,
Default: req.Default,
@ -129,7 +129,7 @@ func (h *Handler) handlePostDBRP(w http.ResponseWriter, r *http.Request) {
}
type getDBRPsResponse struct {
Content []*influxdb.DBRPMappingV2 `json:"content"`
Content []*influxdb.DBRPMapping `json:"content"`
}
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 {
Content *influxdb.DBRPMappingV2 `json:"content"`
Content *influxdb.DBRPMapping `json:"content"`
}
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 {
Content *influxdb.DBRPMappingV2 `json:"content"`
Content *influxdb.DBRPMapping `json:"content"`
}{
Content: dbrp,
})
@ -281,7 +281,7 @@ func (h *Handler) handleDeleteDBRP(w http.ResponseWriter, r *http.Request) {
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.
f.OrgID, err = h.mustGetOrgIDFromHTTPRequest(r)
if err != nil {

View File

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

View File

@ -9,7 +9,7 @@ import (
var (
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 {
return nil, err
}

View File

@ -9,18 +9,18 @@ import (
"github.com/influxdata/influxdb/v2/authorizer"
)
var _ influxdb.DBRPMappingServiceV2 = (*AuthorizedService)(nil)
var _ influxdb.DBRPMappingService = (*AuthorizedService)(nil)
type AuthorizedService struct {
influxdb.DBRPMappingServiceV2
influxdb.DBRPMappingService
}
func NewAuthorizedService(s influxdb.DBRPMappingServiceV2) *AuthorizedService {
return &AuthorizedService{DBRPMappingServiceV2: s}
func NewAuthorizedService(s influxdb.DBRPMappingService) *AuthorizedService {
return &AuthorizedService{DBRPMappingService: s}
}
func (svc AuthorizedService) FindByID(ctx context.Context, orgID, id platform.ID) (*influxdb.DBRPMappingV2, error) {
mapping, err := svc.DBRPMappingServiceV2.FindByID(ctx, orgID, id)
func (svc AuthorizedService) FindByID(ctx context.Context, orgID, id platform.ID) (*influxdb.DBRPMapping, error) {
mapping, err := svc.DBRPMappingService.FindByID(ctx, orgID, id)
if err != nil {
return nil, err
}
@ -30,35 +30,35 @@ func (svc AuthorizedService) FindByID(ctx context.Context, orgID, id platform.ID
return mapping, nil
}
func (svc AuthorizedService) FindMany(ctx context.Context, filter influxdb.DBRPMappingFilterV2, opts ...influxdb.FindOptions) ([]*influxdb.DBRPMappingV2, int, error) {
dbrps, _, err := svc.DBRPMappingServiceV2.FindMany(ctx, filter, opts...)
func (svc AuthorizedService) FindMany(ctx context.Context, filter influxdb.DBRPMappingFilter, opts ...influxdb.FindOptions) ([]*influxdb.DBRPMapping, int, error) {
dbrps, _, err := svc.DBRPMappingService.FindMany(ctx, filter, opts...)
if err != nil {
return nil, 0, err
}
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 {
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 {
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 {
mapping, err := svc.DBRPMappingServiceV2.FindByID(ctx, orgID, id)
mapping, err := svc.DBRPMappingService.FindByID(ctx, orgID, id)
if err != nil {
return err
}
if _, _, err := authorizer.AuthorizeWrite(ctx, influxdb.BucketsResourceType, mapping.BucketID, orgID); err != nil {
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) {
type fields struct {
service influxdb.DBRPMappingServiceV2
service influxdb.DBRPMappingService
}
type args struct {
orgID platform.ID
@ -36,9 +36,9 @@ func TestAuth_FindByID(t *testing.T) {
{
name: "authorized to access id by org id",
fields: fields{
service: &mock.DBRPMappingServiceV2{
FindByIDFn: func(_ context.Context, _, _ platform.ID) (*influxdb.DBRPMappingV2, error) {
return &influxdb.DBRPMappingV2{
service: &mock.DBRPMappingService{
FindByIDFn: func(_ context.Context, _, _ platform.ID) (*influxdb.DBRPMapping, error) {
return &influxdb.DBRPMapping{
OrganizationID: platform.ID(1),
BucketID: platform.ID(1),
}, nil
@ -63,9 +63,9 @@ func TestAuth_FindByID(t *testing.T) {
{
name: "authorized to access id by id",
fields: fields{
service: &mock.DBRPMappingServiceV2{
FindByIDFn: func(_ context.Context, _, _ platform.ID) (*influxdb.DBRPMappingV2, error) {
return &influxdb.DBRPMappingV2{
service: &mock.DBRPMappingService{
FindByIDFn: func(_ context.Context, _, _ platform.ID) (*influxdb.DBRPMapping, error) {
return &influxdb.DBRPMapping{
OrganizationID: platform.ID(1),
BucketID: platform.ID(1),
}, nil
@ -90,9 +90,9 @@ func TestAuth_FindByID(t *testing.T) {
{
name: "unauthorized to access id by org id",
fields: fields{
service: &mock.DBRPMappingServiceV2{
FindByIDFn: func(_ context.Context, _, _ platform.ID) (*influxdb.DBRPMappingV2, error) {
return &influxdb.DBRPMappingV2{
service: &mock.DBRPMappingService{
FindByIDFn: func(_ context.Context, _, _ platform.ID) (*influxdb.DBRPMapping, error) {
return &influxdb.DBRPMapping{
OrganizationID: platform.ID(2),
BucketID: platform.ID(1),
}, nil
@ -120,9 +120,9 @@ func TestAuth_FindByID(t *testing.T) {
{
name: "unauthorized to access id by id",
fields: fields{
service: &mock.DBRPMappingServiceV2{
FindByIDFn: func(_ context.Context, _, _ platform.ID) (*influxdb.DBRPMappingV2, error) {
return &influxdb.DBRPMappingV2{
service: &mock.DBRPMappingService{
FindByIDFn: func(_ context.Context, _, _ platform.ID) (*influxdb.DBRPMapping, error) {
return &influxdb.DBRPMapping{
OrganizationID: platform.ID(1),
BucketID: platform.ID(1),
}, nil
@ -164,15 +164,15 @@ func TestAuth_FindByID(t *testing.T) {
func TestAuth_FindMany(t *testing.T) {
type fields struct {
service influxdb.DBRPMappingServiceV2
service influxdb.DBRPMappingService
}
type args struct {
filter influxdb.DBRPMappingFilterV2
filter influxdb.DBRPMappingFilter
permissions []influxdb.Permission
}
type wants struct {
err error
ms []*influxdb.DBRPMappingV2
ms []*influxdb.DBRPMapping
}
tests := []struct {
@ -184,9 +184,9 @@ func TestAuth_FindMany(t *testing.T) {
{
name: "no result",
fields: fields{
service: &mock.DBRPMappingServiceV2{
FindManyFn: func(ctx context.Context, dbrp influxdb.DBRPMappingFilterV2, opts ...influxdb.FindOptions) ([]*influxdb.DBRPMappingV2, int, error) {
return []*influxdb.DBRPMappingV2{
service: &mock.DBRPMappingService{
FindManyFn: func(ctx context.Context, dbrp influxdb.DBRPMappingFilter, opts ...influxdb.FindOptions) ([]*influxdb.DBRPMapping, int, error) {
return []*influxdb.DBRPMapping{
{
ID: 1,
OrganizationID: 1,
@ -219,19 +219,19 @@ func TestAuth_FindMany(t *testing.T) {
OrgID: influxdbtesting.IDPtr(42),
},
}},
filter: influxdb.DBRPMappingFilterV2{},
filter: influxdb.DBRPMappingFilter{},
},
wants: wants{
err: nil,
ms: []*influxdb.DBRPMappingV2{},
ms: []*influxdb.DBRPMapping{},
},
},
{
name: "partial",
fields: fields{
service: &mock.DBRPMappingServiceV2{
FindManyFn: func(ctx context.Context, dbrp influxdb.DBRPMappingFilterV2, opts ...influxdb.FindOptions) ([]*influxdb.DBRPMappingV2, int, error) {
return []*influxdb.DBRPMappingV2{
service: &mock.DBRPMappingService{
FindManyFn: func(ctx context.Context, dbrp influxdb.DBRPMappingFilter, opts ...influxdb.FindOptions) ([]*influxdb.DBRPMapping, int, error) {
return []*influxdb.DBRPMapping{
{
ID: 1,
OrganizationID: 1,
@ -264,11 +264,11 @@ func TestAuth_FindMany(t *testing.T) {
OrgID: influxdbtesting.IDPtr(1),
},
}},
filter: influxdb.DBRPMappingFilterV2{},
filter: influxdb.DBRPMappingFilter{},
},
wants: wants{
err: nil,
ms: []*influxdb.DBRPMappingV2{
ms: []*influxdb.DBRPMapping{
{
ID: 1,
OrganizationID: 1,
@ -285,9 +285,9 @@ func TestAuth_FindMany(t *testing.T) {
{
name: "all",
fields: fields{
service: &mock.DBRPMappingServiceV2{
FindManyFn: func(ctx context.Context, dbrp influxdb.DBRPMappingFilterV2, opts ...influxdb.FindOptions) ([]*influxdb.DBRPMappingV2, int, error) {
return []*influxdb.DBRPMappingV2{
service: &mock.DBRPMappingService{
FindManyFn: func(ctx context.Context, dbrp influxdb.DBRPMappingFilter, opts ...influxdb.FindOptions) ([]*influxdb.DBRPMapping, int, error) {
return []*influxdb.DBRPMapping{
{
ID: 1,
OrganizationID: 1,
@ -336,11 +336,11 @@ func TestAuth_FindMany(t *testing.T) {
},
},
},
filter: influxdb.DBRPMappingFilterV2{},
filter: influxdb.DBRPMappingFilter{},
},
wants: wants{
err: nil,
ms: []*influxdb.DBRPMappingV2{
ms: []*influxdb.DBRPMapping{
{
ID: 1,
OrganizationID: 1,
@ -378,7 +378,7 @@ func TestAuth_FindMany(t *testing.T) {
t.Errorf("got wrong number back")
}
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)
}
})
@ -387,10 +387,10 @@ func TestAuth_FindMany(t *testing.T) {
func TestAuth_Create(t *testing.T) {
type fields struct {
service influxdb.DBRPMappingServiceV2
service influxdb.DBRPMappingService
}
type args struct {
m influxdb.DBRPMappingV2
m influxdb.DBRPMapping
permission influxdb.Permission
}
type wants struct {
@ -406,10 +406,10 @@ func TestAuth_Create(t *testing.T) {
{
name: "authorized",
fields: fields{
service: &mock.DBRPMappingServiceV2{},
service: &mock.DBRPMappingService{},
},
args: args{
m: influxdb.DBRPMappingV2{
m: influxdb.DBRPMapping{
ID: 1,
OrganizationID: 1,
BucketID: 2,
@ -430,10 +430,10 @@ func TestAuth_Create(t *testing.T) {
{
name: "unauthorized",
fields: fields{
service: &mock.DBRPMappingServiceV2{},
service: &mock.DBRPMappingService{},
},
args: args{
m: influxdb.DBRPMappingV2{
m: influxdb.DBRPMapping{
ID: 1,
OrganizationID: 1,
BucketID: 2,
@ -471,7 +471,7 @@ func TestAuth_Create(t *testing.T) {
func TestAuth_Update(t *testing.T) {
type fields struct {
service influxdb.DBRPMappingServiceV2
service influxdb.DBRPMappingService
}
type args struct {
orgID platform.ID
@ -491,7 +491,7 @@ func TestAuth_Update(t *testing.T) {
{
name: "authorized",
fields: fields{
service: &mock.DBRPMappingServiceV2{},
service: &mock.DBRPMappingService{},
},
args: args{
permission: influxdb.Permission{
@ -511,7 +511,7 @@ func TestAuth_Update(t *testing.T) {
{
name: "unauthorized",
fields: fields{
service: &mock.DBRPMappingServiceV2{},
service: &mock.DBRPMappingService{},
},
args: args{
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}))
// 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)
})
}
@ -549,7 +549,7 @@ func TestAuth_Update(t *testing.T) {
func TestAuth_Delete(t *testing.T) {
type fields struct {
service influxdb.DBRPMappingServiceV2
service influxdb.DBRPMappingService
}
type args struct {
orgID platform.ID
@ -569,9 +569,9 @@ func TestAuth_Delete(t *testing.T) {
{
name: "authorized",
fields: fields{
service: &mock.DBRPMappingServiceV2{
FindByIDFn: func(_ context.Context, _, _ platform.ID) (*influxdb.DBRPMappingV2, error) {
return &influxdb.DBRPMappingV2{
service: &mock.DBRPMappingService{
FindByIDFn: func(_ context.Context, _, _ platform.ID) (*influxdb.DBRPMapping, error) {
return &influxdb.DBRPMapping{
OrganizationID: platform.ID(1),
BucketID: platform.ID(1),
}, nil
@ -596,9 +596,9 @@ func TestAuth_Delete(t *testing.T) {
{
name: "unauthorized",
fields: fields{
service: &mock.DBRPMappingServiceV2{
FindByIDFn: func(_ context.Context, _, _ platform.ID) (*influxdb.DBRPMappingV2, error) {
return &influxdb.DBRPMappingV2{
service: &mock.DBRPMappingService{
FindByIDFn: func(_ context.Context, _, _ platform.ID) (*influxdb.DBRPMapping, error) {
return &influxdb.DBRPMapping{
OrganizationID: platform.ID(1),
BucketID: platform.ID(1),
}, 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")
)
var _ influxdb.DBRPMappingServiceV2 = (*AuthorizedService)(nil)
var _ influxdb.DBRPMappingService = (*AuthorizedService)(nil)
type Service struct {
store kv.Store
@ -54,7 +54,7 @@ type Service struct {
byOrg *kv.Index
}
func indexForeignKey(dbrp influxdb.DBRPMappingV2) []byte {
func indexForeignKey(dbrp influxdb.DBRPMapping) []byte {
return composeForeignKey(dbrp.OrganizationID, dbrp.Database)
}
@ -66,13 +66,13 @@ func composeForeignKey(orgID platform.ID, db string) []byte {
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{
store: st,
IDGen: snowflake.NewDefaultIDGenerator(),
bucketSvc: bucketSvc,
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 {
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.
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.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 {
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.
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()
if err != nil {
return nil, ErrInvalidDBRPID(id.String(), err)
}
m := &influxdb.DBRPMappingV2{}
m := &influxdb.DBRPMapping{}
if err := s.store.View(ctx, func(tx kv.Tx) error {
bucket, err := tx.Bucket(bucket)
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.
// 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.
defs := make(map[string]*platform.ID)
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
}
ms := []*influxdb.DBRPMappingV2{}
ms := []*influxdb.DBRPMapping{}
add := func(tx kv.Tx) 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 {
return false, ErrInternalService(err)
}
@ -342,7 +342,7 @@ func (s *Service) FindMany(ctx context.Context, filter influxdb.DBRPMappingFilte
// Create creates a new mapping.
// 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.
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() {
dbrp.ID = s.IDGen.ID()
}
@ -415,7 +415,7 @@ func (s *Service) Create(ctx context.Context, dbrp *influxdb.DBRPMappingV2) erro
// Updates a mapping.
// 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.
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 {
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.
// 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) &&
(filter.OrgID == nil || (*filter.OrgID) == dbrp.OrganizationID) &&
(filter.BucketID == nil || (*filter.BucketID) == dbrp.BucketID) &&

View File

@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"github.com/influxdata/influxdb/v2/kit/platform"
"io/ioutil"
"os"
"testing"
@ -12,6 +11,7 @@ import (
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/bolt"
"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/migration/all"
"github.com/influxdata/influxdb/v2/mock"
@ -48,7 +48,7 @@ func NewTestBoltStore(t *testing.T) (kv.Store, func(), error) {
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)
if err != nil {
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()
itesting.DBRPMappingServiceV2(initDBRPMappingService, t)
itesting.DBRPMappingService(initDBRPMappingService, t)
}

View File

@ -10,25 +10,25 @@ import (
"github.com/influxdata/influxdb/v2/kit/platform/errors"
)
// DBRPMappingServiceV2 provides CRUD to DBRPMappingV2s.
type DBRPMappingServiceV2 interface {
// DBRPMappingService provides CRUD to DBRPMappingV2s.
type DBRPMappingService interface {
// FindBy returns the dbrp mapping for the specified ID.
// 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(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(ctx context.Context, dbrp *DBRPMappingV2) error
Create(ctx context.Context, dbrp *DBRPMapping) error
// Update a new dbrp mapping
Update(ctx context.Context, dbrp *DBRPMappingV2) error
Update(ctx context.Context, dbrp *DBRPMapping) error
// Delete removes a dbrp mapping.
// Deleting a mapping that does not exists is not an error.
// Requires orgID because every resource will be org-scoped.
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.
type DBRPMappingV2 struct {
// DBRPMapping represents a mapping of a database and retention policy to an organization ID and bucket ID.
type DBRPMapping struct {
ID platform.ID `json:"id"`
Database string `json:"database"`
RetentionPolicy string `json:"retention_policy"`
@ -41,7 +41,7 @@ type DBRPMappingV2 struct {
}
// Validate reports any validation errors for the mapping.
func (m DBRPMappingV2) Validate() error {
func (m DBRPMapping) Validate() error {
if !validName(m.Database) {
return &errors.Error{
Code: errors.EInvalid,
@ -70,7 +70,7 @@ func (m DBRPMappingV2) Validate() error {
}
// 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 {
return true
}
@ -90,8 +90,8 @@ func (m *DBRPMappingV2) Equal(o *DBRPMappingV2) bool {
m.BucketID == o.BucketID
}
// DBRPMappingFilterV2 represents a set of filters that restrict the returned results.
type DBRPMappingFilterV2 struct {
// DBRPMappingFilter represents a set of filters that restrict the returned results.
type DBRPMappingFilter struct {
ID *platform.ID
OrgID *platform.ID
BucketID *platform.ID
@ -101,7 +101,7 @@ type DBRPMappingFilterV2 struct {
Default *bool
}
func (f DBRPMappingFilterV2) String() string {
func (f DBRPMappingFilter) String() string {
var s strings.Builder
s.WriteString("{ id:")
@ -149,69 +149,6 @@ func (f DBRPMappingFilterV2) String() 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
func validName(name string) bool {
for _, r := range name {
@ -224,65 +161,3 @@ func validName(name string) bool {
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
import (
platform2 "github.com/influxdata/influxdb/v2/kit/platform"
"testing"
platform "github.com/influxdata/influxdb/v2"
platform2 "github.com/influxdata/influxdb/v2/kit/platform"
platformtesting "github.com/influxdata/influxdb/v2/testing"
)
func TestDBRPMapping_Validate(t *testing.T) {
type fields struct {
Cluster string
Database string
RetentionPolicy string
Default bool
@ -22,17 +21,9 @@ func TestDBRPMapping_Validate(t *testing.T) {
fields fields
wantErr bool
}{
{
name: "mapping requires a cluster",
fields: fields{
Cluster: "",
},
wantErr: true,
},
{
name: "mapping requires a database",
fields: fields{
Cluster: "abc",
Database: "",
},
wantErr: true,
@ -40,7 +31,6 @@ func TestDBRPMapping_Validate(t *testing.T) {
{
name: "mapping requires an rp",
fields: fields{
Cluster: "abc",
Database: "telegraf",
RetentionPolicy: "",
},
@ -49,7 +39,6 @@ func TestDBRPMapping_Validate(t *testing.T) {
{
name: "mapping requires an orgid",
fields: fields{
Cluster: "abc",
Database: "telegraf",
RetentionPolicy: "autogen",
},
@ -58,24 +47,15 @@ func TestDBRPMapping_Validate(t *testing.T) {
{
name: "mapping requires a bucket id",
fields: fields{
Cluster: "abc",
Database: "telegraf",
RetentionPolicy: "autogen",
OrganizationID: platformtesting.MustIDBase16("debac1e0deadbeef"),
},
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/_/./-",
fields: fields{
Cluster: "12345_.",
Database: string([]byte{0x0D}),
},
wantErr: true,
@ -83,7 +63,6 @@ func TestDBRPMapping_Validate(t *testing.T) {
{
name: "rp cannot have non-printable characters",
fields: fields{
Cluster: "12345",
Database: "telegraf",
RetentionPolicy: string([]byte{0x0D}),
},
@ -92,7 +71,6 @@ func TestDBRPMapping_Validate(t *testing.T) {
{
name: "dash accepted as valid database",
fields: fields{
Cluster: "12345_.",
Database: "howdy-doody",
RetentionPolicy: "autogen",
OrganizationID: platformtesting.MustIDBase16("debac1e0deadbeef"),
@ -103,7 +81,6 @@ func TestDBRPMapping_Validate(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
m := platform.DBRPMapping{
Cluster: tt.fields.Cluster,
Database: tt.fields.Database,
RetentionPolicy: tt.fields.RetentionPolicy,
Default: tt.fields.Default,

View File

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

View File

@ -50,7 +50,7 @@ type Service struct {
*NotificationEndpointService
*TelegrafService
*LabelService
DBRPMappingServiceV2 *dbrp.Client
DBRPMappingService *dbrp.Client
}
// 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},
TelegrafService: NewTelegrafService(httpClient),
LabelService: &LabelService{Client: httpClient},
DBRPMappingServiceV2: dbrp.NewClient(httpClient),
DBRPMappingService: dbrp.NewClient(httpClient),
}, nil
}

View File

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

View File

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

View File

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

View File

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

View File

@ -6,6 +6,7 @@ package mocks
import (
context "context"
"github.com/influxdata/influxdb/v2/kit/platform"
reflect "reflect"
gomock "github.com/golang/mock/gomock"
@ -50,47 +51,32 @@ func (mr *MockDBRPMappingServiceMockRecorder) Create(arg0, arg1 interface{}) *go
}
// 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()
ret := m.ctrl.Call(m, "Delete", arg0, arg1, arg2, arg3)
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, arg3 interface{}) *gomock.Call {
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, arg3)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockDBRPMappingService)(nil).Delete), arg0, arg1, arg2)
}
// Find mocks base method
func (m *MockDBRPMappingService) Find(arg0 context.Context, arg1 influxdb.DBRPMappingFilter) (*influxdb.DBRPMapping, error) {
// 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, "Find", arg0, arg1)
ret := m.ctrl.Call(m, "FindByID", arg0, arg1, arg2)
ret0, _ := ret[0].(*influxdb.DBRPMapping)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// Find indicates an expected call of Find
func (mr *MockDBRPMappingServiceMockRecorder) Find(arg0, arg1 interface{}) *gomock.Call {
// 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, "Find", reflect.TypeOf((*MockDBRPMappingService)(nil).Find), arg0, arg1)
}
// 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)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindByID", reflect.TypeOf((*MockDBRPMappingService)(nil).FindByID), arg0, arg1, arg2)
}
// FindMany mocks base method
@ -113,3 +99,17 @@ func (mr *MockDBRPMappingServiceMockRecorder) FindMany(arg0, arg1 interface{}, a
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,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)
err = s.Launcher.
DBRPMappingServiceV2().
Create(ctx, &influxdb.DBRPMappingV2{
DBRPMappingService().
Create(ctx, &influxdb.DBRPMapping{
Database: bi.db,
RetentionPolicy: bi.rp,
Default: true,

View File

@ -173,8 +173,8 @@ func (qt *Test) init(ctx context.Context, t *testing.T, p *tests.DefaultPipeline
if !qt.noDefaultMapping {
ctx = icontext.SetAuthorizer(ctx, auth)
err := p.Launcher.
DBRPMappingServiceV2().
Create(ctx, &influxdb.DBRPMappingV2{
DBRPMappingService().
Create(ctx, &influxdb.DBRPMapping{
Database: qt.db,
RetentionPolicy: qt.rp,
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()))
if err := p.Launcher.DBRPMappingServiceV2().Create(ctx, &influxdb.DBRPMappingV2{
if err := p.Launcher.DBRPMappingService().Create(ctx, &influxdb.DBRPMapping{
Database: "mydb",
RetentionPolicy: "autogen",
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"
)
var _ influxdb.DBRPMappingServiceV2 = (*DBRPMappingServiceV2)(nil)
var _ influxdb.DBRPMappingService = (*DBRPMappingService)(nil)
type DBRPMappingServiceV2 struct {
FindByIDFn func(ctx context.Context, orgID, id platform.ID) (*influxdb.DBRPMappingV2, error)
FindManyFn func(ctx context.Context, dbrp influxdb.DBRPMappingFilterV2, opts ...influxdb.FindOptions) ([]*influxdb.DBRPMappingV2, int, error)
CreateFn func(ctx context.Context, dbrp *influxdb.DBRPMappingV2) error
UpdateFn func(ctx context.Context, dbrp *influxdb.DBRPMappingV2) error
type DBRPMappingService struct {
FindByIDFn func(ctx context.Context, orgID, id platform.ID) (*influxdb.DBRPMapping, error)
FindManyFn func(ctx context.Context, dbrp influxdb.DBRPMappingFilter, opts ...influxdb.FindOptions) ([]*influxdb.DBRPMapping, int, error)
CreateFn func(ctx context.Context, dbrp *influxdb.DBRPMapping) error
UpdateFn func(ctx context.Context, dbrp *influxdb.DBRPMapping) 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 {
return nil, nil
}
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 {
return nil, 0, nil
}
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 {
return nil
}
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 {
return nil
}
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 {
return nil
}
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"
// 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 NewCompiler(dbrpMappingSvc)
})
@ -31,12 +31,12 @@ type Compiler struct {
logicalPlannerOptions []plan.LogicalOption
dbrpMappingSvc platform.DBRPMappingServiceV2
dbrpMappingSvc platform.DBRPMappingService
}
var _ flux.Compiler = &Compiler{}
func NewCompiler(dbrpMappingSvc platform.DBRPMappingServiceV2) *Compiler {
func NewCompiler(dbrpMappingSvc platform.DBRPMappingService) *Compiler {
return &Compiler{
dbrpMappingSvc: dbrpMappingSvc,
}

View File

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

View File

@ -20,35 +20,35 @@ import (
platformtesting "github.com/influxdata/influxdb/v2/testing"
)
var dbrpMappingSvc = &mock.DBRPMappingServiceV2{}
var dbrpMappingSvc = &mock.DBRPMappingService{}
var organizationID platform2.ID
var bucketID platform2.ID
var altBucketID platform2.ID
func init() {
mapping := platform.DBRPMappingV2{
mapping := platform.DBRPMapping{
Database: "db0",
RetentionPolicy: "autogen",
Default: true,
OrganizationID: organizationID,
BucketID: bucketID,
}
altMapping := platform.DBRPMappingV2{
altMapping := platform.DBRPMapping{
Database: "db0",
RetentionPolicy: "autogen",
Default: true,
OrganizationID: organizationID,
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
}
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
if filter.RetentionPolicy != nil && *filter.RetentionPolicy == "alternate" {
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.
type Transpiler struct {
Config *Config
dbrpMappingSvc influxdb.DBRPMappingServiceV2
dbrpMappingSvc influxdb.DBRPMappingService
}
func NewTranspiler(dbrpMappingSvc influxdb.DBRPMappingServiceV2) *Transpiler {
func NewTranspiler(dbrpMappingSvc influxdb.DBRPMappingService) *Transpiler {
return NewTranspilerWithConfig(dbrpMappingSvc, Config{})
}
func NewTranspilerWithConfig(dbrpMappingSvc influxdb.DBRPMappingServiceV2, cfg Config) *Transpiler {
func NewTranspilerWithConfig(dbrpMappingSvc influxdb.DBRPMappingService, cfg Config) *Transpiler {
return &Transpiler{
Config: &cfg,
dbrpMappingSvc: dbrpMappingSvc,
@ -58,10 +58,10 @@ type transpilerState struct {
config Config
file *ast.File
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{
file: &ast.File{
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 != "" {
filter.Database = &db
}

View File

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

View File

@ -43,7 +43,7 @@ func (s *LocalDatabasesProcedureSpec) Copy() plan.ProcedureSpec {
type DatabasesDecoder struct {
orgID platform2.ID
deps *DatabasesDependencies
databases []*platform.DBRPMappingV2
databases []*platform.DBRPMapping
alloc *memory.Allocator
}
@ -52,7 +52,7 @@ func (bd *DatabasesDecoder) Connect(ctx context.Context) 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 {
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) {
type databaseInfo struct {
*platform.DBRPMappingV2
*platform.DBRPMapping
RetentionPeriod time.Duration
}
@ -77,7 +77,7 @@ func (bd *DatabasesDecoder) Decode(ctx context.Context) (flux.Table, error) {
return nil, err
}
databases = append(databases, databaseInfo{
DBRPMappingV2: db,
DBRPMapping: db,
RetentionPeriod: bucket.RetentionPeriod,
})
}
@ -172,7 +172,7 @@ type key int
const dependenciesKey key = iota
type DatabasesDependencies struct {
DBRP platform.DBRPMappingServiceV2
DBRP platform.DBRPMappingService
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"
)
func strPtr(s string) *string {
return &s
}
func boolPtr(b bool) *bool {
return &b
}
// TODO(goller): remove opPrefix argument
func diffPlatformErrors(name string, actual, expected error, opPrefix string, t *testing.T) {
t.Helper()

View File

@ -319,13 +319,13 @@ func (c *Client) MustCreateDBRPMapping(t *testing.T) platform.ID {
t.Helper()
ctx := context.Background()
m := &influxdb.DBRPMappingV2{
m := &influxdb.DBRPMapping{
Database: "db",
RetentionPolicy: "rp",
OrganizationID: c.OrgID,
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)
}
return m.ID
@ -422,7 +422,7 @@ func (c *Client) DeleteResource(t *testing.T, r influxdb.ResourceType, id platfo
case influxdb.ChecksResourceType: // 16
return c.DeleteCheck(ctx, id)
case influxdb.DBRPResourceType: // 17
return c.DBRPMappingServiceV2.Delete(ctx, c.OrgID, id)
return c.DBRPMappingService.Delete(ctx, c.OrgID, id)
}
return nil
}
@ -535,7 +535,7 @@ func (c *Client) FindAll(t *testing.T, r influxdb.ResourceType) ([]platform.ID,
ids = append(ids, r.ID)
}
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 {
return nil, err
}

View File

@ -32,7 +32,7 @@ type LocalShardMapper struct {
ShardGroup(ids []uint64) tsdb.ShardGroup
}
DBRP influxdb.DBRPMappingServiceV2
DBRP influxdb.DBRPMappingService
}
// 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.
if _, ok := a.ShardMap[source]; !ok {
// lookup bucket and create info
mappings, _, err := e.DBRP.FindMany(ctx, influxdb.DBRPMappingFilterV2{
mappings, _, err := e.DBRP.FindMany(ctx, influxdb.DBRPMappingFilter{
OrgID: &orgID,
Database: &s.Database,
RetentionPolicy: &s.RetentionPolicy,

View File

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

View File

@ -35,7 +35,7 @@ type StatementExecutor struct {
// ShardMapper for mapping shards when executing a SELECT statement.
ShardMapper query.ShardMapper
DBRP influxdb.DBRPMappingServiceV2
DBRP influxdb.DBRPMappingService
// Select statement limits
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) {
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,
})
if err != nil {
@ -349,9 +349,9 @@ func (e *StatementExecutor) executeShowDatabasesStatement(ctx context.Context, q
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
mappings, n, err := e.DBRP.FindMany(ctx, influxdb.DBRPMappingFilterV2{
mappings, n, err := e.DBRP.FindMany(ctx, influxdb.DBRPMappingFilter{
OrgID: &ectx.OrgID,
Database: &database,
Default: &defaultRP,
@ -440,7 +440,7 @@ func (e *StatementExecutor) executeShowRetentionPoliciesStatement(ctx context.Co
return nil, ErrDatabaseNameRequired
}
dbrps, _, err := e.DBRP.FindMany(ctx, influxdb.DBRPMappingFilterV2{
dbrps, _, err := e.DBRP.FindMany(ctx, influxdb.DBRPMappingFilter{
OrgID: &ectx.OrgID,
Database: &q.Database,
})
@ -716,7 +716,7 @@ func (e *StatementExecutor) normalizeMeasurement(ctx context.Context, m *influxq
}
// TODO(sgc): Validate database; fetch default RP
filter := influxdb.DBRPMappingFilterV2{
filter := influxdb.DBRPMappingFilter{
OrgID: &ectx.OrgID,
Database: &m.Database,
}
@ -744,7 +744,7 @@ func (e *StatementExecutor) normalizeMeasurement(ctx context.Context, m *influxq
return nil
}
type mappings []*influxdb.DBRPMappingV2
type mappings []*influxdb.DBRPMapping
func (m mappings) DefaultRetentionPolicy(db string) string {
for _, v := range m {

View File

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