github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/dli/v1/queues/requests.go (about) 1 package queues 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/openstack/common/tags" 6 ) 7 8 // CreateOpts contains the options for create a service. This object is passed to Create(). 9 type CreateOpts struct { 10 // Name of a newly created resource queue. The name can contain only digits, letters, and underscores (_), 11 //but cannot contain only digits or start with an underscore (_). Length range: 1 to 128 characters. 12 QueueName string `json:"queue_name" required:"true"` 13 14 // Indicates the queue type. The options are as follows: 15 // sql 16 // general 17 // all 18 // NOTE: 19 // If the type is not specified, the default value sql is used. 20 QueueType string `json:"queue_type ,omitempty"` 21 22 // Description of a queue. 23 Description string `json:"description,omitempty"` 24 25 // Minimum number of CUs that are bound to a queue. Currently, the value can only be 16, 64, or 256. 26 CuCount int `json:"cu_count" required:"true"` 27 28 // Billing mode of a queue. This value can only be set to 1, indicating that the billing is based on the CUH used. 29 ChargingMode int `json:"charging_mode,omitempty"` 30 31 // Enterprise project ID. The value 0 indicates the default enterprise project. 32 // NOTE: 33 // Users who have enabled Enterprise Management can set this parameter to bind a specified project. 34 EnterpriseProjectId string `json:"enterprise_project_id,omitempty"` 35 36 // CPU architecture of queue computing resources. 37 // x86_64 (default) 38 // aarch64 39 Platform string `json:"platform,omitempty"` 40 41 // Queue resource mode. The options are as follows: 42 // 0: indicates the shared resource mode. 43 // 1: indicates the exclusive resource mode. 44 ResourceMode int `json:"resource_mode"` 45 46 // Specifies the tag information of the queue to be created, 47 // including the JSON character string indicating whether the queue is Dual-AZ. Currently, 48 // only the value 2 is supported, indicating that two queues are created. 49 Labels []string `json:"labels,omitempty"` 50 51 // Indicates the queue feature. The options are as follows: 52 // basic: basic type 53 // ai: AI-enhanced (Only the SQL x86_64 dedicated queue supports this option.) 54 // The default value is basic. 55 // NOTE: 56 // For an enhanced AI queue, an AI image is loaded in the background. 57 // The image integrates AI algorithm packages based on the basic image. 58 Feature string `json:"feature,omitempty"` 59 60 Tags []tags.ResourceTag `json:"tags,omitempty"` 61 } 62 63 type ListOpts struct { 64 QueueType string `q:"queue_type"` 65 WithPriv bool `q:"with-priv"` 66 WithChargeInfo bool `q:"with-charge-info"` 67 Tags string `q:"tags"` 68 } 69 70 type ActionOpts struct { 71 Action string `json:"action" required:"true"` //Operations to be performed: restart; scale_out;scale_in 72 Force bool `json:"force,omitempty"` //when action= restart,can Specifies whether to forcibly restart 73 CuCount int `json:"cu_count,omitempty"` // Number of CUs to be scaled in or out. 74 QueueName string `json:"-" required:"true"` 75 } 76 77 // CreateOptsBuilder allows extensions to add additional parameters to the 78 // Create request. 79 type CreateOptsBuilder interface { 80 ToDomainCreateMap() (map[string]interface{}, error) 81 } 82 83 // ToDomainCreateMap builds a create request body from CreateOpts. 84 func (opts CreateOpts) ToDomainCreateMap() (map[string]interface{}, error) { 85 return golangsdk.BuildRequestBody(opts, "") 86 } 87 88 type ListOptsBuilder interface { 89 ToListQuery() (string, error) 90 } 91 92 func (opts ListOpts) ToListQuery() (string, error) { 93 q, err := golangsdk.BuildQueryString(opts) 94 return q.String(), err 95 } 96 97 /* 98 This API is used to create a queue. 99 100 @cloudAPI-URL: POST /v1.0/{project_id}/queues 101 @cloudAPI-ResourceType: dli 102 @cloudAPI-version: v1.0 103 104 @since: 2021-07-07 12:12:12 105 106 */ 107 func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 108 requstbody, err := opts.ToDomainCreateMap() 109 if err != nil { 110 r.Err = err 111 return 112 } 113 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 114 _, r.Err = c.Post(createURL(c), requstbody, &r.Body, reqOpt) 115 return 116 } 117 118 /* 119 This API is used to delete a queue. 120 121 @cloudAPI-URL: Delete /v1.0/{project_id}/queues/{queueName} 122 @cloudAPI-ResourceType: dli 123 @cloudAPI-version: v1.0 124 125 @since: 2021-07-07 12:12:12 126 127 */ 128 func Delete(c *golangsdk.ServiceClient, queueName string) (r DeleteResult) { 129 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 130 _, r.Err = c.Delete(resourceURL(c, queueName), reqOpt) 131 return 132 } 133 134 /* 135 This API is used to query all Queue list 136 137 @cloudAPI-URL: GET /v1.0/{project_id}/queues 138 @cloudAPI-ResourceType: dli 139 @cloudAPI-version: v1.0 140 141 @since: 2021-07-07 12:12:12 142 143 */ 144 func List(c *golangsdk.ServiceClient, listOpts ListOptsBuilder) (r GetResult) { 145 listResult := new(ListResult) 146 147 url := queryAllURL(c) 148 if listOpts != nil { 149 query, err := listOpts.ToListQuery() 150 if err != nil { 151 r.Err = err 152 return 153 } 154 url += query 155 } 156 157 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 158 _, r.Err = c.Get(queryAllURL(c), &listResult, reqOpt) 159 r.Body = listResult 160 return r 161 } 162 163 /* 164 This API is used to query the Details of a Queue 165 166 @cloudAPI-URL: GET /v1.0/{project_id}/queues/{queueName} 167 @cloudAPI-ResourceType: dli 168 @cloudAPI-version: v1.0 169 170 @since: 2021-07-07 12:12:12 171 172 */ 173 func Get(c *golangsdk.ServiceClient, queueName string) (r GetResult) { 174 result := new(Queue4Get) 175 176 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 177 _, r.Err = c.Get(resourceURL(c, queueName), &result, reqOpt) 178 179 if result != nil { 180 r.Body = result 181 } 182 183 return r 184 } 185 186 func ScaleOrRestart(c *golangsdk.ServiceClient, opts ActionOpts) (r PutResult) { 187 requstbody, err := golangsdk.BuildRequestBody(opts, "") 188 if err != nil { 189 r.Err = err 190 return 191 } 192 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 193 _, r.Err = c.Put(ActionURL(c, opts.QueueName), requstbody, &r.Body, reqOpt) 194 return 195 }