github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/mrs/v1/cluster/requests.go (about) 1 package cluster 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 ) 6 7 var requestOpts golangsdk.RequestOpts = golangsdk.RequestOpts{ 8 MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"}, 9 } 10 11 type CreateOpts struct { 12 BillingType int `json:"billing_type" required:"true"` 13 DataCenter string `json:"data_center" required:"true"` 14 AvailableZoneID string `json:"available_zone_id" required:"true"` 15 ClusterName string `json:"cluster_name" required:"true"` 16 Vpc string `json:"vpc" required:"true"` 17 VpcID string `json:"vpc_id" required:"true"` 18 SubnetID string `json:"subnet_id" required:"true"` 19 SubnetName string `json:"subnet_name" required:"true"` 20 SecurityGroupsID string `json:"security_groups_id,omitempty"` 21 ClusterVersion string `json:"cluster_version" required:"true"` 22 ClusterType int `json:"cluster_type"` 23 MasterNodeNum int `json:"master_node_num,omitempty"` 24 MasterNodeSize string `json:"master_node_size,omitempty"` 25 CoreNodeNum int `json:"core_node_num,omitempty"` 26 CoreNodeSize string `json:"core_node_size,omitempty"` 27 MasterDataVolumeType string `json:"master_data_volume_type,omitempty"` 28 MasterDataVolumeSize int `json:"master_data_volume_size,omitempty"` 29 MasterDataVolumeCount int `json:"master_data_volume_count,omitempty"` 30 CoreDataVolumeType string `json:"core_data_volume_type,omitempty"` 31 CoreDataVolumeSize int `json:"core_data_volume_size,omitempty"` 32 CoreDataVolumeCount int `json:"core_data_volume_count,omitempty"` 33 VolumeType string `json:"volume_type,omitempty"` 34 VolumeSize int `json:"volume_size,omitempty"` 35 SafeMode int `json:"safe_mode"` 36 ClusterAdminSecret string `json:"cluster_admin_secret" required:"true"` 37 LoginMode int `json:"login_mode"` 38 ClusterMasterSecret string `json:"cluster_master_secret,omitempty"` 39 NodePublicCertName string `json:"node_public_cert_name,omitempty"` 40 LogCollection int `json:"log_collection,omitempty"` 41 NodeGroups []NodeGroupOpts `json:"node_groups,omitempty"` 42 ComponentList []ComponentOpts `json:"component_list" required:"true"` 43 AddJobs []JobOpts `json:"add_jobs,omitempty"` 44 BootstrapScripts []ScriptOpts `json:"bootstrap_scripts,omitempty"` 45 } 46 47 type NodeGroupOpts struct { 48 GroupName string `json:"group_name" required:"true"` 49 NodeSize string `json:"node_size" required:"true"` 50 NodeNum int `json:"node_num" required:"true"` 51 RootVolumeType string `json:"root_volume_type" required:"true"` 52 RootVolumeSize int `json:"root_volume_size" required:"true"` 53 DataVolumeType string `json:"data_volume_type" required:"true"` 54 DataVolumeSize int `json:"data_volume_size" required:"true"` 55 DataVolumeCount int `json:"data_volume_count" required:"true"` 56 } 57 58 type ComponentOpts struct { 59 ComponentName string `json:"component_name" required:"true"` 60 } 61 62 type JobOpts struct { 63 JobType int `json:"job_type" required:"true"` 64 JobName string `json:"job_name" required:"true"` 65 JarPath string `json:"jar_path,omitempty"` 66 Arguments string `json:"arguments,omitempty"` 67 Input string `json:"input,omitempty"` 68 Output string `json:"output,omitempty"` 69 JobLog string `json:"job_log,omitempty"` 70 ShutdownCluster bool `json:"shutdown_cluster,omitempty"` 71 FileAction string `json:"file_action,omitempty"` 72 SubmitJobOnceClusterRun bool `json:"submit_job_once_cluster_run" required:"true"` 73 Hql string `json:"hql,omitempty"` 74 HiveScriptPath string `json:"hive_script_path" required:"true"` 75 } 76 77 type ScriptOpts struct { 78 Name string `json:"name" required:"true"` 79 Uri string `json:"uri" required:"true"` 80 Parameters string `json:"parameters,omitempty"` 81 Nodes []string `json:"nodes" required:"true"` 82 ActiveMaster bool `json:"active_master,omitempty"` 83 BeforeComponentStart bool `json:"before_component_start,omitempty"` 84 FailAction string `json:"fail_action" required:"true"` 85 } 86 87 type HostOpts struct { 88 // Maximum number of clusters displayed on a page 89 // Value range: [1-2147483646]. The default value is 10. 90 PageSize int `q:"pageSize"` 91 // Current page number The default value is 1. 92 CurrentPage int `q:"currentPage"` 93 } 94 95 type HostOptsBuilder interface { 96 ToHostsListQuery() (string, error) 97 } 98 99 func (opts HostOpts) ToHostsListQuery() (string, error) { 100 q, err := golangsdk.BuildQueryString(opts) 101 return q.String(), err 102 } 103 104 type CreateOptsBuilder interface { 105 ToClusterCreateMap() (map[string]interface{}, error) 106 } 107 108 func (opts CreateOpts) ToClusterCreateMap() (map[string]interface{}, error) { 109 return golangsdk.BuildRequestBody(opts, "") 110 } 111 112 func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 113 b, err := opts.ToClusterCreateMap() 114 if err != nil { 115 r.Err = err 116 return 117 } 118 119 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 120 _, r.Err = c.Post(createURL(c), b, &r.Body, reqOpt) 121 return 122 } 123 124 func Get(c *golangsdk.ServiceClient, id string) (r GetResult) { 125 _, r.Err = c.Get(resourceURL(c, id), &r.Body, &golangsdk.RequestOpts{ 126 OkCodes: []int{200}, 127 MoreHeaders: requestOpts.MoreHeaders, JSONBody: nil, 128 }) 129 return 130 } 131 132 // UpdateOpts is a struct which will be used to update a node group of the mrs cluster. 133 type UpdateOpts struct { 134 // Core parameters. 135 Parameters ResizeParameters `json:"parameters" required:"true"` 136 // Extension parameter. 137 PreviousValues PreviousValues `json:"previous_values,omitempty"` 138 } 139 140 // ResizeParameters is an object which is a node group resize operations. 141 type ResizeParameters struct { 142 // Number of nodes to be added or removed. 143 Instances string `json:"instances" required:"true"` 144 // When expanding or shrinking the capacity, the ID of the node is added or reduced, 145 // and the parameter value is fixed as 'node_orderadd'. 146 NodeId string `json:"node_id" required:"true"` 147 // scale_in: cluster scale-in 148 // scale_out: cluster scale-out 149 ScaleType string `json:"scale_type" required:"true"` 150 // Node group to be scaled out or in. 151 // If the value of node_group is core_node_default_group, the node group is a Core node group. 152 // If the value of node_group is task_node_default_group, the node group is a Task node group. 153 // If it is left blank, the default value core_node_default_group is used. 154 NodeGroup *string `json:"node_group,omitempty"` 155 // This parameter is valid only when a bootstrap action is configured during cluster creation and takes effect 156 // during scale-out. It indicates whether the bootstrap action specified during cluster creation is performed on 157 // nodes added during scale-out. The default value is false, indicating that the bootstrap action is performed. 158 SkipBootstrapScripts *bool `json:"skip_bootstrap_scripts,omitempty"` 159 // Whether to start components on the added nodes after cluster scale-out 160 // true: Do not start components after scale-out. 161 // false: Start components after scale-out. 162 ScaleWithoutStart *bool `json:"scale_without_start,omitempty"` 163 // ID list of Task nodes to be deleted during task node scale-in. 164 // This parameter does not take effect when scale_type is set to scale-out. 165 // If scale_type is set to scale-in and cannot be left blank, the system deletes the specified Task nodes. 166 // When scale_type is set to scale-in and server_ids is left blank, the system automatically deletes the Task nodes 167 // based on the system rules. 168 ServerIds []string `json:"server_ids,omitempty"` 169 // Task node specifications. 170 // When the number of Task nodes is 0, this parameter is used to specify Task node specifications. 171 // When the number of Task nodes is greater than 0, this parameter is unavailable. 172 TaskNodeInfo *TaskNodeInfo `json:"task_node_info,omitempty"` 173 } 174 175 // PreviousValues is an object which is a extension parameter. 176 type PreviousValues struct { 177 // Reserve the parameter for extending APIs. 178 // You do not need to set the parameter. 179 PlanId string `json:"plan_id,omitempty"` 180 } 181 182 // TaskNodeInfo is an object which is a informations of the task node group creation. 183 type TaskNodeInfo struct { 184 // Instance specifications of a Task node, for example, c3.4xlarge.2.linux.bigdata 185 NodeSize string `json:"node_size" required:"true"` 186 // Data disk storage type of the Task node, supporting SATA, SAS, and SSD currently 187 // SATA: Common I/O 188 // SAS: High I/O 189 // SSD: Ultra-high I/O 190 DataVolumeType string `json:"data_volume_type,omitempty"` 191 // Number of data disks of a Task node 192 // Value range: 1 to 10 193 DataVolumeCount int `json:"data_volume_count,omitempty"` 194 // Data disk storage space of a Task node 195 // Value range: 100 GB to 32,000 GB 196 DataVolumeSize int `json:"data_volume_size,omitempty"` 197 } 198 199 // UpdateOptsBuilder is an interface which to support request body build of the node group updation. 200 type UpdateOptsBuilder interface { 201 ToUpdateOptsMap() (map[string]interface{}, error) 202 } 203 204 // ToUpdateOptsMap is a method which to build a request body by the UpdateOpts. 205 func (opts UpdateOpts) ToUpdateOptsMap() (map[string]interface{}, error) { 206 return golangsdk.BuildRequestBody(opts, "") 207 } 208 209 // Update is a method to resize a node group. 210 func Update(client *golangsdk.ServiceClient, clusterId string, opts UpdateOptsBuilder) (r UpdateResult) { 211 reqBody, err := opts.ToUpdateOptsMap() 212 if err != nil { 213 r.Err = err 214 return 215 } 216 _, r.Err = client.Put(resourceURL(client, clusterId), reqBody, &r.Body, &golangsdk.RequestOpts{ 217 OkCodes: []int{200}, 218 }) 219 return 220 } 221 222 func Delete(c *golangsdk.ServiceClient, id string) (r DeleteResult) { 223 reqOpt := &golangsdk.RequestOpts{ 224 OkCodes: []int{204}, 225 MoreHeaders: requestOpts.MoreHeaders, 226 } 227 _, r.Err = c.Delete(deleteURL(c, id), reqOpt) 228 return 229 } 230 231 func ListHosts(client *golangsdk.ServiceClient, clusterId string, hostOpts HostOptsBuilder) (*HostListResult, error) { 232 url := listHostsURL(client, clusterId) 233 listResult := new(HostListResult) 234 235 if hostOpts != nil { 236 query, err := hostOpts.ToHostsListQuery() 237 if err != nil { 238 return nil, err 239 } 240 url += query 241 } 242 243 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}, MoreHeaders: map[string]string{"Content-Type": "application/json;charset=utf8"}} 244 _, err := client.Get(url, &listResult, reqOpt) 245 return listResult, err 246 247 }