Permalink
Browse files

Remove model facade entirely

  • Loading branch information...
1 parent de0cac8 commit 95a766fd18728ac9331e4f282efcb7861a1e0277 @wallyworld wallyworld committed Jan 28, 2016
@@ -1,11 +1,12 @@
// Copyright 2014 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
-package model_test
+package agent_test
import (
gc "gopkg.in/check.v1"
+ "github.com/juju/juju/api/agent"
apitesting "github.com/juju/juju/api/testing"
jujutesting "github.com/juju/juju/juju/testing"
)
@@ -22,9 +23,9 @@ func (s *modelSuite) SetUpTest(c *gc.C) {
stateAPI, _ := s.OpenAPIAsNewMachine(c)
- modelAPI := stateAPI.Model()
- c.Assert(modelAPI, gc.NotNil)
+ agentAPI := agent.NewState(stateAPI)
+ c.Assert(agentAPI, gc.NotNil)
s.ModelWatcherTests = apitesting.NewModelWatcherTests(
- modelAPI, s.BackingState, apitesting.NoSecrets)
+ agentAPI, s.BackingState, apitesting.NoSecrets)
}
View
@@ -9,6 +9,7 @@ import (
"github.com/juju/names"
"github.com/juju/juju/api/base"
+ "github.com/juju/juju/api/common"
"github.com/juju/juju/apiserver/params"
"github.com/juju/juju/instance"
"github.com/juju/juju/state/multiwatcher"
@@ -17,13 +18,17 @@ import (
// State provides access to an agent's view of the state.
type State struct {
facade base.FacadeCaller
+ *common.ModelWatcher
}
// NewState returns a version of the state that provides functionality
// required by agent code.
func NewState(caller base.APICaller) *State {
facadeCaller := base.NewFacadeCaller(caller, "Agent")
- return &State{facadeCaller}
+ return &State{
+ facade: facadeCaller,
+ ModelWatcher: common.NewModelWatcher(facadeCaller),
+ }
}
func (st *State) getEntity(tag names.Tag) (*params.AgentGetEntitiesResult, error) {
View
@@ -43,7 +43,6 @@ var facadeVersions = map[string]int{
"MetricsManager": 1,
"MeterStatus": 1,
"MetricsAdder": 2,
- "Model": 1,
"ModelManager": 2,
"Networker": 1,
"NotifyWatcher": 1,
View
@@ -22,7 +22,6 @@ import (
"github.com/juju/juju/api/keyupdater"
apilogger "github.com/juju/juju/api/logger"
"github.com/juju/juju/api/machiner"
- "github.com/juju/juju/api/model"
"github.com/juju/juju/api/networker"
"github.com/juju/juju/api/provisioner"
"github.com/juju/juju/api/reboot"
@@ -173,7 +172,6 @@ type Connection interface {
Upgrader() *upgrader.State
Reboot() (reboot.State, error)
Deployer() *deployer.State
- Model() *model.Facade
Logger() *apilogger.State
KeyUpdater() *keyupdater.State
Addresser() *addresser.API
View
@@ -1,24 +0,0 @@
-// Copyright 2014 Canonical Ltd.
-// Licensed under the AGPLv3, see LICENCE file for details.
-
-package model
-
-import (
- "github.com/juju/juju/api/base"
- "github.com/juju/juju/api/common"
-)
-
-const apiName = "Model"
-
-// Facade provides access to a model worker's view of the world.
-type Facade struct {
- *common.ModelWatcher
-}
-
-// NewFacade returns a new api client facade instance.
-func NewFacade(caller base.APICaller) *Facade {
- facadeCaller := base.NewFacadeCaller(caller, apiName)
- return &Facade{
- ModelWatcher: common.NewModelWatcher(facadeCaller),
- }
-}
View
@@ -1,14 +0,0 @@
-// Copyright 2014 Canonical Ltd.
-// Licensed under the AGPLv3, see LICENCE file for details.
-
-package model_test
-
-import (
- stdtesting "testing"
-
- "github.com/juju/juju/testing"
-)
-
-func TestAll(t *stdtesting.T) {
- testing.MgoTestPackage(t)
-}
@@ -24,4 +24,5 @@ func NewFacade(caller base.APICaller) *Facade {
}
// TODO(wallyworld) - add methods for getting proxy settings specifically,
-// rather than the entire model config
+// rather than the entire model config.
+// Also WatchProxySettings instead of WatchForModelConfigChanges.
@@ -22,9 +22,9 @@ func (s *modelSuite) SetUpTest(c *gc.C) {
stateAPI, _ := s.OpenAPIAsNewMachine(c)
- modelAPI := stateAPI.Model()
- c.Assert(modelAPI, gc.NotNil)
+ agentAPI := stateAPI.Agent()
+ c.Assert(agentAPI, gc.NotNil)
s.ModelWatcherTests = apitesting.NewModelWatcherTests(
- modelAPI, s.BackingState, apitesting.NoSecrets)
+ agentAPI, s.BackingState, apitesting.NoSecrets)
}
View
@@ -24,7 +24,6 @@ import (
"github.com/juju/juju/api/keyupdater"
apilogger "github.com/juju/juju/api/logger"
"github.com/juju/juju/api/machiner"
- "github.com/juju/juju/api/model"
"github.com/juju/juju/api/networker"
"github.com/juju/juju/api/provisioner"
"github.com/juju/juju/api/reboot"
@@ -366,11 +365,6 @@ func (st *state) Addresser() *addresser.API {
return addresser.NewAPI(st)
}
-// Model returns access to the Model API
-func (st *state) Model() *model.Facade {
- return model.NewFacade(st)
-}
-
// Logger returns access to the Logger API
func (st *state) Logger() *apilogger.State {
return apilogger.NewState(st)
View
@@ -25,6 +25,7 @@ func init() {
type AgentAPIV2 struct {
*common.PasswordChanger
*common.RebootFlagClearer
+ *common.ModelWatcher
st *state.State
auth common.Authorizer
@@ -43,6 +44,7 @@ func NewAgentAPIV2(st *state.State, resources *common.Resources, auth common.Aut
return &AgentAPIV2{
PasswordChanger: common.NewPasswordChanger(st, getCanChange),
RebootFlagClearer: common.NewRebootFlagClearer(st, getCanChange),
+ ModelWatcher: common.NewModelWatcher(st, resources, auth),
st: st,
auth: auth,
}, nil
@@ -1,15 +1,15 @@
// Copyright 2013 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
-package model_test
+package agent_test
import (
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
+ "github.com/juju/juju/apiserver/agent"
"github.com/juju/juju/apiserver/common"
commontesting "github.com/juju/juju/apiserver/common/testing"
- "github.com/juju/juju/apiserver/model"
apiservertesting "github.com/juju/juju/apiserver/testing"
"github.com/juju/juju/juju/testing"
"github.com/juju/juju/state"
@@ -23,7 +23,7 @@ type modelSuite struct {
resources *common.Resources
machine0 *state.Machine
- api *model.ModelAPI
+ api *agent.AgentAPIV2
}
var _ = gc.Suite(&modelSuite{})
@@ -41,7 +41,7 @@ func (s *modelSuite) SetUpTest(c *gc.C) {
s.resources = common.NewResources()
s.AddCleanup(func(_ *gc.C) { s.resources.StopAll() })
- s.api, err = model.NewModelAPI(
+ s.api, err = agent.NewAgentAPIV2(
s.State,
s.resources,
s.authorizer,
View
@@ -10,6 +10,7 @@ import (
_ "github.com/juju/juju/apiserver/action"
_ "github.com/juju/juju/apiserver/addresser"
_ "github.com/juju/juju/apiserver/agent"
+ _ "github.com/juju/juju/apiserver/agenttools"
_ "github.com/juju/juju/apiserver/annotations"
_ "github.com/juju/juju/apiserver/backups"
_ "github.com/juju/juju/apiserver/block"
@@ -32,10 +33,10 @@ import (
_ "github.com/juju/juju/apiserver/meterstatus"
_ "github.com/juju/juju/apiserver/metricsadder"
_ "github.com/juju/juju/apiserver/metricsmanager"
- _ "github.com/juju/juju/apiserver/model"
_ "github.com/juju/juju/apiserver/modelmanager"
_ "github.com/juju/juju/apiserver/networker"
_ "github.com/juju/juju/apiserver/provisioner"
+ _ "github.com/juju/juju/apiserver/proxyupdater"
_ "github.com/juju/juju/apiserver/reboot"
_ "github.com/juju/juju/apiserver/resumer"
_ "github.com/juju/juju/apiserver/service"
View
@@ -1,25 +0,0 @@
-// Copyright 2014 Canonical Ltd.
-// Licensed under the AGPLv3, see LICENCE file for details.
-
-package model
-
-import (
- "github.com/juju/juju/apiserver/common"
- "github.com/juju/juju/state"
-)
-
-func init() {
- common.RegisterStandardFacade("Model", 1, NewModelAPI)
-}
-
-// ModelAPI implements the API used by the machine model worker.
-type ModelAPI struct {
- *common.ModelWatcher
-}
-
-// NewModelAPI creates a new instance of the Model API.
-func NewModelAPI(st *state.State, resources *common.Resources, authorizer common.Authorizer) (*ModelAPI, error) {
- return &ModelAPI{
- ModelWatcher: common.NewModelWatcher(st, resources, authorizer),
- }, nil
-}
@@ -1,14 +0,0 @@
-// Copyright 2014 Canonical Ltd.
-// Licensed under the AGPLv3, see LICENCE file for details.
-
-package model_test
-
-import (
- stdtesting "testing"
-
- "github.com/juju/juju/testing"
-)
-
-func TestAll(t *stdtesting.T) {
- testing.MgoTestPackage(t)
-}
@@ -7,9 +7,9 @@ import (
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
+ "github.com/juju/juju/apiserver/agent"
"github.com/juju/juju/apiserver/common"
commontesting "github.com/juju/juju/apiserver/common/testing"
- "github.com/juju/juju/apiserver/model"
apiservertesting "github.com/juju/juju/apiserver/testing"
"github.com/juju/juju/juju/testing"
"github.com/juju/juju/state"
@@ -23,7 +23,7 @@ type ProxyUpdaterSuite struct {
resources *common.Resources
machine0 *state.Machine
- api *model.ModelAPI
+ api *agent.AgentAPIV2
}
var _ = gc.Suite(&ProxyUpdaterSuite{})
@@ -41,7 +41,7 @@ func (s *ProxyUpdaterSuite) SetUpTest(c *gc.C) {
s.resources = common.NewResources()
s.AddCleanup(func(_ *gc.C) { s.resources.StopAll() })
- s.api, err = model.NewModelAPI(
+ s.api, err = agent.NewAgentAPIV2(
s.State,
s.resources,
s.authorizer,
@@ -9,7 +9,7 @@ import (
"github.com/juju/utils/series"
gc "gopkg.in/check.v1"
- apienvironment "github.com/juju/juju/api/model"
+ apiproxyupdater "github.com/juju/juju/api/proxyupdater"
agenttesting "github.com/juju/juju/cmd/jujud/agent/testing"
cmdutil "github.com/juju/juju/cmd/jujud/util"
imagetesting "github.com/juju/juju/environs/imagemetadata/testing"
@@ -74,7 +74,7 @@ func (s *AgentSuite) SetUpTest(c *gc.C) {
}
err := s.State.SetAPIHostPorts(hostPorts)
c.Assert(err, jc.ErrorIsNil)
- s.PatchValue(&proxyupdater.New, func(*apienvironment.Facade, bool) worker.Worker {
+ s.PatchValue(&proxyupdater.New, func(*apiproxyupdater.Facade, bool) worker.Worker {
return newDummyWorker()
})
@@ -752,7 +752,7 @@ func (a *MachineAgent) postUpgradeAPIWorker(
return logsender.New(a.bufferedLogs, apilogsender.NewAPI(st)), nil
})
- envConfig, err := st.Model().ModelConfig()
+ envConfig, err := st.Agent().ModelConfig()
if err != nil {
return nil, fmt.Errorf("cannot read model config: %v", err)
}
@@ -1387,7 +1387,7 @@ func (a *MachineAgent) newRunnersForAPIConn(
var getFirewallMode = _getFirewallMode
func _getFirewallMode(apiSt api.Connection) (string, error) {
- envConfig, err := apiSt.Model().ModelConfig()
+ envConfig, err := apiSt.Agent().ModelConfig()
if err != nil {
return "", errors.Annotate(err, "cannot read model config")
}
@@ -17,6 +17,7 @@ import (
"github.com/juju/cmd"
"github.com/juju/cmd/cmdtesting"
"github.com/juju/errors"
+ apiproxyupdater "github.com/juju/juju/api/proxyupdater"
"github.com/juju/names"
gitjujutesting "github.com/juju/testing"
jc "github.com/juju/testing/checkers"
@@ -42,7 +43,6 @@ import (
"github.com/juju/juju/api/imagemetadata"
apiinstancepoller "github.com/juju/juju/api/instancepoller"
apimetricsmanager "github.com/juju/juju/api/metricsmanager"
- apienvironment "github.com/juju/juju/api/model"
apinetworker "github.com/juju/juju/api/networker"
apiundertaker "github.com/juju/juju/api/undertaker"
charmtesting "github.com/juju/juju/apiserver/charmrevisionupdater/testing"
@@ -1339,7 +1339,7 @@ func (s *MachineSuite) assertProxyUpdater(c *gc.C, expectWriteSystemFiles bool)
// Patch out the actual worker func.
started := make(chan struct{})
- mockNew := func(api *apienvironment.Facade, writeSystemFiles bool) worker.Worker {
+ mockNew := func(api *apiproxyupdater.Facade, writeSystemFiles bool) worker.Worker {
// Direct check of the behaviour flag.
c.Check(writeSystemFiles, gc.Equals, expectWriteSystemFiles)
// Indirect check that we get a functional API.
Oops, something went wrong.

0 comments on commit 95a766f

Please sign in to comment.