From 637d77444e0d1ac219b6d48861b7c500cae71551 Mon Sep 17 00:00:00 2001 From: Volodymyr Khoroz Date: Wed, 7 Jun 2023 21:27:33 +0300 Subject: [PATCH] feat: show rollout history in wave info 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 --- client/foundries.go | 13 +++++++++-- subcommands/waves/show.go | 46 +++++++++++++++------------------------ 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/client/foundries.go b/client/foundries.go index f346e48d..31fe3867 100644 --- a/client/foundries.go +++ b/client/foundries.go @@ -392,6 +392,15 @@ 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"` @@ -399,8 +408,8 @@ type Wave struct { 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 { diff --git a/subcommands/waves/show.go b/subcommands/waves/show.go index a6b9ddc7..59e06131 100644 --- a/subcommands/waves/show.go +++ b/subcommands/waves/show.go @@ -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" ) @@ -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 = "" } - 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) } @@ -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 -}