Skip to content

Commit

Permalink
Merge pull request juju#10846 from howbazaar/move-state-multiwatcher-…
Browse files Browse the repository at this point in the history
…package

juju#10846

As a prelude to making the all watchers combined and their own worker, it made sense to move the actual multiwatcher delta types.

Due to name clashes in the params package, two of the delta types have been renamed to use Update suffix rather than Info.

There is only one actual difference in this change, and it is in serialization param for the address type. The new Address uses "space-id" for the provider ID. The old structure used something else. I'm almost 100% confident that this was never used by the GUI nor anyone else, and I didn't feel that it necessitated having its own type just for something that was unused.
  • Loading branch information
jujubot authored Nov 5, 2019
2 parents 4813e14 + 7e41526 commit f26dd43
Show file tree
Hide file tree
Showing 103 changed files with 1,427 additions and 1,468 deletions.
12 changes: 6 additions & 6 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import (
"github.com/juju/juju/api"
"github.com/juju/juju/apiserver/params"
"github.com/juju/juju/core/machinelock"
"github.com/juju/juju/core/model"
"github.com/juju/juju/core/network"
"github.com/juju/juju/core/paths"
"github.com/juju/juju/mongo"
"github.com/juju/juju/state/multiwatcher"
)

var logger = loggo.GetLogger("juju.agent")
Expand Down Expand Up @@ -198,7 +198,7 @@ type Config interface {
SystemIdentityPath() string

// Jobs returns a list of MachineJobs that need to run.
Jobs() []multiwatcher.MachineJob
Jobs() []model.MachineJob

// Tag returns the tag of the entity on whose behalf the state connection
// will be made.
Expand Down Expand Up @@ -378,7 +378,7 @@ type configInternal struct {
nonce string
controller names.ControllerTag
model names.ModelTag
jobs []multiwatcher.MachineJob
jobs []model.MachineJob
upgradedToVersion version.Number
caCert string
apiDetails *apiDetails
Expand All @@ -395,7 +395,7 @@ type configInternal struct {
// a new AgentConfig.
type AgentConfigParams struct {
Paths Paths
Jobs []multiwatcher.MachineJob
Jobs []model.MachineJob
UpgradedToVersion version.Number
Tag names.Tag
Password string
Expand Down Expand Up @@ -552,7 +552,7 @@ func (c0 *configInternal) Clone() Config {
// Deep copy only fields which may be affected
// by ConfigSetter methods.
c1.apiDetails = c0.apiDetails.clone()
c1.jobs = append([]multiwatcher.MachineJob{}, c0.jobs...)
c1.jobs = append([]model.MachineJob{}, c0.jobs...)
c1.values = make(map[string]string, len(c0.values))
for key, val := range c0.values {
c1.values[key] = val
Expand Down Expand Up @@ -653,7 +653,7 @@ func (c *configInternal) SystemIdentityPath() string {
return filepath.Join(c.paths.DataDir, SystemIdentity)
}

func (c *configInternal) Jobs() []multiwatcher.MachineJob {
func (c *configInternal) Jobs() []model.MachineJob {
return c.jobs
}

Expand Down
12 changes: 6 additions & 6 deletions agent/agentbootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ import (
"github.com/juju/juju/cloudconfig/instancecfg"
"github.com/juju/juju/controller/modelmanager"
"github.com/juju/juju/core/instance"
"github.com/juju/juju/core/model"
corenetwork "github.com/juju/juju/core/network"
"github.com/juju/juju/environs"
"github.com/juju/juju/environs/config"
"github.com/juju/juju/mongo"
"github.com/juju/juju/network"
"github.com/juju/juju/state"
"github.com/juju/juju/state/multiwatcher"
"github.com/juju/juju/storage"
"github.com/juju/juju/worker/raft"
)
Expand All @@ -48,7 +48,7 @@ type InitializeStateParams struct {

// BootstrapMachineJobs holds the jobs that the bootstrap machine
// agent will run.
BootstrapMachineJobs []multiwatcher.MachineJob
BootstrapMachineJobs []model.MachineJob

// SharedSecret is the Mongo replica set shared secret (keyfile).
SharedSecret string
Expand Down Expand Up @@ -548,14 +548,14 @@ func initAPIHostPorts(st *state.State, pAddrs corenetwork.ProviderAddresses, api
return st.SetAPIHostPorts([]corenetwork.SpaceHostPorts{hostPorts})
}

// machineJobFromParams returns the job corresponding to params.MachineJob.
// machineJobFromParams returns the job corresponding to model.MachineJob.
// TODO(dfc) this function should live in apiserver/params, move there once
// state does not depend on apiserver/params
func machineJobFromParams(job multiwatcher.MachineJob) (state.MachineJob, error) {
func machineJobFromParams(job model.MachineJob) (state.MachineJob, error) {
switch job {
case multiwatcher.JobHostUnits:
case model.JobHostUnits:
return state.JobHostUnits, nil
case multiwatcher.JobManageModel:
case model.JobManageModel:
return state.JobManageModel, nil
default:
return -1, errors.Errorf("invalid machine job %q", job)
Expand Down
12 changes: 6 additions & 6 deletions agent/agentbootstrap/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/juju/juju/controller"
"github.com/juju/juju/core/constraints"
"github.com/juju/juju/core/instance"
"github.com/juju/juju/core/model"
corenetwork "github.com/juju/juju/core/network"
"github.com/juju/juju/environs"
"github.com/juju/juju/environs/config"
Expand All @@ -32,7 +33,6 @@ import (
"github.com/juju/juju/network"
"github.com/juju/juju/provider/dummy"
"github.com/juju/juju/state"
"github.com/juju/juju/state/multiwatcher"
"github.com/juju/juju/storage/provider"
"github.com/juju/juju/testing"
jujuversion "github.com/juju/juju/version"
Expand Down Expand Up @@ -183,7 +183,7 @@ LXC_BRIDGE="ignored"`[1:])
HostedModelConfig: hostedModelConfigAttrs,
},
BootstrapMachineAddresses: initialAddrs,
BootstrapMachineJobs: []multiwatcher.MachineJob{multiwatcher.JobManageModel},
BootstrapMachineJobs: []model.MachineJob{model.JobManageModel},
SharedSecret: "abc123",
Provider: func(t string) (environs.EnvironProvider, error) {
c.Assert(t, gc.Equals, "dummy")
Expand Down Expand Up @@ -424,7 +424,7 @@ func (s *bootstrapSuite) TestInitializeStateFailsSecondTime(c *gc.C) {
ControllerModelConfig: modelCfg,
HostedModelConfig: hostedModelConfigAttrs,
},
BootstrapMachineJobs: []multiwatcher.MachineJob{multiwatcher.JobManageModel},
BootstrapMachineJobs: []model.MachineJob{model.JobManageModel},
SharedSecret: "abc123",
Provider: func(t string) (environs.EnvironProvider, error) {
return &fakeProvider{}, nil
Expand All @@ -450,14 +450,14 @@ func (s *bootstrapSuite) TestInitializeStateFailsSecondTime(c *gc.C) {

func (s *bootstrapSuite) TestMachineJobFromParams(c *gc.C) {
var tests = []struct {
name multiwatcher.MachineJob
name model.MachineJob
want state.MachineJob
err string
}{{
name: multiwatcher.JobHostUnits,
name: model.JobHostUnits,
want: state.JobHostUnits,
}, {
name: multiwatcher.JobManageModel,
name: model.JobManageModel,
want: state.JobManageModel,
}, {
name: "invalid",
Expand Down
16 changes: 8 additions & 8 deletions agent/format-2.0.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
goyaml "gopkg.in/yaml.v2"

"github.com/juju/juju/apiserver/params"
"github.com/juju/juju/state/multiwatcher"
"github.com/juju/juju/core/model"
)

var format_2_0 = formatter_2_0{}
Expand All @@ -27,13 +27,13 @@ var _ formatter = formatter_2_0{}

// format_2_0Serialization holds information for a given agent.
type format_2_0Serialization struct {
Tag string `yaml:"tag,omitempty"`
DataDir string `yaml:"datadir,omitempty"`
LogDir string `yaml:"logdir,omitempty"`
MetricsSpoolDir string `yaml:"metricsspooldir,omitempty"`
Nonce string `yaml:"nonce,omitempty"`
Jobs []multiwatcher.MachineJob `yaml:"jobs,omitempty"`
UpgradedToVersion *version.Number `yaml:"upgradedToVersion"`
Tag string `yaml:"tag,omitempty"`
DataDir string `yaml:"datadir,omitempty"`
LogDir string `yaml:"logdir,omitempty"`
MetricsSpoolDir string `yaml:"metricsspooldir,omitempty"`
Nonce string `yaml:"nonce,omitempty"`
Jobs []model.MachineJob `yaml:"jobs,omitempty"`
UpgradedToVersion *version.Number `yaml:"upgradedToVersion"`

CACert string `yaml:"cacert,omitempty"`
StateAddresses []string `yaml:"stateaddresses,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions agent/format-2.0_whitebox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/juju/version"
gc "gopkg.in/check.v1"

"github.com/juju/juju/state/multiwatcher"
"github.com/juju/juju/core/model"
"github.com/juju/juju/testing"
)

Expand Down Expand Up @@ -46,7 +46,7 @@ func (*format_2_0Suite) TestReadConfWithExisting2_0ConfigFileContents(c *gc.C) {
config, err := ReadConfig(configPath)
c.Assert(err, jc.ErrorIsNil)
c.Assert(config.UpgradedToVersion(), jc.DeepEquals, version.MustParse("1.17.5.1"))
c.Assert(config.Jobs(), jc.DeepEquals, []multiwatcher.MachineJob{multiwatcher.JobManageModel})
c.Assert(config.Jobs(), jc.DeepEquals, []model.MachineJob{model.JobManageModel})
}

func (*format_2_0Suite) TestMarshalUnmarshal(c *gc.C) {
Expand Down
4 changes: 2 additions & 2 deletions agent/format_whitebox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

"github.com/juju/juju/apiserver/params"
"github.com/juju/juju/cloudconfig/cloudinit"
"github.com/juju/juju/state/multiwatcher"
"github.com/juju/juju/core/model"
"github.com/juju/juju/testing"
jujuversion "github.com/juju/juju/version"
)
Expand All @@ -31,7 +31,7 @@ var _ = gc.Suite(&formatSuite{})
var agentParams = AgentConfigParams{
Tag: names.NewMachineTag("1"),
UpgradedToVersion: jujuversion.Current,
Jobs: []multiwatcher.MachineJob{multiwatcher.JobHostUnits},
Jobs: []model.MachineJob{model.JobHostUnits},
Password: "sekrit",
CACert: "ca cert",
APIAddresses: []string{"localhost:1235"},
Expand Down
4 changes: 2 additions & 2 deletions api/agent/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import (
apiagent "github.com/juju/juju/api/agent"
apiserveragent "github.com/juju/juju/apiserver/facades/agent/agent"
"github.com/juju/juju/apiserver/params"
"github.com/juju/juju/core/model"
"github.com/juju/juju/juju/testing"
"github.com/juju/juju/mongo"
"github.com/juju/juju/mongo/mongotest"
"github.com/juju/juju/rpc"
"github.com/juju/juju/state"
"github.com/juju/juju/state/multiwatcher"
coretesting "github.com/juju/juju/testing"
)

Expand Down Expand Up @@ -136,7 +136,7 @@ func (s *machineSuite) TestMachineEntity(c *gc.C) {
c.Assert(err, jc.ErrorIsNil)
c.Assert(m.Tag(), gc.Equals, s.machine.Tag().String())
c.Assert(m.Life(), gc.Equals, params.Alive)
c.Assert(m.Jobs(), gc.DeepEquals, []multiwatcher.MachineJob{multiwatcher.JobHostUnits})
c.Assert(m.Jobs(), gc.DeepEquals, []model.MachineJob{model.JobHostUnits})

err = s.machine.EnsureDead()
c.Assert(err, jc.ErrorIsNil)
Expand Down
4 changes: 2 additions & 2 deletions api/agent/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/juju/juju/api/common/cloudspec"
"github.com/juju/juju/apiserver/params"
"github.com/juju/juju/core/instance"
"github.com/juju/juju/state/multiwatcher"
"github.com/juju/juju/core/model"
)

// State provides access to an agent's view of the state.
Expand Down Expand Up @@ -109,7 +109,7 @@ func (m *Entity) Life() params.Life {
// if the API is running on behalf of a machine agent.
// When running for other agents, it will return
// the empty list.
func (m *Entity) Jobs() []multiwatcher.MachineJob {
func (m *Entity) Jobs() []model.MachineJob {
return m.doc.Jobs
}

Expand Down
5 changes: 2 additions & 3 deletions api/allwatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/juju/juju/api/base"
"github.com/juju/juju/apiserver/params"
"github.com/juju/juju/state/multiwatcher"
)

// AllWatcher holds information allowing us to get Deltas describing
Expand Down Expand Up @@ -50,7 +49,7 @@ func newAllWatcher(objType string, caller base.APICaller, id *string) *AllWatche
// Next returns a new set of deltas from a watcher previously created
// by the WatchAll or WatchAllModels API calls. It will block until
// there are deltas to return.
func (watcher *AllWatcher) Next() ([]multiwatcher.Delta, error) {
func (watcher *AllWatcher) Next() ([]params.Delta, error) {
var info params.AllWatcherNextResults
err := watcher.caller.APICall(
watcher.objType,
Expand All @@ -66,7 +65,7 @@ func (watcher *AllWatcher) Next() ([]multiwatcher.Delta, error) {
return info.Deltas, err
}

type orderedDeltas []multiwatcher.Delta
type orderedDeltas []params.Delta

func (o orderedDeltas) Len() int {
return len(o)
Expand Down
6 changes: 3 additions & 3 deletions api/application/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,7 @@ func (s *applicationSuite) TestApplicationsInfo(c *gc.C) {
c.Assert(ok, jc.IsTrue)
result.Results = []params.ApplicationInfoResult{
{Error: &params.Error{Message: "boom"}},
{Result: &params.ApplicationInfo{
{Result: &params.ApplicationResult{
Tag: "application-bar",
Charm: "charm-bar",
Series: "bionic",
Expand Down Expand Up @@ -1517,7 +1517,7 @@ func (s *applicationSuite) TestApplicationsInfo(c *gc.C) {
c.Assert(err, jc.ErrorIsNil)
c.Assert(results, gc.DeepEquals, []params.ApplicationInfoResult{
{Error: &params.Error{Message: "boom"}},
{Result: &params.ApplicationInfo{
{Result: &params.ApplicationResult{
Tag: "application-bar",
Charm: "charm-bar",
Series: "bionic",
Expand All @@ -1543,7 +1543,7 @@ func (s *applicationSuite) TestApplicationsInfoResultMismatch(c *gc.C) {
result.Results = []params.ApplicationInfoResult{
{Error: &params.Error{Message: "boom"}},
{Error: &params.Error{Message: "boom again"}},
{Result: &params.ApplicationInfo{Tag: "application-bar"}},
{Result: &params.ApplicationResult{Tag: "application-bar"}},
}
return nil
},
Expand Down
2 changes: 1 addition & 1 deletion api/charms/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type CharmInfo struct {
// CharmInfo returns information about the requested charm.
func (c *Client) CharmInfo(charmURL string) (*CharmInfo, error) {
args := params.CharmURL{URL: charmURL}
var info params.CharmInfo
var info params.Charm
if err := c.facade.FacadeCall("CharmInfo", args, &info); err != nil {
return nil, errors.Trace(err)
}
Expand Down
4 changes: 2 additions & 2 deletions api/charms/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ func (s *charmsMockSuite) TestCharmInfo(c *gc.C) {

url := "local:quantal/dummy-1"
args := params.CharmURL{URL: url}
info := new(params.CharmInfo)
info := new(params.Charm)

params := params.CharmInfo{
params := params.Charm{
Revision: 1,
URL: url,
Config: map[string]params.CharmOption{
Expand Down
9 changes: 4 additions & 5 deletions api/controller/legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/juju/juju/permission"
"github.com/juju/juju/provider/dummy"
"github.com/juju/juju/state"
"github.com/juju/juju/state/multiwatcher"
"github.com/juju/juju/testing"
"github.com/juju/juju/testing/factory"
)
Expand Down Expand Up @@ -147,7 +146,7 @@ func (s *legacySuite) TestWatchAllModels(c *gc.C) {
c.Assert(err, jc.ErrorIsNil)
}()

deltasC := make(chan []multiwatcher.Delta)
deltasC := make(chan []params.Delta)
go func() {
deltas, err := w.Next()
c.Assert(err, jc.ErrorIsNil)
Expand All @@ -157,7 +156,7 @@ func (s *legacySuite) TestWatchAllModels(c *gc.C) {
select {
case deltas := <-deltasC:
c.Assert(deltas, gc.HasLen, 1)
modelInfo := deltas[0].Entity.(*multiwatcher.ModelInfo)
modelInfo := deltas[0].Entity.(*params.ModelUpdate)

model, err := s.State.Model()
c.Assert(err, jc.ErrorIsNil)
Expand Down Expand Up @@ -185,14 +184,14 @@ func (s *legacySuite) TestWatchAllModels(c *gc.C) {
modelInfo.Config[config.NetBondReconfigureDelayKey] = int(val)
}

expectedStatus := multiwatcher.StatusInfo{
expectedStatus := params.StatusInfo{
Current: status.Status,
Message: status.Message,
}
modelInfo.Status.Since = nil
c.Assert(modelInfo.ModelUUID, gc.Equals, model.UUID())
c.Assert(modelInfo.Name, gc.Equals, model.Name())
c.Assert(modelInfo.Life, gc.Equals, multiwatcher.Life("alive"))
c.Assert(modelInfo.Life, gc.Equals, params.Life("alive"))
c.Assert(modelInfo.Owner, gc.Equals, model.Owner().Id())
c.Assert(modelInfo.ControllerUUID, gc.Equals, model.ControllerUUID())
c.Assert(modelInfo.Config, jc.DeepEquals, cfg.AllAttrs())
Expand Down
3 changes: 1 addition & 2 deletions api/uniter/relation.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/juju/juju/apiserver/params"
"github.com/juju/juju/core/relation"
"github.com/juju/juju/state/multiwatcher"
)

// This module implements a subset of the interface provided by
Expand Down Expand Up @@ -90,7 +89,7 @@ func (r *Relation) SetStatus(status relation.Status) error {
return r.st.setRelationStatus(r.id, status)
}

func (r *Relation) toCharmRelation(cr multiwatcher.CharmRelation) charm.Relation {
func (r *Relation) toCharmRelation(cr params.CharmRelation) charm.Relation {
return charm.Relation{
Name: cr.Name,
Role: charm.RelationRole(cr.Role),
Expand Down
Loading

0 comments on commit f26dd43

Please sign in to comment.