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 gcipull/21158/head^2
parent
07c030a9b1
commit
7b2e122869
|
@ -3,9 +3,9 @@ package authorizer
|
|||
import (
|
||||
"context"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform/errors"
|
||||
|
||||
"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.
|
||||
|
@ -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.
|
||||
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
|
||||
// https://github.com/golang/go/wiki/SliceTricks#filtering-without-allocating
|
||||
rrs := rs[:0]
|
||||
|
|
|
@ -3,9 +3,9 @@ package authorizer
|
|||
import (
|
||||
"context"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
)
|
||||
|
||||
var _ influxdb.CheckService = (*CheckService)(nil)
|
||||
|
@ -16,7 +16,7 @@ type CheckService struct {
|
|||
s influxdb.CheckService
|
||||
influxdb.UserResourceMappingService
|
||||
influxdb.OrganizationService
|
||||
influxdb.TaskService
|
||||
taskmodel.TaskService
|
||||
}
|
||||
|
||||
// NewCheckService constructs an instance of an authorizing check service.
|
||||
|
|
|
@ -4,11 +4,11 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
|
||||
"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"
|
||||
"github.com/influxdata/influxdb/v2/kit/tracing"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
@ -35,13 +35,13 @@ var (
|
|||
)
|
||||
|
||||
type taskServiceValidator struct {
|
||||
influxdb.TaskService
|
||||
taskmodel.TaskService
|
||||
log *zap.Logger
|
||||
}
|
||||
|
||||
// TaskService wraps ts and checks appropriate permissions before calling requested methods on ts.
|
||||
// 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{
|
||||
TaskService: ts,
|
||||
log: log,
|
||||
|
@ -61,7 +61,7 @@ func (ts *taskServiceValidator) processPermissionError(a influxdb.Authorizer, p
|
|||
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)
|
||||
defer span.Finish()
|
||||
|
||||
|
@ -79,7 +79,7 @@ func (ts *taskServiceValidator) FindTaskByID(ctx context.Context, id platform.ID
|
|||
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)
|
||||
defer span.Finish()
|
||||
// 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)
|
||||
}
|
||||
|
||||
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)
|
||||
defer span.Finish()
|
||||
|
||||
if !t.OwnerID.Valid() {
|
||||
return nil, influxdb.ErrInvalidOwnerID
|
||||
return nil, taskmodel.ErrInvalidOwnerID
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
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)
|
||||
defer span.Finish()
|
||||
|
||||
|
@ -142,7 +142,7 @@ func (ts *taskServiceValidator) DeleteTask(ctx context.Context, id platform.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)
|
||||
defer span.Finish()
|
||||
|
||||
|
@ -155,7 +155,7 @@ func (ts *taskServiceValidator) FindLogs(ctx context.Context, filter influxdb.Lo
|
|||
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)
|
||||
defer span.Finish()
|
||||
|
||||
|
@ -174,7 +174,7 @@ func (ts *taskServiceValidator) FindRuns(ctx context.Context, filter influxdb.Ru
|
|||
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)
|
||||
defer span.Finish()
|
||||
|
||||
|
@ -210,7 +210,7 @@ func (ts *taskServiceValidator) CancelRun(ctx context.Context, taskID, runID pla
|
|||
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)
|
||||
defer span.Finish()
|
||||
|
||||
|
@ -220,7 +220,7 @@ func (ts *taskServiceValidator) RetryRun(ctx context.Context, taskID, runID plat
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if task.Status != string(influxdb.TaskActive) {
|
||||
if task.Status != string(taskmodel.TaskActive) {
|
||||
return nil, ErrInactiveTask
|
||||
}
|
||||
|
||||
|
@ -232,7 +232,7 @@ func (ts *taskServiceValidator) RetryRun(ctx context.Context, taskID, runID plat
|
|||
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)
|
||||
defer span.Finish()
|
||||
|
||||
|
@ -242,7 +242,7 @@ func (ts *taskServiceValidator) ForceRun(ctx context.Context, taskID platform.ID
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if task.Status != string(influxdb.TaskActive) {
|
||||
if task.Status != string(taskmodel.TaskActive) {
|
||||
return nil, ErrInactiveTask
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package authorizer_test
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -13,9 +12,11 @@ import (
|
|||
_ "github.com/influxdata/influxdb/v2/fluxinit/static"
|
||||
"github.com/influxdata/influxdb/v2/http"
|
||||
"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/migration/all"
|
||||
"github.com/influxdata/influxdb/v2/mock"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
"github.com/influxdata/influxdb/v2/tenant"
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/zap/zaptest"
|
||||
|
@ -39,7 +40,7 @@ func TestOnboardingValidation(t *testing.T) {
|
|||
|
||||
ctx := pctx.SetAuthorizer(context.Background(), r.Auth)
|
||||
|
||||
_, err = ts.CreateTask(ctx, influxdb.TaskCreate{
|
||||
_, err = ts.CreateTask(ctx, taskmodel.TaskCreate{
|
||||
OrganizationID: r.Org.ID,
|
||||
OwnerID: r.Auth.GetUserID(),
|
||||
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 {
|
||||
task := influxdb.Task{
|
||||
func mockTaskService(orgID, taskID, runID platform.ID) taskmodel.TaskService {
|
||||
task := taskmodel.Task{
|
||||
ID: taskID,
|
||||
OrganizationID: orgID,
|
||||
Name: "cows",
|
||||
Status: string(influxdb.TaskActive),
|
||||
Status: string(taskmodel.TaskActive),
|
||||
Flux: `option task = {
|
||||
name: "my_task",
|
||||
every: 1s,
|
||||
|
@ -67,51 +68,51 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`,
|
|||
Every: "1s",
|
||||
}
|
||||
|
||||
log := influxdb.Log{Message: "howdy partner"}
|
||||
log := taskmodel.Log{Message: "howdy partner"}
|
||||
|
||||
run := influxdb.Run{
|
||||
run := taskmodel.Run{
|
||||
ID: runID,
|
||||
TaskID: taskID,
|
||||
Status: "completed",
|
||||
ScheduledFor: time.Now().UTC(),
|
||||
StartedAt: time.Now().UTC().Add(time.Second * 3),
|
||||
FinishedAt: time.Now().UTC().Add(time.Second * 10),
|
||||
Log: []influxdb.Log{log},
|
||||
Log: []taskmodel.Log{log},
|
||||
}
|
||||
|
||||
return &mock.TaskService{
|
||||
FindTaskByIDFn: func(context.Context, platform.ID) (*influxdb.Task, error) {
|
||||
FindTaskByIDFn: func(context.Context, platform.ID) (*taskmodel.Task, error) {
|
||||
return &task, nil
|
||||
},
|
||||
FindTasksFn: func(context.Context, influxdb.TaskFilter) ([]*influxdb.Task, int, error) {
|
||||
return []*influxdb.Task{&task}, 1, nil
|
||||
FindTasksFn: func(context.Context, taskmodel.TaskFilter) ([]*taskmodel.Task, int, error) {
|
||||
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
|
||||
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
|
||||
},
|
||||
DeleteTaskFn: func(context.Context, platform.ID) error {
|
||||
return nil
|
||||
},
|
||||
FindLogsFn: func(context.Context, influxdb.LogFilter) ([]*influxdb.Log, int, error) {
|
||||
return []*influxdb.Log{&log}, 1, nil
|
||||
FindLogsFn: func(context.Context, taskmodel.LogFilter) ([]*taskmodel.Log, int, error) {
|
||||
return []*taskmodel.Log{&log}, 1, nil
|
||||
},
|
||||
FindRunsFn: func(context.Context, influxdb.RunFilter) ([]*influxdb.Run, int, error) {
|
||||
return []*influxdb.Run{&run}, 1, nil
|
||||
FindRunsFn: func(context.Context, taskmodel.RunFilter) ([]*taskmodel.Run, int, error) {
|
||||
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
|
||||
},
|
||||
CancelRunFn: func(context.Context, platform.ID, platform.ID) error {
|
||||
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
|
||||
},
|
||||
ForceRunFn: func(context.Context, platform.ID, int64) (*influxdb.Run, error) {
|
||||
ForceRunFn: func(context.Context, platform.ID, int64) (*taskmodel.Run, error) {
|
||||
return &run, nil
|
||||
},
|
||||
}
|
||||
|
@ -196,13 +197,13 @@ func TestValidations(t *testing.T) {
|
|||
|
||||
tests := []struct {
|
||||
name string
|
||||
check func(context.Context, influxdb.TaskService) error
|
||||
check func(context.Context, taskmodel.TaskService) error
|
||||
auth *influxdb.Authorization
|
||||
}{
|
||||
{
|
||||
name: "create failure",
|
||||
check: func(ctx context.Context, svc influxdb.TaskService) error {
|
||||
_, err := svc.CreateTask(ctx, influxdb.TaskCreate{
|
||||
check: func(ctx context.Context, svc taskmodel.TaskService) error {
|
||||
_, err := svc.CreateTask(ctx, taskmodel.TaskCreate{
|
||||
OrganizationID: r.Org.ID,
|
||||
Flux: `option task = {
|
||||
name: "my_task",
|
||||
|
@ -220,8 +221,8 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`,
|
|||
{
|
||||
name: "create success",
|
||||
auth: r.Auth,
|
||||
check: func(ctx context.Context, svc influxdb.TaskService) error {
|
||||
_, err := svc.CreateTask(ctx, influxdb.TaskCreate{
|
||||
check: func(ctx context.Context, svc taskmodel.TaskService) error {
|
||||
_, err := svc.CreateTask(ctx, taskmodel.TaskCreate{
|
||||
OrganizationID: r.Org.ID,
|
||||
OwnerID: r.Auth.GetUserID(),
|
||||
Flux: `option task = {
|
||||
|
@ -236,7 +237,7 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`,
|
|||
{
|
||||
name: "FindTaskByID missing auth",
|
||||
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)
|
||||
if err == nil {
|
||||
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",
|
||||
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)
|
||||
return err
|
||||
},
|
||||
|
@ -255,7 +256,7 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`,
|
|||
{
|
||||
name: "FindTaskByID with task auth",
|
||||
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)
|
||||
return err
|
||||
},
|
||||
|
@ -263,8 +264,8 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`,
|
|||
{
|
||||
name: "FindTasks with bad auth",
|
||||
auth: &influxdb.Authorization{Status: "active", Permissions: wrongOrgReadAllTaskPermissions},
|
||||
check: func(ctx context.Context, svc influxdb.TaskService) error {
|
||||
ts, _, err := svc.FindTasks(ctx, influxdb.TaskFilter{
|
||||
check: func(ctx context.Context, svc taskmodel.TaskService) error {
|
||||
ts, _, err := svc.FindTasks(ctx, taskmodel.TaskFilter{
|
||||
OrganizationID: &orgID,
|
||||
})
|
||||
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",
|
||||
auth: &influxdb.Authorization{Status: "active", Permissions: orgReadAllTaskPermissions},
|
||||
check: func(ctx context.Context, svc influxdb.TaskService) error {
|
||||
_, _, err := svc.FindTasks(ctx, influxdb.TaskFilter{
|
||||
check: func(ctx context.Context, svc taskmodel.TaskService) error {
|
||||
_, _, err := svc.FindTasks(ctx, taskmodel.TaskFilter{
|
||||
OrganizationID: &orgID,
|
||||
})
|
||||
return err
|
||||
|
@ -286,8 +287,8 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`,
|
|||
{
|
||||
name: "FindTasks with task auth",
|
||||
auth: &influxdb.Authorization{Status: "active", Permissions: orgReadTaskPermissions},
|
||||
check: func(ctx context.Context, svc influxdb.TaskService) error {
|
||||
_, _, err := svc.FindTasks(ctx, influxdb.TaskFilter{
|
||||
check: func(ctx context.Context, svc taskmodel.TaskService) error {
|
||||
_, _, err := svc.FindTasks(ctx, taskmodel.TaskFilter{
|
||||
OrganizationID: &orgID,
|
||||
})
|
||||
return err
|
||||
|
@ -296,21 +297,21 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`,
|
|||
{
|
||||
name: "FindTasks without org filter",
|
||||
auth: &influxdb.Authorization{Status: "active", Permissions: orgReadAllTaskPermissions},
|
||||
check: func(ctx context.Context, svc influxdb.TaskService) error {
|
||||
_, _, err := svc.FindTasks(ctx, influxdb.TaskFilter{})
|
||||
check: func(ctx context.Context, svc taskmodel.TaskService) error {
|
||||
_, _, err := svc.FindTasks(ctx, taskmodel.TaskFilter{})
|
||||
return err
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "UpdateTask with readonly auth",
|
||||
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 = {
|
||||
name: "my_task",
|
||||
every: 1s,
|
||||
}
|
||||
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,
|
||||
})
|
||||
if err == nil {
|
||||
|
@ -322,13 +323,13 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
|
|||
{
|
||||
name: "UpdateTask with org auth",
|
||||
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 = {
|
||||
name: "my_task",
|
||||
every: 1s,
|
||||
}
|
||||
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,
|
||||
})
|
||||
return err
|
||||
|
@ -337,13 +338,13 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
|
|||
{
|
||||
name: "UpdateTask with task auth",
|
||||
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 = {
|
||||
name: "my_task",
|
||||
every: 1s,
|
||||
}
|
||||
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,
|
||||
})
|
||||
return err
|
||||
|
@ -352,7 +353,7 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
|
|||
{
|
||||
name: "DeleteTask missing auth",
|
||||
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)
|
||||
if err == nil {
|
||||
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",
|
||||
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)
|
||||
if err == nil {
|
||||
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",
|
||||
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)
|
||||
return err
|
||||
},
|
||||
|
@ -382,7 +383,7 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
|
|||
{
|
||||
name: "DeleteTask with task auth",
|
||||
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)
|
||||
return err
|
||||
},
|
||||
|
@ -390,8 +391,8 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
|
|||
{
|
||||
name: "FindLogs with bad auth",
|
||||
auth: &influxdb.Authorization{Status: "active", Permissions: wrongOrgReadAllTaskPermissions},
|
||||
check: func(ctx context.Context, svc influxdb.TaskService) error {
|
||||
_, _, err := svc.FindLogs(ctx, influxdb.LogFilter{
|
||||
check: func(ctx context.Context, svc taskmodel.TaskService) error {
|
||||
_, _, err := svc.FindLogs(ctx, taskmodel.LogFilter{
|
||||
Task: taskID,
|
||||
})
|
||||
if err == nil {
|
||||
|
@ -403,8 +404,8 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
|
|||
{
|
||||
name: "FindLogs with org auth",
|
||||
auth: &influxdb.Authorization{Status: "active", Permissions: orgReadAllTaskPermissions},
|
||||
check: func(ctx context.Context, svc influxdb.TaskService) error {
|
||||
_, _, err := svc.FindLogs(ctx, influxdb.LogFilter{
|
||||
check: func(ctx context.Context, svc taskmodel.TaskService) error {
|
||||
_, _, err := svc.FindLogs(ctx, taskmodel.LogFilter{
|
||||
Task: taskID,
|
||||
})
|
||||
return err
|
||||
|
@ -413,8 +414,8 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
|
|||
{
|
||||
name: "FindLogs with task auth",
|
||||
auth: &influxdb.Authorization{Status: "active", Permissions: orgReadTaskPermissions},
|
||||
check: func(ctx context.Context, svc influxdb.TaskService) error {
|
||||
_, _, err := svc.FindLogs(ctx, influxdb.LogFilter{
|
||||
check: func(ctx context.Context, svc taskmodel.TaskService) error {
|
||||
_, _, err := svc.FindLogs(ctx, taskmodel.LogFilter{
|
||||
Task: taskID,
|
||||
})
|
||||
return err
|
||||
|
@ -423,8 +424,8 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
|
|||
{
|
||||
name: "FindRuns with bad auth",
|
||||
auth: &influxdb.Authorization{Status: "active", Permissions: wrongOrgReadAllTaskPermissions},
|
||||
check: func(ctx context.Context, svc influxdb.TaskService) error {
|
||||
_, _, err := svc.FindRuns(ctx, influxdb.RunFilter{
|
||||
check: func(ctx context.Context, svc taskmodel.TaskService) error {
|
||||
_, _, err := svc.FindRuns(ctx, taskmodel.RunFilter{
|
||||
Task: taskID,
|
||||
})
|
||||
if err == nil {
|
||||
|
@ -436,8 +437,8 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
|
|||
{
|
||||
name: "FindRuns with org auth",
|
||||
auth: &influxdb.Authorization{Status: "active", Permissions: orgReadAllTaskPermissions},
|
||||
check: func(ctx context.Context, svc influxdb.TaskService) error {
|
||||
_, _, err := svc.FindRuns(ctx, influxdb.RunFilter{
|
||||
check: func(ctx context.Context, svc taskmodel.TaskService) error {
|
||||
_, _, err := svc.FindRuns(ctx, taskmodel.RunFilter{
|
||||
Task: taskID,
|
||||
})
|
||||
return err
|
||||
|
@ -446,8 +447,8 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
|
|||
{
|
||||
name: "FindRuns with task auth",
|
||||
auth: &influxdb.Authorization{Status: "active", Permissions: orgReadTaskPermissions},
|
||||
check: func(ctx context.Context, svc influxdb.TaskService) error {
|
||||
_, _, err := svc.FindRuns(ctx, influxdb.RunFilter{
|
||||
check: func(ctx context.Context, svc taskmodel.TaskService) error {
|
||||
_, _, err := svc.FindRuns(ctx, taskmodel.RunFilter{
|
||||
Task: taskID,
|
||||
})
|
||||
return err
|
||||
|
@ -456,7 +457,7 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
|
|||
{
|
||||
name: "FindRunByID missing auth",
|
||||
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)
|
||||
if err == nil {
|
||||
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",
|
||||
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)
|
||||
return err
|
||||
},
|
||||
|
@ -475,7 +476,7 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
|
|||
{
|
||||
name: "FindRunByID with task auth",
|
||||
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)
|
||||
return err
|
||||
},
|
||||
|
@ -483,7 +484,7 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
|
|||
{
|
||||
name: "CancelRun with bad auth",
|
||||
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)
|
||||
if err == nil {
|
||||
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",
|
||||
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)
|
||||
return err
|
||||
},
|
||||
|
@ -502,7 +503,7 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
|
|||
{
|
||||
name: "CancelRun with task auth",
|
||||
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)
|
||||
return err
|
||||
},
|
||||
|
@ -510,7 +511,7 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
|
|||
{
|
||||
name: "RetryRun with bad auth",
|
||||
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)
|
||||
if err == nil {
|
||||
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",
|
||||
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)
|
||||
return err
|
||||
},
|
||||
|
@ -529,7 +530,7 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
|
|||
{
|
||||
name: "RetryRun with task auth",
|
||||
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)
|
||||
return err
|
||||
},
|
||||
|
@ -537,7 +538,7 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
|
|||
{
|
||||
name: "ForceRun with bad auth",
|
||||
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)
|
||||
if err == nil {
|
||||
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",
|
||||
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)
|
||||
return err
|
||||
},
|
||||
|
@ -556,7 +557,7 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
|
|||
{
|
||||
name: "ForceRun with task auth",
|
||||
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)
|
||||
return err
|
||||
},
|
||||
|
|
5
check.go
5
check.go
|
@ -6,6 +6,7 @@ import (
|
|||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
"github.com/influxdata/influxdb/v2/kit/platform/errors"
|
||||
"github.com/influxdata/influxdb/v2/query/fluxlang"
|
||||
)
|
||||
|
||||
// consts for checks config.
|
||||
|
@ -16,14 +17,14 @@ const (
|
|||
|
||||
// Check represents the information required to generate a periodic check task.
|
||||
type Check interface {
|
||||
Valid(lang FluxLanguageService) error
|
||||
Valid(lang fluxlang.FluxLanguageService) error
|
||||
Type() string
|
||||
ClearPrivateData()
|
||||
SetTaskID(platform.ID)
|
||||
GetTaskID() platform.ID
|
||||
GetOwnerID() platform.ID
|
||||
SetOwnerID(platform.ID)
|
||||
GenerateFlux(lang FluxLanguageService) (string, error)
|
||||
GenerateFlux(lang fluxlang.FluxLanguageService) (string, error)
|
||||
json.Marshaler
|
||||
|
||||
CRUDLogSetter
|
||||
|
|
|
@ -4,15 +4,15 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
|
||||
"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"
|
||||
"github.com/influxdata/influxdb/v2/kit/tracing"
|
||||
"github.com/influxdata/influxdb/v2/kv"
|
||||
"github.com/influxdata/influxdb/v2/notification/check"
|
||||
"github.com/influxdata/influxdb/v2/query/fluxlang"
|
||||
"github.com/influxdata/influxdb/v2/snowflake"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
@ -26,7 +26,7 @@ type Service struct {
|
|||
log *zap.Logger
|
||||
|
||||
orgs influxdb.OrganizationService
|
||||
tasks influxdb.TaskService
|
||||
tasks taskmodel.TaskService
|
||||
|
||||
timeGenerator influxdb.TimeGenerator
|
||||
idGenerator platform.IDGenerator
|
||||
|
@ -35,7 +35,7 @@ type Service struct {
|
|||
}
|
||||
|
||||
// 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{
|
||||
kv: store,
|
||||
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
|
||||
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)),
|
||||
})
|
||||
}
|
||||
|
@ -338,13 +338,13 @@ func (s *Service) CreateCheck(ctx context.Context, c influxdb.CheckCreate, userI
|
|||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tc := influxdb.TaskCreate{
|
||||
tc := taskmodel.TaskCreate{
|
||||
Type: c.Type(),
|
||||
Flux: script,
|
||||
OwnerID: c.GetOwnerID(),
|
||||
|
@ -440,7 +440,7 @@ func (s *Service) updateCheckTask(ctx context.Context, chk influxdb.CheckCreate)
|
|||
return err
|
||||
}
|
||||
|
||||
tu := influxdb.TaskUpdate{
|
||||
tu := taskmodel.TaskUpdate{
|
||||
Flux: &flux,
|
||||
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 {
|
||||
tu := influxdb.TaskUpdate{
|
||||
tu := taskmodel.TaskUpdate{
|
||||
Description: upd.Description,
|
||||
}
|
||||
|
||||
|
|
|
@ -8,16 +8,16 @@ import (
|
|||
"testing"
|
||||
"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/cmpopts"
|
||||
"github.com/influxdata/flux/ast"
|
||||
"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/notification"
|
||||
"github.com/influxdata/influxdb/v2/notification/check"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -160,14 +160,14 @@ var taskCmpOptions = cmp.Options{
|
|||
}),
|
||||
// skip comparing permissions
|
||||
cmpopts.IgnoreFields(
|
||||
influxdb.Task{},
|
||||
taskmodel.Task{},
|
||||
"LatestCompleted",
|
||||
"LatestScheduled",
|
||||
"CreatedAt",
|
||||
"UpdatedAt",
|
||||
),
|
||||
cmp.Transformer("Sort", func(in []*influxdb.Task) []*influxdb.Task {
|
||||
out := append([]*influxdb.Task{}, in...) // Copy input to avoid mutating it
|
||||
cmp.Transformer("Sort", func(in []*taskmodel.Task) []*taskmodel.Task {
|
||||
out := append([]*taskmodel.Task{}, in...) // Copy input to avoid mutating it
|
||||
sort.Slice(out, func(i, j int) bool {
|
||||
return out[i].ID > out[j].ID
|
||||
})
|
||||
|
@ -179,13 +179,13 @@ var taskCmpOptions = cmp.Options{
|
|||
type CheckFields struct {
|
||||
IDGenerator platform.IDGenerator
|
||||
TimeGenerator influxdb.TimeGenerator
|
||||
TaskService influxdb.TaskService
|
||||
TaskService taskmodel.TaskService
|
||||
Checks []influxdb.Check
|
||||
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(
|
||||
init checkServiceFactory,
|
||||
|
@ -249,7 +249,7 @@ func CreateCheck(
|
|||
type wants struct {
|
||||
err *errors.Error
|
||||
checks []influxdb.Check
|
||||
tasks []*influxdb.Task
|
||||
tasks []*taskmodel.Task
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
|
@ -308,7 +308,7 @@ func CreateCheck(
|
|||
},
|
||||
},
|
||||
wants: wants{
|
||||
tasks: []*influxdb.Task{
|
||||
tasks: []*taskmodel.Task{
|
||||
{
|
||||
ID: MustIDBase16("020f755c3c082000"),
|
||||
Name: "name1",
|
||||
|
@ -437,7 +437,7 @@ func CreateCheck(
|
|||
deadman1,
|
||||
threshold1,
|
||||
},
|
||||
tasks: []*influxdb.Task{
|
||||
tasks: []*taskmodel.Task{
|
||||
{
|
||||
ID: MustIDBase16("020f755c3c082001"),
|
||||
Name: "name2",
|
||||
|
@ -574,7 +574,7 @@ func CreateCheck(
|
|||
},
|
||||
},
|
||||
wants: wants{
|
||||
tasks: []*influxdb.Task{
|
||||
tasks: []*taskmodel.Task{
|
||||
{
|
||||
ID: MustIDBase16("020f755c3c082001"),
|
||||
Name: "name1",
|
||||
|
@ -701,7 +701,7 @@ func CreateCheck(
|
|||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -1060,7 +1060,7 @@ func DeleteCheck(
|
|||
ID: MustIDBase16(orgOneID),
|
||||
},
|
||||
},
|
||||
Tasks: []influxdb.TaskCreate{
|
||||
Tasks: []taskmodel.TaskCreate{
|
||||
{
|
||||
Flux: `option task = { every: 10s, name: "foo" }
|
||||
data = from(bucket: "telegraf") |> range(start: -1m)`,
|
||||
|
@ -1093,7 +1093,7 @@ data = from(bucket: "telegraf") |> range(start: -1m)`,
|
|||
ID: MustIDBase16(orgOneID),
|
||||
},
|
||||
},
|
||||
Tasks: []influxdb.TaskCreate{
|
||||
Tasks: []taskmodel.TaskCreate{
|
||||
{
|
||||
Flux: `option task = { every: 10s, name: "foo" }
|
||||
data = from(bucket: "telegraf") |> range(start: -1m)`,
|
||||
|
@ -1293,7 +1293,7 @@ func UpdateCheck(
|
|||
ID: MustIDBase16(orgOneID),
|
||||
},
|
||||
},
|
||||
Tasks: []influxdb.TaskCreate{
|
||||
Tasks: []taskmodel.TaskCreate{
|
||||
{
|
||||
Flux: `option task = { every: 10s, name: "foo" }
|
||||
data = from(bucket: "telegraf") |> range(start: -1m)`,
|
||||
|
@ -1551,7 +1551,7 @@ func PatchCheck(
|
|||
fields: CheckFields{
|
||||
IDGenerator: mock.NewIDGenerator("0000000000000001", t),
|
||||
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" }
|
||||
data = from(bucket: "telegraf") |> range(start: -1m)`,
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/influxdata/influxdb/v2/kv/migration/all"
|
||||
"github.com/influxdata/influxdb/v2/mock"
|
||||
"github.com/influxdata/influxdb/v2/query/fluxlang"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
"github.com/influxdata/influxdb/v2/tenant"
|
||||
"go.uber.org/zap/zaptest"
|
||||
)
|
||||
|
@ -31,7 +32,7 @@ func TestCheckService(t *testing.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)
|
||||
logger := zaptest.NewLogger(t)
|
||||
|
||||
|
|
|
@ -5,17 +5,17 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
"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/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()
|
||||
if err != nil {
|
||||
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)
|
||||
}
|
||||
|
||||
tc := influxdb.TaskCreate{
|
||||
tc := taskmodel.TaskCreate{
|
||||
Flux: flux,
|
||||
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)
|
||||
cmd.Flags().StringVarP(&b.taskID, "id", "i", "", "task 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")
|
||||
|
||||
return cmd
|
||||
|
@ -169,7 +169,7 @@ func (b *cmdTaskBuilder) taskFindF(cmd *cobra.Command, args []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
filter := influxdb.TaskFilter{}
|
||||
filter := taskmodel.TaskFilter{}
|
||||
if b.taskFindFlags.user != "" {
|
||||
id, err := platform.IDFromString(b.taskFindFlags.user)
|
||||
if err != nil {
|
||||
|
@ -189,12 +189,12 @@ func (b *cmdTaskBuilder) taskFindF(cmd *cobra.Command, args []string) error {
|
|||
filter.OrganizationID = id
|
||||
}
|
||||
|
||||
if b.taskFindFlags.limit < 1 || b.taskFindFlags.limit > influxdb.TaskMaxPageSize {
|
||||
return fmt.Errorf("limit must be between 1 and %d", influxdb.TaskMaxPageSize)
|
||||
if b.taskFindFlags.limit < 1 || b.taskFindFlags.limit > taskmodel.TaskMaxPageSize {
|
||||
return fmt.Errorf("limit must be between 1 and %d", taskmodel.TaskMaxPageSize)
|
||||
}
|
||||
filter.Limit = b.taskFindFlags.limit
|
||||
|
||||
var tasks []*influxdb.Task
|
||||
var tasks []*taskmodel.Task
|
||||
|
||||
if b.taskID != "" {
|
||||
id, err := platform.IDFromString(b.taskID)
|
||||
|
@ -262,7 +262,7 @@ func (b *cmdTaskBuilder) taskRetryFailedF(*cobra.Command, []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
var failedRuns []*influxdb.Run
|
||||
var failedRuns []*taskmodel.Run
|
||||
if b.taskID == "" {
|
||||
failedRuns, err = b.getFailedRunsForOrg(b.taskRerunFailedFlags.taskLimit, b.taskRerunFailedFlags.runLimit)
|
||||
} else {
|
||||
|
@ -295,13 +295,13 @@ func (b *cmdTaskBuilder) taskRetryFailedF(*cobra.Command, []string) error {
|
|||
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
|
||||
tskSvc, _, err := b.svcFn()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
runFilter := influxdb.RunFilter{Limit: limit}
|
||||
runFilter := taskmodel.RunFilter{Limit: limit}
|
||||
id, err := platform.IDFromString(b.taskID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -313,7 +313,7 @@ func (b *cmdTaskBuilder) getFailedRunsForTaskID(limit int) ([]*influxdb.Run, err
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var allFailedRuns []*influxdb.Run
|
||||
var allFailedRuns []*taskmodel.Run
|
||||
for _, run := range allRuns {
|
||||
if run.Status == "failed" {
|
||||
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
|
||||
taskFilter := influxdb.TaskFilter{Limit: taskLimit}
|
||||
runFilter := influxdb.RunFilter{Limit: runLimit}
|
||||
taskFilter := taskmodel.TaskFilter{Limit: taskLimit}
|
||||
runFilter := taskmodel.RunFilter{Limit: runLimit}
|
||||
runFilter.BeforeTime = b.taskRerunFailedFlags.before
|
||||
runFilter.AfterTime = b.taskRerunFailedFlags.after
|
||||
tskSvc, _, err := b.svcFn()
|
||||
|
@ -350,11 +350,11 @@ func (b *cmdTaskBuilder) getFailedRunsForOrg(taskLimit int, runLimit int) ([]*in
|
|||
return nil, err
|
||||
}
|
||||
|
||||
var allFailedRuns []*influxdb.Run
|
||||
var allFailedRuns []*taskmodel.Run
|
||||
for _, t := range allTasks {
|
||||
runFilter.Task = t.ID
|
||||
runsPerTask, _, err := tskSvc.FindRuns(context.Background(), runFilter)
|
||||
var failedRunsPerTask []*influxdb.Run
|
||||
var failedRunsPerTask []*taskmodel.Run
|
||||
for _, r := range runsPerTask {
|
||||
if r.Status == "failed" {
|
||||
failedRunsPerTask = append(failedRunsPerTask, r)
|
||||
|
@ -399,7 +399,7 @@ func (b *cmdTaskBuilder) taskUpdateF(cmd *cobra.Command, args []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
var update influxdb.TaskUpdate
|
||||
var update taskmodel.TaskUpdate
|
||||
if 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 {
|
||||
task *influxdb.Task
|
||||
tasks []*influxdb.Task
|
||||
task *taskmodel.Task
|
||||
tasks []*taskmodel.Task
|
||||
}
|
||||
|
||||
func (b *cmdTaskBuilder) printTasks(printOpts taskPrintOpts) error {
|
||||
|
@ -537,7 +537,7 @@ func (b *cmdTaskBuilder) taskLogFindF(cmd *cobra.Command, args []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
var filter influxdb.LogFilter
|
||||
var filter taskmodel.LogFilter
|
||||
id, err := platform.IDFromString(b.taskID)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -621,7 +621,7 @@ func (b *cmdTaskBuilder) taskRunFindF(cmd *cobra.Command, args []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
filter := influxdb.RunFilter{
|
||||
filter := taskmodel.RunFilter{
|
||||
Limit: b.taskRunFindFlags.limit,
|
||||
AfterTime: b.taskRunFindFlags.afterTime,
|
||||
BeforeTime: b.taskRunFindFlags.beforeTime,
|
||||
|
@ -632,7 +632,7 @@ func (b *cmdTaskBuilder) taskRunFindF(cmd *cobra.Command, args []string) error {
|
|||
}
|
||||
filter.Task = *taskID
|
||||
|
||||
var runs []*influxdb.Run
|
||||
var runs []*taskmodel.Run
|
||||
if b.runID != "" {
|
||||
id, err := platform.IDFromString(b.runID)
|
||||
if err != nil {
|
||||
|
@ -653,7 +653,7 @@ func (b *cmdTaskBuilder) taskRunFindF(cmd *cobra.Command, args []string) error {
|
|||
if b.taskPrintFlags.json {
|
||||
if runs == nil {
|
||||
// guarantee we never return a null value from CLI
|
||||
runs = make([]*influxdb.Run, 0)
|
||||
runs = make([]*taskmodel.Run, 0)
|
||||
}
|
||||
return b.opts.writeJSON(runs)
|
||||
}
|
||||
|
|
|
@ -7,11 +7,11 @@ import (
|
|||
"io/ioutil"
|
||||
"testing"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
"github.com/influxdata/influxdb/v2/mock"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -21,8 +21,8 @@ import (
|
|||
func TestCmdTask(t *testing.T) {
|
||||
orgID := platform.ID(9000)
|
||||
|
||||
fakeSVCFn := func(svc influxdb.TaskService) taskSVCsFn {
|
||||
return func() (influxdb.TaskService, influxdb.OrganizationService, error) {
|
||||
fakeSVCFn := func(svc taskmodel.TaskService) taskSVCsFn {
|
||||
return func() (taskmodel.TaskService, influxdb.OrganizationService, error) {
|
||||
return svc, &mock.OrganizationService{
|
||||
FindOrganizationF: func(ctx context.Context, filter influxdb.OrganizationFilter) (*influxdb.Organization, error) {
|
||||
return &influxdb.Organization{ID: orgID, Name: "influxdata"}, nil
|
||||
|
@ -36,7 +36,7 @@ func TestCmdTask(t *testing.T) {
|
|||
// todo: add more test cases
|
||||
tests := []struct {
|
||||
name string
|
||||
expectedTask influxdb.Task
|
||||
expectedTask taskmodel.Task
|
||||
flags []string
|
||||
envVars map[string]string
|
||||
}{
|
||||
|
@ -45,17 +45,17 @@ func TestCmdTask(t *testing.T) {
|
|||
flags: []string{
|
||||
"--org=influxdata",
|
||||
},
|
||||
expectedTask: influxdb.Task{
|
||||
expectedTask: taskmodel.Task{
|
||||
OrganizationID: 9000,
|
||||
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.CreateTaskFn = func(ctx context.Context, task influxdb.TaskCreate) (*influxdb.Task, error) {
|
||||
tmpTsk := influxdb.Task{
|
||||
svc.CreateTaskFn = func(ctx context.Context, task taskmodel.TaskCreate) (*taskmodel.Task, error) {
|
||||
tmpTsk := taskmodel.Task{
|
||||
Type: task.Type,
|
||||
OrganizationID: task.OrganizationID,
|
||||
Organization: task.Organization,
|
||||
|
|
|
@ -14,8 +14,6 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
platform2 "github.com/influxdata/influxdb/v2/kit/platform"
|
||||
|
||||
"github.com/influxdata/flux"
|
||||
"github.com/influxdata/flux/dependencies/testing"
|
||||
platform "github.com/influxdata/influxdb/v2"
|
||||
|
@ -36,6 +34,7 @@ import (
|
|||
"github.com/influxdata/influxdb/v2/kit/feature"
|
||||
overrideflagger "github.com/influxdata/influxdb/v2/kit/feature/override"
|
||||
"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/tracing"
|
||||
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/middleware"
|
||||
"github.com/influxdata/influxdb/v2/task/backend/scheduler"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
telegrafservice "github.com/influxdata/influxdb/v2/telegraf/service"
|
||||
"github.com/influxdata/influxdb/v2/telemetry"
|
||||
"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"
|
||||
iqlcoordinator "github.com/influxdata/influxdb/v2/v1/coordinator"
|
||||
"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()...)
|
||||
|
||||
var storageQueryService = readservice.NewProxyQueryService(m.queryController)
|
||||
var taskSvc platform.TaskService
|
||||
var taskSvc taskmodel.TaskService
|
||||
{
|
||||
// create the task stack
|
||||
combinedTaskService := taskbackend.NewAnalyticalStorage(
|
||||
|
@ -1137,7 +1141,7 @@ func (m *Launcher) SecretService() platform.SecretService {
|
|||
}
|
||||
|
||||
// TaskService returns the internal task service.
|
||||
func (m *Launcher) TaskService() platform.TaskService {
|
||||
func (m *Launcher) TaskService() taskmodel.TaskService {
|
||||
return m.apibackend.TaskService
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ import (
|
|||
"github.com/influxdata/influxdb/v2/pkger"
|
||||
"github.com/influxdata/influxdb/v2/query"
|
||||
"github.com/influxdata/influxdb/v2/restore"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
"github.com/influxdata/influxdb/v2/tenant"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
"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)}
|
||||
}
|
||||
|
||||
func (tl *TestLauncher) TaskServiceKV(tb testing.TB) influxdb.TaskService {
|
||||
func (tl *TestLauncher) TaskServiceKV(tb testing.TB) taskmodel.TaskService {
|
||||
return tl.kvService
|
||||
}
|
||||
|
||||
|
@ -467,7 +468,7 @@ func (tl *TestLauncher) AuthorizationService(tb testing.TB) *http.AuthorizationS
|
|||
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()
|
||||
return &http.TaskService{Client: tl.HTTPClient(tb)}
|
||||
}
|
||||
|
|
|
@ -12,16 +12,16 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
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/notification"
|
||||
"github.com/influxdata/influxdb/v2/notification/check"
|
||||
"github.com/influxdata/influxdb/v2/notification/endpoint"
|
||||
"github.com/influxdata/influxdb/v2/notification/rule"
|
||||
"github.com/influxdata/influxdb/v2/pkger"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/zap"
|
||||
|
@ -220,7 +220,7 @@ func TestLauncher_Pkger(t *testing.T) {
|
|||
}
|
||||
|
||||
newTaskObject := func(pkgName, name, description string) pkger.Object {
|
||||
obj := pkger.TaskToObject("", influxdb.Task{
|
||||
obj := pkger.TaskToObject("", taskmodel.Task{
|
||||
Name: name,
|
||||
Description: description,
|
||||
Flux: "buckets()",
|
||||
|
@ -2359,7 +2359,7 @@ func TestLauncher_Pkger(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
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,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
@ -2948,7 +2948,7 @@ spec:
|
|||
assert.NotZero(t, endpoints[0].NotificationEndpoint.GetID())
|
||||
assert.Equal(t, "no auth endpoint", endpoints[0].NotificationEndpoint.GetName())
|
||||
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")
|
||||
|
||||
require.Len(t, sum1.NotificationRules, 1)
|
||||
|
@ -3080,7 +3080,7 @@ spec:
|
|||
require.Len(t, endpoints, 1)
|
||||
assert.Equal(t, "no auth endpoint", endpoints[0].NotificationEndpoint.GetName())
|
||||
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")
|
||||
|
||||
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))
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
taskSVC := r.tl.TaskService(t)
|
||||
|
||||
var (
|
||||
task *influxdb.Task
|
||||
task *taskmodel.Task
|
||||
err error
|
||||
)
|
||||
switch opt := getOpt(); {
|
||||
case opt.name != "":
|
||||
tasks, _, err := taskSVC.FindTasks(ctx, influxdb.TaskFilter{
|
||||
tasks, _, err := taskSVC.FindTasks(ctx, taskmodel.TaskFilter{
|
||||
Name: &opt.name,
|
||||
OrganizationID: &r.tl.Org.ID,
|
||||
})
|
||||
if err != nil {
|
||||
return influxdb.Task{}, err
|
||||
return taskmodel.Task{}, err
|
||||
}
|
||||
for _, tt := range tasks {
|
||||
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")
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
func (r resourceChecker) mustGetTask(t *testing.T, getOpt getResourceOptFn) influxdb.Task {
|
||||
func (r resourceChecker) mustGetTask(t *testing.T, getOpt getResourceOptFn) taskmodel.Task {
|
||||
t.Helper()
|
||||
|
||||
task, err := r.getTask(t, getOpt)
|
||||
|
|
|
@ -4,8 +4,7 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform/errors"
|
||||
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -39,7 +38,7 @@ func ErrOrgNotFound(org string) error {
|
|||
return &errors.Error{
|
||||
Code: errors.ENotFound,
|
||||
Msg: fmt.Sprintf("invalid org %q", org),
|
||||
Err: influxdb.ErrOrgNotFound,
|
||||
Err: taskmodel.ErrOrgNotFound,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,9 +4,6 @@ import (
|
|||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
"github.com/influxdata/influxdb/v2/kit/platform/errors"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/influxdata/httprouter"
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
|
@ -16,10 +13,14 @@ import (
|
|||
"github.com/influxdata/influxdb/v2/http/metric"
|
||||
"github.com/influxdata/influxdb/v2/influxql"
|
||||
"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"
|
||||
kithttp "github.com/influxdata/influxdb/v2/kit/transport/http"
|
||||
"github.com/influxdata/influxdb/v2/query"
|
||||
"github.com/influxdata/influxdb/v2/query/fluxlang"
|
||||
"github.com/influxdata/influxdb/v2/storage"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
@ -85,8 +86,8 @@ type APIBackend struct {
|
|||
InfluxQLService query.ProxyQueryService
|
||||
InfluxqldService influxql.ProxyQueryService
|
||||
FluxService query.ProxyQueryService
|
||||
FluxLanguageService influxdb.FluxLanguageService
|
||||
TaskService influxdb.TaskService
|
||||
FluxLanguageService fluxlang.FluxLanguageService
|
||||
TaskService taskmodel.TaskService
|
||||
CheckService influxdb.CheckService
|
||||
TelegrafService influxdb.TelegrafConfigStore
|
||||
ScraperTargetStoreService influxdb.ScraperTargetStoreService
|
||||
|
|
|
@ -9,15 +9,16 @@ import (
|
|||
"path"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
"github.com/influxdata/influxdb/v2/kit/platform/errors"
|
||||
|
||||
"github.com/influxdata/httprouter"
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
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/notification/check"
|
||||
"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"
|
||||
)
|
||||
|
||||
|
@ -28,13 +29,13 @@ type CheckBackend struct {
|
|||
log *zap.Logger
|
||||
|
||||
AlgoWProxy FeatureProxyHandler
|
||||
TaskService influxdb.TaskService
|
||||
TaskService taskmodel.TaskService
|
||||
CheckService influxdb.CheckService
|
||||
UserResourceMappingService influxdb.UserResourceMappingService
|
||||
LabelService influxdb.LabelService
|
||||
UserService influxdb.UserService
|
||||
OrganizationService influxdb.OrganizationService
|
||||
FluxLanguageService influxdb.FluxLanguageService
|
||||
FluxLanguageService fluxlang.FluxLanguageService
|
||||
}
|
||||
|
||||
// NewCheckBackend returns a new instance of CheckBackend.
|
||||
|
@ -59,13 +60,13 @@ type CheckHandler struct {
|
|||
errors.HTTPErrorHandler
|
||||
log *zap.Logger
|
||||
|
||||
TaskService influxdb.TaskService
|
||||
TaskService taskmodel.TaskService
|
||||
CheckService influxdb.CheckService
|
||||
UserResourceMappingService influxdb.UserResourceMappingService
|
||||
LabelService influxdb.LabelService
|
||||
UserService influxdb.UserService
|
||||
OrganizationService influxdb.OrganizationService
|
||||
FluxLanguageService influxdb.FluxLanguageService
|
||||
FluxLanguageService fluxlang.FluxLanguageService
|
||||
}
|
||||
|
||||
const (
|
||||
|
@ -441,7 +442,7 @@ func decodePostCheckRequest(r *http.Request) (postCheckRequest, error) {
|
|||
}, 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)
|
||||
id := params.ByName("id")
|
||||
if id == "" {
|
||||
|
|
|
@ -11,19 +11,19 @@ import (
|
|||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
"github.com/influxdata/influxdb/v2/kit/platform/errors"
|
||||
|
||||
"github.com/influxdata/flux/parser"
|
||||
"github.com/influxdata/httprouter"
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
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"
|
||||
"github.com/influxdata/influxdb/v2/mock"
|
||||
"github.com/influxdata/influxdb/v2/notification"
|
||||
"github.com/influxdata/influxdb/v2/notification/check"
|
||||
"github.com/influxdata/influxdb/v2/pkg/testttp"
|
||||
"github.com/influxdata/influxdb/v2/query/fluxlang"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
influxTesting "github.com/influxdata/influxdb/v2/testing"
|
||||
"go.uber.org/zap/zaptest"
|
||||
)
|
||||
|
@ -284,8 +284,8 @@ func TestService_handleGetChecks(t *testing.T) {
|
|||
checkBackend.CheckService = tt.fields.CheckService
|
||||
checkBackend.LabelService = tt.fields.LabelService
|
||||
checkBackend.TaskService = &mock.TaskService{
|
||||
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*influxdb.Task, error) {
|
||||
return &influxdb.Task{Status: "active"}, nil
|
||||
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*taskmodel.Task, error) {
|
||||
return &taskmodel.Task{Status: "active"}, nil
|
||||
},
|
||||
}
|
||||
h := NewCheckHandler(zaptest.NewLogger(t), checkBackend)
|
||||
|
@ -426,8 +426,8 @@ func TestService_handleGetCheckQuery(t *testing.T) {
|
|||
checkBackend.HTTPErrorHandler = kithttp.ErrorHandler(0)
|
||||
checkBackend.CheckService = tt.fields.CheckService
|
||||
checkBackend.TaskService = &mock.TaskService{
|
||||
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*influxdb.Task, error) {
|
||||
return &influxdb.Task{}, nil
|
||||
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*taskmodel.Task, error) {
|
||||
return &taskmodel.Task{}, nil
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -567,8 +567,8 @@ func TestService_handleGetCheck(t *testing.T) {
|
|||
checkBackend.HTTPErrorHandler = kithttp.ErrorHandler(0)
|
||||
checkBackend.CheckService = tt.fields.CheckService
|
||||
checkBackend.TaskService = &mock.TaskService{
|
||||
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*influxdb.Task, error) {
|
||||
return &influxdb.Task{Status: "active"}, nil
|
||||
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*taskmodel.Task, error) {
|
||||
return &taskmodel.Task{Status: "active"}, nil
|
||||
},
|
||||
}
|
||||
h := NewCheckHandler(zaptest.NewLogger(t), checkBackend)
|
||||
|
@ -734,8 +734,8 @@ func TestService_handlePostCheck(t *testing.T) {
|
|||
checkBackend.CheckService = tt.fields.CheckService
|
||||
checkBackend.OrganizationService = tt.fields.OrganizationService
|
||||
checkBackend.TaskService = &mock.TaskService{
|
||||
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*influxdb.Task, error) {
|
||||
return &influxdb.Task{Status: "active"}, nil
|
||||
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*taskmodel.Task, error) {
|
||||
return &taskmodel.Task{Status: "active"}, nil
|
||||
},
|
||||
}
|
||||
h := NewCheckHandler(zaptest.NewLogger(t), checkBackend)
|
||||
|
@ -837,8 +837,8 @@ func TestService_handleDeleteCheck(t *testing.T) {
|
|||
checkBackend.HTTPErrorHandler = kithttp.ErrorHandler(0)
|
||||
checkBackend.CheckService = tt.fields.CheckService
|
||||
checkBackend.TaskService = &mock.TaskService{
|
||||
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*influxdb.Task, error) {
|
||||
return &influxdb.Task{}, nil
|
||||
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*taskmodel.Task, error) {
|
||||
return &taskmodel.Task{}, nil
|
||||
},
|
||||
}
|
||||
h := NewCheckHandler(zaptest.NewLogger(t), checkBackend)
|
||||
|
@ -1003,8 +1003,8 @@ func TestService_handlePatchCheck(t *testing.T) {
|
|||
checkBackend.HTTPErrorHandler = kithttp.ErrorHandler(0)
|
||||
checkBackend.CheckService = tt.fields.CheckService
|
||||
checkBackend.TaskService = &mock.TaskService{
|
||||
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*influxdb.Task, error) {
|
||||
return &influxdb.Task{Status: "active"}, nil
|
||||
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*taskmodel.Task, error) {
|
||||
return &taskmodel.Task{Status: "active"}, nil
|
||||
},
|
||||
}
|
||||
h := NewCheckHandler(zaptest.NewLogger(t), checkBackend)
|
||||
|
@ -1197,8 +1197,8 @@ func TestService_handleUpdateCheck(t *testing.T) {
|
|||
checkBackend.HTTPErrorHandler = kithttp.ErrorHandler(0)
|
||||
checkBackend.CheckService = tt.fields.CheckService
|
||||
checkBackend.TaskService = &mock.TaskService{
|
||||
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*influxdb.Task, error) {
|
||||
return &influxdb.Task{Status: "active"}, nil
|
||||
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*taskmodel.Task, error) {
|
||||
return &taskmodel.Task{Status: "active"}, nil
|
||||
},
|
||||
}
|
||||
h := NewCheckHandler(zaptest.NewLogger(t), checkBackend)
|
||||
|
@ -1308,8 +1308,8 @@ func TestService_handlePostCheckMember(t *testing.T) {
|
|||
checkBackend := NewMockCheckBackend(t)
|
||||
checkBackend.UserService = tt.fields.UserService
|
||||
checkBackend.TaskService = &mock.TaskService{
|
||||
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*influxdb.Task, error) {
|
||||
return &influxdb.Task{}, nil
|
||||
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*taskmodel.Task, error) {
|
||||
return &taskmodel.Task{}, nil
|
||||
},
|
||||
}
|
||||
h := NewCheckHandler(zaptest.NewLogger(t), checkBackend)
|
||||
|
|
|
@ -9,14 +9,14 @@ import (
|
|||
"path"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
"github.com/influxdata/influxdb/v2/kit/platform/errors"
|
||||
|
||||
"github.com/influxdata/httprouter"
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
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/pkg/httpc"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
@ -39,7 +39,7 @@ type NotificationRuleBackend struct {
|
|||
LabelService influxdb.LabelService
|
||||
UserService influxdb.UserService
|
||||
OrganizationService influxdb.OrganizationService
|
||||
TaskService influxdb.TaskService
|
||||
TaskService taskmodel.TaskService
|
||||
}
|
||||
|
||||
// NewNotificationRuleBackend returns a new instance of NotificationRuleBackend.
|
||||
|
@ -71,7 +71,7 @@ type NotificationRuleHandler struct {
|
|||
LabelService influxdb.LabelService
|
||||
UserService influxdb.UserService
|
||||
OrganizationService influxdb.OrganizationService
|
||||
TaskService influxdb.TaskService
|
||||
TaskService taskmodel.TaskService
|
||||
}
|
||||
|
||||
const (
|
||||
|
|
|
@ -5,12 +5,12 @@ import (
|
|||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
"github.com/influxdata/influxdb/v2/mock"
|
||||
"github.com/influxdata/influxdb/v2/notification"
|
||||
"github.com/influxdata/influxdb/v2/notification/rule"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
influxTesting "github.com/influxdata/influxdb/v2/testing"
|
||||
"go.uber.org/zap/zaptest"
|
||||
)
|
||||
|
@ -25,8 +25,8 @@ func NewMockNotificationRuleBackend(t *testing.T) *NotificationRuleBackend {
|
|||
UserService: mock.NewUserService(),
|
||||
OrganizationService: mock.NewOrganizationService(),
|
||||
TaskService: &mock.TaskService{
|
||||
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*influxdb.Task, error) {
|
||||
return &influxdb.Task{Status: "active"}, nil
|
||||
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*taskmodel.Task, error) {
|
||||
return &taskmodel.Task{Status: "active"}, nil
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
"github.com/influxdata/influxdb/v2"
|
||||
"github.com/influxdata/influxdb/v2/jsonweb"
|
||||
"github.com/influxdata/influxdb/v2/query"
|
||||
"github.com/influxdata/influxdb/v2/query/fluxlang"
|
||||
transpiler "github.com/influxdata/influxdb/v2/query/influxql"
|
||||
"github.com/influxdata/influxql"
|
||||
)
|
||||
|
@ -144,7 +145,7 @@ type queryParseError struct {
|
|||
|
||||
// Analyze attempts to parse the query request and returns any errors
|
||||
// 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 {
|
||||
case "flux":
|
||||
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)
|
||||
}
|
||||
|
||||
func (r QueryRequest) analyzeFluxQuery(l influxdb.FluxLanguageService) (*QueryAnalysis, error) {
|
||||
func (r QueryRequest) analyzeFluxQuery(l fluxlang.FluxLanguageService) (*QueryAnalysis, error) {
|
||||
a := &QueryAnalysis{}
|
||||
pkg, err := query.Parse(l, r.Query)
|
||||
if pkg == nil {
|
||||
|
|
|
@ -12,9 +12,6 @@ import (
|
|||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
errors2 "github.com/influxdata/influxdb/v2/kit/platform/errors"
|
||||
|
||||
"github.com/NYTimes/gziphandler"
|
||||
"github.com/influxdata/flux"
|
||||
"github.com/influxdata/flux/ast"
|
||||
|
@ -26,10 +23,13 @@ import (
|
|||
"github.com/influxdata/influxdb/v2/http/metric"
|
||||
"github.com/influxdata/influxdb/v2/kit/check"
|
||||
"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"
|
||||
kithttp "github.com/influxdata/influxdb/v2/kit/transport/http"
|
||||
"github.com/influxdata/influxdb/v2/logger"
|
||||
"github.com/influxdata/influxdb/v2/query"
|
||||
"github.com/influxdata/influxdb/v2/query/fluxlang"
|
||||
"github.com/influxdata/influxdb/v2/query/influxql"
|
||||
"github.com/pkg/errors"
|
||||
prom "github.com/prometheus/client_golang/prometheus"
|
||||
|
@ -51,7 +51,7 @@ type FluxBackend struct {
|
|||
AlgoWProxy FeatureProxyHandler
|
||||
OrganizationService influxdb.OrganizationService
|
||||
ProxyQueryService query.ProxyQueryService
|
||||
FluxLanguageService influxdb.FluxLanguageService
|
||||
FluxLanguageService fluxlang.FluxLanguageService
|
||||
Flagger feature.Flagger
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ type FluxHandler struct {
|
|||
Now func() time.Time
|
||||
OrganizationService influxdb.OrganizationService
|
||||
ProxyQueryService query.ProxyQueryService
|
||||
FluxLanguageService influxdb.FluxLanguageService
|
||||
FluxLanguageService fluxlang.FluxLanguageService
|
||||
|
||||
EventRecorder metric.EventRecorder
|
||||
|
||||
|
|
|
@ -11,16 +11,16 @@ import (
|
|||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
errors2 "github.com/influxdata/influxdb/v2/kit/platform/errors"
|
||||
|
||||
"github.com/influxdata/httprouter"
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
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/kv"
|
||||
"github.com/influxdata/influxdb/v2/pkg/httpc"
|
||||
"github.com/influxdata/influxdb/v2/task/options"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
@ -31,7 +31,7 @@ type TaskBackend struct {
|
|||
log *zap.Logger
|
||||
|
||||
AlgoWProxy FeatureProxyHandler
|
||||
TaskService influxdb.TaskService
|
||||
TaskService taskmodel.TaskService
|
||||
AuthorizationService influxdb.AuthorizationService
|
||||
OrganizationService influxdb.OrganizationService
|
||||
UserResourceMappingService influxdb.UserResourceMappingService
|
||||
|
@ -62,7 +62,7 @@ type TaskHandler struct {
|
|||
errors2.HTTPErrorHandler
|
||||
log *zap.Logger
|
||||
|
||||
TaskService influxdb.TaskService
|
||||
TaskService taskmodel.TaskService
|
||||
AuthorizationService influxdb.AuthorizationService
|
||||
OrganizationService influxdb.OrganizationService
|
||||
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
|
||||
func NewFrontEndTask(t influxdb.Task) Task {
|
||||
func NewFrontEndTask(t taskmodel.Task) Task {
|
||||
latestCompleted := ""
|
||||
if !t.LatestCompleted.IsZero() {
|
||||
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 (
|
||||
latestCompleted time.Time
|
||||
createdAt time.Time
|
||||
|
@ -251,7 +251,7 @@ func convertTask(t Task) *influxdb.Task {
|
|||
}
|
||||
}
|
||||
|
||||
return &influxdb.Task{
|
||||
return &taskmodel.Task{
|
||||
ID: t.ID,
|
||||
OrganizationID: t.OrganizationID,
|
||||
Organization: t.Organization,
|
||||
|
@ -308,7 +308,7 @@ func customParseDuration(d time.Duration) string {
|
|||
return str
|
||||
}
|
||||
|
||||
func newTaskResponse(t influxdb.Task, labels []*influxdb.Label) taskResponse {
|
||||
func newTaskResponse(t taskmodel.Task, labels []*influxdb.Label) taskResponse {
|
||||
response := taskResponse{
|
||||
Links: map[string]string{
|
||||
"self": fmt.Sprintf("/api/v2/tasks/%s", t.ID),
|
||||
|
@ -329,7 +329,7 @@ func newTaskResponse(t influxdb.Task, labels []*influxdb.Label) taskResponse {
|
|||
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
|
||||
u := url.URL{
|
||||
Path: basePath,
|
||||
|
@ -366,7 +366,7 @@ type tasksResponse struct {
|
|||
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{
|
||||
Links: newTasksPagingLinks(prefixTasks, ts, f),
|
||||
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
|
||||
// value for empty time values
|
||||
type httpRun struct {
|
||||
ID platform.ID `json:"id,omitempty"`
|
||||
TaskID platform.ID `json:"taskID"`
|
||||
Status string `json:"status"`
|
||||
ScheduledFor *time.Time `json:"scheduledFor"`
|
||||
StartedAt *time.Time `json:"startedAt,omitempty"`
|
||||
FinishedAt *time.Time `json:"finishedAt,omitempty"`
|
||||
RequestedAt *time.Time `json:"requestedAt,omitempty"`
|
||||
Log []influxdb.Log `json:"log,omitempty"`
|
||||
ID platform.ID `json:"id,omitempty"`
|
||||
TaskID platform.ID `json:"taskID"`
|
||||
Status string `json:"status"`
|
||||
ScheduledFor *time.Time `json:"scheduledFor"`
|
||||
StartedAt *time.Time `json:"startedAt,omitempty"`
|
||||
FinishedAt *time.Time `json:"finishedAt,omitempty"`
|
||||
RequestedAt *time.Time `json:"requestedAt,omitempty"`
|
||||
Log []taskmodel.Log `json:"log,omitempty"`
|
||||
}
|
||||
|
||||
func newRunResponse(r influxdb.Run) runResponse {
|
||||
func newRunResponse(r taskmodel.Run) runResponse {
|
||||
run := httpRun{
|
||||
ID: r.ID,
|
||||
TaskID: r.TaskID,
|
||||
|
@ -428,8 +428,8 @@ func newRunResponse(r influxdb.Run) runResponse {
|
|||
}
|
||||
}
|
||||
|
||||
func convertRun(r httpRun) *influxdb.Run {
|
||||
run := &influxdb.Run{
|
||||
func convertRun(r httpRun) *taskmodel.Run {
|
||||
run := &taskmodel.Run{
|
||||
ID: r.ID,
|
||||
TaskID: r.TaskID,
|
||||
Status: r.Status,
|
||||
|
@ -460,7 +460,7 @@ type runsResponse struct {
|
|||
Runs []*runResponse `json:"runs"`
|
||||
}
|
||||
|
||||
func newRunsResponse(rs []*influxdb.Run, taskID platform.ID) runsResponse {
|
||||
func newRunsResponse(rs []*taskmodel.Run, taskID platform.ID) runsResponse {
|
||||
r := runsResponse{
|
||||
Links: map[string]string{
|
||||
"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 {
|
||||
filter influxdb.TaskFilter
|
||||
filter taskmodel.TaskFilter
|
||||
}
|
||||
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
if lim < 1 || lim > influxdb.TaskMaxPageSize {
|
||||
if lim < 1 || lim > taskmodel.TaskMaxPageSize {
|
||||
return nil, &errors2.Error{
|
||||
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
|
||||
} else {
|
||||
req.filter.Limit = influxdb.TaskDefaultPageSize
|
||||
req.filter.Limit = taskmodel.TaskDefaultPageSize
|
||||
}
|
||||
|
||||
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.
|
||||
req.filter.Type = &influxdb.TaskSystemType
|
||||
req.filter.Type = &taskmodel.TaskSystemType
|
||||
|
||||
if name := qp.Get("name"); name != "" {
|
||||
req.filter.Name = &name
|
||||
|
@ -643,11 +643,11 @@ func (h *TaskHandler) handlePostTask(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
type postTaskRequest struct {
|
||||
TaskCreate influxdb.TaskCreate
|
||||
TaskCreate taskmodel.TaskCreate
|
||||
}
|
||||
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -659,7 +659,7 @@ func decodePostTaskRequest(ctx context.Context, r *http.Request) (*postTaskReque
|
|||
}
|
||||
tc.OwnerID = auth.GetUserID()
|
||||
// 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 {
|
||||
return nil, err
|
||||
|
@ -754,7 +754,7 @@ func (h *TaskHandler) handleUpdateTask(w http.ResponseWriter, r *http.Request) {
|
|||
Err: err,
|
||||
Msg: "failed to update task",
|
||||
}
|
||||
if err.Err == influxdb.ErrTaskNotFound {
|
||||
if err.Err == taskmodel.ErrTaskNotFound {
|
||||
err.Code = errors2.ENotFound
|
||||
}
|
||||
h.HandleHTTPError(ctx, err, w)
|
||||
|
@ -778,7 +778,7 @@ func (h *TaskHandler) handleUpdateTask(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
type updateTaskRequest struct {
|
||||
Update influxdb.TaskUpdate
|
||||
Update taskmodel.TaskUpdate
|
||||
TaskID platform.ID
|
||||
}
|
||||
|
||||
|
@ -797,7 +797,7 @@ func decodeUpdateTaskRequest(ctx context.Context, r *http.Request) (*updateTaskR
|
|||
return nil, err
|
||||
}
|
||||
|
||||
var upd influxdb.TaskUpdate
|
||||
var upd taskmodel.TaskUpdate
|
||||
if err := json.NewDecoder(r.Body).Decode(&upd); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -830,7 +830,7 @@ func (h *TaskHandler) handleDeleteTask(w http.ResponseWriter, r *http.Request) {
|
|||
Err: err,
|
||||
Msg: "failed to delete task",
|
||||
}
|
||||
if err.Err == influxdb.ErrTaskNotFound {
|
||||
if err.Err == taskmodel.ErrTaskNotFound {
|
||||
err.Code = errors2.ENotFound
|
||||
}
|
||||
h.HandleHTTPError(ctx, err, w)
|
||||
|
@ -907,7 +907,7 @@ func (h *TaskHandler) handleGetLogs(w http.ResponseWriter, r *http.Request) {
|
|||
Err: err,
|
||||
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
|
||||
}
|
||||
h.HandleHTTPError(ctx, err, w)
|
||||
|
@ -921,11 +921,11 @@ func (h *TaskHandler) handleGetLogs(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
type getLogsRequest struct {
|
||||
filter influxdb.LogFilter
|
||||
filter taskmodel.LogFilter
|
||||
}
|
||||
|
||||
type getLogsResponse struct {
|
||||
Events []*influxdb.Log `json:"events"`
|
||||
Events []*taskmodel.Log `json:"events"`
|
||||
}
|
||||
|
||||
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,
|
||||
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
|
||||
}
|
||||
h.HandleHTTPError(ctx, err, w)
|
||||
|
@ -1013,7 +1013,7 @@ func (h *TaskHandler) handleGetRuns(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
type getRunsRequest struct {
|
||||
filter influxdb.RunFilter
|
||||
filter taskmodel.RunFilter
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
if i < 1 || i > influxdb.TaskMaxPageSize {
|
||||
return nil, influxdb.ErrOutOfBoundsLimit
|
||||
if i < 1 || i > taskmodel.TaskMaxPageSize {
|
||||
return nil, taskmodel.ErrOutOfBoundsLimit
|
||||
}
|
||||
req.filter.Limit = i
|
||||
}
|
||||
|
@ -1103,7 +1103,7 @@ func (h *TaskHandler) handleForceRun(w http.ResponseWriter, r *http.Request) {
|
|||
Err: err,
|
||||
Msg: "failed to force run",
|
||||
}
|
||||
if err.Err == influxdb.ErrTaskNotFound {
|
||||
if err.Err == taskmodel.ErrTaskNotFound {
|
||||
err.Code = errors2.ENotFound
|
||||
}
|
||||
h.HandleHTTPError(ctx, err, w)
|
||||
|
@ -1205,7 +1205,7 @@ func (h *TaskHandler) handleGetRun(w http.ResponseWriter, r *http.Request) {
|
|||
Err: err,
|
||||
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
|
||||
}
|
||||
h.HandleHTTPError(ctx, err, w)
|
||||
|
@ -1311,7 +1311,7 @@ func (h *TaskHandler) handleCancelRun(w http.ResponseWriter, r *http.Request) {
|
|||
Err: err,
|
||||
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
|
||||
}
|
||||
h.HandleHTTPError(ctx, err, w)
|
||||
|
@ -1362,7 +1362,7 @@ func (h *TaskHandler) handleRetryRun(w http.ResponseWriter, r *http.Request) {
|
|||
Err: err,
|
||||
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
|
||||
}
|
||||
h.HandleHTTPError(ctx, err, w)
|
||||
|
@ -1409,7 +1409,7 @@ func decodeRetryRunRequest(ctx context.Context, r *http.Request) (*retryRunReque
|
|||
}, 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 != "" {
|
||||
return nil
|
||||
}
|
||||
|
@ -1466,7 +1466,7 @@ type TaskService struct {
|
|||
}
|
||||
|
||||
// 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)
|
||||
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
|
||||
// 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)
|
||||
defer span.Finish()
|
||||
|
||||
|
@ -1522,7 +1522,7 @@ func (t TaskService) FindTasks(ctx context.Context, filter influxdb.TaskFilter)
|
|||
return nil, 0, err
|
||||
}
|
||||
|
||||
tasks := make([]*influxdb.Task, len(tr.Tasks))
|
||||
tasks := make([]*taskmodel.Task, len(tr.Tasks))
|
||||
for i := range tr.Tasks {
|
||||
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.
|
||||
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)
|
||||
defer span.Finish()
|
||||
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.
|
||||
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)
|
||||
defer span.Finish()
|
||||
|
||||
|
@ -1573,7 +1573,7 @@ func (t TaskService) DeleteTask(ctx context.Context, id platform.ID) error {
|
|||
}
|
||||
|
||||
// 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)
|
||||
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.
|
||||
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)
|
||||
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()})
|
||||
}
|
||||
|
||||
if filter.Limit < 0 || filter.Limit > influxdb.TaskMaxPageSize {
|
||||
return nil, 0, influxdb.ErrOutOfBoundsLimit
|
||||
if filter.Limit < 0 || filter.Limit > taskmodel.TaskMaxPageSize {
|
||||
return nil, 0, taskmodel.ErrOutOfBoundsLimit
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
runs := make([]*influxdb.Run, len(rs.Runs))
|
||||
runs := make([]*taskmodel.Run, len(rs.Runs))
|
||||
for i := range rs.Runs {
|
||||
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.
|
||||
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)
|
||||
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,
|
||||
// so return that actual error instead of a different error that looks like it.
|
||||
// TODO cleanup backend error implementation
|
||||
return nil, influxdb.ErrRunNotFound
|
||||
return nil, taskmodel.ErrRunNotFound
|
||||
}
|
||||
|
||||
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).
|
||||
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)
|
||||
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,
|
||||
// so return that actual error instead of a different error that looks like it.
|
||||
// TODO cleanup backend task error implementation
|
||||
return nil, influxdb.ErrRunNotFound
|
||||
return nil, taskmodel.ErrRunNotFound
|
||||
}
|
||||
// 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
|
||||
}
|
||||
|
||||
|
@ -1695,7 +1695,7 @@ func (t TaskService) RetryRun(ctx context.Context, taskID, runID platform.ID) (*
|
|||
}
|
||||
|
||||
// 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)
|
||||
defer span.Finish()
|
||||
|
||||
|
@ -1714,11 +1714,11 @@ func (t TaskService) ForceRun(ctx context.Context, taskID platform.ID, scheduled
|
|||
if errors2.ErrorCode(err) == errors2.ENotFound {
|
||||
// ErrRunNotFound is expected as part of the RetryRun contract,
|
||||
// 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.
|
||||
if e := influxdb.ParseRequestStillQueuedError(err.Error()); e != nil {
|
||||
if e := taskmodel.ParseRequestStillQueuedError(err.Error()); e != nil {
|
||||
return nil, *e
|
||||
}
|
||||
|
||||
|
|
|
@ -13,17 +13,17 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
errors2 "github.com/influxdata/influxdb/v2/kit/platform/errors"
|
||||
|
||||
"github.com/influxdata/httprouter"
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
"github.com/influxdata/influxdb/v2/authorization"
|
||||
pcontext "github.com/influxdata/influxdb/v2/context"
|
||||
_ "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"
|
||||
"github.com/influxdata/influxdb/v2/label"
|
||||
"github.com/influxdata/influxdb/v2/mock"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
"github.com/influxdata/influxdb/v2/tenant"
|
||||
influxdbtesting "github.com/influxdata/influxdb/v2/testing"
|
||||
"go.uber.org/zap"
|
||||
|
@ -73,7 +73,7 @@ func NewMockTaskBackend(t *testing.T) *TaskBackend {
|
|||
|
||||
func TestTaskHandler_handleGetTasks(t *testing.T) {
|
||||
type fields struct {
|
||||
taskService influxdb.TaskService
|
||||
taskService taskmodel.TaskService
|
||||
labelService influxdb.LabelService
|
||||
}
|
||||
type wants struct {
|
||||
|
@ -92,8 +92,8 @@ func TestTaskHandler_handleGetTasks(t *testing.T) {
|
|||
name: "get tasks",
|
||||
fields: fields{
|
||||
taskService: &mock.TaskService{
|
||||
FindTasksFn: func(ctx context.Context, f influxdb.TaskFilter) ([]*influxdb.Task, int, error) {
|
||||
tasks := []*influxdb.Task{
|
||||
FindTasksFn: func(ctx context.Context, f taskmodel.TaskFilter) ([]*taskmodel.Task, int, error) {
|
||||
tasks := []*taskmodel.Task{
|
||||
{
|
||||
ID: 1,
|
||||
Name: "task1",
|
||||
|
@ -199,8 +199,8 @@ func TestTaskHandler_handleGetTasks(t *testing.T) {
|
|||
getParams: "after=0000000000000001&limit=1",
|
||||
fields: fields{
|
||||
taskService: &mock.TaskService{
|
||||
FindTasksFn: func(ctx context.Context, f influxdb.TaskFilter) ([]*influxdb.Task, int, error) {
|
||||
tasks := []*influxdb.Task{
|
||||
FindTasksFn: func(ctx context.Context, f taskmodel.TaskFilter) ([]*taskmodel.Task, int, error) {
|
||||
tasks := []*taskmodel.Task{
|
||||
{
|
||||
ID: 2,
|
||||
Name: "task2",
|
||||
|
@ -272,8 +272,8 @@ func TestTaskHandler_handleGetTasks(t *testing.T) {
|
|||
getParams: "org=test2",
|
||||
fields: fields{
|
||||
taskService: &mock.TaskService{
|
||||
FindTasksFn: func(ctx context.Context, f influxdb.TaskFilter) ([]*influxdb.Task, int, error) {
|
||||
tasks := []*influxdb.Task{
|
||||
FindTasksFn: func(ctx context.Context, f taskmodel.TaskFilter) ([]*taskmodel.Task, int, error) {
|
||||
tasks := []*taskmodel.Task{
|
||||
{
|
||||
ID: 2,
|
||||
Name: "task2",
|
||||
|
@ -344,8 +344,8 @@ func TestTaskHandler_handleGetTasks(t *testing.T) {
|
|||
getParams: "org=non-existent-org",
|
||||
fields: fields{
|
||||
taskService: &mock.TaskService{
|
||||
FindTasksFn: func(ctx context.Context, f influxdb.TaskFilter) ([]*influxdb.Task, int, error) {
|
||||
tasks := []*influxdb.Task{
|
||||
FindTasksFn: func(ctx context.Context, f taskmodel.TaskFilter) ([]*taskmodel.Task, int, error) {
|
||||
tasks := []*taskmodel.Task{
|
||||
{
|
||||
ID: 1,
|
||||
Name: "task1",
|
||||
|
@ -425,10 +425,10 @@ func TestTaskHandler_handleGetTasks(t *testing.T) {
|
|||
|
||||
func TestTaskHandler_handlePostTasks(t *testing.T) {
|
||||
type args struct {
|
||||
taskCreate influxdb.TaskCreate
|
||||
taskCreate taskmodel.TaskCreate
|
||||
}
|
||||
type fields struct {
|
||||
taskService influxdb.TaskService
|
||||
taskService taskmodel.TaskService
|
||||
}
|
||||
type wants struct {
|
||||
statusCode int
|
||||
|
@ -445,15 +445,15 @@ func TestTaskHandler_handlePostTasks(t *testing.T) {
|
|||
{
|
||||
name: "create task",
|
||||
args: args{
|
||||
taskCreate: influxdb.TaskCreate{
|
||||
taskCreate: taskmodel.TaskCreate{
|
||||
OrganizationID: 1,
|
||||
Flux: "abc",
|
||||
},
|
||||
},
|
||||
fields: fields{
|
||||
taskService: &mock.TaskService{
|
||||
CreateTaskFn: func(ctx context.Context, tc influxdb.TaskCreate) (*influxdb.Task, error) {
|
||||
return &influxdb.Task{
|
||||
CreateTaskFn: func(ctx context.Context, tc taskmodel.TaskCreate) (*taskmodel.Task, error) {
|
||||
return &taskmodel.Task{
|
||||
ID: 1,
|
||||
Name: "task1",
|
||||
Description: "Brand New Task",
|
||||
|
@ -494,14 +494,14 @@ func TestTaskHandler_handlePostTasks(t *testing.T) {
|
|||
{
|
||||
name: "create task - influxdb error creating task",
|
||||
args: args{
|
||||
taskCreate: influxdb.TaskCreate{
|
||||
taskCreate: taskmodel.TaskCreate{
|
||||
OrganizationID: 1,
|
||||
Flux: "abc",
|
||||
},
|
||||
},
|
||||
fields: fields{
|
||||
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(
|
||||
errors2.WithErrorErr(errors.New("something went wrong")),
|
||||
errors2.WithErrorMsg("something really went wrong"),
|
||||
|
@ -524,14 +524,14 @@ func TestTaskHandler_handlePostTasks(t *testing.T) {
|
|||
{
|
||||
name: "create task - error creating task",
|
||||
args: args{
|
||||
taskCreate: influxdb.TaskCreate{
|
||||
taskCreate: taskmodel.TaskCreate{
|
||||
OrganizationID: 1,
|
||||
Flux: "abc",
|
||||
},
|
||||
},
|
||||
fields: fields{
|
||||
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")
|
||||
},
|
||||
},
|
||||
|
@ -591,7 +591,7 @@ func TestTaskHandler_handlePostTasks(t *testing.T) {
|
|||
|
||||
func TestTaskHandler_handleGetRun(t *testing.T) {
|
||||
type fields struct {
|
||||
taskService influxdb.TaskService
|
||||
taskService taskmodel.TaskService
|
||||
}
|
||||
type args struct {
|
||||
taskID platform.ID
|
||||
|
@ -613,12 +613,12 @@ func TestTaskHandler_handleGetRun(t *testing.T) {
|
|||
name: "get a run by id",
|
||||
fields: fields{
|
||||
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")
|
||||
startedAt, _ := time.Parse(time.RFC3339Nano, "2018-12-01T17:00:03.155645Z")
|
||||
finishedAt, _ := time.Parse(time.RFC3339Nano, "2018-12-01T17:00:13.155645Z")
|
||||
requestedAt, _ := time.Parse(time.RFC3339, "2018-12-01T17:00:13Z")
|
||||
run := influxdb.Run{
|
||||
run := taskmodel.Run{
|
||||
ID: runID,
|
||||
TaskID: taskID,
|
||||
Status: "success",
|
||||
|
@ -705,7 +705,7 @@ func TestTaskHandler_handleGetRun(t *testing.T) {
|
|||
|
||||
func TestTaskHandler_handleGetRuns(t *testing.T) {
|
||||
type fields struct {
|
||||
taskService influxdb.TaskService
|
||||
taskService taskmodel.TaskService
|
||||
}
|
||||
type args struct {
|
||||
taskID platform.ID
|
||||
|
@ -726,12 +726,12 @@ func TestTaskHandler_handleGetRuns(t *testing.T) {
|
|||
name: "get runs by task id",
|
||||
fields: fields{
|
||||
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")
|
||||
startedAt, _ := time.Parse(time.RFC3339Nano, "2018-12-01T17:00:03.155645Z")
|
||||
finishedAt, _ := time.Parse(time.RFC3339Nano, "2018-12-01T17:00:13.155645Z")
|
||||
requestedAt, _ := time.Parse(time.RFC3339, "2018-12-01T17:00:13Z")
|
||||
runs := []*influxdb.Run{
|
||||
runs := []*taskmodel.Run{
|
||||
{
|
||||
ID: platform.ID(2),
|
||||
TaskID: f.Task,
|
||||
|
@ -875,12 +875,12 @@ func TestTaskHandler_NotFoundStatus(t *testing.T) {
|
|||
{
|
||||
name: "get task",
|
||||
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 {
|
||||
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,
|
||||
|
@ -891,12 +891,12 @@ func TestTaskHandler_NotFoundStatus(t *testing.T) {
|
|||
{
|
||||
name: "update task",
|
||||
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 {
|
||||
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,
|
||||
|
@ -913,7 +913,7 @@ func TestTaskHandler_NotFoundStatus(t *testing.T) {
|
|||
return nil
|
||||
}
|
||||
|
||||
return influxdb.ErrTaskNotFound
|
||||
return taskmodel.ErrTaskNotFound
|
||||
},
|
||||
},
|
||||
method: http.MethodDelete,
|
||||
|
@ -924,12 +924,12 @@ func TestTaskHandler_NotFoundStatus(t *testing.T) {
|
|||
{
|
||||
name: "get task logs",
|
||||
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 {
|
||||
return nil, 0, nil
|
||||
}
|
||||
|
||||
return nil, 0, influxdb.ErrTaskNotFound
|
||||
return nil, 0, taskmodel.ErrTaskNotFound
|
||||
},
|
||||
},
|
||||
method: http.MethodGet,
|
||||
|
@ -940,12 +940,12 @@ func TestTaskHandler_NotFoundStatus(t *testing.T) {
|
|||
{
|
||||
name: "get run logs",
|
||||
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 {
|
||||
return nil, 0, influxdb.ErrTaskNotFound
|
||||
return nil, 0, taskmodel.ErrTaskNotFound
|
||||
}
|
||||
if *f.Run != runID {
|
||||
return nil, 0, influxdb.ErrNoRunsFound
|
||||
return nil, 0, taskmodel.ErrNoRunsFound
|
||||
}
|
||||
|
||||
return nil, 0, nil
|
||||
|
@ -959,9 +959,9 @@ func TestTaskHandler_NotFoundStatus(t *testing.T) {
|
|||
{
|
||||
name: "get runs: task not found",
|
||||
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 {
|
||||
return nil, 0, influxdb.ErrTaskNotFound
|
||||
return nil, 0, taskmodel.ErrTaskNotFound
|
||||
}
|
||||
|
||||
return nil, 0, nil
|
||||
|
@ -975,9 +975,9 @@ func TestTaskHandler_NotFoundStatus(t *testing.T) {
|
|||
{
|
||||
name: "get runs: task found but no runs found",
|
||||
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 {
|
||||
return nil, 0, influxdb.ErrNoRunsFound
|
||||
return nil, 0, taskmodel.ErrNoRunsFound
|
||||
}
|
||||
|
||||
return nil, 0, nil
|
||||
|
@ -991,12 +991,12 @@ func TestTaskHandler_NotFoundStatus(t *testing.T) {
|
|||
{
|
||||
name: "force run",
|
||||
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 {
|
||||
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,
|
||||
|
@ -1008,15 +1008,15 @@ func TestTaskHandler_NotFoundStatus(t *testing.T) {
|
|||
{
|
||||
name: "get run",
|
||||
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 {
|
||||
return nil, influxdb.ErrTaskNotFound
|
||||
return nil, taskmodel.ErrTaskNotFound
|
||||
}
|
||||
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,
|
||||
|
@ -1027,15 +1027,15 @@ func TestTaskHandler_NotFoundStatus(t *testing.T) {
|
|||
{
|
||||
name: "retry run",
|
||||
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 {
|
||||
return nil, influxdb.ErrTaskNotFound
|
||||
return nil, taskmodel.ErrTaskNotFound
|
||||
}
|
||||
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,
|
||||
|
@ -1048,10 +1048,10 @@ func TestTaskHandler_NotFoundStatus(t *testing.T) {
|
|||
svc: &mock.TaskService{
|
||||
CancelRunFn: func(_ context.Context, tid, rid platform.ID) error {
|
||||
if tid != taskID {
|
||||
return influxdb.ErrTaskNotFound
|
||||
return taskmodel.ErrTaskNotFound
|
||||
}
|
||||
if rid != runID {
|
||||
return influxdb.ErrRunNotFound
|
||||
return taskmodel.ErrRunNotFound
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -1252,12 +1252,12 @@ func TestTaskHandler_CreateTaskWithOrgName(t *testing.T) {
|
|||
}
|
||||
|
||||
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 {
|
||||
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"
|
||||
|
||||
b, err := json.Marshal(influxdb.TaskCreate{
|
||||
b, err := json.Marshal(taskmodel.TaskCreate{
|
||||
Flux: script,
|
||||
Organization: o.Name,
|
||||
})
|
||||
|
@ -1305,7 +1305,7 @@ func TestTaskHandler_CreateTaskWithOrgName(t *testing.T) {
|
|||
}
|
||||
|
||||
// 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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -1399,23 +1399,23 @@ func TestTaskHandler_Sessions(t *testing.T) {
|
|||
|
||||
var findRunsCtx context.Context
|
||||
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
|
||||
if f.Task != taskID {
|
||||
t.Fatalf("expected task ID %v, got %v", taskID, f.Task)
|
||||
}
|
||||
|
||||
return []*influxdb.Run{
|
||||
return []*taskmodel.Run{
|
||||
{ID: runID, TaskID: taskID},
|
||||
}, 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 {
|
||||
return nil, influxdb.ErrTaskNotFound
|
||||
return nil, taskmodel.ErrTaskNotFound
|
||||
}
|
||||
|
||||
return &influxdb.Task{
|
||||
return &taskmodel.Task{
|
||||
ID: taskID,
|
||||
OrganizationID: o.ID,
|
||||
}, nil
|
||||
|
@ -1491,7 +1491,7 @@ func TestTaskHandler_Sessions(t *testing.T) {
|
|||
|
||||
var findRunByIDCtx context.Context
|
||||
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
|
||||
if tid != taskID {
|
||||
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)
|
||||
}
|
||||
|
||||
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 {
|
||||
return nil, influxdb.ErrTaskNotFound
|
||||
return nil, taskmodel.ErrTaskNotFound
|
||||
}
|
||||
|
||||
return &influxdb.Task{
|
||||
return &taskmodel.Task{
|
||||
ID: taskID,
|
||||
OrganizationID: o.ID,
|
||||
}, nil
|
||||
|
@ -1585,7 +1585,7 @@ func TestTaskHandler_Sessions(t *testing.T) {
|
|||
|
||||
var findLogsCtx context.Context
|
||||
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
|
||||
if f.Task != taskID {
|
||||
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)
|
||||
}
|
||||
|
||||
line := influxdb.Log{Time: "time", Message: "a log line"}
|
||||
return []*influxdb.Log{&line}, 1, nil
|
||||
line := taskmodel.Log{Time: "time", Message: "a log line"}
|
||||
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 {
|
||||
return nil, influxdb.ErrTaskNotFound
|
||||
return nil, taskmodel.ErrTaskNotFound
|
||||
}
|
||||
|
||||
return &influxdb.Task{
|
||||
return &taskmodel.Task{
|
||||
ID: taskID,
|
||||
OrganizationID: o.ID,
|
||||
}, nil
|
||||
|
@ -1680,7 +1680,7 @@ func TestTaskHandler_Sessions(t *testing.T) {
|
|||
|
||||
var retryRunCtx context.Context
|
||||
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
|
||||
if tid != taskID {
|
||||
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)
|
||||
}
|
||||
|
||||
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 {
|
||||
return nil, influxdb.ErrTaskNotFound
|
||||
return nil, taskmodel.ErrTaskNotFound
|
||||
}
|
||||
|
||||
return &influxdb.Task{
|
||||
return &taskmodel.Task{
|
||||
ID: taskID,
|
||||
OrganizationID: o.ID,
|
||||
}, nil
|
||||
|
|
|
@ -4,10 +4,10 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
|
||||
"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"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
)
|
||||
|
||||
// Resolver is a type which combines multiple resource services
|
||||
|
@ -32,7 +32,7 @@ type Resolver struct {
|
|||
FindSourceByID(context.Context, platform.ID) (*influxdb.Source, error)
|
||||
}
|
||||
TaskFinder interface {
|
||||
FindTaskByID(context.Context, platform.ID) (*influxdb.Task, error)
|
||||
FindTaskByID(context.Context, platform.ID) (*taskmodel.Task, error)
|
||||
}
|
||||
TelegrafConfigFinder interface {
|
||||
FindTelegrafConfigByID(context.Context, platform.ID) (*influxdb.TelegrafConfig, error)
|
||||
|
|
|
@ -5,11 +5,11 @@ import (
|
|||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"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"
|
||||
"github.com/influxdata/influxdb/v2/kv"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
)
|
||||
|
||||
var taskBucket = []byte("tasksv1")
|
||||
|
@ -18,23 +18,23 @@ var taskBucket = []byte("tasksv1")
|
|||
var Migration0003_TaskOwnerIDUpMigration = UpOnlyMigration(
|
||||
"migrate task owner id",
|
||||
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.
|
||||
err := store.View(ctx, func(tx kv.Tx) error {
|
||||
taskBucket, err := tx.Bucket(taskBucket)
|
||||
if err != nil {
|
||||
return influxdb.ErrUnexpectedTaskBucketErr(err)
|
||||
return taskmodel.ErrUnexpectedTaskBucketErr(err)
|
||||
}
|
||||
|
||||
c, err := taskBucket.ForwardCursor([]byte{})
|
||||
if err != nil {
|
||||
return influxdb.ErrUnexpectedTaskBucketErr(err)
|
||||
return taskmodel.ErrUnexpectedTaskBucketErr(err)
|
||||
}
|
||||
|
||||
for k, v := c.Next(); k != nil; k, v = c.Next() {
|
||||
kvTask := &kvTask{}
|
||||
if err := json.Unmarshal(v, kvTask); err != nil {
|
||||
return influxdb.ErrInternalTaskServiceError(err)
|
||||
return taskmodel.ErrInternalTaskServiceError(err)
|
||||
}
|
||||
|
||||
t := kvToInfluxTask(kvTask)
|
||||
|
@ -63,19 +63,19 @@ var Migration0003_TaskOwnerIDUpMigration = UpOnlyMigration(
|
|||
}
|
||||
b, err := tx.Bucket(taskBucket)
|
||||
if err != nil {
|
||||
return influxdb.ErrUnexpectedTaskBucketErr(err)
|
||||
return taskmodel.ErrUnexpectedTaskBucketErr(err)
|
||||
}
|
||||
|
||||
if !t.OwnerID.Valid() {
|
||||
v, err := b.Get(taskKey)
|
||||
if kv.IsNotFound(err) {
|
||||
return influxdb.ErrTaskNotFound
|
||||
return taskmodel.ErrTaskNotFound
|
||||
}
|
||||
authType := struct {
|
||||
AuthorizationID platform.ID `json:"authorizationID"`
|
||||
}{}
|
||||
if err := json.Unmarshal(v, &authType); err != nil {
|
||||
return influxdb.ErrInternalTaskServiceError(err)
|
||||
return taskmodel.ErrInternalTaskServiceError(err)
|
||||
}
|
||||
|
||||
// try populating the owner from auth
|
||||
|
@ -143,12 +143,12 @@ var Migration0003_TaskOwnerIDUpMigration = UpOnlyMigration(
|
|||
// save task
|
||||
taskBytes, err := json.Marshal(t)
|
||||
if err != nil {
|
||||
return influxdb.ErrInternalTaskServiceError(err)
|
||||
return taskmodel.ErrInternalTaskServiceError(err)
|
||||
}
|
||||
|
||||
err = b.Put(taskKey, taskBytes)
|
||||
if err != nil {
|
||||
return influxdb.ErrUnexpectedTaskBucketErr(err)
|
||||
return taskmodel.ErrUnexpectedTaskBucketErr(err)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
@ -182,8 +182,8 @@ type kvTask struct {
|
|||
Metadata map[string]interface{} `json:"metadata,omitempty"`
|
||||
}
|
||||
|
||||
func kvToInfluxTask(k *kvTask) *influxdb.Task {
|
||||
return &influxdb.Task{
|
||||
func kvToInfluxTask(k *kvTask) *taskmodel.Task {
|
||||
return &taskmodel.Task{
|
||||
ID: k.ID,
|
||||
Type: k.Type,
|
||||
OrganizationID: k.OrganizationID,
|
||||
|
@ -209,7 +209,7 @@ func kvToInfluxTask(k *kvTask) *influxdb.Task {
|
|||
func taskKey(taskID platform.ID) ([]byte, error) {
|
||||
encodedID, err := taskID.Encode()
|
||||
if err != nil {
|
||||
return nil, influxdb.ErrInvalidTaskID
|
||||
return nil, taskmodel.ErrInvalidTaskID
|
||||
}
|
||||
return encodedID, nil
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"github.com/benbjohnson/clock"
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
"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/resource"
|
||||
"github.com/influxdata/influxdb/v2/resource/noop"
|
||||
|
@ -26,7 +27,7 @@ type Service struct {
|
|||
// FluxLanguageService is used for parsing flux.
|
||||
// If this is unset, operations that require parsing flux
|
||||
// will fail.
|
||||
FluxLanguageService influxdb.FluxLanguageService
|
||||
FluxLanguageService fluxlang.FluxLanguageService
|
||||
|
||||
TokenGenerator influxdb.TokenGenerator
|
||||
// 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
|
||||
type ServiceConfig struct {
|
||||
Clock clock.Clock
|
||||
FluxLanguageService influxdb.FluxLanguageService
|
||||
FluxLanguageService fluxlang.FluxLanguageService
|
||||
}
|
||||
|
||||
// WithResourceLogger sets the resource audit logger for the service.
|
||||
|
|
354
kv/task.go
354
kv/task.go
File diff suppressed because it is too large
Load Diff
|
@ -3,15 +3,15 @@ package kv
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
func Test_newTaskMatchFN(t *testing.T) {
|
||||
ct := func(typ string, name string) *influxdb.Task {
|
||||
return &influxdb.Task{
|
||||
ct := func(typ string, name string) *taskmodel.Task {
|
||||
return &taskmodel.Task{
|
||||
Type: typ,
|
||||
OrganizationID: 1,
|
||||
Name: name,
|
||||
|
@ -27,7 +27,7 @@ func Test_newTaskMatchFN(t *testing.T) {
|
|||
newMatch := func(orgID platform.ID, typ string, name string) taskMatchFn {
|
||||
var (
|
||||
org *influxdb.Organization
|
||||
fil influxdb.TaskFilter
|
||||
fil taskmodel.TaskFilter
|
||||
)
|
||||
|
||||
if orgID != NoOrg {
|
||||
|
@ -47,7 +47,7 @@ func Test_newTaskMatchFN(t *testing.T) {
|
|||
|
||||
type test struct {
|
||||
name string
|
||||
task *influxdb.Task
|
||||
task *taskmodel.Task
|
||||
fn taskMatchFn
|
||||
exp bool
|
||||
}
|
||||
|
@ -61,13 +61,13 @@ func Test_newTaskMatchFN(t *testing.T) {
|
|||
[]test{
|
||||
{
|
||||
name: "equal",
|
||||
task: ct(influxdb.TaskSystemType, "Foo"),
|
||||
task: ct(taskmodel.TaskSystemType, "Foo"),
|
||||
fn: newMatch(1, NoTyp, NoNam),
|
||||
exp: true,
|
||||
},
|
||||
{
|
||||
name: "not org",
|
||||
task: ct(influxdb.TaskSystemType, "Foo"),
|
||||
task: ct(taskmodel.TaskSystemType, "Foo"),
|
||||
fn: newMatch(2, NoTyp, NoNam),
|
||||
exp: false,
|
||||
},
|
||||
|
@ -79,13 +79,13 @@ func Test_newTaskMatchFN(t *testing.T) {
|
|||
{
|
||||
name: "empty with system type",
|
||||
task: ct("", "Foo"),
|
||||
fn: newMatch(NoOrg, influxdb.TaskSystemType, NoNam),
|
||||
fn: newMatch(NoOrg, taskmodel.TaskSystemType, NoNam),
|
||||
exp: true,
|
||||
},
|
||||
{
|
||||
name: "system with system type",
|
||||
task: ct(influxdb.TaskSystemType, "Foo"),
|
||||
fn: newMatch(NoOrg, influxdb.TaskSystemType, NoNam),
|
||||
task: ct(taskmodel.TaskSystemType, "Foo"),
|
||||
fn: newMatch(NoOrg, taskmodel.TaskSystemType, NoNam),
|
||||
exp: true,
|
||||
},
|
||||
{
|
||||
|
@ -96,7 +96,7 @@ func Test_newTaskMatchFN(t *testing.T) {
|
|||
},
|
||||
{
|
||||
name: "not type",
|
||||
task: ct(influxdb.TaskSystemType, "Foo"),
|
||||
task: ct(taskmodel.TaskSystemType, "Foo"),
|
||||
fn: newMatch(NoOrg, "other type", NoNam),
|
||||
exp: false,
|
||||
},
|
||||
|
@ -107,13 +107,13 @@ func Test_newTaskMatchFN(t *testing.T) {
|
|||
[]test{
|
||||
{
|
||||
name: "equal",
|
||||
task: ct(influxdb.TaskSystemType, "Foo"),
|
||||
task: ct(taskmodel.TaskSystemType, "Foo"),
|
||||
fn: newMatch(NoOrg, NoTyp, "Foo"),
|
||||
exp: true,
|
||||
},
|
||||
{
|
||||
name: "not name",
|
||||
task: ct(influxdb.TaskSystemType, "Foo"),
|
||||
task: ct(taskmodel.TaskSystemType, "Foo"),
|
||||
fn: newMatch(NoOrg, NoTyp, "Bar"),
|
||||
exp: false,
|
||||
},
|
||||
|
@ -124,26 +124,26 @@ func Test_newTaskMatchFN(t *testing.T) {
|
|||
[]test{
|
||||
{
|
||||
name: "equal",
|
||||
task: ct(influxdb.TaskSystemType, "Foo"),
|
||||
fn: newMatch(1, influxdb.TaskSystemType, NoNam),
|
||||
task: ct(taskmodel.TaskSystemType, "Foo"),
|
||||
fn: newMatch(1, taskmodel.TaskSystemType, NoNam),
|
||||
exp: true,
|
||||
},
|
||||
{
|
||||
name: "not type",
|
||||
task: ct(influxdb.TaskSystemType, "Foo"),
|
||||
task: ct(taskmodel.TaskSystemType, "Foo"),
|
||||
fn: newMatch(1, "wrong type", NoNam),
|
||||
exp: false,
|
||||
},
|
||||
{
|
||||
name: "not org",
|
||||
task: ct(influxdb.TaskSystemType, "Foo"),
|
||||
fn: newMatch(2, influxdb.TaskSystemType, NoNam),
|
||||
task: ct(taskmodel.TaskSystemType, "Foo"),
|
||||
fn: newMatch(2, taskmodel.TaskSystemType, NoNam),
|
||||
exp: false,
|
||||
},
|
||||
{
|
||||
name: "not org and type",
|
||||
task: ct("check", "Foo"),
|
||||
fn: newMatch(2, influxdb.TaskSystemType, NoNam),
|
||||
fn: newMatch(2, taskmodel.TaskSystemType, NoNam),
|
||||
exp: false,
|
||||
},
|
||||
},
|
||||
|
@ -153,13 +153,13 @@ func Test_newTaskMatchFN(t *testing.T) {
|
|||
[]test{
|
||||
{
|
||||
name: "equal",
|
||||
task: ct(influxdb.TaskSystemType, "Foo"),
|
||||
task: ct(taskmodel.TaskSystemType, "Foo"),
|
||||
fn: newMatch(1, NoTyp, "Foo"),
|
||||
exp: true,
|
||||
},
|
||||
{
|
||||
name: "not org",
|
||||
task: ct(influxdb.TaskSystemType, "Foo"),
|
||||
task: ct(taskmodel.TaskSystemType, "Foo"),
|
||||
fn: newMatch(2, NoTyp, "Foo"),
|
||||
exp: false,
|
||||
},
|
||||
|
@ -208,7 +208,7 @@ func Test_newTaskMatchFN(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 {
|
||||
t.Error("expected nil")
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -14,10 +13,12 @@ import (
|
|||
"github.com/influxdata/influxdb/v2/authorization"
|
||||
icontext "github.com/influxdata/influxdb/v2/context"
|
||||
_ "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/query/fluxlang"
|
||||
"github.com/influxdata/influxdb/v2/task/options"
|
||||
"github.com/influxdata/influxdb/v2/task/servicetest"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
"github.com/influxdata/influxdb/v2/tenant"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -150,11 +151,11 @@ func TestRetrieveTaskWithBadAuth(t *testing.T) {
|
|||
|
||||
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)`,
|
||||
OrganizationID: ts.Org.ID,
|
||||
OwnerID: ts.User.ID,
|
||||
Status: string(influxdb.TaskActive),
|
||||
Status: string(taskmodel.TaskActive),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -196,7 +197,7 @@ func TestRetrieveTaskWithBadAuth(t *testing.T) {
|
|||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -205,8 +206,8 @@ func TestRetrieveTaskWithBadAuth(t *testing.T) {
|
|||
}
|
||||
|
||||
// test status filter
|
||||
active := string(influxdb.TaskActive)
|
||||
tasksWithActiveFilter, _, err := ts.Service.FindTasks(context.Background(), influxdb.TaskFilter{Status: &active})
|
||||
active := string(taskmodel.TaskActive)
|
||||
tasksWithActiveFilter, _, err := ts.Service.FindTasks(context.Background(), taskmodel.TaskFilter{Status: &active})
|
||||
if err != nil {
|
||||
t.Fatal("could not find tasks")
|
||||
}
|
||||
|
@ -227,20 +228,20 @@ func TestService_UpdateTask_InactiveToActive(t *testing.T) {
|
|||
|
||||
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)`,
|
||||
OrganizationID: ts.Org.ID,
|
||||
OwnerID: ts.User.ID,
|
||||
Status: string(influxdb.TaskActive),
|
||||
Status: string(taskmodel.TaskActive),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal("CreateTask", err)
|
||||
}
|
||||
|
||||
v := influxdb.TaskStatusInactive
|
||||
v := taskmodel.TaskStatusInactive
|
||||
c.Add(1 * time.Second)
|
||||
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 {
|
||||
t.Fatal("UpdateTask", err)
|
||||
}
|
||||
|
@ -254,8 +255,8 @@ func TestService_UpdateTask_InactiveToActive(t *testing.T) {
|
|||
|
||||
c.Add(10 * time.Second)
|
||||
exp = c.Now()
|
||||
v = influxdb.TaskStatusActive
|
||||
updatedTask, err = ts.Service.UpdateTask(ctx, originalTask.ID, influxdb.TaskUpdate{Status: &v})
|
||||
v = taskmodel.TaskStatusActive
|
||||
updatedTask, err = ts.Service.UpdateTask(ctx, originalTask.ID, taskmodel.TaskUpdate{Status: &v})
|
||||
if err != nil {
|
||||
t.Fatal("UpdateTask", err)
|
||||
}
|
||||
|
@ -315,7 +316,7 @@ func TestTaskRunCancellation(t *testing.T) {
|
|||
|
||||
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)`,
|
||||
OrganizationID: o.ID,
|
||||
OwnerID: u.ID,
|
||||
|
@ -338,7 +339,7 @@ func TestTaskRunCancellation(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if canceled.Status != influxdb.RunCanceled.String() {
|
||||
if canceled.Status != taskmodel.RunCanceled.String() {
|
||||
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)
|
||||
|
||||
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)`,
|
||||
OrganizationID: ts.Org.ID,
|
||||
OwnerID: ts.User.ID,
|
||||
Status: string(influxdb.TaskActive),
|
||||
Status: string(taskmodel.TaskActive),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal("CreateTask", err)
|
||||
|
@ -367,7 +368,7 @@ func TestService_UpdateTask_RecordLatestSuccessAndFailure(t *testing.T) {
|
|||
|
||||
c.Add(1 * time.Second)
|
||||
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,
|
||||
LatestScheduled: &exp,
|
||||
|
||||
|
@ -395,7 +396,7 @@ func TestService_UpdateTask_RecordLatestSuccessAndFailure(t *testing.T) {
|
|||
|
||||
c.Add(5 * time.Second)
|
||||
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,
|
||||
LatestScheduled: &exp,
|
||||
|
||||
|
|
|
@ -5,93 +5,92 @@ import (
|
|||
"time"
|
||||
|
||||
"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/taskmodel"
|
||||
)
|
||||
|
||||
var _ influxdb.TaskService = (*TaskService)(nil)
|
||||
var _ taskmodel.TaskService = (*TaskService)(nil)
|
||||
var _ backend.TaskControlService = (*TaskControlService)(nil)
|
||||
|
||||
type TaskService struct {
|
||||
FindTaskByIDFn func(context.Context, platform.ID) (*influxdb.Task, error)
|
||||
FindTaskByIDFn func(context.Context, platform.ID) (*taskmodel.Task, error)
|
||||
FindTaskByIDCalls SafeCount
|
||||
FindTasksFn func(context.Context, influxdb.TaskFilter) ([]*influxdb.Task, int, error)
|
||||
FindTasksFn func(context.Context, taskmodel.TaskFilter) ([]*taskmodel.Task, int, error)
|
||||
FindTasksCalls SafeCount
|
||||
CreateTaskFn func(context.Context, influxdb.TaskCreate) (*influxdb.Task, error)
|
||||
CreateTaskFn func(context.Context, taskmodel.TaskCreate) (*taskmodel.Task, error)
|
||||
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
|
||||
DeleteTaskFn func(context.Context, platform.ID) error
|
||||
DeleteTaskCalls SafeCount
|
||||
FindLogsFn func(context.Context, influxdb.LogFilter) ([]*influxdb.Log, int, error)
|
||||
FindLogsFn func(context.Context, taskmodel.LogFilter) ([]*taskmodel.Log, int, error)
|
||||
FindLogsCalls SafeCount
|
||||
FindRunsFn func(context.Context, influxdb.RunFilter) ([]*influxdb.Run, int, error)
|
||||
FindRunsFn func(context.Context, taskmodel.RunFilter) ([]*taskmodel.Run, int, error)
|
||||
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
|
||||
CancelRunFn func(context.Context, platform.ID, platform.ID) error
|
||||
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
|
||||
ForceRunFn func(context.Context, platform.ID, int64) (*influxdb.Run, error)
|
||||
ForceRunFn func(context.Context, platform.ID, int64) (*taskmodel.Run, error)
|
||||
ForceRunCalls SafeCount
|
||||
}
|
||||
|
||||
func NewTaskService() *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
|
||||
},
|
||||
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
|
||||
},
|
||||
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
|
||||
},
|
||||
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
|
||||
},
|
||||
DeleteTaskFn: func(ctx context.Context, id platform.ID) error {
|
||||
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
|
||||
},
|
||||
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
|
||||
},
|
||||
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
|
||||
},
|
||||
CancelRunFn: func(ctx context.Context, id platform.ID, id2 platform.ID) error {
|
||||
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
|
||||
},
|
||||
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
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
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()()
|
||||
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()()
|
||||
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()()
|
||||
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()()
|
||||
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)
|
||||
}
|
||||
|
||||
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()()
|
||||
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()()
|
||||
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()()
|
||||
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)
|
||||
}
|
||||
|
||||
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()()
|
||||
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()()
|
||||
return s.ForceRunFn(ctx, taskID, scheduledFor)
|
||||
}
|
||||
|
||||
type TaskControlService struct {
|
||||
CreateRunFn func(ctx context.Context, taskID platform.ID, scheduledFor time.Time, runAt time.Time) (*influxdb.Run, error)
|
||||
CurrentlyRunningFn func(ctx context.Context, taskID platform.ID) ([]*influxdb.Run, error)
|
||||
ManualRunsFn func(ctx context.Context, taskID platform.ID) ([]*influxdb.Run, error)
|
||||
StartManualRunFn func(ctx context.Context, taskID, runID platform.ID) (*influxdb.Run, error)
|
||||
FinishRunFn func(ctx context.Context, taskID, runID platform.ID) (*influxdb.Run, error)
|
||||
UpdateRunStateFn func(ctx context.Context, taskID, runID platform.ID, when time.Time, state influxdb.RunStatus) 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) ([]*taskmodel.Run, error)
|
||||
ManualRunsFn func(ctx context.Context, taskID platform.ID) ([]*taskmodel.Run, error)
|
||||
StartManualRunFn func(ctx context.Context, taskID, runID platform.ID) (*taskmodel.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 taskmodel.RunStatus) 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)
|
||||
}
|
||||
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)
|
||||
}
|
||||
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)
|
||||
}
|
||||
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)
|
||||
}
|
||||
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)
|
||||
}
|
||||
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)
|
||||
}
|
||||
func (tcs *TaskControlService) AddRunLog(ctx context.Context, taskID, runID platform.ID, when time.Time, log string) error {
|
||||
|
|
|
@ -4,13 +4,13 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
"github.com/influxdata/influxdb/v2/kit/platform/errors"
|
||||
|
||||
"github.com/influxdata/flux/ast"
|
||||
"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/flux"
|
||||
"github.com/influxdata/influxdb/v2/query/fluxlang"
|
||||
)
|
||||
|
||||
// Base will embed inside a check.
|
||||
|
@ -39,7 +39,7 @@ type Base struct {
|
|||
}
|
||||
|
||||
// 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() {
|
||||
return &errors.Error{
|
||||
Code: errors.EInvalid,
|
||||
|
|
|
@ -4,13 +4,13 @@ import (
|
|||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
"github.com/influxdata/influxdb/v2/kit/platform/errors"
|
||||
|
||||
"github.com/influxdata/flux/ast"
|
||||
"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/query"
|
||||
"github.com/influxdata/influxdb/v2/query/fluxlang"
|
||||
)
|
||||
|
||||
var _ influxdb.Check = &Custom{}
|
||||
|
@ -64,12 +64,12 @@ type Custom struct {
|
|||
// |> monitor.check(data: check, messageFn:messageFn, warn:warn, crit:crit, info:info)
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// 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)
|
||||
if p == nil {
|
||||
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
|
||||
}
|
||||
|
||||
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)
|
||||
if p == nil {
|
||||
|
@ -175,7 +175,7 @@ func (c *Custom) hasRequiredTaskOptions(lang influxdb.FluxLanguageService) (err
|
|||
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)
|
||||
if p == nil {
|
||||
return err
|
||||
|
@ -223,7 +223,7 @@ func (c *Custom) hasRequiredCheckParameters(lang influxdb.FluxLanguageService) (
|
|||
}
|
||||
|
||||
// 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 {
|
||||
return err
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/influxdata/influxdb/v2/notification"
|
||||
"github.com/influxdata/influxdb/v2/notification/flux"
|
||||
"github.com/influxdata/influxdb/v2/query"
|
||||
"github.com/influxdata/influxdb/v2/query/fluxlang"
|
||||
)
|
||||
|
||||
var _ influxdb.Check = (*Deadman)(nil)
|
||||
|
@ -31,7 +32,7 @@ func (c Deadman) Type() string {
|
|||
}
|
||||
|
||||
// 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)
|
||||
if err != nil {
|
||||
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
|
||||
// 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.
|
||||
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)
|
||||
if p == nil {
|
||||
return nil, err
|
||||
|
|
|
@ -5,13 +5,13 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform/errors"
|
||||
|
||||
"github.com/influxdata/flux/ast"
|
||||
"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/flux"
|
||||
"github.com/influxdata/influxdb/v2/query"
|
||||
"github.com/influxdata/influxdb/v2/query/fluxlang"
|
||||
)
|
||||
|
||||
var _ influxdb.Check = (*Threshold)(nil)
|
||||
|
@ -28,7 +28,7 @@ func (t Threshold) Type() string {
|
|||
}
|
||||
|
||||
// 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 {
|
||||
return err
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ func multiError(errs []error) error {
|
|||
// 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
|
||||
// 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)
|
||||
if err != nil {
|
||||
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
|
||||
// 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.
|
||||
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)
|
||||
if p == nil {
|
||||
return nil, err
|
||||
|
|
|
@ -5,14 +5,14 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"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"
|
||||
"github.com/influxdata/influxdb/v2/kv"
|
||||
"github.com/influxdata/influxdb/v2/notification/rule"
|
||||
"github.com/influxdata/influxdb/v2/pkg/pointer"
|
||||
"github.com/influxdata/influxdb/v2/snowflake"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
@ -39,7 +39,7 @@ type RuleService struct {
|
|||
log *zap.Logger
|
||||
|
||||
kv kv.Store
|
||||
tasks influxdb.TaskService
|
||||
tasks taskmodel.TaskService
|
||||
orgs influxdb.OrganizationService
|
||||
endpoints influxdb.NotificationEndpointService
|
||||
|
||||
|
@ -48,7 +48,7 @@ type RuleService struct {
|
|||
}
|
||||
|
||||
// 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{
|
||||
log: logger,
|
||||
kv: store,
|
||||
|
@ -138,7 +138,7 @@ func (s *RuleService) CreateNotificationRule(ctx context.Context, nr influxdb.No
|
|||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
|
@ -154,7 +154,7 @@ func (s *RuleService) createNotificationRule(ctx context.Context, tx kv.Tx, nr i
|
|||
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())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -165,7 +165,7 @@ func (s *RuleService) createNotificationTask(ctx context.Context, r influxdb.Not
|
|||
return nil, err
|
||||
}
|
||||
|
||||
tc := influxdb.TaskCreate{
|
||||
tc := taskmodel.TaskCreate{
|
||||
Type: r.Type(),
|
||||
Flux: script,
|
||||
OwnerID: r.GetOwnerID(),
|
||||
|
@ -218,7 +218,7 @@ func (s *RuleService) UpdateNotificationRule(ctx context.Context, id platform.ID
|
|||
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())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -229,7 +229,7 @@ func (s *RuleService) updateNotificationTask(ctx context.Context, r influxdb.Not
|
|||
return nil, err
|
||||
}
|
||||
|
||||
tu := influxdb.TaskUpdate{
|
||||
tu := taskmodel.TaskUpdate{
|
||||
Flux: &script,
|
||||
Description: pointer.String(r.GetDescription()),
|
||||
Status: status,
|
||||
|
|
|
@ -8,18 +8,18 @@ import (
|
|||
"testing"
|
||||
"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/cmpopts"
|
||||
"github.com/influxdata/flux/ast"
|
||||
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/notification"
|
||||
"github.com/influxdata/influxdb/v2/notification/endpoint"
|
||||
"github.com/influxdata/influxdb/v2/notification/rule"
|
||||
"github.com/influxdata/influxdb/v2/pkg/pointer"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -45,7 +45,7 @@ type NotificationRuleFields struct {
|
|||
TimeGenerator influxdb.TimeGenerator
|
||||
NotificationRules []influxdb.NotificationRule
|
||||
Orgs []*influxdb.Organization
|
||||
Tasks []influxdb.TaskCreate
|
||||
Tasks []taskmodel.TaskCreate
|
||||
Endpoints []influxdb.NotificationEndpoint
|
||||
}
|
||||
|
||||
|
@ -66,14 +66,14 @@ var taskCmpOptions = cmp.Options{
|
|||
}),
|
||||
// skip comparing permissions
|
||||
cmpopts.IgnoreFields(
|
||||
influxdb.Task{},
|
||||
taskmodel.Task{},
|
||||
"LatestCompleted",
|
||||
"LatestScheduled",
|
||||
"CreatedAt",
|
||||
"UpdatedAt",
|
||||
),
|
||||
cmp.Transformer("Sort", func(in []*influxdb.Task) []*influxdb.Task {
|
||||
out := append([]*influxdb.Task{}, in...) // Copy input to avoid mutating it
|
||||
cmp.Transformer("Sort", func(in []*taskmodel.Task) []*taskmodel.Task {
|
||||
out := append([]*taskmodel.Task{}, in...) // Copy input to avoid mutating it
|
||||
sort.Slice(out, func(i, j int) bool {
|
||||
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.
|
||||
func NotificationRuleStore(
|
||||
|
@ -135,7 +135,7 @@ func CreateNotificationRule(
|
|||
type wants struct {
|
||||
err error
|
||||
notificationRule influxdb.NotificationRule
|
||||
task *influxdb.Task
|
||||
task *taskmodel.Task
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
|
@ -287,7 +287,7 @@ func CreateNotificationRule(
|
|||
},
|
||||
MessageTemplate: "msg1",
|
||||
},
|
||||
task: &influxdb.Task{
|
||||
task: &taskmodel.Task{
|
||||
ID: MustIDBase16("020f755c3c082001"),
|
||||
Type: "slack",
|
||||
OrganizationID: MustIDBase16("020f755c3c082003"),
|
||||
|
@ -453,7 +453,7 @@ func CreateNotificationRule(
|
|||
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
|
||||
// no tasks should be persisted
|
||||
_, n, err := tasks.FindTasks(ctx, influxdb.TaskFilter{})
|
||||
_, n, err := tasks.FindTasks(ctx, taskmodel.TaskFilter{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -1323,7 +1323,7 @@ func UpdateNotificationRule(
|
|||
fields: NotificationRuleFields{
|
||||
TimeGenerator: fakeGenerator,
|
||||
IDGenerator: mock.NewIDGenerator(twoID, t),
|
||||
Tasks: []influxdb.TaskCreate{
|
||||
Tasks: []taskmodel.TaskCreate{
|
||||
{
|
||||
OwnerID: MustIDBase16(sixID),
|
||||
OrganizationID: MustIDBase16(fourID),
|
||||
|
@ -1558,7 +1558,7 @@ func PatchNotificationRule(
|
|||
fields: NotificationRuleFields{
|
||||
TimeGenerator: fakeGenerator,
|
||||
IDGenerator: mock.NewIDGenerator(twoID, t),
|
||||
Tasks: []influxdb.TaskCreate{
|
||||
Tasks: []taskmodel.TaskCreate{
|
||||
{
|
||||
OwnerID: MustIDBase16(sixID),
|
||||
OrganizationID: MustIDBase16(fourID),
|
||||
|
@ -1683,7 +1683,7 @@ func PatchNotificationRule(
|
|||
fields: NotificationRuleFields{
|
||||
TimeGenerator: fakeGenerator,
|
||||
IDGenerator: mock.NewIDGenerator(twoID, t),
|
||||
Tasks: []influxdb.TaskCreate{
|
||||
Tasks: []taskmodel.TaskCreate{
|
||||
{
|
||||
OwnerID: MustIDBase16(sixID),
|
||||
OrganizationID: MustIDBase16(fourID),
|
||||
|
@ -1933,7 +1933,7 @@ func DeleteNotificationRule(
|
|||
name: "none existing config",
|
||||
fields: NotificationRuleFields{
|
||||
IDGenerator: mock.NewIDGenerator(twoID, t),
|
||||
Tasks: []influxdb.TaskCreate{
|
||||
Tasks: []taskmodel.TaskCreate{
|
||||
{
|
||||
OwnerID: MustIDBase16(sixID),
|
||||
OrganizationID: MustIDBase16(fourID),
|
||||
|
@ -2038,7 +2038,7 @@ func DeleteNotificationRule(
|
|||
{
|
||||
name: "regular delete",
|
||||
fields: NotificationRuleFields{
|
||||
Tasks: []influxdb.TaskCreate{
|
||||
Tasks: []taskmodel.TaskCreate{
|
||||
{
|
||||
OwnerID: MustIDBase16(sixID),
|
||||
OrganizationID: MustIDBase16(fourID),
|
||||
|
|
|
@ -7,18 +7,18 @@ import (
|
|||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
|
||||
influxdb "github.com/influxdata/influxdb/v2"
|
||||
"github.com/influxdata/influxdb/v2/bolt"
|
||||
_ "github.com/influxdata/influxdb/v2/fluxinit/static"
|
||||
"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/migration/all"
|
||||
"github.com/influxdata/influxdb/v2/mock"
|
||||
endpointservice "github.com/influxdata/influxdb/v2/notification/endpoint/service"
|
||||
"github.com/influxdata/influxdb/v2/query/fluxlang"
|
||||
"github.com/influxdata/influxdb/v2/secret"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
"github.com/influxdata/influxdb/v2/tenant"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/zap/zaptest"
|
||||
|
@ -28,7 +28,7 @@ func TestInmemNotificationRuleStore(t *testing.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()
|
||||
if err := all.Up(context.Background(), zaptest.NewLogger(t), store); err != nil {
|
||||
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)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -57,7 +57,7 @@ func TestBoltNotificationRuleStore(t *testing.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)
|
||||
|
||||
var (
|
||||
|
|
|
@ -8,16 +8,16 @@ import (
|
|||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
ierrors "github.com/influxdata/influxdb/v2/kit/errors"
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
"github.com/influxdata/influxdb/v2/notification"
|
||||
icheck "github.com/influxdata/influxdb/v2/notification/check"
|
||||
"github.com/influxdata/influxdb/v2/notification/endpoint"
|
||||
"github.com/influxdata/influxdb/v2/notification/rule"
|
||||
"github.com/influxdata/influxdb/v2/pkger/internal/wordplay"
|
||||
"github.com/influxdata/influxdb/v2/snowflake"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
)
|
||||
|
||||
var idGenerator = snowflake.NewDefaultIDGenerator()
|
||||
|
@ -90,7 +90,7 @@ type resourceExporter struct {
|
|||
labelSVC influxdb.LabelService
|
||||
endpointSVC influxdb.NotificationEndpointService
|
||||
ruleSVC influxdb.NotificationRuleStore
|
||||
taskSVC influxdb.TaskService
|
||||
taskSVC taskmodel.TaskService
|
||||
teleSVC influxdb.TelegrafConfigStore
|
||||
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))
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
@ -625,7 +625,7 @@ func CheckToObject(name string, ch influxdb.Check) Object {
|
|||
o := newObject(KindCheck, name)
|
||||
assignNonZeroStrings(o.Spec, map[string]string{
|
||||
fieldDescription: ch.GetDescription(),
|
||||
fieldStatus: influxdb.TaskStatusActive,
|
||||
fieldStatus: taskmodel.TaskStatusActive,
|
||||
})
|
||||
|
||||
assignBase := func(base icheck.Base) {
|
||||
|
@ -1333,7 +1333,7 @@ func NotificationRuleToObject(name, endpointPkgName string, iRule influxdb.Notif
|
|||
var taskFluxRegex = regexp.MustCompile(`option task = {(.|\n)*?}`)
|
||||
|
||||
// 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 == "" {
|
||||
name = t.Name
|
||||
}
|
||||
|
|
|
@ -13,12 +13,12 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
errors2 "github.com/influxdata/influxdb/v2/kit/platform/errors"
|
||||
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
errors2 "github.com/influxdata/influxdb/v2/kit/platform/errors"
|
||||
"github.com/influxdata/influxdb/v2/notification"
|
||||
icheck "github.com/influxdata/influxdb/v2/notification/check"
|
||||
"github.com/influxdata/influxdb/v2/notification/endpoint"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -2709,7 +2709,7 @@ spec:
|
|||
Base: endpoint.Base{
|
||||
Name: "basic endpoint name",
|
||||
Description: "http basic auth desc",
|
||||
Status: influxdb.TaskStatusInactive,
|
||||
Status: taskmodel.TaskStatusInactive,
|
||||
},
|
||||
URL: "https://www.example.com/endpoint/basicauth",
|
||||
AuthMethod: "basic",
|
||||
|
@ -2727,7 +2727,7 @@ spec:
|
|||
Base: endpoint.Base{
|
||||
Name: "http-bearer-auth-notification-endpoint",
|
||||
Description: "http bearer auth desc",
|
||||
Status: influxdb.TaskStatusActive,
|
||||
Status: taskmodel.TaskStatusActive,
|
||||
},
|
||||
URL: "https://www.example.com/endpoint/bearerauth",
|
||||
AuthMethod: "bearer",
|
||||
|
@ -2744,7 +2744,7 @@ spec:
|
|||
Base: endpoint.Base{
|
||||
Name: "http-none-auth-notification-endpoint",
|
||||
Description: "http none auth desc",
|
||||
Status: influxdb.TaskStatusActive,
|
||||
Status: taskmodel.TaskStatusActive,
|
||||
},
|
||||
URL: "https://www.example.com/endpoint/noneauth",
|
||||
AuthMethod: "none",
|
||||
|
@ -2760,7 +2760,7 @@ spec:
|
|||
Base: endpoint.Base{
|
||||
Name: "pager duty name",
|
||||
Description: "pager duty desc",
|
||||
Status: influxdb.TaskStatusActive,
|
||||
Status: taskmodel.TaskStatusActive,
|
||||
},
|
||||
ClientURL: "http://localhost:8080/orgs/7167eb6719fa34e5/alert-history",
|
||||
RoutingKey: influxdb.SecretField{Value: strPtr("secret routing-key")},
|
||||
|
@ -2775,7 +2775,7 @@ spec:
|
|||
Base: endpoint.Base{
|
||||
Name: "slack name",
|
||||
Description: "slack desc",
|
||||
Status: influxdb.TaskStatusActive,
|
||||
Status: taskmodel.TaskStatusActive,
|
||||
},
|
||||
URL: "https://hooks.slack.com/services/bip/piddy/boppidy",
|
||||
Token: influxdb.SecretField{Value: strPtr("tokenval")},
|
||||
|
@ -4245,7 +4245,7 @@ spec:
|
|||
expected := &endpoint.PagerDuty{
|
||||
Base: endpoint.Base{
|
||||
Name: "pager-duty-notification-endpoint",
|
||||
Status: influxdb.TaskStatusActive,
|
||||
Status: taskmodel.TaskStatusActive,
|
||||
},
|
||||
ClientURL: "http://localhost:8080/orgs/7167eb6719fa34e5/alert-history",
|
||||
RoutingKey: influxdb.SecretField{Key: "-routing-key", Value: strPtr("not empty")},
|
||||
|
|
|
@ -12,17 +12,17 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
errors2 "github.com/influxdata/influxdb/v2/kit/platform/errors"
|
||||
|
||||
"github.com/go-stack/stack"
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
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"
|
||||
"github.com/influxdata/influxdb/v2/notification/rule"
|
||||
"github.com/influxdata/influxdb/v2/pkger/internal/wordplay"
|
||||
"github.com/influxdata/influxdb/v2/snowflake"
|
||||
"github.com/influxdata/influxdb/v2/task/options"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
@ -162,7 +162,7 @@ type serviceOpt struct {
|
|||
orgSVC influxdb.OrganizationService
|
||||
ruleSVC influxdb.NotificationRuleStore
|
||||
secretSVC influxdb.SecretService
|
||||
taskSVC influxdb.TaskService
|
||||
taskSVC taskmodel.TaskService
|
||||
teleSVC influxdb.TelegrafConfigStore
|
||||
varSVC influxdb.VariableService
|
||||
}
|
||||
|
@ -261,7 +261,7 @@ func WithSecretSVC(secretSVC influxdb.SecretService) ServiceSetterFn {
|
|||
}
|
||||
|
||||
// WithTaskSVC sets the task service.
|
||||
func WithTaskSVC(taskSVC influxdb.TaskService) ServiceSetterFn {
|
||||
func WithTaskSVC(taskSVC taskmodel.TaskService) ServiceSetterFn {
|
||||
return func(opt *serviceOpt) {
|
||||
opt.taskSVC = taskSVC
|
||||
}
|
||||
|
@ -311,7 +311,7 @@ type Service struct {
|
|||
orgSVC influxdb.OrganizationService
|
||||
ruleSVC influxdb.NotificationRuleStore
|
||||
secretSVC influxdb.SecretService
|
||||
taskSVC influxdb.TaskService
|
||||
taskSVC taskmodel.TaskService
|
||||
teleSVC influxdb.TelegrafConfigStore
|
||||
varSVC influxdb.VariableService
|
||||
}
|
||||
|
@ -822,10 +822,10 @@ func (s *Service) cloneOrgTasks(ctx context.Context, orgID platform.ID) ([]Resou
|
|||
return nil, err
|
||||
}
|
||||
|
||||
mTasks := make(map[platform.ID]*influxdb.Task)
|
||||
mTasks := make(map[platform.ID]*taskmodel.Task)
|
||||
for i := range tasks {
|
||||
t := tasks[i]
|
||||
if t.Type != influxdb.TaskSystemType {
|
||||
if t.Type != taskmodel.TaskSystemType {
|
||||
continue
|
||||
}
|
||||
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) {
|
||||
for _, stateTask := range tasks {
|
||||
stateTask.orgID = orgID
|
||||
var existing *influxdb.Task
|
||||
var existing *taskmodel.Task
|
||||
if stateTask.ID() != 0 {
|
||||
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) {
|
||||
return *t.existing, nil
|
||||
}
|
||||
|
@ -2538,9 +2538,9 @@ func (s *Service) applyTask(ctx context.Context, userID platform.ID, t *stateTas
|
|||
case IsRemoval(t.stateStatus):
|
||||
if err := s.taskSVC.DeleteTask(ctx, t.ID()); err != nil {
|
||||
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
|
||||
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,
|
||||
Status: &newStatus,
|
||||
Description: &t.parserTask.description,
|
||||
Options: opt,
|
||||
})
|
||||
if err != nil {
|
||||
return influxdb.Task{}, applyFailErr("update", t.stateIdentity(), err)
|
||||
return taskmodel.Task{}, applyFailErr("update", t.stateIdentity(), err)
|
||||
}
|
||||
return *updatedTask, nil
|
||||
default:
|
||||
newTask, err := s.taskSVC.CreateTask(ctx, influxdb.TaskCreate{
|
||||
Type: influxdb.TaskSystemType,
|
||||
newTask, err := s.taskSVC.CreateTask(ctx, taskmodel.TaskCreate{
|
||||
Type: taskmodel.TaskSystemType,
|
||||
Flux: t.parserTask.flux(),
|
||||
OwnerID: userID,
|
||||
Description: t.parserTask.description,
|
||||
|
@ -2580,7 +2580,7 @@ func (s *Service) applyTask(ctx context.Context, userID platform.ID, t *stateTas
|
|||
OrganizationID: t.orgID,
|
||||
})
|
||||
if err != nil {
|
||||
return influxdb.Task{}, applyFailErr("create", t.stateIdentity(), err)
|
||||
return taskmodel.Task{}, applyFailErr("create", t.stateIdentity(), err)
|
||||
}
|
||||
return *newTask, nil
|
||||
}
|
||||
|
@ -2595,7 +2595,7 @@ func (s *Service) rollbackTasks(ctx context.Context, tasks []*stateTask) error {
|
|||
var err error
|
||||
switch t.stateStatus {
|
||||
case StateStatusRemove:
|
||||
newTask, err := s.taskSVC.CreateTask(ctx, influxdb.TaskCreate{
|
||||
newTask, err := s.taskSVC.CreateTask(ctx, taskmodel.TaskCreate{
|
||||
Type: t.existing.Type,
|
||||
Flux: t.existing.Flux,
|
||||
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,
|
||||
Status: &t.existing.Status,
|
||||
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 (
|
||||
out []*influxdb.Task
|
||||
out []*taskmodel.Task
|
||||
afterID *platform.ID
|
||||
)
|
||||
for {
|
||||
f := influxdb.TaskFilter{
|
||||
f := taskmodel.TaskFilter{
|
||||
OrganizationID: &orgID,
|
||||
Limit: influxdb.TaskMaxPageSize,
|
||||
Limit: taskmodel.TaskMaxPageSize,
|
||||
}
|
||||
if afterID != nil {
|
||||
f.After = afterID
|
||||
|
@ -3688,8 +3688,8 @@ func validURLs(urls []string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func isRestrictedTask(t *influxdb.Task) bool {
|
||||
return t != nil && t.Type != influxdb.TaskSystemType
|
||||
func isRestrictedTask(t *taskmodel.Task) bool {
|
||||
return t != nil && t.Type != taskmodel.TaskSystemType
|
||||
}
|
||||
|
||||
func isSystemBucket(b *influxdb.Bucket) bool {
|
||||
|
|
|
@ -4,10 +4,10 @@ import (
|
|||
"reflect"
|
||||
"sort"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
"github.com/influxdata/influxdb/v2/notification/rule"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
)
|
||||
|
||||
type stateCoordinator struct {
|
||||
|
@ -1347,7 +1347,7 @@ type stateTask struct {
|
|||
labelAssociations []*stateLabel
|
||||
|
||||
parserTask *task
|
||||
existing *influxdb.Task
|
||||
existing *taskmodel.Task
|
||||
}
|
||||
|
||||
func (t *stateTask) ID() platform.ID {
|
||||
|
|
|
@ -13,15 +13,15 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
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/notification"
|
||||
icheck "github.com/influxdata/influxdb/v2/notification/check"
|
||||
"github.com/influxdata/influxdb/v2/notification/endpoint"
|
||||
"github.com/influxdata/influxdb/v2/notification/rule"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/zap/zaptest"
|
||||
|
@ -453,7 +453,7 @@ func TestService(t *testing.T) {
|
|||
ID: &id,
|
||||
Name: "http-none-auth-notification-endpoint",
|
||||
Description: "old desc",
|
||||
Status: influxdb.TaskStatusInactive,
|
||||
Status: taskmodel.TaskStatusInactive,
|
||||
},
|
||||
Method: "POST",
|
||||
AuthMethod: "none",
|
||||
|
@ -500,7 +500,7 @@ func TestService(t *testing.T) {
|
|||
ID: &id,
|
||||
Name: "http-none-auth-notification-endpoint",
|
||||
Description: "http none auth desc",
|
||||
Status: influxdb.TaskStatusActive,
|
||||
Status: taskmodel.TaskStatusActive,
|
||||
},
|
||||
AuthMethod: "none",
|
||||
Method: "GET",
|
||||
|
@ -561,7 +561,7 @@ func TestService(t *testing.T) {
|
|||
// This name here matches the endpoint identified in the template notification rule
|
||||
Name: "endpoint-0",
|
||||
Description: "old desc",
|
||||
Status: influxdb.TaskStatusInactive,
|
||||
Status: taskmodel.TaskStatusInactive,
|
||||
},
|
||||
Method: "POST",
|
||||
AuthMethod: "none",
|
||||
|
@ -1330,13 +1330,13 @@ func TestService(t *testing.T) {
|
|||
t.Run("maps tasks with labels", func(t *testing.T) {
|
||||
opts := func() []ServiceSetterFn {
|
||||
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: "(.+)",`)
|
||||
names := reg.FindStringSubmatch(tc.Flux)
|
||||
if len(names) < 2 {
|
||||
return nil, errors.New("bad flux query provided: " + tc.Flux)
|
||||
}
|
||||
return &influxdb.Task{
|
||||
return &taskmodel.Task{
|
||||
ID: platform.ID(rand.Int()),
|
||||
Type: tc.Type,
|
||||
OrganizationID: tc.OrganizationID,
|
||||
|
@ -1546,13 +1546,13 @@ func TestService(t *testing.T) {
|
|||
orgID := platform.ID(9000)
|
||||
|
||||
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: "(.+)",`)
|
||||
names := reg.FindStringSubmatch(tc.Flux)
|
||||
if len(names) < 2 {
|
||||
return nil, errors.New("bad flux query provided: " + tc.Flux)
|
||||
}
|
||||
return &influxdb.Task{
|
||||
return &taskmodel.Task{
|
||||
ID: platform.ID(fakeTaskSVC.CreateTaskCalls.Count() + 1),
|
||||
Type: tc.Type,
|
||||
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) {
|
||||
testfileRunner(t, "testdata/tasks.yml", func(t *testing.T, template *Template) {
|
||||
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 {
|
||||
return nil, errors.New("expected error")
|
||||
}
|
||||
return &influxdb.Task{
|
||||
return &taskmodel.Task{
|
||||
ID: platform.ID(fakeTaskSVC.CreateTaskCalls.Count() + 1),
|
||||
}, nil
|
||||
}
|
||||
|
@ -3275,7 +3275,7 @@ func TestService(t *testing.T) {
|
|||
Base: endpoint.Base{
|
||||
Name: "pd-endpoint",
|
||||
Description: "desc",
|
||||
Status: influxdb.TaskStatusActive,
|
||||
Status: taskmodel.TaskStatusActive,
|
||||
},
|
||||
ClientURL: "http://example.com",
|
||||
RoutingKey: influxdb.SecretField{Key: "-routing-key"},
|
||||
|
@ -3288,7 +3288,7 @@ func TestService(t *testing.T) {
|
|||
Base: endpoint.Base{
|
||||
Name: "pd-endpoint",
|
||||
Description: "desc",
|
||||
Status: influxdb.TaskStatusActive,
|
||||
Status: taskmodel.TaskStatusActive,
|
||||
},
|
||||
ClientURL: "http://example.com",
|
||||
RoutingKey: influxdb.SecretField{Key: "-routing-key"},
|
||||
|
@ -3300,7 +3300,7 @@ func TestService(t *testing.T) {
|
|||
Base: endpoint.Base{
|
||||
Name: "pd-endpoint",
|
||||
Description: "desc",
|
||||
Status: influxdb.TaskStatusInactive,
|
||||
Status: taskmodel.TaskStatusInactive,
|
||||
},
|
||||
URL: "http://example.com",
|
||||
Token: influxdb.SecretField{Key: "tokne"},
|
||||
|
@ -3312,7 +3312,7 @@ func TestService(t *testing.T) {
|
|||
Base: endpoint.Base{
|
||||
Name: "pd-endpoint",
|
||||
Description: "desc",
|
||||
Status: influxdb.TaskStatusInactive,
|
||||
Status: taskmodel.TaskStatusInactive,
|
||||
},
|
||||
AuthMethod: "basic",
|
||||
Method: "POST",
|
||||
|
@ -3327,7 +3327,7 @@ func TestService(t *testing.T) {
|
|||
Base: endpoint.Base{
|
||||
Name: "pd-endpoint",
|
||||
Description: "desc",
|
||||
Status: influxdb.TaskStatusInactive,
|
||||
Status: taskmodel.TaskStatusInactive,
|
||||
},
|
||||
AuthMethod: "bearer",
|
||||
Method: "GET",
|
||||
|
@ -3341,7 +3341,7 @@ func TestService(t *testing.T) {
|
|||
Base: endpoint.Base{
|
||||
Name: "pd-endpoint",
|
||||
Description: "desc",
|
||||
Status: influxdb.TaskStatusInactive,
|
||||
Status: taskmodel.TaskStatusInactive,
|
||||
},
|
||||
AuthMethod: "none",
|
||||
Method: "GET",
|
||||
|
@ -3404,7 +3404,7 @@ func TestService(t *testing.T) {
|
|||
ID: newTestIDPtr(1),
|
||||
Name: "pd endpoint",
|
||||
Description: "desc",
|
||||
Status: influxdb.TaskStatusActive,
|
||||
Status: taskmodel.TaskStatusActive,
|
||||
},
|
||||
ClientURL: "http://example.com",
|
||||
RoutingKey: influxdb.SecretField{Key: "-routing-key"},
|
||||
|
@ -3414,7 +3414,7 @@ func TestService(t *testing.T) {
|
|||
ID: newTestIDPtr(2),
|
||||
Name: "pd-endpoint",
|
||||
Description: "desc pd",
|
||||
Status: influxdb.TaskStatusActive,
|
||||
Status: taskmodel.TaskStatusActive,
|
||||
},
|
||||
ClientURL: "http://example.com",
|
||||
RoutingKey: influxdb.SecretField{Key: "-routing-key"},
|
||||
|
@ -3424,7 +3424,7 @@ func TestService(t *testing.T) {
|
|||
ID: newTestIDPtr(3),
|
||||
Name: "slack endpoint",
|
||||
Description: "desc slack",
|
||||
Status: influxdb.TaskStatusInactive,
|
||||
Status: taskmodel.TaskStatusInactive,
|
||||
},
|
||||
URL: "http://example.com",
|
||||
Token: influxdb.SecretField{Key: "tokne"},
|
||||
|
@ -3559,7 +3559,7 @@ func TestService(t *testing.T) {
|
|||
ID: newTestIDPtr(13),
|
||||
Name: "endpoint_0",
|
||||
Description: "desc",
|
||||
Status: influxdb.TaskStatusActive,
|
||||
Status: taskmodel.TaskStatusActive,
|
||||
},
|
||||
ClientURL: "http://example.com",
|
||||
RoutingKey: influxdb.SecretField{Key: "-routing-key"},
|
||||
|
@ -3576,7 +3576,7 @@ func TestService(t *testing.T) {
|
|||
ID: newTestIDPtr(13),
|
||||
Name: "endpoint_0",
|
||||
Description: "desc",
|
||||
Status: influxdb.TaskStatusInactive,
|
||||
Status: taskmodel.TaskStatusInactive,
|
||||
},
|
||||
URL: "http://example.com",
|
||||
Token: influxdb.SecretField{Key: "tokne"},
|
||||
|
@ -3594,7 +3594,7 @@ func TestService(t *testing.T) {
|
|||
ID: newTestIDPtr(13),
|
||||
Name: "endpoint_0",
|
||||
Description: "desc",
|
||||
Status: influxdb.TaskStatusInactive,
|
||||
Status: taskmodel.TaskStatusInactive,
|
||||
},
|
||||
AuthMethod: "none",
|
||||
Method: "GET",
|
||||
|
@ -3705,7 +3705,7 @@ func TestService(t *testing.T) {
|
|||
ID: &id,
|
||||
Name: "endpoint_0",
|
||||
Description: "desc",
|
||||
Status: influxdb.TaskStatusInactive,
|
||||
Status: taskmodel.TaskStatusInactive,
|
||||
},
|
||||
AuthMethod: "none",
|
||||
Method: "GET",
|
||||
|
@ -3950,27 +3950,27 @@ func TestService(t *testing.T) {
|
|||
tests := []struct {
|
||||
name string
|
||||
newName string
|
||||
task influxdb.Task
|
||||
task taskmodel.Task
|
||||
}{
|
||||
{
|
||||
name: "every offset is set",
|
||||
newName: "new name",
|
||||
task: influxdb.Task{
|
||||
task: taskmodel.Task{
|
||||
ID: 1,
|
||||
Name: "name_9000",
|
||||
Every: time.Minute.String(),
|
||||
Offset: 10 * time.Second,
|
||||
Type: influxdb.TaskSystemType,
|
||||
Type: taskmodel.TaskSystemType,
|
||||
Flux: `option task = { name: "larry" } from(bucket: "rucket") |> yield()`,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "cron is set",
|
||||
task: influxdb.Task{
|
||||
task: taskmodel.Task{
|
||||
ID: 1,
|
||||
Name: "name_0",
|
||||
Cron: "2 * * * *",
|
||||
Type: influxdb.TaskSystemType,
|
||||
Type: taskmodel.TaskSystemType,
|
||||
Flux: `option task = { name: "larry" } from(bucket: "rucket") |> yield()`,
|
||||
},
|
||||
},
|
||||
|
@ -3979,14 +3979,14 @@ func TestService(t *testing.T) {
|
|||
for _, tt := range tests {
|
||||
fn := func(t *testing.T) {
|
||||
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 {
|
||||
return nil, errors.New("wrong id provided: " + id.String())
|
||||
}
|
||||
return &tt.task, nil
|
||||
}
|
||||
taskSVC.FindTasksFn = func(ctx context.Context, filter influxdb.TaskFilter) ([]*influxdb.Task, int, error) {
|
||||
return []*influxdb.Task{&tt.task}, 1, nil
|
||||
taskSVC.FindTasksFn = func(ctx context.Context, filter taskmodel.TaskFilter) ([]*taskmodel.Task, int, error) {
|
||||
return []*taskmodel.Task{&tt.task}, 1, nil
|
||||
}
|
||||
|
||||
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) {
|
||||
taskSVC := mock.NewTaskService()
|
||||
taskSVC.FindTaskByIDFn = func(ctx context.Context, id platform.ID) (*influxdb.Task, error) {
|
||||
return &influxdb.Task{
|
||||
taskSVC.FindTaskByIDFn = func(ctx context.Context, id platform.ID) (*taskmodel.Task, error) {
|
||||
return &taskmodel.Task{
|
||||
ID: id,
|
||||
Type: influxdb.TaskSystemType,
|
||||
Type: taskmodel.TaskSystemType,
|
||||
Name: "same name",
|
||||
Description: "desc",
|
||||
Status: influxdb.TaskStatusActive,
|
||||
Status: taskmodel.TaskStatusActive,
|
||||
Flux: `from(bucket: "foo")`,
|
||||
Every: "5m0s",
|
||||
}, nil
|
||||
|
@ -4071,14 +4071,14 @@ func TestService(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("tasks by name", func(t *testing.T) {
|
||||
knownTasks := []*influxdb.Task{
|
||||
knownTasks := []*taskmodel.Task{
|
||||
{
|
||||
ID: 1,
|
||||
Name: "task",
|
||||
Description: "task 1",
|
||||
Every: time.Minute.String(),
|
||||
Offset: 10 * time.Second,
|
||||
Type: influxdb.TaskSystemType,
|
||||
Type: taskmodel.TaskSystemType,
|
||||
Flux: `option task = { name: "larry" } from(bucket: "rucket") |> yield()`,
|
||||
},
|
||||
{
|
||||
|
@ -4086,7 +4086,7 @@ func TestService(t *testing.T) {
|
|||
Name: "taskCopy",
|
||||
Description: "task 2",
|
||||
Cron: "2 * * * *",
|
||||
Type: influxdb.TaskSystemType,
|
||||
Type: taskmodel.TaskSystemType,
|
||||
Flux: `option task = { name: "curly" } from(bucket: "rucket") |> yield()`,
|
||||
},
|
||||
{
|
||||
|
@ -4094,7 +4094,7 @@ func TestService(t *testing.T) {
|
|||
Name: "taskCopy",
|
||||
Description: "task 3",
|
||||
Cron: "2 3 4 5 *",
|
||||
Type: influxdb.TaskSystemType,
|
||||
Type: taskmodel.TaskSystemType,
|
||||
Flux: `option task = { name: "moe" } from(bucket: "rucket") |> yield()`,
|
||||
},
|
||||
}
|
||||
|
@ -4103,17 +4103,17 @@ func TestService(t *testing.T) {
|
|||
name string
|
||||
findName string
|
||||
findID platform.ID
|
||||
expected []*influxdb.Task
|
||||
expected []*taskmodel.Task
|
||||
}{
|
||||
{
|
||||
name: "find task with unique name",
|
||||
findName: "task",
|
||||
expected: []*influxdb.Task{knownTasks[0]},
|
||||
expected: []*taskmodel.Task{knownTasks[0]},
|
||||
},
|
||||
{
|
||||
name: "find multiple tasks with shared name",
|
||||
findName: "taskCopy",
|
||||
expected: []*influxdb.Task{knownTasks[1], knownTasks[2]},
|
||||
expected: []*taskmodel.Task{knownTasks[1], knownTasks[2]},
|
||||
},
|
||||
{
|
||||
name: "find no tasks",
|
||||
|
@ -4123,20 +4123,20 @@ func TestService(t *testing.T) {
|
|||
{
|
||||
name: "find task by id",
|
||||
findID: platform.ID(2),
|
||||
expected: []*influxdb.Task{knownTasks[1]},
|
||||
expected: []*taskmodel.Task{knownTasks[1]},
|
||||
},
|
||||
{
|
||||
name: "find by id, set new name",
|
||||
findID: platform.ID(2),
|
||||
findName: "renamedTask",
|
||||
expected: []*influxdb.Task{knownTasks[1]},
|
||||
expected: []*taskmodel.Task{knownTasks[1]},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
fn := func(t *testing.T) {
|
||||
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 {
|
||||
if knownTasks[i].ID == id {
|
||||
return knownTasks[i], nil
|
||||
|
@ -4145,8 +4145,8 @@ func TestService(t *testing.T) {
|
|||
|
||||
return nil, errors.New("wrong id provided: " + id.String())
|
||||
}
|
||||
taskSVC.FindTasksFn = func(ctx context.Context, filter influxdb.TaskFilter) ([]*influxdb.Task, int, error) {
|
||||
tasks := []*influxdb.Task{}
|
||||
taskSVC.FindTasksFn = func(ctx context.Context, filter taskmodel.TaskFilter) ([]*taskmodel.Task, int, error) {
|
||||
tasks := []*taskmodel.Task{}
|
||||
for i := range knownTasks {
|
||||
if knownTasks[i].Name == *filter.Name {
|
||||
tasks = append(tasks, knownTasks[i])
|
||||
|
@ -4850,27 +4850,27 @@ func TestService(t *testing.T) {
|
|||
}
|
||||
|
||||
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 {
|
||||
return nil, 0, nil
|
||||
}
|
||||
return []*influxdb.Task{
|
||||
{ID: 31, Type: influxdb.TaskSystemType},
|
||||
{ID: expectedCheck.TaskID, Type: influxdb.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
|
||||
return []*taskmodel.Task{
|
||||
{ID: 31, Type: taskmodel.TaskSystemType},
|
||||
{ID: expectedCheck.TaskID, Type: taskmodel.TaskSystemType}, // this one should be ignored in the return
|
||||
{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
|
||||
}, 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 {
|
||||
return nil, errors.New("wrong id: " + id.String())
|
||||
}
|
||||
return &influxdb.Task{
|
||||
return &taskmodel.Task{
|
||||
ID: id,
|
||||
Name: "task_0",
|
||||
Every: time.Minute.String(),
|
||||
Offset: 10 * time.Second,
|
||||
Type: influxdb.TaskSystemType,
|
||||
Type: taskmodel.TaskSystemType,
|
||||
Flux: `option task = { name: "larry" } from(bucket: "rucket") |> yield()`,
|
||||
}, nil
|
||||
}
|
||||
|
|
35
query.go
35
query.go
|
@ -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
|
||||
}
|
|
@ -10,11 +10,31 @@ import (
|
|||
"github.com/influxdata/flux/parser"
|
||||
"github.com/influxdata/flux/runtime"
|
||||
"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.
|
||||
var DefaultService influxdb.FluxLanguageService = defaultService{}
|
||||
var DefaultService FluxLanguageService = defaultService{}
|
||||
|
||||
type defaultService struct{}
|
||||
|
||||
|
|
|
@ -4,14 +4,13 @@ import (
|
|||
"context"
|
||||
"io"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform/errors"
|
||||
|
||||
"github.com/influxdata/flux"
|
||||
"github.com/influxdata/flux/ast"
|
||||
"github.com/influxdata/flux/interpreter"
|
||||
"github.com/influxdata/flux/values"
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
"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.
|
||||
|
@ -46,7 +45,7 @@ type ProxyQueryService interface {
|
|||
// but it may be null if parsing didn't even occur.
|
||||
//
|
||||
// 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 {
|
||||
return nil, &errors.Error{
|
||||
Code: errors.EInternal,
|
||||
|
@ -59,7 +58,7 @@ func Parse(lang influxdb.FluxLanguageService, source string) (*ast.Package, erro
|
|||
// EvalAST will evaluate and run an AST.
|
||||
//
|
||||
// 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 {
|
||||
return nil, nil, &errors.Error{
|
||||
Code: errors.EInternal,
|
||||
|
|
|
@ -7,15 +7,15 @@ import (
|
|||
"fmt"
|
||||
"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/lang"
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
"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/storage"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
@ -34,23 +34,11 @@ const (
|
|||
// RunRecorder is a type which records runs into an influxdb
|
||||
// backed storage mechanism
|
||||
type RunRecorder interface {
|
||||
Record(ctx context.Context, orgID platform.ID, org string, bucketID platform.ID, bucket string, run *influxdb.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,
|
||||
}
|
||||
Record(ctx context.Context, orgID platform.ID, org string, bucketID platform.ID, bucket string, run *taskmodel.Run) error
|
||||
}
|
||||
|
||||
// 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{
|
||||
log: log,
|
||||
TaskService: ts,
|
||||
|
@ -62,7 +50,7 @@ func NewAnalyticalStorage(log *zap.Logger, ts influxdb.TaskService, bs influxdb.
|
|||
}
|
||||
|
||||
type AnalyticalStorage struct {
|
||||
influxdb.TaskService
|
||||
taskmodel.TaskService
|
||||
influxdb.BucketService
|
||||
TaskControlService
|
||||
|
||||
|
@ -71,7 +59,7 @@ type AnalyticalStorage struct {
|
|||
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)
|
||||
if run != nil && run.ID.String() != "" {
|
||||
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.
|
||||
// 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) {
|
||||
var logs []*influxdb.Log
|
||||
func (as *AnalyticalStorage) FindLogs(ctx context.Context, filter taskmodel.LogFilter) ([]*taskmodel.Log, int, error) {
|
||||
var logs []*taskmodel.Log
|
||||
if filter.Run != nil {
|
||||
run, err := as.FindRunByID(ctx, filter.Task, *filter.Run)
|
||||
if err != nil {
|
||||
|
@ -106,7 +94,7 @@ func (as *AnalyticalStorage) FindLogs(ctx context.Context, filter influxdb.LogFi
|
|||
}
|
||||
|
||||
// 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 {
|
||||
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.
|
||||
// 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 {
|
||||
filter.Limit = influxdb.TaskDefaultPageSize
|
||||
filter.Limit = taskmodel.TaskDefaultPageSize
|
||||
}
|
||||
|
||||
if filter.Limit < 0 || filter.Limit > influxdb.TaskMaxPageSize {
|
||||
return nil, 0, influxdb.ErrOutOfBoundsLimit
|
||||
if filter.Limit < 0 || filter.Limit > taskmodel.TaskMaxPageSize {
|
||||
return nil, 0, taskmodel.ErrOutOfBoundsLimit
|
||||
}
|
||||
|
||||
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
|
||||
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{}
|
||||
|
||||
// track the current runs
|
||||
|
@ -263,7 +251,7 @@ func (as *AnalyticalStorage) combineRuns(currentRuns, completeRuns []*influxdb.R
|
|||
|
||||
// FindRunByID returns a single run.
|
||||
// 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
|
||||
run, err := as.TaskService.FindRunByID(ctx, taskID, runID)
|
||||
if err != nil {
|
||||
|
@ -334,7 +322,7 @@ func (as *AnalyticalStorage) FindRunByID(ctx context.Context, taskID, runID plat
|
|||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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)
|
||||
if err != nil {
|
||||
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 {
|
||||
runs []*influxdb.Run
|
||||
runs []*taskmodel.Run
|
||||
log *zap.Logger
|
||||
}
|
||||
|
||||
|
@ -382,7 +370,7 @@ func (re *runReader) readTable(tbl flux.Table) error {
|
|||
|
||||
func (re *runReader) readRuns(cr flux.ColReader) error {
|
||||
for i := 0; i < cr.Len(); i++ {
|
||||
var r influxdb.Run
|
||||
var r taskmodel.Run
|
||||
for j, col := range cr.Cols() {
|
||||
switch col.Label {
|
||||
case runIDField:
|
||||
|
|
|
@ -7,8 +7,6 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/influxdata/flux"
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
|
@ -16,6 +14,7 @@ import (
|
|||
icontext "github.com/influxdata/influxdb/v2/context"
|
||||
_ "github.com/influxdata/influxdb/v2/fluxinit/static"
|
||||
"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/migration/all"
|
||||
"github.com/influxdata/influxdb/v2/mock"
|
||||
|
@ -27,6 +26,7 @@ import (
|
|||
storageflux "github.com/influxdata/influxdb/v2/storage/flux"
|
||||
"github.com/influxdata/influxdb/v2/task/backend"
|
||||
"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/v1/services/meta"
|
||||
storage2 "github.com/influxdata/influxdb/v2/v1/services/storage"
|
||||
|
@ -62,8 +62,7 @@ func TestAnalyticalStore(t *testing.T) {
|
|||
|
||||
var (
|
||||
ab = newAnalyticalBackend(t, ts.OrganizationService, ts.BucketService, metaClient)
|
||||
rr = backend.NewStoragePointsWriterRecorder(logger, ab.PointsWriter())
|
||||
svcStack = backend.NewAnalyticalRunStorage(logger, svc, ts.BucketService, svc, rr, ab.QueryService())
|
||||
svcStack = backend.NewAnalyticalStorage(logger, svc, ts.BucketService, svc, ab.PointsWriter(), ab.QueryService())
|
||||
)
|
||||
|
||||
ts.BucketService = storage.NewBucketService(logger, ts.BucketService, ab.storageEngine)
|
||||
|
@ -112,18 +111,18 @@ func TestDeduplicateRuns(t *testing.T) {
|
|||
defer ab.Close(t)
|
||||
|
||||
mockTS := &mock.TaskService{
|
||||
FindTaskByIDFn: func(context.Context, platform.ID) (*influxdb.Task, error) {
|
||||
return &influxdb.Task{ID: 1, OrganizationID: 20}, nil
|
||||
FindTaskByIDFn: func(context.Context, platform.ID) (*taskmodel.Task, error) {
|
||||
return &taskmodel.Task{ID: 1, OrganizationID: 20}, nil
|
||||
},
|
||||
FindRunsFn: func(context.Context, influxdb.RunFilter) ([]*influxdb.Run, int, error) {
|
||||
return []*influxdb.Run{
|
||||
&influxdb.Run{ID: 2, Status: "started"},
|
||||
FindRunsFn: func(context.Context, taskmodel.RunFilter) ([]*taskmodel.Run, int, error) {
|
||||
return []*taskmodel.Run{
|
||||
&taskmodel.Run{ID: 2, Status: "started"},
|
||||
}, 1, nil
|
||||
},
|
||||
}
|
||||
mockTCS := &mock.TaskControlService{
|
||||
FinishRunFn: func(ctx context.Context, taskID, runID platform.ID) (*influxdb.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
|
||||
FinishRunFn: func(ctx context.Context, taskID, runID platform.ID) (*taskmodel.Run, error) {
|
||||
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()
|
||||
|
@ -135,7 +134,7 @@ func TestDeduplicateRuns(t *testing.T) {
|
|||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -5,8 +5,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
@ -16,21 +15,21 @@ var now = func() time.Time {
|
|||
|
||||
// TaskService is a type on which tasks can be listed
|
||||
type TaskService interface {
|
||||
FindTasks(context.Context, influxdb.TaskFilter) ([]*influxdb.Task, int, error)
|
||||
UpdateTask(context.Context, platform.ID, influxdb.TaskUpdate) (*influxdb.Task, error)
|
||||
FindTasks(context.Context, taskmodel.TaskFilter) ([]*taskmodel.Task, int, error)
|
||||
UpdateTask(context.Context, platform.ID, taskmodel.TaskUpdate) (*taskmodel.Task, error)
|
||||
}
|
||||
|
||||
// Coordinator is a type with a single method which
|
||||
// is called when a task has been created
|
||||
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
|
||||
// each task it calls the provided coordinators task created method
|
||||
func NotifyCoordinatorOfExisting(ctx context.Context, log *zap.Logger, ts TaskService, coord Coordinator) error {
|
||||
// If we missed a Create Action
|
||||
tasks, _, err := ts.FindTasks(ctx, influxdb.TaskFilter{})
|
||||
tasks, _, err := ts.FindTasks(ctx, taskmodel.TaskFilter{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -38,11 +37,11 @@ func NotifyCoordinatorOfExisting(ctx context.Context, log *zap.Logger, ts TaskSe
|
|||
latestCompleted := now()
|
||||
for len(tasks) > 0 {
|
||||
for _, task := range tasks {
|
||||
if task.Status != string(influxdb.TaskActive) {
|
||||
if task.Status != string(taskmodel.TaskActive) {
|
||||
continue
|
||||
}
|
||||
|
||||
task, err := ts.UpdateTask(context.Background(), task.ID, influxdb.TaskUpdate{
|
||||
task, err := ts.UpdateTask(context.Background(), task.ID, taskmodel.TaskUpdate{
|
||||
LatestCompleted: &latestCompleted,
|
||||
LatestScheduled: &latestCompleted,
|
||||
})
|
||||
|
@ -54,7 +53,7 @@ func NotifyCoordinatorOfExisting(ctx context.Context, log *zap.Logger, ts TaskSe
|
|||
coord.TaskCreated(ctx, task)
|
||||
}
|
||||
|
||||
tasks, _, err = ts.FindTasks(ctx, influxdb.TaskFilter{
|
||||
tasks, _, err = ts.FindTasks(ctx, taskmodel.TaskFilter{
|
||||
After: &tasks[len(tasks)-1].ID,
|
||||
})
|
||||
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
|
||||
func TaskNotifyCoordinatorOfExisting(ctx context.Context, ts TaskService, tcs TaskControlService, coord Coordinator, exec TaskResumer, log *zap.Logger) error {
|
||||
// If we missed a Create Action
|
||||
tasks, _, err := ts.FindTasks(ctx, influxdb.TaskFilter{})
|
||||
tasks, _, err := ts.FindTasks(ctx, taskmodel.TaskFilter{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -80,11 +79,11 @@ func TaskNotifyCoordinatorOfExisting(ctx context.Context, ts TaskService, tcs Ta
|
|||
latestCompleted := now()
|
||||
for len(tasks) > 0 {
|
||||
for _, task := range tasks {
|
||||
if task.Status != string(influxdb.TaskActive) {
|
||||
if task.Status != string(taskmodel.TaskActive) {
|
||||
continue
|
||||
}
|
||||
|
||||
task, err := ts.UpdateTask(context.Background(), task.ID, influxdb.TaskUpdate{
|
||||
task, err := ts.UpdateTask(context.Background(), task.ID, taskmodel.TaskUpdate{
|
||||
LatestCompleted: &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,
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
@ -6,11 +6,10 @@ import (
|
|||
"time"
|
||||
|
||||
"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/middleware"
|
||||
"github.com/influxdata/influxdb/v2/task/backend/scheduler"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
"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
|
||||
type SchedulableTask struct {
|
||||
*influxdb.Task
|
||||
*taskmodel.Task
|
||||
sch scheduler.Schedule
|
||||
lsc time.Time
|
||||
}
|
||||
|
@ -70,7 +69,7 @@ func WithLimitOpt(i int) CoordinatorOption {
|
|||
}
|
||||
|
||||
// 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 == "" {
|
||||
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
|
||||
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)
|
||||
|
||||
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
|
||||
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)
|
||||
t, err := NewSchedulableTask(to)
|
||||
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 to.Status != from.Status && to.Status == string(influxdb.TaskInactive) {
|
||||
if err := c.sch.Release(sid); err != nil && err != influxdb.ErrTaskNotClaimed {
|
||||
if to.Status != from.Status && to.Status == string(taskmodel.TaskInactive) {
|
||||
if err := c.sch.Release(sid); err != nil && err != taskmodel.ErrTaskNotClaimed {
|
||||
return err
|
||||
}
|
||||
} 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
|
||||
func (c *Coordinator) TaskDeleted(ctx context.Context, id platform.ID) error {
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
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)
|
||||
if err != nil {
|
||||
return influxdb.ErrRunExecutionError(err)
|
||||
return taskmodel.ErrRunExecutionError(err)
|
||||
}
|
||||
|
||||
<-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
|
||||
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)
|
||||
if err != nil {
|
||||
return influxdb.ErrRunExecutionError(err)
|
||||
return taskmodel.ErrRunExecutionError(err)
|
||||
}
|
||||
|
||||
<-promise.Done()
|
||||
|
|
|
@ -6,21 +6,20 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"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/taskmodel"
|
||||
"go.uber.org/zap/zaptest"
|
||||
)
|
||||
|
||||
func Test_Coordinator_Executor_Methods(t *testing.T) {
|
||||
var (
|
||||
one = platform.ID(1)
|
||||
taskOne = &influxdb.Task{ID: one}
|
||||
taskOne = &taskmodel.Task{ID: one}
|
||||
|
||||
runOne = &influxdb.Run{
|
||||
runOne = &taskmodel.Run{
|
||||
ID: one,
|
||||
TaskID: one,
|
||||
ScheduledFor: time.Now(),
|
||||
|
@ -99,7 +98,7 @@ func Test_Coordinator_Executor_Methods(t *testing.T) {
|
|||
func TestNewSchedulableTask(t *testing.T) {
|
||||
now := time.Now().UTC()
|
||||
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)
|
||||
if err != nil {
|
||||
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())
|
||||
}
|
||||
|
||||
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)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -128,17 +127,17 @@ func Test_Coordinator_Scheduler_Methods(t *testing.T) {
|
|||
three = platform.ID(3)
|
||||
now = time.Now().UTC()
|
||||
|
||||
taskOne = &influxdb.Task{ID: one, CreatedAt: now, Cron: "* * * * *"}
|
||||
taskTwo = &influxdb.Task{ID: two, Status: "active", CreatedAt: now, Cron: "* * * * *"}
|
||||
taskTwoInactive = &influxdb.Task{ID: two, Status: "inactive", CreatedAt: now, Cron: "* * * * *"}
|
||||
taskThreeOriginal = &influxdb.Task{
|
||||
taskOne = &taskmodel.Task{ID: one, CreatedAt: now, Cron: "* * * * *"}
|
||||
taskTwo = &taskmodel.Task{ID: two, Status: "active", CreatedAt: now, Cron: "* * * * *"}
|
||||
taskTwoInactive = &taskmodel.Task{ID: two, Status: "inactive", CreatedAt: now, Cron: "* * * * *"}
|
||||
taskThreeOriginal = &taskmodel.Task{
|
||||
ID: three,
|
||||
Status: "active",
|
||||
Name: "Previous",
|
||||
CreatedAt: now,
|
||||
Cron: "* * * * *",
|
||||
}
|
||||
taskThreeNew = &influxdb.Task{
|
||||
taskThreeNew = &taskmodel.Task{
|
||||
ID: three,
|
||||
Status: "active",
|
||||
Name: "Renamed",
|
||||
|
@ -161,7 +160,7 @@ func Test_Coordinator_Scheduler_Methods(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
runOne := &influxdb.Run{
|
||||
runOne := &taskmodel.Run{
|
||||
ID: one,
|
||||
TaskID: one,
|
||||
ScheduledFor: time.Now().UTC(),
|
||||
|
|
|
@ -4,10 +4,9 @@ import (
|
|||
"context"
|
||||
|
||||
"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/scheduler"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
)
|
||||
|
||||
var _ Executor = (*executorE)(nil)
|
||||
|
@ -45,7 +44,7 @@ type (
|
|||
|
||||
type (
|
||||
promise struct {
|
||||
run *influxdb.Run
|
||||
run *taskmodel.Run
|
||||
|
||||
done chan struct{}
|
||||
err error
|
||||
|
|
|
@ -5,10 +5,9 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
|
@ -20,12 +19,12 @@ var (
|
|||
|
||||
aTime = time.Now().UTC()
|
||||
|
||||
taskOne = &influxdb.Task{ID: one}
|
||||
taskTwo = &influxdb.Task{ID: two, Status: "active"}
|
||||
taskThree = &influxdb.Task{ID: three, Status: "inactive"}
|
||||
taskFour = &influxdb.Task{ID: four}
|
||||
taskOne = &taskmodel.Task{ID: one}
|
||||
taskTwo = &taskmodel.Task{ID: two, Status: "active"}
|
||||
taskThree = &taskmodel.Task{ID: three, Status: "inactive"}
|
||||
taskFour = &taskmodel.Task{ID: four}
|
||||
|
||||
allTasks = map[platform.ID]*influxdb.Task{
|
||||
allTasks = map[platform.ID]*taskmodel.Task{
|
||||
one: taskOne,
|
||||
two: taskTwo,
|
||||
three: taskThree,
|
||||
|
@ -38,8 +37,8 @@ func Test_NotifyCoordinatorOfCreated(t *testing.T) {
|
|||
coordinator = &coordinator{}
|
||||
tasks = &taskService{
|
||||
// paginated responses
|
||||
pageOne: []*influxdb.Task{taskOne},
|
||||
otherPages: map[platform.ID][]*influxdb.Task{
|
||||
pageOne: []*taskmodel.Task{taskOne},
|
||||
otherPages: map[platform.ID][]*taskmodel.Task{
|
||||
one: {taskTwo, taskThree},
|
||||
three: {taskFour},
|
||||
},
|
||||
|
@ -57,12 +56,12 @@ func Test_NotifyCoordinatorOfCreated(t *testing.T) {
|
|||
}
|
||||
|
||||
if diff := cmp.Diff([]update{
|
||||
{two, influxdb.TaskUpdate{LatestCompleted: &aTime, LatestScheduled: &aTime}},
|
||||
{two, taskmodel.TaskUpdate{LatestCompleted: &aTime, LatestScheduled: &aTime}},
|
||||
}, tasks.updates); diff != "" {
|
||||
t.Errorf("unexpected updates to task service %v", diff)
|
||||
}
|
||||
|
||||
if diff := cmp.Diff([]*influxdb.Task{
|
||||
if diff := cmp.Diff([]*taskmodel.Task{
|
||||
taskTwo,
|
||||
}, coordinator.tasks); diff != "" {
|
||||
t.Errorf("unexpected tasks sent to coordinator %v", diff)
|
||||
|
@ -70,10 +69,10 @@ func Test_NotifyCoordinatorOfCreated(t *testing.T) {
|
|||
}
|
||||
|
||||
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)
|
||||
|
||||
return nil
|
||||
|
@ -82,27 +81,27 @@ func (c *coordinator) TaskCreated(_ context.Context, task *influxdb.Task) error
|
|||
// TasksService mocking
|
||||
type taskService struct {
|
||||
// paginated tasks
|
||||
pageOne []*influxdb.Task
|
||||
otherPages map[platform.ID][]*influxdb.Task
|
||||
pageOne []*taskmodel.Task
|
||||
otherPages map[platform.ID][]*taskmodel.Task
|
||||
|
||||
// find tasks call
|
||||
filter influxdb.TaskFilter
|
||||
filter taskmodel.TaskFilter
|
||||
// update call
|
||||
updates []update
|
||||
}
|
||||
|
||||
type update struct {
|
||||
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})
|
||||
|
||||
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
|
||||
|
||||
if filter.After == nil {
|
||||
|
|
|
@ -7,8 +7,6 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
|
||||
"github.com/influxdata/flux"
|
||||
"github.com/influxdata/flux/ast"
|
||||
"github.com/influxdata/flux/lang"
|
||||
|
@ -16,10 +14,12 @@ import (
|
|||
"github.com/influxdata/influxdb/v2"
|
||||
icontext "github.com/influxdata/influxdb/v2/context"
|
||||
"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/query"
|
||||
"github.com/influxdata/influxdb/v2/task/backend"
|
||||
"github.com/influxdata/influxdb/v2/task/backend/scheduler"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
"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.
|
||||
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 {
|
||||
if err := lf(task, run); err != nil {
|
||||
return err
|
||||
|
@ -56,7 +56,7 @@ func MultiLimit(limits ...LimitFunc) LimitFunc {
|
|||
}
|
||||
|
||||
// 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 {
|
||||
maxWorkers int
|
||||
|
@ -127,7 +127,7 @@ func WithFlagger(flagger feature.Flagger) executorOption {
|
|||
}
|
||||
|
||||
// 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{
|
||||
maxWorkers: defaultMaxWorkers,
|
||||
systemBuildCompiler: NewASTCompiler,
|
||||
|
@ -147,7 +147,7 @@ func NewExecutor(log *zap.Logger, qs query.QueryService, us PermissionService, t
|
|||
currentPromises: sync.Map{},
|
||||
promiseQueue: make(chan *promise, maxPromises),
|
||||
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,
|
||||
nonSystemBuildCompiler: cfg.nonSystemBuildCompiler,
|
||||
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.
|
||||
type Executor struct {
|
||||
log *zap.Logger
|
||||
ts influxdb.TaskService
|
||||
ts taskmodel.TaskService
|
||||
tcs backend.TaskControlService
|
||||
|
||||
qs query.QueryService
|
||||
|
@ -251,7 +251,7 @@ func (e *Executor) ResumeCurrentRun(ctx context.Context, id platform.ID, runID p
|
|||
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) {
|
||||
|
@ -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 {
|
||||
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))
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
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)
|
||||
defer span.Finish()
|
||||
|
||||
|
@ -411,8 +411,8 @@ func (w *worker) work() {
|
|||
// If done the promise was canceled
|
||||
case <-prom.ctx.Done():
|
||||
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)
|
||||
prom.err = influxdb.ErrRunCanceled
|
||||
w.e.tcs.UpdateRunState(prom.ctx, prom.task.ID, prom.run.ID, time.Now().UTC(), taskmodel.RunCanceled)
|
||||
prom.err = taskmodel.ErrRunCanceled
|
||||
close(prom.done)
|
||||
return
|
||||
case <-time.After(time.Second):
|
||||
|
@ -438,14 +438,14 @@ func (w *worker) start(p *promise) {
|
|||
// 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))
|
||||
// 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
|
||||
w.e.metrics.StartRun(p.task, time.Since(p.createdAt), time.Since(p.run.RunAt))
|
||||
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)
|
||||
defer span.Finish()
|
||||
|
||||
|
@ -496,7 +496,7 @@ func (w *worker) executeQuery(p *promise) {
|
|||
ctx = icontext.SetAuthorizer(ctx, p.auth)
|
||||
|
||||
buildCompiler := w.systemBuildCompiler
|
||||
if p.task.Type != influxdb.TaskSystemType {
|
||||
if p.task.Type != taskmodel.TaskSystemType {
|
||||
buildCompiler = w.nonSystemBuildCompiler
|
||||
}
|
||||
compiler, err := buildCompiler(ctx, p.task.Flux, CompilerBuilderTimestamps{
|
||||
|
@ -504,7 +504,7 @@ func (w *worker) executeQuery(p *promise) {
|
|||
LatestSuccess: p.task.LatestSuccess,
|
||||
})
|
||||
if err != nil {
|
||||
w.finish(p, influxdb.RunFail, influxdb.ErrFluxParseError(err))
|
||||
w.finish(p, taskmodel.RunFail, taskmodel.ErrFluxParseError(err))
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -517,7 +517,7 @@ func (w *worker) executeQuery(p *promise) {
|
|||
it, err := w.e.qs.Query(ctx, req)
|
||||
if err != nil {
|
||||
// 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
|
||||
}
|
||||
|
||||
|
@ -540,16 +540,16 @@ func (w *worker) executeQuery(p *promise) {
|
|||
}
|
||||
|
||||
if runErr != nil {
|
||||
w.finish(p, influxdb.RunFail, influxdb.ErrRunExecutionError(runErr))
|
||||
w.finish(p, taskmodel.RunFail, taskmodel.ErrRunExecutionError(runErr))
|
||||
return
|
||||
}
|
||||
|
||||
if it.Err() != nil {
|
||||
w.finish(p, influxdb.RunFail, influxdb.ErrResultIteratorError(it.Err()))
|
||||
w.finish(p, taskmodel.RunFail, taskmodel.ErrResultIteratorError(it.Err()))
|
||||
return
|
||||
}
|
||||
|
||||
w.finish(p, influxdb.RunSuccess, nil)
|
||||
w.finish(p, taskmodel.RunSuccess, nil)
|
||||
}
|
||||
|
||||
// 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.
|
||||
type promise struct {
|
||||
run *influxdb.Run
|
||||
task *influxdb.Task
|
||||
run *taskmodel.Run
|
||||
task *taskmodel.Task
|
||||
auth *influxdb.Authorization
|
||||
|
||||
done chan struct{}
|
||||
|
|
|
@ -5,8 +5,7 @@ import (
|
|||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
"github.com/influxdata/influxdb/v2/kit/platform/errors"
|
||||
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
"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.
|
||||
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.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.
|
||||
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.runDuration.WithLabelValues(task.Type, "all").Observe(runDuration.Seconds())
|
||||
|
|
|
@ -10,14 +10,13 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/influxdata/flux"
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
"github.com/influxdata/influxdb/v2/authorization"
|
||||
icontext "github.com/influxdata/influxdb/v2/context"
|
||||
"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/promtest"
|
||||
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/executor/mock"
|
||||
"github.com/influxdata/influxdb/v2/task/backend/scheduler"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
"github.com/influxdata/influxdb/v2/tenant"
|
||||
"github.com/opentracing/opentracing-go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -123,7 +123,7 @@ func testQuerySuccess(t *testing.T) {
|
|||
)
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ func testQueryFailure(t *testing.T) {
|
|||
|
||||
script := fmt.Sprintf(fmtTestScript, t.Name())
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -221,7 +221,7 @@ func testManualRun(t *testing.T) {
|
|||
|
||||
script := fmt.Sprintf(fmtTestScript, t.Name())
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -268,7 +268,7 @@ func testResumingRun(t *testing.T) {
|
|||
|
||||
script := fmt.Sprintf(fmtTestScript, t.Name())
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -284,7 +284,7 @@ func testResumingRun(t *testing.T) {
|
|||
}
|
||||
|
||||
// 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")
|
||||
}
|
||||
|
||||
|
@ -311,7 +311,7 @@ func testWorkerLimit(t *testing.T) {
|
|||
|
||||
script := fmt.Sprintf(fmtTestScript, t.Name())
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -341,16 +341,16 @@ func testLimitFunc(t *testing.T) {
|
|||
|
||||
script := fmt.Sprintf(fmtTestScript, t.Name())
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
forcedErr := errors.New("forced")
|
||||
forcedQueryErr := influxdb.ErrQueryError(forcedErr)
|
||||
forcedQueryErr := taskmodel.ErrQueryError(forcedErr)
|
||||
tes.svc.FailNextQuery(forcedErr)
|
||||
|
||||
count := 0
|
||||
tes.ex.SetLimitFunc(func(*influxdb.Task, *influxdb.Run) error {
|
||||
tes.ex.SetLimitFunc(func(*taskmodel.Task, *taskmodel.Run) error {
|
||||
count++
|
||||
if count < 2 {
|
||||
return errors.New("not there yet")
|
||||
|
@ -387,7 +387,7 @@ func testMetrics(t *testing.T) {
|
|||
|
||||
script := fmt.Sprintf(fmtTestScript, t.Name())
|
||||
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)
|
||||
|
||||
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())
|
||||
|
||||
// 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)
|
||||
|
||||
scheduledFor := int64(123)
|
||||
|
@ -463,7 +463,7 @@ func testIteratorFailure(t *testing.T) {
|
|||
|
||||
script := fmt.Sprintf(fmtTestScript, t.Name())
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -503,7 +503,7 @@ func testErrorHandling(t *testing.T) {
|
|||
|
||||
script := fmt.Sprintf(fmtTestScript, t.Name())
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -551,7 +551,7 @@ func TestPromiseFailure(t *testing.T) {
|
|||
)
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -569,7 +569,7 @@ func TestPromiseFailure(t *testing.T) {
|
|||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -587,10 +587,10 @@ func TestPromiseFailure(t *testing.T) {
|
|||
type taskControlService struct {
|
||||
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
|
||||
_, err := icontext.GetAuthorizer(ctx)
|
||||
if err != nil {
|
||||
|
|
|
@ -4,14 +4,15 @@ import (
|
|||
"context"
|
||||
"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/taskmodel"
|
||||
)
|
||||
|
||||
// ConcurrencyLimit creates a concurrency limit func that uses the executor to determine
|
||||
// if the task has exceeded the concurrency limit.
|
||||
func ConcurrencyLimit(exec *Executor, lang influxdb.FluxLanguageService) LimitFunc {
|
||||
return func(t *influxdb.Task, r *influxdb.Run) error {
|
||||
func ConcurrencyLimit(exec *Executor, lang fluxlang.FluxLanguageService) LimitFunc {
|
||||
return func(t *taskmodel.Task, r *taskmodel.Run) error {
|
||||
o, err := options.FromScriptAST(lang, t.Flux)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -39,13 +40,13 @@ func ConcurrencyLimit(exec *Executor, lang influxdb.FluxLanguageService) LimitFu
|
|||
for i, run := range runs {
|
||||
if run.ID == r.ID {
|
||||
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.
|
||||
}
|
||||
}
|
||||
// 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
|
||||
}
|
||||
|
|
|
@ -5,13 +5,13 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
"github.com/influxdata/influxdb/v2/query/fluxlang"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
)
|
||||
|
||||
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")`}
|
||||
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")`}
|
||||
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 = &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) {
|
||||
|
@ -30,7 +30,7 @@ func TestTaskConcurrency(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
r4 := &influxdb.Run{
|
||||
r4 := &taskmodel.Run{
|
||||
ID: 3,
|
||||
ScheduledFor: time.Now(),
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
|
||||
"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
|
||||
|
@ -15,12 +15,12 @@ import (
|
|||
type CoordinatingCheckService struct {
|
||||
influxdb.CheckService
|
||||
coordinator Coordinator
|
||||
taskService influxdb.TaskService
|
||||
taskService taskmodel.TaskService
|
||||
Now func() time.Time
|
||||
}
|
||||
|
||||
// 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{
|
||||
CheckService: cs,
|
||||
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
|
||||
// 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()
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
// 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()
|
||||
}
|
||||
|
||||
|
|
|
@ -3,33 +3,34 @@ package middleware_test
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
"github.com/influxdata/influxdb/v2/mock"
|
||||
"github.com/influxdata/influxdb/v2/notification/check"
|
||||
"github.com/influxdata/influxdb/v2/notification/rule"
|
||||
"github.com/influxdata/influxdb/v2/task/backend/middleware"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
)
|
||||
|
||||
type pipingCoordinator struct {
|
||||
err error
|
||||
taskCreatedPipe chan *influxdb.Task
|
||||
taskUpdatedPipe chan *influxdb.Task
|
||||
taskCreatedPipe chan *taskmodel.Task
|
||||
taskUpdatedPipe chan *taskmodel.Task
|
||||
taskDeletedPipe chan platform.ID
|
||||
}
|
||||
|
||||
func (p *pipingCoordinator) taskCreatedChan() <-chan *influxdb.Task {
|
||||
func (p *pipingCoordinator) taskCreatedChan() <-chan *taskmodel.Task {
|
||||
if p.taskCreatedPipe == nil {
|
||||
p.taskCreatedPipe = make(chan *influxdb.Task, 1)
|
||||
p.taskCreatedPipe = make(chan *taskmodel.Task, 1)
|
||||
}
|
||||
return p.taskCreatedPipe
|
||||
}
|
||||
func (p *pipingCoordinator) taskUpdatedChan() <-chan *influxdb.Task {
|
||||
func (p *pipingCoordinator) taskUpdatedChan() <-chan *taskmodel.Task {
|
||||
if p.taskUpdatedPipe == nil {
|
||||
p.taskUpdatedPipe = make(chan *influxdb.Task, 1)
|
||||
p.taskUpdatedPipe = make(chan *taskmodel.Task, 1)
|
||||
}
|
||||
return p.taskUpdatedPipe
|
||||
}
|
||||
|
@ -40,13 +41,13 @@ func (p *pipingCoordinator) taskDeletedChan() <-chan platform.ID {
|
|||
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 {
|
||||
p.taskCreatedPipe <- t
|
||||
}
|
||||
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 {
|
||||
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 {
|
||||
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
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -78,10 +79,10 @@ type mockedSvc struct {
|
|||
func newMockServices() mockedSvc {
|
||||
return mockedSvc{
|
||||
taskSvc: &mock.TaskService{
|
||||
FindTaskByIDFn: func(_ context.Context, id platform.ID) (*influxdb.Task, error) { return &influxdb.Task{ID: id}, nil },
|
||||
CreateTaskFn: func(context.Context, influxdb.TaskCreate) (*influxdb.Task, error) { return &influxdb.Task{ID: 1}, nil },
|
||||
UpdateTaskFn: func(_ context.Context, id platform.ID, _ influxdb.TaskUpdate) (*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, taskmodel.TaskCreate) (*taskmodel.Task, error) { return &taskmodel.Task{ID: 1}, nil },
|
||||
UpdateTaskFn: func(_ context.Context, id platform.ID, _ taskmodel.TaskUpdate) (*taskmodel.Task, error) {
|
||||
return &taskmodel.Task{ID: id}, nil
|
||||
},
|
||||
DeleteTaskFn: func(context.Context, platform.ID) error { return nil },
|
||||
},
|
||||
|
@ -189,13 +190,13 @@ func TestCheckUpdateFromInactive(t *testing.T) {
|
|||
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 {
|
||||
return &influxdb.Task{ID: id, Status: string(influxdb.TaskInactive)}, nil
|
||||
return &taskmodel.Task{ID: id, Status: string(taskmodel.TaskInactive)}, nil
|
||||
} 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{}
|
||||
|
|
|
@ -6,32 +6,31 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
)
|
||||
|
||||
// Coordinator is a type which is used to react to
|
||||
// task related actions
|
||||
type Coordinator interface {
|
||||
TaskCreated(context.Context, *influxdb.Task) error
|
||||
TaskUpdated(ctx context.Context, from, to *influxdb.Task) error
|
||||
TaskCreated(context.Context, *taskmodel.Task) error
|
||||
TaskUpdated(ctx context.Context, from, to *taskmodel.Task) error
|
||||
TaskDeleted(context.Context, platform.ID) error
|
||||
RunCancelled(ctx context.Context, runID platform.ID) error
|
||||
RunRetried(ctx context.Context, task *influxdb.Task, run *influxdb.Run) error
|
||||
RunForced(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 *taskmodel.Task, run *taskmodel.Run) error
|
||||
}
|
||||
|
||||
// CoordinatingTaskService acts as a TaskService decorator that handles coordinating the api request
|
||||
// with the required task control actions asynchronously via a message dispatcher
|
||||
type CoordinatingTaskService struct {
|
||||
influxdb.TaskService
|
||||
taskmodel.TaskService
|
||||
coordinator Coordinator
|
||||
|
||||
now func() time.Time
|
||||
}
|
||||
|
||||
// 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{
|
||||
TaskService: service,
|
||||
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.
|
||||
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)
|
||||
if err != nil {
|
||||
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
|
||||
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)
|
||||
if err != nil {
|
||||
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.
|
||||
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)
|
||||
if err != nil {
|
||||
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.
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -3,13 +3,12 @@ package middleware_test
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
_ "github.com/influxdata/influxdb/v2/fluxinit/static"
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
pmock "github.com/influxdata/influxdb/v2/mock"
|
||||
"github.com/influxdata/influxdb/v2/snowflake"
|
||||
"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/scheduler"
|
||||
"github.com/influxdata/influxdb/v2/task/mock"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
"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)`
|
||||
|
||||
func inmemTaskService() influxdb.TaskService {
|
||||
func inmemTaskService() taskmodel.TaskService {
|
||||
gen := snowflake.NewDefaultIDGenerator()
|
||||
tasks := map[platform.ID]*influxdb.Task{}
|
||||
tasks := map[platform.ID]*taskmodel.Task{}
|
||||
mu := sync.Mutex{}
|
||||
|
||||
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()
|
||||
defer mu.Unlock()
|
||||
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 == "" {
|
||||
task.Status = string(influxdb.TaskActive)
|
||||
task.Status = string(taskmodel.TaskActive)
|
||||
}
|
||||
tasks[id] = task
|
||||
|
||||
|
@ -55,12 +55,12 @@ func inmemTaskService() influxdb.TaskService {
|
|||
delete(tasks, id)
|
||||
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()
|
||||
defer mu.Unlock()
|
||||
t, ok := tasks[id]
|
||||
if !ok {
|
||||
return nil, influxdb.ErrTaskNotFound
|
||||
return nil, taskmodel.ErrTaskNotFound
|
||||
}
|
||||
if upd.Flux != nil {
|
||||
t.Flux = *upd.Flux
|
||||
|
@ -75,37 +75,37 @@ func inmemTaskService() influxdb.TaskService {
|
|||
|
||||
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()
|
||||
defer mu.Unlock()
|
||||
t, ok := tasks[id]
|
||||
if !ok {
|
||||
return nil, influxdb.ErrTaskNotFound
|
||||
return nil, taskmodel.ErrTaskNotFound
|
||||
}
|
||||
newt := *t
|
||||
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()
|
||||
defer mu.Unlock()
|
||||
if tf.After != nil {
|
||||
return []*influxdb.Task{}, 0, nil
|
||||
return []*taskmodel.Task{}, 0, nil
|
||||
}
|
||||
rtn := []*influxdb.Task{}
|
||||
rtn := []*taskmodel.Task{}
|
||||
for _, task := range tasks {
|
||||
rtn = append(rtn, task)
|
||||
}
|
||||
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()
|
||||
defer mu.Unlock()
|
||||
t, ok := tasks[id]
|
||||
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
|
||||
|
@ -121,7 +121,7 @@ func TestCoordinatingTaskService(t *testing.T) {
|
|||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -147,13 +147,13 @@ func TestCoordinatingTaskService(t *testing.T) {
|
|||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
inactive := string(influxdb.TaskInactive)
|
||||
res, err := middleware.UpdateTask(context.Background(), task.ID, influxdb.TaskUpdate{Status: &inactive})
|
||||
inactive := string(taskmodel.TaskInactive)
|
||||
res, err := middleware.UpdateTask(context.Background(), task.ID, taskmodel.TaskUpdate{Status: &inactive})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -172,8 +172,8 @@ func TestCoordinatingTaskService(t *testing.T) {
|
|||
t.Fatal("task sent to scheduler doesnt match task created")
|
||||
}
|
||||
|
||||
active := string(influxdb.TaskActive)
|
||||
if _, err := middleware.UpdateTask(context.Background(), task.ID, influxdb.TaskUpdate{Status: &active}); err != nil {
|
||||
active := string(taskmodel.TaskActive)
|
||||
if _, err := middleware.UpdateTask(context.Background(), task.ID, taskmodel.TaskUpdate{Status: &active}); err != nil {
|
||||
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)`
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
|
||||
"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
|
||||
|
@ -15,12 +15,12 @@ import (
|
|||
type CoordinatingNotificationRuleStore struct {
|
||||
influxdb.NotificationRuleStore
|
||||
coordinator Coordinator
|
||||
taskService influxdb.TaskService
|
||||
taskService taskmodel.TaskService
|
||||
Now func() time.Time
|
||||
}
|
||||
|
||||
// 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{
|
||||
NotificationRuleStore: ns,
|
||||
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
|
||||
// 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()
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
// 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()
|
||||
}
|
||||
|
||||
|
|
|
@ -3,13 +3,14 @@ package middleware_test
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
"github.com/influxdata/influxdb/v2/notification/rule"
|
||||
"github.com/influxdata/influxdb/v2/task/backend/middleware"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
)
|
||||
|
||||
func newNotificationRuleSvcStack() (mockedSvc, *middleware.CoordinatingNotificationRuleStore) {
|
||||
|
@ -80,13 +81,13 @@ func TestNotificationRuleUpdateFromInactive(t *testing.T) {
|
|||
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 {
|
||||
return &influxdb.Task{ID: id, Status: string(influxdb.TaskInactive)}, nil
|
||||
return &taskmodel.Task{ID: id, Status: string(taskmodel.TaskInactive)}, nil
|
||||
} 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{}
|
||||
|
|
|
@ -7,10 +7,9 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
"github.com/influxdata/influxdb/v2/models"
|
||||
"github.com/influxdata/influxdb/v2/storage"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
"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
|
||||
// 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{
|
||||
statusTag: run.Status,
|
||||
taskIDTag: run.TaskID.String(),
|
||||
|
|
|
@ -6,16 +6,15 @@ import (
|
|||
"time"
|
||||
|
||||
"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/taskmodel"
|
||||
)
|
||||
|
||||
var _ scheduler.SchedulableService = (*SchedulableTaskService)(nil)
|
||||
|
||||
// UpdateTaskService provides an API to update the LatestScheduled time of a task
|
||||
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
|
||||
|
@ -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
|
||||
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,
|
||||
})
|
||||
|
||||
|
|
|
@ -6,9 +6,8 @@ import (
|
|||
"time"
|
||||
|
||||
"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/taskmodel"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -16,8 +15,8 @@ var (
|
|||
mockTimeNow = time.Now()
|
||||
)
|
||||
|
||||
func (m MockTaskService) UpdateTask(_ context.Context, id platform.ID, _ influxdb.TaskUpdate) (*influxdb.Task, error) {
|
||||
return &influxdb.Task{ID: id, UpdatedAt: mockTimeNow}, nil
|
||||
func (m MockTaskService) UpdateTask(_ context.Context, id platform.ID, _ taskmodel.TaskUpdate) (*taskmodel.Task, error) {
|
||||
return &taskmodel.Task{ID: id, UpdatedAt: mockTimeNow}, nil
|
||||
}
|
||||
|
||||
type MockTaskService struct{}
|
||||
|
@ -26,7 +25,7 @@ func Test_Schedulable_Task_Service(t *testing.T) {
|
|||
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
task *influxdb.Task
|
||||
task *taskmodel.Task
|
||||
}{
|
||||
{
|
||||
name: "Create New Schedulable Task Service",
|
||||
|
|
|
@ -5,8 +5,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
)
|
||||
|
||||
// TaskControlService is a low-level controller interface, intended to be passed to
|
||||
|
@ -14,19 +13,19 @@ import (
|
|||
type TaskControlService interface {
|
||||
|
||||
// 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)
|
||||
ManualRuns(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) ([]*taskmodel.Run, error)
|
||||
|
||||
// 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(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(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(ctx context.Context, taskID, runID platform.ID, when time.Time, log string) error
|
||||
|
|
|
@ -8,14 +8,13 @@ import (
|
|||
"time"
|
||||
|
||||
"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/scheduler"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
)
|
||||
|
||||
type promise struct {
|
||||
run *influxdb.Run
|
||||
run *taskmodel.Run
|
||||
hangingFor time.Duration
|
||||
|
||||
done chan struct{}
|
||||
|
@ -54,7 +53,7 @@ func (p *promise) Error() error {
|
|||
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)
|
||||
p := &promise{
|
||||
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) {
|
||||
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)
|
||||
return p, err
|
||||
}
|
||||
|
|
|
@ -8,10 +8,9 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
"github.com/influxdata/influxdb/v2/snowflake"
|
||||
"github.com/influxdata/influxdb/v2/task/backend"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
)
|
||||
|
||||
var idgen = snowflake.NewDefaultIDGenerator()
|
||||
|
@ -20,54 +19,54 @@ var idgen = snowflake.NewDefaultIDGenerator()
|
|||
type TaskControlService struct {
|
||||
mu sync.Mutex
|
||||
// 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.
|
||||
created map[string]*influxdb.Run
|
||||
created map[string]*taskmodel.Run
|
||||
|
||||
// Map of stringified task ID to task meta.
|
||||
tasks map[platform.ID]*influxdb.Task
|
||||
manualRuns []*influxdb.Run
|
||||
tasks map[platform.ID]*taskmodel.Task
|
||||
manualRuns []*taskmodel.Run
|
||||
// Map of task ID to total number of runs created for that task.
|
||||
totalRunsCreated map[platform.ID]int
|
||||
finishedRuns map[platform.ID]*influxdb.Run
|
||||
finishedRuns map[platform.ID]*taskmodel.Run
|
||||
}
|
||||
|
||||
var _ backend.TaskControlService = (*TaskControlService)(nil)
|
||||
|
||||
func NewTaskControlService() *TaskControlService {
|
||||
return &TaskControlService{
|
||||
runs: make(map[platform.ID]map[platform.ID]*influxdb.Run),
|
||||
finishedRuns: make(map[platform.ID]*influxdb.Run),
|
||||
tasks: make(map[platform.ID]*influxdb.Task),
|
||||
created: make(map[string]*influxdb.Run),
|
||||
runs: make(map[platform.ID]map[platform.ID]*taskmodel.Run),
|
||||
finishedRuns: make(map[platform.ID]*taskmodel.Run),
|
||||
tasks: make(map[platform.ID]*taskmodel.Task),
|
||||
created: make(map[string]*taskmodel.Run),
|
||||
totalRunsCreated: make(map[platform.ID]int),
|
||||
}
|
||||
}
|
||||
|
||||
// SetTask sets the task.
|
||||
// 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()
|
||||
defer d.mu.Unlock()
|
||||
|
||||
d.tasks[task.ID] = task
|
||||
}
|
||||
|
||||
func (d *TaskControlService) SetManualRuns(runs []*influxdb.Run) {
|
||||
func (d *TaskControlService) SetManualRuns(runs []*taskmodel.Run) {
|
||||
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()
|
||||
defer t.mu.Unlock()
|
||||
|
||||
runID := idgen.ID()
|
||||
runs, ok := t.runs[taskID]
|
||||
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,
|
||||
ScheduledFor: scheduledFor,
|
||||
}
|
||||
|
@ -75,11 +74,11 @@ func (t *TaskControlService) CreateRun(_ context.Context, taskID platform.ID, sc
|
|||
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()
|
||||
defer t.mu.Unlock()
|
||||
|
||||
var run *influxdb.Run
|
||||
var run *taskmodel.Run
|
||||
for i, r := range t.manualRuns {
|
||||
if r.ID == runID {
|
||||
run = r
|
||||
|
@ -87,12 +86,12 @@ func (t *TaskControlService) StartManualRun(_ context.Context, taskID, runID pla
|
|||
}
|
||||
}
|
||||
if run == nil {
|
||||
return nil, influxdb.ErrRunNotFound
|
||||
return nil, taskmodel.ErrRunNotFound
|
||||
}
|
||||
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()
|
||||
defer d.mu.Unlock()
|
||||
|
||||
|
@ -111,28 +110,28 @@ func (d *TaskControlService) FinishRun(_ context.Context, taskID, runID platform
|
|||
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()
|
||||
defer t.mu.Unlock()
|
||||
rtn := []*influxdb.Run{}
|
||||
rtn := []*taskmodel.Run{}
|
||||
for _, run := range t.runs[taskID] {
|
||||
rtn = append(rtn, run)
|
||||
}
|
||||
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()
|
||||
defer t.mu.Unlock()
|
||||
|
||||
if t.manualRuns != nil {
|
||||
return t.manualRuns, nil
|
||||
}
|
||||
return []*influxdb.Run{}, nil
|
||||
return []*taskmodel.Run{}, nil
|
||||
}
|
||||
|
||||
// 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()
|
||||
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")
|
||||
}
|
||||
switch state {
|
||||
case influxdb.RunStarted:
|
||||
case taskmodel.RunStarted:
|
||||
run.StartedAt = when
|
||||
case influxdb.RunSuccess, influxdb.RunFail, influxdb.RunCanceled:
|
||||
case taskmodel.RunSuccess, taskmodel.RunFail, taskmodel.RunCanceled:
|
||||
run.FinishedAt = when
|
||||
case influxdb.RunScheduled:
|
||||
case taskmodel.RunScheduled:
|
||||
// nothing
|
||||
default:
|
||||
panic("invalid status")
|
||||
|
@ -163,15 +162,15 @@ func (d *TaskControlService) AddRunLog(ctx context.Context, taskID, runID platfo
|
|||
if run == nil {
|
||||
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
|
||||
}
|
||||
|
||||
func (d *TaskControlService) CreatedFor(taskID platform.ID) []*influxdb.Run {
|
||||
func (d *TaskControlService) CreatedFor(taskID platform.ID) []*taskmodel.Run {
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
|
||||
var qrs []*influxdb.Run
|
||||
var qrs []*taskmodel.Run
|
||||
for _, qr := range d.created {
|
||||
if qr.TaskID == taskID {
|
||||
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.
|
||||
//
|
||||
// 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
|
||||
actualCount := 0
|
||||
var created []*influxdb.Run
|
||||
var created []*taskmodel.Run
|
||||
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.
|
||||
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
|
||||
}
|
||||
|
||||
func (d *TaskControlService) FinishedRun(runID platform.ID) *influxdb.Run {
|
||||
func (d *TaskControlService) FinishedRun(runID platform.ID) *taskmodel.Run {
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
|
||||
return d.finishedRuns[runID]
|
||||
}
|
||||
|
||||
func (d *TaskControlService) FinishedRuns() []*influxdb.Run {
|
||||
rtn := []*influxdb.Run{}
|
||||
func (d *TaskControlService) FinishedRuns() []*taskmodel.Run {
|
||||
rtn := []*taskmodel.Run{}
|
||||
for _, run := range d.finishedRuns {
|
||||
rtn = append(rtn, run)
|
||||
}
|
||||
|
|
|
@ -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 }
|
|
@ -16,15 +16,15 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
icontext "github.com/influxdata/influxdb/v2/context"
|
||||
"github.com/influxdata/influxdb/v2/kit/feature"
|
||||
"github.com/influxdata/influxdb/v2/kit/platform"
|
||||
influxdbmock "github.com/influxdata/influxdb/v2/mock"
|
||||
"github.com/influxdata/influxdb/v2/task/backend"
|
||||
"github.com/influxdata/influxdb/v2/task/options"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -173,7 +173,7 @@ type System struct {
|
|||
Ctx context.Context
|
||||
|
||||
// TaskService is the task service we would like to test
|
||||
TaskService influxdb.TaskService
|
||||
TaskService taskmodel.TaskService
|
||||
|
||||
// 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.
|
||||
|
@ -190,11 +190,11 @@ func testTaskCRUD(t *testing.T, sys *System) {
|
|||
cr := creds(t, sys)
|
||||
|
||||
// Create a task.
|
||||
tc := influxdb.TaskCreate{
|
||||
tc := taskmodel.TaskCreate{
|
||||
OrganizationID: cr.OrgID,
|
||||
Flux: fmt.Sprintf(scriptFmt, 0),
|
||||
OwnerID: cr.UserID,
|
||||
Type: influxdb.TaskSystemType,
|
||||
Type: taskmodel.TaskSystemType,
|
||||
}
|
||||
|
||||
authorizedCtx := icontext.SetAuthorizer(sys.Ctx, cr.Authorizer())
|
||||
|
@ -207,7 +207,7 @@ func testTaskCRUD(t *testing.T, sys *System) {
|
|||
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 {
|
||||
if t.ID == id {
|
||||
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)
|
||||
}
|
||||
|
||||
findTasksByStatus := func(tasks []*influxdb.Task, status string) []*influxdb.Task {
|
||||
var foundTasks = []*influxdb.Task{}
|
||||
findTasksByStatus := func(tasks []*taskmodel.Task, status string) []*taskmodel.Task {
|
||||
var foundTasks = []*taskmodel.Task{}
|
||||
for _, t := range tasks {
|
||||
if t.Status == status {
|
||||
foundTasks = append(foundTasks, t)
|
||||
|
@ -241,7 +241,7 @@ func testTaskCRUD(t *testing.T, sys *System) {
|
|||
|
||||
// Look up a task the different ways we can.
|
||||
// Map of method name to found task.
|
||||
found := map[string]*influxdb.Task{
|
||||
found := map[string]*taskmodel.Task{
|
||||
"Created": tsk,
|
||||
}
|
||||
|
||||
|
@ -252,7 +252,7 @@ func testTaskCRUD(t *testing.T, sys *System) {
|
|||
}
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -262,7 +262,7 @@ func testTaskCRUD(t *testing.T, sys *System) {
|
|||
}
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -272,7 +272,7 @@ func testTaskCRUD(t *testing.T, sys *System) {
|
|||
}
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -282,7 +282,7 @@ func testTaskCRUD(t *testing.T, sys *System) {
|
|||
}
|
||||
found["FindTasks with User filter"] = f
|
||||
|
||||
want := &influxdb.Task{
|
||||
want := &taskmodel.Task{
|
||||
ID: tsk.ID,
|
||||
CreatedAt: tsk.CreatedAt,
|
||||
LatestCompleted: tsk.LatestCompleted,
|
||||
|
@ -293,9 +293,9 @@ func testTaskCRUD(t *testing.T, sys *System) {
|
|||
Name: "task #0",
|
||||
Cron: "* * * * *",
|
||||
Offset: 5 * time.Second,
|
||||
Status: string(influxdb.DefaultTaskStatus),
|
||||
Status: string(taskmodel.DefaultTaskStatus),
|
||||
Flux: fmt.Sprintf(scriptFmt, 0),
|
||||
Type: influxdb.TaskSystemType,
|
||||
Type: taskmodel.TaskSystemType,
|
||||
}
|
||||
|
||||
for fn, f := range found {
|
||||
|
@ -306,11 +306,11 @@ func testTaskCRUD(t *testing.T, sys *System) {
|
|||
}
|
||||
|
||||
// Check limits
|
||||
tc2 := influxdb.TaskCreate{
|
||||
tc2 := taskmodel.TaskCreate{
|
||||
OrganizationID: cr.OrgID,
|
||||
Flux: fmt.Sprintf(scriptFmt, 1),
|
||||
OwnerID: cr.UserID,
|
||||
Status: string(influxdb.TaskInactive),
|
||||
Status: string(taskmodel.TaskInactive),
|
||||
}
|
||||
|
||||
if _, err := sys.TaskService.CreateTask(authorizedCtx, tc2); err != nil {
|
||||
|
@ -319,7 +319,7 @@ func testTaskCRUD(t *testing.T, sys *System) {
|
|||
if !tsk.ID.Valid() {
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -329,7 +329,7 @@ func testTaskCRUD(t *testing.T, sys *System) {
|
|||
|
||||
// Check after
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -345,24 +345,24 @@ func testTaskCRUD(t *testing.T, sys *System) {
|
|||
}
|
||||
|
||||
// Check task status filter
|
||||
active := string(influxdb.TaskActive)
|
||||
fs, _, err = sys.TaskService.FindTasks(sys.Ctx, influxdb.TaskFilter{Status: &active})
|
||||
active := string(taskmodel.TaskActive)
|
||||
fs, _, err = sys.TaskService.FindTasks(sys.Ctx, taskmodel.TaskFilter{Status: &active})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
activeTasks := findTasksByStatus(fs, string(influxdb.TaskActive))
|
||||
activeTasks := findTasksByStatus(fs, string(taskmodel.TaskActive))
|
||||
if len(fs) != len(activeTasks) {
|
||||
t.Fatalf("expected to find %d active tasks, found: %d", len(activeTasks), len(fs))
|
||||
}
|
||||
|
||||
inactive := string(influxdb.TaskInactive)
|
||||
fs, _, err = sys.TaskService.FindTasks(sys.Ctx, influxdb.TaskFilter{Status: &inactive})
|
||||
inactive := string(taskmodel.TaskInactive)
|
||||
fs, _, err = sys.TaskService.FindTasks(sys.Ctx, taskmodel.TaskFilter{Status: &inactive})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
inactiveTasks := findTasksByStatus(fs, string(influxdb.TaskInactive))
|
||||
inactiveTasks := findTasksByStatus(fs, string(taskmodel.TaskInactive))
|
||||
if len(fs) != len(inactiveTasks) {
|
||||
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.
|
||||
newFlux := fmt.Sprintf(scriptFmt, 99)
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -382,13 +382,13 @@ func testTaskCRUD(t *testing.T, sys *System) {
|
|||
if f.Flux != newFlux {
|
||||
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)
|
||||
}
|
||||
|
||||
// Update task: status only.
|
||||
newStatus := string(influxdb.TaskInactive)
|
||||
f, err = sys.TaskService.UpdateTask(authorizedCtx, origID, influxdb.TaskUpdate{Status: &newStatus})
|
||||
newStatus := string(taskmodel.TaskInactive)
|
||||
f, err = sys.TaskService.UpdateTask(authorizedCtx, origID, taskmodel.TaskUpdate{Status: &newStatus})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -400,9 +400,9 @@ func testTaskCRUD(t *testing.T, sys *System) {
|
|||
}
|
||||
|
||||
// Update task: reactivate status and update script.
|
||||
newStatus = string(influxdb.TaskActive)
|
||||
newStatus = string(taskmodel.TaskActive)
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -414,9 +414,9 @@ func testTaskCRUD(t *testing.T, sys *System) {
|
|||
}
|
||||
|
||||
// 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\")"
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -429,9 +429,9 @@ func testTaskCRUD(t *testing.T, sys *System) {
|
|||
}
|
||||
|
||||
// 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\")"
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -444,9 +444,9 @@ func testTaskCRUD(t *testing.T, sys *System) {
|
|||
}
|
||||
|
||||
// Update task: just cron.
|
||||
newStatus = string(influxdb.TaskActive)
|
||||
newStatus = string(taskmodel.TaskActive)
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -491,8 +491,8 @@ func testTaskCRUD(t *testing.T, sys *System) {
|
|||
}
|
||||
|
||||
// Task should not be returned.
|
||||
if _, err := sys.TaskService.FindTaskByID(sys.Ctx, origID); err != influxdb.ErrTaskNotFound {
|
||||
t.Fatalf("expected %v, got %v", influxdb.ErrTaskNotFound, err)
|
||||
if _, err := sys.TaskService.FindTaskByID(sys.Ctx, origID); err != taskmodel.ErrTaskNotFound {
|
||||
t.Fatalf("expected %v, got %v", taskmodel.ErrTaskNotFound, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -509,15 +509,15 @@ from(bucket: "b")
|
|||
|
||||
cr := creds(t, sys)
|
||||
|
||||
tc := influxdb.TaskCreate{
|
||||
tc := taskmodel.TaskCreate{
|
||||
OrganizationID: cr.OrgID,
|
||||
OwnerID: cr.UserID,
|
||||
Type: influxdb.TaskSystemType,
|
||||
Type: taskmodel.TaskSystemType,
|
||||
}
|
||||
|
||||
authorizedCtx := icontext.SetAuthorizer(sys.Ctx, cr.Authorizer())
|
||||
|
||||
created := make([]*influxdb.Task, 50)
|
||||
created := make([]*taskmodel.Task, 50)
|
||||
for i := 0; i < 50; i++ {
|
||||
tc.Flux = fmt.Sprintf(script, i/10)
|
||||
tsk, err := sys.TaskService.CreateTask(authorizedCtx, tc)
|
||||
|
@ -531,7 +531,7 @@ from(bucket: "b")
|
|||
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 {
|
||||
t.Fatalf("FindTasks: %v", err)
|
||||
}
|
||||
|
@ -542,7 +542,7 @@ from(bucket: "b")
|
|||
|
||||
// find tasks using name which are after first 10
|
||||
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 {
|
||||
t.Fatalf("FindTasks: %v", err)
|
||||
}
|
||||
|
@ -564,14 +564,14 @@ func testTaskFindTasksAfterPaging(t *testing.T, sys *System) {
|
|||
from(bucket: "b")
|
||||
|> to(bucket: "two", orgID: "000000000000000")`
|
||||
cr = creds(t, sys)
|
||||
tc = influxdb.TaskCreate{
|
||||
tc = taskmodel.TaskCreate{
|
||||
OrganizationID: cr.OrgID,
|
||||
OwnerID: cr.UserID,
|
||||
Type: influxdb.TaskSystemType,
|
||||
Type: taskmodel.TaskSystemType,
|
||||
Flux: script,
|
||||
}
|
||||
authorizedCtx = icontext.SetAuthorizer(sys.Ctx, cr.Authorizer())
|
||||
created = make([]*influxdb.Task, 10)
|
||||
created = make([]*taskmodel.Task, 10)
|
||||
taskName = "some-unique-task-name"
|
||||
)
|
||||
|
||||
|
@ -603,7 +603,7 @@ from(bucket: "b")
|
|||
|
||||
// one more than expected pages
|
||||
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,
|
||||
After: after,
|
||||
Name: &taskName,
|
||||
|
@ -648,7 +648,7 @@ from(bucket: "b")
|
|||
|
||||
cr := creds(t, sys)
|
||||
|
||||
ct := influxdb.TaskCreate{
|
||||
ct := taskmodel.TaskCreate{
|
||||
OrganizationID: cr.OrgID,
|
||||
Flux: script,
|
||||
OwnerID: cr.UserID,
|
||||
|
@ -663,7 +663,7 @@ from(bucket: "b")
|
|||
|
||||
from(bucket: "b")
|
||||
|> 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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -686,7 +686,7 @@ from(bucket: "b")
|
|||
|
||||
from(bucket: "b")
|
||||
|> 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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -707,7 +707,7 @@ from(bucket: "b")
|
|||
|
||||
from(bucket: "b")
|
||||
|> 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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -725,7 +725,7 @@ func testUpdate(t *testing.T, sys *System) {
|
|||
now := time.Now()
|
||||
earliestCA := now.Add(-time.Second)
|
||||
|
||||
ct := influxdb.TaskCreate{
|
||||
ct := taskmodel.TaskCreate{
|
||||
OrganizationID: cr.OrgID,
|
||||
Flux: fmt.Sprintf(scriptFmt, 0),
|
||||
OwnerID: cr.UserID,
|
||||
|
@ -767,11 +767,11 @@ func testUpdate(t *testing.T, sys *System) {
|
|||
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)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -801,7 +801,7 @@ func testUpdate(t *testing.T, sys *System) {
|
|||
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)
|
||||
}
|
||||
|
||||
|
@ -809,7 +809,7 @@ func testUpdate(t *testing.T, sys *System) {
|
|||
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)
|
||||
}
|
||||
|
||||
|
@ -840,7 +840,7 @@ func testUpdate(t *testing.T, sys *System) {
|
|||
|
||||
now = time.Now()
|
||||
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 {
|
||||
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
|
||||
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 {
|
||||
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",
|
||||
// which makes timing of runs somewhat difficult.
|
||||
ct := influxdb.TaskCreate{
|
||||
ct := taskmodel.TaskCreate{
|
||||
OrganizationID: cr.OrgID,
|
||||
Flux: fmt.Sprintf(scriptFmt, 0),
|
||||
OwnerID: cr.UserID,
|
||||
|
@ -901,14 +901,14 @@ func testTaskRuns(t *testing.T, sys *System) {
|
|||
}
|
||||
|
||||
// check run filter errors
|
||||
_, _, err0 := sys.TaskService.FindRuns(sys.Ctx, influxdb.RunFilter{Task: task.ID, Limit: -1})
|
||||
if err0 != influxdb.ErrOutOfBoundsLimit {
|
||||
_, _, err0 := sys.TaskService.FindRuns(sys.Ctx, taskmodel.RunFilter{Task: task.ID, Limit: -1})
|
||||
if err0 != taskmodel.ErrOutOfBoundsLimit {
|
||||
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})
|
||||
if err1 != influxdb.ErrOutOfBoundsLimit {
|
||||
t.Fatalf("failed to error with out of bounds run limit: %d", influxdb.TaskMaxPageSize+1)
|
||||
_, _, err1 := sys.TaskService.FindRuns(sys.Ctx, taskmodel.RunFilter{Task: task.ID, Limit: taskmodel.TaskMaxPageSize + 1})
|
||||
if err1 != taskmodel.ErrOutOfBoundsLimit {
|
||||
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.
|
||||
|
@ -924,7 +924,7 @@ func testTaskRuns(t *testing.T, sys *System) {
|
|||
startedAt := time.Now().UTC()
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
|
@ -937,11 +937,11 @@ func testTaskRuns(t *testing.T, sys *System) {
|
|||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -951,7 +951,7 @@ func testTaskRuns(t *testing.T, sys *System) {
|
|||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
|
@ -960,7 +960,7 @@ func testTaskRuns(t *testing.T, sys *System) {
|
|||
}
|
||||
|
||||
// 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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -973,8 +973,8 @@ func testTaskRuns(t *testing.T, sys *System) {
|
|||
if runs[0].StartedAt != startedAt {
|
||||
t.Fatalf("unexpectedStartedAt; want %s, got %s", startedAt, runs[0].StartedAt)
|
||||
}
|
||||
if runs[0].Status != influxdb.RunStarted.String() {
|
||||
t.Fatalf("unexpected run status; want %s, got %s", influxdb.RunStarted.String(), runs[0].Status)
|
||||
if runs[0].Status != taskmodel.RunStarted.String() {
|
||||
t.Fatalf("unexpected run status; want %s, got %s", taskmodel.RunStarted.String(), runs[0].Status)
|
||||
}
|
||||
|
||||
if !runs[0].FinishedAt.IsZero() {
|
||||
|
@ -984,13 +984,13 @@ func testTaskRuns(t *testing.T, sys *System) {
|
|||
// Look for a run that doesn't exist.
|
||||
_, err = sys.TaskService.FindRunByID(sys.Ctx, task.ID, platform.ID(math.MaxUint64))
|
||||
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.
|
||||
_, err = sys.TaskService.FindRunByID(sys.Ctx, platform.ID(math.MaxUint64), runs[0].ID)
|
||||
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)
|
||||
|
@ -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",
|
||||
// which makes timing of runs somewhat difficult.
|
||||
ct := influxdb.TaskCreate{
|
||||
ct := taskmodel.TaskCreate{
|
||||
OrganizationID: cr.OrgID,
|
||||
Flux: fmt.Sprintf(scriptFmt, 0),
|
||||
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
|
||||
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
|
||||
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)))
|
||||
if err != nil {
|
||||
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 {
|
||||
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 {
|
||||
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.FinishedAt = scheduledFor.Add(time.Second * time.Duration(i+2))
|
||||
run.RunAt = scheduledFor.Add(time.Second * time.Duration(i))
|
||||
run.Status = influxdb.RunSuccess.String()
|
||||
run.Status = taskmodel.RunSuccess.String()
|
||||
run.Log = nil
|
||||
|
||||
if sys.CallFinishRun {
|
||||
|
@ -1061,7 +1061,7 @@ func testTaskRuns(t *testing.T, sys *System) {
|
|||
}
|
||||
|
||||
found, _, err := sys.TaskService.FindRuns(ctx,
|
||||
influxdb.RunFilter{
|
||||
taskmodel.RunFilter{
|
||||
Task: task.ID,
|
||||
Limit: 2,
|
||||
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.Parallel()
|
||||
|
||||
ct := influxdb.TaskCreate{
|
||||
ct := taskmodel.TaskCreate{
|
||||
OrganizationID: cr.OrgID,
|
||||
Flux: fmt.Sprintf(scriptFmt, 0),
|
||||
OwnerID: cr.UserID,
|
||||
|
@ -1107,7 +1107,7 @@ func testTaskRuns(t *testing.T, sys *System) {
|
|||
t.Run("FindLogs", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ct := influxdb.TaskCreate{
|
||||
ct := taskmodel.TaskCreate{
|
||||
OrganizationID: cr.OrgID,
|
||||
Flux: fmt.Sprintf(scriptFmt, 0),
|
||||
OwnerID: cr.UserID,
|
||||
|
@ -1124,7 +1124,7 @@ func testTaskRuns(t *testing.T, sys *System) {
|
|||
if err != nil {
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -1132,7 +1132,7 @@ func testTaskRuns(t *testing.T, sys *System) {
|
|||
if err != nil {
|
||||
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)
|
||||
}
|
||||
// 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.
|
||||
logs, _, err := sys.TaskService.FindLogs(sys.Ctx, influxdb.LogFilter{
|
||||
logs, _, err := sys.TaskService.FindLogs(sys.Ctx, taskmodel.LogFilter{
|
||||
Task: task.ID,
|
||||
Run: &rc1.ID,
|
||||
})
|
||||
|
@ -1150,8 +1150,8 @@ func testTaskRuns(t *testing.T, sys *System) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
expLine1 := &influxdb.Log{RunID: rc1.ID, Time: log1Time.Format(time.RFC3339Nano), Message: "entry 1"}
|
||||
exp := []*influxdb.Log{expLine1}
|
||||
expLine1 := &taskmodel.Log{RunID: rc1.ID, Time: log1Time.Format(time.RFC3339Nano), Message: "entry 1"}
|
||||
exp := []*taskmodel.Log{expLine1}
|
||||
if diff := cmp.Diff(logs, exp); 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.
|
||||
logs, _, err = sys.TaskService.FindLogs(sys.Ctx, influxdb.LogFilter{
|
||||
logs, _, err = sys.TaskService.FindLogs(sys.Ctx, taskmodel.LogFilter{
|
||||
Task: task.ID,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
expLine2 := &influxdb.Log{RunID: rc2.ID, Time: log2Time.Format(time.RFC3339Nano), Message: "entry 2"}
|
||||
exp = []*influxdb.Log{expLine1, expLine2}
|
||||
expLine2 := &taskmodel.Log{RunID: rc2.ID, Time: log2Time.Format(time.RFC3339Nano), Message: "entry 2"}
|
||||
exp = []*taskmodel.Log{expLine1, expLine2}
|
||||
if diff := cmp.Diff(logs, exp); diff != "" {
|
||||
t.Fatalf("unexpected log: -got/+want: %s", diff)
|
||||
}
|
||||
|
@ -1181,7 +1181,7 @@ func testTaskConcurrency(t *testing.T, sys *System) {
|
|||
cr := creds(t, sys)
|
||||
|
||||
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,
|
||||
// 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.
|
||||
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 {
|
||||
t.Errorf("error finding tasks: %v", err)
|
||||
return
|
||||
|
@ -1292,7 +1292,7 @@ func testTaskConcurrency(t *testing.T, sys *System) {
|
|||
}
|
||||
|
||||
// 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 {
|
||||
t.Errorf("error finding tasks: %v", err)
|
||||
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 {
|
||||
// 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.
|
||||
continue
|
||||
}
|
||||
|
@ -1343,7 +1343,7 @@ func testTaskConcurrency(t *testing.T, sys *System) {
|
|||
|
||||
// Start adding tasks.
|
||||
for i := 0; i < numTasks; i++ {
|
||||
createTaskCh <- influxdb.TaskCreate{
|
||||
createTaskCh <- taskmodel.TaskCreate{
|
||||
OrganizationID: cr.OrgID,
|
||||
Flux: fmt.Sprintf(scriptFmt, i),
|
||||
OwnerID: cr.UserID,
|
||||
|
@ -1360,7 +1360,7 @@ func testManualRun(t *testing.T, s *System) {
|
|||
cr := creds(t, s)
|
||||
|
||||
// Create a task.
|
||||
tc := influxdb.TaskCreate{
|
||||
tc := taskmodel.TaskCreate{
|
||||
OrganizationID: cr.OrgID,
|
||||
Flux: fmt.Sprintf(scriptFmt, 0),
|
||||
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",
|
||||
// which makes timing of runs somewhat difficult.
|
||||
ct := influxdb.TaskCreate{
|
||||
ct := taskmodel.TaskCreate{
|
||||
OrganizationID: cr.OrgID,
|
||||
Flux: fmt.Sprintf(scriptFmt, 0),
|
||||
OwnerID: cr.UserID,
|
||||
|
@ -1416,14 +1416,14 @@ func testRunStorage(t *testing.T, sys *System) {
|
|||
}
|
||||
|
||||
// check run filter errors
|
||||
_, _, err0 := sys.TaskService.FindRuns(sys.Ctx, influxdb.RunFilter{Task: task.ID, Limit: -1})
|
||||
if err0 != influxdb.ErrOutOfBoundsLimit {
|
||||
_, _, err0 := sys.TaskService.FindRuns(sys.Ctx, taskmodel.RunFilter{Task: task.ID, Limit: -1})
|
||||
if err0 != taskmodel.ErrOutOfBoundsLimit {
|
||||
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})
|
||||
if err1 != influxdb.ErrOutOfBoundsLimit {
|
||||
t.Fatalf("failed to error with out of bounds run limit: %d", influxdb.TaskMaxPageSize+1)
|
||||
_, _, err1 := sys.TaskService.FindRuns(sys.Ctx, taskmodel.RunFilter{Task: task.ID, Limit: taskmodel.TaskMaxPageSize + 1})
|
||||
if err1 != taskmodel.ErrOutOfBoundsLimit {
|
||||
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.
|
||||
|
@ -1439,7 +1439,7 @@ func testRunStorage(t *testing.T, sys *System) {
|
|||
startedAt := time.Now().UTC().Add(time.Second * -10)
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
|
@ -1452,12 +1452,12 @@ func testRunStorage(t *testing.T, sys *System) {
|
|||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
|
@ -1466,7 +1466,7 @@ func testRunStorage(t *testing.T, sys *System) {
|
|||
}
|
||||
|
||||
// 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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -1479,8 +1479,8 @@ func testRunStorage(t *testing.T, sys *System) {
|
|||
if runs[0].StartedAt != startedAt {
|
||||
t.Fatalf("unexpectedStartedAt; want %s, got %s", startedAt, runs[0].StartedAt)
|
||||
}
|
||||
if runs[0].Status != influxdb.RunStarted.String() {
|
||||
t.Fatalf("unexpected run status; want %s, got %s", influxdb.RunStarted.String(), runs[0].Status)
|
||||
if runs[0].Status != taskmodel.RunStarted.String() {
|
||||
t.Fatalf("unexpected run status; want %s, got %s", taskmodel.RunStarted.String(), runs[0].Status)
|
||||
}
|
||||
|
||||
if !runs[0].FinishedAt.IsZero() {
|
||||
|
@ -1492,18 +1492,18 @@ func testRunStorage(t *testing.T, sys *System) {
|
|||
if err != nil {
|
||||
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)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
if _, err := sys.TaskControlService.FinishRun(sys.Ctx, task.ID, rc2.ID); err != nil {
|
||||
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 {
|
||||
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.
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
|
@ -1529,8 +1529,8 @@ func testRunStorage(t *testing.T, sys *System) {
|
|||
if runs[0].StartedAt != startedAt {
|
||||
t.Fatalf("unexpectedStartedAt; want %s, got %s", startedAt, runs[0].StartedAt)
|
||||
}
|
||||
if runs[0].Status != influxdb.RunStarted.String() {
|
||||
t.Fatalf("unexpected run status; want %s, got %s", influxdb.RunStarted.String(), runs[0].Status)
|
||||
if runs[0].Status != taskmodel.RunStarted.String() {
|
||||
t.Fatalf("unexpected run status; want %s, got %s", taskmodel.RunStarted.String(), runs[0].Status)
|
||||
}
|
||||
// TODO (al): handle empty 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 {
|
||||
t.Fatalf("unexpected StartedAt; want %s, got %s", exp, runs[2].StartedAt)
|
||||
}
|
||||
if runs[2].Status != influxdb.RunFail.String() {
|
||||
t.Fatalf("unexpected run status; want %s, got %s", influxdb.RunSuccess.String(), runs[2].Status)
|
||||
if runs[2].Status != taskmodel.RunFail.String() {
|
||||
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 {
|
||||
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.
|
||||
_, err = sys.TaskService.FindRunByID(sys.Ctx, task.ID, platform.ID(math.MaxUint64))
|
||||
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.
|
||||
_, err = sys.TaskService.FindRunByID(sys.Ctx, platform.ID(math.MaxUint64), runs[0].ID)
|
||||
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)
|
||||
|
@ -1585,7 +1585,7 @@ func testRetryAcrossStorage(t *testing.T, sys *System) {
|
|||
cr := creds(t, sys)
|
||||
|
||||
// Script is set to run every minute.
|
||||
ct := influxdb.TaskCreate{
|
||||
ct := taskmodel.TaskCreate{
|
||||
OrganizationID: cr.OrgID,
|
||||
Flux: fmt.Sprintf(scriptFmt, 0),
|
||||
OwnerID: cr.UserID,
|
||||
|
@ -1597,7 +1597,7 @@ func testRetryAcrossStorage(t *testing.T, sys *System) {
|
|||
// Non-existent ID should return the right error.
|
||||
_, err = sys.TaskService.RetryRun(sys.Ctx, task.ID, platform.ID(math.MaxUint64))
|
||||
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.
|
||||
|
@ -1613,10 +1613,10 @@ func testRetryAcrossStorage(t *testing.T, sys *System) {
|
|||
startedAt := time.Now().UTC()
|
||||
|
||||
// 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)
|
||||
}
|
||||
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)
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
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.
|
||||
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",
|
||||
// which makes timing of runs somewhat difficult.
|
||||
ct := influxdb.TaskCreate{
|
||||
ct := taskmodel.TaskCreate{
|
||||
OrganizationID: cr.OrgID,
|
||||
Flux: fmt.Sprintf(scriptFmt, 0),
|
||||
OwnerID: cr.UserID,
|
||||
|
@ -1675,7 +1675,7 @@ func testLogsAcrossStorage(t *testing.T, sys *System) {
|
|||
startedAt := time.Now().UTC()
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
|
@ -1688,12 +1688,12 @@ func testLogsAcrossStorage(t *testing.T, sys *System) {
|
|||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
|
@ -1710,7 +1710,7 @@ func testLogsAcrossStorage(t *testing.T, sys *System) {
|
|||
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 {
|
||||
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))
|
||||
}
|
||||
smash := func(logs []*influxdb.Log) string {
|
||||
smash := func(logs []*taskmodel.Log) string {
|
||||
smashed := ""
|
||||
for _, log := range logs {
|
||||
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))
|
||||
}
|
||||
|
||||
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 {
|
||||
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))
|
||||
}
|
||||
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -1830,7 +1830,7 @@ func testTaskType(t *testing.T, sys *System) {
|
|||
authorizedCtx := icontext.SetAuthorizer(sys.Ctx, cr.Authorizer())
|
||||
|
||||
// Create a tasks
|
||||
ts := influxdb.TaskCreate{
|
||||
ts := taskmodel.TaskCreate{
|
||||
OrganizationID: cr.OrgID,
|
||||
Flux: fmt.Sprintf(scriptFmt, 0),
|
||||
OwnerID: cr.UserID,
|
||||
|
@ -1844,7 +1844,7 @@ func testTaskType(t *testing.T, sys *System) {
|
|||
t.Fatal("no task ID set")
|
||||
}
|
||||
|
||||
tc := influxdb.TaskCreate{
|
||||
tc := taskmodel.TaskCreate{
|
||||
Type: "cows",
|
||||
OrganizationID: cr.OrgID,
|
||||
Flux: fmt.Sprintf(scriptFmt, 0),
|
||||
|
@ -1859,7 +1859,7 @@ func testTaskType(t *testing.T, sys *System) {
|
|||
t.Fatal("no task ID set")
|
||||
}
|
||||
|
||||
tp := influxdb.TaskCreate{
|
||||
tp := taskmodel.TaskCreate{
|
||||
Type: "pigs",
|
||||
OrganizationID: cr.OrgID,
|
||||
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)
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
||||
// 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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -1898,7 +1898,7 @@ func testTaskType(t *testing.T, sys *System) {
|
|||
}
|
||||
|
||||
// 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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package influxdb
|
||||
package taskmodel
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
@ -8,11 +8,11 @@ import (
|
|||
"strconv"
|
||||
"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/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"
|
||||
)
|
||||
|
||||
|
@ -276,7 +276,7 @@ func (t *TaskUpdate) Validate() error {
|
|||
|
||||
// safeParseSource calls the Flux parser.ParseSource function
|
||||
// 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 {
|
||||
return nil, &errors2.Error{
|
||||
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
|
||||
// flux string, that now has those updated options in it. It zeros the options
|
||||
// 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)
|
||||
}
|
||||
|
||||
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 != "" {
|
||||
oldFlux = *t.Flux
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package influxdb
|
||||
package taskmodel
|
||||
|
||||
import (
|
||||
"fmt"
|
|
@ -1,18 +1,18 @@
|
|||
package influxdb_test
|
||||
package taskmodel_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
platform "github.com/influxdata/influxdb/v2"
|
||||
_ "github.com/influxdata/influxdb/v2/fluxinit/static"
|
||||
"github.com/influxdata/influxdb/v2/query/fluxlang"
|
||||
"github.com/influxdata/influxdb/v2/task/options"
|
||||
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
||||
)
|
||||
|
||||
func TestUpdateValidate(t *testing.T) {
|
||||
tu := &platform.TaskUpdate{}
|
||||
tu := &taskmodel.TaskUpdate{}
|
||||
// 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 {
|
||||
t.Fatal(err)
|
||||
|
@ -30,7 +30,7 @@ func TestUpdateValidate(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
|
||||
if err := json.Unmarshal([]byte(`{"every":"10s", "offset":"1h"}`), tu); err != nil {
|
||||
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)
|
||||
}
|
||||
|
||||
tu = &platform.TaskUpdate{}
|
||||
tu = &taskmodel.TaskUpdate{}
|
||||
// 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 {
|
||||
t.Fatal(err)
|
||||
|
@ -54,7 +54,7 @@ func TestOptionsMarshal(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestOptionsEditWithAST(t *testing.T) {
|
||||
tu := &platform.TaskUpdate{}
|
||||
tu := &taskmodel.TaskUpdate{}
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
|
@ -84,7 +84,7 @@ from(bucket: "x")
|
|||
}
|
||||
})
|
||||
t.Run("add new option", func(t *testing.T) {
|
||||
tu := &platform.TaskUpdate{}
|
||||
tu := &taskmodel.TaskUpdate{}
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
|
@ -98,7 +98,7 @@ from(bucket: "x")
|
|||
}
|
||||
})
|
||||
t.Run("switching from every to cron", func(t *testing.T) {
|
||||
tu := &platform.TaskUpdate{}
|
||||
tu := &taskmodel.TaskUpdate{}
|
||||
tu.Options.Cron = "* * * * *"
|
||||
if err := tu.UpdateFlux(fluxlang.DefaultService, `option task = {every: 20s, name: "foo"} from(bucket:"x") |> range(start:-1h)`); err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -115,7 +115,7 @@ from(bucket: "x")
|
|||
}
|
||||
})
|
||||
t.Run("switching from cron to every", func(t *testing.T) {
|
||||
tu := &platform.TaskUpdate{}
|
||||
tu := &taskmodel.TaskUpdate{}
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
|
@ -132,7 +132,7 @@ from(bucket: "x")
|
|||
}
|
||||
})
|
||||
t.Run("delete deletable option", func(t *testing.T) {
|
||||
tu := &platform.TaskUpdate{}
|
||||
tu := &taskmodel.TaskUpdate{}
|
||||
tu.Options.Offset = &options.Duration{}
|
||||
expscript := `option task = {cron: "* * * * *", name: "foo"}
|
||||
|
||||
|
@ -159,10 +159,10 @@ from(bucket: "x")
|
|||
}
|
||||
|
||||
func TestParseRequestStillQueuedError(t *testing.T) {
|
||||
e := platform.RequestStillQueuedError{Start: 1000, End: 2000}
|
||||
e := taskmodel.RequestStillQueuedError{Start: 1000, End: 2000}
|
||||
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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue