github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/api/cloudcontroller/ccv3/process.go (about) 1 package ccv3 2 3 import ( 4 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant" 5 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/internal" 6 "code.cloudfoundry.org/cli/resources" 7 ) 8 9 // CreateApplicationProcessScale updates process instances count, memory or disk 10 func (client *Client) CreateApplicationProcessScale(appGUID string, process resources.Process) (resources.Process, Warnings, error) { 11 var responseBody resources.Process 12 13 _, warnings, err := client.MakeRequest(RequestParams{ 14 RequestName: internal.PostApplicationProcessActionScaleRequest, 15 URIParams: internal.Params{"app_guid": appGUID, "type": process.Type}, 16 RequestBody: process, 17 ResponseBody: &responseBody, 18 }) 19 20 return responseBody, warnings, err 21 } 22 23 // GetApplicationProcessByType returns application process of specified type 24 func (client *Client) GetApplicationProcessByType(appGUID string, processType string) (resources.Process, Warnings, error) { 25 var responseBody resources.Process 26 27 _, warnings, err := client.MakeRequest(RequestParams{ 28 RequestName: internal.GetApplicationProcessRequest, 29 URIParams: internal.Params{"app_guid": appGUID, "type": processType}, 30 ResponseBody: &responseBody, 31 }) 32 33 return responseBody, warnings, err 34 } 35 36 // GetApplicationProcesses lists processes for a given application. **Note**: 37 // Due to security, the API obfuscates certain values such as `command`. 38 func (client *Client) GetApplicationProcesses(appGUID string) ([]resources.Process, Warnings, error) { 39 var processes []resources.Process 40 41 _, warnings, err := client.MakeListRequest(RequestParams{ 42 RequestName: internal.GetApplicationProcessesRequest, 43 URIParams: internal.Params{"app_guid": appGUID}, 44 ResponseBody: resources.Process{}, 45 AppendToList: func(item interface{}) error { 46 processes = append(processes, item.(resources.Process)) 47 return nil 48 }, 49 }) 50 51 return processes, warnings, err 52 } 53 54 // GetNewApplicationProcesses gets processes for an application in the middle of a deployment. 55 // The app's processes will include a web process that will be removed when the deployment completes, 56 // so exclude that soon-to-be-removed process from the result. 57 func (client *Client) GetNewApplicationProcesses(appGUID string, deploymentGUID string) ([]resources.Process, Warnings, error) { 58 var allWarnings Warnings 59 60 deployment, warnings, err := client.GetDeployment(deploymentGUID) 61 allWarnings = append(allWarnings, warnings...) 62 if err != nil { 63 return nil, allWarnings, err 64 } 65 66 allProcesses, warnings, err := client.GetApplicationProcesses(appGUID) 67 allWarnings = append(allWarnings, warnings...) 68 if err != nil { 69 return nil, allWarnings, err 70 } 71 72 var newWebProcessGUID string 73 for _, process := range deployment.NewProcesses { 74 if process.Type == constant.ProcessTypeWeb { 75 newWebProcessGUID = process.GUID 76 } 77 } 78 79 var processesList []resources.Process 80 for _, process := range allProcesses { 81 if process.Type == constant.ProcessTypeWeb { 82 if process.GUID == newWebProcessGUID { 83 processesList = append(processesList, process) 84 } 85 } else { 86 processesList = append(processesList, process) 87 } 88 } 89 90 return processesList, allWarnings, nil 91 } 92 93 // GetProcess returns a process with the given guid 94 func (client *Client) GetProcess(processGUID string) (resources.Process, Warnings, error) { 95 var responseBody resources.Process 96 97 _, warnings, err := client.MakeRequest(RequestParams{ 98 RequestName: internal.GetProcessRequest, 99 URIParams: internal.Params{"process_guid": processGUID}, 100 ResponseBody: &responseBody, 101 }) 102 103 return responseBody, warnings, err 104 } 105 106 func (client Client) GetProcesses(query ...Query) ([]resources.Process, Warnings, error) { 107 var processes []resources.Process 108 109 _, warnings, err := client.MakeListRequest(RequestParams{ 110 RequestName: internal.GetProcessesRequest, 111 Query: query, 112 ResponseBody: resources.Process{}, 113 AppendToList: func(item interface{}) error { 114 processes = append(processes, item.(resources.Process)) 115 return nil 116 }, 117 }) 118 119 return processes, warnings, err 120 } 121 122 // UpdateProcess updates the process's command or health check settings. GUID 123 // is always required; HealthCheckType is only required when updating health 124 // check settings. 125 func (client *Client) UpdateProcess(process resources.Process) (resources.Process, Warnings, error) { 126 var responseBody resources.Process 127 128 _, warnings, err := client.MakeRequest(RequestParams{ 129 RequestName: internal.PatchProcessRequest, 130 URIParams: internal.Params{"process_guid": process.GUID}, 131 RequestBody: resources.Process{ 132 Command: process.Command, 133 HealthCheckType: process.HealthCheckType, 134 HealthCheckEndpoint: process.HealthCheckEndpoint, 135 HealthCheckTimeout: process.HealthCheckTimeout, 136 HealthCheckInvocationTimeout: process.HealthCheckInvocationTimeout, 137 }, 138 ResponseBody: &responseBody, 139 }) 140 141 return responseBody, warnings, err 142 }