refactor: refactor for tasks backport (#21117)

* chore: remove dead code

* refactor: move FluxLanguageService interface to fluxlang

* chore: run fmt

* refactor: move task.go from top level to task/taskmodel

* chore: run formatter

* chore: fix up import ordering with gci
pull/21158/head^2
Sam Arnold 2021-04-07 15:42:55 -03:00 committed by GitHub
parent 07c030a9b1
commit 7b2e122869
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
74 changed files with 1267 additions and 1358 deletions

View File

@ -3,9 +3,9 @@ package authorizer
import ( import (
"context" "context"
"github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/influxdb/v2/task/taskmodel"
) )
// AuthorizeFindDBRPs takes the given items and returns only the ones that the user is authorized to access. // AuthorizeFindDBRPs takes the given items and returns only the ones that the user is authorized to access.
@ -129,7 +129,7 @@ func AuthorizeFindSources(ctx context.Context, rs []*influxdb.Source) ([]*influx
} }
// AuthorizeFindTasks takes the given items and returns only the ones that the user is authorized to read. // AuthorizeFindTasks takes the given items and returns only the ones that the user is authorized to read.
func AuthorizeFindTasks(ctx context.Context, rs []*influxdb.Task) ([]*influxdb.Task, int, error) { func AuthorizeFindTasks(ctx context.Context, rs []*taskmodel.Task) ([]*taskmodel.Task, int, error) {
// This filters without allocating // This filters without allocating
// https://github.com/golang/go/wiki/SliceTricks#filtering-without-allocating // https://github.com/golang/go/wiki/SliceTricks#filtering-without-allocating
rrs := rs[:0] rrs := rs[:0]

View File

@ -3,9 +3,9 @@ package authorizer
import ( import (
"context" "context"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/task/taskmodel"
) )
var _ influxdb.CheckService = (*CheckService)(nil) var _ influxdb.CheckService = (*CheckService)(nil)
@ -16,7 +16,7 @@ type CheckService struct {
s influxdb.CheckService s influxdb.CheckService
influxdb.UserResourceMappingService influxdb.UserResourceMappingService
influxdb.OrganizationService influxdb.OrganizationService
influxdb.TaskService taskmodel.TaskService
} }
// NewCheckService constructs an instance of an authorizing check service. // NewCheckService constructs an instance of an authorizing check service.

View File

@ -4,11 +4,11 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/platform" "github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/kit/platform/errors" "github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/tracing" "github.com/influxdata/influxdb/v2/kit/tracing"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -35,13 +35,13 @@ var (
) )
type taskServiceValidator struct { type taskServiceValidator struct {
influxdb.TaskService taskmodel.TaskService
log *zap.Logger log *zap.Logger
} }
// TaskService wraps ts and checks appropriate permissions before calling requested methods on ts. // TaskService wraps ts and checks appropriate permissions before calling requested methods on ts.
// Authorization failures are logged to the logger. // Authorization failures are logged to the logger.
func NewTaskService(log *zap.Logger, ts influxdb.TaskService) influxdb.TaskService { func NewTaskService(log *zap.Logger, ts taskmodel.TaskService) taskmodel.TaskService {
return &taskServiceValidator{ return &taskServiceValidator{
TaskService: ts, TaskService: ts,
log: log, log: log,
@ -61,7 +61,7 @@ func (ts *taskServiceValidator) processPermissionError(a influxdb.Authorizer, p
return err return err
} }
func (ts *taskServiceValidator) FindTaskByID(ctx context.Context, id platform.ID) (*influxdb.Task, error) { func (ts *taskServiceValidator) FindTaskByID(ctx context.Context, id platform.ID) (*taskmodel.Task, error) {
span, ctx := tracing.StartSpanFromContext(ctx) span, ctx := tracing.StartSpanFromContext(ctx)
defer span.Finish() defer span.Finish()
@ -79,7 +79,7 @@ func (ts *taskServiceValidator) FindTaskByID(ctx context.Context, id platform.ID
return task, nil return task, nil
} }
func (ts *taskServiceValidator) FindTasks(ctx context.Context, filter influxdb.TaskFilter) ([]*influxdb.Task, int, error) { func (ts *taskServiceValidator) FindTasks(ctx context.Context, filter taskmodel.TaskFilter) ([]*taskmodel.Task, int, error) {
span, ctx := tracing.StartSpanFromContext(ctx) span, ctx := tracing.StartSpanFromContext(ctx)
defer span.Finish() defer span.Finish()
// Get the tasks in the organization, without authentication. // Get the tasks in the organization, without authentication.
@ -90,12 +90,12 @@ func (ts *taskServiceValidator) FindTasks(ctx context.Context, filter influxdb.T
return AuthorizeFindTasks(ctx, unauthenticatedTasks) return AuthorizeFindTasks(ctx, unauthenticatedTasks)
} }
func (ts *taskServiceValidator) CreateTask(ctx context.Context, t influxdb.TaskCreate) (*influxdb.Task, error) { func (ts *taskServiceValidator) CreateTask(ctx context.Context, t taskmodel.TaskCreate) (*taskmodel.Task, error) {
span, ctx := tracing.StartSpanFromContext(ctx) span, ctx := tracing.StartSpanFromContext(ctx)
defer span.Finish() defer span.Finish()
if !t.OwnerID.Valid() { if !t.OwnerID.Valid() {
return nil, influxdb.ErrInvalidOwnerID return nil, taskmodel.ErrInvalidOwnerID
} }
a, p, err := AuthorizeCreate(ctx, influxdb.TasksResourceType, t.OrganizationID) a, p, err := AuthorizeCreate(ctx, influxdb.TasksResourceType, t.OrganizationID)
@ -106,7 +106,7 @@ func (ts *taskServiceValidator) CreateTask(ctx context.Context, t influxdb.TaskC
return ts.TaskService.CreateTask(ctx, t) return ts.TaskService.CreateTask(ctx, t)
} }
func (ts *taskServiceValidator) UpdateTask(ctx context.Context, id platform.ID, upd influxdb.TaskUpdate) (*influxdb.Task, error) { func (ts *taskServiceValidator) UpdateTask(ctx context.Context, id platform.ID, upd taskmodel.TaskUpdate) (*taskmodel.Task, error) {
span, ctx := tracing.StartSpanFromContext(ctx) span, ctx := tracing.StartSpanFromContext(ctx)
defer span.Finish() defer span.Finish()
@ -142,7 +142,7 @@ func (ts *taskServiceValidator) DeleteTask(ctx context.Context, id platform.ID)
return ts.TaskService.DeleteTask(ctx, id) return ts.TaskService.DeleteTask(ctx, id)
} }
func (ts *taskServiceValidator) FindLogs(ctx context.Context, filter influxdb.LogFilter) ([]*influxdb.Log, int, error) { func (ts *taskServiceValidator) FindLogs(ctx context.Context, filter taskmodel.LogFilter) ([]*taskmodel.Log, int, error) {
span, ctx := tracing.StartSpanFromContext(ctx) span, ctx := tracing.StartSpanFromContext(ctx)
defer span.Finish() defer span.Finish()
@ -155,7 +155,7 @@ func (ts *taskServiceValidator) FindLogs(ctx context.Context, filter influxdb.Lo
return ts.TaskService.FindLogs(ctx, filter) return ts.TaskService.FindLogs(ctx, filter)
} }
func (ts *taskServiceValidator) FindRuns(ctx context.Context, filter influxdb.RunFilter) ([]*influxdb.Run, int, error) { func (ts *taskServiceValidator) FindRuns(ctx context.Context, filter taskmodel.RunFilter) ([]*taskmodel.Run, int, error) {
span, ctx := tracing.StartSpanFromContext(ctx) span, ctx := tracing.StartSpanFromContext(ctx)
defer span.Finish() defer span.Finish()
@ -174,7 +174,7 @@ func (ts *taskServiceValidator) FindRuns(ctx context.Context, filter influxdb.Ru
return ts.TaskService.FindRuns(ctx, filter) return ts.TaskService.FindRuns(ctx, filter)
} }
func (ts *taskServiceValidator) FindRunByID(ctx context.Context, taskID, runID platform.ID) (*influxdb.Run, error) { func (ts *taskServiceValidator) FindRunByID(ctx context.Context, taskID, runID platform.ID) (*taskmodel.Run, error) {
span, ctx := tracing.StartSpanFromContext(ctx) span, ctx := tracing.StartSpanFromContext(ctx)
defer span.Finish() defer span.Finish()
@ -210,7 +210,7 @@ func (ts *taskServiceValidator) CancelRun(ctx context.Context, taskID, runID pla
return ts.TaskService.CancelRun(ctx, taskID, runID) return ts.TaskService.CancelRun(ctx, taskID, runID)
} }
func (ts *taskServiceValidator) RetryRun(ctx context.Context, taskID, runID platform.ID) (*influxdb.Run, error) { func (ts *taskServiceValidator) RetryRun(ctx context.Context, taskID, runID platform.ID) (*taskmodel.Run, error) {
span, ctx := tracing.StartSpanFromContext(ctx) span, ctx := tracing.StartSpanFromContext(ctx)
defer span.Finish() defer span.Finish()
@ -220,7 +220,7 @@ func (ts *taskServiceValidator) RetryRun(ctx context.Context, taskID, runID plat
return nil, err return nil, err
} }
if task.Status != string(influxdb.TaskActive) { if task.Status != string(taskmodel.TaskActive) {
return nil, ErrInactiveTask return nil, ErrInactiveTask
} }
@ -232,7 +232,7 @@ func (ts *taskServiceValidator) RetryRun(ctx context.Context, taskID, runID plat
return ts.TaskService.RetryRun(ctx, taskID, runID) return ts.TaskService.RetryRun(ctx, taskID, runID)
} }
func (ts *taskServiceValidator) ForceRun(ctx context.Context, taskID platform.ID, scheduledFor int64) (*influxdb.Run, error) { func (ts *taskServiceValidator) ForceRun(ctx context.Context, taskID platform.ID, scheduledFor int64) (*taskmodel.Run, error) {
span, ctx := tracing.StartSpanFromContext(ctx) span, ctx := tracing.StartSpanFromContext(ctx)
defer span.Finish() defer span.Finish()
@ -242,7 +242,7 @@ func (ts *taskServiceValidator) ForceRun(ctx context.Context, taskID platform.ID
return nil, err return nil, err
} }
if task.Status != string(influxdb.TaskActive) { if task.Status != string(taskmodel.TaskActive) {
return nil, ErrInactiveTask return nil, ErrInactiveTask
} }

View File

@ -2,7 +2,6 @@ package authorizer_test
import ( import (
"context" "context"
"github.com/influxdata/influxdb/v2/kit/platform"
"testing" "testing"
"time" "time"
@ -13,9 +12,11 @@ import (
_ "github.com/influxdata/influxdb/v2/fluxinit/static" _ "github.com/influxdata/influxdb/v2/fluxinit/static"
"github.com/influxdata/influxdb/v2/http" "github.com/influxdata/influxdb/v2/http"
"github.com/influxdata/influxdb/v2/inmem" "github.com/influxdata/influxdb/v2/inmem"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/kv" "github.com/influxdata/influxdb/v2/kv"
"github.com/influxdata/influxdb/v2/kv/migration/all" "github.com/influxdata/influxdb/v2/kv/migration/all"
"github.com/influxdata/influxdb/v2/mock" "github.com/influxdata/influxdb/v2/mock"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"github.com/influxdata/influxdb/v2/tenant" "github.com/influxdata/influxdb/v2/tenant"
"github.com/pkg/errors" "github.com/pkg/errors"
"go.uber.org/zap/zaptest" "go.uber.org/zap/zaptest"
@ -39,7 +40,7 @@ func TestOnboardingValidation(t *testing.T) {
ctx := pctx.SetAuthorizer(context.Background(), r.Auth) ctx := pctx.SetAuthorizer(context.Background(), r.Auth)
_, err = ts.CreateTask(ctx, influxdb.TaskCreate{ _, err = ts.CreateTask(ctx, taskmodel.TaskCreate{
OrganizationID: r.Org.ID, OrganizationID: r.Org.ID,
OwnerID: r.Auth.GetUserID(), OwnerID: r.Auth.GetUserID(),
Flux: `option task = { Flux: `option task = {
@ -53,12 +54,12 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`,
} }
} }
func mockTaskService(orgID, taskID, runID platform.ID) influxdb.TaskService { func mockTaskService(orgID, taskID, runID platform.ID) taskmodel.TaskService {
task := influxdb.Task{ task := taskmodel.Task{
ID: taskID, ID: taskID,
OrganizationID: orgID, OrganizationID: orgID,
Name: "cows", Name: "cows",
Status: string(influxdb.TaskActive), Status: string(taskmodel.TaskActive),
Flux: `option task = { Flux: `option task = {
name: "my_task", name: "my_task",
every: 1s, every: 1s,
@ -67,51 +68,51 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`,
Every: "1s", Every: "1s",
} }
log := influxdb.Log{Message: "howdy partner"} log := taskmodel.Log{Message: "howdy partner"}
run := influxdb.Run{ run := taskmodel.Run{
ID: runID, ID: runID,
TaskID: taskID, TaskID: taskID,
Status: "completed", Status: "completed",
ScheduledFor: time.Now().UTC(), ScheduledFor: time.Now().UTC(),
StartedAt: time.Now().UTC().Add(time.Second * 3), StartedAt: time.Now().UTC().Add(time.Second * 3),
FinishedAt: time.Now().UTC().Add(time.Second * 10), FinishedAt: time.Now().UTC().Add(time.Second * 10),
Log: []influxdb.Log{log}, Log: []taskmodel.Log{log},
} }
return &mock.TaskService{ return &mock.TaskService{
FindTaskByIDFn: func(context.Context, platform.ID) (*influxdb.Task, error) { FindTaskByIDFn: func(context.Context, platform.ID) (*taskmodel.Task, error) {
return &task, nil return &task, nil
}, },
FindTasksFn: func(context.Context, influxdb.TaskFilter) ([]*influxdb.Task, int, error) { FindTasksFn: func(context.Context, taskmodel.TaskFilter) ([]*taskmodel.Task, int, error) {
return []*influxdb.Task{&task}, 1, nil return []*taskmodel.Task{&task}, 1, nil
}, },
CreateTaskFn: func(_ context.Context, tc influxdb.TaskCreate) (*influxdb.Task, error) { CreateTaskFn: func(_ context.Context, tc taskmodel.TaskCreate) (*taskmodel.Task, error) {
taskCopy := task taskCopy := task
return &taskCopy, nil return &taskCopy, nil
}, },
UpdateTaskFn: func(context.Context, platform.ID, influxdb.TaskUpdate) (*influxdb.Task, error) { UpdateTaskFn: func(context.Context, platform.ID, taskmodel.TaskUpdate) (*taskmodel.Task, error) {
return &task, nil return &task, nil
}, },
DeleteTaskFn: func(context.Context, platform.ID) error { DeleteTaskFn: func(context.Context, platform.ID) error {
return nil return nil
}, },
FindLogsFn: func(context.Context, influxdb.LogFilter) ([]*influxdb.Log, int, error) { FindLogsFn: func(context.Context, taskmodel.LogFilter) ([]*taskmodel.Log, int, error) {
return []*influxdb.Log{&log}, 1, nil return []*taskmodel.Log{&log}, 1, nil
}, },
FindRunsFn: func(context.Context, influxdb.RunFilter) ([]*influxdb.Run, int, error) { FindRunsFn: func(context.Context, taskmodel.RunFilter) ([]*taskmodel.Run, int, error) {
return []*influxdb.Run{&run}, 1, nil return []*taskmodel.Run{&run}, 1, nil
}, },
FindRunByIDFn: func(context.Context, platform.ID, platform.ID) (*influxdb.Run, error) { FindRunByIDFn: func(context.Context, platform.ID, platform.ID) (*taskmodel.Run, error) {
return &run, nil return &run, nil
}, },
CancelRunFn: func(context.Context, platform.ID, platform.ID) error { CancelRunFn: func(context.Context, platform.ID, platform.ID) error {
return nil return nil
}, },
RetryRunFn: func(context.Context, platform.ID, platform.ID) (*influxdb.Run, error) { RetryRunFn: func(context.Context, platform.ID, platform.ID) (*taskmodel.Run, error) {
return &run, nil return &run, nil
}, },
ForceRunFn: func(context.Context, platform.ID, int64) (*influxdb.Run, error) { ForceRunFn: func(context.Context, platform.ID, int64) (*taskmodel.Run, error) {
return &run, nil return &run, nil
}, },
} }
@ -196,13 +197,13 @@ func TestValidations(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
check func(context.Context, influxdb.TaskService) error check func(context.Context, taskmodel.TaskService) error
auth *influxdb.Authorization auth *influxdb.Authorization
}{ }{
{ {
name: "create failure", name: "create failure",
check: func(ctx context.Context, svc influxdb.TaskService) error { check: func(ctx context.Context, svc taskmodel.TaskService) error {
_, err := svc.CreateTask(ctx, influxdb.TaskCreate{ _, err := svc.CreateTask(ctx, taskmodel.TaskCreate{
OrganizationID: r.Org.ID, OrganizationID: r.Org.ID,
Flux: `option task = { Flux: `option task = {
name: "my_task", name: "my_task",
@ -220,8 +221,8 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`,
{ {
name: "create success", name: "create success",
auth: r.Auth, auth: r.Auth,
check: func(ctx context.Context, svc influxdb.TaskService) error { check: func(ctx context.Context, svc taskmodel.TaskService) error {
_, err := svc.CreateTask(ctx, influxdb.TaskCreate{ _, err := svc.CreateTask(ctx, taskmodel.TaskCreate{
OrganizationID: r.Org.ID, OrganizationID: r.Org.ID,
OwnerID: r.Auth.GetUserID(), OwnerID: r.Auth.GetUserID(),
Flux: `option task = { Flux: `option task = {
@ -236,7 +237,7 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`,
{ {
name: "FindTaskByID missing auth", name: "FindTaskByID missing auth",
auth: &influxdb.Authorization{Permissions: []influxdb.Permission{}}, auth: &influxdb.Authorization{Permissions: []influxdb.Permission{}},
check: func(ctx context.Context, svc influxdb.TaskService) error { check: func(ctx context.Context, svc taskmodel.TaskService) error {
_, err := svc.FindTaskByID(ctx, taskID) _, err := svc.FindTaskByID(ctx, taskID)
if err == nil { if err == nil {
return errors.New("returned without error without permission") return errors.New("returned without error without permission")
@ -247,7 +248,7 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`,
{ {
name: "FindTaskByID with org auth", name: "FindTaskByID with org auth",
auth: &influxdb.Authorization{Status: "active", Permissions: orgReadAllTaskPermissions}, auth: &influxdb.Authorization{Status: "active", Permissions: orgReadAllTaskPermissions},
check: func(ctx context.Context, svc influxdb.TaskService) error { check: func(ctx context.Context, svc taskmodel.TaskService) error {
_, err := svc.FindTaskByID(ctx, taskID) _, err := svc.FindTaskByID(ctx, taskID)
return err return err
}, },
@ -255,7 +256,7 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`,
{ {
name: "FindTaskByID with task auth", name: "FindTaskByID with task auth",
auth: &influxdb.Authorization{Status: "active", Permissions: orgReadTaskPermissions}, auth: &influxdb.Authorization{Status: "active", Permissions: orgReadTaskPermissions},
check: func(ctx context.Context, svc influxdb.TaskService) error { check: func(ctx context.Context, svc taskmodel.TaskService) error {
_, err := svc.FindTaskByID(ctx, taskID) _, err := svc.FindTaskByID(ctx, taskID)
return err return err
}, },
@ -263,8 +264,8 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`,
{ {
name: "FindTasks with bad auth", name: "FindTasks with bad auth",
auth: &influxdb.Authorization{Status: "active", Permissions: wrongOrgReadAllTaskPermissions}, auth: &influxdb.Authorization{Status: "active", Permissions: wrongOrgReadAllTaskPermissions},
check: func(ctx context.Context, svc influxdb.TaskService) error { check: func(ctx context.Context, svc taskmodel.TaskService) error {
ts, _, err := svc.FindTasks(ctx, influxdb.TaskFilter{ ts, _, err := svc.FindTasks(ctx, taskmodel.TaskFilter{
OrganizationID: &orgID, OrganizationID: &orgID,
}) })
if err == nil && len(ts) > 0 { if err == nil && len(ts) > 0 {
@ -276,8 +277,8 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`,
{ {
name: "FindTasks with org auth", name: "FindTasks with org auth",
auth: &influxdb.Authorization{Status: "active", Permissions: orgReadAllTaskPermissions}, auth: &influxdb.Authorization{Status: "active", Permissions: orgReadAllTaskPermissions},
check: func(ctx context.Context, svc influxdb.TaskService) error { check: func(ctx context.Context, svc taskmodel.TaskService) error {
_, _, err := svc.FindTasks(ctx, influxdb.TaskFilter{ _, _, err := svc.FindTasks(ctx, taskmodel.TaskFilter{
OrganizationID: &orgID, OrganizationID: &orgID,
}) })
return err return err
@ -286,8 +287,8 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`,
{ {
name: "FindTasks with task auth", name: "FindTasks with task auth",
auth: &influxdb.Authorization{Status: "active", Permissions: orgReadTaskPermissions}, auth: &influxdb.Authorization{Status: "active", Permissions: orgReadTaskPermissions},
check: func(ctx context.Context, svc influxdb.TaskService) error { check: func(ctx context.Context, svc taskmodel.TaskService) error {
_, _, err := svc.FindTasks(ctx, influxdb.TaskFilter{ _, _, err := svc.FindTasks(ctx, taskmodel.TaskFilter{
OrganizationID: &orgID, OrganizationID: &orgID,
}) })
return err return err
@ -296,21 +297,21 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`,
{ {
name: "FindTasks without org filter", name: "FindTasks without org filter",
auth: &influxdb.Authorization{Status: "active", Permissions: orgReadAllTaskPermissions}, auth: &influxdb.Authorization{Status: "active", Permissions: orgReadAllTaskPermissions},
check: func(ctx context.Context, svc influxdb.TaskService) error { check: func(ctx context.Context, svc taskmodel.TaskService) error {
_, _, err := svc.FindTasks(ctx, influxdb.TaskFilter{}) _, _, err := svc.FindTasks(ctx, taskmodel.TaskFilter{})
return err return err
}, },
}, },
{ {
name: "UpdateTask with readonly auth", name: "UpdateTask with readonly auth",
auth: &influxdb.Authorization{Status: "active", Permissions: orgReadAllTaskPermissions}, auth: &influxdb.Authorization{Status: "active", Permissions: orgReadAllTaskPermissions},
check: func(ctx context.Context, svc influxdb.TaskService) error { check: func(ctx context.Context, svc taskmodel.TaskService) error {
flux := `option task = { flux := `option task = {
name: "my_task", name: "my_task",
every: 1s, every: 1s,
} }
from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")` from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
_, err := svc.UpdateTask(ctx, taskID, influxdb.TaskUpdate{ _, err := svc.UpdateTask(ctx, taskID, taskmodel.TaskUpdate{
Flux: &flux, Flux: &flux,
}) })
if err == nil { if err == nil {
@ -322,13 +323,13 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
{ {
name: "UpdateTask with org auth", name: "UpdateTask with org auth",
auth: &influxdb.Authorization{Status: "active", Permissions: orgWriteAllTaskBucketPermissions}, auth: &influxdb.Authorization{Status: "active", Permissions: orgWriteAllTaskBucketPermissions},
check: func(ctx context.Context, svc influxdb.TaskService) error { check: func(ctx context.Context, svc taskmodel.TaskService) error {
flux := `option task = { flux := `option task = {
name: "my_task", name: "my_task",
every: 1s, every: 1s,
} }
from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")` from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
_, err := svc.UpdateTask(ctx, taskID, influxdb.TaskUpdate{ _, err := svc.UpdateTask(ctx, taskID, taskmodel.TaskUpdate{
Flux: &flux, Flux: &flux,
}) })
return err return err
@ -337,13 +338,13 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
{ {
name: "UpdateTask with task auth", name: "UpdateTask with task auth",
auth: &influxdb.Authorization{Status: "active", Permissions: orgWriteTaskBucketPermissions}, auth: &influxdb.Authorization{Status: "active", Permissions: orgWriteTaskBucketPermissions},
check: func(ctx context.Context, svc influxdb.TaskService) error { check: func(ctx context.Context, svc taskmodel.TaskService) error {
flux := `option task = { flux := `option task = {
name: "my_task", name: "my_task",
every: 1s, every: 1s,
} }
from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")` from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
_, err := svc.UpdateTask(ctx, taskID, influxdb.TaskUpdate{ _, err := svc.UpdateTask(ctx, taskID, taskmodel.TaskUpdate{
Flux: &flux, Flux: &flux,
}) })
return err return err
@ -352,7 +353,7 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
{ {
name: "DeleteTask missing auth", name: "DeleteTask missing auth",
auth: &influxdb.Authorization{Permissions: []influxdb.Permission{}}, auth: &influxdb.Authorization{Permissions: []influxdb.Permission{}},
check: func(ctx context.Context, svc influxdb.TaskService) error { check: func(ctx context.Context, svc taskmodel.TaskService) error {
err := svc.DeleteTask(ctx, taskID) err := svc.DeleteTask(ctx, taskID)
if err == nil { if err == nil {
return errors.New("returned without error without permission") return errors.New("returned without error without permission")
@ -363,7 +364,7 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
{ {
name: "DeleteTask readonly auth", name: "DeleteTask readonly auth",
auth: &influxdb.Authorization{Permissions: orgReadAllTaskPermissions}, auth: &influxdb.Authorization{Permissions: orgReadAllTaskPermissions},
check: func(ctx context.Context, svc influxdb.TaskService) error { check: func(ctx context.Context, svc taskmodel.TaskService) error {
err := svc.DeleteTask(ctx, taskID) err := svc.DeleteTask(ctx, taskID)
if err == nil { if err == nil {
return errors.New("returned without error without permission") return errors.New("returned without error without permission")
@ -374,7 +375,7 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
{ {
name: "DeleteTask with org auth", name: "DeleteTask with org auth",
auth: &influxdb.Authorization{Status: "active", Permissions: orgWriteAllTaskPermissions}, auth: &influxdb.Authorization{Status: "active", Permissions: orgWriteAllTaskPermissions},
check: func(ctx context.Context, svc influxdb.TaskService) error { check: func(ctx context.Context, svc taskmodel.TaskService) error {
err := svc.DeleteTask(ctx, taskID) err := svc.DeleteTask(ctx, taskID)
return err return err
}, },
@ -382,7 +383,7 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
{ {
name: "DeleteTask with task auth", name: "DeleteTask with task auth",
auth: &influxdb.Authorization{Status: "active", Permissions: orgWriteTaskPermissions}, auth: &influxdb.Authorization{Status: "active", Permissions: orgWriteTaskPermissions},
check: func(ctx context.Context, svc influxdb.TaskService) error { check: func(ctx context.Context, svc taskmodel.TaskService) error {
err := svc.DeleteTask(ctx, taskID) err := svc.DeleteTask(ctx, taskID)
return err return err
}, },
@ -390,8 +391,8 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
{ {
name: "FindLogs with bad auth", name: "FindLogs with bad auth",
auth: &influxdb.Authorization{Status: "active", Permissions: wrongOrgReadAllTaskPermissions}, auth: &influxdb.Authorization{Status: "active", Permissions: wrongOrgReadAllTaskPermissions},
check: func(ctx context.Context, svc influxdb.TaskService) error { check: func(ctx context.Context, svc taskmodel.TaskService) error {
_, _, err := svc.FindLogs(ctx, influxdb.LogFilter{ _, _, err := svc.FindLogs(ctx, taskmodel.LogFilter{
Task: taskID, Task: taskID,
}) })
if err == nil { if err == nil {
@ -403,8 +404,8 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
{ {
name: "FindLogs with org auth", name: "FindLogs with org auth",
auth: &influxdb.Authorization{Status: "active", Permissions: orgReadAllTaskPermissions}, auth: &influxdb.Authorization{Status: "active", Permissions: orgReadAllTaskPermissions},
check: func(ctx context.Context, svc influxdb.TaskService) error { check: func(ctx context.Context, svc taskmodel.TaskService) error {
_, _, err := svc.FindLogs(ctx, influxdb.LogFilter{ _, _, err := svc.FindLogs(ctx, taskmodel.LogFilter{
Task: taskID, Task: taskID,
}) })
return err return err
@ -413,8 +414,8 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
{ {
name: "FindLogs with task auth", name: "FindLogs with task auth",
auth: &influxdb.Authorization{Status: "active", Permissions: orgReadTaskPermissions}, auth: &influxdb.Authorization{Status: "active", Permissions: orgReadTaskPermissions},
check: func(ctx context.Context, svc influxdb.TaskService) error { check: func(ctx context.Context, svc taskmodel.TaskService) error {
_, _, err := svc.FindLogs(ctx, influxdb.LogFilter{ _, _, err := svc.FindLogs(ctx, taskmodel.LogFilter{
Task: taskID, Task: taskID,
}) })
return err return err
@ -423,8 +424,8 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
{ {
name: "FindRuns with bad auth", name: "FindRuns with bad auth",
auth: &influxdb.Authorization{Status: "active", Permissions: wrongOrgReadAllTaskPermissions}, auth: &influxdb.Authorization{Status: "active", Permissions: wrongOrgReadAllTaskPermissions},
check: func(ctx context.Context, svc influxdb.TaskService) error { check: func(ctx context.Context, svc taskmodel.TaskService) error {
_, _, err := svc.FindRuns(ctx, influxdb.RunFilter{ _, _, err := svc.FindRuns(ctx, taskmodel.RunFilter{
Task: taskID, Task: taskID,
}) })
if err == nil { if err == nil {
@ -436,8 +437,8 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
{ {
name: "FindRuns with org auth", name: "FindRuns with org auth",
auth: &influxdb.Authorization{Status: "active", Permissions: orgReadAllTaskPermissions}, auth: &influxdb.Authorization{Status: "active", Permissions: orgReadAllTaskPermissions},
check: func(ctx context.Context, svc influxdb.TaskService) error { check: func(ctx context.Context, svc taskmodel.TaskService) error {
_, _, err := svc.FindRuns(ctx, influxdb.RunFilter{ _, _, err := svc.FindRuns(ctx, taskmodel.RunFilter{
Task: taskID, Task: taskID,
}) })
return err return err
@ -446,8 +447,8 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
{ {
name: "FindRuns with task auth", name: "FindRuns with task auth",
auth: &influxdb.Authorization{Status: "active", Permissions: orgReadTaskPermissions}, auth: &influxdb.Authorization{Status: "active", Permissions: orgReadTaskPermissions},
check: func(ctx context.Context, svc influxdb.TaskService) error { check: func(ctx context.Context, svc taskmodel.TaskService) error {
_, _, err := svc.FindRuns(ctx, influxdb.RunFilter{ _, _, err := svc.FindRuns(ctx, taskmodel.RunFilter{
Task: taskID, Task: taskID,
}) })
return err return err
@ -456,7 +457,7 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
{ {
name: "FindRunByID missing auth", name: "FindRunByID missing auth",
auth: &influxdb.Authorization{Permissions: []influxdb.Permission{}}, auth: &influxdb.Authorization{Permissions: []influxdb.Permission{}},
check: func(ctx context.Context, svc influxdb.TaskService) error { check: func(ctx context.Context, svc taskmodel.TaskService) error {
_, err := svc.FindRunByID(ctx, taskID, 10) _, err := svc.FindRunByID(ctx, taskID, 10)
if err == nil { if err == nil {
return errors.New("returned without error without permission") return errors.New("returned without error without permission")
@ -467,7 +468,7 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
{ {
name: "FindRunByID with org auth", name: "FindRunByID with org auth",
auth: &influxdb.Authorization{Status: "active", Permissions: orgReadAllTaskPermissions}, auth: &influxdb.Authorization{Status: "active", Permissions: orgReadAllTaskPermissions},
check: func(ctx context.Context, svc influxdb.TaskService) error { check: func(ctx context.Context, svc taskmodel.TaskService) error {
_, err := svc.FindRunByID(ctx, taskID, 10) _, err := svc.FindRunByID(ctx, taskID, 10)
return err return err
}, },
@ -475,7 +476,7 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
{ {
name: "FindRunByID with task auth", name: "FindRunByID with task auth",
auth: &influxdb.Authorization{Status: "active", Permissions: orgReadTaskPermissions}, auth: &influxdb.Authorization{Status: "active", Permissions: orgReadTaskPermissions},
check: func(ctx context.Context, svc influxdb.TaskService) error { check: func(ctx context.Context, svc taskmodel.TaskService) error {
_, err := svc.FindRunByID(ctx, taskID, 10) _, err := svc.FindRunByID(ctx, taskID, 10)
return err return err
}, },
@ -483,7 +484,7 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
{ {
name: "CancelRun with bad auth", name: "CancelRun with bad auth",
auth: &influxdb.Authorization{Status: "active", Permissions: wrongOrgReadAllTaskPermissions}, auth: &influxdb.Authorization{Status: "active", Permissions: wrongOrgReadAllTaskPermissions},
check: func(ctx context.Context, svc influxdb.TaskService) error { check: func(ctx context.Context, svc taskmodel.TaskService) error {
err := svc.CancelRun(ctx, taskID, 10) err := svc.CancelRun(ctx, taskID, 10)
if err == nil { if err == nil {
return errors.New("returned no error with a invalid auth") return errors.New("returned no error with a invalid auth")
@ -494,7 +495,7 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
{ {
name: "CancelRun with org auth", name: "CancelRun with org auth",
auth: &influxdb.Authorization{Status: "active", Permissions: orgWriteAllTaskPermissions}, auth: &influxdb.Authorization{Status: "active", Permissions: orgWriteAllTaskPermissions},
check: func(ctx context.Context, svc influxdb.TaskService) error { check: func(ctx context.Context, svc taskmodel.TaskService) error {
err := svc.CancelRun(ctx, taskID, 10) err := svc.CancelRun(ctx, taskID, 10)
return err return err
}, },
@ -502,7 +503,7 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
{ {
name: "CancelRun with task auth", name: "CancelRun with task auth",
auth: &influxdb.Authorization{Status: "active", Permissions: orgWriteTaskPermissions}, auth: &influxdb.Authorization{Status: "active", Permissions: orgWriteTaskPermissions},
check: func(ctx context.Context, svc influxdb.TaskService) error { check: func(ctx context.Context, svc taskmodel.TaskService) error {
err := svc.CancelRun(ctx, taskID, 10) err := svc.CancelRun(ctx, taskID, 10)
return err return err
}, },
@ -510,7 +511,7 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
{ {
name: "RetryRun with bad auth", name: "RetryRun with bad auth",
auth: &influxdb.Authorization{Status: "active", Permissions: wrongOrgReadAllTaskPermissions}, auth: &influxdb.Authorization{Status: "active", Permissions: wrongOrgReadAllTaskPermissions},
check: func(ctx context.Context, svc influxdb.TaskService) error { check: func(ctx context.Context, svc taskmodel.TaskService) error {
_, err := svc.RetryRun(ctx, taskID, 10) _, err := svc.RetryRun(ctx, taskID, 10)
if err == nil { if err == nil {
return errors.New("returned no error with a invalid auth") return errors.New("returned no error with a invalid auth")
@ -521,7 +522,7 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
{ {
name: "RetryRun with org auth", name: "RetryRun with org auth",
auth: &influxdb.Authorization{Status: "active", Permissions: orgWriteAllTaskPermissions}, auth: &influxdb.Authorization{Status: "active", Permissions: orgWriteAllTaskPermissions},
check: func(ctx context.Context, svc influxdb.TaskService) error { check: func(ctx context.Context, svc taskmodel.TaskService) error {
_, err := svc.RetryRun(ctx, taskID, 10) _, err := svc.RetryRun(ctx, taskID, 10)
return err return err
}, },
@ -529,7 +530,7 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
{ {
name: "RetryRun with task auth", name: "RetryRun with task auth",
auth: &influxdb.Authorization{Status: "active", Permissions: orgWriteTaskPermissions}, auth: &influxdb.Authorization{Status: "active", Permissions: orgWriteTaskPermissions},
check: func(ctx context.Context, svc influxdb.TaskService) error { check: func(ctx context.Context, svc taskmodel.TaskService) error {
_, err := svc.RetryRun(ctx, taskID, 10) _, err := svc.RetryRun(ctx, taskID, 10)
return err return err
}, },
@ -537,7 +538,7 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
{ {
name: "ForceRun with bad auth", name: "ForceRun with bad auth",
auth: &influxdb.Authorization{Status: "active", Permissions: wrongOrgReadAllTaskPermissions}, auth: &influxdb.Authorization{Status: "active", Permissions: wrongOrgReadAllTaskPermissions},
check: func(ctx context.Context, svc influxdb.TaskService) error { check: func(ctx context.Context, svc taskmodel.TaskService) error {
_, err := svc.ForceRun(ctx, taskID, 10000) _, err := svc.ForceRun(ctx, taskID, 10000)
if err == nil { if err == nil {
return errors.New("returned no error with a invalid auth") return errors.New("returned no error with a invalid auth")
@ -548,7 +549,7 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
{ {
name: "ForceRun with org auth", name: "ForceRun with org auth",
auth: &influxdb.Authorization{Status: "active", Permissions: orgWriteAllTaskPermissions}, auth: &influxdb.Authorization{Status: "active", Permissions: orgWriteAllTaskPermissions},
check: func(ctx context.Context, svc influxdb.TaskService) error { check: func(ctx context.Context, svc taskmodel.TaskService) error {
_, err := svc.ForceRun(ctx, taskID, 10000) _, err := svc.ForceRun(ctx, taskID, 10000)
return err return err
}, },
@ -556,7 +557,7 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
{ {
name: "ForceRun with task auth", name: "ForceRun with task auth",
auth: &influxdb.Authorization{Status: "active", Permissions: orgWriteTaskPermissions}, auth: &influxdb.Authorization{Status: "active", Permissions: orgWriteTaskPermissions},
check: func(ctx context.Context, svc influxdb.TaskService) error { check: func(ctx context.Context, svc taskmodel.TaskService) error {
_, err := svc.ForceRun(ctx, taskID, 10000) _, err := svc.ForceRun(ctx, taskID, 10000)
return err return err
}, },

View File

@ -6,6 +6,7 @@ import (
"github.com/influxdata/influxdb/v2/kit/platform" "github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/kit/platform/errors" "github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/influxdb/v2/query/fluxlang"
) )
// consts for checks config. // consts for checks config.
@ -16,14 +17,14 @@ const (
// Check represents the information required to generate a periodic check task. // Check represents the information required to generate a periodic check task.
type Check interface { type Check interface {
Valid(lang FluxLanguageService) error Valid(lang fluxlang.FluxLanguageService) error
Type() string Type() string
ClearPrivateData() ClearPrivateData()
SetTaskID(platform.ID) SetTaskID(platform.ID)
GetTaskID() platform.ID GetTaskID() platform.ID
GetOwnerID() platform.ID GetOwnerID() platform.ID
SetOwnerID(platform.ID) SetOwnerID(platform.ID)
GenerateFlux(lang FluxLanguageService) (string, error) GenerateFlux(lang fluxlang.FluxLanguageService) (string, error)
json.Marshaler json.Marshaler
CRUDLogSetter CRUDLogSetter

View File

@ -4,15 +4,15 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/platform" "github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/kit/platform/errors" "github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/tracing" "github.com/influxdata/influxdb/v2/kit/tracing"
"github.com/influxdata/influxdb/v2/kv" "github.com/influxdata/influxdb/v2/kv"
"github.com/influxdata/influxdb/v2/notification/check" "github.com/influxdata/influxdb/v2/notification/check"
"github.com/influxdata/influxdb/v2/query/fluxlang" "github.com/influxdata/influxdb/v2/query/fluxlang"
"github.com/influxdata/influxdb/v2/snowflake" "github.com/influxdata/influxdb/v2/snowflake"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -26,7 +26,7 @@ type Service struct {
log *zap.Logger log *zap.Logger
orgs influxdb.OrganizationService orgs influxdb.OrganizationService
tasks influxdb.TaskService tasks taskmodel.TaskService
timeGenerator influxdb.TimeGenerator timeGenerator influxdb.TimeGenerator
idGenerator platform.IDGenerator idGenerator platform.IDGenerator
@ -35,7 +35,7 @@ type Service struct {
} }
// NewService constructs and configures a new checks.Service // NewService constructs and configures a new checks.Service
func NewService(logger *zap.Logger, store kv.Store, orgs influxdb.OrganizationService, tasks influxdb.TaskService) *Service { func NewService(logger *zap.Logger, store kv.Store, orgs influxdb.OrganizationService, tasks taskmodel.TaskService) *Service {
return &Service{ return &Service{
kv: store, kv: store,
log: logger, log: logger,
@ -330,7 +330,7 @@ func (s *Service) CreateCheck(ctx context.Context, c influxdb.CheckCreate, userI
// update task to be in matching state to check // update task to be in matching state to check
if influxdb.Status(t.Status) != c.Status { if influxdb.Status(t.Status) != c.Status {
_, err = s.tasks.UpdateTask(ctx, t.ID, influxdb.TaskUpdate{ _, err = s.tasks.UpdateTask(ctx, t.ID, taskmodel.TaskUpdate{
Status: strPtr(string(c.Status)), Status: strPtr(string(c.Status)),
}) })
} }
@ -338,13 +338,13 @@ func (s *Service) CreateCheck(ctx context.Context, c influxdb.CheckCreate, userI
return err return err
} }
func (s *Service) createCheckTask(ctx context.Context, c influxdb.CheckCreate) (*influxdb.Task, error) { func (s *Service) createCheckTask(ctx context.Context, c influxdb.CheckCreate) (*taskmodel.Task, error) {
script, err := c.GenerateFlux(fluxlang.DefaultService) script, err := c.GenerateFlux(fluxlang.DefaultService)
if err != nil { if err != nil {
return nil, err return nil, err
} }
tc := influxdb.TaskCreate{ tc := taskmodel.TaskCreate{
Type: c.Type(), Type: c.Type(),
Flux: script, Flux: script,
OwnerID: c.GetOwnerID(), OwnerID: c.GetOwnerID(),
@ -440,7 +440,7 @@ func (s *Service) updateCheckTask(ctx context.Context, chk influxdb.CheckCreate)
return err return err
} }
tu := influxdb.TaskUpdate{ tu := taskmodel.TaskUpdate{
Flux: &flux, Flux: &flux,
Description: strPtr(chk.GetDescription()), Description: strPtr(chk.GetDescription()),
} }
@ -457,7 +457,7 @@ func (s *Service) updateCheckTask(ctx context.Context, chk influxdb.CheckCreate)
} }
func (s *Service) patchCheckTask(ctx context.Context, taskID platform.ID, upd influxdb.CheckUpdate) error { func (s *Service) patchCheckTask(ctx context.Context, taskID platform.ID, upd influxdb.CheckUpdate) error {
tu := influxdb.TaskUpdate{ tu := taskmodel.TaskUpdate{
Description: upd.Description, Description: upd.Description,
} }

View File

@ -8,16 +8,16 @@ import (
"testing" "testing"
"time" "time"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts" "github.com/google/go-cmp/cmp/cmpopts"
"github.com/influxdata/flux/ast" "github.com/influxdata/flux/ast"
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/influxdb/v2/mock" "github.com/influxdata/influxdb/v2/mock"
"github.com/influxdata/influxdb/v2/notification" "github.com/influxdata/influxdb/v2/notification"
"github.com/influxdata/influxdb/v2/notification/check" "github.com/influxdata/influxdb/v2/notification/check"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -160,14 +160,14 @@ var taskCmpOptions = cmp.Options{
}), }),
// skip comparing permissions // skip comparing permissions
cmpopts.IgnoreFields( cmpopts.IgnoreFields(
influxdb.Task{}, taskmodel.Task{},
"LatestCompleted", "LatestCompleted",
"LatestScheduled", "LatestScheduled",
"CreatedAt", "CreatedAt",
"UpdatedAt", "UpdatedAt",
), ),
cmp.Transformer("Sort", func(in []*influxdb.Task) []*influxdb.Task { cmp.Transformer("Sort", func(in []*taskmodel.Task) []*taskmodel.Task {
out := append([]*influxdb.Task{}, in...) // Copy input to avoid mutating it out := append([]*taskmodel.Task{}, in...) // Copy input to avoid mutating it
sort.Slice(out, func(i, j int) bool { sort.Slice(out, func(i, j int) bool {
return out[i].ID > out[j].ID return out[i].ID > out[j].ID
}) })
@ -179,13 +179,13 @@ var taskCmpOptions = cmp.Options{
type CheckFields struct { type CheckFields struct {
IDGenerator platform.IDGenerator IDGenerator platform.IDGenerator
TimeGenerator influxdb.TimeGenerator TimeGenerator influxdb.TimeGenerator
TaskService influxdb.TaskService TaskService taskmodel.TaskService
Checks []influxdb.Check Checks []influxdb.Check
Organizations []*influxdb.Organization Organizations []*influxdb.Organization
Tasks []influxdb.TaskCreate Tasks []taskmodel.TaskCreate
} }
type checkServiceFactory func(CheckFields, *testing.T) (influxdb.CheckService, influxdb.TaskService, string, func()) type checkServiceFactory func(CheckFields, *testing.T) (influxdb.CheckService, taskmodel.TaskService, string, func())
type checkServiceF func( type checkServiceF func(
init checkServiceFactory, init checkServiceFactory,
@ -249,7 +249,7 @@ func CreateCheck(
type wants struct { type wants struct {
err *errors.Error err *errors.Error
checks []influxdb.Check checks []influxdb.Check
tasks []*influxdb.Task tasks []*taskmodel.Task
} }
tests := []struct { tests := []struct {
@ -308,7 +308,7 @@ func CreateCheck(
}, },
}, },
wants: wants{ wants: wants{
tasks: []*influxdb.Task{ tasks: []*taskmodel.Task{
{ {
ID: MustIDBase16("020f755c3c082000"), ID: MustIDBase16("020f755c3c082000"),
Name: "name1", Name: "name1",
@ -437,7 +437,7 @@ func CreateCheck(
deadman1, deadman1,
threshold1, threshold1,
}, },
tasks: []*influxdb.Task{ tasks: []*taskmodel.Task{
{ {
ID: MustIDBase16("020f755c3c082001"), ID: MustIDBase16("020f755c3c082001"),
Name: "name2", Name: "name2",
@ -574,7 +574,7 @@ func CreateCheck(
}, },
}, },
wants: wants{ wants: wants{
tasks: []*influxdb.Task{ tasks: []*taskmodel.Task{
{ {
ID: MustIDBase16("020f755c3c082001"), ID: MustIDBase16("020f755c3c082001"),
Name: "name1", Name: "name1",
@ -701,7 +701,7 @@ func CreateCheck(
t.Errorf("checks are different -got/+want\ndiff %s", diff) t.Errorf("checks are different -got/+want\ndiff %s", diff)
} }
foundTasks, _, err := tasks.FindTasks(ctx, influxdb.TaskFilter{}) foundTasks, _, err := tasks.FindTasks(ctx, taskmodel.TaskFilter{})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -1060,7 +1060,7 @@ func DeleteCheck(
ID: MustIDBase16(orgOneID), ID: MustIDBase16(orgOneID),
}, },
}, },
Tasks: []influxdb.TaskCreate{ Tasks: []taskmodel.TaskCreate{
{ {
Flux: `option task = { every: 10s, name: "foo" } Flux: `option task = { every: 10s, name: "foo" }
data = from(bucket: "telegraf") |> range(start: -1m)`, data = from(bucket: "telegraf") |> range(start: -1m)`,
@ -1093,7 +1093,7 @@ data = from(bucket: "telegraf") |> range(start: -1m)`,
ID: MustIDBase16(orgOneID), ID: MustIDBase16(orgOneID),
}, },
}, },
Tasks: []influxdb.TaskCreate{ Tasks: []taskmodel.TaskCreate{
{ {
Flux: `option task = { every: 10s, name: "foo" } Flux: `option task = { every: 10s, name: "foo" }
data = from(bucket: "telegraf") |> range(start: -1m)`, data = from(bucket: "telegraf") |> range(start: -1m)`,
@ -1293,7 +1293,7 @@ func UpdateCheck(
ID: MustIDBase16(orgOneID), ID: MustIDBase16(orgOneID),
}, },
}, },
Tasks: []influxdb.TaskCreate{ Tasks: []taskmodel.TaskCreate{
{ {
Flux: `option task = { every: 10s, name: "foo" } Flux: `option task = { every: 10s, name: "foo" }
data = from(bucket: "telegraf") |> range(start: -1m)`, data = from(bucket: "telegraf") |> range(start: -1m)`,
@ -1551,7 +1551,7 @@ func PatchCheck(
fields: CheckFields{ fields: CheckFields{
IDGenerator: mock.NewIDGenerator("0000000000000001", t), IDGenerator: mock.NewIDGenerator("0000000000000001", t),
TimeGenerator: mock.TimeGenerator{FakeValue: time.Date(2007, 5, 4, 1, 2, 3, 0, time.UTC)}, TimeGenerator: mock.TimeGenerator{FakeValue: time.Date(2007, 5, 4, 1, 2, 3, 0, time.UTC)},
Tasks: []influxdb.TaskCreate{ Tasks: []taskmodel.TaskCreate{
{ {
Flux: `option task = { every: 10s, name: "foo" } Flux: `option task = { every: 10s, name: "foo" }
data = from(bucket: "telegraf") |> range(start: -1m)`, data = from(bucket: "telegraf") |> range(start: -1m)`,

View File

@ -11,6 +11,7 @@ import (
"github.com/influxdata/influxdb/v2/kv/migration/all" "github.com/influxdata/influxdb/v2/kv/migration/all"
"github.com/influxdata/influxdb/v2/mock" "github.com/influxdata/influxdb/v2/mock"
"github.com/influxdata/influxdb/v2/query/fluxlang" "github.com/influxdata/influxdb/v2/query/fluxlang"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"github.com/influxdata/influxdb/v2/tenant" "github.com/influxdata/influxdb/v2/tenant"
"go.uber.org/zap/zaptest" "go.uber.org/zap/zaptest"
) )
@ -31,7 +32,7 @@ func TestCheckService(t *testing.T) {
CheckService(initCheckService, t) CheckService(initCheckService, t)
} }
func initCheckService(f CheckFields, t *testing.T) (influxdb.CheckService, influxdb.TaskService, string, func()) { func initCheckService(f CheckFields, t *testing.T) (influxdb.CheckService, taskmodel.TaskService, string, func()) {
store, closeKVStore := NewKVTestStore(t) store, closeKVStore := NewKVTestStore(t)
logger := zaptest.NewLogger(t) logger := zaptest.NewLogger(t)

View File

@ -5,17 +5,17 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/http" "github.com/influxdata/influxdb/v2/http"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"github.com/influxdata/influxdb/v2/tenant" "github.com/influxdata/influxdb/v2/tenant"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
type taskSVCsFn func() (influxdb.TaskService, influxdb.OrganizationService, error) type taskSVCsFn func() (taskmodel.TaskService, influxdb.OrganizationService, error)
func newTaskSVCs() (influxdb.TaskService, influxdb.OrganizationService, error) { func newTaskSVCs() (taskmodel.TaskService, influxdb.OrganizationService, error) {
httpClient, err := newHTTPClient() httpClient, err := newHTTPClient()
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@ -116,7 +116,7 @@ func (b *cmdTaskBuilder) taskCreateF(_ *cobra.Command, args []string) error {
return fmt.Errorf("error parsing flux script: %s", err) return fmt.Errorf("error parsing flux script: %s", err)
} }
tc := influxdb.TaskCreate{ tc := taskmodel.TaskCreate{
Flux: flux, Flux: flux,
Organization: b.org.name, Organization: b.org.name,
} }
@ -152,7 +152,7 @@ func (b *cmdTaskBuilder) taskFindCmd() *cobra.Command {
registerPrintOptions(b.opts.viper, cmd, &b.taskPrintFlags.hideHeaders, &b.taskPrintFlags.json) registerPrintOptions(b.opts.viper, cmd, &b.taskPrintFlags.hideHeaders, &b.taskPrintFlags.json)
cmd.Flags().StringVarP(&b.taskID, "id", "i", "", "task ID") cmd.Flags().StringVarP(&b.taskID, "id", "i", "", "task ID")
cmd.Flags().StringVarP(&b.taskFindFlags.user, "user-id", "n", "", "task owner ID") cmd.Flags().StringVarP(&b.taskFindFlags.user, "user-id", "n", "", "task owner ID")
cmd.Flags().IntVarP(&b.taskFindFlags.limit, "limit", "", influxdb.TaskDefaultPageSize, "the number of tasks to find") cmd.Flags().IntVarP(&b.taskFindFlags.limit, "limit", "", taskmodel.TaskDefaultPageSize, "the number of tasks to find")
cmd.Flags().BoolVar(&b.taskFindFlags.headers, "headers", true, "To print the table headers; defaults true") cmd.Flags().BoolVar(&b.taskFindFlags.headers, "headers", true, "To print the table headers; defaults true")
return cmd return cmd
@ -169,7 +169,7 @@ func (b *cmdTaskBuilder) taskFindF(cmd *cobra.Command, args []string) error {
return err return err
} }
filter := influxdb.TaskFilter{} filter := taskmodel.TaskFilter{}
if b.taskFindFlags.user != "" { if b.taskFindFlags.user != "" {
id, err := platform.IDFromString(b.taskFindFlags.user) id, err := platform.IDFromString(b.taskFindFlags.user)
if err != nil { if err != nil {
@ -189,12 +189,12 @@ func (b *cmdTaskBuilder) taskFindF(cmd *cobra.Command, args []string) error {
filter.OrganizationID = id filter.OrganizationID = id
} }
if b.taskFindFlags.limit < 1 || b.taskFindFlags.limit > influxdb.TaskMaxPageSize { if b.taskFindFlags.limit < 1 || b.taskFindFlags.limit > taskmodel.TaskMaxPageSize {
return fmt.Errorf("limit must be between 1 and %d", influxdb.TaskMaxPageSize) return fmt.Errorf("limit must be between 1 and %d", taskmodel.TaskMaxPageSize)
} }
filter.Limit = b.taskFindFlags.limit filter.Limit = b.taskFindFlags.limit
var tasks []*influxdb.Task var tasks []*taskmodel.Task
if b.taskID != "" { if b.taskID != "" {
id, err := platform.IDFromString(b.taskID) id, err := platform.IDFromString(b.taskID)
@ -262,7 +262,7 @@ func (b *cmdTaskBuilder) taskRetryFailedF(*cobra.Command, []string) error {
return err return err
} }
var failedRuns []*influxdb.Run var failedRuns []*taskmodel.Run
if b.taskID == "" { if b.taskID == "" {
failedRuns, err = b.getFailedRunsForOrg(b.taskRerunFailedFlags.taskLimit, b.taskRerunFailedFlags.runLimit) failedRuns, err = b.getFailedRunsForOrg(b.taskRerunFailedFlags.taskLimit, b.taskRerunFailedFlags.runLimit)
} else { } else {
@ -295,13 +295,13 @@ func (b *cmdTaskBuilder) taskRetryFailedF(*cobra.Command, []string) error {
return nil return nil
} }
func (b *cmdTaskBuilder) getFailedRunsForTaskID(limit int) ([]*influxdb.Run, error) { func (b *cmdTaskBuilder) getFailedRunsForTaskID(limit int) ([]*taskmodel.Run, error) {
// use RunFilter to search for failed runs // use RunFilter to search for failed runs
tskSvc, _, err := b.svcFn() tskSvc, _, err := b.svcFn()
if err != nil { if err != nil {
return nil, err return nil, err
} }
runFilter := influxdb.RunFilter{Limit: limit} runFilter := taskmodel.RunFilter{Limit: limit}
id, err := platform.IDFromString(b.taskID) id, err := platform.IDFromString(b.taskID)
if err != nil { if err != nil {
return nil, err return nil, err
@ -313,7 +313,7 @@ func (b *cmdTaskBuilder) getFailedRunsForTaskID(limit int) ([]*influxdb.Run, err
if err != nil { if err != nil {
return nil, err return nil, err
} }
var allFailedRuns []*influxdb.Run var allFailedRuns []*taskmodel.Run
for _, run := range allRuns { for _, run := range allRuns {
if run.Status == "failed" { if run.Status == "failed" {
allFailedRuns = append(allFailedRuns, run) allFailedRuns = append(allFailedRuns, run)
@ -323,10 +323,10 @@ func (b *cmdTaskBuilder) getFailedRunsForTaskID(limit int) ([]*influxdb.Run, err
} }
func (b *cmdTaskBuilder) getFailedRunsForOrg(taskLimit int, runLimit int) ([]*influxdb.Run, error) { func (b *cmdTaskBuilder) getFailedRunsForOrg(taskLimit int, runLimit int) ([]*taskmodel.Run, error) {
// use TaskFilter to get all Tasks in org then search for failed runs in each task // use TaskFilter to get all Tasks in org then search for failed runs in each task
taskFilter := influxdb.TaskFilter{Limit: taskLimit} taskFilter := taskmodel.TaskFilter{Limit: taskLimit}
runFilter := influxdb.RunFilter{Limit: runLimit} runFilter := taskmodel.RunFilter{Limit: runLimit}
runFilter.BeforeTime = b.taskRerunFailedFlags.before runFilter.BeforeTime = b.taskRerunFailedFlags.before
runFilter.AfterTime = b.taskRerunFailedFlags.after runFilter.AfterTime = b.taskRerunFailedFlags.after
tskSvc, _, err := b.svcFn() tskSvc, _, err := b.svcFn()
@ -350,11 +350,11 @@ func (b *cmdTaskBuilder) getFailedRunsForOrg(taskLimit int, runLimit int) ([]*in
return nil, err return nil, err
} }
var allFailedRuns []*influxdb.Run var allFailedRuns []*taskmodel.Run
for _, t := range allTasks { for _, t := range allTasks {
runFilter.Task = t.ID runFilter.Task = t.ID
runsPerTask, _, err := tskSvc.FindRuns(context.Background(), runFilter) runsPerTask, _, err := tskSvc.FindRuns(context.Background(), runFilter)
var failedRunsPerTask []*influxdb.Run var failedRunsPerTask []*taskmodel.Run
for _, r := range runsPerTask { for _, r := range runsPerTask {
if r.Status == "failed" { if r.Status == "failed" {
failedRunsPerTask = append(failedRunsPerTask, r) failedRunsPerTask = append(failedRunsPerTask, r)
@ -399,7 +399,7 @@ func (b *cmdTaskBuilder) taskUpdateF(cmd *cobra.Command, args []string) error {
return err return err
} }
var update influxdb.TaskUpdate var update taskmodel.TaskUpdate
if b.taskUpdateFlags.status != "" { if b.taskUpdateFlags.status != "" {
update.Status = &b.taskUpdateFlags.status update.Status = &b.taskUpdateFlags.status
} }
@ -460,8 +460,8 @@ func (b *cmdTaskBuilder) taskDeleteF(cmd *cobra.Command, args []string) error {
} }
type taskPrintOpts struct { type taskPrintOpts struct {
task *influxdb.Task task *taskmodel.Task
tasks []*influxdb.Task tasks []*taskmodel.Task
} }
func (b *cmdTaskBuilder) printTasks(printOpts taskPrintOpts) error { func (b *cmdTaskBuilder) printTasks(printOpts taskPrintOpts) error {
@ -537,7 +537,7 @@ func (b *cmdTaskBuilder) taskLogFindF(cmd *cobra.Command, args []string) error {
return err return err
} }
var filter influxdb.LogFilter var filter taskmodel.LogFilter
id, err := platform.IDFromString(b.taskID) id, err := platform.IDFromString(b.taskID)
if err != nil { if err != nil {
return err return err
@ -621,7 +621,7 @@ func (b *cmdTaskBuilder) taskRunFindF(cmd *cobra.Command, args []string) error {
return err return err
} }
filter := influxdb.RunFilter{ filter := taskmodel.RunFilter{
Limit: b.taskRunFindFlags.limit, Limit: b.taskRunFindFlags.limit,
AfterTime: b.taskRunFindFlags.afterTime, AfterTime: b.taskRunFindFlags.afterTime,
BeforeTime: b.taskRunFindFlags.beforeTime, BeforeTime: b.taskRunFindFlags.beforeTime,
@ -632,7 +632,7 @@ func (b *cmdTaskBuilder) taskRunFindF(cmd *cobra.Command, args []string) error {
} }
filter.Task = *taskID filter.Task = *taskID
var runs []*influxdb.Run var runs []*taskmodel.Run
if b.runID != "" { if b.runID != "" {
id, err := platform.IDFromString(b.runID) id, err := platform.IDFromString(b.runID)
if err != nil { if err != nil {
@ -653,7 +653,7 @@ func (b *cmdTaskBuilder) taskRunFindF(cmd *cobra.Command, args []string) error {
if b.taskPrintFlags.json { if b.taskPrintFlags.json {
if runs == nil { if runs == nil {
// guarantee we never return a null value from CLI // guarantee we never return a null value from CLI
runs = make([]*influxdb.Run, 0) runs = make([]*taskmodel.Run, 0)
} }
return b.opts.writeJSON(runs) return b.opts.writeJSON(runs)
} }

View File

@ -7,11 +7,11 @@ import (
"io/ioutil" "io/ioutil"
"testing" "testing"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/mock" "github.com/influxdata/influxdb/v2/mock"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -21,8 +21,8 @@ import (
func TestCmdTask(t *testing.T) { func TestCmdTask(t *testing.T) {
orgID := platform.ID(9000) orgID := platform.ID(9000)
fakeSVCFn := func(svc influxdb.TaskService) taskSVCsFn { fakeSVCFn := func(svc taskmodel.TaskService) taskSVCsFn {
return func() (influxdb.TaskService, influxdb.OrganizationService, error) { return func() (taskmodel.TaskService, influxdb.OrganizationService, error) {
return svc, &mock.OrganizationService{ return svc, &mock.OrganizationService{
FindOrganizationF: func(ctx context.Context, filter influxdb.OrganizationFilter) (*influxdb.Organization, error) { FindOrganizationF: func(ctx context.Context, filter influxdb.OrganizationFilter) (*influxdb.Organization, error) {
return &influxdb.Organization{ID: orgID, Name: "influxdata"}, nil return &influxdb.Organization{ID: orgID, Name: "influxdata"}, nil
@ -36,7 +36,7 @@ func TestCmdTask(t *testing.T) {
// todo: add more test cases // todo: add more test cases
tests := []struct { tests := []struct {
name string name string
expectedTask influxdb.Task expectedTask taskmodel.Task
flags []string flags []string
envVars map[string]string envVars map[string]string
}{ }{
@ -45,17 +45,17 @@ func TestCmdTask(t *testing.T) {
flags: []string{ flags: []string{
"--org=influxdata", "--org=influxdata",
}, },
expectedTask: influxdb.Task{ expectedTask: taskmodel.Task{
OrganizationID: 9000, OrganizationID: 9000,
Organization: "influxdata", Organization: "influxdata",
}, },
}, },
} }
cmdFn := func(expectedTsk influxdb.Task) func(*globalFlags, genericCLIOpts) *cobra.Command { cmdFn := func(expectedTsk taskmodel.Task) func(*globalFlags, genericCLIOpts) *cobra.Command {
svc := mock.NewTaskService() svc := mock.NewTaskService()
svc.CreateTaskFn = func(ctx context.Context, task influxdb.TaskCreate) (*influxdb.Task, error) { svc.CreateTaskFn = func(ctx context.Context, task taskmodel.TaskCreate) (*taskmodel.Task, error) {
tmpTsk := influxdb.Task{ tmpTsk := taskmodel.Task{
Type: task.Type, Type: task.Type,
OrganizationID: task.OrganizationID, OrganizationID: task.OrganizationID,
Organization: task.Organization, Organization: task.Organization,

View File

@ -14,8 +14,6 @@ import (
"sync" "sync"
"time" "time"
platform2 "github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/flux" "github.com/influxdata/flux"
"github.com/influxdata/flux/dependencies/testing" "github.com/influxdata/flux/dependencies/testing"
platform "github.com/influxdata/influxdb/v2" platform "github.com/influxdata/influxdb/v2"
@ -36,6 +34,7 @@ import (
"github.com/influxdata/influxdb/v2/kit/feature" "github.com/influxdata/influxdb/v2/kit/feature"
overrideflagger "github.com/influxdata/influxdb/v2/kit/feature/override" overrideflagger "github.com/influxdata/influxdb/v2/kit/feature/override"
"github.com/influxdata/influxdb/v2/kit/metric" "github.com/influxdata/influxdb/v2/kit/metric"
platform2 "github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/kit/prom" "github.com/influxdata/influxdb/v2/kit/prom"
"github.com/influxdata/influxdb/v2/kit/tracing" "github.com/influxdata/influxdb/v2/kit/tracing"
kithttp "github.com/influxdata/influxdb/v2/kit/transport/http" kithttp "github.com/influxdata/influxdb/v2/kit/transport/http"
@ -64,11 +63,16 @@ import (
"github.com/influxdata/influxdb/v2/task/backend/executor" "github.com/influxdata/influxdb/v2/task/backend/executor"
"github.com/influxdata/influxdb/v2/task/backend/middleware" "github.com/influxdata/influxdb/v2/task/backend/middleware"
"github.com/influxdata/influxdb/v2/task/backend/scheduler" "github.com/influxdata/influxdb/v2/task/backend/scheduler"
"github.com/influxdata/influxdb/v2/task/taskmodel"
telegrafservice "github.com/influxdata/influxdb/v2/telegraf/service" telegrafservice "github.com/influxdata/influxdb/v2/telegraf/service"
"github.com/influxdata/influxdb/v2/telemetry" "github.com/influxdata/influxdb/v2/telemetry"
"github.com/influxdata/influxdb/v2/tenant" "github.com/influxdata/influxdb/v2/tenant"
_ "github.com/influxdata/influxdb/v2/tsdb/engine/tsm1" // needed for tsm1
_ "github.com/influxdata/influxdb/v2/tsdb/index/tsi1" // needed for tsi1 // needed for tsm1
_ "github.com/influxdata/influxdb/v2/tsdb/engine/tsm1"
// needed for tsi1
_ "github.com/influxdata/influxdb/v2/tsdb/index/tsi1"
authv1 "github.com/influxdata/influxdb/v2/v1/authorization" authv1 "github.com/influxdata/influxdb/v2/v1/authorization"
iqlcoordinator "github.com/influxdata/influxdb/v2/v1/coordinator" iqlcoordinator "github.com/influxdata/influxdb/v2/v1/coordinator"
"github.com/influxdata/influxdb/v2/v1/services/meta" "github.com/influxdata/influxdb/v2/v1/services/meta"
@ -445,7 +449,7 @@ func (m *Launcher) run(ctx context.Context, opts *InfluxdOpts) (err error) {
m.reg.MustRegister(m.queryController.PrometheusCollectors()...) m.reg.MustRegister(m.queryController.PrometheusCollectors()...)
var storageQueryService = readservice.NewProxyQueryService(m.queryController) var storageQueryService = readservice.NewProxyQueryService(m.queryController)
var taskSvc platform.TaskService var taskSvc taskmodel.TaskService
{ {
// create the task stack // create the task stack
combinedTaskService := taskbackend.NewAnalyticalStorage( combinedTaskService := taskbackend.NewAnalyticalStorage(
@ -1137,7 +1141,7 @@ func (m *Launcher) SecretService() platform.SecretService {
} }
// TaskService returns the internal task service. // TaskService returns the internal task service.
func (m *Launcher) TaskService() platform.TaskService { func (m *Launcher) TaskService() taskmodel.TaskService {
return m.apibackend.TaskService return m.apibackend.TaskService
} }

View File

@ -28,6 +28,7 @@ import (
"github.com/influxdata/influxdb/v2/pkger" "github.com/influxdata/influxdb/v2/pkger"
"github.com/influxdata/influxdb/v2/query" "github.com/influxdata/influxdb/v2/query"
"github.com/influxdata/influxdb/v2/restore" "github.com/influxdata/influxdb/v2/restore"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"github.com/influxdata/influxdb/v2/tenant" "github.com/influxdata/influxdb/v2/tenant"
dto "github.com/prometheus/client_model/go" dto "github.com/prometheus/client_model/go"
"github.com/prometheus/common/expfmt" "github.com/prometheus/common/expfmt"
@ -448,7 +449,7 @@ func (tl *TestLauncher) PkgerService(tb testing.TB) pkger.SVC {
return &pkger.HTTPRemoteService{Client: tl.HTTPClient(tb)} return &pkger.HTTPRemoteService{Client: tl.HTTPClient(tb)}
} }
func (tl *TestLauncher) TaskServiceKV(tb testing.TB) influxdb.TaskService { func (tl *TestLauncher) TaskServiceKV(tb testing.TB) taskmodel.TaskService {
return tl.kvService return tl.kvService
} }
@ -467,7 +468,7 @@ func (tl *TestLauncher) AuthorizationService(tb testing.TB) *http.AuthorizationS
return &http.AuthorizationService{Client: tl.HTTPClient(tb)} return &http.AuthorizationService{Client: tl.HTTPClient(tb)}
} }
func (tl *TestLauncher) TaskService(tb testing.TB) influxdb.TaskService { func (tl *TestLauncher) TaskService(tb testing.TB) taskmodel.TaskService {
tb.Helper() tb.Helper()
return &http.TaskService{Client: tl.HTTPClient(tb)} return &http.TaskService{Client: tl.HTTPClient(tb)}
} }

View File

@ -12,16 +12,16 @@ import (
"testing" "testing"
"time" "time"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/platform" "github.com/influxdata/influxdb/v2/kit/platform"
errors2 "github.com/influxdata/influxdb/v2/kit/platform/errors" errors2 "github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/mock" "github.com/influxdata/influxdb/v2/mock"
"github.com/influxdata/influxdb/v2/notification" "github.com/influxdata/influxdb/v2/notification"
"github.com/influxdata/influxdb/v2/notification/check" "github.com/influxdata/influxdb/v2/notification/check"
"github.com/influxdata/influxdb/v2/notification/endpoint" "github.com/influxdata/influxdb/v2/notification/endpoint"
"github.com/influxdata/influxdb/v2/notification/rule" "github.com/influxdata/influxdb/v2/notification/rule"
"github.com/influxdata/influxdb/v2/pkger" "github.com/influxdata/influxdb/v2/pkger"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"go.uber.org/zap" "go.uber.org/zap"
@ -220,7 +220,7 @@ func TestLauncher_Pkger(t *testing.T) {
} }
newTaskObject := func(pkgName, name, description string) pkger.Object { newTaskObject := func(pkgName, name, description string) pkger.Object {
obj := pkger.TaskToObject("", influxdb.Task{ obj := pkger.TaskToObject("", taskmodel.Task{
Name: name, Name: name,
Description: description, Description: description,
Flux: "buckets()", Flux: "buckets()",
@ -2359,7 +2359,7 @@ func TestLauncher_Pkger(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
assert.Empty(t, rules) assert.Empty(t, rules)
tasks, _, err := l.TaskServiceKV(t).FindTasks(ctx, influxdb.TaskFilter{ tasks, _, err := l.TaskServiceKV(t).FindTasks(ctx, taskmodel.TaskFilter{
OrganizationID: &l.Org.ID, OrganizationID: &l.Org.ID,
}) })
require.NoError(t, err) require.NoError(t, err)
@ -2948,7 +2948,7 @@ spec:
assert.NotZero(t, endpoints[0].NotificationEndpoint.GetID()) assert.NotZero(t, endpoints[0].NotificationEndpoint.GetID())
assert.Equal(t, "no auth endpoint", endpoints[0].NotificationEndpoint.GetName()) assert.Equal(t, "no auth endpoint", endpoints[0].NotificationEndpoint.GetName())
assert.Equal(t, "http none auth desc", endpoints[0].NotificationEndpoint.GetDescription()) assert.Equal(t, "http none auth desc", endpoints[0].NotificationEndpoint.GetDescription())
assert.Equal(t, influxdb.TaskStatusInactive, string(endpoints[0].NotificationEndpoint.GetStatus())) assert.Equal(t, taskmodel.TaskStatusInactive, string(endpoints[0].NotificationEndpoint.GetStatus()))
hasLabelAssociations(t, endpoints[0].LabelAssociations, 1, "label-1") hasLabelAssociations(t, endpoints[0].LabelAssociations, 1, "label-1")
require.Len(t, sum1.NotificationRules, 1) require.Len(t, sum1.NotificationRules, 1)
@ -3080,7 +3080,7 @@ spec:
require.Len(t, endpoints, 1) require.Len(t, endpoints, 1)
assert.Equal(t, "no auth endpoint", endpoints[0].NotificationEndpoint.GetName()) assert.Equal(t, "no auth endpoint", endpoints[0].NotificationEndpoint.GetName())
assert.Equal(t, "http none auth desc", endpoints[0].NotificationEndpoint.GetDescription()) assert.Equal(t, "http none auth desc", endpoints[0].NotificationEndpoint.GetDescription())
assert.Equal(t, influxdb.TaskStatusInactive, string(endpoints[0].NotificationEndpoint.GetStatus())) assert.Equal(t, taskmodel.TaskStatusInactive, string(endpoints[0].NotificationEndpoint.GetStatus()))
hasLabelAssociations(t, endpoints[0].LabelAssociations, 1, "label-1") hasLabelAssociations(t, endpoints[0].LabelAssociations, 1, "label-1")
require.Len(t, sum.NotificationRules, 1) require.Len(t, sum.NotificationRules, 1)
@ -4944,23 +4944,23 @@ func (r resourceChecker) mustDeleteRule(t *testing.T, id platform.ID) {
require.NoError(t, r.tl.NotificationRuleService(t).DeleteNotificationRule(ctx, id)) require.NoError(t, r.tl.NotificationRuleService(t).DeleteNotificationRule(ctx, id))
} }
func (r resourceChecker) getTask(t *testing.T, getOpt getResourceOptFn) (influxdb.Task, error) { func (r resourceChecker) getTask(t *testing.T, getOpt getResourceOptFn) (taskmodel.Task, error) {
t.Helper() t.Helper()
taskSVC := r.tl.TaskService(t) taskSVC := r.tl.TaskService(t)
var ( var (
task *influxdb.Task task *taskmodel.Task
err error err error
) )
switch opt := getOpt(); { switch opt := getOpt(); {
case opt.name != "": case opt.name != "":
tasks, _, err := taskSVC.FindTasks(ctx, influxdb.TaskFilter{ tasks, _, err := taskSVC.FindTasks(ctx, taskmodel.TaskFilter{
Name: &opt.name, Name: &opt.name,
OrganizationID: &r.tl.Org.ID, OrganizationID: &r.tl.Org.ID,
}) })
if err != nil { if err != nil {
return influxdb.Task{}, err return taskmodel.Task{}, err
} }
for _, tt := range tasks { for _, tt := range tasks {
if tt.Name == opt.name { if tt.Name == opt.name {
@ -4974,13 +4974,13 @@ func (r resourceChecker) getTask(t *testing.T, getOpt getResourceOptFn) (influxd
require.Fail(t, "did not provide a valid get option") require.Fail(t, "did not provide a valid get option")
} }
if task == nil { if task == nil {
return influxdb.Task{}, errors.New("did not find expected task by name") return taskmodel.Task{}, errors.New("did not find expected task by name")
} }
return *task, err return *task, err
} }
func (r resourceChecker) mustGetTask(t *testing.T, getOpt getResourceOptFn) influxdb.Task { func (r resourceChecker) mustGetTask(t *testing.T, getOpt getResourceOptFn) taskmodel.Task {
t.Helper() t.Helper()
task, err := r.getTask(t, getOpt) task, err := r.getTask(t, getOpt)

View File

@ -4,8 +4,7 @@ import (
"fmt" "fmt"
"github.com/influxdata/influxdb/v2/kit/platform/errors" "github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"github.com/influxdata/influxdb/v2"
) )
var ( var (
@ -39,7 +38,7 @@ func ErrOrgNotFound(org string) error {
return &errors.Error{ return &errors.Error{
Code: errors.ENotFound, Code: errors.ENotFound,
Msg: fmt.Sprintf("invalid org %q", org), Msg: fmt.Sprintf("invalid org %q", org),
Err: influxdb.ErrOrgNotFound, Err: taskmodel.ErrOrgNotFound,
} }
} }

View File

@ -4,9 +4,6 @@ import (
"context" "context"
"net/http" "net/http"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/go-chi/chi" "github.com/go-chi/chi"
"github.com/influxdata/httprouter" "github.com/influxdata/httprouter"
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
@ -16,10 +13,14 @@ import (
"github.com/influxdata/influxdb/v2/http/metric" "github.com/influxdata/influxdb/v2/http/metric"
"github.com/influxdata/influxdb/v2/influxql" "github.com/influxdata/influxdb/v2/influxql"
"github.com/influxdata/influxdb/v2/kit/feature" "github.com/influxdata/influxdb/v2/kit/feature"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/influxdb/v2/kit/prom" "github.com/influxdata/influxdb/v2/kit/prom"
kithttp "github.com/influxdata/influxdb/v2/kit/transport/http" kithttp "github.com/influxdata/influxdb/v2/kit/transport/http"
"github.com/influxdata/influxdb/v2/query" "github.com/influxdata/influxdb/v2/query"
"github.com/influxdata/influxdb/v2/query/fluxlang"
"github.com/influxdata/influxdb/v2/storage" "github.com/influxdata/influxdb/v2/storage"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -85,8 +86,8 @@ type APIBackend struct {
InfluxQLService query.ProxyQueryService InfluxQLService query.ProxyQueryService
InfluxqldService influxql.ProxyQueryService InfluxqldService influxql.ProxyQueryService
FluxService query.ProxyQueryService FluxService query.ProxyQueryService
FluxLanguageService influxdb.FluxLanguageService FluxLanguageService fluxlang.FluxLanguageService
TaskService influxdb.TaskService TaskService taskmodel.TaskService
CheckService influxdb.CheckService CheckService influxdb.CheckService
TelegrafService influxdb.TelegrafConfigStore TelegrafService influxdb.TelegrafConfigStore
ScraperTargetStoreService influxdb.ScraperTargetStoreService ScraperTargetStoreService influxdb.ScraperTargetStoreService

View File

@ -9,15 +9,16 @@ import (
"path" "path"
"time" "time"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/httprouter" "github.com/influxdata/httprouter"
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
pctx "github.com/influxdata/influxdb/v2/context" pctx "github.com/influxdata/influxdb/v2/context"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/influxdb/v2/kit/tracing" "github.com/influxdata/influxdb/v2/kit/tracing"
"github.com/influxdata/influxdb/v2/notification/check" "github.com/influxdata/influxdb/v2/notification/check"
"github.com/influxdata/influxdb/v2/pkg/httpc" "github.com/influxdata/influxdb/v2/pkg/httpc"
"github.com/influxdata/influxdb/v2/query/fluxlang"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -28,13 +29,13 @@ type CheckBackend struct {
log *zap.Logger log *zap.Logger
AlgoWProxy FeatureProxyHandler AlgoWProxy FeatureProxyHandler
TaskService influxdb.TaskService TaskService taskmodel.TaskService
CheckService influxdb.CheckService CheckService influxdb.CheckService
UserResourceMappingService influxdb.UserResourceMappingService UserResourceMappingService influxdb.UserResourceMappingService
LabelService influxdb.LabelService LabelService influxdb.LabelService
UserService influxdb.UserService UserService influxdb.UserService
OrganizationService influxdb.OrganizationService OrganizationService influxdb.OrganizationService
FluxLanguageService influxdb.FluxLanguageService FluxLanguageService fluxlang.FluxLanguageService
} }
// NewCheckBackend returns a new instance of CheckBackend. // NewCheckBackend returns a new instance of CheckBackend.
@ -59,13 +60,13 @@ type CheckHandler struct {
errors.HTTPErrorHandler errors.HTTPErrorHandler
log *zap.Logger log *zap.Logger
TaskService influxdb.TaskService TaskService taskmodel.TaskService
CheckService influxdb.CheckService CheckService influxdb.CheckService
UserResourceMappingService influxdb.UserResourceMappingService UserResourceMappingService influxdb.UserResourceMappingService
LabelService influxdb.LabelService LabelService influxdb.LabelService
UserService influxdb.UserService UserService influxdb.UserService
OrganizationService influxdb.OrganizationService OrganizationService influxdb.OrganizationService
FluxLanguageService influxdb.FluxLanguageService FluxLanguageService fluxlang.FluxLanguageService
} }
const ( const (
@ -441,7 +442,7 @@ func decodePostCheckRequest(r *http.Request) (postCheckRequest, error) {
}, nil }, nil
} }
func decodePutCheckRequest(ctx context.Context, lang influxdb.FluxLanguageService, r *http.Request) (influxdb.CheckCreate, error) { func decodePutCheckRequest(ctx context.Context, lang fluxlang.FluxLanguageService, r *http.Request) (influxdb.CheckCreate, error) {
params := httprouter.ParamsFromContext(ctx) params := httprouter.ParamsFromContext(ctx)
id := params.ByName("id") id := params.ByName("id")
if id == "" { if id == "" {

View File

@ -11,19 +11,19 @@ import (
"path" "path"
"testing" "testing"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/flux/parser" "github.com/influxdata/flux/parser"
"github.com/influxdata/httprouter" "github.com/influxdata/httprouter"
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
pcontext "github.com/influxdata/influxdb/v2/context" pcontext "github.com/influxdata/influxdb/v2/context"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/kit/platform/errors"
kithttp "github.com/influxdata/influxdb/v2/kit/transport/http" kithttp "github.com/influxdata/influxdb/v2/kit/transport/http"
"github.com/influxdata/influxdb/v2/mock" "github.com/influxdata/influxdb/v2/mock"
"github.com/influxdata/influxdb/v2/notification" "github.com/influxdata/influxdb/v2/notification"
"github.com/influxdata/influxdb/v2/notification/check" "github.com/influxdata/influxdb/v2/notification/check"
"github.com/influxdata/influxdb/v2/pkg/testttp" "github.com/influxdata/influxdb/v2/pkg/testttp"
"github.com/influxdata/influxdb/v2/query/fluxlang" "github.com/influxdata/influxdb/v2/query/fluxlang"
"github.com/influxdata/influxdb/v2/task/taskmodel"
influxTesting "github.com/influxdata/influxdb/v2/testing" influxTesting "github.com/influxdata/influxdb/v2/testing"
"go.uber.org/zap/zaptest" "go.uber.org/zap/zaptest"
) )
@ -284,8 +284,8 @@ func TestService_handleGetChecks(t *testing.T) {
checkBackend.CheckService = tt.fields.CheckService checkBackend.CheckService = tt.fields.CheckService
checkBackend.LabelService = tt.fields.LabelService checkBackend.LabelService = tt.fields.LabelService
checkBackend.TaskService = &mock.TaskService{ checkBackend.TaskService = &mock.TaskService{
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*influxdb.Task, error) { FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*taskmodel.Task, error) {
return &influxdb.Task{Status: "active"}, nil return &taskmodel.Task{Status: "active"}, nil
}, },
} }
h := NewCheckHandler(zaptest.NewLogger(t), checkBackend) h := NewCheckHandler(zaptest.NewLogger(t), checkBackend)
@ -426,8 +426,8 @@ func TestService_handleGetCheckQuery(t *testing.T) {
checkBackend.HTTPErrorHandler = kithttp.ErrorHandler(0) checkBackend.HTTPErrorHandler = kithttp.ErrorHandler(0)
checkBackend.CheckService = tt.fields.CheckService checkBackend.CheckService = tt.fields.CheckService
checkBackend.TaskService = &mock.TaskService{ checkBackend.TaskService = &mock.TaskService{
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*influxdb.Task, error) { FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*taskmodel.Task, error) {
return &influxdb.Task{}, nil return &taskmodel.Task{}, nil
}, },
} }
@ -567,8 +567,8 @@ func TestService_handleGetCheck(t *testing.T) {
checkBackend.HTTPErrorHandler = kithttp.ErrorHandler(0) checkBackend.HTTPErrorHandler = kithttp.ErrorHandler(0)
checkBackend.CheckService = tt.fields.CheckService checkBackend.CheckService = tt.fields.CheckService
checkBackend.TaskService = &mock.TaskService{ checkBackend.TaskService = &mock.TaskService{
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*influxdb.Task, error) { FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*taskmodel.Task, error) {
return &influxdb.Task{Status: "active"}, nil return &taskmodel.Task{Status: "active"}, nil
}, },
} }
h := NewCheckHandler(zaptest.NewLogger(t), checkBackend) h := NewCheckHandler(zaptest.NewLogger(t), checkBackend)
@ -734,8 +734,8 @@ func TestService_handlePostCheck(t *testing.T) {
checkBackend.CheckService = tt.fields.CheckService checkBackend.CheckService = tt.fields.CheckService
checkBackend.OrganizationService = tt.fields.OrganizationService checkBackend.OrganizationService = tt.fields.OrganizationService
checkBackend.TaskService = &mock.TaskService{ checkBackend.TaskService = &mock.TaskService{
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*influxdb.Task, error) { FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*taskmodel.Task, error) {
return &influxdb.Task{Status: "active"}, nil return &taskmodel.Task{Status: "active"}, nil
}, },
} }
h := NewCheckHandler(zaptest.NewLogger(t), checkBackend) h := NewCheckHandler(zaptest.NewLogger(t), checkBackend)
@ -837,8 +837,8 @@ func TestService_handleDeleteCheck(t *testing.T) {
checkBackend.HTTPErrorHandler = kithttp.ErrorHandler(0) checkBackend.HTTPErrorHandler = kithttp.ErrorHandler(0)
checkBackend.CheckService = tt.fields.CheckService checkBackend.CheckService = tt.fields.CheckService
checkBackend.TaskService = &mock.TaskService{ checkBackend.TaskService = &mock.TaskService{
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*influxdb.Task, error) { FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*taskmodel.Task, error) {
return &influxdb.Task{}, nil return &taskmodel.Task{}, nil
}, },
} }
h := NewCheckHandler(zaptest.NewLogger(t), checkBackend) h := NewCheckHandler(zaptest.NewLogger(t), checkBackend)
@ -1003,8 +1003,8 @@ func TestService_handlePatchCheck(t *testing.T) {
checkBackend.HTTPErrorHandler = kithttp.ErrorHandler(0) checkBackend.HTTPErrorHandler = kithttp.ErrorHandler(0)
checkBackend.CheckService = tt.fields.CheckService checkBackend.CheckService = tt.fields.CheckService
checkBackend.TaskService = &mock.TaskService{ checkBackend.TaskService = &mock.TaskService{
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*influxdb.Task, error) { FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*taskmodel.Task, error) {
return &influxdb.Task{Status: "active"}, nil return &taskmodel.Task{Status: "active"}, nil
}, },
} }
h := NewCheckHandler(zaptest.NewLogger(t), checkBackend) h := NewCheckHandler(zaptest.NewLogger(t), checkBackend)
@ -1197,8 +1197,8 @@ func TestService_handleUpdateCheck(t *testing.T) {
checkBackend.HTTPErrorHandler = kithttp.ErrorHandler(0) checkBackend.HTTPErrorHandler = kithttp.ErrorHandler(0)
checkBackend.CheckService = tt.fields.CheckService checkBackend.CheckService = tt.fields.CheckService
checkBackend.TaskService = &mock.TaskService{ checkBackend.TaskService = &mock.TaskService{
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*influxdb.Task, error) { FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*taskmodel.Task, error) {
return &influxdb.Task{Status: "active"}, nil return &taskmodel.Task{Status: "active"}, nil
}, },
} }
h := NewCheckHandler(zaptest.NewLogger(t), checkBackend) h := NewCheckHandler(zaptest.NewLogger(t), checkBackend)
@ -1308,8 +1308,8 @@ func TestService_handlePostCheckMember(t *testing.T) {
checkBackend := NewMockCheckBackend(t) checkBackend := NewMockCheckBackend(t)
checkBackend.UserService = tt.fields.UserService checkBackend.UserService = tt.fields.UserService
checkBackend.TaskService = &mock.TaskService{ checkBackend.TaskService = &mock.TaskService{
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*influxdb.Task, error) { FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*taskmodel.Task, error) {
return &influxdb.Task{}, nil return &taskmodel.Task{}, nil
}, },
} }
h := NewCheckHandler(zaptest.NewLogger(t), checkBackend) h := NewCheckHandler(zaptest.NewLogger(t), checkBackend)

View File

@ -9,14 +9,14 @@ import (
"path" "path"
"time" "time"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/httprouter" "github.com/influxdata/httprouter"
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
pctx "github.com/influxdata/influxdb/v2/context" pctx "github.com/influxdata/influxdb/v2/context"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/influxdb/v2/notification/rule" "github.com/influxdata/influxdb/v2/notification/rule"
"github.com/influxdata/influxdb/v2/pkg/httpc" "github.com/influxdata/influxdb/v2/pkg/httpc"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -39,7 +39,7 @@ type NotificationRuleBackend struct {
LabelService influxdb.LabelService LabelService influxdb.LabelService
UserService influxdb.UserService UserService influxdb.UserService
OrganizationService influxdb.OrganizationService OrganizationService influxdb.OrganizationService
TaskService influxdb.TaskService TaskService taskmodel.TaskService
} }
// NewNotificationRuleBackend returns a new instance of NotificationRuleBackend. // NewNotificationRuleBackend returns a new instance of NotificationRuleBackend.
@ -71,7 +71,7 @@ type NotificationRuleHandler struct {
LabelService influxdb.LabelService LabelService influxdb.LabelService
UserService influxdb.UserService UserService influxdb.UserService
OrganizationService influxdb.OrganizationService OrganizationService influxdb.OrganizationService
TaskService influxdb.TaskService TaskService taskmodel.TaskService
} }
const ( const (

View File

@ -5,12 +5,12 @@ import (
"encoding/json" "encoding/json"
"testing" "testing"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/mock" "github.com/influxdata/influxdb/v2/mock"
"github.com/influxdata/influxdb/v2/notification" "github.com/influxdata/influxdb/v2/notification"
"github.com/influxdata/influxdb/v2/notification/rule" "github.com/influxdata/influxdb/v2/notification/rule"
"github.com/influxdata/influxdb/v2/task/taskmodel"
influxTesting "github.com/influxdata/influxdb/v2/testing" influxTesting "github.com/influxdata/influxdb/v2/testing"
"go.uber.org/zap/zaptest" "go.uber.org/zap/zaptest"
) )
@ -25,8 +25,8 @@ func NewMockNotificationRuleBackend(t *testing.T) *NotificationRuleBackend {
UserService: mock.NewUserService(), UserService: mock.NewUserService(),
OrganizationService: mock.NewOrganizationService(), OrganizationService: mock.NewOrganizationService(),
TaskService: &mock.TaskService{ TaskService: &mock.TaskService{
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*influxdb.Task, error) { FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*taskmodel.Task, error) {
return &influxdb.Task{Status: "active"}, nil return &taskmodel.Task{Status: "active"}, nil
}, },
}, },
} }

View File

@ -21,6 +21,7 @@ import (
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/jsonweb" "github.com/influxdata/influxdb/v2/jsonweb"
"github.com/influxdata/influxdb/v2/query" "github.com/influxdata/influxdb/v2/query"
"github.com/influxdata/influxdb/v2/query/fluxlang"
transpiler "github.com/influxdata/influxdb/v2/query/influxql" transpiler "github.com/influxdata/influxdb/v2/query/influxql"
"github.com/influxdata/influxql" "github.com/influxdata/influxql"
) )
@ -144,7 +145,7 @@ type queryParseError struct {
// Analyze attempts to parse the query request and returns any errors // Analyze attempts to parse the query request and returns any errors
// encountered in a structured way. // encountered in a structured way.
func (r QueryRequest) Analyze(l influxdb.FluxLanguageService) (*QueryAnalysis, error) { func (r QueryRequest) Analyze(l fluxlang.FluxLanguageService) (*QueryAnalysis, error) {
switch r.Type { switch r.Type {
case "flux": case "flux":
return r.analyzeFluxQuery(l) return r.analyzeFluxQuery(l)
@ -155,7 +156,7 @@ func (r QueryRequest) Analyze(l influxdb.FluxLanguageService) (*QueryAnalysis, e
return nil, fmt.Errorf("unknown query request type %s", r.Type) return nil, fmt.Errorf("unknown query request type %s", r.Type)
} }
func (r QueryRequest) analyzeFluxQuery(l influxdb.FluxLanguageService) (*QueryAnalysis, error) { func (r QueryRequest) analyzeFluxQuery(l fluxlang.FluxLanguageService) (*QueryAnalysis, error) {
a := &QueryAnalysis{} a := &QueryAnalysis{}
pkg, err := query.Parse(l, r.Query) pkg, err := query.Parse(l, r.Query)
if pkg == nil { if pkg == nil {

View File

@ -12,9 +12,6 @@ import (
"sort" "sort"
"time" "time"
"github.com/influxdata/influxdb/v2/kit/platform"
errors2 "github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/NYTimes/gziphandler" "github.com/NYTimes/gziphandler"
"github.com/influxdata/flux" "github.com/influxdata/flux"
"github.com/influxdata/flux/ast" "github.com/influxdata/flux/ast"
@ -26,10 +23,13 @@ import (
"github.com/influxdata/influxdb/v2/http/metric" "github.com/influxdata/influxdb/v2/http/metric"
"github.com/influxdata/influxdb/v2/kit/check" "github.com/influxdata/influxdb/v2/kit/check"
"github.com/influxdata/influxdb/v2/kit/feature" "github.com/influxdata/influxdb/v2/kit/feature"
"github.com/influxdata/influxdb/v2/kit/platform"
errors2 "github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/influxdb/v2/kit/tracing" "github.com/influxdata/influxdb/v2/kit/tracing"
kithttp "github.com/influxdata/influxdb/v2/kit/transport/http" kithttp "github.com/influxdata/influxdb/v2/kit/transport/http"
"github.com/influxdata/influxdb/v2/logger" "github.com/influxdata/influxdb/v2/logger"
"github.com/influxdata/influxdb/v2/query" "github.com/influxdata/influxdb/v2/query"
"github.com/influxdata/influxdb/v2/query/fluxlang"
"github.com/influxdata/influxdb/v2/query/influxql" "github.com/influxdata/influxdb/v2/query/influxql"
"github.com/pkg/errors" "github.com/pkg/errors"
prom "github.com/prometheus/client_golang/prometheus" prom "github.com/prometheus/client_golang/prometheus"
@ -51,7 +51,7 @@ type FluxBackend struct {
AlgoWProxy FeatureProxyHandler AlgoWProxy FeatureProxyHandler
OrganizationService influxdb.OrganizationService OrganizationService influxdb.OrganizationService
ProxyQueryService query.ProxyQueryService ProxyQueryService query.ProxyQueryService
FluxLanguageService influxdb.FluxLanguageService FluxLanguageService fluxlang.FluxLanguageService
Flagger feature.Flagger Flagger feature.Flagger
} }
@ -86,7 +86,7 @@ type FluxHandler struct {
Now func() time.Time Now func() time.Time
OrganizationService influxdb.OrganizationService OrganizationService influxdb.OrganizationService
ProxyQueryService query.ProxyQueryService ProxyQueryService query.ProxyQueryService
FluxLanguageService influxdb.FluxLanguageService FluxLanguageService fluxlang.FluxLanguageService
EventRecorder metric.EventRecorder EventRecorder metric.EventRecorder

View File

@ -11,16 +11,16 @@ import (
"strconv" "strconv"
"time" "time"
"github.com/influxdata/influxdb/v2/kit/platform"
errors2 "github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/httprouter" "github.com/influxdata/httprouter"
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
pcontext "github.com/influxdata/influxdb/v2/context" pcontext "github.com/influxdata/influxdb/v2/context"
"github.com/influxdata/influxdb/v2/kit/platform"
errors2 "github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/influxdb/v2/kit/tracing" "github.com/influxdata/influxdb/v2/kit/tracing"
"github.com/influxdata/influxdb/v2/kv" "github.com/influxdata/influxdb/v2/kv"
"github.com/influxdata/influxdb/v2/pkg/httpc" "github.com/influxdata/influxdb/v2/pkg/httpc"
"github.com/influxdata/influxdb/v2/task/options" "github.com/influxdata/influxdb/v2/task/options"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -31,7 +31,7 @@ type TaskBackend struct {
log *zap.Logger log *zap.Logger
AlgoWProxy FeatureProxyHandler AlgoWProxy FeatureProxyHandler
TaskService influxdb.TaskService TaskService taskmodel.TaskService
AuthorizationService influxdb.AuthorizationService AuthorizationService influxdb.AuthorizationService
OrganizationService influxdb.OrganizationService OrganizationService influxdb.OrganizationService
UserResourceMappingService influxdb.UserResourceMappingService UserResourceMappingService influxdb.UserResourceMappingService
@ -62,7 +62,7 @@ type TaskHandler struct {
errors2.HTTPErrorHandler errors2.HTTPErrorHandler
log *zap.Logger log *zap.Logger
TaskService influxdb.TaskService TaskService taskmodel.TaskService
AuthorizationService influxdb.AuthorizationService AuthorizationService influxdb.AuthorizationService
OrganizationService influxdb.OrganizationService OrganizationService influxdb.OrganizationService
UserResourceMappingService influxdb.UserResourceMappingService UserResourceMappingService influxdb.UserResourceMappingService
@ -185,7 +185,7 @@ type taskResponse struct {
} }
// NewFrontEndTask converts a internal task type to a task that we want to display to users // NewFrontEndTask converts a internal task type to a task that we want to display to users
func NewFrontEndTask(t influxdb.Task) Task { func NewFrontEndTask(t taskmodel.Task) Task {
latestCompleted := "" latestCompleted := ""
if !t.LatestCompleted.IsZero() { if !t.LatestCompleted.IsZero() {
latestCompleted = t.LatestCompleted.Format(time.RFC3339) latestCompleted = t.LatestCompleted.Format(time.RFC3339)
@ -224,7 +224,7 @@ func NewFrontEndTask(t influxdb.Task) Task {
} }
} }
func convertTask(t Task) *influxdb.Task { func convertTask(t Task) *taskmodel.Task {
var ( var (
latestCompleted time.Time latestCompleted time.Time
createdAt time.Time createdAt time.Time
@ -251,7 +251,7 @@ func convertTask(t Task) *influxdb.Task {
} }
} }
return &influxdb.Task{ return &taskmodel.Task{
ID: t.ID, ID: t.ID,
OrganizationID: t.OrganizationID, OrganizationID: t.OrganizationID,
Organization: t.Organization, Organization: t.Organization,
@ -308,7 +308,7 @@ func customParseDuration(d time.Duration) string {
return str return str
} }
func newTaskResponse(t influxdb.Task, labels []*influxdb.Label) taskResponse { func newTaskResponse(t taskmodel.Task, labels []*influxdb.Label) taskResponse {
response := taskResponse{ response := taskResponse{
Links: map[string]string{ Links: map[string]string{
"self": fmt.Sprintf("/api/v2/tasks/%s", t.ID), "self": fmt.Sprintf("/api/v2/tasks/%s", t.ID),
@ -329,7 +329,7 @@ func newTaskResponse(t influxdb.Task, labels []*influxdb.Label) taskResponse {
return response return response
} }
func newTasksPagingLinks(basePath string, ts []*influxdb.Task, f influxdb.TaskFilter) *influxdb.PagingLinks { func newTasksPagingLinks(basePath string, ts []*taskmodel.Task, f taskmodel.TaskFilter) *influxdb.PagingLinks {
var self, next string var self, next string
u := url.URL{ u := url.URL{
Path: basePath, Path: basePath,
@ -366,7 +366,7 @@ type tasksResponse struct {
Tasks []taskResponse `json:"tasks"` Tasks []taskResponse `json:"tasks"`
} }
func newTasksResponse(ctx context.Context, ts []*influxdb.Task, f influxdb.TaskFilter, labelService influxdb.LabelService) tasksResponse { func newTasksResponse(ctx context.Context, ts []*taskmodel.Task, f taskmodel.TaskFilter, labelService influxdb.LabelService) tasksResponse {
rs := tasksResponse{ rs := tasksResponse{
Links: newTasksPagingLinks(prefixTasks, ts, f), Links: newTasksPagingLinks(prefixTasks, ts, f),
Tasks: make([]taskResponse, len(ts)), Tasks: make([]taskResponse, len(ts)),
@ -388,17 +388,17 @@ type runResponse struct {
// it uses a pointer to a time.Time instead of a time.Time so that we can pass a nil // it uses a pointer to a time.Time instead of a time.Time so that we can pass a nil
// value for empty time values // value for empty time values
type httpRun struct { type httpRun struct {
ID platform.ID `json:"id,omitempty"` ID platform.ID `json:"id,omitempty"`
TaskID platform.ID `json:"taskID"` TaskID platform.ID `json:"taskID"`
Status string `json:"status"` Status string `json:"status"`
ScheduledFor *time.Time `json:"scheduledFor"` ScheduledFor *time.Time `json:"scheduledFor"`
StartedAt *time.Time `json:"startedAt,omitempty"` StartedAt *time.Time `json:"startedAt,omitempty"`
FinishedAt *time.Time `json:"finishedAt,omitempty"` FinishedAt *time.Time `json:"finishedAt,omitempty"`
RequestedAt *time.Time `json:"requestedAt,omitempty"` RequestedAt *time.Time `json:"requestedAt,omitempty"`
Log []influxdb.Log `json:"log,omitempty"` Log []taskmodel.Log `json:"log,omitempty"`
} }
func newRunResponse(r influxdb.Run) runResponse { func newRunResponse(r taskmodel.Run) runResponse {
run := httpRun{ run := httpRun{
ID: r.ID, ID: r.ID,
TaskID: r.TaskID, TaskID: r.TaskID,
@ -428,8 +428,8 @@ func newRunResponse(r influxdb.Run) runResponse {
} }
} }
func convertRun(r httpRun) *influxdb.Run { func convertRun(r httpRun) *taskmodel.Run {
run := &influxdb.Run{ run := &taskmodel.Run{
ID: r.ID, ID: r.ID,
TaskID: r.TaskID, TaskID: r.TaskID,
Status: r.Status, Status: r.Status,
@ -460,7 +460,7 @@ type runsResponse struct {
Runs []*runResponse `json:"runs"` Runs []*runResponse `json:"runs"`
} }
func newRunsResponse(rs []*influxdb.Run, taskID platform.ID) runsResponse { func newRunsResponse(rs []*taskmodel.Run, taskID platform.ID) runsResponse {
r := runsResponse{ r := runsResponse{
Links: map[string]string{ Links: map[string]string{
"self": fmt.Sprintf("/api/v2/tasks/%s/runs", taskID), "self": fmt.Sprintf("/api/v2/tasks/%s/runs", taskID),
@ -502,7 +502,7 @@ func (h *TaskHandler) handleGetTasks(w http.ResponseWriter, r *http.Request) {
} }
type getTasksRequest struct { type getTasksRequest struct {
filter influxdb.TaskFilter filter taskmodel.TaskFilter
} }
func decodeGetTasksRequest(ctx context.Context, r *http.Request, orgs influxdb.OrganizationService) (*getTasksRequest, error) { func decodeGetTasksRequest(ctx context.Context, r *http.Request, orgs influxdb.OrganizationService) (*getTasksRequest, error) {
@ -554,15 +554,15 @@ func decodeGetTasksRequest(ctx context.Context, r *http.Request, orgs influxdb.O
if err != nil { if err != nil {
return nil, err return nil, err
} }
if lim < 1 || lim > influxdb.TaskMaxPageSize { if lim < 1 || lim > taskmodel.TaskMaxPageSize {
return nil, &errors2.Error{ return nil, &errors2.Error{
Code: errors2.EUnprocessableEntity, Code: errors2.EUnprocessableEntity,
Msg: fmt.Sprintf("limit must be between 1 and %d", influxdb.TaskMaxPageSize), Msg: fmt.Sprintf("limit must be between 1 and %d", taskmodel.TaskMaxPageSize),
} }
} }
req.filter.Limit = lim req.filter.Limit = lim
} else { } else {
req.filter.Limit = influxdb.TaskDefaultPageSize req.filter.Limit = taskmodel.TaskDefaultPageSize
} }
if status := qp.Get("status"); status == "active" { if status := qp.Get("status"); status == "active" {
@ -572,7 +572,7 @@ func decodeGetTasksRequest(ctx context.Context, r *http.Request, orgs influxdb.O
} }
// the task api can only create or lookup system tasks. // the task api can only create or lookup system tasks.
req.filter.Type = &influxdb.TaskSystemType req.filter.Type = &taskmodel.TaskSystemType
if name := qp.Get("name"); name != "" { if name := qp.Get("name"); name != "" {
req.filter.Name = &name req.filter.Name = &name
@ -643,11 +643,11 @@ func (h *TaskHandler) handlePostTask(w http.ResponseWriter, r *http.Request) {
} }
type postTaskRequest struct { type postTaskRequest struct {
TaskCreate influxdb.TaskCreate TaskCreate taskmodel.TaskCreate
} }
func decodePostTaskRequest(ctx context.Context, r *http.Request) (*postTaskRequest, error) { func decodePostTaskRequest(ctx context.Context, r *http.Request) (*postTaskRequest, error) {
var tc influxdb.TaskCreate var tc taskmodel.TaskCreate
if err := json.NewDecoder(r.Body).Decode(&tc); err != nil { if err := json.NewDecoder(r.Body).Decode(&tc); err != nil {
return nil, err return nil, err
} }
@ -659,7 +659,7 @@ func decodePostTaskRequest(ctx context.Context, r *http.Request) (*postTaskReque
} }
tc.OwnerID = auth.GetUserID() tc.OwnerID = auth.GetUserID()
// when creating a task we set the type so we can filter later. // when creating a task we set the type so we can filter later.
tc.Type = influxdb.TaskSystemType tc.Type = taskmodel.TaskSystemType
if err := tc.Validate(); err != nil { if err := tc.Validate(); err != nil {
return nil, err return nil, err
@ -754,7 +754,7 @@ func (h *TaskHandler) handleUpdateTask(w http.ResponseWriter, r *http.Request) {
Err: err, Err: err,
Msg: "failed to update task", Msg: "failed to update task",
} }
if err.Err == influxdb.ErrTaskNotFound { if err.Err == taskmodel.ErrTaskNotFound {
err.Code = errors2.ENotFound err.Code = errors2.ENotFound
} }
h.HandleHTTPError(ctx, err, w) h.HandleHTTPError(ctx, err, w)
@ -778,7 +778,7 @@ func (h *TaskHandler) handleUpdateTask(w http.ResponseWriter, r *http.Request) {
} }
type updateTaskRequest struct { type updateTaskRequest struct {
Update influxdb.TaskUpdate Update taskmodel.TaskUpdate
TaskID platform.ID TaskID platform.ID
} }
@ -797,7 +797,7 @@ func decodeUpdateTaskRequest(ctx context.Context, r *http.Request) (*updateTaskR
return nil, err return nil, err
} }
var upd influxdb.TaskUpdate var upd taskmodel.TaskUpdate
if err := json.NewDecoder(r.Body).Decode(&upd); err != nil { if err := json.NewDecoder(r.Body).Decode(&upd); err != nil {
return nil, err return nil, err
} }
@ -830,7 +830,7 @@ func (h *TaskHandler) handleDeleteTask(w http.ResponseWriter, r *http.Request) {
Err: err, Err: err,
Msg: "failed to delete task", Msg: "failed to delete task",
} }
if err.Err == influxdb.ErrTaskNotFound { if err.Err == taskmodel.ErrTaskNotFound {
err.Code = errors2.ENotFound err.Code = errors2.ENotFound
} }
h.HandleHTTPError(ctx, err, w) h.HandleHTTPError(ctx, err, w)
@ -907,7 +907,7 @@ func (h *TaskHandler) handleGetLogs(w http.ResponseWriter, r *http.Request) {
Err: err, Err: err,
Msg: "failed to find task logs", Msg: "failed to find task logs",
} }
if err.Err == influxdb.ErrTaskNotFound || err.Err == influxdb.ErrNoRunsFound { if err.Err == taskmodel.ErrTaskNotFound || err.Err == taskmodel.ErrNoRunsFound {
err.Code = errors2.ENotFound err.Code = errors2.ENotFound
} }
h.HandleHTTPError(ctx, err, w) h.HandleHTTPError(ctx, err, w)
@ -921,11 +921,11 @@ func (h *TaskHandler) handleGetLogs(w http.ResponseWriter, r *http.Request) {
} }
type getLogsRequest struct { type getLogsRequest struct {
filter influxdb.LogFilter filter taskmodel.LogFilter
} }
type getLogsResponse struct { type getLogsResponse struct {
Events []*influxdb.Log `json:"events"` Events []*taskmodel.Log `json:"events"`
} }
func decodeGetLogsRequest(ctx context.Context, r *http.Request) (*getLogsRequest, error) { func decodeGetLogsRequest(ctx context.Context, r *http.Request) (*getLogsRequest, error) {
@ -999,7 +999,7 @@ func (h *TaskHandler) handleGetRuns(w http.ResponseWriter, r *http.Request) {
Err: err, Err: err,
Msg: "failed to find runs", Msg: "failed to find runs",
} }
if err.Err == influxdb.ErrTaskNotFound || err.Err == influxdb.ErrNoRunsFound { if err.Err == taskmodel.ErrTaskNotFound || err.Err == taskmodel.ErrNoRunsFound {
err.Code = errors2.ENotFound err.Code = errors2.ENotFound
} }
h.HandleHTTPError(ctx, err, w) h.HandleHTTPError(ctx, err, w)
@ -1013,7 +1013,7 @@ func (h *TaskHandler) handleGetRuns(w http.ResponseWriter, r *http.Request) {
} }
type getRunsRequest struct { type getRunsRequest struct {
filter influxdb.RunFilter filter taskmodel.RunFilter
} }
func decodeGetRunsRequest(ctx context.Context, r *http.Request) (*getRunsRequest, error) { func decodeGetRunsRequest(ctx context.Context, r *http.Request) (*getRunsRequest, error) {
@ -1049,8 +1049,8 @@ func decodeGetRunsRequest(ctx context.Context, r *http.Request) (*getRunsRequest
return nil, err return nil, err
} }
if i < 1 || i > influxdb.TaskMaxPageSize { if i < 1 || i > taskmodel.TaskMaxPageSize {
return nil, influxdb.ErrOutOfBoundsLimit return nil, taskmodel.ErrOutOfBoundsLimit
} }
req.filter.Limit = i req.filter.Limit = i
} }
@ -1103,7 +1103,7 @@ func (h *TaskHandler) handleForceRun(w http.ResponseWriter, r *http.Request) {
Err: err, Err: err,
Msg: "failed to force run", Msg: "failed to force run",
} }
if err.Err == influxdb.ErrTaskNotFound { if err.Err == taskmodel.ErrTaskNotFound {
err.Code = errors2.ENotFound err.Code = errors2.ENotFound
} }
h.HandleHTTPError(ctx, err, w) h.HandleHTTPError(ctx, err, w)
@ -1205,7 +1205,7 @@ func (h *TaskHandler) handleGetRun(w http.ResponseWriter, r *http.Request) {
Err: err, Err: err,
Msg: "failed to find run", Msg: "failed to find run",
} }
if err.Err == influxdb.ErrTaskNotFound || err.Err == influxdb.ErrRunNotFound { if err.Err == taskmodel.ErrTaskNotFound || err.Err == taskmodel.ErrRunNotFound {
err.Code = errors2.ENotFound err.Code = errors2.ENotFound
} }
h.HandleHTTPError(ctx, err, w) h.HandleHTTPError(ctx, err, w)
@ -1311,7 +1311,7 @@ func (h *TaskHandler) handleCancelRun(w http.ResponseWriter, r *http.Request) {
Err: err, Err: err,
Msg: "failed to cancel run", Msg: "failed to cancel run",
} }
if err.Err == influxdb.ErrTaskNotFound || err.Err == influxdb.ErrRunNotFound { if err.Err == taskmodel.ErrTaskNotFound || err.Err == taskmodel.ErrRunNotFound {
err.Code = errors2.ENotFound err.Code = errors2.ENotFound
} }
h.HandleHTTPError(ctx, err, w) h.HandleHTTPError(ctx, err, w)
@ -1362,7 +1362,7 @@ func (h *TaskHandler) handleRetryRun(w http.ResponseWriter, r *http.Request) {
Err: err, Err: err,
Msg: "failed to retry run", Msg: "failed to retry run",
} }
if err.Err == influxdb.ErrTaskNotFound || err.Err == influxdb.ErrRunNotFound { if err.Err == taskmodel.ErrTaskNotFound || err.Err == taskmodel.ErrRunNotFound {
err.Code = errors2.ENotFound err.Code = errors2.ENotFound
} }
h.HandleHTTPError(ctx, err, w) h.HandleHTTPError(ctx, err, w)
@ -1409,7 +1409,7 @@ func decodeRetryRunRequest(ctx context.Context, r *http.Request) (*retryRunReque
}, nil }, nil
} }
func (h *TaskHandler) populateTaskCreateOrg(ctx context.Context, tc *influxdb.TaskCreate) error { func (h *TaskHandler) populateTaskCreateOrg(ctx context.Context, tc *taskmodel.TaskCreate) error {
if tc.OrganizationID.Valid() && tc.Organization != "" { if tc.OrganizationID.Valid() && tc.Organization != "" {
return nil return nil
} }
@ -1466,7 +1466,7 @@ type TaskService struct {
} }
// FindTaskByID returns a single task // FindTaskByID returns a single task
func (t TaskService) FindTaskByID(ctx context.Context, id platform.ID) (*influxdb.Task, error) { func (t TaskService) FindTaskByID(ctx context.Context, id platform.ID) (*taskmodel.Task, error) {
span, _ := tracing.StartSpanFromContext(ctx) span, _ := tracing.StartSpanFromContext(ctx)
defer span.Finish() defer span.Finish()
@ -1481,7 +1481,7 @@ func (t TaskService) FindTaskByID(ctx context.Context, id platform.ID) (*influxd
// FindTasks returns a list of tasks that match a filter (limit 100) and the total count // FindTasks returns a list of tasks that match a filter (limit 100) and the total count
// of matching tasks. // of matching tasks.
func (t TaskService) FindTasks(ctx context.Context, filter influxdb.TaskFilter) ([]*influxdb.Task, int, error) { func (t TaskService) FindTasks(ctx context.Context, filter taskmodel.TaskFilter) ([]*taskmodel.Task, int, error) {
span, _ := tracing.StartSpanFromContext(ctx) span, _ := tracing.StartSpanFromContext(ctx)
defer span.Finish() defer span.Finish()
@ -1522,7 +1522,7 @@ func (t TaskService) FindTasks(ctx context.Context, filter influxdb.TaskFilter)
return nil, 0, err return nil, 0, err
} }
tasks := make([]*influxdb.Task, len(tr.Tasks)) tasks := make([]*taskmodel.Task, len(tr.Tasks))
for i := range tr.Tasks { for i := range tr.Tasks {
tasks[i] = convertTask(tr.Tasks[i].Task) tasks[i] = convertTask(tr.Tasks[i].Task)
} }
@ -1530,7 +1530,7 @@ func (t TaskService) FindTasks(ctx context.Context, filter influxdb.TaskFilter)
} }
// CreateTask creates a new task. // CreateTask creates a new task.
func (t TaskService) CreateTask(ctx context.Context, tc influxdb.TaskCreate) (*influxdb.Task, error) { func (t TaskService) CreateTask(ctx context.Context, tc taskmodel.TaskCreate) (*taskmodel.Task, error) {
span, _ := tracing.StartSpanFromContext(ctx) span, _ := tracing.StartSpanFromContext(ctx)
defer span.Finish() defer span.Finish()
var tr taskResponse var tr taskResponse
@ -1547,7 +1547,7 @@ func (t TaskService) CreateTask(ctx context.Context, tc influxdb.TaskCreate) (*i
} }
// UpdateTask updates a single task with changeset. // UpdateTask updates a single task with changeset.
func (t TaskService) UpdateTask(ctx context.Context, id platform.ID, upd influxdb.TaskUpdate) (*influxdb.Task, error) { func (t TaskService) UpdateTask(ctx context.Context, id platform.ID, upd taskmodel.TaskUpdate) (*taskmodel.Task, error) {
span, _ := tracing.StartSpanFromContext(ctx) span, _ := tracing.StartSpanFromContext(ctx)
defer span.Finish() defer span.Finish()
@ -1573,7 +1573,7 @@ func (t TaskService) DeleteTask(ctx context.Context, id platform.ID) error {
} }
// FindLogs returns logs for a run. // FindLogs returns logs for a run.
func (t TaskService) FindLogs(ctx context.Context, filter influxdb.LogFilter) ([]*influxdb.Log, int, error) { func (t TaskService) FindLogs(ctx context.Context, filter taskmodel.LogFilter) ([]*taskmodel.Log, int, error) {
span, _ := tracing.StartSpanFromContext(ctx) span, _ := tracing.StartSpanFromContext(ctx)
defer span.Finish() defer span.Finish()
@ -1602,7 +1602,7 @@ func (t TaskService) FindLogs(ctx context.Context, filter influxdb.LogFilter) ([
} }
// FindRuns returns a list of runs that match a filter and the total count of returned runs. // FindRuns returns a list of runs that match a filter and the total count of returned runs.
func (t TaskService) FindRuns(ctx context.Context, filter influxdb.RunFilter) ([]*influxdb.Run, int, error) { func (t TaskService) FindRuns(ctx context.Context, filter taskmodel.RunFilter) ([]*taskmodel.Run, int, error) {
span, _ := tracing.StartSpanFromContext(ctx) span, _ := tracing.StartSpanFromContext(ctx)
defer span.Finish() defer span.Finish()
@ -1616,8 +1616,8 @@ func (t TaskService) FindRuns(ctx context.Context, filter influxdb.RunFilter) ([
params = append(params, [2]string{"after", filter.After.String()}) params = append(params, [2]string{"after", filter.After.String()})
} }
if filter.Limit < 0 || filter.Limit > influxdb.TaskMaxPageSize { if filter.Limit < 0 || filter.Limit > taskmodel.TaskMaxPageSize {
return nil, 0, influxdb.ErrOutOfBoundsLimit return nil, 0, taskmodel.ErrOutOfBoundsLimit
} }
params = append(params, [2]string{"limit", strconv.Itoa(filter.Limit)}) params = append(params, [2]string{"limit", strconv.Itoa(filter.Limit)})
@ -1632,7 +1632,7 @@ func (t TaskService) FindRuns(ctx context.Context, filter influxdb.RunFilter) ([
return nil, 0, err return nil, 0, err
} }
runs := make([]*influxdb.Run, len(rs.Runs)) runs := make([]*taskmodel.Run, len(rs.Runs))
for i := range rs.Runs { for i := range rs.Runs {
runs[i] = convertRun(rs.Runs[i].httpRun) runs[i] = convertRun(rs.Runs[i].httpRun)
} }
@ -1641,7 +1641,7 @@ func (t TaskService) FindRuns(ctx context.Context, filter influxdb.RunFilter) ([
} }
// FindRunByID returns a single run of a specific task. // FindRunByID returns a single run of a specific task.
func (t TaskService) FindRunByID(ctx context.Context, taskID, runID platform.ID) (*influxdb.Run, error) { func (t TaskService) FindRunByID(ctx context.Context, taskID, runID platform.ID) (*taskmodel.Run, error) {
span, _ := tracing.StartSpanFromContext(ctx) span, _ := tracing.StartSpanFromContext(ctx)
defer span.Finish() defer span.Finish()
@ -1656,7 +1656,7 @@ func (t TaskService) FindRunByID(ctx context.Context, taskID, runID platform.ID)
// ErrRunNotFound is expected as part of the FindRunByID contract, // ErrRunNotFound is expected as part of the FindRunByID contract,
// so return that actual error instead of a different error that looks like it. // so return that actual error instead of a different error that looks like it.
// TODO cleanup backend error implementation // TODO cleanup backend error implementation
return nil, influxdb.ErrRunNotFound return nil, taskmodel.ErrRunNotFound
} }
return nil, err return nil, err
@ -1666,7 +1666,7 @@ func (t TaskService) FindRunByID(ctx context.Context, taskID, runID platform.ID)
} }
// RetryRun creates and returns a new run (which is a retry of another run). // RetryRun creates and returns a new run (which is a retry of another run).
func (t TaskService) RetryRun(ctx context.Context, taskID, runID platform.ID) (*influxdb.Run, error) { func (t TaskService) RetryRun(ctx context.Context, taskID, runID platform.ID) (*taskmodel.Run, error) {
span, _ := tracing.StartSpanFromContext(ctx) span, _ := tracing.StartSpanFromContext(ctx)
defer span.Finish() defer span.Finish()
@ -1681,10 +1681,10 @@ func (t TaskService) RetryRun(ctx context.Context, taskID, runID platform.ID) (*
// ErrRunNotFound is expected as part of the RetryRun contract, // ErrRunNotFound is expected as part of the RetryRun contract,
// so return that actual error instead of a different error that looks like it. // so return that actual error instead of a different error that looks like it.
// TODO cleanup backend task error implementation // TODO cleanup backend task error implementation
return nil, influxdb.ErrRunNotFound return nil, taskmodel.ErrRunNotFound
} }
// RequestStillQueuedError is also part of the contract. // RequestStillQueuedError is also part of the contract.
if e := influxdb.ParseRequestStillQueuedError(err.Error()); e != nil { if e := taskmodel.ParseRequestStillQueuedError(err.Error()); e != nil {
return nil, *e return nil, *e
} }
@ -1695,7 +1695,7 @@ func (t TaskService) RetryRun(ctx context.Context, taskID, runID platform.ID) (*
} }
// ForceRun starts a run manually right now. // ForceRun starts a run manually right now.
func (t TaskService) ForceRun(ctx context.Context, taskID platform.ID, scheduledFor int64) (*influxdb.Run, error) { func (t TaskService) ForceRun(ctx context.Context, taskID platform.ID, scheduledFor int64) (*taskmodel.Run, error) {
span, _ := tracing.StartSpanFromContext(ctx) span, _ := tracing.StartSpanFromContext(ctx)
defer span.Finish() defer span.Finish()
@ -1714,11 +1714,11 @@ func (t TaskService) ForceRun(ctx context.Context, taskID platform.ID, scheduled
if errors2.ErrorCode(err) == errors2.ENotFound { if errors2.ErrorCode(err) == errors2.ENotFound {
// ErrRunNotFound is expected as part of the RetryRun contract, // ErrRunNotFound is expected as part of the RetryRun contract,
// so return that actual error instead of a different error that looks like it. // so return that actual error instead of a different error that looks like it.
return nil, influxdb.ErrRunNotFound return nil, taskmodel.ErrRunNotFound
} }
// RequestStillQueuedError is also part of the contract. // RequestStillQueuedError is also part of the contract.
if e := influxdb.ParseRequestStillQueuedError(err.Error()); e != nil { if e := taskmodel.ParseRequestStillQueuedError(err.Error()); e != nil {
return nil, *e return nil, *e
} }

View File

@ -13,17 +13,17 @@ import (
"testing" "testing"
"time" "time"
"github.com/influxdata/influxdb/v2/kit/platform"
errors2 "github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/httprouter" "github.com/influxdata/httprouter"
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/authorization" "github.com/influxdata/influxdb/v2/authorization"
pcontext "github.com/influxdata/influxdb/v2/context" pcontext "github.com/influxdata/influxdb/v2/context"
_ "github.com/influxdata/influxdb/v2/fluxinit/static" _ "github.com/influxdata/influxdb/v2/fluxinit/static"
"github.com/influxdata/influxdb/v2/kit/platform"
errors2 "github.com/influxdata/influxdb/v2/kit/platform/errors"
kithttp "github.com/influxdata/influxdb/v2/kit/transport/http" kithttp "github.com/influxdata/influxdb/v2/kit/transport/http"
"github.com/influxdata/influxdb/v2/label" "github.com/influxdata/influxdb/v2/label"
"github.com/influxdata/influxdb/v2/mock" "github.com/influxdata/influxdb/v2/mock"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"github.com/influxdata/influxdb/v2/tenant" "github.com/influxdata/influxdb/v2/tenant"
influxdbtesting "github.com/influxdata/influxdb/v2/testing" influxdbtesting "github.com/influxdata/influxdb/v2/testing"
"go.uber.org/zap" "go.uber.org/zap"
@ -73,7 +73,7 @@ func NewMockTaskBackend(t *testing.T) *TaskBackend {
func TestTaskHandler_handleGetTasks(t *testing.T) { func TestTaskHandler_handleGetTasks(t *testing.T) {
type fields struct { type fields struct {
taskService influxdb.TaskService taskService taskmodel.TaskService
labelService influxdb.LabelService labelService influxdb.LabelService
} }
type wants struct { type wants struct {
@ -92,8 +92,8 @@ func TestTaskHandler_handleGetTasks(t *testing.T) {
name: "get tasks", name: "get tasks",
fields: fields{ fields: fields{
taskService: &mock.TaskService{ taskService: &mock.TaskService{
FindTasksFn: func(ctx context.Context, f influxdb.TaskFilter) ([]*influxdb.Task, int, error) { FindTasksFn: func(ctx context.Context, f taskmodel.TaskFilter) ([]*taskmodel.Task, int, error) {
tasks := []*influxdb.Task{ tasks := []*taskmodel.Task{
{ {
ID: 1, ID: 1,
Name: "task1", Name: "task1",
@ -199,8 +199,8 @@ func TestTaskHandler_handleGetTasks(t *testing.T) {
getParams: "after=0000000000000001&limit=1", getParams: "after=0000000000000001&limit=1",
fields: fields{ fields: fields{
taskService: &mock.TaskService{ taskService: &mock.TaskService{
FindTasksFn: func(ctx context.Context, f influxdb.TaskFilter) ([]*influxdb.Task, int, error) { FindTasksFn: func(ctx context.Context, f taskmodel.TaskFilter) ([]*taskmodel.Task, int, error) {
tasks := []*influxdb.Task{ tasks := []*taskmodel.Task{
{ {
ID: 2, ID: 2,
Name: "task2", Name: "task2",
@ -272,8 +272,8 @@ func TestTaskHandler_handleGetTasks(t *testing.T) {
getParams: "org=test2", getParams: "org=test2",
fields: fields{ fields: fields{
taskService: &mock.TaskService{ taskService: &mock.TaskService{
FindTasksFn: func(ctx context.Context, f influxdb.TaskFilter) ([]*influxdb.Task, int, error) { FindTasksFn: func(ctx context.Context, f taskmodel.TaskFilter) ([]*taskmodel.Task, int, error) {
tasks := []*influxdb.Task{ tasks := []*taskmodel.Task{
{ {
ID: 2, ID: 2,
Name: "task2", Name: "task2",
@ -344,8 +344,8 @@ func TestTaskHandler_handleGetTasks(t *testing.T) {
getParams: "org=non-existent-org", getParams: "org=non-existent-org",
fields: fields{ fields: fields{
taskService: &mock.TaskService{ taskService: &mock.TaskService{
FindTasksFn: func(ctx context.Context, f influxdb.TaskFilter) ([]*influxdb.Task, int, error) { FindTasksFn: func(ctx context.Context, f taskmodel.TaskFilter) ([]*taskmodel.Task, int, error) {
tasks := []*influxdb.Task{ tasks := []*taskmodel.Task{
{ {
ID: 1, ID: 1,
Name: "task1", Name: "task1",
@ -425,10 +425,10 @@ func TestTaskHandler_handleGetTasks(t *testing.T) {
func TestTaskHandler_handlePostTasks(t *testing.T) { func TestTaskHandler_handlePostTasks(t *testing.T) {
type args struct { type args struct {
taskCreate influxdb.TaskCreate taskCreate taskmodel.TaskCreate
} }
type fields struct { type fields struct {
taskService influxdb.TaskService taskService taskmodel.TaskService
} }
type wants struct { type wants struct {
statusCode int statusCode int
@ -445,15 +445,15 @@ func TestTaskHandler_handlePostTasks(t *testing.T) {
{ {
name: "create task", name: "create task",
args: args{ args: args{
taskCreate: influxdb.TaskCreate{ taskCreate: taskmodel.TaskCreate{
OrganizationID: 1, OrganizationID: 1,
Flux: "abc", Flux: "abc",
}, },
}, },
fields: fields{ fields: fields{
taskService: &mock.TaskService{ taskService: &mock.TaskService{
CreateTaskFn: func(ctx context.Context, tc influxdb.TaskCreate) (*influxdb.Task, error) { CreateTaskFn: func(ctx context.Context, tc taskmodel.TaskCreate) (*taskmodel.Task, error) {
return &influxdb.Task{ return &taskmodel.Task{
ID: 1, ID: 1,
Name: "task1", Name: "task1",
Description: "Brand New Task", Description: "Brand New Task",
@ -494,14 +494,14 @@ func TestTaskHandler_handlePostTasks(t *testing.T) {
{ {
name: "create task - influxdb error creating task", name: "create task - influxdb error creating task",
args: args{ args: args{
taskCreate: influxdb.TaskCreate{ taskCreate: taskmodel.TaskCreate{
OrganizationID: 1, OrganizationID: 1,
Flux: "abc", Flux: "abc",
}, },
}, },
fields: fields{ fields: fields{
taskService: &mock.TaskService{ taskService: &mock.TaskService{
CreateTaskFn: func(ctx context.Context, tc influxdb.TaskCreate) (*influxdb.Task, error) { CreateTaskFn: func(ctx context.Context, tc taskmodel.TaskCreate) (*taskmodel.Task, error) {
return nil, errors2.NewError( return nil, errors2.NewError(
errors2.WithErrorErr(errors.New("something went wrong")), errors2.WithErrorErr(errors.New("something went wrong")),
errors2.WithErrorMsg("something really went wrong"), errors2.WithErrorMsg("something really went wrong"),
@ -524,14 +524,14 @@ func TestTaskHandler_handlePostTasks(t *testing.T) {
{ {
name: "create task - error creating task", name: "create task - error creating task",
args: args{ args: args{
taskCreate: influxdb.TaskCreate{ taskCreate: taskmodel.TaskCreate{
OrganizationID: 1, OrganizationID: 1,
Flux: "abc", Flux: "abc",
}, },
}, },
fields: fields{ fields: fields{
taskService: &mock.TaskService{ taskService: &mock.TaskService{
CreateTaskFn: func(ctx context.Context, tc influxdb.TaskCreate) (*influxdb.Task, error) { CreateTaskFn: func(ctx context.Context, tc taskmodel.TaskCreate) (*taskmodel.Task, error) {
return nil, errors.New("something bad happened") return nil, errors.New("something bad happened")
}, },
}, },
@ -591,7 +591,7 @@ func TestTaskHandler_handlePostTasks(t *testing.T) {
func TestTaskHandler_handleGetRun(t *testing.T) { func TestTaskHandler_handleGetRun(t *testing.T) {
type fields struct { type fields struct {
taskService influxdb.TaskService taskService taskmodel.TaskService
} }
type args struct { type args struct {
taskID platform.ID taskID platform.ID
@ -613,12 +613,12 @@ func TestTaskHandler_handleGetRun(t *testing.T) {
name: "get a run by id", name: "get a run by id",
fields: fields{ fields: fields{
taskService: &mock.TaskService{ taskService: &mock.TaskService{
FindRunByIDFn: func(ctx context.Context, taskID platform.ID, runID platform.ID) (*influxdb.Run, error) { FindRunByIDFn: func(ctx context.Context, taskID platform.ID, runID platform.ID) (*taskmodel.Run, error) {
scheduledFor, _ := time.Parse(time.RFC3339, "2018-12-01T17:00:13Z") scheduledFor, _ := time.Parse(time.RFC3339, "2018-12-01T17:00:13Z")
startedAt, _ := time.Parse(time.RFC3339Nano, "2018-12-01T17:00:03.155645Z") startedAt, _ := time.Parse(time.RFC3339Nano, "2018-12-01T17:00:03.155645Z")
finishedAt, _ := time.Parse(time.RFC3339Nano, "2018-12-01T17:00:13.155645Z") finishedAt, _ := time.Parse(time.RFC3339Nano, "2018-12-01T17:00:13.155645Z")
requestedAt, _ := time.Parse(time.RFC3339, "2018-12-01T17:00:13Z") requestedAt, _ := time.Parse(time.RFC3339, "2018-12-01T17:00:13Z")
run := influxdb.Run{ run := taskmodel.Run{
ID: runID, ID: runID,
TaskID: taskID, TaskID: taskID,
Status: "success", Status: "success",
@ -705,7 +705,7 @@ func TestTaskHandler_handleGetRun(t *testing.T) {
func TestTaskHandler_handleGetRuns(t *testing.T) { func TestTaskHandler_handleGetRuns(t *testing.T) {
type fields struct { type fields struct {
taskService influxdb.TaskService taskService taskmodel.TaskService
} }
type args struct { type args struct {
taskID platform.ID taskID platform.ID
@ -726,12 +726,12 @@ func TestTaskHandler_handleGetRuns(t *testing.T) {
name: "get runs by task id", name: "get runs by task id",
fields: fields{ fields: fields{
taskService: &mock.TaskService{ taskService: &mock.TaskService{
FindRunsFn: func(ctx context.Context, f influxdb.RunFilter) ([]*influxdb.Run, int, error) { FindRunsFn: func(ctx context.Context, f taskmodel.RunFilter) ([]*taskmodel.Run, int, error) {
scheduledFor, _ := time.Parse(time.RFC3339, "2018-12-01T17:00:13Z") scheduledFor, _ := time.Parse(time.RFC3339, "2018-12-01T17:00:13Z")
startedAt, _ := time.Parse(time.RFC3339Nano, "2018-12-01T17:00:03.155645Z") startedAt, _ := time.Parse(time.RFC3339Nano, "2018-12-01T17:00:03.155645Z")
finishedAt, _ := time.Parse(time.RFC3339Nano, "2018-12-01T17:00:13.155645Z") finishedAt, _ := time.Parse(time.RFC3339Nano, "2018-12-01T17:00:13.155645Z")
requestedAt, _ := time.Parse(time.RFC3339, "2018-12-01T17:00:13Z") requestedAt, _ := time.Parse(time.RFC3339, "2018-12-01T17:00:13Z")
runs := []*influxdb.Run{ runs := []*taskmodel.Run{
{ {
ID: platform.ID(2), ID: platform.ID(2),
TaskID: f.Task, TaskID: f.Task,
@ -875,12 +875,12 @@ func TestTaskHandler_NotFoundStatus(t *testing.T) {
{ {
name: "get task", name: "get task",
svc: &mock.TaskService{ svc: &mock.TaskService{
FindTaskByIDFn: func(_ context.Context, id platform.ID) (*influxdb.Task, error) { FindTaskByIDFn: func(_ context.Context, id platform.ID) (*taskmodel.Task, error) {
if id == taskID { if id == taskID {
return &influxdb.Task{ID: taskID, Organization: "o"}, nil return &taskmodel.Task{ID: taskID, Organization: "o"}, nil
} }
return nil, influxdb.ErrTaskNotFound return nil, taskmodel.ErrTaskNotFound
}, },
}, },
method: http.MethodGet, method: http.MethodGet,
@ -891,12 +891,12 @@ func TestTaskHandler_NotFoundStatus(t *testing.T) {
{ {
name: "update task", name: "update task",
svc: &mock.TaskService{ svc: &mock.TaskService{
UpdateTaskFn: func(_ context.Context, id platform.ID, _ influxdb.TaskUpdate) (*influxdb.Task, error) { UpdateTaskFn: func(_ context.Context, id platform.ID, _ taskmodel.TaskUpdate) (*taskmodel.Task, error) {
if id == taskID { if id == taskID {
return &influxdb.Task{ID: taskID, Organization: "o"}, nil return &taskmodel.Task{ID: taskID, Organization: "o"}, nil
} }
return nil, influxdb.ErrTaskNotFound return nil, taskmodel.ErrTaskNotFound
}, },
}, },
method: http.MethodPatch, method: http.MethodPatch,
@ -913,7 +913,7 @@ func TestTaskHandler_NotFoundStatus(t *testing.T) {
return nil return nil
} }
return influxdb.ErrTaskNotFound return taskmodel.ErrTaskNotFound
}, },
}, },
method: http.MethodDelete, method: http.MethodDelete,
@ -924,12 +924,12 @@ func TestTaskHandler_NotFoundStatus(t *testing.T) {
{ {
name: "get task logs", name: "get task logs",
svc: &mock.TaskService{ svc: &mock.TaskService{
FindLogsFn: func(_ context.Context, f influxdb.LogFilter) ([]*influxdb.Log, int, error) { FindLogsFn: func(_ context.Context, f taskmodel.LogFilter) ([]*taskmodel.Log, int, error) {
if f.Task == taskID { if f.Task == taskID {
return nil, 0, nil return nil, 0, nil
} }
return nil, 0, influxdb.ErrTaskNotFound return nil, 0, taskmodel.ErrTaskNotFound
}, },
}, },
method: http.MethodGet, method: http.MethodGet,
@ -940,12 +940,12 @@ func TestTaskHandler_NotFoundStatus(t *testing.T) {
{ {
name: "get run logs", name: "get run logs",
svc: &mock.TaskService{ svc: &mock.TaskService{
FindLogsFn: func(_ context.Context, f influxdb.LogFilter) ([]*influxdb.Log, int, error) { FindLogsFn: func(_ context.Context, f taskmodel.LogFilter) ([]*taskmodel.Log, int, error) {
if f.Task != taskID { if f.Task != taskID {
return nil, 0, influxdb.ErrTaskNotFound return nil, 0, taskmodel.ErrTaskNotFound
} }
if *f.Run != runID { if *f.Run != runID {
return nil, 0, influxdb.ErrNoRunsFound return nil, 0, taskmodel.ErrNoRunsFound
} }
return nil, 0, nil return nil, 0, nil
@ -959,9 +959,9 @@ func TestTaskHandler_NotFoundStatus(t *testing.T) {
{ {
name: "get runs: task not found", name: "get runs: task not found",
svc: &mock.TaskService{ svc: &mock.TaskService{
FindRunsFn: func(_ context.Context, f influxdb.RunFilter) ([]*influxdb.Run, int, error) { FindRunsFn: func(_ context.Context, f taskmodel.RunFilter) ([]*taskmodel.Run, int, error) {
if f.Task != taskID { if f.Task != taskID {
return nil, 0, influxdb.ErrTaskNotFound return nil, 0, taskmodel.ErrTaskNotFound
} }
return nil, 0, nil return nil, 0, nil
@ -975,9 +975,9 @@ func TestTaskHandler_NotFoundStatus(t *testing.T) {
{ {
name: "get runs: task found but no runs found", name: "get runs: task found but no runs found",
svc: &mock.TaskService{ svc: &mock.TaskService{
FindRunsFn: func(_ context.Context, f influxdb.RunFilter) ([]*influxdb.Run, int, error) { FindRunsFn: func(_ context.Context, f taskmodel.RunFilter) ([]*taskmodel.Run, int, error) {
if f.Task != taskID { if f.Task != taskID {
return nil, 0, influxdb.ErrNoRunsFound return nil, 0, taskmodel.ErrNoRunsFound
} }
return nil, 0, nil return nil, 0, nil
@ -991,12 +991,12 @@ func TestTaskHandler_NotFoundStatus(t *testing.T) {
{ {
name: "force run", name: "force run",
svc: &mock.TaskService{ svc: &mock.TaskService{
ForceRunFn: func(_ context.Context, tid platform.ID, _ int64) (*influxdb.Run, error) { ForceRunFn: func(_ context.Context, tid platform.ID, _ int64) (*taskmodel.Run, error) {
if tid != taskID { if tid != taskID {
return nil, influxdb.ErrTaskNotFound return nil, taskmodel.ErrTaskNotFound
} }
return &influxdb.Run{ID: runID, TaskID: taskID, Status: influxdb.RunScheduled.String()}, nil return &taskmodel.Run{ID: runID, TaskID: taskID, Status: taskmodel.RunScheduled.String()}, nil
}, },
}, },
method: http.MethodPost, method: http.MethodPost,
@ -1008,15 +1008,15 @@ func TestTaskHandler_NotFoundStatus(t *testing.T) {
{ {
name: "get run", name: "get run",
svc: &mock.TaskService{ svc: &mock.TaskService{
FindRunByIDFn: func(_ context.Context, tid, rid platform.ID) (*influxdb.Run, error) { FindRunByIDFn: func(_ context.Context, tid, rid platform.ID) (*taskmodel.Run, error) {
if tid != taskID { if tid != taskID {
return nil, influxdb.ErrTaskNotFound return nil, taskmodel.ErrTaskNotFound
} }
if rid != runID { if rid != runID {
return nil, influxdb.ErrRunNotFound return nil, taskmodel.ErrRunNotFound
} }
return &influxdb.Run{ID: runID, TaskID: taskID, Status: influxdb.RunScheduled.String()}, nil return &taskmodel.Run{ID: runID, TaskID: taskID, Status: taskmodel.RunScheduled.String()}, nil
}, },
}, },
method: http.MethodGet, method: http.MethodGet,
@ -1027,15 +1027,15 @@ func TestTaskHandler_NotFoundStatus(t *testing.T) {
{ {
name: "retry run", name: "retry run",
svc: &mock.TaskService{ svc: &mock.TaskService{
RetryRunFn: func(_ context.Context, tid, rid platform.ID) (*influxdb.Run, error) { RetryRunFn: func(_ context.Context, tid, rid platform.ID) (*taskmodel.Run, error) {
if tid != taskID { if tid != taskID {
return nil, influxdb.ErrTaskNotFound return nil, taskmodel.ErrTaskNotFound
} }
if rid != runID { if rid != runID {
return nil, influxdb.ErrRunNotFound return nil, taskmodel.ErrRunNotFound
} }
return &influxdb.Run{ID: runID, TaskID: taskID, Status: influxdb.RunScheduled.String()}, nil return &taskmodel.Run{ID: runID, TaskID: taskID, Status: taskmodel.RunScheduled.String()}, nil
}, },
}, },
method: http.MethodPost, method: http.MethodPost,
@ -1048,10 +1048,10 @@ func TestTaskHandler_NotFoundStatus(t *testing.T) {
svc: &mock.TaskService{ svc: &mock.TaskService{
CancelRunFn: func(_ context.Context, tid, rid platform.ID) error { CancelRunFn: func(_ context.Context, tid, rid platform.ID) error {
if tid != taskID { if tid != taskID {
return influxdb.ErrTaskNotFound return taskmodel.ErrTaskNotFound
} }
if rid != runID { if rid != runID {
return influxdb.ErrRunNotFound return taskmodel.ErrRunNotFound
} }
return nil return nil
@ -1252,12 +1252,12 @@ func TestTaskHandler_CreateTaskWithOrgName(t *testing.T) {
} }
taskSvc := &mock.TaskService{ taskSvc := &mock.TaskService{
CreateTaskFn: func(_ context.Context, tc influxdb.TaskCreate) (*influxdb.Task, error) { CreateTaskFn: func(_ context.Context, tc taskmodel.TaskCreate) (*taskmodel.Task, error) {
if tc.OrganizationID != o.ID { if tc.OrganizationID != o.ID {
t.Fatalf("expected task to be created with org ID %s, got %s", o.ID, tc.OrganizationID) t.Fatalf("expected task to be created with org ID %s, got %s", o.ID, tc.OrganizationID)
} }
return &influxdb.Task{ID: 9, OrganizationID: o.ID, OwnerID: o.ID, Name: "x", Flux: tc.Flux}, nil return &taskmodel.Task{ID: 9, OrganizationID: o.ID, OwnerID: o.ID, Name: "x", Flux: tc.Flux}, nil
}, },
} }
@ -1278,7 +1278,7 @@ func TestTaskHandler_CreateTaskWithOrgName(t *testing.T) {
url := "http://localhost:8086/api/v2/tasks" url := "http://localhost:8086/api/v2/tasks"
b, err := json.Marshal(influxdb.TaskCreate{ b, err := json.Marshal(taskmodel.TaskCreate{
Flux: script, Flux: script,
Organization: o.Name, Organization: o.Name,
}) })
@ -1305,7 +1305,7 @@ func TestTaskHandler_CreateTaskWithOrgName(t *testing.T) {
} }
// The task should have been created with a valid token. // The task should have been created with a valid token.
var createdTask influxdb.Task var createdTask taskmodel.Task
if err := json.Unmarshal([]byte(body), &createdTask); err != nil { if err := json.Unmarshal([]byte(body), &createdTask); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -1399,23 +1399,23 @@ func TestTaskHandler_Sessions(t *testing.T) {
var findRunsCtx context.Context var findRunsCtx context.Context
ts := &mock.TaskService{ ts := &mock.TaskService{
FindRunsFn: func(ctx context.Context, f influxdb.RunFilter) ([]*influxdb.Run, int, error) { FindRunsFn: func(ctx context.Context, f taskmodel.RunFilter) ([]*taskmodel.Run, int, error) {
findRunsCtx = ctx findRunsCtx = ctx
if f.Task != taskID { if f.Task != taskID {
t.Fatalf("expected task ID %v, got %v", taskID, f.Task) t.Fatalf("expected task ID %v, got %v", taskID, f.Task)
} }
return []*influxdb.Run{ return []*taskmodel.Run{
{ID: runID, TaskID: taskID}, {ID: runID, TaskID: taskID},
}, 1, nil }, 1, nil
}, },
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*influxdb.Task, error) { FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*taskmodel.Task, error) {
if id != taskID { if id != taskID {
return nil, influxdb.ErrTaskNotFound return nil, taskmodel.ErrTaskNotFound
} }
return &influxdb.Task{ return &taskmodel.Task{
ID: taskID, ID: taskID,
OrganizationID: o.ID, OrganizationID: o.ID,
}, nil }, nil
@ -1491,7 +1491,7 @@ func TestTaskHandler_Sessions(t *testing.T) {
var findRunByIDCtx context.Context var findRunByIDCtx context.Context
ts := &mock.TaskService{ ts := &mock.TaskService{
FindRunByIDFn: func(ctx context.Context, tid, rid platform.ID) (*influxdb.Run, error) { FindRunByIDFn: func(ctx context.Context, tid, rid platform.ID) (*taskmodel.Run, error) {
findRunByIDCtx = ctx findRunByIDCtx = ctx
if tid != taskID { if tid != taskID {
t.Fatalf("expected task ID %v, got %v", taskID, tid) t.Fatalf("expected task ID %v, got %v", taskID, tid)
@ -1500,15 +1500,15 @@ func TestTaskHandler_Sessions(t *testing.T) {
t.Fatalf("expected run ID %v, got %v", runID, rid) t.Fatalf("expected run ID %v, got %v", runID, rid)
} }
return &influxdb.Run{ID: runID, TaskID: taskID}, nil return &taskmodel.Run{ID: runID, TaskID: taskID}, nil
}, },
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*influxdb.Task, error) { FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*taskmodel.Task, error) {
if id != taskID { if id != taskID {
return nil, influxdb.ErrTaskNotFound return nil, taskmodel.ErrTaskNotFound
} }
return &influxdb.Task{ return &taskmodel.Task{
ID: taskID, ID: taskID,
OrganizationID: o.ID, OrganizationID: o.ID,
}, nil }, nil
@ -1585,7 +1585,7 @@ func TestTaskHandler_Sessions(t *testing.T) {
var findLogsCtx context.Context var findLogsCtx context.Context
ts := &mock.TaskService{ ts := &mock.TaskService{
FindLogsFn: func(ctx context.Context, f influxdb.LogFilter) ([]*influxdb.Log, int, error) { FindLogsFn: func(ctx context.Context, f taskmodel.LogFilter) ([]*taskmodel.Log, int, error) {
findLogsCtx = ctx findLogsCtx = ctx
if f.Task != taskID { if f.Task != taskID {
t.Fatalf("expected task ID %v, got %v", taskID, f.Task) t.Fatalf("expected task ID %v, got %v", taskID, f.Task)
@ -1594,16 +1594,16 @@ func TestTaskHandler_Sessions(t *testing.T) {
t.Fatalf("expected run ID %v, got %v", runID, *f.Run) t.Fatalf("expected run ID %v, got %v", runID, *f.Run)
} }
line := influxdb.Log{Time: "time", Message: "a log line"} line := taskmodel.Log{Time: "time", Message: "a log line"}
return []*influxdb.Log{&line}, 1, nil return []*taskmodel.Log{&line}, 1, nil
}, },
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*influxdb.Task, error) { FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*taskmodel.Task, error) {
if id != taskID { if id != taskID {
return nil, influxdb.ErrTaskNotFound return nil, taskmodel.ErrTaskNotFound
} }
return &influxdb.Task{ return &taskmodel.Task{
ID: taskID, ID: taskID,
OrganizationID: o.ID, OrganizationID: o.ID,
}, nil }, nil
@ -1680,7 +1680,7 @@ func TestTaskHandler_Sessions(t *testing.T) {
var retryRunCtx context.Context var retryRunCtx context.Context
ts := &mock.TaskService{ ts := &mock.TaskService{
RetryRunFn: func(ctx context.Context, tid, rid platform.ID) (*influxdb.Run, error) { RetryRunFn: func(ctx context.Context, tid, rid platform.ID) (*taskmodel.Run, error) {
retryRunCtx = ctx retryRunCtx = ctx
if tid != taskID { if tid != taskID {
t.Fatalf("expected task ID %v, got %v", taskID, tid) t.Fatalf("expected task ID %v, got %v", taskID, tid)
@ -1689,15 +1689,15 @@ func TestTaskHandler_Sessions(t *testing.T) {
t.Fatalf("expected run ID %v, got %v", runID, rid) t.Fatalf("expected run ID %v, got %v", runID, rid)
} }
return &influxdb.Run{ID: 10 * runID, TaskID: taskID}, nil return &taskmodel.Run{ID: 10 * runID, TaskID: taskID}, nil
}, },
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*influxdb.Task, error) { FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*taskmodel.Task, error) {
if id != taskID { if id != taskID {
return nil, influxdb.ErrTaskNotFound return nil, taskmodel.ErrTaskNotFound
} }
return &influxdb.Task{ return &taskmodel.Task{
ID: taskID, ID: taskID,
OrganizationID: o.ID, OrganizationID: o.ID,
}, nil }, nil

View File

@ -4,10 +4,10 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/platform" "github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/kit/platform/errors" "github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"github.com/influxdata/influxdb/v2"
) )
// Resolver is a type which combines multiple resource services // Resolver is a type which combines multiple resource services
@ -32,7 +32,7 @@ type Resolver struct {
FindSourceByID(context.Context, platform.ID) (*influxdb.Source, error) FindSourceByID(context.Context, platform.ID) (*influxdb.Source, error)
} }
TaskFinder interface { TaskFinder interface {
FindTaskByID(context.Context, platform.ID) (*influxdb.Task, error) FindTaskByID(context.Context, platform.ID) (*taskmodel.Task, error)
} }
TelegrafConfigFinder interface { TelegrafConfigFinder interface {
FindTelegrafConfigByID(context.Context, platform.ID) (*influxdb.TelegrafConfig, error) FindTelegrafConfigByID(context.Context, platform.ID) (*influxdb.TelegrafConfig, error)

View File

@ -5,11 +5,11 @@ import (
"encoding/json" "encoding/json"
"time" "time"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/platform" "github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/kit/platform/errors" "github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kv" "github.com/influxdata/influxdb/v2/kv"
"github.com/influxdata/influxdb/v2/task/taskmodel"
) )
var taskBucket = []byte("tasksv1") var taskBucket = []byte("tasksv1")
@ -18,23 +18,23 @@ var taskBucket = []byte("tasksv1")
var Migration0003_TaskOwnerIDUpMigration = UpOnlyMigration( var Migration0003_TaskOwnerIDUpMigration = UpOnlyMigration(
"migrate task owner id", "migrate task owner id",
func(ctx context.Context, store kv.SchemaStore) error { func(ctx context.Context, store kv.SchemaStore) error {
var ownerlessTasks []*influxdb.Task var ownerlessTasks []*taskmodel.Task
// loop through the tasks and collect a set of tasks that are missing the owner id. // loop through the tasks and collect a set of tasks that are missing the owner id.
err := store.View(ctx, func(tx kv.Tx) error { err := store.View(ctx, func(tx kv.Tx) error {
taskBucket, err := tx.Bucket(taskBucket) taskBucket, err := tx.Bucket(taskBucket)
if err != nil { if err != nil {
return influxdb.ErrUnexpectedTaskBucketErr(err) return taskmodel.ErrUnexpectedTaskBucketErr(err)
} }
c, err := taskBucket.ForwardCursor([]byte{}) c, err := taskBucket.ForwardCursor([]byte{})
if err != nil { if err != nil {
return influxdb.ErrUnexpectedTaskBucketErr(err) return taskmodel.ErrUnexpectedTaskBucketErr(err)
} }
for k, v := c.Next(); k != nil; k, v = c.Next() { for k, v := c.Next(); k != nil; k, v = c.Next() {
kvTask := &kvTask{} kvTask := &kvTask{}
if err := json.Unmarshal(v, kvTask); err != nil { if err := json.Unmarshal(v, kvTask); err != nil {
return influxdb.ErrInternalTaskServiceError(err) return taskmodel.ErrInternalTaskServiceError(err)
} }
t := kvToInfluxTask(kvTask) t := kvToInfluxTask(kvTask)
@ -63,19 +63,19 @@ var Migration0003_TaskOwnerIDUpMigration = UpOnlyMigration(
} }
b, err := tx.Bucket(taskBucket) b, err := tx.Bucket(taskBucket)
if err != nil { if err != nil {
return influxdb.ErrUnexpectedTaskBucketErr(err) return taskmodel.ErrUnexpectedTaskBucketErr(err)
} }
if !t.OwnerID.Valid() { if !t.OwnerID.Valid() {
v, err := b.Get(taskKey) v, err := b.Get(taskKey)
if kv.IsNotFound(err) { if kv.IsNotFound(err) {
return influxdb.ErrTaskNotFound return taskmodel.ErrTaskNotFound
} }
authType := struct { authType := struct {
AuthorizationID platform.ID `json:"authorizationID"` AuthorizationID platform.ID `json:"authorizationID"`
}{} }{}
if err := json.Unmarshal(v, &authType); err != nil { if err := json.Unmarshal(v, &authType); err != nil {
return influxdb.ErrInternalTaskServiceError(err) return taskmodel.ErrInternalTaskServiceError(err)
} }
// try populating the owner from auth // try populating the owner from auth
@ -143,12 +143,12 @@ var Migration0003_TaskOwnerIDUpMigration = UpOnlyMigration(
// save task // save task
taskBytes, err := json.Marshal(t) taskBytes, err := json.Marshal(t)
if err != nil { if err != nil {
return influxdb.ErrInternalTaskServiceError(err) return taskmodel.ErrInternalTaskServiceError(err)
} }
err = b.Put(taskKey, taskBytes) err = b.Put(taskKey, taskBytes)
if err != nil { if err != nil {
return influxdb.ErrUnexpectedTaskBucketErr(err) return taskmodel.ErrUnexpectedTaskBucketErr(err)
} }
return nil return nil
}) })
@ -182,8 +182,8 @@ type kvTask struct {
Metadata map[string]interface{} `json:"metadata,omitempty"` Metadata map[string]interface{} `json:"metadata,omitempty"`
} }
func kvToInfluxTask(k *kvTask) *influxdb.Task { func kvToInfluxTask(k *kvTask) *taskmodel.Task {
return &influxdb.Task{ return &taskmodel.Task{
ID: k.ID, ID: k.ID,
Type: k.Type, Type: k.Type,
OrganizationID: k.OrganizationID, OrganizationID: k.OrganizationID,
@ -209,7 +209,7 @@ func kvToInfluxTask(k *kvTask) *influxdb.Task {
func taskKey(taskID platform.ID) ([]byte, error) { func taskKey(taskID platform.ID) ([]byte, error) {
encodedID, err := taskID.Encode() encodedID, err := taskID.Encode()
if err != nil { if err != nil {
return nil, influxdb.ErrInvalidTaskID return nil, taskmodel.ErrInvalidTaskID
} }
return encodedID, nil return encodedID, nil
} }

View File

@ -4,6 +4,7 @@ import (
"github.com/benbjohnson/clock" "github.com/benbjohnson/clock"
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/platform" "github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/query/fluxlang"
"github.com/influxdata/influxdb/v2/rand" "github.com/influxdata/influxdb/v2/rand"
"github.com/influxdata/influxdb/v2/resource" "github.com/influxdata/influxdb/v2/resource"
"github.com/influxdata/influxdb/v2/resource/noop" "github.com/influxdata/influxdb/v2/resource/noop"
@ -26,7 +27,7 @@ type Service struct {
// FluxLanguageService is used for parsing flux. // FluxLanguageService is used for parsing flux.
// If this is unset, operations that require parsing flux // If this is unset, operations that require parsing flux
// will fail. // will fail.
FluxLanguageService influxdb.FluxLanguageService FluxLanguageService fluxlang.FluxLanguageService
TokenGenerator influxdb.TokenGenerator TokenGenerator influxdb.TokenGenerator
// TODO(desa:ariel): this should not be embedded // TODO(desa:ariel): this should not be embedded
@ -67,7 +68,7 @@ func NewService(log *zap.Logger, kv Store, orgs influxdb.OrganizationService, co
// ServiceConfig allows us to configure Services // ServiceConfig allows us to configure Services
type ServiceConfig struct { type ServiceConfig struct {
Clock clock.Clock Clock clock.Clock
FluxLanguageService influxdb.FluxLanguageService FluxLanguageService fluxlang.FluxLanguageService
} }
// WithResourceLogger sets the resource audit logger for the service. // WithResourceLogger sets the resource audit logger for the service.

File diff suppressed because it is too large Load Diff

View File

@ -3,15 +3,15 @@ package kv
import ( import (
"testing" "testing"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/task/taskmodel"
) )
func Test_newTaskMatchFN(t *testing.T) { func Test_newTaskMatchFN(t *testing.T) {
ct := func(typ string, name string) *influxdb.Task { ct := func(typ string, name string) *taskmodel.Task {
return &influxdb.Task{ return &taskmodel.Task{
Type: typ, Type: typ,
OrganizationID: 1, OrganizationID: 1,
Name: name, Name: name,
@ -27,7 +27,7 @@ func Test_newTaskMatchFN(t *testing.T) {
newMatch := func(orgID platform.ID, typ string, name string) taskMatchFn { newMatch := func(orgID platform.ID, typ string, name string) taskMatchFn {
var ( var (
org *influxdb.Organization org *influxdb.Organization
fil influxdb.TaskFilter fil taskmodel.TaskFilter
) )
if orgID != NoOrg { if orgID != NoOrg {
@ -47,7 +47,7 @@ func Test_newTaskMatchFN(t *testing.T) {
type test struct { type test struct {
name string name string
task *influxdb.Task task *taskmodel.Task
fn taskMatchFn fn taskMatchFn
exp bool exp bool
} }
@ -61,13 +61,13 @@ func Test_newTaskMatchFN(t *testing.T) {
[]test{ []test{
{ {
name: "equal", name: "equal",
task: ct(influxdb.TaskSystemType, "Foo"), task: ct(taskmodel.TaskSystemType, "Foo"),
fn: newMatch(1, NoTyp, NoNam), fn: newMatch(1, NoTyp, NoNam),
exp: true, exp: true,
}, },
{ {
name: "not org", name: "not org",
task: ct(influxdb.TaskSystemType, "Foo"), task: ct(taskmodel.TaskSystemType, "Foo"),
fn: newMatch(2, NoTyp, NoNam), fn: newMatch(2, NoTyp, NoNam),
exp: false, exp: false,
}, },
@ -79,13 +79,13 @@ func Test_newTaskMatchFN(t *testing.T) {
{ {
name: "empty with system type", name: "empty with system type",
task: ct("", "Foo"), task: ct("", "Foo"),
fn: newMatch(NoOrg, influxdb.TaskSystemType, NoNam), fn: newMatch(NoOrg, taskmodel.TaskSystemType, NoNam),
exp: true, exp: true,
}, },
{ {
name: "system with system type", name: "system with system type",
task: ct(influxdb.TaskSystemType, "Foo"), task: ct(taskmodel.TaskSystemType, "Foo"),
fn: newMatch(NoOrg, influxdb.TaskSystemType, NoNam), fn: newMatch(NoOrg, taskmodel.TaskSystemType, NoNam),
exp: true, exp: true,
}, },
{ {
@ -96,7 +96,7 @@ func Test_newTaskMatchFN(t *testing.T) {
}, },
{ {
name: "not type", name: "not type",
task: ct(influxdb.TaskSystemType, "Foo"), task: ct(taskmodel.TaskSystemType, "Foo"),
fn: newMatch(NoOrg, "other type", NoNam), fn: newMatch(NoOrg, "other type", NoNam),
exp: false, exp: false,
}, },
@ -107,13 +107,13 @@ func Test_newTaskMatchFN(t *testing.T) {
[]test{ []test{
{ {
name: "equal", name: "equal",
task: ct(influxdb.TaskSystemType, "Foo"), task: ct(taskmodel.TaskSystemType, "Foo"),
fn: newMatch(NoOrg, NoTyp, "Foo"), fn: newMatch(NoOrg, NoTyp, "Foo"),
exp: true, exp: true,
}, },
{ {
name: "not name", name: "not name",
task: ct(influxdb.TaskSystemType, "Foo"), task: ct(taskmodel.TaskSystemType, "Foo"),
fn: newMatch(NoOrg, NoTyp, "Bar"), fn: newMatch(NoOrg, NoTyp, "Bar"),
exp: false, exp: false,
}, },
@ -124,26 +124,26 @@ func Test_newTaskMatchFN(t *testing.T) {
[]test{ []test{
{ {
name: "equal", name: "equal",
task: ct(influxdb.TaskSystemType, "Foo"), task: ct(taskmodel.TaskSystemType, "Foo"),
fn: newMatch(1, influxdb.TaskSystemType, NoNam), fn: newMatch(1, taskmodel.TaskSystemType, NoNam),
exp: true, exp: true,
}, },
{ {
name: "not type", name: "not type",
task: ct(influxdb.TaskSystemType, "Foo"), task: ct(taskmodel.TaskSystemType, "Foo"),
fn: newMatch(1, "wrong type", NoNam), fn: newMatch(1, "wrong type", NoNam),
exp: false, exp: false,
}, },
{ {
name: "not org", name: "not org",
task: ct(influxdb.TaskSystemType, "Foo"), task: ct(taskmodel.TaskSystemType, "Foo"),
fn: newMatch(2, influxdb.TaskSystemType, NoNam), fn: newMatch(2, taskmodel.TaskSystemType, NoNam),
exp: false, exp: false,
}, },
{ {
name: "not org and type", name: "not org and type",
task: ct("check", "Foo"), task: ct("check", "Foo"),
fn: newMatch(2, influxdb.TaskSystemType, NoNam), fn: newMatch(2, taskmodel.TaskSystemType, NoNam),
exp: false, exp: false,
}, },
}, },
@ -153,13 +153,13 @@ func Test_newTaskMatchFN(t *testing.T) {
[]test{ []test{
{ {
name: "equal", name: "equal",
task: ct(influxdb.TaskSystemType, "Foo"), task: ct(taskmodel.TaskSystemType, "Foo"),
fn: newMatch(1, NoTyp, "Foo"), fn: newMatch(1, NoTyp, "Foo"),
exp: true, exp: true,
}, },
{ {
name: "not org", name: "not org",
task: ct(influxdb.TaskSystemType, "Foo"), task: ct(taskmodel.TaskSystemType, "Foo"),
fn: newMatch(2, NoTyp, "Foo"), fn: newMatch(2, NoTyp, "Foo"),
exp: false, exp: false,
}, },
@ -208,7 +208,7 @@ func Test_newTaskMatchFN(t *testing.T) {
} }
t.Run("match returns nil for no filter", func(t *testing.T) { t.Run("match returns nil for no filter", func(t *testing.T) {
fn := newTaskMatchFn(influxdb.TaskFilter{}, nil) fn := newTaskMatchFn(taskmodel.TaskFilter{}, nil)
if fn != nil { if fn != nil {
t.Error("expected nil") t.Error("expected nil")
} }

View File

@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"context" "context"
"encoding/json" "encoding/json"
"github.com/influxdata/influxdb/v2/kit/platform"
"testing" "testing"
"time" "time"
@ -14,10 +13,12 @@ import (
"github.com/influxdata/influxdb/v2/authorization" "github.com/influxdata/influxdb/v2/authorization"
icontext "github.com/influxdata/influxdb/v2/context" icontext "github.com/influxdata/influxdb/v2/context"
_ "github.com/influxdata/influxdb/v2/fluxinit/static" _ "github.com/influxdata/influxdb/v2/fluxinit/static"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/kv" "github.com/influxdata/influxdb/v2/kv"
"github.com/influxdata/influxdb/v2/query/fluxlang" "github.com/influxdata/influxdb/v2/query/fluxlang"
"github.com/influxdata/influxdb/v2/task/options" "github.com/influxdata/influxdb/v2/task/options"
"github.com/influxdata/influxdb/v2/task/servicetest" "github.com/influxdata/influxdb/v2/task/servicetest"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"github.com/influxdata/influxdb/v2/tenant" "github.com/influxdata/influxdb/v2/tenant"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@ -150,11 +151,11 @@ func TestRetrieveTaskWithBadAuth(t *testing.T) {
ctx = icontext.SetAuthorizer(ctx, &ts.Auth) ctx = icontext.SetAuthorizer(ctx, &ts.Auth)
task, err := ts.Service.CreateTask(ctx, influxdb.TaskCreate{ task, err := ts.Service.CreateTask(ctx, taskmodel.TaskCreate{
Flux: `option task = {name: "a task",every: 1h} from(bucket:"test") |> range(start:-1h)`, Flux: `option task = {name: "a task",every: 1h} from(bucket:"test") |> range(start:-1h)`,
OrganizationID: ts.Org.ID, OrganizationID: ts.Org.ID,
OwnerID: ts.User.ID, OwnerID: ts.User.ID,
Status: string(influxdb.TaskActive), Status: string(taskmodel.TaskActive),
}) })
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -196,7 +197,7 @@ func TestRetrieveTaskWithBadAuth(t *testing.T) {
t.Fatal("miss matching taskID's") t.Fatal("miss matching taskID's")
} }
tasks, _, err := ts.Service.FindTasks(context.Background(), influxdb.TaskFilter{}) tasks, _, err := ts.Service.FindTasks(context.Background(), taskmodel.TaskFilter{})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -205,8 +206,8 @@ func TestRetrieveTaskWithBadAuth(t *testing.T) {
} }
// test status filter // test status filter
active := string(influxdb.TaskActive) active := string(taskmodel.TaskActive)
tasksWithActiveFilter, _, err := ts.Service.FindTasks(context.Background(), influxdb.TaskFilter{Status: &active}) tasksWithActiveFilter, _, err := ts.Service.FindTasks(context.Background(), taskmodel.TaskFilter{Status: &active})
if err != nil { if err != nil {
t.Fatal("could not find tasks") t.Fatal("could not find tasks")
} }
@ -227,20 +228,20 @@ func TestService_UpdateTask_InactiveToActive(t *testing.T) {
ctx = icontext.SetAuthorizer(ctx, &ts.Auth) ctx = icontext.SetAuthorizer(ctx, &ts.Auth)
originalTask, err := ts.Service.CreateTask(ctx, influxdb.TaskCreate{ originalTask, err := ts.Service.CreateTask(ctx, taskmodel.TaskCreate{
Flux: `option task = {name: "a task",every: 1h} from(bucket:"test") |> range(start:-1h)`, Flux: `option task = {name: "a task",every: 1h} from(bucket:"test") |> range(start:-1h)`,
OrganizationID: ts.Org.ID, OrganizationID: ts.Org.ID,
OwnerID: ts.User.ID, OwnerID: ts.User.ID,
Status: string(influxdb.TaskActive), Status: string(taskmodel.TaskActive),
}) })
if err != nil { if err != nil {
t.Fatal("CreateTask", err) t.Fatal("CreateTask", err)
} }
v := influxdb.TaskStatusInactive v := taskmodel.TaskStatusInactive
c.Add(1 * time.Second) c.Add(1 * time.Second)
exp := c.Now() exp := c.Now()
updatedTask, err := ts.Service.UpdateTask(ctx, originalTask.ID, influxdb.TaskUpdate{Status: &v, LatestCompleted: &exp, LatestScheduled: &exp}) updatedTask, err := ts.Service.UpdateTask(ctx, originalTask.ID, taskmodel.TaskUpdate{Status: &v, LatestCompleted: &exp, LatestScheduled: &exp})
if err != nil { if err != nil {
t.Fatal("UpdateTask", err) t.Fatal("UpdateTask", err)
} }
@ -254,8 +255,8 @@ func TestService_UpdateTask_InactiveToActive(t *testing.T) {
c.Add(10 * time.Second) c.Add(10 * time.Second)
exp = c.Now() exp = c.Now()
v = influxdb.TaskStatusActive v = taskmodel.TaskStatusActive
updatedTask, err = ts.Service.UpdateTask(ctx, originalTask.ID, influxdb.TaskUpdate{Status: &v}) updatedTask, err = ts.Service.UpdateTask(ctx, originalTask.ID, taskmodel.TaskUpdate{Status: &v})
if err != nil { if err != nil {
t.Fatal("UpdateTask", err) t.Fatal("UpdateTask", err)
} }
@ -315,7 +316,7 @@ func TestTaskRunCancellation(t *testing.T) {
ctx = icontext.SetAuthorizer(ctx, &authz) ctx = icontext.SetAuthorizer(ctx, &authz)
task, err := service.CreateTask(ctx, influxdb.TaskCreate{ task, err := service.CreateTask(ctx, taskmodel.TaskCreate{
Flux: `option task = {name: "a task",cron: "0 * * * *", offset: 20s} from(bucket:"test") |> range(start:-1h)`, Flux: `option task = {name: "a task",cron: "0 * * * *", offset: 20s} from(bucket:"test") |> range(start:-1h)`,
OrganizationID: o.ID, OrganizationID: o.ID,
OwnerID: u.ID, OwnerID: u.ID,
@ -338,7 +339,7 @@ func TestTaskRunCancellation(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
if canceled.Status != influxdb.RunCanceled.String() { if canceled.Status != taskmodel.RunCanceled.String() {
t.Fatalf("expected task run to be cancelled") t.Fatalf("expected task run to be cancelled")
} }
} }
@ -355,11 +356,11 @@ func TestService_UpdateTask_RecordLatestSuccessAndFailure(t *testing.T) {
ctx = icontext.SetAuthorizer(ctx, &ts.Auth) ctx = icontext.SetAuthorizer(ctx, &ts.Auth)
originalTask, err := ts.Service.CreateTask(ctx, influxdb.TaskCreate{ originalTask, err := ts.Service.CreateTask(ctx, taskmodel.TaskCreate{
Flux: `option task = {name: "a task",every: 1h} from(bucket:"test") |> range(start:-1h)`, Flux: `option task = {name: "a task",every: 1h} from(bucket:"test") |> range(start:-1h)`,
OrganizationID: ts.Org.ID, OrganizationID: ts.Org.ID,
OwnerID: ts.User.ID, OwnerID: ts.User.ID,
Status: string(influxdb.TaskActive), Status: string(taskmodel.TaskActive),
}) })
if err != nil { if err != nil {
t.Fatal("CreateTask", err) t.Fatal("CreateTask", err)
@ -367,7 +368,7 @@ func TestService_UpdateTask_RecordLatestSuccessAndFailure(t *testing.T) {
c.Add(1 * time.Second) c.Add(1 * time.Second)
exp := c.Now() exp := c.Now()
updatedTask, err := ts.Service.UpdateTask(ctx, originalTask.ID, influxdb.TaskUpdate{ updatedTask, err := ts.Service.UpdateTask(ctx, originalTask.ID, taskmodel.TaskUpdate{
LatestCompleted: &exp, LatestCompleted: &exp,
LatestScheduled: &exp, LatestScheduled: &exp,
@ -395,7 +396,7 @@ func TestService_UpdateTask_RecordLatestSuccessAndFailure(t *testing.T) {
c.Add(5 * time.Second) c.Add(5 * time.Second)
exp = c.Now() exp = c.Now()
updatedTask, err = ts.Service.UpdateTask(ctx, originalTask.ID, influxdb.TaskUpdate{ updatedTask, err = ts.Service.UpdateTask(ctx, originalTask.ID, taskmodel.TaskUpdate{
LatestCompleted: &exp, LatestCompleted: &exp,
LatestScheduled: &exp, LatestScheduled: &exp,

View File

@ -5,93 +5,92 @@ import (
"time" "time"
"github.com/influxdata/influxdb/v2/kit/platform" "github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/task/backend" "github.com/influxdata/influxdb/v2/task/backend"
"github.com/influxdata/influxdb/v2/task/taskmodel"
) )
var _ influxdb.TaskService = (*TaskService)(nil) var _ taskmodel.TaskService = (*TaskService)(nil)
var _ backend.TaskControlService = (*TaskControlService)(nil) var _ backend.TaskControlService = (*TaskControlService)(nil)
type TaskService struct { type TaskService struct {
FindTaskByIDFn func(context.Context, platform.ID) (*influxdb.Task, error) FindTaskByIDFn func(context.Context, platform.ID) (*taskmodel.Task, error)
FindTaskByIDCalls SafeCount FindTaskByIDCalls SafeCount
FindTasksFn func(context.Context, influxdb.TaskFilter) ([]*influxdb.Task, int, error) FindTasksFn func(context.Context, taskmodel.TaskFilter) ([]*taskmodel.Task, int, error)
FindTasksCalls SafeCount FindTasksCalls SafeCount
CreateTaskFn func(context.Context, influxdb.TaskCreate) (*influxdb.Task, error) CreateTaskFn func(context.Context, taskmodel.TaskCreate) (*taskmodel.Task, error)
CreateTaskCalls SafeCount CreateTaskCalls SafeCount
UpdateTaskFn func(context.Context, platform.ID, influxdb.TaskUpdate) (*influxdb.Task, error) UpdateTaskFn func(context.Context, platform.ID, taskmodel.TaskUpdate) (*taskmodel.Task, error)
UpdateTaskCalls SafeCount UpdateTaskCalls SafeCount
DeleteTaskFn func(context.Context, platform.ID) error DeleteTaskFn func(context.Context, platform.ID) error
DeleteTaskCalls SafeCount DeleteTaskCalls SafeCount
FindLogsFn func(context.Context, influxdb.LogFilter) ([]*influxdb.Log, int, error) FindLogsFn func(context.Context, taskmodel.LogFilter) ([]*taskmodel.Log, int, error)
FindLogsCalls SafeCount FindLogsCalls SafeCount
FindRunsFn func(context.Context, influxdb.RunFilter) ([]*influxdb.Run, int, error) FindRunsFn func(context.Context, taskmodel.RunFilter) ([]*taskmodel.Run, int, error)
FindRunsCalls SafeCount FindRunsCalls SafeCount
FindRunByIDFn func(context.Context, platform.ID, platform.ID) (*influxdb.Run, error) FindRunByIDFn func(context.Context, platform.ID, platform.ID) (*taskmodel.Run, error)
FindRunByIDCalls SafeCount FindRunByIDCalls SafeCount
CancelRunFn func(context.Context, platform.ID, platform.ID) error CancelRunFn func(context.Context, platform.ID, platform.ID) error
CancelRunCalls SafeCount CancelRunCalls SafeCount
RetryRunFn func(context.Context, platform.ID, platform.ID) (*influxdb.Run, error) RetryRunFn func(context.Context, platform.ID, platform.ID) (*taskmodel.Run, error)
RetryRunCalls SafeCount RetryRunCalls SafeCount
ForceRunFn func(context.Context, platform.ID, int64) (*influxdb.Run, error) ForceRunFn func(context.Context, platform.ID, int64) (*taskmodel.Run, error)
ForceRunCalls SafeCount ForceRunCalls SafeCount
} }
func NewTaskService() *TaskService { func NewTaskService() *TaskService {
return &TaskService{ return &TaskService{
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*influxdb.Task, error) { FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*taskmodel.Task, error) {
return nil, nil return nil, nil
}, },
FindTasksFn: func(ctx context.Context, f influxdb.TaskFilter) ([]*influxdb.Task, int, error) { FindTasksFn: func(ctx context.Context, f taskmodel.TaskFilter) ([]*taskmodel.Task, int, error) {
return nil, 0, nil return nil, 0, nil
}, },
CreateTaskFn: func(ctx context.Context, taskCreate influxdb.TaskCreate) (*influxdb.Task, error) { CreateTaskFn: func(ctx context.Context, taskCreate taskmodel.TaskCreate) (*taskmodel.Task, error) {
return nil, nil return nil, nil
}, },
UpdateTaskFn: func(ctx context.Context, id platform.ID, update influxdb.TaskUpdate) (*influxdb.Task, error) { UpdateTaskFn: func(ctx context.Context, id platform.ID, update taskmodel.TaskUpdate) (*taskmodel.Task, error) {
return nil, nil return nil, nil
}, },
DeleteTaskFn: func(ctx context.Context, id platform.ID) error { DeleteTaskFn: func(ctx context.Context, id platform.ID) error {
return nil return nil
}, },
FindLogsFn: func(ctx context.Context, f influxdb.LogFilter) ([]*influxdb.Log, int, error) { FindLogsFn: func(ctx context.Context, f taskmodel.LogFilter) ([]*taskmodel.Log, int, error) {
return nil, 0, nil return nil, 0, nil
}, },
FindRunsFn: func(ctx context.Context, f influxdb.RunFilter) ([]*influxdb.Run, int, error) { FindRunsFn: func(ctx context.Context, f taskmodel.RunFilter) ([]*taskmodel.Run, int, error) {
return nil, 0, nil return nil, 0, nil
}, },
FindRunByIDFn: func(ctx context.Context, id platform.ID, id2 platform.ID) (*influxdb.Run, error) { FindRunByIDFn: func(ctx context.Context, id platform.ID, id2 platform.ID) (*taskmodel.Run, error) {
return nil, nil return nil, nil
}, },
CancelRunFn: func(ctx context.Context, id platform.ID, id2 platform.ID) error { CancelRunFn: func(ctx context.Context, id platform.ID, id2 platform.ID) error {
return nil return nil
}, },
RetryRunFn: func(ctx context.Context, id platform.ID, id2 platform.ID) (*influxdb.Run, error) { RetryRunFn: func(ctx context.Context, id platform.ID, id2 platform.ID) (*taskmodel.Run, error) {
return nil, nil return nil, nil
}, },
ForceRunFn: func(ctx context.Context, id platform.ID, i int64) (*influxdb.Run, error) { ForceRunFn: func(ctx context.Context, id platform.ID, i int64) (*taskmodel.Run, error) {
return nil, nil return nil, nil
}, },
} }
} }
func (s *TaskService) FindTaskByID(ctx context.Context, id platform.ID) (*influxdb.Task, error) { func (s *TaskService) FindTaskByID(ctx context.Context, id platform.ID) (*taskmodel.Task, error) {
defer s.FindTaskByIDCalls.IncrFn()() defer s.FindTaskByIDCalls.IncrFn()()
return s.FindTaskByIDFn(ctx, id) return s.FindTaskByIDFn(ctx, id)
} }
func (s *TaskService) FindTasks(ctx context.Context, filter influxdb.TaskFilter) ([]*influxdb.Task, int, error) { func (s *TaskService) FindTasks(ctx context.Context, filter taskmodel.TaskFilter) ([]*taskmodel.Task, int, error) {
defer s.FindTasksCalls.IncrFn()() defer s.FindTasksCalls.IncrFn()()
return s.FindTasksFn(ctx, filter) return s.FindTasksFn(ctx, filter)
} }
func (s *TaskService) CreateTask(ctx context.Context, t influxdb.TaskCreate) (*influxdb.Task, error) { func (s *TaskService) CreateTask(ctx context.Context, t taskmodel.TaskCreate) (*taskmodel.Task, error) {
defer s.CreateTaskCalls.IncrFn()() defer s.CreateTaskCalls.IncrFn()()
return s.CreateTaskFn(ctx, t) return s.CreateTaskFn(ctx, t)
} }
func (s *TaskService) UpdateTask(ctx context.Context, id platform.ID, upd influxdb.TaskUpdate) (*influxdb.Task, error) { func (s *TaskService) UpdateTask(ctx context.Context, id platform.ID, upd taskmodel.TaskUpdate) (*taskmodel.Task, error) {
defer s.UpdateTaskCalls.IncrFn()() defer s.UpdateTaskCalls.IncrFn()()
return s.UpdateTaskFn(ctx, id, upd) return s.UpdateTaskFn(ctx, id, upd)
} }
@ -101,17 +100,17 @@ func (s *TaskService) DeleteTask(ctx context.Context, id platform.ID) error {
return s.DeleteTaskFn(ctx, id) return s.DeleteTaskFn(ctx, id)
} }
func (s *TaskService) FindLogs(ctx context.Context, filter influxdb.LogFilter) ([]*influxdb.Log, int, error) { func (s *TaskService) FindLogs(ctx context.Context, filter taskmodel.LogFilter) ([]*taskmodel.Log, int, error) {
defer s.FindLogsCalls.IncrFn()() defer s.FindLogsCalls.IncrFn()()
return s.FindLogsFn(ctx, filter) return s.FindLogsFn(ctx, filter)
} }
func (s *TaskService) FindRuns(ctx context.Context, filter influxdb.RunFilter) ([]*influxdb.Run, int, error) { func (s *TaskService) FindRuns(ctx context.Context, filter taskmodel.RunFilter) ([]*taskmodel.Run, int, error) {
defer s.FindRunsCalls.IncrFn()() defer s.FindRunsCalls.IncrFn()()
return s.FindRunsFn(ctx, filter) return s.FindRunsFn(ctx, filter)
} }
func (s *TaskService) FindRunByID(ctx context.Context, taskID, runID platform.ID) (*influxdb.Run, error) { func (s *TaskService) FindRunByID(ctx context.Context, taskID, runID platform.ID) (*taskmodel.Run, error) {
defer s.FindRunByIDCalls.IncrFn()() defer s.FindRunByIDCalls.IncrFn()()
return s.FindRunByIDFn(ctx, taskID, runID) return s.FindRunByIDFn(ctx, taskID, runID)
} }
@ -121,42 +120,42 @@ func (s *TaskService) CancelRun(ctx context.Context, taskID, runID platform.ID)
return s.CancelRunFn(ctx, taskID, runID) return s.CancelRunFn(ctx, taskID, runID)
} }
func (s *TaskService) RetryRun(ctx context.Context, taskID, runID platform.ID) (*influxdb.Run, error) { func (s *TaskService) RetryRun(ctx context.Context, taskID, runID platform.ID) (*taskmodel.Run, error) {
defer s.RetryRunCalls.IncrFn()() defer s.RetryRunCalls.IncrFn()()
return s.RetryRunFn(ctx, taskID, runID) return s.RetryRunFn(ctx, taskID, runID)
} }
func (s *TaskService) ForceRun(ctx context.Context, taskID platform.ID, scheduledFor int64) (*influxdb.Run, error) { func (s *TaskService) ForceRun(ctx context.Context, taskID platform.ID, scheduledFor int64) (*taskmodel.Run, error) {
defer s.ForceRunCalls.IncrFn()() defer s.ForceRunCalls.IncrFn()()
return s.ForceRunFn(ctx, taskID, scheduledFor) return s.ForceRunFn(ctx, taskID, scheduledFor)
} }
type TaskControlService struct { type TaskControlService struct {
CreateRunFn func(ctx context.Context, taskID platform.ID, scheduledFor time.Time, runAt time.Time) (*influxdb.Run, error) CreateRunFn func(ctx context.Context, taskID platform.ID, scheduledFor time.Time, runAt time.Time) (*taskmodel.Run, error)
CurrentlyRunningFn func(ctx context.Context, taskID platform.ID) ([]*influxdb.Run, error) CurrentlyRunningFn func(ctx context.Context, taskID platform.ID) ([]*taskmodel.Run, error)
ManualRunsFn func(ctx context.Context, taskID platform.ID) ([]*influxdb.Run, error) ManualRunsFn func(ctx context.Context, taskID platform.ID) ([]*taskmodel.Run, error)
StartManualRunFn func(ctx context.Context, taskID, runID platform.ID) (*influxdb.Run, error) StartManualRunFn func(ctx context.Context, taskID, runID platform.ID) (*taskmodel.Run, error)
FinishRunFn func(ctx context.Context, taskID, runID platform.ID) (*influxdb.Run, error) FinishRunFn func(ctx context.Context, taskID, runID platform.ID) (*taskmodel.Run, error)
UpdateRunStateFn func(ctx context.Context, taskID, runID platform.ID, when time.Time, state influxdb.RunStatus) error UpdateRunStateFn func(ctx context.Context, taskID, runID platform.ID, when time.Time, state taskmodel.RunStatus) error
AddRunLogFn func(ctx context.Context, taskID, runID platform.ID, when time.Time, log string) error AddRunLogFn func(ctx context.Context, taskID, runID platform.ID, when time.Time, log string) error
} }
func (tcs *TaskControlService) CreateRun(ctx context.Context, taskID platform.ID, scheduledFor time.Time, runAt time.Time) (*influxdb.Run, error) { func (tcs *TaskControlService) CreateRun(ctx context.Context, taskID platform.ID, scheduledFor time.Time, runAt time.Time) (*taskmodel.Run, error) {
return tcs.CreateRunFn(ctx, taskID, scheduledFor, runAt) return tcs.CreateRunFn(ctx, taskID, scheduledFor, runAt)
} }
func (tcs *TaskControlService) CurrentlyRunning(ctx context.Context, taskID platform.ID) ([]*influxdb.Run, error) { func (tcs *TaskControlService) CurrentlyRunning(ctx context.Context, taskID platform.ID) ([]*taskmodel.Run, error) {
return tcs.CurrentlyRunningFn(ctx, taskID) return tcs.CurrentlyRunningFn(ctx, taskID)
} }
func (tcs *TaskControlService) ManualRuns(ctx context.Context, taskID platform.ID) ([]*influxdb.Run, error) { func (tcs *TaskControlService) ManualRuns(ctx context.Context, taskID platform.ID) ([]*taskmodel.Run, error) {
return tcs.ManualRunsFn(ctx, taskID) return tcs.ManualRunsFn(ctx, taskID)
} }
func (tcs *TaskControlService) StartManualRun(ctx context.Context, taskID, runID platform.ID) (*influxdb.Run, error) { func (tcs *TaskControlService) StartManualRun(ctx context.Context, taskID, runID platform.ID) (*taskmodel.Run, error) {
return tcs.StartManualRunFn(ctx, taskID, runID) return tcs.StartManualRunFn(ctx, taskID, runID)
} }
func (tcs *TaskControlService) FinishRun(ctx context.Context, taskID, runID platform.ID) (*influxdb.Run, error) { func (tcs *TaskControlService) FinishRun(ctx context.Context, taskID, runID platform.ID) (*taskmodel.Run, error) {
return tcs.FinishRunFn(ctx, taskID, runID) return tcs.FinishRunFn(ctx, taskID, runID)
} }
func (tcs *TaskControlService) UpdateRunState(ctx context.Context, taskID, runID platform.ID, when time.Time, state influxdb.RunStatus) error { func (tcs *TaskControlService) UpdateRunState(ctx context.Context, taskID, runID platform.ID, when time.Time, state taskmodel.RunStatus) error {
return tcs.UpdateRunStateFn(ctx, taskID, runID, when, state) return tcs.UpdateRunStateFn(ctx, taskID, runID, when, state)
} }
func (tcs *TaskControlService) AddRunLog(ctx context.Context, taskID, runID platform.ID, when time.Time, log string) error { func (tcs *TaskControlService) AddRunLog(ctx context.Context, taskID, runID platform.ID, when time.Time, log string) error {

View File

@ -4,13 +4,13 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/flux/ast" "github.com/influxdata/flux/ast"
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/influxdb/v2/notification" "github.com/influxdata/influxdb/v2/notification"
"github.com/influxdata/influxdb/v2/notification/flux" "github.com/influxdata/influxdb/v2/notification/flux"
"github.com/influxdata/influxdb/v2/query/fluxlang"
) )
// Base will embed inside a check. // Base will embed inside a check.
@ -39,7 +39,7 @@ type Base struct {
} }
// Valid returns err if the check is invalid. // Valid returns err if the check is invalid.
func (b Base) Valid(lang influxdb.FluxLanguageService) error { func (b Base) Valid(lang fluxlang.FluxLanguageService) error {
if !b.ID.Valid() { if !b.ID.Valid() {
return &errors.Error{ return &errors.Error{
Code: errors.EInvalid, Code: errors.EInvalid,

View File

@ -4,13 +4,13 @@ import (
"encoding/json" "encoding/json"
"time" "time"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/flux/ast" "github.com/influxdata/flux/ast"
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/influxdb/v2/notification/flux" "github.com/influxdata/influxdb/v2/notification/flux"
"github.com/influxdata/influxdb/v2/query" "github.com/influxdata/influxdb/v2/query"
"github.com/influxdata/influxdb/v2/query/fluxlang"
) )
var _ influxdb.Check = &Custom{} var _ influxdb.Check = &Custom{}
@ -64,12 +64,12 @@ type Custom struct {
// |> monitor.check(data: check, messageFn:messageFn, warn:warn, crit:crit, info:info) // |> monitor.check(data: check, messageFn:messageFn, warn:warn, crit:crit, info:info)
// GenerateFlux returns the check query text directly // GenerateFlux returns the check query text directly
func (c Custom) GenerateFlux(lang influxdb.FluxLanguageService) (string, error) { func (c Custom) GenerateFlux(lang fluxlang.FluxLanguageService) (string, error) {
return c.Query.Text, nil return c.Query.Text, nil
} }
// sanitizeFlux modifies the check query text to include correct _check_id param in check object // sanitizeFlux modifies the check query text to include correct _check_id param in check object
func (c Custom) sanitizeFlux(lang influxdb.FluxLanguageService) (string, error) { func (c Custom) sanitizeFlux(lang fluxlang.FluxLanguageService) (string, error) {
p, err := query.Parse(lang, c.Query.Text) p, err := query.Parse(lang, c.Query.Text)
if p == nil { if p == nil {
return "", err return "", err
@ -106,7 +106,7 @@ func propertyHasValue(prop *ast.Property, key string, value string) bool {
return ok && prop.Key.Key() == key && stringLit.Value == value return ok && prop.Key.Key() == key && stringLit.Value == value
} }
func (c *Custom) hasRequiredTaskOptions(lang influxdb.FluxLanguageService) (err error) { func (c *Custom) hasRequiredTaskOptions(lang fluxlang.FluxLanguageService) (err error) {
p, err := query.Parse(lang, c.Query.Text) p, err := query.Parse(lang, c.Query.Text)
if p == nil { if p == nil {
@ -175,7 +175,7 @@ func (c *Custom) hasRequiredTaskOptions(lang influxdb.FluxLanguageService) (err
return nil return nil
} }
func (c *Custom) hasRequiredCheckParameters(lang influxdb.FluxLanguageService) (err error) { func (c *Custom) hasRequiredCheckParameters(lang fluxlang.FluxLanguageService) (err error) {
p, err := query.Parse(lang, c.Query.Text) p, err := query.Parse(lang, c.Query.Text)
if p == nil { if p == nil {
return err return err
@ -223,7 +223,7 @@ func (c *Custom) hasRequiredCheckParameters(lang influxdb.FluxLanguageService) (
} }
// Valid checks whether check flux is valid, returns error if invalid // Valid checks whether check flux is valid, returns error if invalid
func (c *Custom) Valid(lang influxdb.FluxLanguageService) error { func (c *Custom) Valid(lang fluxlang.FluxLanguageService) error {
if err := c.hasRequiredCheckParameters(lang); err != nil { if err := c.hasRequiredCheckParameters(lang); err != nil {
return err return err

View File

@ -10,6 +10,7 @@ import (
"github.com/influxdata/influxdb/v2/notification" "github.com/influxdata/influxdb/v2/notification"
"github.com/influxdata/influxdb/v2/notification/flux" "github.com/influxdata/influxdb/v2/notification/flux"
"github.com/influxdata/influxdb/v2/query" "github.com/influxdata/influxdb/v2/query"
"github.com/influxdata/influxdb/v2/query/fluxlang"
) )
var _ influxdb.Check = (*Deadman)(nil) var _ influxdb.Check = (*Deadman)(nil)
@ -31,7 +32,7 @@ func (c Deadman) Type() string {
} }
// GenerateFlux returns a flux script for the Deadman provided. // GenerateFlux returns a flux script for the Deadman provided.
func (c Deadman) GenerateFlux(lang influxdb.FluxLanguageService) (string, error) { func (c Deadman) GenerateFlux(lang fluxlang.FluxLanguageService) (string, error) {
p, err := c.GenerateFluxAST(lang) p, err := c.GenerateFluxAST(lang)
if err != nil { if err != nil {
return "", err return "", err
@ -43,7 +44,7 @@ func (c Deadman) GenerateFlux(lang influxdb.FluxLanguageService) (string, error)
// GenerateFluxAST returns a flux AST for the deadman provided. If there // GenerateFluxAST returns a flux AST for the deadman provided. If there
// are any errors in the flux that the user provided the function will return // are any errors in the flux that the user provided the function will return
// an error for each error found when the script is parsed. // an error for each error found when the script is parsed.
func (c Deadman) GenerateFluxAST(lang influxdb.FluxLanguageService) (*ast.Package, error) { func (c Deadman) GenerateFluxAST(lang fluxlang.FluxLanguageService) (*ast.Package, error) {
p, err := query.Parse(lang, c.Query.Text) p, err := query.Parse(lang, c.Query.Text)
if p == nil { if p == nil {
return nil, err return nil, err

View File

@ -5,13 +5,13 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/flux/ast" "github.com/influxdata/flux/ast"
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/influxdb/v2/notification" "github.com/influxdata/influxdb/v2/notification"
"github.com/influxdata/influxdb/v2/notification/flux" "github.com/influxdata/influxdb/v2/notification/flux"
"github.com/influxdata/influxdb/v2/query" "github.com/influxdata/influxdb/v2/query"
"github.com/influxdata/influxdb/v2/query/fluxlang"
) )
var _ influxdb.Check = (*Threshold)(nil) var _ influxdb.Check = (*Threshold)(nil)
@ -28,7 +28,7 @@ func (t Threshold) Type() string {
} }
// Valid returns error if something is invalid. // Valid returns error if something is invalid.
func (t Threshold) Valid(lang influxdb.FluxLanguageService) error { func (t Threshold) Valid(lang fluxlang.FluxLanguageService) error {
if err := t.Base.Valid(lang); err != nil { if err := t.Base.Valid(lang); err != nil {
return err return err
} }
@ -106,7 +106,7 @@ func multiError(errs []error) error {
// GenerateFlux returns a flux script for the threshold provided. If there // GenerateFlux returns a flux script for the threshold provided. If there
// are any errors in the flux that the user provided the function will return // are any errors in the flux that the user provided the function will return
// an error for each error found when the script is parsed. // an error for each error found when the script is parsed.
func (t Threshold) GenerateFlux(lang influxdb.FluxLanguageService) (string, error) { func (t Threshold) GenerateFlux(lang fluxlang.FluxLanguageService) (string, error) {
p, err := t.GenerateFluxAST(lang) p, err := t.GenerateFluxAST(lang)
if err != nil { if err != nil {
return "", err return "", err
@ -118,7 +118,7 @@ func (t Threshold) GenerateFlux(lang influxdb.FluxLanguageService) (string, erro
// GenerateFluxAST returns a flux AST for the threshold provided. If there // GenerateFluxAST returns a flux AST for the threshold provided. If there
// are any errors in the flux that the user provided the function will return // are any errors in the flux that the user provided the function will return
// an error for each error found when the script is parsed. // an error for each error found when the script is parsed.
func (t Threshold) GenerateFluxAST(lang influxdb.FluxLanguageService) (*ast.Package, error) { func (t Threshold) GenerateFluxAST(lang fluxlang.FluxLanguageService) (*ast.Package, error) {
p, err := query.Parse(lang, t.Query.Text) p, err := query.Parse(lang, t.Query.Text)
if p == nil { if p == nil {
return nil, err return nil, err

View File

@ -5,14 +5,14 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/platform" "github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/kit/platform/errors" "github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kv" "github.com/influxdata/influxdb/v2/kv"
"github.com/influxdata/influxdb/v2/notification/rule" "github.com/influxdata/influxdb/v2/notification/rule"
"github.com/influxdata/influxdb/v2/pkg/pointer" "github.com/influxdata/influxdb/v2/pkg/pointer"
"github.com/influxdata/influxdb/v2/snowflake" "github.com/influxdata/influxdb/v2/snowflake"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -39,7 +39,7 @@ type RuleService struct {
log *zap.Logger log *zap.Logger
kv kv.Store kv kv.Store
tasks influxdb.TaskService tasks taskmodel.TaskService
orgs influxdb.OrganizationService orgs influxdb.OrganizationService
endpoints influxdb.NotificationEndpointService endpoints influxdb.NotificationEndpointService
@ -48,7 +48,7 @@ type RuleService struct {
} }
// New constructs and configures a notification rule service // New constructs and configures a notification rule service
func New(logger *zap.Logger, store kv.Store, tasks influxdb.TaskService, orgs influxdb.OrganizationService, endpoints influxdb.NotificationEndpointService) (*RuleService, error) { func New(logger *zap.Logger, store kv.Store, tasks taskmodel.TaskService, orgs influxdb.OrganizationService, endpoints influxdb.NotificationEndpointService) (*RuleService, error) {
s := &RuleService{ s := &RuleService{
log: logger, log: logger,
kv: store, kv: store,
@ -138,7 +138,7 @@ func (s *RuleService) CreateNotificationRule(ctx context.Context, nr influxdb.No
} }
// set task to notification rule create status // set task to notification rule create status
_, err = s.tasks.UpdateTask(ctx, t.ID, influxdb.TaskUpdate{Status: pointer.String(string(nr.Status))}) _, err = s.tasks.UpdateTask(ctx, t.ID, taskmodel.TaskUpdate{Status: pointer.String(string(nr.Status))})
return err return err
} }
@ -154,7 +154,7 @@ func (s *RuleService) createNotificationRule(ctx context.Context, tx kv.Tx, nr i
return s.putNotificationRule(ctx, tx, nr.NotificationRule) return s.putNotificationRule(ctx, tx, nr.NotificationRule)
} }
func (s *RuleService) createNotificationTask(ctx context.Context, r influxdb.NotificationRuleCreate) (*influxdb.Task, error) { func (s *RuleService) createNotificationTask(ctx context.Context, r influxdb.NotificationRuleCreate) (*taskmodel.Task, error) {
ep, err := s.endpoints.FindNotificationEndpointByID(ctx, r.GetEndpointID()) ep, err := s.endpoints.FindNotificationEndpointByID(ctx, r.GetEndpointID())
if err != nil { if err != nil {
return nil, err return nil, err
@ -165,7 +165,7 @@ func (s *RuleService) createNotificationTask(ctx context.Context, r influxdb.Not
return nil, err return nil, err
} }
tc := influxdb.TaskCreate{ tc := taskmodel.TaskCreate{
Type: r.Type(), Type: r.Type(),
Flux: script, Flux: script,
OwnerID: r.GetOwnerID(), OwnerID: r.GetOwnerID(),
@ -218,7 +218,7 @@ func (s *RuleService) UpdateNotificationRule(ctx context.Context, id platform.ID
return nr.NotificationRule, err return nr.NotificationRule, err
} }
func (s *RuleService) updateNotificationTask(ctx context.Context, r influxdb.NotificationRule, status *string) (*influxdb.Task, error) { func (s *RuleService) updateNotificationTask(ctx context.Context, r influxdb.NotificationRule, status *string) (*taskmodel.Task, error) {
ep, err := s.endpoints.FindNotificationEndpointByID(ctx, r.GetEndpointID()) ep, err := s.endpoints.FindNotificationEndpointByID(ctx, r.GetEndpointID())
if err != nil { if err != nil {
return nil, err return nil, err
@ -229,7 +229,7 @@ func (s *RuleService) updateNotificationTask(ctx context.Context, r influxdb.Not
return nil, err return nil, err
} }
tu := influxdb.TaskUpdate{ tu := taskmodel.TaskUpdate{
Flux: &script, Flux: &script,
Description: pointer.String(r.GetDescription()), Description: pointer.String(r.GetDescription()),
Status: status, Status: status,

View File

@ -8,18 +8,18 @@ import (
"testing" "testing"
"time" "time"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts" "github.com/google/go-cmp/cmp/cmpopts"
"github.com/influxdata/flux/ast" "github.com/influxdata/flux/ast"
influxdb "github.com/influxdata/influxdb/v2" influxdb "github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/influxdb/v2/mock" "github.com/influxdata/influxdb/v2/mock"
"github.com/influxdata/influxdb/v2/notification" "github.com/influxdata/influxdb/v2/notification"
"github.com/influxdata/influxdb/v2/notification/endpoint" "github.com/influxdata/influxdb/v2/notification/endpoint"
"github.com/influxdata/influxdb/v2/notification/rule" "github.com/influxdata/influxdb/v2/notification/rule"
"github.com/influxdata/influxdb/v2/pkg/pointer" "github.com/influxdata/influxdb/v2/pkg/pointer"
"github.com/influxdata/influxdb/v2/task/taskmodel"
) )
const ( const (
@ -45,7 +45,7 @@ type NotificationRuleFields struct {
TimeGenerator influxdb.TimeGenerator TimeGenerator influxdb.TimeGenerator
NotificationRules []influxdb.NotificationRule NotificationRules []influxdb.NotificationRule
Orgs []*influxdb.Organization Orgs []*influxdb.Organization
Tasks []influxdb.TaskCreate Tasks []taskmodel.TaskCreate
Endpoints []influxdb.NotificationEndpoint Endpoints []influxdb.NotificationEndpoint
} }
@ -66,14 +66,14 @@ var taskCmpOptions = cmp.Options{
}), }),
// skip comparing permissions // skip comparing permissions
cmpopts.IgnoreFields( cmpopts.IgnoreFields(
influxdb.Task{}, taskmodel.Task{},
"LatestCompleted", "LatestCompleted",
"LatestScheduled", "LatestScheduled",
"CreatedAt", "CreatedAt",
"UpdatedAt", "UpdatedAt",
), ),
cmp.Transformer("Sort", func(in []*influxdb.Task) []*influxdb.Task { cmp.Transformer("Sort", func(in []*taskmodel.Task) []*taskmodel.Task {
out := append([]*influxdb.Task{}, in...) // Copy input to avoid mutating it out := append([]*taskmodel.Task{}, in...) // Copy input to avoid mutating it
sort.Slice(out, func(i, j int) bool { sort.Slice(out, func(i, j int) bool {
return out[i].ID > out[j].ID return out[i].ID > out[j].ID
}) })
@ -81,7 +81,7 @@ var taskCmpOptions = cmp.Options{
}), }),
} }
type notificationRuleFactory func(NotificationRuleFields, *testing.T) (influxdb.NotificationRuleStore, influxdb.TaskService, func()) type notificationRuleFactory func(NotificationRuleFields, *testing.T) (influxdb.NotificationRuleStore, taskmodel.TaskService, func())
// NotificationRuleStore tests all the service functions. // NotificationRuleStore tests all the service functions.
func NotificationRuleStore( func NotificationRuleStore(
@ -135,7 +135,7 @@ func CreateNotificationRule(
type wants struct { type wants struct {
err error err error
notificationRule influxdb.NotificationRule notificationRule influxdb.NotificationRule
task *influxdb.Task task *taskmodel.Task
} }
tests := []struct { tests := []struct {
@ -287,7 +287,7 @@ func CreateNotificationRule(
}, },
MessageTemplate: "msg1", MessageTemplate: "msg1",
}, },
task: &influxdb.Task{ task: &taskmodel.Task{
ID: MustIDBase16("020f755c3c082001"), ID: MustIDBase16("020f755c3c082001"),
Type: "slack", Type: "slack",
OrganizationID: MustIDBase16("020f755c3c082003"), OrganizationID: MustIDBase16("020f755c3c082003"),
@ -453,7 +453,7 @@ func CreateNotificationRule(
if tt.wants.task == nil || !tt.wants.task.ID.Valid() { if tt.wants.task == nil || !tt.wants.task.ID.Valid() {
// if not tasks or a task with an invalid ID is provided (0) then assume // if not tasks or a task with an invalid ID is provided (0) then assume
// no tasks should be persisted // no tasks should be persisted
_, n, err := tasks.FindTasks(ctx, influxdb.TaskFilter{}) _, n, err := tasks.FindTasks(ctx, taskmodel.TaskFilter{})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -1323,7 +1323,7 @@ func UpdateNotificationRule(
fields: NotificationRuleFields{ fields: NotificationRuleFields{
TimeGenerator: fakeGenerator, TimeGenerator: fakeGenerator,
IDGenerator: mock.NewIDGenerator(twoID, t), IDGenerator: mock.NewIDGenerator(twoID, t),
Tasks: []influxdb.TaskCreate{ Tasks: []taskmodel.TaskCreate{
{ {
OwnerID: MustIDBase16(sixID), OwnerID: MustIDBase16(sixID),
OrganizationID: MustIDBase16(fourID), OrganizationID: MustIDBase16(fourID),
@ -1558,7 +1558,7 @@ func PatchNotificationRule(
fields: NotificationRuleFields{ fields: NotificationRuleFields{
TimeGenerator: fakeGenerator, TimeGenerator: fakeGenerator,
IDGenerator: mock.NewIDGenerator(twoID, t), IDGenerator: mock.NewIDGenerator(twoID, t),
Tasks: []influxdb.TaskCreate{ Tasks: []taskmodel.TaskCreate{
{ {
OwnerID: MustIDBase16(sixID), OwnerID: MustIDBase16(sixID),
OrganizationID: MustIDBase16(fourID), OrganizationID: MustIDBase16(fourID),
@ -1683,7 +1683,7 @@ func PatchNotificationRule(
fields: NotificationRuleFields{ fields: NotificationRuleFields{
TimeGenerator: fakeGenerator, TimeGenerator: fakeGenerator,
IDGenerator: mock.NewIDGenerator(twoID, t), IDGenerator: mock.NewIDGenerator(twoID, t),
Tasks: []influxdb.TaskCreate{ Tasks: []taskmodel.TaskCreate{
{ {
OwnerID: MustIDBase16(sixID), OwnerID: MustIDBase16(sixID),
OrganizationID: MustIDBase16(fourID), OrganizationID: MustIDBase16(fourID),
@ -1933,7 +1933,7 @@ func DeleteNotificationRule(
name: "none existing config", name: "none existing config",
fields: NotificationRuleFields{ fields: NotificationRuleFields{
IDGenerator: mock.NewIDGenerator(twoID, t), IDGenerator: mock.NewIDGenerator(twoID, t),
Tasks: []influxdb.TaskCreate{ Tasks: []taskmodel.TaskCreate{
{ {
OwnerID: MustIDBase16(sixID), OwnerID: MustIDBase16(sixID),
OrganizationID: MustIDBase16(fourID), OrganizationID: MustIDBase16(fourID),
@ -2038,7 +2038,7 @@ func DeleteNotificationRule(
{ {
name: "regular delete", name: "regular delete",
fields: NotificationRuleFields{ fields: NotificationRuleFields{
Tasks: []influxdb.TaskCreate{ Tasks: []taskmodel.TaskCreate{
{ {
OwnerID: MustIDBase16(sixID), OwnerID: MustIDBase16(sixID),
OrganizationID: MustIDBase16(fourID), OrganizationID: MustIDBase16(fourID),

View File

@ -7,18 +7,18 @@ import (
"os" "os"
"testing" "testing"
"github.com/influxdata/influxdb/v2/kit/platform"
influxdb "github.com/influxdata/influxdb/v2" influxdb "github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/bolt" "github.com/influxdata/influxdb/v2/bolt"
_ "github.com/influxdata/influxdb/v2/fluxinit/static" _ "github.com/influxdata/influxdb/v2/fluxinit/static"
"github.com/influxdata/influxdb/v2/inmem" "github.com/influxdata/influxdb/v2/inmem"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/kv" "github.com/influxdata/influxdb/v2/kv"
"github.com/influxdata/influxdb/v2/kv/migration/all" "github.com/influxdata/influxdb/v2/kv/migration/all"
"github.com/influxdata/influxdb/v2/mock" "github.com/influxdata/influxdb/v2/mock"
endpointservice "github.com/influxdata/influxdb/v2/notification/endpoint/service" endpointservice "github.com/influxdata/influxdb/v2/notification/endpoint/service"
"github.com/influxdata/influxdb/v2/query/fluxlang" "github.com/influxdata/influxdb/v2/query/fluxlang"
"github.com/influxdata/influxdb/v2/secret" "github.com/influxdata/influxdb/v2/secret"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"github.com/influxdata/influxdb/v2/tenant" "github.com/influxdata/influxdb/v2/tenant"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest" "go.uber.org/zap/zaptest"
@ -28,7 +28,7 @@ func TestInmemNotificationRuleStore(t *testing.T) {
NotificationRuleStore(initInmemNotificationRuleStore, t) NotificationRuleStore(initInmemNotificationRuleStore, t)
} }
func initInmemNotificationRuleStore(f NotificationRuleFields, t *testing.T) (influxdb.NotificationRuleStore, influxdb.TaskService, func()) { func initInmemNotificationRuleStore(f NotificationRuleFields, t *testing.T) (influxdb.NotificationRuleStore, taskmodel.TaskService, func()) {
store := inmem.NewKVStore() store := inmem.NewKVStore()
if err := all.Up(context.Background(), zaptest.NewLogger(t), store); err != nil { if err := all.Up(context.Background(), zaptest.NewLogger(t), store); err != nil {
t.Fatal(err) t.Fatal(err)
@ -40,7 +40,7 @@ func initInmemNotificationRuleStore(f NotificationRuleFields, t *testing.T) (inf
} }
} }
func initBoltNotificationRuleStore(f NotificationRuleFields, t *testing.T) (influxdb.NotificationRuleStore, influxdb.TaskService, func()) { func initBoltNotificationRuleStore(f NotificationRuleFields, t *testing.T) (influxdb.NotificationRuleStore, taskmodel.TaskService, func()) {
store, closeBolt, err := newTestBoltStore(t) store, closeBolt, err := newTestBoltStore(t)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -57,7 +57,7 @@ func TestBoltNotificationRuleStore(t *testing.T) {
NotificationRuleStore(initBoltNotificationRuleStore, t) NotificationRuleStore(initBoltNotificationRuleStore, t)
} }
func initNotificationRuleStore(s kv.Store, f NotificationRuleFields, t *testing.T) (influxdb.NotificationRuleStore, influxdb.TaskService, func()) { func initNotificationRuleStore(s kv.Store, f NotificationRuleFields, t *testing.T) (influxdb.NotificationRuleStore, taskmodel.TaskService, func()) {
logger := zaptest.NewLogger(t) logger := zaptest.NewLogger(t)
var ( var (

View File

@ -8,16 +8,16 @@ import (
"sort" "sort"
"strings" "strings"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
ierrors "github.com/influxdata/influxdb/v2/kit/errors" ierrors "github.com/influxdata/influxdb/v2/kit/errors"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/notification" "github.com/influxdata/influxdb/v2/notification"
icheck "github.com/influxdata/influxdb/v2/notification/check" icheck "github.com/influxdata/influxdb/v2/notification/check"
"github.com/influxdata/influxdb/v2/notification/endpoint" "github.com/influxdata/influxdb/v2/notification/endpoint"
"github.com/influxdata/influxdb/v2/notification/rule" "github.com/influxdata/influxdb/v2/notification/rule"
"github.com/influxdata/influxdb/v2/pkger/internal/wordplay" "github.com/influxdata/influxdb/v2/pkger/internal/wordplay"
"github.com/influxdata/influxdb/v2/snowflake" "github.com/influxdata/influxdb/v2/snowflake"
"github.com/influxdata/influxdb/v2/task/taskmodel"
) )
var idGenerator = snowflake.NewDefaultIDGenerator() var idGenerator = snowflake.NewDefaultIDGenerator()
@ -90,7 +90,7 @@ type resourceExporter struct {
labelSVC influxdb.LabelService labelSVC influxdb.LabelService
endpointSVC influxdb.NotificationEndpointService endpointSVC influxdb.NotificationEndpointService
ruleSVC influxdb.NotificationRuleStore ruleSVC influxdb.NotificationRuleStore
taskSVC influxdb.TaskService taskSVC taskmodel.TaskService
teleSVC influxdb.TelegrafConfigStore teleSVC influxdb.TelegrafConfigStore
varSVC influxdb.VariableService varSVC influxdb.VariableService
@ -401,7 +401,7 @@ func (ex *resourceExporter) resourceCloneToKind(ctx context.Context, r ResourceT
} }
mapResource(t.OrganizationID, t.ID, KindTask, TaskToObject(r.Name, *t)) mapResource(t.OrganizationID, t.ID, KindTask, TaskToObject(r.Name, *t))
case len(r.Name) > 0: case len(r.Name) > 0:
tasks, n, err := ex.taskSVC.FindTasks(ctx, influxdb.TaskFilter{Name: &r.Name}) tasks, n, err := ex.taskSVC.FindTasks(ctx, taskmodel.TaskFilter{Name: &r.Name})
if err != nil { if err != nil {
return err return err
} }
@ -625,7 +625,7 @@ func CheckToObject(name string, ch influxdb.Check) Object {
o := newObject(KindCheck, name) o := newObject(KindCheck, name)
assignNonZeroStrings(o.Spec, map[string]string{ assignNonZeroStrings(o.Spec, map[string]string{
fieldDescription: ch.GetDescription(), fieldDescription: ch.GetDescription(),
fieldStatus: influxdb.TaskStatusActive, fieldStatus: taskmodel.TaskStatusActive,
}) })
assignBase := func(base icheck.Base) { assignBase := func(base icheck.Base) {
@ -1333,7 +1333,7 @@ func NotificationRuleToObject(name, endpointPkgName string, iRule influxdb.Notif
var taskFluxRegex = regexp.MustCompile(`option task = {(.|\n)*?}`) var taskFluxRegex = regexp.MustCompile(`option task = {(.|\n)*?}`)
// TaskToObject converts an influxdb.Task into a pkger.Object. // TaskToObject converts an influxdb.Task into a pkger.Object.
func TaskToObject(name string, t influxdb.Task) Object { func TaskToObject(name string, t taskmodel.Task) Object {
if name == "" { if name == "" {
name = t.Name name = t.Name
} }

View File

@ -13,12 +13,12 @@ import (
"testing" "testing"
"time" "time"
errors2 "github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
errors2 "github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/influxdb/v2/notification" "github.com/influxdata/influxdb/v2/notification"
icheck "github.com/influxdata/influxdb/v2/notification/check" icheck "github.com/influxdata/influxdb/v2/notification/check"
"github.com/influxdata/influxdb/v2/notification/endpoint" "github.com/influxdata/influxdb/v2/notification/endpoint"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -2709,7 +2709,7 @@ spec:
Base: endpoint.Base{ Base: endpoint.Base{
Name: "basic endpoint name", Name: "basic endpoint name",
Description: "http basic auth desc", Description: "http basic auth desc",
Status: influxdb.TaskStatusInactive, Status: taskmodel.TaskStatusInactive,
}, },
URL: "https://www.example.com/endpoint/basicauth", URL: "https://www.example.com/endpoint/basicauth",
AuthMethod: "basic", AuthMethod: "basic",
@ -2727,7 +2727,7 @@ spec:
Base: endpoint.Base{ Base: endpoint.Base{
Name: "http-bearer-auth-notification-endpoint", Name: "http-bearer-auth-notification-endpoint",
Description: "http bearer auth desc", Description: "http bearer auth desc",
Status: influxdb.TaskStatusActive, Status: taskmodel.TaskStatusActive,
}, },
URL: "https://www.example.com/endpoint/bearerauth", URL: "https://www.example.com/endpoint/bearerauth",
AuthMethod: "bearer", AuthMethod: "bearer",
@ -2744,7 +2744,7 @@ spec:
Base: endpoint.Base{ Base: endpoint.Base{
Name: "http-none-auth-notification-endpoint", Name: "http-none-auth-notification-endpoint",
Description: "http none auth desc", Description: "http none auth desc",
Status: influxdb.TaskStatusActive, Status: taskmodel.TaskStatusActive,
}, },
URL: "https://www.example.com/endpoint/noneauth", URL: "https://www.example.com/endpoint/noneauth",
AuthMethod: "none", AuthMethod: "none",
@ -2760,7 +2760,7 @@ spec:
Base: endpoint.Base{ Base: endpoint.Base{
Name: "pager duty name", Name: "pager duty name",
Description: "pager duty desc", Description: "pager duty desc",
Status: influxdb.TaskStatusActive, Status: taskmodel.TaskStatusActive,
}, },
ClientURL: "http://localhost:8080/orgs/7167eb6719fa34e5/alert-history", ClientURL: "http://localhost:8080/orgs/7167eb6719fa34e5/alert-history",
RoutingKey: influxdb.SecretField{Value: strPtr("secret routing-key")}, RoutingKey: influxdb.SecretField{Value: strPtr("secret routing-key")},
@ -2775,7 +2775,7 @@ spec:
Base: endpoint.Base{ Base: endpoint.Base{
Name: "slack name", Name: "slack name",
Description: "slack desc", Description: "slack desc",
Status: influxdb.TaskStatusActive, Status: taskmodel.TaskStatusActive,
}, },
URL: "https://hooks.slack.com/services/bip/piddy/boppidy", URL: "https://hooks.slack.com/services/bip/piddy/boppidy",
Token: influxdb.SecretField{Value: strPtr("tokenval")}, Token: influxdb.SecretField{Value: strPtr("tokenval")},
@ -4245,7 +4245,7 @@ spec:
expected := &endpoint.PagerDuty{ expected := &endpoint.PagerDuty{
Base: endpoint.Base{ Base: endpoint.Base{
Name: "pager-duty-notification-endpoint", Name: "pager-duty-notification-endpoint",
Status: influxdb.TaskStatusActive, Status: taskmodel.TaskStatusActive,
}, },
ClientURL: "http://localhost:8080/orgs/7167eb6719fa34e5/alert-history", ClientURL: "http://localhost:8080/orgs/7167eb6719fa34e5/alert-history",
RoutingKey: influxdb.SecretField{Key: "-routing-key", Value: strPtr("not empty")}, RoutingKey: influxdb.SecretField{Key: "-routing-key", Value: strPtr("not empty")},

View File

@ -12,17 +12,17 @@ import (
"sync" "sync"
"time" "time"
"github.com/influxdata/influxdb/v2/kit/platform"
errors2 "github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/go-stack/stack" "github.com/go-stack/stack"
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
ierrors "github.com/influxdata/influxdb/v2/kit/errors" ierrors "github.com/influxdata/influxdb/v2/kit/errors"
"github.com/influxdata/influxdb/v2/kit/platform"
errors2 "github.com/influxdata/influxdb/v2/kit/platform/errors"
icheck "github.com/influxdata/influxdb/v2/notification/check" icheck "github.com/influxdata/influxdb/v2/notification/check"
"github.com/influxdata/influxdb/v2/notification/rule" "github.com/influxdata/influxdb/v2/notification/rule"
"github.com/influxdata/influxdb/v2/pkger/internal/wordplay" "github.com/influxdata/influxdb/v2/pkger/internal/wordplay"
"github.com/influxdata/influxdb/v2/snowflake" "github.com/influxdata/influxdb/v2/snowflake"
"github.com/influxdata/influxdb/v2/task/options" "github.com/influxdata/influxdb/v2/task/options"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -162,7 +162,7 @@ type serviceOpt struct {
orgSVC influxdb.OrganizationService orgSVC influxdb.OrganizationService
ruleSVC influxdb.NotificationRuleStore ruleSVC influxdb.NotificationRuleStore
secretSVC influxdb.SecretService secretSVC influxdb.SecretService
taskSVC influxdb.TaskService taskSVC taskmodel.TaskService
teleSVC influxdb.TelegrafConfigStore teleSVC influxdb.TelegrafConfigStore
varSVC influxdb.VariableService varSVC influxdb.VariableService
} }
@ -261,7 +261,7 @@ func WithSecretSVC(secretSVC influxdb.SecretService) ServiceSetterFn {
} }
// WithTaskSVC sets the task service. // WithTaskSVC sets the task service.
func WithTaskSVC(taskSVC influxdb.TaskService) ServiceSetterFn { func WithTaskSVC(taskSVC taskmodel.TaskService) ServiceSetterFn {
return func(opt *serviceOpt) { return func(opt *serviceOpt) {
opt.taskSVC = taskSVC opt.taskSVC = taskSVC
} }
@ -311,7 +311,7 @@ type Service struct {
orgSVC influxdb.OrganizationService orgSVC influxdb.OrganizationService
ruleSVC influxdb.NotificationRuleStore ruleSVC influxdb.NotificationRuleStore
secretSVC influxdb.SecretService secretSVC influxdb.SecretService
taskSVC influxdb.TaskService taskSVC taskmodel.TaskService
teleSVC influxdb.TelegrafConfigStore teleSVC influxdb.TelegrafConfigStore
varSVC influxdb.VariableService varSVC influxdb.VariableService
} }
@ -822,10 +822,10 @@ func (s *Service) cloneOrgTasks(ctx context.Context, orgID platform.ID) ([]Resou
return nil, err return nil, err
} }
mTasks := make(map[platform.ID]*influxdb.Task) mTasks := make(map[platform.ID]*taskmodel.Task)
for i := range tasks { for i := range tasks {
t := tasks[i] t := tasks[i]
if t.Type != influxdb.TaskSystemType { if t.Type != taskmodel.TaskSystemType {
continue continue
} }
mTasks[t.ID] = t mTasks[t.ID] = t
@ -1191,7 +1191,7 @@ func (s *Service) dryRunSecrets(ctx context.Context, orgID platform.ID, template
func (s *Service) dryRunTasks(ctx context.Context, orgID platform.ID, tasks map[string]*stateTask) { func (s *Service) dryRunTasks(ctx context.Context, orgID platform.ID, tasks map[string]*stateTask) {
for _, stateTask := range tasks { for _, stateTask := range tasks {
stateTask.orgID = orgID stateTask.orgID = orgID
var existing *influxdb.Task var existing *taskmodel.Task
if stateTask.ID() != 0 { if stateTask.ID() != 0 {
existing, _ = s.taskSVC.FindTaskByID(ctx, stateTask.ID()) existing, _ = s.taskSVC.FindTaskByID(ctx, stateTask.ID())
} }
@ -2530,7 +2530,7 @@ func (s *Service) applyTasks(ctx context.Context, tasks []*stateTask) applier {
} }
} }
func (s *Service) applyTask(ctx context.Context, userID platform.ID, t *stateTask) (influxdb.Task, error) { func (s *Service) applyTask(ctx context.Context, userID platform.ID, t *stateTask) (taskmodel.Task, error) {
if isRestrictedTask(t.existing) { if isRestrictedTask(t.existing) {
return *t.existing, nil return *t.existing, nil
} }
@ -2538,9 +2538,9 @@ func (s *Service) applyTask(ctx context.Context, userID platform.ID, t *stateTas
case IsRemoval(t.stateStatus): case IsRemoval(t.stateStatus):
if err := s.taskSVC.DeleteTask(ctx, t.ID()); err != nil { if err := s.taskSVC.DeleteTask(ctx, t.ID()); err != nil {
if errors2.ErrorCode(err) == errors2.ENotFound { if errors2.ErrorCode(err) == errors2.ENotFound {
return influxdb.Task{}, nil return taskmodel.Task{}, nil
} }
return influxdb.Task{}, applyFailErr("delete", t.stateIdentity(), err) return taskmodel.Task{}, applyFailErr("delete", t.stateIdentity(), err)
} }
return *t.existing, nil return *t.existing, nil
case IsExisting(t.stateStatus) && t.existing != nil: case IsExisting(t.stateStatus) && t.existing != nil:
@ -2560,19 +2560,19 @@ func (s *Service) applyTask(ctx context.Context, userID platform.ID, t *stateTas
} }
} }
updatedTask, err := s.taskSVC.UpdateTask(ctx, t.ID(), influxdb.TaskUpdate{ updatedTask, err := s.taskSVC.UpdateTask(ctx, t.ID(), taskmodel.TaskUpdate{
Flux: &newFlux, Flux: &newFlux,
Status: &newStatus, Status: &newStatus,
Description: &t.parserTask.description, Description: &t.parserTask.description,
Options: opt, Options: opt,
}) })
if err != nil { if err != nil {
return influxdb.Task{}, applyFailErr("update", t.stateIdentity(), err) return taskmodel.Task{}, applyFailErr("update", t.stateIdentity(), err)
} }
return *updatedTask, nil return *updatedTask, nil
default: default:
newTask, err := s.taskSVC.CreateTask(ctx, influxdb.TaskCreate{ newTask, err := s.taskSVC.CreateTask(ctx, taskmodel.TaskCreate{
Type: influxdb.TaskSystemType, Type: taskmodel.TaskSystemType,
Flux: t.parserTask.flux(), Flux: t.parserTask.flux(),
OwnerID: userID, OwnerID: userID,
Description: t.parserTask.description, Description: t.parserTask.description,
@ -2580,7 +2580,7 @@ func (s *Service) applyTask(ctx context.Context, userID platform.ID, t *stateTas
OrganizationID: t.orgID, OrganizationID: t.orgID,
}) })
if err != nil { if err != nil {
return influxdb.Task{}, applyFailErr("create", t.stateIdentity(), err) return taskmodel.Task{}, applyFailErr("create", t.stateIdentity(), err)
} }
return *newTask, nil return *newTask, nil
} }
@ -2595,7 +2595,7 @@ func (s *Service) rollbackTasks(ctx context.Context, tasks []*stateTask) error {
var err error var err error
switch t.stateStatus { switch t.stateStatus {
case StateStatusRemove: case StateStatusRemove:
newTask, err := s.taskSVC.CreateTask(ctx, influxdb.TaskCreate{ newTask, err := s.taskSVC.CreateTask(ctx, taskmodel.TaskCreate{
Type: t.existing.Type, Type: t.existing.Type,
Flux: t.existing.Flux, Flux: t.existing.Flux,
OwnerID: t.existing.OwnerID, OwnerID: t.existing.OwnerID,
@ -2623,7 +2623,7 @@ func (s *Service) rollbackTasks(ctx context.Context, tasks []*stateTask) error {
} }
} }
_, err = s.taskSVC.UpdateTask(ctx, t.ID(), influxdb.TaskUpdate{ _, err = s.taskSVC.UpdateTask(ctx, t.ID(), taskmodel.TaskUpdate{
Flux: &t.existing.Flux, Flux: &t.existing.Flux,
Status: &t.existing.Status, Status: &t.existing.Status,
Description: &t.existing.Description, Description: &t.existing.Description,
@ -3412,15 +3412,15 @@ func (s *Service) getNotificationRules(ctx context.Context, orgID platform.ID) (
} }
func (s *Service) getAllTasks(ctx context.Context, orgID platform.ID) ([]*influxdb.Task, error) { func (s *Service) getAllTasks(ctx context.Context, orgID platform.ID) ([]*taskmodel.Task, error) {
var ( var (
out []*influxdb.Task out []*taskmodel.Task
afterID *platform.ID afterID *platform.ID
) )
for { for {
f := influxdb.TaskFilter{ f := taskmodel.TaskFilter{
OrganizationID: &orgID, OrganizationID: &orgID,
Limit: influxdb.TaskMaxPageSize, Limit: taskmodel.TaskMaxPageSize,
} }
if afterID != nil { if afterID != nil {
f.After = afterID f.After = afterID
@ -3688,8 +3688,8 @@ func validURLs(urls []string) error {
return nil return nil
} }
func isRestrictedTask(t *influxdb.Task) bool { func isRestrictedTask(t *taskmodel.Task) bool {
return t != nil && t.Type != influxdb.TaskSystemType return t != nil && t.Type != taskmodel.TaskSystemType
} }
func isSystemBucket(b *influxdb.Bucket) bool { func isSystemBucket(b *influxdb.Bucket) bool {

View File

@ -4,10 +4,10 @@ import (
"reflect" "reflect"
"sort" "sort"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/notification/rule" "github.com/influxdata/influxdb/v2/notification/rule"
"github.com/influxdata/influxdb/v2/task/taskmodel"
) )
type stateCoordinator struct { type stateCoordinator struct {
@ -1347,7 +1347,7 @@ type stateTask struct {
labelAssociations []*stateLabel labelAssociations []*stateLabel
parserTask *task parserTask *task
existing *influxdb.Task existing *taskmodel.Task
} }
func (t *stateTask) ID() platform.ID { func (t *stateTask) ID() platform.ID {

View File

@ -13,15 +13,15 @@ import (
"testing" "testing"
"time" "time"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/platform" "github.com/influxdata/influxdb/v2/kit/platform"
errors2 "github.com/influxdata/influxdb/v2/kit/platform/errors" errors2 "github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/mock" "github.com/influxdata/influxdb/v2/mock"
"github.com/influxdata/influxdb/v2/notification" "github.com/influxdata/influxdb/v2/notification"
icheck "github.com/influxdata/influxdb/v2/notification/check" icheck "github.com/influxdata/influxdb/v2/notification/check"
"github.com/influxdata/influxdb/v2/notification/endpoint" "github.com/influxdata/influxdb/v2/notification/endpoint"
"github.com/influxdata/influxdb/v2/notification/rule" "github.com/influxdata/influxdb/v2/notification/rule"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest" "go.uber.org/zap/zaptest"
@ -453,7 +453,7 @@ func TestService(t *testing.T) {
ID: &id, ID: &id,
Name: "http-none-auth-notification-endpoint", Name: "http-none-auth-notification-endpoint",
Description: "old desc", Description: "old desc",
Status: influxdb.TaskStatusInactive, Status: taskmodel.TaskStatusInactive,
}, },
Method: "POST", Method: "POST",
AuthMethod: "none", AuthMethod: "none",
@ -500,7 +500,7 @@ func TestService(t *testing.T) {
ID: &id, ID: &id,
Name: "http-none-auth-notification-endpoint", Name: "http-none-auth-notification-endpoint",
Description: "http none auth desc", Description: "http none auth desc",
Status: influxdb.TaskStatusActive, Status: taskmodel.TaskStatusActive,
}, },
AuthMethod: "none", AuthMethod: "none",
Method: "GET", Method: "GET",
@ -561,7 +561,7 @@ func TestService(t *testing.T) {
// This name here matches the endpoint identified in the template notification rule // This name here matches the endpoint identified in the template notification rule
Name: "endpoint-0", Name: "endpoint-0",
Description: "old desc", Description: "old desc",
Status: influxdb.TaskStatusInactive, Status: taskmodel.TaskStatusInactive,
}, },
Method: "POST", Method: "POST",
AuthMethod: "none", AuthMethod: "none",
@ -1330,13 +1330,13 @@ func TestService(t *testing.T) {
t.Run("maps tasks with labels", func(t *testing.T) { t.Run("maps tasks with labels", func(t *testing.T) {
opts := func() []ServiceSetterFn { opts := func() []ServiceSetterFn {
fakeTaskSVC := mock.NewTaskService() fakeTaskSVC := mock.NewTaskService()
fakeTaskSVC.CreateTaskFn = func(ctx context.Context, tc influxdb.TaskCreate) (*influxdb.Task, error) { fakeTaskSVC.CreateTaskFn = func(ctx context.Context, tc taskmodel.TaskCreate) (*taskmodel.Task, error) {
reg := regexp.MustCompile(`name: "(.+)",`) reg := regexp.MustCompile(`name: "(.+)",`)
names := reg.FindStringSubmatch(tc.Flux) names := reg.FindStringSubmatch(tc.Flux)
if len(names) < 2 { if len(names) < 2 {
return nil, errors.New("bad flux query provided: " + tc.Flux) return nil, errors.New("bad flux query provided: " + tc.Flux)
} }
return &influxdb.Task{ return &taskmodel.Task{
ID: platform.ID(rand.Int()), ID: platform.ID(rand.Int()),
Type: tc.Type, Type: tc.Type,
OrganizationID: tc.OrganizationID, OrganizationID: tc.OrganizationID,
@ -1546,13 +1546,13 @@ func TestService(t *testing.T) {
orgID := platform.ID(9000) orgID := platform.ID(9000)
fakeTaskSVC := mock.NewTaskService() fakeTaskSVC := mock.NewTaskService()
fakeTaskSVC.CreateTaskFn = func(ctx context.Context, tc influxdb.TaskCreate) (*influxdb.Task, error) { fakeTaskSVC.CreateTaskFn = func(ctx context.Context, tc taskmodel.TaskCreate) (*taskmodel.Task, error) {
reg := regexp.MustCompile(`name: "(.+)",`) reg := regexp.MustCompile(`name: "(.+)",`)
names := reg.FindStringSubmatch(tc.Flux) names := reg.FindStringSubmatch(tc.Flux)
if len(names) < 2 { if len(names) < 2 {
return nil, errors.New("bad flux query provided: " + tc.Flux) return nil, errors.New("bad flux query provided: " + tc.Flux)
} }
return &influxdb.Task{ return &taskmodel.Task{
ID: platform.ID(fakeTaskSVC.CreateTaskCalls.Count() + 1), ID: platform.ID(fakeTaskSVC.CreateTaskCalls.Count() + 1),
Type: tc.Type, Type: tc.Type,
OrganizationID: tc.OrganizationID, OrganizationID: tc.OrganizationID,
@ -1586,11 +1586,11 @@ func TestService(t *testing.T) {
t.Run("rolls back all created tasks on an error", func(t *testing.T) { t.Run("rolls back all created tasks on an error", func(t *testing.T) {
testfileRunner(t, "testdata/tasks.yml", func(t *testing.T, template *Template) { testfileRunner(t, "testdata/tasks.yml", func(t *testing.T, template *Template) {
fakeTaskSVC := mock.NewTaskService() fakeTaskSVC := mock.NewTaskService()
fakeTaskSVC.CreateTaskFn = func(ctx context.Context, tc influxdb.TaskCreate) (*influxdb.Task, error) { fakeTaskSVC.CreateTaskFn = func(ctx context.Context, tc taskmodel.TaskCreate) (*taskmodel.Task, error) {
if fakeTaskSVC.CreateTaskCalls.Count() == 1 { if fakeTaskSVC.CreateTaskCalls.Count() == 1 {
return nil, errors.New("expected error") return nil, errors.New("expected error")
} }
return &influxdb.Task{ return &taskmodel.Task{
ID: platform.ID(fakeTaskSVC.CreateTaskCalls.Count() + 1), ID: platform.ID(fakeTaskSVC.CreateTaskCalls.Count() + 1),
}, nil }, nil
} }
@ -3275,7 +3275,7 @@ func TestService(t *testing.T) {
Base: endpoint.Base{ Base: endpoint.Base{
Name: "pd-endpoint", Name: "pd-endpoint",
Description: "desc", Description: "desc",
Status: influxdb.TaskStatusActive, Status: taskmodel.TaskStatusActive,
}, },
ClientURL: "http://example.com", ClientURL: "http://example.com",
RoutingKey: influxdb.SecretField{Key: "-routing-key"}, RoutingKey: influxdb.SecretField{Key: "-routing-key"},
@ -3288,7 +3288,7 @@ func TestService(t *testing.T) {
Base: endpoint.Base{ Base: endpoint.Base{
Name: "pd-endpoint", Name: "pd-endpoint",
Description: "desc", Description: "desc",
Status: influxdb.TaskStatusActive, Status: taskmodel.TaskStatusActive,
}, },
ClientURL: "http://example.com", ClientURL: "http://example.com",
RoutingKey: influxdb.SecretField{Key: "-routing-key"}, RoutingKey: influxdb.SecretField{Key: "-routing-key"},
@ -3300,7 +3300,7 @@ func TestService(t *testing.T) {
Base: endpoint.Base{ Base: endpoint.Base{
Name: "pd-endpoint", Name: "pd-endpoint",
Description: "desc", Description: "desc",
Status: influxdb.TaskStatusInactive, Status: taskmodel.TaskStatusInactive,
}, },
URL: "http://example.com", URL: "http://example.com",
Token: influxdb.SecretField{Key: "tokne"}, Token: influxdb.SecretField{Key: "tokne"},
@ -3312,7 +3312,7 @@ func TestService(t *testing.T) {
Base: endpoint.Base{ Base: endpoint.Base{
Name: "pd-endpoint", Name: "pd-endpoint",
Description: "desc", Description: "desc",
Status: influxdb.TaskStatusInactive, Status: taskmodel.TaskStatusInactive,
}, },
AuthMethod: "basic", AuthMethod: "basic",
Method: "POST", Method: "POST",
@ -3327,7 +3327,7 @@ func TestService(t *testing.T) {
Base: endpoint.Base{ Base: endpoint.Base{
Name: "pd-endpoint", Name: "pd-endpoint",
Description: "desc", Description: "desc",
Status: influxdb.TaskStatusInactive, Status: taskmodel.TaskStatusInactive,
}, },
AuthMethod: "bearer", AuthMethod: "bearer",
Method: "GET", Method: "GET",
@ -3341,7 +3341,7 @@ func TestService(t *testing.T) {
Base: endpoint.Base{ Base: endpoint.Base{
Name: "pd-endpoint", Name: "pd-endpoint",
Description: "desc", Description: "desc",
Status: influxdb.TaskStatusInactive, Status: taskmodel.TaskStatusInactive,
}, },
AuthMethod: "none", AuthMethod: "none",
Method: "GET", Method: "GET",
@ -3404,7 +3404,7 @@ func TestService(t *testing.T) {
ID: newTestIDPtr(1), ID: newTestIDPtr(1),
Name: "pd endpoint", Name: "pd endpoint",
Description: "desc", Description: "desc",
Status: influxdb.TaskStatusActive, Status: taskmodel.TaskStatusActive,
}, },
ClientURL: "http://example.com", ClientURL: "http://example.com",
RoutingKey: influxdb.SecretField{Key: "-routing-key"}, RoutingKey: influxdb.SecretField{Key: "-routing-key"},
@ -3414,7 +3414,7 @@ func TestService(t *testing.T) {
ID: newTestIDPtr(2), ID: newTestIDPtr(2),
Name: "pd-endpoint", Name: "pd-endpoint",
Description: "desc pd", Description: "desc pd",
Status: influxdb.TaskStatusActive, Status: taskmodel.TaskStatusActive,
}, },
ClientURL: "http://example.com", ClientURL: "http://example.com",
RoutingKey: influxdb.SecretField{Key: "-routing-key"}, RoutingKey: influxdb.SecretField{Key: "-routing-key"},
@ -3424,7 +3424,7 @@ func TestService(t *testing.T) {
ID: newTestIDPtr(3), ID: newTestIDPtr(3),
Name: "slack endpoint", Name: "slack endpoint",
Description: "desc slack", Description: "desc slack",
Status: influxdb.TaskStatusInactive, Status: taskmodel.TaskStatusInactive,
}, },
URL: "http://example.com", URL: "http://example.com",
Token: influxdb.SecretField{Key: "tokne"}, Token: influxdb.SecretField{Key: "tokne"},
@ -3559,7 +3559,7 @@ func TestService(t *testing.T) {
ID: newTestIDPtr(13), ID: newTestIDPtr(13),
Name: "endpoint_0", Name: "endpoint_0",
Description: "desc", Description: "desc",
Status: influxdb.TaskStatusActive, Status: taskmodel.TaskStatusActive,
}, },
ClientURL: "http://example.com", ClientURL: "http://example.com",
RoutingKey: influxdb.SecretField{Key: "-routing-key"}, RoutingKey: influxdb.SecretField{Key: "-routing-key"},
@ -3576,7 +3576,7 @@ func TestService(t *testing.T) {
ID: newTestIDPtr(13), ID: newTestIDPtr(13),
Name: "endpoint_0", Name: "endpoint_0",
Description: "desc", Description: "desc",
Status: influxdb.TaskStatusInactive, Status: taskmodel.TaskStatusInactive,
}, },
URL: "http://example.com", URL: "http://example.com",
Token: influxdb.SecretField{Key: "tokne"}, Token: influxdb.SecretField{Key: "tokne"},
@ -3594,7 +3594,7 @@ func TestService(t *testing.T) {
ID: newTestIDPtr(13), ID: newTestIDPtr(13),
Name: "endpoint_0", Name: "endpoint_0",
Description: "desc", Description: "desc",
Status: influxdb.TaskStatusInactive, Status: taskmodel.TaskStatusInactive,
}, },
AuthMethod: "none", AuthMethod: "none",
Method: "GET", Method: "GET",
@ -3705,7 +3705,7 @@ func TestService(t *testing.T) {
ID: &id, ID: &id,
Name: "endpoint_0", Name: "endpoint_0",
Description: "desc", Description: "desc",
Status: influxdb.TaskStatusInactive, Status: taskmodel.TaskStatusInactive,
}, },
AuthMethod: "none", AuthMethod: "none",
Method: "GET", Method: "GET",
@ -3950,27 +3950,27 @@ func TestService(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
newName string newName string
task influxdb.Task task taskmodel.Task
}{ }{
{ {
name: "every offset is set", name: "every offset is set",
newName: "new name", newName: "new name",
task: influxdb.Task{ task: taskmodel.Task{
ID: 1, ID: 1,
Name: "name_9000", Name: "name_9000",
Every: time.Minute.String(), Every: time.Minute.String(),
Offset: 10 * time.Second, Offset: 10 * time.Second,
Type: influxdb.TaskSystemType, Type: taskmodel.TaskSystemType,
Flux: `option task = { name: "larry" } from(bucket: "rucket") |> yield()`, Flux: `option task = { name: "larry" } from(bucket: "rucket") |> yield()`,
}, },
}, },
{ {
name: "cron is set", name: "cron is set",
task: influxdb.Task{ task: taskmodel.Task{
ID: 1, ID: 1,
Name: "name_0", Name: "name_0",
Cron: "2 * * * *", Cron: "2 * * * *",
Type: influxdb.TaskSystemType, Type: taskmodel.TaskSystemType,
Flux: `option task = { name: "larry" } from(bucket: "rucket") |> yield()`, Flux: `option task = { name: "larry" } from(bucket: "rucket") |> yield()`,
}, },
}, },
@ -3979,14 +3979,14 @@ func TestService(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
fn := func(t *testing.T) { fn := func(t *testing.T) {
taskSVC := mock.NewTaskService() taskSVC := mock.NewTaskService()
taskSVC.FindTaskByIDFn = func(ctx context.Context, id platform.ID) (*influxdb.Task, error) { taskSVC.FindTaskByIDFn = func(ctx context.Context, id platform.ID) (*taskmodel.Task, error) {
if id != tt.task.ID { if id != tt.task.ID {
return nil, errors.New("wrong id provided: " + id.String()) return nil, errors.New("wrong id provided: " + id.String())
} }
return &tt.task, nil return &tt.task, nil
} }
taskSVC.FindTasksFn = func(ctx context.Context, filter influxdb.TaskFilter) ([]*influxdb.Task, int, error) { taskSVC.FindTasksFn = func(ctx context.Context, filter taskmodel.TaskFilter) ([]*taskmodel.Task, int, error) {
return []*influxdb.Task{&tt.task}, 1, nil return []*taskmodel.Task{&tt.task}, 1, nil
} }
svc := newTestService(WithTaskSVC(taskSVC)) svc := newTestService(WithTaskSVC(taskSVC))
@ -4026,13 +4026,13 @@ func TestService(t *testing.T) {
t.Run("handles multiple tasks of same name", func(t *testing.T) { t.Run("handles multiple tasks of same name", func(t *testing.T) {
taskSVC := mock.NewTaskService() taskSVC := mock.NewTaskService()
taskSVC.FindTaskByIDFn = func(ctx context.Context, id platform.ID) (*influxdb.Task, error) { taskSVC.FindTaskByIDFn = func(ctx context.Context, id platform.ID) (*taskmodel.Task, error) {
return &influxdb.Task{ return &taskmodel.Task{
ID: id, ID: id,
Type: influxdb.TaskSystemType, Type: taskmodel.TaskSystemType,
Name: "same name", Name: "same name",
Description: "desc", Description: "desc",
Status: influxdb.TaskStatusActive, Status: taskmodel.TaskStatusActive,
Flux: `from(bucket: "foo")`, Flux: `from(bucket: "foo")`,
Every: "5m0s", Every: "5m0s",
}, nil }, nil
@ -4071,14 +4071,14 @@ func TestService(t *testing.T) {
}) })
t.Run("tasks by name", func(t *testing.T) { t.Run("tasks by name", func(t *testing.T) {
knownTasks := []*influxdb.Task{ knownTasks := []*taskmodel.Task{
{ {
ID: 1, ID: 1,
Name: "task", Name: "task",
Description: "task 1", Description: "task 1",
Every: time.Minute.String(), Every: time.Minute.String(),
Offset: 10 * time.Second, Offset: 10 * time.Second,
Type: influxdb.TaskSystemType, Type: taskmodel.TaskSystemType,
Flux: `option task = { name: "larry" } from(bucket: "rucket") |> yield()`, Flux: `option task = { name: "larry" } from(bucket: "rucket") |> yield()`,
}, },
{ {
@ -4086,7 +4086,7 @@ func TestService(t *testing.T) {
Name: "taskCopy", Name: "taskCopy",
Description: "task 2", Description: "task 2",
Cron: "2 * * * *", Cron: "2 * * * *",
Type: influxdb.TaskSystemType, Type: taskmodel.TaskSystemType,
Flux: `option task = { name: "curly" } from(bucket: "rucket") |> yield()`, Flux: `option task = { name: "curly" } from(bucket: "rucket") |> yield()`,
}, },
{ {
@ -4094,7 +4094,7 @@ func TestService(t *testing.T) {
Name: "taskCopy", Name: "taskCopy",
Description: "task 3", Description: "task 3",
Cron: "2 3 4 5 *", Cron: "2 3 4 5 *",
Type: influxdb.TaskSystemType, Type: taskmodel.TaskSystemType,
Flux: `option task = { name: "moe" } from(bucket: "rucket") |> yield()`, Flux: `option task = { name: "moe" } from(bucket: "rucket") |> yield()`,
}, },
} }
@ -4103,17 +4103,17 @@ func TestService(t *testing.T) {
name string name string
findName string findName string
findID platform.ID findID platform.ID
expected []*influxdb.Task expected []*taskmodel.Task
}{ }{
{ {
name: "find task with unique name", name: "find task with unique name",
findName: "task", findName: "task",
expected: []*influxdb.Task{knownTasks[0]}, expected: []*taskmodel.Task{knownTasks[0]},
}, },
{ {
name: "find multiple tasks with shared name", name: "find multiple tasks with shared name",
findName: "taskCopy", findName: "taskCopy",
expected: []*influxdb.Task{knownTasks[1], knownTasks[2]}, expected: []*taskmodel.Task{knownTasks[1], knownTasks[2]},
}, },
{ {
name: "find no tasks", name: "find no tasks",
@ -4123,20 +4123,20 @@ func TestService(t *testing.T) {
{ {
name: "find task by id", name: "find task by id",
findID: platform.ID(2), findID: platform.ID(2),
expected: []*influxdb.Task{knownTasks[1]}, expected: []*taskmodel.Task{knownTasks[1]},
}, },
{ {
name: "find by id, set new name", name: "find by id, set new name",
findID: platform.ID(2), findID: platform.ID(2),
findName: "renamedTask", findName: "renamedTask",
expected: []*influxdb.Task{knownTasks[1]}, expected: []*taskmodel.Task{knownTasks[1]},
}, },
} }
for _, tt := range tests { for _, tt := range tests {
fn := func(t *testing.T) { fn := func(t *testing.T) {
taskSVC := mock.NewTaskService() taskSVC := mock.NewTaskService()
taskSVC.FindTaskByIDFn = func(ctx context.Context, id platform.ID) (*influxdb.Task, error) { taskSVC.FindTaskByIDFn = func(ctx context.Context, id platform.ID) (*taskmodel.Task, error) {
for i := range knownTasks { for i := range knownTasks {
if knownTasks[i].ID == id { if knownTasks[i].ID == id {
return knownTasks[i], nil return knownTasks[i], nil
@ -4145,8 +4145,8 @@ func TestService(t *testing.T) {
return nil, errors.New("wrong id provided: " + id.String()) return nil, errors.New("wrong id provided: " + id.String())
} }
taskSVC.FindTasksFn = func(ctx context.Context, filter influxdb.TaskFilter) ([]*influxdb.Task, int, error) { taskSVC.FindTasksFn = func(ctx context.Context, filter taskmodel.TaskFilter) ([]*taskmodel.Task, int, error) {
tasks := []*influxdb.Task{} tasks := []*taskmodel.Task{}
for i := range knownTasks { for i := range knownTasks {
if knownTasks[i].Name == *filter.Name { if knownTasks[i].Name == *filter.Name {
tasks = append(tasks, knownTasks[i]) tasks = append(tasks, knownTasks[i])
@ -4850,27 +4850,27 @@ func TestService(t *testing.T) {
} }
taskSVC := mock.NewTaskService() taskSVC := mock.NewTaskService()
taskSVC.FindTasksFn = func(ctx context.Context, f influxdb.TaskFilter) ([]*influxdb.Task, int, error) { taskSVC.FindTasksFn = func(ctx context.Context, f taskmodel.TaskFilter) ([]*taskmodel.Task, int, error) {
if f.After != nil { if f.After != nil {
return nil, 0, nil return nil, 0, nil
} }
return []*influxdb.Task{ return []*taskmodel.Task{
{ID: 31, Type: influxdb.TaskSystemType}, {ID: 31, Type: taskmodel.TaskSystemType},
{ID: expectedCheck.TaskID, Type: influxdb.TaskSystemType}, // this one should be ignored in the return {ID: expectedCheck.TaskID, Type: taskmodel.TaskSystemType}, // this one should be ignored in the return
{ID: expectedRule.TaskID, Type: influxdb.TaskSystemType}, // this one should be ignored in the return as well {ID: expectedRule.TaskID, Type: taskmodel.TaskSystemType}, // this one should be ignored in the return as well
{ID: 99}, // this one should be skipped since it is not a system task {ID: 99}, // this one should be skipped since it is not a system task
}, 3, nil }, 3, nil
} }
taskSVC.FindTaskByIDFn = func(ctx context.Context, id platform.ID) (*influxdb.Task, error) { taskSVC.FindTaskByIDFn = func(ctx context.Context, id platform.ID) (*taskmodel.Task, error) {
if id != 31 { if id != 31 {
return nil, errors.New("wrong id: " + id.String()) return nil, errors.New("wrong id: " + id.String())
} }
return &influxdb.Task{ return &taskmodel.Task{
ID: id, ID: id,
Name: "task_0", Name: "task_0",
Every: time.Minute.String(), Every: time.Minute.String(),
Offset: 10 * time.Second, Offset: 10 * time.Second,
Type: influxdb.TaskSystemType, Type: taskmodel.TaskSystemType,
Flux: `option task = { name: "larry" } from(bucket: "rucket") |> yield()`, Flux: `option task = { name: "larry" } from(bucket: "rucket") |> yield()`,
}, nil }, nil
} }

View File

@ -1,35 +0,0 @@
package influxdb
import (
"context"
"github.com/influxdata/flux/ast"
"github.com/influxdata/flux/complete"
"github.com/influxdata/flux/interpreter"
"github.com/influxdata/flux/values"
)
// TODO(desa): These files are possibly a temporary. This is needed
// as a part of the source work that is being done.
// See https://github.com/influxdata/platform/issues/594 for more info.
// SourceQuery is a query for a source.
type SourceQuery struct {
Query string `json:"query"`
Type string `json:"type"`
}
// FluxLanguageService is a service for interacting with flux code.
type FluxLanguageService interface {
// Parse will take flux source code and produce a package.
// If there are errors when parsing, the first error is returned.
// An ast.Package may be returned when a parsing error occurs,
// but it may be null if parsing didn't even occur.
Parse(source string) (*ast.Package, error)
// EvalAST will evaluate and run an AST.
EvalAST(ctx context.Context, astPkg *ast.Package) ([]interpreter.SideEffect, values.Scope, error)
// Completer will return a flux completer.
Completer() complete.Completer
}

View File

@ -10,11 +10,31 @@ import (
"github.com/influxdata/flux/parser" "github.com/influxdata/flux/parser"
"github.com/influxdata/flux/runtime" "github.com/influxdata/flux/runtime"
"github.com/influxdata/flux/values" "github.com/influxdata/flux/values"
"github.com/influxdata/influxdb/v2"
) )
// SourceQuery is a query for a source.
type SourceQuery struct {
Query string `json:"query"`
Type string `json:"type"`
}
// FluxLanguageService is a service for interacting with flux code.
type FluxLanguageService interface {
// Parse will take flux source code and produce a package.
// If there are errors when parsing, the first error is returned.
// An ast.Package may be returned when a parsing error occurs,
// but it may be null if parsing didn't even occur.
Parse(source string) (*ast.Package, error)
// EvalAST will evaluate and run an AST.
EvalAST(ctx context.Context, astPkg *ast.Package) ([]interpreter.SideEffect, values.Scope, error)
// Completer will return a flux completer.
Completer() complete.Completer
}
// DefaultService is the default language service. // DefaultService is the default language service.
var DefaultService influxdb.FluxLanguageService = defaultService{} var DefaultService FluxLanguageService = defaultService{}
type defaultService struct{} type defaultService struct{}

View File

@ -4,14 +4,13 @@ import (
"context" "context"
"io" "io"
"github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/flux" "github.com/influxdata/flux"
"github.com/influxdata/flux/ast" "github.com/influxdata/flux/ast"
"github.com/influxdata/flux/interpreter" "github.com/influxdata/flux/interpreter"
"github.com/influxdata/flux/values" "github.com/influxdata/flux/values"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/check" "github.com/influxdata/influxdb/v2/kit/check"
"github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/influxdb/v2/query/fluxlang"
) )
// QueryService represents a type capable of performing queries. // QueryService represents a type capable of performing queries.
@ -46,7 +45,7 @@ type ProxyQueryService interface {
// but it may be null if parsing didn't even occur. // but it may be null if parsing didn't even occur.
// //
// This will return an error if the FluxLanguageService is nil. // This will return an error if the FluxLanguageService is nil.
func Parse(lang influxdb.FluxLanguageService, source string) (*ast.Package, error) { func Parse(lang fluxlang.FluxLanguageService, source string) (*ast.Package, error) {
if lang == nil { if lang == nil {
return nil, &errors.Error{ return nil, &errors.Error{
Code: errors.EInternal, Code: errors.EInternal,
@ -59,7 +58,7 @@ func Parse(lang influxdb.FluxLanguageService, source string) (*ast.Package, erro
// EvalAST will evaluate and run an AST. // EvalAST will evaluate and run an AST.
// //
// This will return an error if the FluxLanguageService is nil. // This will return an error if the FluxLanguageService is nil.
func EvalAST(ctx context.Context, lang influxdb.FluxLanguageService, astPkg *ast.Package) ([]interpreter.SideEffect, values.Scope, error) { func EvalAST(ctx context.Context, lang fluxlang.FluxLanguageService, astPkg *ast.Package) ([]interpreter.SideEffect, values.Scope, error) {
if lang == nil { if lang == nil {
return nil, nil, &errors.Error{ return nil, nil, &errors.Error{
Code: errors.EInternal, Code: errors.EInternal,

View File

@ -7,15 +7,15 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/influxdata/influxdb/v2/kit/platform"
errors2 "github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/flux" "github.com/influxdata/flux"
"github.com/influxdata/flux/lang" "github.com/influxdata/flux/lang"
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/errors" "github.com/influxdata/influxdb/v2/kit/errors"
"github.com/influxdata/influxdb/v2/kit/platform"
errors2 "github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/influxdb/v2/query" "github.com/influxdata/influxdb/v2/query"
"github.com/influxdata/influxdb/v2/storage" "github.com/influxdata/influxdb/v2/storage"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -34,23 +34,11 @@ const (
// RunRecorder is a type which records runs into an influxdb // RunRecorder is a type which records runs into an influxdb
// backed storage mechanism // backed storage mechanism
type RunRecorder interface { type RunRecorder interface {
Record(ctx context.Context, orgID platform.ID, org string, bucketID platform.ID, bucket string, run *influxdb.Run) error Record(ctx context.Context, orgID platform.ID, org string, bucketID platform.ID, bucket string, run *taskmodel.Run) error
}
// NewAnalyticalRunStorage creates a new analytical store with access to the necessary systems for storing data and to act as a middleware
func NewAnalyticalRunStorage(log *zap.Logger, ts influxdb.TaskService, bs influxdb.BucketService, tcs TaskControlService, rr RunRecorder, qs query.QueryService) *AnalyticalStorage {
return &AnalyticalStorage{
log: log,
TaskService: ts,
BucketService: bs,
TaskControlService: tcs,
rr: rr,
qs: qs,
}
} }
// NewAnalyticalStorage creates a new analytical store with access to the necessary systems for storing data and to act as a middleware (deprecated) // NewAnalyticalStorage creates a new analytical store with access to the necessary systems for storing data and to act as a middleware (deprecated)
func NewAnalyticalStorage(log *zap.Logger, ts influxdb.TaskService, bs influxdb.BucketService, tcs TaskControlService, pw storage.PointsWriter, qs query.QueryService) *AnalyticalStorage { func NewAnalyticalStorage(log *zap.Logger, ts taskmodel.TaskService, bs influxdb.BucketService, tcs TaskControlService, pw storage.PointsWriter, qs query.QueryService) *AnalyticalStorage {
return &AnalyticalStorage{ return &AnalyticalStorage{
log: log, log: log,
TaskService: ts, TaskService: ts,
@ -62,7 +50,7 @@ func NewAnalyticalStorage(log *zap.Logger, ts influxdb.TaskService, bs influxdb.
} }
type AnalyticalStorage struct { type AnalyticalStorage struct {
influxdb.TaskService taskmodel.TaskService
influxdb.BucketService influxdb.BucketService
TaskControlService TaskControlService
@ -71,7 +59,7 @@ type AnalyticalStorage struct {
log *zap.Logger log *zap.Logger
} }
func (as *AnalyticalStorage) FinishRun(ctx context.Context, taskID, runID platform.ID) (*influxdb.Run, error) { func (as *AnalyticalStorage) FinishRun(ctx context.Context, taskID, runID platform.ID) (*taskmodel.Run, error) {
run, err := as.TaskControlService.FinishRun(ctx, taskID, runID) run, err := as.TaskControlService.FinishRun(ctx, taskID, runID)
if run != nil && run.ID.String() != "" { if run != nil && run.ID.String() != "" {
task, err := as.TaskService.FindTaskByID(ctx, run.TaskID) task, err := as.TaskService.FindTaskByID(ctx, run.TaskID)
@ -92,8 +80,8 @@ func (as *AnalyticalStorage) FinishRun(ctx context.Context, taskID, runID platfo
// FindLogs returns logs for a run. // FindLogs returns logs for a run.
// First attempt to use the TaskService, then append additional analytical's logs to the list // First attempt to use the TaskService, then append additional analytical's logs to the list
func (as *AnalyticalStorage) FindLogs(ctx context.Context, filter influxdb.LogFilter) ([]*influxdb.Log, int, error) { func (as *AnalyticalStorage) FindLogs(ctx context.Context, filter taskmodel.LogFilter) ([]*taskmodel.Log, int, error) {
var logs []*influxdb.Log var logs []*taskmodel.Log
if filter.Run != nil { if filter.Run != nil {
run, err := as.FindRunByID(ctx, filter.Task, *filter.Run) run, err := as.FindRunByID(ctx, filter.Task, *filter.Run)
if err != nil { if err != nil {
@ -106,7 +94,7 @@ func (as *AnalyticalStorage) FindLogs(ctx context.Context, filter influxdb.LogFi
} }
// add historical logs to the transactional logs. // add historical logs to the transactional logs.
runs, n, err := as.FindRuns(ctx, influxdb.RunFilter{Task: filter.Task}) runs, n, err := as.FindRuns(ctx, taskmodel.RunFilter{Task: filter.Task})
if err != nil { if err != nil {
return nil, 0, err return nil, 0, err
} }
@ -122,13 +110,13 @@ func (as *AnalyticalStorage) FindLogs(ctx context.Context, filter influxdb.LogFi
// FindRuns returns a list of runs that match a filter and the total count of returned runs. // FindRuns returns a list of runs that match a filter and the total count of returned runs.
// First attempt to use the TaskService, then append additional analytical's runs to the list // First attempt to use the TaskService, then append additional analytical's runs to the list
func (as *AnalyticalStorage) FindRuns(ctx context.Context, filter influxdb.RunFilter) ([]*influxdb.Run, int, error) { func (as *AnalyticalStorage) FindRuns(ctx context.Context, filter taskmodel.RunFilter) ([]*taskmodel.Run, int, error) {
if filter.Limit == 0 { if filter.Limit == 0 {
filter.Limit = influxdb.TaskDefaultPageSize filter.Limit = taskmodel.TaskDefaultPageSize
} }
if filter.Limit < 0 || filter.Limit > influxdb.TaskMaxPageSize { if filter.Limit < 0 || filter.Limit > taskmodel.TaskMaxPageSize {
return nil, 0, influxdb.ErrOutOfBoundsLimit return nil, 0, taskmodel.ErrOutOfBoundsLimit
} }
runs, n, err := as.TaskService.FindRuns(ctx, filter) runs, n, err := as.TaskService.FindRuns(ctx, filter)
@ -242,7 +230,7 @@ func (as *AnalyticalStorage) FindRuns(ctx context.Context, filter influxdb.RunFi
} }
// remove any kv runs that exist in the list of completed runs // remove any kv runs that exist in the list of completed runs
func (as *AnalyticalStorage) combineRuns(currentRuns, completeRuns []*influxdb.Run) []*influxdb.Run { func (as *AnalyticalStorage) combineRuns(currentRuns, completeRuns []*taskmodel.Run) []*taskmodel.Run {
crMap := map[platform.ID]int{} crMap := map[platform.ID]int{}
// track the current runs // track the current runs
@ -263,7 +251,7 @@ func (as *AnalyticalStorage) combineRuns(currentRuns, completeRuns []*influxdb.R
// FindRunByID returns a single run. // FindRunByID returns a single run.
// First see if it is in the existing TaskService. If not pull it from analytical storage. // First see if it is in the existing TaskService. If not pull it from analytical storage.
func (as *AnalyticalStorage) FindRunByID(ctx context.Context, taskID, runID platform.ID) (*influxdb.Run, error) { func (as *AnalyticalStorage) FindRunByID(ctx context.Context, taskID, runID platform.ID) (*taskmodel.Run, error) {
// check the taskService to see if the run is on its list // check the taskService to see if the run is on its list
run, err := as.TaskService.FindRunByID(ctx, taskID, runID) run, err := as.TaskService.FindRunByID(ctx, taskID, runID)
if err != nil { if err != nil {
@ -334,7 +322,7 @@ func (as *AnalyticalStorage) FindRunByID(ctx context.Context, taskID, runID plat
} }
if len(re.runs) == 0 { if len(re.runs) == 0 {
return nil, influxdb.ErrRunNotFound return nil, taskmodel.ErrRunNotFound
} }
@ -348,7 +336,7 @@ func (as *AnalyticalStorage) FindRunByID(ctx context.Context, taskID, runID plat
return re.runs[0], err return re.runs[0], err
} }
func (as *AnalyticalStorage) RetryRun(ctx context.Context, taskID, runID platform.ID) (*influxdb.Run, error) { func (as *AnalyticalStorage) RetryRun(ctx context.Context, taskID, runID platform.ID) (*taskmodel.Run, error) {
run, err := as.TaskService.RetryRun(ctx, taskID, runID) run, err := as.TaskService.RetryRun(ctx, taskID, runID)
if err != nil { if err != nil {
if err, ok := err.(*errors2.Error); !ok || err.Msg != "run not found" { if err, ok := err.(*errors2.Error); !ok || err.Msg != "run not found" {
@ -372,7 +360,7 @@ func (as *AnalyticalStorage) RetryRun(ctx context.Context, taskID, runID platfor
} }
type runReader struct { type runReader struct {
runs []*influxdb.Run runs []*taskmodel.Run
log *zap.Logger log *zap.Logger
} }
@ -382,7 +370,7 @@ func (re *runReader) readTable(tbl flux.Table) error {
func (re *runReader) readRuns(cr flux.ColReader) error { func (re *runReader) readRuns(cr flux.ColReader) error {
for i := 0; i < cr.Len(); i++ { for i := 0; i < cr.Len(); i++ {
var r influxdb.Run var r taskmodel.Run
for j, col := range cr.Cols() { for j, col := range cr.Cols() {
switch col.Label { switch col.Label {
case runIDField: case runIDField:

View File

@ -7,8 +7,6 @@ import (
"testing" "testing"
"time" "time"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/golang/mock/gomock" "github.com/golang/mock/gomock"
"github.com/influxdata/flux" "github.com/influxdata/flux"
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
@ -16,6 +14,7 @@ import (
icontext "github.com/influxdata/influxdb/v2/context" icontext "github.com/influxdata/influxdb/v2/context"
_ "github.com/influxdata/influxdb/v2/fluxinit/static" _ "github.com/influxdata/influxdb/v2/fluxinit/static"
"github.com/influxdata/influxdb/v2/inmem" "github.com/influxdata/influxdb/v2/inmem"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/kv" "github.com/influxdata/influxdb/v2/kv"
"github.com/influxdata/influxdb/v2/kv/migration/all" "github.com/influxdata/influxdb/v2/kv/migration/all"
"github.com/influxdata/influxdb/v2/mock" "github.com/influxdata/influxdb/v2/mock"
@ -27,6 +26,7 @@ import (
storageflux "github.com/influxdata/influxdb/v2/storage/flux" storageflux "github.com/influxdata/influxdb/v2/storage/flux"
"github.com/influxdata/influxdb/v2/task/backend" "github.com/influxdata/influxdb/v2/task/backend"
"github.com/influxdata/influxdb/v2/task/servicetest" "github.com/influxdata/influxdb/v2/task/servicetest"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"github.com/influxdata/influxdb/v2/tenant" "github.com/influxdata/influxdb/v2/tenant"
"github.com/influxdata/influxdb/v2/v1/services/meta" "github.com/influxdata/influxdb/v2/v1/services/meta"
storage2 "github.com/influxdata/influxdb/v2/v1/services/storage" storage2 "github.com/influxdata/influxdb/v2/v1/services/storage"
@ -62,8 +62,7 @@ func TestAnalyticalStore(t *testing.T) {
var ( var (
ab = newAnalyticalBackend(t, ts.OrganizationService, ts.BucketService, metaClient) ab = newAnalyticalBackend(t, ts.OrganizationService, ts.BucketService, metaClient)
rr = backend.NewStoragePointsWriterRecorder(logger, ab.PointsWriter()) svcStack = backend.NewAnalyticalStorage(logger, svc, ts.BucketService, svc, ab.PointsWriter(), ab.QueryService())
svcStack = backend.NewAnalyticalRunStorage(logger, svc, ts.BucketService, svc, rr, ab.QueryService())
) )
ts.BucketService = storage.NewBucketService(logger, ts.BucketService, ab.storageEngine) ts.BucketService = storage.NewBucketService(logger, ts.BucketService, ab.storageEngine)
@ -112,18 +111,18 @@ func TestDeduplicateRuns(t *testing.T) {
defer ab.Close(t) defer ab.Close(t)
mockTS := &mock.TaskService{ mockTS := &mock.TaskService{
FindTaskByIDFn: func(context.Context, platform.ID) (*influxdb.Task, error) { FindTaskByIDFn: func(context.Context, platform.ID) (*taskmodel.Task, error) {
return &influxdb.Task{ID: 1, OrganizationID: 20}, nil return &taskmodel.Task{ID: 1, OrganizationID: 20}, nil
}, },
FindRunsFn: func(context.Context, influxdb.RunFilter) ([]*influxdb.Run, int, error) { FindRunsFn: func(context.Context, taskmodel.RunFilter) ([]*taskmodel.Run, int, error) {
return []*influxdb.Run{ return []*taskmodel.Run{
&influxdb.Run{ID: 2, Status: "started"}, &taskmodel.Run{ID: 2, Status: "started"},
}, 1, nil }, 1, nil
}, },
} }
mockTCS := &mock.TaskControlService{ mockTCS := &mock.TaskControlService{
FinishRunFn: func(ctx context.Context, taskID, runID platform.ID) (*influxdb.Run, error) { FinishRunFn: func(ctx context.Context, taskID, runID platform.ID) (*taskmodel.Run, error) {
return &influxdb.Run{ID: 2, TaskID: 1, Status: "success", ScheduledFor: time.Now(), StartedAt: time.Now().Add(1), FinishedAt: time.Now().Add(2)}, nil return &taskmodel.Run{ID: 2, TaskID: 1, Status: "success", ScheduledFor: time.Now(), StartedAt: time.Now().Add(1), FinishedAt: time.Now().Add(2)}, nil
}, },
} }
mockBS := mock.NewBucketService() mockBS := mock.NewBucketService()
@ -135,7 +134,7 @@ func TestDeduplicateRuns(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
runs, _, err := svcStack.FindRuns(context.Background(), influxdb.RunFilter{Task: 1}) runs, _, err := svcStack.FindRuns(context.Background(), taskmodel.RunFilter{Task: 1})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -5,8 +5,7 @@ import (
"time" "time"
"github.com/influxdata/influxdb/v2/kit/platform" "github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"github.com/influxdata/influxdb/v2"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -16,21 +15,21 @@ var now = func() time.Time {
// TaskService is a type on which tasks can be listed // TaskService is a type on which tasks can be listed
type TaskService interface { type TaskService interface {
FindTasks(context.Context, influxdb.TaskFilter) ([]*influxdb.Task, int, error) FindTasks(context.Context, taskmodel.TaskFilter) ([]*taskmodel.Task, int, error)
UpdateTask(context.Context, platform.ID, influxdb.TaskUpdate) (*influxdb.Task, error) UpdateTask(context.Context, platform.ID, taskmodel.TaskUpdate) (*taskmodel.Task, error)
} }
// Coordinator is a type with a single method which // Coordinator is a type with a single method which
// is called when a task has been created // is called when a task has been created
type Coordinator interface { type Coordinator interface {
TaskCreated(context.Context, *influxdb.Task) error TaskCreated(context.Context, *taskmodel.Task) error
} }
// NotifyCoordinatorOfExisting lists all tasks by the provided task service and for // NotifyCoordinatorOfExisting lists all tasks by the provided task service and for
// each task it calls the provided coordinators task created method // each task it calls the provided coordinators task created method
func NotifyCoordinatorOfExisting(ctx context.Context, log *zap.Logger, ts TaskService, coord Coordinator) error { func NotifyCoordinatorOfExisting(ctx context.Context, log *zap.Logger, ts TaskService, coord Coordinator) error {
// If we missed a Create Action // If we missed a Create Action
tasks, _, err := ts.FindTasks(ctx, influxdb.TaskFilter{}) tasks, _, err := ts.FindTasks(ctx, taskmodel.TaskFilter{})
if err != nil { if err != nil {
return err return err
} }
@ -38,11 +37,11 @@ func NotifyCoordinatorOfExisting(ctx context.Context, log *zap.Logger, ts TaskSe
latestCompleted := now() latestCompleted := now()
for len(tasks) > 0 { for len(tasks) > 0 {
for _, task := range tasks { for _, task := range tasks {
if task.Status != string(influxdb.TaskActive) { if task.Status != string(taskmodel.TaskActive) {
continue continue
} }
task, err := ts.UpdateTask(context.Background(), task.ID, influxdb.TaskUpdate{ task, err := ts.UpdateTask(context.Background(), task.ID, taskmodel.TaskUpdate{
LatestCompleted: &latestCompleted, LatestCompleted: &latestCompleted,
LatestScheduled: &latestCompleted, LatestScheduled: &latestCompleted,
}) })
@ -54,7 +53,7 @@ func NotifyCoordinatorOfExisting(ctx context.Context, log *zap.Logger, ts TaskSe
coord.TaskCreated(ctx, task) coord.TaskCreated(ctx, task)
} }
tasks, _, err = ts.FindTasks(ctx, influxdb.TaskFilter{ tasks, _, err = ts.FindTasks(ctx, taskmodel.TaskFilter{
After: &tasks[len(tasks)-1].ID, After: &tasks[len(tasks)-1].ID,
}) })
if err != nil { if err != nil {
@ -72,7 +71,7 @@ type TaskResumer func(ctx context.Context, id platform.ID, runID platform.ID) er
// TODO(docmerlin): this is temporary untill the executor queue is persistent // TODO(docmerlin): this is temporary untill the executor queue is persistent
func TaskNotifyCoordinatorOfExisting(ctx context.Context, ts TaskService, tcs TaskControlService, coord Coordinator, exec TaskResumer, log *zap.Logger) error { func TaskNotifyCoordinatorOfExisting(ctx context.Context, ts TaskService, tcs TaskControlService, coord Coordinator, exec TaskResumer, log *zap.Logger) error {
// If we missed a Create Action // If we missed a Create Action
tasks, _, err := ts.FindTasks(ctx, influxdb.TaskFilter{}) tasks, _, err := ts.FindTasks(ctx, taskmodel.TaskFilter{})
if err != nil { if err != nil {
return err return err
} }
@ -80,11 +79,11 @@ func TaskNotifyCoordinatorOfExisting(ctx context.Context, ts TaskService, tcs Ta
latestCompleted := now() latestCompleted := now()
for len(tasks) > 0 { for len(tasks) > 0 {
for _, task := range tasks { for _, task := range tasks {
if task.Status != string(influxdb.TaskActive) { if task.Status != string(taskmodel.TaskActive) {
continue continue
} }
task, err := ts.UpdateTask(context.Background(), task.ID, influxdb.TaskUpdate{ task, err := ts.UpdateTask(context.Background(), task.ID, taskmodel.TaskUpdate{
LatestCompleted: &latestCompleted, LatestCompleted: &latestCompleted,
LatestScheduled: &latestCompleted, LatestScheduled: &latestCompleted,
}) })
@ -105,7 +104,7 @@ func TaskNotifyCoordinatorOfExisting(ctx context.Context, ts TaskService, tcs Ta
} }
} }
tasks, _, err = ts.FindTasks(ctx, influxdb.TaskFilter{ tasks, _, err = ts.FindTasks(ctx, taskmodel.TaskFilter{
After: &tasks[len(tasks)-1].ID, After: &tasks[len(tasks)-1].ID,
}) })
if err != nil { if err != nil {

View File

@ -6,11 +6,10 @@ import (
"time" "time"
"github.com/influxdata/influxdb/v2/kit/platform" "github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/task/backend/executor" "github.com/influxdata/influxdb/v2/task/backend/executor"
"github.com/influxdata/influxdb/v2/task/backend/middleware" "github.com/influxdata/influxdb/v2/task/backend/middleware"
"github.com/influxdata/influxdb/v2/task/backend/scheduler" "github.com/influxdata/influxdb/v2/task/backend/scheduler"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -39,7 +38,7 @@ type CoordinatorOption func(*Coordinator)
// SchedulableTask is a wrapper around the Task struct, giving it methods to make it compatible with the Scheduler // SchedulableTask is a wrapper around the Task struct, giving it methods to make it compatible with the Scheduler
type SchedulableTask struct { type SchedulableTask struct {
*influxdb.Task *taskmodel.Task
sch scheduler.Schedule sch scheduler.Schedule
lsc time.Time lsc time.Time
} }
@ -70,7 +69,7 @@ func WithLimitOpt(i int) CoordinatorOption {
} }
// NewSchedulableTask transforms an influxdb task to a schedulable task type // NewSchedulableTask transforms an influxdb task to a schedulable task type
func NewSchedulableTask(task *influxdb.Task) (SchedulableTask, error) { func NewSchedulableTask(task *taskmodel.Task) (SchedulableTask, error) {
if task.Cron == "" && task.Every == "" { if task.Cron == "" && task.Every == "" {
return SchedulableTask{}, errors.New("invalid cron or every") return SchedulableTask{}, errors.New("invalid cron or every")
@ -108,7 +107,7 @@ func NewCoordinator(log *zap.Logger, scheduler scheduler.Scheduler, executor Exe
} }
// TaskCreated asks the Scheduler to schedule the newly created task // TaskCreated asks the Scheduler to schedule the newly created task
func (c *Coordinator) TaskCreated(ctx context.Context, task *influxdb.Task) error { func (c *Coordinator) TaskCreated(ctx context.Context, task *taskmodel.Task) error {
t, err := NewSchedulableTask(task) t, err := NewSchedulableTask(task)
if err != nil { if err != nil {
@ -124,7 +123,7 @@ func (c *Coordinator) TaskCreated(ctx context.Context, task *influxdb.Task) erro
} }
// TaskUpdated releases the task if it is being disabled, and schedules it otherwise // TaskUpdated releases the task if it is being disabled, and schedules it otherwise
func (c *Coordinator) TaskUpdated(ctx context.Context, from, to *influxdb.Task) error { func (c *Coordinator) TaskUpdated(ctx context.Context, from, to *taskmodel.Task) error {
sid := scheduler.ID(to.ID) sid := scheduler.ID(to.ID)
t, err := NewSchedulableTask(to) t, err := NewSchedulableTask(to)
if err != nil { if err != nil {
@ -132,8 +131,8 @@ func (c *Coordinator) TaskUpdated(ctx context.Context, from, to *influxdb.Task)
} }
// if disabling the task, release it before schedule update // if disabling the task, release it before schedule update
if to.Status != from.Status && to.Status == string(influxdb.TaskInactive) { if to.Status != from.Status && to.Status == string(taskmodel.TaskInactive) {
if err := c.sch.Release(sid); err != nil && err != influxdb.ErrTaskNotClaimed { if err := c.sch.Release(sid); err != nil && err != taskmodel.ErrTaskNotClaimed {
return err return err
} }
} else { } else {
@ -148,7 +147,7 @@ func (c *Coordinator) TaskUpdated(ctx context.Context, from, to *influxdb.Task)
//TaskDeleted asks the Scheduler to release the deleted task //TaskDeleted asks the Scheduler to release the deleted task
func (c *Coordinator) TaskDeleted(ctx context.Context, id platform.ID) error { func (c *Coordinator) TaskDeleted(ctx context.Context, id platform.ID) error {
tid := scheduler.ID(id) tid := scheduler.ID(id)
if err := c.sch.Release(tid); err != nil && err != influxdb.ErrTaskNotClaimed { if err := c.sch.Release(tid); err != nil && err != taskmodel.ErrTaskNotClaimed {
return err return err
} }
@ -163,10 +162,10 @@ func (c *Coordinator) RunCancelled(ctx context.Context, runID platform.ID) error
} }
// RunRetried speaks directly to the executor to re-try a task run immediately // RunRetried speaks directly to the executor to re-try a task run immediately
func (c *Coordinator) RunRetried(ctx context.Context, task *influxdb.Task, run *influxdb.Run) error { func (c *Coordinator) RunRetried(ctx context.Context, task *taskmodel.Task, run *taskmodel.Run) error {
promise, err := c.ex.ManualRun(ctx, task.ID, run.ID) promise, err := c.ex.ManualRun(ctx, task.ID, run.ID)
if err != nil { if err != nil {
return influxdb.ErrRunExecutionError(err) return taskmodel.ErrRunExecutionError(err)
} }
<-promise.Done() <-promise.Done()
@ -178,10 +177,10 @@ func (c *Coordinator) RunRetried(ctx context.Context, task *influxdb.Task, run *
} }
// RunForced speaks directly to the Executor to run a task immediately // RunForced speaks directly to the Executor to run a task immediately
func (c *Coordinator) RunForced(ctx context.Context, task *influxdb.Task, run *influxdb.Run) error { func (c *Coordinator) RunForced(ctx context.Context, task *taskmodel.Task, run *taskmodel.Run) error {
promise, err := c.ex.ManualRun(ctx, task.ID, run.ID) promise, err := c.ex.ManualRun(ctx, task.ID, run.ID)
if err != nil { if err != nil {
return influxdb.ErrRunExecutionError(err) return taskmodel.ErrRunExecutionError(err)
} }
<-promise.Done() <-promise.Done()

View File

@ -6,21 +6,20 @@ import (
"testing" "testing"
"time" "time"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts" "github.com/google/go-cmp/cmp/cmpopts"
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/task/backend/scheduler" "github.com/influxdata/influxdb/v2/task/backend/scheduler"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"go.uber.org/zap/zaptest" "go.uber.org/zap/zaptest"
) )
func Test_Coordinator_Executor_Methods(t *testing.T) { func Test_Coordinator_Executor_Methods(t *testing.T) {
var ( var (
one = platform.ID(1) one = platform.ID(1)
taskOne = &influxdb.Task{ID: one} taskOne = &taskmodel.Task{ID: one}
runOne = &influxdb.Run{ runOne = &taskmodel.Run{
ID: one, ID: one,
TaskID: one, TaskID: one,
ScheduledFor: time.Now(), ScheduledFor: time.Now(),
@ -99,7 +98,7 @@ func Test_Coordinator_Executor_Methods(t *testing.T) {
func TestNewSchedulableTask(t *testing.T) { func TestNewSchedulableTask(t *testing.T) {
now := time.Now().UTC() now := time.Now().UTC()
one := platform.ID(1) one := platform.ID(1)
taskOne := &influxdb.Task{ID: one, CreatedAt: now, Cron: "* * * * *", LatestCompleted: now} taskOne := &taskmodel.Task{ID: one, CreatedAt: now, Cron: "* * * * *", LatestCompleted: now}
schedulableT, err := NewSchedulableTask(taskOne) schedulableT, err := NewSchedulableTask(taskOne)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -109,7 +108,7 @@ func TestNewSchedulableTask(t *testing.T) {
t.Fatalf("expected SchedulableTask's LatestScheduled to equal %s but it was %s", now.Truncate(time.Second), schedulableT.LastScheduled()) t.Fatalf("expected SchedulableTask's LatestScheduled to equal %s but it was %s", now.Truncate(time.Second), schedulableT.LastScheduled())
} }
taskTwo := &influxdb.Task{ID: one, CreatedAt: now, Cron: "* * * * *", LatestCompleted: now, LatestScheduled: now.Add(-10 * time.Second)} taskTwo := &taskmodel.Task{ID: one, CreatedAt: now, Cron: "* * * * *", LatestCompleted: now, LatestScheduled: now.Add(-10 * time.Second)}
schedulableT, err = NewSchedulableTask(taskTwo) schedulableT, err = NewSchedulableTask(taskTwo)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -128,17 +127,17 @@ func Test_Coordinator_Scheduler_Methods(t *testing.T) {
three = platform.ID(3) three = platform.ID(3)
now = time.Now().UTC() now = time.Now().UTC()
taskOne = &influxdb.Task{ID: one, CreatedAt: now, Cron: "* * * * *"} taskOne = &taskmodel.Task{ID: one, CreatedAt: now, Cron: "* * * * *"}
taskTwo = &influxdb.Task{ID: two, Status: "active", CreatedAt: now, Cron: "* * * * *"} taskTwo = &taskmodel.Task{ID: two, Status: "active", CreatedAt: now, Cron: "* * * * *"}
taskTwoInactive = &influxdb.Task{ID: two, Status: "inactive", CreatedAt: now, Cron: "* * * * *"} taskTwoInactive = &taskmodel.Task{ID: two, Status: "inactive", CreatedAt: now, Cron: "* * * * *"}
taskThreeOriginal = &influxdb.Task{ taskThreeOriginal = &taskmodel.Task{
ID: three, ID: three,
Status: "active", Status: "active",
Name: "Previous", Name: "Previous",
CreatedAt: now, CreatedAt: now,
Cron: "* * * * *", Cron: "* * * * *",
} }
taskThreeNew = &influxdb.Task{ taskThreeNew = &taskmodel.Task{
ID: three, ID: three,
Status: "active", Status: "active",
Name: "Renamed", Name: "Renamed",
@ -161,7 +160,7 @@ func Test_Coordinator_Scheduler_Methods(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
runOne := &influxdb.Run{ runOne := &taskmodel.Run{
ID: one, ID: one,
TaskID: one, TaskID: one,
ScheduledFor: time.Now().UTC(), ScheduledFor: time.Now().UTC(),

View File

@ -4,10 +4,9 @@ import (
"context" "context"
"github.com/influxdata/influxdb/v2/kit/platform" "github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/task/backend/executor" "github.com/influxdata/influxdb/v2/task/backend/executor"
"github.com/influxdata/influxdb/v2/task/backend/scheduler" "github.com/influxdata/influxdb/v2/task/backend/scheduler"
"github.com/influxdata/influxdb/v2/task/taskmodel"
) )
var _ Executor = (*executorE)(nil) var _ Executor = (*executorE)(nil)
@ -45,7 +44,7 @@ type (
type ( type (
promise struct { promise struct {
run *influxdb.Run run *taskmodel.Run
done chan struct{} done chan struct{}
err error err error

View File

@ -5,10 +5,9 @@ import (
"testing" "testing"
"time" "time"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"go.uber.org/zap/zaptest" "go.uber.org/zap/zaptest"
) )
@ -20,12 +19,12 @@ var (
aTime = time.Now().UTC() aTime = time.Now().UTC()
taskOne = &influxdb.Task{ID: one} taskOne = &taskmodel.Task{ID: one}
taskTwo = &influxdb.Task{ID: two, Status: "active"} taskTwo = &taskmodel.Task{ID: two, Status: "active"}
taskThree = &influxdb.Task{ID: three, Status: "inactive"} taskThree = &taskmodel.Task{ID: three, Status: "inactive"}
taskFour = &influxdb.Task{ID: four} taskFour = &taskmodel.Task{ID: four}
allTasks = map[platform.ID]*influxdb.Task{ allTasks = map[platform.ID]*taskmodel.Task{
one: taskOne, one: taskOne,
two: taskTwo, two: taskTwo,
three: taskThree, three: taskThree,
@ -38,8 +37,8 @@ func Test_NotifyCoordinatorOfCreated(t *testing.T) {
coordinator = &coordinator{} coordinator = &coordinator{}
tasks = &taskService{ tasks = &taskService{
// paginated responses // paginated responses
pageOne: []*influxdb.Task{taskOne}, pageOne: []*taskmodel.Task{taskOne},
otherPages: map[platform.ID][]*influxdb.Task{ otherPages: map[platform.ID][]*taskmodel.Task{
one: {taskTwo, taskThree}, one: {taskTwo, taskThree},
three: {taskFour}, three: {taskFour},
}, },
@ -57,12 +56,12 @@ func Test_NotifyCoordinatorOfCreated(t *testing.T) {
} }
if diff := cmp.Diff([]update{ if diff := cmp.Diff([]update{
{two, influxdb.TaskUpdate{LatestCompleted: &aTime, LatestScheduled: &aTime}}, {two, taskmodel.TaskUpdate{LatestCompleted: &aTime, LatestScheduled: &aTime}},
}, tasks.updates); diff != "" { }, tasks.updates); diff != "" {
t.Errorf("unexpected updates to task service %v", diff) t.Errorf("unexpected updates to task service %v", diff)
} }
if diff := cmp.Diff([]*influxdb.Task{ if diff := cmp.Diff([]*taskmodel.Task{
taskTwo, taskTwo,
}, coordinator.tasks); diff != "" { }, coordinator.tasks); diff != "" {
t.Errorf("unexpected tasks sent to coordinator %v", diff) t.Errorf("unexpected tasks sent to coordinator %v", diff)
@ -70,10 +69,10 @@ func Test_NotifyCoordinatorOfCreated(t *testing.T) {
} }
type coordinator struct { type coordinator struct {
tasks []*influxdb.Task tasks []*taskmodel.Task
} }
func (c *coordinator) TaskCreated(_ context.Context, task *influxdb.Task) error { func (c *coordinator) TaskCreated(_ context.Context, task *taskmodel.Task) error {
c.tasks = append(c.tasks, task) c.tasks = append(c.tasks, task)
return nil return nil
@ -82,27 +81,27 @@ func (c *coordinator) TaskCreated(_ context.Context, task *influxdb.Task) error
// TasksService mocking // TasksService mocking
type taskService struct { type taskService struct {
// paginated tasks // paginated tasks
pageOne []*influxdb.Task pageOne []*taskmodel.Task
otherPages map[platform.ID][]*influxdb.Task otherPages map[platform.ID][]*taskmodel.Task
// find tasks call // find tasks call
filter influxdb.TaskFilter filter taskmodel.TaskFilter
// update call // update call
updates []update updates []update
} }
type update struct { type update struct {
ID platform.ID ID platform.ID
Update influxdb.TaskUpdate Update taskmodel.TaskUpdate
} }
func (t *taskService) UpdateTask(_ context.Context, id platform.ID, upd influxdb.TaskUpdate) (*influxdb.Task, error) { func (t *taskService) UpdateTask(_ context.Context, id platform.ID, upd taskmodel.TaskUpdate) (*taskmodel.Task, error) {
t.updates = append(t.updates, update{id, upd}) t.updates = append(t.updates, update{id, upd})
return allTasks[id], nil return allTasks[id], nil
} }
func (t *taskService) FindTasks(_ context.Context, filter influxdb.TaskFilter) ([]*influxdb.Task, int, error) { func (t *taskService) FindTasks(_ context.Context, filter taskmodel.TaskFilter) ([]*taskmodel.Task, int, error) {
t.filter = filter t.filter = filter
if filter.After == nil { if filter.After == nil {

View File

@ -7,8 +7,6 @@ import (
"sync" "sync"
"time" "time"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/flux" "github.com/influxdata/flux"
"github.com/influxdata/flux/ast" "github.com/influxdata/flux/ast"
"github.com/influxdata/flux/lang" "github.com/influxdata/flux/lang"
@ -16,10 +14,12 @@ import (
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
icontext "github.com/influxdata/influxdb/v2/context" icontext "github.com/influxdata/influxdb/v2/context"
"github.com/influxdata/influxdb/v2/kit/feature" "github.com/influxdata/influxdb/v2/kit/feature"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/kit/tracing" "github.com/influxdata/influxdb/v2/kit/tracing"
"github.com/influxdata/influxdb/v2/query" "github.com/influxdata/influxdb/v2/query"
"github.com/influxdata/influxdb/v2/task/backend" "github.com/influxdata/influxdb/v2/task/backend"
"github.com/influxdata/influxdb/v2/task/backend/scheduler" "github.com/influxdata/influxdb/v2/task/backend/scheduler"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -45,7 +45,7 @@ type Promise interface {
// MultiLimit allows us to create a single limit func that applies more then one limit. // MultiLimit allows us to create a single limit func that applies more then one limit.
func MultiLimit(limits ...LimitFunc) LimitFunc { func MultiLimit(limits ...LimitFunc) LimitFunc {
return func(task *influxdb.Task, run *influxdb.Run) error { return func(task *taskmodel.Task, run *taskmodel.Run) error {
for _, lf := range limits { for _, lf := range limits {
if err := lf(task, run); err != nil { if err := lf(task, run); err != nil {
return err return err
@ -56,7 +56,7 @@ func MultiLimit(limits ...LimitFunc) LimitFunc {
} }
// LimitFunc is a function the executor will use to // LimitFunc is a function the executor will use to
type LimitFunc func(*influxdb.Task, *influxdb.Run) error type LimitFunc func(*taskmodel.Task, *taskmodel.Run) error
type executorConfig struct { type executorConfig struct {
maxWorkers int maxWorkers int
@ -127,7 +127,7 @@ func WithFlagger(flagger feature.Flagger) executorOption {
} }
// NewExecutor creates a new task executor // NewExecutor creates a new task executor
func NewExecutor(log *zap.Logger, qs query.QueryService, us PermissionService, ts influxdb.TaskService, tcs backend.TaskControlService, opts ...executorOption) (*Executor, *ExecutorMetrics) { func NewExecutor(log *zap.Logger, qs query.QueryService, us PermissionService, ts taskmodel.TaskService, tcs backend.TaskControlService, opts ...executorOption) (*Executor, *ExecutorMetrics) {
cfg := &executorConfig{ cfg := &executorConfig{
maxWorkers: defaultMaxWorkers, maxWorkers: defaultMaxWorkers,
systemBuildCompiler: NewASTCompiler, systemBuildCompiler: NewASTCompiler,
@ -147,7 +147,7 @@ func NewExecutor(log *zap.Logger, qs query.QueryService, us PermissionService, t
currentPromises: sync.Map{}, currentPromises: sync.Map{},
promiseQueue: make(chan *promise, maxPromises), promiseQueue: make(chan *promise, maxPromises),
workerLimit: make(chan struct{}, cfg.maxWorkers), workerLimit: make(chan struct{}, cfg.maxWorkers),
limitFunc: func(*influxdb.Task, *influxdb.Run) error { return nil }, // noop limitFunc: func(*taskmodel.Task, *taskmodel.Run) error { return nil }, // noop
systemBuildCompiler: cfg.systemBuildCompiler, systemBuildCompiler: cfg.systemBuildCompiler,
nonSystemBuildCompiler: cfg.nonSystemBuildCompiler, nonSystemBuildCompiler: cfg.nonSystemBuildCompiler,
flagger: cfg.flagger, flagger: cfg.flagger,
@ -166,7 +166,7 @@ func NewExecutor(log *zap.Logger, qs query.QueryService, us PermissionService, t
// Executor it a task specific executor that works with the new scheduler system. // Executor it a task specific executor that works with the new scheduler system.
type Executor struct { type Executor struct {
log *zap.Logger log *zap.Logger
ts influxdb.TaskService ts taskmodel.TaskService
tcs backend.TaskControlService tcs backend.TaskControlService
qs query.QueryService qs query.QueryService
@ -251,7 +251,7 @@ func (e *Executor) ResumeCurrentRun(ctx context.Context, id platform.ID, runID p
return p, err return p, err
} }
} }
return nil, influxdb.ErrRunNotFound return nil, taskmodel.ErrRunNotFound
} }
func (e *Executor) createRun(ctx context.Context, id platform.ID, scheduledFor time.Time, runAt time.Time) (*promise, error) { func (e *Executor) createRun(ctx context.Context, id platform.ID, scheduledFor time.Time, runAt time.Time) (*promise, error) {
@ -264,7 +264,7 @@ func (e *Executor) createRun(ctx context.Context, id platform.ID, scheduledFor t
if err := e.tcs.AddRunLog(ctx, id, r.ID, time.Now().UTC(), fmt.Sprintf("Failed to enqueue run: %s", err.Error())); err != nil { if err := e.tcs.AddRunLog(ctx, id, r.ID, time.Now().UTC(), fmt.Sprintf("Failed to enqueue run: %s", err.Error())); err != nil {
e.log.Error("failed to fail create run: AddRunLog:", zap.Error(err)) e.log.Error("failed to fail create run: AddRunLog:", zap.Error(err))
} }
if err := e.tcs.UpdateRunState(ctx, id, r.ID, time.Now().UTC(), influxdb.RunFail); err != nil { if err := e.tcs.UpdateRunState(ctx, id, r.ID, time.Now().UTC(), taskmodel.RunFail); err != nil {
e.log.Error("failed to fail create run: UpdateRunState:", zap.Error(err)) e.log.Error("failed to fail create run: UpdateRunState:", zap.Error(err))
} }
if _, err := e.tcs.FinishRun(ctx, id, r.ID); err != nil { if _, err := e.tcs.FinishRun(ctx, id, r.ID); err != nil {
@ -313,7 +313,7 @@ func (e *Executor) Cancel(ctx context.Context, runID platform.ID) error {
return nil return nil
} }
func (e *Executor) createPromise(ctx context.Context, run *influxdb.Run) (*promise, error) { func (e *Executor) createPromise(ctx context.Context, run *taskmodel.Run) (*promise, error) {
span, ctx := tracing.StartSpanFromContext(ctx) span, ctx := tracing.StartSpanFromContext(ctx)
defer span.Finish() defer span.Finish()
@ -411,8 +411,8 @@ func (w *worker) work() {
// If done the promise was canceled // If done the promise was canceled
case <-prom.ctx.Done(): case <-prom.ctx.Done():
w.e.tcs.AddRunLog(prom.ctx, prom.task.ID, prom.run.ID, time.Now().UTC(), "Run canceled") w.e.tcs.AddRunLog(prom.ctx, prom.task.ID, prom.run.ID, time.Now().UTC(), "Run canceled")
w.e.tcs.UpdateRunState(prom.ctx, prom.task.ID, prom.run.ID, time.Now().UTC(), influxdb.RunCanceled) w.e.tcs.UpdateRunState(prom.ctx, prom.task.ID, prom.run.ID, time.Now().UTC(), taskmodel.RunCanceled)
prom.err = influxdb.ErrRunCanceled prom.err = taskmodel.ErrRunCanceled
close(prom.done) close(prom.done)
return return
case <-time.After(time.Second): case <-time.After(time.Second):
@ -438,14 +438,14 @@ func (w *worker) start(p *promise) {
// add to run log // add to run log
w.e.tcs.AddRunLog(p.ctx, p.task.ID, p.run.ID, time.Now().UTC(), fmt.Sprintf("Started task from script: %q", p.task.Flux)) w.e.tcs.AddRunLog(p.ctx, p.task.ID, p.run.ID, time.Now().UTC(), fmt.Sprintf("Started task from script: %q", p.task.Flux))
// update run status // update run status
w.e.tcs.UpdateRunState(ctx, p.task.ID, p.run.ID, time.Now().UTC(), influxdb.RunStarted) w.e.tcs.UpdateRunState(ctx, p.task.ID, p.run.ID, time.Now().UTC(), taskmodel.RunStarted)
// add to metrics // add to metrics
w.e.metrics.StartRun(p.task, time.Since(p.createdAt), time.Since(p.run.RunAt)) w.e.metrics.StartRun(p.task, time.Since(p.createdAt), time.Since(p.run.RunAt))
p.startedAt = time.Now() p.startedAt = time.Now()
} }
func (w *worker) finish(p *promise, rs influxdb.RunStatus, err error) { func (w *worker) finish(p *promise, rs taskmodel.RunStatus, err error) {
span, ctx := tracing.StartSpanFromContext(p.ctx) span, ctx := tracing.StartSpanFromContext(p.ctx)
defer span.Finish() defer span.Finish()
@ -496,7 +496,7 @@ func (w *worker) executeQuery(p *promise) {
ctx = icontext.SetAuthorizer(ctx, p.auth) ctx = icontext.SetAuthorizer(ctx, p.auth)
buildCompiler := w.systemBuildCompiler buildCompiler := w.systemBuildCompiler
if p.task.Type != influxdb.TaskSystemType { if p.task.Type != taskmodel.TaskSystemType {
buildCompiler = w.nonSystemBuildCompiler buildCompiler = w.nonSystemBuildCompiler
} }
compiler, err := buildCompiler(ctx, p.task.Flux, CompilerBuilderTimestamps{ compiler, err := buildCompiler(ctx, p.task.Flux, CompilerBuilderTimestamps{
@ -504,7 +504,7 @@ func (w *worker) executeQuery(p *promise) {
LatestSuccess: p.task.LatestSuccess, LatestSuccess: p.task.LatestSuccess,
}) })
if err != nil { if err != nil {
w.finish(p, influxdb.RunFail, influxdb.ErrFluxParseError(err)) w.finish(p, taskmodel.RunFail, taskmodel.ErrFluxParseError(err))
return return
} }
@ -517,7 +517,7 @@ func (w *worker) executeQuery(p *promise) {
it, err := w.e.qs.Query(ctx, req) it, err := w.e.qs.Query(ctx, req)
if err != nil { if err != nil {
// Assume the error should not be part of the runResult. // Assume the error should not be part of the runResult.
w.finish(p, influxdb.RunFail, influxdb.ErrQueryError(err)) w.finish(p, taskmodel.RunFail, taskmodel.ErrQueryError(err))
return return
} }
@ -540,16 +540,16 @@ func (w *worker) executeQuery(p *promise) {
} }
if runErr != nil { if runErr != nil {
w.finish(p, influxdb.RunFail, influxdb.ErrRunExecutionError(runErr)) w.finish(p, taskmodel.RunFail, taskmodel.ErrRunExecutionError(runErr))
return return
} }
if it.Err() != nil { if it.Err() != nil {
w.finish(p, influxdb.RunFail, influxdb.ErrResultIteratorError(it.Err())) w.finish(p, taskmodel.RunFail, taskmodel.ErrResultIteratorError(it.Err()))
return return
} }
w.finish(p, influxdb.RunSuccess, nil) w.finish(p, taskmodel.RunSuccess, nil)
} }
// RunsActive returns the current number of workers, which is equivalent to // RunsActive returns the current number of workers, which is equivalent to
@ -570,8 +570,8 @@ func (e *Executor) PromiseQueueUsage() float64 {
// promise represents a promise the executor makes to finish a run's execution asynchronously. // promise represents a promise the executor makes to finish a run's execution asynchronously.
type promise struct { type promise struct {
run *influxdb.Run run *taskmodel.Run
task *influxdb.Task task *taskmodel.Task
auth *influxdb.Authorization auth *influxdb.Authorization
done chan struct{} done chan struct{}

View File

@ -5,8 +5,7 @@ import (
"github.com/influxdata/influxdb/v2/kit/platform" "github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/kit/platform/errors" "github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"github.com/influxdata/influxdb/v2"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
) )
@ -137,7 +136,7 @@ func (em *ExecutorMetrics) PrometheusCollectors() []prometheus.Collector {
} }
// StartRun store the delta time between when a run is due to start and actually starting. // StartRun store the delta time between when a run is due to start and actually starting.
func (em *ExecutorMetrics) StartRun(task *influxdb.Task, queueDelta time.Duration, runLatency time.Duration) { func (em *ExecutorMetrics) StartRun(task *taskmodel.Task, queueDelta time.Duration, runLatency time.Duration) {
em.queueDelta.WithLabelValues(task.Type, "all").Observe(queueDelta.Seconds()) em.queueDelta.WithLabelValues(task.Type, "all").Observe(queueDelta.Seconds())
em.queueDelta.WithLabelValues("", task.ID.String()).Observe(queueDelta.Seconds()) em.queueDelta.WithLabelValues("", task.ID.String()).Observe(queueDelta.Seconds())
@ -146,7 +145,7 @@ func (em *ExecutorMetrics) StartRun(task *influxdb.Task, queueDelta time.Duratio
} }
// FinishRun adjusts the metrics to indicate a run is no longer in progress for the given task ID. // FinishRun adjusts the metrics to indicate a run is no longer in progress for the given task ID.
func (em *ExecutorMetrics) FinishRun(task *influxdb.Task, status influxdb.RunStatus, runDuration time.Duration) { func (em *ExecutorMetrics) FinishRun(task *taskmodel.Task, status taskmodel.RunStatus, runDuration time.Duration) {
em.totalRunsComplete.WithLabelValues(task.Type, status.String()).Inc() em.totalRunsComplete.WithLabelValues(task.Type, status.String()).Inc()
em.runDuration.WithLabelValues(task.Type, "all").Observe(runDuration.Seconds()) em.runDuration.WithLabelValues(task.Type, "all").Observe(runDuration.Seconds())

View File

@ -10,14 +10,13 @@ import (
"testing" "testing"
"time" "time"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/golang/mock/gomock" "github.com/golang/mock/gomock"
"github.com/influxdata/flux" "github.com/influxdata/flux"
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/authorization" "github.com/influxdata/influxdb/v2/authorization"
icontext "github.com/influxdata/influxdb/v2/context" icontext "github.com/influxdata/influxdb/v2/context"
"github.com/influxdata/influxdb/v2/inmem" "github.com/influxdata/influxdb/v2/inmem"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/kit/prom" "github.com/influxdata/influxdb/v2/kit/prom"
"github.com/influxdata/influxdb/v2/kit/prom/promtest" "github.com/influxdata/influxdb/v2/kit/prom/promtest"
tracetest "github.com/influxdata/influxdb/v2/kit/tracing/testing" tracetest "github.com/influxdata/influxdb/v2/kit/tracing/testing"
@ -28,6 +27,7 @@ import (
"github.com/influxdata/influxdb/v2/task/backend" "github.com/influxdata/influxdb/v2/task/backend"
"github.com/influxdata/influxdb/v2/task/backend/executor/mock" "github.com/influxdata/influxdb/v2/task/backend/executor/mock"
"github.com/influxdata/influxdb/v2/task/backend/scheduler" "github.com/influxdata/influxdb/v2/task/backend/scheduler"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"github.com/influxdata/influxdb/v2/tenant" "github.com/influxdata/influxdb/v2/tenant"
"github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -123,7 +123,7 @@ func testQuerySuccess(t *testing.T) {
) )
ctx = opentracing.ContextWithSpan(ctx, span) ctx = opentracing.ContextWithSpan(ctx, span)
task, err := tes.i.CreateTask(ctx, influxdb.TaskCreate{OrganizationID: tes.tc.OrgID, OwnerID: tes.tc.Auth.GetUserID(), Flux: script}) task, err := tes.i.CreateTask(ctx, taskmodel.TaskCreate{OrganizationID: tes.tc.OrgID, OwnerID: tes.tc.Auth.GetUserID(), Flux: script})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -185,7 +185,7 @@ func testQueryFailure(t *testing.T) {
script := fmt.Sprintf(fmtTestScript, t.Name()) script := fmt.Sprintf(fmtTestScript, t.Name())
ctx := icontext.SetAuthorizer(context.Background(), tes.tc.Auth) ctx := icontext.SetAuthorizer(context.Background(), tes.tc.Auth)
task, err := tes.i.CreateTask(ctx, influxdb.TaskCreate{OrganizationID: tes.tc.OrgID, OwnerID: tes.tc.Auth.GetUserID(), Flux: script}) task, err := tes.i.CreateTask(ctx, taskmodel.TaskCreate{OrganizationID: tes.tc.OrgID, OwnerID: tes.tc.Auth.GetUserID(), Flux: script})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -221,7 +221,7 @@ func testManualRun(t *testing.T) {
script := fmt.Sprintf(fmtTestScript, t.Name()) script := fmt.Sprintf(fmtTestScript, t.Name())
ctx := icontext.SetAuthorizer(context.Background(), tes.tc.Auth) ctx := icontext.SetAuthorizer(context.Background(), tes.tc.Auth)
task, err := tes.i.CreateTask(ctx, influxdb.TaskCreate{OrganizationID: tes.tc.OrgID, OwnerID: tes.tc.Auth.GetUserID(), Flux: script}) task, err := tes.i.CreateTask(ctx, taskmodel.TaskCreate{OrganizationID: tes.tc.OrgID, OwnerID: tes.tc.Auth.GetUserID(), Flux: script})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -268,7 +268,7 @@ func testResumingRun(t *testing.T) {
script := fmt.Sprintf(fmtTestScript, t.Name()) script := fmt.Sprintf(fmtTestScript, t.Name())
ctx := icontext.SetAuthorizer(context.Background(), tes.tc.Auth) ctx := icontext.SetAuthorizer(context.Background(), tes.tc.Auth)
task, err := tes.i.CreateTask(ctx, influxdb.TaskCreate{OrganizationID: tes.tc.OrgID, OwnerID: tes.tc.Auth.GetUserID(), Flux: script}) task, err := tes.i.CreateTask(ctx, taskmodel.TaskCreate{OrganizationID: tes.tc.OrgID, OwnerID: tes.tc.Auth.GetUserID(), Flux: script})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -284,7 +284,7 @@ func testResumingRun(t *testing.T) {
} }
// ensure that it doesn't recreate a promise // ensure that it doesn't recreate a promise
if _, err := tes.ex.ResumeCurrentRun(ctx, task.ID, stalledRun.ID); err != influxdb.ErrRunNotFound { if _, err := tes.ex.ResumeCurrentRun(ctx, task.ID, stalledRun.ID); err != taskmodel.ErrRunNotFound {
t.Fatal("failed to error when run has already been resumed") t.Fatal("failed to error when run has already been resumed")
} }
@ -311,7 +311,7 @@ func testWorkerLimit(t *testing.T) {
script := fmt.Sprintf(fmtTestScript, t.Name()) script := fmt.Sprintf(fmtTestScript, t.Name())
ctx := icontext.SetAuthorizer(context.Background(), tes.tc.Auth) ctx := icontext.SetAuthorizer(context.Background(), tes.tc.Auth)
task, err := tes.i.CreateTask(ctx, influxdb.TaskCreate{OrganizationID: tes.tc.OrgID, OwnerID: tes.tc.Auth.GetUserID(), Flux: script}) task, err := tes.i.CreateTask(ctx, taskmodel.TaskCreate{OrganizationID: tes.tc.OrgID, OwnerID: tes.tc.Auth.GetUserID(), Flux: script})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -341,16 +341,16 @@ func testLimitFunc(t *testing.T) {
script := fmt.Sprintf(fmtTestScript, t.Name()) script := fmt.Sprintf(fmtTestScript, t.Name())
ctx := icontext.SetAuthorizer(context.Background(), tes.tc.Auth) ctx := icontext.SetAuthorizer(context.Background(), tes.tc.Auth)
task, err := tes.i.CreateTask(ctx, influxdb.TaskCreate{OrganizationID: tes.tc.OrgID, OwnerID: tes.tc.Auth.GetUserID(), Flux: script}) task, err := tes.i.CreateTask(ctx, taskmodel.TaskCreate{OrganizationID: tes.tc.OrgID, OwnerID: tes.tc.Auth.GetUserID(), Flux: script})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
forcedErr := errors.New("forced") forcedErr := errors.New("forced")
forcedQueryErr := influxdb.ErrQueryError(forcedErr) forcedQueryErr := taskmodel.ErrQueryError(forcedErr)
tes.svc.FailNextQuery(forcedErr) tes.svc.FailNextQuery(forcedErr)
count := 0 count := 0
tes.ex.SetLimitFunc(func(*influxdb.Task, *influxdb.Run) error { tes.ex.SetLimitFunc(func(*taskmodel.Task, *taskmodel.Run) error {
count++ count++
if count < 2 { if count < 2 {
return errors.New("not there yet") return errors.New("not there yet")
@ -387,7 +387,7 @@ func testMetrics(t *testing.T) {
script := fmt.Sprintf(fmtTestScript, t.Name()) script := fmt.Sprintf(fmtTestScript, t.Name())
ctx := icontext.SetAuthorizer(context.Background(), tes.tc.Auth) ctx := icontext.SetAuthorizer(context.Background(), tes.tc.Auth)
task, err := tes.i.CreateTask(ctx, influxdb.TaskCreate{OrganizationID: tes.tc.OrgID, OwnerID: tes.tc.Auth.GetUserID(), Flux: script}) task, err := tes.i.CreateTask(ctx, taskmodel.TaskCreate{OrganizationID: tes.tc.OrgID, OwnerID: tes.tc.Auth.GetUserID(), Flux: script})
assert.NoError(t, err) assert.NoError(t, err)
promise, err := tes.ex.PromisedExecute(ctx, scheduler.ID(task.ID), time.Unix(123, 0), time.Unix(126, 0)) promise, err := tes.ex.PromisedExecute(ctx, scheduler.ID(task.ID), time.Unix(123, 0), time.Unix(126, 0))
@ -425,7 +425,7 @@ func testMetrics(t *testing.T) {
assert.NoError(t, promise.Error()) assert.NoError(t, promise.Error())
// manual runs metrics // manual runs metrics
mt, err := tes.i.CreateTask(ctx, influxdb.TaskCreate{OrganizationID: tes.tc.OrgID, OwnerID: tes.tc.Auth.GetUserID(), Flux: script}) mt, err := tes.i.CreateTask(ctx, taskmodel.TaskCreate{OrganizationID: tes.tc.OrgID, OwnerID: tes.tc.Auth.GetUserID(), Flux: script})
assert.NoError(t, err) assert.NoError(t, err)
scheduledFor := int64(123) scheduledFor := int64(123)
@ -463,7 +463,7 @@ func testIteratorFailure(t *testing.T) {
script := fmt.Sprintf(fmtTestScript, t.Name()) script := fmt.Sprintf(fmtTestScript, t.Name())
ctx := icontext.SetAuthorizer(context.Background(), tes.tc.Auth) ctx := icontext.SetAuthorizer(context.Background(), tes.tc.Auth)
task, err := tes.i.CreateTask(ctx, influxdb.TaskCreate{OrganizationID: tes.tc.OrgID, OwnerID: tes.tc.Auth.GetUserID(), Flux: script}) task, err := tes.i.CreateTask(ctx, taskmodel.TaskCreate{OrganizationID: tes.tc.OrgID, OwnerID: tes.tc.Auth.GetUserID(), Flux: script})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -503,7 +503,7 @@ func testErrorHandling(t *testing.T) {
script := fmt.Sprintf(fmtTestScript, t.Name()) script := fmt.Sprintf(fmtTestScript, t.Name())
ctx := icontext.SetAuthorizer(context.Background(), tes.tc.Auth) ctx := icontext.SetAuthorizer(context.Background(), tes.tc.Auth)
task, err := tes.i.CreateTask(ctx, influxdb.TaskCreate{OrganizationID: tes.tc.OrgID, OwnerID: tes.tc.Auth.GetUserID(), Flux: script, Status: "active"}) task, err := tes.i.CreateTask(ctx, taskmodel.TaskCreate{OrganizationID: tes.tc.OrgID, OwnerID: tes.tc.Auth.GetUserID(), Flux: script, Status: "active"})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -551,7 +551,7 @@ func TestPromiseFailure(t *testing.T) {
) )
ctx = opentracing.ContextWithSpan(ctx, span) ctx = opentracing.ContextWithSpan(ctx, span)
task, err := tes.i.CreateTask(ctx, influxdb.TaskCreate{OrganizationID: tes.tc.OrgID, OwnerID: tes.tc.Auth.GetUserID(), Flux: script}) task, err := tes.i.CreateTask(ctx, taskmodel.TaskCreate{OrganizationID: tes.tc.OrgID, OwnerID: tes.tc.Auth.GetUserID(), Flux: script})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -569,7 +569,7 @@ func TestPromiseFailure(t *testing.T) {
t.Fatalf("expected no promise but received one: %+v", promise) t.Fatalf("expected no promise but received one: %+v", promise)
} }
runs, _, err := tes.i.FindRuns(context.Background(), influxdb.RunFilter{Task: task.ID}) runs, _, err := tes.i.FindRuns(context.Background(), taskmodel.RunFilter{Task: task.ID})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -587,10 +587,10 @@ func TestPromiseFailure(t *testing.T) {
type taskControlService struct { type taskControlService struct {
backend.TaskControlService backend.TaskControlService
run *influxdb.Run run *taskmodel.Run
} }
func (t *taskControlService) FinishRun(ctx context.Context, taskID platform.ID, runID platform.ID) (*influxdb.Run, error) { func (t *taskControlService) FinishRun(ctx context.Context, taskID platform.ID, runID platform.ID) (*taskmodel.Run, error) {
// ensure auth set on context // ensure auth set on context
_, err := icontext.GetAuthorizer(ctx) _, err := icontext.GetAuthorizer(ctx)
if err != nil { if err != nil {

View File

@ -4,14 +4,15 @@ import (
"context" "context"
"sort" "sort"
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2/query/fluxlang"
"github.com/influxdata/influxdb/v2/task/options" "github.com/influxdata/influxdb/v2/task/options"
"github.com/influxdata/influxdb/v2/task/taskmodel"
) )
// ConcurrencyLimit creates a concurrency limit func that uses the executor to determine // ConcurrencyLimit creates a concurrency limit func that uses the executor to determine
// if the task has exceeded the concurrency limit. // if the task has exceeded the concurrency limit.
func ConcurrencyLimit(exec *Executor, lang influxdb.FluxLanguageService) LimitFunc { func ConcurrencyLimit(exec *Executor, lang fluxlang.FluxLanguageService) LimitFunc {
return func(t *influxdb.Task, r *influxdb.Run) error { return func(t *taskmodel.Task, r *taskmodel.Run) error {
o, err := options.FromScriptAST(lang, t.Flux) o, err := options.FromScriptAST(lang, t.Flux)
if err != nil { if err != nil {
return err return err
@ -39,13 +40,13 @@ func ConcurrencyLimit(exec *Executor, lang influxdb.FluxLanguageService) LimitFu
for i, run := range runs { for i, run := range runs {
if run.ID == r.ID { if run.ID == r.ID {
if i >= int(*o.Concurrency) { if i >= int(*o.Concurrency) {
return influxdb.ErrTaskConcurrencyLimitReached(i - int(*o.Concurrency)) return taskmodel.ErrTaskConcurrencyLimitReached(i - int(*o.Concurrency))
} }
return nil // no need to keep looping. return nil // no need to keep looping.
} }
} }
// this run isn't currently running. but we have more run's then the concurrency allows // this run isn't currently running. but we have more run's then the concurrency allows
return influxdb.ErrTaskConcurrencyLimitReached(len(runs) - int(*o.Concurrency)) return taskmodel.ErrTaskConcurrencyLimitReached(len(runs) - int(*o.Concurrency))
} }
return nil return nil
} }

View File

@ -5,13 +5,13 @@ import (
"testing" "testing"
"time" "time"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/query/fluxlang" "github.com/influxdata/influxdb/v2/query/fluxlang"
"github.com/influxdata/influxdb/v2/task/taskmodel"
) )
var ( var (
taskWith1Concurrency = &influxdb.Task{ID: 1, Flux: `option task = {concurrency: 1, name:"x", every:1m} from(bucket:"b-src") |> range(start:-1m) |> to(bucket:"b-dst", org:"o")`} taskWith1Concurrency = &taskmodel.Task{ID: 1, Flux: `option task = {concurrency: 1, name:"x", every:1m} from(bucket:"b-src") |> range(start:-1m) |> to(bucket:"b-dst", org:"o")`}
taskWith10Concurrency = &influxdb.Task{ID: 1, Flux: `option task = {concurrency: 10, name:"x", every:1m} from(bucket:"b-src") |> range(start:-1m) |> to(bucket:"b-dst", org:"o")`} taskWith10Concurrency = &taskmodel.Task{ID: 1, Flux: `option task = {concurrency: 10, name:"x", every:1m} from(bucket:"b-src") |> range(start:-1m) |> to(bucket:"b-dst", org:"o")`}
) )
func TestTaskConcurrency(t *testing.T) { func TestTaskConcurrency(t *testing.T) {
@ -30,7 +30,7 @@ func TestTaskConcurrency(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
r4 := &influxdb.Run{ r4 := &taskmodel.Run{
ID: 3, ID: 3,
ScheduledFor: time.Now(), ScheduledFor: time.Now(),
} }

View File

@ -5,9 +5,9 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/task/taskmodel"
) )
// CoordinatingCheckService acts as a CheckService decorator that handles coordinating the api request // CoordinatingCheckService acts as a CheckService decorator that handles coordinating the api request
@ -15,12 +15,12 @@ import (
type CoordinatingCheckService struct { type CoordinatingCheckService struct {
influxdb.CheckService influxdb.CheckService
coordinator Coordinator coordinator Coordinator
taskService influxdb.TaskService taskService taskmodel.TaskService
Now func() time.Time Now func() time.Time
} }
// NewCheckService constructs a new coordinating check service // NewCheckService constructs a new coordinating check service
func NewCheckService(cs influxdb.CheckService, ts influxdb.TaskService, coordinator Coordinator) *CoordinatingCheckService { func NewCheckService(cs influxdb.CheckService, ts taskmodel.TaskService, coordinator Coordinator) *CoordinatingCheckService {
c := &CoordinatingCheckService{ c := &CoordinatingCheckService{
CheckService: cs, CheckService: cs,
taskService: ts, taskService: ts,
@ -80,7 +80,7 @@ func (cs *CoordinatingCheckService) UpdateCheck(ctx context.Context, id platform
// if the update is to activate and the previous task was inactive we should add a "latest completed" update // if the update is to activate and the previous task was inactive we should add a "latest completed" update
// this allows us to see not run the task for inactive time // this allows us to see not run the task for inactive time
if fromTask.Status == string(influxdb.TaskInactive) && toTask.Status == string(influxdb.TaskActive) { if fromTask.Status == string(taskmodel.TaskInactive) && toTask.Status == string(taskmodel.TaskActive) {
toTask.LatestCompleted = cs.Now() toTask.LatestCompleted = cs.Now()
} }
@ -111,7 +111,7 @@ func (cs *CoordinatingCheckService) PatchCheck(ctx context.Context, id platform.
// if the update is to activate and the previous task was inactive we should add a "latest completed" update // if the update is to activate and the previous task was inactive we should add a "latest completed" update
// this allows us to see not run the task for inactive time // this allows us to see not run the task for inactive time
if fromTask.Status == string(influxdb.TaskInactive) && toTask.Status == string(influxdb.TaskActive) { if fromTask.Status == string(taskmodel.TaskInactive) && toTask.Status == string(taskmodel.TaskActive) {
toTask.LatestCompleted = cs.Now() toTask.LatestCompleted = cs.Now()
} }

View File

@ -3,33 +3,34 @@ package middleware_test
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/influxdata/influxdb/v2/kit/platform"
"testing" "testing"
"time" "time"
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/mock" "github.com/influxdata/influxdb/v2/mock"
"github.com/influxdata/influxdb/v2/notification/check" "github.com/influxdata/influxdb/v2/notification/check"
"github.com/influxdata/influxdb/v2/notification/rule" "github.com/influxdata/influxdb/v2/notification/rule"
"github.com/influxdata/influxdb/v2/task/backend/middleware" "github.com/influxdata/influxdb/v2/task/backend/middleware"
"github.com/influxdata/influxdb/v2/task/taskmodel"
) )
type pipingCoordinator struct { type pipingCoordinator struct {
err error err error
taskCreatedPipe chan *influxdb.Task taskCreatedPipe chan *taskmodel.Task
taskUpdatedPipe chan *influxdb.Task taskUpdatedPipe chan *taskmodel.Task
taskDeletedPipe chan platform.ID taskDeletedPipe chan platform.ID
} }
func (p *pipingCoordinator) taskCreatedChan() <-chan *influxdb.Task { func (p *pipingCoordinator) taskCreatedChan() <-chan *taskmodel.Task {
if p.taskCreatedPipe == nil { if p.taskCreatedPipe == nil {
p.taskCreatedPipe = make(chan *influxdb.Task, 1) p.taskCreatedPipe = make(chan *taskmodel.Task, 1)
} }
return p.taskCreatedPipe return p.taskCreatedPipe
} }
func (p *pipingCoordinator) taskUpdatedChan() <-chan *influxdb.Task { func (p *pipingCoordinator) taskUpdatedChan() <-chan *taskmodel.Task {
if p.taskUpdatedPipe == nil { if p.taskUpdatedPipe == nil {
p.taskUpdatedPipe = make(chan *influxdb.Task, 1) p.taskUpdatedPipe = make(chan *taskmodel.Task, 1)
} }
return p.taskUpdatedPipe return p.taskUpdatedPipe
} }
@ -40,13 +41,13 @@ func (p *pipingCoordinator) taskDeletedChan() <-chan platform.ID {
return p.taskDeletedPipe return p.taskDeletedPipe
} }
func (p *pipingCoordinator) TaskCreated(_ context.Context, t *influxdb.Task) error { func (p *pipingCoordinator) TaskCreated(_ context.Context, t *taskmodel.Task) error {
if p.taskCreatedPipe != nil { if p.taskCreatedPipe != nil {
p.taskCreatedPipe <- t p.taskCreatedPipe <- t
} }
return p.err return p.err
} }
func (p *pipingCoordinator) TaskUpdated(_ context.Context, from, to *influxdb.Task) error { func (p *pipingCoordinator) TaskUpdated(_ context.Context, from, to *taskmodel.Task) error {
if p.taskUpdatedPipe != nil { if p.taskUpdatedPipe != nil {
p.taskUpdatedPipe <- to p.taskUpdatedPipe <- to
} }
@ -61,10 +62,10 @@ func (p *pipingCoordinator) TaskDeleted(_ context.Context, id platform.ID) error
func (p *pipingCoordinator) RunCancelled(ctx context.Context, runID platform.ID) error { func (p *pipingCoordinator) RunCancelled(ctx context.Context, runID platform.ID) error {
return p.err return p.err
} }
func (p *pipingCoordinator) RunRetried(ctx context.Context, task *influxdb.Task, run *influxdb.Run) error { func (p *pipingCoordinator) RunRetried(ctx context.Context, task *taskmodel.Task, run *taskmodel.Run) error {
return p.err return p.err
} }
func (p *pipingCoordinator) RunForced(ctx context.Context, task *influxdb.Task, run *influxdb.Run) error { func (p *pipingCoordinator) RunForced(ctx context.Context, task *taskmodel.Task, run *taskmodel.Run) error {
return p.err return p.err
} }
@ -78,10 +79,10 @@ type mockedSvc struct {
func newMockServices() mockedSvc { func newMockServices() mockedSvc {
return mockedSvc{ return mockedSvc{
taskSvc: &mock.TaskService{ taskSvc: &mock.TaskService{
FindTaskByIDFn: func(_ context.Context, id platform.ID) (*influxdb.Task, error) { return &influxdb.Task{ID: id}, nil }, FindTaskByIDFn: func(_ context.Context, id platform.ID) (*taskmodel.Task, error) { return &taskmodel.Task{ID: id}, nil },
CreateTaskFn: func(context.Context, influxdb.TaskCreate) (*influxdb.Task, error) { return &influxdb.Task{ID: 1}, nil }, CreateTaskFn: func(context.Context, taskmodel.TaskCreate) (*taskmodel.Task, error) { return &taskmodel.Task{ID: 1}, nil },
UpdateTaskFn: func(_ context.Context, id platform.ID, _ influxdb.TaskUpdate) (*influxdb.Task, error) { UpdateTaskFn: func(_ context.Context, id platform.ID, _ taskmodel.TaskUpdate) (*taskmodel.Task, error) {
return &influxdb.Task{ID: id}, nil return &taskmodel.Task{ID: id}, nil
}, },
DeleteTaskFn: func(context.Context, platform.ID) error { return nil }, DeleteTaskFn: func(context.Context, platform.ID) error { return nil },
}, },
@ -189,13 +190,13 @@ func TestCheckUpdateFromInactive(t *testing.T) {
return c, nil return c, nil
} }
mocks.taskSvc.FindTaskByIDFn = func(_ context.Context, id platform.ID) (*influxdb.Task, error) { mocks.taskSvc.FindTaskByIDFn = func(_ context.Context, id platform.ID) (*taskmodel.Task, error) {
if id == 1 { if id == 1 {
return &influxdb.Task{ID: id, Status: string(influxdb.TaskInactive)}, nil return &taskmodel.Task{ID: id, Status: string(taskmodel.TaskInactive)}, nil
} else if id == 10 { } else if id == 10 {
return &influxdb.Task{ID: id, Status: string(influxdb.TaskActive)}, nil return &taskmodel.Task{ID: id, Status: string(taskmodel.TaskActive)}, nil
} }
return &influxdb.Task{ID: id}, nil return &taskmodel.Task{ID: id}, nil
} }
deadman := &check.Deadman{} deadman := &check.Deadman{}

View File

@ -6,32 +6,31 @@ import (
"time" "time"
"github.com/influxdata/influxdb/v2/kit/platform" "github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"github.com/influxdata/influxdb/v2"
) )
// Coordinator is a type which is used to react to // Coordinator is a type which is used to react to
// task related actions // task related actions
type Coordinator interface { type Coordinator interface {
TaskCreated(context.Context, *influxdb.Task) error TaskCreated(context.Context, *taskmodel.Task) error
TaskUpdated(ctx context.Context, from, to *influxdb.Task) error TaskUpdated(ctx context.Context, from, to *taskmodel.Task) error
TaskDeleted(context.Context, platform.ID) error TaskDeleted(context.Context, platform.ID) error
RunCancelled(ctx context.Context, runID platform.ID) error RunCancelled(ctx context.Context, runID platform.ID) error
RunRetried(ctx context.Context, task *influxdb.Task, run *influxdb.Run) error RunRetried(ctx context.Context, task *taskmodel.Task, run *taskmodel.Run) error
RunForced(ctx context.Context, task *influxdb.Task, run *influxdb.Run) error RunForced(ctx context.Context, task *taskmodel.Task, run *taskmodel.Run) error
} }
// CoordinatingTaskService acts as a TaskService decorator that handles coordinating the api request // CoordinatingTaskService acts as a TaskService decorator that handles coordinating the api request
// with the required task control actions asynchronously via a message dispatcher // with the required task control actions asynchronously via a message dispatcher
type CoordinatingTaskService struct { type CoordinatingTaskService struct {
influxdb.TaskService taskmodel.TaskService
coordinator Coordinator coordinator Coordinator
now func() time.Time now func() time.Time
} }
// New constructs a new coordinating task service // New constructs a new coordinating task service
func New(service influxdb.TaskService, coordinator Coordinator, opts ...Option) *CoordinatingTaskService { func New(service taskmodel.TaskService, coordinator Coordinator, opts ...Option) *CoordinatingTaskService {
c := &CoordinatingTaskService{ c := &CoordinatingTaskService{
TaskService: service, TaskService: service,
coordinator: coordinator, coordinator: coordinator,
@ -48,7 +47,7 @@ func New(service influxdb.TaskService, coordinator Coordinator, opts ...Option)
} }
// CreateTask Creates a task in the existing task service and Publishes the change so any TaskD service can lease it. // CreateTask Creates a task in the existing task service and Publishes the change so any TaskD service can lease it.
func (s *CoordinatingTaskService) CreateTask(ctx context.Context, tc influxdb.TaskCreate) (*influxdb.Task, error) { func (s *CoordinatingTaskService) CreateTask(ctx context.Context, tc taskmodel.TaskCreate) (*taskmodel.Task, error) {
t, err := s.TaskService.CreateTask(ctx, tc) t, err := s.TaskService.CreateTask(ctx, tc)
if err != nil { if err != nil {
return t, err return t, err
@ -66,7 +65,7 @@ func (s *CoordinatingTaskService) CreateTask(ctx context.Context, tc influxdb.Ta
} }
// UpdateTask Updates a task and publishes the change so the task owner can act on the update // UpdateTask Updates a task and publishes the change so the task owner can act on the update
func (s *CoordinatingTaskService) UpdateTask(ctx context.Context, id platform.ID, upd influxdb.TaskUpdate) (*influxdb.Task, error) { func (s *CoordinatingTaskService) UpdateTask(ctx context.Context, id platform.ID, upd taskmodel.TaskUpdate) (*taskmodel.Task, error) {
from, err := s.TaskService.FindTaskByID(ctx, id) from, err := s.TaskService.FindTaskByID(ctx, id)
if err != nil { if err != nil {
return nil, err return nil, err
@ -99,7 +98,7 @@ func (s *CoordinatingTaskService) CancelRun(ctx context.Context, taskID, runID p
} }
// RetryRun calls retry on the task service and publishes the retry. // RetryRun calls retry on the task service and publishes the retry.
func (s *CoordinatingTaskService) RetryRun(ctx context.Context, taskID, runID platform.ID) (*influxdb.Run, error) { func (s *CoordinatingTaskService) RetryRun(ctx context.Context, taskID, runID platform.ID) (*taskmodel.Run, error) {
t, err := s.TaskService.FindTaskByID(ctx, taskID) t, err := s.TaskService.FindTaskByID(ctx, taskID)
if err != nil { if err != nil {
return nil, err return nil, err
@ -114,7 +113,7 @@ func (s *CoordinatingTaskService) RetryRun(ctx context.Context, taskID, runID pl
} }
// ForceRun create the forced run in the task system and publish to the pubSub. // ForceRun create the forced run in the task system and publish to the pubSub.
func (s *CoordinatingTaskService) ForceRun(ctx context.Context, taskID platform.ID, scheduledFor int64) (*influxdb.Run, error) { func (s *CoordinatingTaskService) ForceRun(ctx context.Context, taskID platform.ID, scheduledFor int64) (*taskmodel.Run, error) {
t, err := s.TaskService.FindTaskByID(ctx, taskID) t, err := s.TaskService.FindTaskByID(ctx, taskID)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -3,13 +3,12 @@ package middleware_test
import ( import (
"context" "context"
"errors" "errors"
"github.com/influxdata/influxdb/v2/kit/platform"
"sync" "sync"
"testing" "testing"
"time" "time"
"github.com/influxdata/influxdb/v2"
_ "github.com/influxdata/influxdb/v2/fluxinit/static" _ "github.com/influxdata/influxdb/v2/fluxinit/static"
"github.com/influxdata/influxdb/v2/kit/platform"
pmock "github.com/influxdata/influxdb/v2/mock" pmock "github.com/influxdata/influxdb/v2/mock"
"github.com/influxdata/influxdb/v2/snowflake" "github.com/influxdata/influxdb/v2/snowflake"
"github.com/influxdata/influxdb/v2/task/backend" "github.com/influxdata/influxdb/v2/task/backend"
@ -17,6 +16,7 @@ import (
"github.com/influxdata/influxdb/v2/task/backend/middleware" "github.com/influxdata/influxdb/v2/task/backend/middleware"
"github.com/influxdata/influxdb/v2/task/backend/scheduler" "github.com/influxdata/influxdb/v2/task/backend/scheduler"
"github.com/influxdata/influxdb/v2/task/mock" "github.com/influxdata/influxdb/v2/task/mock"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"go.uber.org/zap/zaptest" "go.uber.org/zap/zaptest"
) )
@ -31,19 +31,19 @@ func timeoutSelector(ch <-chan scheduler.ID) (scheduler.ID, error) {
const script = `option task = {name: "a task",cron: "* * * * *"} from(bucket:"test") |> range(start:-1h)` const script = `option task = {name: "a task",cron: "* * * * *"} from(bucket:"test") |> range(start:-1h)`
func inmemTaskService() influxdb.TaskService { func inmemTaskService() taskmodel.TaskService {
gen := snowflake.NewDefaultIDGenerator() gen := snowflake.NewDefaultIDGenerator()
tasks := map[platform.ID]*influxdb.Task{} tasks := map[platform.ID]*taskmodel.Task{}
mu := sync.Mutex{} mu := sync.Mutex{}
ts := &pmock.TaskService{ ts := &pmock.TaskService{
CreateTaskFn: func(ctx context.Context, tc influxdb.TaskCreate) (*influxdb.Task, error) { CreateTaskFn: func(ctx context.Context, tc taskmodel.TaskCreate) (*taskmodel.Task, error) {
mu.Lock() mu.Lock()
defer mu.Unlock() defer mu.Unlock()
id := gen.ID() id := gen.ID()
task := &influxdb.Task{ID: id, Flux: tc.Flux, Cron: "* * * * *", Status: tc.Status, OrganizationID: tc.OrganizationID, Organization: tc.Organization} task := &taskmodel.Task{ID: id, Flux: tc.Flux, Cron: "* * * * *", Status: tc.Status, OrganizationID: tc.OrganizationID, Organization: tc.Organization}
if task.Status == "" { if task.Status == "" {
task.Status = string(influxdb.TaskActive) task.Status = string(taskmodel.TaskActive)
} }
tasks[id] = task tasks[id] = task
@ -55,12 +55,12 @@ func inmemTaskService() influxdb.TaskService {
delete(tasks, id) delete(tasks, id)
return nil return nil
}, },
UpdateTaskFn: func(ctx context.Context, id platform.ID, upd influxdb.TaskUpdate) (*influxdb.Task, error) { UpdateTaskFn: func(ctx context.Context, id platform.ID, upd taskmodel.TaskUpdate) (*taskmodel.Task, error) {
mu.Lock() mu.Lock()
defer mu.Unlock() defer mu.Unlock()
t, ok := tasks[id] t, ok := tasks[id]
if !ok { if !ok {
return nil, influxdb.ErrTaskNotFound return nil, taskmodel.ErrTaskNotFound
} }
if upd.Flux != nil { if upd.Flux != nil {
t.Flux = *upd.Flux t.Flux = *upd.Flux
@ -75,37 +75,37 @@ func inmemTaskService() influxdb.TaskService {
return t, nil return t, nil
}, },
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*influxdb.Task, error) { FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*taskmodel.Task, error) {
mu.Lock() mu.Lock()
defer mu.Unlock() defer mu.Unlock()
t, ok := tasks[id] t, ok := tasks[id]
if !ok { if !ok {
return nil, influxdb.ErrTaskNotFound return nil, taskmodel.ErrTaskNotFound
} }
newt := *t newt := *t
return &newt, nil return &newt, nil
}, },
FindTasksFn: func(ctx context.Context, tf influxdb.TaskFilter) ([]*influxdb.Task, int, error) { FindTasksFn: func(ctx context.Context, tf taskmodel.TaskFilter) ([]*taskmodel.Task, int, error) {
mu.Lock() mu.Lock()
defer mu.Unlock() defer mu.Unlock()
if tf.After != nil { if tf.After != nil {
return []*influxdb.Task{}, 0, nil return []*taskmodel.Task{}, 0, nil
} }
rtn := []*influxdb.Task{} rtn := []*taskmodel.Task{}
for _, task := range tasks { for _, task := range tasks {
rtn = append(rtn, task) rtn = append(rtn, task)
} }
return rtn, len(rtn), nil return rtn, len(rtn), nil
}, },
ForceRunFn: func(ctx context.Context, id platform.ID, scheduledFor int64) (*influxdb.Run, error) { ForceRunFn: func(ctx context.Context, id platform.ID, scheduledFor int64) (*taskmodel.Run, error) {
mu.Lock() mu.Lock()
defer mu.Unlock() defer mu.Unlock()
t, ok := tasks[id] t, ok := tasks[id]
if !ok { if !ok {
return nil, influxdb.ErrTaskNotFound return nil, taskmodel.ErrTaskNotFound
} }
return &influxdb.Run{ID: id, TaskID: t.ID, ScheduledFor: time.Unix(scheduledFor, 0)}, nil return &taskmodel.Run{ID: id, TaskID: t.ID, ScheduledFor: time.Unix(scheduledFor, 0)}, nil
}, },
} }
return ts return ts
@ -121,7 +121,7 @@ func TestCoordinatingTaskService(t *testing.T) {
middleware = middleware.New(ts, coord) middleware = middleware.New(ts, coord)
) )
task, err := middleware.CreateTask(context.Background(), influxdb.TaskCreate{OrganizationID: 1, Flux: script}) task, err := middleware.CreateTask(context.Background(), taskmodel.TaskCreate{OrganizationID: 1, Flux: script})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -147,13 +147,13 @@ func TestCoordinatingTaskService(t *testing.T) {
t.Fatal("task sent to scheduler doesn't match task created") t.Fatal("task sent to scheduler doesn't match task created")
} }
task, err = middleware.CreateTask(context.Background(), influxdb.TaskCreate{OrganizationID: 1, Flux: script}) task, err = middleware.CreateTask(context.Background(), taskmodel.TaskCreate{OrganizationID: 1, Flux: script})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
inactive := string(influxdb.TaskInactive) inactive := string(taskmodel.TaskInactive)
res, err := middleware.UpdateTask(context.Background(), task.ID, influxdb.TaskUpdate{Status: &inactive}) res, err := middleware.UpdateTask(context.Background(), task.ID, taskmodel.TaskUpdate{Status: &inactive})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -172,8 +172,8 @@ func TestCoordinatingTaskService(t *testing.T) {
t.Fatal("task sent to scheduler doesnt match task created") t.Fatal("task sent to scheduler doesnt match task created")
} }
active := string(influxdb.TaskActive) active := string(taskmodel.TaskActive)
if _, err := middleware.UpdateTask(context.Background(), task.ID, influxdb.TaskUpdate{Status: &active}); err != nil { if _, err := middleware.UpdateTask(context.Background(), task.ID, taskmodel.TaskUpdate{Status: &active}); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -182,7 +182,7 @@ func TestCoordinatingTaskService(t *testing.T) {
} }
newScript := `option task = {name: "a task",cron: "1 * * * *"} from(bucket:"test") |> range(start:-2h)` newScript := `option task = {name: "a task",cron: "1 * * * *"} from(bucket:"test") |> range(start:-2h)`
if _, err := middleware.UpdateTask(context.Background(), task.ID, influxdb.TaskUpdate{Flux: &newScript}); err != nil { if _, err := middleware.UpdateTask(context.Background(), task.ID, taskmodel.TaskUpdate{Flux: &newScript}); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -201,7 +201,7 @@ func TestCoordinatingTaskService_ForceRun(t *testing.T) {
) )
// Create an isolated task directly through the store so the coordinator doesn't know about it. // Create an isolated task directly through the store so the coordinator doesn't know about it.
task, err := middleware.CreateTask(context.Background(), influxdb.TaskCreate{OrganizationID: 1, Flux: script}) task, err := middleware.CreateTask(context.Background(), taskmodel.TaskCreate{OrganizationID: 1, Flux: script})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -5,9 +5,9 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/task/taskmodel"
) )
// CoordinatingNotificationRuleStore acts as a NotificationRuleStore decorator that handles coordinating the api request // CoordinatingNotificationRuleStore acts as a NotificationRuleStore decorator that handles coordinating the api request
@ -15,12 +15,12 @@ import (
type CoordinatingNotificationRuleStore struct { type CoordinatingNotificationRuleStore struct {
influxdb.NotificationRuleStore influxdb.NotificationRuleStore
coordinator Coordinator coordinator Coordinator
taskService influxdb.TaskService taskService taskmodel.TaskService
Now func() time.Time Now func() time.Time
} }
// NewNotificationRuleStore constructs a new coordinating notification service // NewNotificationRuleStore constructs a new coordinating notification service
func NewNotificationRuleStore(ns influxdb.NotificationRuleStore, ts influxdb.TaskService, coordinator Coordinator) *CoordinatingNotificationRuleStore { func NewNotificationRuleStore(ns influxdb.NotificationRuleStore, ts taskmodel.TaskService, coordinator Coordinator) *CoordinatingNotificationRuleStore {
c := &CoordinatingNotificationRuleStore{ c := &CoordinatingNotificationRuleStore{
NotificationRuleStore: ns, NotificationRuleStore: ns,
taskService: ts, taskService: ts,
@ -79,7 +79,7 @@ func (ns *CoordinatingNotificationRuleStore) UpdateNotificationRule(ctx context.
} }
// if the update is to activate and the previous task was inactive we should add a "latest completed" update // if the update is to activate and the previous task was inactive we should add a "latest completed" update
// this allows us to see not run the task for inactive time // this allows us to see not run the task for inactive time
if fromTask.Status == string(influxdb.TaskInactive) && toTask.Status == string(influxdb.TaskActive) { if fromTask.Status == string(taskmodel.TaskInactive) && toTask.Status == string(taskmodel.TaskActive) {
toTask.LatestCompleted = ns.Now() toTask.LatestCompleted = ns.Now()
} }
@ -110,7 +110,7 @@ func (ns *CoordinatingNotificationRuleStore) PatchNotificationRule(ctx context.C
// if the update is to activate and the previous task was inactive we should add a "latest completed" update // if the update is to activate and the previous task was inactive we should add a "latest completed" update
// this allows us to see not run the task for inactive time // this allows us to see not run the task for inactive time
if fromTask.Status == string(influxdb.TaskInactive) && toTask.Status == string(influxdb.TaskActive) { if fromTask.Status == string(taskmodel.TaskInactive) && toTask.Status == string(taskmodel.TaskActive) {
toTask.LatestCompleted = ns.Now() toTask.LatestCompleted = ns.Now()
} }

View File

@ -3,13 +3,14 @@ package middleware_test
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/influxdata/influxdb/v2/kit/platform"
"testing" "testing"
"time" "time"
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/notification/rule" "github.com/influxdata/influxdb/v2/notification/rule"
"github.com/influxdata/influxdb/v2/task/backend/middleware" "github.com/influxdata/influxdb/v2/task/backend/middleware"
"github.com/influxdata/influxdb/v2/task/taskmodel"
) )
func newNotificationRuleSvcStack() (mockedSvc, *middleware.CoordinatingNotificationRuleStore) { func newNotificationRuleSvcStack() (mockedSvc, *middleware.CoordinatingNotificationRuleStore) {
@ -80,13 +81,13 @@ func TestNotificationRuleUpdateFromInactive(t *testing.T) {
return c, nil return c, nil
} }
mocks.taskSvc.FindTaskByIDFn = func(_ context.Context, id platform.ID) (*influxdb.Task, error) { mocks.taskSvc.FindTaskByIDFn = func(_ context.Context, id platform.ID) (*taskmodel.Task, error) {
if id == 1 { if id == 1 {
return &influxdb.Task{ID: id, Status: string(influxdb.TaskInactive)}, nil return &taskmodel.Task{ID: id, Status: string(taskmodel.TaskInactive)}, nil
} else if id == 10 { } else if id == 10 {
return &influxdb.Task{ID: id, Status: string(influxdb.TaskActive)}, nil return &taskmodel.Task{ID: id, Status: string(taskmodel.TaskActive)}, nil
} }
return &influxdb.Task{ID: id}, nil return &taskmodel.Task{ID: id}, nil
} }
deadman := &rule.HTTP{} deadman := &rule.HTTP{}

View File

@ -7,10 +7,9 @@ import (
"time" "time"
"github.com/influxdata/influxdb/v2/kit/platform" "github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/models" "github.com/influxdata/influxdb/v2/models"
"github.com/influxdata/influxdb/v2/storage" "github.com/influxdata/influxdb/v2/storage"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -29,7 +28,7 @@ func NewStoragePointsWriterRecorder(log *zap.Logger, pw storage.PointsWriter) *S
// Record formats the provided run as a models.Point and writes the resulting // Record formats the provided run as a models.Point and writes the resulting
// point to an underlying storage.PointsWriter // point to an underlying storage.PointsWriter
func (s *StoragePointsWriterRecorder) Record(ctx context.Context, orgID platform.ID, org string, bucketID platform.ID, bucket string, run *influxdb.Run) error { func (s *StoragePointsWriterRecorder) Record(ctx context.Context, orgID platform.ID, org string, bucketID platform.ID, bucket string, run *taskmodel.Run) error {
tags := models.NewTags(map[string]string{ tags := models.NewTags(map[string]string{
statusTag: run.Status, statusTag: run.Status,
taskIDTag: run.TaskID.String(), taskIDTag: run.TaskID.String(),

View File

@ -6,16 +6,15 @@ import (
"time" "time"
"github.com/influxdata/influxdb/v2/kit/platform" "github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/task/backend/scheduler" "github.com/influxdata/influxdb/v2/task/backend/scheduler"
"github.com/influxdata/influxdb/v2/task/taskmodel"
) )
var _ scheduler.SchedulableService = (*SchedulableTaskService)(nil) var _ scheduler.SchedulableService = (*SchedulableTaskService)(nil)
// UpdateTaskService provides an API to update the LatestScheduled time of a task // UpdateTaskService provides an API to update the LatestScheduled time of a task
type UpdateTaskService interface { type UpdateTaskService interface {
UpdateTask(ctx context.Context, id platform.ID, upd influxdb.TaskUpdate) (*influxdb.Task, error) UpdateTask(ctx context.Context, id platform.ID, upd taskmodel.TaskUpdate) (*taskmodel.Task, error)
} }
// SchedulableTaskService implements the SchedulableService interface // SchedulableTaskService implements the SchedulableService interface
@ -30,7 +29,7 @@ func NewSchedulableTaskService(ts UpdateTaskService) SchedulableTaskService {
// UpdateLastScheduled uses the task service to store the latest time a task was scheduled to run // UpdateLastScheduled uses the task service to store the latest time a task was scheduled to run
func (s SchedulableTaskService) UpdateLastScheduled(ctx context.Context, id scheduler.ID, t time.Time) error { func (s SchedulableTaskService) UpdateLastScheduled(ctx context.Context, id scheduler.ID, t time.Time) error {
_, err := s.UpdateTask(ctx, platform.ID(id), influxdb.TaskUpdate{ _, err := s.UpdateTask(ctx, platform.ID(id), taskmodel.TaskUpdate{
LatestScheduled: &t, LatestScheduled: &t,
}) })

View File

@ -6,9 +6,8 @@ import (
"time" "time"
"github.com/influxdata/influxdb/v2/kit/platform" "github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/task/backend/scheduler" "github.com/influxdata/influxdb/v2/task/backend/scheduler"
"github.com/influxdata/influxdb/v2/task/taskmodel"
) )
var ( var (
@ -16,8 +15,8 @@ var (
mockTimeNow = time.Now() mockTimeNow = time.Now()
) )
func (m MockTaskService) UpdateTask(_ context.Context, id platform.ID, _ influxdb.TaskUpdate) (*influxdb.Task, error) { func (m MockTaskService) UpdateTask(_ context.Context, id platform.ID, _ taskmodel.TaskUpdate) (*taskmodel.Task, error) {
return &influxdb.Task{ID: id, UpdatedAt: mockTimeNow}, nil return &taskmodel.Task{ID: id, UpdatedAt: mockTimeNow}, nil
} }
type MockTaskService struct{} type MockTaskService struct{}
@ -26,7 +25,7 @@ func Test_Schedulable_Task_Service(t *testing.T) {
for _, test := range []struct { for _, test := range []struct {
name string name string
task *influxdb.Task task *taskmodel.Task
}{ }{
{ {
name: "Create New Schedulable Task Service", name: "Create New Schedulable Task Service",

View File

@ -5,8 +5,7 @@ import (
"time" "time"
"github.com/influxdata/influxdb/v2/kit/platform" "github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"github.com/influxdata/influxdb/v2"
) )
// TaskControlService is a low-level controller interface, intended to be passed to // TaskControlService is a low-level controller interface, intended to be passed to
@ -14,19 +13,19 @@ import (
type TaskControlService interface { type TaskControlService interface {
// CreateRun creates a run with a scheduled for time. // CreateRun creates a run with a scheduled for time.
CreateRun(ctx context.Context, taskID platform.ID, scheduledFor time.Time, runAt time.Time) (*influxdb.Run, error) CreateRun(ctx context.Context, taskID platform.ID, scheduledFor time.Time, runAt time.Time) (*taskmodel.Run, error)
CurrentlyRunning(ctx context.Context, taskID platform.ID) ([]*influxdb.Run, error) CurrentlyRunning(ctx context.Context, taskID platform.ID) ([]*taskmodel.Run, error)
ManualRuns(ctx context.Context, taskID platform.ID) ([]*influxdb.Run, error) ManualRuns(ctx context.Context, taskID platform.ID) ([]*taskmodel.Run, error)
// StartManualRun pulls a manual run from the list and moves it to currently running. // StartManualRun pulls a manual run from the list and moves it to currently running.
StartManualRun(ctx context.Context, taskID, runID platform.ID) (*influxdb.Run, error) StartManualRun(ctx context.Context, taskID, runID platform.ID) (*taskmodel.Run, error)
// FinishRun removes runID from the list of running tasks and if its `ScheduledFor` is later then last completed update it. // FinishRun removes runID from the list of running tasks and if its `ScheduledFor` is later then last completed update it.
FinishRun(ctx context.Context, taskID, runID platform.ID) (*influxdb.Run, error) FinishRun(ctx context.Context, taskID, runID platform.ID) (*taskmodel.Run, error)
// UpdateRunState sets the run state at the respective time. // UpdateRunState sets the run state at the respective time.
UpdateRunState(ctx context.Context, taskID, runID platform.ID, when time.Time, state influxdb.RunStatus) error UpdateRunState(ctx context.Context, taskID, runID platform.ID, when time.Time, state taskmodel.RunStatus) error
// AddRunLog adds a log line to the run. // AddRunLog adds a log line to the run.
AddRunLog(ctx context.Context, taskID, runID platform.ID, when time.Time, log string) error AddRunLog(ctx context.Context, taskID, runID platform.ID, when time.Time, log string) error

View File

@ -8,14 +8,13 @@ import (
"time" "time"
"github.com/influxdata/influxdb/v2/kit/platform" "github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/task/backend/executor" "github.com/influxdata/influxdb/v2/task/backend/executor"
"github.com/influxdata/influxdb/v2/task/backend/scheduler" "github.com/influxdata/influxdb/v2/task/backend/scheduler"
"github.com/influxdata/influxdb/v2/task/taskmodel"
) )
type promise struct { type promise struct {
run *influxdb.Run run *taskmodel.Run
hangingFor time.Duration hangingFor time.Duration
done chan struct{} done chan struct{}
@ -54,7 +53,7 @@ func (p *promise) Error() error {
return p.err return p.err
} }
func (e *Executor) createPromise(ctx context.Context, run *influxdb.Run) (*promise, error) { func (e *Executor) createPromise(ctx context.Context, run *taskmodel.Run) (*promise, error) {
ctx, cancel := context.WithCancel(ctx) ctx, cancel := context.WithCancel(ctx)
p := &promise{ p := &promise{
run: run, run: run,
@ -104,7 +103,7 @@ func (e *Executor) Execute(ctx context.Context, id scheduler.ID, scheduledAt tim
} }
func (e *Executor) ManualRun(ctx context.Context, id platform.ID, runID platform.ID) (executor.Promise, error) { func (e *Executor) ManualRun(ctx context.Context, id platform.ID, runID platform.ID) (executor.Promise, error) {
run := &influxdb.Run{ID: runID, TaskID: id, StartedAt: time.Now().UTC()} run := &taskmodel.Run{ID: runID, TaskID: id, StartedAt: time.Now().UTC()}
p, err := e.createPromise(ctx, run) p, err := e.createPromise(ctx, run)
return p, err return p, err
} }

View File

@ -8,10 +8,9 @@ import (
"time" "time"
"github.com/influxdata/influxdb/v2/kit/platform" "github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/snowflake" "github.com/influxdata/influxdb/v2/snowflake"
"github.com/influxdata/influxdb/v2/task/backend" "github.com/influxdata/influxdb/v2/task/backend"
"github.com/influxdata/influxdb/v2/task/taskmodel"
) )
var idgen = snowflake.NewDefaultIDGenerator() var idgen = snowflake.NewDefaultIDGenerator()
@ -20,54 +19,54 @@ var idgen = snowflake.NewDefaultIDGenerator()
type TaskControlService struct { type TaskControlService struct {
mu sync.Mutex mu sync.Mutex
// Map of stringified task ID to last ID used for run. // Map of stringified task ID to last ID used for run.
runs map[platform.ID]map[platform.ID]*influxdb.Run runs map[platform.ID]map[platform.ID]*taskmodel.Run
// Map of stringified, concatenated task and platform ID, to runs that have been created. // Map of stringified, concatenated task and platform ID, to runs that have been created.
created map[string]*influxdb.Run created map[string]*taskmodel.Run
// Map of stringified task ID to task meta. // Map of stringified task ID to task meta.
tasks map[platform.ID]*influxdb.Task tasks map[platform.ID]*taskmodel.Task
manualRuns []*influxdb.Run manualRuns []*taskmodel.Run
// Map of task ID to total number of runs created for that task. // Map of task ID to total number of runs created for that task.
totalRunsCreated map[platform.ID]int totalRunsCreated map[platform.ID]int
finishedRuns map[platform.ID]*influxdb.Run finishedRuns map[platform.ID]*taskmodel.Run
} }
var _ backend.TaskControlService = (*TaskControlService)(nil) var _ backend.TaskControlService = (*TaskControlService)(nil)
func NewTaskControlService() *TaskControlService { func NewTaskControlService() *TaskControlService {
return &TaskControlService{ return &TaskControlService{
runs: make(map[platform.ID]map[platform.ID]*influxdb.Run), runs: make(map[platform.ID]map[platform.ID]*taskmodel.Run),
finishedRuns: make(map[platform.ID]*influxdb.Run), finishedRuns: make(map[platform.ID]*taskmodel.Run),
tasks: make(map[platform.ID]*influxdb.Task), tasks: make(map[platform.ID]*taskmodel.Task),
created: make(map[string]*influxdb.Run), created: make(map[string]*taskmodel.Run),
totalRunsCreated: make(map[platform.ID]int), totalRunsCreated: make(map[platform.ID]int),
} }
} }
// SetTask sets the task. // SetTask sets the task.
// SetTask must be called before CreateNextRun, for a given task ID. // SetTask must be called before CreateNextRun, for a given task ID.
func (d *TaskControlService) SetTask(task *influxdb.Task) { func (d *TaskControlService) SetTask(task *taskmodel.Task) {
d.mu.Lock() d.mu.Lock()
defer d.mu.Unlock() defer d.mu.Unlock()
d.tasks[task.ID] = task d.tasks[task.ID] = task
} }
func (d *TaskControlService) SetManualRuns(runs []*influxdb.Run) { func (d *TaskControlService) SetManualRuns(runs []*taskmodel.Run) {
d.manualRuns = runs d.manualRuns = runs
} }
func (t *TaskControlService) CreateRun(_ context.Context, taskID platform.ID, scheduledFor time.Time, runAt time.Time) (*influxdb.Run, error) { func (t *TaskControlService) CreateRun(_ context.Context, taskID platform.ID, scheduledFor time.Time, runAt time.Time) (*taskmodel.Run, error) {
t.mu.Lock() t.mu.Lock()
defer t.mu.Unlock() defer t.mu.Unlock()
runID := idgen.ID() runID := idgen.ID()
runs, ok := t.runs[taskID] runs, ok := t.runs[taskID]
if !ok { if !ok {
runs = make(map[platform.ID]*influxdb.Run) runs = make(map[platform.ID]*taskmodel.Run)
} }
runs[runID] = &influxdb.Run{ runs[runID] = &taskmodel.Run{
ID: runID, ID: runID,
ScheduledFor: scheduledFor, ScheduledFor: scheduledFor,
} }
@ -75,11 +74,11 @@ func (t *TaskControlService) CreateRun(_ context.Context, taskID platform.ID, sc
return runs[runID], nil return runs[runID], nil
} }
func (t *TaskControlService) StartManualRun(_ context.Context, taskID, runID platform.ID) (*influxdb.Run, error) { func (t *TaskControlService) StartManualRun(_ context.Context, taskID, runID platform.ID) (*taskmodel.Run, error) {
t.mu.Lock() t.mu.Lock()
defer t.mu.Unlock() defer t.mu.Unlock()
var run *influxdb.Run var run *taskmodel.Run
for i, r := range t.manualRuns { for i, r := range t.manualRuns {
if r.ID == runID { if r.ID == runID {
run = r run = r
@ -87,12 +86,12 @@ func (t *TaskControlService) StartManualRun(_ context.Context, taskID, runID pla
} }
} }
if run == nil { if run == nil {
return nil, influxdb.ErrRunNotFound return nil, taskmodel.ErrRunNotFound
} }
return run, nil return run, nil
} }
func (d *TaskControlService) FinishRun(_ context.Context, taskID, runID platform.ID) (*influxdb.Run, error) { func (d *TaskControlService) FinishRun(_ context.Context, taskID, runID platform.ID) (*taskmodel.Run, error) {
d.mu.Lock() d.mu.Lock()
defer d.mu.Unlock() defer d.mu.Unlock()
@ -111,28 +110,28 @@ func (d *TaskControlService) FinishRun(_ context.Context, taskID, runID platform
return r, nil return r, nil
} }
func (t *TaskControlService) CurrentlyRunning(ctx context.Context, taskID platform.ID) ([]*influxdb.Run, error) { func (t *TaskControlService) CurrentlyRunning(ctx context.Context, taskID platform.ID) ([]*taskmodel.Run, error) {
t.mu.Lock() t.mu.Lock()
defer t.mu.Unlock() defer t.mu.Unlock()
rtn := []*influxdb.Run{} rtn := []*taskmodel.Run{}
for _, run := range t.runs[taskID] { for _, run := range t.runs[taskID] {
rtn = append(rtn, run) rtn = append(rtn, run)
} }
return rtn, nil return rtn, nil
} }
func (t *TaskControlService) ManualRuns(ctx context.Context, taskID platform.ID) ([]*influxdb.Run, error) { func (t *TaskControlService) ManualRuns(ctx context.Context, taskID platform.ID) ([]*taskmodel.Run, error) {
t.mu.Lock() t.mu.Lock()
defer t.mu.Unlock() defer t.mu.Unlock()
if t.manualRuns != nil { if t.manualRuns != nil {
return t.manualRuns, nil return t.manualRuns, nil
} }
return []*influxdb.Run{}, nil return []*taskmodel.Run{}, nil
} }
// UpdateRunState sets the run state at the respective time. // UpdateRunState sets the run state at the respective time.
func (d *TaskControlService) UpdateRunState(ctx context.Context, taskID, runID platform.ID, when time.Time, state influxdb.RunStatus) error { func (d *TaskControlService) UpdateRunState(ctx context.Context, taskID, runID platform.ID, when time.Time, state taskmodel.RunStatus) error {
d.mu.Lock() d.mu.Lock()
defer d.mu.Unlock() defer d.mu.Unlock()
@ -141,11 +140,11 @@ func (d *TaskControlService) UpdateRunState(ctx context.Context, taskID, runID p
panic("run state called without a run") panic("run state called without a run")
} }
switch state { switch state {
case influxdb.RunStarted: case taskmodel.RunStarted:
run.StartedAt = when run.StartedAt = when
case influxdb.RunSuccess, influxdb.RunFail, influxdb.RunCanceled: case taskmodel.RunSuccess, taskmodel.RunFail, taskmodel.RunCanceled:
run.FinishedAt = when run.FinishedAt = when
case influxdb.RunScheduled: case taskmodel.RunScheduled:
// nothing // nothing
default: default:
panic("invalid status") panic("invalid status")
@ -163,15 +162,15 @@ func (d *TaskControlService) AddRunLog(ctx context.Context, taskID, runID platfo
if run == nil { if run == nil {
panic("cannot add a log to a non existent run") panic("cannot add a log to a non existent run")
} }
run.Log = append(run.Log, influxdb.Log{RunID: runID, Time: when.Format(time.RFC3339Nano), Message: log}) run.Log = append(run.Log, taskmodel.Log{RunID: runID, Time: when.Format(time.RFC3339Nano), Message: log})
return nil return nil
} }
func (d *TaskControlService) CreatedFor(taskID platform.ID) []*influxdb.Run { func (d *TaskControlService) CreatedFor(taskID platform.ID) []*taskmodel.Run {
d.mu.Lock() d.mu.Lock()
defer d.mu.Unlock() defer d.mu.Unlock()
var qrs []*influxdb.Run var qrs []*taskmodel.Run
for _, qr := range d.created { for _, qr := range d.created {
if qr.TaskID == taskID { if qr.TaskID == taskID {
qrs = append(qrs, qr) qrs = append(qrs, qr)
@ -193,10 +192,10 @@ func (d *TaskControlService) TotalRunsCreatedForTask(taskID platform.ID) int {
// If the expected number isn't found in time, it returns an error. // If the expected number isn't found in time, it returns an error.
// //
// Because the scheduler and executor do a lot of state changes asynchronously, this is useful in test. // Because the scheduler and executor do a lot of state changes asynchronously, this is useful in test.
func (d *TaskControlService) PollForNumberCreated(taskID platform.ID, count int) ([]*influxdb.Run, error) { func (d *TaskControlService) PollForNumberCreated(taskID platform.ID, count int) ([]*taskmodel.Run, error) {
const numAttempts = 50 const numAttempts = 50
actualCount := 0 actualCount := 0
var created []*influxdb.Run var created []*taskmodel.Run
for i := 0; i < numAttempts; i++ { for i := 0; i < numAttempts; i++ {
time.Sleep(2 * time.Millisecond) // we sleep even on first so it becomes more likely that we catch when too many are produced. time.Sleep(2 * time.Millisecond) // we sleep even on first so it becomes more likely that we catch when too many are produced.
created = d.CreatedFor(taskID) created = d.CreatedFor(taskID)
@ -208,15 +207,15 @@ func (d *TaskControlService) PollForNumberCreated(taskID platform.ID, count int)
return created, fmt.Errorf("did not see count of %d created run(s) for task with ID %s in time, instead saw %d", count, taskID, actualCount) // we return created anyways, to make it easier to debug return created, fmt.Errorf("did not see count of %d created run(s) for task with ID %s in time, instead saw %d", count, taskID, actualCount) // we return created anyways, to make it easier to debug
} }
func (d *TaskControlService) FinishedRun(runID platform.ID) *influxdb.Run { func (d *TaskControlService) FinishedRun(runID platform.ID) *taskmodel.Run {
d.mu.Lock() d.mu.Lock()
defer d.mu.Unlock() defer d.mu.Unlock()
return d.finishedRuns[runID] return d.finishedRuns[runID]
} }
func (d *TaskControlService) FinishedRuns() []*influxdb.Run { func (d *TaskControlService) FinishedRuns() []*taskmodel.Run {
rtn := []*influxdb.Run{} rtn := []*taskmodel.Run{}
for _, run := range d.finishedRuns { for _, run := range d.finishedRuns {
rtn = append(rtn, run) rtn = append(rtn, run)
} }

View File

@ -1,64 +0,0 @@
package options
import (
"bytes"
"context"
"io/ioutil"
"net"
"net/http"
"net/url"
"os"
"time"
"github.com/influxdata/flux/dependencies/filesystem"
fluxhttp "github.com/influxdata/flux/dependencies/http"
"github.com/influxdata/flux/dependencies/secret"
fluxurl "github.com/influxdata/flux/dependencies/url"
)
var (
_ fluxhttp.Client = httpClient{}
_ filesystem.Service = fileSystem{}
_ secret.Service = secretService{}
_ fluxurl.Validator = urlValidator{}
)
type httpClient struct{}
func (httpClient) Do(*http.Request) (*http.Response, error) {
return &http.Response{
Body: ioutil.NopCloser(&bytes.Reader{}),
}, nil
}
type secretService struct{}
func (secretService) LoadSecret(ctx context.Context, k string) (string, error) { return "", nil }
type urlValidator struct{}
func (urlValidator) Validate(*url.URL) error { return nil }
func (urlValidator) ValidateIP(net.IP) error { return nil }
type fileSystem struct{}
func (fileSystem) Open(_ string) (filesystem.File, error) { return file{}, nil }
func (fileSystem) Create(_ string) (filesystem.File, error) { return file{}, nil }
func (fileSystem) Stat(_ string) (os.FileInfo, error) { return nil, nil }
type file struct{}
func (file) Read(_ []byte) (int, error) { return 0, nil }
func (file) Write(_ []byte) (int, error) { return 0, nil }
func (file) Close() error { return nil }
func (file) Seek(_ int64, _ int) (int64, error) { return 0, nil }
func (file) Stat() (os.FileInfo, error) { return info{}, nil }
type info struct{}
func (info) Name() string { return "" }
func (info) Size() int64 { return 0 }
func (info) Mode() os.FileMode { return 0 }
func (info) ModTime() time.Time { return time.Now() }
func (info) IsDir() bool { return false }
func (info) Sys() interface{} { return nil }

View File

@ -16,15 +16,15 @@ import (
"testing" "testing"
"time" "time"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
icontext "github.com/influxdata/influxdb/v2/context" icontext "github.com/influxdata/influxdb/v2/context"
"github.com/influxdata/influxdb/v2/kit/feature" "github.com/influxdata/influxdb/v2/kit/feature"
"github.com/influxdata/influxdb/v2/kit/platform"
influxdbmock "github.com/influxdata/influxdb/v2/mock" influxdbmock "github.com/influxdata/influxdb/v2/mock"
"github.com/influxdata/influxdb/v2/task/backend" "github.com/influxdata/influxdb/v2/task/backend"
"github.com/influxdata/influxdb/v2/task/options" "github.com/influxdata/influxdb/v2/task/options"
"github.com/influxdata/influxdb/v2/task/taskmodel"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -173,7 +173,7 @@ type System struct {
Ctx context.Context Ctx context.Context
// TaskService is the task service we would like to test // TaskService is the task service we would like to test
TaskService influxdb.TaskService TaskService taskmodel.TaskService
// Override for accessing credentials for an individual test. // Override for accessing credentials for an individual test.
// Callers can leave this nil and the test will create its own random IDs for each test. // Callers can leave this nil and the test will create its own random IDs for each test.
@ -190,11 +190,11 @@ func testTaskCRUD(t *testing.T, sys *System) {
cr := creds(t, sys) cr := creds(t, sys)
// Create a task. // Create a task.
tc := influxdb.TaskCreate{ tc := taskmodel.TaskCreate{
OrganizationID: cr.OrgID, OrganizationID: cr.OrgID,
Flux: fmt.Sprintf(scriptFmt, 0), Flux: fmt.Sprintf(scriptFmt, 0),
OwnerID: cr.UserID, OwnerID: cr.UserID,
Type: influxdb.TaskSystemType, Type: taskmodel.TaskSystemType,
} }
authorizedCtx := icontext.SetAuthorizer(sys.Ctx, cr.Authorizer()) authorizedCtx := icontext.SetAuthorizer(sys.Ctx, cr.Authorizer())
@ -207,7 +207,7 @@ func testTaskCRUD(t *testing.T, sys *System) {
t.Fatal("no task ID set") t.Fatal("no task ID set")
} }
findTask := func(tasks []*influxdb.Task, id platform.ID) (*influxdb.Task, error) { findTask := func(tasks []*taskmodel.Task, id platform.ID) (*taskmodel.Task, error) {
for _, t := range tasks { for _, t := range tasks {
if t.ID == id { if t.ID == id {
return t, nil return t, nil
@ -216,8 +216,8 @@ func testTaskCRUD(t *testing.T, sys *System) {
return nil, fmt.Errorf("failed to find task by id %s", id) return nil, fmt.Errorf("failed to find task by id %s", id)
} }
findTasksByStatus := func(tasks []*influxdb.Task, status string) []*influxdb.Task { findTasksByStatus := func(tasks []*taskmodel.Task, status string) []*taskmodel.Task {
var foundTasks = []*influxdb.Task{} var foundTasks = []*taskmodel.Task{}
for _, t := range tasks { for _, t := range tasks {
if t.Status == status { if t.Status == status {
foundTasks = append(foundTasks, t) foundTasks = append(foundTasks, t)
@ -241,7 +241,7 @@ func testTaskCRUD(t *testing.T, sys *System) {
// Look up a task the different ways we can. // Look up a task the different ways we can.
// Map of method name to found task. // Map of method name to found task.
found := map[string]*influxdb.Task{ found := map[string]*taskmodel.Task{
"Created": tsk, "Created": tsk,
} }
@ -252,7 +252,7 @@ func testTaskCRUD(t *testing.T, sys *System) {
} }
found["FindTaskByID"] = f found["FindTaskByID"] = f
fs, _, err := sys.TaskService.FindTasks(sys.Ctx, influxdb.TaskFilter{OrganizationID: &cr.OrgID}) fs, _, err := sys.TaskService.FindTasks(sys.Ctx, taskmodel.TaskFilter{OrganizationID: &cr.OrgID})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -262,7 +262,7 @@ func testTaskCRUD(t *testing.T, sys *System) {
} }
found["FindTasks with Organization filter"] = f found["FindTasks with Organization filter"] = f
fs, _, err = sys.TaskService.FindTasks(sys.Ctx, influxdb.TaskFilter{Organization: cr.Org}) fs, _, err = sys.TaskService.FindTasks(sys.Ctx, taskmodel.TaskFilter{Organization: cr.Org})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -272,7 +272,7 @@ func testTaskCRUD(t *testing.T, sys *System) {
} }
found["FindTasks with Organization name filter"] = f found["FindTasks with Organization name filter"] = f
fs, _, err = sys.TaskService.FindTasks(sys.Ctx, influxdb.TaskFilter{User: &cr.UserID}) fs, _, err = sys.TaskService.FindTasks(sys.Ctx, taskmodel.TaskFilter{User: &cr.UserID})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -282,7 +282,7 @@ func testTaskCRUD(t *testing.T, sys *System) {
} }
found["FindTasks with User filter"] = f found["FindTasks with User filter"] = f
want := &influxdb.Task{ want := &taskmodel.Task{
ID: tsk.ID, ID: tsk.ID,
CreatedAt: tsk.CreatedAt, CreatedAt: tsk.CreatedAt,
LatestCompleted: tsk.LatestCompleted, LatestCompleted: tsk.LatestCompleted,
@ -293,9 +293,9 @@ func testTaskCRUD(t *testing.T, sys *System) {
Name: "task #0", Name: "task #0",
Cron: "* * * * *", Cron: "* * * * *",
Offset: 5 * time.Second, Offset: 5 * time.Second,
Status: string(influxdb.DefaultTaskStatus), Status: string(taskmodel.DefaultTaskStatus),
Flux: fmt.Sprintf(scriptFmt, 0), Flux: fmt.Sprintf(scriptFmt, 0),
Type: influxdb.TaskSystemType, Type: taskmodel.TaskSystemType,
} }
for fn, f := range found { for fn, f := range found {
@ -306,11 +306,11 @@ func testTaskCRUD(t *testing.T, sys *System) {
} }
// Check limits // Check limits
tc2 := influxdb.TaskCreate{ tc2 := taskmodel.TaskCreate{
OrganizationID: cr.OrgID, OrganizationID: cr.OrgID,
Flux: fmt.Sprintf(scriptFmt, 1), Flux: fmt.Sprintf(scriptFmt, 1),
OwnerID: cr.UserID, OwnerID: cr.UserID,
Status: string(influxdb.TaskInactive), Status: string(taskmodel.TaskInactive),
} }
if _, err := sys.TaskService.CreateTask(authorizedCtx, tc2); err != nil { if _, err := sys.TaskService.CreateTask(authorizedCtx, tc2); err != nil {
@ -319,7 +319,7 @@ func testTaskCRUD(t *testing.T, sys *System) {
if !tsk.ID.Valid() { if !tsk.ID.Valid() {
t.Fatal("no task ID set") t.Fatal("no task ID set")
} }
tasks, _, err := sys.TaskService.FindTasks(sys.Ctx, influxdb.TaskFilter{OrganizationID: &cr.OrgID, Limit: 1}) tasks, _, err := sys.TaskService.FindTasks(sys.Ctx, taskmodel.TaskFilter{OrganizationID: &cr.OrgID, Limit: 1})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -329,7 +329,7 @@ func testTaskCRUD(t *testing.T, sys *System) {
// Check after // Check after
first := tasks[0] first := tasks[0]
tasks, _, err = sys.TaskService.FindTasks(sys.Ctx, influxdb.TaskFilter{OrganizationID: &cr.OrgID, After: &first.ID}) tasks, _, err = sys.TaskService.FindTasks(sys.Ctx, taskmodel.TaskFilter{OrganizationID: &cr.OrgID, After: &first.ID})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -345,24 +345,24 @@ func testTaskCRUD(t *testing.T, sys *System) {
} }
// Check task status filter // Check task status filter
active := string(influxdb.TaskActive) active := string(taskmodel.TaskActive)
fs, _, err = sys.TaskService.FindTasks(sys.Ctx, influxdb.TaskFilter{Status: &active}) fs, _, err = sys.TaskService.FindTasks(sys.Ctx, taskmodel.TaskFilter{Status: &active})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
activeTasks := findTasksByStatus(fs, string(influxdb.TaskActive)) activeTasks := findTasksByStatus(fs, string(taskmodel.TaskActive))
if len(fs) != len(activeTasks) { if len(fs) != len(activeTasks) {
t.Fatalf("expected to find %d active tasks, found: %d", len(activeTasks), len(fs)) t.Fatalf("expected to find %d active tasks, found: %d", len(activeTasks), len(fs))
} }
inactive := string(influxdb.TaskInactive) inactive := string(taskmodel.TaskInactive)
fs, _, err = sys.TaskService.FindTasks(sys.Ctx, influxdb.TaskFilter{Status: &inactive}) fs, _, err = sys.TaskService.FindTasks(sys.Ctx, taskmodel.TaskFilter{Status: &inactive})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
inactiveTasks := findTasksByStatus(fs, string(influxdb.TaskInactive)) inactiveTasks := findTasksByStatus(fs, string(taskmodel.TaskInactive))
if len(fs) != len(inactiveTasks) { if len(fs) != len(inactiveTasks) {
t.Fatalf("expected to find %d inactive tasks, found: %d", len(inactiveTasks), len(fs)) t.Fatalf("expected to find %d inactive tasks, found: %d", len(inactiveTasks), len(fs))
} }
@ -370,7 +370,7 @@ func testTaskCRUD(t *testing.T, sys *System) {
// Update task: script only. // Update task: script only.
newFlux := fmt.Sprintf(scriptFmt, 99) newFlux := fmt.Sprintf(scriptFmt, 99)
origID := f.ID origID := f.ID
f, err = sys.TaskService.UpdateTask(authorizedCtx, origID, influxdb.TaskUpdate{Flux: &newFlux}) f, err = sys.TaskService.UpdateTask(authorizedCtx, origID, taskmodel.TaskUpdate{Flux: &newFlux})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -382,13 +382,13 @@ func testTaskCRUD(t *testing.T, sys *System) {
if f.Flux != newFlux { if f.Flux != newFlux {
t.Fatalf("wrong flux from update; want %q, got %q", newFlux, f.Flux) t.Fatalf("wrong flux from update; want %q, got %q", newFlux, f.Flux)
} }
if f.Status != string(influxdb.TaskActive) { if f.Status != string(taskmodel.TaskActive) {
t.Fatalf("expected task to be created active, got %q", f.Status) t.Fatalf("expected task to be created active, got %q", f.Status)
} }
// Update task: status only. // Update task: status only.
newStatus := string(influxdb.TaskInactive) newStatus := string(taskmodel.TaskInactive)
f, err = sys.TaskService.UpdateTask(authorizedCtx, origID, influxdb.TaskUpdate{Status: &newStatus}) f, err = sys.TaskService.UpdateTask(authorizedCtx, origID, taskmodel.TaskUpdate{Status: &newStatus})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -400,9 +400,9 @@ func testTaskCRUD(t *testing.T, sys *System) {
} }
// Update task: reactivate status and update script. // Update task: reactivate status and update script.
newStatus = string(influxdb.TaskActive) newStatus = string(taskmodel.TaskActive)
newFlux = fmt.Sprintf(scriptFmt, 98) newFlux = fmt.Sprintf(scriptFmt, 98)
f, err = sys.TaskService.UpdateTask(authorizedCtx, origID, influxdb.TaskUpdate{Flux: &newFlux, Status: &newStatus}) f, err = sys.TaskService.UpdateTask(authorizedCtx, origID, taskmodel.TaskUpdate{Flux: &newFlux, Status: &newStatus})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -414,9 +414,9 @@ func testTaskCRUD(t *testing.T, sys *System) {
} }
// Update task: just update an option. // Update task: just update an option.
newStatus = string(influxdb.TaskActive) newStatus = string(taskmodel.TaskActive)
newFlux = "option task = {\n\tname: \"task-changed #98\",\n\tcron: \"* * * * *\",\n\toffset: 5s,\n\tconcurrency: 100,\n}\n\nfrom(bucket: \"b\")\n\t|> to(bucket: \"two\", orgID: \"000000000000000\")" newFlux = "option task = {\n\tname: \"task-changed #98\",\n\tcron: \"* * * * *\",\n\toffset: 5s,\n\tconcurrency: 100,\n}\n\nfrom(bucket: \"b\")\n\t|> to(bucket: \"two\", orgID: \"000000000000000\")"
f, err = sys.TaskService.UpdateTask(authorizedCtx, origID, influxdb.TaskUpdate{Options: options.Options{Name: "task-changed #98"}}) f, err = sys.TaskService.UpdateTask(authorizedCtx, origID, taskmodel.TaskUpdate{Options: options.Options{Name: "task-changed #98"}})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -429,9 +429,9 @@ func testTaskCRUD(t *testing.T, sys *System) {
} }
// Update task: switch to every. // Update task: switch to every.
newStatus = string(influxdb.TaskActive) newStatus = string(taskmodel.TaskActive)
newFlux = "option task = {\n\tname: \"task-changed #98\",\n\tevery: 30s,\n\toffset: 5s,\n\tconcurrency: 100,\n}\n\nfrom(bucket: \"b\")\n\t|> to(bucket: \"two\", orgID: \"000000000000000\")" newFlux = "option task = {\n\tname: \"task-changed #98\",\n\tevery: 30s,\n\toffset: 5s,\n\tconcurrency: 100,\n}\n\nfrom(bucket: \"b\")\n\t|> to(bucket: \"two\", orgID: \"000000000000000\")"
f, err = sys.TaskService.UpdateTask(authorizedCtx, origID, influxdb.TaskUpdate{Options: options.Options{Every: *(options.MustParseDuration("30s"))}}) f, err = sys.TaskService.UpdateTask(authorizedCtx, origID, taskmodel.TaskUpdate{Options: options.Options{Every: *(options.MustParseDuration("30s"))}})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -444,9 +444,9 @@ func testTaskCRUD(t *testing.T, sys *System) {
} }
// Update task: just cron. // Update task: just cron.
newStatus = string(influxdb.TaskActive) newStatus = string(taskmodel.TaskActive)
newFlux = fmt.Sprintf(scriptDifferentName, 98) newFlux = fmt.Sprintf(scriptDifferentName, 98)
f, err = sys.TaskService.UpdateTask(authorizedCtx, origID, influxdb.TaskUpdate{Options: options.Options{Cron: "* * * * *"}}) f, err = sys.TaskService.UpdateTask(authorizedCtx, origID, taskmodel.TaskUpdate{Options: options.Options{Cron: "* * * * *"}})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -491,8 +491,8 @@ func testTaskCRUD(t *testing.T, sys *System) {
} }
// Task should not be returned. // Task should not be returned.
if _, err := sys.TaskService.FindTaskByID(sys.Ctx, origID); err != influxdb.ErrTaskNotFound { if _, err := sys.TaskService.FindTaskByID(sys.Ctx, origID); err != taskmodel.ErrTaskNotFound {
t.Fatalf("expected %v, got %v", influxdb.ErrTaskNotFound, err) t.Fatalf("expected %v, got %v", taskmodel.ErrTaskNotFound, err)
} }
} }
@ -509,15 +509,15 @@ from(bucket: "b")
cr := creds(t, sys) cr := creds(t, sys)
tc := influxdb.TaskCreate{ tc := taskmodel.TaskCreate{
OrganizationID: cr.OrgID, OrganizationID: cr.OrgID,
OwnerID: cr.UserID, OwnerID: cr.UserID,
Type: influxdb.TaskSystemType, Type: taskmodel.TaskSystemType,
} }
authorizedCtx := icontext.SetAuthorizer(sys.Ctx, cr.Authorizer()) authorizedCtx := icontext.SetAuthorizer(sys.Ctx, cr.Authorizer())
created := make([]*influxdb.Task, 50) created := make([]*taskmodel.Task, 50)
for i := 0; i < 50; i++ { for i := 0; i < 50; i++ {
tc.Flux = fmt.Sprintf(script, i/10) tc.Flux = fmt.Sprintf(script, i/10)
tsk, err := sys.TaskService.CreateTask(authorizedCtx, tc) tsk, err := sys.TaskService.CreateTask(authorizedCtx, tc)
@ -531,7 +531,7 @@ from(bucket: "b")
created[i] = tsk created[i] = tsk
} }
tasks, _, err := sys.TaskService.FindTasks(sys.Ctx, influxdb.TaskFilter{Limit: 5}) tasks, _, err := sys.TaskService.FindTasks(sys.Ctx, taskmodel.TaskFilter{Limit: 5})
if err != nil { if err != nil {
t.Fatalf("FindTasks: %v", err) t.Fatalf("FindTasks: %v", err)
} }
@ -542,7 +542,7 @@ from(bucket: "b")
// find tasks using name which are after first 10 // find tasks using name which are after first 10
name := "Task 004" name := "Task 004"
tasks, _, err = sys.TaskService.FindTasks(sys.Ctx, influxdb.TaskFilter{Limit: 5, Name: &name}) tasks, _, err = sys.TaskService.FindTasks(sys.Ctx, taskmodel.TaskFilter{Limit: 5, Name: &name})
if err != nil { if err != nil {
t.Fatalf("FindTasks: %v", err) t.Fatalf("FindTasks: %v", err)
} }
@ -564,14 +564,14 @@ func testTaskFindTasksAfterPaging(t *testing.T, sys *System) {
from(bucket: "b") from(bucket: "b")
|> to(bucket: "two", orgID: "000000000000000")` |> to(bucket: "two", orgID: "000000000000000")`
cr = creds(t, sys) cr = creds(t, sys)
tc = influxdb.TaskCreate{ tc = taskmodel.TaskCreate{
OrganizationID: cr.OrgID, OrganizationID: cr.OrgID,
OwnerID: cr.UserID, OwnerID: cr.UserID,
Type: influxdb.TaskSystemType, Type: taskmodel.TaskSystemType,
Flux: script, Flux: script,
} }
authorizedCtx = icontext.SetAuthorizer(sys.Ctx, cr.Authorizer()) authorizedCtx = icontext.SetAuthorizer(sys.Ctx, cr.Authorizer())
created = make([]*influxdb.Task, 10) created = make([]*taskmodel.Task, 10)
taskName = "some-unique-task-name" taskName = "some-unique-task-name"
) )
@ -603,7 +603,7 @@ from(bucket: "b")
// one more than expected pages // one more than expected pages
for i := 0; i < 6; i++ { for i := 0; i < 6; i++ {
tasks, _, err := sys.TaskService.FindTasks(sys.Ctx, influxdb.TaskFilter{ tasks, _, err := sys.TaskService.FindTasks(sys.Ctx, taskmodel.TaskFilter{
Limit: 2, Limit: 2,
After: after, After: after,
Name: &taskName, Name: &taskName,
@ -648,7 +648,7 @@ from(bucket: "b")
cr := creds(t, sys) cr := creds(t, sys)
ct := influxdb.TaskCreate{ ct := taskmodel.TaskCreate{
OrganizationID: cr.OrgID, OrganizationID: cr.OrgID,
Flux: script, Flux: script,
OwnerID: cr.UserID, OwnerID: cr.UserID,
@ -663,7 +663,7 @@ from(bucket: "b")
from(bucket: "b") from(bucket: "b")
|> to(bucket: "two", orgID: "000000000000000")` |> to(bucket: "two", orgID: "000000000000000")`
f, err := sys.TaskService.UpdateTask(authorizedCtx, task.ID, influxdb.TaskUpdate{Options: options.Options{Offset: &options.Duration{}, Every: *(options.MustParseDuration("10s"))}}) f, err := sys.TaskService.UpdateTask(authorizedCtx, task.ID, taskmodel.TaskUpdate{Options: options.Options{Offset: &options.Duration{}, Every: *(options.MustParseDuration("10s"))}})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -686,7 +686,7 @@ from(bucket: "b")
from(bucket: "b") from(bucket: "b")
|> to(bucket: "two", orgID: "000000000000000")` |> to(bucket: "two", orgID: "000000000000000")`
f, err := sys.TaskService.UpdateTask(authorizedCtx, task.ID, influxdb.TaskUpdate{Options: options.Options{Offset: options.MustParseDuration("10s")}}) f, err := sys.TaskService.UpdateTask(authorizedCtx, task.ID, taskmodel.TaskUpdate{Options: options.Options{Offset: options.MustParseDuration("10s")}})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -707,7 +707,7 @@ from(bucket: "b")
from(bucket: "b") from(bucket: "b")
|> to(bucket: "two", orgID: "000000000000000")` |> to(bucket: "two", orgID: "000000000000000")`
fNoOffset, err := sys.TaskService.UpdateTask(authorizedCtx, task.ID, influxdb.TaskUpdate{Flux: &withoutOffset}) fNoOffset, err := sys.TaskService.UpdateTask(authorizedCtx, task.ID, taskmodel.TaskUpdate{Flux: &withoutOffset})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -725,7 +725,7 @@ func testUpdate(t *testing.T, sys *System) {
now := time.Now() now := time.Now()
earliestCA := now.Add(-time.Second) earliestCA := now.Add(-time.Second)
ct := influxdb.TaskCreate{ ct := taskmodel.TaskCreate{
OrganizationID: cr.OrgID, OrganizationID: cr.OrgID,
Flux: fmt.Sprintf(scriptFmt, 0), Flux: fmt.Sprintf(scriptFmt, 0),
OwnerID: cr.UserID, OwnerID: cr.UserID,
@ -767,11 +767,11 @@ func testUpdate(t *testing.T, sys *System) {
t.Fatal(err) t.Fatal(err)
} }
if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc.ID, time.Now(), influxdb.RunStarted); err != nil { if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc.ID, time.Now(), taskmodel.RunStarted); err != nil {
t.Fatal(err) t.Fatal(err)
} }
if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc.ID, time.Now(), influxdb.RunSuccess); err != nil { if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc.ID, time.Now(), taskmodel.RunSuccess); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -801,7 +801,7 @@ func testUpdate(t *testing.T, sys *System) {
t.Fatal(err) t.Fatal(err)
} }
if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc2.ID, time.Now(), influxdb.RunStarted); err != nil { if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc2.ID, time.Now(), taskmodel.RunStarted); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -809,7 +809,7 @@ func testUpdate(t *testing.T, sys *System) {
t.Fatal(err) t.Fatal(err)
} }
if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc2.ID, time.Now(), influxdb.RunFail); err != nil { if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc2.ID, time.Now(), taskmodel.RunFail); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -840,7 +840,7 @@ func testUpdate(t *testing.T, sys *System) {
now = time.Now() now = time.Now()
flux := fmt.Sprintf(scriptFmt, 1) flux := fmt.Sprintf(scriptFmt, 1)
task, err = sys.TaskService.UpdateTask(authorizedCtx, task.ID, influxdb.TaskUpdate{Flux: &flux}) task, err = sys.TaskService.UpdateTask(authorizedCtx, task.ID, taskmodel.TaskUpdate{Flux: &flux})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -867,7 +867,7 @@ func testUpdate(t *testing.T, sys *System) {
} }
ls := time.Now().Round(time.Second) // round to remove monotonic clock ls := time.Now().Round(time.Second) // round to remove monotonic clock
task, err = sys.TaskService.UpdateTask(authorizedCtx, task.ID, influxdb.TaskUpdate{LatestScheduled: &ls}) task, err = sys.TaskService.UpdateTask(authorizedCtx, task.ID, taskmodel.TaskUpdate{LatestScheduled: &ls})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -890,7 +890,7 @@ func testTaskRuns(t *testing.T, sys *System) {
// Script is set to run every minute. The platform adapter is currently hardcoded to schedule after "now", // Script is set to run every minute. The platform adapter is currently hardcoded to schedule after "now",
// which makes timing of runs somewhat difficult. // which makes timing of runs somewhat difficult.
ct := influxdb.TaskCreate{ ct := taskmodel.TaskCreate{
OrganizationID: cr.OrgID, OrganizationID: cr.OrgID,
Flux: fmt.Sprintf(scriptFmt, 0), Flux: fmt.Sprintf(scriptFmt, 0),
OwnerID: cr.UserID, OwnerID: cr.UserID,
@ -901,14 +901,14 @@ func testTaskRuns(t *testing.T, sys *System) {
} }
// check run filter errors // check run filter errors
_, _, err0 := sys.TaskService.FindRuns(sys.Ctx, influxdb.RunFilter{Task: task.ID, Limit: -1}) _, _, err0 := sys.TaskService.FindRuns(sys.Ctx, taskmodel.RunFilter{Task: task.ID, Limit: -1})
if err0 != influxdb.ErrOutOfBoundsLimit { if err0 != taskmodel.ErrOutOfBoundsLimit {
t.Fatalf("failed to error with out of bounds run limit: %d", -1) t.Fatalf("failed to error with out of bounds run limit: %d", -1)
} }
_, _, err1 := sys.TaskService.FindRuns(sys.Ctx, influxdb.RunFilter{Task: task.ID, Limit: influxdb.TaskMaxPageSize + 1}) _, _, err1 := sys.TaskService.FindRuns(sys.Ctx, taskmodel.RunFilter{Task: task.ID, Limit: taskmodel.TaskMaxPageSize + 1})
if err1 != influxdb.ErrOutOfBoundsLimit { if err1 != taskmodel.ErrOutOfBoundsLimit {
t.Fatalf("failed to error with out of bounds run limit: %d", influxdb.TaskMaxPageSize+1) t.Fatalf("failed to error with out of bounds run limit: %d", taskmodel.TaskMaxPageSize+1)
} }
requestedAt := time.Now().Add(time.Hour * -1).UTC() // This should guarantee we can make two runs. requestedAt := time.Now().Add(time.Hour * -1).UTC() // This should guarantee we can make two runs.
@ -924,7 +924,7 @@ func testTaskRuns(t *testing.T, sys *System) {
startedAt := time.Now().UTC() startedAt := time.Now().UTC()
// Update the run state to Started; normally the scheduler would do this. // Update the run state to Started; normally the scheduler would do this.
if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc0.ID, startedAt, influxdb.RunStarted); err != nil { if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc0.ID, startedAt, taskmodel.RunStarted); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -937,11 +937,11 @@ func testTaskRuns(t *testing.T, sys *System) {
} }
// Update the run state to Started; normally the scheduler would do this. // Update the run state to Started; normally the scheduler would do this.
if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc1.ID, startedAt, influxdb.RunStarted); err != nil { if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc1.ID, startedAt, taskmodel.RunStarted); err != nil {
t.Fatal(err) t.Fatal(err)
} }
runs, _, err := sys.TaskService.FindRuns(sys.Ctx, influxdb.RunFilter{Task: task.ID, Limit: 1}) runs, _, err := sys.TaskService.FindRuns(sys.Ctx, taskmodel.RunFilter{Task: task.ID, Limit: 1})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -951,7 +951,7 @@ func testTaskRuns(t *testing.T, sys *System) {
} }
// Mark the second run finished. // Mark the second run finished.
if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc1.ID, startedAt.Add(time.Second), influxdb.RunSuccess); err != nil { if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc1.ID, startedAt.Add(time.Second), taskmodel.RunSuccess); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -960,7 +960,7 @@ func testTaskRuns(t *testing.T, sys *System) {
} }
// Limit 1 should only return the earlier run. // Limit 1 should only return the earlier run.
runs, _, err = sys.TaskService.FindRuns(sys.Ctx, influxdb.RunFilter{Task: task.ID, Limit: 1}) runs, _, err = sys.TaskService.FindRuns(sys.Ctx, taskmodel.RunFilter{Task: task.ID, Limit: 1})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -973,8 +973,8 @@ func testTaskRuns(t *testing.T, sys *System) {
if runs[0].StartedAt != startedAt { if runs[0].StartedAt != startedAt {
t.Fatalf("unexpectedStartedAt; want %s, got %s", startedAt, runs[0].StartedAt) t.Fatalf("unexpectedStartedAt; want %s, got %s", startedAt, runs[0].StartedAt)
} }
if runs[0].Status != influxdb.RunStarted.String() { if runs[0].Status != taskmodel.RunStarted.String() {
t.Fatalf("unexpected run status; want %s, got %s", influxdb.RunStarted.String(), runs[0].Status) t.Fatalf("unexpected run status; want %s, got %s", taskmodel.RunStarted.String(), runs[0].Status)
} }
if !runs[0].FinishedAt.IsZero() { if !runs[0].FinishedAt.IsZero() {
@ -984,13 +984,13 @@ func testTaskRuns(t *testing.T, sys *System) {
// Look for a run that doesn't exist. // Look for a run that doesn't exist.
_, err = sys.TaskService.FindRunByID(sys.Ctx, task.ID, platform.ID(math.MaxUint64)) _, err = sys.TaskService.FindRunByID(sys.Ctx, task.ID, platform.ID(math.MaxUint64))
if err == nil { if err == nil {
t.Fatalf("expected %s but got %s instead", influxdb.ErrRunNotFound, err) t.Fatalf("expected %s but got %s instead", taskmodel.ErrRunNotFound, err)
} }
// look for a taskID that doesn't exist. // look for a taskID that doesn't exist.
_, err = sys.TaskService.FindRunByID(sys.Ctx, platform.ID(math.MaxUint64), runs[0].ID) _, err = sys.TaskService.FindRunByID(sys.Ctx, platform.ID(math.MaxUint64), runs[0].ID)
if err == nil { if err == nil {
t.Fatalf("expected %s but got %s instead", influxdb.ErrRunNotFound, err) t.Fatalf("expected %s but got %s instead", taskmodel.ErrRunNotFound, err)
} }
foundRun0, err := sys.TaskService.FindRunByID(sys.Ctx, task.ID, runs[0].ID) foundRun0, err := sys.TaskService.FindRunByID(sys.Ctx, task.ID, runs[0].ID)
@ -1014,7 +1014,7 @@ func testTaskRuns(t *testing.T, sys *System) {
// Script is set to run every minute. The platform adapter is currently hardcoded to schedule after "now", // Script is set to run every minute. The platform adapter is currently hardcoded to schedule after "now",
// which makes timing of runs somewhat difficult. // which makes timing of runs somewhat difficult.
ct := influxdb.TaskCreate{ ct := taskmodel.TaskCreate{
OrganizationID: cr.OrgID, OrganizationID: cr.OrgID,
Flux: fmt.Sprintf(scriptFmt, 0), Flux: fmt.Sprintf(scriptFmt, 0),
OwnerID: cr.UserID, OwnerID: cr.UserID,
@ -1026,18 +1026,18 @@ func testTaskRuns(t *testing.T, sys *System) {
// set to one hour before now because of bucket retention policy // set to one hour before now because of bucket retention policy
scheduledFor := time.Now().Add(time.Hour * -1).UTC() scheduledFor := time.Now().Add(time.Hour * -1).UTC()
runs := make([]*influxdb.Run, 0, 5) runs := make([]*taskmodel.Run, 0, 5)
// create runs to put into Context // create runs to put into Context
for i := 5; i > 0; i-- { for i := 5; i > 0; i-- {
run, err := sys.TaskControlService.CreateRun(ctx, task.ID, scheduledFor.Add(time.Second*time.Duration(i)), scheduledFor.Add(time.Second*time.Duration(i))) run, err := sys.TaskControlService.CreateRun(ctx, task.ID, scheduledFor.Add(time.Second*time.Duration(i)), scheduledFor.Add(time.Second*time.Duration(i)))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
err = sys.TaskControlService.UpdateRunState(ctx, task.ID, run.ID, scheduledFor.Add(time.Second*time.Duration(i+1)), influxdb.RunStarted) err = sys.TaskControlService.UpdateRunState(ctx, task.ID, run.ID, scheduledFor.Add(time.Second*time.Duration(i+1)), taskmodel.RunStarted)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
err = sys.TaskControlService.UpdateRunState(ctx, task.ID, run.ID, scheduledFor.Add(time.Second*time.Duration(i+2)), influxdb.RunSuccess) err = sys.TaskControlService.UpdateRunState(ctx, task.ID, run.ID, scheduledFor.Add(time.Second*time.Duration(i+2)), taskmodel.RunSuccess)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -1045,7 +1045,7 @@ func testTaskRuns(t *testing.T, sys *System) {
run.StartedAt = scheduledFor.Add(time.Second * time.Duration(i+1)) run.StartedAt = scheduledFor.Add(time.Second * time.Duration(i+1))
run.FinishedAt = scheduledFor.Add(time.Second * time.Duration(i+2)) run.FinishedAt = scheduledFor.Add(time.Second * time.Duration(i+2))
run.RunAt = scheduledFor.Add(time.Second * time.Duration(i)) run.RunAt = scheduledFor.Add(time.Second * time.Duration(i))
run.Status = influxdb.RunSuccess.String() run.Status = taskmodel.RunSuccess.String()
run.Log = nil run.Log = nil
if sys.CallFinishRun { if sys.CallFinishRun {
@ -1061,7 +1061,7 @@ func testTaskRuns(t *testing.T, sys *System) {
} }
found, _, err := sys.TaskService.FindRuns(ctx, found, _, err := sys.TaskService.FindRuns(ctx,
influxdb.RunFilter{ taskmodel.RunFilter{
Task: task.ID, Task: task.ID,
Limit: 2, Limit: 2,
AfterTime: scheduledFor.Add(time.Second * time.Duration(1)).Format(time.RFC3339), AfterTime: scheduledFor.Add(time.Second * time.Duration(1)).Format(time.RFC3339),
@ -1078,7 +1078,7 @@ func testTaskRuns(t *testing.T, sys *System) {
t.Run("ForceRun", func(t *testing.T) { t.Run("ForceRun", func(t *testing.T) {
t.Parallel() t.Parallel()
ct := influxdb.TaskCreate{ ct := taskmodel.TaskCreate{
OrganizationID: cr.OrgID, OrganizationID: cr.OrgID,
Flux: fmt.Sprintf(scriptFmt, 0), Flux: fmt.Sprintf(scriptFmt, 0),
OwnerID: cr.UserID, OwnerID: cr.UserID,
@ -1107,7 +1107,7 @@ func testTaskRuns(t *testing.T, sys *System) {
t.Run("FindLogs", func(t *testing.T) { t.Run("FindLogs", func(t *testing.T) {
t.Parallel() t.Parallel()
ct := influxdb.TaskCreate{ ct := taskmodel.TaskCreate{
OrganizationID: cr.OrgID, OrganizationID: cr.OrgID,
Flux: fmt.Sprintf(scriptFmt, 0), Flux: fmt.Sprintf(scriptFmt, 0),
OwnerID: cr.UserID, OwnerID: cr.UserID,
@ -1124,7 +1124,7 @@ func testTaskRuns(t *testing.T, sys *System) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc1.ID, time.Now(), influxdb.RunStarted); err != nil { if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc1.ID, time.Now(), taskmodel.RunStarted); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -1132,7 +1132,7 @@ func testTaskRuns(t *testing.T, sys *System) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc2.ID, time.Now(), influxdb.RunStarted); err != nil { if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc2.ID, time.Now(), taskmodel.RunStarted); err != nil {
t.Fatal(err) t.Fatal(err)
} }
// Add a log for the first run. // Add a log for the first run.
@ -1142,7 +1142,7 @@ func testTaskRuns(t *testing.T, sys *System) {
} }
// Ensure it is returned when filtering logs by run ID. // Ensure it is returned when filtering logs by run ID.
logs, _, err := sys.TaskService.FindLogs(sys.Ctx, influxdb.LogFilter{ logs, _, err := sys.TaskService.FindLogs(sys.Ctx, taskmodel.LogFilter{
Task: task.ID, Task: task.ID,
Run: &rc1.ID, Run: &rc1.ID,
}) })
@ -1150,8 +1150,8 @@ func testTaskRuns(t *testing.T, sys *System) {
t.Fatal(err) t.Fatal(err)
} }
expLine1 := &influxdb.Log{RunID: rc1.ID, Time: log1Time.Format(time.RFC3339Nano), Message: "entry 1"} expLine1 := &taskmodel.Log{RunID: rc1.ID, Time: log1Time.Format(time.RFC3339Nano), Message: "entry 1"}
exp := []*influxdb.Log{expLine1} exp := []*taskmodel.Log{expLine1}
if diff := cmp.Diff(logs, exp); diff != "" { if diff := cmp.Diff(logs, exp); diff != "" {
t.Fatalf("unexpected log: -got/+want: %s", diff) t.Fatalf("unexpected log: -got/+want: %s", diff)
} }
@ -1163,14 +1163,14 @@ func testTaskRuns(t *testing.T, sys *System) {
} }
// Ensure both returned when filtering logs by task ID. // Ensure both returned when filtering logs by task ID.
logs, _, err = sys.TaskService.FindLogs(sys.Ctx, influxdb.LogFilter{ logs, _, err = sys.TaskService.FindLogs(sys.Ctx, taskmodel.LogFilter{
Task: task.ID, Task: task.ID,
}) })
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
expLine2 := &influxdb.Log{RunID: rc2.ID, Time: log2Time.Format(time.RFC3339Nano), Message: "entry 2"} expLine2 := &taskmodel.Log{RunID: rc2.ID, Time: log2Time.Format(time.RFC3339Nano), Message: "entry 2"}
exp = []*influxdb.Log{expLine1, expLine2} exp = []*taskmodel.Log{expLine1, expLine2}
if diff := cmp.Diff(logs, exp); diff != "" { if diff := cmp.Diff(logs, exp); diff != "" {
t.Fatalf("unexpected log: -got/+want: %s", diff) t.Fatalf("unexpected log: -got/+want: %s", diff)
} }
@ -1181,7 +1181,7 @@ func testTaskConcurrency(t *testing.T, sys *System) {
cr := creds(t, sys) cr := creds(t, sys)
const numTasks = 450 // Arbitrarily chosen to get a reasonable count of concurrent creates and deletes. const numTasks = 450 // Arbitrarily chosen to get a reasonable count of concurrent creates and deletes.
createTaskCh := make(chan influxdb.TaskCreate, numTasks) createTaskCh := make(chan taskmodel.TaskCreate, numTasks)
// Since this test is run in parallel with other tests, // Since this test is run in parallel with other tests,
// we need to keep a whitelist of IDs that are okay to delete. // we need to keep a whitelist of IDs that are okay to delete.
@ -1234,7 +1234,7 @@ func testTaskConcurrency(t *testing.T, sys *System) {
} }
// Get all the tasks. // Get all the tasks.
tasks, _, err := sys.TaskService.FindTasks(sys.Ctx, influxdb.TaskFilter{OrganizationID: &cr.OrgID}) tasks, _, err := sys.TaskService.FindTasks(sys.Ctx, taskmodel.TaskFilter{OrganizationID: &cr.OrgID})
if err != nil { if err != nil {
t.Errorf("error finding tasks: %v", err) t.Errorf("error finding tasks: %v", err)
return return
@ -1292,7 +1292,7 @@ func testTaskConcurrency(t *testing.T, sys *System) {
} }
// Get all the tasks. // Get all the tasks.
tasks, _, err := sys.TaskService.FindTasks(sys.Ctx, influxdb.TaskFilter{OrganizationID: &cr.OrgID}) tasks, _, err := sys.TaskService.FindTasks(sys.Ctx, taskmodel.TaskFilter{OrganizationID: &cr.OrgID})
if err != nil { if err != nil {
t.Errorf("error finding tasks: %v", err) t.Errorf("error finding tasks: %v", err)
return return
@ -1326,7 +1326,7 @@ func testTaskConcurrency(t *testing.T, sys *System) {
if _, err := sys.TaskControlService.CreateRun(sys.Ctx, tid, time.Unix(253339232461, 0), time.Unix(253339232469, 1)); err != nil { if _, err := sys.TaskControlService.CreateRun(sys.Ctx, tid, time.Unix(253339232461, 0), time.Unix(253339232469, 1)); err != nil {
// This may have errored due to the task being deleted. Check if the task still exists. // This may have errored due to the task being deleted. Check if the task still exists.
if _, err2 := sys.TaskService.FindTaskByID(sys.Ctx, tid); err2 == influxdb.ErrTaskNotFound { if _, err2 := sys.TaskService.FindTaskByID(sys.Ctx, tid); err2 == taskmodel.ErrTaskNotFound {
// It was deleted. Just continue. // It was deleted. Just continue.
continue continue
} }
@ -1343,7 +1343,7 @@ func testTaskConcurrency(t *testing.T, sys *System) {
// Start adding tasks. // Start adding tasks.
for i := 0; i < numTasks; i++ { for i := 0; i < numTasks; i++ {
createTaskCh <- influxdb.TaskCreate{ createTaskCh <- taskmodel.TaskCreate{
OrganizationID: cr.OrgID, OrganizationID: cr.OrgID,
Flux: fmt.Sprintf(scriptFmt, i), Flux: fmt.Sprintf(scriptFmt, i),
OwnerID: cr.UserID, OwnerID: cr.UserID,
@ -1360,7 +1360,7 @@ func testManualRun(t *testing.T, s *System) {
cr := creds(t, s) cr := creds(t, s)
// Create a task. // Create a task.
tc := influxdb.TaskCreate{ tc := taskmodel.TaskCreate{
OrganizationID: cr.OrgID, OrganizationID: cr.OrgID,
Flux: fmt.Sprintf(scriptFmt, 0), Flux: fmt.Sprintf(scriptFmt, 0),
OwnerID: cr.UserID, OwnerID: cr.UserID,
@ -1405,7 +1405,7 @@ func testRunStorage(t *testing.T, sys *System) {
// Script is set to run every minute. The platform adapter is currently hardcoded to schedule after "now", // Script is set to run every minute. The platform adapter is currently hardcoded to schedule after "now",
// which makes timing of runs somewhat difficult. // which makes timing of runs somewhat difficult.
ct := influxdb.TaskCreate{ ct := taskmodel.TaskCreate{
OrganizationID: cr.OrgID, OrganizationID: cr.OrgID,
Flux: fmt.Sprintf(scriptFmt, 0), Flux: fmt.Sprintf(scriptFmt, 0),
OwnerID: cr.UserID, OwnerID: cr.UserID,
@ -1416,14 +1416,14 @@ func testRunStorage(t *testing.T, sys *System) {
} }
// check run filter errors // check run filter errors
_, _, err0 := sys.TaskService.FindRuns(sys.Ctx, influxdb.RunFilter{Task: task.ID, Limit: -1}) _, _, err0 := sys.TaskService.FindRuns(sys.Ctx, taskmodel.RunFilter{Task: task.ID, Limit: -1})
if err0 != influxdb.ErrOutOfBoundsLimit { if err0 != taskmodel.ErrOutOfBoundsLimit {
t.Fatalf("failed to error with out of bounds run limit: %d", -1) t.Fatalf("failed to error with out of bounds run limit: %d", -1)
} }
_, _, err1 := sys.TaskService.FindRuns(sys.Ctx, influxdb.RunFilter{Task: task.ID, Limit: influxdb.TaskMaxPageSize + 1}) _, _, err1 := sys.TaskService.FindRuns(sys.Ctx, taskmodel.RunFilter{Task: task.ID, Limit: taskmodel.TaskMaxPageSize + 1})
if err1 != influxdb.ErrOutOfBoundsLimit { if err1 != taskmodel.ErrOutOfBoundsLimit {
t.Fatalf("failed to error with out of bounds run limit: %d", influxdb.TaskMaxPageSize+1) t.Fatalf("failed to error with out of bounds run limit: %d", taskmodel.TaskMaxPageSize+1)
} }
requestedAt := time.Now().Add(time.Hour * -1).UTC() // This should guarantee we can make two runs. requestedAt := time.Now().Add(time.Hour * -1).UTC() // This should guarantee we can make two runs.
@ -1439,7 +1439,7 @@ func testRunStorage(t *testing.T, sys *System) {
startedAt := time.Now().UTC().Add(time.Second * -10) startedAt := time.Now().UTC().Add(time.Second * -10)
// Update the run state to Started; normally the scheduler would do this. // Update the run state to Started; normally the scheduler would do this.
if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc0.ID, startedAt, influxdb.RunStarted); err != nil { if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc0.ID, startedAt, taskmodel.RunStarted); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -1452,12 +1452,12 @@ func testRunStorage(t *testing.T, sys *System) {
} }
// Update the run state to Started; normally the scheduler would do this. // Update the run state to Started; normally the scheduler would do this.
if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc1.ID, startedAt.Add(time.Second), influxdb.RunStarted); err != nil { if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc1.ID, startedAt.Add(time.Second), taskmodel.RunStarted); err != nil {
t.Fatal(err) t.Fatal(err)
} }
// Mark the second run finished. // Mark the second run finished.
if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc1.ID, startedAt.Add(time.Second*2), influxdb.RunFail); err != nil { if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc1.ID, startedAt.Add(time.Second*2), taskmodel.RunFail); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -1466,7 +1466,7 @@ func testRunStorage(t *testing.T, sys *System) {
} }
// Limit 1 should only return the earlier run. // Limit 1 should only return the earlier run.
runs, _, err := sys.TaskService.FindRuns(sys.Ctx, influxdb.RunFilter{Task: task.ID, Limit: 1}) runs, _, err := sys.TaskService.FindRuns(sys.Ctx, taskmodel.RunFilter{Task: task.ID, Limit: 1})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -1479,8 +1479,8 @@ func testRunStorage(t *testing.T, sys *System) {
if runs[0].StartedAt != startedAt { if runs[0].StartedAt != startedAt {
t.Fatalf("unexpectedStartedAt; want %s, got %s", startedAt, runs[0].StartedAt) t.Fatalf("unexpectedStartedAt; want %s, got %s", startedAt, runs[0].StartedAt)
} }
if runs[0].Status != influxdb.RunStarted.String() { if runs[0].Status != taskmodel.RunStarted.String() {
t.Fatalf("unexpected run status; want %s, got %s", influxdb.RunStarted.String(), runs[0].Status) t.Fatalf("unexpected run status; want %s, got %s", taskmodel.RunStarted.String(), runs[0].Status)
} }
if !runs[0].FinishedAt.IsZero() { if !runs[0].FinishedAt.IsZero() {
@ -1492,18 +1492,18 @@ func testRunStorage(t *testing.T, sys *System) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc2.ID, startedAt.Add(time.Second*3), influxdb.RunStarted); err != nil { if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc2.ID, startedAt.Add(time.Second*3), taskmodel.RunStarted); err != nil {
t.Fatal(err) t.Fatal(err)
} }
if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc2.ID, startedAt.Add(time.Second*4), influxdb.RunSuccess); err != nil { if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc2.ID, startedAt.Add(time.Second*4), taskmodel.RunSuccess); err != nil {
t.Fatal(err) t.Fatal(err)
} }
if _, err := sys.TaskControlService.FinishRun(sys.Ctx, task.ID, rc2.ID); err != nil { if _, err := sys.TaskControlService.FinishRun(sys.Ctx, task.ID, rc2.ID); err != nil {
t.Fatal(err) t.Fatal(err)
} }
runsLimit2, _, err := sys.TaskService.FindRuns(sys.Ctx, influxdb.RunFilter{Task: task.ID, Limit: 2}) runsLimit2, _, err := sys.TaskService.FindRuns(sys.Ctx, taskmodel.RunFilter{Task: task.ID, Limit: 2})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -1515,7 +1515,7 @@ func testRunStorage(t *testing.T, sys *System) {
} }
// Unspecified limit returns all three runs, sorted by most recently scheduled first. // Unspecified limit returns all three runs, sorted by most recently scheduled first.
runs, _, err = sys.TaskService.FindRuns(sys.Ctx, influxdb.RunFilter{Task: task.ID}) runs, _, err = sys.TaskService.FindRuns(sys.Ctx, taskmodel.RunFilter{Task: task.ID})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -1529,8 +1529,8 @@ func testRunStorage(t *testing.T, sys *System) {
if runs[0].StartedAt != startedAt { if runs[0].StartedAt != startedAt {
t.Fatalf("unexpectedStartedAt; want %s, got %s", startedAt, runs[0].StartedAt) t.Fatalf("unexpectedStartedAt; want %s, got %s", startedAt, runs[0].StartedAt)
} }
if runs[0].Status != influxdb.RunStarted.String() { if runs[0].Status != taskmodel.RunStarted.String() {
t.Fatalf("unexpected run status; want %s, got %s", influxdb.RunStarted.String(), runs[0].Status) t.Fatalf("unexpected run status; want %s, got %s", taskmodel.RunStarted.String(), runs[0].Status)
} }
// TODO (al): handle empty finishedAt // TODO (al): handle empty finishedAt
// if runs[0].FinishedAt != "" { // if runs[0].FinishedAt != "" {
@ -1544,8 +1544,8 @@ func testRunStorage(t *testing.T, sys *System) {
if exp := startedAt.Add(time.Second); runs[2].StartedAt != exp { if exp := startedAt.Add(time.Second); runs[2].StartedAt != exp {
t.Fatalf("unexpected StartedAt; want %s, got %s", exp, runs[2].StartedAt) t.Fatalf("unexpected StartedAt; want %s, got %s", exp, runs[2].StartedAt)
} }
if runs[2].Status != influxdb.RunFail.String() { if runs[2].Status != taskmodel.RunFail.String() {
t.Fatalf("unexpected run status; want %s, got %s", influxdb.RunSuccess.String(), runs[2].Status) t.Fatalf("unexpected run status; want %s, got %s", taskmodel.RunSuccess.String(), runs[2].Status)
} }
if exp := startedAt.Add(time.Second * 2); runs[2].FinishedAt != exp { if exp := startedAt.Add(time.Second * 2); runs[2].FinishedAt != exp {
t.Fatalf("unexpected FinishedAt; want %s, got %s", exp, runs[2].FinishedAt) t.Fatalf("unexpected FinishedAt; want %s, got %s", exp, runs[2].FinishedAt)
@ -1554,13 +1554,13 @@ func testRunStorage(t *testing.T, sys *System) {
// Look for a run that doesn't exist. // Look for a run that doesn't exist.
_, err = sys.TaskService.FindRunByID(sys.Ctx, task.ID, platform.ID(math.MaxUint64)) _, err = sys.TaskService.FindRunByID(sys.Ctx, task.ID, platform.ID(math.MaxUint64))
if err == nil { if err == nil {
t.Fatalf("expected %s but got %s instead", influxdb.ErrRunNotFound, err) t.Fatalf("expected %s but got %s instead", taskmodel.ErrRunNotFound, err)
} }
// look for a taskID that doesn't exist. // look for a taskID that doesn't exist.
_, err = sys.TaskService.FindRunByID(sys.Ctx, platform.ID(math.MaxUint64), runs[0].ID) _, err = sys.TaskService.FindRunByID(sys.Ctx, platform.ID(math.MaxUint64), runs[0].ID)
if err == nil { if err == nil {
t.Fatalf("expected %s but got %s instead", influxdb.ErrRunNotFound, err) t.Fatalf("expected %s but got %s instead", taskmodel.ErrRunNotFound, err)
} }
foundRun0, err := sys.TaskService.FindRunByID(sys.Ctx, task.ID, runs[0].ID) foundRun0, err := sys.TaskService.FindRunByID(sys.Ctx, task.ID, runs[0].ID)
@ -1585,7 +1585,7 @@ func testRetryAcrossStorage(t *testing.T, sys *System) {
cr := creds(t, sys) cr := creds(t, sys)
// Script is set to run every minute. // Script is set to run every minute.
ct := influxdb.TaskCreate{ ct := taskmodel.TaskCreate{
OrganizationID: cr.OrgID, OrganizationID: cr.OrgID,
Flux: fmt.Sprintf(scriptFmt, 0), Flux: fmt.Sprintf(scriptFmt, 0),
OwnerID: cr.UserID, OwnerID: cr.UserID,
@ -1597,7 +1597,7 @@ func testRetryAcrossStorage(t *testing.T, sys *System) {
// Non-existent ID should return the right error. // Non-existent ID should return the right error.
_, err = sys.TaskService.RetryRun(sys.Ctx, task.ID, platform.ID(math.MaxUint64)) _, err = sys.TaskService.RetryRun(sys.Ctx, task.ID, platform.ID(math.MaxUint64))
if !strings.Contains(err.Error(), "run not found") { if !strings.Contains(err.Error(), "run not found") {
t.Errorf("expected retrying run that doesn't exist to return %v, got %v", influxdb.ErrRunNotFound, err) t.Errorf("expected retrying run that doesn't exist to return %v, got %v", taskmodel.ErrRunNotFound, err)
} }
requestedAt := time.Now().Add(time.Hour * -1).UTC() // This should guarantee we can make a run. requestedAt := time.Now().Add(time.Hour * -1).UTC() // This should guarantee we can make a run.
@ -1613,10 +1613,10 @@ func testRetryAcrossStorage(t *testing.T, sys *System) {
startedAt := time.Now().UTC() startedAt := time.Now().UTC()
// Update the run state to Started then Failed; normally the scheduler would do this. // Update the run state to Started then Failed; normally the scheduler would do this.
if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc.ID, startedAt, influxdb.RunStarted); err != nil { if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc.ID, startedAt, taskmodel.RunStarted); err != nil {
t.Fatal(err) t.Fatal(err)
} }
if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc.ID, startedAt.Add(time.Second), influxdb.RunFail); err != nil { if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc.ID, startedAt.Add(time.Second), taskmodel.RunFail); err != nil {
t.Fatal(err) t.Fatal(err)
} }
if _, err := sys.TaskControlService.FinishRun(sys.Ctx, task.ID, rc.ID); err != nil { if _, err := sys.TaskControlService.FinishRun(sys.Ctx, task.ID, rc.ID); err != nil {
@ -1639,7 +1639,7 @@ func testRetryAcrossStorage(t *testing.T, sys *System) {
t.Fatalf("wrong scheduledFor on task: got %s, want %s", m.ScheduledFor, rc.ScheduledFor) t.Fatalf("wrong scheduledFor on task: got %s, want %s", m.ScheduledFor, rc.ScheduledFor)
} }
exp := influxdb.RequestStillQueuedError{Start: rc.ScheduledFor.Unix(), End: rc.ScheduledFor.Unix()} exp := taskmodel.RequestStillQueuedError{Start: rc.ScheduledFor.Unix(), End: rc.ScheduledFor.Unix()}
// Retrying a run which has been queued but not started, should be rejected. // Retrying a run which has been queued but not started, should be rejected.
if _, err = sys.TaskService.RetryRun(sys.Ctx, task.ID, rc.ID); err != exp && err.Error() != "run already queued" { if _, err = sys.TaskService.RetryRun(sys.Ctx, task.ID, rc.ID); err != exp && err.Error() != "run already queued" {
@ -1652,7 +1652,7 @@ func testLogsAcrossStorage(t *testing.T, sys *System) {
// Script is set to run every minute. The platform adapter is currently hardcoded to schedule after "now", // Script is set to run every minute. The platform adapter is currently hardcoded to schedule after "now",
// which makes timing of runs somewhat difficult. // which makes timing of runs somewhat difficult.
ct := influxdb.TaskCreate{ ct := taskmodel.TaskCreate{
OrganizationID: cr.OrgID, OrganizationID: cr.OrgID,
Flux: fmt.Sprintf(scriptFmt, 0), Flux: fmt.Sprintf(scriptFmt, 0),
OwnerID: cr.UserID, OwnerID: cr.UserID,
@ -1675,7 +1675,7 @@ func testLogsAcrossStorage(t *testing.T, sys *System) {
startedAt := time.Now().UTC() startedAt := time.Now().UTC()
// Update the run state to Started; normally the scheduler would do this. // Update the run state to Started; normally the scheduler would do this.
if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc0.ID, startedAt, influxdb.RunStarted); err != nil { if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc0.ID, startedAt, taskmodel.RunStarted); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -1688,12 +1688,12 @@ func testLogsAcrossStorage(t *testing.T, sys *System) {
} }
// Update the run state to Started; normally the scheduler would do this. // Update the run state to Started; normally the scheduler would do this.
if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc1.ID, startedAt, influxdb.RunStarted); err != nil { if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc1.ID, startedAt, taskmodel.RunStarted); err != nil {
t.Fatal(err) t.Fatal(err)
} }
// Mark the second run finished. // Mark the second run finished.
if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc1.ID, startedAt.Add(time.Second), influxdb.RunSuccess); err != nil { if err := sys.TaskControlService.UpdateRunState(sys.Ctx, task.ID, rc1.ID, startedAt.Add(time.Second), taskmodel.RunSuccess); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -1710,7 +1710,7 @@ func testLogsAcrossStorage(t *testing.T, sys *System) {
t.Fatal(err) t.Fatal(err)
} }
logs, _, err := sys.TaskService.FindLogs(sys.Ctx, influxdb.LogFilter{Task: task.ID}) logs, _, err := sys.TaskService.FindLogs(sys.Ctx, taskmodel.LogFilter{Task: task.ID})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -1720,7 +1720,7 @@ func testLogsAcrossStorage(t *testing.T, sys *System) {
} }
t.Fatalf("failed to get all logs: expected: 7 got: %d", len(logs)) t.Fatalf("failed to get all logs: expected: 7 got: %d", len(logs))
} }
smash := func(logs []*influxdb.Log) string { smash := func(logs []*taskmodel.Log) string {
smashed := "" smashed := ""
for _, log := range logs { for _, log := range logs {
smashed = smashed + log.Message smashed = smashed + log.Message
@ -1731,7 +1731,7 @@ func testLogsAcrossStorage(t *testing.T, sys *System) {
t.Fatalf("log contents not acceptable, expected: %q, got: %q", "0-00-10-21-01-11-21-3", smash(logs)) t.Fatalf("log contents not acceptable, expected: %q, got: %q", "0-00-10-21-01-11-21-3", smash(logs))
} }
logs, _, err = sys.TaskService.FindLogs(sys.Ctx, influxdb.LogFilter{Task: task.ID, Run: &rc1.ID}) logs, _, err = sys.TaskService.FindLogs(sys.Ctx, taskmodel.LogFilter{Task: task.ID, Run: &rc1.ID})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -1743,7 +1743,7 @@ func testLogsAcrossStorage(t *testing.T, sys *System) {
t.Fatalf("log contents not acceptable, expected: %q, got: %q", "1-01-11-21-3", smash(logs)) t.Fatalf("log contents not acceptable, expected: %q, got: %q", "1-01-11-21-3", smash(logs))
} }
logs, _, err = sys.TaskService.FindLogs(sys.Ctx, influxdb.LogFilter{Task: task.ID, Run: &rc0.ID}) logs, _, err = sys.TaskService.FindLogs(sys.Ctx, taskmodel.LogFilter{Task: task.ID, Run: &rc0.ID})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -1830,7 +1830,7 @@ func testTaskType(t *testing.T, sys *System) {
authorizedCtx := icontext.SetAuthorizer(sys.Ctx, cr.Authorizer()) authorizedCtx := icontext.SetAuthorizer(sys.Ctx, cr.Authorizer())
// Create a tasks // Create a tasks
ts := influxdb.TaskCreate{ ts := taskmodel.TaskCreate{
OrganizationID: cr.OrgID, OrganizationID: cr.OrgID,
Flux: fmt.Sprintf(scriptFmt, 0), Flux: fmt.Sprintf(scriptFmt, 0),
OwnerID: cr.UserID, OwnerID: cr.UserID,
@ -1844,7 +1844,7 @@ func testTaskType(t *testing.T, sys *System) {
t.Fatal("no task ID set") t.Fatal("no task ID set")
} }
tc := influxdb.TaskCreate{ tc := taskmodel.TaskCreate{
Type: "cows", Type: "cows",
OrganizationID: cr.OrgID, OrganizationID: cr.OrgID,
Flux: fmt.Sprintf(scriptFmt, 0), Flux: fmt.Sprintf(scriptFmt, 0),
@ -1859,7 +1859,7 @@ func testTaskType(t *testing.T, sys *System) {
t.Fatal("no task ID set") t.Fatal("no task ID set")
} }
tp := influxdb.TaskCreate{ tp := taskmodel.TaskCreate{
Type: "pigs", Type: "pigs",
OrganizationID: cr.OrgID, OrganizationID: cr.OrgID,
Flux: fmt.Sprintf(scriptFmt, 0), Flux: fmt.Sprintf(scriptFmt, 0),
@ -1875,19 +1875,19 @@ func testTaskType(t *testing.T, sys *System) {
} }
// get system tasks (or task's with no type) // get system tasks (or task's with no type)
tasks, _, err := sys.TaskService.FindTasks(sys.Ctx, influxdb.TaskFilter{OrganizationID: &cr.OrgID, Type: &influxdb.TaskSystemType}) tasks, _, err := sys.TaskService.FindTasks(sys.Ctx, taskmodel.TaskFilter{OrganizationID: &cr.OrgID, Type: &taskmodel.TaskSystemType})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
for _, task := range tasks { for _, task := range tasks {
if task.Type != "" && task.Type != influxdb.TaskSystemType { if task.Type != "" && task.Type != taskmodel.TaskSystemType {
t.Fatal("received a task with a type when sending no type restriction") t.Fatal("received a task with a type when sending no type restriction")
} }
} }
// get filtered tasks // get filtered tasks
tasks, _, err = sys.TaskService.FindTasks(sys.Ctx, influxdb.TaskFilter{OrganizationID: &cr.OrgID, Type: &tc.Type}) tasks, _, err = sys.TaskService.FindTasks(sys.Ctx, taskmodel.TaskFilter{OrganizationID: &cr.OrgID, Type: &tc.Type})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -1898,7 +1898,7 @@ func testTaskType(t *testing.T, sys *System) {
} }
// get all tasks // get all tasks
tasks, _, err = sys.TaskService.FindTasks(sys.Ctx, influxdb.TaskFilter{OrganizationID: &cr.OrgID}) tasks, _, err = sys.TaskService.FindTasks(sys.Ctx, taskmodel.TaskFilter{OrganizationID: &cr.OrgID})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -1,4 +1,4 @@
package influxdb package taskmodel
import ( import (
"context" "context"
@ -8,11 +8,11 @@ import (
"strconv" "strconv"
"time" "time"
"github.com/influxdata/influxdb/v2/kit/platform"
errors2 "github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/flux/ast" "github.com/influxdata/flux/ast"
"github.com/influxdata/flux/ast/edit" "github.com/influxdata/flux/ast/edit"
"github.com/influxdata/influxdb/v2/kit/platform"
errors2 "github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/influxdb/v2/query/fluxlang"
"github.com/influxdata/influxdb/v2/task/options" "github.com/influxdata/influxdb/v2/task/options"
) )
@ -276,7 +276,7 @@ func (t *TaskUpdate) Validate() error {
// safeParseSource calls the Flux parser.ParseSource function // safeParseSource calls the Flux parser.ParseSource function
// and is guaranteed not to panic. // and is guaranteed not to panic.
func safeParseSource(parser FluxLanguageService, f string) (pkg *ast.Package, err error) { func safeParseSource(parser fluxlang.FluxLanguageService, f string) (pkg *ast.Package, err error) {
if parser == nil { if parser == nil {
return nil, &errors2.Error{ return nil, &errors2.Error{
Code: errors2.EInternal, Code: errors2.EInternal,
@ -298,11 +298,11 @@ func safeParseSource(parser FluxLanguageService, f string) (pkg *ast.Package, er
// UpdateFlux updates the TaskUpdate to go from updating options to updating a // UpdateFlux updates the TaskUpdate to go from updating options to updating a
// flux string, that now has those updated options in it. It zeros the options // flux string, that now has those updated options in it. It zeros the options
// in the TaskUpdate. // in the TaskUpdate.
func (t *TaskUpdate) UpdateFlux(parser FluxLanguageService, oldFlux string) error { func (t *TaskUpdate) UpdateFlux(parser fluxlang.FluxLanguageService, oldFlux string) error {
return t.updateFlux(parser, oldFlux) return t.updateFlux(parser, oldFlux)
} }
func (t *TaskUpdate) updateFlux(parser FluxLanguageService, oldFlux string) error { func (t *TaskUpdate) updateFlux(parser fluxlang.FluxLanguageService, oldFlux string) error {
if t.Flux != nil && *t.Flux != "" { if t.Flux != nil && *t.Flux != "" {
oldFlux = *t.Flux oldFlux = *t.Flux
} }

View File

@ -1,4 +1,4 @@
package influxdb package taskmodel
import ( import (
"fmt" "fmt"

View File

@ -1,18 +1,18 @@
package influxdb_test package taskmodel_test
import ( import (
"encoding/json" "encoding/json"
"testing" "testing"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
platform "github.com/influxdata/influxdb/v2"
_ "github.com/influxdata/influxdb/v2/fluxinit/static" _ "github.com/influxdata/influxdb/v2/fluxinit/static"
"github.com/influxdata/influxdb/v2/query/fluxlang" "github.com/influxdata/influxdb/v2/query/fluxlang"
"github.com/influxdata/influxdb/v2/task/options" "github.com/influxdata/influxdb/v2/task/options"
"github.com/influxdata/influxdb/v2/task/taskmodel"
) )
func TestUpdateValidate(t *testing.T) { func TestUpdateValidate(t *testing.T) {
tu := &platform.TaskUpdate{} tu := &taskmodel.TaskUpdate{}
// this is to make sure that string durations are properly marshaled into durations // this is to make sure that string durations are properly marshaled into durations
if err := json.Unmarshal([]byte(`{"every":"3d2h", "offset":"1h"}`), tu); err != nil { if err := json.Unmarshal([]byte(`{"every":"3d2h", "offset":"1h"}`), tu); err != nil {
t.Fatal(err) t.Fatal(err)
@ -30,7 +30,7 @@ func TestUpdateValidate(t *testing.T) {
} }
func TestOptionsMarshal(t *testing.T) { func TestOptionsMarshal(t *testing.T) {
tu := &platform.TaskUpdate{} tu := &taskmodel.TaskUpdate{}
// this is to make sure that string durations are properly marshaled into durations // this is to make sure that string durations are properly marshaled into durations
if err := json.Unmarshal([]byte(`{"every":"10s", "offset":"1h"}`), tu); err != nil { if err := json.Unmarshal([]byte(`{"every":"10s", "offset":"1h"}`), tu); err != nil {
t.Fatal(err) t.Fatal(err)
@ -42,7 +42,7 @@ func TestOptionsMarshal(t *testing.T) {
t.Fatalf("option.every not properly unmarshaled, expected 1h got %s", tu.Options.Offset) t.Fatalf("option.every not properly unmarshaled, expected 1h got %s", tu.Options.Offset)
} }
tu = &platform.TaskUpdate{} tu = &taskmodel.TaskUpdate{}
// this is to make sure that string durations are properly marshaled into durations // this is to make sure that string durations are properly marshaled into durations
if err := json.Unmarshal([]byte(`{"flux":"option task = {\n\tname: \"task #99\",\n\tcron: \"* * * * *\",\n\toffset: 5s,\n\tconcurrency: 100,\n}\nfrom(bucket:\"b\") |\u003e toHTTP(url:\"http://example.com\")"}`), tu); err != nil { if err := json.Unmarshal([]byte(`{"flux":"option task = {\n\tname: \"task #99\",\n\tcron: \"* * * * *\",\n\toffset: 5s,\n\tconcurrency: 100,\n}\nfrom(bucket:\"b\") |\u003e toHTTP(url:\"http://example.com\")"}`), tu); err != nil {
t.Fatal(err) t.Fatal(err)
@ -54,7 +54,7 @@ func TestOptionsMarshal(t *testing.T) {
} }
func TestOptionsEditWithAST(t *testing.T) { func TestOptionsEditWithAST(t *testing.T) {
tu := &platform.TaskUpdate{} tu := &taskmodel.TaskUpdate{}
tu.Options.Every = *(options.MustParseDuration("10s")) tu.Options.Every = *(options.MustParseDuration("10s"))
if err := tu.UpdateFlux(fluxlang.DefaultService, `option task = {every: 20s, name: "foo"} from(bucket:"x") |> range(start:-1h)`); err != nil { if err := tu.UpdateFlux(fluxlang.DefaultService, `option task = {every: 20s, name: "foo"} from(bucket:"x") |> range(start:-1h)`); err != nil {
t.Fatal(err) t.Fatal(err)
@ -84,7 +84,7 @@ from(bucket: "x")
} }
}) })
t.Run("add new option", func(t *testing.T) { t.Run("add new option", func(t *testing.T) {
tu := &platform.TaskUpdate{} tu := &taskmodel.TaskUpdate{}
tu.Options.Offset = options.MustParseDuration("30s") tu.Options.Offset = options.MustParseDuration("30s")
if err := tu.UpdateFlux(fluxlang.DefaultService, `option task = {every: 20s, name: "foo"} from(bucket:"x") |> range(start:-1h)`); err != nil { if err := tu.UpdateFlux(fluxlang.DefaultService, `option task = {every: 20s, name: "foo"} from(bucket:"x") |> range(start:-1h)`); err != nil {
t.Fatal(err) t.Fatal(err)
@ -98,7 +98,7 @@ from(bucket: "x")
} }
}) })
t.Run("switching from every to cron", func(t *testing.T) { t.Run("switching from every to cron", func(t *testing.T) {
tu := &platform.TaskUpdate{} tu := &taskmodel.TaskUpdate{}
tu.Options.Cron = "* * * * *" tu.Options.Cron = "* * * * *"
if err := tu.UpdateFlux(fluxlang.DefaultService, `option task = {every: 20s, name: "foo"} from(bucket:"x") |> range(start:-1h)`); err != nil { if err := tu.UpdateFlux(fluxlang.DefaultService, `option task = {every: 20s, name: "foo"} from(bucket:"x") |> range(start:-1h)`); err != nil {
t.Fatal(err) t.Fatal(err)
@ -115,7 +115,7 @@ from(bucket: "x")
} }
}) })
t.Run("switching from cron to every", func(t *testing.T) { t.Run("switching from cron to every", func(t *testing.T) {
tu := &platform.TaskUpdate{} tu := &taskmodel.TaskUpdate{}
tu.Options.Every = *(options.MustParseDuration("10s")) tu.Options.Every = *(options.MustParseDuration("10s"))
if err := tu.UpdateFlux(fluxlang.DefaultService, `option task = {cron: "* * * * *", name: "foo"} from(bucket:"x") |> range(start:-1h)`); err != nil { if err := tu.UpdateFlux(fluxlang.DefaultService, `option task = {cron: "* * * * *", name: "foo"} from(bucket:"x") |> range(start:-1h)`); err != nil {
t.Fatal(err) t.Fatal(err)
@ -132,7 +132,7 @@ from(bucket: "x")
} }
}) })
t.Run("delete deletable option", func(t *testing.T) { t.Run("delete deletable option", func(t *testing.T) {
tu := &platform.TaskUpdate{} tu := &taskmodel.TaskUpdate{}
tu.Options.Offset = &options.Duration{} tu.Options.Offset = &options.Duration{}
expscript := `option task = {cron: "* * * * *", name: "foo"} expscript := `option task = {cron: "* * * * *", name: "foo"}
@ -159,10 +159,10 @@ from(bucket: "x")
} }
func TestParseRequestStillQueuedError(t *testing.T) { func TestParseRequestStillQueuedError(t *testing.T) {
e := platform.RequestStillQueuedError{Start: 1000, End: 2000} e := taskmodel.RequestStillQueuedError{Start: 1000, End: 2000}
validMsg := e.Error() validMsg := e.Error()
if err := platform.ParseRequestStillQueuedError(validMsg); err == nil || *err != e { if err := taskmodel.ParseRequestStillQueuedError(validMsg); err == nil || *err != e {
t.Fatalf("%q should have parsed to %v, but got %v", validMsg, e, err) t.Fatalf("%q should have parsed to %v, but got %v", validMsg, e, err)
} }
} }