forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_instance.go
52 lines (43 loc) · 1.56 KB
/
process_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
package v3action
import (
"time"
"code.cloudfoundry.org/cli/actor/actionerror"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
)
type ProcessInstance ccv3.ProcessInstance
// Running will return true if the instance is running.
func (instance ProcessInstance) Running() bool {
return instance.State == constant.ProcessInstanceRunning
}
// StartTime returns the time that the instance started.
func (instance *ProcessInstance) StartTime() time.Time {
return time.Now().Add(-instance.Uptime)
}
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
}