github.com/lukasheimann/cloudfoundrycli@v7.1.0+incompatible/actor/v7action/process_health_check.go (about)

     1  package v7action
     2  
     3  import (
     4  	"sort"
     5  
     6  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
     7  )
     8  
     9  type ProcessHealthCheck struct {
    10  	ProcessType       string
    11  	HealthCheckType   constant.HealthCheckType
    12  	Endpoint          string
    13  	InvocationTimeout int64
    14  }
    15  
    16  type ProcessHealthChecks []ProcessHealthCheck
    17  
    18  func (phs ProcessHealthChecks) Sort() {
    19  	sort.Slice(phs, func(i int, j int) bool {
    20  		var iScore int
    21  		var jScore int
    22  
    23  		switch phs[i].ProcessType {
    24  		case constant.ProcessTypeWeb:
    25  			iScore = 0
    26  		default:
    27  			iScore = 1
    28  		}
    29  
    30  		switch phs[j].ProcessType {
    31  		case constant.ProcessTypeWeb:
    32  			jScore = 0
    33  		default:
    34  			jScore = 1
    35  		}
    36  
    37  		if iScore == 1 && jScore == 1 {
    38  			return phs[i].ProcessType < phs[j].ProcessType
    39  		}
    40  		return iScore < jScore
    41  	})
    42  }
    43  
    44  func (actor Actor) GetApplicationProcessHealthChecksByNameAndSpace(appName string, spaceGUID string) ([]ProcessHealthCheck, Warnings, error) {
    45  	app, allWarnings, err := actor.GetApplicationByNameAndSpace(appName, spaceGUID)
    46  	if err != nil {
    47  		return nil, allWarnings, err
    48  	}
    49  
    50  	ccv3Processes, warnings, err := actor.CloudControllerClient.GetApplicationProcesses(app.GUID)
    51  	allWarnings = append(allWarnings, Warnings(warnings)...)
    52  	if err != nil {
    53  		return nil, allWarnings, err
    54  	}
    55  
    56  	var processHealthChecks ProcessHealthChecks
    57  	for _, ccv3Process := range ccv3Processes {
    58  		processHealthCheck := ProcessHealthCheck{
    59  			ProcessType:       ccv3Process.Type,
    60  			HealthCheckType:   ccv3Process.HealthCheckType,
    61  			Endpoint:          ccv3Process.HealthCheckEndpoint,
    62  			InvocationTimeout: ccv3Process.HealthCheckInvocationTimeout,
    63  		}
    64  		processHealthChecks = append(processHealthChecks, processHealthCheck)
    65  	}
    66  
    67  	processHealthChecks.Sort()
    68  
    69  	return processHealthChecks, allWarnings, nil
    70  }