Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add back the state of each unit in a relation to goal state #9263

Merged
merged 1 commit into from
Sep 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
65 changes: 25 additions & 40 deletions apiserver/facades/agent/uniter/goal-state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,9 @@ func (s *uniterGoalStateSuite) TestGoalStatesSingleRelation(c *gc.C) {
Result: &params.GoalState{
Units: expectedUnitWordpress,
Relations: map[string]params.UnitsGoalState{
"db": params.UnitsGoalState{
"wordpress": expectedRelationStatus,
},
"server": params.UnitsGoalState{
"mysql": expectedRelationStatus,
"server": {
"mysql": expectedRelationStatus,
"mysql/0": expectedUnitStatus,
},
},
},
Expand Down Expand Up @@ -224,11 +222,9 @@ func (s *uniterGoalStateSuite) TestGoalStatesDeadUnitsExcluded(c *gc.C) {
Result: &params.GoalState{
Units: expected2UnitsWordPress,
Relations: map[string]params.UnitsGoalState{
"db": params.UnitsGoalState{
"wordpress": expectedRelationStatus,
},
"server": params.UnitsGoalState{
"mysql": expectedRelationStatus,
"server": {
"mysql": expectedRelationStatus,
"mysql/0": expectedUnitStatus,
},
},
},
Expand All @@ -246,11 +242,9 @@ func (s *uniterGoalStateSuite) TestGoalStatesDeadUnitsExcluded(c *gc.C) {
"wordpress/0": expectedUnitStatus,
},
Relations: map[string]params.UnitsGoalState{
"db": params.UnitsGoalState{
"wordpress": expectedRelationStatus,
},
"server": params.UnitsGoalState{
"mysql": expectedRelationStatus,
"server": {
"mysql": expectedRelationStatus,
"mysql/0": expectedUnitStatus,
},
},
},
Expand Down Expand Up @@ -301,11 +295,9 @@ func (s *uniterGoalStateSuite) TestGoalStatesSingleRelationDyingUnits(c *gc.C) {
Result: &params.GoalState{
Units: expected2UnitsWordPress,
Relations: map[string]params.UnitsGoalState{
"db": params.UnitsGoalState{
"wordpress": expectedRelationStatus,
},
"server": params.UnitsGoalState{
"mysql": expectedRelationStatus,
"server": {
"mysql": expectedRelationStatus,
"mysql/0": expectedUnitStatus,
},
},
},
Expand All @@ -328,11 +320,9 @@ func (s *uniterGoalStateSuite) TestGoalStatesSingleRelationDyingUnits(c *gc.C) {
},
},
Relations: map[string]params.UnitsGoalState{
"db": params.UnitsGoalState{
"wordpress": expectedRelationStatus,
},
"server": params.UnitsGoalState{
"mysql": expectedRelationStatus,
"server": {
"mysql": expectedRelationStatus,
"mysql/0": expectedUnitStatus,
},
},
},
Expand All @@ -356,11 +346,9 @@ func (s *uniterGoalStateSuite) TestGoalStatesCrossModelRelation(c *gc.C) {
"wordpress/0": expectedUnitStatus,
},
Relations: map[string]params.UnitsGoalState{
"db": params.UnitsGoalState{
"wordpress": expectedRelationStatus,
},
"server": params.UnitsGoalState{
"mysql": expectedRelationStatus,
"server": {
"mysql": expectedRelationStatus,
"mysql/0": expectedUnitStatus,
},
},
},
Expand Down Expand Up @@ -389,11 +377,9 @@ func (s *uniterGoalStateSuite) TestGoalStatesCrossModelRelation(c *gc.C) {
"wordpress/0": expectedUnitStatus,
},
Relations: map[string]params.UnitsGoalState{
"db": params.UnitsGoalState{
"wordpress": expectedRelationStatus,
},
"server": params.UnitsGoalState{
"server": {
"mysql": expectedRelationStatus,
"mysql/0": expectedUnitStatus,
"ctrl1:admin/default.mysql": expectedRelationStatus,
},
},
Expand Down Expand Up @@ -440,12 +426,11 @@ func (s *uniterGoalStateSuite) TestGoalStatesMultipleRelations(c *gc.C) {
Result: &params.GoalState{
Units: expected2UnitsWordPress,
Relations: map[string]params.UnitsGoalState{
"db": params.UnitsGoalState{
"wordpress": expectedRelationStatus,
},
"server": params.UnitsGoalState{
"mysql": expectedRelationStatus,
"mysql1": expectedRelationStatus,
"server": {
"mysql": expectedRelationStatus,
"mysql/0": expectedUnitStatus,
"mysql1": expectedRelationStatus,
"mysql1/0": expectedUnitStatus,
},
},
},
Expand Down
30 changes: 24 additions & 6 deletions apiserver/facades/agent/uniter/uniter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2559,7 +2559,7 @@ func (u *UniterAPI) goalStateResult(application *state.Application) (*params.Goa
return nil, err
}
if allRelations != nil {
gs.Relations, err = u.goalStateRelations(allRelations)
gs.Relations, err = u.goalStateRelations(application.Name(), allRelations)
if err != nil {
return nil, err
}
Expand All @@ -2568,11 +2568,15 @@ func (u *UniterAPI) goalStateResult(application *state.Application) (*params.Goa
}

// goalStateRelations creates the structure with all the relations between endpoints in an application.
func (u *UniterAPI) goalStateRelations(allRelations []*state.Relation) (map[string]params.UnitsGoalState, error) {
func (u *UniterAPI) goalStateRelations(appName string, allRelations []*state.Relation) (map[string]params.UnitsGoalState, error) {

result := map[string]params.UnitsGoalState{}

for _, r := range allRelations {
statusInfo, err := r.Status()
if err != nil {
return nil, errors.Annotate(err, "getting relation status")
}
endPoints := r.Endpoints()
for _, e := range endPoints {
if e.Relation.Role == "peer" {
Expand All @@ -2598,18 +2602,32 @@ func (u *UniterAPI) goalStateRelations(allRelations []*state.Relation) (map[stri
} else {
return nil, err
}
goalState := params.GoalStateStatus{}
statusInfo, err := r.Status()
if err != nil {
return nil, errors.Annotate(err, "getting relation status")

// We don't show units for the same application as we are currently processing.
if key == appName {
continue
}

goalState := params.GoalStateStatus{}
goalState.Status = statusInfo.Status.String()
goalState.Since = statusInfo.Since
relationGoalState := result[e.Name]
if relationGoalState == nil {
relationGoalState = params.UnitsGoalState{}
}
relationGoalState[key] = goalState

// For local applications, add in the status of units as well.
if application != nil {
units, err := u.goalStateUnits(application)
if err != nil {
return nil, err
}
for unitName, unitGS := range units {
relationGoalState[unitName] = unitGS
}
}

result[e.Name] = relationGoalState
}
}
Expand Down
10 changes: 2 additions & 8 deletions worker/uniter/runner/context/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,7 @@ func (s *InterfaceSuite) TestGoalState(c *gc.C) {
},
},
Relations: map[string]application.UnitsGoalState{
"db": application.UnitsGoalState{
"u": application.GoalStateStatus{
Status: "joining",
Since: &timestamp,
},
},
"server": application.UnitsGoalState{
"server": {
"db0": application.GoalStateStatus{
Status: "joining",
Since: &timestamp,
Expand All @@ -281,7 +275,7 @@ func (s *InterfaceSuite) TestGoalState(c *gc.C) {
}

c.Assert(err, jc.ErrorIsNil)
c.Assert(goalState, gc.DeepEquals, &goalStateCheck)
c.Assert(goalState, jc.DeepEquals, &goalStateCheck)
}

// TestNonActionCallsToActionMethodsFail does exactly what its name says:
Expand Down
4 changes: 2 additions & 2 deletions worker/uniter/runner/jujuc/jujuctesting/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ func (s *ContextSuite) NewInfo() *ContextInfo {
"mysql/0": gsStatus,
},
Relations: map[string]application.UnitsGoalState{
"db": application.UnitsGoalState{
"db": {
"mysql/0": gsStatus,
},
"server": application.UnitsGoalState{
"server": {
"wordpress/0": gsStatus,
},
},
Expand Down