Skip to content

Commit

Permalink
Merge pull request #10867 from nammn/list-commit
Browse files Browse the repository at this point in the history
#10867

## To change/add
- [x] sort list-commits desc
- [x] time format in human readable format (4h ago...)
- [x] no commits feedback

## Description of change
#### adds:
- `commits`
- `show-commit <number>`
commands

#### changes:
- renames feature flag from generations to branches

## QA steps
#### preparation
- bootstrapped controller
```
export JUJU_DEV_FEATURE_FLAGS=generations
juju deploy ubuntu
juju add-branch bla
juju add-branch blub
juju track bla ubuntu
juju config ubuntu hostname=random
juju commit bla
```

#### list-commits test
```
❯ juju commits
Commit Committed at Committed by Branch name
3 07 Nov 2019 14:41:41+01:00 admin bla 
```
should not show anything other than bla, because blub did not get committed

It should not show aborted branches as well!

no branches committed yet
```
~/golang/src/github.com/juju/juju list-commit
❯ juju commits 
Commit Committed at Committed by Branch name
```
--> might want to change that to a proper message

#### show-commits test
```
> juju show-commit 3

branch:
 bla:
 applications:
 - application: ubuntu
 units:
 tracking:
 - redis/0
 config:
 hostname: bla
committed-at: 08 Nov 2019 10:14:10+01:00
committed-by: admin
created: 08 Nov 2019 10:13:04+01:00
created-by: admin
```

err case:

```
## Documentation change
- rename feature flag from generations to branches

❯ juju show-commit 10 
ERROR generation_id 10 in model "default" not found
```
## Bug reference
  • Loading branch information
