forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
application_instance.go
41 lines (30 loc) · 1.34 KB
/
application_instance.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
package v2action
import (
"code.cloudfoundry.org/cli/actor/actionerror"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/constant"
)
type ApplicationInstanceState constant.ApplicationInstanceState
type ApplicationInstance ccv2.ApplicationInstance
func (instance ApplicationInstance) Crashed() bool {
return instance.State == constant.ApplicationInstanceCrashed
}
func (instance ApplicationInstance) Flapping() bool {
return instance.State == constant.ApplicationInstanceFlapping
}
func (instance ApplicationInstance) Running() bool {
return instance.State == constant.ApplicationInstanceRunning
}
func (actor Actor) GetApplicationInstancesByApplication(guid string) (map[int]ApplicationInstance, Warnings, error) {
ccAppInstances, warnings, err := actor.CloudControllerClient.GetApplicationApplicationInstances(guid)
switch err.(type) {
case ccerror.ResourceNotFoundError, ccerror.NotStagedError, ccerror.InstancesError:
return nil, Warnings(warnings), actionerror.ApplicationInstancesNotFoundError{ApplicationGUID: guid}
}
appInstances := map[int]ApplicationInstance{}
for id, applicationInstance := range ccAppInstances {
appInstances[id] = ApplicationInstance(applicationInstance)
}
return appInstances, Warnings(warnings), err
}