Skip to content

Commit

Permalink
Merge commit 'ed78ec51b1a7509ef69ed0cd81814214952056ac' into null-mer…
Browse files Browse the repository at this point in the history
…ge-1.25

Conflicts:
	component/all/payload.go
  • Loading branch information
ericsnowcurrently committed Nov 4, 2015
2 parents 9c9dc58 + ed78ec5 commit 3586c80
Show file tree
Hide file tree
Showing 79 changed files with 911 additions and 934 deletions.
2 changes: 1 addition & 1 deletion component/all/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type component interface {
}

var components = []component{
&workloads{},
&payloads{},
}

// RegisterForServer registers all the parts of the components with the
Expand Down
82 changes: 41 additions & 41 deletions component/all/workload.go → component/all/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@ import (
"github.com/juju/juju/apiserver/common"
"github.com/juju/juju/cmd/envcmd"
"github.com/juju/juju/cmd/juju/commands"
"github.com/juju/juju/payload"
"github.com/juju/juju/payload/api/client"
internalclient "github.com/juju/juju/payload/api/internal/client"
internalserver "github.com/juju/juju/payload/api/internal/server"
"github.com/juju/juju/payload/api/server"
"github.com/juju/juju/payload/context"
"github.com/juju/juju/payload/persistence"
payloadstate "github.com/juju/juju/payload/state"
"github.com/juju/juju/payload/status"
"github.com/juju/juju/state"
unitercontext "github.com/juju/juju/worker/uniter/runner/context"
"github.com/juju/juju/worker/uniter/runner/jujuc"
"github.com/juju/juju/workload"
"github.com/juju/juju/workload/api/client"
internalclient "github.com/juju/juju/workload/api/internal/client"
internalserver "github.com/juju/juju/workload/api/internal/server"
"github.com/juju/juju/workload/api/server"
"github.com/juju/juju/workload/context"
"github.com/juju/juju/workload/persistence"
workloadstate "github.com/juju/juju/workload/state"
"github.com/juju/juju/workload/status"
)

const workloadsHookContextFacade = workload.ComponentName + "-hook-context"
const payloadsHookContextFacade = payload.ComponentName + "-hook-context"

type workloads struct{}
type payloads struct{}

