Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slim jimm model #1488

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions cmd/jimmctl/cmd/relation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"os"
"sort"
"strings"
"time"

petname "github.com/dustinkirkland/golang-petname"
"github.com/google/uuid"
Expand Down Expand Up @@ -542,13 +541,6 @@ func (s *relationSuite) TestCheckRelationViaSuperuser(c *gc.C) {
CloudRegionID: cloud.Regions[0].ID,
CloudCredentialID: cred.ID,
Life: "alive",
Status: dbmodel.Status{
Status: "available",
Since: sql.NullTime{
Time: time.Now().UTC().Truncate(time.Millisecond),
Valid: true,
},
},
}

err = db.AddModel(ctx, &model)
Expand Down
37 changes: 21 additions & 16 deletions cmd/jimmsrv/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,6 @@ func (s *Service) ServeHTTP(w http.ResponseWriter, req *http.Request) {
s.mux.ServeHTTP(w, req)
}

// WatchControllers connects to all controllers and starts an AllWatcher
// monitoring all changes to models. WatchControllers finishes when the
// given context is canceled, or there is a fatal error watching models.
func (s *Service) WatchControllers(ctx context.Context) error {
w := jimm.Watcher{
Database: s.jimm.Database,
Dialer: s.jimm.Dialer,
}
return w.Watch(ctx, 10*time.Minute)
}

// WatchModelSummaries connects to all controllers and starts a
// ModelSummaryWatcher for all models. WatchModelSummaries finishes when
// the given context is canceled, or there is a fatal error watching model
Expand Down Expand Up @@ -275,6 +264,22 @@ func (s *Service) OpenFGACleanup(ctx context.Context, trigger <-chan time.Time)
}
}

// CleanupDyingModels triggers every `trigger` time and calls the jimm methods to cleanup dying models.
func (s *Service) CleanupDyingModels(ctx context.Context, trigger <-chan time.Time) error {
for {
select {
case <-trigger:
err := s.jimm.CleanupDyingModels(ctx)
if err != nil {
zapctx.Error(ctx, "dying models cleanup", zap.Error(err))
continue
}
case <-ctx.Done():
return nil
}
}
}

