Skip to content

Commit

Permalink
feat: show rollout history in wave info
Browse files Browse the repository at this point in the history
This is a part of info rather than a status.
We need this same information in the Web UI.
Also, a user might want to look at it without a full status breakdown.

Signed-off-by: Volodymyr Khoroz <[email protected]>
  • Loading branch information
vkhoroz committed Jun 9, 2023
1 parent 04d4cdc commit 637d774
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 30 deletions.
13 changes: 11 additions & 2 deletions client/foundries.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,15 +392,24 @@ type WaveRolloutGroupRef struct {
CreatedBy string `json:"created-by"`
}

type RolloutHistory struct {
GroupName string `json:"group-name"`
RolloutBy string `json:"rollout-by"`
RolloutAt string `json:"rollout-at"`
IsFullGroup bool `json:"is-full-group"`
IsFactoryWide bool `json:"is-factory-wide"`
DeviceNumber int `json:"num-devices"`
}

type Wave struct {
Name string `json:"name"`
Version string `json:"version"`
Tag string `json:"tag"`
Targets *json.RawMessage `json:"targets"`
Status string `json:"status"`
RolloutGroups map[string]WaveRolloutGroupRef `json:"rollout-groups"`

ChangeMeta ChangeMeta `json:"change-meta"`
History []RolloutHistory `json:"rollout-history"`
ChangeMeta ChangeMeta `json:"change-meta"`
}

type WaveCreate struct {
Expand Down
46 changes: 18 additions & 28 deletions subcommands/waves/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ package waves

import (
"fmt"
"sort"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/foundriesio/fioctl/client"
"github.com/foundriesio/fioctl/subcommands"
)

Expand Down Expand Up @@ -41,23 +39,27 @@ func doShowWave(cmd *cobra.Command, args []string) {
if len(wave.ChangeMeta.CreatedBy) > 0 {
fmt.Printf("Created By: \t%s\n", wave.ChangeMeta.CreatedBy)
}
if len(wave.RolloutGroups) > 0 {
groupRefs := sortRolloutGroups(wave.RolloutGroups)
firstLine := true
for _, ref := range groupRefs {
formatLine := "\t\t%s: rollout to device group %s"
if firstLine {
firstLine = false
formatLine = "Rollout At: \t%s: rollout to device group %s"
}
groupName := ref.GroupName
if groupName == "" {
if len(wave.History) > 0 {
fmt.Println("Rollout history:")
for _, rollout := range wave.History {
line := fmt.Sprintf("\t%s: rollout to ", rollout.RolloutAt)

groupName := rollout.GroupName
if !rollout.IsFactoryWide && groupName == "" {
// A group has been deleted, only a reference still exists - we cannot track down a name
groupName = "<deleted group>"
}
line := fmt.Sprintf(formatLine, ref.CreatedAt, groupName)
if len(ref.CreatedBy) > 0 {
line += " by " + ref.CreatedBy

if rollout.IsFactoryWide {
line += fmt.Sprintf("%d devices in factory", rollout.DeviceNumber)
} else if rollout.IsFullGroup {
line += fmt.Sprintf("all devices in group %s", groupName)
} else {
line += fmt.Sprintf("%d devices in group %s", rollout.DeviceNumber, groupName)
}

if len(rollout.RolloutBy) > 0 {
line += " by " + rollout.RolloutBy
}
fmt.Println(line)
}
Expand All @@ -75,15 +77,3 @@ func doShowWave(cmd *cobra.Command, args []string) {
fmt.Println(" " + string(data))
}
}

func sortRolloutGroups(groupMap map[string]client.WaveRolloutGroupRef) []client.WaveRolloutGroupRef {
groupRefs := make([]client.WaveRolloutGroupRef, 0, len(groupMap))
for _, ref := range groupMap {
groupRefs = append(groupRefs, ref)
}
sort.Slice(groupRefs, func(i, j int) bool {
// Time is in RFC3339 format i.e. with zero padding, so it compares properly
return groupRefs[i].CreatedAt < groupRefs[j].CreatedAt
})
return groupRefs
}

0 comments on commit 637d774

Please sign in to comment.