Skip to content

Commit

Permalink
Merge pull request juju#10981 from howbazaar/core-multiwatcher
Browse files Browse the repository at this point in the history
juju#10981

This is step one of the multiwatcher refactoring.

Introduce a new core package for multiwatcher types. Have the state multiwatchers use this core type. This necessitates changes in the modelcache worker and in the apiserver.

The apiserver now does the translation between the core/multiwatcher types and the types returned over the API using apiserver/params types. This should almost be the last of the apiserver/params dependencies in the state package.

## QA steps

Unit tests keep passing. Any bundle deployment uses the multiwatchers.
Bootstrap a new controller, deploy stuff into some models and look at the controller engine report to see that the model cache is being populated properly.

## Documentation changes

Everything is internal, no user facing changes.
  • Loading branch information
jujubot authored Dec 6, 2019
2 parents 606b35f + 486f806 commit 045c3a5
Show file tree
Hide file tree
Showing 21 changed files with 1,896 additions and 1,101 deletions.
3 changes: 2 additions & 1 deletion apiserver/apiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
apitesting "github.com/juju/juju/apiserver/testing"
"github.com/juju/juju/core/auditlog"
"github.com/juju/juju/core/cache"
"github.com/juju/juju/core/multiwatcher"
"github.com/juju/juju/core/presence"
psapiserver "github.com/juju/juju/pubsub/apiserver"
"github.com/juju/juju/pubsub/centralhub"
Expand Down Expand Up @@ -83,7 +84,7 @@ func (s *apiserverConfigFixture) SetUpTest(c *gc.C) {
modelCache, err := modelcache.NewWorker(modelcache.Config{
InitializedGate: initialized,
Logger: loggo.GetLogger("test"),
WatcherFactory: func() modelcache.BackingWatcher {
WatcherFactory: func() multiwatcher.Watcher {
return s.StatePool.SystemState().WatchAllModels(s.StatePool)
},
PrometheusRegisterer: noopRegisterer{},
Expand Down
24 changes: 6 additions & 18 deletions apiserver/params/multiwatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ func (d *Delta) UnmarshalJSON(data []byte) error {
d.Entity = new(ActionInfo)
case "charm":
d.Entity = new(CharmInfo)
case "generation":
d.Entity = new(GenerationInfo)
case "branch":
d.Entity = new(BranchInfo)
default:
return errors.Errorf("Unexpected entity name %q", entityKind)
}
Expand Down Expand Up @@ -156,18 +156,6 @@ type StatusInfo struct {
Data map[string]interface{} `json:"data,omitempty"`
}

// NewStatusInfo return a new multiwatcher StatusInfo from a
// status StatusInfo.
func NewStatusInfo(s status.StatusInfo, err error) StatusInfo {
return StatusInfo{
Err: err,
Current: s.Status,
Message: s.Message,
Since: s.Since,
Data: s.Data,
}
}

// ApplicationInfo holds the information about an application that is tracked
// by multiwatcherStore.
type ApplicationInfo struct {
Expand Down Expand Up @@ -432,9 +420,9 @@ type ItemChange struct {
NewValue interface{} `json:"new,omitempty"`
}

// GenerationInfo holds data about a model generation (branch)
// BranchInfo holds data about a model generation (branch)
// that is tracked by multiwatcherStore.
type GenerationInfo struct {
type BranchInfo struct {
ModelUUID string `json:"model-uuid"`
Id string `json:"id"`
Name string `json:"name"`
Expand All @@ -448,9 +436,9 @@ type GenerationInfo struct {
}

// EntityId returns a unique identifier for a generation.
func (i *GenerationInfo) EntityId() EntityId {
func (i *BranchInfo) EntityId() EntityId {
return EntityId{
Kind: "generation",
Kind: "branch",
ModelUUID: i.ModelUUID,
Id: i.Id,
}
Expand Down
2 changes: 1 addition & 1 deletion apiserver/params/multiwatcher_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ var (
_ EntityInfo = (*BlockInfo)(nil)
_ EntityInfo = (*ActionInfo)(nil)
_ EntityInfo = (*ModelUpdate)(nil)
_ EntityInfo = (*GenerationInfo)(nil)
_ EntityInfo = (*BranchInfo)(nil)
)
3 changes: 2 additions & 1 deletion apiserver/shared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

corecontroller "github.com/juju/juju/controller"
"github.com/juju/juju/core/cache"
"github.com/juju/juju/core/multiwatcher"
"github.com/juju/juju/core/presence"
"github.com/juju/juju/feature"
"github.com/juju/juju/pubsub/controller"
Expand All @@ -43,7 +44,7 @@ func (s *sharedServerContextSuite) SetUpTest(c *gc.C) {
modelCache, err := modelcache.NewWorker(modelcache.Config{
InitializedGate: initialized,
Logger: loggo.GetLogger("test"),
WatcherFactory: func() modelcache.BackingWatcher {
WatcherFactory: func() multiwatcher.Watcher {
return s.StatePool.SystemState().WatchAllModels(s.StatePool)
},
PrometheusRegisterer: noopRegisterer{},
Expand Down
Loading

0 comments on commit 045c3a5

Please sign in to comment.