Skip to content

Commit bb3fd25

Browse files
committed
[coconut] Add support for run numbers and correct version information
1 parent d9cc286 commit bb3fd25

File tree

2 files changed

+53
-12
lines changed

2 files changed

+53
-12
lines changed

coconut/control/control.go

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,26 @@ func GetInfo(cxt context.Context, rpc *coconut.RpcClient, cmd *cobra.Command, ar
105105
return
106106
}
107107

108+
versionStr := response.GetVersion().GetVersionStr()
109+
// VersionStr will be empty if the core was built with go build directly instead of make.
110+
// This happens because the Makefile takes care of pushing the version number.
111+
if len(versionStr) == 0 || versionStr == "0.0.0" {
112+
versionStr = "dev"
113+
}
114+
versionStr = green(versionStr)
115+
116+
revisionStr := response.GetVersion().GetBuild()
117+
if len(revisionStr) > 0 {
118+
revisionStr = fmt.Sprintf("revision %s", green(revisionStr))
119+
}
120+
108121
_, _ = fmt.Fprintf(o, "instance name: %s\n", response.GetInstanceName())
109-
_, _ = fmt.Fprintf(o, "endpoint: %s\n", viper.GetString("endpoint"))
110-
_, _ = fmt.Fprintf(o, "core version: %s %s build %s\n", response.GetVersion().GetProductName(), response.GetVersion().GetVersionStr(), response.GetVersion().GetBuild())
122+
_, _ = fmt.Fprintf(o, "endpoint: %s\n", green(viper.GetString("endpoint")))
123+
_, _ = fmt.Fprintf(o, "core version: %s %s %s\n", response.GetVersion().GetProductName(), versionStr, revisionStr)
111124
_, _ = fmt.Fprintf(o, "framework id: %s\n", response.GetFrameworkId())
112-
_, _ = fmt.Fprintf(o, "environments count: %d\n", response.GetEnvironmentsCount())
113-
_, _ = fmt.Fprintf(o, "active tasks count: %d\n", response.GetTasksCount())
114-
_, _ = fmt.Fprintf(o, "global state: %s\n", response.GetState())
125+
_, _ = fmt.Fprintf(o, "environments count: %s\n", green(response.GetEnvironmentsCount()))
126+
_, _ = fmt.Fprintf(o, "active tasks count: %s\n", green(response.GetTasksCount()))
127+
_, _ = fmt.Fprintf(o, "global state: %s\n", colorGlobalState(response.GetState()))
115128

116129
return nil
117130
}
@@ -204,9 +217,12 @@ func ShowEnvironment(cxt context.Context, rpc *coconut.RpcClient, cmd *cobra.Com
204217

205218
env := response.GetEnvironment()
206219
tasks := env.GetTasks()
207-
fmt.Fprintf(o, "environment id: %s\n", env.GetId())
208-
fmt.Fprintf(o, "created: %s\n", formatTimestamp(env.GetCreatedWhen()))
209-
fmt.Fprintf(o, "state: %s\n", colorState(env.GetState()))
220+
rnString := formatRunNumber(env.GetCurrentRunNumber())
221+
222+
_, _ = fmt.Fprintf(o, "environment id: %s\n", env.GetId())
223+
_, _ = fmt.Fprintf(o, "created: %s\n", formatTimestamp(env.GetCreatedWhen()))
224+
_, _ = fmt.Fprintf(o, "state: %s\n", colorState(env.GetState()))
225+
_, _ = fmt.Fprintf(o, "run number: %s\n", rnString)
210226

211227
if printTasks {
212228
fmt.Fprintln(o, "")
@@ -247,9 +263,12 @@ func ControlEnvironment(cxt context.Context, rpc *coconut.RpcClient, cmd *cobra.
247263
return
248264
}
249265

250-
fmt.Fprintln(o, "transition complete")
251-
fmt.Fprintf(o, "environment id: %s\n", response.GetId())
252-
fmt.Fprintf(o, "state: %s\n", colorState(response.GetState()))
266+
rnString := formatRunNumber(response.GetCurrentRunNumber())
267+
268+
_, _ = fmt.Fprintln(o, "transition complete")
269+
_, _ = fmt.Fprintf(o, "environment id: %s\n", response.GetId())
270+
_, _ = fmt.Fprintf(o, "state: %s\n", colorState(response.GetState()))
271+
_, _ = fmt.Fprintf(o, "run number: %s\n", rnString)
253272
return
254273
}
255274

coconut/control/controlutil.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,41 @@ var(
4444
grey = color.New(color.FgWhite).SprintFunc()
4545
)
4646

47+
func formatRunNumber(rn uint64) string {
48+
rnString := strconv.FormatUint(rn, 10)
49+
if rn == 0 {
50+
rnString = grey("none")
51+
} else {
52+
rnString = red(rnString)
53+
}
54+
return rnString
55+
}
56+
4757
func colorState(st string) string {
4858
switch st {
4959
case "STANDBY", "DONE":
5060
return blue(st)
5161
case "RUNNING":
52-
return yellow(st)
62+
return green(st)
5363
case "CONFIGURED":
64+
return yellow(st)
65+
default:
66+
return red(st)
67+
}
68+
}
69+
70+
func colorGlobalState(st string) string {
71+
switch st {
72+
case "INITIAL", "FINAL":
73+
return yellow(st)
74+
case "CONNECTED":
5475
return green(st)
5576
default:
5677
return red(st)
5778
}
5879
}
5980

81+
6082
func colorStateFromNode(node *pb.RoleInfo) string {
6183
return colorState(node.GetState())
6284
}

0 commit comments

Comments
 (0)