github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/actor/v2action/application_summary.go (about) 1 package v2action 2 3 import "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2" 4 5 type ApplicationSummary struct { 6 Application 7 Stack Stack 8 RunningInstances []ApplicationInstanceWithStats 9 Routes []Route 10 } 11 12 func (actor Actor) GetApplicationSummaryByNameAndSpace(name string, spaceGUID string) (ApplicationSummary, Warnings, error) { 13 var allWarnings Warnings 14 15 app, warnings, err := actor.GetApplicationByNameAndSpace(name, spaceGUID) 16 allWarnings = append(allWarnings, warnings...) 17 if err != nil { 18 return ApplicationSummary{}, allWarnings, err 19 } 20 21 applicationSummary := ApplicationSummary{Application: app} 22 23 // cloud controller calls the instance reporter only when the desired 24 // application state is STARTED 25 if app.State == ccv2.ApplicationStarted { 26 var instances []ApplicationInstanceWithStats 27 instances, warnings, err = actor.GetApplicationInstancesWithStatsByApplication(app.GUID) 28 allWarnings = append(allWarnings, warnings...) 29 30 switch err.(type) { 31 case nil: 32 applicationSummary.RunningInstances = instances 33 case ApplicationInstancesNotFoundError: 34 // don't set instances in summary 35 default: 36 return ApplicationSummary{}, allWarnings, err 37 } 38 } 39 40 routes, warnings, err := actor.GetApplicationRoutes(app.GUID, nil) 41 allWarnings = append(allWarnings, warnings...) 42 if err != nil { 43 return ApplicationSummary{}, allWarnings, err 44 } 45 applicationSummary.Routes = routes 46 47 stack, warnings, err := actor.GetStack(app.StackGUID) 48 allWarnings = append(allWarnings, warnings...) 49 if err != nil { 50 return ApplicationSummary{}, allWarnings, err 51 } 52 applicationSummary.Stack = stack 53 54 return applicationSummary, allWarnings, nil 55 }