-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduces model creation to model migration.
This PR introduces model creation in DQlite as part of model migration. We are doing this to facilitate further changes to the model DDL that requires the removal of the modelmanager service. To achieve this removal we need to properly create models during migration. As well as this because of how application and machine importing was working we also need to migrate these two entities into the model database. This commit also disables the current model migration tests that we have. This is because they are currently not setup to properly handle DQlite migration and will need to be addressed in follow up PR's.
- Loading branch information
Showing
26 changed files
with
814 additions
and
188 deletions.
There are no files selected for viewing
42 changes: 2 additions & 40 deletions
42
apiserver/facades/controller/migrationtarget/domain_mock_test.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright 2024 Canonical Ltd. | ||
// Licensed under the AGPLv3, see LICENCE file for details. | ||
|
||
package modelmigration | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/juju/description/v5" | ||
"github.com/juju/loggo" | ||
|
||
"github.com/juju/juju/core/modelmigration" | ||
"github.com/juju/juju/domain/application/service" | ||
"github.com/juju/juju/domain/application/state" | ||
) | ||
|
||
var logger = loggo.GetLogger("juju.migration.applications") | ||
|
||
// Coordinator is the interface that is used to add operations to a migration. | ||
type Coordinator interface { | ||
Add(modelmigration.Operation) | ||
} | ||
|
||
// RegisterImport register's a new model migration importer into the supplied | ||
// coordinator. | ||
func RegisterImport(coordinator Coordinator) { | ||
coordinator.Add(&importOperation{}) | ||
} | ||
|
||
type importOperation struct { | ||
modelmigration.BaseOperation | ||
|
||
service ImportService | ||
} | ||
|
||
// ImportService defines the application service used to import applications | ||
// from another controller model to this controller. | ||
type ImportService interface { | ||
// CreateApplication registers the existence of an application in the model. | ||
CreateApplication(context.Context, string, service.AddApplicationParams, ...service.AddUnitParams) error | ||
} | ||
|
||
func (i *importOperation) Setup(scope modelmigration.Scope) error { | ||
i.service = service.NewService( | ||
state.NewState(scope.ModelDB(), logger), | ||
) | ||
return nil | ||
} | ||
|
||
func (i *importOperation) Execute(ctx context.Context, model description.Model) error { | ||
for _, app := range model.Applications() { | ||
unitArgs := make([]service.AddUnitParams, 0, len(app.Units())) | ||
for _, unit := range app.Units() { | ||
name := unit.Name() | ||
unitArgs = append(unitArgs, service.AddUnitParams{UnitName: &name}) | ||
} | ||
|
||
err := i.service.CreateApplication( | ||
ctx, app.Name(), service.AddApplicationParams{}, unitArgs..., | ||
) | ||
if err != nil { | ||
return fmt.Errorf( | ||
"import model application %q with %d units: %w", | ||
app.Name(), len(app.Units()), err, | ||
) | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2024 Canonical Ltd. | ||
// Licensed under the AGPLv3, see LICENCE file for details. | ||
|
||
package modelmigration | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/juju/description/v5" | ||
"github.com/juju/names/v5" | ||
jc "github.com/juju/testing/checkers" | ||
gomock "go.uber.org/mock/gomock" | ||
gc "gopkg.in/check.v1" | ||
|
||
"github.com/juju/juju/domain/application/service" | ||
) | ||
|
||
type importSuite struct { | ||
importService *MockImportService | ||
} | ||
|
||
var _ = gc.Suite(&importSuite{}) | ||
|
||
func (s *importSuite) setupMocks(c *gc.C) *gomock.Controller { | ||
ctrl := gomock.NewController(c) | ||
s.importService = NewMockImportService(ctrl) | ||
return ctrl | ||
} | ||
|
||
func (i *importSuite) TestApplicationSave(c *gc.C) { | ||
model := description.NewModel(description.ModelArgs{}) | ||
|
||
appArgs := description.ApplicationArgs{ | ||
Tag: names.NewApplicationTag("prometheus"), | ||
} | ||
model.AddApplication(appArgs).AddUnit(description.UnitArgs{ | ||
Tag: names.NewUnitTag("prometheus/0"), | ||
}) | ||
|
||
defer i.setupMocks(c).Finish() | ||
|
||
i.importService.EXPECT().CreateApplication( | ||
gomock.Any(), | ||
"prometheus", | ||
gomock.Any(), | ||
[]service.AddUnitParams{ | ||
{ | ||
ptrString("prometheus/0"), | ||
}, | ||
}, | ||
).Return(nil) | ||
|
||
importOp := importOperation{ | ||
service: i.importService, | ||
} | ||
|
||
err := importOp.Execute(context.Background(), model) | ||
c.Assert(err, jc.ErrorIsNil) | ||
} | ||
|
||
func ptrString(s string) *string { | ||
return &s | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.