From 4c5939313b9bd087922209c00e0d7055731a988e Mon Sep 17 00:00:00 2001 From: Carolina Calderon Date: Tue, 24 Oct 2023 16:12:50 -0400 Subject: [PATCH] chore: indirect import for jobs to avoid import cycle (#8238) --- master/internal/api_experiment.go | 4 ++-- master/internal/api_job.go | 7 ++++--- master/internal/command/command.go | 6 +++--- master/internal/command/command_job_service.go | 2 +- master/internal/core.go | 4 ++-- master/internal/experiment.go | 6 +++--- master/internal/experiment_job_service.go | 2 +- master/internal/job/{job.go => jobservice/jobservice.go} | 2 +- 8 files changed, 17 insertions(+), 16 deletions(-) rename master/internal/job/{job.go => jobservice/jobservice.go} (99%) diff --git a/master/internal/api_experiment.go b/master/internal/api_experiment.go index 3a61828d57a..b4fc5ce331e 100644 --- a/master/internal/api_experiment.go +++ b/master/internal/api_experiment.go @@ -31,7 +31,7 @@ import ( "github.com/determined-ai/determined/master/internal/db" exputil "github.com/determined-ai/determined/master/internal/experiment" "github.com/determined-ai/determined/master/internal/grpcutil" - "github.com/determined-ai/determined/master/internal/job" + "github.com/determined-ai/determined/master/internal/job/jobservice" "github.com/determined-ai/determined/master/internal/prom" "github.com/determined-ai/determined/master/internal/sproto" "github.com/determined-ai/determined/master/internal/trials" @@ -337,7 +337,7 @@ func (a *apiServer) GetExperiment( } jobID := model.JobID(exp.JobId) - jobSummary, err := job.DefaultService.GetJobSummary(jobID, exp.ResourcePool) + jobSummary, err := jobservice.DefaultService.GetJobSummary(jobID, exp.ResourcePool) if err != nil { // An error here either is real or just that the experiment was not yet terminal in the DB // when we first queried it but was by the time it got around to handling out ask. We can't diff --git a/master/internal/api_job.go b/master/internal/api_job.go index 8256dd66e6f..1fe3f8670a8 100644 --- a/master/internal/api_job.go +++ b/master/internal/api_job.go @@ -4,6 +4,7 @@ import ( "context" "github.com/determined-ai/determined/master/internal/api" + "github.com/determined-ai/determined/master/internal/job/jobservice" "github.com/determined-ai/determined/master/internal/authz" "github.com/determined-ai/determined/master/internal/grpcutil" @@ -16,7 +17,7 @@ import ( func (a *apiServer) GetJobs( ctx context.Context, req *apiv1.GetJobsRequest, ) (resp *apiv1.GetJobsResponse, err error) { - jobs, err := job.DefaultService.GetJobs( + jobs, err := jobservice.DefaultService.GetJobs( req.ResourcePool, req.OrderBy == apiv1.OrderBy_ORDER_BY_DESC, req.States, @@ -47,7 +48,7 @@ func (a *apiServer) GetJobs( func (a *apiServer) GetJobsV2( ctx context.Context, req *apiv1.GetJobsV2Request, ) (resp *apiv1.GetJobsV2Response, err error) { - jobs, err := job.DefaultService.GetJobs( + jobs, err := jobservice.DefaultService.GetJobs( req.ResourcePool, req.OrderBy == apiv1.OrderBy_ORDER_BY_DESC, req.States, @@ -118,7 +119,7 @@ func (a *apiServer) UpdateJobQueue( if permErr != nil { return nil, permErr } - err = job.DefaultService.UpdateJobQueue(req.Updates) + err = jobservice.DefaultService.UpdateJobQueue(req.Updates) if err != nil { return nil, err } diff --git a/master/internal/command/command.go b/master/internal/command/command.go index 3b44577bf16..34d6c45f8e0 100644 --- a/master/internal/command/command.go +++ b/master/internal/command/command.go @@ -12,7 +12,7 @@ import ( "github.com/sirupsen/logrus" "github.com/determined-ai/determined/master/internal/db" - "github.com/determined-ai/determined/master/internal/job" + "github.com/determined-ai/determined/master/internal/job/jobservice" "github.com/determined-ai/determined/master/internal/rm" "github.com/determined-ai/determined/master/internal/rm/rmerrors" "github.com/determined-ai/determined/master/internal/rm/tasklist" @@ -307,7 +307,7 @@ func (c *command) Receive(ctx *actor.Context) error { return err } - job.DefaultService.RegisterJob(c.jobID, c) + jobservice.DefaultService.RegisterJob(c.jobID, c) if err := c.persist(); err != nil { ctx.Log().WithError(err).Warnf("command persist failure") @@ -324,7 +324,7 @@ func (c *command) Receive(ctx *actor.Context) error { ctx.Log().WithError(err).Error("marking task complete") } } - go job.DefaultService.UnregisterJob(c.jobID) + go jobservice.DefaultService.UnregisterJob(c.jobID) if err := user.DeleteSessionByToken( context.TODO(), c.GenericCommandSpec.Base.UserSessionToken, diff --git a/master/internal/command/command_job_service.go b/master/internal/command/command_job_service.go index 8cb7bdcce61..cd21048602a 100644 --- a/master/internal/command/command_job_service.go +++ b/master/internal/command/command_job_service.go @@ -12,7 +12,7 @@ import ( "github.com/determined-ai/determined/proto/pkg/jobv1" ) -// job.Service methods +// jobservice.Service methods // ToV1Job() takes a command and returns a job. func (c *command) ToV1Job() *jobv1.Job { diff --git a/master/internal/core.go b/master/internal/core.go index ce56e4f36cd..324208b62da 100644 --- a/master/internal/core.go +++ b/master/internal/core.go @@ -46,7 +46,7 @@ import ( "github.com/determined-ai/determined/master/internal/db" "github.com/determined-ai/determined/master/internal/elastic" "github.com/determined-ai/determined/master/internal/grpcutil" - "github.com/determined-ai/determined/master/internal/job" + "github.com/determined-ai/determined/master/internal/job/jobservice" "github.com/determined-ai/determined/master/internal/plugin/sso" "github.com/determined-ai/determined/master/internal/portregistry" "github.com/determined-ai/determined/master/internal/prom" @@ -1051,7 +1051,7 @@ func (m *Master) Run(ctx context.Context, gRPCLogInitDone chan struct{}) error { }, cert, ) - job.SetDefaultService(m.rm) + jobservice.SetDefaultService(m.rm) tasksGroup := m.echo.Group("/tasks") tasksGroup.GET("", api.Route(m.getTasks)) diff --git a/master/internal/experiment.go b/master/internal/experiment.go index 8947d2fe8e2..3ea031a5235 100644 --- a/master/internal/experiment.go +++ b/master/internal/experiment.go @@ -19,7 +19,7 @@ import ( "github.com/determined-ai/determined/master/internal/api" "github.com/determined-ai/determined/master/internal/config" "github.com/determined-ai/determined/master/internal/db" - "github.com/determined-ai/determined/master/internal/job" + "github.com/determined-ai/determined/master/internal/job/jobservice" "github.com/determined-ai/determined/master/internal/rm" "github.com/determined-ai/determined/master/internal/rm/rmerrors" "github.com/determined-ai/determined/master/internal/rm/tasklist" @@ -292,7 +292,7 @@ func (e *experiment) Receive(ctx *actor.Context) error { return err } - job.DefaultService.RegisterJob(e.JobID, e) + jobservice.DefaultService.RegisterJob(e.JobID, e) if e.restored { j, err := e.db.JobByID(e.JobID) @@ -445,7 +445,7 @@ func (e *experiment) Receive(ctx *actor.Context) error { e.syslog.Error(err) } } - go job.DefaultService.UnregisterJob(e.JobID) + go jobservice.DefaultService.UnregisterJob(e.JobID) state := model.StoppingToTerminalStates[e.State] if state == "" { state = model.ErrorState diff --git a/master/internal/experiment_job_service.go b/master/internal/experiment_job_service.go index 7198d9d55b3..d7a99acb0c6 100644 --- a/master/internal/experiment_job_service.go +++ b/master/internal/experiment_job_service.go @@ -13,7 +13,7 @@ import ( "github.com/determined-ai/determined/proto/pkg/jobv1" ) -// job.Service methods +// jobservice.Service methods // ToV1Jobs() takes an experiment and returns a job. func (e *experiment) ToV1Job() *jobv1.Job { diff --git a/master/internal/job/job.go b/master/internal/job/jobservice/jobservice.go similarity index 99% rename from master/internal/job/job.go rename to master/internal/job/jobservice/jobservice.go index a358cf3a04b..1bb94fb158f 100644 --- a/master/internal/job/job.go +++ b/master/internal/job/jobservice/jobservice.go @@ -1,4 +1,4 @@ -package job +package jobservice import ( "fmt"