Skip to content

Commit

Permalink
Merge pull request #6478 from wallyworld/more-crossmodel-featureflag
Browse files Browse the repository at this point in the history
Add cross-model feature flag checks to more places to avoid trying to invoke missing functionality when the flag is not set.
  • Loading branch information
wallyworld committed Oct 20, 2016
2 parents 70abdba + 7a420a6 commit c211c22
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 16 deletions.
6 changes: 5 additions & 1 deletion apiserver/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/juju/errors"
"github.com/juju/loggo"
"github.com/juju/utils/featureflag"
"gopkg.in/juju/charm.v6-unstable"
csparams "gopkg.in/juju/charmrepo.v2-unstable/csclient/params"
goyaml "gopkg.in/yaml.v2"
Expand All @@ -26,7 +27,6 @@ import (
"github.com/juju/juju/permission"
"github.com/juju/juju/state"
statestorage "github.com/juju/juju/state/storage"
"github.com/juju/utils/featureflag"
)

var (
Expand All @@ -36,6 +36,10 @@ var (
)

func init() {
// TODO - version 1 is required for the legacy deployer,
// remove when deploy is updated.
common.RegisterStandardFacade("Application", 1, newAPI)

common.RegisterStandardFacade("Application", 2, newAPI)

// Version 3 adds support for cross model relations.
Expand Down
2 changes: 1 addition & 1 deletion cmd/juju/application/addrelation.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/juju/cmd"
"github.com/juju/errors"
"github.com/juju/utils/featureflag"
"gopkg.in/juju/names.v2"

"github.com/juju/juju/api/application"
Expand All @@ -18,7 +19,6 @@ import (
"github.com/juju/juju/cmd/modelcmd"
"github.com/juju/juju/core/crossmodel"
"github.com/juju/juju/feature"
"github.com/juju/utils/featureflag"
)

const addRelationDocCrossModel = `
Expand Down
2 changes: 1 addition & 1 deletion featuretests/cmd_juju_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (s *cmdControllerSuite) createModelNormalUser(c *gc.C, modelname string, is
func (s *cmdControllerSuite) TestControllerListCommand(c *gc.C) {
context := s.run(c, "list-controllers")
expectedOutput := `
Use --refresh to see the latest information.
Use --refresh flag with this command to see the latest information.
Controller Model User Access Cloud/Region Models Machines HA Version
kontroll* controller admin superuser dummy/dummy-region - - - (unknown)
Expand Down
2 changes: 1 addition & 1 deletion state/allcollections.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
package state

import (
"github.com/juju/utils/featureflag"
"gopkg.in/mgo.v2"

"github.com/juju/juju/feature"
"github.com/juju/juju/state/bakerystorage"
"github.com/juju/utils/featureflag"
)

// The capped collection used for transaction logs defaults to 10MB.
Expand Down
15 changes: 14 additions & 1 deletion state/allwatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import (
"strings"

"github.com/juju/errors"
"github.com/juju/utils/featureflag"
"gopkg.in/juju/names.v2"
"gopkg.in/mgo.v2"

"github.com/juju/juju/feature"
"github.com/juju/juju/network"
"github.com/juju/juju/state/multiwatcher"
"github.com/juju/juju/state/watcher"
Expand Down Expand Up @@ -1050,6 +1052,12 @@ func newAllWatcherStateBacking(st *State) Backing {
actionsC,
blocksC,
)
if featureflag.Enabled(feature.CrossModelRelations) {
crossModelCollections := makeAllWatcherCollectionInfo(remoteApplicationsC)
for name, w := range crossModelCollections {
collections[name] = w
}
}
return &allWatcherStateBacking{
st: st,
watcher: st.workers.TxnLogWatcher(),
Expand Down Expand Up @@ -1122,14 +1130,19 @@ func NewAllModelWatcherStateBacking(st *State) Backing {
machinesC,
unitsC,
applicationsC,
remoteApplicationsC,
relationsC,
annotationsC,
statusesC,
constraintsC,
settingsC,
openedPortsC,
)
if featureflag.Enabled(feature.CrossModelRelations) {
crossModelCollections := makeAllWatcherCollectionInfo(remoteApplicationsC)
for name, w := range crossModelCollections {
collections[name] = w
}
}
return &allModelWatcherStateBacking{
st: st,
watcher: st.workers.TxnLogWatcher(),
Expand Down
17 changes: 11 additions & 6 deletions state/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/juju/errors"
jujutxn "github.com/juju/txn"
"github.com/juju/utils/featureflag"
"github.com/juju/utils/series"
"gopkg.in/juju/charm.v6-unstable"
csparams "gopkg.in/juju/charmrepo.v2-unstable/csclient/params"
Expand All @@ -22,6 +23,7 @@ import (

"github.com/juju/juju/constraints"
"github.com/juju/juju/core/leadership"
"github.com/juju/juju/feature"
"github.com/juju/juju/status"
)

Expand Down Expand Up @@ -1747,15 +1749,18 @@ func addApplicationOps(st *State, args addApplicationOpsArgs) ([]txn.Op, error)
addModelApplicationRefOp(st, app.Name()),
}
ops = append(ops, charmRefOps...)
ops = append(ops, []txn.Op{{
ops = append(ops, txn.Op{
C: applicationsC,
Id: app.Name(),
Assert: txn.DocMissing,
Insert: args.applicationDoc,
}, {
C: remoteApplicationsC,
Id: app.Name(),
Assert: txn.DocMissing,
}}...)
})
if featureflag.Enabled(feature.CrossModelRelations) {
ops = append(ops, txn.Op{
C: remoteApplicationsC,
Id: app.Name(),
Assert: txn.DocMissing,
})
}
return ops, nil
}
14 changes: 9 additions & 5 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
jujutxn "github.com/juju/txn"
"github.com/juju/utils"
"github.com/juju/utils/clock"
"github.com/juju/utils/featureflag"
"github.com/juju/utils/os"
"github.com/juju/utils/series"
"github.com/juju/utils/set"
Expand All @@ -35,6 +36,7 @@ import (
"github.com/juju/juju/audit"
"github.com/juju/juju/constraints"
"github.com/juju/juju/core/lease"
"github.com/juju/juju/feature"
"github.com/juju/juju/instance"
"github.com/juju/juju/mongo"
"github.com/juju/juju/network"
Expand Down Expand Up @@ -1149,11 +1151,13 @@ func (st *State) AddApplication(args AddApplicationArgs) (_ *Application, err er
} else if exists {
return nil, errLocalApplicationExists
}
// Ensure a remote application with the same name doesn't exist.
if remoteExists, err := isNotDead(st, remoteApplicationsC, args.Name); err != nil {
return nil, errors.Trace(err)
} else if remoteExists {
return nil, errSameNameRemoteApplicationExists
if featureflag.Enabled(feature.CrossModelRelations) {
// Ensure a remote application with the same name doesn't exist.
if remoteExists, err := isNotDead(st, remoteApplicationsC, args.Name); err != nil {
return nil, errors.Trace(err)
} else if remoteExists {
return nil, errSameNameRemoteApplicationExists
}
}
}
// The addApplicationOps does not include the model alive assertion,
Expand Down

0 comments on commit c211c22

Please sign in to comment.