forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
application_summary.go
74 lines (62 loc) · 2.14 KB
/
application_summary.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package v2action
import (
"code.cloudfoundry.org/cli/actor/actionerror"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2"
)
type ApplicationSummary struct {
Application
Stack Stack
IsolationSegment string
RunningInstances []ApplicationInstanceWithStats
Routes []Route
}
func (app ApplicationSummary) StartingOrRunningInstanceCount() int {
count := 0
for _, instance := range app.RunningInstances {
if instance.State == ApplicationInstanceState(ccv2.ApplicationInstanceStarting) ||
instance.State == ApplicationInstanceState(ccv2.ApplicationInstanceRunning) {
count++
}
}
return count
}
func (actor Actor) GetApplicationSummaryByNameAndSpace(name string, spaceGUID string) (ApplicationSummary, Warnings, error) {
var allWarnings Warnings
app, warnings, err := actor.GetApplicationByNameAndSpace(name, spaceGUID)
allWarnings = append(allWarnings, warnings...)
if err != nil {
return ApplicationSummary{}, allWarnings, err
}
applicationSummary := ApplicationSummary{Application: app}
// cloud controller calls the instance reporter only when the desired
// application state is STARTED
if app.State == ccv2.ApplicationStarted {
var instances []ApplicationInstanceWithStats
instances, warnings, err = actor.GetApplicationInstancesWithStatsByApplication(app.GUID)
allWarnings = append(allWarnings, warnings...)
switch err.(type) {
case nil:
applicationSummary.RunningInstances = instances
if len(instances) > 0 {
applicationSummary.IsolationSegment = instances[0].IsolationSegment
}
case actionerror.ApplicationInstancesNotFoundError:
// don't set instances in summary
default:
return ApplicationSummary{}, allWarnings, err
}
}
routes, warnings, err := actor.GetApplicationRoutes(app.GUID)
allWarnings = append(allWarnings, warnings...)
if err != nil {
return ApplicationSummary{}, allWarnings, err
}
applicationSummary.Routes = routes
stack, warnings, err := actor.GetStack(app.StackGUID)
allWarnings = append(allWarnings, warnings...)
if err != nil {
return ApplicationSummary{}, allWarnings, err
}
applicationSummary.Stack = stack
return applicationSummary, allWarnings, nil
}