mirror of https://github.com/apache/cloudstack.git
Make createLoadBalancer async
This commit is contained in:
parent
b829cde18f
commit
042c06fbb6
|
|
@ -23,11 +23,13 @@ import java.util.List;
|
|||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.BaseAsyncCmd;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.response.LoadBalancerResponse;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientAddressCapacityException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
|
|
@ -38,10 +40,11 @@ import com.cloud.network.IpAddress;
|
|||
import com.cloud.network.rules.LoadBalancer;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.UserContext;
|
||||
import com.cloud.utils.StringUtils;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
|
||||
@Implementation(description="Creates a load balancer rule", responseObject=LoadBalancerResponse.class)
|
||||
public class CreateLoadBalancerRuleCmd extends BaseCmd implements LoadBalancer {
|
||||
public class CreateLoadBalancerRuleCmd extends BaseAsyncCmd /*implements LoadBalancer */{
|
||||
public static final Logger s_logger = Logger.getLogger(CreateLoadBalancerRuleCmd.class.getName());
|
||||
|
||||
private static final String s_name = "createloadbalancerruleresponse";
|
||||
|
|
@ -81,12 +84,10 @@ public class CreateLoadBalancerRuleCmd extends BaseCmd implements LoadBalancer
|
|||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public String getAlgorithm() {
|
||||
return algorithm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
|
@ -180,53 +181,26 @@ public class CreateLoadBalancerRuleCmd extends BaseCmd implements LoadBalancer
|
|||
this.setResponseObject(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
throw new UnsupportedOperationException("not supported");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getXid() {
|
||||
// FIXME: Should fix this.
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSourceIpAddressId() {
|
||||
public Long getSourceIpAddressId() {
|
||||
return publicIpId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSourcePortStart() {
|
||||
return publicPort.intValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSourcePortEnd() {
|
||||
return publicPort.intValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProtocol() {
|
||||
return NetUtils.TCP_PROTO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Purpose getPurpose() {
|
||||
return Purpose.LoadBalancing;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public State getState() {
|
||||
throw new UnsupportedOperationException("not supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getNetworkId() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getAccountId() {
|
||||
if (publicIpId != null)
|
||||
return _networkService.getIp(getPublicIpId()).getAccountId();
|
||||
|
|
@ -247,7 +221,6 @@ public class CreateLoadBalancerRuleCmd extends BaseCmd implements LoadBalancer
|
|||
return Account.ACCOUNT_ID_SYSTEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDomainId() {
|
||||
if (publicIpId != null)
|
||||
return _networkService.getIp(getPublicIpId()).getDomainId();
|
||||
|
|
@ -257,12 +230,10 @@ public class CreateLoadBalancerRuleCmd extends BaseCmd implements LoadBalancer
|
|||
return UserContext.current().getCaller().getDomainId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDefaultPortStart() {
|
||||
return privatePort.intValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDefaultPortEnd() {
|
||||
return privatePort.intValue();
|
||||
}
|
||||
|
|
@ -283,5 +254,21 @@ public class CreateLoadBalancerRuleCmd extends BaseCmd implements LoadBalancer
|
|||
public void setPublicIpId(Long publicIpId) {
|
||||
this.publicIpId = publicIpId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventType() {
|
||||
return EventTypes.EVENT_LOAD_BALANCER_CREATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventDescription() {
|
||||
return "creating load balancer: " + getName() + " account: " + getAccountName();
|
||||
|
||||
}
|
||||
|
||||
public String getXid() {
|
||||
/*FIXME*/
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package com.cloud.network.lb;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.api.commands.CreateLoadBalancerRuleCmd;
|
||||
import com.cloud.api.commands.ListLoadBalancerRuleInstancesCmd;
|
||||
import com.cloud.api.commands.ListLoadBalancerRulesCmd;
|
||||
import com.cloud.api.commands.UpdateLoadBalancerRuleCmd;
|
||||
|
|
@ -33,7 +34,7 @@ public interface LoadBalancingRulesService {
|
|||
* @param cmd the command specifying the ip address, public port, protocol, private port, and algorithm
|
||||
* @return the newly created LoadBalancerVO if successful, null otherwise
|
||||
*/
|
||||
LoadBalancer createLoadBalancerRule(LoadBalancer lb) throws NetworkRuleConflictException;
|
||||
LoadBalancer createLoadBalancerRule(CreateLoadBalancerRuleCmd lb) throws NetworkRuleConflictException;
|
||||
|
||||
LoadBalancer updateLoadBalancerRule(UpdateLoadBalancerRuleCmd cmd);
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package com.cloud.network.lb;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.api.commands.CreateLoadBalancerRuleCmd;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
|
|
@ -37,6 +38,6 @@ public interface ElasticLoadBalancerManager {
|
|||
List<? extends FirewallRule> rules)
|
||||
throws ResourceUnavailableException;
|
||||
|
||||
public void handleCreateLoadBalancerRule(LoadBalancer lb, Account caller);
|
||||
public void handleCreateLoadBalancerRule(CreateLoadBalancerRuleCmd lb, Account caller);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import com.cloud.agent.api.routing.NetworkElementCommand;
|
|||
import com.cloud.agent.api.to.IpAddressTO;
|
||||
import com.cloud.agent.api.to.LoadBalancerTO;
|
||||
import com.cloud.agent.manager.Commands;
|
||||
import com.cloud.api.commands.CreateLoadBalancerRuleCmd;
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.dc.DataCenter;
|
||||
|
|
@ -443,7 +444,7 @@ public class ElasticLoadBalancerManagerImpl implements
|
|||
|
||||
@Override
|
||||
@DB
|
||||
public void handleCreateLoadBalancerRule( LoadBalancer lb, Account account) {
|
||||
public void handleCreateLoadBalancerRule( CreateLoadBalancerRuleCmd lb, Account account) {
|
||||
|
||||
long ipId = lb.getSourceIpAddressId();
|
||||
IPAddressVO ipAddr = _ipAddressDao.findById(ipId);
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import javax.naming.ConfigurationException;
|
|||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.commands.CreateLoadBalancerRuleCmd;
|
||||
import com.cloud.api.commands.ListLoadBalancerRuleInstancesCmd;
|
||||
import com.cloud.api.commands.ListLoadBalancerRulesCmd;
|
||||
import com.cloud.api.commands.UpdateLoadBalancerRuleCmd;
|
||||
|
|
@ -349,7 +350,7 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesManager,
|
|||
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_LOAD_BALANCER_CREATE, eventDescription = "creating load balancer")
|
||||
public LoadBalancer createLoadBalancerRule(LoadBalancer lb) throws NetworkRuleConflictException {
|
||||
public LoadBalancer createLoadBalancerRule(CreateLoadBalancerRuleCmd lb) throws NetworkRuleConflictException {
|
||||
UserContext caller = UserContext.current();
|
||||
|
||||
long ipId = lb.getSourceIpAddressId();
|
||||
|
|
|
|||
Loading…
Reference in New Issue