Skip to content

Commit ee0f6d7

Browse files
committed
feat: add ready indicator to cf app command
Signed-off-by: Christopher Banck <christopher.banck@broadcom.com>
1 parent c219e62 commit ee0f6d7

File tree

4 files changed

+44
-16
lines changed

4 files changed

+44
-16
lines changed

api/cloudcontroller/ccv3/process_instance.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ type ProcessInstance struct {
4040
LogRate uint64
4141
// State is the state of the instance.
4242
State constant.ProcessInstanceState
43+
// Routeable is the readiness state of the instance, can be true, false or null.
44+
Routable *bool
4345
// Type is the process type for the instance.
4446
Type string
4547
// Uptime is the duration that the instance has been running.
@@ -56,6 +58,7 @@ func (instance *ProcessInstance) UnmarshalJSON(data []byte) error {
5658
MemQuota uint64 `json:"mem_quota"`
5759
LogRateLimit int64 `json:"log_rate_limit"`
5860
State string `json:"state"`
61+
Routable *bool `json:"routable"`
5962
Type string `json:"type"`
6063
Uptime int64 `json:"uptime"`
6164
Usage struct {
@@ -84,6 +87,7 @@ func (instance *ProcessInstance) UnmarshalJSON(data []byte) error {
8487
instance.LogRateLimit = inputInstance.LogRateLimit
8588
instance.LogRate = inputInstance.Usage.LogRate
8689
instance.State = constant.ProcessInstanceState(inputInstance.State)
90+
instance.Routable = inputInstance.Routable
8791
instance.Type = inputInstance.Type
8892
instance.Uptime, err = time.ParseDuration(fmt.Sprintf("%ds", inputInstance.Uptime))
8993
if err != nil {

command/v7/shared/app_summary_displayer.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ func formatCPUEntitlement(cpuEntitlement types.NullFloat64) string {
8080
return fmt.Sprintf("%.1f%%", cpuEntitlement.Value*100)
8181
}
8282

83+
func formatRoutable(b *bool) string {
84+
if b == nil {
85+
return "-"
86+
}
87+
88+
return fmt.Sprintf("%t", *b)
89+
}
90+
8391
func (display AppSummaryDisplayer) displayAppInstancesTable(processSummary v7action.ProcessSummary) {
8492
table := [][]string{
8593
{
@@ -92,6 +100,7 @@ func (display AppSummaryDisplayer) displayAppInstancesTable(processSummary v7act
92100
display.UI.TranslateText("logging"),
93101
display.UI.TranslateText("cpu entitlement"),
94102
display.UI.TranslateText("details"),
103+
display.UI.TranslateText("ready"),
95104
},
96105
}
97106

@@ -115,6 +124,7 @@ func (display AppSummaryDisplayer) displayAppInstancesTable(processSummary v7act
115124
}),
116125
formatCPUEntitlement(instance.CPUEntitlement),
117126
instance.Details,
127+
formatRoutable(instance.Routable),
118128
})
119129
}
120130

command/v7/shared/app_summary_displayer_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717

1818
var _ = Describe("app summary displayer", func() {
1919

20-
const instanceStatsTitles = `state\s+since\s+cpu\s+memory\s+disk\s+logging\s+cpu entitlement\s+details`
20+
const instanceStatsTitles = `state\s+since\s+cpu\s+memory\s+disk\s+logging\s+cpu entitlement\s+details\s+ready`
2121

2222
var (
2323
appSummaryDisplayer *AppSummaryDisplayer
@@ -48,6 +48,10 @@ var _ = Describe("app summary displayer", func() {
4848

4949
BeforeEach(func() {
5050
uptime = time.Since(time.Unix(267321600, 0))
51+
var (
52+
bTrue = true
53+
bFalse = false
54+
)
5155
summary = v7action.DetailedApplicationSummary{
5256
ApplicationSummary: v7action.ApplicationSummary{
5357
Application: resources.Application{
@@ -76,6 +80,7 @@ var _ = Describe("app summary displayer", func() {
7680
LogRateLimit: 1024 * 5,
7781
Uptime: uptime,
7882
Details: "Some Details 1",
83+
Routable: &bTrue,
7984
},
8085
v7action.ProcessInstance{
8186
Index: 1,
@@ -89,6 +94,7 @@ var _ = Describe("app summary displayer", func() {
8994
LogRateLimit: 1024 * 5,
9095
Uptime: time.Since(time.Unix(330480000, 0)),
9196
Details: "Some Details 2",
97+
Routable: &bTrue,
9298
},
9399
v7action.ProcessInstance{
94100
Index: 2,
@@ -101,6 +107,7 @@ var _ = Describe("app summary displayer", func() {
101107
DiskQuota: 6000000,
102108
LogRateLimit: 1024 * 5,
103109
Uptime: time.Since(time.Unix(1277164800, 0)),
110+
Routable: &bFalse,
104111
},
105112
},
106113
},
@@ -123,6 +130,7 @@ var _ = Describe("app summary displayer", func() {
123130
DiskQuota: 8000000,
124131
LogRateLimit: 256,
125132
Uptime: time.Since(time.Unix(167572800, 0)),
133+
Routable: &bTrue,
126134
},
127135
},
128136
},
@@ -149,19 +157,22 @@ var _ = Describe("app summary displayer", func() {
149157
Expect(webProcessSummary.Instances[0].CPUEntitlement).To(Equal("0.0%"))
150158
Expect(webProcessSummary.Instances[0].LogRate).To(Equal("1K/s of 5K/s"))
151159
Expect(webProcessSummary.Instances[0].Details).To(Equal("Some Details 1"))
160+
Expect(webProcessSummary.Instances[0].Ready).To(Equal("true"))
152161

153162
Expect(webProcessSummary.Instances[1].Memory).To(Equal("1.9M of 32M"))
154163
Expect(webProcessSummary.Instances[1].Disk).To(Equal("1.9M of 3.8M"))
155164
Expect(webProcessSummary.Instances[1].CPU).To(Equal("0.0%"))
156165
Expect(webProcessSummary.Instances[1].CPUEntitlement).To(Equal(""))
157166
Expect(webProcessSummary.Instances[1].LogRate).To(Equal("2K/s of 5K/s"))
158167
Expect(webProcessSummary.Instances[1].Details).To(Equal("Some Details 2"))
168+
Expect(webProcessSummary.Instances[1].Ready).To(Equal("true"))
159169

160170
Expect(webProcessSummary.Instances[2].Memory).To(Equal("2.9M of 32M"))
161171
Expect(webProcessSummary.Instances[2].Disk).To(Equal("2.9M of 5.7M"))
162172
Expect(webProcessSummary.Instances[2].CPU).To(Equal("0.0%"))
163173
Expect(webProcessSummary.Instances[2].CPUEntitlement).To(Equal("3.0%"))
164174
Expect(webProcessSummary.Instances[2].LogRate).To(Equal("3K/s of 5K/s"))
175+
Expect(webProcessSummary.Instances[2].Ready).To(Equal("false"))
165176

166177
consoleProcessSummary := processTable.Processes[1]
167178
Expect(consoleProcessSummary.Type).To(Equal("console"))

integration/helpers/app_instance_table.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type AppInstanceRow struct {
1717
LogRate string
1818
CPUEntitlement string
1919
Details string
20+
Ready string
2021
}
2122

2223
// AppProcessTable represents a process of a V3 app, as displayed in the 'cf
@@ -57,18 +58,8 @@ func ParseV3AppProcessTable(input []byte) AppTable {
5758

5859
switch {
5960
case strings.HasPrefix(row, "#"):
60-
const columnCount = 9
61-
6261
// instance row
6362
columns := splitColumns(row)
64-
cpuEntitlement, details := "", ""
65-
if len(columns) >= columnCount-1 {
66-
cpuEntitlement = columns[columnCount-2]
67-
}
68-
if len(columns) >= columnCount {
69-
details = columns[columnCount-1]
70-
}
71-
7263
instanceRow := AppInstanceRow{
7364
Index: columns[0],
7465
State: columns[1],
@@ -77,8 +68,9 @@ func ParseV3AppProcessTable(input []byte) AppTable {
7768
Memory: columns[4],
7869
Disk: columns[5],
7970
LogRate: columns[6],
80-
CPUEntitlement: cpuEntitlement,
81-
Details: details,
71+
CPUEntitlement: columns[7],
72+
Details: columns[8],
73+
Ready: columns[9],
8274
}
8375
lastProcessIndex := len(appTable.Processes) - 1
8476
appTable.Processes[lastProcessIndex].Instances = append(
@@ -115,9 +107,20 @@ func splitColumns(row string) []string {
115107
s := strings.TrimSpace(row)
116108
// uses 3 spaces between columns
117109
result := regexp.MustCompile(`\s{3,}`).Split(s, -1)
118-
// 21 spaces should only occur if cpu entitlement is empty but details is filled in
119-
if regexp.MustCompile(`\s{21}`).MatchString(s) {
120-
result = append(result[:len(result)-1], "", result[len(result)-1])
110+
111+
if regexp.MustCompile(`\s{31}`).MatchString(s) {
112+
113+
if len(result) == 8 {
114+
// Both cpu entitlement and details are empty
115+
result = append(result[:len(result)-1], "", "", result[len(result)-1])
116+
} else {
117+
// Only details is empty
118+
result = append(result[:len(result)-2], result[len(result)-2], "", result[len(result)-1])
119+
}
120+
121+
} else if regexp.MustCompile(`\s{21}`).MatchString(s) {
122+
// cpu entitlement is empty, details is filled
123+
result = append(result[:len(result)-2], "", result[len(result)-2], result[len(result)-1])
121124
}
122125
return result
123126
}

0 commit comments

Comments
 (0)