jujubot committed Nov 12, 2019
2 parents ad963f0 + b62da3d commit ee8ec9c
Show file tree
Hide file tree
Showing 33 changed files with 1,269 additions and 46 deletions.
2 changes: 1 addition & 1 deletion api/facadeversions.go
Expand Up @@ -75,7 +75,7 @@ var facadeVersions = map[string]int{
"MigrationStatusWatcher": 1,
"MigrationTarget": 1,
"ModelConfig": 2,
"ModelGeneration": 3,
"ModelGeneration": 4,
"ModelManager": 8,
"ModelUpgrader": 1,
"NotifyWatcher": 1,
Expand Down
67 changes: 65 additions & 2 deletions api/modelgeneration/modelgeneration.go
Expand Up @@ -69,6 +69,33 @@ func (c *Client) CommitBranch(branchName string) (int, error) {
return result.Result, nil
}

// ListCommits returns the details of all committed model branches.
func (c *Client) ListCommits() (model.GenerationCommits, error) {
var result params.BranchResults
err := c.facade.FacadeCall("ListCommits", nil, &result)
if err != nil {
return nil, errors.Trace(err)
}
if result.Error != nil {
return nil, errors.Trace(result.Error)
}
return generationCommitsFromResults(result), nil
}

// ShowCommit details of the branch with the input generation ID.
func (c *Client) ShowCommit(generationId int) (model.GenerationCommit, error) {
var result params.GenerationResult
arg := params.GenerationId{GenerationId: generationId}
err := c.facade.FacadeCall("ShowCommit", arg, &result)
if err != nil {
return model.GenerationCommit{}, errors.Trace(err)
}
if result.Error != nil {
return model.GenerationCommit{}, errors.Trace(result.Error)
}
return generationCommitFromResult(result), nil
}

// TrackBranch sets the input units and/or applications
// to track changes made under the input branch name.
func (c *Client) TrackBranch(branchName string, entities []string, numUnits int) error {
Expand Down Expand Up @@ -129,7 +156,7 @@ func (c *Client) BranchInfo(
arg.BranchNames = []string{branchName}
}

var result params.GenerationResults
var result params.BranchResults
err := c.facade.FacadeCall("BranchInfo", arg, &result)
if err != nil {
return nil, errors.Trace(err)
Expand All @@ -147,7 +174,7 @@ func argForBranch(branchName string) params.BranchArg {
}

func generationInfoFromResult(
results params.GenerationResults, detailed bool, formatTime func(time.Time) string,
results params.BranchResults, detailed bool, formatTime func(time.Time) string,
) model.GenerationSummaries {
summaries := make(model.GenerationSummaries)
for _, res := range results.Generations {
Expand All @@ -174,3 +201,39 @@ func generationInfoFromResult(
}
return summaries
}

func generationCommitsFromResults(results params.BranchResults) model.GenerationCommits {
commits := make(model.GenerationCommits, len(results.Generations))
for i, gen := range results.Generations {
commits[i] = model.GenerationCommit{
GenerationId: gen.GenerationId,
Completed: time.Unix(gen.Completed, 0),
CompletedBy: gen.CompletedBy,
BranchName: gen.BranchName,
}
}
return commits
}

func generationCommitFromResult(result params.GenerationResult) model.GenerationCommit {
genCommit := result.Generation
appChanges := make([]model.GenerationApplication, len(genCommit.Applications))
for i, a := range genCommit.Applications {
app := model.GenerationApplication{
ApplicationName: a.ApplicationName,
ConfigChanges: a.ConfigChanges,
UnitDetail: &model.GenerationUnits{UnitsTracking: a.UnitsTracking},
}
appChanges[i] = app
}
modelCommit := model.GenerationCommit{
BranchName: genCommit.BranchName,
Completed: time.Unix(genCommit.Completed, 0),
CompletedBy: genCommit.CompletedBy,
Created: time.Unix(genCommit.Created, 0),
CreatedBy: genCommit.CreatedBy,
GenerationId: genCommit.GenerationId,
Applications: appChanges,
}
return modelCommit
}
2 changes: 1 addition & 1 deletion api/modelgeneration/modelgeneration_test.go
Expand Up @@ -127,7 +127,7 @@ func (s *modelGenerationSuite) TestHasActiveBranch(c *gc.C) {
func (s *modelGenerationSuite) TestBranchInfo(c *gc.C) {
defer s.setUpMocks(c).Finish()

resultSource := params.GenerationResults{Generations: []params.Generation{{
resultSource := params.BranchResults{Generations: []params.Generation{{
BranchName: "new-branch",
Created: time.Time{}.Unix(),
CreatedBy: "test-user",
Expand Down
1 change: 1 addition & 0 deletions apiserver/allfacades.go
Expand Up @@ -252,6 +252,7 @@ func AllFacades() *facade.Registry {
reg("ModelGeneration", 1, modelgeneration.NewModelGenerationFacade)
reg("ModelGeneration", 2, modelgeneration.NewModelGenerationFacadeV2)
reg("ModelGeneration", 3, modelgeneration.NewModelGenerationFacadeV3)
reg("ModelGeneration", 4, modelgeneration.NewModelGenerationFacadeV4)
reg("ModelManager", 2, modelmanager.NewFacadeV2)
reg("ModelManager", 3, modelmanager.NewFacadeV3)
reg("ModelManager", 4, modelmanager.NewFacadeV4)
Expand Down
2 changes: 1 addition & 1 deletion apiserver/facades/client/client/status_test.go
Expand Up @@ -1032,7 +1032,7 @@ func (m mockLeadershipReader) Leaders() (map[string]string, error) {

func setGenerationsControllerConfig(c *gc.C, st *state.State) {
err := st.UpdateControllerConfig(map[string]interface{}{
"features": []interface{}{feature.Generations},
"features": []interface{}{feature.Branches},
}, nil)
c.Assert(err, jc.ErrorIsNil)
}
5 changes: 5 additions & 0 deletions apiserver/facades/client/modelgeneration/interface.go
Expand Up @@ -26,6 +26,8 @@ type Model interface {
AddBranch(string, string) error
Branch(string) (Generation, error)
Branches() ([]Generation, error)
Generation(int) (Generation, error)
Generations() ([]Generation, error)
}

// ModelCache describes a cached model used by the model generation API.
Expand All @@ -38,13 +40,16 @@ type Generation interface {
BranchName() string
Created() int64
CreatedBy() string
Completed() int64
CompletedBy() string
AssignAllUnits(string) error
AssignUnits(string, int) error
AssignUnit(string) error
AssignedUnits() map[string][]string
Commit(string) (int, error)
Abort(string) error
Config() map[string]settings.ItemChanges
GenerationId() int
}

// Application describes application state used by the model generation API.
Expand Down

0 comments on commit ee8ec9c

Please sign in to comment.