func (c workloads) registerForServer() error {
func (c payloads) registerForServer() error {
c.registerState()
c.registerPublicFacade()

Expand All @@ -40,22 +40,22 @@ func (c workloads) registerForServer() error {
return nil
}

func (c workloads) registerForClient() error {
func (c payloads) registerForClient() error {
c.registerPublicCommands()
return nil
}

func (workloads) newPublicFacade(st *state.State, resources *common.Resources, authorizer common.Authorizer) (*server.PublicAPI, error) {
func (payloads) newPublicFacade(st *state.State, resources *common.Resources, authorizer common.Authorizer) (*server.PublicAPI, error) {
up, err := st.EnvPayloads()
if err != nil {
return nil, errors.Trace(err)
}
return server.NewPublicAPI(up), nil
}

func (c workloads) registerPublicFacade() {
func (c payloads) registerPublicFacade() {
common.RegisterStandardFacade(
workload.ComponentName,
payload.ComponentName,
0,
c.newPublicFacade,
)
Expand All @@ -70,12 +70,12 @@ func (c facadeCaller) Close() error {
return c.closeFunc()
}

func (workloads) newListAPIClient(cmd *status.ListCommand) (status.ListAPI, error) {
func (payloads) newListAPIClient(cmd *status.ListCommand) (status.ListAPI, error) {
apiCaller, err := cmd.NewAPIRoot()
if err != nil {
return nil, errors.Trace(err)
}
caller := base.NewFacadeCallerForVersion(apiCaller, workload.ComponentName, 0)
caller := base.NewFacadeCallerForVersion(apiCaller, payload.ComponentName, 0)

listAPI := client.NewPublicClient(&facadeCaller{
FacadeCaller: caller,
Expand All @@ -84,8 +84,8 @@ func (workloads) newListAPIClient(cmd *status.ListCommand) (status.ListAPI, erro
return listAPI, nil
}

func (c workloads) registerPublicCommands() {
if !markRegistered(workload.ComponentName, "public-commands") {
func (c payloads) registerPublicCommands() {
if !markRegistered(payload.ComponentName, "public-commands") {
return
}

Expand All @@ -94,12 +94,12 @@ func (c workloads) registerPublicCommands() {
})
}

func (c workloads) registerHookContext() {
if !markRegistered(workload.ComponentName, "hook-context") {
func (c payloads) registerHookContext() {
if !markRegistered(payload.ComponentName, "hook-context") {
return
}

unitercontext.RegisterComponentFunc(workload.ComponentName,
unitercontext.RegisterComponentFunc(payload.ComponentName,
func(config unitercontext.ComponentConfig) (jujuc.ContextComponent, error) {
hctxClient := c.newUnitFacadeClient(config.APICaller)
// TODO(ericsnow) Pass the unit's tag through to the component?
Expand All @@ -115,34 +115,34 @@ func (c workloads) registerHookContext() {
c.registerHookContextFacade()
}

func (workloads) newUnitFacadeClient(caller base.APICaller) context.APIClient {
facadeCaller := base.NewFacadeCallerForVersion(caller, workloadsHookContextFacade, 0)
func (payloads) newUnitFacadeClient(caller base.APICaller) context.APIClient {
facadeCaller := base.NewFacadeCallerForVersion(caller, payloadsHookContextFacade, 0)
return internalclient.NewUnitFacadeClient(facadeCaller)
}

func (workloads) newHookContextFacade(st *state.State, unit *state.Unit) (interface{}, error) {
func (payloads) newHookContextFacade(st *state.State, unit *state.Unit) (interface{}, error) {
up, err := st.UnitPayloads(unit)
if err != nil {
return nil, errors.Trace(err)
}
return internalserver.NewUnitFacade(up), nil
}

func (c workloads) registerHookContextFacade() {
func (c payloads) registerHookContextFacade() {
common.RegisterHookContextFacade(
workloadsHookContextFacade,
payloadsHookContextFacade,
0,
c.newHookContextFacade,
reflect.TypeOf(&internalserver.UnitFacade{}),
)
}

type workloadsHookContext struct {
type payloadsHookContext struct {
jujuc.Context
}

// Component implements context.HookContext.
func (c workloadsHookContext) Component(name string) (context.Component, error) {
func (c payloadsHookContext) Component(name string) (context.Component, error) {
found, err := c.Context.Component(name)
if err != nil {
return nil, errors.Trace(err)
Expand All @@ -154,13 +154,13 @@ func (c workloadsHookContext) Component(name string) (context.Component, error)
return compCtx, nil
}

func (workloads) registerHookContextCommands() {
if !markRegistered(workload.ComponentName, "hook-context-commands") {
func (payloads) registerHookContextCommands() {
if !markRegistered(payload.ComponentName, "hook-context-commands") {
return
}

jujuc.RegisterCommand(context.RegisterCmdName, func(ctx jujuc.Context) (cmd.Command, error) {
compCtx := workloadsHookContext{ctx}
compCtx := payloadsHookContext{ctx}
cmd, err := context.NewRegisterCmd(compCtx)
if err != nil {
return nil, errors.Trace(err)
Expand All @@ -169,7 +169,7 @@ func (workloads) registerHookContextCommands() {
})

jujuc.RegisterCommand(context.StatusSetCmdName, func(ctx jujuc.Context) (cmd.Command, error) {
compCtx := workloadsHookContext{ctx}
compCtx := payloadsHookContext{ctx}
cmd, err := context.NewStatusSetCmd(compCtx)
if err != nil {
return nil, errors.Trace(err)
Expand All @@ -178,7 +178,7 @@ func (workloads) registerHookContextCommands() {
})

jujuc.RegisterCommand(context.UnregisterCmdName, func(ctx jujuc.Context) (cmd.Command, error) {
compCtx := workloadsHookContext{ctx}
compCtx := payloadsHookContext{ctx}
cmd, err := context.NewUnregisterCmd(compCtx)
if err != nil {
return nil, errors.Trace(err)
Expand All @@ -187,21 +187,21 @@ func (workloads) registerHookContextCommands() {
})
}

func (workloads) registerState() {
func (payloads) registerState() {
// TODO(ericsnow) Use a more general registration mechanism.
//state.RegisterMultiEnvCollections(persistence.Collections...)

newUnitPayloads := func(persist state.Persistence, unit string) (state.UnitPayloads, error) {
return workloadstate.NewUnitPayloads(persist, unit), nil
newUnitPayloads := func(persist state.Persistence, unit, machine string) (state.UnitPayloads, error) {
return payloadstate.NewUnitPayloads(persist, unit, machine), nil
}
state.SetWorkloadsComponent(newUnitPayloads)

newEnvPayloads := func(persist state.PayloadsEnvPersistence) (state.EnvPayloads, error) {
envPersist := persistence.NewEnvPersistence(persist)
envPayloads := workloadstate.EnvPayloads{
envPayloads := payloadstate.EnvPayloads{
Persist: envPersist,
}
return envPayloads, nil
}
state.SetPayloadsComponent(newEnvPayloads)

state.SetPayloadsComponent(newEnvPayloads, newUnitPayloads)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ import (
"github.com/juju/loggo"
)

var logger = loggo.GetLogger("juju.workload.api.client")
var logger = loggo.GetLogger("juju.payload.api.client")
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

"github.com/juju/errors"

"github.com/juju/juju/workload"
"github.com/juju/juju/workload/api"
"github.com/juju/juju/payload"
"github.com/juju/juju/payload/api"
)

type facadeCaller interface {
Expand All @@ -35,7 +35,7 @@ func NewPublicClient(raw rawAPI) PublicClient {
}

// ListFull calls the List API server method.
func (c PublicClient) ListFull(patterns ...string) ([]workload.FullPayloadInfo, error) {
func (c PublicClient) ListFull(patterns ...string) ([]payload.FullPayloadInfo, error) {
var result api.EnvListResults

args := api.EnvListArgs{
Expand All @@ -45,7 +45,7 @@ func (c PublicClient) ListFull(patterns ...string) ([]workload.FullPayloadInfo,
return nil, errors.Trace(err)
}

payloads := make([]workload.FullPayloadInfo, len(result.Results))
payloads := make([]payload.FullPayloadInfo, len(result.Results))
for i, apiInfo := range result.Results {
payload, err := api.API2Payload(apiInfo)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"

"github.com/juju/juju/workload"
"github.com/juju/juju/workload/api"
"github.com/juju/juju/workload/api/client"
"github.com/juju/juju/payload"
"github.com/juju/juju/payload/api"
"github.com/juju/juju/payload/api/client"
)

type publicSuite struct {
Expand All @@ -31,7 +31,7 @@ func (s *publicSuite) SetUpTest(c *gc.C) {
Class: "spam",
Type: "docker",
ID: "idspam",
Status: workload.StateRunning,
Status: payload.StateRunning,
Labels: nil,
Unit: names.NewUnitTag("a-service/0").String(),
Machine: names.NewMachineTag("1").String(),
Expand All @@ -52,7 +52,7 @@ func (s *publicSuite) TestListOkay(c *gc.C) {
c.Assert(err, jc.ErrorIsNil)

expected, _ := api.API2Payload(s.payload)
c.Check(payloads, jc.DeepEquals, []workload.FullPayloadInfo{
c.Check(payloads, jc.DeepEquals, []payload.FullPayloadInfo{
expected,
})
}
Expand Down
File renamed without changes.
16 changes: 8 additions & 8 deletions workload/api/helpers.go → payload/api/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (
"github.com/juju/names"
"gopkg.in/juju/charm.v5"

"github.com/juju/juju/workload"
"github.com/juju/juju/payload"
)

// Payload2api converts a workload.FullPayloadInfo struct into
// Payload2api converts a payload.FullPayloadInfo struct into
// a Payload struct.
func Payload2api(p workload.FullPayloadInfo) Payload {
func Payload2api(p payload.FullPayloadInfo) Payload {
labels := make([]string, len(p.Labels))
copy(labels, p.Labels)

Expand All @@ -38,13 +38,13 @@ func Payload2api(p workload.FullPayloadInfo) Payload {
}

// API2Payload converts an API Payload info struct into
// a workload.FullPayloadInfo struct.
func API2Payload(apiInfo Payload) (workload.FullPayloadInfo, error) {
// a payload.FullPayloadInfo struct.
func API2Payload(apiInfo Payload) (payload.FullPayloadInfo, error) {
labels := make([]string, len(apiInfo.Labels))
copy(labels, apiInfo.Labels)

var unit, machine string
var empty workload.FullPayloadInfo
var empty payload.FullPayloadInfo
if apiInfo.Unit != "" {
tag, err := names.ParseUnitTag(apiInfo.Unit)
if err != nil {
Expand All @@ -60,8 +60,8 @@ func API2Payload(apiInfo Payload) (workload.FullPayloadInfo, error) {
machine = tag.Id()
}

return workload.FullPayloadInfo{
Payload: workload.Payload{
return payload.FullPayloadInfo{
Payload: payload.Payload{
PayloadClass: charm.PayloadClass{
Name: apiInfo.Class,
Type: apiInfo.Type,
Expand Down
20 changes: 10 additions & 10 deletions workload/api/helpers_test.go → payload/api/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
gc "gopkg.in/check.v1"
"gopkg.in/juju/charm.v5"

"github.com/juju/juju/workload"
"github.com/juju/juju/payload"
)

type helpersSuite struct {
Expand All @@ -20,14 +20,14 @@ type helpersSuite struct {
var _ = gc.Suite(&helpersSuite{})

func (helpersSuite) TestPayload2api(c *gc.C) {
apiPayload := Payload2api(workload.FullPayloadInfo{
Payload: workload.Payload{
apiPayload := Payload2api(payload.FullPayloadInfo{
Payload: payload.Payload{
PayloadClass: charm.PayloadClass{
Name: "spam",
Type: "docker",
},
ID: "idspam",
Status: workload.StateRunning,
Status: payload.StateRunning,
Labels: []string{"a-tag"},
Unit: "a-service/0",
},
Expand All @@ -38,33 +38,33 @@ func (helpersSuite) TestPayload2api(c *gc.C) {
Class: "spam",
Type: "docker",
ID: "idspam",
Status: workload.StateRunning,
Status: payload.StateRunning,
Labels: []string{"a-tag"},
Unit: names.NewUnitTag("a-service/0").String(),
Machine: names.NewMachineTag("1").String(),
})
}

func (helpersSuite) TestAPI2Payload(c *gc.C) {
payload, err := API2Payload(Payload{
pl, err := API2Payload(Payload{
Class: "spam",
Type: "docker",
ID: "idspam",
Status: workload.StateRunning,
Status: payload.StateRunning,
Labels: []string{"a-tag"},
Unit: names.NewUnitTag("a-service/0").String(),
Machine: names.NewMachineTag("1").String(),
})
c.Assert(err, jc.ErrorIsNil)

c.Check(payload, jc.DeepEquals, workload.FullPayloadInfo{
Payload: workload.Payload{
c.Check(pl, jc.DeepEquals, payload.FullPayloadInfo{
Payload: payload.Payload{
PayloadClass: charm.PayloadClass{
Name: "spam",
Type: "docker",
},
ID: "idspam",
Status: workload.StateRunning,
Status: payload.StateRunning,
Labels: []string{"a-tag"},
Unit: "a-service/0",
},
Expand Down
Loading

0 comments on commit 3586c80

Please sign in to comment.