github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+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 // GetProcessByTypeAndApplication returns a process for the given application 14 // and type. 15 func (actor Actor) GetProcessByTypeAndApplication(processType string, appGUID string) (Process, Warnings, error) { 16 process, warnings, err := actor.CloudControllerClient.GetApplicationProcessByType(appGUID, processType) 17 if _, ok := err.(ccerror.ProcessNotFoundError); ok { 18 return Process{}, Warnings(warnings), actionerror.ProcessNotFoundError{ProcessType: processType} 19 } 20 return Process(process), Warnings(warnings), err 21 } 22 23 func (actor Actor) ScaleProcessByApplication(appGUID string, process Process) (Warnings, error) { 24 _, warnings, err := actor.CloudControllerClient.CreateApplicationProcessScale(appGUID, ccv3.Process(process)) 25 allWarnings := Warnings(warnings) 26 if err != nil { 27 if _, ok := err.(ccerror.ProcessNotFoundError); ok { 28 return allWarnings, actionerror.ProcessNotFoundError{ProcessType: process.Type} 29 } 30 return allWarnings, err 31 } 32 33 return allWarnings, nil 34 } 35 36 func (actor Actor) UpdateProcessByTypeAndApplication(processType string, appGUID string, updatedProcess Process) (Warnings, error) { 37 if updatedProcess.HealthCheckType != constant.HTTP { 38 if updatedProcess.HealthCheckEndpoint == constant.ProcessHealthCheckEndpointDefault || updatedProcess.HealthCheckEndpoint == "" { 39 updatedProcess.HealthCheckEndpoint = "" 40 } else { 41 return nil, actionerror.HTTPHealthCheckInvalidError{} 42 } 43 } 44 45 process, warnings, err := actor.GetProcessByTypeAndApplication(processType, appGUID) 46 allWarnings := Warnings(warnings) 47 if err != nil { 48 return allWarnings, err 49 } 50 51 updatedProcess.GUID = process.GUID 52 _, updateWarnings, err := actor.CloudControllerClient.UpdateProcess(ccv3.Process(updatedProcess)) 53 allWarnings = append(allWarnings, Warnings(updateWarnings)...) 54 if err != nil { 55 return allWarnings, err 56 } 57 58 return allWarnings, nil 59 }