mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
bug 7467: release IP address works now.
status 7467: resolved fixed Fixed all load balancer commands to work with the latest networking code
This commit is contained in:
parent
9c8d8d1dc4
commit
88d6ff2136
@ -19,8 +19,7 @@ package com.cloud.agent.api.routing;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.cloud.network.rules.LoadBalancer;
|
import com.cloud.network.lb.LoadBalancingRule.LbDestination;
|
||||||
import com.cloud.network.rules.LoadBalancer.Destination;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LoadBalancerConfigCommand sends the load balancer configuration
|
* LoadBalancerConfigCommand sends the load balancer configuration
|
||||||
@ -35,7 +34,7 @@ public class LoadBalancerConfigCommand extends RoutingCommand {
|
|||||||
boolean alreadyAdded;
|
boolean alreadyAdded;
|
||||||
DestinationTO[] destinations;
|
DestinationTO[] destinations;
|
||||||
|
|
||||||
public LoadBalancerConfigCommand(String srcIp, int srcPort, String protocol, String algorithm, boolean revoked, boolean alreadyAdded, List<? extends Destination> destinations) {
|
public LoadBalancerConfigCommand(String srcIp, int srcPort, String protocol, String algorithm, boolean revoked, boolean alreadyAdded, List<LbDestination> destinations) {
|
||||||
this.srcIp = srcIp;
|
this.srcIp = srcIp;
|
||||||
this.srcPort = srcPort;
|
this.srcPort = srcPort;
|
||||||
this.protocol = protocol;
|
this.protocol = protocol;
|
||||||
@ -44,8 +43,8 @@ public class LoadBalancerConfigCommand extends RoutingCommand {
|
|||||||
this.alreadyAdded = alreadyAdded;
|
this.alreadyAdded = alreadyAdded;
|
||||||
this.destinations = new DestinationTO[destinations.size()];
|
this.destinations = new DestinationTO[destinations.size()];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (Destination destination : destinations) {
|
for (LbDestination destination : destinations) {
|
||||||
this.destinations[i++] = new DestinationTO(destination.getIpAddress(), destination.getDestinationPortStart(), destination.getRevoked(), destination.getAlreadyAdded());
|
this.destinations[i++] = new DestinationTO(destination.getIpAddress(), destination.getDestinationPortStart(), destination.isRevoked(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.cloud.api.commands;
|
package com.cloud.api.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
@ -30,9 +29,9 @@ import com.cloud.api.Parameter;
|
|||||||
import com.cloud.api.ServerApiException;
|
import com.cloud.api.ServerApiException;
|
||||||
import com.cloud.api.response.SuccessResponse;
|
import com.cloud.api.response.SuccessResponse;
|
||||||
import com.cloud.event.EventTypes;
|
import com.cloud.event.EventTypes;
|
||||||
import com.cloud.exception.InvalidParameterValueException;
|
|
||||||
import com.cloud.network.rules.LoadBalancer;
|
import com.cloud.network.rules.LoadBalancer;
|
||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
|
import com.cloud.utils.StringUtils;
|
||||||
|
|
||||||
@Implementation(description="Assigns virtual machine or a list of virtual machines to a load balancer rule.", responseObject=SuccessResponse.class)
|
@Implementation(description="Assigns virtual machine or a list of virtual machines to a load balancer rule.", responseObject=SuccessResponse.class)
|
||||||
public class AssignToLoadBalancerRuleCmd extends BaseAsyncCmd {
|
public class AssignToLoadBalancerRuleCmd extends BaseAsyncCmd {
|
||||||
@ -47,9 +46,6 @@ public class AssignToLoadBalancerRuleCmd extends BaseAsyncCmd {
|
|||||||
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the load balancer rule")
|
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the load balancer rule")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Parameter(name=ApiConstants.VIRTUAL_MACHINE_ID, type=CommandType.LONG, required=false, description="the ID of the virtual machine that is being assigned to the load balancer rule")
|
|
||||||
private Long virtualMachineId;
|
|
||||||
|
|
||||||
@Parameter(name=ApiConstants.VIRTUAL_MACHINE_IDS, type=CommandType.LIST, collectionType=CommandType.LONG, required=false, description="the list of IDs of the virtual machine that are being assigned to the load balancer rule(i.e. virtualMachineIds=1,2,3)")
|
@Parameter(name=ApiConstants.VIRTUAL_MACHINE_IDS, type=CommandType.LIST, collectionType=CommandType.LONG, required=false, description="the list of IDs of the virtual machine that are being assigned to the load balancer rule(i.e. virtualMachineIds=1,2,3)")
|
||||||
private List<Long> virtualMachineIds;
|
private List<Long> virtualMachineIds;
|
||||||
|
|
||||||
@ -61,10 +57,6 @@ public class AssignToLoadBalancerRuleCmd extends BaseAsyncCmd {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getVirtualMachineId() {
|
|
||||||
return virtualMachineId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Long> getVirtualMachineIds() {
|
public List<Long> getVirtualMachineIds() {
|
||||||
return virtualMachineIds;
|
return virtualMachineIds;
|
||||||
}
|
}
|
||||||
@ -94,21 +86,11 @@ public class AssignToLoadBalancerRuleCmd extends BaseAsyncCmd {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getEventDescription() {
|
public String getEventDescription() {
|
||||||
return "applying port forwarding service for vm with id: " + getVirtualMachineId();
|
return "applying instances for load balancer: " + getLoadBalancerId() + " (ids: " + StringUtils.join(getVirtualMachineIds(), ",") + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(){
|
public void execute(){
|
||||||
if (virtualMachineIds == null && virtualMachineId == null) {
|
|
||||||
throw new InvalidParameterValueException("Must specify virtual machine id");
|
|
||||||
}
|
|
||||||
if (virtualMachineIds == null) {
|
|
||||||
virtualMachineIds = new ArrayList<Long>();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (virtualMachineId != null) {
|
|
||||||
virtualMachineIds.add(virtualMachineId);
|
|
||||||
}
|
|
||||||
boolean result = _lbService.assignToLoadBalancer(getLoadBalancerId(), virtualMachineIds);
|
boolean result = _lbService.assignToLoadBalancer(getLoadBalancerId(), virtualMachineIds);
|
||||||
if (result) {
|
if (result) {
|
||||||
SuccessResponse response = new SuccessResponse(getCommandName());
|
SuccessResponse response = new SuccessResponse(getCommandName());
|
||||||
|
|||||||
@ -18,8 +18,6 @@
|
|||||||
|
|
||||||
package com.cloud.api.commands;
|
package com.cloud.api.commands;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.api.ApiConstants;
|
import com.cloud.api.ApiConstants;
|
||||||
@ -186,9 +184,4 @@ public class CreateLoadBalancerRuleCmd extends BaseCmd implements LoadBalancer
|
|||||||
return Integer.parseInt(privatePort);
|
return Integer.parseInt(privatePort);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<? extends Destination> getDestinations() {
|
|
||||||
throw new UnsupportedOperationException("not supported");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.cloud.api.commands;
|
package com.cloud.api.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
@ -30,7 +29,6 @@ import com.cloud.api.Parameter;
|
|||||||
import com.cloud.api.ServerApiException;
|
import com.cloud.api.ServerApiException;
|
||||||
import com.cloud.api.response.SuccessResponse;
|
import com.cloud.api.response.SuccessResponse;
|
||||||
import com.cloud.event.EventTypes;
|
import com.cloud.event.EventTypes;
|
||||||
import com.cloud.exception.InvalidParameterValueException;
|
|
||||||
import com.cloud.network.rules.LoadBalancer;
|
import com.cloud.network.rules.LoadBalancer;
|
||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
import com.cloud.utils.StringUtils;
|
import com.cloud.utils.StringUtils;
|
||||||
@ -48,10 +46,7 @@ public class RemoveFromLoadBalancerRuleCmd extends BaseAsyncCmd {
|
|||||||
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="The ID of the load balancer rule")
|
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="The ID of the load balancer rule")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Parameter(name=ApiConstants.VIRTUAL_MACHINE_ID, type=CommandType.LONG, description="the ID of the virtual machine that is being removed from the load balancer rule")
|
@Parameter(name=ApiConstants.VIRTUAL_MACHINE_IDS, type=CommandType.LIST, required = true, collectionType=CommandType.LONG, description="the list of IDs of the virtual machines that are being removed from the load balancer rule (i.e. virtualMachineIds=1,2,3)")
|
||||||
private Long virtualMachineId;
|
|
||||||
|
|
||||||
@Parameter(name=ApiConstants.VIRTUAL_MACHINE_IDS, type=CommandType.LIST, collectionType=CommandType.LONG, description="the list of IDs of the virtual machines that are being removed from the load balancer rule (i.e. virtualMachineIds=1,2,3)")
|
|
||||||
private List<Long> virtualMachineIds;
|
private List<Long> virtualMachineIds;
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
@ -62,10 +57,6 @@ public class RemoveFromLoadBalancerRuleCmd extends BaseAsyncCmd {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getVirtualMachineId() {
|
|
||||||
return virtualMachineId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Long> getVirtualMachineIds() {
|
public List<Long> getVirtualMachineIds() {
|
||||||
return virtualMachineIds;
|
return virtualMachineIds;
|
||||||
}
|
}
|
||||||
@ -95,28 +86,11 @@ public class RemoveFromLoadBalancerRuleCmd extends BaseAsyncCmd {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getEventDescription() {
|
public String getEventDescription() {
|
||||||
List<Long> vmIds = getVirtualMachineIds();
|
return "removing instances from load balancer: " + getId() + " (ids: " + StringUtils.join(getVirtualMachineIds(), ",") + ")";
|
||||||
if ((vmIds == null) || vmIds.isEmpty()) {
|
|
||||||
vmIds = new ArrayList<Long>();
|
|
||||||
vmIds.add(getVirtualMachineId());
|
|
||||||
}
|
|
||||||
|
|
||||||
return "removing instances from load balancer: " + getId() + " (ids: " + StringUtils.join(vmIds, ",") + ")";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(){
|
public void execute(){
|
||||||
if (virtualMachineIds == null && virtualMachineId == null) {
|
|
||||||
throw new InvalidParameterValueException("Must specify virtual machine id");
|
|
||||||
}
|
|
||||||
if (virtualMachineIds == null) {
|
|
||||||
virtualMachineIds = new ArrayList<Long>();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (virtualMachineId != null) {
|
|
||||||
virtualMachineIds.add(virtualMachineId);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean result = _lbService.removeFromLoadBalancer(id, virtualMachineIds);
|
boolean result = _lbService.removeFromLoadBalancer(id, virtualMachineIds);
|
||||||
if (result) {
|
if (result) {
|
||||||
SuccessResponse response = new SuccessResponse(getCommandName());
|
SuccessResponse response = new SuccessResponse(getCommandName());
|
||||||
|
|||||||
@ -51,8 +51,8 @@ public class UpdateLoadBalancerRuleCmd extends BaseAsyncCmd {
|
|||||||
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="the name of the load balancer rule")
|
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="the name of the load balancer rule")
|
||||||
private String loadBalancerName;
|
private String loadBalancerName;
|
||||||
|
|
||||||
@Parameter(name=ApiConstants.PRIVATE_PORT, type=CommandType.STRING, description="the private port of the private ip address/virtual machine where the network traffic will be load balanced to")
|
// @Parameter(name=ApiConstants.PRIVATE_PORT, type=CommandType.STRING, description="the private port of the private ip address/virtual machine where the network traffic will be load balanced to")
|
||||||
private String privatePort;
|
// private String privatePort;
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
/////////////////// Accessors ///////////////////////
|
/////////////////// Accessors ///////////////////////
|
||||||
@ -74,9 +74,9 @@ public class UpdateLoadBalancerRuleCmd extends BaseAsyncCmd {
|
|||||||
return loadBalancerName;
|
return loadBalancerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPrivatePort() {
|
// public String getPrivatePort() {
|
||||||
return privatePort;
|
// return privatePort;
|
||||||
}
|
// }
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
/////////////// API Implementation///////////////////
|
/////////////// API Implementation///////////////////
|
||||||
|
|||||||
139
api/src/com/cloud/network/lb/LoadBalancingRule.java
Normal file
139
api/src/com/cloud/network/lb/LoadBalancingRule.java
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
package com.cloud.network.lb;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.cloud.network.rules.FirewallRule;
|
||||||
|
import com.cloud.network.rules.LoadBalancer;
|
||||||
|
import com.cloud.utils.net.Ip;
|
||||||
|
|
||||||
|
public class LoadBalancingRule implements FirewallRule, LoadBalancer{
|
||||||
|
private LoadBalancer lb;
|
||||||
|
private List<LbDestination> destinations;
|
||||||
|
|
||||||
|
public LoadBalancingRule(LoadBalancer lb, List<LbDestination> destinations) {
|
||||||
|
this.lb = lb;
|
||||||
|
this.destinations = destinations;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getId() {
|
||||||
|
return lb.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getAccountId() {
|
||||||
|
return lb.getAccountId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getDomainId() {
|
||||||
|
return lb.getDomainId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return lb.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return lb.getDescription();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDefaultPortStart() {
|
||||||
|
return lb.getDefaultPortStart();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getDefaultPortEnd() {
|
||||||
|
return lb.getDefaultPortEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getAlgorithm() {
|
||||||
|
return lb.getAlgorithm();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getXid() {
|
||||||
|
return lb.getXid();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Ip getSourceIpAddress() {
|
||||||
|
return lb.getSourceIpAddress();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSourcePortStart() {
|
||||||
|
return lb.getSourcePortStart();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSourcePortEnd() {
|
||||||
|
return lb.getSourcePortEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getProtocol() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Purpose getPurpose() {
|
||||||
|
return Purpose.LoadBalancing;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public State getState() {
|
||||||
|
return lb.getState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getNetworkId() {
|
||||||
|
return lb.getNetworkId();
|
||||||
|
}
|
||||||
|
|
||||||
|
public LoadBalancer getLb() {
|
||||||
|
return lb;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<LbDestination> getDestinations() {
|
||||||
|
return destinations;
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface Destination {
|
||||||
|
String getIpAddress();
|
||||||
|
int getDestinationPortStart();
|
||||||
|
int getDestinationPortEnd();
|
||||||
|
boolean isRevoked();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class LbDestination implements Destination {
|
||||||
|
private int portStart;
|
||||||
|
private int portEnd;
|
||||||
|
private String ip;
|
||||||
|
boolean revoked;
|
||||||
|
|
||||||
|
public LbDestination(int portStart, int portEnd, String ip, boolean revoked) {
|
||||||
|
this.portStart = portStart;
|
||||||
|
this.portEnd = portEnd;
|
||||||
|
this.ip = ip;
|
||||||
|
this.revoked = revoked;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIpAddress() {
|
||||||
|
return ip;
|
||||||
|
}
|
||||||
|
public int getDestinationPortStart() {
|
||||||
|
return portStart;
|
||||||
|
}
|
||||||
|
public int getDestinationPortEnd() {
|
||||||
|
return portEnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRevoked() {
|
||||||
|
return revoked;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -46,7 +46,7 @@ public interface LoadBalancingRulesService {
|
|||||||
|
|
||||||
boolean removeFromLoadBalancer(long lbRuleId, List<Long> vmIds);
|
boolean removeFromLoadBalancer(long lbRuleId, List<Long> vmIds);
|
||||||
|
|
||||||
boolean applyLoadBalancerConfig(long id) throws ResourceUnavailableException;
|
boolean applyLoadBalancerConfig(long lbRuleId) throws ResourceUnavailableException;
|
||||||
/**
|
/**
|
||||||
* List instances that have either been applied to a load balancer or are eligible to be assigned to a load balancer.
|
* List instances that have either been applied to a load balancer or are eligible to be assigned to a load balancer.
|
||||||
* @param cmd
|
* @param cmd
|
||||||
|
|||||||
@ -17,13 +17,13 @@
|
|||||||
*/
|
*/
|
||||||
package com.cloud.network.rules;
|
package com.cloud.network.rules;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Definition for a LoadBalancer
|
* Definition for a LoadBalancer
|
||||||
*/
|
*/
|
||||||
public interface LoadBalancer extends FirewallRule {
|
public interface LoadBalancer extends FirewallRule {
|
||||||
|
|
||||||
|
|
||||||
String getName();
|
String getName();
|
||||||
|
|
||||||
String getDescription();
|
String getDescription();
|
||||||
@ -34,13 +34,4 @@ public interface LoadBalancer extends FirewallRule {
|
|||||||
|
|
||||||
String getAlgorithm();
|
String getAlgorithm();
|
||||||
|
|
||||||
List<? extends Destination> getDestinations();
|
|
||||||
|
|
||||||
public interface Destination {
|
|
||||||
String getIpAddress();
|
|
||||||
int getDestinationPortStart();
|
|
||||||
int getDestinationPortEnd();
|
|
||||||
boolean getRevoked();
|
|
||||||
boolean getAlreadyAdded();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -115,11 +115,11 @@ listIpForwardingRules=com.cloud.api.commands.ListIpForwardingRulesCmd;15
|
|||||||
#### load balancer commands
|
#### load balancer commands
|
||||||
createLoadBalancerRule=com.cloud.api.commands.CreateLoadBalancerRuleCmd;15
|
createLoadBalancerRule=com.cloud.api.commands.CreateLoadBalancerRuleCmd;15
|
||||||
deleteLoadBalancerRule=com.cloud.api.commands.DeleteLoadBalancerRuleCmd;15
|
deleteLoadBalancerRule=com.cloud.api.commands.DeleteLoadBalancerRuleCmd;15
|
||||||
updateLoadBalancerRule=com.cloud.api.commands.UpdateLoadBalancerRuleCmd;15
|
|
||||||
removeFromLoadBalancerRule=com.cloud.api.commands.RemoveFromLoadBalancerRuleCmd;15
|
removeFromLoadBalancerRule=com.cloud.api.commands.RemoveFromLoadBalancerRuleCmd;15
|
||||||
assignToLoadBalancerRule=com.cloud.api.commands.AssignToLoadBalancerRuleCmd;15
|
assignToLoadBalancerRule=com.cloud.api.commands.AssignToLoadBalancerRuleCmd;15
|
||||||
listLoadBalancerRules=com.cloud.api.commands.ListLoadBalancerRulesCmd;15
|
listLoadBalancerRules=com.cloud.api.commands.ListLoadBalancerRulesCmd;15
|
||||||
listLoadBalancerRuleInstances=com.cloud.api.commands.ListLoadBalancerRuleInstancesCmd;15
|
listLoadBalancerRuleInstances=com.cloud.api.commands.ListLoadBalancerRuleInstancesCmd;15
|
||||||
|
updateLoadBalancerRule=com.cloud.api.commands.UpdateLoadBalancerRuleCmd;15
|
||||||
|
|
||||||
#### router commands
|
#### router commands
|
||||||
startRouter=com.cloud.api.commands.StartRouterCmd;3
|
startRouter=com.cloud.api.commands.StartRouterCmd;3
|
||||||
|
|||||||
@ -39,8 +39,8 @@ public class LoadBalancerVMMapVO {
|
|||||||
@Column(name="instance_id")
|
@Column(name="instance_id")
|
||||||
private long instanceId;
|
private long instanceId;
|
||||||
|
|
||||||
@Column(name="pending")
|
@Column(name="revoke")
|
||||||
private boolean pending = false;
|
private boolean revoke = false;
|
||||||
|
|
||||||
public LoadBalancerVMMapVO() { }
|
public LoadBalancerVMMapVO() { }
|
||||||
|
|
||||||
@ -49,10 +49,10 @@ public class LoadBalancerVMMapVO {
|
|||||||
this.instanceId = instanceId;
|
this.instanceId = instanceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LoadBalancerVMMapVO(long loadBalancerId, long instanceId, boolean pending) {
|
public LoadBalancerVMMapVO(long loadBalancerId, long instanceId, boolean revoke) {
|
||||||
this.loadBalancerId = loadBalancerId;
|
this.loadBalancerId = loadBalancerId;
|
||||||
this.instanceId = instanceId;
|
this.instanceId = instanceId;
|
||||||
this.pending = pending;
|
this.revoke = revoke;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getId() {
|
public long getId() {
|
||||||
@ -67,11 +67,11 @@ public class LoadBalancerVMMapVO {
|
|||||||
return instanceId;
|
return instanceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPending() {
|
public boolean isRevoke() {
|
||||||
return pending;
|
return revoke;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPending(boolean pending) {
|
public void setRevoke(boolean revoke) {
|
||||||
this.pending = pending;
|
this.revoke = revoke;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,8 +18,6 @@
|
|||||||
|
|
||||||
package com.cloud.network;
|
package com.cloud.network;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.DiscriminatorValue;
|
import javax.persistence.DiscriminatorValue;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
@ -89,9 +87,15 @@ public class LoadBalancerVO extends FirewallRuleVO implements LoadBalancer {
|
|||||||
return defaultPortEnd;
|
return defaultPortEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void setName(String name) {
|
||||||
public List<? extends Destination> getDestinations() {
|
this.name = name;
|
||||||
// TODO Auto-generated method stub
|
}
|
||||||
return null;
|
|
||||||
|
public void setAlgorithm(String algorithm) {
|
||||||
|
this.algorithm = algorithm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,6 +27,7 @@ import javax.ejb.Local;
|
|||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import com.cloud.domain.DomainVO;
|
||||||
import com.cloud.network.LoadBalancerVO;
|
import com.cloud.network.LoadBalancerVO;
|
||||||
import com.cloud.utils.db.GenericDaoBase;
|
import com.cloud.utils.db.GenericDaoBase;
|
||||||
import com.cloud.utils.db.SearchBuilder;
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
|
|||||||
@ -28,5 +28,7 @@ public interface LoadBalancerVMMapDao extends GenericDao<LoadBalancerVMMapVO, Lo
|
|||||||
void remove(long loadBalancerId, List<Long> instanceIds, Boolean pending);
|
void remove(long loadBalancerId, List<Long> instanceIds, Boolean pending);
|
||||||
List<LoadBalancerVMMapVO> listByInstanceId(long instanceId);
|
List<LoadBalancerVMMapVO> listByInstanceId(long instanceId);
|
||||||
List<LoadBalancerVMMapVO> listByLoadBalancerId(long loadBalancerId);
|
List<LoadBalancerVMMapVO> listByLoadBalancerId(long loadBalancerId);
|
||||||
List<LoadBalancerVMMapVO> listByLoadBalancerId(long loadBalancerId, boolean pending);
|
List<LoadBalancerVMMapVO> listByLoadBalancerId(long loadBalancerId, boolean revoke);
|
||||||
|
LoadBalancerVMMapVO findByLoadBalancerIdAndVmId(long loadBalancerId, long instanceId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,12 +38,12 @@ public class LoadBalancerVMMapDaoImpl extends GenericDaoBase<LoadBalancerVMMapVO
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove(long loadBalancerId, List<Long> instanceIds, Boolean pending) {
|
public void remove(long loadBalancerId, List<Long> instanceIds, Boolean revoke) {
|
||||||
SearchCriteria<LoadBalancerVMMapVO> sc = createSearchCriteria();
|
SearchCriteria<LoadBalancerVMMapVO> sc = createSearchCriteria();
|
||||||
sc.addAnd("loadBalancerId", SearchCriteria.Op.EQ, loadBalancerId);
|
sc.addAnd("loadBalancerId", SearchCriteria.Op.EQ, loadBalancerId);
|
||||||
sc.addAnd("instanceId", SearchCriteria.Op.IN, instanceIds.toArray());
|
sc.addAnd("instanceId", SearchCriteria.Op.IN, instanceIds.toArray());
|
||||||
if (pending != null) {
|
if (revoke != null) {
|
||||||
sc.addAnd("pending", SearchCriteria.Op.EQ, pending);
|
sc.addAnd("revoke", SearchCriteria.Op.EQ, revoke);
|
||||||
}
|
}
|
||||||
|
|
||||||
expunge(sc);
|
expunge(sc);
|
||||||
@ -69,8 +69,18 @@ public class LoadBalancerVMMapDaoImpl extends GenericDaoBase<LoadBalancerVMMapVO
|
|||||||
public List<LoadBalancerVMMapVO> listByLoadBalancerId(long loadBalancerId, boolean pending) {
|
public List<LoadBalancerVMMapVO> listByLoadBalancerId(long loadBalancerId, boolean pending) {
|
||||||
SearchCriteria<LoadBalancerVMMapVO> sc = createSearchCriteria();
|
SearchCriteria<LoadBalancerVMMapVO> sc = createSearchCriteria();
|
||||||
sc.addAnd("loadBalancerId", SearchCriteria.Op.EQ, loadBalancerId);
|
sc.addAnd("loadBalancerId", SearchCriteria.Op.EQ, loadBalancerId);
|
||||||
sc.addAnd("pending", SearchCriteria.Op.EQ, pending);
|
sc.addAnd("revoke", SearchCriteria.Op.EQ, pending);
|
||||||
|
|
||||||
return listBy(sc);
|
return listBy(sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LoadBalancerVMMapVO findByLoadBalancerIdAndVmId(long loadBalancerId, long instanceId) {
|
||||||
|
SearchCriteria<LoadBalancerVMMapVO> sc = createSearchCriteria();
|
||||||
|
sc.addAnd("loadBalancerId", SearchCriteria.Op.EQ, loadBalancerId);
|
||||||
|
sc.addAnd("instanceId", SearchCriteria.Op.EQ, instanceId);
|
||||||
|
return findOneBy(sc);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,7 +33,6 @@ import com.cloud.api.commands.ListLoadBalancerRuleInstancesCmd;
|
|||||||
import com.cloud.api.commands.ListLoadBalancerRulesCmd;
|
import com.cloud.api.commands.ListLoadBalancerRulesCmd;
|
||||||
import com.cloud.api.commands.UpdateLoadBalancerRuleCmd;
|
import com.cloud.api.commands.UpdateLoadBalancerRuleCmd;
|
||||||
import com.cloud.dc.dao.VlanDao;
|
import com.cloud.dc.dao.VlanDao;
|
||||||
import com.cloud.domain.DomainVO;
|
|
||||||
import com.cloud.domain.dao.DomainDao;
|
import com.cloud.domain.dao.DomainDao;
|
||||||
import com.cloud.event.EventTypes;
|
import com.cloud.event.EventTypes;
|
||||||
import com.cloud.event.EventVO;
|
import com.cloud.event.EventVO;
|
||||||
@ -50,7 +49,9 @@ import com.cloud.network.dao.FirewallRulesDao;
|
|||||||
import com.cloud.network.dao.IPAddressDao;
|
import com.cloud.network.dao.IPAddressDao;
|
||||||
import com.cloud.network.dao.LoadBalancerDao;
|
import com.cloud.network.dao.LoadBalancerDao;
|
||||||
import com.cloud.network.dao.LoadBalancerVMMapDao;
|
import com.cloud.network.dao.LoadBalancerVMMapDao;
|
||||||
|
import com.cloud.network.lb.LoadBalancingRule.LbDestination;
|
||||||
import com.cloud.network.rules.FirewallRule;
|
import com.cloud.network.rules.FirewallRule;
|
||||||
|
import com.cloud.network.rules.FirewallRule.Purpose;
|
||||||
import com.cloud.network.rules.FirewallRuleVO;
|
import com.cloud.network.rules.FirewallRuleVO;
|
||||||
import com.cloud.network.rules.LoadBalancer;
|
import com.cloud.network.rules.LoadBalancer;
|
||||||
import com.cloud.network.rules.RulesManager;
|
import com.cloud.network.rules.RulesManager;
|
||||||
@ -73,6 +74,7 @@ import com.cloud.utils.net.NetUtils;
|
|||||||
import com.cloud.vm.Nic;
|
import com.cloud.vm.Nic;
|
||||||
import com.cloud.vm.State;
|
import com.cloud.vm.State;
|
||||||
import com.cloud.vm.UserVmVO;
|
import com.cloud.vm.UserVmVO;
|
||||||
|
import com.cloud.vm.dao.NicDao;
|
||||||
import com.cloud.vm.dao.UserVmDao;
|
import com.cloud.vm.dao.UserVmDao;
|
||||||
|
|
||||||
@Local(value = { LoadBalancingRulesManager.class, LoadBalancingRulesService.class })
|
@Local(value = { LoadBalancingRulesManager.class, LoadBalancingRulesService.class })
|
||||||
@ -102,6 +104,7 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesManager,
|
|||||||
@Inject UserVmDao _vmDao;
|
@Inject UserVmDao _vmDao;
|
||||||
@Inject AccountDao _accountDao;
|
@Inject AccountDao _accountDao;
|
||||||
@Inject DomainDao _domainDao;
|
@Inject DomainDao _domainDao;
|
||||||
|
@Inject NicDao _nicDao;
|
||||||
|
|
||||||
@Override @DB
|
@Override @DB
|
||||||
public boolean assignToLoadBalancer(long loadBalancerId, List<Long> instanceIds) {
|
public boolean assignToLoadBalancer(long loadBalancerId, List<Long> instanceIds) {
|
||||||
@ -161,12 +164,22 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesManager,
|
|||||||
|
|
||||||
Transaction txn = Transaction.currentTxn();
|
Transaction txn = Transaction.currentTxn();
|
||||||
txn.start();
|
txn.start();
|
||||||
|
|
||||||
for (UserVm vm : vmsToAdd) {
|
for (UserVm vm : vmsToAdd) {
|
||||||
LoadBalancerVMMapVO map = new LoadBalancerVMMapVO(loadBalancer.getId(), vm.getId(), true);
|
LoadBalancerVMMapVO map = new LoadBalancerVMMapVO(loadBalancer.getId(), vm.getId(), false);
|
||||||
map = _lb2VmMapDao.persist(map);
|
map = _lb2VmMapDao.persist(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
txn.commit();
|
txn.commit();
|
||||||
|
|
||||||
|
try {
|
||||||
|
loadBalancer.setState(FirewallRule.State.Add);
|
||||||
|
_lbDao.persist(loadBalancer);
|
||||||
|
applyLoadBalancerConfig(loadBalancerId);
|
||||||
|
} catch (ResourceUnavailableException e) {
|
||||||
|
s_logger.warn("Unable to apply the load balancer config because resource is unavaliable.", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,7 +195,25 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesManager,
|
|||||||
|
|
||||||
_accountMgr.checkAccess(caller.getAccount(), loadBalancer);
|
_accountMgr.checkAccess(caller.getAccount(), loadBalancer);
|
||||||
|
|
||||||
_lb2VmMapDao.remove(loadBalancerId, instanceIds, null);
|
try {
|
||||||
|
loadBalancer.setState(FirewallRule.State.Add);
|
||||||
|
_lbDao.persist(loadBalancer);
|
||||||
|
|
||||||
|
for (long instanceId : instanceIds) {
|
||||||
|
LoadBalancerVMMapVO map = _lb2VmMapDao.findByLoadBalancerIdAndVmId(loadBalancerId, instanceId);
|
||||||
|
map.setRevoke(true);
|
||||||
|
_lb2VmMapDao.persist(map);
|
||||||
|
s_logger.debug("Set load balancer rule for revoke: rule id " + loadBalancerId + ", vmId " + instanceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
applyLoadBalancerConfig(loadBalancerId);
|
||||||
|
_lb2VmMapDao.remove(loadBalancerId, instanceIds, null);
|
||||||
|
s_logger.debug("Load balancer rule id " + loadBalancerId + " is removed for vms " + instanceIds);
|
||||||
|
} catch (ResourceUnavailableException e) {
|
||||||
|
s_logger.warn("Unable to apply the load balancer config because resource is unavaliable.", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,6 +229,7 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesManager,
|
|||||||
_accountMgr.checkAccess(caller.getAccount(), lb);
|
_accountMgr.checkAccess(caller.getAccount(), lb);
|
||||||
|
|
||||||
lb.setState(FirewallRule.State.Revoke);
|
lb.setState(FirewallRule.State.Revoke);
|
||||||
|
_lbDao.persist(lb);
|
||||||
|
|
||||||
if (apply) {
|
if (apply) {
|
||||||
try {
|
try {
|
||||||
@ -207,6 +239,9 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesManager,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_rulesDao.remove(lb.getId());
|
||||||
|
s_logger.debug("Load balancer with id " + lb.getId() + " is removed successfully");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,7 +300,7 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesManager,
|
|||||||
if (!_rulesDao.setStateToAdd(newRule)) {
|
if (!_rulesDao.setStateToAdd(newRule)) {
|
||||||
throw new CloudRuntimeException("Unable to update the state to add for " + newRule);
|
throw new CloudRuntimeException("Unable to update the state to add for " + newRule);
|
||||||
}
|
}
|
||||||
|
s_logger.debug("Load balancer " + newRule.getId() + " for Ip address " + srcIp + ", public port " + srcPortStart + ", private port " + defPortStart+ " is added successfully.");
|
||||||
success = true;
|
success = true;
|
||||||
return newRule;
|
return newRule;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -273,7 +308,6 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesManager,
|
|||||||
if (e instanceof NetworkRuleConflictException) {
|
if (e instanceof NetworkRuleConflictException) {
|
||||||
throw (NetworkRuleConflictException) e;
|
throw (NetworkRuleConflictException) e;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new CloudRuntimeException("Unable to add rule for " + newRule.getSourceIpAddress(), e);
|
throw new CloudRuntimeException("Unable to add rule for " + newRule.getSourceIpAddress(), e);
|
||||||
} finally {
|
} finally {
|
||||||
long userId = caller.getUserId();
|
long userId = caller.getUserId();
|
||||||
@ -300,13 +334,61 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesManager,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean applyLoadBalancerConfig(long lbRuleId) throws ResourceUnavailableException {
|
public boolean applyLoadBalancerConfig(long lbRuleId) throws ResourceUnavailableException {
|
||||||
return false;
|
|
||||||
|
List<LoadBalancingRule> rules = new ArrayList<LoadBalancingRule>();
|
||||||
|
LoadBalancerVO lb = _lbDao.findById(lbRuleId);
|
||||||
|
List<LbDestination> dstList = getExistingDestinations(lb.getId());
|
||||||
|
|
||||||
|
if (dstList != null && !dstList.isEmpty()) {
|
||||||
|
LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList);
|
||||||
|
rules.add(loadBalancing);
|
||||||
|
|
||||||
|
if (!_networkMgr.applyRules(lb.getSourceIpAddress(), rules, false)) {
|
||||||
|
s_logger.debug("LB rules are not completely applied");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lb.getState() == FirewallRule.State.Revoke) {
|
||||||
|
_lbDao.remove(lb.getId());
|
||||||
|
s_logger.debug("LB " + lb.getId() + " is successfully removed");
|
||||||
|
} else if (lb.getState() == FirewallRule.State.Add) {
|
||||||
|
lb.setState(FirewallRule.State.Active);
|
||||||
|
s_logger.debug("LB rule " + lbRuleId + " state is set to Active");
|
||||||
|
_lbDao.persist(lb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean removeAllLoadBalanacers(Ip ip) {
|
public boolean removeAllLoadBalanacers(Ip ip) {
|
||||||
// TODO Auto-generated method stub
|
List<FirewallRuleVO> rules = _rulesDao.listByIpAndNotRevoked(ip);
|
||||||
return false;
|
for (FirewallRule rule : rules) {
|
||||||
|
if (rule.getPurpose() == Purpose.LoadBalancing) {
|
||||||
|
boolean result = deleteLoadBalancerRule(rule.getId(), true);
|
||||||
|
if (result == false) {
|
||||||
|
s_logger.warn("Unable to remove load balancer rule " + rule.getId());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<LbDestination> getExistingDestinations(long lbId) {
|
||||||
|
List<LbDestination> dstList = new ArrayList<LbDestination>();
|
||||||
|
List<LoadBalancerVMMapVO> lbVmMaps = _lb2VmMapDao.listByLoadBalancerId(lbId);
|
||||||
|
LoadBalancerVO lb = _lbDao.findById(lbId);
|
||||||
|
|
||||||
|
String dstIp = null;
|
||||||
|
for (LoadBalancerVMMapVO lbVmMap : lbVmMaps) {
|
||||||
|
UserVm vm = _vmDao.findById(lbVmMap.getInstanceId());
|
||||||
|
Nic nic = _nicDao.findByInstanceIdAndNetworkId(lb.getNetworkId(), vm.getId());
|
||||||
|
dstIp = nic.getIp4Address();
|
||||||
|
LbDestination lbDst = new LbDestination(lb.getDefaultPortStart(), lb.getDefaultPortEnd(), dstIp, lbVmMap.isRevoke());
|
||||||
|
dstList.add(lbDst);
|
||||||
|
}
|
||||||
|
return dstList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -332,8 +414,39 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesManager,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LoadBalancer updateLoadBalancerRule(UpdateLoadBalancerRuleCmd cmd) {
|
public LoadBalancer updateLoadBalancerRule(UpdateLoadBalancerRuleCmd cmd) {
|
||||||
// TODO Auto-generated method stub
|
Long lbRuleId = cmd.getId();
|
||||||
return null;
|
String name = cmd.getLoadBalancerName();
|
||||||
|
String description = cmd.getDescription();
|
||||||
|
String algorithm = cmd.getAlgorithm();
|
||||||
|
LoadBalancerVO lb = _lbDao.findById(lbRuleId);
|
||||||
|
|
||||||
|
|
||||||
|
if (name != null) {
|
||||||
|
lb.setName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (description != null) {
|
||||||
|
lb.setDescription(description);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (algorithm != null) {
|
||||||
|
lb.setAlgorithm(algorithm);
|
||||||
|
}
|
||||||
|
|
||||||
|
_lbDao.update(lbRuleId, lb);
|
||||||
|
|
||||||
|
//If algorithm is changed, have to reapply the lb config
|
||||||
|
if (algorithm != null) {
|
||||||
|
try {
|
||||||
|
lb.setState(FirewallRule.State.Add);
|
||||||
|
_lbDao.persist(lb);
|
||||||
|
applyLoadBalancerConfig(lbRuleId);
|
||||||
|
} catch (ResourceUnavailableException e) {
|
||||||
|
s_logger.warn("Unable to apply the load balancer config because resource is unavaliable.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return lb;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override @DB
|
// @Override @DB
|
||||||
|
|||||||
@ -16,4 +16,5 @@ public interface NicDao extends GenericDao<NicVO, Long> {
|
|||||||
List<NicVO> listByNetworkId(long networkId);
|
List<NicVO> listByNetworkId(long networkId);
|
||||||
|
|
||||||
List<Long> listNetworksWithNoActiveNics();
|
List<Long> listNetworksWithNoActiveNics();
|
||||||
|
NicVO findByInstanceIdAndNetworkId(long networkId, long instanceId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import javax.ejb.Local;
|
import javax.ejb.Local;
|
||||||
|
|
||||||
|
import com.cloud.domain.DomainVO;
|
||||||
import com.cloud.utils.db.GenericDaoBase;
|
import com.cloud.utils.db.GenericDaoBase;
|
||||||
import com.cloud.utils.db.GenericSearchBuilder;
|
import com.cloud.utils.db.GenericSearchBuilder;
|
||||||
import com.cloud.utils.db.SearchBuilder;
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
@ -73,4 +74,11 @@ public class NicDaoImpl extends GenericDaoBase<NicVO, Long> implements NicDao {
|
|||||||
|
|
||||||
return customSearch(sc, null);
|
return customSearch(sc, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NicVO findByInstanceIdAndNetworkId(long networkId, long instanceId) {
|
||||||
|
SearchCriteria<NicVO> sc = createSearchCriteria();
|
||||||
|
sc.addAnd("networkId", SearchCriteria.Op.EQ, networkId);
|
||||||
|
sc.addAnd("instanceId", SearchCriteria.Op.EQ, instanceId);
|
||||||
|
return findOneBy(sc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -482,7 +482,7 @@ CREATE TABLE `cloud`.`load_balancer_vm_map` (
|
|||||||
`id` bigint unsigned NOT NULL auto_increment,
|
`id` bigint unsigned NOT NULL auto_increment,
|
||||||
`load_balancer_id` bigint unsigned NOT NULL,
|
`load_balancer_id` bigint unsigned NOT NULL,
|
||||||
`instance_id` bigint unsigned NOT NULL,
|
`instance_id` bigint unsigned NOT NULL,
|
||||||
`pending` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT 'whether the vm is being applied to the load balancer (pending=1) or has already been applied (pending=0)',
|
`revoke` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT '1 when vm is set for revoke from load balancer',
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
UNIQUE KEY (`load_balancer_id`, `instance_id`),
|
UNIQUE KEY (`load_balancer_id`, `instance_id`),
|
||||||
CONSTRAINT `fk_load_balancer_vm_map__load_balancer_id` FOREIGN KEY(`load_balancer_id`) REFERENCES `load_balancing_rules`(`id`) ON DELETE CASCADE,
|
CONSTRAINT `fk_load_balancer_vm_map__load_balancer_id` FOREIGN KEY(`load_balancer_id`) REFERENCES `load_balancing_rules`(`id`) ON DELETE CASCADE,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user