Skip to content
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

Add algorithm checks in lb api calls #906

Merged
merged 1 commit into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ public static boolean isValidPort(final String p) {
}

public static boolean isValidAlgorithm(final String p) {
final String algo = p.toLowerCase();
final String algo = p;
return algo.equals("roundrobin") || algo.equals("leastconn") || algo.equals("source");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public class CreateLoadBalancerRuleCmd extends BaseAsyncCreateCmd /*implements L
/////////////////////////////////////////////////////

public String getAlgorithm() {
return algorithm;
return algorithm.toLowerCase();
}

public String getDescription() {
Expand Down Expand Up @@ -284,10 +284,14 @@ public void create() {
throw new InvalidParameterValueException(
"Only TCP protocol is supported because HAProxy can only do TCP.");
}
if (getAlgorithm() != null && !NetUtils.isValidAlgorithm(getAlgorithm())) {
throw new InvalidParameterValueException("Only source/roundrobin/leastconn are supported loadbalance algorithms.");
}
try {
final LoadBalancer result =
_lbService.createPublicLoadBalancerRule(getXid(), getName(), getDescription(), getSourcePortStart(), getSourcePortEnd(), getDefaultPortStart(),
getDefaultPortEnd(), getSourceIpAddressId(), getProtocol(), getAlgorithm(), getNetworkId(), getEntityOwnerId(), getOpenFirewall(), getLbProtocol(),
getDefaultPortEnd(), getSourceIpAddressId(), getProtocol(), getAlgorithm(), getNetworkId(), getEntityOwnerId(), getOpenFirewall(),
getLbProtocol(),
isDisplay(), getClientTimeout(), getServerTimeout());
this.setEntityId(result.getId());
this.setEntityUuid(result.getUuid());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.cloud.legacymodel.network.FirewallRule;
import com.cloud.legacymodel.network.LoadBalancer;
import com.cloud.legacymodel.user.Account;
import com.cloud.utils.net.NetUtils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -131,6 +132,9 @@ public Long getId() {

@Override
public void execute() {
if (algorithm != null && !NetUtils.isValidAlgorithm(algorithm)) {
throw new InvalidParameterValueException("Only source/roundrobin/leastconn are supported loadbalance algorithms.");
}
CallContext.current().setEventDetails("Load balancer ID: " + getId());
final LoadBalancer result = _lbService.updateLoadBalancerRule(this);
if (result != null) {
Expand Down