github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+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  	uptimeDuration := time.Duration(instance.Uptime) * time.Second
    22  
    23  	return time.Now().Add(-uptimeDuration)
    24  }
    25  
    26  func (actor Actor) DeleteInstanceByApplicationNameSpaceProcessTypeAndIndex(appName string, spaceGUID string, processType string, instanceIndex int) (Warnings, error) {
    27  	var allWarnings Warnings
    28  	app, appWarnings, err := actor.GetApplicationByNameAndSpace(appName, spaceGUID)
    29  	allWarnings = append(allWarnings, appWarnings...)
    30  	if err != nil {
    31  		return allWarnings, err
    32  	}
    33  
    34  	deleteWarnings, err := actor.CloudControllerClient.DeleteApplicationProcessInstance(app.GUID, processType, instanceIndex)
    35  	allWarnings = append(allWarnings, deleteWarnings...)
    36  
    37  	if err != nil {
    38  		switch err.(type) {
    39  		case ccerror.ProcessNotFoundError:
    40  			return allWarnings, actionerror.ProcessNotFoundError{
    41  				ProcessType: processType,
    42  			}
    43  		case ccerror.InstanceNotFoundError:
    44  			return allWarnings, actionerror.ProcessInstanceNotFoundError{
    45  				ProcessType:   processType,
    46  				InstanceIndex: uint(instanceIndex),
    47  			}
    48  		default:
    49  			return allWarnings, err
    50  		}
    51  	}
    52  
    53  	return allWarnings, nil
    54  }