-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[New feature] Load balancer customization (haproxy-based) #4141
Changes from 75 commits
539ff56
8832d25
2f4d613
23cd6fd
f1ab741
c435afe
9383261
d19076e
67b43db
af6ab20
4a35ee2
c759f69
ffa0a9a
7c4da09
bfa64da
3d0e012
240acfc
7bff801
5e3f152
8f9f752
757be26
9c6fa85
7a1a2a9
0df8cc7
f52a609
ea66b36
e44c8f6
f50330c
156c4f4
1e7dd8f
68036f7
ece2b9b
30052e4
78eabc1
1584234
81125fc
3e089fe
fdb416e
2bd2c56
23fdf4b
d6c1251
9f34384
d7c48f4
edd8e0e
efcbcbf
61ba911
a3bbacb
ee75cab
e205c22
95f5695
4f92d50
dfc6cce
76b78ac
4f0b35d
fc623c1
3a58185
9a6e8d4
6237ba2
668a189
f98e575
c9e4b70
d7b51ec
95c1a9b
3d7bcda
26ccc8e
454b660
1ccff82
9d303ed
b3d4e72
6e2e86b
c1c07a9
9f1860c
39e7def
24c1206
2f07a1f
5690847
b59b4b8
fd8e6b2
0009b8d
4125854
444d37a
317ecbb
f5e5d0c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
package com.cloud.agent.api.to; | ||
|
||
import org.apache.cloudstack.network.lb.LoadBalancerConfig; | ||
|
||
public class LoadBalancerConfigTO { | ||
private String name; | ||
private String value; | ||
|
||
public LoadBalancerConfigTO(String name, String value) { | ||
this.name = name; | ||
this.value = value; | ||
} | ||
|
||
public LoadBalancerConfigTO(LoadBalancerConfig config) { | ||
this.name = config.getName(); | ||
this.value = config.getValue(); | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,8 @@ | |
import com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy; | ||
import com.cloud.utils.Pair; | ||
|
||
import org.apache.cloudstack.network.lb.LoadBalancerConfig; | ||
|
||
public class LoadBalancerTO { | ||
String uuid; | ||
String srcIp; | ||
|
@@ -50,6 +52,7 @@ public class LoadBalancerTO { | |
String srcIpNetmask; | ||
Long networkId; | ||
DestinationTO[] destinations; | ||
private LoadBalancerConfigTO[] lbConfigs; | ||
private StickinessPolicyTO[] stickinessPolicies; | ||
private HealthCheckPolicyTO[] healthCheckPolicies; | ||
private LbSslCert sslCert; /* XXX: Should this be SslCertTO? */ | ||
|
@@ -179,6 +182,22 @@ public boolean isInline() { | |
return inline; | ||
} | ||
|
||
public LoadBalancerConfigTO[] getLbConfigs() { | ||
return this.lbConfigs; | ||
} | ||
|
||
public void setLbConfigs(List<? extends LoadBalancerConfig> lbConfigs) { | ||
if (lbConfigs == null || lbConfigs.size() == 0) { | ||
this.lbConfigs = new LoadBalancerConfigTO[0]; | ||
return; | ||
} | ||
this.lbConfigs = new LoadBalancerConfigTO[lbConfigs.size()]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @weizhouapache advised changes to improve similar code, consider this as well. thanks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sureshanaparti this has been changed in commit as well |
||
int i = 0; | ||
for (LoadBalancerConfig lbConfig : lbConfigs) { | ||
this.lbConfigs[i++] = new LoadBalancerConfigTO(lbConfig); | ||
} | ||
} | ||
|
||
public StickinessPolicyTO[] getStickinessPolicies() { | ||
return stickinessPolicies; | ||
} | ||
|
@@ -207,6 +226,10 @@ public LbSslCert getSslCert() { | |
return this.sslCert; | ||
} | ||
|
||
public void setLbSslCert(LbSslCert sslCert) { | ||
this.sslCert = sslCert; | ||
} | ||
|
||
public String getSrcIpVlan() { | ||
return srcIpVlan; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
import org.apache.log4j.Logger; | ||
|
||
import org.apache.cloudstack.api.APICommand; | ||
import org.apache.cloudstack.api.ApiCommandJobType; | ||
import org.apache.cloudstack.api.ApiConstants; | ||
import org.apache.cloudstack.api.ApiErrorCode; | ||
import org.apache.cloudstack.api.BaseAsyncCmd; | ||
|
@@ -60,11 +61,17 @@ public class AssignCertToLoadBalancerCmd extends BaseAsyncCmd { | |
description = "the ID of the certificate") | ||
Long certId; | ||
|
||
@Parameter(name = ApiConstants.FORCED, type = CommandType.BOOLEAN, required = false, | ||
since = "4.15", | ||
description = "Force assign the certificate. If there is a certificate bound to the LB, it will be removed") | ||
private Boolean forced; | ||
|
||
|
||
@Override | ||
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, | ||
ResourceAllocationException, NetworkRuleConflictException { | ||
//To change body of implemented methods use File | Settings | File Templates. | ||
if (_lbService.assignCertToLoadBalancer(getLbRuleId(), getCertId())) { | ||
if (_lbService.assignCertToLoadBalancer(getLbRuleId(), getCertId(), isForced())) { | ||
SuccessResponse response = new SuccessResponse(getCommandName()); | ||
this.setResponseObject(response); | ||
} else { | ||
|
@@ -103,4 +110,32 @@ public Long getCertId() { | |
public Long getLbRuleId() { | ||
return lbRuleId; | ||
} | ||
|
||
public boolean isForced() { | ||
return (forced != null) ? forced : false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could use ...
return BooleanUtils.toBoolean(forced);
... |
||
} | ||
|
||
@Override | ||
public ApiCommandJobType getInstanceType() { | ||
return ApiCommandJobType.LoadBalancerRule; | ||
} | ||
|
||
@Override | ||
public Long getInstanceId() { | ||
return lbRuleId; | ||
} | ||
|
||
@Override | ||
public String getSyncObjType() { | ||
return BaseAsyncCmd.networkSyncObject; | ||
} | ||
|
||
@Override | ||
public Long getSyncObjId() { | ||
LoadBalancer lb = _entityMgr.findById(LoadBalancer.class, getLbRuleId()); | ||
if (lb == null) { | ||
return null; | ||
} | ||
return lb.getNetworkId(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could implement a ternary here. |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use
org.apache.commons.lang3.ArrayUtils
here:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GutoVeronezi
org.apache.commons.lang3.ArrayUtils
package don't have isEmpty method which accepts List object. I have to override it like:It imposes unnecessary conversion. What do you think?