Skip to content

Commit e8b9ed8

Browse files
authored
Merge branch 'main' into appsCommandOutput
2 parents 0e4d2bf + 4c5ee0e commit e8b9ed8

16 files changed

+1089
-79
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package v7action
2+
3+
import (
4+
"sort"
5+
6+
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
7+
)
8+
9+
type ProcessReadinessHealthCheck struct {
10+
ProcessType string
11+
HealthCheckType constant.HealthCheckType
12+
Endpoint string
13+
InvocationTimeout int64
14+
Interval int64
15+
}
16+
17+
type ProcessReadinessHealthChecks []ProcessReadinessHealthCheck
18+
19+
func (phs ProcessReadinessHealthChecks) Sort() {
20+
sort.Slice(phs, func(i int, j int) bool {
21+
var iScore int
22+
var jScore int
23+
24+
switch phs[i].ProcessType {
25+
case constant.ProcessTypeWeb:
26+
iScore = 0
27+
default:
28+
iScore = 1
29+
}
30+
31+
switch phs[j].ProcessType {
32+
case constant.ProcessTypeWeb:
33+
jScore = 0
34+
default:
35+
jScore = 1
36+
}
37+
38+
if iScore == 1 && jScore == 1 {
39+
return phs[i].ProcessType < phs[j].ProcessType
40+
}
41+
return iScore < jScore
42+
})
43+
}
44+
45+
func (actor Actor) GetApplicationProcessReadinessHealthChecksByNameAndSpace(appName string, spaceGUID string) ([]ProcessReadinessHealthCheck, Warnings, error) {
46+
app, allWarnings, err := actor.GetApplicationByNameAndSpace(appName, spaceGUID)
47+
if err != nil {
48+
return nil, allWarnings, err
49+
}
50+
51+
ccv3Processes, warnings, err := actor.CloudControllerClient.GetApplicationProcesses(app.GUID)
52+
allWarnings = append(allWarnings, Warnings(warnings)...)
53+
if err != nil {
54+
return nil, allWarnings, err
55+
}
56+
57+
var processReadinessHealthChecks ProcessReadinessHealthChecks
58+
for _, ccv3Process := range ccv3Processes {
59+
processReadinessHealthCheck := ProcessReadinessHealthCheck{
60+
ProcessType: ccv3Process.Type,
61+
HealthCheckType: ccv3Process.ReadinessHealthCheckType,
62+
Endpoint: ccv3Process.ReadinessHealthCheckEndpoint,
63+
InvocationTimeout: ccv3Process.ReadinessHealthCheckInvocationTimeout,
64+
Interval: ccv3Process.ReadinessHealthCheckInterval,
65+
}
66+
processReadinessHealthChecks = append(processReadinessHealthChecks, processReadinessHealthCheck)
67+
}
68+
69+
processReadinessHealthChecks.Sort()
70+
71+
return processReadinessHealthChecks, allWarnings, nil
72+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
package v7action_test
2+
3+
import (
4+
"errors"
5+
6+
"code.cloudfoundry.org/cli/actor/actionerror"
7+
. "code.cloudfoundry.org/cli/actor/v7action"
8+
"code.cloudfoundry.org/cli/actor/v7action/v7actionfakes"
9+
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
10+
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
11+
"code.cloudfoundry.org/cli/resources"
12+
. "github.com/onsi/ginkgo/v2"
13+
. "github.com/onsi/gomega"
14+
)
15+
16+
var _ = Describe("Process Readiness Health Check Actions", func() {
17+
var (
18+
actor *Actor
19+
fakeCloudControllerClient *v7actionfakes.FakeCloudControllerClient
20+
)
21+
22+
BeforeEach(func() {
23+
fakeCloudControllerClient = new(v7actionfakes.FakeCloudControllerClient)
24+
actor = NewActor(fakeCloudControllerClient, nil, nil, nil, nil, nil)
25+
})
26+
27+
Describe("ProcessReadinessHealthChecks", func() {
28+
var readinessHealthChecks ProcessReadinessHealthChecks
29+
30+
BeforeEach(func() {
31+
readinessHealthChecks = ProcessReadinessHealthChecks{
32+
{
33+
ProcessType: "worker",
34+
HealthCheckType: constant.Process,
35+
},
36+
{
37+
ProcessType: "console",
38+
HealthCheckType: constant.Process,
39+
},
40+
{
41+
ProcessType: constant.ProcessTypeWeb,
42+
HealthCheckType: constant.HTTP,
43+
Endpoint: constant.ProcessHealthCheckEndpointDefault,
44+
},
45+
}
46+
})
47+
48+
Describe("Sort", func() {
49+
It("sorts readiness health checks with web first and then alphabetically sorted", func() {
50+
readinessHealthChecks.Sort()
51+
Expect(readinessHealthChecks[0].ProcessType).To(Equal(constant.ProcessTypeWeb))
52+
Expect(readinessHealthChecks[1].ProcessType).To(Equal("console"))
53+
Expect(readinessHealthChecks[2].ProcessType).To(Equal("worker"))
54+
})
55+
})
56+
})
57+
58+
Describe("GetApplicationProcessReadinessHealthChecksByNameAndSpace", func() {
59+
var (
60+
warnings Warnings
61+
executeErr error
62+
processReadinessHealthChecks []ProcessReadinessHealthCheck
63+
)
64+
65+
JustBeforeEach(func() {
66+
processReadinessHealthChecks, warnings, executeErr = actor.GetApplicationProcessReadinessHealthChecksByNameAndSpace("some-app-name", "some-space-guid")
67+
})
68+
69+
When("application does not exist", func() {
70+
BeforeEach(func() {
71+
fakeCloudControllerClient.GetApplicationsReturns(
72+
[]resources.Application{},
73+
ccv3.Warnings{"some-warning"},
74+
nil,
75+
)
76+
})
77+
78+
It("returns the error and warnings", func() {
79+
Expect(executeErr).To(Equal(actionerror.ApplicationNotFoundError{Name: "some-app-name"}))
80+
Expect(warnings).To(ConsistOf("some-warning"))
81+
})
82+
})
83+
84+
When("getting application returns an error", func() {
85+
var expectedErr error
86+
87+
BeforeEach(func() {
88+
expectedErr = errors.New("some-error")
89+
fakeCloudControllerClient.GetApplicationsReturns(
90+
[]resources.Application{},
91+
ccv3.Warnings{"some-warning"},
92+
expectedErr,
93+
)
94+
})
95+
96+
It("returns the error and warnings", func() {
97+
Expect(executeErr).To(Equal(expectedErr))
98+
Expect(warnings).To(ConsistOf("some-warning"))
99+
})
100+
})
101+
102+
When("application exists", func() {
103+
BeforeEach(func() {
104+
fakeCloudControllerClient.GetApplicationsReturns(
105+
[]resources.Application{
106+
{
107+
GUID: "some-app-guid",
108+
},
109+
},
110+
ccv3.Warnings{"some-warning"},
111+
nil,
112+
)
113+
})
114+
115+
When("getting application processes returns an error", func() {
116+
var expectedErr error
117+
118+
BeforeEach(func() {
119+
expectedErr = errors.New("some-error")
120+
fakeCloudControllerClient.GetApplicationProcessesReturns(
121+
[]resources.Process{},
122+
ccv3.Warnings{"some-process-warning"},
123+
expectedErr,
124+
)
125+
})
126+
127+
It("returns the error and warnings", func() {
128+
Expect(executeErr).To(Equal(expectedErr))
129+
Expect(warnings).To(ConsistOf("some-warning", "some-process-warning"))
130+
})
131+
})
132+
133+
When("application has processes", func() {
134+
BeforeEach(func() {
135+
fakeCloudControllerClient.GetApplicationProcessesReturns(
136+
[]resources.Process{
137+
{
138+
GUID: "process-guid-1",
139+
Type: "process-type-1",
140+
ReadinessHealthCheckType: "readiness-health-check-type-1",
141+
ReadinessHealthCheckEndpoint: "readiness-health-check-endpoint-1",
142+
ReadinessHealthCheckInvocationTimeout: 42,
143+
},
144+
{
145+
GUID: "process-guid-2",
146+
Type: "process-type-2",
147+
ReadinessHealthCheckType: "readiness-health-check-type-2",
148+
ReadinessHealthCheckInvocationTimeout: 0,
149+
},
150+
},
151+
ccv3.Warnings{"some-process-warning"},
152+
nil,
153+
)
154+
})
155+
156+
It("returns health checks", func() {
157+
Expect(executeErr).NotTo(HaveOccurred())
158+
Expect(warnings).To(ConsistOf("some-warning", "some-process-warning"))
159+
Expect(processReadinessHealthChecks).To(Equal([]ProcessReadinessHealthCheck{
160+
{
161+
ProcessType: "process-type-1",
162+
HealthCheckType: "readiness-health-check-type-1",
163+
Endpoint: "readiness-health-check-endpoint-1",
164+
InvocationTimeout: 42,
165+
},
166+
{
167+
ProcessType: "process-type-2",
168+
HealthCheckType: "readiness-health-check-type-2",
169+
InvocationTimeout: 0,
170+
},
171+
}))
172+
})
173+
})
174+
})
175+
})
176+
})

api/cloudcontroller/ccv3/process_test.go

+48-24
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ var _ = Describe("Process", func() {
5656
"endpoint": "/health",
5757
"invocation_timeout": 42
5858
}
59+
},
60+
"readiness_health_check": {
61+
"type": "http",
62+
"data": {
63+
"interval": 9,
64+
"endpoint": "/foo",
65+
"invocation_timeout": 2
66+
}
5967
}
6068
}`
6169
server.AppendHandlers(
@@ -70,18 +78,22 @@ var _ = Describe("Process", func() {
7078
Expect(err).NotTo(HaveOccurred())
7179
Expect(warnings).To(ConsistOf("this is a warning"))
7280
Expect(process).To(MatchAllFields(Fields{
73-
"GUID": Equal("process-1-guid"),
74-
"Type": Equal("some-type"),
75-
"AppGUID": Equal("some-app-guid"),
76-
"Command": Equal(types.FilteredString{IsSet: true, Value: "start-command-1"}),
77-
"Instances": Equal(types.NullInt{Value: 22, IsSet: true}),
78-
"MemoryInMB": Equal(types.NullUint64{Value: 32, IsSet: true}),
79-
"DiskInMB": Equal(types.NullUint64{Value: 1024, IsSet: true}),
80-
"LogRateLimitInBPS": Equal(types.NullInt{Value: 512, IsSet: true}),
81-
"HealthCheckType": Equal(constant.HTTP),
82-
"HealthCheckEndpoint": Equal("/health"),
83-
"HealthCheckInvocationTimeout": BeEquivalentTo(42),
84-
"HealthCheckTimeout": BeEquivalentTo(90),
81+
"GUID": Equal("process-1-guid"),
82+
"Type": Equal("some-type"),
83+
"AppGUID": Equal("some-app-guid"),
84+
"Command": Equal(types.FilteredString{IsSet: true, Value: "start-command-1"}),
85+
"Instances": Equal(types.NullInt{Value: 22, IsSet: true}),
86+
"MemoryInMB": Equal(types.NullUint64{Value: 32, IsSet: true}),
87+
"DiskInMB": Equal(types.NullUint64{Value: 1024, IsSet: true}),
88+
"LogRateLimitInBPS": Equal(types.NullInt{Value: 512, IsSet: true}),
89+
"HealthCheckType": Equal(constant.HTTP),
90+
"HealthCheckEndpoint": Equal("/health"),
91+
"HealthCheckInvocationTimeout": BeEquivalentTo(42),
92+
"HealthCheckTimeout": BeEquivalentTo(90),
93+
"ReadinessHealthCheckType": Equal(constant.HTTP),
94+
"ReadinessHealthCheckEndpoint": Equal("/foo"),
95+
"ReadinessHealthCheckInvocationTimeout": BeEquivalentTo(2),
96+
"ReadinessHealthCheckInterval": BeEquivalentTo(9),
8597
}))
8698
})
8799
})
@@ -317,6 +329,14 @@ var _ = Describe("Process", func() {
317329
"endpoint": "/health",
318330
"invocation_timeout": 42
319331
}
332+
},
333+
"readiness_health_check": {
334+
"type": "http",
335+
"data": {
336+
"interval": 9,
337+
"endpoint": "/foo",
338+
"invocation_timeout": 2
339+
}
320340
}
321341
}`
322342
server.AppendHandlers(
@@ -331,18 +351,22 @@ var _ = Describe("Process", func() {
331351
Expect(err).NotTo(HaveOccurred())
332352
Expect(warnings).To(ConsistOf("this is a warning"))
333353
Expect(process).To(MatchAllFields(Fields{
334-
"GUID": Equal("process-1-guid"),
335-
"Type": Equal("some-type"),
336-
"AppGUID": Equal("some-app-guid"),
337-
"Command": Equal(types.FilteredString{IsSet: true, Value: "start-command-1"}),
338-
"Instances": Equal(types.NullInt{Value: 22, IsSet: true}),
339-
"MemoryInMB": Equal(types.NullUint64{Value: 32, IsSet: true}),
340-
"DiskInMB": Equal(types.NullUint64{Value: 1024, IsSet: true}),
341-
"LogRateLimitInBPS": Equal(types.NullInt{Value: 64, IsSet: true}),
342-
"HealthCheckType": Equal(constant.HTTP),
343-
"HealthCheckEndpoint": Equal("/health"),
344-
"HealthCheckInvocationTimeout": BeEquivalentTo(42),
345-
"HealthCheckTimeout": BeEquivalentTo(90),
354+
"GUID": Equal("process-1-guid"),
355+
"Type": Equal("some-type"),
356+
"AppGUID": Equal("some-app-guid"),
357+
"Command": Equal(types.FilteredString{IsSet: true, Value: "start-command-1"}),
358+
"Instances": Equal(types.NullInt{Value: 22, IsSet: true}),
359+
"MemoryInMB": Equal(types.NullUint64{Value: 32, IsSet: true}),
360+
"DiskInMB": Equal(types.NullUint64{Value: 1024, IsSet: true}),
361+
"LogRateLimitInBPS": Equal(types.NullInt{Value: 64, IsSet: true}),
362+
"HealthCheckType": Equal(constant.HTTP),
363+
"HealthCheckEndpoint": Equal("/health"),
364+
"HealthCheckInvocationTimeout": BeEquivalentTo(42),
365+
"HealthCheckTimeout": BeEquivalentTo(90),
366+
"ReadinessHealthCheckType": Equal(constant.HTTP),
367+
"ReadinessHealthCheckEndpoint": Equal("/foo"),
368+
"ReadinessHealthCheckInvocationTimeout": BeEquivalentTo(2),
369+
"ReadinessHealthCheckInterval": BeEquivalentTo(9),
346370
}))
347371
})
348372
})

