forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
instance.go
53 lines (43 loc) · 1.49 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
package v3action
import (
"time"
"code.cloudfoundry.org/cli/actor/actionerror"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
)
// Instance represents a V3 actor instance.
type Instance ccv3.Instance
func (i Instance) Running() bool {
return i.State == "RUNNING"
}
// StartTime returns the time that the instance started.
func (instance *Instance) StartTime() time.Time {
uptimeDuration := time.Duration(instance.Uptime) * time.Second
return time.Now().Add(-uptimeDuration)
}
func (actor Actor) DeleteInstanceByApplicationNameSpaceProcessTypeAndIndex(appName string, spaceGUID string, processType string, instanceIndex int) (Warnings, error) {
var allWarnings Warnings
app, appWarnings, err := actor.GetApplicationByNameAndSpace(appName, spaceGUID)
allWarnings = append(allWarnings, appWarnings...)
if err != nil {
return allWarnings, err
}
deleteWarnings, err := actor.CloudControllerClient.DeleteApplicationProcessInstance(app.GUID, processType, instanceIndex)
allWarnings = append(allWarnings, deleteWarnings...)
if err != nil {
switch err.(type) {
case ccerror.ProcessNotFoundError:
return allWarnings, actionerror.ProcessNotFoundError{
ProcessType: processType,
}
case ccerror.InstanceNotFoundError:
return allWarnings, actionerror.ProcessInstanceNotFoundError{
ProcessType: processType,
InstanceIndex: uint(instanceIndex),
}
default:
return allWarnings, err
}
}
return allWarnings, nil
}