// Cleanup cleans up resources that need to be released on shutdown.
func (s *Service) Cleanup() {
// Iterating over clean up function in reverse-order to avoid early clean ups.
Expand Down Expand Up @@ -498,11 +503,6 @@ func NewService(ctx context.Context, p Params) (*Service, error) {
func (s *Service) StartServices(ctx context.Context, svc *service.Service) {
// on the leader unit we start additional routines
if s.isLeader {
// the leader unit connects to all controllers' AllWatcher
svc.Go(func() error {
return s.WatchControllers(ctx)
})

// audit log cleanup routine
if s.auditLogCleanupPeriod != 0 {
svc.Go(func() error {
Expand All @@ -524,6 +524,11 @@ func (s *Service) StartServices(ctx context.Context, svc *service.Service) {
svc.Go(func() error {
return s.OpenFGACleanup(ctx, time.NewTicker(6*time.Hour).C)
})

// CleanupDyingModels cleanup - cleans up all dying models
svc.Go(func() error {
return s.CleanupDyingModels(ctx, time.NewTicker(time.Minute).C)
})
}

// all units periodically update their controller/model metrics
Expand Down
19 changes: 0 additions & 19 deletions internal/db/applicationoffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"database/sql"
"sort"
"testing"
"time"

qt "github.com/frankban/quicktest"
"github.com/google/go-cmp/cmp/cmpopts"
Expand Down Expand Up @@ -82,16 +81,7 @@ func initTestEnvironment(c *qt.C, db *db.Database) testEnvironment {
Controller: env.controller,
CloudRegion: env.cloud.Regions[0],
CloudCredential: env.cred,
Type: "iaas",
IsController: false,
Life: state.Alive.String(),
Status: dbmodel.Status{
Status: "available",
Since: sql.NullTime{
Time: time.Now(),
Valid: true,
},
},
}
c.Assert(db.DB.Create(&env.model).Error, qt.IsNil)

Expand All @@ -105,16 +95,7 @@ func initTestEnvironment(c *qt.C, db *db.Database) testEnvironment {
Controller: env.controller,
CloudRegion: env.cloud.Regions[0],
CloudCredential: env.cred,
Type: "iaas",
IsController: false,
Life: state.Alive.String(),
Status: dbmodel.Status{
Status: "available",
Since: sql.NullTime{
Time: time.Now(),
Valid: true,
},
},
}
c.Assert(db.DB.Create(&env.model1).Error, qt.IsNil)

Expand Down
87 changes: 0 additions & 87 deletions internal/db/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"database/sql"
"sort"
"testing"
"time"

qt "github.com/frankban/quicktest"
"github.com/juju/juju/state"
Expand Down Expand Up @@ -72,16 +71,7 @@ func (s *dbSuite) TestAddModel(c *qt.C) {
ControllerID: controller.ID,
CloudRegionID: cloud.Regions[0].ID,
CloudCredentialID: cred.ID,
Type: "iaas",
DefaultSeries: "warty",
Life: state.Alive.String(),
Status: dbmodel.Status{
Status: "available",
Since: db.Now(),
},
SLA: dbmodel.SLA{
Level: "unsupported",
},
}
m1 := model
err = s.Database.AddModel(context.Background(), &model)
Expand Down Expand Up @@ -147,16 +137,7 @@ func (s *dbSuite) TestGetModel(c *qt.C) {
CloudRegion: cloud.Regions[0],
CloudCredentialID: cred.ID,
CloudCredential: cred,
Type: "iaas",
DefaultSeries: "warty",
Life: state.Alive.String(),
Status: dbmodel.Status{
Status: "available",
Since: db.Now(),
},
SLA: dbmodel.SLA{
Level: "unsupported",
},
}
model.CloudCredential.Cloud = dbmodel.Cloud{}
// We don't care about the cloud credential owner when
Expand Down Expand Up @@ -240,16 +221,7 @@ func (s *dbSuite) TestUpdateModel(c *qt.C) {
ControllerID: controller.ID,
CloudRegionID: cloud.Regions[0].ID,
CloudCredentialID: cred.ID,
Type: "iaas",
DefaultSeries: "warty",
Life: state.Alive.String(),
Status: dbmodel.Status{
Status: "available",
Since: db.Now(),
},
SLA: dbmodel.SLA{
Level: "unsupported",
},
}
err = s.Database.AddModel(context.Background(), &model)
c.Assert(err, qt.Equals, nil)
Expand Down Expand Up @@ -317,16 +289,7 @@ func (s *dbSuite) TestDeleteModel(c *qt.C) {
Controller: controller,
CloudRegionID: cloud.Regions[0].ID,
CloudCredentialID: cred.ID,
Type: "iaas",
DefaultSeries: "warty",
Life: state.Alive.String(),
Status: dbmodel.Status{
Status: "available",
Since: db.Now(),
},
SLA: dbmodel.SLA{
Level: "unsupported",
},
}

// model does not exist
Expand Down Expand Up @@ -400,16 +363,7 @@ func (s *dbSuite) TestGetModelsUsingCredential(c *qt.C) {
ControllerID: controller.ID,
CloudRegionID: cloud.Regions[0].ID,
CloudCredentialID: cred1.ID,
Type: "iaas",
DefaultSeries: "warty",
Life: state.Alive.String(),
Status: dbmodel.Status{
Status: "available",
Since: db.Now(),
},
SLA: dbmodel.SLA{
Level: "unsupported",
},
}
err = s.Database.AddModel(context.Background(), &model1)
c.Assert(err, qt.Equals, nil)
Expand All @@ -424,16 +378,7 @@ func (s *dbSuite) TestGetModelsUsingCredential(c *qt.C) {
ControllerID: controller.ID,
CloudRegionID: cloud.Regions[0].ID,
CloudCredentialID: cred2.ID,
Type: "iaas",
DefaultSeries: "warty",
Life: state.Alive.String(),
Status: dbmodel.Status{
Status: "available",
Since: db.Now(),
},
SLA: dbmodel.SLA{
Level: "unsupported",
},
}
err = s.Database.AddModel(context.Background(), &model2)
c.Assert(err, qt.Equals, nil)
Expand All @@ -454,13 +399,7 @@ func (s *dbSuite) TestGetModelsUsingCredential(c *qt.C) {
Controller: controller,
CloudRegionID: cloud.Regions[0].ID,
CloudCredentialID: cred1.ID,
Type: "iaas",
DefaultSeries: "warty",
Life: state.Alive.String(),
Status: model1.Status,
SLA: dbmodel.SLA{
Level: "unsupported",
},
}})

models, err = s.Database.GetModelsUsingCredential(context.Background(), 0)
Expand Down Expand Up @@ -683,20 +622,7 @@ func (s *dbSuite) TestGetModelsByController(c *qt.C) {
Controller: controller,
CloudRegion: cloud.Regions[0],
CloudCredential: cred,
Type: "iaas",
IsController: true,
DefaultSeries: "focal",
Life: state.Alive.String(),
Status: dbmodel.Status{
Status: "available",
Since: sql.NullTime{
Time: time.Now(),
Valid: true,
},
},
SLA: dbmodel.SLA{
Level: "unsupported",
},
}, {
Name: "test-model-2",
UUID: sql.NullString{
Expand All @@ -707,20 +633,7 @@ func (s *dbSuite) TestGetModelsByController(c *qt.C) {
Controller: controller,
CloudRegion: cloud.Regions[0],
CloudCredential: cred,
Type: "iaas",
IsController: false,
DefaultSeries: "focal",
Life: state.Alive.String(),
Status: dbmodel.Status{
Status: "available",
Since: sql.NullTime{
Time: time.Now(),
Valid: true,
},
},
SLA: dbmodel.SLA{
Level: "unsupported",
},
}}
for _, m := range models {
c.Assert(s.Database.DB.Create(&m).Error, qt.IsNil)
Expand Down
9 changes: 0 additions & 9 deletions internal/db/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,7 @@ func SetupDB(c *qt.C, database *db.Database) (dbmodel.Model, dbmodel.Controller,
ControllerID: controller.ID,
CloudRegionID: cloud.Regions[0].ID,
CloudCredentialID: cred.ID,
Type: "iaas",
DefaultSeries: "warty",
Life: state.Alive.String(),
Status: dbmodel.Status{
Status: "available",
Since: db.Now(),
},
SLA: dbmodel.SLA{
Level: "unsupported",
},
}
err = database.AddModel(context.Background(), &model)
c.Assert(err, qt.Equals, nil)
Expand Down
3 changes: 0 additions & 3 deletions internal/dbmodel/applicationoffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ func TestApplicationOfferUniqueConstraint(t *testing.T) {
Controller: ctl,
CloudRegion: cl.Regions[0],
CloudCredential: cred,
Type: "iaas",
IsController: false,
DefaultSeries: "warty",
Life: state.Alive.String(),
}
c.Assert(db.Create(&m).Error, qt.IsNil)
Expand Down
Loading
Loading