github.com/swisscom/cloudfoundry-cli@v7.1.0+incompatible/api/cloudcontroller/ccv3/task.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 ) 7 8 // Task represents a Cloud Controller V3 Task. 9 type Task struct { 10 // Command represents the command that will be executed. May be excluded 11 // based on the user's role. 12 Command string `json:"command,omitempty"` 13 // CreatedAt represents the time with zone when the object was created. 14 CreatedAt string `json:"created_at,omitempty"` 15 // DiskInMB represents the disk in MB allocated for the task. 16 DiskInMB uint64 `json:"disk_in_mb,omitempty"` 17 // GUID represents the unique task identifier. 18 GUID string `json:"guid,omitempty"` 19 // MemoryInMB represents the memory in MB allocated for the task. 20 MemoryInMB uint64 `json:"memory_in_mb,omitempty"` 21 // Name represents the name of the task. 22 Name string `json:"name,omitempty"` 23 // SequenceID represents the user-facing id of the task. This number is 24 // unique for every task associated with a given app. 25 SequenceID int64 `json:"sequence_id,omitempty"` 26 // State represents the task state. 27 State constant.TaskState `json:"state,omitempty"` 28 // Tasks can use a process as a template to fill in 29 // command, memory, disk values 30 // 31 // Using a pointer so that it can be set to nil to prevent 32 // json serialization when no template is used 33 Template *TaskTemplate `json:"template,omitempty"` 34 } 35 36 type TaskTemplate struct { 37 Process TaskProcessTemplate `json:"process,omitempty"` 38 } 39 40 type TaskProcessTemplate struct { 41 Guid string `json:"guid,omitempty"` 42 } 43 44 // CreateApplicationTask runs a command in the Application environment 45 // associated with the provided Application GUID. 46 func (client *Client) CreateApplicationTask(appGUID string, task Task) (Task, Warnings, error) { 47 var responseBody Task 48 49 _, warnings, err := client.MakeRequest(RequestParams{ 50 RequestName: internal.PostApplicationTasksRequest, 51 URIParams: internal.Params{"app_guid": appGUID}, 52 RequestBody: task, 53 ResponseBody: &responseBody, 54 }) 55 56 return responseBody, warnings, err 57 } 58 59 // GetApplicationTasks returns a list of tasks associated with the provided 60 // application GUID. Results can be filtered by providing URL queries. 61 func (client *Client) GetApplicationTasks(appGUID string, query ...Query) ([]Task, Warnings, error) { 62 var resources []Task 63 64 _, warnings, err := client.MakeListRequest(RequestParams{ 65 RequestName: internal.GetApplicationTasksRequest, 66 URIParams: internal.Params{"app_guid": appGUID}, 67 Query: query, 68 ResponseBody: Task{}, 69 AppendToList: func(item interface{}) error { 70 resources = append(resources, item.(Task)) 71 return nil 72 }, 73 }) 74 75 return resources, warnings, err 76 } 77 78 // UpdateTaskCancel cancels a task. 79 func (client *Client) UpdateTaskCancel(taskGUID string) (Task, Warnings, error) { 80 var responseBody Task 81 82 _, warnings, err := client.MakeRequest(RequestParams{ 83 RequestName: internal.PutTaskCancelRequest, 84 URIParams: internal.Params{ 85 "task_guid": taskGUID, 86 }, 87 ResponseBody: &responseBody, 88 }) 89 90 return responseBody, warnings, err 91 }