github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/actor/v3action/process_instance.go (about)

     1  package v3action
     2  
     3  import (
     4  	"time"
     5  
     6  	"code.cloudfoundry.org/cli/actor/actionerror"
     7  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
     8  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
     9  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
    10  )
    11  
    12  type ProcessInstance ccv3.ProcessInstance
    13  
    14  // Running will return true if the instance is running.
    15  func (instance ProcessInstance) Running() bool {
    16  	return instance.State == constant.ProcessInstanceRunning
    17  }
    18  
    19  // StartTime returns the time that the instance started.
    20  func (instance *ProcessInstance) StartTime() time.Time {
    21  	return time.Now().Add(-instance.Uptime)
    22  }
    23  
    24  func (actor Actor) DeleteInstanceByApplicationNameSpaceProcessTypeAndIndex(appName string, spaceGUID string, processType string, instanceIndex int) (Warnings, error) {
    25  	var allWarnings Warnings
    26  	app, appWarnings, err := actor.GetApplicationByNameAndSpace(appName, spaceGUID)
    27  	allWarnings = append(allWarnings, appWarnings...)
    28  	if err != nil {
    29  		return allWarnings, err
    30  	}
    31  
    32  	deleteWarnings, err := actor.CloudControllerClient.DeleteApplicationProcessInstance(app.GUID, processType, instanceIndex)
    33  	allWarnings = append(allWarnings, deleteWarnings...)
    34  
    35  	if err != nil {
    36  		switch err.(type) {
    37  		case ccerror.ProcessNotFoundError:
    38  			return allWarnings, actionerror.ProcessNotFoundError{
    39  				ProcessType: processType,
    40  			}
    41  		case ccerror.InstanceNotFoundError:
    42  			return allWarnings, actionerror.ProcessInstanceNotFoundError{
    43  				ProcessType:   processType,
    44  				InstanceIndex: uint(instanceIndex),
    45  			}
    46  		default:
    47  			return allWarnings, err
    48  		}
    49  	}
    50  
    51  	return allWarnings, nil
    52  }