Skip to content

Commit f39e17a

Browse files
committed
state: more type shuffling
1 parent 4179d3d commit f39e17a

File tree

11 files changed

+86
-79
lines changed

11 files changed

+86
-79
lines changed

agent/agent.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/juju/names"
2121
"github.com/juju/utils"
2222

23+
"github.com/juju/juju"
2324
"github.com/juju/juju/api"
2425
"github.com/juju/juju/apiserver/params"
2526
"github.com/juju/juju/cloudinit"
@@ -85,7 +86,7 @@ type Config interface {
8586
SystemIdentityPath() string
8687

8788
// Jobs returns a list of MachineJobs that need to run.
88-
Jobs() []params.MachineJob
89+
Jobs() []juju.MachineJob
8990

9091
// Tag returns the tag of the entity on whose behalf the state connection
9192
// will be made.
@@ -207,7 +208,7 @@ type ConfigSetterWriter interface {
207208
type MigrateParams struct {
208209
DataDir string
209210
LogDir string
210-
Jobs []params.MachineJob
211+
Jobs []juju.MachineJob
211212
DeleteValues []string
212213
Values map[string]string
213214
}
@@ -235,7 +236,7 @@ type configInternal struct {
235236
logDir string
236237
tag names.Tag
237238
nonce string
238-
jobs []params.MachineJob
239+
jobs []juju.MachineJob
239240
upgradedToVersion version.Number
240241
caCert string
241242
stateDetails *connectionDetails
@@ -249,7 +250,7 @@ type configInternal struct {
249250
type AgentConfigParams struct {
250251
DataDir string
251252
LogDir string
252-
Jobs []params.MachineJob
253+
Jobs []juju.MachineJob
253254
UpgradedToVersion version.Number
254255
Tag names.Tag
255256
Password string
@@ -420,7 +421,7 @@ func (c0 *configInternal) Clone() Config {
420421
// by ConfigSetter methods.
421422
c1.stateDetails = c0.stateDetails.clone()
422423
c1.apiDetails = c0.apiDetails.clone()
423-
c1.jobs = append([]params.MachineJob{}, c0.jobs...)
424+
c1.jobs = append([]juju.MachineJob{}, c0.jobs...)
424425
c1.values = make(map[string]string, len(c0.values))
425426
for key, val := range c0.values {
426427
c1.values[key] = val
@@ -437,7 +438,7 @@ func (config *configInternal) Migrate(newParams MigrateParams) error {
437438
config.logDir = newParams.LogDir
438439
}
439440
if len(newParams.Jobs) > 0 {
440-
config.jobs = make([]params.MachineJob, len(newParams.Jobs))
441+
config.jobs = make([]juju.MachineJob, len(newParams.Jobs))
441442
copy(config.jobs, newParams.Jobs)
442443
}
443444
for _, key := range newParams.DeleteValues {
@@ -527,7 +528,7 @@ func (c *configInternal) SystemIdentityPath() string {
527528
return filepath.Join(c.dataDir, SystemIdentity)
528529
}
529530

530-
func (c *configInternal) Jobs() []params.MachineJob {
531+
func (c *configInternal) Jobs() []juju.MachineJob {
531532
return c.jobs
532533
}
533534

agent/bootstrap.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/juju/names"
99
"github.com/juju/utils"
1010

11+
"github.com/juju/juju"
1112
"github.com/juju/juju/apiserver/params"
1213
"github.com/juju/juju/constraints"
1314
"github.com/juju/juju/environs/config"
@@ -34,7 +35,7 @@ type BootstrapMachineConfig struct {
3435
Constraints constraints.Value
3536

3637
// Jobs holds the jobs that the machine agent will run.
37-
Jobs []params.MachineJob
38+
Jobs []juju.MachineJob
3839

3940
// InstanceId holds the instance id of the bootstrap machine.
4041
InstanceId instance.Id
@@ -198,15 +199,15 @@ func initAPIHostPorts(c ConfigSetter, st *state.State, addrs []network.Address,
198199
// machineJobFromParams returns the job corresponding to params.MachineJob.
199200
// TODO(dfc) this function should live in apiserver/params, move there once
200201
// state does not depend on apiserver/params
201-
func machineJobFromParams(job params.MachineJob) (state.MachineJob, error) {
202+
func machineJobFromParams(job juju.MachineJob) (state.MachineJob, error) {
202203
switch job {
203-
case params.JobHostUnits:
204+
case juju.JobHostUnits:
204205
return state.JobHostUnits, nil
205-
case params.JobManageEnviron:
206+
case juju.JobManageEnviron:
206207
return state.JobManageEnviron, nil
207-
case params.JobManageNetworking:
208+
case juju.JobManageNetworking:
208209
return state.JobManageNetworking, nil
209-
case params.JobManageStateDeprecated:
210+
case juju.JobManageStateDeprecated:
210211
// Deprecated in 1.18.
211212
return state.JobManageStateDeprecated, nil
212213
default:

agent/format-1.18.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/juju/names"
1212
goyaml "gopkg.in/yaml.v1"
1313

14+
"github.com/juju/juju"
1415
"github.com/juju/juju/apiserver/params"
1516
"github.com/juju/juju/version"
1617
)
@@ -30,8 +31,8 @@ type format_1_18Serialization struct {
3031
DataDir string
3132
LogDir string
3233
Nonce string
33-
Jobs []params.MachineJob `yaml:",omitempty"`
34-
UpgradedToVersion *version.Number `yaml:"upgradedToVersion"`
34+
Jobs []juju.MachineJob `yaml:",omitempty"`
35+
UpgradedToVersion *version.Number `yaml:"upgradedToVersion"`
3536

3637
CACert string
3738
StateAddresses []string `yaml:",omitempty"`

api/agent/state.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/juju/names"
1010

11+
"github.com/juju/juju"
1112
"github.com/juju/juju/api/base"
1213
"github.com/juju/juju/apiserver/params"
1314
"github.com/juju/juju/instance"
@@ -93,7 +94,7 @@ func (m *Entity) Life() params.Life {
9394
// if the API is running on behalf of a machine agent.
9495
// When running for other agents, it will return
9596
// the empty list.
96-
func (m *Entity) Jobs() []params.MachineJob {
97+
func (m *Entity) Jobs() []juju.MachineJob {
9798
return m.doc.Jobs
9899
}
99100

api/client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/juju/utils"
2424
"gopkg.in/juju/charm.v4"
2525

26+
"github.com/juju/juju"
2627
"github.com/juju/juju/api/base"
2728
"github.com/juju/juju/apiserver/params"
2829
"github.com/juju/juju/constraints"
@@ -77,7 +78,7 @@ type MachineStatus struct {
7778
Id string
7879
Containers map[string]MachineStatus
7980
Hardware string
80-
Jobs []params.MachineJob
81+
Jobs []juju.MachineJob
8182
HasVote bool
8283
WantsVote bool
8384
}

apiserver/params/constants.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,35 +31,6 @@ const (
3131
ShouldShutdown RebootAction = "shutdown"
3232
)
3333

34-
// MachineJob values define responsibilities that machines may be
35-
// expected to fulfil.
36-
type MachineJob string
37-
38-
const (
39-
JobHostUnits MachineJob = "JobHostUnits"
40-
JobManageEnviron MachineJob = "JobManageEnviron"
41-
JobManageNetworking MachineJob = "JobManageNetworking"
42-
43-
// Deprecated in 1.18
44-
JobManageStateDeprecated MachineJob = "JobManageState"
45-
)
46-
47-
// NeedsState returns true if the job requires a state connection.
48-
func (job MachineJob) NeedsState() bool {
49-
return job == JobManageEnviron
50-
}
51-
52-
// AnyJobNeedsState returns true if any of the provided jobs
53-
// require a state connection.
54-
func AnyJobNeedsState(jobs ...MachineJob) bool {
55-
for _, j := range jobs {
56-
if j.NeedsState() {
57-
return true
58-
}
59-
}
60-
return false
61-
}
62-
6334
// ResolvedMode describes the way state transition errors
6435
// are resolved.
6536
type ResolvedMode string

apiserver/params/internal.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ type AgentGetEntitiesResults struct {
487487
// machineagent.API.GetEntities call for a single entity.
488488
type AgentGetEntitiesResult struct {
489489
Life Life
490-
Jobs []MachineJob
490+
Jobs []juju.MachineJob
491491
ContainerType instance.ContainerType
492492
Error *Error
493493
}
@@ -621,7 +621,7 @@ type ProvisioningInfo struct {
621621
Series string
622622
Placement string
623623
Networks []string
624-
Jobs []MachineJob
624+
Jobs []juju.MachineJob
625625
}
626626

627627
// ProvisioningInfoResult holds machine provisioning info or an error.

apiserver/params/params.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/juju/utils/proxy"
1616
"gopkg.in/juju/charm.v4"
1717

18+
"github.com/juju/juju"
1819
"github.com/juju/juju/constraints"
1920
"github.com/juju/juju/instance"
2021
"github.com/juju/juju/network"
@@ -110,7 +111,7 @@ type AddMachineParams struct {
110111
// new machine when it is created.
111112
Series string
112113
Constraints constraints.Value
113-
Jobs []MachineJob
114+
Jobs []juju.MachineJob
114115

115116
// If Placement is non-nil, it contains a placement directive
116117
// that will be used to decide how to instantiate the machine.
@@ -543,7 +544,7 @@ type MachineInfo struct {
543544
SupportedContainers []instance.ContainerType
544545
SupportedContainersKnown bool
545546
HardwareCharacteristics *instance.HardwareCharacteristics `json:",omitempty"`
546-
Jobs []MachineJob
547+
Jobs []juju.MachineJob
547548
Addresses []network.Address
548549
}
549550

juju.go

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,41 @@ package juju
1313
// When remote units leave scope, their ids will be noted in the
1414
// Departed field, and no further events will be sent for those units.
1515
type RelationUnitsChange struct {
16-
Changed map[string]UnitSettings
17-
Departed []string
16+
Changed map[string]UnitSettings
17+
Departed []string
1818
}
1919

2020
// UnitSettings holds information about a service unit's settings
2121
// within a relation.
2222
type UnitSettings struct {
23-
Version int64
23+
Version int64
24+
}
25+
26+
// MachineJob values define responsibilities that machines may be
27+
// expected to fulfil.
28+
type MachineJob string
29+
30+
const (
31+
JobHostUnits MachineJob = "JobHostUnits"
32+
JobManageEnviron MachineJob = "JobManageEnviron"
33+
JobManageNetworking MachineJob = "JobManageNetworking"
34+
35+
// Deprecated in 1.18
36+
JobManageStateDeprecated MachineJob = "JobManageState"
37+
)
38+
39+
// NeedsState returns true if the job requires a state connection.
40+
func (job MachineJob) NeedsState() bool {
41+
return job == JobManageEnviron
42+
}
43+
44+
// AnyJobNeedsState returns true if any of the provided jobs
45+
// require a state connection.
46+
func AnyJobNeedsState(jobs ...MachineJob) bool {
47+
for _, j := range jobs {
48+
if j.NeedsState() {
49+
return true
50+
}
51+
}
52+
return false
2453
}

state/machine.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"gopkg.in/mgo.v2/bson"
1919
"gopkg.in/mgo.v2/txn"
2020

21-
"github.com/juju/juju/apiserver/params"
21+
"github.com/juju/juju"
2222
"github.com/juju/juju/constraints"
2323
"github.com/juju/juju/instance"
2424
"github.com/juju/juju/mongo"
@@ -50,13 +50,13 @@ const (
5050
JobManageStateDeprecated
5151
)
5252

53-
var jobNames = map[MachineJob]params.MachineJob{
54-
JobHostUnits: params.JobHostUnits,
55-
JobManageEnviron: params.JobManageEnviron,
56-
JobManageNetworking: params.JobManageNetworking,
53+
var jobNames = map[MachineJob]juju.MachineJob{
54+
JobHostUnits: juju.JobHostUnits,
55+
JobManageEnviron: juju.JobManageEnviron,
56+
JobManageNetworking: juju.JobManageNetworking,
5757

5858
// Deprecated in 1.18.
59-
JobManageStateDeprecated: params.JobManageStateDeprecated,
59+
JobManageStateDeprecated: juju.JobManageStateDeprecated,
6060
}
6161

6262
// AllJobs returns all supported machine jobs.
@@ -68,21 +68,21 @@ func AllJobs() []MachineJob {
6868
}
6969
}
7070

71-
// ToParams returns the job as params.MachineJob.
72-
func (job MachineJob) ToParams() params.MachineJob {
73-
if paramsJob, ok := jobNames[job]; ok {
74-
return paramsJob
71+
// ToParams returns the job as juju.MachineJob.
72+
func (job MachineJob) ToParams() juju.MachineJob {
73+
if jujuJob, ok := jobNames[job]; ok {
74+
return jujuJob
7575
}
76-
return params.MachineJob(fmt.Sprintf("<unknown job %d>", int(job)))
76+
return juju.MachineJob(fmt.Sprintf("<unknown job %d>", int(job)))
7777
}
7878

79-
// paramsJobsFromJobs converts state jobs to params jobs.
80-
func paramsJobsFromJobs(jobs []MachineJob) []params.MachineJob {
81-
paramsJobs := make([]params.MachineJob, len(jobs))
79+
// params.JobsFromJobs converts state jobs to juju jobs.
80+
func paramsJobsFromJobs(jobs []MachineJob) []juju.MachineJob {
81+
jujuJobs := make([]juju.MachineJob, len(jobs))
8282
for i, machineJob := range jobs {
83-
paramsJobs[i] = machineJob.ToParams()
83+
jujuJobs[i] = machineJob.ToParams()
8484
}
85-
return paramsJobs
85+
return jujuJobs
8686
}
8787

8888
func (job MachineJob) String() string {
@@ -94,7 +94,7 @@ func (job MachineJob) String() string {
9494
const manualMachinePrefix = "manual:"
9595

9696
// machineDoc represents the internal state of a machine in MongoDB.
97-
// Note the correspondence with MachineInfo in apiserver/params.
97+
// Note the correspondence with MachineInfo in apiserver/juju.
9898
type machineDoc struct {
9999
DocID string `bson:"_id"`
100100
Id string `bson:"machineid"`

0 commit comments

Comments
 (0)