github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/actor/v7action/process_instance.go (about) 1 package v7action 2 3 import ( 4 "time" 5 6 "code.cloudfoundry.org/cli/actor/actionerror" 7 "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" 8 9 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3" 10 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant" 11 ) 12 13 type ProcessInstance ccv3.ProcessInstance 14 15 // Running will return true if the instance is running. 16 func (instance ProcessInstance) Running() bool { 17 return instance.State == constant.ProcessInstanceRunning 18 } 19 20 // StartTime returns the time that the instance started. 21 func (instance *ProcessInstance) StartTime() time.Time { 22 return time.Now().Add(-instance.Uptime) 23 } 24 25 type ProcessInstances []ccv3.ProcessInstance 26 27 func (pi ProcessInstances) AllCrashed() bool { 28 for _, instance := range pi { 29 if instance.State != constant.ProcessInstanceCrashed { 30 return false 31 } 32 } 33 return true 34 } 35 36 func (pi ProcessInstances) AnyRunning() bool { 37 for _, instance := range pi { 38 if instance.State == constant.ProcessInstanceRunning { 39 return true 40 } 41 } 42 return false 43 } 44 45 func (pi ProcessInstances) Empty() bool { 46 return len(pi) == 0 47 } 48 49 func (actor Actor) DeleteInstanceByApplicationNameSpaceProcessTypeAndIndex(appName string, spaceGUID string, processType string, instanceIndex int) (Warnings, error) { 50 var allWarnings Warnings 51 app, appWarnings, err := actor.GetApplicationByNameAndSpace(appName, spaceGUID) 52 allWarnings = append(allWarnings, appWarnings...) 53 if err != nil { 54 return allWarnings, err 55 } 56 57 deleteWarnings, err := actor.CloudControllerClient.DeleteApplicationProcessInstance(app.GUID, processType, instanceIndex) 58 allWarnings = append(allWarnings, deleteWarnings...) 59 60 if err != nil { 61 switch err.(type) { 62 case ccerror.ProcessNotFoundError: 63 return allWarnings, actionerror.ProcessNotFoundError{ 64 ProcessType: processType, 65 } 66 case ccerror.InstanceNotFoundError: 67 return allWarnings, actionerror.ProcessInstanceNotFoundError{ 68 ProcessType: processType, 69 InstanceIndex: uint(instanceIndex), 70 } 71 default: 72 return allWarnings, err 73 } 74 } 75 76 return allWarnings, nil 77 }