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

     1  package v7action
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/actor/actionerror"
     5  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
     6  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
     7  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
     8  )
     9  
    10  // Process represents a V3 actor process.
    11  type Process ccv3.Process
    12  
    13  func (actor Actor) GetProcess(processGUID string) (Process, Warnings, error) {
    14  	process, warnings, err := actor.CloudControllerClient.GetProcess(processGUID)
    15  
    16  	return Process(process), Warnings(warnings), err
    17  }
    18  
    19  // GetProcessByTypeAndApplication returns a process for the given application
    20  // and type.
    21  func (actor Actor) GetProcessByTypeAndApplication(processType string, appGUID string) (Process, Warnings, error) {
    22  	process, warnings, err := actor.CloudControllerClient.GetApplicationProcessByType(appGUID, processType)
    23  	if _, ok := err.(ccerror.ProcessNotFoundError); ok {
    24  		return Process{}, Warnings(warnings), actionerror.ProcessNotFoundError{ProcessType: processType}
    25  	}
    26  	return Process(process), Warnings(warnings), err
    27  }
    28  
    29  func (actor Actor) ScaleProcessByApplication(appGUID string, process Process) (Warnings, error) {
    30  	_, warnings, err := actor.CloudControllerClient.CreateApplicationProcessScale(appGUID, ccv3.Process(process))
    31  	allWarnings := Warnings(warnings)
    32  	if err != nil {
    33  		if _, ok := err.(ccerror.ProcessNotFoundError); ok {
    34  			return allWarnings, actionerror.ProcessNotFoundError{ProcessType: process.Type}
    35  		}
    36  		return allWarnings, err
    37  	}
    38  
    39  	return allWarnings, nil
    40  }
    41  
    42  func (actor Actor) UpdateProcessByTypeAndApplication(processType string, appGUID string, updatedProcess Process) (Warnings, error) {
    43  	if updatedProcess.HealthCheckType != constant.HTTP {
    44  		if updatedProcess.HealthCheckEndpoint != constant.ProcessHealthCheckEndpointDefault && updatedProcess.HealthCheckEndpoint != "" {
    45  			return nil, actionerror.HTTPHealthCheckInvalidError{}
    46  		}
    47  
    48  		updatedProcess.HealthCheckEndpoint = ""
    49  	}
    50  
    51  	process, warnings, err := actor.GetProcessByTypeAndApplication(processType, appGUID)
    52  	allWarnings := warnings
    53  	if err != nil {
    54  		return allWarnings, err
    55  	}
    56  
    57  	updatedProcess.GUID = process.GUID
    58  	_, updateWarnings, err := actor.CloudControllerClient.UpdateProcess(ccv3.Process(updatedProcess))
    59  	allWarnings = append(allWarnings, Warnings(updateWarnings)...)
    60  	if err != nil {
    61  		return allWarnings, err
    62  	}
    63  
    64  	return allWarnings, nil
    65  }