cf/appfiles/app_files_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ var _ = Describe("AppFiles", func() {
108108

109109
Describe("CopyFiles", func() {
110110
It("copies only the files specified", func() {
111-
copyDir := filepath.Join(fixturePath, "app-copy-test")
111+
copyDir, err := filepath.Abs(filepath.Join(fixturePath, "app-copy-test"))
112+
Expect(err).NotTo(HaveOccurred())
112113

113114
filesToCopy := []models.AppFileFields{
114115
{Path: filepath.Join("dir1")},
@@ -117,7 +118,8 @@ var _ = Describe("AppFiles", func() {
117118

118119
files := []string{}
119120

120-
fileutils.TempDir("copyToDir", func(tmpDir string, err error) {
121+
fileutils.TempDir("copyToDir", func(tmpDir string, tmpErr error) {
122+
Expect(tmpErr).NotTo(HaveOccurred())
121123
copyErr := appFiles.CopyFiles(filesToCopy, copyDir, tmpDir)
122124
Expect(copyErr).ToNot(HaveOccurred())
123125

command/common/command_list_v7.go

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ type commandList struct {
8787
FeatureFlag v7.FeatureFlagCommand `command:"feature-flag" description:"Retrieve an individual feature flag with status"`
8888
FeatureFlags v7.FeatureFlagsCommand `command:"feature-flags" description:"Retrieve list of feature flags with status"`
8989
GetHealthCheck v7.GetHealthCheckCommand `command:"get-health-check" description:"Show the type of health check performed on an app"`
90+
GetReadinessHealthCheck v7.GetReadinessHealthCheckCommand `command:"get-readiness-health-check" description:"Show the type of readiness health check performed on an app"`
9091
Help HelpCommand `command:"help" alias:"h" description:"Show help"`
9192
InstallPlugin InstallPluginCommand `command:"install-plugin" description:"Install CLI plugin"`
9293
IsolationSegments v7.IsolationSegmentsCommand `command:"isolation-segments" description:"List all isolation segments"`

command/common/internal/help_all_display.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ var HelpCategoryList = []HelpCategory{
2323
{"env", "set-env", "unset-env"},
2424
{"stacks", "stack"},
2525
{"copy-source", "create-app-manifest"},
26-
{"get-health-check", "set-health-check", "enable-ssh", "disable-ssh", "ssh-enabled", "ssh"},
26+
{"get-health-check", "set-health-check", "get-readiness-health-check"},
27+
{"enable-ssh", "disable-ssh", "ssh-enabled", "ssh"},
2728
},
2829
},
2930
{

command/v7/actor.go

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ type Actor interface {
9494
GetApplicationLabels(appName string, spaceGUID string) (map[string]types.NullString, v7action.Warnings, error)
9595
GetApplicationPackages(appName string, spaceGUID string) ([]resources.Package, v7action.Warnings, error)
9696
GetApplicationProcessHealthChecksByNameAndSpace(appName string, spaceGUID string) ([]v7action.ProcessHealthCheck, v7action.Warnings, error)
97+
GetApplicationProcessReadinessHealthChecksByNameAndSpace(appName string, spaceGUID string) ([]v7action.ProcessReadinessHealthCheck, v7action.Warnings, error)
9798
GetApplicationRevisionsDeployed(appGUID string) ([]resources.Revision, v7action.Warnings, error)
9899
GetApplicationRoutes(appGUID string) ([]resources.Route, v7action.Warnings, error)
99100
GetApplicationTasks(appName string, sortOrder v7action.SortOrder) ([]resources.Task, v7action.Warnings, error)

0 commit comments

Comments
 (0)