yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/aliyun/loadbalancerudplistener.go (about) 1 // Copyright 2019 Yunion 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package aliyun 16 17 import ( 18 "context" 19 "fmt" 20 21 "yunion.io/x/jsonutils" 22 23 api "yunion.io/x/cloudmux/pkg/apis/compute" 24 "yunion.io/x/cloudmux/pkg/cloudprovider" 25 "yunion.io/x/cloudmux/pkg/multicloud" 26 ) 27 28 type SLoadbalancerUDPListener struct { 29 multicloud.SResourceBase 30 multicloud.SLoadbalancerRedirectBase 31 AliyunTags 32 lb *SLoadbalancer 33 34 ListenerPort int // 负载均衡实例前端使用的端口。 35 BackendServerPort int // 负载均衡实例后端使用的端口。 36 Bandwidth int // 监听的带宽峰值。 37 Status string // 当前监听的状态,取值:starting | running | configuring | stopping | stopped 38 Description string 39 40 Scheduler string // 调度算法 41 VServerGroupId string // 绑定的服务器组ID。 42 MasterSlaveServerGroupId string // 绑定的主备服务器组ID。 43 AclStatus string // 是否开启访问控制功能。取值:on | off(默认值) 44 45 AclType string // 访问控制类型: 46 47 AclId string // 监听绑定的访问策略组ID。当AclStatus参数的值为on时,该参数必选。 48 49 HealthCheck string // 是否开启健康检查。 50 HealthyThreshold int // 健康检查阈值。 51 UnhealthyThreshold int // 不健康检查阈值。 52 HealthCheckConnectTimeout int // 每次健康检查响应的最大超时间,单位为秒。 53 HealthCheckInterval int // 健康检查的时间间隔,单位为秒。 54 HealthCheckConnectPort int // 健康检查的端口。 55 56 HealthCheckExp string // UDP监听健康检查的响应串 57 HealthCheckReq string // UDP监听健康检查的请求串 58 } 59 60 func (listener *SLoadbalancerUDPListener) GetName() string { 61 if len(listener.Description) == 0 { 62 listener.Refresh() 63 } 64 if len(listener.Description) > 0 { 65 return listener.Description 66 } 67 return fmt.Sprintf("UDP:%d", listener.ListenerPort) 68 } 69 70 func (listerner *SLoadbalancerUDPListener) GetId() string { 71 return fmt.Sprintf("%s/%d", listerner.lb.LoadBalancerId, listerner.ListenerPort) 72 } 73 74 func (listerner *SLoadbalancerUDPListener) GetGlobalId() string { 75 return listerner.GetId() 76 } 77 78 func (listerner *SLoadbalancerUDPListener) GetStatus() string { 79 switch listerner.Status { 80 case "starting", "running": 81 return api.LB_STATUS_ENABLED 82 case "configuring", "stopping", "stopped": 83 return api.LB_STATUS_DISABLED 84 default: 85 return api.LB_STATUS_UNKNOWN 86 } 87 } 88 89 func (listerner *SLoadbalancerUDPListener) GetEgressMbps() int { 90 if listerner.Bandwidth < 1 { 91 return 0 92 } 93 return listerner.Bandwidth 94 } 95 96 func (listerner *SLoadbalancerUDPListener) IsEmulated() bool { 97 return false 98 } 99 100 func (listerner *SLoadbalancerUDPListener) Refresh() error { 101 lis, err := listerner.lb.region.GetLoadbalancerUDPListener(listerner.lb.LoadBalancerId, listerner.ListenerPort) 102 if err != nil { 103 return err 104 } 105 return jsonutils.Update(listerner, lis) 106 } 107 108 func (listerner *SLoadbalancerUDPListener) GetListenerType() string { 109 return "udp" 110 } 111 112 func (listerner *SLoadbalancerUDPListener) GetListenerPort() int { 113 return listerner.ListenerPort 114 } 115 116 func (listerner *SLoadbalancerUDPListener) GetBackendGroupId() string { 117 if len(listerner.VServerGroupId) > 0 { 118 return listerner.VServerGroupId 119 } 120 return listerner.MasterSlaveServerGroupId 121 } 122 123 func (listerner *SLoadbalancerUDPListener) GetBackendServerPort() int { 124 return listerner.BackendServerPort 125 } 126 127 func (listerner *SLoadbalancerUDPListener) GetScheduler() string { 128 return listerner.Scheduler 129 } 130 131 func (listerner *SLoadbalancerUDPListener) GetAclStatus() string { 132 return listerner.AclStatus 133 } 134 135 func (listerner *SLoadbalancerUDPListener) GetAclType() string { 136 return listerner.AclType 137 } 138 139 func (listerner *SLoadbalancerUDPListener) GetAclId() string { 140 return listerner.AclId 141 } 142 143 func (listerner *SLoadbalancerUDPListener) GetHealthCheck() string { 144 return listerner.HealthCheck 145 } 146 147 func (listerner *SLoadbalancerUDPListener) GetHealthCheckType() string { 148 return api.LB_HEALTH_CHECK_UDP 149 } 150 151 func (listerner *SLoadbalancerUDPListener) GetHealthCheckDomain() string { 152 return "" 153 } 154 155 func (listerner *SLoadbalancerUDPListener) GetHealthCheckURI() string { 156 return "" 157 } 158 159 func (listerner *SLoadbalancerUDPListener) GetHealthCheckCode() string { 160 return "" 161 } 162 163 func (listerner *SLoadbalancerUDPListener) GetHealthCheckRise() int { 164 return listerner.HealthyThreshold 165 } 166 167 func (listerner *SLoadbalancerUDPListener) GetHealthCheckFail() int { 168 return listerner.UnhealthyThreshold 169 } 170 171 func (listerner *SLoadbalancerUDPListener) GetHealthCheckTimeout() int { 172 return listerner.HealthCheckConnectTimeout 173 } 174 175 func (listerner *SLoadbalancerUDPListener) GetHealthCheckInterval() int { 176 return listerner.HealthCheckInterval 177 } 178 179 func (listerner *SLoadbalancerUDPListener) GetHealthCheckReq() string { 180 return listerner.HealthCheckReq 181 } 182 183 func (listerner *SLoadbalancerUDPListener) GetHealthCheckExp() string { 184 return listerner.HealthCheckExp 185 } 186 187 func (listerner *SLoadbalancerUDPListener) GetStickySession() string { 188 return "" 189 } 190 191 func (listerner *SLoadbalancerUDPListener) GetStickySessionType() string { 192 return "" 193 } 194 195 func (listerner *SLoadbalancerUDPListener) GetStickySessionCookie() string { 196 return "" 197 } 198 199 func (listerner *SLoadbalancerUDPListener) GetStickySessionCookieTimeout() int { 200 return 0 201 } 202 203 func (listerner *SLoadbalancerUDPListener) XForwardedForEnabled() bool { 204 return false 205 } 206 207 func (listerner *SLoadbalancerUDPListener) GzipEnabled() bool { 208 return false 209 } 210 211 func (listerner *SLoadbalancerUDPListener) GetCertificateId() string { 212 return "" 213 } 214 215 func (listerner *SLoadbalancerUDPListener) GetTLSCipherPolicy() string { 216 return "" 217 } 218 219 func (listerner *SLoadbalancerUDPListener) HTTP2Enabled() bool { 220 return false 221 } 222 223 func (listerner *SLoadbalancerUDPListener) GetILoadbalancerListenerRules() ([]cloudprovider.ICloudLoadbalancerListenerRule, error) { 224 return []cloudprovider.ICloudLoadbalancerListenerRule{}, nil 225 } 226 227 func (region *SRegion) GetLoadbalancerUDPListener(loadbalancerId string, listenerPort int) (*SLoadbalancerUDPListener, error) { 228 params := map[string]string{} 229 params["RegionId"] = region.RegionId 230 params["LoadBalancerId"] = loadbalancerId 231 params["ListenerPort"] = fmt.Sprintf("%d", listenerPort) 232 body, err := region.lbRequest("DescribeLoadBalancerUDPListenerAttribute", params) 233 if err != nil { 234 return nil, err 235 } 236 listener := SLoadbalancerUDPListener{} 237 return &listener, body.Unmarshal(&listener) 238 } 239 240 func (region *SRegion) CreateLoadbalancerUDPListener(lb *SLoadbalancer, listener *cloudprovider.SLoadbalancerListener) (cloudprovider.ICloudLoadbalancerListener, error) { 241 params := region.constructBaseCreateListenerParams(lb, listener) 242 _, err := region.lbRequest("CreateLoadBalancerUDPListener", params) 243 if err != nil { 244 return nil, err 245 } 246 iListener, err := region.GetLoadbalancerUDPListener(lb.LoadBalancerId, listener.ListenerPort) 247 if err != nil { 248 return nil, err 249 } 250 iListener.lb = lb 251 return iListener, nil 252 } 253 254 func (listerner *SLoadbalancerUDPListener) Delete(ctx context.Context) error { 255 return listerner.lb.region.DeleteLoadbalancerListener(listerner.lb.LoadBalancerId, listerner.ListenerPort) 256 } 257 258 func (listerner *SLoadbalancerUDPListener) CreateILoadBalancerListenerRule(rule *cloudprovider.SLoadbalancerListenerRule) (cloudprovider.ICloudLoadbalancerListenerRule, error) { 259 return nil, cloudprovider.ErrNotSupported 260 } 261 262 func (listerner *SLoadbalancerUDPListener) GetILoadBalancerListenerRuleById(ruleId string) (cloudprovider.ICloudLoadbalancerListenerRule, error) { 263 return nil, cloudprovider.ErrNotSupported 264 } 265 266 func (listerner *SLoadbalancerUDPListener) Start() error { 267 return listerner.lb.region.startListener(listerner.ListenerPort, listerner.lb.LoadBalancerId) 268 } 269 270 func (listerner *SLoadbalancerUDPListener) Stop() error { 271 return listerner.lb.region.stopListener(listerner.ListenerPort, listerner.lb.LoadBalancerId) 272 } 273 274 func (region *SRegion) SyncLoadbalancerUDPListener(lb *SLoadbalancer, listener *cloudprovider.SLoadbalancerListener) error { 275 params := region.constructBaseCreateListenerParams(lb, listener) 276 _, err := region.lbRequest("SetLoadBalancerUDPListenerAttribute", params) 277 return err 278 } 279 280 func (listerner *SLoadbalancerUDPListener) Sync(ctx context.Context, lblis *cloudprovider.SLoadbalancerListener) error { 281 return listerner.lb.region.SyncLoadbalancerUDPListener(listerner.lb, lblis) 282 } 283 284 func (listerner *SLoadbalancerUDPListener) GetProjectId() string { 285 return listerner.lb.GetProjectId() 286 } 287 288 func (listerner *SLoadbalancerUDPListener) GetClientIdleTimeout() int { 289 return 0 290 } 291 292 func (listerner *SLoadbalancerUDPListener) GetBackendConnectTimeout() int { 293 return 0 294 }